in reply to Error while inserting null values with DBI
A couple of solutions.
1. Use placeholders:
If $id is undef then a correct NULL value will be passed to the data server (which from the error message would appear to be Sybase or MS-SQL).my $sth = $dbh->prepare("insert test(id, name) values(?, ?)"); $sth->execute($id, $name);
An alternative solution:
The latter solution is much inferior to the placeholder solution, and is incomplete and bug-prone (i.e. if $name is NULL instead of $id you need to handle this differently, not to mention quoting issues with strings...)$id = 'NULL' unless defined($id); $dbh->do("insert test(id, name) values($id, \"$name\")");
Michael
In Section
Seekers of Perl Wisdom