insert NULL with bind_param gives uninitialized value warnings (DBD::SQLite)
al.danial_at_gmail.com
Date: 02/17/05
- Previous message: Jonathan Leffler: "Re: export to"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 16 Feb 2005 15:00:58 -0800
Is it possible to insert NULL values into a table via prepare()/
bind_param()/execute() without triggering runtime errors for
uninitialized
variables? I can do such inserts cleanly with
do("insert into XXX values (NULL)")
but prepare()/bind_param()/execute(), which I use to increase insert
performance, gives lots warnings whenever the value is a Perl undef.
If there is a limitation is it with DBD::SQLite, or with DBI itself?
Here's a small program to illustrate my point:
- - - - - \/ - - - - - \/ - - - - - \/ - - - - - \/ - - - - - \/
#!/usr/bin/perl
use strict;
use warnings;
use DBI qw (:sql_types) ;
use DBD::SQLite 1.00;
my $dbfile = "/tmp/a.db"; unlink $dbfile if -e $dbfile;
my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile","","");
$dbh->do("create table T( ID integer )");
$dbh->do("insert into T values (NULL)"); # this works, inserts NULL
my $st = $dbh->prepare("insert into T values(?)");
my $i = int(rand(50_000_000));
$st->bind_param( 1, $i, SQL_INTEGER);
$st->execute; # this works, inserts a random
int
$i = int(rand(50_000_000));
$st->bind_param( 1, $i, SQL_INTEGER);
$st->execute; # this works, inserts another
random int
# now insert a NULL
$i = undef;
$st->bind_param( 1, $i, SQL_INTEGER); # line A
$st->execute; # line B
# the three lines above will insert a NULL but Perl gives these
warnings
# on lines A and B:
# "Use of uninitialized value in subroutine entry"
$dbh->disconnect;
- Previous message: Jonathan Leffler: "Re: export to"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|