mirror of
https://github.com/DBD-SQLite/DBD-SQLite
synced 2025-06-08 14:48:32 -04:00
added placeholder explanation and its test
This commit is contained in:
parent
18254d2a82
commit
126b5e6dc4
2 changed files with 45 additions and 0 deletions
|
@ -748,6 +748,17 @@ This is somewhat weird, but works anyway.
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
|
=head2 Placeholders
|
||||||
|
|
||||||
|
SQLite supports several placeholder expressions, including C<?> and C<:AAAA>. Consult the L<DBI> and sqlite documentation for details.
|
||||||
|
|
||||||
|
L<http://www.sqlite.org/lang_expr.html#varparam>
|
||||||
|
|
||||||
|
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
|
=head2 Foreign Keys
|
||||||
|
|
||||||
B<BE PREPARED! WOLVES APPROACH!!>
|
B<BE PREPARED! WOLVES APPROACH!!>
|
||||||
|
|
34
t/41_placeholders.t
Normal file
34
t/41_placeholders.t
Normal file
|
@ -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;
|
||||||
|
|
Loading…
Add table
Reference in a new issue