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

pull/7022/head
Aleksander Machniak 5 years ago
parent 29e7c16b33
commit 71990b59d6

@ -7,6 +7,7 @@ CHANGELOG Roundcube Webmail
- 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 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
-------------

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

@ -34,19 +34,28 @@ class Framework_DB extends PHPUnit_Framework_TestCase
"-- test comment",
"ALTER TABLE `xxx` CHANGE test test int;",
"TRUNCATE xxx;",
"TRUNCATE TABLE xxx;",
"DROP TABLE `vvv`;",
"CREATE TABLE `i` (test int CONSTRAINT `iii`
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;",
"SELECT test FROM xxx;",
));
$output = implode("\n", array(
"CREATE TABLE `prefix_xxx` (test int, INDEX prefix_xxx (test))",
"ALTER TABLE `prefix_xxx` CHANGE test test int",
"TRUNCATE prefix_xxx",
"TRUNCATE TABLE prefix_xxx",
"DROP TABLE `prefix_vvv`",
"CREATE TABLE `prefix_i` (test int CONSTRAINT `prefix_iii`
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",
"SELECT test FROM prefix_xxx",
));

Loading…
Cancel
Save