mirror of
https://github.com/DBD-SQLite/DBD-SQLite
synced 2025-06-07 14:19:10 -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
20
dbdimp.c
20
dbdimp.c
|
@ -392,9 +392,23 @@ sqlite_st_execute (SV *sth, imp_sth_t *imp_sth)
|
|||
retval = sqlite3_bind_blob(imp_sth->stmt, i+1, data, len, SQLITE_TRANSIENT);
|
||||
}
|
||||
else {
|
||||
STRLEN len;
|
||||
char * data = SvPV(value, len);
|
||||
retval = sqlite3_bind_text(imp_sth->stmt, i+1, data, len, SQLITE_TRANSIENT);
|
||||
/* 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 {
|
||||
STRLEN len;
|
||||
char * data = SvPV(value, len);
|
||||
retval = sqlite3_bind_text(imp_sth->stmt, i+1, data, len, SQLITE_TRANSIENT);
|
||||
}
|
||||
}
|
||||
|
||||
if (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