From 79494dde1c53b671f279e5c5fab2ae03a9ff0353 Mon Sep 17 00:00:00 2001 From: Andrew Podner Date: Wed, 19 Dec 2012 14:15:41 -0500 Subject: Resolves issue #2081 : provides an option to include statements to disable and re-enable foreign key checks in a MySQL database backup output statement. --- system/database/DB_utility.php | 3 ++- system/database/drivers/mysql/mysql_utility.php | 13 +++++++++++++ system/database/drivers/mysqli/mysqli_utility.php | 13 +++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index c4140aef3..3ed75967e 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -326,7 +326,8 @@ abstract class CI_DB_utility { 'format' => 'gzip', // gzip, zip, txt 'add_drop' => TRUE, 'add_insert' => TRUE, - 'newline' => "\n" + 'newline' => "\n", + 'fk_checks' => TRUE ); // Did the user submit any preferences? If so set them.... diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 8aa051755..e2de82d0b 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -76,6 +76,13 @@ class CI_DB_mysql_utility extends CI_DB_utility { // Build the output $output = ''; + + // Do we need to include a statement to disable FK checks? + if ($fk_checks === FALSE) + { + $output .= "SET foreign_key_checks = 0;".$newline; + } + foreach ( (array) $tables as $table) { // Is the table in the "ignore" list? @@ -181,6 +188,12 @@ class CI_DB_mysql_utility extends CI_DB_utility { $output .= $newline.$newline; } + // Do we need to include a statement to re-enable FK checks? + if ($fk_checks === FALSE) + { + $output .= "SET foreign_key_checks = 1;".$newline; + } + return $output; } diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 345691e84..ff4949046 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -76,6 +76,13 @@ class CI_DB_mysqli_utility extends CI_DB_utility { // Build the output $output = ''; + + // Do we need to include a statement to disable FK checks? + if ($fk_checks === FALSE) + { + $output .= "SET foreign_key_checks = 0;".$newline; + } + foreach ( (array) $tables as $table) { // Is the table in the "ignore" list? @@ -181,6 +188,12 @@ class CI_DB_mysqli_utility extends CI_DB_utility { $output .= $newline.$newline; } + // Do we need to include a statement to re-enable FK checks? + if ($fk_checks === FALSE) + { + $output .= "SET foreign_key_checks = 1;".$newline; + } + return $output; } -- cgit v1.2.3-24-g4f1b From 4851217a1330580ebf73f0a6fb79ad451b73759a Mon Sep 17 00:00:00 2001 From: Andrew Podner Date: Thu, 20 Dec 2012 07:56:19 -0500 Subject: fixes #2081 : change parameter/variable name to 'foreign_key_checks', update change log Signed-off-by:Andrew Podner --- system/database/DB_utility.php | 16 ++++++++-------- system/database/drivers/mysql/mysql_utility.php | 8 ++++---- system/database/drivers/mysqli/mysqli_utility.php | 8 ++++---- 3 files changed, 16 insertions(+), 16 deletions(-) (limited to 'system') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 3ed75967e..aff3cf8c2 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -320,14 +320,14 @@ abstract class CI_DB_utility { // Set up our default preferences $prefs = array( - 'tables' => array(), - 'ignore' => array(), - 'filename' => '', - 'format' => 'gzip', // gzip, zip, txt - 'add_drop' => TRUE, - 'add_insert' => TRUE, - 'newline' => "\n", - 'fk_checks' => TRUE + 'tables' => array(), + 'ignore' => array(), + 'filename' => '', + 'format' => 'gzip', // gzip, zip, txt + 'add_drop' => TRUE, + 'add_insert' => TRUE, + 'newline' => "\n", + 'foreign_key_checks' => TRUE ); // Did the user submit any preferences? If so set them.... diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index e2de82d0b..f118033dc 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -77,8 +77,8 @@ class CI_DB_mysql_utility extends CI_DB_utility { // Build the output $output = ''; - // Do we need to include a statement to disable FK checks? - if ($fk_checks === FALSE) + // Do we need to include a statement to disable foreign key checks? + if ($foreign_key_checks === FALSE) { $output .= "SET foreign_key_checks = 0;".$newline; } @@ -188,8 +188,8 @@ class CI_DB_mysql_utility extends CI_DB_utility { $output .= $newline.$newline; } - // Do we need to include a statement to re-enable FK checks? - if ($fk_checks === FALSE) + // Do we need to include a statement to re-enable foreign key checks? + if ($foreign_key_checks === FALSE) { $output .= "SET foreign_key_checks = 1;".$newline; } diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index ff4949046..2edf38cf5 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -77,8 +77,8 @@ class CI_DB_mysqli_utility extends CI_DB_utility { // Build the output $output = ''; - // Do we need to include a statement to disable FK checks? - if ($fk_checks === FALSE) + // Do we need to include a statement to disable foreign key checks? + if ($foreign_key_checks === FALSE) { $output .= "SET foreign_key_checks = 0;".$newline; } @@ -188,8 +188,8 @@ class CI_DB_mysqli_utility extends CI_DB_utility { $output .= $newline.$newline; } - // Do we need to include a statement to re-enable FK checks? - if ($fk_checks === FALSE) + // Do we need to include a statement to re-enable foreign key checks? + if ($foreign_key_checks === FALSE) { $output .= "SET foreign_key_checks = 1;".$newline; } -- cgit v1.2.3-24-g4f1b