Skip to content

Commit

Permalink
fix some queries with columns beginning with limit would fail
Browse files Browse the repository at this point in the history
  • Loading branch information
kebhr authored and dveeden committed Sep 19, 2024
1 parent 684ffee commit bb15d9b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions dbdimp.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,8 @@ static char *parse_params(
it would be good to be able to handle any number of cases and orders
*/
if (((*statement_ptr == ' ') || (*statement_ptr == '\n') || (*statement_ptr == '\t')) &&
(!strncmp(statement_ptr+1, "limit ", 5) ||
!strncmp(statement_ptr+1, "LIMIT ", 5)))
(!strncmp(statement_ptr+1, "limit ", 6) ||
!strncmp(statement_ptr+1, "LIMIT ", 6)))
{
limit_flag = 1;
}
Expand Down
13 changes: 9 additions & 4 deletions t/35limit.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ eval {$dbh= DBI->connect($test_dsn, $test_user, $test_password,
if ($@) {
plan skip_all => "no database connection";
}
plan tests => 115;
plan tests => 117;

ok(defined $dbh, "Connected to database");

ok($dbh->do("DROP TABLE IF EXISTS dbd_mysql_t35"), "making slate clean");

ok($dbh->do("CREATE TABLE dbd_mysql_t35 (id INT(4), name VARCHAR(64), name_limit VARCHAR(64))"), "creating table");
ok($dbh->do("CREATE TABLE dbd_mysql_t35 (id INT(4), name VARCHAR(64), name_limit VARCHAR(64), limit_by VARCHAR(64))"), "creating table");

ok(($sth = $dbh->prepare("INSERT INTO dbd_mysql_t35 VALUES (?,?,?)")));
ok(($sth = $dbh->prepare("INSERT INTO dbd_mysql_t35 VALUES (?,?,?,?)")));

for my $i (0..99) {
my @chars = grep !/[0O1Iil]/, 0..9, 'A'..'Z', 'a'..'z';
my $random_chars = join '', map { $chars[rand @chars] } 0 .. 16;

# save these values for later testing
$testInsertVals->{$i} = $random_chars;
ok(($rows = $sth->execute($i, $random_chars, $random_chars)));
ok(($rows = $sth->execute($i, $random_chars, $random_chars, $random_chars)));
}

ok($sth = $dbh->prepare("SELECT * FROM dbd_mysql_t35 LIMIT ?, ?"),
Expand All @@ -53,6 +53,11 @@ ok( (defined($array_ref = $sth->fetchall_arrayref) &&

ok(@$array_ref == 50);

ok($sth = $dbh->prepare("SELECT * FROM dbd_mysql_t35 WHERE limit_by > ?"),
"testing prepare of select statement with started by 'limit' column");

ok($sth->execute("foobar"), 'testing exec of bind vars for placeholder');

ok($sth->finish);

ok($dbh->do("UPDATE dbd_mysql_t35 SET name_limit = ? WHERE id = ?", undef, "updated_string", 1));
Expand Down

0 comments on commit bb15d9b

Please sign in to comment.