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
| Taisha:~/perl/forum $ perl -E '
use DBI;
my $dbh = DBI->connect("dbi:SQLite:dbname=:memory:","","");
$dbh->do(q{CREATE TABLE people (id INTEGER PRIMARY KEY, name VARCHAR(20))});
{
my $sth = $dbh->prepare("INSERT INTO people(id,name) VALUES (?,?)");
$sth->execute(0, "alice");
$sth->execute(1, "bob");
$sth->execute(3, undef);
$sth->execute(4, "dave");
}
{
my $sth = $dbh->prepare("SELECT id, name FROM people");
$sth->execute;
my @row;
while (@row = $sth->fetchrow_array) {
print "# (", scalar(@row), " colonnes) ",join(" ", @row),"\n";
for my $v (@row) {
print "[$v]\n";
}
}
}'
# (2 colonnes) 0 alice
[0]
[alice]
# (2 colonnes) 1 bob
[1]
[bob]
# (2 colonnes) 3
[3]
[]
# (2 colonnes) 4 dave
[4]
[dave]
Taisha:~/perl/forum $ |
Partager