mirror of
https://github.com/DBD-SQLite/DBD-SQLite
synced 2025-06-07 22:28:47 -04:00
DBD-SQLite: hopefully resolved RT #29058; don't quote (as text) when a bind param look like a number
This commit is contained in:
parent
e1650f962b
commit
14b5e9270b
2 changed files with 55 additions and 3 deletions
14
dbdimp.c
14
dbdimp.c
|
@ -391,11 +391,25 @@ sqlite_st_execute (SV *sth, imp_sth_t *imp_sth)
|
||||||
char * data = SvPV(value, len);
|
char * data = SvPV(value, len);
|
||||||
retval = sqlite3_bind_blob(imp_sth->stmt, i+1, data, len, SQLITE_TRANSIENT);
|
retval = sqlite3_bind_blob(imp_sth->stmt, i+1, data, len, SQLITE_TRANSIENT);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
/* guess a bit before binding */
|
||||||
|
const int numtype = looks_like_number(value);
|
||||||
|
if ((numtype & (IS_NUMBER_IN_UV|IS_NUMBER_NOT_INT)) == IS_NUMBER_IN_UV) {
|
||||||
|
#if defined(USE_64_BIT_INT)
|
||||||
|
retval = sqlite3_bind_int64(imp_sth->stmt, i+1, SvIV(value));
|
||||||
|
#else
|
||||||
|
retval = sqlite3_bind_int(imp_sth->stmt, i+1, SvIV(value));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else if ((numtype & (IS_NUMBER_NOT_INT|IS_NUMBER_INFINITY|IS_NUMBER_NAN)) == IS_NUMBER_NOT_INT) {
|
||||||
|
retval = sqlite3_bind_double(imp_sth->stmt, i+1, SvNV(value));
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
STRLEN len;
|
STRLEN len;
|
||||||
char * data = SvPV(value, len);
|
char * data = SvPV(value, len);
|
||||||
retval = sqlite3_bind_text(imp_sth->stmt, i+1, data, len, SQLITE_TRANSIENT);
|
retval = sqlite3_bind_text(imp_sth->stmt, i+1, data, len, SQLITE_TRANSIENT);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (value) {
|
if (value) {
|
||||||
SvREFCNT_dec(value);
|
SvREFCNT_dec(value);
|
||||||
|
|
38
t/rt_29058_group_by.t
Normal file
38
t/rt_29058_group_by.t
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
use strict;
|
||||||
|
|
||||||
|
BEGIN {
|
||||||
|
$| = 1;
|
||||||
|
$^W = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
use t::lib::Test;
|
||||||
|
|
||||||
|
use Test::More tests => 6;
|
||||||
|
use DBI;
|
||||||
|
|
||||||
|
my $dbh = connect_ok();
|
||||||
|
$dbh->do( 'CREATE TABLE foo (bar TEXT, num INT)' );
|
||||||
|
|
||||||
|
for (1..5) {
|
||||||
|
$dbh->do('INSERT INTO foo (bar, num) VALUES (?,?)', undef, ($_%2 ? "odd" : "even"), $_);
|
||||||
|
}
|
||||||
|
# DBI->trace(9);
|
||||||
|
|
||||||
|
# see if placeholder works
|
||||||
|
my ($v, $num) = $dbh->selectrow_array('SELECT bar, num FROM foo WHERE num = ?', undef, 3);
|
||||||
|
ok $v eq 'odd' && $num == 3;
|
||||||
|
|
||||||
|
# see if the sql itself works as expected
|
||||||
|
my $ar = $dbh->selectall_arrayref('SELECT bar FROM foo GROUP BY bar HAVING count(*) > 1');
|
||||||
|
ok
|
||||||
|
ok @$ar == 2;
|
||||||
|
|
||||||
|
# known workaround
|
||||||
|
# ref: http://code.google.com/p/gears/issues/detail?id=163
|
||||||
|
$ar = $dbh->selectall_arrayref('SELECT bar FROM foo GROUP BY bar HAVING count(*) > 0+?', undef, 1);
|
||||||
|
ok @$ar == 2;
|
||||||
|
|
||||||
|
# and this is what should be tested
|
||||||
|
$ar = $dbh->selectall_arrayref('SELECT bar FROM foo GROUP BY bar HAVING count(*) > ?', undef, 1);
|
||||||
|
print "4: @$_\n" for @$ar;
|
||||||
|
ok @$ar == 2, "we got ".(@$ar)." items";
|
Loading…
Add table
Reference in a new issue