Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix some queries with columns beginning with limit would fail #349

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dbdimp.c
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,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 @@ -19,23 +19,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 @@ -49,6 +49,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