Skip Menu |

This queue is for tickets about the DBD-SQLite CPAN distribution.

Report information
The Basics
Id: 20378
Status: resolved
Priority: 0/
Queue: DBD-SQLite

People
Owner: Nobody in particular
Requestors: dbdsqlite [...] mowsey.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.12
Fixed in: (no value)



Subject: Patch for named parameters
While sqlite3 (at least 3.3.6) allows named parameters, one gets an error using them with DBI-1.51 and DBD::SQLite-1.12. I have written a tiny patch to fix bind_param, but I do not know if more is required. Here is the unpatched example: test.pl: #!/usr/bin/perl use strict; use warnings; use DBI; my $dbh=DBI->connect('dbi:SQLite:dbname=temp.db','','',{AutoCommit=>0}); $dbh->do(q{DROP TABLE IF EXISTS temp}); $dbh->do(q{CREATE TABLE temp(a VARCHAR(9),b VARCHAR(9))}); my $sth=$dbh->prepare(q{INSERT INTO temp(a,b) VALUES(:a,:b)}); $sth->bind_param(':a','This is a'); $sth->bind_param(':b','This is b'); $sth->execute; $sth->finish; $dbh->commit; $dbh->disconnect; $ perl test.pl ; sqlite3 temp.db .dump Argument ":a" isn't numeric in subroutine entry at test.pl line 7. Argument ":b" isn't numeric in subroutine entry at test.pl line 7. Use of uninitialized value in subroutine entry at test.pl line 8. Use of uninitialized value in subroutine entry at test.pl line 8. BEGIN TRANSACTION; CREATE TABLE temp(a VARCHAR(9),b VARCHAR(9)); INSERT INTO "temp" VALUES(NULL, NULL); COMMIT; $ Here is the "better" output from the patched version: $ perl test.pl ; sqlite3 temp.db .dump BEGIN TRANSACTION; CREATE TABLE temp(a VARCHAR(9),b VARCHAR(9)); INSERT INTO "temp" VALUES('This is a', 'This is b'); COMMIT; $ Here is the patch (check if dbd_bind_ph is called with a noninteger "param" and if so use sqlite3_bind_parameter_index to convert it to a positional param): diff -r DBD-SQLite-1.12/dbdimp.c DBD-SQLite-1.12-namedparam/dbdimp.c 440a441,451 Show quoted text
> if(!SvIOK(param)) { > int len; char *paramstring; > paramstring = SvPV(param,len); > if(paramstring[len]==0 && strlen(paramstring)==len) { > pos = sqlite3_bind_parameter_index(imp_sth->stmt,
paramstring); Show quoted text
> if(pos==0) croak("Unknown named parameter"); > pos = 2*(pos-1); > } > else croak("<param> could not be coerced to a C string"); > } > else {
443a455 Show quoted text
> }
Applying, thanks.