summaryrefslogtreecommitdiffstats
path: root/system/database/drivers/mysql
diff options
context:
space:
mode:
authorBarry Mieny <barry@mieny.com>2010-10-04 16:33:58 +0200
committerBarry Mieny <barry@mieny.com>2010-10-04 16:33:58 +0200
commitdd6719738936be31cdaa1758ca86d5eb14dcab3d (patch)
treeb5ef66e31b2d0f4f2c1cbccc367bde92c156e1f9 /system/database/drivers/mysql
parent3351fbc56cea19ec3dd603836beb0a420b1ded65 (diff)
Cleanup of stray spaces and tabs
Diffstat (limited to 'system/database/drivers/mysql')
-rw-r--r--system/database/drivers/mysql/mysql_driver.php144
-rw-r--r--system/database/drivers/mysql/mysql_forge.php30
-rw-r--r--system/database/drivers/mysql/mysql_result.php24
-rw-r--r--system/database/drivers/mysql/mysql_utility.php46
4 files changed, 122 insertions, 122 deletions
diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php
index d684c8a49..cb985a764 100644
--- a/system/database/drivers/mysql/mysql_driver.php
+++ b/system/database/drivers/mysql/mysql_driver.php
@@ -43,9 +43,9 @@ class CI_DB_mysql_driver extends CI_DB {
* Whether to use the MySQL "delete hack" which allows the number
* of affected rows to be shown. Uses a preg_replace when enabled,
* adding a bit more processing to all queries.
- */
+ */
var $delete_hack = TRUE;
-
+
/**
* The syntax to count rows is slightly different across different
* database engines, so this string appears in each driver and is
@@ -59,17 +59,17 @@ class CI_DB_mysql_driver extends CI_DB {
*
* @access private called by the base class
* @return resource
- */
+ */
function db_connect()
{
if ($this->port != '')
{
$this->hostname .= ':'.$this->port;
}
-
+
return @mysql_connect($this->hostname, $this->username, $this->password, TRUE);
}
-
+
// --------------------------------------------------------------------
/**
@@ -77,7 +77,7 @@ class CI_DB_mysql_driver extends CI_DB {
*
* @access private called by the base class
* @return resource
- */
+ */
function db_pconnect()
{
if ($this->port != '')
@@ -87,7 +87,7 @@ class CI_DB_mysql_driver extends CI_DB {
return @mysql_pconnect($this->hostname, $this->username, $this->password);
}
-
+
// --------------------------------------------------------------------
/**
@@ -108,13 +108,13 @@ class CI_DB_mysql_driver extends CI_DB {
}
// --------------------------------------------------------------------
-
+
/**
* Select the database
*
* @access private called by the base class
* @return resource
- */
+ */
function db_select()
{
return @mysql_select_db($this->database, $this->conn_id);
@@ -136,7 +136,7 @@ class CI_DB_mysql_driver extends CI_DB {
}
// --------------------------------------------------------------------
-
+
/**
* Version number query string
*
@@ -156,13 +156,13 @@ class CI_DB_mysql_driver extends CI_DB {
* @access private called by the base class
* @param string an SQL query
* @return resource
- */
+ */
function _execute($sql)
{
$sql = $this->_prep_query($sql);
return @mysql_query($sql, $this->conn_id);
}
-
+
// --------------------------------------------------------------------
/**
@@ -173,7 +173,7 @@ class CI_DB_mysql_driver extends CI_DB {
* @access private called by execute()
* @param string an SQL query
* @return string
- */
+ */
function _prep_query($sql)
{
// "DELETE FROM TABLE" returns 0 affected rows This hack modifies
@@ -185,7 +185,7 @@ class CI_DB_mysql_driver extends CI_DB {
$sql = preg_replace("/^\s*DELETE\s+FROM\s+(\S+)\s*$/", "DELETE FROM \\1 WHERE 1=1", $sql);
}
}
-
+
return $sql;
}
@@ -195,15 +195,15 @@ class CI_DB_mysql_driver extends CI_DB {
* Begin Transaction
*
* @access public
- * @return bool
- */
+ * @return bool
+ */
function trans_begin($test_mode = FALSE)
{
if ( ! $this->trans_enabled)
{
return TRUE;
}
-
+
// When transactions are nested we only begin/commit/rollback the outermost ones
if ($this->_trans_depth > 0)
{
@@ -214,7 +214,7 @@ class CI_DB_mysql_driver extends CI_DB {
// If the $test_mode flag is set to TRUE transactions will be rolled back
// even if the queries produce a successful result.
$this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
-
+
$this->simple_query('SET AUTOCOMMIT=0');
$this->simple_query('START TRANSACTION'); // can also be BEGIN or BEGIN WORK
return TRUE;
@@ -226,8 +226,8 @@ class CI_DB_mysql_driver extends CI_DB {
* Commit Transaction
*
* @access public
- * @return bool
- */
+ * @return bool
+ */
function trans_commit()
{
if ( ! $this->trans_enabled)
@@ -252,8 +252,8 @@ class CI_DB_mysql_driver extends CI_DB {
* Rollback Transaction
*
* @access public
- * @return bool
- */
+ * @return bool
+ */
function trans_rollback()
{
if ( ! $this->trans_enabled)
@@ -271,7 +271,7 @@ class CI_DB_mysql_driver extends CI_DB {
$this->simple_query('SET AUTOCOMMIT=1');
return TRUE;
}
-
+
// --------------------------------------------------------------------
/**
@@ -282,17 +282,17 @@ class CI_DB_mysql_driver extends CI_DB {
* @param bool whether or not the string will be used in a LIKE condition
* @return string
*/
- function escape_str($str, $like = FALSE)
- {
+ function escape_str($str, $like = FALSE)
+ {
if (is_array($str))
{
foreach($str as $key => $val)
- {
+ {
$str[$key] = $this->escape_str($val, $like);
- }
-
- return $str;
- }
+ }
+
+ return $str;
+ }
if (function_exists('mysql_real_escape_string') AND is_resource($this->conn_id))
{
@@ -306,16 +306,16 @@ class CI_DB_mysql_driver extends CI_DB {
{
$str = addslashes($str);
}
-
+
// escape LIKE condition wildcards
if ($like === TRUE)
{
$str = str_replace(array('%', '_'), array('\\%', '\\_'), $str);
}
-
+
return $str;
}
-
+
// --------------------------------------------------------------------
/**
@@ -328,7 +328,7 @@ class CI_DB_mysql_driver extends CI_DB {
{
return @mysql_affected_rows($this->conn_id);
}
-
+
// --------------------------------------------------------------------
/**
@@ -360,7 +360,7 @@ class CI_DB_mysql_driver extends CI_DB {
{
return 0;
}
-
+
$query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE));
if ($query->num_rows() == 0)
@@ -385,7 +385,7 @@ class CI_DB_mysql_driver extends CI_DB {
*/
function _list_tables($prefix_limit = FALSE)
{
- $sql = "SHOW TABLES FROM ".$this->_escape_char.$this->database.$this->_escape_char;
+ $sql = "SHOW TABLES FROM ".$this->_escape_char.$this->database.$this->_escape_char;
if ($prefix_limit !== FALSE AND $this->dbprefix != '')
{
@@ -394,7 +394,7 @@ class CI_DB_mysql_driver extends CI_DB {
return $sql;
}
-
+
// --------------------------------------------------------------------
/**
@@ -439,7 +439,7 @@ class CI_DB_mysql_driver extends CI_DB {
{
return mysql_error($this->conn_id);
}
-
+
// --------------------------------------------------------------------
/**
@@ -475,26 +475,26 @@ class CI_DB_mysql_driver extends CI_DB {
{
if (strpos($item, '.'.$id) !== FALSE)
{
- $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);
-
+ $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);
+
// remove duplicates if the user already included the escape
return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
- }
+ }
}
-
+
if (strpos($item, '.') !== FALSE)
{
- $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
+ $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
}
else
{
$str = $this->_escape_char.$item.$this->_escape_char;
}
-
+
// remove duplicates if the user already included the escape
return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
}
-
+
// --------------------------------------------------------------------
/**
@@ -513,12 +513,12 @@ class CI_DB_mysql_driver extends CI_DB {
{
$tables = array($tables);
}
-
+
return '('.implode(', ', $tables).')';
}
// --------------------------------------------------------------------
-
+
/**
* Insert statement
*
@@ -531,13 +531,13 @@ class CI_DB_mysql_driver extends CI_DB {
* @return string
*/
function _insert($table, $keys, $values)
- {
+ {
return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
}
-
+
// --------------------------------------------------------------------
-
+
/**
* Replace statement
*
@@ -550,10 +550,10 @@ class CI_DB_mysql_driver extends CI_DB {
* @return string
*/
function _replace($table, $keys, $values)
- {
+ {
return "REPLACE INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
}
-
+
// --------------------------------------------------------------------
/**
@@ -568,10 +568,10 @@ class CI_DB_mysql_driver extends CI_DB {
* @return string
*/
function _insert_batch($table, $keys, $values)
- {
+ {
return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values);
}
-
+
// --------------------------------------------------------------------
@@ -594,17 +594,17 @@ class CI_DB_mysql_driver extends CI_DB {
{
$valstr[] = $key." = ".$val;
}
-
+
$limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
-
+
$orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
-
+
$sql = "UPDATE ".$table." SET ".implode(', ', $valstr);
$sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
$sql .= $orderby.$limit;
-
+
return $sql;
}
@@ -630,16 +630,16 @@ class CI_DB_mysql_driver extends CI_DB {
foreach($values as $key => $val)
{
$ids[] = $val[$index];
-
+
foreach(array_keys($val) as $field)
- {
+ {
if ($field != $index)
{
$final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field];
}
}
}
-
+
$sql = "UPDATE ".$table." SET ";
$cases = '';
@@ -650,14 +650,14 @@ class CI_DB_mysql_driver extends CI_DB {
{
$cases .= $row."\n";
}
-
+
$cases .= 'ELSE '.$k.' END, ';
}
-
+
$sql .= substr($cases, 0, -2);
-
+
$sql .= ' WHERE '.$where.$index.' IN ('.implode(',', $ids).')';
-
+
return $sql;
}
@@ -674,12 +674,12 @@ class CI_DB_mysql_driver extends CI_DB {
* @access public
* @param string the table name
* @return string
- */
+ */
function _truncate($table)
{
return "TRUNCATE ".$table;
}
-
+
// --------------------------------------------------------------------
/**
@@ -692,7 +692,7 @@ class CI_DB_mysql_driver extends CI_DB {
* @param array the where clause
* @param string the limit clause
* @return string
- */
+ */
function _delete($table, $where = array(), $like = array(), $limit = FALSE)
{
$conditions = '';
@@ -710,7 +710,7 @@ class CI_DB_mysql_driver extends CI_DB {
}
$limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
-
+
return "DELETE FROM ".$table.$conditions.$limit;
}
@@ -728,7 +728,7 @@ class CI_DB_mysql_driver extends CI_DB {
* @return string
*/
function _limit($sql, $limit, $offset)
- {
+ {
if ($offset == 0)
{
$offset = '';
@@ -737,7 +737,7 @@ class CI_DB_mysql_driver extends CI_DB {
{
$offset .= ", ";
}
-
+
return $sql."LIMIT ".$offset.$limit;
}
@@ -754,7 +754,7 @@ class CI_DB_mysql_driver extends CI_DB {
{
@mysql_close($conn_id);
}
-
+
}
diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php
index ccacf99f8..973f32dcb 100644
--- a/system/database/drivers/mysql/mysql_forge.php
+++ b/system/database/drivers/mysql/mysql_forge.php
@@ -23,7 +23,7 @@
* @link http://codeigniter.com/user_guide/database/
*/
class CI_DB_mysql_forge extends CI_DB_forge {
-
+
/**
* Create database
*
@@ -76,52 +76,52 @@ class CI_DB_mysql_forge extends CI_DB_forge {
else
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
-
+
$sql .= "\n\t".$this->db->_protect_identifiers($field);
if (array_key_exists('NAME', $attributes))
{
$sql .= ' '.$this->db->_protect_identifiers($attributes['NAME']).' ';
}
-
+
if (array_key_exists('TYPE', $attributes))
{
$sql .= ' '.$attributes['TYPE'];
}
-
+
if (array_key_exists('CONSTRAINT', $attributes))
{
$sql .= '('.$attributes['CONSTRAINT'].')';
}
-
+
if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
{
$sql .= ' UNSIGNED';
}
-
+
if (array_key_exists('DEFAULT', $attributes))
{
$sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
}
-
+
if (array_key_exists('NULL', $attributes))
{
$sql .= ($attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL';
}
-
+
if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)
{
$sql .= ' AUTO_INCREMENT';
}
}
-
+
// don't add a comma on the end of the last field
if (++$current_field_count < count($fields))
{
$sql .= ',';
}
}
-
+
return $sql;
}
@@ -141,12 +141,12 @@ class CI_DB_mysql_forge extends CI_DB_forge {
function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
{
$sql = 'CREATE TABLE ';
-
+
if ($if_not_exists === TRUE)
{
$sql .= 'IF NOT EXISTS ';
}
-
+
$sql .= $this->db->_escape_identifiers($table)." (";
$sql .= $this->_process_fields($fields);
@@ -165,14 +165,14 @@ class CI_DB_mysql_forge extends CI_DB_forge {
if (is_array($key))
{
$key_name = $this->db->_protect_identifiers(implode('_', $key));
- $key = $this->db->_protect_identifiers($key);
+ $key = $this->db->_protect_identifiers($key);
}
else
{
$key_name = $this->db->_protect_identifiers($key);
$key = array($key_name);
}
-
+
$sql .= ",\n\tKEY {$key_name} (" . implode(', ', $key) . ")";
}
}
@@ -226,7 +226,7 @@ class CI_DB_mysql_forge extends CI_DB_forge {
{
$sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
}
-
+
return $sql;
}
diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php
index acc586626..0140ec647 100644
--- a/system/database/drivers/mysql/mysql_result.php
+++ b/system/database/drivers/mysql/mysql_result.php
@@ -36,7 +36,7 @@ class CI_DB_mysql_result extends CI_DB_result {
{
return @mysql_num_rows($this->result_id);
}
-
+
// --------------------------------------------------------------------
/**
@@ -49,7 +49,7 @@ class CI_DB_mysql_result extends CI_DB_result {
{
return @mysql_num_fields($this->result_id);
}
-
+
// --------------------------------------------------------------------
/**
@@ -67,7 +67,7 @@ class CI_DB_mysql_result extends CI_DB_result {
{
$field_names[] = $field->name;
}
-
+
return $field_names;
}
@@ -85,27 +85,27 @@ class CI_DB_mysql_result extends CI_DB_result {
{
$retval = array();
while ($field = mysql_fetch_field($this->result_id))
- {
+ {
$F = new stdClass();
- $F->name = $field->name;
- $F->type = $field->type;
+ $F->name = $field->name;
+ $F->type = $field->type;
$F->default = $field->def;
$F->max_length = $field->max_length;
$F->primary_key = $field->primary_key;
-
+
$retval[] = $F;
}
-
+
return $retval;
}
-
+
// --------------------------------------------------------------------
/**
* Free the result
*
* @return null
- */
+ */
function free_result()
{
if (is_resource($this->result_id))
@@ -146,7 +146,7 @@ class CI_DB_mysql_result extends CI_DB_result {
{
return mysql_fetch_assoc($this->result_id);
}
-
+
// --------------------------------------------------------------------
/**
@@ -161,7 +161,7 @@ class CI_DB_mysql_result extends CI_DB_result {
{
return mysql_fetch_object($this->result_id);
}
-
+
}
diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php
index c4a970cfd..3b574c6f4 100644
--- a/system/database/drivers/mysql/mysql_utility.php
+++ b/system/database/drivers/mysql/mysql_utility.php
@@ -84,7 +84,7 @@ class CI_DB_mysql_utility extends CI_DB_utility {
// Extract the prefs for simplicity
extract($params);
-
+
// Build the output
$output = '';
foreach ((array)$tables as $table)
@@ -97,31 +97,31 @@ class CI_DB_mysql_utility extends CI_DB_utility {
// 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)
- {
+ 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)
{
@@ -130,16 +130,16 @@ class CI_DB_mysql_utility extends CI_DB_utility {
// 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();
@@ -148,24 +148,24 @@ class CI_DB_mysql_utility extends CI_DB_utility {
// Most versions of MySQL store timestamp as a string
$is_int[$i] = (in_array(
strtolower(mysql_field_type($query->result_id, $i)),
- array('tinyint', 'smallint', 'mediumint', 'int', 'bigint'), //, 'timestamp'),
+ 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)
{
@@ -184,21 +184,21 @@ class CI_DB_mysql_utility extends CI_DB_utility {
else
{
$val_str .= $v;
- }
- }
-
+ }
+ }
+
// Append a comma
$val_str .= ', ';
$i++;
}
-
+
// Remove the comma at the end of the string
$val_str = preg_replace( "/, $/" , "" , $val_str);
-
+
// Build the INSERT string
$output .= 'INSERT INTO '.$table.' ('.$field_str.') VALUES ('.$val_str.');'.$newline;
}
-
+
$output .= $newline.$newline;
}