From 63f620481913cac1069062561c0eb46649219e42 Mon Sep 17 00:00:00 2001 From: "E. Choroba" Date: Fri, 28 Jun 2024 12:24:27 -0700 Subject: [PATCH] Stop parsing a table named "limits" as the LIMIT keyword Fixes #205. --- dbdimp.c | 2 ++ t/35limit.t | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/dbdimp.c b/dbdimp.c index 6104405d..869a4d21 100644 --- a/dbdimp.c +++ b/dbdimp.c @@ -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; diff --git a/t/35limit.t b/t/35limit.t index 35429049..4a833e79 100644 --- a/t/35limit.t +++ b/t/35limit.t @@ -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"); @@ -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);