-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathexample.pl
executable file
·42 lines (32 loc) · 1017 Bytes
/
example.pl
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
#!/usr/bin/perl
# A small script to test using the module
use strict;
use warnings;
use lib "lib";
use DBI;
use DBI::Log trace => 1, timing => 1;
use Data::Dumper;
END {
unlink "foo.db";
};
my $dbh = DBI->connect("dbi:SQLite:dbname=foo.db", "", "", {RaiseError => 1, PrintError => 0});
my $sth = $dbh->prepare("CREATE TABLE foo (a INT, b INT)");
$sth->execute();
$dbh->do("INSERT INTO foo VALUES (?, ?)", undef, 1, 2);
$dbh->do("INSERT INTO foo VALUES (?, ?)", undef, 3, 4);
$dbh->do("INSERT INTO foo VALUES (?, ?)", undef, 5, 6);
$dbh->selectcol_arrayref("SELECT * FROM foo");
# There is a bug where if a query dies it doesn't print the timing or the ending
# newline
eval {$dbh->do("INSERT INTO bar VALUES (?, ?)", undef, 1, 2)};
print "\n";
$dbh->selectall_hashref("SELECT * FROM foo", "a");
foo();
sub foo {
$sth = $dbh->prepare("SELECT * FROM foo WHERE a=?");
$sth->bind_param(1, 3);
$sth->execute();
while (my $row = $sth->fetchrow_hashref()) {
print Dumper($row);
}
}