-
Notifications
You must be signed in to change notification settings - Fork 33
/
Connection.pm6
86 lines (66 loc) · 1.42 KB
/
Connection.pm6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use v6;
=begin pod
=head2 role DBDish::Connection
Does the C<DBDish::ErrorHandling> role.
=end pod
need DBDish::ErrorHandling;
unit role DBDish::Connection does DBDish::ErrorHandling;
=begin pod
=head4 instance variables
=head4 methods
=head5 do
=end pod
has %.Statements;
has $.last-sth-id is rw;
method dispose() {
$_.dispose for %!Statements.values;
self._disconnect;
?($.parent.Connections{self.WHICH}:delete);
}
submethod DESTROY() {
self.dispose;
}
method disconnect is hidden-from-backtrace {
warn "{::?CLASS.^name}.disconnect is DEPRECATED, please use .dispose";
self.dispose;
}
method drv { $.parent }
method new(*%args) {
my \con = ::?CLASS.bless(|%args);
con.reset-err;
%args<parent>.Connections{con.WHICH} = con;
}
method prepare(Str $statement, *%args) { ... }
method do(Str $statement, *@params, *%args) {
if !@params && self.can('execute') {
self.execute($statement, |%args);
} orwith self.prepare($statement, |%args) {
LEAVE { .finish }
.execute(@params, |%args);
}
else {
.fail;
}
}
method rows {
if $!last-sth-id {
with %!Statements{$!last-sth-id} {
.rows;
}
}
}
=begin pod
=head5 quote-identifier
Returns the string parameter as a quoted identifier
=end pod
method quote-identifier(Str:D $name) {
# a first approximation
qq["$name"];
}
=begin pod
=head5 _disconnect
The C<_disconnect> method
=end pod
method _disconnect() {
...
}