diff options
author | Dan Ungureanu <udan1107@gmail.com> | 2015-07-11 00:42:16 +0300 |
---|---|---|
committer | Dan Ungureanu <udan1107@gmail.com> | 2015-07-11 00:42:16 +0300 |
commit | 5fa3bdf0d107d9892020f94124d2ae81e247d559 (patch) | |
tree | 41c36d5551f96d730fd8cf63f763024d4abb3c42 | |
parent | 617f807c57a97cd5c89e64fd3df769fd43ae4445 (diff) |
Restore SQL mode after export with certain configuration has finished.
Signed-off-by: Dan Ungureanu <udan1107@gmail.com>
-rw-r--r-- | libraries/plugins/export/ExportSql.class.php | 9 | ||||
-rw-r--r-- | test/classes/plugin/export/PMA_ExportSql_test.php | 23 |
2 files changed, 24 insertions, 8 deletions
diff --git a/libraries/plugins/export/ExportSql.class.php b/libraries/plugins/export/ExportSql.class.php index 0ce177ee89..1ce3921da0 100644 --- a/libraries/plugins/export/ExportSql.class.php +++ b/libraries/plugins/export/ExportSql.class.php @@ -1392,6 +1392,9 @@ class ExportSql extends ExportPlugin return $this->_exportComment(__('in use') . '(' . $tmp_error . ')'); } + // Old mode is stored so it can be restored once exporting is done. + $old_mode = SqlParser\Context::$MODE; + $warning = ''; if ($result != false && ($row = $GLOBALS['dbi']->fetchRow($result))) { $create_query = $row[1]; @@ -1535,7 +1538,7 @@ class ExportSql extends ExportPlugin unset($statement->fields[$key]); } - // Creating the parts that drop froeign keys. + // Creating the parts that drop foreign keys. if (!empty($field->key)) { if ($field->key->type === 'FOREIGN KEY') { $dropped[] = 'FOREIGN KEY ' . SqlParser\Context::escape($field->name); @@ -1637,6 +1640,10 @@ class ExportSql extends ExportPlugin } $GLOBALS['dbi']->freeResult($result); + + // Restoring old mode. + SqlParser\Context::$MODE = $old_mode; + return $warning . $schema_create . ($add_semicolon ? ';' . $crlf : ''); } // end of the 'getTableDef()' function diff --git a/test/classes/plugin/export/PMA_ExportSql_test.php b/test/classes/plugin/export/PMA_ExportSql_test.php index 1b724c0e22..ab0f02190f 100644 --- a/test/classes/plugin/export/PMA_ExportSql_test.php +++ b/test/classes/plugin/export/PMA_ExportSql_test.php @@ -1222,12 +1222,21 @@ class PMA_ExportSql_Test extends PHPUnit_Framework_TestCase $row = array( '', "CREATE TABLE `table` (\n" . - "`id` INT NOT NULL AUTO_INCREMENT,\n" . - "username VARCHAR(64) NULL,\n" . - "`password` VARCHAR(256) DEFAULT '123456',\n" . - "CONSTRAINT pk_id PRIMARY KEY (`id`),\n" . - "UNIQUE (username)\n" . - ")" + "`payment_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,\n" . + "`customer_id` smallint(5) unsigned NOT NULL,\n" . + "`staff_id` tinyint(3) unsigned NOT NULL,\n" . + "`rental_id` int(11) DEFAULT NULL,\n" . + "`amount` decimal(5,2) NOT NULL,\n" . + "`payment_date` datetime NOT NULL,\n" . + "`last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n" . + "PRIMARY KEY (`payment_id`),\n" . + "KEY `idx_fk_staff_id` (`staff_id`),\n" . + "KEY `idx_fk_customer_id` (`customer_id`),\n" . + "KEY `fk_payment_rental` (`rental_id`),\n" . + "CONSTRAINT `fk_payment_customer` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`customer_id`) ON UPDATE CASCADE,\n" . + "CONSTRAINT `fk_payment_rental` FOREIGN KEY (`rental_id`) REFERENCES `rental` (`rental_id`) ON DELETE SET NULL ON UPDATE CASCADE,\n" . + "CONSTRAINT `fk_payment_staff` FOREIGN KEY (`staff_id`) REFERENCES `staff` (`staff_id`) ON UPDATE CASCADE\n" . + ") ENGINE=InnoDB AUTO_INCREMENT=16050 DEFAULT CHARSET=utf8\n" ); $dbi->expects($this->once()) @@ -1298,7 +1307,7 @@ class PMA_ExportSql_Test extends PHPUnit_Framework_TestCase ); $this->assertContains( - 'ALTER TABLE "db"."table"' . "\n", + 'ALTER TABLE "table"', $GLOBALS['sql_drop_foreign_keys'] ); |