Skip to content
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
7 changes: 4 additions & 3 deletions dbdimp.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,9 +604,9 @@ static char *parse_params(
/*
it would be good to be able to handle any number of cases and orders
*/
if ((*statement_ptr == 'l' || *statement_ptr == 'L') &&
(!strncmp(statement_ptr+1, "imit ", 5) ||
!strncmp(statement_ptr+1, "IMIT ", 5)))
if (((*statement_ptr == ' ') || (*statement_ptr == '\n') || (*statement_ptr == '\t')) &&
(!strncmp(statement_ptr+1, "limit ", 5) ||
!strncmp(statement_ptr+1, "LIMIT ", 5)))
{
limit_flag = 1;
}
Expand Down Expand Up @@ -780,6 +780,7 @@ static char *parse_params(

/* in case this is a nested LIMIT */
case ')':
case '=':
limit_flag = 0;
*ptr++ = *statement_ptr++;
break;
Expand Down
26 changes: 22 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 => 111;
plan tests => 115;

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))"), "creating table");
ok($dbh->do("CREATE TABLE dbd_mysql_t35 (id INT(4), name VARCHAR(64), name_limit 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)));
ok(($rows = $sth->execute($i, $random_chars, $random_chars)));
}

ok($sth = $dbh->prepare("SELECT * FROM dbd_mysql_t35 LIMIT ?, ?"),
Expand All @@ -51,6 +51,24 @@ ok(@$array_ref == 50);

ok($sth->finish);

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

ok($dbh->do("UPDATE dbd_mysql_t35 SET name = ? WHERE name_limit > ?", undef, "updated_string", 999999));

# newline before LIMIT
ok($dbh->do(<<'SQL'
UPDATE dbd_mysql_t35 SET name = ?
LIMIT ?
SQL
, undef, "updated_string", 0));

# tab before LIMIT
ok($dbh->do(<<'SQL'
UPDATE dbd_mysql_t35 SET name = ?
LIMIT ?
SQL
, undef, "updated_string", 0));

ok($dbh->do("DROP TABLE dbd_mysql_t35"));

ok($dbh->disconnect);