#!/usr/bin/perl use DBI; use Benchmark; my $table_name = 'food'; $| = 1; for my $i (0..20) { print "."; $dbh = DBI->connect('dbi:Pg:dbname=test', '', ''); #$dbh->do("DROP TABLE $table_name") if {map { $_ => 1 } $dbh->tables}->{$table_name}; #$dbh->do("CREATE TABLE $table_name (name varchar(10), cost int)"); my $tables = [$dbh->tables]; #print 'Tables: ' . pretty_list($tables); my $sth = $dbh->prepare("SELECT * FROM $table_name"); # $sth->execute; # my $fields = $sth->{NAME}; # my $sth1 = $dbh->prepare("INSERT INTO $table_name VALUES (?, ?)"); # print "SELECT * FROM $table_name:\n"; # print "fields: ", pretty_list($fields); # while (my $row = $sth->fetchrow_arrayref) { # print pretty_list($row); # } # $sth1->execute('asdf', 11); # $sth1->execute('cow', 12); # $sth1->finish; #$dbh->do("ALTER TABLE $table_name ADD (weight int)"); #$dbh->do("INSERT INTO $table_name VALUES (?, ?, ?)", {}, 'worms', undef, 10); $sth->execute; $fields = $sth->{NAME}; # print "SELECT * FROM $table_name:\n"; # print "fields: ", pretty_list($fields); my $rows = $sth->fetchall_arrayref; # for my $row (@$rows) { # print pretty_list($row); # } $sth->finish; $dbh->disconnect; } sub pretty_list { my $list = ref $_[0] ? shift : \@_; return "(" . (join ',', map { defined $_ ? $_ : 'NULL' } @$list) . ")\n"; }