- or download this
for (@values) {
my $affected =
$dbh->do(qq{INSERT INTO $table (col1, col2) VALUES (?, ?)},
undef, @$_);
}
- or download this
my $sth = $dbh->prepare(qq{INSERT INTO $table (col1, col2) VALUES (?,
+?)});
for (@values) {
# do something with the values
my $affected = $sth->execute (@$_);
}
- or download this
my $query = qq{INSERT INTO $table (column1, column2) VALUES };
my @values = (['a','b','c'],
...
.')';
}
my $affected = $dbh->do($query);
- or download this
$sth->execute; # dataset has 1,000,000 records
#
...
# do something with $aref
# $aref now contains (at most) 5,000 rows
};
- or download this
my $rowcache;
while (my $aref = shift(@$rowcache)
...
# do something with $aref
# $aref now contains only one row
};
- or download this
#!/usr/bin/perl -w
# create a MySQL test database
...
$inserted += $dbh->do($query) if $count;
print "inserted $inserted records\n";
$dbh->disconnect;
- or download this
#!/usr/bin/perl -w
# create a SQLite test database
...
print "inserted $inserted records\n";
$dbh->disconnect;
- or download this
#!/usr/bin/perl -w
# test_profile.pl
...
$sth->execute();
print "@$_" while $_ = $sth->fetchrow_arrayref();
$dbh->disconnect();
- or download this
c:\path> set DBI_PROFILE=2
c:\path> perl test_profile.pl
- or download this
$ DBI_PROFILE=2 perl test_profile.pl
- or download this
DBI::Profile: 0.002769 seconds 1.09% (16 method calls) test_profile.pl
'' =>
0.002072s / 10 = 0.000207s avg (first 0.000007s, min 0.000003s, ma
+x 0.001857s)
'select count(*) from testdbi' =>
0.000697s / 6 = 0.000116s avg (first 0.000119s, min 0.000010s, max
+ 0.000511s)
- or download this
DBI::Profile: 0.002569 seconds 0.46% (16 method calls) test_profile.pl
'DESTROY' =>
...
0.000041s / 2 = 0.000021s avg (first 0.000028s, min 0.000013s, max
+ 0.000028s)
'prepare' =>
0.000121s
- or download this
$ DBI_PROFILE=4/DBI::ProfileDumper perl test_profile.pl
$ dbiprof -match key1=fetchrow_arrayref
...
Shortest Time : 0.000013 seconds
Average Time : 0.000021 seconds
Key 1 : fetchrow_arrayref
- or download this
$ perldoc DBI::ProfileDumper
$ perldoc dbiprof
- or download this
$dbh->{Profile} = 4;
$sth->{Profile} = 6;
- or download this
DBI::Profile: 0.000444 seconds (3 method calls) test_profile.pl
'DESTROY' =>
...
0.000384s
'DBD::mysql::st::fetchrow_arrayref' =>
0.000041s / 2 = 0.000021s avg (first 0.000027s, min 0.000014s, max
+ 0.000027s)
- or download this
$dbh->{Profile} = 0;
$sth->{Profile} = 0;
- or download this
# create a DBI::Profile object. Notice that the object
# is an attribute of $sth, not a standalone entity.
...
# at DESTROY time
$sth->{Profile} =0;
}
- or download this
perldoc DBI::Profile
- or download this
#!/usr/bin/perl -w
use strict;
...
profile_calls($sth20, 20, $max_rows);
$dbh->disconnect;
- or download this
#
# NB. Output edited and trimmed to fit the screen
...
'fetchrow_array' => 0.758613s / 100001 = 0.000008s avg
'fetchrow_arrayref' => 0.690056s / 100001 = 0.000007s avg
'fetchrow_hashref' => 4.451645s / 100001 = 0.000045s avg