Fix db_prefix handling in queries with `TRUNCATE TABLE <name>` and `UNIQUE <name>` (#7013)

pull/5989/merge
Aleksander Machniak 5 years ago
parent b8555ce4f3
commit a80d73602f

@ -7,6 +7,7 @@ CHANGELOG Roundcube Webmail
- Fix bug where cache keys could exceed length limit specified in db schema (#7004) - Fix bug where cache keys could exceed length limit specified in db schema (#7004)
- Fix invalid Signature button state after escaping Mailvelope mode (#7015) - Fix invalid Signature button state after escaping Mailvelope mode (#7015)
- Fix so 401 error is returned only on failed logon requests (#7010) - Fix so 401 error is returned only on failed logon requests (#7010)
- Fix db_prefix handling in queries with `TRUNCATE TABLE <name>` and `UNIQUE <name>` (#7013)
RELEASE 1.4.0 RELEASE 1.4.0
------------- -------------

@ -1369,8 +1369,8 @@ class rcube_db
} }
$sql = preg_replace_callback( $sql = preg_replace_callback(
'/((TABLE|TRUNCATE|(?<!ON )UPDATE|INSERT INTO|FROM' '/((TABLE|TRUNCATE( TABLE)?|(?<!ON )UPDATE|INSERT INTO|FROM'
. '| ON(?! (DELETE|UPDATE))|REFERENCES|CONSTRAINT|FOREIGN KEY|INDEX)' . '| ON(?! (DELETE|UPDATE))|REFERENCES|CONSTRAINT|FOREIGN KEY|INDEX|UNIQUE( INDEX)?)'
. '\s+(IF (NOT )?EXISTS )?[`"]*)([^`"\( \r\n]+)/', . '\s+(IF (NOT )?EXISTS )?[`"]*)([^`"\( \r\n]+)/',
array($this, 'fix_table_names_callback'), array($this, 'fix_table_names_callback'),
$sql $sql

@ -34,19 +34,28 @@ class Framework_DB extends PHPUnit_Framework_TestCase
"-- test comment", "-- test comment",
"ALTER TABLE `xxx` CHANGE test test int;", "ALTER TABLE `xxx` CHANGE test test int;",
"TRUNCATE xxx;", "TRUNCATE xxx;",
"TRUNCATE TABLE xxx;",
"DROP TABLE `vvv`;", "DROP TABLE `vvv`;",
"CREATE TABLE `i` (test int CONSTRAINT `iii` "CREATE TABLE `i` (test int CONSTRAINT `iii`
FOREIGN KEY (`test`) REFERENCES `xxx`(`test`) ON DELETE CASCADE ON UPDATE CASCADE);", FOREIGN KEY (`test`) REFERENCES `xxx`(`test`) ON DELETE CASCADE ON UPDATE CASCADE);",
"CREATE TABLE `i` (`test` int, INDEX `testidx` (`test`))",
"CREATE TABLE `i` (`test` int, UNIQUE `testidx` (`test`))",
"CREATE TABLE `i` (`test` int, UNIQUE INDEX `testidx` (`test`))",
"INSERT INTO xxx test = 1;", "INSERT INTO xxx test = 1;",
"SELECT test FROM xxx;", "SELECT test FROM xxx;",
)); ));
$output = implode("\n", array( $output = implode("\n", array(
"CREATE TABLE `prefix_xxx` (test int, INDEX prefix_xxx (test))", "CREATE TABLE `prefix_xxx` (test int, INDEX prefix_xxx (test))",
"ALTER TABLE `prefix_xxx` CHANGE test test int", "ALTER TABLE `prefix_xxx` CHANGE test test int",
"TRUNCATE prefix_xxx", "TRUNCATE prefix_xxx",
"TRUNCATE TABLE prefix_xxx",
"DROP TABLE `prefix_vvv`", "DROP TABLE `prefix_vvv`",
"CREATE TABLE `prefix_i` (test int CONSTRAINT `prefix_iii` "CREATE TABLE `prefix_i` (test int CONSTRAINT `prefix_iii`
FOREIGN KEY (`test`) REFERENCES `prefix_xxx`(`test`) ON DELETE CASCADE ON UPDATE CASCADE)", FOREIGN KEY (`test`) REFERENCES `prefix_xxx`(`test`) ON DELETE CASCADE ON UPDATE CASCADE)",
"CREATE TABLE `prefix_i` (`test` int, INDEX `prefix_testidx` (`test`))",
"CREATE TABLE `prefix_i` (`test` int, UNIQUE `prefix_testidx` (`test`))",
"CREATE TABLE `prefix_i` (`test` int, UNIQUE INDEX `prefix_testidx` (`test`))",
"INSERT INTO prefix_xxx test = 1", "INSERT INTO prefix_xxx test = 1",
"SELECT test FROM prefix_xxx", "SELECT test FROM prefix_xxx",
)); ));

Loading…
Cancel
Save