From 653ca4f697dadcd75401e86a892ca771d677b697 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Tue, 30 Sep 2025 22:27:36 +0900 Subject: [PATCH] Add "TABLE" to list of keywords to recognize in addPrefixes() --- common/framework/DB.php | 6 +++--- tests/unit/framework/DBTest.php | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/common/framework/DB.php b/common/framework/DB.php index b436ce9e8..0f30246e8 100644 --- a/common/framework/DB.php +++ b/common/framework/DB.php @@ -1126,17 +1126,17 @@ class DB } else { - $exceptions = []; + $exceptions = ['TABLE']; } // Add prefixes to all other table names in the query string. - return preg_replace_callback('/\b((?:DELETE\s+)?FROM|JOIN|INTO|(?assertEquals($target, $oDB->addPrefixes($source)); + $source = "LOAD DATA LOCAL INFILE '/tmp/foo.csv' INTO TABLE foo_table FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' (a, b, c)"; + $target = "LOAD DATA LOCAL INFILE '/tmp/foo.csv' INTO TABLE `" . $prefix . "foo_table` FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' (a, b, c)"; + $this->assertEquals($target, $oDB->addPrefixes($source)); + + $source = 'ALTER TABLE documents ADD INDEX idx_foo (a, b)'; + $target = 'ALTER TABLE `' . $prefix . 'documents` ADD INDEX idx_foo (a, b)'; + $this->assertEquals($target, $oDB->addPrefixes($source)); + + $source = 'TRUNCATE TABLE documents'; + $target = 'TRUNCATE TABLE `' . $prefix . 'documents`'; + $this->assertEquals($target, $oDB->addPrefixes($source)); + + $source = 'DROP TABLE documents'; + $target = 'DROP TABLE `' . $prefix . 'documents`'; + $this->assertEquals($target, $oDB->addPrefixes($source)); + $source = 'update documents set a = ?, b = ? where c = ?'; $this->assertEquals($source, $oDB->addPrefixes($source));