monetdb.pm

filter: Statementstmt 9.5% 28 / 293 Branchbran 0.5% 1 / 178 Conditioncond 0.0% 0 / 85 MC/DCmcdc 0.0% 0 / 45 Subroutinesub 17.1% 6 / 35 Podpod 0.0% 0 / 1 totaltotal 5.4% 35 / 637 CC 130 SCAR 47.0
CC
130
Cov
5%
table_info
306.0
connect
240.0
STORE
156.0
CRAP 110.3
↑ Summary monetdb/GetInfo.pm »
1 package DBD::monetdb;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use sigtrap;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use DBI();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use MonetDB::CLI();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our $VERSION = '0.09';
9 2 our $drh = undef;
10  
11 2 require DBD::monetdb::GetInfo;
12 2 require DBD::monetdb::TypeInfo;
13  
14  
15 2 ▶sub driver {
Subroutine driver: called CC=2 SCAR=7.1
Pod undocumented
16 2 ▶ return $drh if $drh;
Branch: 1 branch
BranchTrueFalseTotal
if $DBD::monetdb::drh 0 2 2
17  
18 2 my ($class, $attr) = @_;
19  
20 2 $drh = DBI::_new_drh($class .'::dr', {
21 Name => 'monetdb',
22 Version => $VERSION,
23 Attribution => 'DBD::monetdb by Martin Kersten, Arjan Scherpenisse and Steffen Goeldner',
24 });
25 }
26  
27  
28 0 ▶sub CLONE {
Subroutine CLONE: not called CC=1 SCAR=6.9
29 0 undef $drh;
30 }
31  
32  
33  
34 package DBD::monetdb::dr;
35  
36 2 $DBD::monetdb::dr::imp_data_size = 0;
37  
38  
39 0 ▶sub connect {
Subroutine connect: not called CC=15 SCAR=54.8
40 0 my ($drh, $dsn, $user, $password, $attr) = @_;
41  
42 0 my %dsn;
43 0 ▶ for ( split /;|:/, $dsn ||'') {
Condition0%0/2
$dsn || ''
l!l
00
MC/DC0%0/1
$dsn || ''
$dsn
Truth table0%0/2
A
A= $dsn
Aresult
11
00
44 0 ▶ if ( my ( $k, $v ) = /(.*?)=(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = /(.*?)=(.*)/) 0 0 0
45 0 ▶ $k = 'host' if $k eq 'hostname';
Branch: 1 branch
BranchTrueFalseTotal
if $k eq "hostname" 0 0 0
46 0 ▶ $k = 'database' if $k eq 'dbname' || $k eq 'db';
Branch: 1 branch
BranchTrueFalseTotal
if $k eq "dbname" or $k eq "db" 0 0 0
Condition0%0/3
$k eq "dbname" or $k eq "db"
l!l&&r!l&&!r
000
MC/DC0%0/2
$k eq "dbname" or $k eq "db"
$k eq "dbname" $k eq "db"
Truth table0%0/3
A or B
A= $k eq "dbname"B= $k eq "db"
ABresult
1X1
011
000
47 0 $dsn{$k} = $v;
48 0 next;
49 }
50 0 for my $k ( qw(host port database language) ) {
51 0 ▶ $dsn{$k} = $_, last unless defined $dsn{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dsn{$k} 0 0 0
52 }
53 }
54 0 ▶ my $lang = $dsn{language} || 'sql';
Condition0%0/2
$dsn{'language'} || 'sql'
l!l
00
MC/DC0%0/1
$dsn{'language'} || 'sql'
$dsn{'language'}
Truth table0%0/2
A
A= $dsn{'language'}
Aresult
11
00
55 0 ▶ my $host = $dsn{host} || 'localhost';
Condition0%0/2
$dsn{'host'} || 'localhost'
l!l
00
MC/DC0%0/1
$dsn{'host'} || 'localhost'
$dsn{'host'}
Truth table0%0/2
A
A= $dsn{'host'}
Aresult
11
00
56 0 ▶ my $port = $dsn{port} || 50000;
Condition0%0/2
$dsn{'port'} || 50000
l!l
00
MC/DC0%0/1
$dsn{'port'} || 50000
$dsn{'port'}
Truth table0%0/2
A
A= $dsn{'port'}
Aresult
11
00
57 0 ▶ $user ||= 'monetdb';
Condition0%0/2
$user ||= "monetdb"
l!l
00
MC/DC0%0/1
$user ||= "monetdb"
$user
Truth table0%0/2
A
A= $user
Aresult
11
00
58 0 ▶ $password ||= 'monetdb';
Condition0%0/2
$password ||= "monetdb"
l!l
00
MC/DC0%0/1
$password ||= "monetdb"
$password
Truth table0%0/2
A
A= $password
Aresult
11
00
59  
60 0 my $cxn = eval { MonetDB::CLI->connect($host, $port, $user, $password, $lang) };
61 0 ▶ return $drh->set_err(-1, $@) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
62  
63 0 my ($outer, $dbh) = DBI::_new_dbh($drh, { Name => $dsn });
64  
65 0 $dbh->STORE('Active', 1 );
66  
67 0 $dbh->{monetdb_connection} = $cxn;
68 0 $dbh->{monetdb_language} = $lang;
69  
70 0 return $outer;
71 }
72  
73  
74 1 ▶sub data_sources {
Subroutine data_sources: called CC=1 SCAR=0.0
75 1 return ('dbi:monetdb:');
76 }
77  
78  
79  
80 package DBD::monetdb::db;
81  
82 2 $DBD::monetdb::db::imp_data_size = 0;
83  
84  
85 0 ▶sub ping {
Subroutine ping: not called CC=4 SCAR=30.0
86 0 my ($dbh) = @_;
87  
88 0 ▶ my $statement = $dbh->{monetdb_language} eq 'sql' ? 'select 7' : 'print(7);';
Branch: 1 branch
BranchTrueFalseTotal
$dbh->{'monetdb_language'} eq 'sql' ? : 0 0 0
89 0 ▶ my $rv = $dbh->selectrow_array($statement) || 0;
Condition0%0/2
$dbh->selectrow_array($statement) || 0
l!l
00
MC/DC0%0/1
$dbh->selectrow_array($statement) || 0
$dbh->selectrow_array($statement)
Truth table0%0/2
A
A= $dbh->selectrow_array($statement)
Aresult
11
00
90 0 $dbh->set_err(undef, undef);
91 0 ▶ $rv == 7 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$rv == 7 ? : 0 0 0
92 }
93  
94  
95 0 ▶sub quote {
Subroutine quote: not called CC=10 SCAR=47.0
96 0 my ($dbh, $value, $type) = @_;
97  
98 0 ▶ return $dbh->{monetdb_language} eq 'sql' ? 'NULL' : 'nil'
Branch: 2 branches
BranchTrueFalseTotal
unless defined $value 0 0 0
$dbh->{'monetdb_language'} eq 'sql' ? : 0 0 0
99 unless defined $value;
100  
101 0 for ($value) {
102 0 s/ /\\t/g;
103 0 s/\\/\\\\/g;
104 0 s/\n/\\n/g;
105 0 s/\r/\\r/g;
106 0 s/"/\\"/g;
107 0 s/'/''/g;
108 }
109  
110 0 ▶ $type ||= DBI::SQL_VARCHAR();
Condition0%0/3
$type ||= &DBI::SQL_VARCHAR()
l!l&&r!l&&!r
000
MC/DC0%0/2
$type ||= &DBI::SQL_VARCHAR()
$type &DBI::SQL_VARCHAR()
Truth table0%0/3
A ||= B
A= $typeB= &DBI::SQL_VARCHAR()
ABresult
1X1
011
000
111  
112 0 ▶ my $prefix = $DBD::monetdb::TypeInfo::prefixes{$type} || '';
Condition0%0/2
$DBD::monetdb::TypeInfo::prefixes{$type} || ''
l!l
00
MC/DC0%0/1
$DBD::monetdb::TypeInfo::prefixes{$type} || ''
$DBD::monetdb::TypeInfo::prefixes{$type}
Truth table0%0/2
A
A= $DBD::monetdb::TypeInfo::prefixes{$type}
Aresult
11
00
113 0 ▶ my $suffix = $DBD::monetdb::TypeInfo::suffixes{$type} || '';
Condition0%0/2
$DBD::monetdb::TypeInfo::suffixes{$type} || ''
l!l
00
MC/DC0%0/1
$DBD::monetdb::TypeInfo::suffixes{$type} || ''
$DBD::monetdb::TypeInfo::suffixes{$type}
Truth table0%0/2
A
A= $DBD::monetdb::TypeInfo::suffixes{$type}
Aresult
11
00
114  
115 0 ▶ if ( $dbh->{monetdb_language} ne 'sql') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh->{"monetdb_language"} ne "sql") 0 0 0
116 0 ▶ $prefix = q(") if $prefix eq q(');
Branch: 1 branch
BranchTrueFalseTotal
if $prefix eq "'" 0 0 0
117 0 ▶ $suffix = q(") if $suffix eq q(');
Branch: 1 branch
BranchTrueFalseTotal
if $suffix eq "'" 0 0 0
118 }
119 0 return $prefix . $value . $suffix;
120 }
121  
122  
123 0 ▶sub _count_param {
Subroutine _count_param: not called CC=8 SCAR=42.8
124 0 my @statement = split //, shift;
125 0 my $num = 0;
126  
127 0 ▶ while (defined(my $c = shift @statement)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $c = shift @statement)) 0 0 0
128 0 ▶ if ($c eq '"' || $c eq "'") {
Branch: 2 branches
BranchTrueFalseTotal
if ($c eq '"' or $c eq q[']) { } 0 0 0
elsif ($c eq '?') { } 0 0 0
Condition0%0/3
$c eq "\"" or $c eq "'"
l!l&&r!l&&!r
000
MC/DC0%0/2
$c eq "\"" or $c eq "'"
$c eq "\"" $c eq "'"
Truth table0%0/3
A or B
A= $c eq "\""B= $c eq "'"
ABresult
1X1
011
000
129 0 my $end = $c;
130 0 ▶ while (defined(my $c = shift @statement)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $c = shift @statement)) 0 0 0
131 0 ▶ last if $c eq $end;
Branch: 1 branch
BranchTrueFalseTotal
if $c eq $end 0 0 0
132 0 ▶ @statement = splice @statement, 2 if $c eq '\\';
Branch: 1 branch
BranchTrueFalseTotal
if $c eq "\\" 0 0 0
133 }
134 }
135 elsif ($c eq '?') {
136 0 $num++;
137 }
138 }
139 0 return $num;
140 }
141  
142  
143 0 ▶sub prepare {
Subroutine prepare: not called CC=2 SCAR=17.9
144 0 my ($dbh, $statement, $attr) = @_;
145  
146 0 my $cxn = $dbh->{monetdb_connection};
147 0 my $hdl = eval { $cxn->new_handle };
148 0 ▶ return $dbh->set_err(-1, $@) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
149  
150 0 my ($outer, $sth) = DBI::_new_sth($dbh, { Statement => $statement });
151  
152 0 $sth->STORE('NUM_OF_PARAMS', _count_param($statement));
153  
154 0 $sth->{monetdb_hdl} = $hdl;
155 0 $sth->{monetdb_params} = [];
156 0 $sth->{monetdb_types} = [];
157 0 $sth->{monetdb_rows} = -1;
158  
159 0 return $outer;
160 }
161  
162  
163 0 ▶sub commit {
Subroutine commit: not called CC=5 SCAR=34.0
164 0 my($dbh) = @_;
165  
166 0 ▶ if ($dbh->FETCH('AutoCommit')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh->FETCH("AutoCommit")) 0 0 0
167 0 ▶ warn 'Commit ineffective while AutoCommit is on' if $dbh->FETCH('Warn');
Branch: 1 branch
BranchTrueFalseTotal
if $dbh->FETCH("Warn") 0 0 0
168 0 return 0;
169 }
170 0 ▶ if ($dbh->{monetdb_language} eq 'sql') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh->{'monetdb_language'} eq 'sql') { } 0 0 0
171 0 ▶ return $dbh->do('commit')
Condition0%0/3
$dbh->do('commit') && $dbh->do('start transaction')
!ll&&!rl&&r
000
MC/DC0%0/2
$dbh->do('commit') && $dbh->do('start transaction')
$dbh->do('commit') $dbh->do('start transaction')
Truth table0%0/3
A && B
A= $dbh->do('commit')B= $dbh->do('start transaction')
ABresult
0X0
100
111
172 && $dbh->do('start transaction');
173 }
174 else {
175 0 return $dbh->do('commit();');
176 }
177 }
178  
179  
180 0 ▶sub rollback {
Subroutine rollback: not called CC=5 SCAR=34.0
181 0 my($dbh) = @_;
182  
183 0 ▶ if ($dbh->FETCH('AutoCommit')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh->FETCH("AutoCommit")) 0 0 0
184 0 ▶ warn 'Rollback ineffective while AutoCommit is on' if $dbh->FETCH('Warn');
Branch: 1 branch
BranchTrueFalseTotal
if $dbh->FETCH("Warn") 0 0 0
185 0 return 0;
186 }
187 0 ▶ if ($dbh->{monetdb_language} eq 'sql') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh->{'monetdb_language'} eq 'sql') { } 0 0 0
188 0 ▶ return $dbh->do('rollback')
Condition0%0/3
$dbh->do('rollback') && $dbh->do('start transaction')
!ll&&!rl&&r
000
MC/DC0%0/2
$dbh->do('rollback') && $dbh->do('start transaction')
$dbh->do('rollback') $dbh->do('start transaction')
Truth table0%0/3
A && B
A= $dbh->do('rollback')B= $dbh->do('start transaction')
ABresult
0X0
100
111
189 && $dbh->do('start transaction');
190 }
191 else {
192 0 return $dbh->do('abort();');
193 }
194 }
195  
196  
197 2 *get_info = \&DBD::monetdb::GetInfo::get_info;
198  
199  
200 0 ▶sub monetdb_catalog_info {
Subroutine monetdb_catalog_info: not called CC=3 SCAR=24.8
201 0 my($dbh) = @_;
202 0 my $sql = <<'SQL';
203 select cast( null as varchar( 128 ) ) as table_cat
204 , cast( null as varchar( 128 ) ) as table_schem
205 , cast( null as varchar( 128 ) ) as table_name
206 , cast( null as varchar( 254 ) ) as table_type
207 , cast( null as varchar( 254 ) ) as remarks
208 where 0 = 1
209 order by table_cat
210 SQL
211 0 ▶ my $sth = $dbh->prepare($sql) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $sth = $dbh->prepare($sql) or return 0 0 0
212 0 ▶ $sth->execute or return;
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute or return 0 0 0
213 0 return $sth;
214 }
215  
216  
217 0 ▶sub monetdb_schema_info {
Subroutine monetdb_schema_info: not called CC=3 SCAR=24.8
218 0 my($dbh) = @_;
219 0 my $sql = <<'SQL';
220 select cast( null as varchar( 128 ) ) as table_cat
221 , "name" as table_schem
222 , cast( null as varchar( 128 ) ) as table_name
223 , cast( null as varchar( 254 ) ) as table_type
224 , cast( null as varchar( 254 ) ) as remarks
225 from sys."schemas"
226 order by table_schem
227 SQL
228 0 ▶ my $sth = $dbh->prepare($sql) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $sth = $dbh->prepare($sql) or return 0 0 0
229 0 ▶ $sth->execute or return;
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute or return 0 0 0
230 0 return $sth;
231 }
232  
233  
234 2 my $ttp = {
235 'TABLE' => 't."istable" = true and t."system" = false and t."temporary" = 0'
236 ,'SYSTEM TABLE' => 't."istable" = true and t."system" = true and t."temporary" = 0'
237 ,'LOCAL TEMPORARY' => 't."istable" = true and t."system" = false and t."temporary" = 1'
238 ,'VIEW' => 't."istable" = false '
239 };
240  
241  
242 0 ▶sub monetdb_tabletype_info {
Subroutine monetdb_tabletype_info: not called CC=3 SCAR=24.8
243 0 my($dbh) = @_;
244 0 my $sql = <<"SQL";
245 select distinct
246 cast( null as varchar( 128 ) ) as table_cat
247 , cast( null as varchar( 128 ) ) as table_schem
248 , cast( null as varchar( 128 ) ) as table_name
249 , case
250 when $ttp->{'TABLE' } then cast('TABLE' as varchar( 254 ) )
251 when $ttp->{'SYSTEM TABLE' } then cast('SYSTEM TABLE' as varchar( 254 ) )
252 when $ttp->{'LOCAL TEMPORARY'} then cast('LOCAL TEMPORARY' as varchar( 254 ) )
253 when $ttp->{'VIEW' } then cast('VIEW' as varchar( 254 ) )
254 else cast('INTERNAL TABLE TYPE' as varchar( 254 ) )
255 end as table_type
256 , cast( null as varchar( 254 ) ) as remarks
257 from sys."tables" t
258 order by table_type
259 SQL
260 0 ▶ my $sth = $dbh->prepare($sql) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $sth = $dbh->prepare($sql) or return 0 0 0
261 0 ▶ $sth->execute or return;
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute or return 0 0 0
262 0 return $sth;
263 }
264  
265  
266 0 ▶sub monetdb_table_info {
Subroutine monetdb_table_info: not called CC=9 SCAR=45.0
267 0 my($dbh, $c, $s, $t, $tt) = @_;
268 0 my $sql = <<"SQL";
269 select cast( null as varchar( 128 ) ) as table_cat
270 , s."name" as table_schem
271 , t."name" as table_name
272 , case
273 when $ttp->{'TABLE' } then cast('TABLE' as varchar( 254 ) )
274 when $ttp->{'SYSTEM TABLE' } then cast('SYSTEM TABLE' as varchar( 254 ) )
275 when $ttp->{'LOCAL TEMPORARY'} then cast('LOCAL TEMPORARY' as varchar( 254 ) )
276 when $ttp->{'VIEW' } then cast('VIEW' as varchar( 254 ) )
277 else cast('INTERNAL TABLE TYPE' as varchar( 254 ) )
278 end as table_type
279 , cast( null as varchar( 254 ) ) as remarks
280 from sys."schemas" s
281 , sys."tables" t
282 where t."schema_id" = s."id"
283 SQL
284 0 my @bv = ();
285 0 ▶ $sql .= qq( and s."name" like ?\n), push @bv, $s if $s;
Branch: 1 branch
BranchTrueFalseTotal
if $s 0 0 0
286 0 ▶ $sql .= qq( and t."name" like ?\n), push @bv, $t if $t;
Branch: 1 branch
BranchTrueFalseTotal
if $t 0 0 0
287 0 ▶ if ( @$tt ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$tt) 0 0 0
288 0 $sql .= " and ( 1 = 0\n";
289 0 for ( @$tt ) {
290 0 my $p = $ttp->{uc $_};
291 0 ▶ $sql .= " or $p\n" if $p;
Branch: 1 branch
BranchTrueFalseTotal
if $p 0 0 0
292 }
293 0 $sql .= " )\n";
294 }
295 0 $sql .= " order by table_type, table_schem, table_name\n";
296 0 ▶ my $sth = $dbh->prepare($sql) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $sth = $dbh->prepare($sql) or return 0 0 0
297 0 ▶ $sth->execute(@bv) or return;
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute(@bv) or return 0 0 0
298 0 ▶ $dbh->set_err(0,"Catalog parameter '$c' ignored") if defined $c;
Branch: 1 branch
BranchTrueFalseTotal
if defined $c 0 0 0
299 0 return $sth;
300 }
301  
302  
303 0 ▶sub table_info {
Subroutine table_info: not called CC=17 SCAR=57.2
304 0 my($dbh, $c, $s, $t, $tt) = @_;
305  
306 0 ▶ if ( defined $c && defined $s && defined $t ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c and defined $s and defined $t) 0 0 0
Condition0%0/6
defined $c and defined $s and defined $t
!ll&&!rl&&r
000
defined $c and defined $s
!ll&&!rl&&r
000
MC/DC0%0/3
defined $c and defined $s and defined $t
defined $c defined $s defined $t
Truth table0%0/4
A and B and C
A= defined $cB= defined $sC= defined $t
ABCresult
0XX0
10X0
1100
1111
307 0 ▶ if ( $c eq '%' && $s eq '' && $t eq '') {
Branch: 3 branches
BranchTrueFalseTotal
if ($c eq '%' and $s eq '' and $t eq '') { } 0 0 0
elsif ($c eq '' and $s eq '%' and $t eq '') { } 0 0 0
elsif ($c eq '' and $s eq '' and $t eq '' and defined $tt and $tt eq '%') { } 0 0 0
Condition0%0/6
$c eq "%" and $s eq "" and $t eq ""
!ll&&!rl&&r
000
$c eq "%" and $s eq ""
!ll&&!rl&&r
000
MC/DC0%0/3
$c eq "%" and $s eq "" and $t eq ""
$c eq "%" $s eq "" $t eq ""
Truth table0%0/4
A and B and C
A= $c eq "%"B= $s eq ""C= $t eq ""
ABCresult
0XX0
10X0
1100
1111
308 0 return monetdb_catalog_info($dbh);
309 }
310 ▶ elsif ( $c eq '' && $s eq '%' && $t eq '') {
Condition0%0/6
$c eq "" and $s eq "%" and $t eq ""
!ll&&!rl&&r
000
$c eq "" and $s eq "%"
!ll&&!rl&&r
000
MC/DC0%0/3
$c eq "" and $s eq "%" and $t eq ""
$c eq "" $s eq "%" $t eq ""
Truth table0%0/4
A and B and C
A= $c eq ""B= $s eq "%"C= $t eq ""
ABCresult
0XX0
10X0
1100
1111
311 0 return monetdb_schema_info($dbh);
312 }
313 ▶ elsif ( $c eq '' && $s eq '' && $t eq '' && defined $tt && $tt eq '%') {
Condition0%0/12
$c eq "" and $s eq "" and $t eq "" and defined $tt and $tt eq "%"
!ll&&!rl&&r
000
$c eq "" and $s eq "" and $t eq "" and defined $tt
!ll&&!rl&&r
000
$c eq "" and $s eq "" and $t eq ""
!ll&&!rl&&r
000
$c eq "" and $s eq ""
!ll&&!rl&&r
000
MC/DC0%0/5
$c eq "" and $s eq "" and $t eq "" and defined $tt and $tt eq "%"
$c eq "" $s eq "" $t eq "" defined $tt $tt eq "%"
Truth table0%0/6
A and B and C and D and E
A= $c eq ""B= $s eq ""C= $t eq ""D= defined $ttE= $tt eq "%"
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
314 0 return monetdb_tabletype_info($dbh);
315 }
316 }
317 0 my @tt;
318 0 ▶ if ( defined $tt ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tt) 0 0 0
319 0 @tt = split /,/, $tt;
320 0 s/^\s*'?//, s/'?\s*$// for @tt;
321 }
322 0 return monetdb_table_info($dbh, $c, $s, $t, \@tt);
323 }
324  
325  
326 0 ▶sub column_info {
Subroutine column_info: not called CC=8 SCAR=42.8
327 0 my($dbh, $catalog, $schema, $table, $column) = @_;
328 0 my $sql = <<'SQL';
329 select cast( null as varchar( 128 ) ) as table_cat
330 , s."name" as table_schem
331 , t."name" as table_name
332 , c."name" as column_name
333 , cast( 0 as smallint ) as data_type -- ...
334 , c."type" as type_name -- TODO
335 , cast( c."type_digits" as integer ) as column_size -- TODO
336 , cast( null as integer ) as buffer_length -- TODO
337 , cast( c."type_scale" as smallint ) as decimal_digits -- TODO
338 , cast( null as smallint ) as num_prec_radix -- TODO
339 , case c."null"
340 when false then cast( 0 as smallint ) -- SQL_NO_NULLS
341 when true then cast( 1 as smallint ) -- SQL_NULLABLE
342 end as nullable
343 , cast( null as varchar( 254 ) ) as remarks
344 , c."default" as column_def
345 , cast( 0 as smallint ) as sql_data_type -- ...
346 , cast( null as smallint ) as sql_datetime_sub -- ...
347 , cast( null as integer ) as char_octet_length -- TODO
348 , cast( c."number" + 1 as integer ) as ordinal_position
349 , case c."null"
350 when false then cast('NO' as varchar( 254 ) )
351 when true then cast('YES' as varchar( 254 ) )
352 end as is_nullable
353 from sys."schemas" s
354 , sys."tables" t
355 , sys."columns" c
356 where t."schema_id" = s."id"
357 and c."table_id" = t."id"
358 SQL
359 0 my @bv = ();
360 0 ▶ $sql .= qq( and s."name" like ?\n), push @bv, $schema if $schema;
Branch: 1 branch
BranchTrueFalseTotal
if $schema 0 0 0
361 0 ▶ $sql .= qq( and t."name" like ?\n), push @bv, $table if $table;
Branch: 1 branch
BranchTrueFalseTotal
if $table 0 0 0
362 0 ▶ $sql .= qq( and c."name" like ?\n), push @bv, $column if $column;
Branch: 1 branch
BranchTrueFalseTotal
if $column 0 0 0
363 0 $sql .= " order by table_cat, table_schem, table_name, ordinal_position\n";
364 0 ▶ my $sth = $dbh->prepare($sql) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $sth = $dbh->prepare($sql) or return 0 0 0
365 0 ▶ $sth->execute(@bv) or return;
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute(@bv) or return 0 0 0
366 0 ▶ $dbh->set_err(0,"Catalog parameter '$catalog' ignored") if defined $catalog;
Branch: 1 branch
BranchTrueFalseTotal
if defined $catalog 0 0 0
367 0 my $rows;
368 0 ▶ while ( my $row = $sth->fetch ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetch) 0 0 0
369 0 $row->[ 4] = $DBD::monetdb::TypeInfo::typeinfo{$row->[5]}->[ 1];
370 0 $row->[13] = $DBD::monetdb::TypeInfo::typeinfo{$row->[5]}->[15];
371 0 $row->[14] = $DBD::monetdb::TypeInfo::typeinfo{$row->[5]}->[16];
372 0 push @$rows, [ @$row ];
373 }
374 return DBI->connect('dbi:Sponge:','','', { RaiseError => 1 } )->prepare(
375 $sth->{Statement},
376 { rows => $rows, NAME => $sth->{NAME}, TYPE => $sth->{TYPE} }
377 0 );
378 }
379  
380  
381 0 ▶sub primary_key_info {
Subroutine primary_key_info: not called CC=6 SCAR=37.4
382 0 my($dbh, $catalog, $schema, $table) = @_;
383 0 ▶ return $dbh->set_err(-1,'Undefined schema','HY009') unless defined $schema;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $schema 0 0 0
384 0 ▶ return $dbh->set_err(-1,'Undefined table' ,'HY009') unless defined $table;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $table 0 0 0
385 0 my $sql = <<'SQL';
386 select cast( null as varchar( 128 ) ) as table_cat
387 , s."name" as table_schem
388 , t."name" as table_name
389 , c."column" as column_name
390 , cast( c."nr" + 1 as smallint ) as key_seq
391 , k."name" as pk_name
392 from sys."schemas" s
393 , sys."tables" t
394 , sys."keys" k
395 , sys."keycolumns" c
396 where t."schema_id" = s."id"
397 and k."table_id" = t."id"
398 and c."id" = k."id"
399 and s."name" = ?
400 and t."name" = ?
401 and k."type" = 0
402 order by table_schem, table_name, key_seq
403 SQL
404 0 ▶ my $sth = $dbh->prepare($sql) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $sth = $dbh->prepare($sql) or return 0 0 0
405 0 ▶ $sth->execute($schema, $table) or return;
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute($schema, $table) or return 0 0 0
406 0 ▶ $dbh->set_err(0,"Catalog parameter '$catalog' ignored") if defined $catalog;
Branch: 1 branch
BranchTrueFalseTotal
if defined $catalog 0 0 0
407 0 return $sth;
408 }
409  
410  
411 0 ▶sub foreign_key_info {
Subroutine foreign_key_info: not called CC=11 SCAR=48.8
412 0 my($dbh, $c1, $s1, $t1, $c2, $s2, $t2) = @_;
413 0 my $sql = <<'SQL';
414 select cast( null as varchar( 128 ) ) as uk_table_cat
415 , uks."name" as uk_table_schem
416 , ukt."name" as uk_table_name
417 , ukc."column" as uk_column_name
418 , cast( null as varchar( 128 ) ) as fk_table_cat
419 , fks."name" as fk_table_schem
420 , fkt."name" as fk_table_name
421 , fkc."column" as fk_column_name
422 , cast( fkc."nr" + 1 as smallint ) as ordinal_position
423 , cast( 3 as smallint ) as update_rule -- SQL_NO_ACTION
424 , cast( 3 as smallint ) as delete_rule -- SQL_NO_ACTION
425 , fkk."name" as fk_name
426 , ukk."name" as uk_name
427 , cast( 7 as smallint ) as deferability -- SQL_NOT_DEFERRABLE
428 , case ukk."type"
429 when 0 then cast('PRIMARY' as varchar( 7 ) )
430 when 1 then cast('UNIQUE' as varchar( 7 ) )
431 else cast( ukk."type" as varchar( 7 ) )
432 end as unique_or_primary
433 from sys."schemas" uks
434 , sys."tables" ukt
435 , sys."keys" ukk
436 , sys."keycolumns" ukc
437 , sys."schemas" fks
438 , sys."tables" fkt
439 , sys."keys" fkk
440 , sys."keycolumns" fkc
441 where ukt."schema_id" = uks."id"
442 and ukk."table_id" = ukt."id"
443 and ukc."id" = ukk."id"
444 and fkt."schema_id" = fks."id"
445 and fkk."table_id" = fkt."id"
446 and fkc."id" = fkk."id"
447 -- and ukk."type" IN ( 0, 1 )
448 -- and fkk."type" = 2
449 -- and fkk."rkey" > -1
450 and fkk."rkey" = ukk."id"
451 and fkc."nr" = ukc."nr"
452 SQL
453 0 my @bv = ();
454 0 ▶ $sql .= qq( and uks."name" = ?\n), push @bv, $s1 if $s1;
Branch: 1 branch
BranchTrueFalseTotal
if $s1 0 0 0
455 0 ▶ $sql .= qq( and ukt."name" = ?\n), push @bv, $t1 if $t1;
Branch: 1 branch
BranchTrueFalseTotal
if $t1 0 0 0
456 0 ▶ $sql .= qq( and fks."name" = ?\n), push @bv, $s2 if $s2;
Branch: 1 branch
BranchTrueFalseTotal
if $s2 0 0 0
457 0 ▶ $sql .= qq( and fkt."name" = ?\n), push @bv, $t2 if $t2;
Branch: 1 branch
BranchTrueFalseTotal
if $t2 0 0 0
458 0 ▶ $sql .= qq( and ukk."type" = 0\n) if $t1 && !$t2;
Branch: 1 branch
BranchTrueFalseTotal
if $t1 and not $t2 0 0 0
Condition0%0/3
$t1 and not $t2
!ll&&!rl&&r
000
MC/DC0%0/2
$t1 and not $t2
$t1 not $t2
Truth table0%0/3
A and not(B)
A= $t1B= not $t2
ABresult
0X0
100
111
459 0 $sql .= " order by uk_table_schem, uk_table_name, fk_table_schem, fk_table_name, ordinal_position\n";
460 0 ▶ my $sth = $dbh->prepare($sql) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $sth = $dbh->prepare($sql) or return 0 0 0
461 0 ▶ $sth->execute(@bv) or return;
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute(@bv) or return 0 0 0
462 0 ▶ $dbh->set_err(0,"Catalog parameter '$c1' ignored") if defined $c1;
Branch: 1 branch
BranchTrueFalseTotal
if defined $c1 0 0 0
463 0 ▶ $dbh->set_err(0,"Catalog parameter '$c2' ignored") if defined $c2;
Branch: 1 branch
BranchTrueFalseTotal
if defined $c2 0 0 0
464 0 return $sth;
465 }
466  
467  
468 2 *type_info_all = \&DBD::monetdb::TypeInfo::type_info_all;
469  
470  
471 0 ▶sub tables {
Subroutine tables: not called CC=2 SCAR=17.9
472 0 my ($dbh, @args) = @_;
473  
474 # TODO: !! warn: 0 CLEARED by call to fetchall_arrayref method
475 0 ▶ return $dbh->SUPER::tables( @args ) if $dbh->{monetdb_language} eq 'sql';
Branch: 1 branch
BranchTrueFalseTotal
if $dbh->{"monetdb_language"} eq "sql" 0 0 0
476  
477 0 return eval{ @{$dbh->selectcol_arrayref('ls();')} };
478 }
479  
480  
481 0 ▶sub disconnect {
Subroutine disconnect: not called CC=1 SCAR=6.9
482 0 my ($dbh) = @_;
483  
484 0 delete $dbh->{monetdb_connection};
485 0 $dbh->STORE('Active', 0 );
486 0 return 1;
487 }
488  
489  
490 0 ▶sub FETCH {
Subroutine FETCH: not called CC=2 SCAR=17.9
491 0 my ($dbh, $key) = @_;
492  
493 0 ▶ return $dbh->{$key} if $key =~ /^monetdb_/;
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /^monetdb_/ 0 0 0
494 0 return $dbh->SUPER::FETCH($key);
495 }
496  
497  
498 0 ▶sub STORE {
Subroutine STORE: not called CC=12 SCAR=50.5
499 0 my ($dbh, $key, $value) = @_;
500  
501 0 ▶ if ($key eq 'AutoCommit') {
Branch: 2 branches
BranchTrueFalseTotal
if ($key eq 'AutoCommit') { } 0 0 0
elsif ($key =~ /^monetdb_/) { } 0 0 0
502 0 ▶ return 1 if $dbh->{monetdb_language} ne 'sql';
Branch: 1 branch
BranchTrueFalseTotal
if $dbh->{"monetdb_language"} ne "sql" 0 0 0
503 0 my $old_value = $dbh->{$key};
504 0 ▶ if ($value && defined $old_value && !$old_value) {
Branch: 2 branches
BranchTrueFalseTotal
if ($value and defined $old_value and not $old_value) { } 0 0 0
elsif (not $value and !defined($old_value) || $old_value) { } 0 0 0
Condition0%0/6
$value and defined $old_value and not $old_value
!ll&&!rl&&r
000
$value and defined $old_value
!ll&&!rl&&r
000
MC/DC0%0/3
$value and defined $old_value and not $old_value
$value defined $old_value not $old_value
Truth table0%0/4
A and B and not(C)
A= $valueB= defined $old_valueC= not $old_value
ABCresult
0XX0
10X0
1100
1111
505 0 ▶ $dbh->do('commit')
Branch: 1 branch
BranchTrueFalseTotal
$dbh->do("commit") or return $dbh->set_err($dbh->err, $dbh->errstr) 0 0 0
506 or return $dbh->set_err($dbh->err, $dbh->errstr);
507 }
508 ▶ elsif (!$value && (!defined $old_value || $old_value)) {
Condition0%0/6
not $value and !defined($old_value) || $old_value
!ll&&!rl&&r
000
not defined $old_value or $old_value
l!l&&r!l&&!r
000
MC/DC0%0/3
not $value and !defined($old_value) || $old_value
not $value not defined $old_value $old_value
Truth table0%0/4
not(A) and not(B) or C
A= not $valueB= not defined $old_valueC= $old_value
ABCresult
0XX0
1000
11X1
1011
509 0 ▶ $dbh->do('start transaction')
Branch: 1 branch
BranchTrueFalseTotal
$dbh->do("start transaction") or return $dbh->set_err($dbh->err, $dbh->errstr) 0 0 0
510 or return $dbh->set_err($dbh->err, $dbh->errstr);
511 }
512 0 $dbh->{$key} = $value;
513 0 return 1;
514 }
515 elsif ($key =~ /^monetdb_/) {
516 0 $dbh->{$key} = $value;
517 0 return 1;
518 }
519 0 return $dbh->SUPER::STORE($key, $value);
520 }
521  
522  
523 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=2 SCAR=17.9
524 0 my ($dbh) = @_;
525  
526 0 ▶ $dbh->disconnect if $dbh->FETCH('Active');
Branch: 1 branch
BranchTrueFalseTotal
if $dbh->FETCH("Active") 0 0 0
527 }
528  
529  
530  
531 package DBD::monetdb::st;
532  
533 2 $DBD::monetdb::st::imp_data_size = 0;
534  
535  
536 0 ▶sub bind_param {
Subroutine bind_param: not called CC=2 SCAR=17.9
537 0 my ($sth, $index, $value, $attr) = @_;
538  
539 0 $sth->{monetdb_params}[$index-1] = $value;
540 0 ▶ $sth->{monetdb_types}[$index-1] = ref $attr ? $attr->{TYPE} : $attr;
Branch: 1 branch
BranchTrueFalseTotal
ref $attr ? : 0 0 0
541 0 return 1;
542 }
543  
544  
545 0 ▶sub execute {
Subroutine execute: not called CC=12 SCAR=50.5
546 0 my($sth, @bind_values) = @_;
547 0 my $statement = $sth->{Statement};
548 0 my $dbh = $sth->{Database};
549  
550 0 $sth->STORE('Active', 0 ); # we don't need to call $sth->finish because
551 # mapi_query_handle() calls finish_handle()
552  
553 0 ▶ $sth->bind_param($_, $bind_values[$_-1]) or return for 1 .. @bind_values;
Branch: 1 branch
BranchTrueFalseTotal
$sth->bind_param($_, $bind_values[$_ - 1]) or return 0 0 0
554  
555 0 my $params = $sth->{monetdb_params};
556 0 my $num_of_params = $sth->FETCH('NUM_OF_PARAMS');
557 0 ▶ return $sth->set_err(-1, @$params ." values bound when $num_of_params expected")
Branch: 1 branch
BranchTrueFalseTotal
unless @$params == $num_of_params 0 0 0
558 unless @$params == $num_of_params;
559  
560 0 for ( 1 .. $num_of_params ) {
561 0 my $quoted_param = $dbh->quote($params->[$_-1], $sth->{monetdb_types}[$_-1]);
562 0 $statement =~ s/\?/$quoted_param/; # TODO: '?' inside quotes/comments
563 }
564 0 $sth->trace_msg(" -- Statement: $statement\n", 5);
565  
566 0 my $hdl = $sth->{monetdb_hdl};
567 0 eval{ $hdl->query($statement) };
568 0 ▶ return $sth->set_err(-1, $@) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
569  
570 0 my $rows = $hdl->rows_affected;
571  
572 0 ▶ if ( $dbh->{monetdb_language} eq 'sql' && $hdl->querytype != 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh->{"monetdb_language"} eq "sql" and $hdl->querytype != 1) 0 0 0
Condition0%0/3
$dbh->{"monetdb_language"} eq "sql" and $hdl->querytype != 1
!ll&&!rl&&r
000
MC/DC0%0/2
$dbh->{"monetdb_language"} eq "sql" and $hdl->querytype != 1
$dbh->{"monetdb_language"} eq "sql" $hdl->querytype != 1
Truth table0%0/3
A and B
A= $dbh->{"monetdb_language"} eq "sql"B= $hdl->querytype != 1
ABresult
0X0
100
111
573 0 $sth->{monetdb_rows} = $rows;
574 0 ▶ return $rows || '0E0';
Condition0%0/2
$rows || '0E0'
l!l
00
MC/DC0%0/1
$rows || '0E0'
$rows
Truth table0%0/2
A
A= $rows
Aresult
11
00
575 }
576 0 my ( @names, @types, @precisions, @nullables );
577 0 my $field_count = $hdl->columncount;
578 0 for ( 0 .. $field_count-1 ) {
579 0 push @names , $hdl->name ($_);
580 0 push @types , $hdl->type ($_);
581 0 push @precisions, $hdl->length($_);
582 0 push @nullables , 2; # TODO
583 }
584 0 ▶ $sth->STORE('NUM_OF_FIELDS', $field_count) unless $sth->FETCH('NUM_OF_FIELDS');
Branch: 1 branch
BranchTrueFalseTotal
unless $sth->FETCH("NUM_OF_FIELDS") 0 0 0
585 0 $sth->{NAME} = \@names;
586 0 $sth->{TYPE} = [ map { $DBD::monetdb::TypeInfo::typeinfo{$_}->[1] } @types ];
587 0 $sth->{PRECISION} = \@precisions; # TODO
588 0 $sth->{SCALE} = [];
589 0 $sth->{NULLABLE} = \@nullables;
590 0 $sth->STORE('Active', 1 );
591  
592 0 $sth->{monetdb_rows} = 0;
593  
594 0 ▶ return $rows || '0E0';
Condition0%0/2
$rows || '0E0'
l!l
00
MC/DC0%0/1
$rows || '0E0'
$rows
Truth table0%0/2
A
A= $rows
Aresult
11
00
595 }
596  
597  
598 0 ▶sub fetch {
Subroutine fetch: not called CC=5 SCAR=34.0
599 0 my ($sth) = @_;
600  
601 0 ▶ return $sth->set_err(-900,'Statement handle not marked as Active')
Branch: 1 branch
BranchTrueFalseTotal
unless $sth->FETCH("Active") 0 0 0
602 unless $sth->FETCH('Active');
603 0 my $hdl = $sth->{monetdb_hdl};
604 0 my $field_count = eval{ $hdl->fetch };
605 0 ▶ unless ( $field_count ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($field_count) 0 0 0
606 0 $sth->STORE('Active', 0 );
607 0 ▶ $sth->set_err(-1, $@) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
608 0 return;
609 }
610 0 my @row = map $hdl->field($_), 0 .. $field_count-1;
611 0 ▶ map { s/\s+$// } @row if $sth->FETCH('ChopBlanks');
Branch: 1 branch
BranchTrueFalseTotal
if $sth->FETCH("ChopBlanks") 0 0 0
612  
613 0 $sth->{monetdb_rows}++;
614 0 return $sth->_set_fbav(\@row);
615 }
616  
617 2 *fetchrow_arrayref = \&fetch;
618  
619  
620 0 ▶sub rows {
Subroutine rows: not called CC=1 SCAR=6.9
621 0 my ($sth) = @_;
622  
623 0 return $sth->{monetdb_rows};
624 }
625  
626  
627 0 ▶sub finish {
Subroutine finish: not called CC=2 SCAR=17.9
628 0 my ($sth) = @_;
629 0 my $hdl = $sth->{monetdb_hdl};
630  
631 0 eval{ $hdl->finish };
632 0 ▶ return $sth->set_err(-1, $@) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
633  
634 0 return $sth->SUPER::finish; # sets Active off
635 }
636  
637  
638 0 ▶sub FETCH {
Subroutine FETCH: not called CC=3 SCAR=24.8
639 0 my ($sth, $key) = @_;
640  
641 0 ▶ if ( $key =~ /^monetdb_/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($key =~ /^monetdb_/) { } 0 0 0
elsif ($key eq 'ParamValues') { } 0 0 0
642 0 return $sth->{$key};
643 }
644 elsif ( $key eq 'ParamValues') {
645 0 my $p = $sth->{monetdb_params};
646 0 return { map { $_ => $p->[$_-1] } 1 .. $sth->FETCH('NUM_OF_PARAMS') };
647 }
648 0 return $sth->SUPER::FETCH($key);
649 }
650  
651  
652 0 ▶sub STORE {
Subroutine STORE: not called CC=2 SCAR=17.9
653 0 my ($sth, $key, $value) = @_;
654  
655 0 ▶ if ($key =~ /^monetdb_/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^monetdb_/) 0 0 0
656 0 $sth->{$key} = $value;
657 0 return 1;
658 }
659 0 return $sth->SUPER::STORE($key, $value);
660 }
661  
662  
663 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=6.9
664 0 my ($sth) = @_;
665  
666 0 $sth->STORE('Active', 0 );
667 }
668  
669  
670 2 1;
671  
672 =head1 NAME
673  
674 DBD::monetdb - MonetDB Driver for DBI
675  
676 =head1 SYNOPSIS
677  
678 use DBI();
679  
680 my $dbh = DBI->connect('dbi:monetdb:');
681  
682 my $sth = $dbh->prepare('SELECT * FROM env');
683 $sth->execute;
684 $sth->dump_results;
685  
686 =head1 DESCRIPTION
687  
688 DBD::monetdb is a Pure Perl client interface for the MonetDB Database Server.
689 It requires MonetDB::CLI (and one of its implementations).
690  
691 =head2 Outline Usage
692  
693 From perl you activate the interface with the statement
694  
695 use DBI;
696  
697 After that you can connect to multiple MonetDB database servers
698 and send multiple queries to any of them via a simple object oriented
699 interface. Two types of objects are available: database handles and
700 statement handles. Perl returns a database handle to the connect
701 method like so:
702  
703 $dbh = DBI->connect("dbi:monetdb:host=$host",
704 $user, $password, { RaiseError => 1 } );
705  
706 Once you have connected to a database, you can can execute SQL
707 statements with:
708  
709 my $sql = sprintf('INSERT INTO foo VALUES (%d, %s)',
710 $number, $dbh->quote('name'));
711 $dbh->do($sql);
712  
713 See L<DBI> for details on the quote and do methods. An alternative
714 approach is
715  
716 $dbh->do('INSERT INTO foo VALUES (?, ?)', undef, $number, $name);
717  
718 in which case the quote method is executed automatically. See also
719 the bind_param method in L<DBI>.
720  
721 If you want to retrieve results, you need to create a so-called
722 statement handle with:
723  
724 $sth = $dbh->prepare("SELECT id, name FROM $table");
725 $sth->execute;
726  
727 This statement handle can be used for multiple things. First of all
728 you can retreive a row of data:
729  
730 my $row = $sth->fetch;
731  
732 If your table has columns ID and NAME, then $row will be array ref with
733 index 0 and 1.
734  
735 =head2 Example
736  
737 #!/usr/bin/perl
738  
739 use strict;
740 use DBI;
741  
742 # Connect to the database.
743 my $dbh = DBI->connect('dbi:monetdb:host=localhost',
744 'joe', "joe's password", { RaiseError => 1 } );
745  
746 # Drop table 'foo'. This may fail, if 'foo' doesn't exist.
747 # Thus we put an eval around it.
748 eval { $dbh->do('DROP TABLE foo') };
749 print "Dropping foo failed: $@\n" if $@;
750  
751 # Create a new table 'foo'. This must not fail, thus we don't
752 # catch errors.
753 $dbh->do('CREATE TABLE foo (id INTEGER, name VARCHAR(20))');
754  
755 # INSERT some data into 'foo'. We are using $dbh->quote() for
756 # quoting the name.
757 $dbh->do('INSERT INTO foo VALUES (1, ' . $dbh->quote('Tim') . ')');
758  
759 # Same thing, but using placeholders
760 $dbh->do('INSERT INTO foo VALUES (?, ?)', undef, 2, 'Jochen');
761  
762 # Now retrieve data from the table.
763 my $sth = $dbh->prepare('SELECT id, name FROM foo');
764 $sth->execute;
765 while ( my $row = $sth->fetch ) {
766 print "Found a row: id = $row->[0], name = $row->[1]\n";
767 }
768  
769 # Disconnect from the database.
770 $dbh->disconnect;
771  
772 =head1 METHODS
773  
774 =head2 Driver Handle Methods
775  
776 =over
777  
778 =item B<connect>
779  
780 use DBI();
781  
782 $dsn = 'dbi:monetdb:';
783 $dsn = "dbi:monetdb:host=$host";
784 $dsn = "dbi:monetdb:host=$host;port=$port";
785  
786 $dbh = DBI->connect($dsn, $user, $password);
787  
788 =over
789  
790 =item host
791  
792 The default host to connect to is 'localhost', i.e. your workstation.
793  
794 =item port
795  
796 The port where MonetDB daemon listens to. Default for MonetDB is 50000.
797  
798 =back
799  
800 =back
801  
802 =head2 Database Handle Methods
803  
804 The following methods are currently not supported:
805  
806 last_insert_id
807  
808 All MetaData methods are supported. However, column_info() currently doesn't
809 provide length (size, ...) related information.
810 The foreign_key_info() method returns a SQL/CLI like result set,
811 because it provides additional information about unique keys.
812  
813 =head2 Statement Handle Methods
814  
815 The following methods are currently not supported:
816  
817 bind_param_inout
818 more_results
819 blob_read
820  
821 =head1 ATTRIBUTES
822  
823 The following attributes are currently not supported:
824  
825 LongReadLen
826 LongTruncOk
827  
828 =head2 Database Handle Attributes
829  
830 The following attributes are currently not supported:
831  
832 RowCacheSize
833  
834 =head2 Statement Handle Attributes
835  
836 The following attributes are currently not (or not correctly) supported:
837  
838 PRECISION (MonetDB semantic != DBI semantic)
839 SCALE (empty)
840 NULLABLE (SQL_NULLABLE_UNKNOWN = 2)
841 CursorName
842 RowsInCache
843  
844 =head1 AUTHORS
845  
846 Martin Kersten E<lt>Martin.Kersten@cwi.nlE<gt> implemented the initial Mapi
847 based version of the driver (F<monet.pm>).
848 Arjan Scherpenisse E<lt>acscherp@science.uva.nlE<gt> renamed this module to
849 F<monetdbPP.pm> and derived the new MapiLib based version (F<monetdb.pm>).
850 Current maintainer is Steffen Goeldner E<lt>sgoeldner@cpan.orgE<gt>.
851  
852 =head1 COPYRIGHT AND LICENCE
853  
854 The contents of this file are subject to the MonetDB Public License
855 Version 1.1 (the "License"); you may not use this file except in
856 compliance with the License. You may obtain a copy of the License at
857 http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html
858  
859 Software distributed under the License is distributed on an "AS IS"
860 basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
861 License for the specific language governing rights and limitations
862 under the License.
863  
864 The Original Code is the MonetDB Database System.
865  
866 The Initial Developer of the Original Code is CWI.
867 Portions created by CWI are Copyright (C) 1997-2006 CWI.
868 All Rights Reserved.
869  
870 Contributor(s): Steffen Goeldner.
871  
872 =head1 SEE ALSO
873  
874 =head2 MonetDB
875  
876 Homepage : http://monetdb.cwi.nl
877 SourceForge : http://sourceforge.net/projects/monetdb
878  
879 =head2 Perl modules
880  
881 L<DBI>, L<MonetDB::CLI>
882  
883 =cut
↑ Summary monetdb/GetInfo.pm »