From 126b5e6dc4beb29e3e757fab713c618a329b1249 Mon Sep 17 00:00:00 2001 From: Kenichi Ishigaki Date: Thu, 11 Feb 2010 03:24:36 +0000 Subject: [PATCH] added placeholder explanation and its test --- lib/DBD/SQLite.pm | 11 +++++++++++ t/41_placeholders.t | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 t/41_placeholders.t diff --git a/lib/DBD/SQLite.pm b/lib/DBD/SQLite.pm index dec0c41..2dd332c 100644 --- a/lib/DBD/SQLite.pm +++ b/lib/DBD/SQLite.pm @@ -748,6 +748,17 @@ This is somewhat weird, but works anyway. =back +=head2 Placeholders + +SQLite supports several placeholder expressions, including C and C<:AAAA>. Consult the L and sqlite documentation for details. + +L + +Note that a question mark actually means a next unused (numbered) placeholder. You're advised not to use it with other (numbered or named) placeholders to avoid confusion. + + my $sth = $dbh->prepare('update TABLE set a=?1 where b=?2 and a IS NOT ?1'); + $sth->execute(1, 2); + =head2 Foreign Keys B diff --git a/t/41_placeholders.t b/t/41_placeholders.t new file mode 100644 index 0000000..a9a5116 --- /dev/null +++ b/t/41_placeholders.t @@ -0,0 +1,34 @@ +#!/usr/bin/perl + +use strict; +BEGIN { + $| = 1; + $^W = 1; +} + +use t::lib::Test qw/connect_ok/; +use Test::More; +use Test::NoWarnings; + +plan tests => 9; + +my $dbh = connect_ok( RaiseError => 1 ); +ok $dbh->do('create table foo (id integer, value integer)'); + +ok $dbh->do('insert into foo values(?, ?)', undef, 1, 2); +ok $dbh->do('insert into foo values(?1, ?2)', undef, 2, 3); +ok $dbh->do('insert into foo values(:1, :2)', undef, 3, 4); +ok $dbh->do('insert into foo values(@1, @2)', undef, 4, 4); + +ok $dbh->do( + 'update foo set id = $1 where value = $2 and id is not $1', + undef, 3, 4 +); + +my ($count) = $dbh->selectrow_array( + 'select count(id) from foo where id = ? and value = ?', + undef, 3, 4 +); + +ok $count == 2; +