diff options
author | admin <devnull@localhost> | 2006-10-02 05:21:46 +0200 |
---|---|---|
committer | admin <devnull@localhost> | 2006-10-02 05:21:46 +0200 |
commit | 3cad41e56fe4edc057cf6a84952a343686376429 (patch) | |
tree | f09f0ae669677a0c0a54d8f0d854cfda4ff5cf09 | |
parent | 78ce3cc370efc9d63b3d473deb37c92f40002d3d (diff) |
-rw-r--r-- | system/database/drivers/mssql/mssql_utility.php | 16 | ||||
-rw-r--r-- | system/database/drivers/mysqli/mysqli_utility.php | 131 | ||||
-rw-r--r-- | system/database/drivers/oci8/oci8_result.php | 6 | ||||
-rw-r--r-- | system/database/drivers/oci8/oci8_utility.php | 15 | ||||
-rw-r--r-- | system/database/drivers/odbc/odbc_utility.php | 14 | ||||
-rw-r--r-- | system/database/drivers/postgre/postgre_utility.php | 14 | ||||
-rw-r--r-- | system/database/drivers/sqlite/sqlite_utility.php | 14 | ||||
-rw-r--r-- | user_guide/helpers/download_helper.html | 2 |
8 files changed, 208 insertions, 4 deletions
diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index 388dbe1c2..129ba6861 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -109,6 +109,22 @@ class CI_DB_mssql_utility extends CI_DB_utility { return return FALSE; // Is this supported in MS SQL? } + // -------------------------------------------------------------------- + + /** + * MSSQL Export + * + * @access private + * @param array Preferences + * @return mixed + */ + function _backup($params = array()) + { + // Currently unsupported + return $this->db->display_error('db_unsuported_feature'); + } + + } ?>
\ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index a40441d20..17af40b76 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -108,6 +108,137 @@ class CI_DB_mysqli_utility extends CI_DB_utility { return "REPAIR TABLE ".$this->db->_escape_table($table); } + // -------------------------------------------------------------------- + + /** + * MySQLi Export + * + * @access private + * @param array Preferences + * @return mixed + */ + function _backup($params = array()) + { + if (count($params) == 0) + { + return FALSE; + } + + // Extract the prefs for simplicity + extract($params); + + // Build the output + $output = ''; + foreach ((array)$tables as $table) + { + // Is the table in the "ignore" list? + if (in_array($table, (array)$ignore, TRUE)) + { + continue; + } + + // Get the table schema + $query = $this->db->query("SHOW CREATE TABLE `".$this->db->database.'`.'.$table); + + // No result means the table name was invalid + if ($query === FALSE) + { + continue; + } + + // Write out the table schema + $output .= '#'.$newline.'# TABLE STRUCTURE FOR: '.$table.$newline.'#'.$newline.$newline; + + if ($add_drop == TRUE) + { + $output .= 'DROP TABLE IF EXISTS '.$table.';'.$newline.$newline; + } + + $i = 0; + $result = $query->result_array(); + foreach ($result[0] as $val) + { + if ($i++ % 2) + { + $output .= $val.';'.$newline.$newline; + } + } + + // If inserts are not needed we're done... + if ($add_insert == FALSE) + { + continue; + } + + // Grab all the data from the current table + $query = $this->db->query("SELECT * FROM $table"); + + if ($query->num_rows() == 0) + { + continue; + } + + // Fetch the field names and determine if the field is an + // integer type. We use this info to decide whether to + // surround the data with quotes or not + + $i = 0; + $field_str = ''; + $is_int = array(); + while ($field = mysqli_fetch_field($query->result_id)) + { + $is_int[$i] = (in_array( + strtolower(mysql_field_type($query->result_id, $i)), + array('tinyint', 'smallint', 'mediumint', 'int', 'bigint', 'timestamp'), + TRUE) + ) ? TRUE : FALSE; + + // Create a string of field names + $field_str .= $field->name.', '; + $i++; + } + + // Trim off the end comma + $field_str = preg_replace( "/, $/" , "" , $field_str); + + + // Build the insert string + foreach ($query->result_array() as $row) + { + $val_str = ''; + + $i = 0; + foreach ($row as $v) + { + // Do a little formatting... + $v = str_replace(array("\x00", "\x0a", "\x0d", "\x1a"), array('\0', '\n', '\r', '\Z'), $v); + $v = str_replace(array("\n", "\r", "\t"), array('\n', '\r', '\t'), $v); + $v = str_replace('\\', '\\\\', $v); + $v = str_replace('\'', '\\\'', $v); + $v = str_replace('\\\n', '\n', $v); + $v = str_replace('\\\r', '\r', $v); + $v = str_replace('\\\t', '\t', $v); + + // Escape the data if it's not an integer type + $val_str .= ($is_int[$i] == FALSE) ? $this->db->escape($v) : $v; + $val_str .= ', '; + + $i++; + } + + $val_str = preg_replace( "/, $/" , "" , $val_str); + + // Build the INSERT string + $output .= 'INSERT INTO '.$table.' ('.$field_str.') VALUES ('.$val_str.');'.$newline; + } + + $output .= $newline.$newline; + } + + return $output; + } + + } diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 59adda76b..30c023ddc 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -46,9 +46,9 @@ class CI_DB_oci8_result extends CI_DB_result { $rowcount = count($this->result_array); @ociexecute($this->stmt_id); if ($this->curs_id) - { - @ociexecute($this->curs_id); - } + { + @ociexecute($this->curs_id); + } return $rowcount; } diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index b1d539ad6..96be09506 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -109,6 +109,21 @@ class CI_DB_oci8_utility extends CI_DB_utility { return return FALSE; // Is this supported in Oracle? } + // -------------------------------------------------------------------- + + /** + * Oracle Export + * + * @access private + * @param array Preferences + * @return mixed + */ + function _backup($params = array()) + { + // Currently unsupported + return $this->db->display_error('db_unsuported_feature'); + } + } ?>
\ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index 5a0e365ef..dc62df9f0 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -141,6 +141,20 @@ class CI_DB_odbc_utility extends CI_DB_utility { return FALSE; } + // -------------------------------------------------------------------- + + /** + * ODBC Export + * + * @access private + * @param array Preferences + * @return mixed + */ + function _backup($params = array()) + { + // Currently unsupported + return $this->db->display_error('db_unsuported_feature'); + } } diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 038aa26cd..0c265de16 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -109,6 +109,20 @@ class CI_DB_postgre_utility extends CI_DB_utility { return return FALSE; } + // -------------------------------------------------------------------- + + /** + * Postgre Export + * + * @access private + * @param array Preferences + * @return mixed + */ + function _backup($params = array()) + { + // Currently unsupported + return $this->db->display_error('db_unsuported_feature'); + } } diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 19b06bd6d..9cb2cf027 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -134,6 +134,20 @@ class CI_DB_sqlite_utility extends CI_DB_utility { return return FALSE; } + // -------------------------------------------------------------------- + + /** + * SQLite Export + * + * @access private + * @param array Preferences + * @return mixed + */ + function _backup($params = array()) + { + // Currently unsupported + return $this->db->display_error('db_unsuported_feature'); + } } diff --git a/user_guide/helpers/download_helper.html b/user_guide/helpers/download_helper.html index f204d4280..f3f78dc5c 100644 --- a/user_guide/helpers/download_helper.html +++ b/user_guide/helpers/download_helper.html @@ -64,7 +64,7 @@ Download Helper <h1>Download Helper</h1>
-<p>The Download Helper file helps you download data to your desktop.</p>
+<p>The Download Helper lets you download data to your desktop.</p>
<h2>Loading this Helper</h2>
|