-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsqlite-test.pl
More file actions
47 lines (40 loc) · 1.07 KB
/
sqlite-test.pl
File metadata and controls
47 lines (40 loc) · 1.07 KB
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
use SQLite3;
my $dbh = sqlite_open('test.db');
my $sth = $dbh.prepare('CREATE TABLE foo (item,count)');
$sth.step();
$sth.finalize();
$sth = $dbh.prepare("insert into foo values('o hai',5)");
my $result = $sth.step();
say "step: $result";
$sth.finalize();
say '';
$sth = $dbh.prepare("insert into foo values('lol',?)");
$result = $sth.bind(1,137);
say "bind: $result";
$result = $sth.step();
say "step: $result";
$sth.finalize();
say '';
## XXX bind_text doesn't work.
# $sth = $dbh.prepare("insert into foo values(?,200)");
# $result = $sth.bind(1,"lol",3,0);
# say "bind: $result";
# $result = $sth.step();
# say "step: $result";
# $sth.finalize();
# say '';
$sth = $dbh.prepare("select * from foo");
while $sth.step() == 100 {
my $numcols = $sth.column_count();
say "fetching a row of $numcols columns";
for 0..^$numcols {
my $name = $sth.column_name($_);
# We should use column_type to find out which function to use to fetch
my $val = $sth.column_text($_);
say " $name: $val";
}
}
$sth.finalize();
say '';
$dbh.close();
say 'done';