Skip to content

Commit

Permalink
Stop parsing a table named "limits" as the LIMIT keyword
Browse files Browse the repository at this point in the history
Fixes #205.
  • Loading branch information
choroba committed Jun 29, 2024
1 parent f907004 commit 118dea6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions dbdimp.c
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,8 @@ static char *parse_params(

/* in case this is a nested LIMIT */
case ')':
/* in case this is table named "limit" */
case '=':
limit_flag = FALSE;
*ptr++ = *statement_ptr++;
break;
Expand Down
22 changes: 21 additions & 1 deletion t/35limit.t
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require 'lib.pl';

my $dbh = DbiTestConnect($test_dsn, $test_user, $test_password,
{ RaiseError => 1, PrintError => 0, AutoCommit => 0 });
plan tests => 120;
plan tests => 124;

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

Expand Down Expand Up @@ -75,4 +75,24 @@ SQL

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

# Issue #205: A table named "limits" shouldn't be parsed as LIMIT.
my $limits = 500;
my $flag = 1;
my $id = 1;
$dbh->do('CREATE TABLE IF NOT EXISTS dbd_mysql_t35_1 ( id INT(10) PRIMARY KEY, lxmxts INT(10), flag ENUM("9","0","1") )');
$dbh->do('INSERT INTO dbd_mysql_t35_1 SET id=?, lxmxts=?, flag=?', undef, $id, $limits, $flag);
my ($set_flag1) = $dbh->selectrow_array('SELECT flag FROM dbd_mysql_t35_1 WHERE id=?', undef, $id);

is($set_flag1, $flag, 'flag set without limits involved');

ok($dbh->do('DROP TABLE dbd_mysql_t35_1'));

$dbh->do('CREATE TABLE IF NOT EXISTS dbd_mysql_t35_2 ( id INT(10) PRIMARY KEY, limits INT(10), flag ENUM("9","0","1") )');
$dbh->do('INSERT INTO dbd_mysql_t35_2 SET id=?, limits=?, flag=?', undef, $id, $limits, $flag);
my ($set_flag2) = $dbh->selectrow_array('SELECT flag FROM dbd_mysql_t35_2 WHERE id=?', undef, $id);

is($set_flag2, $flag, 'flag set with limits involved');

ok($dbh->do('DROP TABLE dbd_mysql_t35_2'));

ok($dbh->disconnect);

0 comments on commit 118dea6

Please sign in to comment.