summaryrefslogtreecommitdiff
path: root/modules/gallery
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2010-02-07 08:28:32 -0800
committerBharat Mediratta <bharat@menalto.com>2010-02-07 08:28:32 -0800
commitadac97b5372322be5154996974a6496198105d16 (patch)
tree5f06f49106066b9b31782910286313ff29b539a5 /modules/gallery
parent2c3c126aafaa4d7ed86075927887636042117a1c (diff)
Add prefix support for the target of RENAME TABLE.
Diffstat (limited to 'modules/gallery')
-rw-r--r--modules/gallery/libraries/MY_Database.php9
-rw-r--r--modules/gallery/tests/Database_Test.php7
2 files changed, 15 insertions, 1 deletions
diff --git a/modules/gallery/libraries/MY_Database.php b/modules/gallery/libraries/MY_Database.php
index e2ef68cd..cb70104a 100644
--- a/modules/gallery/libraries/MY_Database.php
+++ b/modules/gallery/libraries/MY_Database.php
@@ -54,11 +54,18 @@ abstract class Database extends Database_Core {
*/
return $sql;
} else if (strpos($sql, "CREATE TABLE") === 0) {
- // Creating a new table add it to the table cache.
+ // Creating a new table; add it to the table cache.
$open_brace = strpos($sql, "{") + 1;
$close_brace = strpos($sql, "}", $open_brace);
$name = substr($sql, $open_brace, $close_brace - $open_brace);
$this->_table_names["{{$name}}"] = "{$prefix}$name";
+ } else if (strpos($sql, "RENAME TABLE") === 0) {
+ // Renaming a table; add it to the table cache.
+ // You must use the form "TO {new_table_name}" exactly for this to work.
+ $open_brace = strpos($sql, "TO {") + 4;
+ $close_brace = strpos($sql, "}", $open_brace);
+ $name = substr($sql, $open_brace, $close_brace - $open_brace);
+ $this->_table_names["{{$name}}"] = "{$prefix}$name";
}
if (!isset($this->_table_names)) {
diff --git a/modules/gallery/tests/Database_Test.php b/modules/gallery/tests/Database_Test.php
index 861f7bba..730785e2 100644
--- a/modules/gallery/tests/Database_Test.php
+++ b/modules/gallery/tests/Database_Test.php
@@ -130,6 +130,13 @@ class Database_Test extends Gallery_Unit_Test_Case {
$this->assert_same($expected, $sql);
}
+ function prefix_replacement_for_rename_table_test() {
+ $db = Database::instance("mock");
+ $this->assert_same(
+ "RENAME TABLE g_test TO g_new_test",
+ $db->add_table_prefixes("RENAME TABLE {test} TO {new_test}"));
+ }
+
function prefix_no_replacement_test() {
$sql = db::build("mock")
->from("test_tables")