From 7b613c7000a496fe0e4f9152ee8937d06eba2301 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 18:05:17 +0000 Subject: Adding database folder --- system/database/DB_active_record.php | 875 +++++++++++++++++++++ system/database/DB_driver.php | 578 ++++++++++++++ system/database/DB_result.php | 286 +++++++ system/database/DB_utility.php | 282 +++++++ system/database/drivers/index.html | 15 + system/database/drivers/mssql/mssql.php | 457 +++++++++++ system/database/drivers/mssql/mssql_result.php | 129 +++ system/database/drivers/mssql/mssql_utility.php | 41 + system/database/drivers/mysql/mysql.php | 478 +++++++++++ system/database/drivers/mysql/mysql_result.php | 129 +++ system/database/drivers/mysql/mysql_utility.php | 41 + system/database/drivers/mysqli/mysqli.php | 479 +++++++++++ system/database/drivers/mysqli/mysqli_result.php | 129 +++ system/database/drivers/mysqli/mysqli_utility.php | 41 + system/database/drivers/oci8/oci8.php | 608 ++++++++++++++ system/database/drivers/oci8/oci8_result.php | 207 +++++ system/database/drivers/oci8/oci8_utility.php | 41 + system/database/drivers/odbc/odbc.php | 454 +++++++++++ system/database/drivers/odbc/odbc_result.php | 190 +++++ system/database/drivers/odbc/odbc_utility.php | 41 + system/database/drivers/postgre/postgre.php | 484 ++++++++++++ system/database/drivers/postgre/postgre_result.php | 129 +++ .../database/drivers/postgre/postgre_utility.php | 41 + system/database/drivers/sqlite/sqlite.php | 481 +++++++++++ system/database/drivers/sqlite/sqlite_result.php | 132 ++++ system/database/drivers/sqlite/sqlite_utility.php | 41 + system/database/index.html | 15 + 27 files changed, 6824 insertions(+) create mode 100644 system/database/DB_active_record.php create mode 100644 system/database/DB_driver.php create mode 100644 system/database/DB_result.php create mode 100644 system/database/DB_utility.php create mode 100644 system/database/drivers/index.html create mode 100644 system/database/drivers/mssql/mssql.php create mode 100644 system/database/drivers/mssql/mssql_result.php create mode 100644 system/database/drivers/mssql/mssql_utility.php create mode 100644 system/database/drivers/mysql/mysql.php create mode 100644 system/database/drivers/mysql/mysql_result.php create mode 100644 system/database/drivers/mysql/mysql_utility.php create mode 100644 system/database/drivers/mysqli/mysqli.php create mode 100644 system/database/drivers/mysqli/mysqli_result.php create mode 100644 system/database/drivers/mysqli/mysqli_utility.php create mode 100644 system/database/drivers/oci8/oci8.php create mode 100644 system/database/drivers/oci8/oci8_result.php create mode 100644 system/database/drivers/oci8/oci8_utility.php create mode 100644 system/database/drivers/odbc/odbc.php create mode 100644 system/database/drivers/odbc/odbc_result.php create mode 100644 system/database/drivers/odbc/odbc_utility.php create mode 100644 system/database/drivers/postgre/postgre.php create mode 100644 system/database/drivers/postgre/postgre_result.php create mode 100644 system/database/drivers/postgre/postgre_utility.php create mode 100644 system/database/drivers/sqlite/sqlite.php create mode 100644 system/database/drivers/sqlite/sqlite_result.php create mode 100644 system/database/drivers/sqlite/sqlite_utility.php create mode 100644 system/database/index.html (limited to 'system/database') diff --git a/system/database/DB_active_record.php b/system/database/DB_active_record.php new file mode 100644 index 000000000..c038185bc --- /dev/null +++ b/system/database/DB_active_record.php @@ -0,0 +1,875 @@ +ar_select[] = $val; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * DISTINCT + * + * Sets a flag which tells the query string compiler to add DISTINCT + * + * @access public + * @param bool + * @return object + */ + function distinct($val = TRUE) + { + $this->ar_distinct = (is_bool($val)) ? $val : TRUE; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * From + * + * Generates the FROM portion of the query + * + * @access public + * @param mixed can be a string or array + * @return object + */ + function from($from) + { + foreach ((array)$from as $val) + { + $this->ar_from[] = $this->dbprefix.$val; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Join + * + * Generates the JOIN portion of the query + * + * @access public + * @param string + * @param string the join condition + * @param string the type of join + * @return object + */ + function join($table, $cond, $type = '') + { + if ($type != '') + { + $type = strtoupper(trim($type)); + + if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'))) + { + $type = ''; + } + else + { + $type .= ' '; + } + } + + $this->ar_join[] = $type.'JOIN '.$table.' ON '.$cond; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Where + * + * Generates the WHERE portion of the query. Separates + * multiple calls with AND + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function where($key, $value = NULL) + { + return $this->_where($key, $value, 'AND '); + } + + // -------------------------------------------------------------------- + + /** + * OR Where + * + * Generates the WHERE portion of the query. Separates + * multiple calls with OR + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function orwhere($key, $value = NULL) + { + return $this->_where($key, $value, 'OR '); + } + + // -------------------------------------------------------------------- + + /** + * Where + * + * Called by where() or orwhere() + * + * @access private + * @param mixed + * @param mixed + * @param string + * @return object + */ + function _where($key, $value = NULL, $type = 'AND ') + { + if ( ! is_array($key)) + { + $key = array($key => $value); + } + + foreach ($key as $k => $v) + { + $prefix = (count($this->ar_where) == 0) ? '' : $type; + + if ( ! is_null($v)) + { + if ( ! $this->_has_operator($k)) + { + $k .= ' ='; + } + + $v = ' '.$this->escape($v); + } + + $this->ar_where[] = $prefix.$k.$v; + } + return $this; + } + + + + // -------------------------------------------------------------------- + + /** + * Like + * + * Generates a %LIKE% portion of the query. Separates + * multiple calls with AND + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function like($field, $match = '') + { + return $this->_like($field, $match, 'AND '); + } + + // -------------------------------------------------------------------- + + /** + * OR Like + * + * Generates a %LIKE% portion of the query. Separates + * multiple calls with OR + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function orlike($field, $match = '') + { + return $this->_like($field, $match, 'OR '); + } + + // -------------------------------------------------------------------- + + /** + * Like + * + * Called by like() or orlike() + * + * @access private + * @param mixed + * @param mixed + * @param string + * @return object + */ + function _like($field, $match = '', $type = 'AND ') + { + if ( ! is_array($field)) + { + $field = array($field => $match); + } + + foreach ($field as $k => $v) + { + $prefix = (count($this->ar_like) == 0) ? '' : $type; + + $v = $this->escape_str($v); + + $this->ar_like[] = $prefix." $k LIKE '%{$v}%'"; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * GROUP BY + * + * @access public + * @param string + * @return object + */ + function groupby($by) + { + if (is_string($by)) + { + $by = explode(',', $by); + } + + foreach ($by as $val) + { + $val = trim($val); + + if ($val != '') + $this->ar_groupby[] = $val; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Sets the HAVING value + * + * Separates multiple calls with AND + * + * @access public + * @param string + * @param string + * @return object + */ + function having($key, $value = '') + { + return $this->_having($key, $value, 'AND '); + } + + // -------------------------------------------------------------------- + + /** + * Sets the OR HAVING value + * + * Separates multiple calls with OR + * + * @access public + * @param string + * @param string + * @return object + */ + function orhaving($key, $value = '') + { + return $this->_having($key, $value, 'OR '); + } + + // -------------------------------------------------------------------- + + /** + * Sets the HAVING values + * + * Called by having() or orhaving() + * + * @access private + * @param string + * @param string + * @return object + */ + function _having($key, $value = '', $type = 'AND ') + { + if ( ! is_array($key)) + { + $key = array($key => $value); + } + + foreach ($key as $k => $v) + { + $prefix = (count($this->ar_having) == 0) ? '' : $type; + + if ($v != '') + { + $v = ' '.$this->escape($v); + } + + $this->ar_having[] = $prefix.$k.$v; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Sets the ORDER BY value + * + * @access public + * @param string + * @param string direction: asc or desc + * @return object + */ + function orderby($orderby, $direction = '') + { + if (trim($direction) != '') + { + $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC', 'RAND()'))) ? ' '.$direction : ' ASC'; + } + + $this->ar_orderby[] = $orderby.$direction; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Sets the LIMIT value + * + * @access public + * @param integer the limit value + * @param integer the offset value + * @return object + */ + function limit($value, $offset = '') + { + $this->ar_limit = $value; + + if ($offset != '') + $this->ar_offset = $offset; + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Sets the OFFSET value + * + * @access public + * @param integer the offset value + * @return object + */ + function offset($value) + { + $this->ar_offset = $value; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * The "set" function. Allows key/value pairs to be set for inserting or updating + * + * @access public + * @param mixed + * @param string + * @return object + */ + function set($key, $value = '') + { + $key = $this->_object_to_array($key); + + if ( ! is_array($key)) + { + $key = array($key => $value); + } + + foreach ($key as $k => $v) + { + $this->ar_set[$k] = $this->escape($v); + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Get + * + * Compiles the select statement based on the other functions called + * and runs the query + * + * @access public + * @param string the limit clause + * @param string the offset clause + * @return object + */ + function get($table = '', $limit = null, $offset = null) + { + if ($table != '') + { + $this->from($table); + } + + if ( ! is_null($limit)) + { + $this->limit($limit, $offset); + } + + $sql = $this->_compile_select(); + + $this->_reset_select(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * GetWhere + * + * Allows the where clause, limit and offset to be added directly + * + * @access public + * @param string the where clause + * @param string the limit clause + * @param string the offset clause + * @return object + */ + function getwhere($table = '', $where = null, $limit = null, $offset = null) + { + if ($table != '') + { + $this->from($table); + } + + if ( ! is_null($where)) + { + $this->where($where); + } + + if ( ! is_null($limit)) + { + $this->limit($limit, $offset); + } + + $sql = $this->_compile_select(); + + $this->_reset_select(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Insert + * + * Compiles an insert string and runs the query + * + * @access public + * @param string the table to retrieve the results from + * @param array an associative array of insert values + * @return object + */ + function insert($table = '', $set = NULL) + { + if ( ! is_null($set)) + { + $this->set($set); + } + + if (count($this->ar_set) == 0) + { + if ($this->db_debug) + { + return $this->display_error('db_must_use_set'); + } + return FALSE; + } + + if ($table == '') + { + if ( ! isset($this->ar_from[0])) + { + if ($this->db_debug) + { + return $this->display_error('db_must_set_table'); + } + return FALSE; + } + + $table = $this->ar_from[0]; + } + + $sql = $this->_insert($this->dbprefix.$table, array_keys($this->ar_set), array_values($this->ar_set)); + + $this->_reset_write(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Update + * + * Compiles an update string and runs the query + * + * @access public + * @param string the table to retrieve the results from + * @param array an associative array of update values + * @param mixed the where clause + * @return object + */ + function update($table = '', $set = NULL, $where = null) + { + if ( ! is_null($set)) + { + $this->set($set); + } + + if (count($this->ar_set) == 0) + { + if ($this->db_debug) + { + return $this->display_error('db_must_use_set'); + } + return FALSE; + } + + if ($table == '') + { + if ( ! isset($this->ar_from[0])) + { + if ($this->db_debug) + { + return $this->display_error('db_must_set_table'); + } + return FALSE; + } + + $table = $this->ar_from[0]; + } + + if ($where != null) + { + $this->where($where); + } + + $sql = $this->_update($this->dbprefix.$table, $this->ar_set, $this->ar_where); + + $this->_reset_write(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Delete + * + * Compiles a delete string and runs the query + * + * @access public + * @param string the table to retrieve the results from + * @param mixed the where clause + * @return object + */ + function delete($table = '', $where = '') + { + if ($table == '') + { + if ( ! isset($this->ar_from[0])) + { + if ($this->db_debug) + { + return $this->display_error('db_must_set_table'); + } + return FALSE; + } + + $table = $this->ar_from[0]; + } + + if ($where != '') + { + $this->where($where); + } + + if (count($this->ar_where) == 0) + { + if ($this->db_debug) + { + return $this->display_error('db_del_must_use_where'); + } + return FALSE; + } + + $sql = $this->_delete($this->dbprefix.$table, $this->ar_where); + + $this->_reset_write(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Use Table - DEPRECATED + * + * @deprecated use $this->db->from instead + */ + function use_table($table) + { + return $this->from($table); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * ORDER BY - DEPRECATED + * + * @deprecated use $this->db->orderby() instead + */ + function order_by($orderby, $direction = '') + { + return $this->orderby($orderby, $direction); + } + + // -------------------------------------------------------------------- + + /** + * Tests whether the string has an SQL operator + * + * @access private + * @param string + * @return bool + */ + function _has_operator($str) + { + $str = trim($str); + if ( ! preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str)) + { + return FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Compile the SELECT statement + * + * Generates a query string based on which functions were used. + * Should not be called directly. The get() function calls it. + * + * @access private + * @return string + */ + function _compile_select() + { + $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; + + $sql .= (count($this->ar_select) == 0) ? '*' : implode(', ', $this->ar_select); + + if (count($this->ar_from) > 0) + { + $sql .= "\nFROM "; + $sql .= implode(', ', $this->ar_from); + } + + if (count($this->ar_join) > 0) + { + $sql .= "\n"; + $sql .= implode("\n", $this->ar_join); + } + + if (count($this->ar_where) > 0 OR count($this->ar_like) > 0) + { + $sql .= "\nWHERE "; + } + + $sql .= implode("\n", $this->ar_where); + + if (count($this->ar_like) > 0) + { + if (count($this->ar_where) > 0) + { + $sql .= " AND "; + } + + $sql .= implode("\n", $this->ar_like); + } + + if (count($this->ar_groupby) > 0) + { + $sql .= "\nGROUP BY "; + $sql .= implode(', ', $this->ar_groupby); + } + + if (count($this->ar_having) > 0) + { + $sql .= "\nHAVING "; + $sql .= implode("\n", $this->ar_having); + } + + if (count($this->ar_orderby) > 0) + { + $sql .= "\nORDER BY "; + $sql .= implode(', ', $this->ar_orderby); + + if ($this->ar_order !== FALSE) + { + $sql .= ($this->ar_order == 'desc') ? ' DESC' : ' ASC'; + } + } + + if (is_numeric($this->ar_limit)) + { + $sql .= "\n"; + $sql = $this->_limit($sql, $this->ar_limit, $this->ar_offset); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Object to Array + * + * Takes an object as input and convers the class variables to array key/vals + * + * @access public + * @param object + * @return array + */ + function _object_to_array($object) + { + if ( ! is_object($object)) + { + return $object; + } + + $array = array(); + foreach (get_object_vars($object) as $key => $val) + { + if ( ! is_object($val) AND ! is_array($val)) + { + $array[$key] = $val; + } + } + + return $array; + } + + // -------------------------------------------------------------------- + + /** + * Resets the active record values. Called by the get() function + * + * @access private + * @return void + */ + function _reset_select() + { + $this->ar_select = array(); + $this->ar_distinct = FALSE; + $this->ar_from = array(); + $this->ar_join = array(); + $this->ar_where = array(); + $this->ar_like = array(); + $this->ar_groupby = array(); + $this->ar_having = array(); + $this->ar_limit = FALSE; + $this->ar_offset = FALSE; + $this->ar_order = FALSE; + $this->ar_orderby = array(); + } + + // -------------------------------------------------------------------- + + /** + * Resets the active record "write" values. + * + * Called by the insert() or update() functions + * + * @access private + * @return void + */ + function _reset_write() + { + $this->ar_set = array(); + $this->ar_from = array(); + $this->ar_where = array(); + } + +} + +?> \ No newline at end of file diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php new file mode 100644 index 000000000..ef37967dc --- /dev/null +++ b/system/database/DB_driver.php @@ -0,0 +1,578 @@ +initialize($params); + log_message('debug', 'Database Driver Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Initialize Database Settings + * + * @access private Called by the constructor + * @param mixed + * @return void + */ + function initialize($params = '') + { + if (is_array($params)) + { + foreach (array('hostname' => '', 'username' => '', 'password' => '', 'database' => '', 'dbdriver' => 'mysql', 'dbprefix' => '', 'port' => '', 'pconnect' => FALSE, 'db_debug' => FALSE) as $key => $val) + { + $this->$key = ( ! isset($params[$key])) ? $val : $params[$key]; + } + } + elseif (strpos($params, '://')) + { + if (FALSE === ($dsn = @parse_url($params))) + { + log_message('error', 'Invalid DB Connection String'); + + if ($this->db_debug) + { + return $this->display_error('db_invalid_connection_str'); + } + return FALSE; + } + + $this->hostname = ( ! isset($dsn['host'])) ? '' : rawurldecode($dsn['host']); + $this->username = ( ! isset($dsn['user'])) ? '' : rawurldecode($dsn['user']); + $this->password = ( ! isset($dsn['pass'])) ? '' : rawurldecode($dsn['pass']); + $this->database = ( ! isset($dsn['path'])) ? '' : rawurldecode(substr($dsn['path'], 1)); + } + + if ($this->pconnect == FALSE) + { + $this->conn_id = $this->db_connect(); + } + else + { + $this->conn_id = $this->db_pconnect(); + } + + if ( ! $this->conn_id) + { + log_message('error', 'Unable to connect to the database'); + + if ($this->db_debug) + { + $this->display_error('db_unable_to_connect'); + } + } + else + { + if ( ! $this->db_select()) + { + log_message('error', 'Unable to select database: '.$this->database); + + if ($this->db_debug) + { + $this->display_error('db_unable_to_select', $this->database); + } + } + } + } + + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * Accepts an SQL string as input and returns a result object upon + * successful execution of a "read" type query. Returns boolean TRUE + * upon successful execution of a "write" type query. Returns boolean + * FALSE upon failure, and if the $db_debug variable is set to TRUE + * will raise an error. + * + * @access public + * @param string An SQL query string + * @param array An array of binding data + * @return mixed + */ + function query($sql, $binds = FALSE, $return_object = TRUE) + { + if ($sql == '') + { + if ($this->db_debug) + { + log_message('error', 'Invalid query: '.$sql); + return $this->display_error('db_invalid_query'); + } + return FALSE; + } + + // Compile binds if needed + if ($binds !== FALSE) + { + $sql = $this->compile_binds($sql, $binds); + } + + // Save the query for debugging + $this->queries[] = $sql; + + // Start the Query Timer + $time_start = list($sm, $ss) = explode(' ', microtime()); + + // Run the Query + if (FALSE === ($this->result_id = $this->simple_query($sql))) + { + // This will trigger a rollback if transactions are being used + $this->_trans_failure = TRUE; + + if ($this->db_debug) + { + log_message('error', 'Query error: '.$this->error_message()); + return $this->display_error( + array( + 'Error Number: '.$this->error_number(), + $this->error_message(), + $sql + ) + ); + } + + return FALSE; + } + + // Stop and aggregate the query time results + $time_end = list($em, $es) = explode(' ', microtime()); + $this->benchmark += ($em + $es) - ($sm + $ss); + + // Increment the query counter + $this->query_count++; + + // Was the query a "write" type? + // If so we'll simply return true + if ($this->is_write_type($sql) === TRUE) + { + return TRUE; + } + + // Return TRUE if we don't need to create a result object + // Currently only the Oracle driver uses this when stored + // procedures are used + if ($return_object !== TRUE) + { + return TRUE; + } + + // Define the result driver name + $result = 'CI_DB_'.$this->dbdriver.'_result'; + + // Load the result classes + if ( ! class_exists($result)) + { + include_once(BASEPATH.'database/DB_result'.EXT); + include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result'.EXT); + } + + // Instantiate the result object + $RES = new $result(); + $RES->conn_id = $this->conn_id; + $RES->db_debug = $this->db_debug; + $RES->result_id = $this->result_id; + + if ($this->dbdriver == 'oci8') + { + $RES->stmt_id = $this->stmt_id; + $RES->curs_id = NULL; + $RES->limit_used = $this->limit_used; + } + + return $RES; + } + + // -------------------------------------------------------------------- + + /** + * Simple Query + * This is a simiplified version of the query() function. Internally + * we only use it when running transaction commands since they do + * not require all the features of the main query() function. + * + * @access public + * @param string the sql query + * @return mixed + */ + function simple_query($sql) + { + if ( ! $this->conn_id) + { + $this->initialize(); + } + + return $this->_execute($sql, $this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Disable Transactions + * This permits transactions to be disabled at run-time. + * + * @access public + * @return void + */ + function trans_off() + { + $this->trans_enabled = FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Start Transaction + * + * @access public + * @return void + */ + function trans_start($test_mode = FALSE) + { + if ( ! $this->trans_enabled) + { + return FALSE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + $this->_trans_depth += 1; + return; + } + + $this->trans_begin($test_mode); + } + + // -------------------------------------------------------------------- + + /** + * Complete Transaction + * + * @access public + * @return bool + */ + function trans_complete() + { + if ( ! $this->trans_enabled) + { + return FALSE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 1) + { + $this->_trans_depth -= 1; + return TRUE; + } + + // The query() function will set this flag to TRUE in the event that a query failed + if ($this->_trans_failure === TRUE) + { + $this->trans_rollback(); + + if ($this->db_debug) + { + return $this->display_error('db_transaction_failure'); + } + return FALSE; + } + + $this->trans_commit(); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Lets you retrieve the transaction flag to determine if it has failed + * + * @access public + * @return bool + */ + function trans_status() + { + return $this->_trans_failure; + } + + // -------------------------------------------------------------------- + + /** + * Compile Bindings + * + * @access public + * @param string the sql statement + * @param array an array of bind data + * @return string + */ + function compile_binds($sql, $binds) + { + if (FALSE === strpos($sql, $this->bind_marker)) + { + return $sql; + } + + if ( ! is_array($binds)) + { + $binds = array($binds); + } + + foreach ($binds as $val) + { + $val = $this->escape($val); + + // Just in case the replacement string contains the bind + // character we'll temporarily replace it with a marker + $val = str_replace($this->bind_marker, '{%bind_marker%}', $val); + $sql = preg_replace("#".preg_quote($this->bind_marker, '#')."#", str_replace('$', '\$', $val), $sql, 1); + } + + return str_replace('{%bind_marker%}', $this->bind_marker, $sql); + } + + // -------------------------------------------------------------------- + + /** + * Determines if a query is a "write" type. + * + * @access public + * @param string An SQL query string + * @return boolean + */ + function is_write_type($sql) + { + if ( ! preg_match('/^\s*"?(INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql)) + { + return FALSE; + } + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Calculate the aggregate query elapsed time + * + * @access public + * @param intiger The number of decimal places + * @return integer + */ + function elapsed_time($decimals = 6) + { + return number_format($this->benchmark, $decimals); + } + + // -------------------------------------------------------------------- + + /** + * Returns the total number of queries + * + * @access public + * @return integer + */ + function total_queries() + { + return $this->query_count; + } + + // -------------------------------------------------------------------- + + /** + * Returns the last query that was executed + * + * @access public + * @return void + */ + function last_query() + { + return end($this->queries); + } + + // -------------------------------------------------------------------- + + /** + * "Smart" Escape String + * + * Escapes data based on type + * Sets boolean and null types + * + * @access public + * @param string + * @return integer + */ + function escape($str) + { + switch (gettype($str)) + { + case 'string' : $str = "'".$this->escape_str($str)."'"; + break; + case 'boolean' : $str = ($str === FALSE) ? 0 : 1; + break; + default : $str = ($str === NULL) ? 'NULL' : $str; + break; + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Enables a native PHP function to be run, using a platform agnostic wrapper. + * + * @access public + * @param string the function name + * @param mixed any parameters needed by the function + * @return mixed + */ + function call_function($function) + { + $driver = ($this->dbdriver == 'postgre') ? 'pg_' : $this->dbdriver.'_'; + + if (FALSE === strpos($driver, $function)) + { + $function = $driver.$function; + } + + if ( ! function_exists($function)) + { + if ($this->db_debug) + { + return $this->display_error('db_unsupported_function'); + } + return FALSE; + } + else + { + $args = (func_num_args() > 1) ? array_shift(func_get_args()) : null; + + return call_user_func_array($function, $args); + } + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @return void + */ + function close() + { + if (is_resource($this->conn_id)) + { + $this->_close($this->conn_id); + } + $this->conn_id = FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Display an error message + * + * @access public + * @param string the error message + * @param string any "swap" values + * @param boolean whether to localize the message + * @return string sends the application/errror_db.php template + */ + function display_error($error = '', $swap = '', $native = FALSE) + { + $LANG = new CI_Language(); + $LANG->load('db'); + + $heading = 'MySQL Error'; + + if ($native == TRUE) + { + $message = $error; + } + else + { + $message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error; + } + + if ( ! class_exists('CI_Exceptions')) + { + include_once(BASEPATH.'libraries/Exceptions'.EXT); + } + + $error = new CI_Exceptions(); + echo $error->show_error('An Error Was Encountered', $message, 'error_db'); + exit; + + } + +} + +?> \ No newline at end of file diff --git a/system/database/DB_result.php b/system/database/DB_result.php new file mode 100644 index 000000000..abb6b588b --- /dev/null +++ b/system/database/DB_result.php @@ -0,0 +1,286 @@ +result_object() : $this->result_array(); + } + + // -------------------------------------------------------------------- + + /** + * Query result. "object" version. + * + * @access public + * @return object + */ + function result_object() + { + if (count($this->result_object) > 0) + { + return $this->result_object; + } + + while ($row = $this->_fetch_object()) + { + $this->result_object[] = $row; + } + + if (count($this->result_object) == 0) + { + return FALSE; + } + + return $this->result_object; + } + + // -------------------------------------------------------------------- + + /** + * Query result. "array" version. + * + * @access public + * @return array + */ + function result_array() + { + if (count($this->result_array) > 0) + { + return $this->result_array; + } + + while ($row = $this->_fetch_assoc()) + { + $this->result_array[] = $row; + } + + if (count($this->result_array) == 0) + { + return FALSE; + } + + return $this->result_array; + } + + // -------------------------------------------------------------------- + + /** + * Query result. Acts as a wrapper function for the following functions. + * + * @access public + * @param string can be "object" or "array" + * @return mixed either a result object or array + */ + function row($n = 0, $type = 'object') + { + return ($type == 'object') ? $this->row_object($n) : $this->row_array($n); + } + + // -------------------------------------------------------------------- + + /** + * Returns a single result row - object version + * + * @access public + * @return object + */ + function row_object($n = 0) + { + if (FALSE === ($result = $this->result_object())) + { + return FALSE; + } + + if ($n != $this->current_row AND isset($result[$n])) + { + $this->current_row = $n; + } + + return $result[$this->current_row]; + } + + // -------------------------------------------------------------------- + + /** + * Returns a single result row - array version + * + * @access public + * @return array + */ + function row_array($n = 0) + { + if (FALSE === ($result = $this->result_array())) + { + return FALSE; + } + + if ($n != $this->current_row AND isset($result[$n])) + { + $this->current_row = $n; + } + + return $result[$this->current_row]; + } + + + // -------------------------------------------------------------------- + + /** + * Returns the "first" row + * + * @access public + * @return object + */ + function first_row($type = 'object') + { + if (FALSE === ($result = $this->result($type))) + { + return FALSE; + } + return $result[0]; + } + + // -------------------------------------------------------------------- + + /** + * Returns the "last" row + * + * @access public + * @return object + */ + function last_row($type = 'object') + { + if (FALSE === ($result = $this->result($type))) + { + return FALSE; + } + return $result[count($result) -1]; + } + + // -------------------------------------------------------------------- + + /** + * Returns the "next" row + * + * @access public + * @return object + */ + function next_row($type = 'object') + { + if (FALSE === ($result = $this->result($type))) + { + return FALSE; + } + + if (isset($result[$this->current_row + 1])) + { + ++$this->current_row; + } + + return $result[$this->current_row]; + } + + // -------------------------------------------------------------------- + + /** + * Returns the "previous" row + * + * @access public + * @return object + */ + function previous_row($type = 'object') + { + if (FALSE === ($result = $this->result($type))) + { + return FALSE; + } + + if (isset($result[$this->current_row - 1])) + { + --$this->current_row; + } + return $result[$this->current_row]; + } + + /** + * Number of rows in the result set + * + * @access public + * @return integer + */ + function num_rows() + { + // Result supplied by the result adaptor class + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + // Result supplied by the result adaptor class + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + // Result supplied by the result adaptor class + } +} + +?> \ No newline at end of file diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php new file mode 100644 index 000000000..a4d4eb0d1 --- /dev/null +++ b/system/database/DB_utility.php @@ -0,0 +1,282 @@ +_version())) + { + if ($this->db_debug) + { + return $this->display_error('db_unsupported_function'); + } + return FALSE; + } + + if ($this->dbdriver == 'oci8') + { + return $sql; + } + + $query = $this->query($sql); + $row = $query->row(); + return $row->ver; + } + + // -------------------------------------------------------------------- + + /** + * Returns an array of table names + * + * @access public + * @return array + */ + function tables() + { + if (FALSE === ($sql = $this->_show_tables())) + { + if ($this->db_debug) + { + return $this->display_error('db_unsupported_function'); + } + return FALSE; + } + + $retval = array(); + $query = $this->query($sql); + + if ($query->num_rows() > 0) + { + foreach($query->result_array() as $row) + { + if (isset($row['TABLE_NAME'])) + { + $retval[] = $row['TABLE_NAME']; + } + else + { + $retval[] = array_shift($row); + } + } + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Determine if a particular table exists + * @access public + * @return boolean + */ + function table_exists($table_name) + { + return ( ! in_array($this->dbprefix.$table_name, $this->tables())) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Fetch MySQL Field Names + * + * @access public + * @param string the table name + * @return array + */ + function field_names($table = '') + { + if ($table == '') + { + if ($this->db_debug) + { + return $this->display_error('db_field_param_missing'); + } + return FALSE; + } + + if (FALSE === ($sql = $this->_show_columns($this->dbprefix.$table))) + { + if ($this->db_debug) + { + return $this->display_error('db_unsupported_function'); + } + return FALSE; + } + + $query = $this->query($sql); + + $retval = array(); + foreach($query->result_array() as $row) + { + if (isset($row['COLUMN_NAME'])) + { + $retval[] = $row['COLUMN_NAME']; + } + else + { + $retval[] = current($row); + } + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @access public + * @param string the table name + * @return object + */ + function field_data($table = '') + { + if ($table == '') + { + if ($this->db_debug) + { + return $this->display_error('db_field_param_missing'); + } + return FALSE; + } + + return $this->_field_data($this->dbprefix.$table); + } + + // -------------------------------------------------------------------- + + /** + * Primary + * + * Retrieves the primary key. It assumes that the row in the first + * position is the primary key + * + * @access public + * @param string the table name + * @return string + */ + function primary($table = '') + { + $fields = $this->field_names($table); + + if ( ! is_array($fields)) + { + return FALSE; + } + + return current($fields); + } + + // -------------------------------------------------------------------- + + /** + * Generate an insert string + * + * @access public + * @param string the table upon which the query will be performed + * @param array an associative array data of key/values + * @return string + */ + function insert_string($table, $data) + { + $fields = array(); + $values = array(); + + foreach($data as $key => $val) + { + $fields[] = $key; + $values[] = $this->escape($val); + } + + return $this->_insert($this->dbprefix.$table, $fields, $values); + } + + // -------------------------------------------------------------------- + + /** + * Generate an update string + * + * @access public + * @param string the table upon which the query will be performed + * @param array an associative array data of key/values + * @param mixed the "where" statement + * @return string + */ + function update_string($table, $data, $where) + { + if ($where == '') + return false; + + $fields = array(); + foreach($data as $key => $val) + { + $fields[$key] = $this->escape($val); + } + + if ( ! is_array($where)) + { + $dest = array($where); + } + else + { + $dest = array(); + foreach ($where as $key => $val) + { + $prefix = (count($dest) == 0) ? '' : ' AND '; + + if ($val != '') + { + if ( ! $this->_has_operator($key)) + { + $key .= ' ='; + } + + $val = ' '.$this->escape($val); + } + + $dest[] = $prefix.$key.$val; + } + } + + return $this->_update($this->dbprefix.$table, $fields, $dest); + } + + +} + +?> \ No newline at end of file diff --git a/system/database/drivers/index.html b/system/database/drivers/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/database/drivers/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql.php b/system/database/drivers/mssql/mssql.php new file mode 100644 index 000000000..5f30bf905 --- /dev/null +++ b/system/database/drivers/mssql/mssql.php @@ -0,0 +1,457 @@ +hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return mssql_pconnect($this->hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return @mssql_select_db($this->database, $this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + function _execute($sql) + { + $sql = $this->_prep_query($sql); + return @mssql_query($sql, $this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @access private called by execute() + * @param string an SQL query + * @return string + */ + function _prep_query($sql) + { + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @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) + { + return TRUE; + } + + // Reset the transaction failure flag. + // 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('BEGIN TRAN'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @access public + * @return bool + */ + function trans_commit() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $this->simple_query('COMMIT TRAN'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @access public + * @return bool + */ + function trans_rollback() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $this->simple_query('ROLLBACK TRAN'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + // Escape single quotes + return str_replace("'", "''", $str); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @mssql_rows_affected($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + // Not supported in MS SQL? + return 0; + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + return '0'; + + $query = $this->query("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + // Are errros even supported in MS SQL? + return ''; + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + // Are error numbers supported? + return ''; + } + + // -------------------------------------------------------------------- + + /** + * Escape Table Name + * + * This function adds backticks if the table name has a period + * in it. Some DBs will get cranky unless periods are escaped + * + * @access public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $table; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + $sql = "SELECT TOP 1 FROM ".$this->escape_table($table); + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @return string + */ + function _update($table, $values, $where) + { + foreach($values as $key => $val) + { + $valstr[] = $key." = ".$val; + } + + return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _show_columns($table = '') + { + return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$this->escape_table($table)."'"; + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + $i = $limit + $offset; + + return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql); + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + mssql_close($conn_id); + } + + +} + + +?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php new file mode 100644 index 000000000..a8a8e2006 --- /dev/null +++ b/system/database/drivers/mssql/mssql_result.php @@ -0,0 +1,129 @@ +result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @mssql_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + while ($field = mssql_fetch_field($this->result_id)) + { + $F = new stdClass(); + $F->name = $field->name; + $F->type = $field->type; + $F->max_length = $field->max_length; + $F->primary_key = 0; + $F->default = ''; + + $retval[] = $F; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return null + */ + function free_result() + { + if (is_resource($this->result_id)) + { + mssql_free_result($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @access private + * @return array + */ + function _fetch_assoc() + { + return mssql_fetch_assoc($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + function _fetch_object() + { + return mssql_fetch_object($this->result_id); + } + +} + +?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php new file mode 100644 index 000000000..a76e1f14f --- /dev/null +++ b/system/database/drivers/mssql/mssql_utility.php @@ -0,0 +1,41 @@ + \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql.php b/system/database/drivers/mysql/mysql.php new file mode 100644 index 000000000..4d59f784d --- /dev/null +++ b/system/database/drivers/mysql/mysql.php @@ -0,0 +1,478 @@ +hostname, $this->username, $this->password, TRUE); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return mysql_pconnect($this->hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return @mysql_select_db($this->database, $this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @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); + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @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 + // the query so that it returns the number of affected rows + if ($this->delete_hack === TRUE) + { + if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql)) + { + $sql = preg_replace("/^\s*DELETE\s+FROM\s+(\S+)\s*$/", "DELETE FROM \\1 WHERE 1=1", $sql); + } + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @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) + { + return TRUE; + } + + // Reset the transaction failure flag. + // 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; + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @access public + * @return bool + */ + function trans_commit() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $this->simple_query('COMMIT'); + $this->simple_query('SET AUTOCOMMIT=1'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @access public + * @return bool + */ + function trans_rollback() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $this->simple_query('ROLLBACK'); + $this->simple_query('SET AUTOCOMMIT=1'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + return mysql_real_escape_string($str); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @mysql_affected_rows($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + return @mysql_insert_id($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + return '0'; + + $query = $this->query("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + return mysql_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + return mysql_errno($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Escape Table Name + * + * This function adds backticks if the table name has a period + * in it. Some DBs will get cranky unless periods are escaped + * + * @access public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $table; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @return string + */ + function _update($table, $values, $where) + { + foreach($values as $key => $val) + { + $valstr[] = $key." = ".$val; + } + + return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SHOW TABLES FROM `".$this->database."`"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _show_columns($table = '') + { + return "SHOW COLUMNS FROM ".$this->escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + if ($offset == 0) + { + $offset = ''; + } + else + { + $offset .= ", "; + } + + return $sql."LIMIT ".$offset.$limit; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + mysql_close($conn_id); + } + +} + +?> \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php new file mode 100644 index 000000000..e540489bb --- /dev/null +++ b/system/database/drivers/mysql/mysql_result.php @@ -0,0 +1,129 @@ +result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @mysql_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + while ($field = mysql_fetch_field($this->result_id)) + { + $F = new stdClass(); + $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)) + { + mysql_free_result($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @access private + * @return array + */ + function _fetch_assoc() + { + return mysql_fetch_assoc($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + function _fetch_object() + { + return mysql_fetch_object($this->result_id); + } + +} + +?> \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php new file mode 100644 index 000000000..8dd764888 --- /dev/null +++ b/system/database/drivers/mysql/mysql_utility.php @@ -0,0 +1,41 @@ + \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli.php b/system/database/drivers/mysqli/mysqli.php new file mode 100644 index 000000000..6ca21c976 --- /dev/null +++ b/system/database/drivers/mysqli/mysqli.php @@ -0,0 +1,479 @@ +hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return $this->db_connect(); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return @mysqli_select_db($this->conn_id, $this->database); + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + function _execute($sql) + { + $sql = $this->_prep_query($sql); + $result = @mysqli_query($this->conn_id, $sql); + return $result; + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @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 + // the query so that it returns the number of affected rows + if ($this->delete_hack === TRUE) + { + if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql)) + { + $sql = preg_replace("/^\s*DELETE\s+FROM\s+(\S+)\s*$/", "DELETE FROM \\1 WHERE 1=1", $sql); + } + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @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) + { + return TRUE; + } + + // Reset the transaction failure flag. + // 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; + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @access public + * @return bool + */ + function trans_commit() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $this->simple_query('COMMIT'); + $this->simple_query('SET AUTOCOMMIT=1'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @access public + * @return bool + */ + function trans_rollback() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $this->simple_query('ROLLBACK'); + $this->simple_query('SET AUTOCOMMIT=1'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + return mysqli_real_escape_string($this->conn_id, $str); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @mysqli_affected_rows($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + return @mysqli_insert_id($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + return '0'; + + $query = $this->query("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + return mysqli_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + return mysqli_errno($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Escape Table Name + * + * This function adds backticks if the table name has a period + * in it. Some DBs will get cranky unless periods are escaped + * + * @access public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $table; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @return string + */ + function _update($table, $values, $where) + { + foreach($values as $key => $val) + { + $valstr[] = $key." = ".$val; + } + + return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SHOW TABLES FROM `".$this->database."`"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _show_columns($table = '') + { + return "SHOW COLUMNS FROM ".$this->escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + $sql .= "LIMIT ".$limit; + + if ($offset > 0) + { + $sql .= " OFFSET ".$offset; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + mysqli_close($conn_id); + } + +} + +?> \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php new file mode 100644 index 000000000..b0db6c106 --- /dev/null +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -0,0 +1,129 @@ +result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @mysqli_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + while ($field = mysqli_fetch_field($this->result_id)) + { + $F = new stdClass(); + $F->name = $field->name; + $F->type = $field->type; + $F->default = $field->def; + $F->max_length = $field->max_length; + $F->primary_key = ($field->flags & MYSQLI_PRI_KEY_FLAG) ? 1 : 0; + + $retval[] = $F; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return null + */ + function free_result() + { + if (is_resource($this->result_id)) + { + mysqli_free_result($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @access private + * @return array + */ + function _fetch_assoc() + { + return mysqli_fetch_assoc($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + function _fetch_object() + { + return mysqli_fetch_object($this->result_id); + } + +} + +?> \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php new file mode 100644 index 000000000..02b423c30 --- /dev/null +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -0,0 +1,41 @@ + \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8.php b/system/database/drivers/oci8/oci8.php new file mode 100644 index 000000000..40aabcea7 --- /dev/null +++ b/system/database/drivers/oci8/oci8.php @@ -0,0 +1,608 @@ +username, $this->password, $this->hostname); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return ociplogon($this->username, $this->password, $this->hostname); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + function _execute($sql) + { + // oracle must parse the query before it + // is run, all of the actions with + // the query are based off the statement id + // returned by ociparse + $this->_set_stmt_id($sql); + ocisetprefetch($this->stmt_id, 1000); + return @ociexecute($this->stmt_id, $this->_commit); + } + + /** + * Generate a statement ID + * + * @access private + * @param string an SQL query + * @return none + */ + function _set_stmt_id($sql) + { + if ( ! is_resource($this->stmt_id)) + { + $this->stmt_id = ociparse($this->conn_id, $this->_prep_query($sql)); + } + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @access private called by execute() + * @param string an SQL query + * @return string + */ + function _prep_query($sql) + { + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * getCursor. Returns a cursor from the datbase + * + * @access public + * @return cursor id + */ + function get_cursor() + { + return $this->curs_id = ocinewcursor($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Stored Procedure. Executes a stored procedure + * + * @access public + * @param package package stored procedure is in + * @param procedure stored procedure to execute + * @param params array of parameters + * @return array + * + * params array keys + * + * KEY OPTIONAL NOTES + * name no the name of the parameter should be in : format + * value no the value of the parameter. If this is an OUT or IN OUT parameter, + * this should be a reference to a variable + * type yes the type of the parameter + * length yes the max size of the parameter + */ + function stored_procedure($package, $procedure, $params) + { + if ($package == '' OR $procedure == '' OR ! is_array($params)) + { + if ($this->db_debug) + { + log_message('error', 'Invalid query: '.$package.'.'.$procedure); + return $this->display_error('db_invalid_query'); + } + return FALSE; + } + + // build the query string + $sql = "begin $package.$procedure("; + + $have_cursor = FALSE; + foreach($params as $param) + { + $sql .= $param['name'] . ","; + + if (array_key_exists('type', $param) && ($param['type'] == OCI_B_CURSOR)) + { + $have_cursor = TRUE; + } + } + $sql = trim($sql, ",") . "); end;"; + + $this->stmt_id = FALSE; + $this->_set_stmt_id($sql); + $this->_bind_params($params); + $this->query($sql, FALSE, $have_cursor); + } + + // -------------------------------------------------------------------- + + /** + * Bind parameters + * + * @access private + * @return none + */ + function _bind_params($params) + { + if ( ! is_array($params) OR ! is_resource($this->stmt_id)) + { + return; + } + + foreach ($params as $param) + { + foreach (array('name', 'value', 'type', 'length') as $val) + { + if ( ! isset($param[$val])) + { + $param[$val] = ''; + } + } + + ocibindbyname($this->stmt_id, $param['name'], $param['value'], $param['length'], $param['type']); + } + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @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) + { + return TRUE; + } + + // Reset the transaction failure flag. + // 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->_commit = OCI_DEFAULT; + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @access public + * @return bool + */ + function trans_commit() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $ret = OCIcommit($this->conn_id); + $this->_commit = OCI_COMMIT_ON_SUCCESS; + return $ret; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @access public + * @return bool + */ + function trans_rollback() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $ret = OCIrollback($this->conn_id); + $this->_commit = OCI_COMMIT_ON_SUCCESS; + return $ret; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @ocirowcount($this->stmt_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + // not supported in oracle + return 0; + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + return '0'; + + $query = $this->query("SELECT COUNT(1) AS numrows FROM ".$table); + + if ($query == FALSE) + { + return 0; + } + + $row = $query->row(); + return $row->NUMROWS; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + $error = ocierror($this->conn_id); + return $error['message']; + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + $error = ocierror($this->conn_id); + return $error['code']; + } + + // -------------------------------------------------------------------- + + /** + * Escape Table Name + * + * This function adds backticks if the table name has a period + * in it. Some DBs will get cranky unless periods are escaped + * + * @access public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $table; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + $sql = "SELECT * FROM ".$this->escape_table($table)." where rownum = 1"; + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @return string + */ + function _update($table, $values, $where) + { + foreach($values as $key => $val) + { + $valstr[] = $key." = ".$val; + } + + return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + $ver = ociserverversion($this->conn_id); + return $ver; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "select TABLE_NAME FROM ALL_TABLES"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _show_columns($table = '') + { + return "SELECT COLUMN_NAME FROM all_tab_columns WHERE table_name = '$table'"; + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + $limit = $offset + $limit; + $newsql = "SELECT * FROM (select inner_query.*, rownum rnum FROM ($sql) inner_query WHERE rownum < $limit)"; + + if ($offset != 0) + { + $newsql .= " WHERE rnum >= $offset"; + } + + // remember that we used limits + $this->limit_used = TRUE; + + return $newsql; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + ocilogoff($conn_id); + } + +} + + +?> \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php new file mode 100644 index 000000000..d2354a1c6 --- /dev/null +++ b/system/database/drivers/oci8/oci8_result.php @@ -0,0 +1,207 @@ +result_array(); + $rowcount = count($this->result_array); + @ociexecute($this->stmt_id); + if ($this->curs_id) + { + @ociexecute($this->curs_id); + } + return $rowcount; + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + $count = @ocinumcols($this->stmt_id); + + // if we used a limit, we added a field, + // subtract it out + if ($this->limit_used) + { + $count = $count - 1; + } + + return $count; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + $fieldCount = $this->num_fields(); + for ($c = 1; $c <= $fieldCount; $c++) + { + $F = new stdClass(); + $F->name = ocicolumnname($this->stmt_id, $c); + $F->type = ocicolumntype($this->stmt_id, $c); + $F->max_length = ocicolumnsize($this->stmt_id, $c); + + $retval[] = $F; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return null + */ + function free_result() + { + if (is_resource($this->result_id)) + { + OCIFreeStatement($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @access private + * @return array + */ + function _fetch_assoc(&$row) + { + // if pulling from a cursor, use curs_id + if ($this->curs_id) + { + return ocifetchinto($this->curs_id, $row, OCI_ASSOC + OCI_RETURN_NULLS); + } + else + { + return ocifetchinto($this->stmt_id, $row, OCI_ASSOC + OCI_RETURN_NULLS); + } + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + function _fetch_object() + { + // the PHP 4 version of the oracle functions do not + // have a fetch method so we call the array version + // and build an object from that + + $row = array(); + $res = $this->_fetch_assoc($row); + if ($res != FALSE) + { + $obj = new stdClass(); + foreach ($row as $key => $value) + { + $obj->{$key} = $value; + } + + $res = $obj; + } + return $res; + } + + /** + * Query result. "array" version. + * + * @access public + * @return array + */ + function result_array() + { + if (count($this->result_array) > 0) + { + return $this->result_array; + } + + // oracle's fetch functions do not + // return arrays, the information + // is returned in reference parameters + // + $row = NULL; + while ($this->_fetch_assoc($row)) + { + $this->result_array[] = $row; + } + + if (count($this->result_array) == 0) + { + return FALSE; + } + + return $this->result_array; + } + +} + +?> \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php new file mode 100644 index 000000000..f1e327a3e --- /dev/null +++ b/system/database/drivers/oci8/oci8_utility.php @@ -0,0 +1,41 @@ + \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc.php b/system/database/drivers/odbc/odbc.php new file mode 100644 index 000000000..ea311e590 --- /dev/null +++ b/system/database/drivers/odbc/odbc.php @@ -0,0 +1,454 @@ +database, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return odbc_pconnect($this->database, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + // Not needed for ODBC + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + function _execute($sql) + { + $sql = $this->_prep_query($sql); + return @odbc_exec($this->conn_id, $sql); + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @access private called by execute() + * @param string an SQL query + * @return string + */ + function _prep_query($sql) + { + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @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) + { + return TRUE; + } + + // Reset the transaction failure flag. + // 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; + + return odbc_autocommit($this->conn_id, FALSE); + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @access public + * @return bool + */ + function trans_commit() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $ret = odbc_commit($this->conn_id); + odbc_autocommit($this->conn_id, TRUE); + return $ret; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @access public + * @return bool + */ + function trans_rollback() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $ret = odbc_rollback($this->conn_id); + odbc_autocommit($this->conn_id, TRUE); + return $ret; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + // ODBC doesn't require escaping + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @odbc_num_rows($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + return @odbc_insert_id($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + return '0'; + + $query = $this->query("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + return odbc_errormsg($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + return odbc_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Escape Table Name + * + * This function adds backticks if the table name has a period + * in it. Some DBs will get cranky unless periods are escaped + * + * @access public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $table; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + $sql = "SELECT TOP 1 FROM ".$this->escape_table($table); + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @return string + */ + function _update($table, $values, $where) + { + foreach($values as $key => $val) + { + $valstr[] = $key." = ".$val; + } + + return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SHOW TABLES FROM `".$this->database."`"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _show_columns($table = '') + { + return "SHOW COLUMNS FROM ".$this->escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + // Does ODBC doesn't use the LIMIT clause? + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + odbc_close($conn_id); + } + +} + + +?> \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php new file mode 100644 index 000000000..49e5e9012 --- /dev/null +++ b/system/database/drivers/odbc/odbc_result.php @@ -0,0 +1,190 @@ +result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @odbc_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + for ($i = 0; $i < $this->num_fields(); $i++) + { + $F = new stdClass(); + $F->name = odbc_field_name($this->result_id, $i); + $F->type = odbc_field_type($this->result_id, $i); + $F->max_length = odbc_field_len($this->result_id, $i); + $F->primary_key = 0; + $F->default = ''; + + $retval[] = $F; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return null + */ + function free_result() + { + if (is_resource($this->result_id)) + { + odbc_free_result($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @access private + * @return array + */ + function _fetch_assoc() + { + if (function_exists('odbc_fetch_object')) + { + return odbc_fetch_array($this->result_id); + } + else + { + return $this->_odbc_fetch_array($this->result_id); + } + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + function _fetch_object() + { + if (function_exists('odbc_fetch_object')) + { + return odbc_fetch_object($this->result_id); + } + else + { + return $this->_odbc_fetch_object($this->result_id); + } + } + + + /** + * Result - object + * + * subsititutes the odbc_fetch_object function when + * not available (odbc_fetch_object requires unixODBC) + * + * @access private + * @return object + */ + + function _odbc_fetch_object(& $odbc_result) { + $rs = array(); + $rs_obj = false; + if (odbc_fetch_into($odbc_result, $rs)) { + foreach ($rs as $k=>$v) { + $field_name= odbc_field_name($odbc_result, $k+1); + $rs_obj->$field_name = $v; + } + } + return $rs_obj; + } + + + /** + * Result - array + * + * subsititutes the odbc_fetch_array function when + * not available (odbc_fetch_array requires unixODBC) + * + * @access private + * @return array + */ + + function _odbc_fetch_array(& $odbc_result) { + $rs = array(); + $rs_assoc = false; + if (odbc_fetch_into($odbc_result, $rs)) { + $rs_assoc=array(); + foreach ($rs as $k=>$v) { + $field_name= odbc_field_name($odbc_result, $k+1); + $rs_assoc[$field_name] = $v; + } + } + return $rs_assoc; + } + +} + +?> \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php new file mode 100644 index 000000000..f2b5602cc --- /dev/null +++ b/system/database/drivers/odbc/odbc_utility.php @@ -0,0 +1,41 @@ + \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre.php b/system/database/drivers/postgre/postgre.php new file mode 100644 index 000000000..317df37d1 --- /dev/null +++ b/system/database/drivers/postgre/postgre.php @@ -0,0 +1,484 @@ +port == '') ? '' : " port=".$this->port; + + return pg_connect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + $port = ($this->port == '') ? '' : " port=".$this->port; + + return pg_pconnect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + // Not needed for Postgre so we'll return TRUE + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + function _execute($sql) + { + $sql = $this->_prep_query($sql); + return @pg_query($this->conn_id, $sql); + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @access private called by execute() + * @param string an SQL query + * @return string + */ + function _prep_query($sql) + { + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @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) + { + return TRUE; + } + + // Reset the transaction failure flag. + // 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; + + return @pg_exec($this->conn_id, "begin"); + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @access public + * @return bool + */ + function trans_commit() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + return @pg_exec($this->conn_id, "commit"); + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @access public + * @return bool + */ + function trans_rollback() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + return @pg_exec($this->conn_id, "rollback"); + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + return pg_escape_string($str); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @pg_affected_rows($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + $v = pg_version($this->conn_id); + $v = $v['server']; + + $table = func_num_args() > 0 ? func_get_arg(0) : null; + $column = func_num_args() > 1 ? func_get_arg(1) : null; + + if ($table == null && $v >= '8.1') + { + $sql='SELECT LASTVAL() as ins_id'; + } + elseif ($table != null && $column != null && $v >= '8.0') + { + $sql = sprintf("SELECT pg_get_serial_sequence('%s','%s') as seq", $table, $column); + $query = $this->query($sql); + $row = $query->row(); + $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $row->seq); + } + elseif ($table != null) + { + // seq_name passed in table parameter + $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $table); + } + else + { + return pg_last_oid($this->result_id); + } + $query = $this->query($sql); + $row = $query->row(); + return $row->ins_id; + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + return '0'; + + $query = $this->query('SELECT COUNT(*) AS numrows FROM "'.$this->dbprefix.$table.'"'); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + return pg_last_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + return ''; + } + + // -------------------------------------------------------------------- + + /** + * Escape Table Name + * + * This function adds backticks if the table name has a period + * in it. Some DBs will get cranky unless periods are escaped. + * + * @access public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = '"'.preg_replace("/\./", '"."', $table).'"'; + } + + return $table; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @return string + */ + function _update($table, $values, $where) + { + foreach($values as $key => $val) + { + $valstr[] = $key." = ".$val; + } + + return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _show_columns($table = '') + { + return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->escape_table($table)."'"; + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + $sql .= "LIMIT ".$limit; + + if ($offset > 0) + { + $sql .= " OFFSET ".$offset; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + pg_close($conn_id); + } + +} + +?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php new file mode 100644 index 000000000..6af7f94f2 --- /dev/null +++ b/system/database/drivers/postgre/postgre_result.php @@ -0,0 +1,129 @@ +result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @pg_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + for ($i = 0; $i < $this->num_fields(); $i++) + { + $F = new stdClass(); + $F->name = pg_field_name($this->result_id, $i); + $F->type = pg_field_type($this->result_id, $i); + $F->max_length = pg_field_size($this->result_id, $i); + $F->primary_key = $i == 0; + $F->default = ''; + + $retval[] = $F; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return null + */ + function free_result() + { + if (is_resource($this->result_id)) + { + pg_free_result($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @access private + * @return array + */ + function _fetch_assoc() + { + return pg_fetch_assoc($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + function _fetch_object() + { + return pg_fetch_object($this->result_id); + } + +} + +?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php new file mode 100644 index 000000000..760be81a0 --- /dev/null +++ b/system/database/drivers/postgre/postgre_utility.php @@ -0,0 +1,41 @@ + \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite.php b/system/database/drivers/sqlite/sqlite.php new file mode 100644 index 000000000..6116a84ab --- /dev/null +++ b/system/database/drivers/sqlite/sqlite.php @@ -0,0 +1,481 @@ +database, 0666, $error)) + { + log_message('error', $error); + + if ($this->db_debug) + { + $this->display_error($error, '', TRUE); + } + } + + return $conn_id; + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + if ( ! $conn_id = sqlite_popen($this->database, 0666, $error)) + { + log_message('error', $error); + + if ($this->db_debug) + { + $this->display_error($error, '', TRUE); + } + } + + return $conn_id; + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + function _execute($sql) + { + $sql = $this->_prep_query($sql); + return @sqlite_query($this->conn_id, $sql); + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @access private called by execute() + * @param string an SQL query + * @return string + */ + function _prep_query($sql) + { + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @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) + { + return TRUE; + } + + // Reset the transaction failure flag. + // 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('BEGIN TRANSACTION'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @access public + * @return bool + */ + function trans_commit() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $this->simple_query('COMMIT'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @access public + * @return bool + */ + function trans_rollback() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $this->simple_query('ROLLBACK'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + return sqlite_escape_string($str); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return sqlite_changes($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + return @sqlite_last_insert_rowid($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + return '0'; + + $query = $this->query("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + return sqlite_error_string(sqlite_last_error($this->conn_id)); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + return sqlite_last_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function version() + { + return sqlite_libversion(); + } + + // -------------------------------------------------------------------- + + /** + * Escape Table Name + * + * This function adds backticks if the table name has a period + * in it. Some DBs will get cranky unless periods are escaped + * + * @access public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $table; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @return string + */ + function _update($table, $values, $where) + { + foreach($values as $key => $val) + { + $valstr[] = $key." = ".$val; + } + + return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SELECT name from sqlite_master WHERE type='table'"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _show_columns($table = '') + { + // Not supported + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + if ($offset == 0) + { + $offset = ''; + } + else + { + $offset .= ", "; + } + + return $sql."LIMIT ".$offset.$limit; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + sqlite_close($conn_id); + } + +} + +?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php new file mode 100644 index 000000000..f30a8cfdf --- /dev/null +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -0,0 +1,132 @@ +result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @sqlite_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + for ($i = 0; $i < $this->num_fields(); $i++) + { + $F = new stdClass(); + $F->name = sqlite_field_name($this->result_id, $i); + $F->type = 'varchar'; + $F->max_length = 0; + $F->primary_key = 0; + $F->default = ''; + + $retval[] = $F; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return null + */ + function free_result() + { + // Not implemented in SQLite + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @access private + * @return array + */ + function _fetch_assoc() + { + return sqlite_fetch_array($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + function _fetch_object() + { + if (function_exists('sqlite_fetch_object')) + { + return sqlite_fetch_object($this->result_id); + } + else + { + return $this->_fetch_assoc(); + } + } + +} + +?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php new file mode 100644 index 000000000..3cbec6f14 --- /dev/null +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -0,0 +1,41 @@ + \ No newline at end of file diff --git a/system/database/index.html b/system/database/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/database/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From ea8ca450f5fad9cf3820a6a63cb9a5cc53a357ef Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 18:11:44 +0000 Subject: --- system/database/drivers/mssql/mssql_driver.php | 457 +++++++++++++++++++++++++ 1 file changed, 457 insertions(+) create mode 100644 system/database/drivers/mssql/mssql_driver.php (limited to 'system/database') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php new file mode 100644 index 000000000..4f668f282 --- /dev/null +++ b/system/database/drivers/mssql/mssql_driver.php @@ -0,0 +1,457 @@ +hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return mssql_pconnect($this->hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return @mssql_select_db($this->database, $this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + function _execute($sql) + { + $sql = $this->_prep_query($sql); + return @mssql_query($sql, $this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @access private called by execute() + * @param string an SQL query + * @return string + */ + function _prep_query($sql) + { + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @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) + { + return TRUE; + } + + // Reset the transaction failure flag. + // 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('BEGIN TRAN'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @access public + * @return bool + */ + function trans_commit() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $this->simple_query('COMMIT TRAN'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @access public + * @return bool + */ + function trans_rollback() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $this->simple_query('ROLLBACK TRAN'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + // Escape single quotes + return str_replace("'", "''", $str); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @mssql_rows_affected($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + // Not supported in MS SQL? + return 0; + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + return '0'; + + $query = $this->query("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + // Are errros even supported in MS SQL? + return ''; + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + // Are error numbers supported? + return ''; + } + + // -------------------------------------------------------------------- + + /** + * Escape Table Name + * + * This function adds backticks if the table name has a period + * in it. Some DBs will get cranky unless periods are escaped + * + * @access public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $table; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + $sql = "SELECT TOP 1 FROM ".$this->escape_table($table); + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @return string + */ + function _update($table, $values, $where) + { + foreach($values as $key => $val) + { + $valstr[] = $key." = ".$val; + } + + return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _show_columns($table = '') + { + return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$this->escape_table($table)."'"; + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + $i = $limit + $offset; + + return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql); + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + mssql_close($conn_id); + } + + +} + + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 046000bed008ff2031414aba71741595f808cf1e Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 18:12:07 +0000 Subject: --- system/database/drivers/mysql/mysql_driver.php | 478 +++++++++++++++++++++++++ 1 file changed, 478 insertions(+) create mode 100644 system/database/drivers/mysql/mysql_driver.php (limited to 'system/database') diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php new file mode 100644 index 000000000..8aa82da72 --- /dev/null +++ b/system/database/drivers/mysql/mysql_driver.php @@ -0,0 +1,478 @@ +hostname, $this->username, $this->password, TRUE); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return mysql_pconnect($this->hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return @mysql_select_db($this->database, $this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @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); + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @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 + // the query so that it returns the number of affected rows + if ($this->delete_hack === TRUE) + { + if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql)) + { + $sql = preg_replace("/^\s*DELETE\s+FROM\s+(\S+)\s*$/", "DELETE FROM \\1 WHERE 1=1", $sql); + } + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @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) + { + return TRUE; + } + + // Reset the transaction failure flag. + // 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; + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @access public + * @return bool + */ + function trans_commit() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $this->simple_query('COMMIT'); + $this->simple_query('SET AUTOCOMMIT=1'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @access public + * @return bool + */ + function trans_rollback() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $this->simple_query('ROLLBACK'); + $this->simple_query('SET AUTOCOMMIT=1'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + return mysql_real_escape_string($str); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @mysql_affected_rows($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + return @mysql_insert_id($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + return '0'; + + $query = $this->query("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + return mysql_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + return mysql_errno($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Escape Table Name + * + * This function adds backticks if the table name has a period + * in it. Some DBs will get cranky unless periods are escaped + * + * @access public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $table; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @return string + */ + function _update($table, $values, $where) + { + foreach($values as $key => $val) + { + $valstr[] = $key." = ".$val; + } + + return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SHOW TABLES FROM `".$this->database."`"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _show_columns($table = '') + { + return "SHOW COLUMNS FROM ".$this->escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + if ($offset == 0) + { + $offset = ''; + } + else + { + $offset .= ", "; + } + + return $sql."LIMIT ".$offset.$limit; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + mysql_close($conn_id); + } + +} + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From ff2d2514937ee2a153ebcc26acfc00d44ba4d7ce Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 18:12:18 +0000 Subject: --- system/database/drivers/mysqli/mysqli_driver.php | 479 +++++++++++++++++++++++ 1 file changed, 479 insertions(+) create mode 100644 system/database/drivers/mysqli/mysqli_driver.php (limited to 'system/database') diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php new file mode 100644 index 000000000..8d28c2c5f --- /dev/null +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -0,0 +1,479 @@ +hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return $this->db_connect(); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return @mysqli_select_db($this->conn_id, $this->database); + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + function _execute($sql) + { + $sql = $this->_prep_query($sql); + $result = @mysqli_query($this->conn_id, $sql); + return $result; + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @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 + // the query so that it returns the number of affected rows + if ($this->delete_hack === TRUE) + { + if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql)) + { + $sql = preg_replace("/^\s*DELETE\s+FROM\s+(\S+)\s*$/", "DELETE FROM \\1 WHERE 1=1", $sql); + } + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @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) + { + return TRUE; + } + + // Reset the transaction failure flag. + // 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; + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @access public + * @return bool + */ + function trans_commit() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $this->simple_query('COMMIT'); + $this->simple_query('SET AUTOCOMMIT=1'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @access public + * @return bool + */ + function trans_rollback() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $this->simple_query('ROLLBACK'); + $this->simple_query('SET AUTOCOMMIT=1'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + return mysqli_real_escape_string($this->conn_id, $str); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @mysqli_affected_rows($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + return @mysqli_insert_id($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + return '0'; + + $query = $this->query("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + return mysqli_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + return mysqli_errno($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Escape Table Name + * + * This function adds backticks if the table name has a period + * in it. Some DBs will get cranky unless periods are escaped + * + * @access public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $table; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @return string + */ + function _update($table, $values, $where) + { + foreach($values as $key => $val) + { + $valstr[] = $key." = ".$val; + } + + return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SHOW TABLES FROM `".$this->database."`"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _show_columns($table = '') + { + return "SHOW COLUMNS FROM ".$this->escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + $sql .= "LIMIT ".$limit; + + if ($offset > 0) + { + $sql .= " OFFSET ".$offset; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + mysqli_close($conn_id); + } + +} + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 99e1b29f1308e8d6c5faa84246e5be5fa93ef5aa Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 18:12:43 +0000 Subject: --- system/database/drivers/oci8/oci8_driver.php | 608 +++++++++++++++++++++++++++ 1 file changed, 608 insertions(+) create mode 100644 system/database/drivers/oci8/oci8_driver.php (limited to 'system/database') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php new file mode 100644 index 000000000..707394d53 --- /dev/null +++ b/system/database/drivers/oci8/oci8_driver.php @@ -0,0 +1,608 @@ +username, $this->password, $this->hostname); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return ociplogon($this->username, $this->password, $this->hostname); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + function _execute($sql) + { + // oracle must parse the query before it + // is run, all of the actions with + // the query are based off the statement id + // returned by ociparse + $this->_set_stmt_id($sql); + ocisetprefetch($this->stmt_id, 1000); + return @ociexecute($this->stmt_id, $this->_commit); + } + + /** + * Generate a statement ID + * + * @access private + * @param string an SQL query + * @return none + */ + function _set_stmt_id($sql) + { + if ( ! is_resource($this->stmt_id)) + { + $this->stmt_id = ociparse($this->conn_id, $this->_prep_query($sql)); + } + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @access private called by execute() + * @param string an SQL query + * @return string + */ + function _prep_query($sql) + { + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * getCursor. Returns a cursor from the datbase + * + * @access public + * @return cursor id + */ + function get_cursor() + { + return $this->curs_id = ocinewcursor($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Stored Procedure. Executes a stored procedure + * + * @access public + * @param package package stored procedure is in + * @param procedure stored procedure to execute + * @param params array of parameters + * @return array + * + * params array keys + * + * KEY OPTIONAL NOTES + * name no the name of the parameter should be in : format + * value no the value of the parameter. If this is an OUT or IN OUT parameter, + * this should be a reference to a variable + * type yes the type of the parameter + * length yes the max size of the parameter + */ + function stored_procedure($package, $procedure, $params) + { + if ($package == '' OR $procedure == '' OR ! is_array($params)) + { + if ($this->db_debug) + { + log_message('error', 'Invalid query: '.$package.'.'.$procedure); + return $this->display_error('db_invalid_query'); + } + return FALSE; + } + + // build the query string + $sql = "begin $package.$procedure("; + + $have_cursor = FALSE; + foreach($params as $param) + { + $sql .= $param['name'] . ","; + + if (array_key_exists('type', $param) && ($param['type'] == OCI_B_CURSOR)) + { + $have_cursor = TRUE; + } + } + $sql = trim($sql, ",") . "); end;"; + + $this->stmt_id = FALSE; + $this->_set_stmt_id($sql); + $this->_bind_params($params); + $this->query($sql, FALSE, $have_cursor); + } + + // -------------------------------------------------------------------- + + /** + * Bind parameters + * + * @access private + * @return none + */ + function _bind_params($params) + { + if ( ! is_array($params) OR ! is_resource($this->stmt_id)) + { + return; + } + + foreach ($params as $param) + { + foreach (array('name', 'value', 'type', 'length') as $val) + { + if ( ! isset($param[$val])) + { + $param[$val] = ''; + } + } + + ocibindbyname($this->stmt_id, $param['name'], $param['value'], $param['length'], $param['type']); + } + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @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) + { + return TRUE; + } + + // Reset the transaction failure flag. + // 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->_commit = OCI_DEFAULT; + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @access public + * @return bool + */ + function trans_commit() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $ret = OCIcommit($this->conn_id); + $this->_commit = OCI_COMMIT_ON_SUCCESS; + return $ret; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @access public + * @return bool + */ + function trans_rollback() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $ret = OCIrollback($this->conn_id); + $this->_commit = OCI_COMMIT_ON_SUCCESS; + return $ret; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @ocirowcount($this->stmt_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + // not supported in oracle + return 0; + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + return '0'; + + $query = $this->query("SELECT COUNT(1) AS numrows FROM ".$table); + + if ($query == FALSE) + { + return 0; + } + + $row = $query->row(); + return $row->NUMROWS; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + $error = ocierror($this->conn_id); + return $error['message']; + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + $error = ocierror($this->conn_id); + return $error['code']; + } + + // -------------------------------------------------------------------- + + /** + * Escape Table Name + * + * This function adds backticks if the table name has a period + * in it. Some DBs will get cranky unless periods are escaped + * + * @access public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $table; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + $sql = "SELECT * FROM ".$this->escape_table($table)." where rownum = 1"; + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @return string + */ + function _update($table, $values, $where) + { + foreach($values as $key => $val) + { + $valstr[] = $key." = ".$val; + } + + return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + $ver = ociserverversion($this->conn_id); + return $ver; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "select TABLE_NAME FROM ALL_TABLES"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _show_columns($table = '') + { + return "SELECT COLUMN_NAME FROM all_tab_columns WHERE table_name = '$table'"; + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + $limit = $offset + $limit; + $newsql = "SELECT * FROM (select inner_query.*, rownum rnum FROM ($sql) inner_query WHERE rownum < $limit)"; + + if ($offset != 0) + { + $newsql .= " WHERE rnum >= $offset"; + } + + // remember that we used limits + $this->limit_used = TRUE; + + return $newsql; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + ocilogoff($conn_id); + } + +} + + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 0d0116910ea060f08f69db4af0c474d7fcbf9802 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 18:12:58 +0000 Subject: --- system/database/drivers/odbc/odbc_driver.php | 454 +++++++++++++++++++++++++++ 1 file changed, 454 insertions(+) create mode 100644 system/database/drivers/odbc/odbc_driver.php (limited to 'system/database') diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php new file mode 100644 index 000000000..1725ed743 --- /dev/null +++ b/system/database/drivers/odbc/odbc_driver.php @@ -0,0 +1,454 @@ +database, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return odbc_pconnect($this->database, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + // Not needed for ODBC + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + function _execute($sql) + { + $sql = $this->_prep_query($sql); + return @odbc_exec($this->conn_id, $sql); + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @access private called by execute() + * @param string an SQL query + * @return string + */ + function _prep_query($sql) + { + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @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) + { + return TRUE; + } + + // Reset the transaction failure flag. + // 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; + + return odbc_autocommit($this->conn_id, FALSE); + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @access public + * @return bool + */ + function trans_commit() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $ret = odbc_commit($this->conn_id); + odbc_autocommit($this->conn_id, TRUE); + return $ret; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @access public + * @return bool + */ + function trans_rollback() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $ret = odbc_rollback($this->conn_id); + odbc_autocommit($this->conn_id, TRUE); + return $ret; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + // ODBC doesn't require escaping + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @odbc_num_rows($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + return @odbc_insert_id($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + return '0'; + + $query = $this->query("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + return odbc_errormsg($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + return odbc_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Escape Table Name + * + * This function adds backticks if the table name has a period + * in it. Some DBs will get cranky unless periods are escaped + * + * @access public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $table; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + $sql = "SELECT TOP 1 FROM ".$this->escape_table($table); + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @return string + */ + function _update($table, $values, $where) + { + foreach($values as $key => $val) + { + $valstr[] = $key." = ".$val; + } + + return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SHOW TABLES FROM `".$this->database."`"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _show_columns($table = '') + { + return "SHOW COLUMNS FROM ".$this->escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + // Does ODBC doesn't use the LIMIT clause? + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + odbc_close($conn_id); + } + +} + + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 7eea4f8906c21c1061cc9f21100e5597aae648b9 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 18:13:17 +0000 Subject: --- system/database/drivers/postgre/postgre_driver.php | 484 +++++++++++++++++++++ 1 file changed, 484 insertions(+) create mode 100644 system/database/drivers/postgre/postgre_driver.php (limited to 'system/database') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php new file mode 100644 index 000000000..92767c42b --- /dev/null +++ b/system/database/drivers/postgre/postgre_driver.php @@ -0,0 +1,484 @@ +port == '') ? '' : " port=".$this->port; + + return pg_connect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + $port = ($this->port == '') ? '' : " port=".$this->port; + + return pg_pconnect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + // Not needed for Postgre so we'll return TRUE + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + function _execute($sql) + { + $sql = $this->_prep_query($sql); + return @pg_query($this->conn_id, $sql); + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @access private called by execute() + * @param string an SQL query + * @return string + */ + function _prep_query($sql) + { + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @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) + { + return TRUE; + } + + // Reset the transaction failure flag. + // 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; + + return @pg_exec($this->conn_id, "begin"); + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @access public + * @return bool + */ + function trans_commit() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + return @pg_exec($this->conn_id, "commit"); + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @access public + * @return bool + */ + function trans_rollback() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + return @pg_exec($this->conn_id, "rollback"); + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + return pg_escape_string($str); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @pg_affected_rows($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + $v = pg_version($this->conn_id); + $v = $v['server']; + + $table = func_num_args() > 0 ? func_get_arg(0) : null; + $column = func_num_args() > 1 ? func_get_arg(1) : null; + + if ($table == null && $v >= '8.1') + { + $sql='SELECT LASTVAL() as ins_id'; + } + elseif ($table != null && $column != null && $v >= '8.0') + { + $sql = sprintf("SELECT pg_get_serial_sequence('%s','%s') as seq", $table, $column); + $query = $this->query($sql); + $row = $query->row(); + $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $row->seq); + } + elseif ($table != null) + { + // seq_name passed in table parameter + $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $table); + } + else + { + return pg_last_oid($this->result_id); + } + $query = $this->query($sql); + $row = $query->row(); + return $row->ins_id; + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + return '0'; + + $query = $this->query('SELECT COUNT(*) AS numrows FROM "'.$this->dbprefix.$table.'"'); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + return pg_last_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + return ''; + } + + // -------------------------------------------------------------------- + + /** + * Escape Table Name + * + * This function adds backticks if the table name has a period + * in it. Some DBs will get cranky unless periods are escaped. + * + * @access public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = '"'.preg_replace("/\./", '"."', $table).'"'; + } + + return $table; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @return string + */ + function _update($table, $values, $where) + { + foreach($values as $key => $val) + { + $valstr[] = $key." = ".$val; + } + + return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _show_columns($table = '') + { + return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->escape_table($table)."'"; + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + $sql .= "LIMIT ".$limit; + + if ($offset > 0) + { + $sql .= " OFFSET ".$offset; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + pg_close($conn_id); + } + +} + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 46537628a0b319387367fc661478740a7393be8d Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 18:13:49 +0000 Subject: --- system/database/drivers/sqlite/sqlite_driver.php | 481 +++++++++++++++++++++++ 1 file changed, 481 insertions(+) create mode 100644 system/database/drivers/sqlite/sqlite_driver.php (limited to 'system/database') diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php new file mode 100644 index 000000000..634b72ed4 --- /dev/null +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -0,0 +1,481 @@ +database, 0666, $error)) + { + log_message('error', $error); + + if ($this->db_debug) + { + $this->display_error($error, '', TRUE); + } + } + + return $conn_id; + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + if ( ! $conn_id = sqlite_popen($this->database, 0666, $error)) + { + log_message('error', $error); + + if ($this->db_debug) + { + $this->display_error($error, '', TRUE); + } + } + + return $conn_id; + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + function _execute($sql) + { + $sql = $this->_prep_query($sql); + return @sqlite_query($this->conn_id, $sql); + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @access private called by execute() + * @param string an SQL query + * @return string + */ + function _prep_query($sql) + { + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @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) + { + return TRUE; + } + + // Reset the transaction failure flag. + // 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('BEGIN TRANSACTION'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @access public + * @return bool + */ + function trans_commit() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $this->simple_query('COMMIT'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @access public + * @return bool + */ + function trans_rollback() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $this->simple_query('ROLLBACK'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + return sqlite_escape_string($str); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return sqlite_changes($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + return @sqlite_last_insert_rowid($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + return '0'; + + $query = $this->query("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + return sqlite_error_string(sqlite_last_error($this->conn_id)); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + return sqlite_last_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function version() + { + return sqlite_libversion(); + } + + // -------------------------------------------------------------------- + + /** + * Escape Table Name + * + * This function adds backticks if the table name has a period + * in it. Some DBs will get cranky unless periods are escaped + * + * @access public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $table; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @return string + */ + function _update($table, $values, $where) + { + foreach($values as $key => $val) + { + $valstr[] = $key." = ".$val; + } + + return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SELECT name from sqlite_master WHERE type='table'"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _show_columns($table = '') + { + // Not supported + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + if ($offset == 0) + { + $offset = ''; + } + else + { + $offset .= ", "; + } + + return $sql."LIMIT ".$offset.$limit; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + sqlite_close($conn_id); + } + +} + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 46563d570944d6c5af8b4f46ba1eeca111eabaa4 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 18:14:22 +0000 Subject: --- system/database/drivers/mssql/mssql.php | 457 --------------------- system/database/drivers/mysql/mysql.php | 478 ---------------------- system/database/drivers/mysqli/mysqli.php | 479 ---------------------- system/database/drivers/oci8/oci8.php | 608 ---------------------------- system/database/drivers/odbc/odbc.php | 454 --------------------- system/database/drivers/postgre/postgre.php | 484 ---------------------- system/database/drivers/sqlite/sqlite.php | 481 ---------------------- 7 files changed, 3441 deletions(-) delete mode 100644 system/database/drivers/mssql/mssql.php delete mode 100644 system/database/drivers/mysql/mysql.php delete mode 100644 system/database/drivers/mysqli/mysqli.php delete mode 100644 system/database/drivers/oci8/oci8.php delete mode 100644 system/database/drivers/odbc/odbc.php delete mode 100644 system/database/drivers/postgre/postgre.php delete mode 100644 system/database/drivers/sqlite/sqlite.php (limited to 'system/database') diff --git a/system/database/drivers/mssql/mssql.php b/system/database/drivers/mssql/mssql.php deleted file mode 100644 index 5f30bf905..000000000 --- a/system/database/drivers/mssql/mssql.php +++ /dev/null @@ -1,457 +0,0 @@ -hostname, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return mssql_pconnect($this->hostname, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - return @mssql_select_db($this->database, $this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return resource - */ - function _execute($sql) - { - $sql = $this->_prep_query($sql); - return @mssql_query($sql, $this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @access private called by execute() - * @param string an SQL query - * @return string - */ - function _prep_query($sql) - { - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @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) - { - return TRUE; - } - - // Reset the transaction failure flag. - // 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('BEGIN TRAN'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $this->simple_query('COMMIT TRAN'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $this->simple_query('ROLLBACK TRAN'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @return string - */ - function escape_str($str) - { - // Escape single quotes - return str_replace("'", "''", $str); - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @mssql_rows_affected($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - // Not supported in MS SQL? - return 0; - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - return '0'; - - $query = $this->query("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); - - if ($query->num_rows() == 0) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access public - * @return string - */ - function error_message() - { - // Are errros even supported in MS SQL? - return ''; - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access public - * @return integer - */ - function error_number() - { - // Are error numbers supported? - return ''; - } - - // -------------------------------------------------------------------- - - /** - * Escape Table Name - * - * This function adds backticks if the table name has a period - * in it. Some DBs will get cranky unless periods are escaped - * - * @access public - * @param string the table name - * @return string - */ - function escape_table($table) - { - if (stristr($table, '.')) - { - $table = preg_replace("/\./", "`.`", $table); - } - - return $table; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - $sql = "SELECT TOP 1 FROM ".$this->escape_table($table); - $query = $this->query($sql); - return $query->field_data(); - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @return string - */ - function _update($table, $values, $where) - { - foreach($values as $key => $val) - { - $valstr[] = $key." = ".$val; - } - - return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @return string - */ - function _delete($table, $where) - { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _show_columns($table = '') - { - return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$this->escape_table($table)."'"; - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - $i = $limit + $offset; - - return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql); - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - mssql_close($conn_id); - } - - -} - - -?> \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql.php b/system/database/drivers/mysql/mysql.php deleted file mode 100644 index 4d59f784d..000000000 --- a/system/database/drivers/mysql/mysql.php +++ /dev/null @@ -1,478 +0,0 @@ -hostname, $this->username, $this->password, TRUE); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return mysql_pconnect($this->hostname, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - return @mysql_select_db($this->database, $this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @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); - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @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 - // the query so that it returns the number of affected rows - if ($this->delete_hack === TRUE) - { - if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql)) - { - $sql = preg_replace("/^\s*DELETE\s+FROM\s+(\S+)\s*$/", "DELETE FROM \\1 WHERE 1=1", $sql); - } - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @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) - { - return TRUE; - } - - // Reset the transaction failure flag. - // 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; - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $this->simple_query('COMMIT'); - $this->simple_query('SET AUTOCOMMIT=1'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $this->simple_query('ROLLBACK'); - $this->simple_query('SET AUTOCOMMIT=1'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @return string - */ - function escape_str($str) - { - return mysql_real_escape_string($str); - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @mysql_affected_rows($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - return @mysql_insert_id($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - return '0'; - - $query = $this->query("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); - - if ($query->num_rows() == 0) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access public - * @return string - */ - function error_message() - { - return mysql_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access public - * @return integer - */ - function error_number() - { - return mysql_errno($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Escape Table Name - * - * This function adds backticks if the table name has a period - * in it. Some DBs will get cranky unless periods are escaped - * - * @access public - * @param string the table name - * @return string - */ - function escape_table($table) - { - if (stristr($table, '.')) - { - $table = preg_replace("/\./", "`.`", $table); - } - - return $table; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; - $query = $this->query($sql); - return $query->field_data(); - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @return string - */ - function _update($table, $values, $where) - { - foreach($values as $key => $val) - { - $valstr[] = $key." = ".$val; - } - - return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @return string - */ - function _delete($table, $where) - { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SHOW TABLES FROM `".$this->database."`"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _show_columns($table = '') - { - return "SHOW COLUMNS FROM ".$this->escape_table($table); - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - if ($offset == 0) - { - $offset = ''; - } - else - { - $offset .= ", "; - } - - return $sql."LIMIT ".$offset.$limit; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - mysql_close($conn_id); - } - -} - -?> \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli.php b/system/database/drivers/mysqli/mysqli.php deleted file mode 100644 index 6ca21c976..000000000 --- a/system/database/drivers/mysqli/mysqli.php +++ /dev/null @@ -1,479 +0,0 @@ -hostname, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return $this->db_connect(); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - return @mysqli_select_db($this->conn_id, $this->database); - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return resource - */ - function _execute($sql) - { - $sql = $this->_prep_query($sql); - $result = @mysqli_query($this->conn_id, $sql); - return $result; - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @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 - // the query so that it returns the number of affected rows - if ($this->delete_hack === TRUE) - { - if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql)) - { - $sql = preg_replace("/^\s*DELETE\s+FROM\s+(\S+)\s*$/", "DELETE FROM \\1 WHERE 1=1", $sql); - } - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @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) - { - return TRUE; - } - - // Reset the transaction failure flag. - // 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; - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $this->simple_query('COMMIT'); - $this->simple_query('SET AUTOCOMMIT=1'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $this->simple_query('ROLLBACK'); - $this->simple_query('SET AUTOCOMMIT=1'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @return string - */ - function escape_str($str) - { - return mysqli_real_escape_string($this->conn_id, $str); - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @mysqli_affected_rows($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - return @mysqli_insert_id($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - return '0'; - - $query = $this->query("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); - - if ($query->num_rows() == 0) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access public - * @return string - */ - function error_message() - { - return mysqli_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access public - * @return integer - */ - function error_number() - { - return mysqli_errno($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Escape Table Name - * - * This function adds backticks if the table name has a period - * in it. Some DBs will get cranky unless periods are escaped - * - * @access public - * @param string the table name - * @return string - */ - function escape_table($table) - { - if (stristr($table, '.')) - { - $table = preg_replace("/\./", "`.`", $table); - } - - return $table; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; - $query = $this->query($sql); - return $query->field_data(); - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @return string - */ - function _update($table, $values, $where) - { - foreach($values as $key => $val) - { - $valstr[] = $key." = ".$val; - } - - return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @return string - */ - function _delete($table, $where) - { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SHOW TABLES FROM `".$this->database."`"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _show_columns($table = '') - { - return "SHOW COLUMNS FROM ".$this->escape_table($table); - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - $sql .= "LIMIT ".$limit; - - if ($offset > 0) - { - $sql .= " OFFSET ".$offset; - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - mysqli_close($conn_id); - } - -} - -?> \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8.php b/system/database/drivers/oci8/oci8.php deleted file mode 100644 index 40aabcea7..000000000 --- a/system/database/drivers/oci8/oci8.php +++ /dev/null @@ -1,608 +0,0 @@ -username, $this->password, $this->hostname); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return ociplogon($this->username, $this->password, $this->hostname); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return resource - */ - function _execute($sql) - { - // oracle must parse the query before it - // is run, all of the actions with - // the query are based off the statement id - // returned by ociparse - $this->_set_stmt_id($sql); - ocisetprefetch($this->stmt_id, 1000); - return @ociexecute($this->stmt_id, $this->_commit); - } - - /** - * Generate a statement ID - * - * @access private - * @param string an SQL query - * @return none - */ - function _set_stmt_id($sql) - { - if ( ! is_resource($this->stmt_id)) - { - $this->stmt_id = ociparse($this->conn_id, $this->_prep_query($sql)); - } - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @access private called by execute() - * @param string an SQL query - * @return string - */ - function _prep_query($sql) - { - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * getCursor. Returns a cursor from the datbase - * - * @access public - * @return cursor id - */ - function get_cursor() - { - return $this->curs_id = ocinewcursor($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Stored Procedure. Executes a stored procedure - * - * @access public - * @param package package stored procedure is in - * @param procedure stored procedure to execute - * @param params array of parameters - * @return array - * - * params array keys - * - * KEY OPTIONAL NOTES - * name no the name of the parameter should be in : format - * value no the value of the parameter. If this is an OUT or IN OUT parameter, - * this should be a reference to a variable - * type yes the type of the parameter - * length yes the max size of the parameter - */ - function stored_procedure($package, $procedure, $params) - { - if ($package == '' OR $procedure == '' OR ! is_array($params)) - { - if ($this->db_debug) - { - log_message('error', 'Invalid query: '.$package.'.'.$procedure); - return $this->display_error('db_invalid_query'); - } - return FALSE; - } - - // build the query string - $sql = "begin $package.$procedure("; - - $have_cursor = FALSE; - foreach($params as $param) - { - $sql .= $param['name'] . ","; - - if (array_key_exists('type', $param) && ($param['type'] == OCI_B_CURSOR)) - { - $have_cursor = TRUE; - } - } - $sql = trim($sql, ",") . "); end;"; - - $this->stmt_id = FALSE; - $this->_set_stmt_id($sql); - $this->_bind_params($params); - $this->query($sql, FALSE, $have_cursor); - } - - // -------------------------------------------------------------------- - - /** - * Bind parameters - * - * @access private - * @return none - */ - function _bind_params($params) - { - if ( ! is_array($params) OR ! is_resource($this->stmt_id)) - { - return; - } - - foreach ($params as $param) - { - foreach (array('name', 'value', 'type', 'length') as $val) - { - if ( ! isset($param[$val])) - { - $param[$val] = ''; - } - } - - ocibindbyname($this->stmt_id, $param['name'], $param['value'], $param['length'], $param['type']); - } - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @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) - { - return TRUE; - } - - // Reset the transaction failure flag. - // 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->_commit = OCI_DEFAULT; - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $ret = OCIcommit($this->conn_id); - $this->_commit = OCI_COMMIT_ON_SUCCESS; - return $ret; - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $ret = OCIrollback($this->conn_id); - $this->_commit = OCI_COMMIT_ON_SUCCESS; - return $ret; - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @return string - */ - function escape_str($str) - { - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @ocirowcount($this->stmt_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - // not supported in oracle - return 0; - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - return '0'; - - $query = $this->query("SELECT COUNT(1) AS numrows FROM ".$table); - - if ($query == FALSE) - { - return 0; - } - - $row = $query->row(); - return $row->NUMROWS; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access public - * @return string - */ - function error_message() - { - $error = ocierror($this->conn_id); - return $error['message']; - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access public - * @return integer - */ - function error_number() - { - $error = ocierror($this->conn_id); - return $error['code']; - } - - // -------------------------------------------------------------------- - - /** - * Escape Table Name - * - * This function adds backticks if the table name has a period - * in it. Some DBs will get cranky unless periods are escaped - * - * @access public - * @param string the table name - * @return string - */ - function escape_table($table) - { - if (stristr($table, '.')) - { - $table = preg_replace("/\./", "`.`", $table); - } - - return $table; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - $sql = "SELECT * FROM ".$this->escape_table($table)." where rownum = 1"; - $query = $this->query($sql); - return $query->field_data(); - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @return string - */ - function _update($table, $values, $where) - { - foreach($values as $key => $val) - { - $valstr[] = $key." = ".$val; - } - - return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @return string - */ - function _delete($table, $where) - { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - $ver = ociserverversion($this->conn_id); - return $ver; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "select TABLE_NAME FROM ALL_TABLES"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _show_columns($table = '') - { - return "SELECT COLUMN_NAME FROM all_tab_columns WHERE table_name = '$table'"; - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - $limit = $offset + $limit; - $newsql = "SELECT * FROM (select inner_query.*, rownum rnum FROM ($sql) inner_query WHERE rownum < $limit)"; - - if ($offset != 0) - { - $newsql .= " WHERE rnum >= $offset"; - } - - // remember that we used limits - $this->limit_used = TRUE; - - return $newsql; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - ocilogoff($conn_id); - } - -} - - -?> \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc.php b/system/database/drivers/odbc/odbc.php deleted file mode 100644 index ea311e590..000000000 --- a/system/database/drivers/odbc/odbc.php +++ /dev/null @@ -1,454 +0,0 @@ -database, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return odbc_pconnect($this->database, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - // Not needed for ODBC - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return resource - */ - function _execute($sql) - { - $sql = $this->_prep_query($sql); - return @odbc_exec($this->conn_id, $sql); - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @access private called by execute() - * @param string an SQL query - * @return string - */ - function _prep_query($sql) - { - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @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) - { - return TRUE; - } - - // Reset the transaction failure flag. - // 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; - - return odbc_autocommit($this->conn_id, FALSE); - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $ret = odbc_commit($this->conn_id); - odbc_autocommit($this->conn_id, TRUE); - return $ret; - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $ret = odbc_rollback($this->conn_id); - odbc_autocommit($this->conn_id, TRUE); - return $ret; - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @return string - */ - function escape_str($str) - { - // ODBC doesn't require escaping - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @odbc_num_rows($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - return @odbc_insert_id($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - return '0'; - - $query = $this->query("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); - - if ($query->num_rows() == 0) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access public - * @return string - */ - function error_message() - { - return odbc_errormsg($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access public - * @return integer - */ - function error_number() - { - return odbc_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Escape Table Name - * - * This function adds backticks if the table name has a period - * in it. Some DBs will get cranky unless periods are escaped - * - * @access public - * @param string the table name - * @return string - */ - function escape_table($table) - { - if (stristr($table, '.')) - { - $table = preg_replace("/\./", "`.`", $table); - } - - return $table; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - $sql = "SELECT TOP 1 FROM ".$this->escape_table($table); - $query = $this->query($sql); - return $query->field_data(); - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @return string - */ - function _update($table, $values, $where) - { - foreach($values as $key => $val) - { - $valstr[] = $key." = ".$val; - } - - return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @return string - */ - function _delete($table, $where) - { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SHOW TABLES FROM `".$this->database."`"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _show_columns($table = '') - { - return "SHOW COLUMNS FROM ".$this->escape_table($table); - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - // Does ODBC doesn't use the LIMIT clause? - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - odbc_close($conn_id); - } - -} - - -?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre.php b/system/database/drivers/postgre/postgre.php deleted file mode 100644 index 317df37d1..000000000 --- a/system/database/drivers/postgre/postgre.php +++ /dev/null @@ -1,484 +0,0 @@ -port == '') ? '' : " port=".$this->port; - - return pg_connect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - $port = ($this->port == '') ? '' : " port=".$this->port; - - return pg_pconnect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - // Not needed for Postgre so we'll return TRUE - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return resource - */ - function _execute($sql) - { - $sql = $this->_prep_query($sql); - return @pg_query($this->conn_id, $sql); - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @access private called by execute() - * @param string an SQL query - * @return string - */ - function _prep_query($sql) - { - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @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) - { - return TRUE; - } - - // Reset the transaction failure flag. - // 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; - - return @pg_exec($this->conn_id, "begin"); - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - return @pg_exec($this->conn_id, "commit"); - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - return @pg_exec($this->conn_id, "rollback"); - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @return string - */ - function escape_str($str) - { - return pg_escape_string($str); - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @pg_affected_rows($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - $v = pg_version($this->conn_id); - $v = $v['server']; - - $table = func_num_args() > 0 ? func_get_arg(0) : null; - $column = func_num_args() > 1 ? func_get_arg(1) : null; - - if ($table == null && $v >= '8.1') - { - $sql='SELECT LASTVAL() as ins_id'; - } - elseif ($table != null && $column != null && $v >= '8.0') - { - $sql = sprintf("SELECT pg_get_serial_sequence('%s','%s') as seq", $table, $column); - $query = $this->query($sql); - $row = $query->row(); - $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $row->seq); - } - elseif ($table != null) - { - // seq_name passed in table parameter - $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $table); - } - else - { - return pg_last_oid($this->result_id); - } - $query = $this->query($sql); - $row = $query->row(); - return $row->ins_id; - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - return '0'; - - $query = $this->query('SELECT COUNT(*) AS numrows FROM "'.$this->dbprefix.$table.'"'); - - if ($query->num_rows() == 0) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access public - * @return string - */ - function error_message() - { - return pg_last_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access public - * @return integer - */ - function error_number() - { - return ''; - } - - // -------------------------------------------------------------------- - - /** - * Escape Table Name - * - * This function adds backticks if the table name has a period - * in it. Some DBs will get cranky unless periods are escaped. - * - * @access public - * @param string the table name - * @return string - */ - function escape_table($table) - { - if (stristr($table, '.')) - { - $table = '"'.preg_replace("/\./", '"."', $table).'"'; - } - - return $table; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; - $query = $this->query($sql); - return $query->field_data(); - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @return string - */ - function _update($table, $values, $where) - { - foreach($values as $key => $val) - { - $valstr[] = $key." = ".$val; - } - - return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @return string - */ - function _delete($table, $where) - { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _show_columns($table = '') - { - return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->escape_table($table)."'"; - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - $sql .= "LIMIT ".$limit; - - if ($offset > 0) - { - $sql .= " OFFSET ".$offset; - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - pg_close($conn_id); - } - -} - -?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite.php b/system/database/drivers/sqlite/sqlite.php deleted file mode 100644 index 6116a84ab..000000000 --- a/system/database/drivers/sqlite/sqlite.php +++ /dev/null @@ -1,481 +0,0 @@ -database, 0666, $error)) - { - log_message('error', $error); - - if ($this->db_debug) - { - $this->display_error($error, '', TRUE); - } - } - - return $conn_id; - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - if ( ! $conn_id = sqlite_popen($this->database, 0666, $error)) - { - log_message('error', $error); - - if ($this->db_debug) - { - $this->display_error($error, '', TRUE); - } - } - - return $conn_id; - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return resource - */ - function _execute($sql) - { - $sql = $this->_prep_query($sql); - return @sqlite_query($this->conn_id, $sql); - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @access private called by execute() - * @param string an SQL query - * @return string - */ - function _prep_query($sql) - { - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @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) - { - return TRUE; - } - - // Reset the transaction failure flag. - // 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('BEGIN TRANSACTION'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $this->simple_query('COMMIT'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $this->simple_query('ROLLBACK'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @return string - */ - function escape_str($str) - { - return sqlite_escape_string($str); - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return sqlite_changes($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - return @sqlite_last_insert_rowid($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - return '0'; - - $query = $this->query("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); - - if ($query->num_rows() == 0) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access public - * @return string - */ - function error_message() - { - return sqlite_error_string(sqlite_last_error($this->conn_id)); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access public - * @return integer - */ - function error_number() - { - return sqlite_last_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function version() - { - return sqlite_libversion(); - } - - // -------------------------------------------------------------------- - - /** - * Escape Table Name - * - * This function adds backticks if the table name has a period - * in it. Some DBs will get cranky unless periods are escaped - * - * @access public - * @param string the table name - * @return string - */ - function escape_table($table) - { - if (stristr($table, '.')) - { - $table = preg_replace("/\./", "`.`", $table); - } - - return $table; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; - $query = $this->query($sql); - return $query->field_data(); - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @return string - */ - function _update($table, $values, $where) - { - foreach($values as $key => $val) - { - $valstr[] = $key." = ".$val; - } - - return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @return string - */ - function _delete($table, $where) - { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SELECT name from sqlite_master WHERE type='table'"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _show_columns($table = '') - { - // Not supported - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - if ($offset == 0) - { - $offset = ''; - } - else - { - $offset .= ", "; - } - - return $sql."LIMIT ".$offset.$limit; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - sqlite_close($conn_id); - } - -} - -?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From bb1d439a981023415569549d8b8c4987fa5b9b51 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 20:14:38 +0000 Subject: --- system/database/DB_driver.php | 82 +++++++++++- system/database/DB_utility.php | 95 ++++--------- system/database/drivers/mssql/mssql_driver.php | 109 +++++++-------- system/database/drivers/mysql/mysql_driver.php | 124 ++++++++--------- system/database/drivers/mysqli/mysqli_driver.php | 119 ++++++++-------- system/database/drivers/oci8/oci8_driver.php | 121 ++++++++--------- system/database/drivers/odbc/odbc_driver.php | 107 +++++++-------- system/database/drivers/postgre/postgre_driver.php | 117 ++++++++-------- system/database/drivers/sqlite/sqlite_driver.php | 149 +++++++++++---------- 9 files changed, 533 insertions(+), 490 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index ef37967dc..3f7c82627 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -190,11 +190,11 @@ class CI_DB_driver { if ($this->db_debug) { - log_message('error', 'Query error: '.$this->error_message()); + log_message('error', 'Query error: '.$this->_error_message()); return $this->display_error( array( - 'Error Number: '.$this->error_number(), - $this->error_message(), + 'Error Number: '.$this->_error_number(), + $this->_error_message(), $sql ) ); @@ -481,7 +481,81 @@ class CI_DB_driver { } return $str; - } + } + + // -------------------------------------------------------------------- + + /** + * Generate an insert string + * + * @access public + * @param string the table upon which the query will be performed + * @param array an associative array data of key/values + * @return string + */ + function insert_string($table, $data) + { + $fields = array(); + $values = array(); + + foreach($data as $key => $val) + { + $fields[] = $key; + $values[] = $this->escape($val); + } + + return $this->_insert($this->dbprefix.$table, $fields, $values); + } + + // -------------------------------------------------------------------- + + /** + * Generate an update string + * + * @access public + * @param string the table upon which the query will be performed + * @param array an associative array data of key/values + * @param mixed the "where" statement + * @return string + */ + function update_string($table, $data, $where) + { + if ($where == '') + return false; + + $fields = array(); + foreach($data as $key => $val) + { + $fields[$key] = $this->escape($val); + } + + if ( ! is_array($where)) + { + $dest = array($where); + } + else + { + $dest = array(); + foreach ($where as $key => $val) + { + $prefix = (count($dest) == 0) ? '' : ' AND '; + + if ($val != '') + { + if ( ! $this->_has_operator($key)) + { + $key .= ' ='; + } + + $val = ' '.$this->escape($val); + } + + $dest[] = $prefix.$key.$val; + } + } + + return $this->_update($this->dbprefix.$table, $fields, $dest); + } // -------------------------------------------------------------------- diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index a4d4eb0d1..39dc2cca2 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -202,79 +202,42 @@ class CI_DB_utility { return current($fields); } - // -------------------------------------------------------------------- - /** - * Generate an insert string - * - * @access public - * @param string the table upon which the query will be performed - * @param array an associative array data of key/values - * @return string - */ - function insert_string($table, $data) - { - $fields = array(); - $values = array(); - - foreach($data as $key => $val) - { - $fields[] = $key; - $values[] = $this->escape($val); - } - return $this->_insert($this->dbprefix.$table, $fields, $values); + + + function create_database() + { } - // -------------------------------------------------------------------- - - /** - * Generate an update string - * - * @access public - * @param string the table upon which the query will be performed - * @param array an associative array data of key/values - * @param mixed the "where" statement - * @return string - */ - function update_string($table, $data, $where) + function drop_database() { - if ($where == '') - return false; - - $fields = array(); - foreach($data as $key => $val) - { - $fields[$key] = $this->escape($val); - } - - if ( ! is_array($where)) - { - $dest = array($where); - } - else - { - $dest = array(); - foreach ($where as $key => $val) - { - $prefix = (count($dest) == 0) ? '' : ' AND '; + } - if ($val != '') - { - if ( ! $this->_has_operator($key)) - { - $key .= ' ='; - } - - $val = ' '.$this->escape($val); - } - - $dest[] = $prefix.$key.$val; - } - } + function show_databases() + { + } + + function create_table() + { + } + + function alter_table() + { + } + + function create_index() + { + } + + function drop_index() + { + } + + function optimize() + { + } - return $this->_update($this->dbprefix.$table, $fields, $dest); - } } diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 4f668f282..cd808da46 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -251,10 +251,10 @@ class CI_DB_mssql_driver extends CI_DB { /** * The error message string * - * @access public + * @access private * @return string */ - function error_message() + function _error_message() { // Are errros even supported in MS SQL? return ''; @@ -265,10 +265,10 @@ class CI_DB_mssql_driver extends CI_DB { /** * The error message number * - * @access public + * @access private * @return integer */ - function error_number() + function _error_number() { // Are error numbers supported? return ''; @@ -282,11 +282,11 @@ class CI_DB_mssql_driver extends CI_DB { * This function adds backticks if the table name has a period * in it. Some DBs will get cranky unless periods are escaped * - * @access public + * @access private * @param string the table name * @return string */ - function escape_table($table) + function _escape_table($table) { if (stristr($table, '.')) { @@ -294,25 +294,7 @@ class CI_DB_mssql_driver extends CI_DB { } return $table; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - $sql = "SELECT TOP 1 FROM ".$this->escape_table($table); - $query = $this->query($sql); - return $query->field_data(); - } + } // -------------------------------------------------------------------- @@ -329,7 +311,7 @@ class CI_DB_mssql_driver extends CI_DB { */ function _insert($table, $keys, $values) { - return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -352,7 +334,7 @@ class CI_DB_mssql_driver extends CI_DB { $valstr[] = $key." = ".$val; } - return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); } // -------------------------------------------------------------------- @@ -369,9 +351,43 @@ class CI_DB_mssql_driver extends CI_DB { */ function _delete($table, $where) { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + $i = $limit + $offset; + return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql); + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + mssql_close($conn_id); + } + // -------------------------------------------------------------------- /** @@ -413,43 +429,28 @@ class CI_DB_mssql_driver extends CI_DB { */ function _show_columns($table = '') { - return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$this->escape_table($table)."'"; - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - $i = $limit + $offset; - - return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql); + return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$this->_escape_table($table)."'"; } // -------------------------------------------------------------------- /** - * Close DB Connection + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved * * @access public - * @param resource - * @return void + * @param string the table name + * @return object */ - function _close($conn_id) + function _field_data($table) { - mssql_close($conn_id); + $sql = "SELECT TOP 1 FROM ".$this->_escape_table($table); + $query = $this->query($sql); + return $query->field_data(); } + } diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 8aa82da72..fc7f6780b 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -269,10 +269,10 @@ class CI_DB_mysql_driver extends CI_DB { /** * The error message string * - * @access public + * @access private * @return string */ - function error_message() + function _error_message() { return mysql_error($this->conn_id); } @@ -282,10 +282,10 @@ class CI_DB_mysql_driver extends CI_DB { /** * The error message number * - * @access public + * @access private * @return integer */ - function error_number() + function _error_number() { return mysql_errno($this->conn_id); } @@ -298,11 +298,11 @@ class CI_DB_mysql_driver extends CI_DB { * This function adds backticks if the table name has a period * in it. Some DBs will get cranky unless periods are escaped * - * @access public + * @access private * @param string the table name * @return string */ - function escape_table($table) + function _escape_table($table) { if (stristr($table, '.')) { @@ -311,25 +311,7 @@ class CI_DB_mysql_driver extends CI_DB { return $table; } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; - $query = $this->query($sql); - return $query->field_data(); - } - + // -------------------------------------------------------------------- /** @@ -345,7 +327,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function _insert($table, $keys, $values) { - return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -368,7 +350,7 @@ class CI_DB_mysql_driver extends CI_DB { $valstr[] = $key." = ".$val; } - return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); } // -------------------------------------------------------------------- @@ -385,9 +367,50 @@ class CI_DB_mysql_driver extends CI_DB { */ function _delete($table, $where) { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); } - + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + if ($offset == 0) + { + $offset = ''; + } + else + { + $offset .= ", "; + } + + return $sql."LIMIT ".$offset.$limit; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + mysql_close($conn_id); + } + // -------------------------------------------------------------------- /** @@ -429,48 +452,25 @@ class CI_DB_mysql_driver extends CI_DB { */ function _show_columns($table = '') { - return "SHOW COLUMNS FROM ".$this->escape_table($table); - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - if ($offset == 0) - { - $offset = ''; - } - else - { - $offset .= ", "; - } - - return $sql."LIMIT ".$offset.$limit; + return "SHOW COLUMNS FROM ".$this->_escape_table($table); } // -------------------------------------------------------------------- /** - * Close DB Connection + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved * * @access public - * @param resource - * @return void + * @param string the table name + * @return object */ - function _close($conn_id) + function _field_data($table) { - mysql_close($conn_id); + $sql = "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; + $query = $this->query($sql); + return $query->field_data(); } } diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 8d28c2c5f..959384164 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -272,10 +272,10 @@ class CI_DB_mysqli_driver extends CI_DB { /** * The error message string * - * @access public + * @access private * @return string */ - function error_message() + function _error_message() { return mysqli_error($this->conn_id); } @@ -285,10 +285,10 @@ class CI_DB_mysqli_driver extends CI_DB { /** * The error message number * - * @access public + * @access private * @return integer */ - function error_number() + function _error_number() { return mysqli_errno($this->conn_id); } @@ -301,11 +301,11 @@ class CI_DB_mysqli_driver extends CI_DB { * This function adds backticks if the table name has a period * in it. Some DBs will get cranky unless periods are escaped * - * @access public + * @access private * @param string the table name * @return string */ - function escape_table($table) + function _escape_table($table) { if (stristr($table, '.')) { @@ -314,25 +314,7 @@ class CI_DB_mysqli_driver extends CI_DB { return $table; } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; - $query = $this->query($sql); - return $query->field_data(); - } - + // -------------------------------------------------------------------- /** @@ -348,7 +330,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ function _insert($table, $keys, $values) { - return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -371,7 +353,7 @@ class CI_DB_mysqli_driver extends CI_DB { $valstr[] = $key." = ".$val; } - return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); } // -------------------------------------------------------------------- @@ -388,9 +370,48 @@ class CI_DB_mysqli_driver extends CI_DB { */ function _delete($table, $where) { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + $sql .= "LIMIT ".$limit; + if ($offset > 0) + { + $sql .= " OFFSET ".$offset; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + mysqli_close($conn_id); + } + // -------------------------------------------------------------------- /** @@ -432,47 +453,27 @@ class CI_DB_mysqli_driver extends CI_DB { */ function _show_columns($table = '') { - return "SHOW COLUMNS FROM ".$this->escape_table($table); - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - $sql .= "LIMIT ".$limit; - - if ($offset > 0) - { - $sql .= " OFFSET ".$offset; - } - - return $sql; + return "SHOW COLUMNS FROM ".$this->_escape_table($table); } // -------------------------------------------------------------------- /** - * Close DB Connection + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved * * @access public - * @param resource - * @return void + * @param string the table name + * @return object */ - function _close($conn_id) + function _field_data($table) { - mysqli_close($conn_id); + $sql = "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; + $query = $this->query($sql); + return $query->field_data(); } + } diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 707394d53..bfc38a435 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -393,10 +393,10 @@ class CI_DB_oci8_driver extends CI_DB { /** * The error message string * - * @access public + * @access private * @return string */ - function error_message() + function _error_message() { $error = ocierror($this->conn_id); return $error['message']; @@ -407,10 +407,10 @@ class CI_DB_oci8_driver extends CI_DB { /** * The error message number * - * @access public + * @access private * @return integer */ - function error_number() + function _error_number() { $error = ocierror($this->conn_id); return $error['code']; @@ -424,11 +424,11 @@ class CI_DB_oci8_driver extends CI_DB { * This function adds backticks if the table name has a period * in it. Some DBs will get cranky unless periods are escaped * - * @access public + * @access private * @param string the table name * @return string */ - function escape_table($table) + function _escape_table($table) { if (stristr($table, '.')) { @@ -440,24 +440,6 @@ class CI_DB_oci8_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - $sql = "SELECT * FROM ".$this->escape_table($table)." where rownum = 1"; - $query = $this->query($sql); - return $query->field_data(); - } - - // -------------------------------------------------------------------- - /** * Insert statement * @@ -471,7 +453,7 @@ class CI_DB_oci8_driver extends CI_DB { */ function _insert($table, $keys, $values) { - return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -494,7 +476,7 @@ class CI_DB_oci8_driver extends CI_DB { $valstr[] = $key." = ".$val; } - return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); } // -------------------------------------------------------------------- @@ -511,7 +493,50 @@ class CI_DB_oci8_driver extends CI_DB { */ function _delete($table, $where) { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + $limit = $offset + $limit; + $newsql = "SELECT * FROM (select inner_query.*, rownum rnum FROM ($sql) inner_query WHERE rownum < $limit)"; + + if ($offset != 0) + { + $newsql .= " WHERE rnum >= $offset"; + } + + // remember that we used limits + $this->limit_used = TRUE; + + return $newsql; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + ocilogoff($conn_id); } // -------------------------------------------------------------------- @@ -562,46 +587,22 @@ class CI_DB_oci8_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Limit string - * - * Generates a platform-specific LIMIT clause + * Field data query * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - $limit = $offset + $limit; - $newsql = "SELECT * FROM (select inner_query.*, rownum rnum FROM ($sql) inner_query WHERE rownum < $limit)"; - - if ($offset != 0) - { - $newsql .= " WHERE rnum >= $offset"; - } - - // remember that we used limits - $this->limit_used = TRUE; - - return $newsql; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection + * Generates a platform-specific query so that the column data can be retrieved * * @access public - * @param resource - * @return void + * @param string the table name + * @return object */ - function _close($conn_id) + function _field_data($table) { - ocilogoff($conn_id); + $sql = "SELECT * FROM ".$this->_escape_table($table)." where rownum = 1"; + $query = $this->query($sql); + return $query->field_data(); } + } diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 1725ed743..c05abd082 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -252,10 +252,10 @@ class CI_DB_odbc_driver extends CI_DB { /** * The error message string * - * @access public + * @access private * @return string */ - function error_message() + function _error_message() { return odbc_errormsg($this->conn_id); } @@ -265,10 +265,10 @@ class CI_DB_odbc_driver extends CI_DB { /** * The error message number * - * @access public + * @access private * @return integer */ - function error_number() + function _error_number() { return odbc_error($this->conn_id); } @@ -281,11 +281,11 @@ class CI_DB_odbc_driver extends CI_DB { * This function adds backticks if the table name has a period * in it. Some DBs will get cranky unless periods are escaped * - * @access public + * @access private * @param string the table name * @return string */ - function escape_table($table) + function _escape_table($table) { if (stristr($table, '.')) { @@ -294,25 +294,7 @@ class CI_DB_odbc_driver extends CI_DB { return $table; } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - $sql = "SELECT TOP 1 FROM ".$this->escape_table($table); - $query = $this->query($sql); - return $query->field_data(); - } - + // -------------------------------------------------------------------- /** @@ -328,7 +310,7 @@ class CI_DB_odbc_driver extends CI_DB { */ function _insert($table, $keys, $values) { - return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -351,7 +333,7 @@ class CI_DB_odbc_driver extends CI_DB { $valstr[] = $key." = ".$val; } - return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); } // -------------------------------------------------------------------- @@ -368,9 +350,42 @@ class CI_DB_odbc_driver extends CI_DB { */ function _delete($table, $where) { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); } - + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + // Does ODBC doesn't use the LIMIT clause? + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + odbc_close($conn_id); + } + // -------------------------------------------------------------------- /** @@ -412,41 +427,27 @@ class CI_DB_odbc_driver extends CI_DB { */ function _show_columns($table = '') { - return "SHOW COLUMNS FROM ".$this->escape_table($table); + return "SHOW COLUMNS FROM ".$this->_escape_table($table); } - + // -------------------------------------------------------------------- /** - * Limit string + * Field data query * - * Generates a platform-specific LIMIT clause + * Generates a platform-specific query so that the column data can be retrieved * * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string + * @param string the table name + * @return object */ - function _limit($sql, $limit, $offset) + function _field_data($table) { - // Does ODBC doesn't use the LIMIT clause? - return $sql; + $sql = "SELECT TOP 1 FROM ".$this->_escape_table($table); + $query = $this->query($sql); + return $query->field_data(); } - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - odbc_close($conn_id); - } } diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 92767c42b..03817188f 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -279,10 +279,10 @@ class CI_DB_postgre_driver extends CI_DB { /** * The error message string * - * @access public + * @access private * @return string */ - function error_message() + function _error_message() { return pg_last_error($this->conn_id); } @@ -292,10 +292,10 @@ class CI_DB_postgre_driver extends CI_DB { /** * The error message number * - * @access public + * @access private * @return integer */ - function error_number() + function _error_number() { return ''; } @@ -308,11 +308,11 @@ class CI_DB_postgre_driver extends CI_DB { * This function adds backticks if the table name has a period * in it. Some DBs will get cranky unless periods are escaped. * - * @access public + * @access private * @param string the table name * @return string */ - function escape_table($table) + function _escape_table($table) { if (stristr($table, '.')) { @@ -324,24 +324,6 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; - $query = $this->query($sql); - return $query->field_data(); - } - - // -------------------------------------------------------------------- - /** * Insert statement * @@ -355,7 +337,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function _insert($table, $keys, $values) { - return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -378,7 +360,7 @@ class CI_DB_postgre_driver extends CI_DB { $valstr[] = $key." = ".$val; } - return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); } // -------------------------------------------------------------------- @@ -395,9 +377,48 @@ class CI_DB_postgre_driver extends CI_DB { */ function _delete($table, $where) { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + $sql .= "LIMIT ".$limit; + if ($offset > 0) + { + $sql .= " OFFSET ".$offset; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + pg_close($conn_id); + } + // -------------------------------------------------------------------- /** @@ -437,48 +458,28 @@ class CI_DB_postgre_driver extends CI_DB { */ function _show_columns($table = '') { - return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->escape_table($table)."'"; - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - $sql .= "LIMIT ".$limit; - - if ($offset > 0) - { - $sql .= " OFFSET ".$offset; - } - - return $sql; + return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->_escape_table($table)."'"; } // -------------------------------------------------------------------- /** - * Close DB Connection + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved * * @access public - * @param resource - * @return void + * @param string the table name + * @return object */ - function _close($conn_id) + function _field_data($table) { - pg_close($conn_id); + $sql = "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; + $query = $this->query($sql); + return $query->field_data(); } + } ?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 634b72ed4..f8318b814 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -271,10 +271,10 @@ class CI_DB_sqlite_driver extends CI_DB { /** * The error message string * - * @access public + * @access private * @return string */ - function error_message() + function _error_message() { return sqlite_error_string(sqlite_last_error($this->conn_id)); } @@ -284,27 +284,14 @@ class CI_DB_sqlite_driver extends CI_DB { /** * The error message number * - * @access public + * @access private * @return integer */ - function error_number() + function _error_number() { return sqlite_last_error($this->conn_id); } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function version() - { - return sqlite_libversion(); - } - + // -------------------------------------------------------------------- /** @@ -313,11 +300,11 @@ class CI_DB_sqlite_driver extends CI_DB { * This function adds backticks if the table name has a period * in it. Some DBs will get cranky unless periods are escaped * - * @access public + * @access private * @param string the table name * @return string */ - function escape_table($table) + function _escape_table($table) { if (stristr($table, '.')) { @@ -326,25 +313,7 @@ class CI_DB_sqlite_driver extends CI_DB { return $table; } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; - $query = $this->query($sql); - return $query->field_data(); - } - + // -------------------------------------------------------------------- /** @@ -360,7 +329,7 @@ class CI_DB_sqlite_driver extends CI_DB { */ function _insert($table, $keys, $values) { - return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -383,7 +352,7 @@ class CI_DB_sqlite_driver extends CI_DB { $valstr[] = $key." = ".$val; } - return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); } // -------------------------------------------------------------------- @@ -400,41 +369,9 @@ class CI_DB_sqlite_driver extends CI_DB { */ function _delete($table, $where) { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SELECT name from sqlite_master WHERE type='table'"; + return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); } - - // -------------------------------------------------------------------- - /** - * Show columnn query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _show_columns($table = '') - { - // Not supported - return FALSE; - } - // -------------------------------------------------------------------- /** @@ -476,6 +413,70 @@ class CI_DB_sqlite_driver extends CI_DB { sqlite_close($conn_id); } + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return sqlite_libversion(); + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SELECT name from sqlite_master WHERE type='table'"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _show_columns($table = '') + { + // Not supported + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + $sql = "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; + $query = $this->query($sql); + return $query->field_data(); + } + + } ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 1716d5880b5b8d26db5608922f88adcf1ff8077c Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 20:15:03 +0000 Subject: --- system/database/DB_export.php | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 system/database/DB_export.php (limited to 'system/database') diff --git a/system/database/DB_export.php b/system/database/DB_export.php new file mode 100644 index 000000000..195510d9d --- /dev/null +++ b/system/database/DB_export.php @@ -0,0 +1,41 @@ + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From ac94f38e9f501721d3148c94b3962a529f646e20 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 20:28:12 +0000 Subject: --- system/database/DB_active_rec.php | 875 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 875 insertions(+) create mode 100644 system/database/DB_active_rec.php (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php new file mode 100644 index 000000000..c038185bc --- /dev/null +++ b/system/database/DB_active_rec.php @@ -0,0 +1,875 @@ +ar_select[] = $val; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * DISTINCT + * + * Sets a flag which tells the query string compiler to add DISTINCT + * + * @access public + * @param bool + * @return object + */ + function distinct($val = TRUE) + { + $this->ar_distinct = (is_bool($val)) ? $val : TRUE; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * From + * + * Generates the FROM portion of the query + * + * @access public + * @param mixed can be a string or array + * @return object + */ + function from($from) + { + foreach ((array)$from as $val) + { + $this->ar_from[] = $this->dbprefix.$val; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Join + * + * Generates the JOIN portion of the query + * + * @access public + * @param string + * @param string the join condition + * @param string the type of join + * @return object + */ + function join($table, $cond, $type = '') + { + if ($type != '') + { + $type = strtoupper(trim($type)); + + if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'))) + { + $type = ''; + } + else + { + $type .= ' '; + } + } + + $this->ar_join[] = $type.'JOIN '.$table.' ON '.$cond; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Where + * + * Generates the WHERE portion of the query. Separates + * multiple calls with AND + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function where($key, $value = NULL) + { + return $this->_where($key, $value, 'AND '); + } + + // -------------------------------------------------------------------- + + /** + * OR Where + * + * Generates the WHERE portion of the query. Separates + * multiple calls with OR + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function orwhere($key, $value = NULL) + { + return $this->_where($key, $value, 'OR '); + } + + // -------------------------------------------------------------------- + + /** + * Where + * + * Called by where() or orwhere() + * + * @access private + * @param mixed + * @param mixed + * @param string + * @return object + */ + function _where($key, $value = NULL, $type = 'AND ') + { + if ( ! is_array($key)) + { + $key = array($key => $value); + } + + foreach ($key as $k => $v) + { + $prefix = (count($this->ar_where) == 0) ? '' : $type; + + if ( ! is_null($v)) + { + if ( ! $this->_has_operator($k)) + { + $k .= ' ='; + } + + $v = ' '.$this->escape($v); + } + + $this->ar_where[] = $prefix.$k.$v; + } + return $this; + } + + + + // -------------------------------------------------------------------- + + /** + * Like + * + * Generates a %LIKE% portion of the query. Separates + * multiple calls with AND + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function like($field, $match = '') + { + return $this->_like($field, $match, 'AND '); + } + + // -------------------------------------------------------------------- + + /** + * OR Like + * + * Generates a %LIKE% portion of the query. Separates + * multiple calls with OR + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function orlike($field, $match = '') + { + return $this->_like($field, $match, 'OR '); + } + + // -------------------------------------------------------------------- + + /** + * Like + * + * Called by like() or orlike() + * + * @access private + * @param mixed + * @param mixed + * @param string + * @return object + */ + function _like($field, $match = '', $type = 'AND ') + { + if ( ! is_array($field)) + { + $field = array($field => $match); + } + + foreach ($field as $k => $v) + { + $prefix = (count($this->ar_like) == 0) ? '' : $type; + + $v = $this->escape_str($v); + + $this->ar_like[] = $prefix." $k LIKE '%{$v}%'"; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * GROUP BY + * + * @access public + * @param string + * @return object + */ + function groupby($by) + { + if (is_string($by)) + { + $by = explode(',', $by); + } + + foreach ($by as $val) + { + $val = trim($val); + + if ($val != '') + $this->ar_groupby[] = $val; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Sets the HAVING value + * + * Separates multiple calls with AND + * + * @access public + * @param string + * @param string + * @return object + */ + function having($key, $value = '') + { + return $this->_having($key, $value, 'AND '); + } + + // -------------------------------------------------------------------- + + /** + * Sets the OR HAVING value + * + * Separates multiple calls with OR + * + * @access public + * @param string + * @param string + * @return object + */ + function orhaving($key, $value = '') + { + return $this->_having($key, $value, 'OR '); + } + + // -------------------------------------------------------------------- + + /** + * Sets the HAVING values + * + * Called by having() or orhaving() + * + * @access private + * @param string + * @param string + * @return object + */ + function _having($key, $value = '', $type = 'AND ') + { + if ( ! is_array($key)) + { + $key = array($key => $value); + } + + foreach ($key as $k => $v) + { + $prefix = (count($this->ar_having) == 0) ? '' : $type; + + if ($v != '') + { + $v = ' '.$this->escape($v); + } + + $this->ar_having[] = $prefix.$k.$v; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Sets the ORDER BY value + * + * @access public + * @param string + * @param string direction: asc or desc + * @return object + */ + function orderby($orderby, $direction = '') + { + if (trim($direction) != '') + { + $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC', 'RAND()'))) ? ' '.$direction : ' ASC'; + } + + $this->ar_orderby[] = $orderby.$direction; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Sets the LIMIT value + * + * @access public + * @param integer the limit value + * @param integer the offset value + * @return object + */ + function limit($value, $offset = '') + { + $this->ar_limit = $value; + + if ($offset != '') + $this->ar_offset = $offset; + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Sets the OFFSET value + * + * @access public + * @param integer the offset value + * @return object + */ + function offset($value) + { + $this->ar_offset = $value; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * The "set" function. Allows key/value pairs to be set for inserting or updating + * + * @access public + * @param mixed + * @param string + * @return object + */ + function set($key, $value = '') + { + $key = $this->_object_to_array($key); + + if ( ! is_array($key)) + { + $key = array($key => $value); + } + + foreach ($key as $k => $v) + { + $this->ar_set[$k] = $this->escape($v); + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Get + * + * Compiles the select statement based on the other functions called + * and runs the query + * + * @access public + * @param string the limit clause + * @param string the offset clause + * @return object + */ + function get($table = '', $limit = null, $offset = null) + { + if ($table != '') + { + $this->from($table); + } + + if ( ! is_null($limit)) + { + $this->limit($limit, $offset); + } + + $sql = $this->_compile_select(); + + $this->_reset_select(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * GetWhere + * + * Allows the where clause, limit and offset to be added directly + * + * @access public + * @param string the where clause + * @param string the limit clause + * @param string the offset clause + * @return object + */ + function getwhere($table = '', $where = null, $limit = null, $offset = null) + { + if ($table != '') + { + $this->from($table); + } + + if ( ! is_null($where)) + { + $this->where($where); + } + + if ( ! is_null($limit)) + { + $this->limit($limit, $offset); + } + + $sql = $this->_compile_select(); + + $this->_reset_select(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Insert + * + * Compiles an insert string and runs the query + * + * @access public + * @param string the table to retrieve the results from + * @param array an associative array of insert values + * @return object + */ + function insert($table = '', $set = NULL) + { + if ( ! is_null($set)) + { + $this->set($set); + } + + if (count($this->ar_set) == 0) + { + if ($this->db_debug) + { + return $this->display_error('db_must_use_set'); + } + return FALSE; + } + + if ($table == '') + { + if ( ! isset($this->ar_from[0])) + { + if ($this->db_debug) + { + return $this->display_error('db_must_set_table'); + } + return FALSE; + } + + $table = $this->ar_from[0]; + } + + $sql = $this->_insert($this->dbprefix.$table, array_keys($this->ar_set), array_values($this->ar_set)); + + $this->_reset_write(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Update + * + * Compiles an update string and runs the query + * + * @access public + * @param string the table to retrieve the results from + * @param array an associative array of update values + * @param mixed the where clause + * @return object + */ + function update($table = '', $set = NULL, $where = null) + { + if ( ! is_null($set)) + { + $this->set($set); + } + + if (count($this->ar_set) == 0) + { + if ($this->db_debug) + { + return $this->display_error('db_must_use_set'); + } + return FALSE; + } + + if ($table == '') + { + if ( ! isset($this->ar_from[0])) + { + if ($this->db_debug) + { + return $this->display_error('db_must_set_table'); + } + return FALSE; + } + + $table = $this->ar_from[0]; + } + + if ($where != null) + { + $this->where($where); + } + + $sql = $this->_update($this->dbprefix.$table, $this->ar_set, $this->ar_where); + + $this->_reset_write(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Delete + * + * Compiles a delete string and runs the query + * + * @access public + * @param string the table to retrieve the results from + * @param mixed the where clause + * @return object + */ + function delete($table = '', $where = '') + { + if ($table == '') + { + if ( ! isset($this->ar_from[0])) + { + if ($this->db_debug) + { + return $this->display_error('db_must_set_table'); + } + return FALSE; + } + + $table = $this->ar_from[0]; + } + + if ($where != '') + { + $this->where($where); + } + + if (count($this->ar_where) == 0) + { + if ($this->db_debug) + { + return $this->display_error('db_del_must_use_where'); + } + return FALSE; + } + + $sql = $this->_delete($this->dbprefix.$table, $this->ar_where); + + $this->_reset_write(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Use Table - DEPRECATED + * + * @deprecated use $this->db->from instead + */ + function use_table($table) + { + return $this->from($table); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * ORDER BY - DEPRECATED + * + * @deprecated use $this->db->orderby() instead + */ + function order_by($orderby, $direction = '') + { + return $this->orderby($orderby, $direction); + } + + // -------------------------------------------------------------------- + + /** + * Tests whether the string has an SQL operator + * + * @access private + * @param string + * @return bool + */ + function _has_operator($str) + { + $str = trim($str); + if ( ! preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str)) + { + return FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Compile the SELECT statement + * + * Generates a query string based on which functions were used. + * Should not be called directly. The get() function calls it. + * + * @access private + * @return string + */ + function _compile_select() + { + $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; + + $sql .= (count($this->ar_select) == 0) ? '*' : implode(', ', $this->ar_select); + + if (count($this->ar_from) > 0) + { + $sql .= "\nFROM "; + $sql .= implode(', ', $this->ar_from); + } + + if (count($this->ar_join) > 0) + { + $sql .= "\n"; + $sql .= implode("\n", $this->ar_join); + } + + if (count($this->ar_where) > 0 OR count($this->ar_like) > 0) + { + $sql .= "\nWHERE "; + } + + $sql .= implode("\n", $this->ar_where); + + if (count($this->ar_like) > 0) + { + if (count($this->ar_where) > 0) + { + $sql .= " AND "; + } + + $sql .= implode("\n", $this->ar_like); + } + + if (count($this->ar_groupby) > 0) + { + $sql .= "\nGROUP BY "; + $sql .= implode(', ', $this->ar_groupby); + } + + if (count($this->ar_having) > 0) + { + $sql .= "\nHAVING "; + $sql .= implode("\n", $this->ar_having); + } + + if (count($this->ar_orderby) > 0) + { + $sql .= "\nORDER BY "; + $sql .= implode(', ', $this->ar_orderby); + + if ($this->ar_order !== FALSE) + { + $sql .= ($this->ar_order == 'desc') ? ' DESC' : ' ASC'; + } + } + + if (is_numeric($this->ar_limit)) + { + $sql .= "\n"; + $sql = $this->_limit($sql, $this->ar_limit, $this->ar_offset); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Object to Array + * + * Takes an object as input and convers the class variables to array key/vals + * + * @access public + * @param object + * @return array + */ + function _object_to_array($object) + { + if ( ! is_object($object)) + { + return $object; + } + + $array = array(); + foreach (get_object_vars($object) as $key => $val) + { + if ( ! is_object($val) AND ! is_array($val)) + { + $array[$key] = $val; + } + } + + return $array; + } + + // -------------------------------------------------------------------- + + /** + * Resets the active record values. Called by the get() function + * + * @access private + * @return void + */ + function _reset_select() + { + $this->ar_select = array(); + $this->ar_distinct = FALSE; + $this->ar_from = array(); + $this->ar_join = array(); + $this->ar_where = array(); + $this->ar_like = array(); + $this->ar_groupby = array(); + $this->ar_having = array(); + $this->ar_limit = FALSE; + $this->ar_offset = FALSE; + $this->ar_order = FALSE; + $this->ar_orderby = array(); + } + + // -------------------------------------------------------------------- + + /** + * Resets the active record "write" values. + * + * Called by the insert() or update() functions + * + * @access private + * @return void + */ + function _reset_write() + { + $this->ar_set = array(); + $this->ar_from = array(); + $this->ar_where = array(); + } + +} + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c9a8bab572388bbba541f1cf8f12a46e2103e447 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 20:28:33 +0000 Subject: --- system/database/DB_active_record.php | 875 ----------------------------------- 1 file changed, 875 deletions(-) delete mode 100644 system/database/DB_active_record.php (limited to 'system/database') diff --git a/system/database/DB_active_record.php b/system/database/DB_active_record.php deleted file mode 100644 index c038185bc..000000000 --- a/system/database/DB_active_record.php +++ /dev/null @@ -1,875 +0,0 @@ -ar_select[] = $val; - } - return $this; - } - - // -------------------------------------------------------------------- - - /** - * DISTINCT - * - * Sets a flag which tells the query string compiler to add DISTINCT - * - * @access public - * @param bool - * @return object - */ - function distinct($val = TRUE) - { - $this->ar_distinct = (is_bool($val)) ? $val : TRUE; - return $this; - } - - // -------------------------------------------------------------------- - - /** - * From - * - * Generates the FROM portion of the query - * - * @access public - * @param mixed can be a string or array - * @return object - */ - function from($from) - { - foreach ((array)$from as $val) - { - $this->ar_from[] = $this->dbprefix.$val; - } - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Join - * - * Generates the JOIN portion of the query - * - * @access public - * @param string - * @param string the join condition - * @param string the type of join - * @return object - */ - function join($table, $cond, $type = '') - { - if ($type != '') - { - $type = strtoupper(trim($type)); - - if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'))) - { - $type = ''; - } - else - { - $type .= ' '; - } - } - - $this->ar_join[] = $type.'JOIN '.$table.' ON '.$cond; - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Where - * - * Generates the WHERE portion of the query. Separates - * multiple calls with AND - * - * @access public - * @param mixed - * @param mixed - * @return object - */ - function where($key, $value = NULL) - { - return $this->_where($key, $value, 'AND '); - } - - // -------------------------------------------------------------------- - - /** - * OR Where - * - * Generates the WHERE portion of the query. Separates - * multiple calls with OR - * - * @access public - * @param mixed - * @param mixed - * @return object - */ - function orwhere($key, $value = NULL) - { - return $this->_where($key, $value, 'OR '); - } - - // -------------------------------------------------------------------- - - /** - * Where - * - * Called by where() or orwhere() - * - * @access private - * @param mixed - * @param mixed - * @param string - * @return object - */ - function _where($key, $value = NULL, $type = 'AND ') - { - if ( ! is_array($key)) - { - $key = array($key => $value); - } - - foreach ($key as $k => $v) - { - $prefix = (count($this->ar_where) == 0) ? '' : $type; - - if ( ! is_null($v)) - { - if ( ! $this->_has_operator($k)) - { - $k .= ' ='; - } - - $v = ' '.$this->escape($v); - } - - $this->ar_where[] = $prefix.$k.$v; - } - return $this; - } - - - - // -------------------------------------------------------------------- - - /** - * Like - * - * Generates a %LIKE% portion of the query. Separates - * multiple calls with AND - * - * @access public - * @param mixed - * @param mixed - * @return object - */ - function like($field, $match = '') - { - return $this->_like($field, $match, 'AND '); - } - - // -------------------------------------------------------------------- - - /** - * OR Like - * - * Generates a %LIKE% portion of the query. Separates - * multiple calls with OR - * - * @access public - * @param mixed - * @param mixed - * @return object - */ - function orlike($field, $match = '') - { - return $this->_like($field, $match, 'OR '); - } - - // -------------------------------------------------------------------- - - /** - * Like - * - * Called by like() or orlike() - * - * @access private - * @param mixed - * @param mixed - * @param string - * @return object - */ - function _like($field, $match = '', $type = 'AND ') - { - if ( ! is_array($field)) - { - $field = array($field => $match); - } - - foreach ($field as $k => $v) - { - $prefix = (count($this->ar_like) == 0) ? '' : $type; - - $v = $this->escape_str($v); - - $this->ar_like[] = $prefix." $k LIKE '%{$v}%'"; - } - return $this; - } - - // -------------------------------------------------------------------- - - /** - * GROUP BY - * - * @access public - * @param string - * @return object - */ - function groupby($by) - { - if (is_string($by)) - { - $by = explode(',', $by); - } - - foreach ($by as $val) - { - $val = trim($val); - - if ($val != '') - $this->ar_groupby[] = $val; - } - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Sets the HAVING value - * - * Separates multiple calls with AND - * - * @access public - * @param string - * @param string - * @return object - */ - function having($key, $value = '') - { - return $this->_having($key, $value, 'AND '); - } - - // -------------------------------------------------------------------- - - /** - * Sets the OR HAVING value - * - * Separates multiple calls with OR - * - * @access public - * @param string - * @param string - * @return object - */ - function orhaving($key, $value = '') - { - return $this->_having($key, $value, 'OR '); - } - - // -------------------------------------------------------------------- - - /** - * Sets the HAVING values - * - * Called by having() or orhaving() - * - * @access private - * @param string - * @param string - * @return object - */ - function _having($key, $value = '', $type = 'AND ') - { - if ( ! is_array($key)) - { - $key = array($key => $value); - } - - foreach ($key as $k => $v) - { - $prefix = (count($this->ar_having) == 0) ? '' : $type; - - if ($v != '') - { - $v = ' '.$this->escape($v); - } - - $this->ar_having[] = $prefix.$k.$v; - } - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Sets the ORDER BY value - * - * @access public - * @param string - * @param string direction: asc or desc - * @return object - */ - function orderby($orderby, $direction = '') - { - if (trim($direction) != '') - { - $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC', 'RAND()'))) ? ' '.$direction : ' ASC'; - } - - $this->ar_orderby[] = $orderby.$direction; - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Sets the LIMIT value - * - * @access public - * @param integer the limit value - * @param integer the offset value - * @return object - */ - function limit($value, $offset = '') - { - $this->ar_limit = $value; - - if ($offset != '') - $this->ar_offset = $offset; - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Sets the OFFSET value - * - * @access public - * @param integer the offset value - * @return object - */ - function offset($value) - { - $this->ar_offset = $value; - return $this; - } - - // -------------------------------------------------------------------- - - /** - * The "set" function. Allows key/value pairs to be set for inserting or updating - * - * @access public - * @param mixed - * @param string - * @return object - */ - function set($key, $value = '') - { - $key = $this->_object_to_array($key); - - if ( ! is_array($key)) - { - $key = array($key => $value); - } - - foreach ($key as $k => $v) - { - $this->ar_set[$k] = $this->escape($v); - } - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Get - * - * Compiles the select statement based on the other functions called - * and runs the query - * - * @access public - * @param string the limit clause - * @param string the offset clause - * @return object - */ - function get($table = '', $limit = null, $offset = null) - { - if ($table != '') - { - $this->from($table); - } - - if ( ! is_null($limit)) - { - $this->limit($limit, $offset); - } - - $sql = $this->_compile_select(); - - $this->_reset_select(); - return $this->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * GetWhere - * - * Allows the where clause, limit and offset to be added directly - * - * @access public - * @param string the where clause - * @param string the limit clause - * @param string the offset clause - * @return object - */ - function getwhere($table = '', $where = null, $limit = null, $offset = null) - { - if ($table != '') - { - $this->from($table); - } - - if ( ! is_null($where)) - { - $this->where($where); - } - - if ( ! is_null($limit)) - { - $this->limit($limit, $offset); - } - - $sql = $this->_compile_select(); - - $this->_reset_select(); - return $this->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Insert - * - * Compiles an insert string and runs the query - * - * @access public - * @param string the table to retrieve the results from - * @param array an associative array of insert values - * @return object - */ - function insert($table = '', $set = NULL) - { - if ( ! is_null($set)) - { - $this->set($set); - } - - if (count($this->ar_set) == 0) - { - if ($this->db_debug) - { - return $this->display_error('db_must_use_set'); - } - return FALSE; - } - - if ($table == '') - { - if ( ! isset($this->ar_from[0])) - { - if ($this->db_debug) - { - return $this->display_error('db_must_set_table'); - } - return FALSE; - } - - $table = $this->ar_from[0]; - } - - $sql = $this->_insert($this->dbprefix.$table, array_keys($this->ar_set), array_values($this->ar_set)); - - $this->_reset_write(); - return $this->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Update - * - * Compiles an update string and runs the query - * - * @access public - * @param string the table to retrieve the results from - * @param array an associative array of update values - * @param mixed the where clause - * @return object - */ - function update($table = '', $set = NULL, $where = null) - { - if ( ! is_null($set)) - { - $this->set($set); - } - - if (count($this->ar_set) == 0) - { - if ($this->db_debug) - { - return $this->display_error('db_must_use_set'); - } - return FALSE; - } - - if ($table == '') - { - if ( ! isset($this->ar_from[0])) - { - if ($this->db_debug) - { - return $this->display_error('db_must_set_table'); - } - return FALSE; - } - - $table = $this->ar_from[0]; - } - - if ($where != null) - { - $this->where($where); - } - - $sql = $this->_update($this->dbprefix.$table, $this->ar_set, $this->ar_where); - - $this->_reset_write(); - return $this->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Delete - * - * Compiles a delete string and runs the query - * - * @access public - * @param string the table to retrieve the results from - * @param mixed the where clause - * @return object - */ - function delete($table = '', $where = '') - { - if ($table == '') - { - if ( ! isset($this->ar_from[0])) - { - if ($this->db_debug) - { - return $this->display_error('db_must_set_table'); - } - return FALSE; - } - - $table = $this->ar_from[0]; - } - - if ($where != '') - { - $this->where($where); - } - - if (count($this->ar_where) == 0) - { - if ($this->db_debug) - { - return $this->display_error('db_del_must_use_where'); - } - return FALSE; - } - - $sql = $this->_delete($this->dbprefix.$table, $this->ar_where); - - $this->_reset_write(); - return $this->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Use Table - DEPRECATED - * - * @deprecated use $this->db->from instead - */ - function use_table($table) - { - return $this->from($table); - return $this; - } - - // -------------------------------------------------------------------- - - /** - * ORDER BY - DEPRECATED - * - * @deprecated use $this->db->orderby() instead - */ - function order_by($orderby, $direction = '') - { - return $this->orderby($orderby, $direction); - } - - // -------------------------------------------------------------------- - - /** - * Tests whether the string has an SQL operator - * - * @access private - * @param string - * @return bool - */ - function _has_operator($str) - { - $str = trim($str); - if ( ! preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str)) - { - return FALSE; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Compile the SELECT statement - * - * Generates a query string based on which functions were used. - * Should not be called directly. The get() function calls it. - * - * @access private - * @return string - */ - function _compile_select() - { - $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; - - $sql .= (count($this->ar_select) == 0) ? '*' : implode(', ', $this->ar_select); - - if (count($this->ar_from) > 0) - { - $sql .= "\nFROM "; - $sql .= implode(', ', $this->ar_from); - } - - if (count($this->ar_join) > 0) - { - $sql .= "\n"; - $sql .= implode("\n", $this->ar_join); - } - - if (count($this->ar_where) > 0 OR count($this->ar_like) > 0) - { - $sql .= "\nWHERE "; - } - - $sql .= implode("\n", $this->ar_where); - - if (count($this->ar_like) > 0) - { - if (count($this->ar_where) > 0) - { - $sql .= " AND "; - } - - $sql .= implode("\n", $this->ar_like); - } - - if (count($this->ar_groupby) > 0) - { - $sql .= "\nGROUP BY "; - $sql .= implode(', ', $this->ar_groupby); - } - - if (count($this->ar_having) > 0) - { - $sql .= "\nHAVING "; - $sql .= implode("\n", $this->ar_having); - } - - if (count($this->ar_orderby) > 0) - { - $sql .= "\nORDER BY "; - $sql .= implode(', ', $this->ar_orderby); - - if ($this->ar_order !== FALSE) - { - $sql .= ($this->ar_order == 'desc') ? ' DESC' : ' ASC'; - } - } - - if (is_numeric($this->ar_limit)) - { - $sql .= "\n"; - $sql = $this->_limit($sql, $this->ar_limit, $this->ar_offset); - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Object to Array - * - * Takes an object as input and convers the class variables to array key/vals - * - * @access public - * @param object - * @return array - */ - function _object_to_array($object) - { - if ( ! is_object($object)) - { - return $object; - } - - $array = array(); - foreach (get_object_vars($object) as $key => $val) - { - if ( ! is_object($val) AND ! is_array($val)) - { - $array[$key] = $val; - } - } - - return $array; - } - - // -------------------------------------------------------------------- - - /** - * Resets the active record values. Called by the get() function - * - * @access private - * @return void - */ - function _reset_select() - { - $this->ar_select = array(); - $this->ar_distinct = FALSE; - $this->ar_from = array(); - $this->ar_join = array(); - $this->ar_where = array(); - $this->ar_like = array(); - $this->ar_groupby = array(); - $this->ar_having = array(); - $this->ar_limit = FALSE; - $this->ar_offset = FALSE; - $this->ar_order = FALSE; - $this->ar_orderby = array(); - } - - // -------------------------------------------------------------------- - - /** - * Resets the active record "write" values. - * - * Called by the insert() or update() functions - * - * @access private - * @return void - */ - function _reset_write() - { - $this->ar_set = array(); - $this->ar_from = array(); - $this->ar_where = array(); - } - -} - -?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From a5e812c007b8dfbc4c117df379d63060f08b096a Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 25 Sep 2006 02:17:30 +0000 Subject: --- system/database/DB_result.php | 38 ----------- system/database/DB_utility.php | 50 +++++++------- system/database/drivers/mssql/mssql_driver.php | 66 +------------------ system/database/drivers/mssql/mssql_utility.php | 59 +++++++++++++++-- system/database/drivers/mysql/mysql_driver.php | 62 ----------------- system/database/drivers/mysql/mysql_utility.php | 58 ++++++++++++++-- system/database/drivers/mysqli/mysqli_driver.php | 62 ----------------- system/database/drivers/mysqli/mysqli_utility.php | 58 ++++++++++++++-- system/database/drivers/oci8/oci8_driver.php | 63 ------------------ system/database/drivers/oci8/oci8_utility.php | 77 ++++++++++++++++++---- system/database/drivers/odbc/odbc_driver.php | 62 ----------------- system/database/drivers/odbc/odbc_utility.php | 58 ++++++++++++++-- system/database/drivers/postgre/postgre_driver.php | 60 ----------------- .../database/drivers/postgre/postgre_utility.php | 58 ++++++++++++++-- system/database/drivers/sqlite/sqlite_driver.php | 63 ------------------ system/database/drivers/sqlite/sqlite_utility.php | 61 +++++++++++++++-- 16 files changed, 420 insertions(+), 535 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_result.php b/system/database/DB_result.php index abb6b588b..970a0db68 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -243,44 +243,6 @@ class CI_DB_result { return $result[$this->current_row]; } - /** - * Number of rows in the result set - * - * @access public - * @return integer - */ - function num_rows() - { - // Result supplied by the result adaptor class - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - // Result supplied by the result adaptor class - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - function field_data() - { - // Result supplied by the result adaptor class - } } ?> \ No newline at end of file diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 39dc2cca2..c43b39950 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -24,9 +24,15 @@ */ class CI_DB_utility { + var $db; + + function CI_DB_utility() + { + // Assign the main database object to $this->db + $obj =& get_instance(); + $this->db =& $obj->db; + } - - // -------------------------------------------------------------------- /** * Database Version Number. Returns a string containing the @@ -39,19 +45,19 @@ class CI_DB_utility { { if (FALSE === ($sql = $this->_version())) { - if ($this->db_debug) + if ($this->db->db_debug) { - return $this->display_error('db_unsupported_function'); + return $this->db->display_error('db_unsupported_function'); } return FALSE; } - if ($this->dbdriver == 'oci8') + if ($this->db->dbdriver == 'oci8') { return $sql; - } + } - $query = $this->query($sql); + $query = $this->db->query($sql); $row = $query->row(); return $row->ver; } @@ -65,18 +71,18 @@ class CI_DB_utility { * @return array */ function tables() - { + { if (FALSE === ($sql = $this->_show_tables())) { - if ($this->db_debug) + if ($this->db->db_debug) { - return $this->display_error('db_unsupported_function'); + return $this->db->display_error('db_unsupported_function'); } return FALSE; } $retval = array(); - $query = $this->query($sql); + $query = $this->db->query($sql); if ($query->num_rows() > 0) { @@ -104,8 +110,8 @@ class CI_DB_utility { * @return boolean */ function table_exists($table_name) - { - return ( ! in_array($this->dbprefix.$table_name, $this->tables())) ? FALSE : TRUE; + { + return ( ! in_array($this->db->dbprefix.$table_name, $this->tables())) ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -121,23 +127,23 @@ class CI_DB_utility { { if ($table == '') { - if ($this->db_debug) + if ($this->db->db_debug) { - return $this->display_error('db_field_param_missing'); + return $this->db->display_error('db_field_param_missing'); } return FALSE; } - if (FALSE === ($sql = $this->_show_columns($this->dbprefix.$table))) + if (FALSE === ($sql = $this->_show_columns($this->db->dbprefix.$table))) { - if ($this->db_debug) + if ($this->db->db_debug) { - return $this->display_error('db_unsupported_function'); + return $this->db->display_error('db_unsupported_function'); } return FALSE; } - $query = $this->query($sql); + $query = $this->db->query($sql); $retval = array(); foreach($query->result_array() as $row) @@ -168,14 +174,14 @@ class CI_DB_utility { { if ($table == '') { - if ($this->db_debug) + if ($this->db->db_debug) { - return $this->display_error('db_field_param_missing'); + return $this->db->display_error('db_field_param_missing'); } return FALSE; } - return $this->_field_data($this->dbprefix.$table); + return $this->_field_data($this->db->dbprefix.$table); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index cd808da46..38fce1134 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -386,71 +386,7 @@ class CI_DB_mssql_driver extends CI_DB { function _close($conn_id) { mssql_close($conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _show_columns($table = '') - { - return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$this->_escape_table($table)."'"; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - $sql = "SELECT TOP 1 FROM ".$this->_escape_table($table); - $query = $this->query($sql); - return $query->field_data(); - } - - + } } diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index a76e1f14f..96d112805 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -22,20 +22,71 @@ * @author Rick Ellis * @link http://www.codeigniter.com/user_guide/database/ */ -class CI_DB_mssql_utility { +class CI_DB_mssql_utility extends CI_DB_utility { + + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + // -------------------------------------------------------------------- + /** - * Some function + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched * * @access public - * @return integer + * @return string */ - function something() + function _show_tables() { + return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; } // -------------------------------------------------------------------- + /** + * Show columnn query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _show_columns($table = '') + { + return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$this->db->_escape_table($table)."'"; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + $sql = "SELECT TOP 1 FROM ".$this->db->_escape_table($table); + $query = $this->db->query($sql); + return $query->field_data(); + } + + + } ?> \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index fc7f6780b..545ac1986 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -410,69 +410,7 @@ class CI_DB_mysql_driver extends CI_DB { { mysql_close($conn_id); } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SHOW TABLES FROM `".$this->database."`"; - } - // -------------------------------------------------------------------- - - /** - * Show columnn query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _show_columns($table = '') - { - return "SHOW COLUMNS FROM ".$this->_escape_table($table); - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - $sql = "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; - $query = $this->query($sql); - return $query->field_data(); - } - } ?> \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 8dd764888..9bf2f5aa9 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -22,20 +22,70 @@ * @author Rick Ellis * @link http://www.codeigniter.com/user_guide/database/ */ -class CI_DB_mysql_utility { +class CI_DB_mysql_utility extends CI_DB_utility { + /** - * Some function + * Version number query string * * @access public - * @return integer + * @return string */ - function something() + function _version() { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SHOW TABLES FROM `".$this->db->database."`"; } // -------------------------------------------------------------------- + /** + * Show columnn query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _show_columns($table = '') + { + return "SHOW COLUMNS FROM ".$this->db->_escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + $sql = "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; + $query = $this->db->query($sql); + return $query->field_data(); + } + + } ?> \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 959384164..adc482dfe 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -412,68 +412,6 @@ class CI_DB_mysqli_driver extends CI_DB { mysqli_close($conn_id); } - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SHOW TABLES FROM `".$this->database."`"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _show_columns($table = '') - { - return "SHOW COLUMNS FROM ".$this->_escape_table($table); - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - $sql = "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; - $query = $this->query($sql); - return $query->field_data(); - } - } diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 02b423c30..a1498a33d 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -22,20 +22,70 @@ * @author Rick Ellis * @link http://www.codeigniter.com/user_guide/database/ */ -class CI_DB_mysqli_utility { +class CI_DB_mysqli_utility extends CI_DB_utility { /** - * Some function + * Version number query string * * @access public - * @return integer + * @return string */ - function something() + function _version() { + return "SELECT version() AS ver"; } // -------------------------------------------------------------------- + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SHOW TABLES FROM `".$this->db->database."`"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _show_columns($table = '') + { + return "SHOW COLUMNS FROM ".$this->db->_escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + $sql = "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; + $query = $this->db->query($sql); + return $query->field_data(); + } + + + } ?> \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index bfc38a435..f7f4bd143 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -539,69 +539,6 @@ class CI_DB_oci8_driver extends CI_DB { ocilogoff($conn_id); } - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - $ver = ociserverversion($this->conn_id); - return $ver; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "select TABLE_NAME FROM ALL_TABLES"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _show_columns($table = '') - { - return "SELECT COLUMN_NAME FROM all_tab_columns WHERE table_name = '$table'"; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - $sql = "SELECT * FROM ".$this->_escape_table($table)." where rownum = 1"; - $query = $this->query($sql); - return $query->field_data(); - } - } diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index f1e327a3e..fdd585d98 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -22,19 +22,70 @@ * @author Rick Ellis * @link http://www.codeigniter.com/user_guide/database/ */ -class CI_DB_oci8_utility { - - /** - * Some function - * - * @access public - * @return integer - */ - function something() - { - } - - // -------------------------------------------------------------------- +class CI_DB_oci8_utility extends CI_DB_utility { + + + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return ociserverversion($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "select TABLE_NAME FROM ALL_TABLES"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _show_columns($table = '') + { + return "SELECT COLUMN_NAME FROM all_tab_columns WHERE table_name = '$table'"; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + $sql = "SELECT * FROM ".$this->db->_escape_table($table)." where rownum = 1"; + $query = $this->db->query($sql); + return $query->field_data(); + } + } diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index c05abd082..bef6258de 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -386,68 +386,6 @@ class CI_DB_odbc_driver extends CI_DB { odbc_close($conn_id); } - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SHOW TABLES FROM `".$this->database."`"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _show_columns($table = '') - { - return "SHOW COLUMNS FROM ".$this->_escape_table($table); - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - $sql = "SELECT TOP 1 FROM ".$this->_escape_table($table); - $query = $this->query($sql); - return $query->field_data(); - } - } diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index f2b5602cc..837c8c881 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -22,20 +22,70 @@ * @author Rick Ellis * @link http://www.codeigniter.com/database/ */ -class CI_DB_odbc_utility { +class CI_DB_odbc_utility extends CI_DB_utility { + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + // -------------------------------------------------------------------- + /** - * Some function + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched * * @access public - * @return integer + * @return string */ - function something() + function _show_tables() { + return "SHOW TABLES FROM `".$this->db->database."`"; } // -------------------------------------------------------------------- + /** + * Show columnn query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _show_columns($table = '') + { + return "SHOW COLUMNS FROM ".$this->db->_escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + $sql = "SELECT TOP 1 FROM ".$this->db->_escape_table($table); + $query = $this->db->query($sql); + return $query->field_data(); + } + + + } ?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 03817188f..9c8a18eb5 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -419,66 +419,6 @@ class CI_DB_postgre_driver extends CI_DB { pg_close($conn_id); } - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _show_columns($table = '') - { - return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->_escape_table($table)."'"; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - $sql = "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; - $query = $this->query($sql); - return $query->field_data(); - } - } diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 760be81a0..cfc475f6b 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -22,20 +22,70 @@ * @author Rick Ellis * @link http://www.codeigniter.com/user_guide/database/ */ -class CI_DB_postgre_utility { +class CI_DB_postgre_utility extends CI_DB_utility { + /** - * Some function + * Version number query string * * @access public - * @return integer + * @return string */ - function something() + function _version() { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; } // -------------------------------------------------------------------- + /** + * Show columnn query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _show_columns($table = '') + { + return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->db->_escape_table($table)."'"; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + $sql = "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; + $query = $this->db->query($sql); + return $query->field_data(); + } + + } ?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index f8318b814..603984575 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -413,69 +413,6 @@ class CI_DB_sqlite_driver extends CI_DB { sqlite_close($conn_id); } - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return sqlite_libversion(); - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SELECT name from sqlite_master WHERE type='table'"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _show_columns($table = '') - { - // Not supported - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - $sql = "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; - $query = $this->query($sql); - return $query->field_data(); - } - } diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 3cbec6f14..2b99df907 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -22,20 +22,71 @@ * @author Rick Ellis * @link http://www.codeigniter.com/user_guide/database/ */ -class CI_DB_sqlite_utility { - +class CI_DB_sqlite_utility extends CI_DB_utility { + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return sqlite_libversion(); + } + + // -------------------------------------------------------------------- + /** - * Some function + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched * * @access public - * @return integer + * @return string */ - function something() + function _show_tables() { + return "SELECT name from sqlite_master WHERE type='table'"; } // -------------------------------------------------------------------- + /** + * Show columnn query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _show_columns($table = '') + { + // Not supported + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + $sql = "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; + $query = $this->db->query($sql); + return $query->field_data(); + } + + + } ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 6ca6f9471ba31f7cba9054d075b4f90382b2d410 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 25 Sep 2006 02:51:08 +0000 Subject: --- system/database/DB_utility.php | 6 ---- system/database/drivers/mssql/mssql_utility.php | 28 ++++++++++++++++ system/database/drivers/mysql/mysql_utility.php | 28 ++++++++++++++++ system/database/drivers/mysqli/mysqli_utility.php | 28 ++++++++++++++++ system/database/drivers/oci8/oci8_utility.php | 27 +++++++++++++++ system/database/drivers/odbc/odbc_utility.php | 33 +++++++++++++++++++ .../database/drivers/postgre/postgre_utility.php | 28 ++++++++++++++++ system/database/drivers/sqlite/sqlite_utility.php | 38 ++++++++++++++++++++++ 8 files changed, 210 insertions(+), 6 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index c43b39950..d96fffa04 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -212,13 +212,7 @@ class CI_DB_utility { - function create_database() - { - } - function drop_database() - { - } function show_databases() { diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index 96d112805..9ff92d41b 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -24,6 +24,34 @@ */ class CI_DB_mssql_utility extends CI_DB_utility { + + /** + * Create database + * + * @access public + * @param string the database name + * @return bool + */ + function create_database($name) + { + return $this->db->query("CREATE DATABASE ".$this->db->_escape_table($name)); + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access public + * @param string the database name + * @return bool + */ + function drop_database($name) + { + return $this->db->query("DROP DATABASE ".$this->db->_escape_table($name)); + } + + // -------------------------------------------------------------------- /** * Version number query string diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 9bf2f5aa9..d4e97867a 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -24,6 +24,33 @@ */ class CI_DB_mysql_utility extends CI_DB_utility { + /** + * Create database + * + * @access public + * @param string the database name + * @return bool + */ + function create_database($name) + { + return $this->db->query("CREATE DATABASE ".$this->db->_escape_table($name)); + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access public + * @param string the database name + * @return bool + */ + function drop_database($name) + { + return $this->db->query("DROP DATABASE ".$this->db->_escape_table($name)); + } + + // -------------------------------------------------------------------- /** * Version number query string @@ -86,6 +113,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { } + } ?> \ 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 a1498a33d..9c773b4b9 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -24,6 +24,34 @@ */ class CI_DB_mysqli_utility extends CI_DB_utility { + /** + * Create database + * + * @access public + * @param string the database name + * @return bool + */ + function create_database($name) + { + return $this->db->query("CREATE DATABASE ".$this->db->_escape_table($name)); + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access public + * @param string the database name + * @return bool + */ + function drop_database($name) + { + return $this->db->query("DROP DATABASE ".$this->db->_escape_table($name)); + } + + // -------------------------------------------------------------------- + /** * Version number query string * diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index fdd585d98..35b753ec6 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -25,6 +25,33 @@ class CI_DB_oci8_utility extends CI_DB_utility { + /** + * Create database + * + * @access public + * @param string the database name + * @return bool + */ + function create_database($name) + { + + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access public + * @param string the database name + * @return bool + */ + function drop_database($name) + { + + } + + // -------------------------------------------------------------------- /** * Version number query string diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index 837c8c881..51fec8eed 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -24,6 +24,39 @@ */ class CI_DB_odbc_utility extends CI_DB_utility { + + /** + * Create database + * + * @access public + * @param string the database name + * @return bool + */ + function create_database($name) + { + // ODBC has no "create database" command since it's + // designed to connect to an existing database + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access public + * @param string the database name + * @return bool + */ + function drop_database($name) + { + // ODBC has no "drop database" command since it's + // designed to connect to an existing database + return FALSE; + } + + // -------------------------------------------------------------------- + /** * Version number query string * diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index cfc475f6b..c38cf6e69 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -25,6 +25,34 @@ class CI_DB_postgre_utility extends CI_DB_utility { + /** + * Create database + * + * @access public + * @param string the database name + * @return bool + */ + function create_database($name) + { + return $this->db->query("CREATE DATABASE ".$this->db->_escape_table($name)); + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access public + * @param string the database name + * @return bool + */ + function drop_database($name) + { + return $this->db->query("DROP DATABASE ".$this->db->_escape_table($name)); + } + + // -------------------------------------------------------------------- + /** * Version number query string * diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 2b99df907..8cbf0d56d 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -24,6 +24,44 @@ */ class CI_DB_sqlite_utility extends CI_DB_utility { + + /** + * Create database + * + * @access public + * @param string the database name + * @return bool + */ + function create_database() + { + // In SQLite, a database is created when you connect to the database + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access public + * @param string the database name + * @return bool + */ + function drop_database($name) + { + if ( ! @file_exists($this->db->database) OR ! @unlink($this->db->database)) + { + if ($this->db_debug) + { + return $this->display_error('db_unable_to_drop'); + } + return FALSE; + } + return TRUE; + } + + // -------------------------------------------------------------------- + /** * Version number query string * -- cgit v1.2.3-24-g4f1b From 72496373008b263e098cf6082cdce1d47d01d3f1 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 25 Sep 2006 03:44:04 +0000 Subject: --- system/database/DB_utility.php | 7 ------ system/database/drivers/mssql/mssql_utility.php | 23 ++++++++++++++++++ system/database/drivers/mysql/mysql_utility.php | 23 ++++++++++++++++++ system/database/drivers/mysqli/mysqli_utility.php | 23 ++++++++++++++++++ system/database/drivers/oci8/oci8_utility.php | 12 +++++++++- system/database/drivers/odbc/odbc_utility.php | 28 +++++++++++++++++++++- .../database/drivers/postgre/postgre_utility.php | 23 ++++++++++++++++++ system/database/drivers/sqlite/sqlite_utility.php | 17 +++++++++++++ 8 files changed, 147 insertions(+), 9 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index d96fffa04..b17b3d51c 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -211,13 +211,6 @@ class CI_DB_utility { - - - - function show_databases() - { - } - function create_table() { } diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index 9ff92d41b..bc398e7f7 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -51,6 +51,29 @@ class CI_DB_mssql_utility extends CI_DB_utility { return $this->db->query("DROP DATABASE ".$this->db->_escape_table($name)); } + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access public + * @return bool + */ + function list_databases() + { + $query = $this->db->query("EXEC sp_helpdb"); // Can also be: EXEC sp_databases + $dbs = array(); + if ($query->num_rows() > 0) + { + foreach ($query->result_array() as $row) + { + $dbs[] = current($row); + } + } + + return $dbs; + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index d4e97867a..5bbf46810 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -52,6 +52,29 @@ class CI_DB_mysql_utility extends CI_DB_utility { // -------------------------------------------------------------------- + /** + * List databases + * + * @access public + * @return bool + */ + function list_databases() + { + $query = $this->db->query("SHOW DATABASES"); + $dbs = array(); + if ($query->num_rows() > 0) + { + foreach ($query->result_array() as $row) + { + $dbs[] = current($row); + } + } + + return $dbs; + } + + // -------------------------------------------------------------------- + /** * Version number query string * diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 9c773b4b9..14a6ef8cf 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -52,6 +52,29 @@ class CI_DB_mysqli_utility extends CI_DB_utility { // -------------------------------------------------------------------- + /** + * List databases + * + * @access public + * @return bool + */ + function list_databases() + { + $query = $this->db->query("SHOW DATABASES"); + $dbs = array(); + if ($query->num_rows() > 0) + { + foreach ($query->result_array() as $row) + { + $dbs[] = current($row); + } + } + + return $dbs; + } + + // -------------------------------------------------------------------- + /** * Version number query string * diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 35b753ec6..03edcb2c8 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -34,7 +34,6 @@ class CI_DB_oci8_utility extends CI_DB_utility { */ function create_database($name) { - } // -------------------------------------------------------------------- @@ -48,7 +47,18 @@ class CI_DB_oci8_utility extends CI_DB_utility { */ function drop_database($name) { + } + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access public + * @return bool + */ + function list_databases() + { } // -------------------------------------------------------------------- diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index 51fec8eed..42537de70 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -36,6 +36,10 @@ class CI_DB_odbc_utility extends CI_DB_utility { { // ODBC has no "create database" command since it's // designed to connect to an existing database + if ($this->db_debug) + { + return $this->display_error('db_unsuported_feature'); + } return FALSE; } @@ -51,7 +55,29 @@ class CI_DB_odbc_utility extends CI_DB_utility { function drop_database($name) { // ODBC has no "drop database" command since it's - // designed to connect to an existing database + // designed to connect to an existing database + if ($this->db_debug) + { + return $this->display_error('db_unsuported_feature'); + } + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access public + * @return bool + */ + function list_databases() + { + // Not sure if ODBC lets you list all databases... + if ($this->db_debug) + { + return $this->display_error('db_unsuported_feature'); + } return FALSE; } diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index c38cf6e69..103f8d553 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -53,6 +53,29 @@ class CI_DB_postgre_utility extends CI_DB_utility { // -------------------------------------------------------------------- + /** + * List databases + * + * @access public + * @return bool + */ + function list_databases() + { + $query = $this->db->query("SELECT datname FROM pg_database"); + $dbs = array(); + if ($query->num_rows() > 0) + { + foreach ($query->result_array() as $row) + { + $dbs[] = current($row); + } + } + + return $dbs; + } + + // -------------------------------------------------------------------- + /** * Version number query string * diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 8cbf0d56d..5f1f02eab 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -62,6 +62,23 @@ class CI_DB_sqlite_utility extends CI_DB_utility { // -------------------------------------------------------------------- + /** + * List databases + * + * @access public + * @return bool + */ + function list_databases() + { + if ($this->db_debug) + { + return $this->display_error('db_unsuported_feature'); + } + return array(); + } + + // -------------------------------------------------------------------- + /** * Version number query string * -- cgit v1.2.3-24-g4f1b From 4ceac2d4efa5a16486b6e97911bb32e261b9d648 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 25 Sep 2006 06:40:16 +0000 Subject: --- system/database/DB_utility.php | 1 - system/database/drivers/mssql/mssql_utility.php | 17 +++++++++++++++-- system/database/drivers/mysql/mysql_utility.php | 17 +++++++++++++++-- system/database/drivers/mysqli/mysqli_utility.php | 17 +++++++++++++++-- system/database/drivers/oci8/oci8_utility.php | 12 ++++++++++++ system/database/drivers/odbc/odbc_utility.php | 18 ++++++++++++++++++ system/database/drivers/postgre/postgre_utility.php | 17 +++++++++++++++-- system/database/drivers/sqlite/sqlite_utility.php | 17 +++++++++++++++++ 8 files changed, 107 insertions(+), 9 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index b17b3d51c..8e1921dbc 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -210,7 +210,6 @@ class CI_DB_utility { - function create_table() { } diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index bc398e7f7..61fe5fcbc 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -34,7 +34,7 @@ class CI_DB_mssql_utility extends CI_DB_utility { */ function create_database($name) { - return $this->db->query("CREATE DATABASE ".$this->db->_escape_table($name)); + return $this->db->query("CREATE DATABASE ".$name); } // -------------------------------------------------------------------- @@ -48,7 +48,7 @@ class CI_DB_mssql_utility extends CI_DB_utility { */ function drop_database($name) { - return $this->db->query("DROP DATABASE ".$this->db->_escape_table($name)); + return $this->db->query("DROP DATABASE ".$name); } // -------------------------------------------------------------------- @@ -74,6 +74,19 @@ class CI_DB_mssql_utility extends CI_DB_utility { return $dbs; } + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * @access public + * @return bool + */ + function drop_table($table) + { + "DROP TABLE ".$this->db->_escape_table($name); + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 5bbf46810..23c4e094d 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -33,7 +33,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { */ function create_database($name) { - return $this->db->query("CREATE DATABASE ".$this->db->_escape_table($name)); + return $this->db->query("CREATE DATABASE ".$name); } // -------------------------------------------------------------------- @@ -47,7 +47,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { */ function drop_database($name) { - return $this->db->query("DROP DATABASE ".$this->db->_escape_table($name)); + return $this->db->query("DROP DATABASE ".$name); } // -------------------------------------------------------------------- @@ -75,6 +75,19 @@ class CI_DB_mysql_utility extends CI_DB_utility { // -------------------------------------------------------------------- + /** + * Drop Table + * + * @access public + * @return bool + */ + function drop_table($table) + { + "DROP TABLE IF EXISTS ".$this->db->_escape_table($name); + } + + // -------------------------------------------------------------------- + /** * Version number query string * diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 14a6ef8cf..ca8f3fe34 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -33,7 +33,7 @@ class CI_DB_mysqli_utility extends CI_DB_utility { */ function create_database($name) { - return $this->db->query("CREATE DATABASE ".$this->db->_escape_table($name)); + return $this->db->query("CREATE DATABASE ".$name); } // -------------------------------------------------------------------- @@ -47,7 +47,7 @@ class CI_DB_mysqli_utility extends CI_DB_utility { */ function drop_database($name) { - return $this->db->query("DROP DATABASE ".$this->db->_escape_table($name)); + return $this->db->query("DROP DATABASE ".$name); } // -------------------------------------------------------------------- @@ -72,6 +72,19 @@ class CI_DB_mysqli_utility extends CI_DB_utility { return $dbs; } + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * @access public + * @return bool + */ + function drop_table($table) + { + "DROP TABLE IF EXISTS ".$this->db->_escape_table($name); + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 03edcb2c8..7e3ee7285 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -63,6 +63,18 @@ class CI_DB_oci8_utility extends CI_DB_utility { // -------------------------------------------------------------------- + /** + * Drop Table + * + * @access public + * @return bool + */ + function drop_table($table) + { + } + + // -------------------------------------------------------------------- + /** * Version number query string * diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index 42537de70..cfd829cb6 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -83,6 +83,24 @@ class CI_DB_odbc_utility extends CI_DB_utility { // -------------------------------------------------------------------- + /** + * Drop Table + * + * @access public + * @return bool + */ + function drop_table($table) + { + // Not a supported ODBC feature + if ($this->db_debug) + { + return $this->display_error('db_unsuported_feature'); + } + return FALSE; + } + + // -------------------------------------------------------------------- + /** * Version number query string * diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 103f8d553..7bb210ab7 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -34,7 +34,7 @@ class CI_DB_postgre_utility extends CI_DB_utility { */ function create_database($name) { - return $this->db->query("CREATE DATABASE ".$this->db->_escape_table($name)); + return $this->db->query("CREATE DATABASE ".$name); } // -------------------------------------------------------------------- @@ -48,7 +48,7 @@ class CI_DB_postgre_utility extends CI_DB_utility { */ function drop_database($name) { - return $this->db->query("DROP DATABASE ".$this->db->_escape_table($name)); + return $this->db->query("DROP DATABASE ".$name); } // -------------------------------------------------------------------- @@ -73,6 +73,19 @@ class CI_DB_postgre_utility extends CI_DB_utility { return $dbs; } + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * @access public + * @return bool + */ + function drop_table($table) + { + "DROP TABLE ".$this->db->_escape_table($name)." CASCADE"; + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 5f1f02eab..744ca3f37 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -79,6 +79,23 @@ class CI_DB_sqlite_utility extends CI_DB_utility { // -------------------------------------------------------------------- + /** + * Drop Table + * + * @access public + * @return bool + */ + function drop_table($table) + { + if ($this->db_debug) + { + return $this->display_error('db_unsuported_feature'); + } + return array(); + } + + // -------------------------------------------------------------------- + /** * Version number query string * -- cgit v1.2.3-24-g4f1b From 6cec6a58d993fb0b1beb5fac7ea0d1cb9769c0a4 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 25 Sep 2006 06:56:49 +0000 Subject: --- system/database/DB_utility.php | 29 +++++++++++++++++++++- system/database/drivers/mssql/mssql_utility.php | 12 ++++----- system/database/drivers/mysql/mysql_utility.php | 12 ++++----- system/database/drivers/mysqli/mysqli_utility.php | 12 ++++----- system/database/drivers/oci8/oci8_utility.php | 6 ++--- system/database/drivers/odbc/odbc_utility.php | 8 +++--- .../database/drivers/postgre/postgre_utility.php | 12 ++++----- system/database/drivers/sqlite/sqlite_utility.php | 6 ++--- 8 files changed, 55 insertions(+), 42 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 8e1921dbc..128984d4f 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -181,7 +181,8 @@ class CI_DB_utility { return FALSE; } - return $this->_field_data($this->db->dbprefix.$table); + $query = $this->db->query($this->_field_data($this->db->dbprefix.$table)); + return $query->field_data(); } // -------------------------------------------------------------------- @@ -208,6 +209,32 @@ class CI_DB_utility { return current($fields); } + // -------------------------------------------------------------------- + + /** + * Create database + * + * @access public + * @param string the database name + * @return bool + */ + function create_database($name) + { + $sql = $this->_create_database($name); + + if (is_bool($sql)) + { + return $sql; + } + + return $this->db->query($sql); + } + + // -------------------------------------------------------------------- + + + + function create_table() diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index 61fe5fcbc..49b63b7d0 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -28,13 +28,13 @@ class CI_DB_mssql_utility extends CI_DB_utility { /** * Create database * - * @access public + * @access private * @param string the database name * @return bool */ - function create_database($name) + function _create_database($name) { - return $this->db->query("CREATE DATABASE ".$name); + return "CREATE DATABASE ".$name; } // -------------------------------------------------------------------- @@ -84,7 +84,7 @@ class CI_DB_mssql_utility extends CI_DB_utility { */ function drop_table($table) { - "DROP TABLE ".$this->db->_escape_table($name); + return $this->db->query("DROP TABLE ".$this->db->_escape_table($name)); } // -------------------------------------------------------------------- @@ -144,9 +144,7 @@ class CI_DB_mssql_utility extends CI_DB_utility { */ function _field_data($table) { - $sql = "SELECT TOP 1 FROM ".$this->db->_escape_table($table); - $query = $this->db->query($sql); - return $query->field_data(); + return "SELECT TOP 1 FROM ".$this->db->_escape_table($table); } diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 23c4e094d..e5f8e850d 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -27,13 +27,13 @@ class CI_DB_mysql_utility extends CI_DB_utility { /** * Create database * - * @access public + * @access private * @param string the database name * @return bool */ - function create_database($name) + function _create_database($name) { - return $this->db->query("CREATE DATABASE ".$name); + return "CREATE DATABASE ".$name; } // -------------------------------------------------------------------- @@ -83,7 +83,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { */ function drop_table($table) { - "DROP TABLE IF EXISTS ".$this->db->_escape_table($name); + return $this->db->query("DROP TABLE IF EXISTS ".$this->db->_escape_table($name)); } // -------------------------------------------------------------------- @@ -143,9 +143,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { */ function _field_data($table) { - $sql = "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; - $query = $this->db->query($sql); - return $query->field_data(); + return "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; } diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index ca8f3fe34..1775047ca 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -27,13 +27,13 @@ class CI_DB_mysqli_utility extends CI_DB_utility { /** * Create database * - * @access public + * @access private * @param string the database name * @return bool */ - function create_database($name) + function _create_database($name) { - return $this->db->query("CREATE DATABASE ".$name); + return "CREATE DATABASE ".$name; } // -------------------------------------------------------------------- @@ -83,7 +83,7 @@ class CI_DB_mysqli_utility extends CI_DB_utility { */ function drop_table($table) { - "DROP TABLE IF EXISTS ".$this->db->_escape_table($name); + return $this->db->query("DROP TABLE IF EXISTS ".$this->db->_escape_table($name)); } // -------------------------------------------------------------------- @@ -143,9 +143,7 @@ class CI_DB_mysqli_utility extends CI_DB_utility { */ function _field_data($table) { - $sql = "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; - $query = $this->db->query($sql); - return $query->field_data(); + return "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; } diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 7e3ee7285..74b0165cb 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -32,7 +32,7 @@ class CI_DB_oci8_utility extends CI_DB_utility { * @param string the database name * @return bool */ - function create_database($name) + function _create_database($name) { } @@ -130,9 +130,7 @@ class CI_DB_oci8_utility extends CI_DB_utility { */ function _field_data($table) { - $sql = "SELECT * FROM ".$this->db->_escape_table($table)." where rownum = 1"; - $query = $this->db->query($sql); - return $query->field_data(); + return "SELECT * FROM ".$this->db->_escape_table($table)." where rownum = 1"; } diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index cfd829cb6..74f8d3905 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -28,11 +28,11 @@ class CI_DB_odbc_utility extends CI_DB_utility { /** * Create database * - * @access public + * @access private * @param string the database name * @return bool */ - function create_database($name) + function _create_database() { // ODBC has no "create database" command since it's // designed to connect to an existing database @@ -156,9 +156,7 @@ class CI_DB_odbc_utility extends CI_DB_utility { */ function _field_data($table) { - $sql = "SELECT TOP 1 FROM ".$this->db->_escape_table($table); - $query = $this->db->query($sql); - return $query->field_data(); + return "SELECT TOP 1 FROM ".$this->db->_escape_table($table); } diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 7bb210ab7..8e51623be 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -28,13 +28,13 @@ class CI_DB_postgre_utility extends CI_DB_utility { /** * Create database * - * @access public + * @access private * @param string the database name * @return bool */ - function create_database($name) + function _create_database($name) { - return $this->db->query("CREATE DATABASE ".$name); + return "CREATE DATABASE ".$name; } // -------------------------------------------------------------------- @@ -84,7 +84,7 @@ class CI_DB_postgre_utility extends CI_DB_utility { */ function drop_table($table) { - "DROP TABLE ".$this->db->_escape_table($name)." CASCADE"; + return $this->db->query("DROP TABLE ".$this->db->_escape_table($name)." CASCADE"); } // -------------------------------------------------------------------- @@ -144,9 +144,7 @@ class CI_DB_postgre_utility extends CI_DB_utility { */ function _field_data($table) { - $sql = "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; - $query = $this->db->query($sql); - return $query->field_data(); + return "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; } diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 744ca3f37..14b406a5c 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -32,7 +32,7 @@ class CI_DB_sqlite_utility extends CI_DB_utility { * @param string the database name * @return bool */ - function create_database() + function _create_database() { // In SQLite, a database is created when you connect to the database return TRUE; @@ -152,9 +152,7 @@ class CI_DB_sqlite_utility extends CI_DB_utility { */ function _field_data($table) { - $sql = "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; - $query = $this->db->query($sql); - return $query->field_data(); + return "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; } -- cgit v1.2.3-24-g4f1b From 83b05a860a5f208d15942b517385848cfe4887bb Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 25 Sep 2006 21:06:46 +0000 Subject: --- system/database/DB_utility.php | 60 +++++++++++++++++++++- system/database/drivers/mssql/mssql_utility.php | 28 ++++------ system/database/drivers/mysql/mysql_utility.php | 28 ++++------ system/database/drivers/mysqli/mysqli_utility.php | 28 ++++------ system/database/drivers/oci8/oci8_utility.php | 16 +++--- system/database/drivers/odbc/odbc_utility.php | 12 ++--- .../database/drivers/postgre/postgre_utility.php | 28 ++++------ system/database/drivers/sqlite/sqlite_utility.php | 12 ++--- 8 files changed, 116 insertions(+), 96 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 128984d4f..36d74c5b3 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -232,14 +232,70 @@ class CI_DB_utility { // -------------------------------------------------------------------- + /** + * Drop database + * + * @access public + * @param string the database name + * @return bool + */ + function drop_database($name) + { + $sql = $this->_drop_database($name); + + if (is_bool($sql)) + { + return $sql; + } + + return $this->db->query($sql); + } + // -------------------------------------------------------------------- + /** + * List databases + * + * @access public + * @return bool + */ + function list_databases() + { + $query = $this->db->query($this->_list_database()); + $dbs = array(); + if ($query->num_rows() > 0) + { + foreach ($query->result_array() as $row) + { + $dbs[] = current($row); + } + } + + return $dbs; + } + // -------------------------------------------------------------------- - - function create_table() + /** + * Drop Table + * + * @access public + * @param string the table name + * @return bool + */ + function drop_table($name) { + $sql = $this->_drop_table($name); + + if (is_bool($sql)) + { + return $sql; + } + + return $this->db->query($sql); } + + function alter_table() { diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index 49b63b7d0..b85a420e7 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -42,13 +42,13 @@ class CI_DB_mssql_utility extends CI_DB_utility { /** * Drop database * - * @access public + * @access private * @param string the database name * @return bool */ - function drop_database($name) + function _drop_database($name) { - return $this->db->query("DROP DATABASE ".$name); + return "DROP DATABASE ".$name; } // -------------------------------------------------------------------- @@ -56,22 +56,12 @@ class CI_DB_mssql_utility extends CI_DB_utility { /** * List databases * - * @access public + * @access private * @return bool */ - function list_databases() + function _list_databases() { - $query = $this->db->query("EXEC sp_helpdb"); // Can also be: EXEC sp_databases - $dbs = array(); - if ($query->num_rows() > 0) - { - foreach ($query->result_array() as $row) - { - $dbs[] = current($row); - } - } - - return $dbs; + return "EXEC sp_helpdb"; // Can also be: EXEC sp_databases } // -------------------------------------------------------------------- @@ -79,12 +69,12 @@ class CI_DB_mssql_utility extends CI_DB_utility { /** * Drop Table * - * @access public + * @access private * @return bool */ - function drop_table($table) + function _drop_table($table) { - return $this->db->query("DROP TABLE ".$this->db->_escape_table($name)); + return "DROP TABLE ".$this->db->_escape_table($name); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index e5f8e850d..a0c746207 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -41,13 +41,13 @@ class CI_DB_mysql_utility extends CI_DB_utility { /** * Drop database * - * @access public + * @access private * @param string the database name * @return bool */ - function drop_database($name) + function _drop_database($name) { - return $this->db->query("DROP DATABASE ".$name); + return "DROP DATABASE ".$name; } // -------------------------------------------------------------------- @@ -55,22 +55,12 @@ class CI_DB_mysql_utility extends CI_DB_utility { /** * List databases * - * @access public + * @access private * @return bool */ - function list_databases() + function _list_databases() { - $query = $this->db->query("SHOW DATABASES"); - $dbs = array(); - if ($query->num_rows() > 0) - { - foreach ($query->result_array() as $row) - { - $dbs[] = current($row); - } - } - - return $dbs; + return "SHOW DATABASES"; } // -------------------------------------------------------------------- @@ -78,12 +68,12 @@ class CI_DB_mysql_utility extends CI_DB_utility { /** * Drop Table * - * @access public + * @access private * @return bool */ - function drop_table($table) + function _drop_table($table) { - return $this->db->query("DROP TABLE IF EXISTS ".$this->db->_escape_table($name)); + return "DROP TABLE IF EXISTS ".$this->db->_escape_table($name); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 1775047ca..328661866 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -41,13 +41,13 @@ class CI_DB_mysqli_utility extends CI_DB_utility { /** * Drop database * - * @access public + * @access private * @param string the database name * @return bool */ - function drop_database($name) + function _drop_database($name) { - return $this->db->query("DROP DATABASE ".$name); + return "DROP DATABASE ".$name; } // -------------------------------------------------------------------- @@ -55,22 +55,12 @@ class CI_DB_mysqli_utility extends CI_DB_utility { /** * List databases * - * @access public + * @access private * @return bool */ - function list_databases() + function _list_databases() { - $query = $this->db->query("SHOW DATABASES"); - $dbs = array(); - if ($query->num_rows() > 0) - { - foreach ($query->result_array() as $row) - { - $dbs[] = current($row); - } - } - - return $dbs; + return "SHOW DATABASES"; } // -------------------------------------------------------------------- @@ -78,12 +68,12 @@ class CI_DB_mysqli_utility extends CI_DB_utility { /** * Drop Table * - * @access public + * @access private * @return bool */ - function drop_table($table) + function _drop_table($table) { - return $this->db->query("DROP TABLE IF EXISTS ".$this->db->_escape_table($name)); + return "DROP TABLE IF EXISTS ".$this->db->_escape_table($name); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 74b0165cb..9c3059f41 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -34,6 +34,7 @@ class CI_DB_oci8_utility extends CI_DB_utility { */ function _create_database($name) { + return FALSE; } // -------------------------------------------------------------------- @@ -41,12 +42,13 @@ class CI_DB_oci8_utility extends CI_DB_utility { /** * Drop database * - * @access public + * @access private * @param string the database name * @return bool */ - function drop_database($name) + function _drop_database($name) { + return FALSE; } // -------------------------------------------------------------------- @@ -54,11 +56,12 @@ class CI_DB_oci8_utility extends CI_DB_utility { /** * List databases * - * @access public + * @access private * @return bool */ - function list_databases() + function _list_databases() { + return FALSE; } // -------------------------------------------------------------------- @@ -66,11 +69,12 @@ class CI_DB_oci8_utility extends CI_DB_utility { /** * Drop Table * - * @access public + * @access private * @return bool */ - function drop_table($table) + function _drop_table($table) { + return FALSE; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index 74f8d3905..5b4558f68 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -48,11 +48,11 @@ class CI_DB_odbc_utility extends CI_DB_utility { /** * Drop database * - * @access public + * @access private * @param string the database name * @return bool */ - function drop_database($name) + function _drop_database($name) { // ODBC has no "drop database" command since it's // designed to connect to an existing database @@ -68,10 +68,10 @@ class CI_DB_odbc_utility extends CI_DB_utility { /** * List databases * - * @access public + * @access private * @return bool */ - function list_databases() + function _list_databases() { // Not sure if ODBC lets you list all databases... if ($this->db_debug) @@ -86,10 +86,10 @@ class CI_DB_odbc_utility extends CI_DB_utility { /** * Drop Table * - * @access public + * @access private * @return bool */ - function drop_table($table) + function _drop_table($table) { // Not a supported ODBC feature if ($this->db_debug) diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 8e51623be..b31609aea 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -42,13 +42,13 @@ class CI_DB_postgre_utility extends CI_DB_utility { /** * Drop database * - * @access public + * @access private * @param string the database name * @return bool */ - function drop_database($name) + function _drop_database($name) { - return $this->db->query("DROP DATABASE ".$name); + return "DROP DATABASE ".$name; } // -------------------------------------------------------------------- @@ -56,22 +56,12 @@ class CI_DB_postgre_utility extends CI_DB_utility { /** * List databases * - * @access public + * @access private * @return bool */ - function list_databases() + function _list_databases() { - $query = $this->db->query("SELECT datname FROM pg_database"); - $dbs = array(); - if ($query->num_rows() > 0) - { - foreach ($query->result_array() as $row) - { - $dbs[] = current($row); - } - } - - return $dbs; + return "SELECT datname FROM pg_database"; } // -------------------------------------------------------------------- @@ -79,12 +69,12 @@ class CI_DB_postgre_utility extends CI_DB_utility { /** * Drop Table * - * @access public + * @access private * @return bool */ - function drop_table($table) + function _drop_table($table) { - return $this->db->query("DROP TABLE ".$this->db->_escape_table($name)." CASCADE"); + return "DROP TABLE ".$this->db->_escape_table($name)." CASCADE"; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 14b406a5c..754a755e4 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -43,11 +43,11 @@ class CI_DB_sqlite_utility extends CI_DB_utility { /** * Drop database * - * @access public + * @access private * @param string the database name * @return bool */ - function drop_database($name) + function _drop_database($name) { if ( ! @file_exists($this->db->database) OR ! @unlink($this->db->database)) { @@ -65,10 +65,10 @@ class CI_DB_sqlite_utility extends CI_DB_utility { /** * List databases * - * @access public + * @access private * @return bool */ - function list_databases() + function _list_databases() { if ($this->db_debug) { @@ -82,10 +82,10 @@ class CI_DB_sqlite_utility extends CI_DB_utility { /** * Drop Table * - * @access public + * @access private * @return bool */ - function drop_table($table) + function _drop_table($table) { if ($this->db_debug) { -- cgit v1.2.3-24-g4f1b From e106318c19938c621198924ab5d292592dbb4477 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 25 Sep 2006 22:12:16 +0000 Subject: --- system/database/DB_result.php | 72 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 970a0db68..32c51e07b 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -35,6 +35,7 @@ class CI_DB_result { var $result_object = array(); var $current_row = 0; + /** * Query result. Acts as a wrapper function for the following functions. * @@ -46,7 +47,7 @@ class CI_DB_result { { return ($type == 'object') ? $this->result_object() : $this->result_array(); } - + // -------------------------------------------------------------------- /** @@ -243,6 +244,75 @@ class CI_DB_result { return $result[$this->current_row]; } + // -------------------------------------------------------------------- + + /** + * Number of rows in the result set + * + * @access public + * @return integer + */ + function num_rows() + { + // Implemented in the platform-specific result adapter + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + // Implemented in the platform-specific result adapter + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function field_names() + { + // Implemented in the platform-specific result adapter + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + // Implemented in the platform-specific result adapter + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return null + */ + function free_result() + { + // Implemented in the platform-specific result adapter + } + + } ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From ab4f61bacfa022c0c7238e9661ad9cb2ac440d95 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 25 Sep 2006 22:12:32 +0000 Subject: --- system/database/DB_utility.php | 114 +++++++++++++-------- system/database/drivers/mssql/mssql_result.php | 23 ++++- system/database/drivers/mssql/mssql_utility.php | 31 ++++++ system/database/drivers/mysql/mysql_result.php | 21 ++++ system/database/drivers/mysql/mysql_utility.php | 33 ++++++ system/database/drivers/mysqli/mysqli_result.php | 23 ++++- system/database/drivers/mysqli/mysqli_utility.php | 31 ++++++ system/database/drivers/oci8/oci8_result.php | 21 ++++ system/database/drivers/oci8/oci8_utility.php | 32 ++++++ system/database/drivers/odbc/odbc_result.php | 23 ++++- system/database/drivers/odbc/odbc_utility.php | 41 ++++++++ system/database/drivers/postgre/postgre_result.php | 23 ++++- .../database/drivers/postgre/postgre_utility.php | 32 ++++++ system/database/drivers/sqlite/sqlite_result.php | 23 ++++- system/database/drivers/sqlite/sqlite_utility.php | 31 ++++++ 15 files changed, 454 insertions(+), 48 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 36d74c5b3..950db7dfd 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -64,6 +64,30 @@ class CI_DB_utility { // -------------------------------------------------------------------- + /** + * Primary + * + * Retrieves the primary key. It assumes that the row in the first + * position is the primary key + * + * @access public + * @param string the table name + * @return string + */ + function primary($table = '') + { + $fields = $this->field_names($table); + + if ( ! is_array($fields)) + { + return FALSE; + } + + return current($fields); + } + + // -------------------------------------------------------------------- + /** * Returns an array of table names * @@ -187,30 +211,6 @@ class CI_DB_utility { // -------------------------------------------------------------------- - /** - * Primary - * - * Retrieves the primary key. It assumes that the row in the first - * position is the primary key - * - * @access public - * @param string the table name - * @return string - */ - function primary($table = '') - { - $fields = $this->field_names($table); - - if ( ! is_array($fields)) - { - return FALSE; - } - - return current($fields); - } - - // -------------------------------------------------------------------- - /** * Create database * @@ -218,9 +218,9 @@ class CI_DB_utility { * @param string the database name * @return bool */ - function create_database($name) + function create_database($db_name) { - $sql = $this->_create_database($name); + $sql = $this->_create_database($db_name); if (is_bool($sql)) { @@ -239,9 +239,9 @@ class CI_DB_utility { * @param string the database name * @return bool */ - function drop_database($name) + function drop_database($db_name) { - $sql = $this->_drop_database($name); + $sql = $this->_drop_database($db_name); if (is_bool($sql)) { @@ -273,48 +273,76 @@ class CI_DB_utility { return $dbs; } - + // -------------------------------------------------------------------- /** - * Drop Table + * Optimize Table * * @access public * @param string the table name * @return bool */ - function drop_table($name) + function optimize_table($table_name) { - $sql = $this->_drop_table($name); + $sql = $this->_optimize_table($table_name); if (is_bool($sql)) { return $sql; } - return $this->db->query($sql); + $query = $this->db->query($sql); + return current($query->result_array()); } + // -------------------------------------------------------------------- - - function alter_table() + /** + * Optimize Table + * + * @access public + * @param string the table name + * @return bool + */ + + function repair_table($table_name) { - } + $sql = $this->_repair_table($table_name); + + if (is_bool($sql)) + { + return $sql; + } - function create_index() - { + $query = $this->db->query($sql); + return current($query->result_array()); } - - function drop_index() + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * @access public + * @param string the table name + * @return bool + */ + function drop_table($table_name) { - } + $sql = $this->_drop_table($table_name); + + if (is_bool($sql)) + { + return $sql; + } - function optimize() - { + return $this->db->query($sql); } + } ?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index a8a8e2006..53b7832d9 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -49,7 +49,28 @@ class CI_DB_mssql_result extends CI_DB_result { { return @mssql_num_fields($this->result_id); } - + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function field_names() + { + $field_names = array(); + while ($field = mssql_fetch_field($this->result_id)) + { + $field_names[] = $field->name; + } + + return $field_names; + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index b85a420e7..cf15104c6 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -138,6 +138,37 @@ class CI_DB_mssql_utility extends CI_DB_utility { } + // -------------------------------------------------------------------- + + /** + * Optimize table query + * + * Generates a platform-specific query so that a table can be optimized + * + * @access private + * @param string the table name + * @return object + */ + function _optimize_table($table) + { + return FALSE; // Is this supported in MS SQL? + } + + // -------------------------------------------------------------------- + + /** + * Repair table query + * + * Generates a platform-specific query so that a table can be repaired + * + * @access private + * @param string the table name + * @return object + */ + function _repair_table($table) + { + return return FALSE; // Is this supported in MS SQL? + } } diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index e540489bb..91c4af12c 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -52,6 +52,27 @@ class CI_DB_mysql_result extends CI_DB_result { // -------------------------------------------------------------------- + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function field_names() + { + $field_names = array(); + while ($field = mysql_fetch_field($this->result_id)) + { + $field_names[] = $field->name; + } + + return $field_names; + } + + // -------------------------------------------------------------------- + /** * Field data * diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index a0c746207..800a90c7a 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -136,6 +136,39 @@ class CI_DB_mysql_utility extends CI_DB_utility { return "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; } + // -------------------------------------------------------------------- + + /** + * Optimize table query + * + * Generates a platform-specific query so that a table can be optimized + * + * @access private + * @param string the table name + * @return object + */ + function _optimize_table($table) + { + return "OPTIMIZE TABLE ".$this->db->_escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * Repair table query + * + * Generates a platform-specific query so that a table can be repaired + * + * @access private + * @param string the table name + * @return object + */ + function _repair_table($table) + { + return "REPAIR TABLE ".$this->db->_escape_table($table); + } + + } diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index b0db6c106..2eca68ff5 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -49,7 +49,28 @@ class CI_DB_mysqli_result extends CI_DB_result { { return @mysqli_num_fields($this->result_id); } - + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function field_names() + { + $field_names = array(); + while ($field = mysql_fetch_field($this->result_id)) + { + $field_names[] = $field->name; + } + + return $field_names; + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 328661866..8c9e1e960 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -136,6 +136,37 @@ class CI_DB_mysqli_utility extends CI_DB_utility { return "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; } + // -------------------------------------------------------------------- + + /** + * Optimize table query + * + * Generates a platform-specific query so that a table can be optimized + * + * @access private + * @param string the table name + * @return object + */ + function _optimize_table($table) + { + return "OPTIMIZE TABLE ".$this->db->_escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * Repair table query + * + * Generates a platform-specific query so that a table can be repaired + * + * @access private + * @param string the table name + * @return object + */ + function _repair_table($table) + { + return "REPAIR TABLE ".$this->db->_escape_table($table); + } } diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index d2354a1c6..59adda76b 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -74,6 +74,27 @@ class CI_DB_oci8_result extends CI_DB_result { return $count; } + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function field_names() + { + $field_names = array(); + $fieldCount = $this->num_fields(); + for ($c = 1; $c <= $fieldCount; $c++) + { + $field_names[] = ocicolumnname($this->stmt_id, $c); + } + return $field_names; + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 9c3059f41..011e971d9 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -138,6 +138,38 @@ class CI_DB_oci8_utility extends CI_DB_utility { } + // -------------------------------------------------------------------- + + /** + * Optimize table query + * + * Generates a platform-specific query so that a table can be optimized + * + * @access private + * @param string the table name + * @return object + */ + function _optimize_table($table) + { + return FALSE; // Is this supported in Oracle? + } + + // -------------------------------------------------------------------- + + /** + * Repair table query + * + * Generates a platform-specific query so that a table can be repaired + * + * @access private + * @param string the table name + * @return object + */ + function _repair_table($table) + { + return return FALSE; // Is this supported in Oracle? + } + } ?> \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index 49e5e9012..385209c56 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -49,7 +49,28 @@ class CI_DB_odbc_result extends CI_DB_result { { return @odbc_num_fields($this->result_id); } - + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function field_names() + { + $field_names = array(); + for ($i = 0; $i < $this->num_fields(); $i++) + { + $field_names[] = odbc_field_name($this->result_id, $i); + } + + return $field_names; + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index 5b4558f68..2932da874 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -159,6 +159,47 @@ class CI_DB_odbc_utility extends CI_DB_utility { return "SELECT TOP 1 FROM ".$this->db->_escape_table($table); } + // -------------------------------------------------------------------- + + /** + * Optimize table query + * + * Generates a platform-specific query so that a table can be optimized + * + * @access private + * @param string the table name + * @return object + */ + function _optimize_table($table) + { + // Not a supported ODBC feature + if ($this->db_debug) + { + return $this->display_error('db_unsuported_feature'); + } + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Repair table query + * + * Generates a platform-specific query so that a table can be repaired + * + * @access private + * @param string the table name + * @return object + */ + function _repair_table($table) + { + // Not a supported ODBC feature + if ($this->db_debug) + { + return $this->display_error('db_unsuported_feature'); + } + return FALSE; + } } diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index 6af7f94f2..ee838b450 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -49,7 +49,28 @@ class CI_DB_postgre_result extends CI_DB_result { { return @pg_num_fields($this->result_id); } - + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function field_names() + { + $field_names = array(); + for ($i = 0; $i < $this->num_fields(); $i++) + { + $Ffield_names[] = pg_field_name($this->result_id, $i); + } + + return $field_names; + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index b31609aea..b2fdd5fd4 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -137,6 +137,38 @@ class CI_DB_postgre_utility extends CI_DB_utility { return "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; } + // -------------------------------------------------------------------- + + /** + * Optimize table query + * + * Generates a platform-specific query so that a table can be optimized + * + * @access private + * @param string the table name + * @return object + */ + function _optimize_table($table) + { + return FALSE; // Is this supported in Postgre? + } + + // -------------------------------------------------------------------- + + /** + * Repair table query + * + * Generates a platform-specific query so that a table can be repaired + * + * @access private + * @param string the table name + * @return object + */ + function _repair_table($table) + { + return return FALSE; // Is this supported in Postgre? + } + } diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index f30a8cfdf..7f48ce8aa 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -49,7 +49,28 @@ class CI_DB_sqlite_result extends CI_DB_result { { return @sqlite_num_fields($this->result_id); } - + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function field_names() + { + $field_names = array(); + for ($i = 0; $i < $this->num_fields(); $i++) + { + $Ffield_names[] = sqlite_field_name($this->result_id, $i); + } + + return $field_names; + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 754a755e4..e9f4eb64e 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -155,6 +155,37 @@ class CI_DB_sqlite_utility extends CI_DB_utility { return "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; } + // -------------------------------------------------------------------- + + /** + * Optimize table query + * + * Generates a platform-specific query so that a table can be optimized + * + * @access private + * @param string the table name + * @return object + */ + function _optimize_table($table) + { + return FALSE; // Is this supported SQLite? + } + + // -------------------------------------------------------------------- + + /** + * Repair table query + * + * Generates a platform-specific query so that a table can be repaired + * + * @access private + * @param string the table name + * @return object + */ + function _repair_table($table) + { + return return FALSE; // Is this supported in SQLite? + } } -- cgit v1.2.3-24-g4f1b From 9cd4e8e639a1a09fd6ca426f1af94586f30d4a80 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 25 Sep 2006 23:26:25 +0000 Subject: --- system/database/DB_driver.php | 140 ++++++++++++++ system/database/DB_utility.php | 214 +++++---------------- system/database/drivers/mssql/mssql_driver.php | 45 +++++ system/database/drivers/mssql/mssql_utility.php | 62 +----- system/database/drivers/mysql/mysql_driver.php | 47 ++++- system/database/drivers/mysql/mysql_utility.php | 59 +----- system/database/drivers/mysqli/mysqli_driver.php | 47 ++++- system/database/drivers/mysqli/mysqli_utility.php | 59 +----- system/database/drivers/oci8/oci8_driver.php | 51 ++++- system/database/drivers/oci8/oci8_utility.php | 72 ++----- system/database/drivers/odbc/odbc_driver.php | 47 ++++- system/database/drivers/odbc/odbc_utility.php | 69 ++----- system/database/drivers/postgre/postgre_driver.php | 47 ++++- .../database/drivers/postgre/postgre_utility.php | 59 +----- system/database/drivers/sqlite/sqlite_driver.php | 46 +++++ system/database/drivers/sqlite/sqlite_utility.php | 68 ++----- 16 files changed, 572 insertions(+), 560 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 3f7c82627..d25135ea6 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -142,6 +142,49 @@ class CI_DB_driver { } + // -------------------------------------------------------------------- + + /** + * The name of the platform in use (mysql, mssql, etc...) + * + * @access public + * @return string + */ + function platform() + { + return $this->dbdriver; + } + + // -------------------------------------------------------------------- + + /** + * Database Version Number. Returns a string containing the + * version of the database being used + * + * @access public + * @return string + */ + function version() + { + if (FALSE === ($sql = $this->_version())) + { + if ($this->db_debug) + { + return $this->display_error('db_unsupported_function'); + } + return FALSE; + } + + if ($this->dbdriver == 'oci8') + { + return $sql; + } + + $query = $this->query($sql); + $row = $query->row(); + return $row->ver; + } + // -------------------------------------------------------------------- /** @@ -483,6 +526,103 @@ class CI_DB_driver { return $str; } + + + // -------------------------------------------------------------------- + + /** + * Primary + * + * Retrieves the primary key. It assumes that the row in the first + * position is the primary key + * + * @access public + * @param string the table name + * @return string + */ + function primary($table = '') + { + $fields = $this->field_names($table); + + if ( ! is_array($fields)) + { + return FALSE; + } + + return current($fields); + } + + // -------------------------------------------------------------------- + + /** + * Fetch MySQL Field Names + * + * @access public + * @param string the table name + * @return array + */ + function field_names($table = '') + { + if ($table == '') + { + if ($this->db_debug) + { + return $this->display_error('db_field_param_missing'); + } + return FALSE; + } + + if (FALSE === ($sql = $this->_list_columns($this->dbprefix.$table))) + { + if ($this->db_debug) + { + return $this->display_error('db_unsupported_function'); + } + return FALSE; + } + + $query = $this->query($sql); + + $retval = array(); + foreach($query->result_array() as $row) + { + if (isset($row['COLUMN_NAME'])) + { + $retval[] = $row['COLUMN_NAME']; + } + else + { + $retval[] = current($row); + } + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @access public + * @param string the table name + * @return object + */ + function field_data($table = '') + { + if ($table == '') + { + if ($this->db_debug) + { + return $this->display_error('db_field_param_missing'); + } + return FALSE; + } + + $query = $this->query($this->_field_data($this->dbprefix.$table)); + return $query->field_data(); + } + // -------------------------------------------------------------------- /** diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 950db7dfd..f98448adf 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -33,57 +33,69 @@ class CI_DB_utility { $this->db =& $obj->db; } + // -------------------------------------------------------------------- /** - * Database Version Number. Returns a string containing the - * version of the database being used + * Create database * * @access public - * @return string - */ - function version() + * @param string the database name + * @return bool + */ + function create_database($db_name) { - if (FALSE === ($sql = $this->_version())) + $sql = $this->_create_database($db_name); + + if (is_bool($sql)) { - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsupported_function'); - } - return FALSE; + return $sql; } + + return $this->db->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access public + * @param string the database name + * @return bool + */ + function drop_database($db_name) + { + $sql = $this->_drop_database($db_name); - if ($this->db->dbdriver == 'oci8') - { + if (is_bool($sql)) + { return $sql; } - $query = $this->db->query($sql); - $row = $query->row(); - return $row->ver; + return $this->db->query($sql); } // -------------------------------------------------------------------- /** - * Primary + * List databases * - * Retrieves the primary key. It assumes that the row in the first - * position is the primary key - * * @access public - * @param string the table name - * @return string - */ - function primary($table = '') + * @return bool + */ + function list_databases() { - $fields = $this->field_names($table); - - if ( ! is_array($fields)) + $query = $this->db->query($this->_list_database()); + $dbs = array(); + if ($query->num_rows() > 0) { - return FALSE; + foreach ($query->result_array() as $row) + { + $dbs[] = current($row); + } } - - return current($fields); + + return $dbs; } // -------------------------------------------------------------------- @@ -94,9 +106,9 @@ class CI_DB_utility { * @access public * @return array */ - function tables() + function list_tables() { - if (FALSE === ($sql = $this->_show_tables())) + if (FALSE === ($sql = $this->_list_tables())) { if ($this->db->db_debug) { @@ -135,143 +147,7 @@ class CI_DB_utility { */ function table_exists($table_name) { - return ( ! in_array($this->db->dbprefix.$table_name, $this->tables())) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Fetch MySQL Field Names - * - * @access public - * @param string the table name - * @return array - */ - function field_names($table = '') - { - if ($table == '') - { - if ($this->db->db_debug) - { - return $this->db->display_error('db_field_param_missing'); - } - return FALSE; - } - - if (FALSE === ($sql = $this->_show_columns($this->db->dbprefix.$table))) - { - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsupported_function'); - } - return FALSE; - } - - $query = $this->db->query($sql); - - $retval = array(); - foreach($query->result_array() as $row) - { - if (isset($row['COLUMN_NAME'])) - { - $retval[] = $row['COLUMN_NAME']; - } - else - { - $retval[] = current($row); - } - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Returns an object with field data - * - * @access public - * @param string the table name - * @return object - */ - function field_data($table = '') - { - if ($table == '') - { - if ($this->db->db_debug) - { - return $this->db->display_error('db_field_param_missing'); - } - return FALSE; - } - - $query = $this->db->query($this->_field_data($this->db->dbprefix.$table)); - return $query->field_data(); - } - - // -------------------------------------------------------------------- - - /** - * Create database - * - * @access public - * @param string the database name - * @return bool - */ - function create_database($db_name) - { - $sql = $this->_create_database($db_name); - - if (is_bool($sql)) - { - return $sql; - } - - return $this->db->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access public - * @param string the database name - * @return bool - */ - function drop_database($db_name) - { - $sql = $this->_drop_database($db_name); - - if (is_bool($sql)) - { - return $sql; - } - - return $this->db->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * List databases - * - * @access public - * @return bool - */ - function list_databases() - { - $query = $this->db->query($this->_list_database()); - $dbs = array(); - if ($query->num_rows() > 0) - { - foreach ($query->result_array() as $row) - { - $dbs[] = current($row); - } - } - - return $dbs; + return ( ! in_array($this->db->dbprefix.$table_name, $this->list_tables())) ? FALSE : TRUE; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 38fce1134..3f5e53345 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -66,6 +66,19 @@ class CI_DB_mssql_driver extends CI_DB { { return @mssql_select_db($this->database, $this->conn_id); } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } // -------------------------------------------------------------------- @@ -248,6 +261,38 @@ class CI_DB_mssql_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * List columnn query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access private + * @param string the table name + * @return string + */ + function _list_columns($table = '') + { + return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$this->_escape_table($table)."'"; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + return "SELECT TOP 1 FROM ".$this->_escape_table($table); + } + + // -------------------------------------------------------------------- + /** * The error message string * diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index cf15104c6..96b8180b8 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -67,76 +67,30 @@ class CI_DB_mssql_utility extends CI_DB_utility { // -------------------------------------------------------------------- /** - * Drop Table - * - * @access private - * @return bool - */ - function _drop_table($table) - { - return "DROP TABLE ".$this->db->_escape_table($name); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Show table query + * List table query * * Generates a platform-specific query string so that the table names can be fetched * - * @access public + * @access private * @return string */ - function _show_tables() + function _list_tables() { return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; } - - // -------------------------------------------------------------------- - - /** - * Show columnn query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _show_columns($table = '') - { - return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$this->db->_escape_table($table)."'"; - } // -------------------------------------------------------------------- /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved + * Drop Table * - * @access public - * @param string the table name - * @return object + * @access private + * @return bool */ - function _field_data($table) + function _drop_table($table) { - return "SELECT TOP 1 FROM ".$this->db->_escape_table($table); + return "DROP TABLE ".$this->db->_escape_table($name); } - // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 545ac1986..b6c4eb7ea 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -73,7 +73,20 @@ class CI_DB_mysql_driver extends CI_DB { { return @mysql_select_db($this->database, $this->conn_id); } - + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + // -------------------------------------------------------------------- /** @@ -266,6 +279,38 @@ class CI_DB_mysql_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Show columnn query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _list_columns($table = '') + { + return "SHOW COLUMNS FROM ".$this->_escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + return "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; + } + + // -------------------------------------------------------------------- + /** * The error message string * diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 800a90c7a..9ba4a79c5 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -65,75 +65,30 @@ class CI_DB_mysql_utility extends CI_DB_utility { // -------------------------------------------------------------------- - /** - * Drop Table - * - * @access private - * @return bool - */ - function _drop_table($table) - { - return "DROP TABLE IF EXISTS ".$this->db->_escape_table($name); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - /** * Show table query * * Generates a platform-specific query string so that the table names can be fetched * - * @access public + * @access private * @return string */ - function _show_tables() + function _list_tables() { return "SHOW TABLES FROM `".$this->db->database."`"; } - - // -------------------------------------------------------------------- - - /** - * Show columnn query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _show_columns($table = '') - { - return "SHOW COLUMNS FROM ".$this->db->_escape_table($table); - } // -------------------------------------------------------------------- /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved + * Drop Table * - * @access public - * @param string the table name - * @return object + * @access private + * @return bool */ - function _field_data($table) + function _drop_table($table) { - return "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; + return "DROP TABLE IF EXISTS ".$this->db->_escape_table($name); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index adc482dfe..d6e967498 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -75,7 +75,20 @@ class CI_DB_mysqli_driver extends CI_DB { { return @mysqli_select_db($this->conn_id, $this->database); } - + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + // -------------------------------------------------------------------- /** @@ -269,6 +282,38 @@ class CI_DB_mysqli_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Show columnn query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _list_columns($table = '') + { + return "SHOW COLUMNS FROM ".$this->_escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + return "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; + } + + // -------------------------------------------------------------------- + /** * The error message string * diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 8c9e1e960..754ffbda2 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -62,33 +62,7 @@ class CI_DB_mysqli_utility extends CI_DB_utility { { return "SHOW DATABASES"; } - - // -------------------------------------------------------------------- - /** - * Drop Table - * - * @access private - * @return bool - */ - function _drop_table($table) - { - return "DROP TABLE IF EXISTS ".$this->db->_escape_table($name); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - // -------------------------------------------------------------------- /** @@ -96,44 +70,25 @@ class CI_DB_mysqli_utility extends CI_DB_utility { * * Generates a platform-specific query string so that the table names can be fetched * - * @access public + * @access private * @return string */ - function _show_tables() + function _list_tables() { return "SHOW TABLES FROM `".$this->db->database."`"; } - - // -------------------------------------------------------------------- - - /** - * Show columnn query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _show_columns($table = '') - { - return "SHOW COLUMNS FROM ".$this->db->_escape_table($table); - } // -------------------------------------------------------------------- /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved + * Drop Table * - * @access public - * @param string the table name - * @return object + * @access private + * @return bool */ - function _field_data($table) + function _drop_table($table) { - return "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; + return "DROP TABLE IF EXISTS ".$this->db->_escape_table($name); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index f7f4bd143..bc0a100c2 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -91,6 +91,19 @@ class CI_DB_oci8_driver extends CI_DB { return TRUE; } + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return ociserverversion($this->conn_id); + } + // -------------------------------------------------------------------- /** @@ -102,10 +115,8 @@ class CI_DB_oci8_driver extends CI_DB { */ function _execute($sql) { - // oracle must parse the query before it - // is run, all of the actions with - // the query are based off the statement id - // returned by ociparse + // oracle must parse the query before it is run. All of the actions with + // the query are based on the statement id returned by ociparse $this->_set_stmt_id($sql); ocisetprefetch($this->stmt_id, 1000); return @ociexecute($this->stmt_id, $this->_commit); @@ -390,6 +401,38 @@ class CI_DB_oci8_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Show columnn query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _list_columns($table = '') + { + return "SELECT COLUMN_NAME FROM all_tab_columns WHERE table_name = '$table'"; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + return "SELECT * FROM ".$this->_escape_table($table)." where rownum = 1"; + } + + // -------------------------------------------------------------------- + /** * The error message string * diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 011e971d9..dc259ac39 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -64,32 +64,6 @@ class CI_DB_oci8_utility extends CI_DB_utility { return FALSE; } - // -------------------------------------------------------------------- - - /** - * Drop Table - * - * @access private - * @return bool - */ - function _drop_table($table) - { - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return ociserverversion($this->conn_id); - } - // -------------------------------------------------------------------- /** @@ -97,46 +71,26 @@ class CI_DB_oci8_utility extends CI_DB_utility { * * Generates a platform-specific query string so that the table names can be fetched * - * @access public + * @access private * @return string */ - function _show_tables() + function _list_tables() { return "select TABLE_NAME FROM ALL_TABLES"; } - // -------------------------------------------------------------------- - - /** - * Show columnn query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _show_columns($table = '') - { - return "SELECT COLUMN_NAME FROM all_tab_columns WHERE table_name = '$table'"; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - return "SELECT * FROM ".$this->db->_escape_table($table)." where rownum = 1"; - } + // -------------------------------------------------------------------- + /** + * Drop Table + * + * @access private + * @return bool + */ + function _drop_table($table) + { + return FALSE; + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index bef6258de..cdde2e2ea 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -67,7 +67,20 @@ class CI_DB_odbc_driver extends CI_DB { // Not needed for ODBC return TRUE; } - + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + // -------------------------------------------------------------------- /** @@ -249,6 +262,38 @@ class CI_DB_odbc_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Show columnn query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _list_columns($table = '') + { + return "SHOW COLUMNS FROM ".$this->_escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + return "SELECT TOP 1 FROM ".$this->_escape_table($table); + } + + // -------------------------------------------------------------------- + /** * The error message string * diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index 2932da874..3d420f69d 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -83,80 +83,35 @@ class CI_DB_odbc_utility extends CI_DB_utility { // -------------------------------------------------------------------- - /** - * Drop Table - * - * @access private - * @return bool - */ - function _drop_table($table) - { - // Not a supported ODBC feature - if ($this->db_debug) - { - return $this->display_error('db_unsuported_feature'); - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - /** * Show table query * * Generates a platform-specific query string so that the table names can be fetched * - * @access public + * @access private * @return string */ - function _show_tables() + function _list_tables() { return "SHOW TABLES FROM `".$this->db->database."`"; } - - // -------------------------------------------------------------------- - - /** - * Show columnn query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _show_columns($table = '') - { - return "SHOW COLUMNS FROM ".$this->db->_escape_table($table); - } // -------------------------------------------------------------------- /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved + * Drop Table * - * @access public - * @param string the table name - * @return object + * @access private + * @return bool */ - function _field_data($table) + function _drop_table($table) { - return "SELECT TOP 1 FROM ".$this->db->_escape_table($table); + // Not a supported ODBC feature + if ($this->db_debug) + { + return $this->display_error('db_unsuported_feature'); + } + return FALSE; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 9c8a18eb5..026284118 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -71,7 +71,20 @@ class CI_DB_postgre_driver extends CI_DB { // Not needed for Postgre so we'll return TRUE return TRUE; } - + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + // -------------------------------------------------------------------- /** @@ -276,6 +289,38 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Show columnn query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _list_columns($table = '') + { + return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->_escape_table($table)."'"; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + return "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; + } + + // -------------------------------------------------------------------- + /** * The error message string * diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index b2fdd5fd4..0ee448f9e 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -63,32 +63,6 @@ class CI_DB_postgre_utility extends CI_DB_utility { { return "SELECT datname FROM pg_database"; } - - // -------------------------------------------------------------------- - - /** - * Drop Table - * - * @access private - * @return bool - */ - function _drop_table($table) - { - return "DROP TABLE ".$this->db->_escape_table($name)." CASCADE"; - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } // -------------------------------------------------------------------- @@ -97,44 +71,25 @@ class CI_DB_postgre_utility extends CI_DB_utility { * * Generates a platform-specific query string so that the table names can be fetched * - * @access public + * @access private * @return string */ - function _show_tables() + function _list_tables() { return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; } - - // -------------------------------------------------------------------- - - /** - * Show columnn query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _show_columns($table = '') - { - return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->db->_escape_table($table)."'"; - } // -------------------------------------------------------------------- /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved + * Drop Table * - * @access public - * @param string the table name - * @return object + * @access private + * @return bool */ - function _field_data($table) + function _drop_table($table) { - return "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; + return "DROP TABLE ".$this->db->_escape_table($name)." CASCADE"; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 603984575..45dd7a892 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -88,6 +88,19 @@ class CI_DB_sqlite_driver extends CI_DB { { return TRUE; } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return sqlite_libversion(); + } // -------------------------------------------------------------------- @@ -268,6 +281,39 @@ class CI_DB_sqlite_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Show columnn query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _list_columns($table = '') + { + // Not supported + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + return "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; + } + + // -------------------------------------------------------------------- + /** * The error message string * diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index e9f4eb64e..43c43e03c 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -79,80 +79,34 @@ class CI_DB_sqlite_utility extends CI_DB_utility { // -------------------------------------------------------------------- - /** - * Drop Table - * - * @access private - * @return bool - */ - function _drop_table($table) - { - if ($this->db_debug) - { - return $this->display_error('db_unsuported_feature'); - } - return array(); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return sqlite_libversion(); - } - - // -------------------------------------------------------------------- - /** * Show table query * * Generates a platform-specific query string so that the table names can be fetched * - * @access public + * @access private * @return string */ - function _show_tables() + function _list_tables() { return "SELECT name from sqlite_master WHERE type='table'"; } - - // -------------------------------------------------------------------- - - /** - * Show columnn query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _show_columns($table = '') - { - // Not supported - return FALSE; - } // -------------------------------------------------------------------- /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved + * Drop Table * - * @access public - * @param string the table name - * @return object + * @access private + * @return bool */ - function _field_data($table) + function _drop_table($table) { - return "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; + if ($this->db_debug) + { + return $this->display_error('db_unsuported_feature'); + } + return array(); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 910d8620519d777ab45bdad5fb6dc9f05c6b2869 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 26 Sep 2006 02:09:05 +0000 Subject: --- system/database/DB_export.php | 38 +++++++++++++++++++++++++++++++++++--- system/database/DB_utility.php | 2 ++ 2 files changed, 37 insertions(+), 3 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_export.php b/system/database/DB_export.php index 195510d9d..1e94c6c97 100644 --- a/system/database/DB_export.php +++ b/system/database/DB_export.php @@ -23,19 +23,51 @@ * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_export { - + + + function CI_DB_export() + { + log_message('debug', "Database Export Class Initialized"); + } + /** - * Some function + * Generate CVS * * @access public * @return integer */ - function something() + function generate_cvs($query, $delim = "\t", $newline = "\n") { + if ( ! is_object($query) OR ! method_exists($query, 'field_names')) + { + show_error('You must submit a valid result object'); + } + + $out = ''; + foreach ($query->field_names() as $name) + { + $out .= $name.$delim; + } + + $out .= $newline; + + foreach ($query->result_array() as $row) + { + foreach ($row as $item) + { + $out .= $item.$delim; + } + + $out .= $newline; + } + + + return $out; } // -------------------------------------------------------------------- + } ?> \ No newline at end of file diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index f98448adf..41941ae35 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -31,6 +31,8 @@ class CI_DB_utility { // Assign the main database object to $this->db $obj =& get_instance(); $this->db =& $obj->db; + + log_message('debug', "Database Utility Class Initialized"); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From e79dc7130a0003a07833609487b8ebb5ebcf31c8 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 26 Sep 2006 03:52:45 +0000 Subject: --- system/database/DB_export.php | 7 +++++++ system/database/DB_utility.php | 5 +++++ 2 files changed, 12 insertions(+) (limited to 'system/database') diff --git a/system/database/DB_export.php b/system/database/DB_export.php index 1e94c6c97..8194cb9b1 100644 --- a/system/database/DB_export.php +++ b/system/database/DB_export.php @@ -13,6 +13,13 @@ * @filesource */ + + +// INITIALIZE THE CLASS --------------------------------------------------- + +$obj =& get_instance(); +$obj->dbexport =& new CI_DB_export(); + // ------------------------------------------------------------------------ /** diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 41941ae35..e4ae0c5df 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -13,6 +13,11 @@ * @filesource */ +// INITIALIZE THE CLASS --------------------------------------------------- + +$obj =& get_instance(); +$obj->dbutility =& new CI_DB_utility(); + // ------------------------------------------------------------------------ /** -- cgit v1.2.3-24-g4f1b From 7981a9a752c339611ae10a252469f9dbc266fb96 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 26 Sep 2006 07:52:09 +0000 Subject: --- system/database/DB_export.php | 2 +- system/database/DB_utility.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_export.php b/system/database/DB_export.php index 8194cb9b1..14e7af68b 100644 --- a/system/database/DB_export.php +++ b/system/database/DB_export.php @@ -18,7 +18,7 @@ // INITIALIZE THE CLASS --------------------------------------------------- $obj =& get_instance(); -$obj->dbexport =& new CI_DB_export(); +$obj->init_class('CI_DB_export', 'dbexport'); // ------------------------------------------------------------------------ diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index e4ae0c5df..3b4b09d6e 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -16,7 +16,7 @@ // INITIALIZE THE CLASS --------------------------------------------------- $obj =& get_instance(); -$obj->dbutility =& new CI_DB_utility(); +$obj->init_class('CI_DB_utility', 'dbutility'); // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From b63ac845de0c7c57c7db755de9af36ce34b67426 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 26 Sep 2006 18:14:43 +0000 Subject: --- system/database/DB_export.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_export.php b/system/database/DB_export.php index 14e7af68b..02b4b42ad 100644 --- a/system/database/DB_export.php +++ b/system/database/DB_export.php @@ -12,7 +12,6 @@ * @since Version 1.0 * @filesource */ - // INITIALIZE THE CLASS --------------------------------------------------- @@ -38,10 +37,13 @@ class CI_DB_export { } /** - * Generate CVS + * Generate CVS from a query result object * * @access public - * @return integer + * @param object The query result object + * @param string The delimiter - tab by default + * @param string The newline character - \n by default + * @return string */ function generate_cvs($query, $delim = "\t", $newline = "\n") { @@ -51,13 +53,15 @@ class CI_DB_export { } $out = ''; + + // First generate the headings from the table column names foreach ($query->field_names() as $name) { $out .= $name.$delim; } - $out .= $newline; + // Next blast through the result array and build out the rows foreach ($query->result_array() as $row) { foreach ($row as $item) @@ -67,7 +71,6 @@ class CI_DB_export { $out .= $newline; } - return $out; } -- cgit v1.2.3-24-g4f1b From f0839f3bb0fc8b13a1d9b64ed4a7ff86147be9ae Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 26 Sep 2006 18:16:01 +0000 Subject: --- system/database/DB_export.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'system/database') diff --git a/system/database/DB_export.php b/system/database/DB_export.php index 02b4b42ad..a217ad138 100644 --- a/system/database/DB_export.php +++ b/system/database/DB_export.php @@ -31,6 +31,9 @@ $obj->init_class('CI_DB_export', 'dbexport'); class CI_DB_export { + /** + * Constructor. Simply calls the log function + */ function CI_DB_export() { log_message('debug', "Database Export Class Initialized"); -- cgit v1.2.3-24-g4f1b From 41a1685573aa0ede15a9bf7b373c36a0406fb19d Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 26 Sep 2006 18:17:19 +0000 Subject: --- system/database/DB_utility.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'system/database') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 3b4b09d6e..00e20c6c6 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -31,6 +31,12 @@ class CI_DB_utility { var $db; + /** + * Constructor + * + * Grabs the CI super object instance so we can access it. + * + */ function CI_DB_utility() { // Assign the main database object to $this->db -- cgit v1.2.3-24-g4f1b From 31075cf97ac386686e679eb7b8aaf852fd12d838 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 26 Sep 2006 18:50:02 +0000 Subject: --- system/database/DB_utility.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'system/database') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 00e20c6c6..281a3b87d 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -187,6 +187,39 @@ class CI_DB_utility { // -------------------------------------------------------------------- + /** + * Optimize Database + * + * @access public + * @param string the table name + * @return bool + */ + function optimize_database() + { + $result = array(); + foreach ($this->list_tables() as $table_name) + { + $sql = $this->_optimize_table($table_name); + + if (is_bool($sql)) + { + return $sql; + } + + $query = $this->db->query($sql); + $res = current($query->result_array()); + $key = str_replace($this->db->database.'.', '', current($res)); + $keys = array_keys($res); + unset($res[$keys[0]]); + + $result[$key] = $res; + } + + return $result; + } + + // -------------------------------------------------------------------- + /** * Optimize Table * -- cgit v1.2.3-24-g4f1b From eb13db750ac04921774b8bc7d8b26f343195061a Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 27 Sep 2006 00:30:48 +0000 Subject: --- system/database/DB_export.php | 80 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_export.php b/system/database/DB_export.php index a217ad138..8d6446cb6 100644 --- a/system/database/DB_export.php +++ b/system/database/DB_export.php @@ -39,6 +39,8 @@ class CI_DB_export { log_message('debug', "Database Export Class Initialized"); } + // -------------------------------------------------------------------- + /** * Generate CVS from a query result object * @@ -48,7 +50,7 @@ class CI_DB_export { * @param string The newline character - \n by default * @return string */ - function generate_cvs($query, $delim = "\t", $newline = "\n") + function cvs_from_result($query, $delim = "\t", $newline = "\n") { if ( ! is_object($query) OR ! method_exists($query, 'field_names')) { @@ -62,6 +64,8 @@ class CI_DB_export { { $out .= $name.$delim; } + + $out = rtrim($out); $out .= $newline; // Next blast through the result array and build out the rows @@ -71,7 +75,7 @@ class CI_DB_export { { $out .= $item.$delim; } - + $out = rtrim($out); $out .= $newline; } @@ -81,6 +85,78 @@ class CI_DB_export { // -------------------------------------------------------------------- + /** + * Generate XML data from a query result object + * + * @access public + * @param object The query result object + * @param array Any preferences + * @return string + */ + function xml_from_result($query, $params = array()) + { + if ( ! is_object($query) OR ! method_exists($query, 'field_names')) + { + show_error('You must submit a valid result object'); + } + + // Set our default values + foreach (array('root' => 'root', 'element' => 'element', 'newline' => "\n", 'tab' => "\t") as $key => $val) + { + if ( ! isset($params[$key])) + { + $params[$key] = $val; + } + } + + // Create variables for convenience + extract($params); + + // Generate the result + + $xml = "<{$root}/>".$newline; + foreach ($query->result_array() as $row) + { + $xml .= $tab."<{$element}/>".$newline; + + foreach ($row as $key => $val) + { + $xml .= $tab.$tab."<{$key}>".$this->_xml_convert($val)."".$newline; + } + $xml .= $tab."".$newline; + } + $xml .= "".$newline; + + return $xml; + } + + + // ------------------------------------------------------------------------ + + /** + * Convert Reserved XML characters to Entities + * + * @access public + * @param string + * @return string + */ + function _xml_convert($str) + { + $temp = '__TEMP_AMPERSANDS'; + + $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str); + $str = preg_replace("/&(\w+);/", "$temp\\1;", $str); + + $str = str_replace(array("&","<",">","\"", "'", "-"), + array("&", "<", ">", """, "'", "-"), + $str); + + $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); + $str = preg_replace("/$temp(\w+);/","&\\1;", $str); + + return $str; + } + } ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From e5bb936f808bfd39a6ba8cbe1fc2ddbcf9bf502f Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 27 Sep 2006 00:31:22 +0000 Subject: --- system/database/DB_utility.php | 5 +++-- system/database/drivers/mysql/mysql_utility.php | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 281a3b87d..a2469d059 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -191,8 +191,7 @@ class CI_DB_utility { * Optimize Database * * @access public - * @param string the table name - * @return bool + * @return array */ function optimize_database() { @@ -207,6 +206,8 @@ class CI_DB_utility { } $query = $this->db->query($sql); + + // Build the result array... $res = current($query->result_array()); $key = str_replace($this->db->database.'.', '', current($res)); $keys = array_keys($res); diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 9ba4a79c5..a81936c56 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -12,7 +12,7 @@ * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** -- cgit v1.2.3-24-g4f1b From 913ffb7af39d07eefb887e1c8faaf25e0ae79097 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 27 Sep 2006 00:36:28 +0000 Subject: --- system/database/DB_cache.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 system/database/DB_cache.php (limited to 'system/database') diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php new file mode 100644 index 000000000..ca3bba2eb --- /dev/null +++ b/system/database/DB_cache.php @@ -0,0 +1,44 @@ + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 5abd04902b11472cd8243280f0c08687325c5e90 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 27 Sep 2006 01:54:01 +0000 Subject: --- system/database/DB_export.php | 34 +++++----------------------------- 1 file changed, 5 insertions(+), 29 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_export.php b/system/database/DB_export.php index 8d6446cb6..a2e3e3e4c 100644 --- a/system/database/DB_export.php +++ b/system/database/DB_export.php @@ -112,8 +112,11 @@ class CI_DB_export { // Create variables for convenience extract($params); + // Load the xml helper + $obj =& get_instance(); + $obj->load->helper('xml'); + // Generate the result - $xml = "<{$root}/>".$newline; foreach ($query->result_array() as $row) { @@ -121,7 +124,7 @@ class CI_DB_export { foreach ($row as $key => $val) { - $xml .= $tab.$tab."<{$key}>".$this->_xml_convert($val)."".$newline; + $xml .= $tab.$tab."<{$key}>".xml_convert($val)."".$newline; } $xml .= $tab."".$newline; } @@ -130,33 +133,6 @@ class CI_DB_export { return $xml; } - - // ------------------------------------------------------------------------ - - /** - * Convert Reserved XML characters to Entities - * - * @access public - * @param string - * @return string - */ - function _xml_convert($str) - { - $temp = '__TEMP_AMPERSANDS'; - - $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str); - $str = preg_replace("/&(\w+);/", "$temp\\1;", $str); - - $str = str_replace(array("&","<",">","\"", "'", "-"), - array("&", "<", ">", """, "'", "-"), - $str); - - $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); - $str = preg_replace("/$temp(\w+);/","&\\1;", $str); - - return $str; - } - } ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 402d1d511d79b4e6d760dc3c88b4fe80a53a8a56 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 27 Sep 2006 01:54:14 +0000 Subject: --- system/database/DB_active_rec.php | 2 +- system/database/DB_cache.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index c038185bc..eb9f14a92 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -135,7 +135,7 @@ class CI_DB_active_record extends CI_DB_driver { } } - $this->ar_join[] = $type.'JOIN '.$table.' ON '.$cond; + $this->ar_join[] = $type.'JOIN '.$this->dbprefix.$table.' ON '.$cond; return $this; } diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index ca3bba2eb..086958d3d 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -27,7 +27,7 @@ class CI_DB_cache { /** - * Generate CVS from a query result object + * Cache it! * * @access public * @return string -- cgit v1.2.3-24-g4f1b From 17a890df20b56c8d82812f365f27bc590be009f3 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 27 Sep 2006 20:42:42 +0000 Subject: --- system/database/drivers/mysql/mysql_driver.php | 14 +++++++++++++- system/database/drivers/mysqli/mysqli_driver.php | 14 +++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index b6c4eb7ea..d4f322d5f 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -222,7 +222,19 @@ class CI_DB_mysql_driver extends CI_DB { */ function escape_str($str) { - return mysql_real_escape_string($str); + if (get_magic_quotes_gpc()) + { + return $str; + } + + if (function_exists('mysql_escape_string')) + { + return mysql_real_escape_string($str); + } + else + { + return addslashes($str); + } } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index d6e967498..63df0fe6f 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -225,7 +225,19 @@ class CI_DB_mysqli_driver extends CI_DB { */ function escape_str($str) { - return mysqli_real_escape_string($this->conn_id, $str); + if (get_magic_quotes_gpc()) + { + return $str; + } + + if (function_exists('mysql_escape_string')) + { + return mysqli_real_escape_string($this->conn_id, $str); + } + else + { + return addslashes($str); + } } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 33de9a144aad28763405f8ae2d5c59df5e929b4f Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 28 Sep 2006 06:50:16 +0000 Subject: --- system/database/DB_export.php | 6 ------ system/database/DB_utility.php | 5 ----- system/database/drivers/mysql/mysql_driver.php | 8 ++++++-- system/database/drivers/mysqli/mysqli_driver.php | 9 +-------- 4 files changed, 7 insertions(+), 21 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_export.php b/system/database/DB_export.php index a2e3e3e4c..1704f0dfd 100644 --- a/system/database/DB_export.php +++ b/system/database/DB_export.php @@ -13,12 +13,6 @@ * @filesource */ - -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_DB_export', 'dbexport'); - // ------------------------------------------------------------------------ /** diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index a2469d059..764f10cb7 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -12,11 +12,6 @@ * @since Version 1.0 * @filesource */ - -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_DB_utility', 'dbutility'); // ------------------------------------------------------------------------ diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index d4f322d5f..792e023a8 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -227,9 +227,13 @@ class CI_DB_mysql_driver extends CI_DB { return $str; } - if (function_exists('mysql_escape_string')) + if (function_exists('mysql_real_escape_string')) { - return mysql_real_escape_string($str); + return mysql_real_escape_string($str, $this->conn_id); + } + elseif (function_exists('mysql_escape_string')) + { + return mysql_escape_string($str); } else { diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 63df0fe6f..b158cfefe 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -230,14 +230,7 @@ class CI_DB_mysqli_driver extends CI_DB { return $str; } - if (function_exists('mysql_escape_string')) - { - return mysqli_real_escape_string($this->conn_id, $str); - } - else - { - return addslashes($str); - } + return mysqli_real_escape_string($this->conn_id, $str); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From ee54c112bfb488f833fa032758b817e1bb2c1d7d Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 28 Sep 2006 17:13:38 +0000 Subject: --- system/database/DB_active_rec.php | 4 ++-- system/database/DB_driver.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index eb9f14a92..1fa4f9557 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -125,7 +125,7 @@ class CI_DB_active_record extends CI_DB_driver { { $type = strtoupper(trim($type)); - if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'))) + if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'), TRUE)) { $type = ''; } @@ -390,7 +390,7 @@ class CI_DB_active_record extends CI_DB_driver { { if (trim($direction) != '') { - $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC', 'RAND()'))) ? ' '.$direction : ' ASC'; + $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC', 'RAND()'), TRUE)) ? ' '.$direction : ' ASC'; } $this->ar_orderby[] = $orderby.$direction; diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index d25135ea6..94db84bbf 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -726,8 +726,8 @@ class CI_DB_driver { } else { - $args = (func_num_args() > 1) ? array_shift(func_get_args()) : null; - + $args = (func_num_args() > 1) ? array_splice(func_get_args(), 1) : null; + return call_user_func_array($function, $args); } } -- cgit v1.2.3-24-g4f1b From 4a2ed69c3af500ca51bddcc9b6c54bebb2bfeae8 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 29 Sep 2006 01:14:52 +0000 Subject: --- system/database/drivers/oci8/oci8_utility.php | 2 +- system/database/drivers/postgre/postgre_utility.php | 8 ++++---- system/database/drivers/sqlite/sqlite_utility.php | 19 ++++++++++++++----- 3 files changed, 19 insertions(+), 10 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index dc259ac39..4d267dc6a 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -76,7 +76,7 @@ class CI_DB_oci8_utility extends CI_DB_utility { */ function _list_tables() { - return "select TABLE_NAME FROM ALL_TABLES"; + return "SELECT TABLE_NAME FROM ALL_TABLES"; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 0ee448f9e..7b51c3fe7 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -97,7 +97,7 @@ class CI_DB_postgre_utility extends CI_DB_utility { /** * Optimize table query * - * Generates a platform-specific query so that a table can be optimized + * Is table optimization supported in Postgre? * * @access private * @param string the table name @@ -105,7 +105,7 @@ class CI_DB_postgre_utility extends CI_DB_utility { */ function _optimize_table($table) { - return FALSE; // Is this supported in Postgre? + return FALSE; } // -------------------------------------------------------------------- @@ -113,7 +113,7 @@ class CI_DB_postgre_utility extends CI_DB_utility { /** * Repair table query * - * Generates a platform-specific query so that a table can be repaired + * Are table repairs supported in Postgre? * * @access private * @param string the table name @@ -121,7 +121,7 @@ class CI_DB_postgre_utility extends CI_DB_utility { */ function _repair_table($table) { - return return FALSE; // Is this supported in Postgre? + return return FALSE; } diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 43c43e03c..ae241db87 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -34,7 +34,8 @@ class CI_DB_sqlite_utility extends CI_DB_utility { */ function _create_database() { - // In SQLite, a database is created when you connect to the database + // In SQLite, a database is created when you connect to the database. + // We'll return TRUE so that an error isn't generated return TRUE; } @@ -65,11 +66,17 @@ class CI_DB_sqlite_utility extends CI_DB_utility { /** * List databases * + * I don't believe you can do a database listing with SQLite + * since each database is its own file. I suppose we could + * try reading a directory looking for SQLite files, but + * that doesn't seem like a terribly good idea + * * @access private * @return bool */ function _list_databases() { + if ($this->db_debug) { return $this->display_error('db_unsuported_feature'); @@ -97,6 +104,8 @@ class CI_DB_sqlite_utility extends CI_DB_utility { /** * Drop Table * + * Unsupported feature in SQLite + * * @access private * @return bool */ @@ -114,7 +123,7 @@ class CI_DB_sqlite_utility extends CI_DB_utility { /** * Optimize table query * - * Generates a platform-specific query so that a table can be optimized + * Is optimization even supported in SQLite? * * @access private * @param string the table name @@ -122,7 +131,7 @@ class CI_DB_sqlite_utility extends CI_DB_utility { */ function _optimize_table($table) { - return FALSE; // Is this supported SQLite? + return FALSE; } // -------------------------------------------------------------------- @@ -130,7 +139,7 @@ class CI_DB_sqlite_utility extends CI_DB_utility { /** * Repair table query * - * Generates a platform-specific query so that a table can be repaired + * Are table repairs even supported in SQLite? * * @access private * @param string the table name @@ -138,7 +147,7 @@ class CI_DB_sqlite_utility extends CI_DB_utility { */ function _repair_table($table) { - return return FALSE; // Is this supported in SQLite? + return return FALSE; } -- cgit v1.2.3-24-g4f1b From 051402b4c281cf125c9b369b682128aaefb587cd Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 29 Sep 2006 23:11:40 +0000 Subject: --- system/database/drivers/mysql/mysql_utility.php | 170 ++++++++++++++++++++++++ 1 file changed, 170 insertions(+) (limited to 'system/database') diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index a81936c56..65fb87f92 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -123,7 +123,177 @@ class CI_DB_mysql_utility extends CI_DB_utility { return "REPAIR TABLE ".$this->db->_escape_table($table); } + // -------------------------------------------------------------------- + + /** + * MySQL Export + * + * @access public + * @param object The query result object + * @param array Any preferences + * @return string + */ + function export($params = array()) + { + // Set up our default preferences + $prefs = array( + 'tables' => array(), + 'ignore' => array(), + 'format' => 'gzip', + 'download' => TRUE, + 'filename' => date('Y-m-d-H:i', time()), + 'filepath' => '', + 'add_drop' => TRUE, + 'add_insert' => TRUE, + 'newline' => "\n" + ); + + // Did the user submit any preference overrides? If so set them.... + if (count($params) > 0) + { + foreach ($prefs as $key => $val) + { + if (isset($params[$key])) + { + $prefs[$key] = $params[$key]; + } + } + } + + // Extract the prefs for simplicity + extract($prefs); + + // Are we backing up a complete database or individual tables? + if (count($tables) == 0) + { + $tables = $this->list_tables(); + } + + + + // Start buffering the output + ob_start(); + + // Build the output + foreach ($tables as $table) + { + // Is the table in the "ignore" list? + if (in_array($table, $ignore)) + { + 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 + + echo $newline.$newline.'#'.$newline.'# TABLE STRUCTURE FOR: '.$table.$newline.'#'.$newline.$newline; + + if ($add_drop == TRUE) + { + echo 'DROP TABLE IF EXISTS '.$table.';'.$newline.$newline; + } + + $i = 0; + $result = $query->result_array(); + foreach ($result[0] as $val) + { + if ($i++ % 2) + { + echo $val.';'.$newline.$newline; + } + } + + // Build the insert statements + + if ($add_insert == FALSE) + { + continue; + } + + $query = $this->db->query("SELECT * FROM $table"); + + if ($query->num_rows() == 0) + { + continue; + } + + // Grab 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; + $fields = ''; + $is_int = array(); + while ($field = mysql_fetch_field($query->result_id)) + { + $is_int[$i] = (in_array( + mysql_field_type($query->result_id, $i), + array('tinyint', 'smallint', 'mediumint', 'int', 'bigint', 'timestamp'), + TRUE) + ) ? TRUE : FALSE; + + // Create a string of field names + $fields .= $field->name.', '; + $i++; + } + + $fields = preg_replace( "/, $/" , "" , $fields); + + + // Build the inserts + foreach ($query->result_array() as $row) + { + $values = ''; + + $i = 0; + foreach ($row as $v) + { + $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 + $values .= ($is_int[$i] == FALSE) ? $this->db->escape($v) : $v; + $values .= ', '; + + $i++; + } + + $values = preg_replace( "/, $/" , "" , $values); + + if ($download == FALSE) + { + $values = htmlspecialchars($values); + } + + // Build the INSERT string + echo 'INSERT INTO '.$table.' ('.$fields.') VALUES ('.$values.');'.$newline; + + } + + + + $buffer = ob_get_contents(); + @ob_end_clean(); + + echo $buffer; + + } + + + } } -- cgit v1.2.3-24-g4f1b From 3ed8c51254a5b26d951fa675802fcf69adf9638e Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 29 Sep 2006 23:26:28 +0000 Subject: --- system/database/DB_driver.php | 9 +- system/database/DB_export.php | 132 ------------------------ system/database/DB_utility.php | 121 +++++++++++++++++++++- system/database/drivers/mysql/mysql_utility.php | 48 +++++---- 4 files changed, 150 insertions(+), 160 deletions(-) delete mode 100644 system/database/DB_export.php (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 94db84bbf..275d51c53 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -45,6 +45,7 @@ class CI_DB_driver { var $query_count = 0; var $bind_marker = '?'; var $queries = array(); + var $cache = array(); var $trans_enabled = TRUE; var $_trans_depth = 0; var $_trans_failure = FALSE; // Used with transactions to determine if a rollback should occur @@ -563,6 +564,12 @@ class CI_DB_driver { */ function field_names($table = '') { + // Is there a cached result? + if (isset($this->cache['field_names'][$table])) + { + return $this->cache['field_names'][$table]; + } + if ($table == '') { if ($this->db_debug) @@ -596,7 +603,7 @@ class CI_DB_driver { } } - return $retval; + return $this->cache['field_names'][$table] =& $retval; } // -------------------------------------------------------------------- diff --git a/system/database/DB_export.php b/system/database/DB_export.php deleted file mode 100644 index 1704f0dfd..000000000 --- a/system/database/DB_export.php +++ /dev/null @@ -1,132 +0,0 @@ -field_names() as $name) - { - $out .= $name.$delim; - } - - $out = rtrim($out); - $out .= $newline; - - // Next blast through the result array and build out the rows - foreach ($query->result_array() as $row) - { - foreach ($row as $item) - { - $out .= $item.$delim; - } - $out = rtrim($out); - $out .= $newline; - } - - return $out; - } - - // -------------------------------------------------------------------- - - - /** - * Generate XML data from a query result object - * - * @access public - * @param object The query result object - * @param array Any preferences - * @return string - */ - function xml_from_result($query, $params = array()) - { - if ( ! is_object($query) OR ! method_exists($query, 'field_names')) - { - show_error('You must submit a valid result object'); - } - - // Set our default values - foreach (array('root' => 'root', 'element' => 'element', 'newline' => "\n", 'tab' => "\t") as $key => $val) - { - if ( ! isset($params[$key])) - { - $params[$key] = $val; - } - } - - // Create variables for convenience - extract($params); - - // Load the xml helper - $obj =& get_instance(); - $obj->load->helper('xml'); - - // Generate the result - $xml = "<{$root}/>".$newline; - foreach ($query->result_array() as $row) - { - $xml .= $tab."<{$element}/>".$newline; - - foreach ($row as $key => $val) - { - $xml .= $tab.$tab."<{$key}>".xml_convert($val)."".$newline; - } - $xml .= $tab."".$newline; - } - $xml .= "".$newline; - - return $xml; - } - -} - -?> \ No newline at end of file diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 764f10cb7..ff9407ebd 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -25,6 +25,7 @@ class CI_DB_utility { var $db; + var $cache = array(); /** * Constructor @@ -93,6 +94,12 @@ class CI_DB_utility { */ function list_databases() { + // Is there a cached result? + if (isset($this->cache['db_names'])) + { + return $this->cache['db_names']; + } + $query = $this->db->query($this->_list_database()); $dbs = array(); if ($query->num_rows() > 0) @@ -103,7 +110,7 @@ class CI_DB_utility { } } - return $dbs; + return $this->cache['db_names'] =& $dbs; } // -------------------------------------------------------------------- @@ -116,6 +123,12 @@ class CI_DB_utility { */ function list_tables() { + // Is there a cached result? + if (isset($this->cache['table_names'])) + { + return $this->cache['table_names']; + } + if (FALSE === ($sql = $this->_list_tables())) { if ($this->db->db_debug) @@ -143,7 +156,7 @@ class CI_DB_utility { } } - return $retval; + return $this->cache['table_names'] =& $retval; } // -------------------------------------------------------------------- @@ -258,7 +271,111 @@ class CI_DB_utility { return $this->db->query($sql); } + // -------------------------------------------------------------------- + + /** + * Generate CVS from a query result object + * + * @access public + * @param object The query result object + * @param string The delimiter - tab by default + * @param string The newline character - \n by default + * @return string + */ + function cvs_from_result($query, $delim = "\t", $newline = "\n") + { + if ( ! is_object($query) OR ! method_exists($query, 'field_names')) + { + show_error('You must submit a valid result object'); + } + + $out = ''; + + // First generate the headings from the table column names + foreach ($query->field_names() as $name) + { + $out .= $name.$delim; + } + + $out = rtrim($out); + $out .= $newline; + + // Next blast through the result array and build out the rows + foreach ($query->result_array() as $row) + { + foreach ($row as $item) + { + $out .= $item.$delim; + } + $out = rtrim($out); + $out .= $newline; + } + + return $out; + } + + // -------------------------------------------------------------------- + + /** + * Generate XML data from a query result object + * + * @access public + * @param object The query result object + * @param array Any preferences + * @return string + */ + function xml_from_result($query, $params = array()) + { + if ( ! is_object($query) OR ! method_exists($query, 'field_names')) + { + show_error('You must submit a valid result object'); + } + + // Set our default values + foreach (array('root' => 'root', 'element' => 'element', 'newline' => "\n", 'tab' => "\t") as $key => $val) + { + if ( ! isset($params[$key])) + { + $params[$key] = $val; + } + } + + // Create variables for convenience + extract($params); + + // Load the xml helper + $obj =& get_instance(); + $obj->load->helper('xml'); + + // Generate the result + $xml = "<{$root}/>".$newline; + foreach ($query->result_array() as $row) + { + $xml .= $tab."<{$element}/>".$newline; + + foreach ($row as $key => $val) + { + $xml .= $tab.$tab."<{$key}>".xml_convert($val)."".$newline; + } + $xml .= $tab."".$newline; + } + $xml .= "".$newline; + + return $xml; + } + + // -------------------------------------------------------------------- + /** + * Database Backup + * + * @access public + * @return void + */ + function export() + { + // The individual driver overloads this method + } } diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 65fb87f92..f43299382 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -128,19 +128,18 @@ class CI_DB_mysql_utility extends CI_DB_utility { /** * MySQL Export * - * @access public - * @param object The query result object + * @access private * @param array Any preferences - * @return string + * @return mixed */ - function export($params = array()) + function _export($params = array()) { // Set up our default preferences $prefs = array( 'tables' => array(), 'ignore' => array(), 'format' => 'gzip', - 'download' => TRUE, + 'action' => 'download', // download, archive, echo, return 'filename' => date('Y-m-d-H:i', time()), 'filepath' => '', 'add_drop' => TRUE, @@ -169,8 +168,6 @@ class CI_DB_mysql_utility extends CI_DB_utility { $tables = $this->list_tables(); } - - // Start buffering the output ob_start(); @@ -193,7 +190,6 @@ class CI_DB_mysql_utility extends CI_DB_utility { } // Write out the table schema - echo $newline.$newline.'#'.$newline.'# TABLE STRUCTURE FOR: '.$table.$newline.'#'.$newline.$newline; if ($add_drop == TRUE) @@ -211,13 +207,13 @@ class CI_DB_mysql_utility extends CI_DB_utility { } } - // Build the insert statements - + // 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) @@ -225,37 +221,39 @@ class CI_DB_mysql_utility extends CI_DB_utility { continue; } - // Grab the field names and determine if the field is an + // 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; - $fields = ''; + $field_str = ''; $is_int = array(); while ($field = mysql_fetch_field($query->result_id)) { $is_int[$i] = (in_array( - mysql_field_type($query->result_id, $i), + strtolower(mysql_field_type($query->result_id, $i)), array('tinyint', 'smallint', 'mediumint', 'int', 'bigint', 'timestamp'), TRUE) ) ? TRUE : FALSE; // Create a string of field names - $fields .= $field->name.', '; + $field_str .= $field->name.', '; $i++; } - - $fields = preg_replace( "/, $/" , "" , $fields); + + // Trim off the end comma + $field_str = preg_replace( "/, $/" , "" , $field_str); - // Build the inserts + // Build the insert string foreach ($query->result_array() as $row) { - $values = ''; + $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); @@ -265,21 +263,21 @@ class CI_DB_mysql_utility extends CI_DB_utility { $v = str_replace('\\\t', '\t', $v); // Escape the data if it's not an integer type - $values .= ($is_int[$i] == FALSE) ? $this->db->escape($v) : $v; - $values .= ', '; + $val_str .= ($is_int[$i] == FALSE) ? $this->db->escape($v) : $v; + $val_str .= ', '; $i++; } - $values = preg_replace( "/, $/" , "" , $values); + $val_str = preg_replace( "/, $/" , "" , $val_str); - if ($download == FALSE) + if ($action == 'echo') { - $values = htmlspecialchars($values); + $val_str = htmlspecialchars($val_str); } // Build the INSERT string - echo 'INSERT INTO '.$table.' ('.$fields.') VALUES ('.$values.');'.$newline; + echo 'INSERT INTO '.$table.' ('.$field_str.') VALUES ('.$val_str.');'.$newline; } -- cgit v1.2.3-24-g4f1b From 3dd978f680076be842bfcb5c9e2cbf35b926373b Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 30 Sep 2006 19:24:45 +0000 Subject: --- system/database/DB_driver.php | 101 ++++++- system/database/DB_utility.php | 310 +++++++++++++++------ system/database/drivers/mssql/mssql_driver.php | 28 ++ system/database/drivers/mssql/mssql_utility.php | 28 -- system/database/drivers/mysql/mysql_driver.php | 28 ++ system/database/drivers/mysql/mysql_utility.php | 95 +------ system/database/drivers/mysqli/mysqli_driver.php | 30 +- system/database/drivers/mysqli/mysqli_utility.php | 28 -- system/database/drivers/oci8/oci8_driver.php | 28 ++ system/database/drivers/oci8/oci8_utility.php | 28 -- system/database/drivers/odbc/odbc_driver.php | 33 +++ system/database/drivers/odbc/odbc_utility.php | 53 +--- system/database/drivers/postgre/postgre_driver.php | 28 ++ .../database/drivers/postgre/postgre_utility.php | 28 -- system/database/drivers/sqlite/sqlite_driver.php | 39 ++- system/database/drivers/sqlite/sqlite_utility.php | 46 +-- 16 files changed, 561 insertions(+), 370 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 275d51c53..5102cc74c 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -555,6 +555,95 @@ class CI_DB_driver { // -------------------------------------------------------------------- + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access public + * @return bool + */ + function list_databases() + { + // Is there a cached result? + if (isset($this->cache['db_names'])) + { + return $this->cache['db_names']; + } + + $query = $this->query($this->_list_database()); + $dbs = array(); + if ($query->num_rows() > 0) + { + foreach ($query->result_array() as $row) + { + $dbs[] = current($row); + } + } + + return $this->cache['db_names'] =& $dbs; + } + + // -------------------------------------------------------------------- + + /** + * Returns an array of table names + * + * @access public + * @return array + */ + function list_tables() + { + // Is there a cached result? + if (isset($this->cache['table_names'])) + { + return $this->cache['table_names']; + } + + if (FALSE === ($sql = $this->_list_tables())) + { + if ($this->db_debug) + { + return $this->display_error('db_unsupported_function'); + } + return FALSE; + } + + $retval = array(); + $query = $this->query($sql); + + if ($query->num_rows() > 0) + { + foreach($query->result_array() as $row) + { + if (isset($row['TABLE_NAME'])) + { + $retval[] = $row['TABLE_NAME']; + } + else + { + $retval[] = array_shift($row); + } + } + } + + return $this->cache['table_names'] =& $retval; + } + + // -------------------------------------------------------------------- + + /** + * Determine if a particular table exists + * @access public + * @return boolean + */ + function table_exists($table_name) + { + return ( ! in_array($this->dbprefix.$table_name, $this->list_tables())) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + /** * Fetch MySQL Field Names * @@ -562,7 +651,7 @@ class CI_DB_driver { * @param string the table name * @return array */ - function field_names($table = '') + function list_fields($table = '') { // Is there a cached result? if (isset($this->cache['field_names'][$table])) @@ -605,6 +694,16 @@ class CI_DB_driver { return $this->cache['field_names'][$table] =& $retval; } + + // -------------------------------------------------------------------- + + /** + * DEPRECATED - use list_fields() + */ + function field_names($table = '') + { + return $this->list_fields($table); + } // -------------------------------------------------------------------- diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index ff9407ebd..dc56d6524 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -86,93 +86,6 @@ class CI_DB_utility { // -------------------------------------------------------------------- - /** - * List databases - * - * @access public - * @return bool - */ - function list_databases() - { - // Is there a cached result? - if (isset($this->cache['db_names'])) - { - return $this->cache['db_names']; - } - - $query = $this->db->query($this->_list_database()); - $dbs = array(); - if ($query->num_rows() > 0) - { - foreach ($query->result_array() as $row) - { - $dbs[] = current($row); - } - } - - return $this->cache['db_names'] =& $dbs; - } - - // -------------------------------------------------------------------- - - /** - * Returns an array of table names - * - * @access public - * @return array - */ - function list_tables() - { - // Is there a cached result? - if (isset($this->cache['table_names'])) - { - return $this->cache['table_names']; - } - - if (FALSE === ($sql = $this->_list_tables())) - { - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsupported_function'); - } - return FALSE; - } - - $retval = array(); - $query = $this->db->query($sql); - - if ($query->num_rows() > 0) - { - foreach($query->result_array() as $row) - { - if (isset($row['TABLE_NAME'])) - { - $retval[] = $row['TABLE_NAME']; - } - else - { - $retval[] = array_shift($row); - } - } - } - - return $this->cache['table_names'] =& $retval; - } - - // -------------------------------------------------------------------- - - /** - * Determine if a particular table exists - * @access public - * @return boolean - */ - function table_exists($table_name) - { - return ( ! in_array($this->db->dbprefix.$table_name, $this->list_tables())) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - /** * Optimize Table * @@ -372,12 +285,231 @@ class CI_DB_utility { * @access public * @return void */ - function export() + function backup($params = array()) { - // The individual driver overloads this method + // If the parameters have not been submitted as an + // array then we know that it is simply the table + // name, which is a valid short cut. + if (is_string($params)) + { + $params = array('tables' => $params); + } + + // ------------------------------------------------------ + + // Set up our default preferences + $prefs = array( + 'tables' => array(), + 'ignore' => array(), + 'format' => 'gzip', // gzip, zip, txt + 'action' => 'download', // download, archive, echo, return + 'filename' => '', + 'filepath' => '', + 'add_drop' => TRUE, + 'add_insert' => TRUE, + 'newline' => "\n" + ); + + // Did the user submit any preferences? If so set them.... + if (count($params) > 0) + { + foreach ($prefs as $key => $val) + { + if (isset($params[$key])) + { + $prefs[$key] = $params[$key]; + } + } + } + + // ------------------------------------------------------ + + // Are we backing up a complete database or individual tables? + // If no table names were submitted we'll fetch the entire table list + if (count($prefs['tables']) == 0) + { + $prefs['tables'] = $this->list_tables(); + } + + // ------------------------------------------------------ + + // Validate the format + if ( ! in_array($prefs['format'], array('gzip', 'zip', 'txt'), TRUE)) + { + $prefs['format'] = 'txt'; + } + + // ------------------------------------------------------ + + // Is the encoder supported? If not, we'll either issue an + // error or use plain text depending on the debug settings + if (($prefs['format'] == 'gzip' AND ! @function_exists('gzencode')) + OR ($prefs['format'] == 'zip' AND ! @function_exists('gzcompress'))) + { + if ($this->db->db_debug) + { + return $this->db->display_error('db_unsuported_compression'); + } + + $prefs['format'] = 'txt'; + } + + // ------------------------------------------------------ + + // Set the filename if not provided + if ($prefs['filename'] == '') + { + $prefs['filename'] = (count($prefs['tables']) == 1) ? $prefs['tables'] : $this->db->database; + $prefs['filename'] .= '_'.date('Y-m-d_H-i', time()); + } + + // ------------------------------------------------------ + + // If we are archiving the export, does this filepath exist + // and resolve to a writable directory + if ($prefs['action'] == 'archive') + { + if ($prefs['filepath'] == '' OR ! is_writable($prefs['filepath'])) + { + if ($this->db->db_debug) + { + return $this->db->display_error('db_filepath_error'); + } + + $prefs['action'] = 'download'; + } + } + + // ------------------------------------------------------ + + // Are we returning the backup data? If so, we're done... + if ($prefs['action'] == 'return') + { + return $this->_backup($prefs); + } + + // ------------------------------------------------------ + + // Are we echoing the backup? If so, format the data and spit it at the screen... + if ($prefs['action'] == 'echo') + { + echo '

';
+			echo htmlspecialchars($this->_backup($prefs));
+			echo '
'; + + return TRUE; + } + + // ------------------------------------------------------ + + // Are we archiving the data to the server? + if ($prefs['action'] == 'archive') + { + // Make sure the filepath has a trailing slash + if (ereg("/$", $prefs['filepath']) === FALSE) + { + $prefs['filepath'] .= '/'; + } + + // Assemble the path and tack on the file extension + $ext = array('gzip' => 'gz', 'zip' => 'zip', 'txt' => 'sql'); + $path = $prefs['filepath'].$prefs['filename'].$ext[$prefs['format']]; + + // Load the file helper + $obj =& get_instance(); + $obj->load->helper('file'); + + // Write the file based on type + switch ($prefs['format']) + { + case 'gzip' : + write_file($path, gzencode($this->_backup($prefs))); + return TRUE; + break; + case 'txt' : + write_file($path, $this->_backup($prefs)); + return TRUE; + break; + default : + require BASEPATH.'libraries/Zip.php'; + $zip = new Zip; + $zip->add_file($this->_backup($prefs), $prefs['filename'].'.sql'); + write_file($path, $zip->output_zipfile()); + return TRUE; + break; + } + + } + + // ------------------------------------------------------ + + // Set the mime type used in the server header + switch ($prefs['format']) + { + case 'zip' : $mime = 'application/x-zip'; + break; + case 'gzip' : $mime = 'application/x-gzip'; + break; + default : + if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE") || strstr($_SERVER['HTTP_USER_AGENT'], "OPERA")) + { + $mime = 'application/octetstream'; + } + else + { + $mime = 'application/octet-stream'; + } + break; + } + + // Grab the super object + $obj =& get_instance(); + + // Remap the file extensions + $ext = array('gzip' => 'gz', 'zip' => 'zip', 'txt' => 'sql'); + + // Send headers + if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) + { + $obj->output->set_header('Content-Type: '.$mime); + $obj->output->set_header('Content-Disposition: inline; filename="'.$prefs['filename'].'.'.$ext[$prefs['format']].'"'); + $obj->output->set_header('Expires: 0'); + $obj->output->set_header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + $obj->output->set_header('Pragma: public'); + } + else + { + $obj->output->set_header('Content-Type: '.$mime); + $obj->output->set_header('Content-Disposition: attachment; filename="'.$prefs['filename'].'.'.$ext[$prefs['format']].'"'); + $obj->output->set_header('Expires: 0'); + $obj->output->set_header('Pragma: no-cache'); + } + + + // Write the file based on type + switch ($prefs['format']) + { + case 'gzip' : $obj->output->set_output(gzencode($this->_backup($prefs))); + break; + case 'txt' : $obj->output->set_output($this->_backup($prefs)); + break; + default : + require BASEPATH.'libraries/Zip.php'; + + $zip = new Zip; + $zip->add_file($this->_backup($prefs), $prefs['filename'].'.sql'); + $obj->output->set_output($zip->output_zipfile()); + break; + } + + return TRUE; } + + + + } ?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 3f5e53345..8b82ee314 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -261,6 +261,34 @@ class CI_DB_mssql_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + return "EXEC sp_helpdb"; // Can also be: EXEC sp_databases + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; + } + + // -------------------------------------------------------------------- + /** * List columnn query * diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index 96b8180b8..ad13167cd 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -53,34 +53,6 @@ class CI_DB_mssql_utility extends CI_DB_utility { // -------------------------------------------------------------------- - /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - return "EXEC sp_helpdb"; // Can also be: EXEC sp_databases - } - - // -------------------------------------------------------------------- - - /** - * List table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; - } - - // -------------------------------------------------------------------- - /** * Drop Table * diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 792e023a8..ecab648d4 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -292,6 +292,34 @@ class CI_DB_mysql_driver extends CI_DB { $row = $query->row(); return $row->numrows; } + + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + return "SHOW DATABASES"; + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SHOW TABLES FROM `".$this->database."`"; + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index f43299382..a81c915f6 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -52,34 +52,6 @@ class CI_DB_mysql_utility extends CI_DB_utility { // -------------------------------------------------------------------- - /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - return "SHOW DATABASES"; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SHOW TABLES FROM `".$this->db->database."`"; - } - - // -------------------------------------------------------------------- - /** * Drop Table * @@ -132,50 +104,22 @@ class CI_DB_mysql_utility extends CI_DB_utility { * @param array Any preferences * @return mixed */ - function _export($params = array()) + function _backup($params = array()) { - // Set up our default preferences - $prefs = array( - 'tables' => array(), - 'ignore' => array(), - 'format' => 'gzip', - 'action' => 'download', // download, archive, echo, return - 'filename' => date('Y-m-d-H:i', time()), - 'filepath' => '', - 'add_drop' => TRUE, - 'add_insert' => TRUE, - 'newline' => "\n" - ); - - // Did the user submit any preference overrides? If so set them.... - if (count($params) > 0) + if (count($params) == 0) { - foreach ($prefs as $key => $val) - { - if (isset($params[$key])) - { - $prefs[$key] = $params[$key]; - } - } + return FALSE; } // Extract the prefs for simplicity - extract($prefs); - - // Are we backing up a complete database or individual tables? - if (count($tables) == 0) - { - $tables = $this->list_tables(); - } - - // Start buffering the output - ob_start(); + extract($params); // Build the output - foreach ($tables as $table) + $output = ''; + foreach ((array)$tables as $table) { // Is the table in the "ignore" list? - if (in_array($table, $ignore)) + if (in_array($table, (array)$ignore, TRUE)) { continue; } @@ -190,11 +134,11 @@ class CI_DB_mysql_utility extends CI_DB_utility { } // Write out the table schema - echo $newline.$newline.'#'.$newline.'# TABLE STRUCTURE FOR: '.$table.$newline.'#'.$newline.$newline; + $output .= '#'.$newline.'# TABLE STRUCTURE FOR: '.$table.$newline.'#'.$newline.$newline; if ($add_drop == TRUE) { - echo 'DROP TABLE IF EXISTS '.$table.';'.$newline.$newline; + $output .= 'DROP TABLE IF EXISTS '.$table.';'.$newline.$newline; } $i = 0; @@ -203,7 +147,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { { if ($i++ % 2) { - echo $val.';'.$newline.$newline; + $output .= $val.';'.$newline.$newline; } } @@ -270,27 +214,16 @@ class CI_DB_mysql_utility extends CI_DB_utility { } $val_str = preg_replace( "/, $/" , "" , $val_str); - - if ($action == 'echo') - { - $val_str = htmlspecialchars($val_str); - } - + // Build the INSERT string - echo 'INSERT INTO '.$table.' ('.$field_str.') VALUES ('.$val_str.');'.$newline; + $output .= 'INSERT INTO '.$table.' ('.$field_str.') VALUES ('.$val_str.');'.$newline; } - - - $buffer = ob_get_contents(); - @ob_end_clean(); - - echo $buffer; - + $output .= $newline.$newline; } - + return $output; } diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index b158cfefe..a2c380355 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -284,7 +284,35 @@ class CI_DB_mysqli_driver extends CI_DB { $row = $query->row(); return $row->numrows; } - + + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + return "SHOW DATABASES"; + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SHOW TABLES FROM `".$this->database."`"; + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 754ffbda2..f5b98b11f 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -52,34 +52,6 @@ class CI_DB_mysqli_utility extends CI_DB_utility { // -------------------------------------------------------------------- - /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - return "SHOW DATABASES"; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SHOW TABLES FROM `".$this->db->database."`"; - } - - // -------------------------------------------------------------------- - /** * Drop Table * diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index bc0a100c2..b43b4c41f 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -399,6 +399,34 @@ class CI_DB_oci8_driver extends CI_DB { return $row->NUMROWS; } + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SELECT TABLE_NAME FROM ALL_TABLES"; + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 4d267dc6a..b6503de63 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -53,34 +53,6 @@ class CI_DB_oci8_utility extends CI_DB_utility { // -------------------------------------------------------------------- - /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SELECT TABLE_NAME FROM ALL_TABLES"; - } - - // -------------------------------------------------------------------- - /** * Drop Table * diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index cdde2e2ea..0f002cc1b 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -259,6 +259,39 @@ class CI_DB_odbc_driver extends CI_DB { $row = $query->row(); return $row->numrows; } + + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + // Not sure if ODBC lets you list all databases... + if ($this->db_debug) + { + return $this->display_error('db_unsuported_feature'); + } + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SHOW TABLES FROM `".$this->database."`"; + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index 3d420f69d..6d0fb79f1 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -36,9 +36,9 @@ class CI_DB_odbc_utility extends CI_DB_utility { { // ODBC has no "create database" command since it's // designed to connect to an existing database - if ($this->db_debug) + if ($this->db->db_debug) { - return $this->display_error('db_unsuported_feature'); + return $this->db->display_error('db_unsuported_feature'); } return FALSE; } @@ -56,48 +56,15 @@ class CI_DB_odbc_utility extends CI_DB_utility { { // ODBC has no "drop database" command since it's // designed to connect to an existing database - if ($this->db_debug) + if ($this->db->db_debug) { - return $this->display_error('db_unsuported_feature'); + return $this->db->display_error('db_unsuported_feature'); } return FALSE; } // -------------------------------------------------------------------- - /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - // Not sure if ODBC lets you list all databases... - if ($this->db_debug) - { - return $this->display_error('db_unsuported_feature'); - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SHOW TABLES FROM `".$this->db->database."`"; - } - - // -------------------------------------------------------------------- - /** * Drop Table * @@ -107,9 +74,9 @@ class CI_DB_odbc_utility extends CI_DB_utility { function _drop_table($table) { // Not a supported ODBC feature - if ($this->db_debug) + if ($this->db->db_debug) { - return $this->display_error('db_unsuported_feature'); + return $this->db->display_error('db_unsuported_feature'); } return FALSE; } @@ -128,9 +95,9 @@ class CI_DB_odbc_utility extends CI_DB_utility { function _optimize_table($table) { // Not a supported ODBC feature - if ($this->db_debug) + if ($this->db->db_debug) { - return $this->display_error('db_unsuported_feature'); + return $this->db->display_error('db_unsuported_feature'); } return FALSE; } @@ -149,9 +116,9 @@ class CI_DB_odbc_utility extends CI_DB_utility { function _repair_table($table) { // Not a supported ODBC feature - if ($this->db_debug) + if ($this->db->db_debug) { - return $this->display_error('db_unsuported_feature'); + return $this->db->display_error('db_unsuported_feature'); } return FALSE; } diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 026284118..f14395638 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -286,6 +286,34 @@ class CI_DB_postgre_driver extends CI_DB { $row = $query->row(); return $row->numrows; } + + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + return "SELECT datname FROM pg_database"; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 7b51c3fe7..46c98cc7d 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -53,34 +53,6 @@ class CI_DB_postgre_utility extends CI_DB_utility { // -------------------------------------------------------------------- - /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - return "SELECT datname FROM pg_database"; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; - } - - // -------------------------------------------------------------------- - /** * Drop Table * diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 45dd7a892..f57c4b8c8 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -278,7 +278,44 @@ class CI_DB_sqlite_driver extends CI_DB { $row = $query->row(); return $row->numrows; } - + + // -------------------------------------------------------------------- + + /** + * List databases + * + * I don't believe you can do a database listing with SQLite + * since each database is its own file. I suppose we could + * try reading a directory looking for SQLite files, but + * that doesn't seem like a terribly good idea + * + * @access private + * @return bool + */ + function _list_databases() + { + if ($this->db_debug) + { + return $this->display_error('db_unsuported_feature'); + } + return array(); + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SELECT name from sqlite_master WHERE type='table'"; + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index ae241db87..801660d94 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -52,9 +52,9 @@ class CI_DB_sqlite_utility extends CI_DB_utility { { if ( ! @file_exists($this->db->database) OR ! @unlink($this->db->database)) { - if ($this->db_debug) + if ($this->db->db_debug) { - return $this->display_error('db_unable_to_drop'); + return $this->db->display_error('db_unable_to_drop'); } return FALSE; } @@ -63,44 +63,6 @@ class CI_DB_sqlite_utility extends CI_DB_utility { // -------------------------------------------------------------------- - /** - * List databases - * - * I don't believe you can do a database listing with SQLite - * since each database is its own file. I suppose we could - * try reading a directory looking for SQLite files, but - * that doesn't seem like a terribly good idea - * - * @access private - * @return bool - */ - function _list_databases() - { - - if ($this->db_debug) - { - return $this->display_error('db_unsuported_feature'); - } - return array(); - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SELECT name from sqlite_master WHERE type='table'"; - } - - // -------------------------------------------------------------------- - /** * Drop Table * @@ -111,9 +73,9 @@ class CI_DB_sqlite_utility extends CI_DB_utility { */ function _drop_table($table) { - if ($this->db_debug) + if ($this->db->db_debug) { - return $this->display_error('db_unsuported_feature'); + return $this->db->display_error('db_unsuported_feature'); } return array(); } -- cgit v1.2.3-24-g4f1b From b2a9ceccdb85050cb494e6d0a98b0a49495d29bb Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 1 Oct 2006 03:38:04 +0000 Subject: --- system/database/DB_driver.php | 45 +++++++--------------- system/database/DB_utility.php | 29 ++++++++++++++ system/database/drivers/mssql/mssql_driver.php | 13 ------- system/database/drivers/mssql/mssql_utility.php | 13 +++++++ system/database/drivers/mysql/mysql_driver.php | 13 ------- system/database/drivers/mysql/mysql_utility.php | 16 +++++++- system/database/drivers/mysqli/mysqli_driver.php | 13 ------- system/database/drivers/mysqli/mysqli_utility.php | 13 +++++++ system/database/drivers/oci8/oci8_driver.php | 13 ------- system/database/drivers/oci8/oci8_utility.php | 13 +++++++ system/database/drivers/odbc/odbc_driver.php | 18 --------- system/database/drivers/odbc/odbc_utility.php | 18 +++++++++ system/database/drivers/postgre/postgre_driver.php | 13 ------- .../database/drivers/postgre/postgre_utility.php | 13 +++++++ system/database/drivers/sqlite/sqlite_driver.php | 22 ----------- system/database/drivers/sqlite/sqlite_utility.php | 22 +++++++++++ 16 files changed, 149 insertions(+), 138 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 5102cc74c..81af466ef 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -555,37 +555,6 @@ class CI_DB_driver { // -------------------------------------------------------------------- - // -------------------------------------------------------------------- - - /** - * List databases - * - * @access public - * @return bool - */ - function list_databases() - { - // Is there a cached result? - if (isset($this->cache['db_names'])) - { - return $this->cache['db_names']; - } - - $query = $this->query($this->_list_database()); - $dbs = array(); - if ($query->num_rows() > 0) - { - foreach ($query->result_array() as $row) - { - $dbs[] = current($row); - } - } - - return $this->cache['db_names'] =& $dbs; - } - - // -------------------------------------------------------------------- - /** * Returns an array of table names * @@ -694,6 +663,20 @@ class CI_DB_driver { return $this->cache['field_names'][$table] =& $retval; } + + // -------------------------------------------------------------------- + + /** + * Determine if a particular field exists + * @access public + * @param string + * @param string + * @return boolean + */ + function field_exists($field_name, $table_name) + { + return ( ! in_array($field_name, $this->list_fields($table_name))) ? FALSE : TRUE; + } // -------------------------------------------------------------------- diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index dc56d6524..e568bce02 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -86,6 +86,35 @@ class CI_DB_utility { // -------------------------------------------------------------------- + /** + * List databases + * + * @access public + * @return bool + */ + function list_databases() + { + // Is there a cached result? + if (isset($this->cache['db_names'])) + { + return $this->cache['db_names']; + } + + $query = $this->db->query($this->_list_database()); + $dbs = array(); + if ($query->num_rows() > 0) + { + foreach ($query->result_array() as $row) + { + $dbs[] = current($row); + } + } + + return $this->cache['db_names'] =& $dbs; + } + + // -------------------------------------------------------------------- + /** * Optimize Table * diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 8b82ee314..cb2f48dc3 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -258,19 +258,6 @@ class CI_DB_mssql_driver extends CI_DB { $row = $query->row(); return $row->numrows; } - - // -------------------------------------------------------------------- - - /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - return "EXEC sp_helpdb"; // Can also be: EXEC sp_databases - } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index ad13167cd..388dbe1c2 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -66,6 +66,19 @@ class CI_DB_mssql_utility extends CI_DB_utility { // -------------------------------------------------------------------- + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + return "EXEC sp_helpdb"; // Can also be: EXEC sp_databases + } + + // -------------------------------------------------------------------- + /** * Optimize table query * diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index ecab648d4..253627cd9 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -295,19 +295,6 @@ class CI_DB_mysql_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - return "SHOW DATABASES"; - } - - // -------------------------------------------------------------------- - /** * List table query * diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index a81c915f6..b387ace9e 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -52,6 +52,19 @@ class CI_DB_mysql_utility extends CI_DB_utility { // -------------------------------------------------------------------- + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + return "SHOW DATABASES"; + } + + // -------------------------------------------------------------------- + /** * Drop Table * @@ -101,7 +114,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { * MySQL Export * * @access private - * @param array Any preferences + * @param array Preferences * @return mixed */ function _backup($params = array()) @@ -217,7 +230,6 @@ class CI_DB_mysql_utility extends CI_DB_utility { // Build the INSERT string $output .= 'INSERT INTO '.$table.' ('.$field_str.') VALUES ('.$val_str.');'.$newline; - } $output .= $newline.$newline; diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index a2c380355..4fd9f3aaa 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -287,19 +287,6 @@ class CI_DB_mysqli_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - return "SHOW DATABASES"; - } - - // -------------------------------------------------------------------- - /** * List table query * diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index f5b98b11f..a40441d20 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -62,6 +62,19 @@ class CI_DB_mysqli_utility extends CI_DB_utility { { return "DROP TABLE IF EXISTS ".$this->db->_escape_table($name); } + + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + return "SHOW DATABASES"; + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index b43b4c41f..e83c640bd 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -399,19 +399,6 @@ class CI_DB_oci8_driver extends CI_DB { return $row->NUMROWS; } - // -------------------------------------------------------------------- - - /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - return FALSE; - } - // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index b6503de63..b1d539ad6 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -53,6 +53,19 @@ class CI_DB_oci8_utility extends CI_DB_utility { // -------------------------------------------------------------------- + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + return FALSE; + } + + // -------------------------------------------------------------------- + /** * Drop Table * diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 0f002cc1b..4bd6e1106 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -262,24 +262,6 @@ class CI_DB_odbc_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - // Not sure if ODBC lets you list all databases... - if ($this->db_debug) - { - return $this->display_error('db_unsuported_feature'); - } - return FALSE; - } - - // -------------------------------------------------------------------- - /** * Show table query * diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index 6d0fb79f1..5a0e365ef 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -65,6 +65,24 @@ class CI_DB_odbc_utility extends CI_DB_utility { // -------------------------------------------------------------------- + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + // Not sure if ODBC lets you list all databases... + if ($this->db->db_debug) + { + return $this->db->display_error('db_unsuported_feature'); + } + return FALSE; + } + + // -------------------------------------------------------------------- + /** * Drop Table * diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index f14395638..340d65046 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -289,19 +289,6 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - return "SELECT datname FROM pg_database"; - } - - // -------------------------------------------------------------------- - /** * Show table query * diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 46c98cc7d..038aa26cd 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -53,6 +53,19 @@ class CI_DB_postgre_utility extends CI_DB_utility { // -------------------------------------------------------------------- + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + return "SELECT datname FROM pg_database"; + } + + // -------------------------------------------------------------------- + /** * Drop Table * diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index f57c4b8c8..9da50b676 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -281,28 +281,6 @@ class CI_DB_sqlite_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * List databases - * - * I don't believe you can do a database listing with SQLite - * since each database is its own file. I suppose we could - * try reading a directory looking for SQLite files, but - * that doesn't seem like a terribly good idea - * - * @access private - * @return bool - */ - function _list_databases() - { - if ($this->db_debug) - { - return $this->display_error('db_unsuported_feature'); - } - return array(); - } - - // -------------------------------------------------------------------- - /** * List table query * diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 801660d94..19b06bd6d 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -63,6 +63,28 @@ class CI_DB_sqlite_utility extends CI_DB_utility { // -------------------------------------------------------------------- + /** + * List databases + * + * I don't believe you can do a database listing with SQLite + * since each database is its own file. I suppose we could + * try reading a directory looking for SQLite files, but + * that doesn't seem like a terribly good idea + * + * @access private + * @return bool + */ + function _list_databases() + { + if ($this->db_debug) + { + return $this->display_error('db_unsuported_feature'); + } + return array(); + } + + // -------------------------------------------------------------------- + /** * Drop Table * -- cgit v1.2.3-24-g4f1b From 24dd7e71d2587c4290c85bc85e0e181b29ab0539 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 1 Oct 2006 19:02:29 +0000 Subject: --- system/database/DB_utility.php | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index e568bce02..2748a4407 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -216,7 +216,7 @@ class CI_DB_utility { // -------------------------------------------------------------------- /** - * Generate CVS from a query result object + * Generate CSV from a query result object * * @access public * @param object The query result object @@ -224,7 +224,7 @@ class CI_DB_utility { * @param string The newline character - \n by default * @return string */ - function cvs_from_result($query, $delim = "\t", $newline = "\n") + function csv_from_result($query, $delim = "\t", $newline = "\n") { if ( ! is_object($query) OR ! method_exists($query, 'field_names')) { @@ -502,6 +502,7 @@ class CI_DB_utility { { $obj->output->set_header('Content-Type: '.$mime); $obj->output->set_header('Content-Disposition: inline; filename="'.$prefs['filename'].'.'.$ext[$prefs['format']].'"'); + $obj->output->set_header('Content-Transfer-Encoding: binary'); $obj->output->set_header('Expires: 0'); $obj->output->set_header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); $obj->output->set_header('Pragma: public'); @@ -510,26 +511,27 @@ class CI_DB_utility { { $obj->output->set_header('Content-Type: '.$mime); $obj->output->set_header('Content-Disposition: attachment; filename="'.$prefs['filename'].'.'.$ext[$prefs['format']].'"'); + $obj->output->set_header('Content-Transfer-Encoding: binary'); $obj->output->set_header('Expires: 0'); $obj->output->set_header('Pragma: no-cache'); } - - - // Write the file based on type - switch ($prefs['format']) - { - case 'gzip' : $obj->output->set_output(gzencode($this->_backup($prefs))); - break; - case 'txt' : $obj->output->set_output($this->_backup($prefs)); - break; - default : - require BASEPATH.'libraries/Zip.php'; - - $zip = new Zip; - $zip->add_file($this->_backup($prefs), $prefs['filename'].'.sql'); - $obj->output->set_output($zip->output_zipfile()); - break; - } + + + // Write the file based on type + switch ($prefs['format']) + { + case 'gzip' : $obj->output->set_output(gzencode($this->_backup($prefs))); + break; + case 'txt' : $obj->output->set_output($this->_backup($prefs)); + break; + default : + require BASEPATH.'libraries/Zip.php'; + + $zip = new Zip; + $zip->add_file($this->_backup($prefs), $prefs['filename'].'.sql'); + $obj->output->set_output($zip->output_zipfile()); + break; + } return TRUE; } -- cgit v1.2.3-24-g4f1b From 0f8015fcdc4eb7a2bedc6a04548e588b39914c60 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 1 Oct 2006 22:08:34 +0000 Subject: --- system/database/DB_utility.php | 81 +++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 44 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 2748a4407..e239d75e8 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -460,10 +460,9 @@ class CI_DB_utility { return TRUE; break; default : - require BASEPATH.'libraries/Zip.php'; - $zip = new Zip; - $zip->add_file($this->_backup($prefs), $prefs['filename'].'.sql'); - write_file($path, $zip->output_zipfile()); + $obj->load->library('zip'); + $obj->zip->add_data($prefs['filename'].'.sql', $this->_backup($prefs)); + $obj->zip->archive($path); return TRUE; break; } @@ -472,65 +471,59 @@ class CI_DB_utility { // ------------------------------------------------------ - // Set the mime type used in the server header - switch ($prefs['format']) - { - case 'zip' : $mime = 'application/x-zip'; - break; - case 'gzip' : $mime = 'application/x-gzip'; - break; - default : - if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE") || strstr($_SERVER['HTTP_USER_AGENT'], "OPERA")) - { - $mime = 'application/octetstream'; - } - else - { - $mime = 'application/octet-stream'; - } - break; - } // Grab the super object $obj =& get_instance(); // Remap the file extensions $ext = array('gzip' => 'gz', 'zip' => 'zip', 'txt' => 'sql'); + + // Is a Zip file requested? + if ($prefs['format'] == 'zip') + { + $obj->load->library('zip'); + $obj->zip->add_data($prefs['filename'].'.sql', $this->_backup($prefs)); + $obj->zip->download($prefs['filename'].'.'.$ext[$prefs['format']]); + return TRUE; + } + + + // Set the mime type + switch ($prefs['format']) + { + case 'gzip' : $mime = 'application/x-gzip'; + break; + default : $mime = (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE") || strstr($_SERVER['HTTP_USER_AGENT'], "OPERA")) ? 'application/octetstream' : 'application/octet-stream'; + break; + } + + $filename = $prefs['filename'].'.sql.'.$ext[$prefs['format']]; - // Send headers if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) { - $obj->output->set_header('Content-Type: '.$mime); - $obj->output->set_header('Content-Disposition: inline; filename="'.$prefs['filename'].'.'.$ext[$prefs['format']].'"'); - $obj->output->set_header('Content-Transfer-Encoding: binary'); - $obj->output->set_header('Expires: 0'); - $obj->output->set_header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); - $obj->output->set_header('Pragma: public'); + header('Content-Type: '.$mime); + header('Content-Disposition: inline; filename="'.$filename.'"'); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header("Content-Transfer-Encoding: binary"); + header('Pragma: public'); } else { - $obj->output->set_header('Content-Type: '.$mime); - $obj->output->set_header('Content-Disposition: attachment; filename="'.$prefs['filename'].'.'.$ext[$prefs['format']].'"'); - $obj->output->set_header('Content-Transfer-Encoding: binary'); - $obj->output->set_header('Expires: 0'); - $obj->output->set_header('Pragma: no-cache'); + header('Content-Type: '.$mime); + header('Content-Disposition: attachment; filename="'.$filename.'"'); + header("Content-Transfer-Encoding: binary"); + header('Expires: 0'); + header('Pragma: no-cache'); } - // Write the file based on type switch ($prefs['format']) { - case 'gzip' : $obj->output->set_output(gzencode($this->_backup($prefs))); + case 'gzip' : echo gzencode($this->_backup($prefs)); break; - case 'txt' : $obj->output->set_output($this->_backup($prefs)); + case 'txt' : echo $this->_backup($prefs); break; - default : - require BASEPATH.'libraries/Zip.php'; - - $zip = new Zip; - $zip->add_file($this->_backup($prefs), $prefs['filename'].'.sql'); - $obj->output->set_output($zip->output_zipfile()); - break; } return TRUE; -- cgit v1.2.3-24-g4f1b From 78bc039b72695ab67a2d0d537b4c1f03d5d01b83 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 2 Oct 2006 02:38:50 +0000 Subject: --- system/database/DB_utility.php | 141 +++++++---------------------------------- 1 file changed, 23 insertions(+), 118 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index e239d75e8..339baa8be 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -330,10 +330,8 @@ class CI_DB_utility { $prefs = array( 'tables' => array(), 'ignore' => array(), - 'format' => 'gzip', // gzip, zip, txt - 'action' => 'download', // download, archive, echo, return 'filename' => '', - 'filepath' => '', + 'format' => 'gzip', // gzip, zip, txt 'add_drop' => TRUE, 'add_insert' => TRUE, 'newline' => "\n" @@ -385,148 +383,55 @@ class CI_DB_utility { // ------------------------------------------------------ - // Set the filename if not provided - if ($prefs['filename'] == '') + // Set the filename if not provided - Only needed with Zip files + if ($prefs['filename'] == '' AND $prefs['format'] == 'zip') { $prefs['filename'] = (count($prefs['tables']) == 1) ? $prefs['tables'] : $this->db->database; $prefs['filename'] .= '_'.date('Y-m-d_H-i', time()); } // ------------------------------------------------------ - - // If we are archiving the export, does this filepath exist - // and resolve to a writable directory - if ($prefs['action'] == 'archive') + + // Grab the super object + $obj =& get_instance(); + + // Was a Gzip file requested? + if ($prefs['format'] == 'gzip') { - if ($prefs['filepath'] == '' OR ! is_writable($prefs['filepath'])) - { - if ($this->db->db_debug) - { - return $this->db->display_error('db_filepath_error'); - } - - $prefs['action'] = 'download'; - } + return gzencode($this->_backup($prefs)); } // ------------------------------------------------------ - // Are we returning the backup data? If so, we're done... - if ($prefs['action'] == 'return') + // Was a text file requested? + if ($prefs['format'] == 'txt') { return $this->_backup($prefs); } - // ------------------------------------------------------ - - // Are we echoing the backup? If so, format the data and spit it at the screen... - if ($prefs['action'] == 'echo') - { - echo '
';
-			echo htmlspecialchars($this->_backup($prefs));
-			echo '
'; - - return TRUE; - } - // ------------------------------------------------------ - // Are we archiving the data to the server? - if ($prefs['action'] == 'archive') + // Was a Zip file requested? + if ($prefs['format'] == 'zip') { - // Make sure the filepath has a trailing slash - if (ereg("/$", $prefs['filepath']) === FALSE) + // If they included the .zip file extension we'll remove it + if (preg_match("|.+?\.zip$|", $prefs['filename'])) { - $prefs['filepath'] .= '/'; + $prefs['filename'] = str_replace('.zip', '', $prefs['filename']); } - - // Assemble the path and tack on the file extension - $ext = array('gzip' => 'gz', 'zip' => 'zip', 'txt' => 'sql'); - $path = $prefs['filepath'].$prefs['filename'].$ext[$prefs['format']]; - - // Load the file helper - $obj =& get_instance(); - $obj->load->helper('file'); - // Write the file based on type - switch ($prefs['format']) + // Tack on the ".sql" file extension if needed + if ( ! preg_match("|.+?\.sql$|", $prefs['filename'])) { - case 'gzip' : - write_file($path, gzencode($this->_backup($prefs))); - return TRUE; - break; - case 'txt' : - write_file($path, $this->_backup($prefs)); - return TRUE; - break; - default : - $obj->load->library('zip'); - $obj->zip->add_data($prefs['filename'].'.sql', $this->_backup($prefs)); - $obj->zip->archive($path); - return TRUE; - break; + $prefs['filename'] .= '.sql'; } - - } - // ------------------------------------------------------ - - - // Grab the super object - $obj =& get_instance(); - - // Remap the file extensions - $ext = array('gzip' => 'gz', 'zip' => 'zip', 'txt' => 'sql'); - - // Is a Zip file requested? - if ($prefs['format'] == 'zip') - { + // Load the Zip class and output it $obj->load->library('zip'); - $obj->zip->add_data($prefs['filename'].'.sql', $this->_backup($prefs)); - $obj->zip->download($prefs['filename'].'.'.$ext[$prefs['format']]); - return TRUE; + $obj->zip->add_data($prefs['filename'], $this->_backup($prefs)); + return $obj->zip->get_zip(); } - - // Set the mime type - switch ($prefs['format']) - { - case 'gzip' : $mime = 'application/x-gzip'; - break; - default : $mime = (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE") || strstr($_SERVER['HTTP_USER_AGENT'], "OPERA")) ? 'application/octetstream' : 'application/octet-stream'; - break; - } - - $filename = $prefs['filename'].'.sql.'.$ext[$prefs['format']]; - - if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) - { - header('Content-Type: '.$mime); - header('Content-Disposition: inline; filename="'.$filename.'"'); - header('Expires: 0'); - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); - header("Content-Transfer-Encoding: binary"); - header('Pragma: public'); - } - else - { - header('Content-Type: '.$mime); - header('Content-Disposition: attachment; filename="'.$filename.'"'); - header("Content-Transfer-Encoding: binary"); - header('Expires: 0'); - header('Pragma: no-cache'); - } - - // Write the file based on type - switch ($prefs['format']) - { - case 'gzip' : echo gzencode($this->_backup($prefs)); - break; - case 'txt' : echo $this->_backup($prefs); - break; - } - - return TRUE; } -- cgit v1.2.3-24-g4f1b From 3cad41e56fe4edc057cf6a84952a343686376429 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 2 Oct 2006 03:21:46 +0000 Subject: --- system/database/drivers/mssql/mssql_utility.php | 16 +++ system/database/drivers/mysqli/mysqli_utility.php | 131 +++++++++++++++++++++ system/database/drivers/oci8/oci8_result.php | 6 +- system/database/drivers/oci8/oci8_utility.php | 15 +++ system/database/drivers/odbc/odbc_utility.php | 14 +++ .../database/drivers/postgre/postgre_utility.php | 14 +++ system/database/drivers/sqlite/sqlite_utility.php | 14 +++ 7 files changed, 207 insertions(+), 3 deletions(-) (limited to 'system/database') 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'); + } } -- cgit v1.2.3-24-g4f1b From e8f6eb62a0600daf5b192746e1eed3e81516bc92 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 2 Oct 2006 06:46:16 +0000 Subject: --- system/database/DB_cache.php | 32 ++++++++++++ system/database/DB_driver.php | 107 ++++++++++++++++++++++++++++++++++++++--- system/database/DB_utility.php | 8 +-- 3 files changed, 135 insertions(+), 12 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 086958d3d..4721f32c3 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -39,6 +39,38 @@ class CI_DB_cache { // -------------------------------------------------------------------- + + function cache_exists($sql) + { + + + } + + + function get_cache($sql) + { + + + } + + + function delete_cache() + { + + } + + + function delete_all_caches() + { + + + } + + + + + + } ?> \ No newline at end of file diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 81af466ef..73c723d96 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -41,11 +41,13 @@ class CI_DB_driver { var $conn_id = FALSE; var $result_id = FALSE; var $db_debug = FALSE; + var $query_caching = FALSE; + var $cache_dir = ''; var $benchmark = 0; var $query_count = 0; var $bind_marker = '?'; var $queries = array(); - var $cache = array(); + var $data_cache = array(); var $trans_enabled = TRUE; var $_trans_depth = 0; var $_trans_failure = FALSE; // Used with transactions to determine if a rollback should occur @@ -55,6 +57,7 @@ class CI_DB_driver { var $curs_id; var $limit_used; + /** * Constructor. Accepts one parameter containing the database @@ -214,6 +217,21 @@ class CI_DB_driver { return FALSE; } + // Is query caching enabled? If the query is a "read type" we'll + // grab the previously cached query if it exists and return it. + if ($this->query_caching == TRUE) + { + if (stristr($sql, 'SELECT')) + { + $CACHE =& _load_cache_class(); + + if (FALSE !== ($CACHE->cache_exists($sql))) + { + return $CACHE->get_cache($sql); + } + } + } + // Compile binds if needed if ($binds !== FALSE) { @@ -257,7 +275,7 @@ class CI_DB_driver { // Was the query a "write" type? // If so we'll simply return true if ($this->is_write_type($sql) === TRUE) - { + { return TRUE; } @@ -564,9 +582,9 @@ class CI_DB_driver { function list_tables() { // Is there a cached result? - if (isset($this->cache['table_names'])) + if (isset($this->data_cache['table_names'])) { - return $this->cache['table_names']; + return $this->data_cache['table_names']; } if (FALSE === ($sql = $this->_list_tables())) @@ -596,7 +614,7 @@ class CI_DB_driver { } } - return $this->cache['table_names'] =& $retval; + return $this->data_cache['table_names'] =& $retval; } // -------------------------------------------------------------------- @@ -623,9 +641,9 @@ class CI_DB_driver { function list_fields($table = '') { // Is there a cached result? - if (isset($this->cache['field_names'][$table])) + if (isset($this->data_cache['field_names'][$table])) { - return $this->cache['field_names'][$table]; + return $this->data_cache['field_names'][$table]; } if ($table == '') @@ -661,7 +679,7 @@ class CI_DB_driver { } } - return $this->cache['field_names'][$table] =& $retval; + return $this->data_cache['field_names'][$table] =& $retval; } // -------------------------------------------------------------------- @@ -820,6 +838,79 @@ class CI_DB_driver { return call_user_func_array($function, $args); } } + + // -------------------------------------------------------------------- + + /** + * Set Cache Path + * + * @access public + * @param string the path to the cache directory + * @return void + */ + function set_cache_path($path = '') + { + if ( ! is_dir($path) OR ! is_writable($path)) + { + if ($this->db_debug) + { + return $this->display_error('db_invalid_cache_path'); + } + + $this->enable_caching(FALSE); + return FALSE; + } + + $this->cache_dir = $path; + } + + // -------------------------------------------------------------------- + + /** + * Enable Query Caching + * + * @access public + * @return void + */ + function cache_on() + { + $this->query_caching = TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Disable Query Caching + * + * @access public + * @return void + */ + function cache_off() + { + $this->query_caching = FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Load Caching Class + * + * @access private + * @return object + */ + function _load_cache_class() + { + static $CACHE = NULL; + + if (is_object($CACHE)) + { + return $CACHE; + } + + require_once BASEPATH.'database/DB_cache'.EXT; + $CACHE = new DB_cache(); + return $CACHE; + } // -------------------------------------------------------------------- diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 339baa8be..433056ff0 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -25,7 +25,7 @@ class CI_DB_utility { var $db; - var $cache = array(); + var $data_cache = array(); /** * Constructor @@ -95,9 +95,9 @@ class CI_DB_utility { function list_databases() { // Is there a cached result? - if (isset($this->cache['db_names'])) + if (isset($this->data_cache['db_names'])) { - return $this->cache['db_names']; + return $this->data_cache['db_names']; } $query = $this->db->query($this->_list_database()); @@ -110,7 +110,7 @@ class CI_DB_utility { } } - return $this->cache['db_names'] =& $dbs; + return $this->data_cache['db_names'] =& $dbs; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 07ad666409b60610a1e5b07368506f9f0ca45b22 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 3 Oct 2006 06:12:52 +0000 Subject: --- system/database/DB_result.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 32c51e07b..3bd43bac6 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -70,7 +70,7 @@ class CI_DB_result { if (count($this->result_object) == 0) { - return FALSE; + return array(); } return $this->result_object; @@ -98,7 +98,7 @@ class CI_DB_result { if (count($this->result_array) == 0) { - return FALSE; + return array(); } return $this->result_array; -- cgit v1.2.3-24-g4f1b From 6871d95930a148722f2b99fa80ef6dd44f86f078 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 4 Oct 2006 00:36:18 +0000 Subject: --- system/database/DB_driver.php | 390 ++++++++++++++++++++++++++---------------- 1 file changed, 246 insertions(+), 144 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 73c723d96..811f09093 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -41,8 +41,6 @@ class CI_DB_driver { var $conn_id = FALSE; var $result_id = FALSE; var $db_debug = FALSE; - var $query_caching = FALSE; - var $cache_dir = ''; var $benchmark = 0; var $query_count = 0; var $bind_marker = '?'; @@ -51,11 +49,14 @@ class CI_DB_driver { var $trans_enabled = TRUE; var $_trans_depth = 0; var $_trans_failure = FALSE; // Used with transactions to determine if a rollback should occur + var $cache_on = FALSE; + var $cachedir = ''; - // These are use with Oracle - var $stmt_id; - var $curs_id; - var $limit_used; + + // These are use with Oracle + var $stmt_id; + var $curs_id; + var $limit_used; @@ -86,10 +87,24 @@ class CI_DB_driver { * @return void */ function initialize($params = '') - { + { if (is_array($params)) { - foreach (array('hostname' => '', 'username' => '', 'password' => '', 'database' => '', 'dbdriver' => 'mysql', 'dbprefix' => '', 'port' => '', 'pconnect' => FALSE, 'db_debug' => FALSE) as $key => $val) + $defaults = array( + 'hostname' => '', + 'username' => '', + 'password' => '', + 'database' => '', + 'dbdriver' => 'mysql', + 'dbprefix' => '', + 'port' => '', + 'pconnect' => FALSE, + 'db_debug' => FALSE, + 'cachedir' => '', + 'cache_on' => FALSE + ); + + foreach ($defaults as $key => $val) { $this->$key = ( ! isset($params[$key])) ? $val : $params[$key]; } @@ -112,25 +127,19 @@ class CI_DB_driver { $this->password = ( ! isset($dsn['pass'])) ? '' : rawurldecode($dsn['pass']); $this->database = ( ! isset($dsn['path'])) ? '' : rawurldecode(substr($dsn['path'], 1)); } - - if ($this->pconnect == FALSE) - { - $this->conn_id = $this->db_connect(); - } - else - { - $this->conn_id = $this->db_pconnect(); - } - - if ( ! $this->conn_id) - { + + // Connect to the database + $this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect(); + + if ( ! $this->conn_id) + { log_message('error', 'Unable to connect to the database'); - if ($this->db_debug) - { + if ($this->db_debug) + { $this->display_error('db_unable_to_connect'); - } - } + } + } else { if ( ! $this->db_select()) @@ -142,7 +151,13 @@ class CI_DB_driver { $this->display_error('db_unable_to_select', $this->database); } } - } + } + + // Is there a cache direcotry specified in the config file? + if ($this->cachedir != '') + { + $this->cache_set_dir($this->cachedir); + } } @@ -172,15 +187,15 @@ class CI_DB_driver { { if (FALSE === ($sql = $this->_version())) { - if ($this->db_debug) - { + if ($this->db_debug) + { return $this->display_error('db_unsupported_function'); - } - return FALSE; + } + return FALSE; } - if ($this->dbdriver == 'oci8') - { + if ($this->dbdriver == 'oci8') + { return $sql; } @@ -205,30 +220,25 @@ class CI_DB_driver { * @param array An array of binding data * @return mixed */ - function query($sql, $binds = FALSE, $return_object = TRUE) - { + function query($sql, $binds = FALSE, $return_object = TRUE) + { if ($sql == '') { - if ($this->db_debug) - { + if ($this->db_debug) + { log_message('error', 'Invalid query: '.$sql); return $this->display_error('db_invalid_query'); - } - return FALSE; + } + return FALSE; } - // Is query caching enabled? If the query is a "read type" we'll + // Is query caching enabled? If the query is a "read type" we will // grab the previously cached query if it exists and return it. - if ($this->query_caching == TRUE) - { - if (stristr($sql, 'SELECT')) + if ($this->cache_on == TRUE AND stristr($sql, 'SELECT')) + { + if (FALSE !== ($cache = $this->cache_read($sql))) { - $CACHE =& _load_cache_class(); - - if (FALSE !== ($CACHE->cache_exists($sql))) - { - return $CACHE->get_cache($sql); - } + return $cache; } } @@ -238,20 +248,20 @@ class CI_DB_driver { $sql = $this->compile_binds($sql, $binds); } - // Save the query for debugging - $this->queries[] = $sql; + // Save the query for debugging + $this->queries[] = $sql; // Start the Query Timer - $time_start = list($sm, $ss) = explode(' ', microtime()); - + $time_start = list($sm, $ss) = explode(' ', microtime()); + // Run the Query - if (FALSE === ($this->result_id = $this->simple_query($sql))) - { - // This will trigger a rollback if transactions are being used - $this->_trans_failure = TRUE; - - if ($this->db_debug) - { + if (FALSE === ($this->result_id = $this->simple_query($sql))) + { + // This will trigger a rollback if transactions are being used + $this->_trans_failure = TRUE; + + if ($this->db_debug) + { log_message('error', 'Query error: '.$this->_error_message()); return $this->display_error( array( @@ -260,18 +270,18 @@ class CI_DB_driver { $sql ) ); - } - - return FALSE; - } - + } + + return FALSE; + } + // Stop and aggregate the query time results $time_end = list($em, $es) = explode(' ', microtime()); $this->benchmark += ($em + $es) - ($sm + $ss); // Increment the query counter - $this->query_count++; - + $this->query_count++; + // Was the query a "write" type? // If so we'll simply return true if ($this->is_write_type($sql) === TRUE) @@ -298,17 +308,17 @@ class CI_DB_driver { } // Instantiate the result object - $RES = new $result(); - $RES->conn_id = $this->conn_id; - $RES->db_debug = $this->db_debug; - $RES->result_id = $this->result_id; - - if ($this->dbdriver == 'oci8') - { + $RES = new $result(); + $RES->conn_id = $this->conn_id; + $RES->db_debug = $this->db_debug; + $RES->result_id = $this->result_id; + + if ($this->dbdriver == 'oci8') + { $RES->stmt_id = $this->stmt_id; $RES->curs_id = NULL; $RES->limit_used = $this->limit_used; - } + } return $RES; } @@ -589,11 +599,11 @@ class CI_DB_driver { if (FALSE === ($sql = $this->_list_tables())) { - if ($this->db_debug) - { + if ($this->db_debug) + { return $this->display_error('db_unsupported_function'); - } - return FALSE; + } + return FALSE; } $retval = array(); @@ -638,35 +648,35 @@ class CI_DB_driver { * @param string the table name * @return array */ - function list_fields($table = '') - { + function list_fields($table = '') + { // Is there a cached result? if (isset($this->data_cache['field_names'][$table])) { return $this->data_cache['field_names'][$table]; } - - if ($table == '') - { + + if ($table == '') + { if ($this->db_debug) { return $this->display_error('db_field_param_missing'); } return FALSE; - } - + } + if (FALSE === ($sql = $this->_list_columns($this->dbprefix.$table))) { - if ($this->db_debug) - { + if ($this->db_debug) + { return $this->display_error('db_unsupported_function'); - } - return FALSE; + } + return FALSE; } - - $query = $this->query($sql); - - $retval = array(); + + $query = $this->query($sql); + + $retval = array(); foreach($query->result_array() as $row) { if (isset($row['COLUMN_NAME'])) @@ -676,11 +686,11 @@ class CI_DB_driver { else { $retval[] = current($row); - } + } } - + return $this->data_cache['field_names'][$table] =& $retval; - } + } // -------------------------------------------------------------------- @@ -695,16 +705,16 @@ class CI_DB_driver { { return ( ! in_array($field_name, $this->list_fields($table_name))) ? FALSE : TRUE; } - + // -------------------------------------------------------------------- /** * DEPRECATED - use list_fields() */ - function field_names($table = '') - { - return $this->list_fields($table); - } + function field_names($table = '') + { + return $this->list_fields($table); + } // -------------------------------------------------------------------- @@ -717,15 +727,15 @@ class CI_DB_driver { */ function field_data($table = '') { - if ($table == '') - { + if ($table == '') + { if ($this->db_debug) { return $this->display_error('db_field_param_missing'); } return FALSE; - } - + } + $query = $this->query($this->_field_data($this->dbprefix.$table)); return $query->field_data(); } @@ -742,7 +752,7 @@ class CI_DB_driver { */ function insert_string($table, $data) { - $fields = array(); + $fields = array(); $values = array(); foreach($data as $key => $val) @@ -802,7 +812,7 @@ class CI_DB_driver { } return $this->_update($this->dbprefix.$table, $fields, $dest); - } + } // -------------------------------------------------------------------- @@ -838,18 +848,47 @@ class CI_DB_driver { return call_user_func_array($function, $args); } } + + // -------------------------------------------------------------------- + + /** + * Enable Query Caching + * + * @access public + * @return void + */ + function cache_on() + { + $this->query_caching = TRUE; + } // -------------------------------------------------------------------- /** - * Set Cache Path + * Disable Query Caching + * + * @access public + * @return void + */ + function cache_off() + { + $this->query_caching = FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Set Cache Directory Path * * @access public * @param string the path to the cache directory * @return void */ - function set_cache_path($path = '') + function cache_set_dir($path = '') { + // Add a trailing slash to the path if needed + $path = preg_replace("/(.+?)\/*$/", "\\1/", $path); + if ( ! is_dir($path) OR ! is_writable($path)) { if ($this->db_debug) @@ -860,58 +899,121 @@ class CI_DB_driver { $this->enable_caching(FALSE); return FALSE; } - + $this->cache_dir = $path; } // -------------------------------------------------------------------- /** - * Enable Query Caching + * Set Cache Path * * @access public + * @param string the path to the cache directory * @return void - */ - function cache_on() + */ + function cache_set_path($sql) { - $this->query_caching = TRUE; + $obj =& get_instance(); + + // The URI being requested will become the name of the cache sub-folder + + $uri = ($obj->uri->uri_string() == '') ? 'index' : $obj->uri->uri_string(); + + // Convert the SQL query into a hash. This will become the cache file name. + + return md5($uri).'/'.md5($sql); } - + // -------------------------------------------------------------------- /** - * Disable Query Caching + * Retreive a cached query * * @access public - * @return void - */ - function cache_off() - { - $this->query_caching = FALSE; - } + * @return string + */ + function cache_read($sql) + { + if ( ! @is_dir($this->cache_dir)) + { + return $this->cache_on = FALSE; + } + + $filepath = $this->cache_set_path($sql); + + if ( ! @file_exists($this->cache_dir.$filepath)) + { + return FALSE; + } + + if ( ! $fp = @fopen($this->cache_dir.$filepath, 'rb')) + { + return FALSE; + } + + $cachedata = file_get_contents($this->cache_dir.$filepath); + + if ( ! is_string($cachedata)) + { + return FALSE; + } + + return unserialize($cachedata); + } // -------------------------------------------------------------------- /** - * Load Caching Class - * - * @access private - * @return object - */ - function _load_cache_class() + * Write a query to a cache file + * + * @access public + * @return bool + */ + function cache_write($sql, $object) { - static $CACHE = NULL; - - if (is_object($CACHE)) + if ( ! @is_dir($this->cache_dir)) { - return $CACHE; + return $this->cache_on = FALSE; } - require_once BASEPATH.'database/DB_cache'.EXT; - $CACHE = new DB_cache(); - return $CACHE; - } + $filepath = $this->cache_set_path($sql); + + + + + + $dirs = array(PATH_CACHE.'db_cache', substr($this->cache_dir, 0, -1)); + + foreach ($dirs as $dir) + { + if ( ! @is_dir($dir)) + { + if ( ! @mkdir($dir, 0777)) + { + return; + } + + @chmod($dir, 0777); + } + } + + if ( ! $fp = @fopen($this->cache_dir.$this->cache_file, 'wb')) + { + return FALSE; + } + + flock($fp, LOCK_EX); + fwrite($fp, $object); + flock($fp, LOCK_UN); + fclose($fp); + + @chmod($this->cache_dir.$this->cache_file, 0777); + + return TRUE; + } + // -------------------------------------------------------------------- /** @@ -920,14 +1022,14 @@ class CI_DB_driver { * @access public * @return void */ - function close() - { - if (is_resource($this->conn_id)) - { - $this->_close($this->conn_id); + function close() + { + if (is_resource($this->conn_id)) + { + $this->_close($this->conn_id); } $this->conn_id = FALSE; - } + } // -------------------------------------------------------------------- @@ -940,8 +1042,8 @@ class CI_DB_driver { * @param boolean whether to localize the message * @return string sends the application/errror_db.php template */ - function display_error($error = '', $swap = '', $native = FALSE) - { + function display_error($error = '', $swap = '', $native = FALSE) + { $LANG = new CI_Language(); $LANG->load('db'); @@ -965,7 +1067,7 @@ class CI_DB_driver { echo $error->show_error('An Error Was Encountered', $message, 'error_db'); exit; - } + } } -- cgit v1.2.3-24-g4f1b From db8a3744e2c40b57aa8d128e0293d098021c69b1 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 4 Oct 2006 07:43:35 +0000 Subject: --- system/database/DB_driver.php | 213 +++++++++++++++++++++++++----------------- 1 file changed, 125 insertions(+), 88 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 811f09093..a7a89a953 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -156,7 +156,7 @@ class CI_DB_driver { // Is there a cache direcotry specified in the config file? if ($this->cachedir != '') { - $this->cache_set_dir($this->cachedir); + $this->cache_set_path($this->cachedir); } } @@ -221,7 +221,7 @@ class CI_DB_driver { * @return mixed */ function query($sql, $binds = FALSE, $return_object = TRUE) - { + { if ($sql == '') { if ($this->db_debug) @@ -235,7 +235,7 @@ class CI_DB_driver { // Is query caching enabled? If the query is a "read type" we will // grab the previously cached query if it exists and return it. if ($this->cache_on == TRUE AND stristr($sql, 'SELECT')) - { + { if (FALSE !== ($cache = $this->cache_read($sql))) { return $cache; @@ -285,7 +285,15 @@ class CI_DB_driver { // Was the query a "write" type? // If so we'll simply return true if ($this->is_write_type($sql) === TRUE) - { + { + // If caching is enabled we'll auto-cleanup any + // existing files related to this particular URI + + if ($this->cache_on == TRUE) + { + $this->cache_delete(); + } + return TRUE; } @@ -296,19 +304,12 @@ class CI_DB_driver { { return TRUE; } - - // Define the result driver name - $result = 'CI_DB_'.$this->dbdriver.'_result'; - - // Load the result classes - if ( ! class_exists($result)) - { - include_once(BASEPATH.'database/DB_result'.EXT); - include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result'.EXT); - } + + // Load and instantiate the result driver - // Instantiate the result object - $RES = new $result(); + $driver = $this->load_rdriver(); + + $RES = new $driver(); $RES->conn_id = $this->conn_id; $RES->db_debug = $this->db_debug; $RES->result_id = $this->result_id; @@ -319,9 +320,37 @@ class CI_DB_driver { $RES->curs_id = NULL; $RES->limit_used = $this->limit_used; } - + + // Is query caching enabled? If so, we'll serialize the + // result object and save it to a cache file + if ($this->cache_on == TRUE) + { + $this->cache_write($sql, $RES); + } + return $RES; } + + // -------------------------------------------------------------------- + + /** + * Load the result drivers + * + * @access public + * @return string the name of the result class + */ + function load_rdriver() + { + $driver = 'CI_DB_'.$this->dbdriver.'_result'; + + if ( ! class_exists($driver)) + { + include_once(BASEPATH.'database/DB_result'.EXT); + include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result'.EXT); + } + + return $driver; + } // -------------------------------------------------------------------- @@ -859,7 +888,7 @@ class CI_DB_driver { */ function cache_on() { - $this->query_caching = TRUE; + return $this->query_caching = TRUE; } // -------------------------------------------------------------------- @@ -872,7 +901,7 @@ class CI_DB_driver { */ function cache_off() { - $this->query_caching = FALSE; + return $this->query_caching = FALSE; } // -------------------------------------------------------------------- @@ -882,10 +911,15 @@ class CI_DB_driver { * * @access public * @param string the path to the cache directory - * @return void + * @return bool */ - function cache_set_dir($path = '') + function cache_set_path($path = '') { + if ($path == '') + { + return $this->cache_off(); + } + // Add a trailing slash to the path if needed $path = preg_replace("/(.+?)\/*$/", "\\1/", $path); @@ -896,33 +930,12 @@ class CI_DB_driver { return $this->display_error('db_invalid_cache_path'); } - $this->enable_caching(FALSE); - return FALSE; + // If the path is wrong we'll turn off caching + return $this->cache_off(); } $this->cache_dir = $path; - } - - // -------------------------------------------------------------------- - - /** - * Set Cache Path - * - * @access public - * @param string the path to the cache directory - * @return void - */ - function cache_set_path($sql) - { - $obj =& get_instance(); - - // The URI being requested will become the name of the cache sub-folder - - $uri = ($obj->uri->uri_string() == '') ? 'index' : $obj->uri->uri_string(); - - // Convert the SQL query into a hash. This will become the cache file name. - - return md5($uri).'/'.md5($sql); + return TRUE; } // -------------------------------------------------------------------- @@ -930,31 +943,27 @@ class CI_DB_driver { /** * Retreive a cached query * + * The URI being requested will become the name of the cache sub-folder. + * An MD5 hash of the SQL statement will become the cache file name + * * @access public * @return string */ function cache_read($sql) - { - if ( ! @is_dir($this->cache_dir)) + { + if ( ! $this->cache_set_path($this->cache_dir)) { - return $this->cache_on = FALSE; + return $this->cache_off(); } - $filepath = $this->cache_set_path($sql); - - if ( ! @file_exists($this->cache_dir.$filepath)) - { - return FALSE; - } + $obj =& get_instance(); + $uri = ($obj->uri->segment(1) == FALSE) ? 'base' : $obj->uri->segment(2); + $uri .= ($obj->uri->segment(2) == FALSE) ? 'index' : $obj->uri->segment(2); - if ( ! $fp = @fopen($this->cache_dir.$filepath, 'rb')) - { - return FALSE; - } - - $cachedata = file_get_contents($this->cache_dir.$filepath); + $filepath = md5($uri).'/'.md5($sql); - if ( ! is_string($cachedata)) + $obj->load->helper('file'); + if (FALSE === ($cachedata = read_file($this->cache_dir.$filepath))) { return FALSE; } @@ -972,46 +981,74 @@ class CI_DB_driver { */ function cache_write($sql, $object) { - if ( ! @is_dir($this->cache_dir)) + if ( ! $this->cache_set_path($this->cache_dir)) { - return $this->cache_on = FALSE; + return $this->cache_off(); } - - $filepath = $this->cache_set_path($sql); - - - + + $obj =& get_instance(); + $uri = ($obj->uri->segment(1) == FALSE) ? 'base' : $obj->uri->segment(2); + $uri .= ($obj->uri->segment(2) == FALSE) ? 'index' : $obj->uri->segment(2); - - - $dirs = array(PATH_CACHE.'db_cache', substr($this->cache_dir, 0, -1)); + $dir_path = $this->cache_dir.md5($uri).'/'; - foreach ($dirs as $dir) - { - if ( ! @is_dir($dir)) + $filename = md5($sql); + + if ( ! @is_dir($dir_path)) + { + if ( ! @mkdir($dir_path, 0777)) { - if ( ! @mkdir($dir, 0777)) - { - return; - } - - @chmod($dir, 0777); + return FALSE; } + + @chmod($dir_path, 0777); } - - if ( ! $fp = @fopen($this->cache_dir.$this->cache_file, 'wb')) + + $obj->load->helper('file'); + if (write_file($dir_path.$filename, serialize($object)) === FALSE) { return FALSE; } - flock($fp, LOCK_EX); - fwrite($fp, $object); - flock($fp, LOCK_UN); - fclose($fp); + @chmod($dir_path.$filename, 0777); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Delete cache files within a particular directory + * + * @access public + * @return bool + */ + function cache_delete() + { + $obj =& get_instance(); + $uri = ($obj->uri->segment(1) == FALSE) ? 'base' : $obj->uri->segment(2); + $uri .= ($obj->uri->segment(2) == FALSE) ? 'index' : $obj->uri->segment(2); + + $dir_path = $this->cache_dir.md5($uri).'/'; - @chmod($this->cache_dir.$this->cache_file, 0777); + $obj->load->helper('file'); + delete_files($dir_path, TRUE); + } - return TRUE; + // -------------------------------------------------------------------- + + /** + * Delete all existing cache files + * + * @access public + * @return bool + */ + // -------------------------------------------------------------------- + + function cache_delete_all() + { + $obj =& get_instance(); + $obj->load->helper('file'); + delete_files($this->cache_dir, TRUE); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 194b894c33eb812f84862b53691eb5de304455bb Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 4 Oct 2006 07:59:32 +0000 Subject: --- system/database/DB_cache.php | 76 -------------------------------------------- 1 file changed, 76 deletions(-) delete mode 100644 system/database/DB_cache.php (limited to 'system/database') diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php deleted file mode 100644 index 4721f32c3..000000000 --- a/system/database/DB_cache.php +++ /dev/null @@ -1,76 +0,0 @@ - \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 0c40565cbbf0218ad6927cbcbc80daf6aefc4377 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 4 Oct 2006 18:37:57 +0000 Subject: --- system/database/DB_driver.php | 170 +++++++----------------------------------- 1 file changed, 25 insertions(+), 145 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index a7a89a953..24707aaca 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -51,6 +51,7 @@ class CI_DB_driver { var $_trans_failure = FALSE; // Used with transactions to determine if a rollback should occur var $cache_on = FALSE; var $cachedir = ''; + var $cache; // The cache class object // These are use with Oracle @@ -152,12 +153,6 @@ class CI_DB_driver { } } } - - // Is there a cache direcotry specified in the config file? - if ($this->cachedir != '') - { - $this->cache_set_path($this->cachedir); - } } @@ -232,13 +227,17 @@ class CI_DB_driver { return FALSE; } - // Is query caching enabled? If the query is a "read type" we will - // grab the previously cached query if it exists and return it. + // Is query caching enabled? If the query is a "read type" + // we will load the caching class and return the previously + // cached query if it exists if ($this->cache_on == TRUE AND stristr($sql, 'SELECT')) - { - if (FALSE !== ($cache = $this->cache_read($sql))) + { + if ($this->_cache_init()) { - return $cache; + if (FALSE !== ($cache = $this->cache->read($sql))) + { + return $cache; + } } } @@ -289,9 +288,9 @@ class CI_DB_driver { // If caching is enabled we'll auto-cleanup any // existing files related to this particular URI - if ($this->cache_on == TRUE) + if ($this->cache_on == TRUE AND $this->_cache_init()) { - $this->cache_delete(); + $this->cache->delete(); } return TRUE; @@ -323,9 +322,9 @@ class CI_DB_driver { // Is query caching enabled? If so, we'll serialize the // result object and save it to a cache file - if ($this->cache_on == TRUE) + if ($this->cache_on == TRUE AND $this->_cache_init()) { - $this->cache_write($sql, $RES); + $this->cache->write($sql, $RES); } return $RES; @@ -903,153 +902,34 @@ class CI_DB_driver { { return $this->query_caching = FALSE; } - - // -------------------------------------------------------------------- - - /** - * Set Cache Directory Path - * - * @access public - * @param string the path to the cache directory - * @return bool - */ - function cache_set_path($path = '') - { - if ($path == '') - { - return $this->cache_off(); - } - - // Add a trailing slash to the path if needed - $path = preg_replace("/(.+?)\/*$/", "\\1/", $path); - - if ( ! is_dir($path) OR ! is_writable($path)) - { - if ($this->db_debug) - { - return $this->display_error('db_invalid_cache_path'); - } - - // If the path is wrong we'll turn off caching - return $this->cache_off(); - } - - $this->cache_dir = $path; - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Retreive a cached query - * - * The URI being requested will become the name of the cache sub-folder. - * An MD5 hash of the SQL statement will become the cache file name - * - * @access public - * @return string - */ - function cache_read($sql) - { - if ( ! $this->cache_set_path($this->cache_dir)) - { - return $this->cache_off(); - } - - $obj =& get_instance(); - $uri = ($obj->uri->segment(1) == FALSE) ? 'base' : $obj->uri->segment(2); - $uri .= ($obj->uri->segment(2) == FALSE) ? 'index' : $obj->uri->segment(2); - - $filepath = md5($uri).'/'.md5($sql); - - $obj->load->helper('file'); - if (FALSE === ($cachedata = read_file($this->cache_dir.$filepath))) - { - return FALSE; - } - - return unserialize($cachedata); - } // -------------------------------------------------------------------- /** - * Write a query to a cache file + * Initialize the Cache Class * - * @access public - * @return bool - */ - function cache_write($sql, $object) + * @access private + * @return void + */ + function _cache_init() { - if ( ! $this->cache_set_path($this->cache_dir)) + if (is_object($this->cache)) { - return $this->cache_off(); + return TRUE; } - - $obj =& get_instance(); - $uri = ($obj->uri->segment(1) == FALSE) ? 'base' : $obj->uri->segment(2); - $uri .= ($obj->uri->segment(2) == FALSE) ? 'index' : $obj->uri->segment(2); - - $dir_path = $this->cache_dir.md5($uri).'/'; - - $filename = md5($sql); - if ( ! @is_dir($dir_path)) + if ( ! class_exists('CI_DB_Cache')) { - if ( ! @mkdir($dir_path, 0777)) + if ( ! @include_once(BASEPATH.'database/DB_cache'.EXT)) { - return FALSE; + return $this->cache_off(); } - - @chmod($dir_path, 0777); } - $obj->load->helper('file'); - if (write_file($dir_path.$filename, serialize($object)) === FALSE) - { - return FALSE; - } - - @chmod($dir_path.$filename, 0777); + $this->cache = new CI_DB_Cache; return TRUE; } - // -------------------------------------------------------------------- - - /** - * Delete cache files within a particular directory - * - * @access public - * @return bool - */ - function cache_delete() - { - $obj =& get_instance(); - $uri = ($obj->uri->segment(1) == FALSE) ? 'base' : $obj->uri->segment(2); - $uri .= ($obj->uri->segment(2) == FALSE) ? 'index' : $obj->uri->segment(2); - - $dir_path = $this->cache_dir.md5($uri).'/'; - - $obj->load->helper('file'); - delete_files($dir_path, TRUE); - } - - // -------------------------------------------------------------------- - - /** - * Delete all existing cache files - * - * @access public - * @return bool - */ - // -------------------------------------------------------------------- - - function cache_delete_all() - { - $obj =& get_instance(); - $obj->load->helper('file'); - delete_files($this->cache_dir, TRUE); - } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From fa708175d3b3932e67af04858b841eb881c9579b Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 4 Oct 2006 18:42:42 +0000 Subject: --- system/database/DB_driver.php | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 24707aaca..39577ca83 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -902,6 +902,20 @@ class CI_DB_driver { { return $this->query_caching = FALSE; } + + // -------------------------------------------------------------------- + + /** + * Set Cache Directory Path + * + * @access public + * @param string the path to the cache directory + * @return void + */ + function cache_set_path($path = '') + { + $this->cachedir = $path; + } // -------------------------------------------------------------------- @@ -913,17 +927,14 @@ class CI_DB_driver { */ function _cache_init() { - if (is_object($this->cache)) + if (is_object($this->cache) AND class_exists('CI_DB_Cache')) { return TRUE; } - if ( ! class_exists('CI_DB_Cache')) + if ( ! @include_once(BASEPATH.'database/DB_cache'.EXT)) { - if ( ! @include_once(BASEPATH.'database/DB_cache'.EXT)) - { - return $this->cache_off(); - } + return $this->cache_off(); } $this->cache = new CI_DB_Cache; -- cgit v1.2.3-24-g4f1b From 7e75a7e0c73381072766b52b49240e3aac9bec18 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 4 Oct 2006 18:43:24 +0000 Subject: --- system/database/DB_cache.php | 187 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 187 insertions(+) create mode 100644 system/database/DB_cache.php (limited to 'system/database') diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php new file mode 100644 index 000000000..135be3ce9 --- /dev/null +++ b/system/database/DB_cache.php @@ -0,0 +1,187 @@ +obj + // and load the file helper since we use it a lot + $this->obj =& get_instance(); + $this->obj->load->helper('file'); + } + + // -------------------------------------------------------------------- + + /** + * Set Cache Directory Path + * + * @access public + * @param string the path to the cache directory + * @return bool + */ + function check_path($path = '') + { + if ($path == '') + { + if ($this->obj->db->cachedir == '') + { + return $this->obj->db->cache_off(); + } + + $path = $this->obj->db->cachedir; + } + + // Add a trailing slash to the path if needed + $path = preg_replace("/(.+?)\/*$/", "\\1/", $path); + + if ( ! is_dir($path) OR ! is_writable($path)) + { + if ($this->obj->db->db_debug) + { + return $this->obj->db->display_error('db_invalid_cache_path'); + } + + // If the path is wrong we'll turn off caching + return $this->obj->db->cache_off(); + } + + $this->obj->db->cachedir = $path; + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Retreive a cached query + * + * The URI being requested will become the name of the cache sub-folder. + * An MD5 hash of the SQL statement will become the cache file name + * + * @access public + * @return string + */ + function read($sql) + { + if ( ! $this->check_path()) + { + return $this->obj->db->cache_off(); + } + + $uri = ($this->obj->uri->segment(1) == FALSE) ? 'base' : $this->obj->uri->segment(2); + $uri .= ($this->obj->uri->segment(2) == FALSE) ? 'index' : $this->obj->uri->segment(2); + + $filepath = md5($uri).'/'.md5($sql); + + if (FALSE === ($cachedata = read_file($this->obj->db->cachedir.$filepath))) + { + return FALSE; + } + + return unserialize($cachedata); + } + + // -------------------------------------------------------------------- + + /** + * Write a query to a cache file + * + * @access public + * @return bool + */ + function write($sql, $object) + { + if ( ! $this->check_path()) + { + return $this->obj->db->cache_off(); + } + + $uri = ($this->obj->uri->segment(1) == FALSE) ? 'base' : $this->obj->uri->segment(2); + $uri .= ($this->obj->uri->segment(2) == FALSE) ? 'index' : $this->obj->uri->segment(2); + + $dir_path = $this->obj->db->cachedir.md5($uri).'/'; + + $filename = md5($sql); + + if ( ! @is_dir($dir_path)) + { + if ( ! @mkdir($dir_path, 0777)) + { + return FALSE; + } + + @chmod($dir_path, 0777); + } + + if (write_file($dir_path.$filename, serialize($object)) === FALSE) + { + return FALSE; + } + + @chmod($dir_path.$filename, 0777); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Delete cache files within a particular directory + * + * @access public + * @return bool + */ + function delete() + { + $uri = ($this->obj->uri->segment(1) == FALSE) ? 'base' : $this->obj->uri->segment(2); + $uri .= ($this->obj->uri->segment(2) == FALSE) ? 'index' : $this->obj->uri->segment(2); + + $dir_path = $this->obj->db->cachedir.md5($uri).'/'; + + delete_files($dir_path, TRUE); + } + + // -------------------------------------------------------------------- + + /** + * Delete all existing cache files + * + * @access public + * @return bool + */ + function delete_all() + { + delete_files($this->obj->db->cachedir, TRUE); + } + +} + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c2e3cd76579dd32b434a75287611985acea770bc Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 5 Oct 2006 04:22:30 +0000 Subject: --- system/database/DB_driver.php | 44 +++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 39577ca83..403255799 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -51,7 +51,7 @@ class CI_DB_driver { var $_trans_failure = FALSE; // Used with transactions to determine if a rollback should occur var $cache_on = FALSE; var $cachedir = ''; - var $cache; // The cache class object + var $CACHE; // The cache class object // These are use with Oracle @@ -234,7 +234,7 @@ class CI_DB_driver { { if ($this->_cache_init()) { - if (FALSE !== ($cache = $this->cache->read($sql))) + if (FALSE !== ($cache = $this->CACHE->read($sql))) { return $cache; } @@ -287,10 +287,9 @@ class CI_DB_driver { { // If caching is enabled we'll auto-cleanup any // existing files related to this particular URI - if ($this->cache_on == TRUE AND $this->_cache_init()) { - $this->cache->delete(); + $this->CACHE->delete(); } return TRUE; @@ -305,26 +304,35 @@ class CI_DB_driver { } // Load and instantiate the result driver - - $driver = $this->load_rdriver(); - $RES = new $driver(); + $driver = $this->load_rdriver(); + $RES = new $driver(); $RES->conn_id = $this->conn_id; - $RES->db_debug = $this->db_debug; $RES->result_id = $this->result_id; if ($this->dbdriver == 'oci8') { - $RES->stmt_id = $this->stmt_id; - $RES->curs_id = NULL; - $RES->limit_used = $this->limit_used; + $RES->stmt_id = $this->stmt_id; + $RES->curs_id = NULL; + $RES->limit_used = $this->limit_used; } // Is query caching enabled? If so, we'll serialize the - // result object and save it to a cache file + // result object and save it to a cache file. if ($this->cache_on == TRUE AND $this->_cache_init()) - { - $this->cache->write($sql, $RES); + { + // We'll create a new instance of the result object + // only without the platform specific driver since + // we can't use it with cached data (the query result + // resource ID won't be any good once we've cached the + // result object, so we'll have to compile the data + // and save it) + $CR = new CI_DB_result(); + $CR->num_rows = $RES->num_rows(); + $CR->result_object = $RES->result_object(); + $CR->result_array = $RES->result_array(); + + $this->CACHE->write($sql, $CR); } return $RES; @@ -887,7 +895,7 @@ class CI_DB_driver { */ function cache_on() { - return $this->query_caching = TRUE; + return $this->cache_on = TRUE; } // -------------------------------------------------------------------- @@ -900,7 +908,7 @@ class CI_DB_driver { */ function cache_off() { - return $this->query_caching = FALSE; + return $this->cache_on = FALSE; } // -------------------------------------------------------------------- @@ -927,7 +935,7 @@ class CI_DB_driver { */ function _cache_init() { - if (is_object($this->cache) AND class_exists('CI_DB_Cache')) + if (is_object($this->CACHE) AND class_exists('CI_DB_Cache')) { return TRUE; } @@ -937,7 +945,7 @@ class CI_DB_driver { return $this->cache_off(); } - $this->cache = new CI_DB_Cache; + $this->CACHE = new CI_DB_Cache; return TRUE; } -- cgit v1.2.3-24-g4f1b From af644691beae3cbfb3598238d129196da4c7e5bb Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 5 Oct 2006 04:22:41 +0000 Subject: --- system/database/DB_result.php | 133 ++++++++++++++++++++++++++++++------------ 1 file changed, 95 insertions(+), 38 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 3bd43bac6..766a2e380 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -30,10 +30,10 @@ class CI_DB_result { var $conn_id = FALSE; var $result_id = FALSE; - var $db_debug = FALSE; var $result_array = array(); var $result_object = array(); var $current_row = 0; + var $num_rows = 0; /** @@ -44,7 +44,7 @@ class CI_DB_result { * @return mixed either a result object or array */ function result($type = 'object') - { + { return ($type == 'object') ? $this->result_object() : $this->result_array(); } @@ -62,20 +62,16 @@ class CI_DB_result { { return $this->result_object; } - + + $this->_data_seek(0); while ($row = $this->_fetch_object()) - { + { $this->result_object[] = $row; } - if (count($this->result_object) == 0) - { - return array(); - } - return $this->result_object; } - + // -------------------------------------------------------------------- /** @@ -90,17 +86,13 @@ class CI_DB_result { { return $this->result_array; } - + + $this->_data_seek(0); while ($row = $this->_fetch_assoc()) { $this->result_array[] = $row; } - if (count($this->result_array) == 0) - { - return array(); - } - return $this->result_array; } @@ -128,16 +120,18 @@ class CI_DB_result { */ function row_object($n = 0) { - if (FALSE === ($result = $this->result_object())) + $result = $this->result_object(); + + if (count($result) == 0) { - return FALSE; + return $result; } - + if ($n != $this->current_row AND isset($result[$n])) { $this->current_row = $n; } - + return $result[$this->current_row]; } @@ -151,9 +145,11 @@ class CI_DB_result { */ function row_array($n = 0) { - if (FALSE === ($result = $this->result_array())) + $result = $this->result_array(); + + if (count($result) == 0) { - return FALSE; + return $result; } if ($n != $this->current_row AND isset($result[$n])) @@ -175,9 +171,11 @@ class CI_DB_result { */ function first_row($type = 'object') { - if (FALSE === ($result = $this->result($type))) + $result = $this->result($type); + + if (count($result) == 0) { - return FALSE; + return $result; } return $result[0]; } @@ -192,9 +190,11 @@ class CI_DB_result { */ function last_row($type = 'object') { - if (FALSE === ($result = $this->result($type))) + $result = $this->result($type); + + if (count($result) == 0) { - return FALSE; + return $result; } return $result[count($result) -1]; } @@ -209,9 +209,11 @@ class CI_DB_result { */ function next_row($type = 'object') { - if (FALSE === ($result = $this->result($type))) + $result = $this->result($type); + + if (count($result) == 0) { - return FALSE; + return $result; } if (isset($result[$this->current_row + 1])) @@ -232,9 +234,11 @@ class CI_DB_result { */ function previous_row($type = 'object') { - if (FALSE === ($result = $this->result($type))) + $result = $this->result($type); + + if (count($result) == 0) { - return FALSE; + return $result; } if (isset($result[$this->current_row - 1])) @@ -254,7 +258,7 @@ class CI_DB_result { */ function num_rows() { - // Implemented in the platform-specific result adapter + return $this->num_rows; } // -------------------------------------------------------------------- @@ -267,9 +271,9 @@ class CI_DB_result { */ function num_fields() { - // Implemented in the platform-specific result adapter + return 0; } - + // -------------------------------------------------------------------- /** @@ -281,8 +285,8 @@ class CI_DB_result { * @return array */ function field_names() - { - // Implemented in the platform-specific result adapter + { + return array(); } // -------------------------------------------------------------------- @@ -297,9 +301,16 @@ class CI_DB_result { */ function field_data() { - // Implemented in the platform-specific result adapter + $F = new stdClass(); + $F->name = NULL; + $F->type = NULL; + $F->default = NULL; + $F->max_length = NULL; + $F->primary_key = NULL; + + return $retval[] = $F; } - + // -------------------------------------------------------------------- /** @@ -309,9 +320,55 @@ class CI_DB_result { */ function free_result() { - // Implemented in the platform-specific result adapter + return TRUE; } + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero + * + * @access private + * @return array + */ + function _data_seek($n = 0) + { + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @access private + * @return array + */ + function _fetch_assoc() + { + return array(); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + function _fetch_object() + { + return array(); + } } -- cgit v1.2.3-24-g4f1b From 44351bfc2a4dbd384bce7393cd76333885bf2c7f Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 5 Oct 2006 04:22:54 +0000 Subject: --- system/database/drivers/mysql/mysql_result.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index 91c4af12c..3fdfc8183 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -117,6 +117,23 @@ class CI_DB_mysql_result extends CI_DB_result { // -------------------------------------------------------------------- + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero + * + * @access private + * @return array + */ + function _data_seek($n = 0) + { + mysql_data_seek($this->result_id, $n); + } + + // -------------------------------------------------------------------- + /** * Result - associative array * @@ -141,7 +158,7 @@ class CI_DB_mysql_result extends CI_DB_result { * @return object */ function _fetch_object() - { + { return mysql_fetch_object($this->result_id); } -- cgit v1.2.3-24-g4f1b From d2dd03143d9e47a36a2f8561160e278a358fa031 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 5 Oct 2006 04:34:38 +0000 Subject: --- system/database/drivers/mssql/mssql_result.php | 17 +++++++++++++++++ system/database/drivers/mysqli/mysqli_result.php | 17 +++++++++++++++++ system/database/drivers/oci8/oci8_result.php | 19 +++++++++++++++++++ system/database/drivers/odbc/odbc_result.php | 19 ++++++++++++++++++- system/database/drivers/postgre/postgre_result.php | 17 +++++++++++++++++ system/database/drivers/sqlite/sqlite_result.php | 17 +++++++++++++++++ 6 files changed, 105 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index 53b7832d9..498deae09 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -114,6 +114,23 @@ class CI_DB_mssql_result extends CI_DB_result { $this->result_id = FALSE; } } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero + * + * @access private + * @return array + */ + function _data_seek($n = 0) + { + mssql_data_seek($this->result_id, $n); + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index 2eca68ff5..08db13f10 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -117,6 +117,23 @@ class CI_DB_mysqli_result extends CI_DB_result { // -------------------------------------------------------------------- + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero + * + * @access private + * @return array + */ + function _data_seek($n = 0) + { + mysqli_data_seek($this->result_id, $n); + } + + // -------------------------------------------------------------------- + /** * Result - associative array * diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 30c023ddc..a3da80026 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -161,6 +161,23 @@ class CI_DB_oci8_result extends CI_DB_result { } } + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero + * + * @access private + * @return array + */ + function _data_seek($n = 0) + { + return FALSE; + } + // -------------------------------------------------------------------- /** @@ -192,6 +209,8 @@ class CI_DB_oci8_result extends CI_DB_result { return $res; } + // -------------------------------------------------------------------- + /** * Query result. "array" version. * diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index 385209c56..9204d8680 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -114,7 +114,24 @@ class CI_DB_odbc_result extends CI_DB_result { $this->result_id = FALSE; } } - + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero + * + * @access private + * @return array + */ + function _data_seek($n = 0) + { + return FALSE; + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index ee838b450..8c25c5d4c 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -117,6 +117,23 @@ class CI_DB_postgre_result extends CI_DB_result { // -------------------------------------------------------------------- + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero + * + * @access private + * @return array + */ + function _data_seek($n = 0) + { + pg_result_seek($this->result_id, $n); + } + + // -------------------------------------------------------------------- + /** * Result - associative array * diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index 7f48ce8aa..a3e94b471 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -113,6 +113,23 @@ class CI_DB_sqlite_result extends CI_DB_result { // -------------------------------------------------------------------- + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero + * + * @access private + * @return array + */ + function _data_seek($n = 0) + { + sqlite_seek($this->result_id, $n); + } + + // -------------------------------------------------------------------- + /** * Result - associative array * -- cgit v1.2.3-24-g4f1b From 7b9d47296e6e68bfda0a9603d155de4fb7d0c099 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 5 Oct 2006 04:46:47 +0000 Subject: --- system/database/DB_result.php | 46 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 766a2e380..b3dbc2149 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -253,6 +253,11 @@ class CI_DB_result { /** * Number of rows in the result set * + * Note: This function is normally overloaded by the identically named + * method in the platform-specific driver -- except when query caching + * is used. When caching is enabled we do not load the other driver, + * so this function is here primarily to prevent undefined function errors. + * * @access public * @return integer */ @@ -266,6 +271,11 @@ class CI_DB_result { /** * Number of fields in the result set * + * Note: This function is normally overloaded by the identically named + * method in the platform-specific driver -- except when query caching + * is used. When caching is enabled we do not load the other driver, + * so this function is here primarily to prevent undefined function errors. + * * @access public * @return integer */ @@ -279,7 +289,10 @@ class CI_DB_result { /** * Fetch Field Names * - * Generates an array of column names + * Note: This function is normally overloaded by the identically named + * method in the platform-specific driver -- except when query caching + * is used. When caching is enabled we do not load the other driver, + * so this function is here primarily to prevent undefined function errors. * * @access public * @return array @@ -294,7 +307,10 @@ class CI_DB_result { /** * Field data * - * Generates an array of objects containing field meta-data + * Note: This function is normally overloaded by the identically named + * method in the platform-specific driver -- except when query caching + * is used. When caching is enabled we do not load the other driver, + * so this function is here primarily to prevent undefined function errors. * * @access public * @return array @@ -316,6 +332,11 @@ class CI_DB_result { /** * Free the result * + * Note: This function is normally overloaded by the identically named + * method in the platform-specific driver -- except when query caching + * is used. When caching is enabled we do not load the other driver, + * so this function is here primarily to prevent undefined function errors. + * * @return null */ function free_result() @@ -328,14 +349,15 @@ class CI_DB_result { /** * Data Seek * - * Moves the internal pointer to the desired offset. We call - * this internally before fetching results to make sure the - * result set starts at zero + * Note: This function is normally overloaded by the identically named + * method in the platform-specific driver -- except when query caching + * is used. When caching is enabled we do not load the other driver, + * so this function is here primarily to prevent undefined function errors. * * @access private * @return array */ - function _data_seek($n = 0) + function _data_seek() { return TRUE; } @@ -345,7 +367,10 @@ class CI_DB_result { /** * Result - associative array * - * Returns the result set as an array + * Note: This function is normally overloaded by the identically named + * method in the platform-specific driver -- except when query caching + * is used. When caching is enabled we do not load the other driver, + * so this function is here primarily to prevent undefined function errors. * * @access private * @return array @@ -360,7 +385,10 @@ class CI_DB_result { /** * Result - object * - * Returns the result set as an object + * Note: This function is normally overloaded by the identically named + * method in the platform-specific driver -- except when query caching + * is used. When caching is enabled we do not load the other driver, + * so this function is here primarily to prevent undefined function errors. * * @access private * @return object @@ -371,5 +399,5 @@ class CI_DB_result { } } - +// END DB_result class ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 386ec187efc7c713b37f0155c9b81e1693e2689b Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 5 Oct 2006 21:52:20 +0000 Subject: --- system/database/DB_result.php | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_result.php b/system/database/DB_result.php index b3dbc2149..525dd235a 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -255,8 +255,8 @@ class CI_DB_result { * * Note: This function is normally overloaded by the identically named * method in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver, - * so this function is here primarily to prevent undefined function errors. + * is used. When caching is enabled we do not load the other driver. + * This function will only be called when a cached result object is in use. * * @access public * @return integer @@ -273,8 +273,8 @@ class CI_DB_result { * * Note: This function is normally overloaded by the identically named * method in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver, - * so this function is here primarily to prevent undefined function errors. + * is used. When caching is enabled we do not load the other driver. + * This function will only be called when a cached result object is in use. * * @access public * @return integer @@ -291,8 +291,8 @@ class CI_DB_result { * * Note: This function is normally overloaded by the identically named * method in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver, - * so this function is here primarily to prevent undefined function errors. + * is used. When caching is enabled we do not load the other driver. + * This function will only be called when a cached result object is in use. * * @access public * @return array @@ -309,8 +309,8 @@ class CI_DB_result { * * Note: This function is normally overloaded by the identically named * method in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver, - * so this function is here primarily to prevent undefined function errors. + * is used. When caching is enabled we do not load the other driver. + * This function will only be called when a cached result object is in use. * * @access public * @return array @@ -334,8 +334,8 @@ class CI_DB_result { * * Note: This function is normally overloaded by the identically named * method in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver, - * so this function is here primarily to prevent undefined function errors. + * is used. When caching is enabled we do not load the other driver. + * This function will only be called when a cached result object is in use. * * @return null */ @@ -351,8 +351,8 @@ class CI_DB_result { * * Note: This function is normally overloaded by the identically named * method in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver, - * so this function is here primarily to prevent undefined function errors. + * is used. When caching is enabled we do not load the other driver. + * This function will only be called when a cached result object is in use. * * @access private * @return array @@ -369,8 +369,8 @@ class CI_DB_result { * * Note: This function is normally overloaded by the identically named * method in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver, - * so this function is here primarily to prevent undefined function errors. + * is used. When caching is enabled we do not load the other driver. + * This function will only be called when a cached result object is in use. * * @access private * @return array @@ -387,8 +387,8 @@ class CI_DB_result { * * Note: This function is normally overloaded by the identically named * method in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver, - * so this function is here primarily to prevent undefined function errors. + * is used. When caching is enabled we do not load the other driver. + * This function will only be called when a cached result object is in use. * * @access private * @return object -- cgit v1.2.3-24-g4f1b From a0564c0c6b8814b8c0e5c1b516e26711deb326a5 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 5 Oct 2006 22:18:11 +0000 Subject: --- system/database/DB_cache.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 135be3ce9..344736c24 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -97,10 +97,10 @@ class CI_DB_Cache { return $this->obj->db->cache_off(); } - $uri = ($this->obj->uri->segment(1) == FALSE) ? 'base' : $this->obj->uri->segment(2); - $uri .= ($this->obj->uri->segment(2) == FALSE) ? 'index' : $this->obj->uri->segment(2); + $uri = ($this->obj->uri->segment(1) == FALSE) ? 'default_' : $this->obj->uri->segment(1).'_'; + $uri .= ($this->obj->uri->segment(2) == FALSE) ? 'index' : $this->obj->uri->segment(2); - $filepath = md5($uri).'/'.md5($sql); + $filepath = $uri.'/'.md5($sql); if (FALSE === ($cachedata = read_file($this->obj->db->cachedir.$filepath))) { @@ -125,10 +125,10 @@ class CI_DB_Cache { return $this->obj->db->cache_off(); } - $uri = ($this->obj->uri->segment(1) == FALSE) ? 'base' : $this->obj->uri->segment(2); - $uri .= ($this->obj->uri->segment(2) == FALSE) ? 'index' : $this->obj->uri->segment(2); + $uri = ($this->obj->uri->segment(1) == FALSE) ? 'default_' : $this->obj->uri->segment(1).'_'; + $uri .= ($this->obj->uri->segment(2) == FALSE) ? 'index' : $this->obj->uri->segment(2); - $dir_path = $this->obj->db->cachedir.md5($uri).'/'; + $dir_path = $this->obj->db->cachedir.$uri.'/'; $filename = md5($sql); -- cgit v1.2.3-24-g4f1b From 7da9476fe67661398484ff57bdfad94ea483476d Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 5 Oct 2006 22:18:31 +0000 Subject: --- system/database/DB_result.php | 161 +++++------------------------------------- 1 file changed, 16 insertions(+), 145 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 525dd235a..76b7b9e9c 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -28,8 +28,8 @@ */ class CI_DB_result { - var $conn_id = FALSE; - var $result_id = FALSE; + var $conn_id = NULL; + var $result_id = NULL; var $result_array = array(); var $result_object = array(); var $current_row = 0; @@ -251,152 +251,23 @@ class CI_DB_result { // -------------------------------------------------------------------- /** - * Number of rows in the result set - * - * Note: This function is normally overloaded by the identically named - * method in the platform-specific driver -- except when query caching + * The following functions are normally overloaded by the identically named + * methods in the platform-specific driver -- except when query caching * is used. When caching is enabled we do not load the other driver. - * This function will only be called when a cached result object is in use. - * - * @access public - * @return integer - */ - function num_rows() - { - return $this->num_rows; - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * Note: This function is normally overloaded by the identically named - * method in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver. - * This function will only be called when a cached result object is in use. - * - * @access public - * @return integer - */ - function num_fields() - { - return 0; - } - - // -------------------------------------------------------------------- - - /** - * Fetch Field Names - * - * Note: This function is normally overloaded by the identically named - * method in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver. - * This function will only be called when a cached result object is in use. - * - * @access public - * @return array - */ - function field_names() - { - return array(); - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Note: This function is normally overloaded by the identically named - * method in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver. - * This function will only be called when a cached result object is in use. - * - * @access public - * @return array - */ - function field_data() - { - $F = new stdClass(); - $F->name = NULL; - $F->type = NULL; - $F->default = NULL; - $F->max_length = NULL; - $F->primary_key = NULL; - - return $retval[] = $F; - } - - // -------------------------------------------------------------------- - - /** - * Free the result - * - * Note: This function is normally overloaded by the identically named - * method in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver. - * This function will only be called when a cached result object is in use. - * - * @return null - */ - function free_result() - { - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Data Seek - * - * Note: This function is normally overloaded by the identically named - * method in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver. - * This function will only be called when a cached result object is in use. - * - * @access private - * @return array - */ - function _data_seek() - { - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Result - associative array - * - * Note: This function is normally overloaded by the identically named - * method in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver. - * This function will only be called when a cached result object is in use. - * - * @access private - * @return array + * These functions are primarily here to prevent undefined function errors + * when a cached result object is in use. They are not otherwise fully + * operational due to the unavailability of database resource IDs with + * cached results. */ - function _fetch_assoc() - { - return array(); - } - - // -------------------------------------------------------------------- + function num_rows() { return $this->num_rows; } + function num_fields() { return 0; } + function field_names() { return array(); } + function field_data() { return array(); } + function free_result() { return TRUE; } + function _data_seek() { return TRUE; } + function _fetch_assoc() { return array(); } + function _fetch_object() { return array(); } - /** - * Result - object - * - * Note: This function is normally overloaded by the identically named - * method in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver. - * This function will only be called when a cached result object is in use. - * - * @access private - * @return object - */ - function _fetch_object() - { - return array(); - } } // END DB_result class -- cgit v1.2.3-24-g4f1b From a658e314697e0b9e529a73df25edf4fffaf2b519 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 6 Oct 2006 01:29:36 +0000 Subject: --- system/database/DB_driver.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 403255799..f77b46609 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -51,6 +51,7 @@ class CI_DB_driver { var $_trans_failure = FALSE; // Used with transactions to determine if a rollback should occur var $cache_on = FALSE; var $cachedir = ''; + var $cache_autodel = TRUE; var $CACHE; // The cache class object @@ -287,7 +288,7 @@ class CI_DB_driver { { // If caching is enabled we'll auto-cleanup any // existing files related to this particular URI - if ($this->cache_on == TRUE AND $this->_cache_init()) + if ($this->cache_on == TRUE AND $this->cache_autodel == TRUE AND $this->_cache_init()) { $this->CACHE->delete(); } @@ -331,6 +332,10 @@ class CI_DB_driver { $CR->num_rows = $RES->num_rows(); $CR->result_object = $RES->result_object(); $CR->result_array = $RES->result_array(); + + // Reset these since cached objects can not utilize resource IDs. + $CR->conn_id = NULL; + $CR->result_id = NULL; $this->CACHE->write($sql, $CR); } @@ -910,6 +915,19 @@ class CI_DB_driver { { return $this->cache_on = FALSE; } + + // -------------------------------------------------------------------- + + /** + * Set the cache "auto-delete" value + * + * @access public + * @return void + */ + function cache_autodelete($val = TRUE) + { + $this->cache_autodel = ( ! is_bool($val)) ? TRUE : $val; + } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From e6419c4eeed88280a3e59851987e202f4c614dad Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 6 Oct 2006 01:50:43 +0000 Subject: --- system/database/DB_cache.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 344736c24..913140f6c 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -159,12 +159,19 @@ class CI_DB_Cache { * @access public * @return bool */ - function delete() - { - $uri = ($this->obj->uri->segment(1) == FALSE) ? 'base' : $this->obj->uri->segment(2); - $uri .= ($this->obj->uri->segment(2) == FALSE) ? 'index' : $this->obj->uri->segment(2); + function delete($segment_one = '', $segment_two = '') + { + if ($segment_one == '') + { + $segment_one = ($this->obj->uri->segment(1) == FALSE) ? 'default' : $this->obj->uri->segment(2); + } + + if ($segment_two == '') + { + $segment_two = ($this->obj->uri->segment(2) == FALSE) ? 'index' : $this->obj->uri->segment(2); + } - $dir_path = $this->obj->db->cachedir.md5($uri).'/'; + $dir_path = $this->obj->db->cachedir.md5($segment_one.'_'.$segment_two).'/'; delete_files($dir_path, TRUE); } -- cgit v1.2.3-24-g4f1b From c5f7fa3f8fea283b51ee6cd80b36b2112b2e81db Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 6 Oct 2006 02:10:23 +0000 Subject: --- system/database/DB_driver.php | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index f77b46609..e8c4a8236 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -51,7 +51,7 @@ class CI_DB_driver { var $_trans_failure = FALSE; // Used with transactions to determine if a rollback should occur var $cache_on = FALSE; var $cachedir = ''; - var $cache_autodel = TRUE; + var $cache_autodel = FALSE; var $CACHE; // The cache class object @@ -889,7 +889,21 @@ class CI_DB_driver { return call_user_func_array($function, $args); } } - + + // -------------------------------------------------------------------- + + /** + * Set Cache Directory Path + * + * @access public + * @param string the path to the cache directory + * @return void + */ + function cache_set_path($path = '') + { + $this->cachedir = $path; + } + // -------------------------------------------------------------------- /** @@ -915,32 +929,41 @@ class CI_DB_driver { { return $this->cache_on = FALSE; } + // -------------------------------------------------------------------- /** - * Set the cache "auto-delete" value + * Delete the cache files associated with a particular URI * * @access public * @return void */ - function cache_autodelete($val = TRUE) + function cache_delete() { - $this->cache_autodel = ( ! is_bool($val)) ? TRUE : $val; + if ( ! $this->_cache_init()) + { + return FALSE; + } + return $this->CACHE->delete(); } - + // -------------------------------------------------------------------- /** - * Set Cache Directory Path + * Delete All cache files * * @access public - * @param string the path to the cache directory * @return void */ - function cache_set_path($path = '') + function cache_delete_all() { - $this->cachedir = $path; + if ( ! $this->_cache_init()) + { + return FALSE; + } + + return $this->CACHE->delete_all(); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From fd2750b8f85b4f204e536d255742e18018c3f1f2 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 6 Oct 2006 17:29:12 +0000 Subject: --- system/database/DB_cache.php | 6 +++--- system/database/DB_driver.php | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 913140f6c..bb2b47b7b 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -97,7 +97,7 @@ class CI_DB_Cache { return $this->obj->db->cache_off(); } - $uri = ($this->obj->uri->segment(1) == FALSE) ? 'default_' : $this->obj->uri->segment(1).'_'; + $uri = ($this->obj->uri->segment(1) == FALSE) ? 'default.' : $this->obj->uri->segment(1).'.'; $uri .= ($this->obj->uri->segment(2) == FALSE) ? 'index' : $this->obj->uri->segment(2); $filepath = $uri.'/'.md5($sql); @@ -125,7 +125,7 @@ class CI_DB_Cache { return $this->obj->db->cache_off(); } - $uri = ($this->obj->uri->segment(1) == FALSE) ? 'default_' : $this->obj->uri->segment(1).'_'; + $uri = ($this->obj->uri->segment(1) == FALSE) ? 'default.' : $this->obj->uri->segment(1).'.'; $uri .= ($this->obj->uri->segment(2) == FALSE) ? 'index' : $this->obj->uri->segment(2); $dir_path = $this->obj->db->cachedir.$uri.'/'; @@ -171,7 +171,7 @@ class CI_DB_Cache { $segment_two = ($this->obj->uri->segment(2) == FALSE) ? 'index' : $this->obj->uri->segment(2); } - $dir_path = $this->obj->db->cachedir.md5($segment_one.'_'.$segment_two).'/'; + $dir_path = $this->obj->db->cachedir.md5($segment_one.'.'.$segment_two).'/'; delete_files($dir_path, TRUE); } diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index e8c4a8236..b89ebbf8d 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -156,6 +156,23 @@ class CI_DB_driver { } } + // -------------------------------------------------------------------- + + /** + * Load the Utilities Class + * + * @access public + * @return string + */ + function load_utilities() + { + $obj =& get_instance(); + + require_once(BASEPATH.'database/DB_utility'.EXT); + require_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_utility'.EXT); + $class = 'CI_DB_'.$this->dbdriver.'_utility'; + $obj->dbutil = new $class(); + } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 61c5717b76bc39823215aaceacdba97264f668d4 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 6 Oct 2006 17:29:24 +0000 Subject: --- system/database/DB.php | 100 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 system/database/DB.php (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php new file mode 100644 index 000000000..a60c98e2e --- /dev/null +++ b/system/database/DB.php @@ -0,0 +1,100 @@ +_ci_is_loaded('db') == TRUE AND $return == FALSE AND $active_record == FALSE) + { + return FALSE; + } + + // Load the DB config file if a DSN string wasn't passed + if (is_string($params) AND strpos($params, '://') === FALSE) + { + include(APPPATH.'config/database'.EXT); + + $group = ($params == '') ? $active_group : $params; + + if ( ! isset($db[$group])) + { + show_error('You have specified an invalid database connection group: '.$group); + } + + $params = $db[$group]; + } + + // No DB specified yet? Beat them senseless... + if ( ! isset($params['dbdriver']) OR $params['dbdriver'] == '') + { + show_error('You have not selected a database type to connect to.'); + } + + // Load the DB classes. Note: Since the active record class is optional + // we need to dynamically create a class that extends proper parent class + // based on whether we're using the active record class or not. + // Kudos to Paul for discovering this clever use of eval() + + if ($active_record == TRUE) + { + $params['active_r'] = TRUE; + } + + require_once(BASEPATH.'database/DB_driver'.EXT); + + if ( ! isset($params['active_r']) OR $params['active_r'] == TRUE) + { + require_once(BASEPATH.'database/DB_active_rec'.EXT); + + if ( ! class_exists('CI_DB')) + { + eval('class CI_DB extends CI_DB_active_record { }'); + } + } + else + { + if ( ! class_exists('CI_DB')) + { + eval('class CI_DB extends CI_DB_driver { }'); + } + } + + require_once(BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver'.EXT); + + // Instantiate the DB adapter + $driver = 'CI_DB_'.$params['dbdriver'].'_driver'; + $DB = new $driver($params); + + if ($return === TRUE) + { + return $DB; + } + + $obj->db =& $DB; +} + + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 8f0a8f693307a6d04b8a50aa11f81041c961adf6 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 7 Oct 2006 01:17:25 +0000 Subject: --- system/database/DB.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index a60c98e2e..f7476a68e 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -27,7 +27,7 @@ function DB($params = '', $return = FALSE, $active_record = FALSE) $obj =& get_instance(); // Do we even need to load the database class? - if ($obj->_ci_is_loaded('db') == TRUE AND $return == FALSE AND $active_record == FALSE) + if (class_exists('CI_DB') AND $return == FALSE AND $active_record == FALSE) { return FALSE; } -- cgit v1.2.3-24-g4f1b From b3ab70bfdce29b570c853ae53e370e54ca39da93 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 7 Oct 2006 03:07:29 +0000 Subject: --- system/database/DB_cache.php | 46 ++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index bb2b47b7b..081b56584 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -24,7 +24,7 @@ */ class CI_DB_Cache { - var $obj; + var $CI; /** * Constructor @@ -34,10 +34,10 @@ class CI_DB_Cache { */ function CI_DB_Cache() { - // Assign the main CI object to $this->obj + // Assign the main CI object to $this->CI // and load the file helper since we use it a lot - $this->obj =& get_instance(); - $this->obj->load->helper('file'); + $this->CI =& get_instance(); + $this->CI->load->helper('file'); } // -------------------------------------------------------------------- @@ -53,12 +53,12 @@ class CI_DB_Cache { { if ($path == '') { - if ($this->obj->db->cachedir == '') + if ($this->CI->db->cachedir == '') { - return $this->obj->db->cache_off(); + return $this->CI->db->cache_off(); } - $path = $this->obj->db->cachedir; + $path = $this->CI->db->cachedir; } // Add a trailing slash to the path if needed @@ -66,16 +66,16 @@ class CI_DB_Cache { if ( ! is_dir($path) OR ! is_writable($path)) { - if ($this->obj->db->db_debug) + if ($this->CI->db->db_debug) { - return $this->obj->db->display_error('db_invalid_cache_path'); + return $this->CI->db->display_error('db_invalid_cache_path'); } // If the path is wrong we'll turn off caching - return $this->obj->db->cache_off(); + return $this->CI->db->cache_off(); } - $this->obj->db->cachedir = $path; + $this->CI->db->cachedir = $path; return TRUE; } @@ -94,15 +94,15 @@ class CI_DB_Cache { { if ( ! $this->check_path()) { - return $this->obj->db->cache_off(); + return $this->CI->db->cache_off(); } - $uri = ($this->obj->uri->segment(1) == FALSE) ? 'default.' : $this->obj->uri->segment(1).'.'; - $uri .= ($this->obj->uri->segment(2) == FALSE) ? 'index' : $this->obj->uri->segment(2); + $uri = ($this->CI->uri->segment(1) == FALSE) ? 'default.' : $this->CI->uri->segment(1).'.'; + $uri .= ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); $filepath = $uri.'/'.md5($sql); - if (FALSE === ($cachedata = read_file($this->obj->db->cachedir.$filepath))) + if (FALSE === ($cachedata = read_file($this->CI->db->cachedir.$filepath))) { return FALSE; } @@ -122,13 +122,13 @@ class CI_DB_Cache { { if ( ! $this->check_path()) { - return $this->obj->db->cache_off(); + return $this->CI->db->cache_off(); } - $uri = ($this->obj->uri->segment(1) == FALSE) ? 'default.' : $this->obj->uri->segment(1).'.'; - $uri .= ($this->obj->uri->segment(2) == FALSE) ? 'index' : $this->obj->uri->segment(2); + $uri = ($this->CI->uri->segment(1) == FALSE) ? 'default.' : $this->CI->uri->segment(1).'.'; + $uri .= ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); - $dir_path = $this->obj->db->cachedir.$uri.'/'; + $dir_path = $this->CI->db->cachedir.$uri.'/'; $filename = md5($sql); @@ -163,15 +163,15 @@ class CI_DB_Cache { { if ($segment_one == '') { - $segment_one = ($this->obj->uri->segment(1) == FALSE) ? 'default' : $this->obj->uri->segment(2); + $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(2); } if ($segment_two == '') { - $segment_two = ($this->obj->uri->segment(2) == FALSE) ? 'index' : $this->obj->uri->segment(2); + $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); } - $dir_path = $this->obj->db->cachedir.md5($segment_one.'.'.$segment_two).'/'; + $dir_path = $this->CI->db->cachedir.md5($segment_one.'.'.$segment_two).'/'; delete_files($dir_path, TRUE); } @@ -186,7 +186,7 @@ class CI_DB_Cache { */ function delete_all() { - delete_files($this->obj->db->cachedir, TRUE); + delete_files($this->CI->db->cachedir, TRUE); } } -- cgit v1.2.3-24-g4f1b From 88a8ad187b13b36d6120eae2344fe16c3a76219d Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 7 Oct 2006 03:16:32 +0000 Subject: --- system/database/DB.php | 7 +++---- system/database/DB_driver.php | 8 ++++---- system/database/DB_utility.php | 21 ++++++++++----------- 3 files changed, 17 insertions(+), 19 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index f7476a68e..62237440f 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -24,8 +24,6 @@ */ function DB($params = '', $return = FALSE, $active_record = FALSE) { - $obj =& get_instance(); - // Do we even need to load the database class? if (class_exists('CI_DB') AND $return == FALSE AND $active_record == FALSE) { @@ -92,8 +90,9 @@ function DB($params = '', $return = FALSE, $active_record = FALSE) { return $DB; } - - $obj->db =& $DB; + + $CI =& get_instance(); + $CI->db =& $DB; } diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index b89ebbf8d..c8a00b7b1 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -165,13 +165,13 @@ class CI_DB_driver { * @return string */ function load_utilities() - { - $obj =& get_instance(); - + { require_once(BASEPATH.'database/DB_utility'.EXT); require_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_utility'.EXT); $class = 'CI_DB_'.$this->dbdriver.'_utility'; - $obj->dbutil = new $class(); + + $CI =& get_instance(); + $CI->dbutil = new $class(); } // -------------------------------------------------------------------- diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 433056ff0..64d67db41 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -36,8 +36,8 @@ class CI_DB_utility { function CI_DB_utility() { // Assign the main database object to $this->db - $obj =& get_instance(); - $this->db =& $obj->db; + $CI =& get_instance(); + $this->CI =& $obj->db; log_message('debug', "Database Utility Class Initialized"); } @@ -286,8 +286,8 @@ class CI_DB_utility { extract($params); // Load the xml helper - $obj =& get_instance(); - $obj->load->helper('xml'); + $CI =& get_instance(); + $CI->load->helper('xml'); // Generate the result $xml = "<{$root}/>".$newline; @@ -391,10 +391,7 @@ class CI_DB_utility { } // ------------------------------------------------------ - - // Grab the super object - $obj =& get_instance(); - + // Was a Gzip file requested? if ($prefs['format'] == 'gzip') { @@ -427,9 +424,11 @@ class CI_DB_utility { } // Load the Zip class and output it - $obj->load->library('zip'); - $obj->zip->add_data($prefs['filename'], $this->_backup($prefs)); - return $obj->zip->get_zip(); + + $CI =& get_instance(); + $CI->load->library('zip'); + $CI->zip->add_data($prefs['filename'], $this->_backup($prefs)); + return $CI->zip->get_zip(); } } -- cgit v1.2.3-24-g4f1b From dee8ba233621af79fbf9b529b37a845734843fb8 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 7 Oct 2006 03:20:32 +0000 Subject: --- system/database/DB_cache.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 081b56584..86493e77c 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -97,7 +97,7 @@ class CI_DB_Cache { return $this->CI->db->cache_off(); } - $uri = ($this->CI->uri->segment(1) == FALSE) ? 'default.' : $this->CI->uri->segment(1).'.'; + $uri = ($this->CI->uri->segment(1) == FALSE) ? 'default.' : $this->CI->uri->segment(1).'+'; $uri .= ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); $filepath = $uri.'/'.md5($sql); @@ -125,7 +125,7 @@ class CI_DB_Cache { return $this->CI->db->cache_off(); } - $uri = ($this->CI->uri->segment(1) == FALSE) ? 'default.' : $this->CI->uri->segment(1).'.'; + $uri = ($this->CI->uri->segment(1) == FALSE) ? 'default.' : $this->CI->uri->segment(1).'+'; $uri .= ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); $dir_path = $this->CI->db->cachedir.$uri.'/'; @@ -171,7 +171,7 @@ class CI_DB_Cache { $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); } - $dir_path = $this->CI->db->cachedir.md5($segment_one.'.'.$segment_two).'/'; + $dir_path = $this->CI->db->cachedir.md5($segment_one.'+'.$segment_two).'/'; delete_files($dir_path, TRUE); } -- cgit v1.2.3-24-g4f1b From 69af5bd5d457468e0b2875c47d06830496679a8f Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 7 Oct 2006 03:22:46 +0000 Subject: --- system/database/DB_utility.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 64d67db41..c2c5f1fe0 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -290,10 +290,10 @@ class CI_DB_utility { $CI->load->helper('xml'); // Generate the result - $xml = "<{$root}/>".$newline; + $xml = "<{$root}>".$newline; foreach ($query->result_array() as $row) { - $xml .= $tab."<{$element}/>".$newline; + $xml .= $tab."<{$element}>".$newline; foreach ($row as $key => $val) { -- cgit v1.2.3-24-g4f1b From 10c3f41cbe5bd3bb66fd106cc9fb171ffcc7364b Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 8 Oct 2006 07:21:12 +0000 Subject: --- system/database/DB_result.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 76b7b9e9c..1c8ad6be0 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -256,7 +256,7 @@ class CI_DB_result { * is used. When caching is enabled we do not load the other driver. * These functions are primarily here to prevent undefined function errors * when a cached result object is in use. They are not otherwise fully - * operational due to the unavailability of database resource IDs with + * operational due to the unavailability of the database resource IDs with * cached results. */ function num_rows() { return $this->num_rows; } -- cgit v1.2.3-24-g4f1b From 7099a589d1719311427d7552523ec962ebc3b650 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 10 Oct 2006 17:47:59 +0000 Subject: --- system/database/DB_driver.php | 12 ++++++++---- system/database/DB_utility.php | 3 ++- system/database/drivers/oci8/oci8_driver.php | 3 ++- system/database/drivers/postgre/postgre_utility.php | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index c8a00b7b1..99c95a6f2 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -682,7 +682,8 @@ class CI_DB_driver { } } - return $this->data_cache['table_names'] =& $retval; + $this->data_cache['table_names'] = $retval; + return $this->data_cache['table_names']; } // -------------------------------------------------------------------- @@ -747,7 +748,8 @@ class CI_DB_driver { } } - return $this->data_cache['field_names'][$table] =& $retval; + $this->data_cache['field_names'][$table] = $retval; + return $this->data_cache['field_names'][$table]; } // -------------------------------------------------------------------- @@ -931,7 +933,8 @@ class CI_DB_driver { */ function cache_on() { - return $this->cache_on = TRUE; + $this->cache_on = TRUE; + return TRUE; } // -------------------------------------------------------------------- @@ -944,7 +947,8 @@ class CI_DB_driver { */ function cache_off() { - return $this->cache_on = FALSE; + $this->cache_on = FALSE; + return FALSE; } diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index c2c5f1fe0..51e43a7c8 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -110,7 +110,8 @@ class CI_DB_utility { } } - return $this->data_cache['db_names'] =& $dbs; + $this->data_cache['db_names'] = $dbs; + return $this->data_cache['db_names']; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index e83c640bd..794405a03 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -163,7 +163,8 @@ class CI_DB_oci8_driver extends CI_DB { */ function get_cursor() { - return $this->curs_id = ocinewcursor($this->conn_id); + $this->curs_id = ocinewcursor($this->conn_id); + return $this->curs_id; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 0c265de16..b08b879d7 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -106,7 +106,7 @@ class CI_DB_postgre_utility extends CI_DB_utility { */ function _repair_table($table) { - return return FALSE; + return FALSE; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 1b0ab4665720446eee6b03f864bb5576e6065a4a Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 10 Oct 2006 23:30:21 +0000 Subject: --- system/database/DB_driver.php | 4 ++-- system/database/DB_utility.php | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 99c95a6f2..6da645a38 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -960,13 +960,13 @@ class CI_DB_driver { * @access public * @return void */ - function cache_delete() + function cache_delete($segment_one = '', $segment_two = '') { if ( ! $this->_cache_init()) { return FALSE; } - return $this->CACHE->delete(); + return $this->CACHE->delete($segment_one, $segment_two); } // -------------------------------------------------------------------- diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 51e43a7c8..13fcaa5c9 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -37,7 +37,7 @@ class CI_DB_utility { { // Assign the main database object to $this->db $CI =& get_instance(); - $this->CI =& $obj->db; + $this->db =& $CI->db; log_message('debug', "Database Utility Class Initialized"); } @@ -100,7 +100,7 @@ class CI_DB_utility { return $this->data_cache['db_names']; } - $query = $this->db->query($this->_list_database()); + $query = $this->db->query($this->_list_databases()); $dbs = array(); if ($query->num_rows() > 0) { @@ -147,7 +147,7 @@ class CI_DB_utility { function optimize_database() { $result = array(); - foreach ($this->list_tables() as $table_name) + foreach ($this->db->list_tables() as $table_name) { $sql = $this->_optimize_table($table_name); @@ -356,7 +356,7 @@ class CI_DB_utility { // If no table names were submitted we'll fetch the entire table list if (count($prefs['tables']) == 0) { - $prefs['tables'] = $this->list_tables(); + $prefs['tables'] = $this->db->list_tables(); } // ------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 4003718f35247ef9b4a8d678389bda639677bac7 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 11 Oct 2006 19:16:58 +0000 Subject: --- system/database/DB_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 6da645a38..22f91ed4c 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -400,7 +400,7 @@ class CI_DB_driver { $this->initialize(); } - return $this->_execute($sql, $this->conn_id); + return $this->_execute($sql); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 606f99c043272f96f21911d89c21cd36c2ef59e4 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 11 Oct 2006 23:48:41 +0000 Subject: --- system/database/DB_driver.php | 3 ++- system/database/DB_result.php | 6 +++--- system/database/drivers/mssql/mssql_result.php | 8 +++++++- system/database/drivers/mysql/mysql_result.php | 8 +++++++- system/database/drivers/mysqli/mysqli_result.php | 8 +++++++- system/database/drivers/oci8/oci8_result.php | 8 +++++++- system/database/drivers/odbc/odbc_result.php | 8 +++++++- system/database/drivers/postgre/postgre_result.php | 8 +++++++- system/database/drivers/sqlite/sqlite_result.php | 8 +++++++- 9 files changed, 54 insertions(+), 11 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 22f91ed4c..a4131fd73 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -172,6 +172,7 @@ class CI_DB_driver { $CI =& get_instance(); $CI->dbutil = new $class(); + $CI->_ci_assign_to_models(); } // -------------------------------------------------------------------- @@ -629,7 +630,7 @@ class CI_DB_driver { */ function primary($table = '') { - $fields = $this->field_names($table); + $fields = $this->list_fields($table); if ( ! is_array($fields)) { diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 1c8ad6be0..b163bb5ea 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -261,14 +261,14 @@ class CI_DB_result { */ function num_rows() { return $this->num_rows; } function num_fields() { return 0; } - function field_names() { return array(); } + function list_fields() { return array(); } + function field_names() { return array(); } // Deprecated function field_data() { return array(); } function free_result() { return TRUE; } function _data_seek() { return TRUE; } function _fetch_assoc() { return array(); } function _fetch_object() { return array(); } - - + } // END DB_result class ?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index 498deae09..0ba0b8c57 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -60,7 +60,7 @@ class CI_DB_mssql_result extends CI_DB_result { * @access public * @return array */ - function field_names() + function list_fields() { $field_names = array(); while ($field = mssql_fetch_field($this->result_id)) @@ -70,6 +70,12 @@ class CI_DB_mssql_result extends CI_DB_result { return $field_names; } + + // Deprecated + function field_names() + { + return $this->list_fields(); + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index 3fdfc8183..1cf6ff188 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -60,7 +60,7 @@ class CI_DB_mysql_result extends CI_DB_result { * @access public * @return array */ - function field_names() + function list_fields() { $field_names = array(); while ($field = mysql_fetch_field($this->result_id)) @@ -70,6 +70,12 @@ class CI_DB_mysql_result extends CI_DB_result { return $field_names; } + + // Deprecated + function field_names() + { + return $this->list_fields(); + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index 08db13f10..215403e9d 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -60,7 +60,7 @@ class CI_DB_mysqli_result extends CI_DB_result { * @access public * @return array */ - function field_names() + function list_fields() { $field_names = array(); while ($field = mysql_fetch_field($this->result_id)) @@ -71,6 +71,12 @@ class CI_DB_mysqli_result extends CI_DB_result { return $field_names; } + // Deprecated + function field_names() + { + return $this->list_fields(); + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index a3da80026..ab13a3935 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -84,7 +84,7 @@ class CI_DB_oci8_result extends CI_DB_result { * @access public * @return array */ - function field_names() + function list_fields() { $field_names = array(); $fieldCount = $this->num_fields(); @@ -95,6 +95,12 @@ class CI_DB_oci8_result extends CI_DB_result { return $field_names; } + // Deprecated + function field_names() + { + return $this->list_fields(); + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index 9204d8680..ea834f9b4 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -60,7 +60,7 @@ class CI_DB_odbc_result extends CI_DB_result { * @access public * @return array */ - function field_names() + function list_fields() { $field_names = array(); for ($i = 0; $i < $this->num_fields(); $i++) @@ -71,6 +71,12 @@ class CI_DB_odbc_result extends CI_DB_result { return $field_names; } + // Deprecated + function field_names() + { + return $this->list_fields(); + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index 8c25c5d4c..e792544ae 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -60,7 +60,7 @@ class CI_DB_postgre_result extends CI_DB_result { * @access public * @return array */ - function field_names() + function list_fields() { $field_names = array(); for ($i = 0; $i < $this->num_fields(); $i++) @@ -71,6 +71,12 @@ class CI_DB_postgre_result extends CI_DB_result { return $field_names; } + // Deprecated + function field_names() + { + return $this->list_fields(); + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index a3e94b471..55364bb24 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -60,7 +60,7 @@ class CI_DB_sqlite_result extends CI_DB_result { * @access public * @return array */ - function field_names() + function list_fields() { $field_names = array(); for ($i = 0; $i < $this->num_fields(); $i++) @@ -71,6 +71,12 @@ class CI_DB_sqlite_result extends CI_DB_result { return $field_names; } + // Deprecated + function field_names() + { + return $this->list_fields(); + } + // -------------------------------------------------------------------- /** -- cgit v1.2.3-24-g4f1b From 0aef222d246da84c90e9a89f31f6677cbe6b4ddc Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 12 Oct 2006 18:00:22 +0000 Subject: --- system/database/DB.php | 19 +++---------------- system/database/DB_driver.php | 19 ------------------- 2 files changed, 3 insertions(+), 35 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index 62237440f..a148c9ffe 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -22,14 +22,8 @@ * @author Rick Ellis * @link http://www.codeigniter.com/user_guide/database/ */ -function DB($params = '', $return = FALSE, $active_record = FALSE) +function DB($params = '', $active_record = FALSE) { - // Do we even need to load the database class? - if (class_exists('CI_DB') AND $return == FALSE AND $active_record == FALSE) - { - return FALSE; - } - // Load the DB config file if a DSN string wasn't passed if (is_string($params) AND strpos($params, '://') === FALSE) { @@ -84,15 +78,8 @@ function DB($params = '', $return = FALSE, $active_record = FALSE) // Instantiate the DB adapter $driver = 'CI_DB_'.$params['dbdriver'].'_driver'; - $DB = new $driver($params); - - if ($return === TRUE) - { - return $DB; - } - - $CI =& get_instance(); - $CI->db =& $DB; + $DB = new $driver($params); + return $DB; } diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index a4131fd73..848d4f1c6 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -155,26 +155,7 @@ class CI_DB_driver { } } } - - // -------------------------------------------------------------------- - - /** - * Load the Utilities Class - * - * @access public - * @return string - */ - function load_utilities() - { - require_once(BASEPATH.'database/DB_utility'.EXT); - require_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_utility'.EXT); - $class = 'CI_DB_'.$this->dbdriver.'_utility'; - $CI =& get_instance(); - $CI->dbutil = new $class(); - $CI->_ci_assign_to_models(); - } - // -------------------------------------------------------------------- /** -- cgit v1.2.3-24-g4f1b From 9a661810d2b9b96c458c1f369f0059b31012b6a8 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 16 Oct 2006 19:02:48 +0000 Subject: --- system/database/DB.php | 4 ++-- system/database/drivers/mssql/mssql_utility.php | 2 +- system/database/drivers/oci8/oci8_utility.php | 2 +- system/database/drivers/sqlite/sqlite_utility.php | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index a148c9ffe..d2afce982 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -22,7 +22,7 @@ * @author Rick Ellis * @link http://www.codeigniter.com/user_guide/database/ */ -function DB($params = '', $active_record = FALSE) +function &DB($params = '', $active_record = FALSE) { // Load the DB config file if a DSN string wasn't passed if (is_string($params) AND strpos($params, '://') === FALSE) @@ -78,7 +78,7 @@ function DB($params = '', $active_record = FALSE) // Instantiate the DB adapter $driver = 'CI_DB_'.$params['dbdriver'].'_driver'; - $DB = new $driver($params); + $DB =& new $driver($params); return $DB; } diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index 129ba6861..24ff1e13c 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -106,7 +106,7 @@ class CI_DB_mssql_utility extends CI_DB_utility { */ function _repair_table($table) { - return return FALSE; // Is this supported in MS SQL? + return FALSE; // Is this supported in MS SQL? } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 96be09506..f4e912183 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -106,7 +106,7 @@ class CI_DB_oci8_utility extends CI_DB_utility { */ function _repair_table($table) { - return return FALSE; // Is this supported in Oracle? + return FALSE; // Is this supported in Oracle? } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 9cb2cf027..ecce5be40 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -131,7 +131,7 @@ class CI_DB_sqlite_utility extends CI_DB_utility { */ function _repair_table($table) { - return return FALSE; + return FALSE; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 31eeb0587cd5fcef8209ca5083f28a39435c135d Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 20 Oct 2006 05:11:33 +0000 Subject: --- system/database/DB_result.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'system/database') diff --git a/system/database/DB_result.php b/system/database/DB_result.php index b163bb5ea..4e8c4fc76 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -63,6 +63,11 @@ class CI_DB_result { return $this->result_object; } + if ($this->num_rows == 0) + { + return array(); + } + $this->_data_seek(0); while ($row = $this->_fetch_object()) { @@ -87,6 +92,11 @@ class CI_DB_result { return $this->result_array; } + if ($this->num_rows == 0) + { + return array(); + } + $this->_data_seek(0); while ($row = $this->_fetch_assoc()) { -- cgit v1.2.3-24-g4f1b From 9fcc28a29299fbbc242f87bf1b1e61fda6543886 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 21 Oct 2006 17:49:47 +0000 Subject: --- system/database/DB_cache.php | 2 +- system/database/DB_driver.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 86493e77c..aee5ce6fa 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -171,7 +171,7 @@ class CI_DB_Cache { $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); } - $dir_path = $this->CI->db->cachedir.md5($segment_one.'+'.$segment_two).'/'; + $dir_path = $this->CI->db->cachedir.$segment_one.'+'.$segment_two.'/'; delete_files($dir_path, TRUE); } diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 848d4f1c6..a24bd20d8 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -236,6 +236,7 @@ class CI_DB_driver { { if (FALSE !== ($cache = $this->CACHE->read($sql))) { + $this->load_rdriver(); return $cache; } } -- cgit v1.2.3-24-g4f1b From fafe28bec4f414e48f63e01ed9105ae5c2c99802 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 21 Oct 2006 19:08:17 +0000 Subject: --- system/database/DB_active_rec.php | 2 +- system/database/DB_cache.php | 2 +- system/database/DB_driver.php | 6 +++--- system/database/DB_result.php | 2 +- system/database/drivers/mssql/mssql_driver.php | 2 +- system/database/drivers/mysql/mysql_driver.php | 2 +- system/database/drivers/mysqli/mysqli_driver.php | 2 +- system/database/drivers/oci8/oci8_driver.php | 2 +- system/database/drivers/odbc/odbc_driver.php | 2 +- system/database/drivers/postgre/postgre_driver.php | 2 +- system/database/drivers/sqlite/sqlite_driver.php | 2 +- 11 files changed, 13 insertions(+), 13 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 1fa4f9557..8db6161af 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -804,7 +804,7 @@ class CI_DB_active_record extends CI_DB_driver { /** * Object to Array * - * Takes an object as input and convers the class variables to array key/vals + * Takes an object as input and converts the class variables to array key/vals * * @access public * @param object diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index aee5ce6fa..b469b0e1e 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -82,7 +82,7 @@ class CI_DB_Cache { // -------------------------------------------------------------------- /** - * Retreive a cached query + * Retrieve a cached query * * The URI being requested will become the name of the cache sub-folder. * An MD5 hash of the SQL statement will become the cache file name diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index a24bd20d8..8a7b88f18 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -368,7 +368,7 @@ class CI_DB_driver { /** * Simple Query - * This is a simiplified version of the query() function. Internally + * This is a simplified version of the query() function. Internally * we only use it when running transaction commands since they do * not require all the features of the main query() function. * @@ -535,7 +535,7 @@ class CI_DB_driver { * Calculate the aggregate query elapsed time * * @access public - * @param intiger The number of decimal places + * @param integer The number of decimal places * @return integer */ function elapsed_time($decimals = 6) @@ -1021,7 +1021,7 @@ class CI_DB_driver { * @param string the error message * @param string any "swap" values * @param boolean whether to localize the message - * @return string sends the application/errror_db.php template + * @return string sends the application/error_db.php template */ function display_error($error = '', $swap = '', $native = FALSE) { diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 4e8c4fc76..d02bfb96e 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -63,7 +63,7 @@ class CI_DB_result { return $this->result_object; } - if ($this->num_rows == 0) + if ($this->numerous == 0) { return array(); } diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index cb2f48dc3..4dc8792ca 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -277,7 +277,7 @@ class CI_DB_mssql_driver extends CI_DB { // -------------------------------------------------------------------- /** - * List columnn query + * List column query * * Generates a platform-specific query string so that the column names can be fetched * diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 253627cd9..20311ffa0 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -311,7 +311,7 @@ class CI_DB_mysql_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Show columnn query + * Show column query * * Generates a platform-specific query string so that the column names can be fetched * diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 4fd9f3aaa..ea2adbea9 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -303,7 +303,7 @@ class CI_DB_mysqli_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Show columnn query + * Show column query * * Generates a platform-specific query string so that the column names can be fetched * diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 794405a03..4f5470c1a 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -418,7 +418,7 @@ class CI_DB_oci8_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Show columnn query + * Show column query * * Generates a platform-specific query string so that the column names can be fetched * diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 4bd6e1106..17a6dfbd0 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -278,7 +278,7 @@ class CI_DB_odbc_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Show columnn query + * Show column query * * Generates a platform-specific query string so that the column names can be fetched * diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 340d65046..f74e652d5 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -305,7 +305,7 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Show columnn query + * Show column query * * Generates a platform-specific query string so that the column names can be fetched * diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 9da50b676..fd9fd2c50 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -297,7 +297,7 @@ class CI_DB_sqlite_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Show columnn query + * Show column query * * Generates a platform-specific query string so that the column names can be fetched * -- cgit v1.2.3-24-g4f1b From e334c472fb4be44feec3a73402fc4a2b062cbfc0 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 21 Oct 2006 19:44:22 +0000 Subject: --- system/database/DB.php | 6 +- system/database/DB_active_rec.php | 34 +- system/database/DB_cache.php | 2 +- system/database/DB_driver.php | 176 ++-- system/database/DB_result.php | 52 +- system/database/DB_utility.php | 14 +- system/database/drivers/mssql/mssql_driver.php | 26 +- system/database/drivers/mssql/mssql_result.php | 10 +- system/database/drivers/mssql/mssql_utility.php | 6 +- system/database/drivers/mysql/mysql_driver.php | 44 +- system/database/drivers/mysql/mysql_result.php | 8 +- system/database/drivers/mysql/mysql_utility.php | 52 +- system/database/drivers/mysqli/mysqli_driver.php | 34 +- system/database/drivers/mysqli/mysqli_result.php | 10 +- system/database/drivers/mysqli/mysqli_utility.php | 54 +- system/database/drivers/oci8/oci8_driver.php | 902 ++++++++++----------- system/database/drivers/oci8/oci8_result.php | 308 +++---- system/database/drivers/oci8/oci8_utility.php | 4 +- system/database/drivers/odbc/odbc_driver.php | 28 +- system/database/drivers/odbc/odbc_result.php | 8 +- system/database/drivers/odbc/odbc_utility.php | 8 +- system/database/drivers/postgre/postgre_driver.php | 28 +- system/database/drivers/postgre/postgre_result.php | 8 +- .../database/drivers/postgre/postgre_utility.php | 6 +- system/database/drivers/sqlite/sqlite_driver.php | 38 +- system/database/drivers/sqlite/sqlite_result.php | 6 +- system/database/drivers/sqlite/sqlite_utility.php | 6 +- 27 files changed, 939 insertions(+), 939 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index d2afce982..c6bd365d9 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource @@ -46,7 +46,7 @@ function &DB($params = '', $active_record = FALSE) } // Load the DB classes. Note: Since the active record class is optional - // we need to dynamically create a class that extends proper parent class + // we need to dynamically create a class that extends proper parent class // based on whether we're using the active record class or not. // Kudos to Paul for discovering this clever use of eval() @@ -57,7 +57,7 @@ function &DB($params = '', $active_record = FALSE) require_once(BASEPATH.'database/DB_driver'.EXT); - if ( ! isset($params['active_r']) OR $params['active_r'] == TRUE) + if ( ! isset($params['active_r']) OR $params['active_r'] == TRUE) { require_once(BASEPATH.'database/DB_active_rec'.EXT); diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 8db6161af..b41b929d7 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -7,17 +7,17 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** * Active Record Class - * + * * This is the platform-independent base Active Record implementation class. * * @package CodeIgniter @@ -547,11 +547,11 @@ class CI_DB_active_record extends CI_DB_driver { if (count($this->ar_set) == 0) { - if ($this->db_debug) - { + if ($this->db_debug) + { return $this->display_error('db_must_use_set'); - } - return FALSE; + } + return FALSE; } if ($table == '') @@ -596,11 +596,11 @@ class CI_DB_active_record extends CI_DB_driver { if (count($this->ar_set) == 0) { - if ($this->db_debug) - { + if ($this->db_debug) + { return $this->display_error('db_must_use_set'); - } - return FALSE; + } + return FALSE; } if ($table == '') @@ -663,11 +663,11 @@ class CI_DB_active_record extends CI_DB_driver { if (count($this->ar_where) == 0) { - if ($this->db_debug) - { + if ($this->db_debug) + { return $this->display_error('db_del_must_use_where'); - } - return FALSE; + } + return FALSE; } $sql = $this->_delete($this->dbprefix.$table, $this->ar_where); @@ -679,7 +679,7 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- /** - * Use Table - DEPRECATED + * Use Table - DEPRECATED * * @deprecated use $this->db->from instead */ @@ -726,7 +726,7 @@ class CI_DB_active_record extends CI_DB_driver { /** * Compile the SELECT statement * - * Generates a query string based on which functions were used. + * Generates a query string based on which functions were used. * Should not be called directly. The get() function calls it. * * @access private diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index b469b0e1e..53425d1d9 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 8a7b88f18..ab8a6a8e2 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -7,17 +7,17 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** * Database Driver Class - * + * * This is the platform-independent base DB implementation class. * This class will not be called directly. Rather, the adapter * class for the specific database will extend and instantiate it. @@ -64,10 +64,10 @@ class CI_DB_driver { /** * Constructor. Accepts one parameter containing the database - * connection settings. + * connection settings. * - * Database settings can be passed as discreet - * parameters or as a data source name in the first + * Database settings can be passed as discreet + * parameters or as a data source name in the first * parameter. DSNs must have this prototype: * $dsn = 'driver://username:password@hostname/database'; * @@ -93,16 +93,16 @@ class CI_DB_driver { if (is_array($params)) { $defaults = array( - 'hostname' => '', - 'username' => '', - 'password' => '', - 'database' => '', - 'dbdriver' => 'mysql', - 'dbprefix' => '', - 'port' => '', - 'pconnect' => FALSE, - 'db_debug' => FALSE, - 'cachedir' => '', + 'hostname' => '', + 'username' => '', + 'password' => '', + 'database' => '', + 'dbdriver' => 'mysql', + 'dbprefix' => '', + 'port' => '', + 'pconnect' => FALSE, + 'db_debug' => FALSE, + 'cachedir' => '', 'cache_on' => FALSE ); @@ -132,9 +132,9 @@ class CI_DB_driver { // Connect to the database $this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect(); - + if ( ! $this->conn_id) - { + { log_message('error', 'Unable to connect to the database'); if ($this->db_debug) @@ -162,7 +162,7 @@ class CI_DB_driver { * The name of the platform in use (mysql, mssql, etc...) * * @access public - * @return string + * @return string */ function platform() { @@ -172,7 +172,7 @@ class CI_DB_driver { // -------------------------------------------------------------------- /** - * Database Version Number. Returns a string containing the + * Database Version Number. Returns a string containing the * version of the database being used * * @access public @@ -204,16 +204,16 @@ class CI_DB_driver { /** * Execute the query * - * Accepts an SQL string as input and returns a result object upon - * successful execution of a "read" type query. Returns boolean TRUE - * upon successful execution of a "write" type query. Returns boolean - * FALSE upon failure, and if the $db_debug variable is set to TRUE + * Accepts an SQL string as input and returns a result object upon + * successful execution of a "read" type query. Returns boolean TRUE + * upon successful execution of a "write" type query. Returns boolean + * FALSE upon failure, and if the $db_debug variable is set to TRUE * will raise an error. - * + * * @access public * @param string An SQL query string * @param array An array of binding data - * @return mixed + * @return mixed */ function query($sql, $binds = FALSE, $return_object = TRUE) { @@ -227,8 +227,8 @@ class CI_DB_driver { return FALSE; } - // Is query caching enabled? If the query is a "read type" - // we will load the caching class and return the previously + // Is query caching enabled? If the query is a "read type" + // we will load the caching class and return the previously // cached query if it exists if ($this->cache_on == TRUE AND stristr($sql, 'SELECT')) { @@ -253,10 +253,10 @@ class CI_DB_driver { // Start the Query Timer $time_start = list($sm, $ss) = explode(' ', microtime()); - + // Run the Query if (FALSE === ($this->result_id = $this->simple_query($sql))) - { + { // This will trigger a rollback if transactions are being used $this->_trans_failure = TRUE; @@ -265,13 +265,13 @@ class CI_DB_driver { log_message('error', 'Query error: '.$this->_error_message()); return $this->display_error( array( - 'Error Number: '.$this->_error_number(), + 'Error Number: '.$this->_error_number(), $this->_error_message(), $sql ) ); } - + return FALSE; } @@ -296,7 +296,7 @@ class CI_DB_driver { return TRUE; } - // Return TRUE if we don't need to create a result object + // Return TRUE if we don't need to create a result object // Currently only the Oracle driver uses this when stored // procedures are used if ($return_object !== TRUE) @@ -318,7 +318,7 @@ class CI_DB_driver { $RES->limit_used = $this->limit_used; } - // Is query caching enabled? If so, we'll serialize the + // Is query caching enabled? If so, we'll serialize the // result object and save it to a cache file. if ($this->cache_on == TRUE AND $this->_cache_init()) { @@ -347,9 +347,9 @@ class CI_DB_driver { /** * Load the result drivers - * + * * @access public - * @return string the name of the result class + * @return string the name of the result class */ function load_rdriver() { @@ -367,14 +367,14 @@ class CI_DB_driver { // -------------------------------------------------------------------- /** - * Simple Query + * Simple Query * This is a simplified version of the query() function. Internally * we only use it when running transaction commands since they do * not require all the features of the main query() function. - * + * * @access public * @param string the sql query - * @return mixed + * @return mixed */ function simple_query($sql) { @@ -391,9 +391,9 @@ class CI_DB_driver { /** * Disable Transactions * This permits transactions to be disabled at run-time. - * + * * @access public - * @return void + * @return void */ function trans_off() { @@ -404,9 +404,9 @@ class CI_DB_driver { /** * Start Transaction - * + * * @access public - * @return void + * @return void */ function trans_start($test_mode = FALSE) { @@ -429,9 +429,9 @@ class CI_DB_driver { /** * Complete Transaction - * + * * @access public - * @return bool + * @return bool */ function trans_complete() { @@ -467,9 +467,9 @@ class CI_DB_driver { /** * Lets you retrieve the transaction flag to determine if it has failed - * + * * @access public - * @return bool + * @return bool */ function trans_status() { @@ -480,11 +480,11 @@ class CI_DB_driver { /** * Compile Bindings - * + * * @access public * @param string the sql statement * @param array an array of bind data - * @return string + * @return string */ function compile_binds($sql, $binds) { @@ -514,15 +514,15 @@ class CI_DB_driver { // -------------------------------------------------------------------- /** - * Determines if a query is a "write" type. - * + * Determines if a query is a "write" type. + * * @access public * @param string An SQL query string - * @return boolean + * @return boolean */ function is_write_type($sql) { - if ( ! preg_match('/^\s*"?(INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql)) + if ( ! preg_match('/^\s*"?(INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql)) { return FALSE; } @@ -532,11 +532,11 @@ class CI_DB_driver { // -------------------------------------------------------------------- /** - * Calculate the aggregate query elapsed time - * + * Calculate the aggregate query elapsed time + * * @access public * @param integer The number of decimal places - * @return integer + * @return integer */ function elapsed_time($decimals = 6) { @@ -547,9 +547,9 @@ class CI_DB_driver { /** * Returns the total number of queries - * + * * @access public - * @return integer + * @return integer */ function total_queries() { @@ -560,9 +560,9 @@ class CI_DB_driver { /** * Returns the last query that was executed - * + * * @access public - * @return void + * @return void */ function last_query() { @@ -576,10 +576,10 @@ class CI_DB_driver { * * Escapes data based on type * Sets boolean and null types - * + * * @access public * @param string - * @return integer + * @return integer */ function escape($str) { @@ -605,10 +605,10 @@ class CI_DB_driver { * * Retrieves the primary key. It assumes that the row in the first * position is the primary key - * + * * @access public * @param string the table name - * @return string + * @return string */ function primary($table = '') { @@ -626,9 +626,9 @@ class CI_DB_driver { /** * Returns an array of table names - * + * * @access public - * @return array + * @return array */ function list_tables() { @@ -688,7 +688,7 @@ class CI_DB_driver { * * @access public * @param string the table name - * @return array + * @return array */ function list_fields($table = '') { @@ -754,7 +754,7 @@ class CI_DB_driver { /** * DEPRECATED - use list_fields() */ - function field_names($table = '') + function field_names($table = '') { return $this->list_fields($table); } @@ -763,10 +763,10 @@ class CI_DB_driver { /** * Returns an object with field data - * + * * @access public * @param string the table name - * @return object + * @return object */ function field_data($table = '') { @@ -787,18 +787,18 @@ class CI_DB_driver { /** * Generate an insert string - * + * * @access public * @param string the table upon which the query will be performed * @param array an associative array data of key/values - * @return string + * @return string */ function insert_string($table, $data) { - $fields = array(); + $fields = array(); $values = array(); - foreach($data as $key => $val) + foreach($data as $key => $val) { $fields[] = $key; $values[] = $this->escape($val); @@ -811,12 +811,12 @@ class CI_DB_driver { /** * Generate an update string - * + * * @access public * @param string the table upon which the query will be performed * @param array an associative array data of key/values * @param mixed the "where" statement - * @return string + * @return string */ function update_string($table, $data, $where) { @@ -824,7 +824,7 @@ class CI_DB_driver { return false; $fields = array(); - foreach($data as $key => $val) + foreach($data as $key => $val) { $fields[$key] = $this->escape($val); } @@ -861,11 +861,11 @@ class CI_DB_driver { /** * Enables a native PHP function to be run, using a platform agnostic wrapper. - * + * * @access public * @param string the function name * @param mixed any parameters needed by the function - * @return mixed + * @return mixed */ function call_function($function) { @@ -877,7 +877,7 @@ class CI_DB_driver { } if ( ! function_exists($function)) - { + { if ($this->db_debug) { return $this->display_error('db_unsupported_function'); @@ -888,7 +888,7 @@ class CI_DB_driver { { $args = (func_num_args() > 1) ? array_splice(func_get_args(), 1) : null; - return call_user_func_array($function, $args); + return call_user_func_array($function, $args); } } @@ -999,16 +999,16 @@ class CI_DB_driver { /** * Close DB Connection - * + * * @access public - * @return void + * @return void */ function close() { if (is_resource($this->conn_id)) { $this->_close($this->conn_id); - } + } $this->conn_id = FALSE; } @@ -1016,14 +1016,14 @@ class CI_DB_driver { /** * Display an error message - * + * * @access public * @param string the error message * @param string any "swap" values * @param boolean whether to localize the message - * @return string sends the application/error_db.php template + * @return string sends the application/error_db.php template */ - function display_error($error = '', $swap = '', $native = FALSE) + function display_error($error = '', $swap = '', $native = FALSE) { $LANG = new CI_Language(); $LANG->load('db'); @@ -1048,7 +1048,7 @@ class CI_DB_driver { echo $error->show_error('An Error Was Encountered', $message, 'error_db'); exit; - } + } } diff --git a/system/database/DB_result.php b/system/database/DB_result.php index d02bfb96e..44f166d21 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -7,17 +7,17 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** * Database Result Class - * + * * This is the platform-independent result class. * This class will not be called directly. Rather, the adapter * class for the specific database will extend and instantiate it. @@ -38,10 +38,10 @@ class CI_DB_result { /** * Query result. Acts as a wrapper function for the following functions. - * + * * @access public * @param string can be "object" or "array" - * @return mixed either a result object or array + * @return mixed either a result object or array */ function result($type = 'object') { @@ -52,9 +52,9 @@ class CI_DB_result { /** * Query result. "object" version. - * + * * @access public - * @return object + * @return object */ function result_object() { @@ -70,7 +70,7 @@ class CI_DB_result { $this->_data_seek(0); while ($row = $this->_fetch_object()) - { + { $this->result_object[] = $row; } @@ -81,9 +81,9 @@ class CI_DB_result { /** * Query result. "array" version. - * + * * @access public - * @return array + * @return array */ function result_array() { @@ -110,10 +110,10 @@ class CI_DB_result { /** * Query result. Acts as a wrapper function for the following functions. - * + * * @access public * @param string can be "object" or "array" - * @return mixed either a result object or array + * @return mixed either a result object or array */ function row($n = 0, $type = 'object') { @@ -124,9 +124,9 @@ class CI_DB_result { /** * Returns a single result row - object version - * + * * @access public - * @return object + * @return object */ function row_object($n = 0) { @@ -149,9 +149,9 @@ class CI_DB_result { /** * Returns a single result row - array version - * + * * @access public - * @return array + * @return array */ function row_array($n = 0) { @@ -175,9 +175,9 @@ class CI_DB_result { /** * Returns the "first" row - * + * * @access public - * @return object + * @return object */ function first_row($type = 'object') { @@ -194,9 +194,9 @@ class CI_DB_result { /** * Returns the "last" row - * + * * @access public - * @return object + * @return object */ function last_row($type = 'object') { @@ -213,9 +213,9 @@ class CI_DB_result { /** * Returns the "next" row - * + * * @access public - * @return object + * @return object */ function next_row($type = 'object') { @@ -238,9 +238,9 @@ class CI_DB_result { /** * Returns the "previous" row - * + * * @access public - * @return object + * @return object */ function previous_row($type = 'object') { @@ -261,11 +261,11 @@ class CI_DB_result { // -------------------------------------------------------------------- /** - * The following functions are normally overloaded by the identically named + * The following functions are normally overloaded by the identically named * methods in the platform-specific driver -- except when query caching * is used. When caching is enabled we do not load the other driver. * These functions are primarily here to prevent undefined function errors - * when a cached result object is in use. They are not otherwise fully + * when a cached result object is in use. They are not otherwise fully * operational due to the unavailability of the database resource IDs with * cached results. */ diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 13fcaa5c9..e64e008bc 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource @@ -302,7 +302,7 @@ class CI_DB_utility { } $xml .= $tab."".$newline; } - $xml .= "".$newline; + $xml .= "".$newline; return $xml; } @@ -371,13 +371,13 @@ class CI_DB_utility { // Is the encoder supported? If not, we'll either issue an // error or use plain text depending on the debug settings - if (($prefs['format'] == 'gzip' AND ! @function_exists('gzencode')) - OR ($prefs['format'] == 'zip' AND ! @function_exists('gzcompress'))) + if (($prefs['format'] == 'gzip' AND ! @function_exists('gzencode')) + OR ($prefs['format'] == 'zip' AND ! @function_exists('gzcompress'))) { - if ($this->db->db_debug) - { + if ($this->db->db_debug) + { return $this->db->display_error('db_unsuported_compression'); - } + } $prefs['format'] = 'txt'; } diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 4dc8792ca..a1d7d29ed 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -106,18 +106,18 @@ class CI_DB_mssql_driver extends CI_DB { * @param string an SQL query * @return string */ - function _prep_query($sql) - { + function _prep_query($sql) + { return $sql; - } + } // -------------------------------------------------------------------- /** * Begin Transaction - * + * * @access public - * @return bool + * @return bool */ function trans_begin($test_mode = FALSE) { @@ -133,8 +133,8 @@ class CI_DB_mssql_driver extends CI_DB { } // Reset the transaction failure flag. - // If the $test_mode flag is set to TRUE transactions will be rolled back - // even if the queries produce a successful result. + // 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('BEGIN TRAN'); @@ -145,9 +145,9 @@ class CI_DB_mssql_driver extends CI_DB { /** * Commit Transaction - * + * * @access public - * @return bool + * @return bool */ function trans_commit() { @@ -170,9 +170,9 @@ class CI_DB_mssql_driver extends CI_DB { /** * Rollback Transaction - * + * * @access public - * @return bool + * @return bool */ function trans_rollback() { diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index 0ba0b8c57..230c1b55b 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -65,7 +65,7 @@ class CI_DB_mssql_result extends CI_DB_result { $field_names = array(); while ($field = mssql_fetch_field($this->result_id)) { - $field_names[] = $field->name; + $field_names[] = $field->name; } return $field_names; @@ -116,8 +116,8 @@ class CI_DB_mssql_result extends CI_DB_result { { if (is_resource($this->result_id)) { - mssql_free_result($this->result_id); - $this->result_id = FALSE; + mssql_free_result($this->result_id); + $this->result_id = FALSE; } } diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index 24ff1e13c..4a49f533e 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -74,7 +74,7 @@ class CI_DB_mssql_utility extends CI_DB_utility { */ function _list_databases() { - return "EXEC sp_helpdb"; // Can also be: EXEC sp_databases + return "EXEC sp_helpdb"; // Can also be: EXEC sp_databases } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 20311ffa0..be7c672f7 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -32,10 +32,10 @@ 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, + * of affected rows to be shown. Uses a preg_replace when enabled, * adding a bit more processing to all queries. */ - var $delete_hack = TRUE; + var $delete_hack = TRUE; /** * Non-persistent database connection @@ -113,28 +113,28 @@ class CI_DB_mysql_driver extends CI_DB { * @param string an SQL query * @return string */ - function _prep_query($sql) - { - // "DELETE FROM TABLE" returns 0 affected rows This hack modifies + function _prep_query($sql) + { + // "DELETE FROM TABLE" returns 0 affected rows This hack modifies // the query so that it returns the number of affected rows if ($this->delete_hack === TRUE) { - if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql)) + if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql)) { $sql = preg_replace("/^\s*DELETE\s+FROM\s+(\S+)\s*$/", "DELETE FROM \\1 WHERE 1=1", $sql); } } return $sql; - } - + } + // -------------------------------------------------------------------- /** * Begin Transaction - * + * * @access public - * @return bool + * @return bool */ function trans_begin($test_mode = FALSE) { @@ -150,8 +150,8 @@ class CI_DB_mysql_driver extends CI_DB { } // Reset the transaction failure flag. - // If the $test_mode flag is set to TRUE transactions will be rolled back - // even if the queries produce a successful result. + // 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'); @@ -163,9 +163,9 @@ class CI_DB_mysql_driver extends CI_DB { /** * Commit Transaction - * + * * @access public - * @return bool + * @return bool */ function trans_commit() { @@ -189,9 +189,9 @@ class CI_DB_mysql_driver extends CI_DB { /** * Rollback Transaction - * + * * @access public - * @return bool + * @return bool */ function trans_rollback() { @@ -227,8 +227,8 @@ class CI_DB_mysql_driver extends CI_DB { return $str; } - if (function_exists('mysql_real_escape_string')) - { + if (function_exists('mysql_real_escape_string')) + { return mysql_real_escape_string($str, $this->conn_id); } elseif (function_exists('mysql_escape_string')) @@ -237,8 +237,8 @@ class CI_DB_mysql_driver extends CI_DB { } else { - return addslashes($str); - } + return addslashes($str); + } } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index 1cf6ff188..4bfaf54a4 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource @@ -65,7 +65,7 @@ class CI_DB_mysql_result extends CI_DB_result { $field_names = array(); while ($field = mysql_fetch_field($this->result_id)) { - $field_names[] = $field->name; + $field_names[] = $field->name; } return $field_names; @@ -116,8 +116,8 @@ class CI_DB_mysql_result extends CI_DB_result { { if (is_resource($this->result_id)) { - mysql_free_result($this->result_id); - $this->result_id = FALSE; + mysql_free_result($this->result_id); + $this->result_id = FALSE; } } diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index b387ace9e..b0a7dfea7 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource @@ -129,39 +129,39 @@ class CI_DB_mysql_utility extends CI_DB_utility { // Build the output $output = ''; - foreach ((array)$tables as $table) - { - // Is the table in the "ignore" list? + foreach ((array)$tables as $table) + { + // Is the table in the "ignore" list? if (in_array($table, (array)$ignore, TRUE)) { - continue; - } + continue; + } - // Get the table schema + // 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 ($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; + $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 ($i++ % 2) + { + $output .= $val.';'.$newline.$newline; + } } // If inserts are not needed we're done... @@ -179,7 +179,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { } // Fetch the field names and determine if the field is an - // integer type. We use this info to decide whether to + // integer type. We use this info to decide whether to // surround the data with quotes or not $i = 0; @@ -188,13 +188,13 @@ class CI_DB_mysql_utility extends CI_DB_utility { while ($field = mysql_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'), + 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.', '; + $field_str .= $field->name.', '; $i++; } @@ -211,8 +211,8 @@ class CI_DB_mysql_utility extends CI_DB_utility { 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(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); diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index ea2adbea9..59420912f 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -32,10 +32,10 @@ class CI_DB_mysqli_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, + * of affected rows to be shown. Uses a preg_replace when enabled, * adding a bit more processing to all queries. */ - var $delete_hack = TRUE; + var $delete_hack = TRUE; // -------------------------------------------------------------------- @@ -116,28 +116,28 @@ class CI_DB_mysqli_driver extends CI_DB { * @param string an SQL query * @return string */ - function _prep_query($sql) - { - // "DELETE FROM TABLE" returns 0 affected rows This hack modifies + function _prep_query($sql) + { + // "DELETE FROM TABLE" returns 0 affected rows This hack modifies // the query so that it returns the number of affected rows if ($this->delete_hack === TRUE) { - if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql)) + if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql)) { $sql = preg_replace("/^\s*DELETE\s+FROM\s+(\S+)\s*$/", "DELETE FROM \\1 WHERE 1=1", $sql); } } return $sql; - } + } // -------------------------------------------------------------------- /** * Begin Transaction - * + * * @access public - * @return bool + * @return bool */ function trans_begin($test_mode = FALSE) { @@ -153,8 +153,8 @@ class CI_DB_mysqli_driver extends CI_DB { } // Reset the transaction failure flag. - // If the $test_mode flag is set to TRUE transactions will be rolled back - // even if the queries produce a successful result. + // 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'); @@ -166,9 +166,9 @@ class CI_DB_mysqli_driver extends CI_DB { /** * Commit Transaction - * + * * @access public - * @return bool + * @return bool */ function trans_commit() { @@ -192,9 +192,9 @@ class CI_DB_mysqli_driver extends CI_DB { /** * Rollback Transaction - * + * * @access public - * @return bool + * @return bool */ function trans_rollback() { diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index 215403e9d..5e4e65ff7 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -65,7 +65,7 @@ class CI_DB_mysqli_result extends CI_DB_result { $field_names = array(); while ($field = mysql_fetch_field($this->result_id)) { - $field_names[] = $field->name; + $field_names[] = $field->name; } return $field_names; @@ -116,8 +116,8 @@ class CI_DB_mysqli_result extends CI_DB_result { { if (is_resource($this->result_id)) { - mysqli_free_result($this->result_id); - $this->result_id = FALSE; + mysqli_free_result($this->result_id); + $this->result_id = FALSE; } } diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 17af40b76..a7bdb708e 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -129,39 +129,39 @@ class CI_DB_mysqli_utility extends CI_DB_utility { // Build the output $output = ''; - foreach ((array)$tables as $table) - { - // Is the table in the "ignore" list? + foreach ((array)$tables as $table) + { + // Is the table in the "ignore" list? if (in_array($table, (array)$ignore, TRUE)) { - continue; - } + continue; + } - // Get the table schema + // 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 ($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; + $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 ($i++ % 2) + { + $output .= $val.';'.$newline.$newline; + } } // If inserts are not needed we're done... @@ -179,7 +179,7 @@ class CI_DB_mysqli_utility extends CI_DB_utility { } // Fetch the field names and determine if the field is an - // integer type. We use this info to decide whether to + // integer type. We use this info to decide whether to // surround the data with quotes or not $i = 0; @@ -188,13 +188,13 @@ class CI_DB_mysqli_utility extends CI_DB_utility { 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'), + 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.', '; + $field_str .= $field->name.', '; $i++; } @@ -211,8 +211,8 @@ class CI_DB_mysqli_utility extends CI_DB_utility { 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(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); diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 4f5470c1a..c091edf64 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -4,12 +4,12 @@ * * An open source application development framework for PHP 4.3.2 or newer * - * @package CodeIgniter - * @author Rick Ellis + * @package CodeIgniter + * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html - * @link http://www.codeigniter.com - * @since Version 1.0 + * @license http://www.codeignitor.com/user_guide/license.html + * @link http://www.codeigniter.com + * @since Version 1.0 * @filesource */ @@ -22,182 +22,182 @@ * creates dynamically based on whether the active record * class is being used or not. * - * @package CodeIgniter + * @package CodeIgniter * @subpackage Drivers - * @category Database - * @author Rick Ellis - * @link http://www.codeigniter.com/user_guide/database/ + * @category Database + * @author Rick Ellis + * @link http://www.codeigniter.com/user_guide/database/ */ /** * oci8 Database Adapter Class * - * This is a modification of the DB_driver class to + * This is a modification of the DB_driver class to * permit access to oracle databases * * NOTE: this uses the PHP 4 oci methods * - * @author Kelly McArdle + * @author Kelly McArdle * */ class CI_DB_oci8_driver extends CI_DB { // Set "auto commit" by default - var $_commit = OCI_COMMIT_ON_SUCCESS; - - // need to track statement id and cursor id - var $stmt_id; - var $curs_id; - - // if we use a limit, we will add a field that will - // throw off num_fields later - var $limit_used; - - /** - * Non-persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_connect() - { - return ocilogon($this->username, $this->password, $this->hostname); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return ociplogon($this->username, $this->password, $this->hostname); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - return TRUE; - } + var $_commit = OCI_COMMIT_ON_SUCCESS; + + // need to track statement id and cursor id + var $stmt_id; + var $curs_id; + + // if we use a limit, we will add a field that will + // throw off num_fields later + var $limit_used; + + /** + * Non-persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_connect() + { + return ocilogon($this->username, $this->password, $this->hostname); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return ociplogon($this->username, $this->password, $this->hostname); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return ociserverversion($this->conn_id); + } // -------------------------------------------------------------------- - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return ociserverversion($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return resource - */ - function _execute($sql) - { - // oracle must parse the query before it is run. All of the actions with - // the query are based on the statement id returned by ociparse - $this->_set_stmt_id($sql); - ocisetprefetch($this->stmt_id, 1000); - return @ociexecute($this->stmt_id, $this->_commit); - } - - /** - * Generate a statement ID - * - * @access private - * @param string an SQL query - * @return none - */ - function _set_stmt_id($sql) - { - if ( ! is_resource($this->stmt_id)) - { + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + function _execute($sql) + { + // oracle must parse the query before it is run. All of the actions with + // the query are based on the statement id returned by ociparse + $this->_set_stmt_id($sql); + ocisetprefetch($this->stmt_id, 1000); + return @ociexecute($this->stmt_id, $this->_commit); + } + + /** + * Generate a statement ID + * + * @access private + * @param string an SQL query + * @return none + */ + function _set_stmt_id($sql) + { + if ( ! is_resource($this->stmt_id)) + { $this->stmt_id = ociparse($this->conn_id, $this->_prep_query($sql)); - } - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @access private called by execute() - * @param string an SQL query - * @return string - */ - function _prep_query($sql) - { - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * getCursor. Returns a cursor from the datbase - * - * @access public - * @return cursor id - */ - function get_cursor() - { + } + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @access private called by execute() + * @param string an SQL query + * @return string + */ + function _prep_query($sql) + { + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * getCursor. Returns a cursor from the datbase + * + * @access public + * @return cursor id + */ + function get_cursor() + { $this->curs_id = ocinewcursor($this->conn_id); return $this->curs_id; - } - - // -------------------------------------------------------------------- - - /** - * Stored Procedure. Executes a stored procedure - * - * @access public - * @param package package stored procedure is in - * @param procedure stored procedure to execute - * @param params array of parameters - * @return array - * - * params array keys - * - * KEY OPTIONAL NOTES - * name no the name of the parameter should be in : format - * value no the value of the parameter. If this is an OUT or IN OUT parameter, - * this should be a reference to a variable - * type yes the type of the parameter - * length yes the max size of the parameter - */ - function stored_procedure($package, $procedure, $params) - { - if ($package == '' OR $procedure == '' OR ! is_array($params)) - { - if ($this->db_debug) - { - log_message('error', 'Invalid query: '.$package.'.'.$procedure); - return $this->display_error('db_invalid_query'); - } - return FALSE; - } + } + + // -------------------------------------------------------------------- + + /** + * Stored Procedure. Executes a stored procedure + * + * @access public + * @param package package stored procedure is in + * @param procedure stored procedure to execute + * @param params array of parameters + * @return array + * + * params array keys + * + * KEY OPTIONAL NOTES + * name no the name of the parameter should be in : format + * value no the value of the parameter. If this is an OUT or IN OUT parameter, + * this should be a reference to a variable + * type yes the type of the parameter + * length yes the max size of the parameter + */ + function stored_procedure($package, $procedure, $params) + { + if ($package == '' OR $procedure == '' OR ! is_array($params)) + { + if ($this->db_debug) + { + log_message('error', 'Invalid query: '.$package.'.'.$procedure); + return $this->display_error('db_invalid_query'); + } + return FALSE; + } // build the query string $sql = "begin $package.$procedure("; @@ -216,18 +216,18 @@ class CI_DB_oci8_driver extends CI_DB { $this->stmt_id = FALSE; $this->_set_stmt_id($sql); - $this->_bind_params($params); + $this->_bind_params($params); $this->query($sql, FALSE, $have_cursor); } - // -------------------------------------------------------------------- - - /** - * Bind parameters - * - * @access private - * @return none - */ + // -------------------------------------------------------------------- + + /** + * Bind parameters + * + * @access private + * @return none + */ function _bind_params($params) { if ( ! is_array($params) OR ! is_resource($this->stmt_id)) @@ -235,27 +235,27 @@ class CI_DB_oci8_driver extends CI_DB { return; } - foreach ($params as $param) - { + foreach ($params as $param) + { foreach (array('name', 'value', 'type', 'length') as $val) - { - if ( ! isset($param[$val])) - { - $param[$val] = ''; - } - } - + { + if ( ! isset($param[$val])) + { + $param[$val] = ''; + } + } + ocibindbyname($this->stmt_id, $param['name'], $param['value'], $param['length'], $param['type']); - } + } } // -------------------------------------------------------------------- /** * Begin Transaction - * + * * @access public - * @return bool + * @return bool */ function trans_begin($test_mode = FALSE) { @@ -271,8 +271,8 @@ class CI_DB_oci8_driver extends CI_DB { } // Reset the transaction failure flag. - // If the $test_mode flag is set to TRUE transactions will be rolled back - // even if the queries produce a successful result. + // 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->_commit = OCI_DEFAULT; @@ -283,9 +283,9 @@ class CI_DB_oci8_driver extends CI_DB { /** * Commit Transaction - * + * * @access public - * @return bool + * @return bool */ function trans_commit() { @@ -309,9 +309,9 @@ class CI_DB_oci8_driver extends CI_DB { /** * Rollback Transaction - * + * * @access public - * @return bool + * @return bool */ function trans_rollback() { @@ -331,272 +331,272 @@ class CI_DB_oci8_driver extends CI_DB { return $ret; } - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @return string - */ - function escape_str($str) - { - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @ocirowcount($this->stmt_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - // not supported in oracle - return 0; - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - return '0'; - - $query = $this->query("SELECT COUNT(1) AS numrows FROM ".$table); - - if ($query == FALSE) - { - return 0; - } - - $row = $query->row(); - return $row->NUMROWS; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SELECT TABLE_NAME FROM ALL_TABLES"; - } - - // -------------------------------------------------------------------- - - /** - * Show column query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _list_columns($table = '') - { - return "SELECT COLUMN_NAME FROM all_tab_columns WHERE table_name = '$table'"; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @ocirowcount($this->stmt_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + // not supported in oracle + return 0; + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + return '0'; + + $query = $this->query("SELECT COUNT(1) AS numrows FROM ".$table); + + if ($query == FALSE) + { + return 0; + } + + $row = $query->row(); + return $row->NUMROWS; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SELECT TABLE_NAME FROM ALL_TABLES"; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _list_columns($table = '') + { + return "SELECT COLUMN_NAME FROM all_tab_columns WHERE table_name = '$table'"; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { return "SELECT * FROM ".$this->_escape_table($table)." where rownum = 1"; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access private - * @return string - */ - function _error_message() - { - $error = ocierror($this->conn_id); - return $error['message']; - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access private - * @return integer - */ - function _error_number() - { - $error = ocierror($this->conn_id); - return $error['code']; - } - - // -------------------------------------------------------------------- - - /** - * Escape Table Name - * - * This function adds backticks if the table name has a period - * in it. Some DBs will get cranky unless periods are escaped - * - * @access private - * @param string the table name - * @return string - */ - function _escape_table($table) - { - if (stristr($table, '.')) - { - $table = preg_replace("/\./", "`.`", $table); - } - - return $table; - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @return string - */ - function _update($table, $values, $where) - { - foreach($values as $key => $val) - { - $valstr[] = $key." = ".$val; - } - - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @return string - */ - function _delete($table, $where) - { - return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - $limit = $offset + $limit; - $newsql = "SELECT * FROM (select inner_query.*, rownum rnum FROM ($sql) inner_query WHERE rownum < $limit)"; - - if ($offset != 0) - { - $newsql .= " WHERE rnum >= $offset"; - } - - // remember that we used limits - $this->limit_used = TRUE; - - return $newsql; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - ocilogoff($conn_id); - } + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access private + * @return string + */ + function _error_message() + { + $error = ocierror($this->conn_id); + return $error['message']; + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access private + * @return integer + */ + function _error_number() + { + $error = ocierror($this->conn_id); + return $error['code']; + } + + // -------------------------------------------------------------------- + + /** + * Escape Table Name + * + * This function adds backticks if the table name has a period + * in it. Some DBs will get cranky unless periods are escaped + * + * @access private + * @param string the table name + * @return string + */ + function _escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $table; + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @return string + */ + function _update($table, $values, $where) + { + foreach($values as $key => $val) + { + $valstr[] = $key." = ".$val; + } + + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + $limit = $offset + $limit; + $newsql = "SELECT * FROM (select inner_query.*, rownum rnum FROM ($sql) inner_query WHERE rownum < $limit)"; + + if ($offset != 0) + { + $newsql .= " WHERE rnum >= $offset"; + } + + // remember that we used limits + $this->limit_used = TRUE; + + return $newsql; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + ocilogoff($conn_id); + } } diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index ab13a3935..947a76109 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -4,12 +4,12 @@ * * An open source application development framework for PHP 4.3.2 or newer * - * @package CodeIgniter - * @author Rick Ellis + * @package CodeIgniter + * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html - * @link http://www.codeigniter.com - * @since Version 1.0 + * @license http://www.codeignitor.com/user_guide/license.html + * @link http://www.codeigniter.com + * @since Version 1.0 * @filesource */ @@ -20,59 +20,59 @@ * * This class extends the parent result class: CI_DB_result * - * @category Database - * @author Rick Ellis - * @link http://www.codeigniter.com/user_guide/database/ + * @category Database + * @author Rick Ellis + * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_oci8_result extends CI_DB_result { - var $stmt_id; - var $curs_id; - var $limit_used; - - /** - * Number of rows in the result set - * - * @access public - * @return integer - */ - function num_rows() - { - // get the results, count them, - // rerun query - otherwise we - // won't have data after calling - // num_rows() - $this->result_array(); - $rowcount = count($this->result_array); - @ociexecute($this->stmt_id); - if ($this->curs_id) + var $stmt_id; + var $curs_id; + var $limit_used; + + /** + * Number of rows in the result set + * + * @access public + * @return integer + */ + function num_rows() + { + // get the results, count them, + // rerun query - otherwise we + // won't have data after calling + // num_rows() + $this->result_array(); + $rowcount = count($this->result_array); + @ociexecute($this->stmt_id); + if ($this->curs_id) { @ociexecute($this->curs_id); } - return $rowcount; - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - $count = @ocinumcols($this->stmt_id); - - // if we used a limit, we added a field, - // subtract it out - if ($this->limit_used) - { - $count = $count - 1; - } - - return $count; - } + return $rowcount; + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + $count = @ocinumcols($this->stmt_id); + + // if we used a limit, we added a field, + // subtract it out + if ($this->limit_used) + { + $count = $count - 1; + } + + return $count; + } // -------------------------------------------------------------------- @@ -87,11 +87,11 @@ class CI_DB_oci8_result extends CI_DB_result { function list_fields() { $field_names = array(); - $fieldCount = $this->num_fields(); - for ($c = 1; $c <= $fieldCount; $c++) - { - $field_names[] = ocicolumnname($this->stmt_id, $c); - } + $fieldCount = $this->num_fields(); + for ($c = 1; $c <= $fieldCount; $c++) + { + $field_names[] = ocicolumnname($this->stmt_id, $c); + } return $field_names; } @@ -101,32 +101,32 @@ class CI_DB_oci8_result extends CI_DB_result { return $this->list_fields(); } - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - function field_data() - { - $retval = array(); - $fieldCount = $this->num_fields(); - for ($c = 1; $c <= $fieldCount; $c++) - { - $F = new stdClass(); - $F->name = ocicolumnname($this->stmt_id, $c); - $F->type = ocicolumntype($this->stmt_id, $c); - $F->max_length = ocicolumnsize($this->stmt_id, $c); - - $retval[] = $F; - } - - return $retval; - } + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + $fieldCount = $this->num_fields(); + for ($c = 1; $c <= $fieldCount; $c++) + { + $F = new stdClass(); + $F->name = ocicolumnname($this->stmt_id, $c); + $F->type = ocicolumntype($this->stmt_id, $c); + $F->max_length = ocicolumnsize($this->stmt_id, $c); + + $retval[] = $F; + } + + return $retval; + } // -------------------------------------------------------------------- @@ -139,25 +139,25 @@ class CI_DB_oci8_result extends CI_DB_result { { if (is_resource($this->result_id)) { - OCIFreeStatement($this->result_id); - $this->result_id = FALSE; + OCIFreeStatement($this->result_id); + $this->result_id = FALSE; } } - // -------------------------------------------------------------------- - - /** - * Result - associative array - * - * Returns the result set as an array - * - * @access private - * @return array - */ - function _fetch_assoc(&$row) - { - // if pulling from a cursor, use curs_id - if ($this->curs_id) + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @access private + * @return array + */ + function _fetch_assoc(&$row) + { + // if pulling from a cursor, use curs_id + if ($this->curs_id) { return ocifetchinto($this->curs_id, $row, OCI_ASSOC + OCI_RETURN_NULLS); } @@ -165,7 +165,7 @@ class CI_DB_oci8_result extends CI_DB_result { { return ocifetchinto($this->stmt_id, $row, OCI_ASSOC + OCI_RETURN_NULLS); } - } + } // -------------------------------------------------------------------- @@ -184,25 +184,25 @@ class CI_DB_oci8_result extends CI_DB_result { return FALSE; } - // -------------------------------------------------------------------- - - /** - * Result - object - * - * Returns the result set as an object - * - * @access private - * @return object - */ - function _fetch_object() - { - // the PHP 4 version of the oracle functions do not - // have a fetch method so we call the array version - // and build an object from that - - $row = array(); - $res = $this->_fetch_assoc($row); - if ($res != FALSE) + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + function _fetch_object() + { + // the PHP 4 version of the oracle functions do not + // have a fetch method so we call the array version + // and build an object from that + + $row = array(); + $res = $this->_fetch_assoc($row); + if ($res != FALSE) { $obj = new stdClass(); foreach ($row as $key => $value) @@ -212,41 +212,41 @@ class CI_DB_oci8_result extends CI_DB_result { $res = $obj; } - return $res; - } - - // -------------------------------------------------------------------- - - /** - * Query result. "array" version. - * - * @access public - * @return array - */ - function result_array() - { - if (count($this->result_array) > 0) - { - return $this->result_array; - } - - // oracle's fetch functions do not - // return arrays, the information - // is returned in reference parameters - // - $row = NULL; - while ($this->_fetch_assoc($row)) - { - $this->result_array[] = $row; - } - - if (count($this->result_array) == 0) - { - return FALSE; - } - - return $this->result_array; - } + return $res; + } + + // -------------------------------------------------------------------- + + /** + * Query result. "array" version. + * + * @access public + * @return array + */ + function result_array() + { + if (count($this->result_array) > 0) + { + return $this->result_array; + } + + // oracle's fetch functions do not + // return arrays, the information + // is returned in reference parameters + // + $row = NULL; + while ($this->_fetch_assoc($row)) + { + $this->result_array[] = $row; + } + + if (count($this->result_array) == 0) + { + return FALSE; + } + + return $this->result_array; + } } diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index f4e912183..1d83af1fe 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 17a6dfbd0..09ca07ee4 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -21,7 +21,7 @@ * Note: _DB is an extender class that the app controller * creates dynamically based on whether the active record * class is being used or not. - * + * * @package CodeIgniter * @subpackage Drivers * @category Database @@ -107,18 +107,18 @@ class CI_DB_odbc_driver extends CI_DB { * @param string an SQL query * @return string */ - function _prep_query($sql) - { + function _prep_query($sql) + { return $sql; - } + } // -------------------------------------------------------------------- /** * Begin Transaction - * + * * @access public - * @return bool + * @return bool */ function trans_begin($test_mode = FALSE) { @@ -134,8 +134,8 @@ class CI_DB_odbc_driver extends CI_DB { } // Reset the transaction failure flag. - // If the $test_mode flag is set to TRUE transactions will be rolled back - // even if the queries produce a successful result. + // 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; return odbc_autocommit($this->conn_id, FALSE); @@ -145,9 +145,9 @@ class CI_DB_odbc_driver extends CI_DB { /** * Commit Transaction - * + * * @access public - * @return bool + * @return bool */ function trans_commit() { @@ -171,9 +171,9 @@ class CI_DB_odbc_driver extends CI_DB { /** * Rollback Transaction - * + * * @access public - * @return bool + * @return bool */ function trans_rollback() { diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index ea834f9b4..47fb103b3 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -116,8 +116,8 @@ class CI_DB_odbc_result extends CI_DB_result { { if (is_resource($this->result_id)) { - odbc_free_result($this->result_id); - $this->result_id = FALSE; + odbc_free_result($this->result_id); + $this->result_id = FALSE; } } diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index dc62df9f0..8af463b13 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -34,7 +34,7 @@ class CI_DB_odbc_utility extends CI_DB_utility { */ function _create_database() { - // ODBC has no "create database" command since it's + // ODBC has no "create database" command since it's // designed to connect to an existing database if ($this->db->db_debug) { @@ -54,7 +54,7 @@ class CI_DB_odbc_utility extends CI_DB_utility { */ function _drop_database($name) { - // ODBC has no "drop database" command since it's + // ODBC has no "drop database" command since it's // designed to connect to an existing database if ($this->db->db_debug) { diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index f74e652d5..81aaafe14 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -111,18 +111,18 @@ class CI_DB_postgre_driver extends CI_DB { * @param string an SQL query * @return string */ - function _prep_query($sql) - { + function _prep_query($sql) + { return $sql; - } + } // -------------------------------------------------------------------- /** * Begin Transaction - * + * * @access public - * @return bool + * @return bool */ function trans_begin($test_mode = FALSE) { @@ -138,8 +138,8 @@ class CI_DB_postgre_driver extends CI_DB { } // Reset the transaction failure flag. - // If the $test_mode flag is set to TRUE transactions will be rolled back - // even if the queries produce a successful result. + // 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; return @pg_exec($this->conn_id, "begin"); @@ -149,9 +149,9 @@ class CI_DB_postgre_driver extends CI_DB { /** * Commit Transaction - * + * * @access public - * @return bool + * @return bool */ function trans_commit() { @@ -173,9 +173,9 @@ class CI_DB_postgre_driver extends CI_DB { /** * Rollback Transaction - * + * * @access public - * @return bool + * @return bool */ function trans_rollback() { @@ -298,7 +298,7 @@ class CI_DB_postgre_driver extends CI_DB { * @return string */ function _list_tables() - { + { return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; } diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index e792544ae..76bd60187 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -116,8 +116,8 @@ class CI_DB_postgre_result extends CI_DB_result { { if (is_resource($this->result_id)) { - pg_free_result($this->result_id); - $this->result_id = FALSE; + pg_free_result($this->result_id); + $this->result_id = FALSE; } } diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index b08b879d7..478e74276 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -90,7 +90,7 @@ class CI_DB_postgre_utility extends CI_DB_utility { */ function _optimize_table($table) { - return FALSE; + return FALSE; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index fd9fd2c50..ce3c57935 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ @@ -44,10 +44,10 @@ class CI_DB_sqlite_driver extends CI_DB { { log_message('error', $error); - if ($this->db_debug) - { + if ($this->db_debug) + { $this->display_error($error, '', TRUE); - } + } } return $conn_id; @@ -67,10 +67,10 @@ class CI_DB_sqlite_driver extends CI_DB { { log_message('error', $error); - if ($this->db_debug) - { + if ($this->db_debug) + { $this->display_error($error, '', TRUE); - } + } } return $conn_id; @@ -128,18 +128,18 @@ class CI_DB_sqlite_driver extends CI_DB { * @param string an SQL query * @return string */ - function _prep_query($sql) - { + function _prep_query($sql) + { return $sql; - } + } // -------------------------------------------------------------------- /** * Begin Transaction - * + * * @access public - * @return bool + * @return bool */ function trans_begin($test_mode = FALSE) { @@ -155,8 +155,8 @@ class CI_DB_sqlite_driver extends CI_DB { } // Reset the transaction failure flag. - // If the $test_mode flag is set to TRUE transactions will be rolled back - // even if the queries produce a successful result. + // 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('BEGIN TRANSACTION'); @@ -167,9 +167,9 @@ class CI_DB_sqlite_driver extends CI_DB { /** * Commit Transaction - * + * * @access public - * @return bool + * @return bool */ function trans_commit() { @@ -192,9 +192,9 @@ class CI_DB_sqlite_driver extends CI_DB { /** * Rollback Transaction - * + * * @access public - * @return bool + * @return bool */ function trans_rollback() { diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index 55364bb24..00045d06c 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -7,19 +7,19 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** * SQLite Result Class * * This class extends the parent result class: CI_DB_result - * + * * @category Database * @author Rick Ellis * @link http://www.codeigniter.com/user_guide/database/ diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index ecce5be40..91649c78d 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -68,7 +68,7 @@ class CI_DB_sqlite_utility extends CI_DB_utility { * * I don't believe you can do a database listing with SQLite * since each database is its own file. I suppose we could - * try reading a directory looking for SQLite files, but + * try reading a directory looking for SQLite files, but * that doesn't seem like a terribly good idea * * @access private -- cgit v1.2.3-24-g4f1b From 36e644241623461d6ac9531bdc5a61ee40b28be4 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 22 Oct 2006 01:30:50 +0000 Subject: --- system/database/DB_driver.php | 2 +- system/database/DB_result.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index ab8a6a8e2..61f0d307f 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -234,9 +234,9 @@ class CI_DB_driver { { if ($this->_cache_init()) { + $this->load_rdriver(); if (FALSE !== ($cache = $this->CACHE->read($sql))) { - $this->load_rdriver(); return $cache; } } diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 44f166d21..7553c167f 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -63,7 +63,7 @@ class CI_DB_result { return $this->result_object; } - if ($this->numerous == 0) + if ($this->num_rows == 0) { return array(); } -- cgit v1.2.3-24-g4f1b From 7591faf97bc152e385a154ffdf3c6a75d6b74bc9 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 22 Oct 2006 03:13:22 +0000 Subject: --- system/database/DB_result.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 7553c167f..5c8b4c3ae 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -63,11 +63,14 @@ class CI_DB_result { return $this->result_object; } - if ($this->num_rows == 0) + // In the event that query caching is on the result_id variable + // will return FALSE since there isn't a valid SQL resource so + // we'll simply return an empty array. + if ($this->result_id === FALSE) { return array(); } - + $this->_data_seek(0); while ($row = $this->_fetch_object()) { @@ -92,7 +95,10 @@ class CI_DB_result { return $this->result_array; } - if ($this->num_rows == 0) + // In the event that query caching is on the result_id variable + // will return FALSE since there isn't a valid SQL resource so + // we'll simply return an empty array. + if ($this->result_id === FALSE) { return array(); } -- cgit v1.2.3-24-g4f1b From b6224a136c3fc2893e7f1bd3005959fab4008a47 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 23 Oct 2006 01:25:46 +0000 Subject: --- system/database/DB_utility.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index e64e008bc..d7018bf2b 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -235,7 +235,7 @@ class CI_DB_utility { $out = ''; // First generate the headings from the table column names - foreach ($query->field_names() as $name) + foreach ($query->list_fields() as $name) { $out .= $name.$delim; } -- cgit v1.2.3-24-g4f1b From c1e23ce329575d2777dc1c87b87c4b1171c4e18b Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 23 Oct 2006 20:49:27 +0000 Subject: --- system/database/DB_driver.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 61f0d307f..139dbf7db 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -596,8 +596,6 @@ class CI_DB_driver { return $str; } - - // -------------------------------------------------------------------- /** -- cgit v1.2.3-24-g4f1b From ca335fcd8342ec1422a63ac397a404e73766b0ef Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 23 Oct 2006 21:18:36 +0000 Subject: --- system/database/drivers/mssql/mssql_driver.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index a1d7d29ed..f8eea5b45 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -38,7 +38,7 @@ class CI_DB_mssql_driver extends CI_DB { */ function db_connect() { - return mssql_connect($this->hostname, $this->username, $this->password); + return @mssql_connect($this->hostname, $this->username, $this->password); } // -------------------------------------------------------------------- @@ -51,7 +51,7 @@ class CI_DB_mssql_driver extends CI_DB { */ function db_pconnect() { - return mssql_pconnect($this->hostname, $this->username, $this->password); + return @mssql_pconnect($this->hostname, $this->username, $this->password); } // -------------------------------------------------------------------- @@ -250,7 +250,7 @@ class CI_DB_mssql_driver extends CI_DB { if ($table == '') return '0'; - $query = $this->query("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + $query = $this->query("SELECT COUNT(*) AS numrows FROM ".$this->dbprefix.$table); if ($query->num_rows() == 0) return '0'; @@ -303,7 +303,7 @@ class CI_DB_mssql_driver extends CI_DB { */ function _field_data($table) { - return "SELECT TOP 1 FROM ".$this->_escape_table($table); + return "SELECT TOP 1 * FROM ".$this->_escape_table($table); } // -------------------------------------------------------------------- @@ -348,10 +348,14 @@ class CI_DB_mssql_driver extends CI_DB { */ function _escape_table($table) { + // I don't believe this is necessary with MS SQL. Not sure, though. - Rick + + /* if (stristr($table, '.')) { $table = preg_replace("/\./", "`.`", $table); } + */ return $table; } -- cgit v1.2.3-24-g4f1b From 7acd581d9441fb8ada4c46c58f4ec30a01507506 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 23 Oct 2006 21:37:22 +0000 Subject: --- system/database/DB_utility.php | 17 ++++++++++++++--- system/database/drivers/mysql/mysql_driver.php | 4 ++-- system/database/drivers/mysqli/mysqli_driver.php | 2 +- system/database/drivers/oci8/oci8_driver.php | 4 ++-- system/database/drivers/odbc/odbc_driver.php | 4 ++-- system/database/drivers/postgre/postgre_driver.php | 4 ++-- system/database/drivers/sqlite/sqlite_driver.php | 12 ++++++++---- 7 files changed, 31 insertions(+), 16 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index d7018bf2b..9533ec607 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -133,7 +133,11 @@ class CI_DB_utility { } $query = $this->db->query($sql); - return current($query->result_array()); + $res = $query->result_array(); + + // Note: Due to a bug in current() that affects some versions + // of PHP we can not pass function call directly into it + return current($res); } // -------------------------------------------------------------------- @@ -159,7 +163,10 @@ class CI_DB_utility { $query = $this->db->query($sql); // Build the result array... - $res = current($query->result_array()); + // Note: Due to a bug in current() that affects some versions + // of PHP we can not pass function call directly into it + $res = $query->result_array(); + $res = current($res); $key = str_replace($this->db->database.'.', '', current($res)); $keys = array_keys($res); unset($res[$keys[0]]); @@ -190,7 +197,11 @@ class CI_DB_utility { } $query = $this->db->query($sql); - return current($query->result_array()); + + // Note: Due to a bug in current() that affects some versions + // of PHP we can not pass function call directly into it + $res = $query->result_array(); + return current($res); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index be7c672f7..1afc2062b 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -45,7 +45,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function db_connect() { - return mysql_connect($this->hostname, $this->username, $this->password, TRUE); + return @mysql_connect($this->hostname, $this->username, $this->password, TRUE); } // -------------------------------------------------------------------- @@ -58,7 +58,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function db_pconnect() { - return mysql_pconnect($this->hostname, $this->username, $this->password); + return @mysql_pconnect($this->hostname, $this->username, $this->password); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 59420912f..3a0d3b562 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -47,7 +47,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ function db_connect() { - return mysqli_connect($this->hostname, $this->username, $this->password); + return @mysqli_connect($this->hostname, $this->username, $this->password); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index c091edf64..551a670fe 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -62,7 +62,7 @@ class CI_DB_oci8_driver extends CI_DB { */ function db_connect() { - return ocilogon($this->username, $this->password, $this->hostname); + return @ocilogon($this->username, $this->password, $this->hostname); } // -------------------------------------------------------------------- @@ -75,7 +75,7 @@ class CI_DB_oci8_driver extends CI_DB { */ function db_pconnect() { - return ociplogon($this->username, $this->password, $this->hostname); + return @ociplogon($this->username, $this->password, $this->hostname); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 09ca07ee4..4d1fac2ed 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -38,7 +38,7 @@ class CI_DB_odbc_driver extends CI_DB { */ function db_connect() { - return odbc_connect($this->database, $this->username, $this->password); + return @odbc_connect($this->database, $this->username, $this->password); } // -------------------------------------------------------------------- @@ -51,7 +51,7 @@ class CI_DB_odbc_driver extends CI_DB { */ function db_pconnect() { - return odbc_pconnect($this->database, $this->username, $this->password); + return @odbc_pconnect($this->database, $this->username, $this->password); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 81aaafe14..68fde01b1 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -40,7 +40,7 @@ class CI_DB_postgre_driver extends CI_DB { { $port = ($this->port == '') ? '' : " port=".$this->port; - return pg_connect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); + return @pg_connect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); } // -------------------------------------------------------------------- @@ -55,7 +55,7 @@ class CI_DB_postgre_driver extends CI_DB { { $port = ($this->port == '') ? '' : " port=".$this->port; - return pg_pconnect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); + return @pg_pconnect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index ce3c57935..3f71b3536 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -40,14 +40,16 @@ class CI_DB_sqlite_driver extends CI_DB { */ function db_connect() { - if ( ! $conn_id = sqlite_open($this->database, 0666, $error)) + if ( ! $conn_id = @sqlite_open($this->database, 0666, $error)) { log_message('error', $error); if ($this->db_debug) { $this->display_error($error, '', TRUE); - } + } + + return FALSE; } return $conn_id; @@ -63,14 +65,16 @@ class CI_DB_sqlite_driver extends CI_DB { */ function db_pconnect() { - if ( ! $conn_id = sqlite_popen($this->database, 0666, $error)) + if ( ! $conn_id = @sqlite_popen($this->database, 0666, $error)) { log_message('error', $error); if ($this->db_debug) { $this->display_error($error, '', TRUE); - } + } + + return FALSE; } return $conn_id; -- cgit v1.2.3-24-g4f1b From 25701d75807a3fc8707c8afdb5d43062acfcf88e Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 24 Oct 2006 22:34:33 +0000 Subject: --- system/database/DB_driver.php | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 139dbf7db..d08e47f26 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -97,6 +97,7 @@ class CI_DB_driver { 'username' => '', 'password' => '', 'database' => '', + 'conn_id' => FALSE, 'dbdriver' => 'mysql', 'dbprefix' => '', 'port' => '', @@ -130,9 +131,17 @@ class CI_DB_driver { $this->database = ( ! isset($dsn['path'])) ? '' : rawurldecode(substr($dsn['path'], 1)); } + // If an existing DB connection resource is supplied + // there is no need to connect and select the database + if (is_resource($this->conn_id)) + { + return TRUE; + } + // Connect to the database $this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect(); - + + // No connection? Throw an error if ( ! $this->conn_id) { log_message('error', 'Unable to connect to the database'); @@ -141,19 +150,22 @@ class CI_DB_driver { { $this->display_error('db_unable_to_connect'); } + return FALSE; } - else + + // Select the database + if ( ! $this->db_select()) { - if ( ! $this->db_select()) + log_message('error', 'Unable to select database: '.$this->database); + + if ($this->db_debug) { - log_message('error', 'Unable to select database: '.$this->database); - - if ($this->db_debug) - { - $this->display_error('db_unable_to_select', $this->database); - } - } - } + $this->display_error('db_unable_to_select', $this->database); + } + return FALSE; + } + + return TRUE; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 1716cb80344dcb09dd263293b7901cd5b669e302 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 25 Oct 2006 05:12:34 +0000 Subject: --- system/database/DB_result.php | 6 +++--- system/database/drivers/mssql/mssql_result.php | 2 +- system/database/drivers/mssql/mssql_utility.php | 2 +- system/database/drivers/mysql/mysql_result.php | 2 +- system/database/drivers/mysql/mysql_utility.php | 2 +- system/database/drivers/mysqli/mysqli_result.php | 2 +- system/database/drivers/mysqli/mysqli_utility.php | 2 +- system/database/drivers/postgre/postgre_result.php | 2 +- system/database/drivers/postgre/postgre_utility.php | 2 +- system/database/drivers/sqlite/sqlite_result.php | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 5c8b4c3ae..9784561d4 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -66,11 +66,11 @@ class CI_DB_result { // In the event that query caching is on the result_id variable // will return FALSE since there isn't a valid SQL resource so // we'll simply return an empty array. - if ($this->result_id === FALSE) + if ($this->result_id === FALSE OR $this->num_rows() == 0) { return array(); } - + $this->_data_seek(0); while ($row = $this->_fetch_object()) { @@ -98,7 +98,7 @@ class CI_DB_result { // In the event that query caching is on the result_id variable // will return FALSE since there isn't a valid SQL resource so // we'll simply return an empty array. - if ($this->result_id === FALSE) + if ($this->result_id === FALSE OR $this->num_rows() == 0) { return array(); } diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index 230c1b55b..eb7afef70 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -135,7 +135,7 @@ class CI_DB_mssql_result extends CI_DB_result { */ function _data_seek($n = 0) { - mssql_data_seek($this->result_id, $n); + return mssql_data_seek($this->result_id, $n); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index 4a49f533e..b24646123 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -61,7 +61,7 @@ class CI_DB_mssql_utility extends CI_DB_utility { */ function _drop_table($table) { - return "DROP TABLE ".$this->db->_escape_table($name); + return "DROP TABLE ".$this->db->_escape_table($table); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index 4bfaf54a4..9b28dead7 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -135,7 +135,7 @@ class CI_DB_mysql_result extends CI_DB_result { */ function _data_seek($n = 0) { - mysql_data_seek($this->result_id, $n); + return mysql_data_seek($this->result_id, $n); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index b0a7dfea7..32007d224 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -73,7 +73,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { */ function _drop_table($table) { - return "DROP TABLE IF EXISTS ".$this->db->_escape_table($name); + return "DROP TABLE IF EXISTS ".$this->db->_escape_table($table); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index 5e4e65ff7..be7ec356c 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -135,7 +135,7 @@ class CI_DB_mysqli_result extends CI_DB_result { */ function _data_seek($n = 0) { - mysqli_data_seek($this->result_id, $n); + return mysqli_data_seek($this->result_id, $n); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index a7bdb708e..d5dbf2fb0 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -60,7 +60,7 @@ class CI_DB_mysqli_utility extends CI_DB_utility { */ function _drop_table($table) { - return "DROP TABLE IF EXISTS ".$this->db->_escape_table($name); + return "DROP TABLE IF EXISTS ".$this->db->_escape_table($table); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index 76bd60187..f065e54fb 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -135,7 +135,7 @@ class CI_DB_postgre_result extends CI_DB_result { */ function _data_seek($n = 0) { - pg_result_seek($this->result_id, $n); + return pg_result_seek($this->result_id, $n); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 478e74276..bebe09415 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -74,7 +74,7 @@ class CI_DB_postgre_utility extends CI_DB_utility { */ function _drop_table($table) { - return "DROP TABLE ".$this->db->_escape_table($name)." CASCADE"; + return "DROP TABLE ".$this->db->_escape_table($table)." CASCADE"; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index 00045d06c..a406a935c 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -131,7 +131,7 @@ class CI_DB_sqlite_result extends CI_DB_result { */ function _data_seek($n = 0) { - sqlite_seek($this->result_id, $n); + return sqlite_seek($this->result_id, $n); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From befd4c226950dfe7fae260961355787bb1bf29a9 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 26 Oct 2006 01:49:26 +0000 Subject: --- system/database/drivers/mssql/mssql_driver.php | 2 +- system/database/drivers/mysql/mysql_driver.php | 2 +- system/database/drivers/mysqli/mysqli_driver.php | 2 +- system/database/drivers/oci8/oci8_driver.php | 2 +- system/database/drivers/odbc/odbc_driver.php | 2 +- system/database/drivers/postgre/postgre_driver.php | 2 +- system/database/drivers/sqlite/sqlite_driver.php | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index f8eea5b45..47cfa6bbe 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -449,7 +449,7 @@ class CI_DB_mssql_driver extends CI_DB { */ function _close($conn_id) { - mssql_close($conn_id); + @mssql_close($conn_id); } } diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 1afc2062b..2104b9abd 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -484,7 +484,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function _close($conn_id) { - mysql_close($conn_id); + @mysql_close($conn_id); } } diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 3a0d3b562..f8d3acf20 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -474,7 +474,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ function _close($conn_id) { - mysqli_close($conn_id); + @mysqli_close($conn_id); } diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 551a670fe..ff301a57d 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -595,7 +595,7 @@ class CI_DB_oci8_driver extends CI_DB { */ function _close($conn_id) { - ocilogoff($conn_id); + @ocilogoff($conn_id); } diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 4d1fac2ed..7dd9295fc 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -443,7 +443,7 @@ class CI_DB_odbc_driver extends CI_DB { */ function _close($conn_id) { - odbc_close($conn_id); + @odbc_close($conn_id); } diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 68fde01b1..a66fddbdf 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -476,7 +476,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function _close($conn_id) { - pg_close($conn_id); + @pg_close($conn_id); } diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 3f71b3536..877f445bb 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -475,7 +475,7 @@ class CI_DB_sqlite_driver extends CI_DB { */ function _close($conn_id) { - sqlite_close($conn_id); + @sqlite_close($conn_id); } -- cgit v1.2.3-24-g4f1b From 3f643e678ef64ae29aa9720aef9b2a40496a5343 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 27 Oct 2006 06:25:31 +0000 Subject: --- system/database/drivers/oci8/oci8_result.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 947a76109..efb2f7bed 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -38,18 +38,14 @@ class CI_DB_oci8_result extends CI_DB_result { */ function num_rows() { - // get the results, count them, - // rerun query - otherwise we - // won't have data after calling - // num_rows() - $this->result_array(); - $rowcount = count($this->result_array); - @ociexecute($this->stmt_id); - if ($this->curs_id) + if (function_exists('oci_num_rows')) + { + return @oci_num_rows($this->stmt_id); + } + else { - @ociexecute($this->curs_id); + return @ocirowcount($this->stmt_id) } - return $rowcount; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 259ea846018b3c465d3b9c3283a6142a5c342191 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 27 Oct 2006 17:56:58 +0000 Subject: --- system/database/drivers/oci8/oci8_result.php | 104 ++++++++++++++------------- 1 file changed, 54 insertions(+), 50 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index efb2f7bed..af30457b3 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -44,7 +44,7 @@ class CI_DB_oci8_result extends CI_DB_result { } else { - return @ocirowcount($this->stmt_id) + return @ocirowcount($this->stmt_id); } } @@ -60,8 +60,7 @@ class CI_DB_oci8_result extends CI_DB_result { { $count = @ocinumcols($this->stmt_id); - // if we used a limit, we added a field, - // subtract it out + // if we used a limit we subtract it if ($this->limit_used) { $count = $count - 1; @@ -135,7 +134,7 @@ class CI_DB_oci8_result extends CI_DB_result { { if (is_resource($this->result_id)) { - OCIFreeStatement($this->result_id); + ocifreestatement($this->result_id); $this->result_id = FALSE; } } @@ -152,32 +151,9 @@ class CI_DB_oci8_result extends CI_DB_result { */ function _fetch_assoc(&$row) { - // if pulling from a cursor, use curs_id - if ($this->curs_id) - { - return ocifetchinto($this->curs_id, $row, OCI_ASSOC + OCI_RETURN_NULLS); - } - else - { - return ocifetchinto($this->stmt_id, $row, OCI_ASSOC + OCI_RETURN_NULLS); - } - } - - // -------------------------------------------------------------------- - - /** - * Data Seek - * - * Moves the internal pointer to the desired offset. We call - * this internally before fetching results to make sure the - * result set starts at zero - * - * @access private - * @return array - */ - function _data_seek($n = 0) - { - return FALSE; + $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; + + return ocifetchinto($id, $row, OCI_ASSOC + OCI_RETURN_NULLS); } // -------------------------------------------------------------------- @@ -191,24 +167,42 @@ class CI_DB_oci8_result extends CI_DB_result { * @return object */ function _fetch_object() - { - // the PHP 4 version of the oracle functions do not - // have a fetch method so we call the array version - // and build an object from that + { + $result = array(); - $row = array(); - $res = $this->_fetch_assoc($row); - if ($res != FALSE) + // If PHP 5 is being used we can fetch an result object + if (function_exists('oci_fetch_object')) + { + $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; + + while ($row = oci_fetch_object($id)) + { + $result[] = $row; + } + + return $result; + } + + // If PHP 4 is being used we have to build our own result + foreach ($this->result_array() as $key => $val) { $obj = new stdClass(); - foreach ($row as $key => $value) + if (is_array($val)) + { + foreach ($val as $k => $v) + { + $obj->$k = $v; + } + } + else { - $obj->{$key} = $value; + $obj->$key = $val; } - $res = $obj; + $result[] = $obj; } - return $res; + + return $result; } // -------------------------------------------------------------------- @@ -226,24 +220,34 @@ class CI_DB_oci8_result extends CI_DB_result { return $this->result_array; } - // oracle's fetch functions do not - // return arrays, the information - // is returned in reference parameters - // + // oracle's fetch functions do not return arrays. + // The information is returned in reference parameters $row = NULL; while ($this->_fetch_assoc($row)) { $this->result_array[] = $row; } - if (count($this->result_array) == 0) - { - return FALSE; - } - return $this->result_array; } + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero + * + * @access private + * @return array + */ + function _data_seek($n = 0) + { + return FALSE; // Not needed + } + } ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 59612e91b178e729ffd63cbabb0446fd51038e50 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 28 Oct 2006 18:50:23 +0000 Subject: --- system/database/DB_driver.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index d08e47f26..49ac8ab24 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -154,16 +154,19 @@ class CI_DB_driver { } // Select the database - if ( ! $this->db_select()) + if ($this->database != '') { - log_message('error', 'Unable to select database: '.$this->database); - - if ($this->db_debug) + if ( ! $this->db_select()) { - $this->display_error('db_unable_to_select', $this->database); + log_message('error', 'Unable to select database: '.$this->database); + + if ($this->db_debug) + { + $this->display_error('db_unable_to_select', $this->database); + } + return FALSE; } - return FALSE; - } + } return TRUE; } -- cgit v1.2.3-24-g4f1b From f3a6204bb0f4538d6a77d9c85c56545be73ecd64 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 29 Oct 2006 20:24:11 +0000 Subject: --- system/database/DB_driver.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 49ac8ab24..77069d1a8 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -372,8 +372,8 @@ class CI_DB_driver { if ( ! class_exists($driver)) { - include_once(BASEPATH.'database/DB_result'.EXT); - include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result'.EXT); + include(BASEPATH.'database/DB_result'.EXT); + include(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result'.EXT); } return $driver; @@ -998,7 +998,7 @@ class CI_DB_driver { return TRUE; } - if ( ! @include_once(BASEPATH.'database/DB_cache'.EXT)) + if ( ! @include(BASEPATH.'database/DB_cache'.EXT)) { return $this->cache_off(); } @@ -1054,13 +1054,12 @@ class CI_DB_driver { if ( ! class_exists('CI_Exceptions')) { - include_once(BASEPATH.'libraries/Exceptions'.EXT); + include(BASEPATH.'libraries/Exceptions'.EXT); } $error = new CI_Exceptions(); echo $error->show_error('An Error Was Encountered', $message, 'error_db'); exit; - } } -- cgit v1.2.3-24-g4f1b From bf9ee3f82dda6c738b65f2b558579b6cab7f7774 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 31 Oct 2006 02:35:04 +0000 Subject: --- system/database/DB_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 77069d1a8..03631d69a 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -137,7 +137,7 @@ class CI_DB_driver { { return TRUE; } - + // Connect to the database $this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect(); -- cgit v1.2.3-24-g4f1b From fc84bd259cb4ce5143148a840c96d638945985f8 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 1 Nov 2006 05:25:41 +0000 Subject: --- system/database/drivers/mssql/index.html | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 system/database/drivers/mssql/index.html (limited to 'system/database') diff --git a/system/database/drivers/mssql/index.html b/system/database/drivers/mssql/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/database/drivers/mssql/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 06f3be8ac351235d6e6db4cd9f61c281f3a43cc2 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 1 Nov 2006 05:25:54 +0000 Subject: --- system/database/drivers/mysql/index.html | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 system/database/drivers/mysql/index.html (limited to 'system/database') diff --git a/system/database/drivers/mysql/index.html b/system/database/drivers/mysql/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/database/drivers/mysql/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 8508cae2ca1b98799f8fad55ca2e5c4c863b4c18 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 1 Nov 2006 05:26:06 +0000 Subject: --- system/database/drivers/mysqli/index.html | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 system/database/drivers/mysqli/index.html (limited to 'system/database') diff --git a/system/database/drivers/mysqli/index.html b/system/database/drivers/mysqli/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/database/drivers/mysqli/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From a176f26c4a0e26443c073fe9ecc121df23e94502 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 1 Nov 2006 05:26:40 +0000 Subject: --- system/database/drivers/oci8/index.html | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 system/database/drivers/oci8/index.html (limited to 'system/database') diff --git a/system/database/drivers/oci8/index.html b/system/database/drivers/oci8/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/database/drivers/oci8/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From b95b6d2dc7ffc3bcc18bfffdea3d43c0915590ce Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 1 Nov 2006 05:26:58 +0000 Subject: --- system/database/drivers/odbc/index.html | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 system/database/drivers/odbc/index.html (limited to 'system/database') diff --git a/system/database/drivers/odbc/index.html b/system/database/drivers/odbc/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/database/drivers/odbc/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 1a726a6a21d2ef2b6402d9027aab29544655760d Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 1 Nov 2006 05:27:15 +0000 Subject: --- system/database/drivers/postgre/index.html | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 system/database/drivers/postgre/index.html (limited to 'system/database') diff --git a/system/database/drivers/postgre/index.html b/system/database/drivers/postgre/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/database/drivers/postgre/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 2f0dc10e48e3f766ff558fd8856a45205881512f Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 1 Nov 2006 05:27:25 +0000 Subject: --- system/database/drivers/sqlite/index.html | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 system/database/drivers/sqlite/index.html (limited to 'system/database') diff --git a/system/database/drivers/sqlite/index.html b/system/database/drivers/sqlite/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/database/drivers/sqlite/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c50747cfe50a4c6b7e8bde81d0f56c3bd26bd29a Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 3 Nov 2006 17:17:02 +0000 Subject: --- system/database/DB_active_rec.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index b41b929d7..90f58ae0e 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -486,8 +486,9 @@ class CI_DB_active_record extends CI_DB_driver { $sql = $this->_compile_select(); + $result = $this->query($sql); $this->_reset_select(); - return $this->query($sql); + return $result; } // -------------------------------------------------------------------- @@ -522,8 +523,9 @@ class CI_DB_active_record extends CI_DB_driver { $sql = $this->_compile_select(); + $result = $this->query($sql); $this->_reset_select(); - return $this->query($sql); + return $result; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 325197e700564f8e4e0ba7c9fc82abfd85f451b0 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 20 Nov 2006 17:29:05 +0000 Subject: --- system/database/drivers/oci8/oci8_result.php | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index af30457b3..fb4ed1f0d 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -31,21 +31,24 @@ class CI_DB_oci8_result extends CI_DB_result { var $limit_used; /** - * Number of rows in the result set + * Number of rows in the result set. + * + * Oracle doesn't have a graceful way to retun the number of rows + * so we have to use what amounts to a hack. + * * * @access public * @return integer */ function num_rows() { - if (function_exists('oci_num_rows')) - { - return @oci_num_rows($this->stmt_id); - } - else + $rowcount = count($this->result_array()); + @ociexecute($this->stmt_id); + if ($this->curs_id) { - return @ocirowcount($this->stmt_id); + @ociexecute($this->curs_id); } + return $rowcount; } // -------------------------------------------------------------------- @@ -175,12 +178,7 @@ class CI_DB_oci8_result extends CI_DB_result { { $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; - while ($row = oci_fetch_object($id)) - { - $result[] = $row; - } - - return $result; + return @oci_fetch_object($id); } // If PHP 4 is being used we have to build our own result -- cgit v1.2.3-24-g4f1b From 6b151050a80aa62808a5afc5a4c934f8bfb47512 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Thu, 23 Nov 2006 18:08:26 +0000 Subject: --- system/database/drivers/mysqli/mysqli_result.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index be7ec356c..57c89ea80 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -63,7 +63,7 @@ class CI_DB_mysqli_result extends CI_DB_result { function list_fields() { $field_names = array(); - while ($field = mysql_fetch_field($this->result_id)) + while ($field = mysqli_fetch_field($this->result_id)) { $field_names[] = $field->name; } -- cgit v1.2.3-24-g4f1b From d1c638f0e9d1d838d80ff3641f1dc889f488cbf6 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Thu, 23 Nov 2006 18:56:39 +0000 Subject: --- system/database/DB_driver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 03631d69a..2a8510e13 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -372,8 +372,8 @@ class CI_DB_driver { if ( ! class_exists($driver)) { - include(BASEPATH.'database/DB_result'.EXT); - include(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result'.EXT); + include_once(BASEPATH.'database/DB_result'.EXT); + include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result'.EXT); } return $driver; -- cgit v1.2.3-24-g4f1b From bb433723c84e174ed87a1daf46017866c32c83c8 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 5 Feb 2007 22:32:49 +0000 Subject: --- system/database/DB_active_rec.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 90f58ae0e..d27d3dc1e 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -134,7 +134,17 @@ class CI_DB_active_record extends CI_DB_driver { $type .= ' '; } } - + + // If a DB prefix is used we might need to add it to the column names + if ($this->dbprefix) + { + // First we remove any existing prefixes in the condition to avoid duplicates + $cond = preg_replace('|('.$this->dbprefix.')([\w\.]+)([\W\s]+)|', "$2$3", $cond); + + // Next we add the prefixes to the condition + $cond = preg_replace('|([\w\.]+)([\W\s]+)(.+)|', $this->dbprefix . "$1$2" . $this->dbprefix . "$3", $cond); + } + $this->ar_join[] = $type.'JOIN '.$this->dbprefix.$table.' ON '.$cond; return $this; } -- cgit v1.2.3-24-g4f1b From 09de1854b1ac78f81264ca7a6b9d849ddcd1d159 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 14 Feb 2007 01:35:56 +0000 Subject: updated AR join() to accommodate database prefixes --- system/database/DB_active_rec.php | 1777 +++++++++++++++++++------------------ 1 file changed, 891 insertions(+), 886 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index d27d3dc1e..1c72528e5 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1,887 +1,892 @@ -ar_select[] = $val; - } - return $this; - } - - // -------------------------------------------------------------------- - - /** - * DISTINCT - * - * Sets a flag which tells the query string compiler to add DISTINCT - * - * @access public - * @param bool - * @return object - */ - function distinct($val = TRUE) - { - $this->ar_distinct = (is_bool($val)) ? $val : TRUE; - return $this; - } - - // -------------------------------------------------------------------- - - /** - * From - * - * Generates the FROM portion of the query - * - * @access public - * @param mixed can be a string or array - * @return object - */ - function from($from) - { - foreach ((array)$from as $val) - { - $this->ar_from[] = $this->dbprefix.$val; - } - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Join - * - * Generates the JOIN portion of the query - * - * @access public - * @param string - * @param string the join condition - * @param string the type of join - * @return object - */ - function join($table, $cond, $type = '') - { - if ($type != '') - { - $type = strtoupper(trim($type)); - - if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'), TRUE)) - { - $type = ''; - } - else - { - $type .= ' '; - } - } - - // If a DB prefix is used we might need to add it to the column names - if ($this->dbprefix) - { - // First we remove any existing prefixes in the condition to avoid duplicates - $cond = preg_replace('|('.$this->dbprefix.')([\w\.]+)([\W\s]+)|', "$2$3", $cond); - - // Next we add the prefixes to the condition - $cond = preg_replace('|([\w\.]+)([\W\s]+)(.+)|', $this->dbprefix . "$1$2" . $this->dbprefix . "$3", $cond); - } - - $this->ar_join[] = $type.'JOIN '.$this->dbprefix.$table.' ON '.$cond; - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Where - * - * Generates the WHERE portion of the query. Separates - * multiple calls with AND - * - * @access public - * @param mixed - * @param mixed - * @return object - */ - function where($key, $value = NULL) - { - return $this->_where($key, $value, 'AND '); - } - - // -------------------------------------------------------------------- - - /** - * OR Where - * - * Generates the WHERE portion of the query. Separates - * multiple calls with OR - * - * @access public - * @param mixed - * @param mixed - * @return object - */ - function orwhere($key, $value = NULL) - { - return $this->_where($key, $value, 'OR '); - } - - // -------------------------------------------------------------------- - - /** - * Where - * - * Called by where() or orwhere() - * - * @access private - * @param mixed - * @param mixed - * @param string - * @return object - */ - function _where($key, $value = NULL, $type = 'AND ') - { - if ( ! is_array($key)) - { - $key = array($key => $value); - } - - foreach ($key as $k => $v) - { - $prefix = (count($this->ar_where) == 0) ? '' : $type; - - if ( ! is_null($v)) - { - if ( ! $this->_has_operator($k)) - { - $k .= ' ='; - } - - $v = ' '.$this->escape($v); - } - - $this->ar_where[] = $prefix.$k.$v; - } - return $this; - } - - - - // -------------------------------------------------------------------- - - /** - * Like - * - * Generates a %LIKE% portion of the query. Separates - * multiple calls with AND - * - * @access public - * @param mixed - * @param mixed - * @return object - */ - function like($field, $match = '') - { - return $this->_like($field, $match, 'AND '); - } - - // -------------------------------------------------------------------- - - /** - * OR Like - * - * Generates a %LIKE% portion of the query. Separates - * multiple calls with OR - * - * @access public - * @param mixed - * @param mixed - * @return object - */ - function orlike($field, $match = '') - { - return $this->_like($field, $match, 'OR '); - } - - // -------------------------------------------------------------------- - - /** - * Like - * - * Called by like() or orlike() - * - * @access private - * @param mixed - * @param mixed - * @param string - * @return object - */ - function _like($field, $match = '', $type = 'AND ') - { - if ( ! is_array($field)) - { - $field = array($field => $match); - } - - foreach ($field as $k => $v) - { - $prefix = (count($this->ar_like) == 0) ? '' : $type; - - $v = $this->escape_str($v); - - $this->ar_like[] = $prefix." $k LIKE '%{$v}%'"; - } - return $this; - } - - // -------------------------------------------------------------------- - - /** - * GROUP BY - * - * @access public - * @param string - * @return object - */ - function groupby($by) - { - if (is_string($by)) - { - $by = explode(',', $by); - } - - foreach ($by as $val) - { - $val = trim($val); - - if ($val != '') - $this->ar_groupby[] = $val; - } - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Sets the HAVING value - * - * Separates multiple calls with AND - * - * @access public - * @param string - * @param string - * @return object - */ - function having($key, $value = '') - { - return $this->_having($key, $value, 'AND '); - } - - // -------------------------------------------------------------------- - - /** - * Sets the OR HAVING value - * - * Separates multiple calls with OR - * - * @access public - * @param string - * @param string - * @return object - */ - function orhaving($key, $value = '') - { - return $this->_having($key, $value, 'OR '); - } - - // -------------------------------------------------------------------- - - /** - * Sets the HAVING values - * - * Called by having() or orhaving() - * - * @access private - * @param string - * @param string - * @return object - */ - function _having($key, $value = '', $type = 'AND ') - { - if ( ! is_array($key)) - { - $key = array($key => $value); - } - - foreach ($key as $k => $v) - { - $prefix = (count($this->ar_having) == 0) ? '' : $type; - - if ($v != '') - { - $v = ' '.$this->escape($v); - } - - $this->ar_having[] = $prefix.$k.$v; - } - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Sets the ORDER BY value - * - * @access public - * @param string - * @param string direction: asc or desc - * @return object - */ - function orderby($orderby, $direction = '') - { - if (trim($direction) != '') - { - $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC', 'RAND()'), TRUE)) ? ' '.$direction : ' ASC'; - } - - $this->ar_orderby[] = $orderby.$direction; - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Sets the LIMIT value - * - * @access public - * @param integer the limit value - * @param integer the offset value - * @return object - */ - function limit($value, $offset = '') - { - $this->ar_limit = $value; - - if ($offset != '') - $this->ar_offset = $offset; - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Sets the OFFSET value - * - * @access public - * @param integer the offset value - * @return object - */ - function offset($value) - { - $this->ar_offset = $value; - return $this; - } - - // -------------------------------------------------------------------- - - /** - * The "set" function. Allows key/value pairs to be set for inserting or updating - * - * @access public - * @param mixed - * @param string - * @return object - */ - function set($key, $value = '') - { - $key = $this->_object_to_array($key); - - if ( ! is_array($key)) - { - $key = array($key => $value); - } - - foreach ($key as $k => $v) - { - $this->ar_set[$k] = $this->escape($v); - } - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Get - * - * Compiles the select statement based on the other functions called - * and runs the query - * - * @access public - * @param string the limit clause - * @param string the offset clause - * @return object - */ - function get($table = '', $limit = null, $offset = null) - { - if ($table != '') - { - $this->from($table); - } - - if ( ! is_null($limit)) - { - $this->limit($limit, $offset); - } - - $sql = $this->_compile_select(); - - $result = $this->query($sql); - $this->_reset_select(); - return $result; - } - - // -------------------------------------------------------------------- - - /** - * GetWhere - * - * Allows the where clause, limit and offset to be added directly - * - * @access public - * @param string the where clause - * @param string the limit clause - * @param string the offset clause - * @return object - */ - function getwhere($table = '', $where = null, $limit = null, $offset = null) - { - if ($table != '') - { - $this->from($table); - } - - if ( ! is_null($where)) - { - $this->where($where); - } - - if ( ! is_null($limit)) - { - $this->limit($limit, $offset); - } - - $sql = $this->_compile_select(); - - $result = $this->query($sql); - $this->_reset_select(); - return $result; - } - - // -------------------------------------------------------------------- - - /** - * Insert - * - * Compiles an insert string and runs the query - * - * @access public - * @param string the table to retrieve the results from - * @param array an associative array of insert values - * @return object - */ - function insert($table = '', $set = NULL) - { - if ( ! is_null($set)) - { - $this->set($set); - } - - if (count($this->ar_set) == 0) - { - if ($this->db_debug) - { - return $this->display_error('db_must_use_set'); - } - return FALSE; - } - - if ($table == '') - { - if ( ! isset($this->ar_from[0])) - { - if ($this->db_debug) - { - return $this->display_error('db_must_set_table'); - } - return FALSE; - } - - $table = $this->ar_from[0]; - } - - $sql = $this->_insert($this->dbprefix.$table, array_keys($this->ar_set), array_values($this->ar_set)); - - $this->_reset_write(); - return $this->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Update - * - * Compiles an update string and runs the query - * - * @access public - * @param string the table to retrieve the results from - * @param array an associative array of update values - * @param mixed the where clause - * @return object - */ - function update($table = '', $set = NULL, $where = null) - { - if ( ! is_null($set)) - { - $this->set($set); - } - - if (count($this->ar_set) == 0) - { - if ($this->db_debug) - { - return $this->display_error('db_must_use_set'); - } - return FALSE; - } - - if ($table == '') - { - if ( ! isset($this->ar_from[0])) - { - if ($this->db_debug) - { - return $this->display_error('db_must_set_table'); - } - return FALSE; - } - - $table = $this->ar_from[0]; - } - - if ($where != null) - { - $this->where($where); - } - - $sql = $this->_update($this->dbprefix.$table, $this->ar_set, $this->ar_where); - - $this->_reset_write(); - return $this->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Delete - * - * Compiles a delete string and runs the query - * - * @access public - * @param string the table to retrieve the results from - * @param mixed the where clause - * @return object - */ - function delete($table = '', $where = '') - { - if ($table == '') - { - if ( ! isset($this->ar_from[0])) - { - if ($this->db_debug) - { - return $this->display_error('db_must_set_table'); - } - return FALSE; - } - - $table = $this->ar_from[0]; - } - - if ($where != '') - { - $this->where($where); - } - - if (count($this->ar_where) == 0) - { - if ($this->db_debug) - { - return $this->display_error('db_del_must_use_where'); - } - return FALSE; - } - - $sql = $this->_delete($this->dbprefix.$table, $this->ar_where); - - $this->_reset_write(); - return $this->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Use Table - DEPRECATED - * - * @deprecated use $this->db->from instead - */ - function use_table($table) - { - return $this->from($table); - return $this; - } - - // -------------------------------------------------------------------- - - /** - * ORDER BY - DEPRECATED - * - * @deprecated use $this->db->orderby() instead - */ - function order_by($orderby, $direction = '') - { - return $this->orderby($orderby, $direction); - } - - // -------------------------------------------------------------------- - - /** - * Tests whether the string has an SQL operator - * - * @access private - * @param string - * @return bool - */ - function _has_operator($str) - { - $str = trim($str); - if ( ! preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str)) - { - return FALSE; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Compile the SELECT statement - * - * Generates a query string based on which functions were used. - * Should not be called directly. The get() function calls it. - * - * @access private - * @return string - */ - function _compile_select() - { - $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; - - $sql .= (count($this->ar_select) == 0) ? '*' : implode(', ', $this->ar_select); - - if (count($this->ar_from) > 0) - { - $sql .= "\nFROM "; - $sql .= implode(', ', $this->ar_from); - } - - if (count($this->ar_join) > 0) - { - $sql .= "\n"; - $sql .= implode("\n", $this->ar_join); - } - - if (count($this->ar_where) > 0 OR count($this->ar_like) > 0) - { - $sql .= "\nWHERE "; - } - - $sql .= implode("\n", $this->ar_where); - - if (count($this->ar_like) > 0) - { - if (count($this->ar_where) > 0) - { - $sql .= " AND "; - } - - $sql .= implode("\n", $this->ar_like); - } - - if (count($this->ar_groupby) > 0) - { - $sql .= "\nGROUP BY "; - $sql .= implode(', ', $this->ar_groupby); - } - - if (count($this->ar_having) > 0) - { - $sql .= "\nHAVING "; - $sql .= implode("\n", $this->ar_having); - } - - if (count($this->ar_orderby) > 0) - { - $sql .= "\nORDER BY "; - $sql .= implode(', ', $this->ar_orderby); - - if ($this->ar_order !== FALSE) - { - $sql .= ($this->ar_order == 'desc') ? ' DESC' : ' ASC'; - } - } - - if (is_numeric($this->ar_limit)) - { - $sql .= "\n"; - $sql = $this->_limit($sql, $this->ar_limit, $this->ar_offset); - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Object to Array - * - * Takes an object as input and converts the class variables to array key/vals - * - * @access public - * @param object - * @return array - */ - function _object_to_array($object) - { - if ( ! is_object($object)) - { - return $object; - } - - $array = array(); - foreach (get_object_vars($object) as $key => $val) - { - if ( ! is_object($val) AND ! is_array($val)) - { - $array[$key] = $val; - } - } - - return $array; - } - - // -------------------------------------------------------------------- - - /** - * Resets the active record values. Called by the get() function - * - * @access private - * @return void - */ - function _reset_select() - { - $this->ar_select = array(); - $this->ar_distinct = FALSE; - $this->ar_from = array(); - $this->ar_join = array(); - $this->ar_where = array(); - $this->ar_like = array(); - $this->ar_groupby = array(); - $this->ar_having = array(); - $this->ar_limit = FALSE; - $this->ar_offset = FALSE; - $this->ar_order = FALSE; - $this->ar_orderby = array(); - } - - // -------------------------------------------------------------------- - - /** - * Resets the active record "write" values. - * - * Called by the insert() or update() functions - * - * @access private - * @return void - */ - function _reset_write() - { - $this->ar_set = array(); - $this->ar_from = array(); - $this->ar_where = array(); - } - -} - +ar_select[] = $val; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * DISTINCT + * + * Sets a flag which tells the query string compiler to add DISTINCT + * + * @access public + * @param bool + * @return object + */ + function distinct($val = TRUE) + { + $this->ar_distinct = (is_bool($val)) ? $val : TRUE; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * From + * + * Generates the FROM portion of the query + * + * @access public + * @param mixed can be a string or array + * @return object + */ + function from($from) + { + foreach ((array)$from as $val) + { + $this->ar_from[] = $this->dbprefix.$val; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Join + * + * Generates the JOIN portion of the query + * + * @access public + * @param string + * @param string the join condition + * @param string the type of join + * @return object + */ + function join($table, $cond, $type = '') + { + if ($type != '') + { + $type = strtoupper(trim($type)); + + if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'), TRUE)) + { + $type = ''; + } + else + { + $type .= ' '; + } + } + + if ($this->dbprefix) + { + $cond = preg_replace('|([\w\.]+)([\W\s]+)(.+)|', $this->dbprefix . "$1$2" . $this->dbprefix . "$3", $cond); + } + + // If a DB prefix is used we might need to add it to the column names + if ($this->dbprefix) + { + // First we remove any existing prefixes in the condition to avoid duplicates + $cond = preg_replace('|('.$this->dbprefix.')([\w\.]+)([\W\s]+)|', "$2$3", $cond); + + // Next we add the prefixes to the condition + $cond = preg_replace('|([\w\.]+)([\W\s]+)(.+)|', $this->dbprefix . "$1$2" . $this->dbprefix . "$3", $cond); + } + + $this->ar_join[] = $type.'JOIN '.$this->dbprefix.$table.' ON '.$cond; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Where + * + * Generates the WHERE portion of the query. Separates + * multiple calls with AND + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function where($key, $value = NULL) + { + return $this->_where($key, $value, 'AND '); + } + + // -------------------------------------------------------------------- + + /** + * OR Where + * + * Generates the WHERE portion of the query. Separates + * multiple calls with OR + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function orwhere($key, $value = NULL) + { + return $this->_where($key, $value, 'OR '); + } + + // -------------------------------------------------------------------- + + /** + * Where + * + * Called by where() or orwhere() + * + * @access private + * @param mixed + * @param mixed + * @param string + * @return object + */ + function _where($key, $value = NULL, $type = 'AND ') + { + if ( ! is_array($key)) + { + $key = array($key => $value); + } + + foreach ($key as $k => $v) + { + $prefix = (count($this->ar_where) == 0) ? '' : $type; + + if ( ! is_null($v)) + { + if ( ! $this->_has_operator($k)) + { + $k .= ' ='; + } + + $v = ' '.$this->escape($v); + } + + $this->ar_where[] = $prefix.$k.$v; + } + return $this; + } + + + + // -------------------------------------------------------------------- + + /** + * Like + * + * Generates a %LIKE% portion of the query. Separates + * multiple calls with AND + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function like($field, $match = '') + { + return $this->_like($field, $match, 'AND '); + } + + // -------------------------------------------------------------------- + + /** + * OR Like + * + * Generates a %LIKE% portion of the query. Separates + * multiple calls with OR + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function orlike($field, $match = '') + { + return $this->_like($field, $match, 'OR '); + } + + // -------------------------------------------------------------------- + + /** + * Like + * + * Called by like() or orlike() + * + * @access private + * @param mixed + * @param mixed + * @param string + * @return object + */ + function _like($field, $match = '', $type = 'AND ') + { + if ( ! is_array($field)) + { + $field = array($field => $match); + } + + foreach ($field as $k => $v) + { + $prefix = (count($this->ar_like) == 0) ? '' : $type; + + $v = $this->escape_str($v); + + $this->ar_like[] = $prefix." $k LIKE '%{$v}%'"; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * GROUP BY + * + * @access public + * @param string + * @return object + */ + function groupby($by) + { + if (is_string($by)) + { + $by = explode(',', $by); + } + + foreach ($by as $val) + { + $val = trim($val); + + if ($val != '') + $this->ar_groupby[] = $val; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Sets the HAVING value + * + * Separates multiple calls with AND + * + * @access public + * @param string + * @param string + * @return object + */ + function having($key, $value = '') + { + return $this->_having($key, $value, 'AND '); + } + + // -------------------------------------------------------------------- + + /** + * Sets the OR HAVING value + * + * Separates multiple calls with OR + * + * @access public + * @param string + * @param string + * @return object + */ + function orhaving($key, $value = '') + { + return $this->_having($key, $value, 'OR '); + } + + // -------------------------------------------------------------------- + + /** + * Sets the HAVING values + * + * Called by having() or orhaving() + * + * @access private + * @param string + * @param string + * @return object + */ + function _having($key, $value = '', $type = 'AND ') + { + if ( ! is_array($key)) + { + $key = array($key => $value); + } + + foreach ($key as $k => $v) + { + $prefix = (count($this->ar_having) == 0) ? '' : $type; + + if ($v != '') + { + $v = ' '.$this->escape($v); + } + + $this->ar_having[] = $prefix.$k.$v; + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Sets the ORDER BY value + * + * @access public + * @param string + * @param string direction: asc or desc + * @return object + */ + function orderby($orderby, $direction = '') + { + if (trim($direction) != '') + { + $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC', 'RAND()'), TRUE)) ? ' '.$direction : ' ASC'; + } + + $this->ar_orderby[] = $orderby.$direction; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Sets the LIMIT value + * + * @access public + * @param integer the limit value + * @param integer the offset value + * @return object + */ + function limit($value, $offset = '') + { + $this->ar_limit = $value; + + if ($offset != '') + $this->ar_offset = $offset; + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Sets the OFFSET value + * + * @access public + * @param integer the offset value + * @return object + */ + function offset($value) + { + $this->ar_offset = $value; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * The "set" function. Allows key/value pairs to be set for inserting or updating + * + * @access public + * @param mixed + * @param string + * @return object + */ + function set($key, $value = '') + { + $key = $this->_object_to_array($key); + + if ( ! is_array($key)) + { + $key = array($key => $value); + } + + foreach ($key as $k => $v) + { + $this->ar_set[$k] = $this->escape($v); + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Get + * + * Compiles the select statement based on the other functions called + * and runs the query + * + * @access public + * @param string the limit clause + * @param string the offset clause + * @return object + */ + function get($table = '', $limit = null, $offset = null) + { + if ($table != '') + { + $this->from($table); + } + + if ( ! is_null($limit)) + { + $this->limit($limit, $offset); + } + + $sql = $this->_compile_select(); + + $result = $this->query($sql); + $this->_reset_select(); + return $result; + } + + // -------------------------------------------------------------------- + + /** + * GetWhere + * + * Allows the where clause, limit and offset to be added directly + * + * @access public + * @param string the where clause + * @param string the limit clause + * @param string the offset clause + * @return object + */ + function getwhere($table = '', $where = null, $limit = null, $offset = null) + { + if ($table != '') + { + $this->from($table); + } + + if ( ! is_null($where)) + { + $this->where($where); + } + + if ( ! is_null($limit)) + { + $this->limit($limit, $offset); + } + + $sql = $this->_compile_select(); + + $result = $this->query($sql); + $this->_reset_select(); + return $result; + } + + // -------------------------------------------------------------------- + + /** + * Insert + * + * Compiles an insert string and runs the query + * + * @access public + * @param string the table to retrieve the results from + * @param array an associative array of insert values + * @return object + */ + function insert($table = '', $set = NULL) + { + if ( ! is_null($set)) + { + $this->set($set); + } + + if (count($this->ar_set) == 0) + { + if ($this->db_debug) + { + return $this->display_error('db_must_use_set'); + } + return FALSE; + } + + if ($table == '') + { + if ( ! isset($this->ar_from[0])) + { + if ($this->db_debug) + { + return $this->display_error('db_must_set_table'); + } + return FALSE; + } + + $table = $this->ar_from[0]; + } + + $sql = $this->_insert($this->dbprefix.$table, array_keys($this->ar_set), array_values($this->ar_set)); + + $this->_reset_write(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Update + * + * Compiles an update string and runs the query + * + * @access public + * @param string the table to retrieve the results from + * @param array an associative array of update values + * @param mixed the where clause + * @return object + */ + function update($table = '', $set = NULL, $where = null) + { + if ( ! is_null($set)) + { + $this->set($set); + } + + if (count($this->ar_set) == 0) + { + if ($this->db_debug) + { + return $this->display_error('db_must_use_set'); + } + return FALSE; + } + + if ($table == '') + { + if ( ! isset($this->ar_from[0])) + { + if ($this->db_debug) + { + return $this->display_error('db_must_set_table'); + } + return FALSE; + } + + $table = $this->ar_from[0]; + } + + if ($where != null) + { + $this->where($where); + } + + $sql = $this->_update($this->dbprefix.$table, $this->ar_set, $this->ar_where); + + $this->_reset_write(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Delete + * + * Compiles a delete string and runs the query + * + * @access public + * @param string the table to retrieve the results from + * @param mixed the where clause + * @return object + */ + function delete($table = '', $where = '') + { + if ($table == '') + { + if ( ! isset($this->ar_from[0])) + { + if ($this->db_debug) + { + return $this->display_error('db_must_set_table'); + } + return FALSE; + } + + $table = $this->ar_from[0]; + } + + if ($where != '') + { + $this->where($where); + } + + if (count($this->ar_where) == 0) + { + if ($this->db_debug) + { + return $this->display_error('db_del_must_use_where'); + } + return FALSE; + } + + $sql = $this->_delete($this->dbprefix.$table, $this->ar_where); + + $this->_reset_write(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Use Table - DEPRECATED + * + * @deprecated use $this->db->from instead + */ + function use_table($table) + { + return $this->from($table); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * ORDER BY - DEPRECATED + * + * @deprecated use $this->db->orderby() instead + */ + function order_by($orderby, $direction = '') + { + return $this->orderby($orderby, $direction); + } + + // -------------------------------------------------------------------- + + /** + * Tests whether the string has an SQL operator + * + * @access private + * @param string + * @return bool + */ + function _has_operator($str) + { + $str = trim($str); + if ( ! preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str)) + { + return FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Compile the SELECT statement + * + * Generates a query string based on which functions were used. + * Should not be called directly. The get() function calls it. + * + * @access private + * @return string + */ + function _compile_select() + { + $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; + + $sql .= (count($this->ar_select) == 0) ? '*' : implode(', ', $this->ar_select); + + if (count($this->ar_from) > 0) + { + $sql .= "\nFROM "; + $sql .= implode(', ', $this->ar_from); + } + + if (count($this->ar_join) > 0) + { + $sql .= "\n"; + $sql .= implode("\n", $this->ar_join); + } + + if (count($this->ar_where) > 0 OR count($this->ar_like) > 0) + { + $sql .= "\nWHERE "; + } + + $sql .= implode("\n", $this->ar_where); + + if (count($this->ar_like) > 0) + { + if (count($this->ar_where) > 0) + { + $sql .= " AND "; + } + + $sql .= implode("\n", $this->ar_like); + } + + if (count($this->ar_groupby) > 0) + { + $sql .= "\nGROUP BY "; + $sql .= implode(', ', $this->ar_groupby); + } + + if (count($this->ar_having) > 0) + { + $sql .= "\nHAVING "; + $sql .= implode("\n", $this->ar_having); + } + + if (count($this->ar_orderby) > 0) + { + $sql .= "\nORDER BY "; + $sql .= implode(', ', $this->ar_orderby); + + if ($this->ar_order !== FALSE) + { + $sql .= ($this->ar_order == 'desc') ? ' DESC' : ' ASC'; + } + } + + if (is_numeric($this->ar_limit)) + { + $sql .= "\n"; + $sql = $this->_limit($sql, $this->ar_limit, $this->ar_offset); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Object to Array + * + * Takes an object as input and converts the class variables to array key/vals + * + * @access public + * @param object + * @return array + */ + function _object_to_array($object) + { + if ( ! is_object($object)) + { + return $object; + } + + $array = array(); + foreach (get_object_vars($object) as $key => $val) + { + if ( ! is_object($val) AND ! is_array($val)) + { + $array[$key] = $val; + } + } + + return $array; + } + + // -------------------------------------------------------------------- + + /** + * Resets the active record values. Called by the get() function + * + * @access private + * @return void + */ + function _reset_select() + { + $this->ar_select = array(); + $this->ar_distinct = FALSE; + $this->ar_from = array(); + $this->ar_join = array(); + $this->ar_where = array(); + $this->ar_like = array(); + $this->ar_groupby = array(); + $this->ar_having = array(); + $this->ar_limit = FALSE; + $this->ar_offset = FALSE; + $this->ar_order = FALSE; + $this->ar_orderby = array(); + } + + // -------------------------------------------------------------------- + + /** + * Resets the active record "write" values. + * + * Called by the insert() or update() functions + * + * @access private + * @return void + */ + function _reset_write() + { + $this->ar_set = array(); + $this->ar_from = array(); + $this->ar_where = array(); + } + +} + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From ba0dd638336d2617066b67cf4f59667aaff8c531 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 7 Mar 2007 12:10:58 +0000 Subject: pg_version() doesn't exist. Changed reference to version() which does. --- system/database/drivers/postgre/postgre_driver.php | 968 ++++++++++----------- 1 file changed, 484 insertions(+), 484 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index a66fddbdf..58cc69a96 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -1,485 +1,485 @@ -port == '') ? '' : " port=".$this->port; - - return @pg_connect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - $port = ($this->port == '') ? '' : " port=".$this->port; - - return @pg_pconnect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - // Not needed for Postgre so we'll return TRUE - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return resource - */ - function _execute($sql) - { - $sql = $this->_prep_query($sql); - return @pg_query($this->conn_id, $sql); - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @access private called by execute() - * @param string an SQL query - * @return string - */ - function _prep_query($sql) - { - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @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) - { - return TRUE; - } - - // Reset the transaction failure flag. - // 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; - - return @pg_exec($this->conn_id, "begin"); - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - return @pg_exec($this->conn_id, "commit"); - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - return @pg_exec($this->conn_id, "rollback"); - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @return string - */ - function escape_str($str) - { - return pg_escape_string($str); - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @pg_affected_rows($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - $v = pg_version($this->conn_id); - $v = $v['server']; - - $table = func_num_args() > 0 ? func_get_arg(0) : null; - $column = func_num_args() > 1 ? func_get_arg(1) : null; - - if ($table == null && $v >= '8.1') - { - $sql='SELECT LASTVAL() as ins_id'; - } - elseif ($table != null && $column != null && $v >= '8.0') - { - $sql = sprintf("SELECT pg_get_serial_sequence('%s','%s') as seq", $table, $column); - $query = $this->query($sql); - $row = $query->row(); - $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $row->seq); - } - elseif ($table != null) - { - // seq_name passed in table parameter - $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $table); - } - else - { - return pg_last_oid($this->result_id); - } - $query = $this->query($sql); - $row = $query->row(); - return $row->ins_id; - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - return '0'; - - $query = $this->query('SELECT COUNT(*) AS numrows FROM "'.$this->dbprefix.$table.'"'); - - if ($query->num_rows() == 0) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; - } - - // -------------------------------------------------------------------- - - /** - * Show column query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _list_columns($table = '') - { - return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->_escape_table($table)."'"; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - return "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access private - * @return string - */ - function _error_message() - { - return pg_last_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access private - * @return integer - */ - function _error_number() - { - return ''; - } - - // -------------------------------------------------------------------- - - /** - * Escape Table Name - * - * This function adds backticks if the table name has a period - * in it. Some DBs will get cranky unless periods are escaped. - * - * @access private - * @param string the table name - * @return string - */ - function _escape_table($table) - { - if (stristr($table, '.')) - { - $table = '"'.preg_replace("/\./", '"."', $table).'"'; - } - - return $table; - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @return string - */ - function _update($table, $values, $where) - { - foreach($values as $key => $val) - { - $valstr[] = $key." = ".$val; - } - - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @return string - */ - function _delete($table, $where) - { - return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - $sql .= "LIMIT ".$limit; - - if ($offset > 0) - { - $sql .= " OFFSET ".$offset; - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - @pg_close($conn_id); - } - - -} - +port == '') ? '' : " port=".$this->port; + + return @pg_connect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + $port = ($this->port == '') ? '' : " port=".$this->port; + + return @pg_pconnect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + // Not needed for Postgre so we'll return TRUE + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + function _execute($sql) + { + $sql = $this->_prep_query($sql); + return @pg_query($this->conn_id, $sql); + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @access private called by execute() + * @param string an SQL query + * @return string + */ + function _prep_query($sql) + { + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @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) + { + return TRUE; + } + + // Reset the transaction failure flag. + // 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; + + return @pg_exec($this->conn_id, "begin"); + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @access public + * @return bool + */ + function trans_commit() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + return @pg_exec($this->conn_id, "commit"); + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @access public + * @return bool + */ + function trans_rollback() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + return @pg_exec($this->conn_id, "rollback"); + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + return pg_escape_string($str); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @pg_affected_rows($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + $v = version($this->conn_id); + $v = $v['server']; + + $table = func_num_args() > 0 ? func_get_arg(0) : null; + $column = func_num_args() > 1 ? func_get_arg(1) : null; + + if ($table == null && $v >= '8.1') + { + $sql='SELECT LASTVAL() as ins_id'; + } + elseif ($table != null && $column != null && $v >= '8.0') + { + $sql = sprintf("SELECT pg_get_serial_sequence('%s','%s') as seq", $table, $column); + $query = $this->query($sql); + $row = $query->row(); + $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $row->seq); + } + elseif ($table != null) + { + // seq_name passed in table parameter + $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $table); + } + else + { + return pg_last_oid($this->result_id); + } + $query = $this->query($sql); + $row = $query->row(); + return $row->ins_id; + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + return '0'; + + $query = $this->query('SELECT COUNT(*) AS numrows FROM "'.$this->dbprefix.$table.'"'); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _list_columns($table = '') + { + return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->_escape_table($table)."'"; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + return "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access private + * @return string + */ + function _error_message() + { + return pg_last_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access private + * @return integer + */ + function _error_number() + { + return ''; + } + + // -------------------------------------------------------------------- + + /** + * Escape Table Name + * + * This function adds backticks if the table name has a period + * in it. Some DBs will get cranky unless periods are escaped. + * + * @access private + * @param string the table name + * @return string + */ + function _escape_table($table) + { + if (stristr($table, '.')) + { + $table = '"'.preg_replace("/\./", '"."', $table).'"'; + } + + return $table; + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @return string + */ + function _update($table, $values, $where) + { + foreach($values as $key => $val) + { + $valstr[] = $key." = ".$val; + } + + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + $sql .= "LIMIT ".$limit; + + if ($offset > 0) + { + $sql .= " OFFSET ".$offset; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + @pg_close($conn_id); + } + + +} + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 5c3905b4241b4ff68f768a81151f8c6e7a75fa5d Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sat, 24 Mar 2007 11:08:55 +0000 Subject: passes hostname and not database now --- system/database/drivers/odbc/odbc_driver.php | 904 +++++++++++++-------------- 1 file changed, 452 insertions(+), 452 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 7dd9295fc..9d540c77f 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -1,453 +1,453 @@ -database, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return @odbc_pconnect($this->database, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - // Not needed for ODBC - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return resource - */ - function _execute($sql) - { - $sql = $this->_prep_query($sql); - return @odbc_exec($this->conn_id, $sql); - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @access private called by execute() - * @param string an SQL query - * @return string - */ - function _prep_query($sql) - { - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @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) - { - return TRUE; - } - - // Reset the transaction failure flag. - // 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; - - return odbc_autocommit($this->conn_id, FALSE); - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $ret = odbc_commit($this->conn_id); - odbc_autocommit($this->conn_id, TRUE); - return $ret; - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $ret = odbc_rollback($this->conn_id); - odbc_autocommit($this->conn_id, TRUE); - return $ret; - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @return string - */ - function escape_str($str) - { - // ODBC doesn't require escaping - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @odbc_num_rows($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - return @odbc_insert_id($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - return '0'; - - $query = $this->query("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); - - if ($query->num_rows() == 0) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SHOW TABLES FROM `".$this->database."`"; - } - - // -------------------------------------------------------------------- - - /** - * Show column query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _list_columns($table = '') - { - return "SHOW COLUMNS FROM ".$this->_escape_table($table); - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - return "SELECT TOP 1 FROM ".$this->_escape_table($table); - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access private - * @return string - */ - function _error_message() - { - return odbc_errormsg($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access private - * @return integer - */ - function _error_number() - { - return odbc_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Escape Table Name - * - * This function adds backticks if the table name has a period - * in it. Some DBs will get cranky unless periods are escaped - * - * @access private - * @param string the table name - * @return string - */ - function _escape_table($table) - { - if (stristr($table, '.')) - { - $table = preg_replace("/\./", "`.`", $table); - } - - return $table; - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @return string - */ - function _update($table, $values, $where) - { - foreach($values as $key => $val) - { - $valstr[] = $key." = ".$val; - } - - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @return string - */ - function _delete($table, $where) - { - return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - // Does ODBC doesn't use the LIMIT clause? - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - @odbc_close($conn_id); - } - - -} - - +hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return @odbc_pconnect($this->hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + // Not needed for ODBC + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + function _execute($sql) + { + $sql = $this->_prep_query($sql); + return @odbc_exec($this->conn_id, $sql); + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @access private called by execute() + * @param string an SQL query + * @return string + */ + function _prep_query($sql) + { + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @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) + { + return TRUE; + } + + // Reset the transaction failure flag. + // 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; + + return odbc_autocommit($this->conn_id, FALSE); + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @access public + * @return bool + */ + function trans_commit() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $ret = odbc_commit($this->conn_id); + odbc_autocommit($this->conn_id, TRUE); + return $ret; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @access public + * @return bool + */ + function trans_rollback() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $ret = odbc_rollback($this->conn_id); + odbc_autocommit($this->conn_id, TRUE); + return $ret; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + // ODBC doesn't require escaping + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @odbc_num_rows($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + return @odbc_insert_id($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + return '0'; + + $query = $this->query("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SHOW TABLES FROM `".$this->database."`"; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _list_columns($table = '') + { + return "SHOW COLUMNS FROM ".$this->_escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + return "SELECT TOP 1 FROM ".$this->_escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access private + * @return string + */ + function _error_message() + { + return odbc_errormsg($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access private + * @return integer + */ + function _error_number() + { + return odbc_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Escape Table Name + * + * This function adds backticks if the table name has a period + * in it. Some DBs will get cranky unless periods are escaped + * + * @access private + * @param string the table name + * @return string + */ + function _escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $table; + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @return string + */ + function _update($table, $values, $where) + { + foreach($values as $key => $val) + { + $valstr[] = $key." = ".$val; + } + + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + // Does ODBC doesn't use the LIMIT clause? + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + @odbc_close($conn_id); + } + + +} + + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From d2df9bc7cc9d4b3e53818470c5d0977c9a36677c Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 15 Apr 2007 17:41:17 +0000 Subject: update pMachine to EllisLab update copyright year update Code Igniter to CodeIgniter --- system/database/DB.php | 170 +- system/database/DB_active_rec.php | 4 +- system/database/DB_cache.php | 386 ++-- system/database/DB_driver.php | 2132 ++++++++++---------- system/database/DB_result.php | 578 +++--- system/database/DB_utility.php | 908 ++++----- system/database/drivers/mssql/mssql_driver.php | 914 ++++----- system/database/drivers/mssql/mssql_result.php | 344 ++-- system/database/drivers/mssql/mssql_utility.php | 258 +-- system/database/drivers/mysql/mysql_driver.php | 982 ++++----- system/database/drivers/mysql/mysql_result.php | 344 ++-- system/database/drivers/mysql/mysql_utility.php | 486 ++--- system/database/drivers/mysqli/mysqli_driver.php | 964 ++++----- system/database/drivers/mysqli/mysqli_result.php | 344 ++-- system/database/drivers/mysqli/mysqli_utility.php | 488 ++--- system/database/drivers/oci8/oci8_driver.php | 1208 +++++------ system/database/drivers/oci8/oci8_result.php | 500 ++--- system/database/drivers/oci8/oci8_utility.php | 256 +-- system/database/drivers/odbc/odbc_driver.php | 4 +- system/database/drivers/odbc/odbc_result.php | 466 ++--- system/database/drivers/odbc/odbc_utility.php | 320 +-- system/database/drivers/postgre/postgre_driver.php | 4 +- system/database/drivers/postgre/postgre_result.php | 344 ++-- .../database/drivers/postgre/postgre_utility.php | 256 +-- system/database/drivers/sqlite/sqlite_driver.php | 966 ++++----- system/database/drivers/sqlite/sqlite_result.php | 350 ++-- system/database/drivers/sqlite/sqlite_utility.php | 306 +-- 27 files changed, 7141 insertions(+), 7141 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index c6bd365d9..4a119d042 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -1,86 +1,86 @@ - \ No newline at end of file diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 1c72528e5..d79a068e3 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1,12 +1,12 @@ CI - // and load the file helper since we use it a lot - $this->CI =& get_instance(); - $this->CI->load->helper('file'); - } - - // -------------------------------------------------------------------- - - /** - * Set Cache Directory Path - * - * @access public - * @param string the path to the cache directory - * @return bool - */ - function check_path($path = '') - { - if ($path == '') - { - if ($this->CI->db->cachedir == '') - { - return $this->CI->db->cache_off(); - } - - $path = $this->CI->db->cachedir; - } - - // Add a trailing slash to the path if needed - $path = preg_replace("/(.+?)\/*$/", "\\1/", $path); - - if ( ! is_dir($path) OR ! is_writable($path)) - { - if ($this->CI->db->db_debug) - { - return $this->CI->db->display_error('db_invalid_cache_path'); - } - - // If the path is wrong we'll turn off caching - return $this->CI->db->cache_off(); - } - - $this->CI->db->cachedir = $path; - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Retrieve a cached query - * - * The URI being requested will become the name of the cache sub-folder. - * An MD5 hash of the SQL statement will become the cache file name - * - * @access public - * @return string - */ - function read($sql) - { - if ( ! $this->check_path()) - { - return $this->CI->db->cache_off(); - } - - $uri = ($this->CI->uri->segment(1) == FALSE) ? 'default.' : $this->CI->uri->segment(1).'+'; - $uri .= ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); - - $filepath = $uri.'/'.md5($sql); - - if (FALSE === ($cachedata = read_file($this->CI->db->cachedir.$filepath))) - { - return FALSE; - } - - return unserialize($cachedata); - } - - // -------------------------------------------------------------------- - - /** - * Write a query to a cache file - * - * @access public - * @return bool - */ - function write($sql, $object) - { - if ( ! $this->check_path()) - { - return $this->CI->db->cache_off(); - } - - $uri = ($this->CI->uri->segment(1) == FALSE) ? 'default.' : $this->CI->uri->segment(1).'+'; - $uri .= ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); - - $dir_path = $this->CI->db->cachedir.$uri.'/'; - - $filename = md5($sql); - - if ( ! @is_dir($dir_path)) - { - if ( ! @mkdir($dir_path, 0777)) - { - return FALSE; - } - - @chmod($dir_path, 0777); - } - - if (write_file($dir_path.$filename, serialize($object)) === FALSE) - { - return FALSE; - } - - @chmod($dir_path.$filename, 0777); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Delete cache files within a particular directory - * - * @access public - * @return bool - */ - function delete($segment_one = '', $segment_two = '') - { - if ($segment_one == '') - { - $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(2); - } - - if ($segment_two == '') - { - $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); - } - - $dir_path = $this->CI->db->cachedir.$segment_one.'+'.$segment_two.'/'; - - delete_files($dir_path, TRUE); - } - - // -------------------------------------------------------------------- - - /** - * Delete all existing cache files - * - * @access public - * @return bool - */ - function delete_all() - { - delete_files($this->CI->db->cachedir, TRUE); - } - -} - +CI + // and load the file helper since we use it a lot + $this->CI =& get_instance(); + $this->CI->load->helper('file'); + } + + // -------------------------------------------------------------------- + + /** + * Set Cache Directory Path + * + * @access public + * @param string the path to the cache directory + * @return bool + */ + function check_path($path = '') + { + if ($path == '') + { + if ($this->CI->db->cachedir == '') + { + return $this->CI->db->cache_off(); + } + + $path = $this->CI->db->cachedir; + } + + // Add a trailing slash to the path if needed + $path = preg_replace("/(.+?)\/*$/", "\\1/", $path); + + if ( ! is_dir($path) OR ! is_writable($path)) + { + if ($this->CI->db->db_debug) + { + return $this->CI->db->display_error('db_invalid_cache_path'); + } + + // If the path is wrong we'll turn off caching + return $this->CI->db->cache_off(); + } + + $this->CI->db->cachedir = $path; + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Retrieve a cached query + * + * The URI being requested will become the name of the cache sub-folder. + * An MD5 hash of the SQL statement will become the cache file name + * + * @access public + * @return string + */ + function read($sql) + { + if ( ! $this->check_path()) + { + return $this->CI->db->cache_off(); + } + + $uri = ($this->CI->uri->segment(1) == FALSE) ? 'default.' : $this->CI->uri->segment(1).'+'; + $uri .= ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); + + $filepath = $uri.'/'.md5($sql); + + if (FALSE === ($cachedata = read_file($this->CI->db->cachedir.$filepath))) + { + return FALSE; + } + + return unserialize($cachedata); + } + + // -------------------------------------------------------------------- + + /** + * Write a query to a cache file + * + * @access public + * @return bool + */ + function write($sql, $object) + { + if ( ! $this->check_path()) + { + return $this->CI->db->cache_off(); + } + + $uri = ($this->CI->uri->segment(1) == FALSE) ? 'default.' : $this->CI->uri->segment(1).'+'; + $uri .= ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); + + $dir_path = $this->CI->db->cachedir.$uri.'/'; + + $filename = md5($sql); + + if ( ! @is_dir($dir_path)) + { + if ( ! @mkdir($dir_path, 0777)) + { + return FALSE; + } + + @chmod($dir_path, 0777); + } + + if (write_file($dir_path.$filename, serialize($object)) === FALSE) + { + return FALSE; + } + + @chmod($dir_path.$filename, 0777); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Delete cache files within a particular directory + * + * @access public + * @return bool + */ + function delete($segment_one = '', $segment_two = '') + { + if ($segment_one == '') + { + $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(2); + } + + if ($segment_two == '') + { + $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); + } + + $dir_path = $this->CI->db->cachedir.$segment_one.'+'.$segment_two.'/'; + + delete_files($dir_path, TRUE); + } + + // -------------------------------------------------------------------- + + /** + * Delete all existing cache files + * + * @access public + * @return bool + */ + function delete_all() + { + delete_files($this->CI->db->cachedir, TRUE); + } + +} + ?> \ No newline at end of file diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 2a8510e13..7ff33246a 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1,1067 +1,1067 @@ -initialize($params); - log_message('debug', 'Database Driver Class Initialized'); - } - - // -------------------------------------------------------------------- - - /** - * Initialize Database Settings - * - * @access private Called by the constructor - * @param mixed - * @return void - */ - function initialize($params = '') - { - if (is_array($params)) - { - $defaults = array( - 'hostname' => '', - 'username' => '', - 'password' => '', - 'database' => '', - 'conn_id' => FALSE, - 'dbdriver' => 'mysql', - 'dbprefix' => '', - 'port' => '', - 'pconnect' => FALSE, - 'db_debug' => FALSE, - 'cachedir' => '', - 'cache_on' => FALSE - ); - - foreach ($defaults as $key => $val) - { - $this->$key = ( ! isset($params[$key])) ? $val : $params[$key]; - } - } - elseif (strpos($params, '://')) - { - if (FALSE === ($dsn = @parse_url($params))) - { - log_message('error', 'Invalid DB Connection String'); - - if ($this->db_debug) - { - return $this->display_error('db_invalid_connection_str'); - } - return FALSE; - } - - $this->hostname = ( ! isset($dsn['host'])) ? '' : rawurldecode($dsn['host']); - $this->username = ( ! isset($dsn['user'])) ? '' : rawurldecode($dsn['user']); - $this->password = ( ! isset($dsn['pass'])) ? '' : rawurldecode($dsn['pass']); - $this->database = ( ! isset($dsn['path'])) ? '' : rawurldecode(substr($dsn['path'], 1)); - } - - // If an existing DB connection resource is supplied - // there is no need to connect and select the database - if (is_resource($this->conn_id)) - { - return TRUE; - } - - // Connect to the database - $this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect(); - - // No connection? Throw an error - if ( ! $this->conn_id) - { - log_message('error', 'Unable to connect to the database'); - - if ($this->db_debug) - { - $this->display_error('db_unable_to_connect'); - } - return FALSE; - } - - // Select the database - if ($this->database != '') - { - if ( ! $this->db_select()) - { - log_message('error', 'Unable to select database: '.$this->database); - - if ($this->db_debug) - { - $this->display_error('db_unable_to_select', $this->database); - } - return FALSE; - } - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * The name of the platform in use (mysql, mssql, etc...) - * - * @access public - * @return string - */ - function platform() - { - return $this->dbdriver; - } - - // -------------------------------------------------------------------- - - /** - * Database Version Number. Returns a string containing the - * version of the database being used - * - * @access public - * @return string - */ - function version() - { - if (FALSE === ($sql = $this->_version())) - { - if ($this->db_debug) - { - return $this->display_error('db_unsupported_function'); - } - return FALSE; - } - - if ($this->dbdriver == 'oci8') - { - return $sql; - } - - $query = $this->query($sql); - $row = $query->row(); - return $row->ver; - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * Accepts an SQL string as input and returns a result object upon - * successful execution of a "read" type query. Returns boolean TRUE - * upon successful execution of a "write" type query. Returns boolean - * FALSE upon failure, and if the $db_debug variable is set to TRUE - * will raise an error. - * - * @access public - * @param string An SQL query string - * @param array An array of binding data - * @return mixed - */ - function query($sql, $binds = FALSE, $return_object = TRUE) - { - if ($sql == '') - { - if ($this->db_debug) - { - log_message('error', 'Invalid query: '.$sql); - return $this->display_error('db_invalid_query'); - } - return FALSE; - } - - // Is query caching enabled? If the query is a "read type" - // we will load the caching class and return the previously - // cached query if it exists - if ($this->cache_on == TRUE AND stristr($sql, 'SELECT')) - { - if ($this->_cache_init()) - { - $this->load_rdriver(); - if (FALSE !== ($cache = $this->CACHE->read($sql))) - { - return $cache; - } - } - } - - // Compile binds if needed - if ($binds !== FALSE) - { - $sql = $this->compile_binds($sql, $binds); - } - - // Save the query for debugging - $this->queries[] = $sql; - - // Start the Query Timer - $time_start = list($sm, $ss) = explode(' ', microtime()); - - // Run the Query - if (FALSE === ($this->result_id = $this->simple_query($sql))) - { - // This will trigger a rollback if transactions are being used - $this->_trans_failure = TRUE; - - if ($this->db_debug) - { - log_message('error', 'Query error: '.$this->_error_message()); - return $this->display_error( - array( - 'Error Number: '.$this->_error_number(), - $this->_error_message(), - $sql - ) - ); - } - - return FALSE; - } - - // Stop and aggregate the query time results - $time_end = list($em, $es) = explode(' ', microtime()); - $this->benchmark += ($em + $es) - ($sm + $ss); - - // Increment the query counter - $this->query_count++; - - // Was the query a "write" type? - // If so we'll simply return true - if ($this->is_write_type($sql) === TRUE) - { - // If caching is enabled we'll auto-cleanup any - // existing files related to this particular URI - if ($this->cache_on == TRUE AND $this->cache_autodel == TRUE AND $this->_cache_init()) - { - $this->CACHE->delete(); - } - - return TRUE; - } - - // Return TRUE if we don't need to create a result object - // Currently only the Oracle driver uses this when stored - // procedures are used - if ($return_object !== TRUE) - { - return TRUE; - } - - // Load and instantiate the result driver - - $driver = $this->load_rdriver(); - $RES = new $driver(); - $RES->conn_id = $this->conn_id; - $RES->result_id = $this->result_id; - - if ($this->dbdriver == 'oci8') - { - $RES->stmt_id = $this->stmt_id; - $RES->curs_id = NULL; - $RES->limit_used = $this->limit_used; - } - - // Is query caching enabled? If so, we'll serialize the - // result object and save it to a cache file. - if ($this->cache_on == TRUE AND $this->_cache_init()) - { - // We'll create a new instance of the result object - // only without the platform specific driver since - // we can't use it with cached data (the query result - // resource ID won't be any good once we've cached the - // result object, so we'll have to compile the data - // and save it) - $CR = new CI_DB_result(); - $CR->num_rows = $RES->num_rows(); - $CR->result_object = $RES->result_object(); - $CR->result_array = $RES->result_array(); - - // Reset these since cached objects can not utilize resource IDs. - $CR->conn_id = NULL; - $CR->result_id = NULL; - - $this->CACHE->write($sql, $CR); - } - - return $RES; - } - - // -------------------------------------------------------------------- - - /** - * Load the result drivers - * - * @access public - * @return string the name of the result class - */ - function load_rdriver() - { - $driver = 'CI_DB_'.$this->dbdriver.'_result'; - - if ( ! class_exists($driver)) - { - include_once(BASEPATH.'database/DB_result'.EXT); - include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result'.EXT); - } - - return $driver; - } - - // -------------------------------------------------------------------- - - /** - * Simple Query - * This is a simplified version of the query() function. Internally - * we only use it when running transaction commands since they do - * not require all the features of the main query() function. - * - * @access public - * @param string the sql query - * @return mixed - */ - function simple_query($sql) - { - if ( ! $this->conn_id) - { - $this->initialize(); - } - - return $this->_execute($sql); - } - - // -------------------------------------------------------------------- - - /** - * Disable Transactions - * This permits transactions to be disabled at run-time. - * - * @access public - * @return void - */ - function trans_off() - { - $this->trans_enabled = FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Start Transaction - * - * @access public - * @return void - */ - function trans_start($test_mode = FALSE) - { - if ( ! $this->trans_enabled) - { - return FALSE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - $this->_trans_depth += 1; - return; - } - - $this->trans_begin($test_mode); - } - - // -------------------------------------------------------------------- - - /** - * Complete Transaction - * - * @access public - * @return bool - */ - function trans_complete() - { - if ( ! $this->trans_enabled) - { - return FALSE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 1) - { - $this->_trans_depth -= 1; - return TRUE; - } - - // The query() function will set this flag to TRUE in the event that a query failed - if ($this->_trans_failure === TRUE) - { - $this->trans_rollback(); - - if ($this->db_debug) - { - return $this->display_error('db_transaction_failure'); - } - return FALSE; - } - - $this->trans_commit(); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Lets you retrieve the transaction flag to determine if it has failed - * - * @access public - * @return bool - */ - function trans_status() - { - return $this->_trans_failure; - } - - // -------------------------------------------------------------------- - - /** - * Compile Bindings - * - * @access public - * @param string the sql statement - * @param array an array of bind data - * @return string - */ - function compile_binds($sql, $binds) - { - if (FALSE === strpos($sql, $this->bind_marker)) - { - return $sql; - } - - if ( ! is_array($binds)) - { - $binds = array($binds); - } - - foreach ($binds as $val) - { - $val = $this->escape($val); - - // Just in case the replacement string contains the bind - // character we'll temporarily replace it with a marker - $val = str_replace($this->bind_marker, '{%bind_marker%}', $val); - $sql = preg_replace("#".preg_quote($this->bind_marker, '#')."#", str_replace('$', '\$', $val), $sql, 1); - } - - return str_replace('{%bind_marker%}', $this->bind_marker, $sql); - } - - // -------------------------------------------------------------------- - - /** - * Determines if a query is a "write" type. - * - * @access public - * @param string An SQL query string - * @return boolean - */ - function is_write_type($sql) - { - if ( ! preg_match('/^\s*"?(INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql)) - { - return FALSE; - } - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Calculate the aggregate query elapsed time - * - * @access public - * @param integer The number of decimal places - * @return integer - */ - function elapsed_time($decimals = 6) - { - return number_format($this->benchmark, $decimals); - } - - // -------------------------------------------------------------------- - - /** - * Returns the total number of queries - * - * @access public - * @return integer - */ - function total_queries() - { - return $this->query_count; - } - - // -------------------------------------------------------------------- - - /** - * Returns the last query that was executed - * - * @access public - * @return void - */ - function last_query() - { - return end($this->queries); - } - - // -------------------------------------------------------------------- - - /** - * "Smart" Escape String - * - * Escapes data based on type - * Sets boolean and null types - * - * @access public - * @param string - * @return integer - */ - function escape($str) - { - switch (gettype($str)) - { - case 'string' : $str = "'".$this->escape_str($str)."'"; - break; - case 'boolean' : $str = ($str === FALSE) ? 0 : 1; - break; - default : $str = ($str === NULL) ? 'NULL' : $str; - break; - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Primary - * - * Retrieves the primary key. It assumes that the row in the first - * position is the primary key - * - * @access public - * @param string the table name - * @return string - */ - function primary($table = '') - { - $fields = $this->list_fields($table); - - if ( ! is_array($fields)) - { - return FALSE; - } - - return current($fields); - } - - // -------------------------------------------------------------------- - - /** - * Returns an array of table names - * - * @access public - * @return array - */ - function list_tables() - { - // Is there a cached result? - if (isset($this->data_cache['table_names'])) - { - return $this->data_cache['table_names']; - } - - if (FALSE === ($sql = $this->_list_tables())) - { - if ($this->db_debug) - { - return $this->display_error('db_unsupported_function'); - } - return FALSE; - } - - $retval = array(); - $query = $this->query($sql); - - if ($query->num_rows() > 0) - { - foreach($query->result_array() as $row) - { - if (isset($row['TABLE_NAME'])) - { - $retval[] = $row['TABLE_NAME']; - } - else - { - $retval[] = array_shift($row); - } - } - } - - $this->data_cache['table_names'] = $retval; - return $this->data_cache['table_names']; - } - - // -------------------------------------------------------------------- - - /** - * Determine if a particular table exists - * @access public - * @return boolean - */ - function table_exists($table_name) - { - return ( ! in_array($this->dbprefix.$table_name, $this->list_tables())) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Fetch MySQL Field Names - * - * @access public - * @param string the table name - * @return array - */ - function list_fields($table = '') - { - // Is there a cached result? - if (isset($this->data_cache['field_names'][$table])) - { - return $this->data_cache['field_names'][$table]; - } - - if ($table == '') - { - if ($this->db_debug) - { - return $this->display_error('db_field_param_missing'); - } - return FALSE; - } - - if (FALSE === ($sql = $this->_list_columns($this->dbprefix.$table))) - { - if ($this->db_debug) - { - return $this->display_error('db_unsupported_function'); - } - return FALSE; - } - - $query = $this->query($sql); - - $retval = array(); - foreach($query->result_array() as $row) - { - if (isset($row['COLUMN_NAME'])) - { - $retval[] = $row['COLUMN_NAME']; - } - else - { - $retval[] = current($row); - } - } - - $this->data_cache['field_names'][$table] = $retval; - return $this->data_cache['field_names'][$table]; - } - - // -------------------------------------------------------------------- - - /** - * Determine if a particular field exists - * @access public - * @param string - * @param string - * @return boolean - */ - function field_exists($field_name, $table_name) - { - return ( ! in_array($field_name, $this->list_fields($table_name))) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * DEPRECATED - use list_fields() - */ - function field_names($table = '') - { - return $this->list_fields($table); - } - - // -------------------------------------------------------------------- - - /** - * Returns an object with field data - * - * @access public - * @param string the table name - * @return object - */ - function field_data($table = '') - { - if ($table == '') - { - if ($this->db_debug) - { - return $this->display_error('db_field_param_missing'); - } - return FALSE; - } - - $query = $this->query($this->_field_data($this->dbprefix.$table)); - return $query->field_data(); - } - - // -------------------------------------------------------------------- - - /** - * Generate an insert string - * - * @access public - * @param string the table upon which the query will be performed - * @param array an associative array data of key/values - * @return string - */ - function insert_string($table, $data) - { - $fields = array(); - $values = array(); - - foreach($data as $key => $val) - { - $fields[] = $key; - $values[] = $this->escape($val); - } - - return $this->_insert($this->dbprefix.$table, $fields, $values); - } - - // -------------------------------------------------------------------- - - /** - * Generate an update string - * - * @access public - * @param string the table upon which the query will be performed - * @param array an associative array data of key/values - * @param mixed the "where" statement - * @return string - */ - function update_string($table, $data, $where) - { - if ($where == '') - return false; - - $fields = array(); - foreach($data as $key => $val) - { - $fields[$key] = $this->escape($val); - } - - if ( ! is_array($where)) - { - $dest = array($where); - } - else - { - $dest = array(); - foreach ($where as $key => $val) - { - $prefix = (count($dest) == 0) ? '' : ' AND '; - - if ($val != '') - { - if ( ! $this->_has_operator($key)) - { - $key .= ' ='; - } - - $val = ' '.$this->escape($val); - } - - $dest[] = $prefix.$key.$val; - } - } - - return $this->_update($this->dbprefix.$table, $fields, $dest); - } - - // -------------------------------------------------------------------- - - /** - * Enables a native PHP function to be run, using a platform agnostic wrapper. - * - * @access public - * @param string the function name - * @param mixed any parameters needed by the function - * @return mixed - */ - function call_function($function) - { - $driver = ($this->dbdriver == 'postgre') ? 'pg_' : $this->dbdriver.'_'; - - if (FALSE === strpos($driver, $function)) - { - $function = $driver.$function; - } - - if ( ! function_exists($function)) - { - if ($this->db_debug) - { - return $this->display_error('db_unsupported_function'); - } - return FALSE; - } - else - { - $args = (func_num_args() > 1) ? array_splice(func_get_args(), 1) : null; - - return call_user_func_array($function, $args); - } - } - - // -------------------------------------------------------------------- - - /** - * Set Cache Directory Path - * - * @access public - * @param string the path to the cache directory - * @return void - */ - function cache_set_path($path = '') - { - $this->cachedir = $path; - } - - // -------------------------------------------------------------------- - - /** - * Enable Query Caching - * - * @access public - * @return void - */ - function cache_on() - { - $this->cache_on = TRUE; - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Disable Query Caching - * - * @access public - * @return void - */ - function cache_off() - { - $this->cache_on = FALSE; - return FALSE; - } - - - // -------------------------------------------------------------------- - - /** - * Delete the cache files associated with a particular URI - * - * @access public - * @return void - */ - function cache_delete($segment_one = '', $segment_two = '') - { - if ( ! $this->_cache_init()) - { - return FALSE; - } - return $this->CACHE->delete($segment_one, $segment_two); - } - - // -------------------------------------------------------------------- - - /** - * Delete All cache files - * - * @access public - * @return void - */ - function cache_delete_all() - { - if ( ! $this->_cache_init()) - { - return FALSE; - } - - return $this->CACHE->delete_all(); - } - - // -------------------------------------------------------------------- - - /** - * Initialize the Cache Class - * - * @access private - * @return void - */ - function _cache_init() - { - if (is_object($this->CACHE) AND class_exists('CI_DB_Cache')) - { - return TRUE; - } - - if ( ! @include(BASEPATH.'database/DB_cache'.EXT)) - { - return $this->cache_off(); - } - - $this->CACHE = new CI_DB_Cache; - return TRUE; - } - - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @return void - */ - function close() - { - if (is_resource($this->conn_id)) - { - $this->_close($this->conn_id); - } - $this->conn_id = FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Display an error message - * - * @access public - * @param string the error message - * @param string any "swap" values - * @param boolean whether to localize the message - * @return string sends the application/error_db.php template - */ - function display_error($error = '', $swap = '', $native = FALSE) - { - $LANG = new CI_Language(); - $LANG->load('db'); - - $heading = 'MySQL Error'; - - if ($native == TRUE) - { - $message = $error; - } - else - { - $message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error; - } - - if ( ! class_exists('CI_Exceptions')) - { - include(BASEPATH.'libraries/Exceptions'.EXT); - } - - $error = new CI_Exceptions(); - echo $error->show_error('An Error Was Encountered', $message, 'error_db'); - exit; - } - -} - +initialize($params); + log_message('debug', 'Database Driver Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Initialize Database Settings + * + * @access private Called by the constructor + * @param mixed + * @return void + */ + function initialize($params = '') + { + if (is_array($params)) + { + $defaults = array( + 'hostname' => '', + 'username' => '', + 'password' => '', + 'database' => '', + 'conn_id' => FALSE, + 'dbdriver' => 'mysql', + 'dbprefix' => '', + 'port' => '', + 'pconnect' => FALSE, + 'db_debug' => FALSE, + 'cachedir' => '', + 'cache_on' => FALSE + ); + + foreach ($defaults as $key => $val) + { + $this->$key = ( ! isset($params[$key])) ? $val : $params[$key]; + } + } + elseif (strpos($params, '://')) + { + if (FALSE === ($dsn = @parse_url($params))) + { + log_message('error', 'Invalid DB Connection String'); + + if ($this->db_debug) + { + return $this->display_error('db_invalid_connection_str'); + } + return FALSE; + } + + $this->hostname = ( ! isset($dsn['host'])) ? '' : rawurldecode($dsn['host']); + $this->username = ( ! isset($dsn['user'])) ? '' : rawurldecode($dsn['user']); + $this->password = ( ! isset($dsn['pass'])) ? '' : rawurldecode($dsn['pass']); + $this->database = ( ! isset($dsn['path'])) ? '' : rawurldecode(substr($dsn['path'], 1)); + } + + // If an existing DB connection resource is supplied + // there is no need to connect and select the database + if (is_resource($this->conn_id)) + { + return TRUE; + } + + // Connect to the database + $this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect(); + + // No connection? Throw an error + if ( ! $this->conn_id) + { + log_message('error', 'Unable to connect to the database'); + + if ($this->db_debug) + { + $this->display_error('db_unable_to_connect'); + } + return FALSE; + } + + // Select the database + if ($this->database != '') + { + if ( ! $this->db_select()) + { + log_message('error', 'Unable to select database: '.$this->database); + + if ($this->db_debug) + { + $this->display_error('db_unable_to_select', $this->database); + } + return FALSE; + } + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * The name of the platform in use (mysql, mssql, etc...) + * + * @access public + * @return string + */ + function platform() + { + return $this->dbdriver; + } + + // -------------------------------------------------------------------- + + /** + * Database Version Number. Returns a string containing the + * version of the database being used + * + * @access public + * @return string + */ + function version() + { + if (FALSE === ($sql = $this->_version())) + { + if ($this->db_debug) + { + return $this->display_error('db_unsupported_function'); + } + return FALSE; + } + + if ($this->dbdriver == 'oci8') + { + return $sql; + } + + $query = $this->query($sql); + $row = $query->row(); + return $row->ver; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * Accepts an SQL string as input and returns a result object upon + * successful execution of a "read" type query. Returns boolean TRUE + * upon successful execution of a "write" type query. Returns boolean + * FALSE upon failure, and if the $db_debug variable is set to TRUE + * will raise an error. + * + * @access public + * @param string An SQL query string + * @param array An array of binding data + * @return mixed + */ + function query($sql, $binds = FALSE, $return_object = TRUE) + { + if ($sql == '') + { + if ($this->db_debug) + { + log_message('error', 'Invalid query: '.$sql); + return $this->display_error('db_invalid_query'); + } + return FALSE; + } + + // Is query caching enabled? If the query is a "read type" + // we will load the caching class and return the previously + // cached query if it exists + if ($this->cache_on == TRUE AND stristr($sql, 'SELECT')) + { + if ($this->_cache_init()) + { + $this->load_rdriver(); + if (FALSE !== ($cache = $this->CACHE->read($sql))) + { + return $cache; + } + } + } + + // Compile binds if needed + if ($binds !== FALSE) + { + $sql = $this->compile_binds($sql, $binds); + } + + // Save the query for debugging + $this->queries[] = $sql; + + // Start the Query Timer + $time_start = list($sm, $ss) = explode(' ', microtime()); + + // Run the Query + if (FALSE === ($this->result_id = $this->simple_query($sql))) + { + // This will trigger a rollback if transactions are being used + $this->_trans_failure = TRUE; + + if ($this->db_debug) + { + log_message('error', 'Query error: '.$this->_error_message()); + return $this->display_error( + array( + 'Error Number: '.$this->_error_number(), + $this->_error_message(), + $sql + ) + ); + } + + return FALSE; + } + + // Stop and aggregate the query time results + $time_end = list($em, $es) = explode(' ', microtime()); + $this->benchmark += ($em + $es) - ($sm + $ss); + + // Increment the query counter + $this->query_count++; + + // Was the query a "write" type? + // If so we'll simply return true + if ($this->is_write_type($sql) === TRUE) + { + // If caching is enabled we'll auto-cleanup any + // existing files related to this particular URI + if ($this->cache_on == TRUE AND $this->cache_autodel == TRUE AND $this->_cache_init()) + { + $this->CACHE->delete(); + } + + return TRUE; + } + + // Return TRUE if we don't need to create a result object + // Currently only the Oracle driver uses this when stored + // procedures are used + if ($return_object !== TRUE) + { + return TRUE; + } + + // Load and instantiate the result driver + + $driver = $this->load_rdriver(); + $RES = new $driver(); + $RES->conn_id = $this->conn_id; + $RES->result_id = $this->result_id; + + if ($this->dbdriver == 'oci8') + { + $RES->stmt_id = $this->stmt_id; + $RES->curs_id = NULL; + $RES->limit_used = $this->limit_used; + } + + // Is query caching enabled? If so, we'll serialize the + // result object and save it to a cache file. + if ($this->cache_on == TRUE AND $this->_cache_init()) + { + // We'll create a new instance of the result object + // only without the platform specific driver since + // we can't use it with cached data (the query result + // resource ID won't be any good once we've cached the + // result object, so we'll have to compile the data + // and save it) + $CR = new CI_DB_result(); + $CR->num_rows = $RES->num_rows(); + $CR->result_object = $RES->result_object(); + $CR->result_array = $RES->result_array(); + + // Reset these since cached objects can not utilize resource IDs. + $CR->conn_id = NULL; + $CR->result_id = NULL; + + $this->CACHE->write($sql, $CR); + } + + return $RES; + } + + // -------------------------------------------------------------------- + + /** + * Load the result drivers + * + * @access public + * @return string the name of the result class + */ + function load_rdriver() + { + $driver = 'CI_DB_'.$this->dbdriver.'_result'; + + if ( ! class_exists($driver)) + { + include_once(BASEPATH.'database/DB_result'.EXT); + include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result'.EXT); + } + + return $driver; + } + + // -------------------------------------------------------------------- + + /** + * Simple Query + * This is a simplified version of the query() function. Internally + * we only use it when running transaction commands since they do + * not require all the features of the main query() function. + * + * @access public + * @param string the sql query + * @return mixed + */ + function simple_query($sql) + { + if ( ! $this->conn_id) + { + $this->initialize(); + } + + return $this->_execute($sql); + } + + // -------------------------------------------------------------------- + + /** + * Disable Transactions + * This permits transactions to be disabled at run-time. + * + * @access public + * @return void + */ + function trans_off() + { + $this->trans_enabled = FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Start Transaction + * + * @access public + * @return void + */ + function trans_start($test_mode = FALSE) + { + if ( ! $this->trans_enabled) + { + return FALSE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + $this->_trans_depth += 1; + return; + } + + $this->trans_begin($test_mode); + } + + // -------------------------------------------------------------------- + + /** + * Complete Transaction + * + * @access public + * @return bool + */ + function trans_complete() + { + if ( ! $this->trans_enabled) + { + return FALSE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 1) + { + $this->_trans_depth -= 1; + return TRUE; + } + + // The query() function will set this flag to TRUE in the event that a query failed + if ($this->_trans_failure === TRUE) + { + $this->trans_rollback(); + + if ($this->db_debug) + { + return $this->display_error('db_transaction_failure'); + } + return FALSE; + } + + $this->trans_commit(); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Lets you retrieve the transaction flag to determine if it has failed + * + * @access public + * @return bool + */ + function trans_status() + { + return $this->_trans_failure; + } + + // -------------------------------------------------------------------- + + /** + * Compile Bindings + * + * @access public + * @param string the sql statement + * @param array an array of bind data + * @return string + */ + function compile_binds($sql, $binds) + { + if (FALSE === strpos($sql, $this->bind_marker)) + { + return $sql; + } + + if ( ! is_array($binds)) + { + $binds = array($binds); + } + + foreach ($binds as $val) + { + $val = $this->escape($val); + + // Just in case the replacement string contains the bind + // character we'll temporarily replace it with a marker + $val = str_replace($this->bind_marker, '{%bind_marker%}', $val); + $sql = preg_replace("#".preg_quote($this->bind_marker, '#')."#", str_replace('$', '\$', $val), $sql, 1); + } + + return str_replace('{%bind_marker%}', $this->bind_marker, $sql); + } + + // -------------------------------------------------------------------- + + /** + * Determines if a query is a "write" type. + * + * @access public + * @param string An SQL query string + * @return boolean + */ + function is_write_type($sql) + { + if ( ! preg_match('/^\s*"?(INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql)) + { + return FALSE; + } + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Calculate the aggregate query elapsed time + * + * @access public + * @param integer The number of decimal places + * @return integer + */ + function elapsed_time($decimals = 6) + { + return number_format($this->benchmark, $decimals); + } + + // -------------------------------------------------------------------- + + /** + * Returns the total number of queries + * + * @access public + * @return integer + */ + function total_queries() + { + return $this->query_count; + } + + // -------------------------------------------------------------------- + + /** + * Returns the last query that was executed + * + * @access public + * @return void + */ + function last_query() + { + return end($this->queries); + } + + // -------------------------------------------------------------------- + + /** + * "Smart" Escape String + * + * Escapes data based on type + * Sets boolean and null types + * + * @access public + * @param string + * @return integer + */ + function escape($str) + { + switch (gettype($str)) + { + case 'string' : $str = "'".$this->escape_str($str)."'"; + break; + case 'boolean' : $str = ($str === FALSE) ? 0 : 1; + break; + default : $str = ($str === NULL) ? 'NULL' : $str; + break; + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Primary + * + * Retrieves the primary key. It assumes that the row in the first + * position is the primary key + * + * @access public + * @param string the table name + * @return string + */ + function primary($table = '') + { + $fields = $this->list_fields($table); + + if ( ! is_array($fields)) + { + return FALSE; + } + + return current($fields); + } + + // -------------------------------------------------------------------- + + /** + * Returns an array of table names + * + * @access public + * @return array + */ + function list_tables() + { + // Is there a cached result? + if (isset($this->data_cache['table_names'])) + { + return $this->data_cache['table_names']; + } + + if (FALSE === ($sql = $this->_list_tables())) + { + if ($this->db_debug) + { + return $this->display_error('db_unsupported_function'); + } + return FALSE; + } + + $retval = array(); + $query = $this->query($sql); + + if ($query->num_rows() > 0) + { + foreach($query->result_array() as $row) + { + if (isset($row['TABLE_NAME'])) + { + $retval[] = $row['TABLE_NAME']; + } + else + { + $retval[] = array_shift($row); + } + } + } + + $this->data_cache['table_names'] = $retval; + return $this->data_cache['table_names']; + } + + // -------------------------------------------------------------------- + + /** + * Determine if a particular table exists + * @access public + * @return boolean + */ + function table_exists($table_name) + { + return ( ! in_array($this->dbprefix.$table_name, $this->list_tables())) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Fetch MySQL Field Names + * + * @access public + * @param string the table name + * @return array + */ + function list_fields($table = '') + { + // Is there a cached result? + if (isset($this->data_cache['field_names'][$table])) + { + return $this->data_cache['field_names'][$table]; + } + + if ($table == '') + { + if ($this->db_debug) + { + return $this->display_error('db_field_param_missing'); + } + return FALSE; + } + + if (FALSE === ($sql = $this->_list_columns($this->dbprefix.$table))) + { + if ($this->db_debug) + { + return $this->display_error('db_unsupported_function'); + } + return FALSE; + } + + $query = $this->query($sql); + + $retval = array(); + foreach($query->result_array() as $row) + { + if (isset($row['COLUMN_NAME'])) + { + $retval[] = $row['COLUMN_NAME']; + } + else + { + $retval[] = current($row); + } + } + + $this->data_cache['field_names'][$table] = $retval; + return $this->data_cache['field_names'][$table]; + } + + // -------------------------------------------------------------------- + + /** + * Determine if a particular field exists + * @access public + * @param string + * @param string + * @return boolean + */ + function field_exists($field_name, $table_name) + { + return ( ! in_array($field_name, $this->list_fields($table_name))) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * DEPRECATED - use list_fields() + */ + function field_names($table = '') + { + return $this->list_fields($table); + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @access public + * @param string the table name + * @return object + */ + function field_data($table = '') + { + if ($table == '') + { + if ($this->db_debug) + { + return $this->display_error('db_field_param_missing'); + } + return FALSE; + } + + $query = $this->query($this->_field_data($this->dbprefix.$table)); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * Generate an insert string + * + * @access public + * @param string the table upon which the query will be performed + * @param array an associative array data of key/values + * @return string + */ + function insert_string($table, $data) + { + $fields = array(); + $values = array(); + + foreach($data as $key => $val) + { + $fields[] = $key; + $values[] = $this->escape($val); + } + + return $this->_insert($this->dbprefix.$table, $fields, $values); + } + + // -------------------------------------------------------------------- + + /** + * Generate an update string + * + * @access public + * @param string the table upon which the query will be performed + * @param array an associative array data of key/values + * @param mixed the "where" statement + * @return string + */ + function update_string($table, $data, $where) + { + if ($where == '') + return false; + + $fields = array(); + foreach($data as $key => $val) + { + $fields[$key] = $this->escape($val); + } + + if ( ! is_array($where)) + { + $dest = array($where); + } + else + { + $dest = array(); + foreach ($where as $key => $val) + { + $prefix = (count($dest) == 0) ? '' : ' AND '; + + if ($val != '') + { + if ( ! $this->_has_operator($key)) + { + $key .= ' ='; + } + + $val = ' '.$this->escape($val); + } + + $dest[] = $prefix.$key.$val; + } + } + + return $this->_update($this->dbprefix.$table, $fields, $dest); + } + + // -------------------------------------------------------------------- + + /** + * Enables a native PHP function to be run, using a platform agnostic wrapper. + * + * @access public + * @param string the function name + * @param mixed any parameters needed by the function + * @return mixed + */ + function call_function($function) + { + $driver = ($this->dbdriver == 'postgre') ? 'pg_' : $this->dbdriver.'_'; + + if (FALSE === strpos($driver, $function)) + { + $function = $driver.$function; + } + + if ( ! function_exists($function)) + { + if ($this->db_debug) + { + return $this->display_error('db_unsupported_function'); + } + return FALSE; + } + else + { + $args = (func_num_args() > 1) ? array_splice(func_get_args(), 1) : null; + + return call_user_func_array($function, $args); + } + } + + // -------------------------------------------------------------------- + + /** + * Set Cache Directory Path + * + * @access public + * @param string the path to the cache directory + * @return void + */ + function cache_set_path($path = '') + { + $this->cachedir = $path; + } + + // -------------------------------------------------------------------- + + /** + * Enable Query Caching + * + * @access public + * @return void + */ + function cache_on() + { + $this->cache_on = TRUE; + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Disable Query Caching + * + * @access public + * @return void + */ + function cache_off() + { + $this->cache_on = FALSE; + return FALSE; + } + + + // -------------------------------------------------------------------- + + /** + * Delete the cache files associated with a particular URI + * + * @access public + * @return void + */ + function cache_delete($segment_one = '', $segment_two = '') + { + if ( ! $this->_cache_init()) + { + return FALSE; + } + return $this->CACHE->delete($segment_one, $segment_two); + } + + // -------------------------------------------------------------------- + + /** + * Delete All cache files + * + * @access public + * @return void + */ + function cache_delete_all() + { + if ( ! $this->_cache_init()) + { + return FALSE; + } + + return $this->CACHE->delete_all(); + } + + // -------------------------------------------------------------------- + + /** + * Initialize the Cache Class + * + * @access private + * @return void + */ + function _cache_init() + { + if (is_object($this->CACHE) AND class_exists('CI_DB_Cache')) + { + return TRUE; + } + + if ( ! @include(BASEPATH.'database/DB_cache'.EXT)) + { + return $this->cache_off(); + } + + $this->CACHE = new CI_DB_Cache; + return TRUE; + } + + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @return void + */ + function close() + { + if (is_resource($this->conn_id)) + { + $this->_close($this->conn_id); + } + $this->conn_id = FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Display an error message + * + * @access public + * @param string the error message + * @param string any "swap" values + * @param boolean whether to localize the message + * @return string sends the application/error_db.php template + */ + function display_error($error = '', $swap = '', $native = FALSE) + { + $LANG = new CI_Language(); + $LANG->load('db'); + + $heading = 'MySQL Error'; + + if ($native == TRUE) + { + $message = $error; + } + else + { + $message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error; + } + + if ( ! class_exists('CI_Exceptions')) + { + include(BASEPATH.'libraries/Exceptions'.EXT); + } + + $error = new CI_Exceptions(); + echo $error->show_error('An Error Was Encountered', $message, 'error_db'); + exit; + } + +} + ?> \ No newline at end of file diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 9784561d4..7d85ebb92 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -1,290 +1,290 @@ -result_object() : $this->result_array(); - } - - // -------------------------------------------------------------------- - - /** - * Query result. "object" version. - * - * @access public - * @return object - */ - function result_object() - { - if (count($this->result_object) > 0) - { - return $this->result_object; - } - - // In the event that query caching is on the result_id variable - // will return FALSE since there isn't a valid SQL resource so - // we'll simply return an empty array. - if ($this->result_id === FALSE OR $this->num_rows() == 0) - { - return array(); - } - - $this->_data_seek(0); - while ($row = $this->_fetch_object()) - { - $this->result_object[] = $row; - } - - return $this->result_object; - } - - // -------------------------------------------------------------------- - - /** - * Query result. "array" version. - * - * @access public - * @return array - */ - function result_array() - { - if (count($this->result_array) > 0) - { - return $this->result_array; - } - - // In the event that query caching is on the result_id variable - // will return FALSE since there isn't a valid SQL resource so - // we'll simply return an empty array. - if ($this->result_id === FALSE OR $this->num_rows() == 0) - { - return array(); - } - - $this->_data_seek(0); - while ($row = $this->_fetch_assoc()) - { - $this->result_array[] = $row; - } - - return $this->result_array; - } - - // -------------------------------------------------------------------- - - /** - * Query result. Acts as a wrapper function for the following functions. - * - * @access public - * @param string can be "object" or "array" - * @return mixed either a result object or array - */ - function row($n = 0, $type = 'object') - { - return ($type == 'object') ? $this->row_object($n) : $this->row_array($n); - } - - // -------------------------------------------------------------------- - - /** - * Returns a single result row - object version - * - * @access public - * @return object - */ - function row_object($n = 0) - { - $result = $this->result_object(); - - if (count($result) == 0) - { - return $result; - } - - if ($n != $this->current_row AND isset($result[$n])) - { - $this->current_row = $n; - } - - return $result[$this->current_row]; - } - - // -------------------------------------------------------------------- - - /** - * Returns a single result row - array version - * - * @access public - * @return array - */ - function row_array($n = 0) - { - $result = $this->result_array(); - - if (count($result) == 0) - { - return $result; - } - - if ($n != $this->current_row AND isset($result[$n])) - { - $this->current_row = $n; - } - - return $result[$this->current_row]; - } - - - // -------------------------------------------------------------------- - - /** - * Returns the "first" row - * - * @access public - * @return object - */ - function first_row($type = 'object') - { - $result = $this->result($type); - - if (count($result) == 0) - { - return $result; - } - return $result[0]; - } - - // -------------------------------------------------------------------- - - /** - * Returns the "last" row - * - * @access public - * @return object - */ - function last_row($type = 'object') - { - $result = $this->result($type); - - if (count($result) == 0) - { - return $result; - } - return $result[count($result) -1]; - } - - // -------------------------------------------------------------------- - - /** - * Returns the "next" row - * - * @access public - * @return object - */ - function next_row($type = 'object') - { - $result = $this->result($type); - - if (count($result) == 0) - { - return $result; - } - - if (isset($result[$this->current_row + 1])) - { - ++$this->current_row; - } - - return $result[$this->current_row]; - } - - // -------------------------------------------------------------------- - - /** - * Returns the "previous" row - * - * @access public - * @return object - */ - function previous_row($type = 'object') - { - $result = $this->result($type); - - if (count($result) == 0) - { - return $result; - } - - if (isset($result[$this->current_row - 1])) - { - --$this->current_row; - } - return $result[$this->current_row]; - } - - // -------------------------------------------------------------------- - - /** - * The following functions are normally overloaded by the identically named - * methods in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver. - * These functions are primarily here to prevent undefined function errors - * when a cached result object is in use. They are not otherwise fully - * operational due to the unavailability of the database resource IDs with - * cached results. - */ - function num_rows() { return $this->num_rows; } - function num_fields() { return 0; } - function list_fields() { return array(); } - function field_names() { return array(); } // Deprecated - function field_data() { return array(); } - function free_result() { return TRUE; } - function _data_seek() { return TRUE; } - function _fetch_assoc() { return array(); } - function _fetch_object() { return array(); } - -} -// END DB_result class +result_object() : $this->result_array(); + } + + // -------------------------------------------------------------------- + + /** + * Query result. "object" version. + * + * @access public + * @return object + */ + function result_object() + { + if (count($this->result_object) > 0) + { + return $this->result_object; + } + + // In the event that query caching is on the result_id variable + // will return FALSE since there isn't a valid SQL resource so + // we'll simply return an empty array. + if ($this->result_id === FALSE OR $this->num_rows() == 0) + { + return array(); + } + + $this->_data_seek(0); + while ($row = $this->_fetch_object()) + { + $this->result_object[] = $row; + } + + return $this->result_object; + } + + // -------------------------------------------------------------------- + + /** + * Query result. "array" version. + * + * @access public + * @return array + */ + function result_array() + { + if (count($this->result_array) > 0) + { + return $this->result_array; + } + + // In the event that query caching is on the result_id variable + // will return FALSE since there isn't a valid SQL resource so + // we'll simply return an empty array. + if ($this->result_id === FALSE OR $this->num_rows() == 0) + { + return array(); + } + + $this->_data_seek(0); + while ($row = $this->_fetch_assoc()) + { + $this->result_array[] = $row; + } + + return $this->result_array; + } + + // -------------------------------------------------------------------- + + /** + * Query result. Acts as a wrapper function for the following functions. + * + * @access public + * @param string can be "object" or "array" + * @return mixed either a result object or array + */ + function row($n = 0, $type = 'object') + { + return ($type == 'object') ? $this->row_object($n) : $this->row_array($n); + } + + // -------------------------------------------------------------------- + + /** + * Returns a single result row - object version + * + * @access public + * @return object + */ + function row_object($n = 0) + { + $result = $this->result_object(); + + if (count($result) == 0) + { + return $result; + } + + if ($n != $this->current_row AND isset($result[$n])) + { + $this->current_row = $n; + } + + return $result[$this->current_row]; + } + + // -------------------------------------------------------------------- + + /** + * Returns a single result row - array version + * + * @access public + * @return array + */ + function row_array($n = 0) + { + $result = $this->result_array(); + + if (count($result) == 0) + { + return $result; + } + + if ($n != $this->current_row AND isset($result[$n])) + { + $this->current_row = $n; + } + + return $result[$this->current_row]; + } + + + // -------------------------------------------------------------------- + + /** + * Returns the "first" row + * + * @access public + * @return object + */ + function first_row($type = 'object') + { + $result = $this->result($type); + + if (count($result) == 0) + { + return $result; + } + return $result[0]; + } + + // -------------------------------------------------------------------- + + /** + * Returns the "last" row + * + * @access public + * @return object + */ + function last_row($type = 'object') + { + $result = $this->result($type); + + if (count($result) == 0) + { + return $result; + } + return $result[count($result) -1]; + } + + // -------------------------------------------------------------------- + + /** + * Returns the "next" row + * + * @access public + * @return object + */ + function next_row($type = 'object') + { + $result = $this->result($type); + + if (count($result) == 0) + { + return $result; + } + + if (isset($result[$this->current_row + 1])) + { + ++$this->current_row; + } + + return $result[$this->current_row]; + } + + // -------------------------------------------------------------------- + + /** + * Returns the "previous" row + * + * @access public + * @return object + */ + function previous_row($type = 'object') + { + $result = $this->result($type); + + if (count($result) == 0) + { + return $result; + } + + if (isset($result[$this->current_row - 1])) + { + --$this->current_row; + } + return $result[$this->current_row]; + } + + // -------------------------------------------------------------------- + + /** + * The following functions are normally overloaded by the identically named + * methods in the platform-specific driver -- except when query caching + * is used. When caching is enabled we do not load the other driver. + * These functions are primarily here to prevent undefined function errors + * when a cached result object is in use. They are not otherwise fully + * operational due to the unavailability of the database resource IDs with + * cached results. + */ + function num_rows() { return $this->num_rows; } + function num_fields() { return 0; } + function list_fields() { return array(); } + function field_names() { return array(); } // Deprecated + function field_data() { return array(); } + function free_result() { return TRUE; } + function _data_seek() { return TRUE; } + function _fetch_assoc() { return array(); } + function _fetch_object() { return array(); } + +} +// END DB_result class ?> \ No newline at end of file diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 9533ec607..d48425d7e 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -1,455 +1,455 @@ -db - $CI =& get_instance(); - $this->db =& $CI->db; - - log_message('debug', "Database Utility Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Create database - * - * @access public - * @param string the database name - * @return bool - */ - function create_database($db_name) - { - $sql = $this->_create_database($db_name); - - if (is_bool($sql)) - { - return $sql; - } - - return $this->db->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access public - * @param string the database name - * @return bool - */ - function drop_database($db_name) - { - $sql = $this->_drop_database($db_name); - - if (is_bool($sql)) - { - return $sql; - } - - return $this->db->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * List databases - * - * @access public - * @return bool - */ - function list_databases() - { - // Is there a cached result? - if (isset($this->data_cache['db_names'])) - { - return $this->data_cache['db_names']; - } - - $query = $this->db->query($this->_list_databases()); - $dbs = array(); - if ($query->num_rows() > 0) - { - foreach ($query->result_array() as $row) - { - $dbs[] = current($row); - } - } - - $this->data_cache['db_names'] = $dbs; - return $this->data_cache['db_names']; - } - - // -------------------------------------------------------------------- - - /** - * Optimize Table - * - * @access public - * @param string the table name - * @return bool - */ - function optimize_table($table_name) - { - $sql = $this->_optimize_table($table_name); - - if (is_bool($sql)) - { - return $sql; - } - - $query = $this->db->query($sql); - $res = $query->result_array(); - - // Note: Due to a bug in current() that affects some versions - // of PHP we can not pass function call directly into it - return current($res); - } - - // -------------------------------------------------------------------- - - /** - * Optimize Database - * - * @access public - * @return array - */ - function optimize_database() - { - $result = array(); - foreach ($this->db->list_tables() as $table_name) - { - $sql = $this->_optimize_table($table_name); - - if (is_bool($sql)) - { - return $sql; - } - - $query = $this->db->query($sql); - - // Build the result array... - // Note: Due to a bug in current() that affects some versions - // of PHP we can not pass function call directly into it - $res = $query->result_array(); - $res = current($res); - $key = str_replace($this->db->database.'.', '', current($res)); - $keys = array_keys($res); - unset($res[$keys[0]]); - - $result[$key] = $res; - } - - return $result; - } - - // -------------------------------------------------------------------- - - /** - * Optimize Table - * - * @access public - * @param string the table name - * @return bool - */ - - function repair_table($table_name) - { - $sql = $this->_repair_table($table_name); - - if (is_bool($sql)) - { - return $sql; - } - - $query = $this->db->query($sql); - - // Note: Due to a bug in current() that affects some versions - // of PHP we can not pass function call directly into it - $res = $query->result_array(); - return current($res); - } - - // -------------------------------------------------------------------- - - /** - * Drop Table - * - * @access public - * @param string the table name - * @return bool - */ - function drop_table($table_name) - { - $sql = $this->_drop_table($table_name); - - if (is_bool($sql)) - { - return $sql; - } - - return $this->db->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Generate CSV from a query result object - * - * @access public - * @param object The query result object - * @param string The delimiter - tab by default - * @param string The newline character - \n by default - * @return string - */ - function csv_from_result($query, $delim = "\t", $newline = "\n") - { - if ( ! is_object($query) OR ! method_exists($query, 'field_names')) - { - show_error('You must submit a valid result object'); - } - - $out = ''; - - // First generate the headings from the table column names - foreach ($query->list_fields() as $name) - { - $out .= $name.$delim; - } - - $out = rtrim($out); - $out .= $newline; - - // Next blast through the result array and build out the rows - foreach ($query->result_array() as $row) - { - foreach ($row as $item) - { - $out .= $item.$delim; - } - $out = rtrim($out); - $out .= $newline; - } - - return $out; - } - - // -------------------------------------------------------------------- - - /** - * Generate XML data from a query result object - * - * @access public - * @param object The query result object - * @param array Any preferences - * @return string - */ - function xml_from_result($query, $params = array()) - { - if ( ! is_object($query) OR ! method_exists($query, 'field_names')) - { - show_error('You must submit a valid result object'); - } - - // Set our default values - foreach (array('root' => 'root', 'element' => 'element', 'newline' => "\n", 'tab' => "\t") as $key => $val) - { - if ( ! isset($params[$key])) - { - $params[$key] = $val; - } - } - - // Create variables for convenience - extract($params); - - // Load the xml helper - $CI =& get_instance(); - $CI->load->helper('xml'); - - // Generate the result - $xml = "<{$root}>".$newline; - foreach ($query->result_array() as $row) - { - $xml .= $tab."<{$element}>".$newline; - - foreach ($row as $key => $val) - { - $xml .= $tab.$tab."<{$key}>".xml_convert($val)."".$newline; - } - $xml .= $tab."".$newline; - } - $xml .= "".$newline; - - return $xml; - } - - // -------------------------------------------------------------------- - - /** - * Database Backup - * - * @access public - * @return void - */ - function backup($params = array()) - { - // If the parameters have not been submitted as an - // array then we know that it is simply the table - // name, which is a valid short cut. - if (is_string($params)) - { - $params = array('tables' => $params); - } - - // ------------------------------------------------------ - - // 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" - ); - - // Did the user submit any preferences? If so set them.... - if (count($params) > 0) - { - foreach ($prefs as $key => $val) - { - if (isset($params[$key])) - { - $prefs[$key] = $params[$key]; - } - } - } - - // ------------------------------------------------------ - - // Are we backing up a complete database or individual tables? - // If no table names were submitted we'll fetch the entire table list - if (count($prefs['tables']) == 0) - { - $prefs['tables'] = $this->db->list_tables(); - } - - // ------------------------------------------------------ - - // Validate the format - if ( ! in_array($prefs['format'], array('gzip', 'zip', 'txt'), TRUE)) - { - $prefs['format'] = 'txt'; - } - - // ------------------------------------------------------ - - // Is the encoder supported? If not, we'll either issue an - // error or use plain text depending on the debug settings - if (($prefs['format'] == 'gzip' AND ! @function_exists('gzencode')) - OR ($prefs['format'] == 'zip' AND ! @function_exists('gzcompress'))) - { - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_compression'); - } - - $prefs['format'] = 'txt'; - } - - // ------------------------------------------------------ - - // Set the filename if not provided - Only needed with Zip files - if ($prefs['filename'] == '' AND $prefs['format'] == 'zip') - { - $prefs['filename'] = (count($prefs['tables']) == 1) ? $prefs['tables'] : $this->db->database; - $prefs['filename'] .= '_'.date('Y-m-d_H-i', time()); - } - - // ------------------------------------------------------ - - // Was a Gzip file requested? - if ($prefs['format'] == 'gzip') - { - return gzencode($this->_backup($prefs)); - } - - // ------------------------------------------------------ - - // Was a text file requested? - if ($prefs['format'] == 'txt') - { - return $this->_backup($prefs); - } - - // ------------------------------------------------------ - - // Was a Zip file requested? - if ($prefs['format'] == 'zip') - { - // If they included the .zip file extension we'll remove it - if (preg_match("|.+?\.zip$|", $prefs['filename'])) - { - $prefs['filename'] = str_replace('.zip', '', $prefs['filename']); - } - - // Tack on the ".sql" file extension if needed - if ( ! preg_match("|.+?\.sql$|", $prefs['filename'])) - { - $prefs['filename'] .= '.sql'; - } - - // Load the Zip class and output it - - $CI =& get_instance(); - $CI->load->library('zip'); - $CI->zip->add_data($prefs['filename'], $this->_backup($prefs)); - return $CI->zip->get_zip(); - } - - } - - - - - - -} - +db + $CI =& get_instance(); + $this->db =& $CI->db; + + log_message('debug', "Database Utility Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Create database + * + * @access public + * @param string the database name + * @return bool + */ + function create_database($db_name) + { + $sql = $this->_create_database($db_name); + + if (is_bool($sql)) + { + return $sql; + } + + return $this->db->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access public + * @param string the database name + * @return bool + */ + function drop_database($db_name) + { + $sql = $this->_drop_database($db_name); + + if (is_bool($sql)) + { + return $sql; + } + + return $this->db->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access public + * @return bool + */ + function list_databases() + { + // Is there a cached result? + if (isset($this->data_cache['db_names'])) + { + return $this->data_cache['db_names']; + } + + $query = $this->db->query($this->_list_databases()); + $dbs = array(); + if ($query->num_rows() > 0) + { + foreach ($query->result_array() as $row) + { + $dbs[] = current($row); + } + } + + $this->data_cache['db_names'] = $dbs; + return $this->data_cache['db_names']; + } + + // -------------------------------------------------------------------- + + /** + * Optimize Table + * + * @access public + * @param string the table name + * @return bool + */ + function optimize_table($table_name) + { + $sql = $this->_optimize_table($table_name); + + if (is_bool($sql)) + { + return $sql; + } + + $query = $this->db->query($sql); + $res = $query->result_array(); + + // Note: Due to a bug in current() that affects some versions + // of PHP we can not pass function call directly into it + return current($res); + } + + // -------------------------------------------------------------------- + + /** + * Optimize Database + * + * @access public + * @return array + */ + function optimize_database() + { + $result = array(); + foreach ($this->db->list_tables() as $table_name) + { + $sql = $this->_optimize_table($table_name); + + if (is_bool($sql)) + { + return $sql; + } + + $query = $this->db->query($sql); + + // Build the result array... + // Note: Due to a bug in current() that affects some versions + // of PHP we can not pass function call directly into it + $res = $query->result_array(); + $res = current($res); + $key = str_replace($this->db->database.'.', '', current($res)); + $keys = array_keys($res); + unset($res[$keys[0]]); + + $result[$key] = $res; + } + + return $result; + } + + // -------------------------------------------------------------------- + + /** + * Optimize Table + * + * @access public + * @param string the table name + * @return bool + */ + + function repair_table($table_name) + { + $sql = $this->_repair_table($table_name); + + if (is_bool($sql)) + { + return $sql; + } + + $query = $this->db->query($sql); + + // Note: Due to a bug in current() that affects some versions + // of PHP we can not pass function call directly into it + $res = $query->result_array(); + return current($res); + } + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * @access public + * @param string the table name + * @return bool + */ + function drop_table($table_name) + { + $sql = $this->_drop_table($table_name); + + if (is_bool($sql)) + { + return $sql; + } + + return $this->db->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Generate CSV from a query result object + * + * @access public + * @param object The query result object + * @param string The delimiter - tab by default + * @param string The newline character - \n by default + * @return string + */ + function csv_from_result($query, $delim = "\t", $newline = "\n") + { + if ( ! is_object($query) OR ! method_exists($query, 'field_names')) + { + show_error('You must submit a valid result object'); + } + + $out = ''; + + // First generate the headings from the table column names + foreach ($query->list_fields() as $name) + { + $out .= $name.$delim; + } + + $out = rtrim($out); + $out .= $newline; + + // Next blast through the result array and build out the rows + foreach ($query->result_array() as $row) + { + foreach ($row as $item) + { + $out .= $item.$delim; + } + $out = rtrim($out); + $out .= $newline; + } + + return $out; + } + + // -------------------------------------------------------------------- + + /** + * Generate XML data from a query result object + * + * @access public + * @param object The query result object + * @param array Any preferences + * @return string + */ + function xml_from_result($query, $params = array()) + { + if ( ! is_object($query) OR ! method_exists($query, 'field_names')) + { + show_error('You must submit a valid result object'); + } + + // Set our default values + foreach (array('root' => 'root', 'element' => 'element', 'newline' => "\n", 'tab' => "\t") as $key => $val) + { + if ( ! isset($params[$key])) + { + $params[$key] = $val; + } + } + + // Create variables for convenience + extract($params); + + // Load the xml helper + $CI =& get_instance(); + $CI->load->helper('xml'); + + // Generate the result + $xml = "<{$root}>".$newline; + foreach ($query->result_array() as $row) + { + $xml .= $tab."<{$element}>".$newline; + + foreach ($row as $key => $val) + { + $xml .= $tab.$tab."<{$key}>".xml_convert($val)."".$newline; + } + $xml .= $tab."".$newline; + } + $xml .= "".$newline; + + return $xml; + } + + // -------------------------------------------------------------------- + + /** + * Database Backup + * + * @access public + * @return void + */ + function backup($params = array()) + { + // If the parameters have not been submitted as an + // array then we know that it is simply the table + // name, which is a valid short cut. + if (is_string($params)) + { + $params = array('tables' => $params); + } + + // ------------------------------------------------------ + + // 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" + ); + + // Did the user submit any preferences? If so set them.... + if (count($params) > 0) + { + foreach ($prefs as $key => $val) + { + if (isset($params[$key])) + { + $prefs[$key] = $params[$key]; + } + } + } + + // ------------------------------------------------------ + + // Are we backing up a complete database or individual tables? + // If no table names were submitted we'll fetch the entire table list + if (count($prefs['tables']) == 0) + { + $prefs['tables'] = $this->db->list_tables(); + } + + // ------------------------------------------------------ + + // Validate the format + if ( ! in_array($prefs['format'], array('gzip', 'zip', 'txt'), TRUE)) + { + $prefs['format'] = 'txt'; + } + + // ------------------------------------------------------ + + // Is the encoder supported? If not, we'll either issue an + // error or use plain text depending on the debug settings + if (($prefs['format'] == 'gzip' AND ! @function_exists('gzencode')) + OR ($prefs['format'] == 'zip' AND ! @function_exists('gzcompress'))) + { + if ($this->db->db_debug) + { + return $this->db->display_error('db_unsuported_compression'); + } + + $prefs['format'] = 'txt'; + } + + // ------------------------------------------------------ + + // Set the filename if not provided - Only needed with Zip files + if ($prefs['filename'] == '' AND $prefs['format'] == 'zip') + { + $prefs['filename'] = (count($prefs['tables']) == 1) ? $prefs['tables'] : $this->db->database; + $prefs['filename'] .= '_'.date('Y-m-d_H-i', time()); + } + + // ------------------------------------------------------ + + // Was a Gzip file requested? + if ($prefs['format'] == 'gzip') + { + return gzencode($this->_backup($prefs)); + } + + // ------------------------------------------------------ + + // Was a text file requested? + if ($prefs['format'] == 'txt') + { + return $this->_backup($prefs); + } + + // ------------------------------------------------------ + + // Was a Zip file requested? + if ($prefs['format'] == 'zip') + { + // If they included the .zip file extension we'll remove it + if (preg_match("|.+?\.zip$|", $prefs['filename'])) + { + $prefs['filename'] = str_replace('.zip', '', $prefs['filename']); + } + + // Tack on the ".sql" file extension if needed + if ( ! preg_match("|.+?\.sql$|", $prefs['filename'])) + { + $prefs['filename'] .= '.sql'; + } + + // Load the Zip class and output it + + $CI =& get_instance(); + $CI->load->library('zip'); + $CI->zip->add_data($prefs['filename'], $this->_backup($prefs)); + return $CI->zip->get_zip(); + } + + } + + + + + + +} + ?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 47cfa6bbe..ef66e3f3a 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -1,458 +1,458 @@ -hostname, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return @mssql_pconnect($this->hostname, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - return @mssql_select_db($this->database, $this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return resource - */ - function _execute($sql) - { - $sql = $this->_prep_query($sql); - return @mssql_query($sql, $this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @access private called by execute() - * @param string an SQL query - * @return string - */ - function _prep_query($sql) - { - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @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) - { - return TRUE; - } - - // Reset the transaction failure flag. - // 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('BEGIN TRAN'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $this->simple_query('COMMIT TRAN'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $this->simple_query('ROLLBACK TRAN'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @return string - */ - function escape_str($str) - { - // Escape single quotes - return str_replace("'", "''", $str); - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @mssql_rows_affected($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - // Not supported in MS SQL? - return 0; - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - return '0'; - - $query = $this->query("SELECT COUNT(*) AS numrows FROM ".$this->dbprefix.$table); - - if ($query->num_rows() == 0) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * List table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; - } - - // -------------------------------------------------------------------- - - /** - * List column query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access private - * @param string the table name - * @return string - */ - function _list_columns($table = '') - { - return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$this->_escape_table($table)."'"; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - return "SELECT TOP 1 * FROM ".$this->_escape_table($table); - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access private - * @return string - */ - function _error_message() - { - // Are errros even supported in MS SQL? - return ''; - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access private - * @return integer - */ - function _error_number() - { - // Are error numbers supported? - return ''; - } - - // -------------------------------------------------------------------- - - /** - * Escape Table Name - * - * This function adds backticks if the table name has a period - * in it. Some DBs will get cranky unless periods are escaped - * - * @access private - * @param string the table name - * @return string - */ - function _escape_table($table) - { - // I don't believe this is necessary with MS SQL. Not sure, though. - Rick - - /* - if (stristr($table, '.')) - { - $table = preg_replace("/\./", "`.`", $table); - } - */ - - return $table; - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @return string - */ - function _update($table, $values, $where) - { - foreach($values as $key => $val) - { - $valstr[] = $key." = ".$val; - } - - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @return string - */ - function _delete($table, $where) - { - return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - $i = $limit + $offset; - - return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql); - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - @mssql_close($conn_id); - } - -} - - +hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return @mssql_pconnect($this->hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return @mssql_select_db($this->database, $this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + function _execute($sql) + { + $sql = $this->_prep_query($sql); + return @mssql_query($sql, $this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @access private called by execute() + * @param string an SQL query + * @return string + */ + function _prep_query($sql) + { + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @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) + { + return TRUE; + } + + // Reset the transaction failure flag. + // 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('BEGIN TRAN'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @access public + * @return bool + */ + function trans_commit() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $this->simple_query('COMMIT TRAN'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @access public + * @return bool + */ + function trans_rollback() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $this->simple_query('ROLLBACK TRAN'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + // Escape single quotes + return str_replace("'", "''", $str); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @mssql_rows_affected($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + // Not supported in MS SQL? + return 0; + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + return '0'; + + $query = $this->query("SELECT COUNT(*) AS numrows FROM ".$this->dbprefix.$table); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; + } + + // -------------------------------------------------------------------- + + /** + * List column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access private + * @param string the table name + * @return string + */ + function _list_columns($table = '') + { + return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$this->_escape_table($table)."'"; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + return "SELECT TOP 1 * FROM ".$this->_escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access private + * @return string + */ + function _error_message() + { + // Are errros even supported in MS SQL? + return ''; + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access private + * @return integer + */ + function _error_number() + { + // Are error numbers supported? + return ''; + } + + // -------------------------------------------------------------------- + + /** + * Escape Table Name + * + * This function adds backticks if the table name has a period + * in it. Some DBs will get cranky unless periods are escaped + * + * @access private + * @param string the table name + * @return string + */ + function _escape_table($table) + { + // I don't believe this is necessary with MS SQL. Not sure, though. - Rick + + /* + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + */ + + return $table; + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @return string + */ + function _update($table, $values, $where) + { + foreach($values as $key => $val) + { + $valstr[] = $key." = ".$val; + } + + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + $i = $limit + $offset; + + return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql); + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + @mssql_close($conn_id); + } + +} + + ?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index eb7afef70..eb471e4be 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -1,173 +1,173 @@ -result_id); - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - return @mssql_num_fields($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Fetch Field Names - * - * Generates an array of column names - * - * @access public - * @return array - */ - function list_fields() - { - $field_names = array(); - while ($field = mssql_fetch_field($this->result_id)) - { - $field_names[] = $field->name; - } - - return $field_names; - } - - // Deprecated - function field_names() - { - return $this->list_fields(); - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - function field_data() - { - $retval = array(); - while ($field = mssql_fetch_field($this->result_id)) - { - $F = new stdClass(); - $F->name = $field->name; - $F->type = $field->type; - $F->max_length = $field->max_length; - $F->primary_key = 0; - $F->default = ''; - - $retval[] = $F; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Free the result - * - * @return null - */ - function free_result() - { - if (is_resource($this->result_id)) - { - mssql_free_result($this->result_id); - $this->result_id = FALSE; - } - } - - // -------------------------------------------------------------------- - - /** - * Data Seek - * - * Moves the internal pointer to the desired offset. We call - * this internally before fetching results to make sure the - * result set starts at zero - * - * @access private - * @return array - */ - function _data_seek($n = 0) - { - return mssql_data_seek($this->result_id, $n); - } - - // -------------------------------------------------------------------- - - /** - * Result - associative array - * - * Returns the result set as an array - * - * @access private - * @return array - */ - function _fetch_assoc() - { - return mssql_fetch_assoc($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Result - object - * - * Returns the result set as an object - * - * @access private - * @return object - */ - function _fetch_object() - { - return mssql_fetch_object($this->result_id); - } - -} - +result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @mssql_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function list_fields() + { + $field_names = array(); + while ($field = mssql_fetch_field($this->result_id)) + { + $field_names[] = $field->name; + } + + return $field_names; + } + + // Deprecated + function field_names() + { + return $this->list_fields(); + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + while ($field = mssql_fetch_field($this->result_id)) + { + $F = new stdClass(); + $F->name = $field->name; + $F->type = $field->type; + $F->max_length = $field->max_length; + $F->primary_key = 0; + $F->default = ''; + + $retval[] = $F; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return null + */ + function free_result() + { + if (is_resource($this->result_id)) + { + mssql_free_result($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero + * + * @access private + * @return array + */ + function _data_seek($n = 0) + { + return mssql_data_seek($this->result_id, $n); + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @access private + * @return array + */ + function _fetch_assoc() + { + return mssql_fetch_assoc($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + function _fetch_object() + { + return mssql_fetch_object($this->result_id); + } + +} + ?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index b24646123..7f4e73084 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -1,130 +1,130 @@ -db->_escape_table($table); - } - - // -------------------------------------------------------------------- - - /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - return "EXEC sp_helpdb"; // Can also be: EXEC sp_databases - } - - // -------------------------------------------------------------------- - - /** - * Optimize table query - * - * Generates a platform-specific query so that a table can be optimized - * - * @access private - * @param string the table name - * @return object - */ - function _optimize_table($table) - { - return FALSE; // Is this supported in MS SQL? - } - - // -------------------------------------------------------------------- - - /** - * Repair table query - * - * Generates a platform-specific query so that a table can be repaired - * - * @access private - * @param string the table name - * @return object - */ - function _repair_table($table) - { - 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'); - } - - -} - +db->_escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + return "EXEC sp_helpdb"; // Can also be: EXEC sp_databases + } + + // -------------------------------------------------------------------- + + /** + * Optimize table query + * + * Generates a platform-specific query so that a table can be optimized + * + * @access private + * @param string the table name + * @return object + */ + function _optimize_table($table) + { + return FALSE; // Is this supported in MS SQL? + } + + // -------------------------------------------------------------------- + + /** + * Repair table query + * + * Generates a platform-specific query so that a table can be repaired + * + * @access private + * @param string the table name + * @return object + */ + function _repair_table($table) + { + 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/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 2104b9abd..367c2d11f 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -1,492 +1,492 @@ -hostname, $this->username, $this->password, TRUE); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return @mysql_pconnect($this->hostname, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - return @mysql_select_db($this->database, $this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @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); - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @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 - // the query so that it returns the number of affected rows - if ($this->delete_hack === TRUE) - { - if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql)) - { - $sql = preg_replace("/^\s*DELETE\s+FROM\s+(\S+)\s*$/", "DELETE FROM \\1 WHERE 1=1", $sql); - } - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @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) - { - return TRUE; - } - - // Reset the transaction failure flag. - // 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; - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $this->simple_query('COMMIT'); - $this->simple_query('SET AUTOCOMMIT=1'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $this->simple_query('ROLLBACK'); - $this->simple_query('SET AUTOCOMMIT=1'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @return string - */ - function escape_str($str) - { - if (get_magic_quotes_gpc()) - { - return $str; - } - - if (function_exists('mysql_real_escape_string')) - { - return mysql_real_escape_string($str, $this->conn_id); - } - elseif (function_exists('mysql_escape_string')) - { - return mysql_escape_string($str); - } - else - { - return addslashes($str); - } - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @mysql_affected_rows($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - return @mysql_insert_id($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - return '0'; - - $query = $this->query("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); - - if ($query->num_rows() == 0) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * List table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SHOW TABLES FROM `".$this->database."`"; - } - - // -------------------------------------------------------------------- - - /** - * Show column query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _list_columns($table = '') - { - return "SHOW COLUMNS FROM ".$this->_escape_table($table); - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - return "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access private - * @return string - */ - function _error_message() - { - return mysql_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access private - * @return integer - */ - function _error_number() - { - return mysql_errno($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Escape Table Name - * - * This function adds backticks if the table name has a period - * in it. Some DBs will get cranky unless periods are escaped - * - * @access private - * @param string the table name - * @return string - */ - function _escape_table($table) - { - if (stristr($table, '.')) - { - $table = preg_replace("/\./", "`.`", $table); - } - - return $table; - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @return string - */ - function _update($table, $values, $where) - { - foreach($values as $key => $val) - { - $valstr[] = $key." = ".$val; - } - - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @return string - */ - function _delete($table, $where) - { - return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - if ($offset == 0) - { - $offset = ''; - } - else - { - $offset .= ", "; - } - - return $sql."LIMIT ".$offset.$limit; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - @mysql_close($conn_id); - } - -} - +hostname, $this->username, $this->password, TRUE); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return @mysql_pconnect($this->hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return @mysql_select_db($this->database, $this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @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); + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @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 + // the query so that it returns the number of affected rows + if ($this->delete_hack === TRUE) + { + if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql)) + { + $sql = preg_replace("/^\s*DELETE\s+FROM\s+(\S+)\s*$/", "DELETE FROM \\1 WHERE 1=1", $sql); + } + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @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) + { + return TRUE; + } + + // Reset the transaction failure flag. + // 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; + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @access public + * @return bool + */ + function trans_commit() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $this->simple_query('COMMIT'); + $this->simple_query('SET AUTOCOMMIT=1'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @access public + * @return bool + */ + function trans_rollback() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $this->simple_query('ROLLBACK'); + $this->simple_query('SET AUTOCOMMIT=1'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + if (get_magic_quotes_gpc()) + { + return $str; + } + + if (function_exists('mysql_real_escape_string')) + { + return mysql_real_escape_string($str, $this->conn_id); + } + elseif (function_exists('mysql_escape_string')) + { + return mysql_escape_string($str); + } + else + { + return addslashes($str); + } + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @mysql_affected_rows($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + return @mysql_insert_id($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + return '0'; + + $query = $this->query("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SHOW TABLES FROM `".$this->database."`"; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _list_columns($table = '') + { + return "SHOW COLUMNS FROM ".$this->_escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + return "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access private + * @return string + */ + function _error_message() + { + return mysql_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access private + * @return integer + */ + function _error_number() + { + return mysql_errno($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Escape Table Name + * + * This function adds backticks if the table name has a period + * in it. Some DBs will get cranky unless periods are escaped + * + * @access private + * @param string the table name + * @return string + */ + function _escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $table; + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @return string + */ + function _update($table, $values, $where) + { + foreach($values as $key => $val) + { + $valstr[] = $key." = ".$val; + } + + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + if ($offset == 0) + { + $offset = ''; + } + else + { + $offset .= ", "; + } + + return $sql."LIMIT ".$offset.$limit; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + @mysql_close($conn_id); + } + +} + ?> \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index 9b28dead7..7dcd5cb0e 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -1,173 +1,173 @@ -result_id); - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - return @mysql_num_fields($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Fetch Field Names - * - * Generates an array of column names - * - * @access public - * @return array - */ - function list_fields() - { - $field_names = array(); - while ($field = mysql_fetch_field($this->result_id)) - { - $field_names[] = $field->name; - } - - return $field_names; - } - - // Deprecated - function field_names() - { - return $this->list_fields(); - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - function field_data() - { - $retval = array(); - while ($field = mysql_fetch_field($this->result_id)) - { - $F = new stdClass(); - $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)) - { - mysql_free_result($this->result_id); - $this->result_id = FALSE; - } - } - - // -------------------------------------------------------------------- - - /** - * Data Seek - * - * Moves the internal pointer to the desired offset. We call - * this internally before fetching results to make sure the - * result set starts at zero - * - * @access private - * @return array - */ - function _data_seek($n = 0) - { - return mysql_data_seek($this->result_id, $n); - } - - // -------------------------------------------------------------------- - - /** - * Result - associative array - * - * Returns the result set as an array - * - * @access private - * @return array - */ - function _fetch_assoc() - { - return mysql_fetch_assoc($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Result - object - * - * Returns the result set as an object - * - * @access private - * @return object - */ - function _fetch_object() - { - return mysql_fetch_object($this->result_id); - } - -} - +result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @mysql_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function list_fields() + { + $field_names = array(); + while ($field = mysql_fetch_field($this->result_id)) + { + $field_names[] = $field->name; + } + + return $field_names; + } + + // Deprecated + function field_names() + { + return $this->list_fields(); + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + while ($field = mysql_fetch_field($this->result_id)) + { + $F = new stdClass(); + $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)) + { + mysql_free_result($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero + * + * @access private + * @return array + */ + function _data_seek($n = 0) + { + return mysql_data_seek($this->result_id, $n); + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @access private + * @return array + */ + function _fetch_assoc() + { + return mysql_fetch_assoc($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + function _fetch_object() + { + return mysql_fetch_object($this->result_id); + } + +} + ?> \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 32007d224..b357f47df 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -1,244 +1,244 @@ -db->_escape_table($table); - } - - // -------------------------------------------------------------------- - - /** - * Optimize table query - * - * Generates a platform-specific query so that a table can be optimized - * - * @access private - * @param string the table name - * @return object - */ - function _optimize_table($table) - { - return "OPTIMIZE TABLE ".$this->db->_escape_table($table); - } - - // -------------------------------------------------------------------- - - /** - * Repair table query - * - * Generates a platform-specific query so that a table can be repaired - * - * @access private - * @param string the table name - * @return object - */ - function _repair_table($table) - { - return "REPAIR TABLE ".$this->db->_escape_table($table); - } - - // -------------------------------------------------------------------- - - /** - * MySQL 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 = mysql_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; - } - - -} - +db->_escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * Optimize table query + * + * Generates a platform-specific query so that a table can be optimized + * + * @access private + * @param string the table name + * @return object + */ + function _optimize_table($table) + { + return "OPTIMIZE TABLE ".$this->db->_escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * Repair table query + * + * Generates a platform-specific query so that a table can be repaired + * + * @access private + * @param string the table name + * @return object + */ + function _repair_table($table) + { + return "REPAIR TABLE ".$this->db->_escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * MySQL 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 = mysql_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; + } + + +} + ?> \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index f8d3acf20..98e7f6c76 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -1,483 +1,483 @@ -hostname, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return $this->db_connect(); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - return @mysqli_select_db($this->conn_id, $this->database); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return resource - */ - function _execute($sql) - { - $sql = $this->_prep_query($sql); - $result = @mysqli_query($this->conn_id, $sql); - return $result; - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @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 - // the query so that it returns the number of affected rows - if ($this->delete_hack === TRUE) - { - if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql)) - { - $sql = preg_replace("/^\s*DELETE\s+FROM\s+(\S+)\s*$/", "DELETE FROM \\1 WHERE 1=1", $sql); - } - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @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) - { - return TRUE; - } - - // Reset the transaction failure flag. - // 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; - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $this->simple_query('COMMIT'); - $this->simple_query('SET AUTOCOMMIT=1'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $this->simple_query('ROLLBACK'); - $this->simple_query('SET AUTOCOMMIT=1'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @return string - */ - function escape_str($str) - { - if (get_magic_quotes_gpc()) - { - return $str; - } - - return mysqli_real_escape_string($this->conn_id, $str); - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @mysqli_affected_rows($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - return @mysqli_insert_id($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - return '0'; - - $query = $this->query("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); - - if ($query->num_rows() == 0) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * List table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SHOW TABLES FROM `".$this->database."`"; - } - - // -------------------------------------------------------------------- - - /** - * Show column query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _list_columns($table = '') - { - return "SHOW COLUMNS FROM ".$this->_escape_table($table); - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - return "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access private - * @return string - */ - function _error_message() - { - return mysqli_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access private - * @return integer - */ - function _error_number() - { - return mysqli_errno($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Escape Table Name - * - * This function adds backticks if the table name has a period - * in it. Some DBs will get cranky unless periods are escaped - * - * @access private - * @param string the table name - * @return string - */ - function _escape_table($table) - { - if (stristr($table, '.')) - { - $table = preg_replace("/\./", "`.`", $table); - } - - return $table; - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @return string - */ - function _update($table, $values, $where) - { - foreach($values as $key => $val) - { - $valstr[] = $key." = ".$val; - } - - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @return string - */ - function _delete($table, $where) - { - return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - $sql .= "LIMIT ".$limit; - - if ($offset > 0) - { - $sql .= " OFFSET ".$offset; - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - @mysqli_close($conn_id); - } - - -} - +hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return $this->db_connect(); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return @mysqli_select_db($this->conn_id, $this->database); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + function _execute($sql) + { + $sql = $this->_prep_query($sql); + $result = @mysqli_query($this->conn_id, $sql); + return $result; + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @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 + // the query so that it returns the number of affected rows + if ($this->delete_hack === TRUE) + { + if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql)) + { + $sql = preg_replace("/^\s*DELETE\s+FROM\s+(\S+)\s*$/", "DELETE FROM \\1 WHERE 1=1", $sql); + } + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @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) + { + return TRUE; + } + + // Reset the transaction failure flag. + // 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; + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @access public + * @return bool + */ + function trans_commit() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $this->simple_query('COMMIT'); + $this->simple_query('SET AUTOCOMMIT=1'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @access public + * @return bool + */ + function trans_rollback() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $this->simple_query('ROLLBACK'); + $this->simple_query('SET AUTOCOMMIT=1'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + if (get_magic_quotes_gpc()) + { + return $str; + } + + return mysqli_real_escape_string($this->conn_id, $str); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @mysqli_affected_rows($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + return @mysqli_insert_id($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + return '0'; + + $query = $this->query("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SHOW TABLES FROM `".$this->database."`"; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _list_columns($table = '') + { + return "SHOW COLUMNS FROM ".$this->_escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + return "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access private + * @return string + */ + function _error_message() + { + return mysqli_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access private + * @return integer + */ + function _error_number() + { + return mysqli_errno($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Escape Table Name + * + * This function adds backticks if the table name has a period + * in it. Some DBs will get cranky unless periods are escaped + * + * @access private + * @param string the table name + * @return string + */ + function _escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $table; + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @return string + */ + function _update($table, $values, $where) + { + foreach($values as $key => $val) + { + $valstr[] = $key." = ".$val; + } + + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + $sql .= "LIMIT ".$limit; + + if ($offset > 0) + { + $sql .= " OFFSET ".$offset; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + @mysqli_close($conn_id); + } + + +} + ?> \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index 57c89ea80..0f2eb5345 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -1,173 +1,173 @@ -result_id); - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - return @mysqli_num_fields($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Fetch Field Names - * - * Generates an array of column names - * - * @access public - * @return array - */ - function list_fields() - { - $field_names = array(); - while ($field = mysqli_fetch_field($this->result_id)) - { - $field_names[] = $field->name; - } - - return $field_names; - } - - // Deprecated - function field_names() - { - return $this->list_fields(); - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - function field_data() - { - $retval = array(); - while ($field = mysqli_fetch_field($this->result_id)) - { - $F = new stdClass(); - $F->name = $field->name; - $F->type = $field->type; - $F->default = $field->def; - $F->max_length = $field->max_length; - $F->primary_key = ($field->flags & MYSQLI_PRI_KEY_FLAG) ? 1 : 0; - - $retval[] = $F; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Free the result - * - * @return null - */ - function free_result() - { - if (is_resource($this->result_id)) - { - mysqli_free_result($this->result_id); - $this->result_id = FALSE; - } - } - - // -------------------------------------------------------------------- - - /** - * Data Seek - * - * Moves the internal pointer to the desired offset. We call - * this internally before fetching results to make sure the - * result set starts at zero - * - * @access private - * @return array - */ - function _data_seek($n = 0) - { - return mysqli_data_seek($this->result_id, $n); - } - - // -------------------------------------------------------------------- - - /** - * Result - associative array - * - * Returns the result set as an array - * - * @access private - * @return array - */ - function _fetch_assoc() - { - return mysqli_fetch_assoc($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Result - object - * - * Returns the result set as an object - * - * @access private - * @return object - */ - function _fetch_object() - { - return mysqli_fetch_object($this->result_id); - } - -} - +result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @mysqli_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function list_fields() + { + $field_names = array(); + while ($field = mysqli_fetch_field($this->result_id)) + { + $field_names[] = $field->name; + } + + return $field_names; + } + + // Deprecated + function field_names() + { + return $this->list_fields(); + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + while ($field = mysqli_fetch_field($this->result_id)) + { + $F = new stdClass(); + $F->name = $field->name; + $F->type = $field->type; + $F->default = $field->def; + $F->max_length = $field->max_length; + $F->primary_key = ($field->flags & MYSQLI_PRI_KEY_FLAG) ? 1 : 0; + + $retval[] = $F; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return null + */ + function free_result() + { + if (is_resource($this->result_id)) + { + mysqli_free_result($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero + * + * @access private + * @return array + */ + function _data_seek($n = 0) + { + return mysqli_data_seek($this->result_id, $n); + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @access private + * @return array + */ + function _fetch_assoc() + { + return mysqli_fetch_assoc($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + function _fetch_object() + { + return mysqli_fetch_object($this->result_id); + } + +} + ?> \ 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 d5dbf2fb0..3e2b8da6e 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -1,245 +1,245 @@ -db->_escape_table($table); - } - - // -------------------------------------------------------------------- - - /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - return "SHOW DATABASES"; - } - - // -------------------------------------------------------------------- - - /** - * Optimize table query - * - * Generates a platform-specific query so that a table can be optimized - * - * @access private - * @param string the table name - * @return object - */ - function _optimize_table($table) - { - return "OPTIMIZE TABLE ".$this->db->_escape_table($table); - } - - // -------------------------------------------------------------------- - - /** - * Repair table query - * - * Generates a platform-specific query so that a table can be repaired - * - * @access private - * @param string the table name - * @return object - */ - function _repair_table($table) - { - 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; - } - - - -} - +db->_escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + return "SHOW DATABASES"; + } + + // -------------------------------------------------------------------- + + /** + * Optimize table query + * + * Generates a platform-specific query so that a table can be optimized + * + * @access private + * @param string the table name + * @return object + */ + function _optimize_table($table) + { + return "OPTIMIZE TABLE ".$this->db->_escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * Repair table query + * + * Generates a platform-specific query so that a table can be repaired + * + * @access private + * @param string the table name + * @return object + */ + function _repair_table($table) + { + 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; + } + + + +} + ?> \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index ff301a57d..291e168eb 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -1,605 +1,605 @@ -username, $this->password, $this->hostname); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return @ociplogon($this->username, $this->password, $this->hostname); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return ociserverversion($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return resource - */ - function _execute($sql) - { - // oracle must parse the query before it is run. All of the actions with - // the query are based on the statement id returned by ociparse - $this->_set_stmt_id($sql); - ocisetprefetch($this->stmt_id, 1000); - return @ociexecute($this->stmt_id, $this->_commit); - } - - /** - * Generate a statement ID - * - * @access private - * @param string an SQL query - * @return none - */ - function _set_stmt_id($sql) - { - if ( ! is_resource($this->stmt_id)) - { - $this->stmt_id = ociparse($this->conn_id, $this->_prep_query($sql)); - } - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @access private called by execute() - * @param string an SQL query - * @return string - */ - function _prep_query($sql) - { - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * getCursor. Returns a cursor from the datbase - * - * @access public - * @return cursor id - */ - function get_cursor() - { - $this->curs_id = ocinewcursor($this->conn_id); - return $this->curs_id; - } - - // -------------------------------------------------------------------- - - /** - * Stored Procedure. Executes a stored procedure - * - * @access public - * @param package package stored procedure is in - * @param procedure stored procedure to execute - * @param params array of parameters - * @return array - * - * params array keys - * - * KEY OPTIONAL NOTES - * name no the name of the parameter should be in : format - * value no the value of the parameter. If this is an OUT or IN OUT parameter, - * this should be a reference to a variable - * type yes the type of the parameter - * length yes the max size of the parameter - */ - function stored_procedure($package, $procedure, $params) - { - if ($package == '' OR $procedure == '' OR ! is_array($params)) - { - if ($this->db_debug) - { - log_message('error', 'Invalid query: '.$package.'.'.$procedure); - return $this->display_error('db_invalid_query'); - } - return FALSE; - } - - // build the query string - $sql = "begin $package.$procedure("; - - $have_cursor = FALSE; - foreach($params as $param) - { - $sql .= $param['name'] . ","; - - if (array_key_exists('type', $param) && ($param['type'] == OCI_B_CURSOR)) - { - $have_cursor = TRUE; - } - } - $sql = trim($sql, ",") . "); end;"; - - $this->stmt_id = FALSE; - $this->_set_stmt_id($sql); - $this->_bind_params($params); - $this->query($sql, FALSE, $have_cursor); - } - - // -------------------------------------------------------------------- - - /** - * Bind parameters - * - * @access private - * @return none - */ - function _bind_params($params) - { - if ( ! is_array($params) OR ! is_resource($this->stmt_id)) - { - return; - } - - foreach ($params as $param) - { - foreach (array('name', 'value', 'type', 'length') as $val) - { - if ( ! isset($param[$val])) - { - $param[$val] = ''; - } - } - - ocibindbyname($this->stmt_id, $param['name'], $param['value'], $param['length'], $param['type']); - } - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @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) - { - return TRUE; - } - - // Reset the transaction failure flag. - // 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->_commit = OCI_DEFAULT; - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $ret = OCIcommit($this->conn_id); - $this->_commit = OCI_COMMIT_ON_SUCCESS; - return $ret; - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $ret = OCIrollback($this->conn_id); - $this->_commit = OCI_COMMIT_ON_SUCCESS; - return $ret; - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @return string - */ - function escape_str($str) - { - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @ocirowcount($this->stmt_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - // not supported in oracle - return 0; - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - return '0'; - - $query = $this->query("SELECT COUNT(1) AS numrows FROM ".$table); - - if ($query == FALSE) - { - return 0; - } - - $row = $query->row(); - return $row->NUMROWS; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SELECT TABLE_NAME FROM ALL_TABLES"; - } - - // -------------------------------------------------------------------- - - /** - * Show column query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _list_columns($table = '') - { - return "SELECT COLUMN_NAME FROM all_tab_columns WHERE table_name = '$table'"; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - return "SELECT * FROM ".$this->_escape_table($table)." where rownum = 1"; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access private - * @return string - */ - function _error_message() - { - $error = ocierror($this->conn_id); - return $error['message']; - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access private - * @return integer - */ - function _error_number() - { - $error = ocierror($this->conn_id); - return $error['code']; - } - - // -------------------------------------------------------------------- - - /** - * Escape Table Name - * - * This function adds backticks if the table name has a period - * in it. Some DBs will get cranky unless periods are escaped - * - * @access private - * @param string the table name - * @return string - */ - function _escape_table($table) - { - if (stristr($table, '.')) - { - $table = preg_replace("/\./", "`.`", $table); - } - - return $table; - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @return string - */ - function _update($table, $values, $where) - { - foreach($values as $key => $val) - { - $valstr[] = $key." = ".$val; - } - - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @return string - */ - function _delete($table, $where) - { - return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - $limit = $offset + $limit; - $newsql = "SELECT * FROM (select inner_query.*, rownum rnum FROM ($sql) inner_query WHERE rownum < $limit)"; - - if ($offset != 0) - { - $newsql .= " WHERE rnum >= $offset"; - } - - // remember that we used limits - $this->limit_used = TRUE; - - return $newsql; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - @ocilogoff($conn_id); - } - - -} - - +username, $this->password, $this->hostname); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return @ociplogon($this->username, $this->password, $this->hostname); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return ociserverversion($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + function _execute($sql) + { + // oracle must parse the query before it is run. All of the actions with + // the query are based on the statement id returned by ociparse + $this->_set_stmt_id($sql); + ocisetprefetch($this->stmt_id, 1000); + return @ociexecute($this->stmt_id, $this->_commit); + } + + /** + * Generate a statement ID + * + * @access private + * @param string an SQL query + * @return none + */ + function _set_stmt_id($sql) + { + if ( ! is_resource($this->stmt_id)) + { + $this->stmt_id = ociparse($this->conn_id, $this->_prep_query($sql)); + } + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @access private called by execute() + * @param string an SQL query + * @return string + */ + function _prep_query($sql) + { + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * getCursor. Returns a cursor from the datbase + * + * @access public + * @return cursor id + */ + function get_cursor() + { + $this->curs_id = ocinewcursor($this->conn_id); + return $this->curs_id; + } + + // -------------------------------------------------------------------- + + /** + * Stored Procedure. Executes a stored procedure + * + * @access public + * @param package package stored procedure is in + * @param procedure stored procedure to execute + * @param params array of parameters + * @return array + * + * params array keys + * + * KEY OPTIONAL NOTES + * name no the name of the parameter should be in : format + * value no the value of the parameter. If this is an OUT or IN OUT parameter, + * this should be a reference to a variable + * type yes the type of the parameter + * length yes the max size of the parameter + */ + function stored_procedure($package, $procedure, $params) + { + if ($package == '' OR $procedure == '' OR ! is_array($params)) + { + if ($this->db_debug) + { + log_message('error', 'Invalid query: '.$package.'.'.$procedure); + return $this->display_error('db_invalid_query'); + } + return FALSE; + } + + // build the query string + $sql = "begin $package.$procedure("; + + $have_cursor = FALSE; + foreach($params as $param) + { + $sql .= $param['name'] . ","; + + if (array_key_exists('type', $param) && ($param['type'] == OCI_B_CURSOR)) + { + $have_cursor = TRUE; + } + } + $sql = trim($sql, ",") . "); end;"; + + $this->stmt_id = FALSE; + $this->_set_stmt_id($sql); + $this->_bind_params($params); + $this->query($sql, FALSE, $have_cursor); + } + + // -------------------------------------------------------------------- + + /** + * Bind parameters + * + * @access private + * @return none + */ + function _bind_params($params) + { + if ( ! is_array($params) OR ! is_resource($this->stmt_id)) + { + return; + } + + foreach ($params as $param) + { + foreach (array('name', 'value', 'type', 'length') as $val) + { + if ( ! isset($param[$val])) + { + $param[$val] = ''; + } + } + + ocibindbyname($this->stmt_id, $param['name'], $param['value'], $param['length'], $param['type']); + } + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @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) + { + return TRUE; + } + + // Reset the transaction failure flag. + // 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->_commit = OCI_DEFAULT; + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @access public + * @return bool + */ + function trans_commit() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $ret = OCIcommit($this->conn_id); + $this->_commit = OCI_COMMIT_ON_SUCCESS; + return $ret; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @access public + * @return bool + */ + function trans_rollback() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $ret = OCIrollback($this->conn_id); + $this->_commit = OCI_COMMIT_ON_SUCCESS; + return $ret; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @ocirowcount($this->stmt_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + // not supported in oracle + return 0; + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + return '0'; + + $query = $this->query("SELECT COUNT(1) AS numrows FROM ".$table); + + if ($query == FALSE) + { + return 0; + } + + $row = $query->row(); + return $row->NUMROWS; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SELECT TABLE_NAME FROM ALL_TABLES"; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _list_columns($table = '') + { + return "SELECT COLUMN_NAME FROM all_tab_columns WHERE table_name = '$table'"; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + return "SELECT * FROM ".$this->_escape_table($table)." where rownum = 1"; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access private + * @return string + */ + function _error_message() + { + $error = ocierror($this->conn_id); + return $error['message']; + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access private + * @return integer + */ + function _error_number() + { + $error = ocierror($this->conn_id); + return $error['code']; + } + + // -------------------------------------------------------------------- + + /** + * Escape Table Name + * + * This function adds backticks if the table name has a period + * in it. Some DBs will get cranky unless periods are escaped + * + * @access private + * @param string the table name + * @return string + */ + function _escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $table; + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @return string + */ + function _update($table, $values, $where) + { + foreach($values as $key => $val) + { + $valstr[] = $key." = ".$val; + } + + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + $limit = $offset + $limit; + $newsql = "SELECT * FROM (select inner_query.*, rownum rnum FROM ($sql) inner_query WHERE rownum < $limit)"; + + if ($offset != 0) + { + $newsql .= " WHERE rnum >= $offset"; + } + + // remember that we used limits + $this->limit_used = TRUE; + + return $newsql; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + @ocilogoff($conn_id); + } + + +} + + ?> \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index fb4ed1f0d..07f154489 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -1,251 +1,251 @@ -result_array()); - @ociexecute($this->stmt_id); - if ($this->curs_id) - { - @ociexecute($this->curs_id); - } - return $rowcount; - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - $count = @ocinumcols($this->stmt_id); - - // if we used a limit we subtract it - if ($this->limit_used) - { - $count = $count - 1; - } - - return $count; - } - - // -------------------------------------------------------------------- - - /** - * Fetch Field Names - * - * Generates an array of column names - * - * @access public - * @return array - */ - function list_fields() - { - $field_names = array(); - $fieldCount = $this->num_fields(); - for ($c = 1; $c <= $fieldCount; $c++) - { - $field_names[] = ocicolumnname($this->stmt_id, $c); - } - return $field_names; - } - - // Deprecated - function field_names() - { - return $this->list_fields(); - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - function field_data() - { - $retval = array(); - $fieldCount = $this->num_fields(); - for ($c = 1; $c <= $fieldCount; $c++) - { - $F = new stdClass(); - $F->name = ocicolumnname($this->stmt_id, $c); - $F->type = ocicolumntype($this->stmt_id, $c); - $F->max_length = ocicolumnsize($this->stmt_id, $c); - - $retval[] = $F; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Free the result - * - * @return null - */ - function free_result() - { - if (is_resource($this->result_id)) - { - ocifreestatement($this->result_id); - $this->result_id = FALSE; - } - } - - // -------------------------------------------------------------------- - - /** - * Result - associative array - * - * Returns the result set as an array - * - * @access private - * @return array - */ - function _fetch_assoc(&$row) - { - $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; - - return ocifetchinto($id, $row, OCI_ASSOC + OCI_RETURN_NULLS); - } - - // -------------------------------------------------------------------- - - /** - * Result - object - * - * Returns the result set as an object - * - * @access private - * @return object - */ - function _fetch_object() - { - $result = array(); - - // If PHP 5 is being used we can fetch an result object - if (function_exists('oci_fetch_object')) - { - $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; - - return @oci_fetch_object($id); - } - - // If PHP 4 is being used we have to build our own result - foreach ($this->result_array() as $key => $val) - { - $obj = new stdClass(); - if (is_array($val)) - { - foreach ($val as $k => $v) - { - $obj->$k = $v; - } - } - else - { - $obj->$key = $val; - } - - $result[] = $obj; - } - - return $result; - } - - // -------------------------------------------------------------------- - - /** - * Query result. "array" version. - * - * @access public - * @return array - */ - function result_array() - { - if (count($this->result_array) > 0) - { - return $this->result_array; - } - - // oracle's fetch functions do not return arrays. - // The information is returned in reference parameters - $row = NULL; - while ($this->_fetch_assoc($row)) - { - $this->result_array[] = $row; - } - - return $this->result_array; - } - - // -------------------------------------------------------------------- - - /** - * Data Seek - * - * Moves the internal pointer to the desired offset. We call - * this internally before fetching results to make sure the - * result set starts at zero - * - * @access private - * @return array - */ - function _data_seek($n = 0) - { - return FALSE; // Not needed - } - -} - +result_array()); + @ociexecute($this->stmt_id); + if ($this->curs_id) + { + @ociexecute($this->curs_id); + } + return $rowcount; + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + $count = @ocinumcols($this->stmt_id); + + // if we used a limit we subtract it + if ($this->limit_used) + { + $count = $count - 1; + } + + return $count; + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function list_fields() + { + $field_names = array(); + $fieldCount = $this->num_fields(); + for ($c = 1; $c <= $fieldCount; $c++) + { + $field_names[] = ocicolumnname($this->stmt_id, $c); + } + return $field_names; + } + + // Deprecated + function field_names() + { + return $this->list_fields(); + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + $fieldCount = $this->num_fields(); + for ($c = 1; $c <= $fieldCount; $c++) + { + $F = new stdClass(); + $F->name = ocicolumnname($this->stmt_id, $c); + $F->type = ocicolumntype($this->stmt_id, $c); + $F->max_length = ocicolumnsize($this->stmt_id, $c); + + $retval[] = $F; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return null + */ + function free_result() + { + if (is_resource($this->result_id)) + { + ocifreestatement($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @access private + * @return array + */ + function _fetch_assoc(&$row) + { + $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; + + return ocifetchinto($id, $row, OCI_ASSOC + OCI_RETURN_NULLS); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + function _fetch_object() + { + $result = array(); + + // If PHP 5 is being used we can fetch an result object + if (function_exists('oci_fetch_object')) + { + $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; + + return @oci_fetch_object($id); + } + + // If PHP 4 is being used we have to build our own result + foreach ($this->result_array() as $key => $val) + { + $obj = new stdClass(); + if (is_array($val)) + { + foreach ($val as $k => $v) + { + $obj->$k = $v; + } + } + else + { + $obj->$key = $val; + } + + $result[] = $obj; + } + + return $result; + } + + // -------------------------------------------------------------------- + + /** + * Query result. "array" version. + * + * @access public + * @return array + */ + function result_array() + { + if (count($this->result_array) > 0) + { + return $this->result_array; + } + + // oracle's fetch functions do not return arrays. + // The information is returned in reference parameters + $row = NULL; + while ($this->_fetch_assoc($row)) + { + $this->result_array[] = $row; + } + + return $this->result_array; + } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero + * + * @access private + * @return array + */ + function _data_seek($n = 0) + { + return FALSE; // Not needed + } + +} + ?> \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 1d83af1fe..1b49f4131 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -1,129 +1,129 @@ -db->display_error('db_unsuported_feature'); - } - -} - +db->display_error('db_unsuported_feature'); + } + +} + ?> \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 9d540c77f..d6451e04a 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -1,12 +1,12 @@ result_id); - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - return @odbc_num_fields($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Fetch Field Names - * - * Generates an array of column names - * - * @access public - * @return array - */ - function list_fields() - { - $field_names = array(); - for ($i = 0; $i < $this->num_fields(); $i++) - { - $field_names[] = odbc_field_name($this->result_id, $i); - } - - return $field_names; - } - - // Deprecated - function field_names() - { - return $this->list_fields(); - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - function field_data() - { - $retval = array(); - for ($i = 0; $i < $this->num_fields(); $i++) - { - $F = new stdClass(); - $F->name = odbc_field_name($this->result_id, $i); - $F->type = odbc_field_type($this->result_id, $i); - $F->max_length = odbc_field_len($this->result_id, $i); - $F->primary_key = 0; - $F->default = ''; - - $retval[] = $F; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Free the result - * - * @return null - */ - function free_result() - { - if (is_resource($this->result_id)) - { - odbc_free_result($this->result_id); - $this->result_id = FALSE; - } - } - - // -------------------------------------------------------------------- - - /** - * Data Seek - * - * Moves the internal pointer to the desired offset. We call - * this internally before fetching results to make sure the - * result set starts at zero - * - * @access private - * @return array - */ - function _data_seek($n = 0) - { - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Result - associative array - * - * Returns the result set as an array - * - * @access private - * @return array - */ - function _fetch_assoc() - { - if (function_exists('odbc_fetch_object')) - { - return odbc_fetch_array($this->result_id); - } - else - { - return $this->_odbc_fetch_array($this->result_id); - } - } - - // -------------------------------------------------------------------- - - /** - * Result - object - * - * Returns the result set as an object - * - * @access private - * @return object - */ - function _fetch_object() - { - if (function_exists('odbc_fetch_object')) - { - return odbc_fetch_object($this->result_id); - } - else - { - return $this->_odbc_fetch_object($this->result_id); - } - } - - - /** - * Result - object - * - * subsititutes the odbc_fetch_object function when - * not available (odbc_fetch_object requires unixODBC) - * - * @access private - * @return object - */ - - function _odbc_fetch_object(& $odbc_result) { - $rs = array(); - $rs_obj = false; - if (odbc_fetch_into($odbc_result, $rs)) { - foreach ($rs as $k=>$v) { - $field_name= odbc_field_name($odbc_result, $k+1); - $rs_obj->$field_name = $v; - } - } - return $rs_obj; - } - - - /** - * Result - array - * - * subsititutes the odbc_fetch_array function when - * not available (odbc_fetch_array requires unixODBC) - * - * @access private - * @return array - */ - - function _odbc_fetch_array(& $odbc_result) { - $rs = array(); - $rs_assoc = false; - if (odbc_fetch_into($odbc_result, $rs)) { - $rs_assoc=array(); - foreach ($rs as $k=>$v) { - $field_name= odbc_field_name($odbc_result, $k+1); - $rs_assoc[$field_name] = $v; - } - } - return $rs_assoc; - } - -} - +result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @odbc_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function list_fields() + { + $field_names = array(); + for ($i = 0; $i < $this->num_fields(); $i++) + { + $field_names[] = odbc_field_name($this->result_id, $i); + } + + return $field_names; + } + + // Deprecated + function field_names() + { + return $this->list_fields(); + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + for ($i = 0; $i < $this->num_fields(); $i++) + { + $F = new stdClass(); + $F->name = odbc_field_name($this->result_id, $i); + $F->type = odbc_field_type($this->result_id, $i); + $F->max_length = odbc_field_len($this->result_id, $i); + $F->primary_key = 0; + $F->default = ''; + + $retval[] = $F; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return null + */ + function free_result() + { + if (is_resource($this->result_id)) + { + odbc_free_result($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero + * + * @access private + * @return array + */ + function _data_seek($n = 0) + { + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @access private + * @return array + */ + function _fetch_assoc() + { + if (function_exists('odbc_fetch_object')) + { + return odbc_fetch_array($this->result_id); + } + else + { + return $this->_odbc_fetch_array($this->result_id); + } + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + function _fetch_object() + { + if (function_exists('odbc_fetch_object')) + { + return odbc_fetch_object($this->result_id); + } + else + { + return $this->_odbc_fetch_object($this->result_id); + } + } + + + /** + * Result - object + * + * subsititutes the odbc_fetch_object function when + * not available (odbc_fetch_object requires unixODBC) + * + * @access private + * @return object + */ + + function _odbc_fetch_object(& $odbc_result) { + $rs = array(); + $rs_obj = false; + if (odbc_fetch_into($odbc_result, $rs)) { + foreach ($rs as $k=>$v) { + $field_name= odbc_field_name($odbc_result, $k+1); + $rs_obj->$field_name = $v; + } + } + return $rs_obj; + } + + + /** + * Result - array + * + * subsititutes the odbc_fetch_array function when + * not available (odbc_fetch_array requires unixODBC) + * + * @access private + * @return array + */ + + function _odbc_fetch_array(& $odbc_result) { + $rs = array(); + $rs_assoc = false; + if (odbc_fetch_into($odbc_result, $rs)) { + $rs_assoc=array(); + foreach ($rs as $k=>$v) { + $field_name= odbc_field_name($odbc_result, $k+1); + $rs_assoc[$field_name] = $v; + } + } + return $rs_assoc; + } + +} + ?> \ 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 8af463b13..f8d9e3c42 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -1,161 +1,161 @@ -db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access private - * @param string the database name - * @return bool - */ - function _drop_database($name) - { - // ODBC has no "drop database" command since it's - // designed to connect to an existing database - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - // Not sure if ODBC lets you list all databases... - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Drop Table - * - * @access private - * @return bool - */ - function _drop_table($table) - { - // Not a supported ODBC feature - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Optimize table query - * - * Generates a platform-specific query so that a table can be optimized - * - * @access private - * @param string the table name - * @return object - */ - function _optimize_table($table) - { - // Not a supported ODBC feature - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Repair table query - * - * Generates a platform-specific query so that a table can be repaired - * - * @access private - * @param string the table name - * @return object - */ - function _repair_table($table) - { - // Not a supported ODBC feature - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - 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'); - } - -} - +db->db_debug) + { + return $this->db->display_error('db_unsuported_feature'); + } + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access private + * @param string the database name + * @return bool + */ + function _drop_database($name) + { + // ODBC has no "drop database" command since it's + // designed to connect to an existing database + if ($this->db->db_debug) + { + return $this->db->display_error('db_unsuported_feature'); + } + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + // Not sure if ODBC lets you list all databases... + if ($this->db->db_debug) + { + return $this->db->display_error('db_unsuported_feature'); + } + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * @access private + * @return bool + */ + function _drop_table($table) + { + // Not a supported ODBC feature + if ($this->db->db_debug) + { + return $this->db->display_error('db_unsuported_feature'); + } + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Optimize table query + * + * Generates a platform-specific query so that a table can be optimized + * + * @access private + * @param string the table name + * @return object + */ + function _optimize_table($table) + { + // Not a supported ODBC feature + if ($this->db->db_debug) + { + return $this->db->display_error('db_unsuported_feature'); + } + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Repair table query + * + * Generates a platform-specific query so that a table can be repaired + * + * @access private + * @param string the table name + * @return object + */ + function _repair_table($table) + { + // Not a supported ODBC feature + if ($this->db->db_debug) + { + return $this->db->display_error('db_unsuported_feature'); + } + 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'); + } + +} + ?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 58cc69a96..bfb212cfd 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -1,12 +1,12 @@ result_id); - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - return @pg_num_fields($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Fetch Field Names - * - * Generates an array of column names - * - * @access public - * @return array - */ - function list_fields() - { - $field_names = array(); - for ($i = 0; $i < $this->num_fields(); $i++) - { - $Ffield_names[] = pg_field_name($this->result_id, $i); - } - - return $field_names; - } - - // Deprecated - function field_names() - { - return $this->list_fields(); - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - function field_data() - { - $retval = array(); - for ($i = 0; $i < $this->num_fields(); $i++) - { - $F = new stdClass(); - $F->name = pg_field_name($this->result_id, $i); - $F->type = pg_field_type($this->result_id, $i); - $F->max_length = pg_field_size($this->result_id, $i); - $F->primary_key = $i == 0; - $F->default = ''; - - $retval[] = $F; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Free the result - * - * @return null - */ - function free_result() - { - if (is_resource($this->result_id)) - { - pg_free_result($this->result_id); - $this->result_id = FALSE; - } - } - - // -------------------------------------------------------------------- - - /** - * Data Seek - * - * Moves the internal pointer to the desired offset. We call - * this internally before fetching results to make sure the - * result set starts at zero - * - * @access private - * @return array - */ - function _data_seek($n = 0) - { - return pg_result_seek($this->result_id, $n); - } - - // -------------------------------------------------------------------- - - /** - * Result - associative array - * - * Returns the result set as an array - * - * @access private - * @return array - */ - function _fetch_assoc() - { - return pg_fetch_assoc($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Result - object - * - * Returns the result set as an object - * - * @access private - * @return object - */ - function _fetch_object() - { - return pg_fetch_object($this->result_id); - } - -} - +result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @pg_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function list_fields() + { + $field_names = array(); + for ($i = 0; $i < $this->num_fields(); $i++) + { + $Ffield_names[] = pg_field_name($this->result_id, $i); + } + + return $field_names; + } + + // Deprecated + function field_names() + { + return $this->list_fields(); + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + for ($i = 0; $i < $this->num_fields(); $i++) + { + $F = new stdClass(); + $F->name = pg_field_name($this->result_id, $i); + $F->type = pg_field_type($this->result_id, $i); + $F->max_length = pg_field_size($this->result_id, $i); + $F->primary_key = $i == 0; + $F->default = ''; + + $retval[] = $F; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return null + */ + function free_result() + { + if (is_resource($this->result_id)) + { + pg_free_result($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero + * + * @access private + * @return array + */ + function _data_seek($n = 0) + { + return pg_result_seek($this->result_id, $n); + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @access private + * @return array + */ + function _fetch_assoc() + { + return pg_fetch_assoc($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + function _fetch_object() + { + return pg_fetch_object($this->result_id); + } + +} + ?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index bebe09415..9d56af363 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -1,129 +1,129 @@ -db->_escape_table($table)." CASCADE"; - } - - // -------------------------------------------------------------------- - - /** - * Optimize table query - * - * Is table optimization supported in Postgre? - * - * @access private - * @param string the table name - * @return object - */ - function _optimize_table($table) - { - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Repair table query - * - * Are table repairs supported in Postgre? - * - * @access private - * @param string the table name - * @return object - */ - function _repair_table($table) - { - 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'); - } - -} - +db->_escape_table($table)." CASCADE"; + } + + // -------------------------------------------------------------------- + + /** + * Optimize table query + * + * Is table optimization supported in Postgre? + * + * @access private + * @param string the table name + * @return object + */ + function _optimize_table($table) + { + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Repair table query + * + * Are table repairs supported in Postgre? + * + * @access private + * @param string the table name + * @return object + */ + function _repair_table($table) + { + 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'); + } + +} + ?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 877f445bb..b82618c6a 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -1,484 +1,484 @@ -database, 0666, $error)) - { - log_message('error', $error); - - if ($this->db_debug) - { - $this->display_error($error, '', TRUE); - } - - return FALSE; - } - - return $conn_id; - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - if ( ! $conn_id = @sqlite_popen($this->database, 0666, $error)) - { - log_message('error', $error); - - if ($this->db_debug) - { - $this->display_error($error, '', TRUE); - } - - return FALSE; - } - - return $conn_id; - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return sqlite_libversion(); - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return resource - */ - function _execute($sql) - { - $sql = $this->_prep_query($sql); - return @sqlite_query($this->conn_id, $sql); - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @access private called by execute() - * @param string an SQL query - * @return string - */ - function _prep_query($sql) - { - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @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) - { - return TRUE; - } - - // Reset the transaction failure flag. - // 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('BEGIN TRANSACTION'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $this->simple_query('COMMIT'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $this->simple_query('ROLLBACK'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @return string - */ - function escape_str($str) - { - return sqlite_escape_string($str); - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return sqlite_changes($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - return @sqlite_last_insert_rowid($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - return '0'; - - $query = $this->query("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); - - if ($query->num_rows() == 0) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * List table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SELECT name from sqlite_master WHERE type='table'"; - } - - // -------------------------------------------------------------------- - - /** - * Show column query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _list_columns($table = '') - { - // Not supported - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - return "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access private - * @return string - */ - function _error_message() - { - return sqlite_error_string(sqlite_last_error($this->conn_id)); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access private - * @return integer - */ - function _error_number() - { - return sqlite_last_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Escape Table Name - * - * This function adds backticks if the table name has a period - * in it. Some DBs will get cranky unless periods are escaped - * - * @access private - * @param string the table name - * @return string - */ - function _escape_table($table) - { - if (stristr($table, '.')) - { - $table = preg_replace("/\./", "`.`", $table); - } - - return $table; - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @return string - */ - function _update($table, $values, $where) - { - foreach($values as $key => $val) - { - $valstr[] = $key." = ".$val; - } - - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @return string - */ - function _delete($table, $where) - { - return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - if ($offset == 0) - { - $offset = ''; - } - else - { - $offset .= ", "; - } - - return $sql."LIMIT ".$offset.$limit; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - @sqlite_close($conn_id); - } - - -} - +database, 0666, $error)) + { + log_message('error', $error); + + if ($this->db_debug) + { + $this->display_error($error, '', TRUE); + } + + return FALSE; + } + + return $conn_id; + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + if ( ! $conn_id = @sqlite_popen($this->database, 0666, $error)) + { + log_message('error', $error); + + if ($this->db_debug) + { + $this->display_error($error, '', TRUE); + } + + return FALSE; + } + + return $conn_id; + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return sqlite_libversion(); + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + function _execute($sql) + { + $sql = $this->_prep_query($sql); + return @sqlite_query($this->conn_id, $sql); + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @access private called by execute() + * @param string an SQL query + * @return string + */ + function _prep_query($sql) + { + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @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) + { + return TRUE; + } + + // Reset the transaction failure flag. + // 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('BEGIN TRANSACTION'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @access public + * @return bool + */ + function trans_commit() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $this->simple_query('COMMIT'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @access public + * @return bool + */ + function trans_rollback() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $this->simple_query('ROLLBACK'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + return sqlite_escape_string($str); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return sqlite_changes($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + return @sqlite_last_insert_rowid($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + return '0'; + + $query = $this->query("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SELECT name from sqlite_master WHERE type='table'"; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _list_columns($table = '') + { + // Not supported + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + return "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access private + * @return string + */ + function _error_message() + { + return sqlite_error_string(sqlite_last_error($this->conn_id)); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access private + * @return integer + */ + function _error_number() + { + return sqlite_last_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Escape Table Name + * + * This function adds backticks if the table name has a period + * in it. Some DBs will get cranky unless periods are escaped + * + * @access private + * @param string the table name + * @return string + */ + function _escape_table($table) + { + if (stristr($table, '.')) + { + $table = preg_replace("/\./", "`.`", $table); + } + + return $table; + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @return string + */ + function _update($table, $values, $where) + { + foreach($values as $key => $val) + { + $valstr[] = $key." = ".$val; + } + + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + if ($offset == 0) + { + $offset = ''; + } + else + { + $offset .= ", "; + } + + return $sql."LIMIT ".$offset.$limit; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + @sqlite_close($conn_id); + } + + +} + ?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index a406a935c..a16a5b054 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -1,176 +1,176 @@ -result_id); - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - return @sqlite_num_fields($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Fetch Field Names - * - * Generates an array of column names - * - * @access public - * @return array - */ - function list_fields() - { - $field_names = array(); - for ($i = 0; $i < $this->num_fields(); $i++) - { - $Ffield_names[] = sqlite_field_name($this->result_id, $i); - } - - return $field_names; - } - - // Deprecated - function field_names() - { - return $this->list_fields(); - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - function field_data() - { - $retval = array(); - for ($i = 0; $i < $this->num_fields(); $i++) - { - $F = new stdClass(); - $F->name = sqlite_field_name($this->result_id, $i); - $F->type = 'varchar'; - $F->max_length = 0; - $F->primary_key = 0; - $F->default = ''; - - $retval[] = $F; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Free the result - * - * @return null - */ - function free_result() - { - // Not implemented in SQLite - } - - // -------------------------------------------------------------------- - - /** - * Data Seek - * - * Moves the internal pointer to the desired offset. We call - * this internally before fetching results to make sure the - * result set starts at zero - * - * @access private - * @return array - */ - function _data_seek($n = 0) - { - return sqlite_seek($this->result_id, $n); - } - - // -------------------------------------------------------------------- - - /** - * Result - associative array - * - * Returns the result set as an array - * - * @access private - * @return array - */ - function _fetch_assoc() - { - return sqlite_fetch_array($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Result - object - * - * Returns the result set as an object - * - * @access private - * @return object - */ - function _fetch_object() - { - if (function_exists('sqlite_fetch_object')) - { - return sqlite_fetch_object($this->result_id); - } - else - { - return $this->_fetch_assoc(); - } - } - -} - +result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @sqlite_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function list_fields() + { + $field_names = array(); + for ($i = 0; $i < $this->num_fields(); $i++) + { + $Ffield_names[] = sqlite_field_name($this->result_id, $i); + } + + return $field_names; + } + + // Deprecated + function field_names() + { + return $this->list_fields(); + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + for ($i = 0; $i < $this->num_fields(); $i++) + { + $F = new stdClass(); + $F->name = sqlite_field_name($this->result_id, $i); + $F->type = 'varchar'; + $F->max_length = 0; + $F->primary_key = 0; + $F->default = ''; + + $retval[] = $F; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return null + */ + function free_result() + { + // Not implemented in SQLite + } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero + * + * @access private + * @return array + */ + function _data_seek($n = 0) + { + return sqlite_seek($this->result_id, $n); + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @access private + * @return array + */ + function _fetch_assoc() + { + return sqlite_fetch_array($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + function _fetch_object() + { + if (function_exists('sqlite_fetch_object')) + { + return sqlite_fetch_object($this->result_id); + } + else + { + return $this->_fetch_assoc(); + } + } + +} + ?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 91649c78d..9683b1756 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -1,154 +1,154 @@ -db->database) OR ! @unlink($this->db->database)) - { - if ($this->db->db_debug) - { - return $this->db->display_error('db_unable_to_drop'); - } - return FALSE; - } - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * List databases - * - * I don't believe you can do a database listing with SQLite - * since each database is its own file. I suppose we could - * try reading a directory looking for SQLite files, but - * that doesn't seem like a terribly good idea - * - * @access private - * @return bool - */ - function _list_databases() - { - if ($this->db_debug) - { - return $this->display_error('db_unsuported_feature'); - } - return array(); - } - - // -------------------------------------------------------------------- - - /** - * Drop Table - * - * Unsupported feature in SQLite - * - * @access private - * @return bool - */ - function _drop_table($table) - { - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return array(); - } - - // -------------------------------------------------------------------- - - /** - * Optimize table query - * - * Is optimization even supported in SQLite? - * - * @access private - * @param string the table name - * @return object - */ - function _optimize_table($table) - { - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Repair table query - * - * Are table repairs even supported in SQLite? - * - * @access private - * @param string the table name - * @return object - */ - function _repair_table($table) - { - 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'); - } - -} - +db->database) OR ! @unlink($this->db->database)) + { + if ($this->db->db_debug) + { + return $this->db->display_error('db_unable_to_drop'); + } + return FALSE; + } + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * List databases + * + * I don't believe you can do a database listing with SQLite + * since each database is its own file. I suppose we could + * try reading a directory looking for SQLite files, but + * that doesn't seem like a terribly good idea + * + * @access private + * @return bool + */ + function _list_databases() + { + if ($this->db_debug) + { + return $this->display_error('db_unsuported_feature'); + } + return array(); + } + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * Unsupported feature in SQLite + * + * @access private + * @return bool + */ + function _drop_table($table) + { + if ($this->db->db_debug) + { + return $this->db->display_error('db_unsuported_feature'); + } + return array(); + } + + // -------------------------------------------------------------------- + + /** + * Optimize table query + * + * Is optimization even supported in SQLite? + * + * @access private + * @param string the table name + * @return object + */ + function _optimize_table($table) + { + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Repair table query + * + * Are table repairs even supported in SQLite? + * + * @access private + * @param string the table name + * @return object + */ + function _repair_table($table) + { + 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'); + } + +} + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From bb2041dc4e5a121de9321fbf87846b7358d59d39 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Sat, 9 Jun 2007 00:16:13 +0000 Subject: --- system/database/drivers/mysql/mysql_driver.php | 5 ----- system/database/drivers/mysqli/mysqli_driver.php | 5 ----- 2 files changed, 10 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 367c2d11f..50f4ecfbf 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -222,11 +222,6 @@ class CI_DB_mysql_driver extends CI_DB { */ function escape_str($str) { - if (get_magic_quotes_gpc()) - { - return $str; - } - if (function_exists('mysql_real_escape_string')) { return mysql_real_escape_string($str, $this->conn_id); diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 98e7f6c76..9cfc68ea6 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -225,11 +225,6 @@ class CI_DB_mysqli_driver extends CI_DB { */ function escape_str($str) { - if (get_magic_quotes_gpc()) - { - return $str; - } - return mysqli_real_escape_string($this->conn_id, $str); } -- cgit v1.2.3-24-g4f1b From 28239ad0146eccecc9f2ca81764ca5605b3c50bf Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 11 Jun 2007 04:26:39 +0000 Subject: --- system/database/DB_driver.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 7ff33246a..8f238fc52 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -48,7 +48,7 @@ class CI_DB_driver { var $data_cache = array(); var $trans_enabled = TRUE; var $_trans_depth = 0; - var $_trans_failure = FALSE; // Used with transactions to determine if a rollback should occur + var $_trans_status = TRUE; // Used with transactions to determine if a rollback should occur var $cache_on = FALSE; var $cachedir = ''; var $cache_autodel = FALSE; @@ -273,7 +273,7 @@ class CI_DB_driver { if (FALSE === ($this->result_id = $this->simple_query($sql))) { // This will trigger a rollback if transactions are being used - $this->_trans_failure = TRUE; + $this->_trans_status = FALSE; if ($this->db_debug) { @@ -463,7 +463,7 @@ class CI_DB_driver { } // The query() function will set this flag to TRUE in the event that a query failed - if ($this->_trans_failure === TRUE) + if ($this->_trans_status === FALSE) { $this->trans_rollback(); @@ -488,7 +488,7 @@ class CI_DB_driver { */ function trans_status() { - return $this->_trans_failure; + return $this->_trans_status; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 1db17b57686911fea83103509c1438cbe1e545da Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 11 Jun 2007 05:33:21 +0000 Subject: --- system/database/drivers/mssql/mssql_driver.php | 50 ++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 7 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index ef66e3f3a..aef8da926 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -222,15 +222,51 @@ class CI_DB_mssql_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Insert ID - * - * @access public - * @return integer - */ + * Insert ID + * + * Returns the last id created in the Identity column. + * + * @access public + * @return integer + */ function insert_id() { - // Not supported in MS SQL? - return 0; + $ver = self::_parse_major_version($this->version()); + $sql = ($ver >= 8 ? "SELECT SCOPE_IDENTITY() AS last_id" : "SELECT @@IDENTITY AS last_id"); + $query = $this->query($sql); + $row = $query->row(); + return $row->last_id; + } + + // -------------------------------------------------------------------- + + /** + * Parse major version + * + * Grabs the major version number from the + * database server version string passed in. + * + * @access private + * @param string $version + * @return int16 major version number + */ + function _parse_major_version($version) + { + preg_match('/([0-9]+)\.([0-9]+)\.([0-9]+)/', $version, $ver_info); + return $ver_info[1]; // return the major version b/c that's all we're interested in. + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT @@VERSION AS ver"; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 7dcd7a3aa4b145fc8a040c16e7c4de9ea35fd5cf Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 12 Jul 2007 12:36:50 +0000 Subject: csv_from_result() move robust against data with "," in it. --- system/database/DB_utility.php | 54 +++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 19 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index d48425d7e..8ce19b17f 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -236,35 +236,51 @@ class CI_DB_utility { * @param string The newline character - \n by default * @return string */ - function csv_from_result($query, $delim = "\t", $newline = "\n") + function csv_from_result($query, $delim = ',', $newline = '', $enclosure = '"') { - if ( ! is_object($query) OR ! method_exists($query, 'field_names')) - { - show_error('You must submit a valid result object'); - } + if (!is_a($query, 'CI_DB_result')) { + show_error('CI_DB_utility::csv_from_result - You must submit a valid result object'); + } + + if ($delim === '') { + show_error('CI_DB_utility::csv_from_result - Empty delimiters are not permitted'); + } + + if ($newline === '') { + $newline = (stripos(getenv('HTTP_USER_AGENT'), 'win') !== false) ? "\r\n" : "\n"; + } + if ((strpos($enclosure, $newline) !== false) or (($enclosure !== '') and (strpos($newline, $enclosure) !== false))) { + show_error('CI_DB_utility::csv_from_result - Field enclosure must not be contained within delimiter (or vice versa)'); + } + $out = ''; // First generate the headings from the table column names - foreach ($query->list_fields() as $name) - { - $out .= $name.$delim; + foreach ($query->list_fields() as $name) { + // there's no point enclosing strings that do not require it + if (strpos($name, $delim) !== false) { + $out .= $enclosure . $name . $enclosure . $delim; + } else { + $out .= $name . $delim; + } } - $out = rtrim($out); - $out .= $newline; - + $out = rtrim($out, $delim) . $newline; + // Next blast through the result array and build out the rows - foreach ($query->result_array() as $row) - { - foreach ($row as $item) - { - $out .= $item.$delim; + foreach ($query->result_array() as $row) { + foreach ($row as $item) { + // there's no point enclosing strings that do not require it + if (strpos($item, $delim) !== false) { + $out .= $enclosure . $item . $enclosure . $delim; + } else { + $out .= $item . $delim; + } } - $out = rtrim($out); - $out .= $newline; + $out = rtrim($out, $delim) . $newline; } - + return $out; } -- cgit v1.2.3-24-g4f1b From f9a4e9e04589df8dcf808519c95703f16c318384 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 12 Jul 2007 13:56:21 +0000 Subject: fixed undefined function in insert_id() of PostgreSQL driver --- system/database/drivers/postgre/postgre_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index bfb212cfd..798905126 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -230,7 +230,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function insert_id() { - $v = version($this->conn_id); + $v = $this->_version(); $v = $v['server']; $table = func_num_args() > 0 ? func_get_arg(0) : null; -- cgit v1.2.3-24-g4f1b From 476b87150809861e6963eb26be083086f8ea0464 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 12 Jul 2007 18:22:05 +0000 Subject: csv_from_result buggy. revert to old function until rewrite --- system/database/DB_utility.php | 924 ++++++++++++++++++++--------------------- 1 file changed, 454 insertions(+), 470 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 8ce19b17f..9533ec607 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -1,471 +1,455 @@ -db - $CI =& get_instance(); - $this->db =& $CI->db; - - log_message('debug', "Database Utility Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Create database - * - * @access public - * @param string the database name - * @return bool - */ - function create_database($db_name) - { - $sql = $this->_create_database($db_name); - - if (is_bool($sql)) - { - return $sql; - } - - return $this->db->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access public - * @param string the database name - * @return bool - */ - function drop_database($db_name) - { - $sql = $this->_drop_database($db_name); - - if (is_bool($sql)) - { - return $sql; - } - - return $this->db->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * List databases - * - * @access public - * @return bool - */ - function list_databases() - { - // Is there a cached result? - if (isset($this->data_cache['db_names'])) - { - return $this->data_cache['db_names']; - } - - $query = $this->db->query($this->_list_databases()); - $dbs = array(); - if ($query->num_rows() > 0) - { - foreach ($query->result_array() as $row) - { - $dbs[] = current($row); - } - } - - $this->data_cache['db_names'] = $dbs; - return $this->data_cache['db_names']; - } - - // -------------------------------------------------------------------- - - /** - * Optimize Table - * - * @access public - * @param string the table name - * @return bool - */ - function optimize_table($table_name) - { - $sql = $this->_optimize_table($table_name); - - if (is_bool($sql)) - { - return $sql; - } - - $query = $this->db->query($sql); - $res = $query->result_array(); - - // Note: Due to a bug in current() that affects some versions - // of PHP we can not pass function call directly into it - return current($res); - } - - // -------------------------------------------------------------------- - - /** - * Optimize Database - * - * @access public - * @return array - */ - function optimize_database() - { - $result = array(); - foreach ($this->db->list_tables() as $table_name) - { - $sql = $this->_optimize_table($table_name); - - if (is_bool($sql)) - { - return $sql; - } - - $query = $this->db->query($sql); - - // Build the result array... - // Note: Due to a bug in current() that affects some versions - // of PHP we can not pass function call directly into it - $res = $query->result_array(); - $res = current($res); - $key = str_replace($this->db->database.'.', '', current($res)); - $keys = array_keys($res); - unset($res[$keys[0]]); - - $result[$key] = $res; - } - - return $result; - } - - // -------------------------------------------------------------------- - - /** - * Optimize Table - * - * @access public - * @param string the table name - * @return bool - */ - - function repair_table($table_name) - { - $sql = $this->_repair_table($table_name); - - if (is_bool($sql)) - { - return $sql; - } - - $query = $this->db->query($sql); - - // Note: Due to a bug in current() that affects some versions - // of PHP we can not pass function call directly into it - $res = $query->result_array(); - return current($res); - } - - // -------------------------------------------------------------------- - - /** - * Drop Table - * - * @access public - * @param string the table name - * @return bool - */ - function drop_table($table_name) - { - $sql = $this->_drop_table($table_name); - - if (is_bool($sql)) - { - return $sql; - } - - return $this->db->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Generate CSV from a query result object - * - * @access public - * @param object The query result object - * @param string The delimiter - tab by default - * @param string The newline character - \n by default - * @return string - */ - function csv_from_result($query, $delim = ',', $newline = '', $enclosure = '"') - { - if (!is_a($query, 'CI_DB_result')) { - show_error('CI_DB_utility::csv_from_result - You must submit a valid result object'); - } - - if ($delim === '') { - show_error('CI_DB_utility::csv_from_result - Empty delimiters are not permitted'); - } - - if ($newline === '') { - $newline = (stripos(getenv('HTTP_USER_AGENT'), 'win') !== false) ? "\r\n" : "\n"; - } - - if ((strpos($enclosure, $newline) !== false) or (($enclosure !== '') and (strpos($newline, $enclosure) !== false))) { - show_error('CI_DB_utility::csv_from_result - Field enclosure must not be contained within delimiter (or vice versa)'); - } - - $out = ''; - - // First generate the headings from the table column names - foreach ($query->list_fields() as $name) { - // there's no point enclosing strings that do not require it - if (strpos($name, $delim) !== false) { - $out .= $enclosure . $name . $enclosure . $delim; - } else { - $out .= $name . $delim; - } - } - - $out = rtrim($out, $delim) . $newline; - - // Next blast through the result array and build out the rows - foreach ($query->result_array() as $row) { - foreach ($row as $item) { - // there's no point enclosing strings that do not require it - if (strpos($item, $delim) !== false) { - $out .= $enclosure . $item . $enclosure . $delim; - } else { - $out .= $item . $delim; - } - } - $out = rtrim($out, $delim) . $newline; - } - - return $out; - } - - // -------------------------------------------------------------------- - - /** - * Generate XML data from a query result object - * - * @access public - * @param object The query result object - * @param array Any preferences - * @return string - */ - function xml_from_result($query, $params = array()) - { - if ( ! is_object($query) OR ! method_exists($query, 'field_names')) - { - show_error('You must submit a valid result object'); - } - - // Set our default values - foreach (array('root' => 'root', 'element' => 'element', 'newline' => "\n", 'tab' => "\t") as $key => $val) - { - if ( ! isset($params[$key])) - { - $params[$key] = $val; - } - } - - // Create variables for convenience - extract($params); - - // Load the xml helper - $CI =& get_instance(); - $CI->load->helper('xml'); - - // Generate the result - $xml = "<{$root}>".$newline; - foreach ($query->result_array() as $row) - { - $xml .= $tab."<{$element}>".$newline; - - foreach ($row as $key => $val) - { - $xml .= $tab.$tab."<{$key}>".xml_convert($val)."".$newline; - } - $xml .= $tab."".$newline; - } - $xml .= "".$newline; - - return $xml; - } - - // -------------------------------------------------------------------- - - /** - * Database Backup - * - * @access public - * @return void - */ - function backup($params = array()) - { - // If the parameters have not been submitted as an - // array then we know that it is simply the table - // name, which is a valid short cut. - if (is_string($params)) - { - $params = array('tables' => $params); - } - - // ------------------------------------------------------ - - // 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" - ); - - // Did the user submit any preferences? If so set them.... - if (count($params) > 0) - { - foreach ($prefs as $key => $val) - { - if (isset($params[$key])) - { - $prefs[$key] = $params[$key]; - } - } - } - - // ------------------------------------------------------ - - // Are we backing up a complete database or individual tables? - // If no table names were submitted we'll fetch the entire table list - if (count($prefs['tables']) == 0) - { - $prefs['tables'] = $this->db->list_tables(); - } - - // ------------------------------------------------------ - - // Validate the format - if ( ! in_array($prefs['format'], array('gzip', 'zip', 'txt'), TRUE)) - { - $prefs['format'] = 'txt'; - } - - // ------------------------------------------------------ - - // Is the encoder supported? If not, we'll either issue an - // error or use plain text depending on the debug settings - if (($prefs['format'] == 'gzip' AND ! @function_exists('gzencode')) - OR ($prefs['format'] == 'zip' AND ! @function_exists('gzcompress'))) - { - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_compression'); - } - - $prefs['format'] = 'txt'; - } - - // ------------------------------------------------------ - - // Set the filename if not provided - Only needed with Zip files - if ($prefs['filename'] == '' AND $prefs['format'] == 'zip') - { - $prefs['filename'] = (count($prefs['tables']) == 1) ? $prefs['tables'] : $this->db->database; - $prefs['filename'] .= '_'.date('Y-m-d_H-i', time()); - } - - // ------------------------------------------------------ - - // Was a Gzip file requested? - if ($prefs['format'] == 'gzip') - { - return gzencode($this->_backup($prefs)); - } - - // ------------------------------------------------------ - - // Was a text file requested? - if ($prefs['format'] == 'txt') - { - return $this->_backup($prefs); - } - - // ------------------------------------------------------ - - // Was a Zip file requested? - if ($prefs['format'] == 'zip') - { - // If they included the .zip file extension we'll remove it - if (preg_match("|.+?\.zip$|", $prefs['filename'])) - { - $prefs['filename'] = str_replace('.zip', '', $prefs['filename']); - } - - // Tack on the ".sql" file extension if needed - if ( ! preg_match("|.+?\.sql$|", $prefs['filename'])) - { - $prefs['filename'] .= '.sql'; - } - - // Load the Zip class and output it - - $CI =& get_instance(); - $CI->load->library('zip'); - $CI->zip->add_data($prefs['filename'], $this->_backup($prefs)); - return $CI->zip->get_zip(); - } - - } - - - - - - -} - +db + $CI =& get_instance(); + $this->db =& $CI->db; + + log_message('debug', "Database Utility Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Create database + * + * @access public + * @param string the database name + * @return bool + */ + function create_database($db_name) + { + $sql = $this->_create_database($db_name); + + if (is_bool($sql)) + { + return $sql; + } + + return $this->db->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access public + * @param string the database name + * @return bool + */ + function drop_database($db_name) + { + $sql = $this->_drop_database($db_name); + + if (is_bool($sql)) + { + return $sql; + } + + return $this->db->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access public + * @return bool + */ + function list_databases() + { + // Is there a cached result? + if (isset($this->data_cache['db_names'])) + { + return $this->data_cache['db_names']; + } + + $query = $this->db->query($this->_list_databases()); + $dbs = array(); + if ($query->num_rows() > 0) + { + foreach ($query->result_array() as $row) + { + $dbs[] = current($row); + } + } + + $this->data_cache['db_names'] = $dbs; + return $this->data_cache['db_names']; + } + + // -------------------------------------------------------------------- + + /** + * Optimize Table + * + * @access public + * @param string the table name + * @return bool + */ + function optimize_table($table_name) + { + $sql = $this->_optimize_table($table_name); + + if (is_bool($sql)) + { + return $sql; + } + + $query = $this->db->query($sql); + $res = $query->result_array(); + + // Note: Due to a bug in current() that affects some versions + // of PHP we can not pass function call directly into it + return current($res); + } + + // -------------------------------------------------------------------- + + /** + * Optimize Database + * + * @access public + * @return array + */ + function optimize_database() + { + $result = array(); + foreach ($this->db->list_tables() as $table_name) + { + $sql = $this->_optimize_table($table_name); + + if (is_bool($sql)) + { + return $sql; + } + + $query = $this->db->query($sql); + + // Build the result array... + // Note: Due to a bug in current() that affects some versions + // of PHP we can not pass function call directly into it + $res = $query->result_array(); + $res = current($res); + $key = str_replace($this->db->database.'.', '', current($res)); + $keys = array_keys($res); + unset($res[$keys[0]]); + + $result[$key] = $res; + } + + return $result; + } + + // -------------------------------------------------------------------- + + /** + * Optimize Table + * + * @access public + * @param string the table name + * @return bool + */ + + function repair_table($table_name) + { + $sql = $this->_repair_table($table_name); + + if (is_bool($sql)) + { + return $sql; + } + + $query = $this->db->query($sql); + + // Note: Due to a bug in current() that affects some versions + // of PHP we can not pass function call directly into it + $res = $query->result_array(); + return current($res); + } + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * @access public + * @param string the table name + * @return bool + */ + function drop_table($table_name) + { + $sql = $this->_drop_table($table_name); + + if (is_bool($sql)) + { + return $sql; + } + + return $this->db->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Generate CSV from a query result object + * + * @access public + * @param object The query result object + * @param string The delimiter - tab by default + * @param string The newline character - \n by default + * @return string + */ + function csv_from_result($query, $delim = "\t", $newline = "\n") + { + if ( ! is_object($query) OR ! method_exists($query, 'field_names')) + { + show_error('You must submit a valid result object'); + } + + $out = ''; + + // First generate the headings from the table column names + foreach ($query->list_fields() as $name) + { + $out .= $name.$delim; + } + + $out = rtrim($out); + $out .= $newline; + + // Next blast through the result array and build out the rows + foreach ($query->result_array() as $row) + { + foreach ($row as $item) + { + $out .= $item.$delim; + } + $out = rtrim($out); + $out .= $newline; + } + + return $out; + } + + // -------------------------------------------------------------------- + + /** + * Generate XML data from a query result object + * + * @access public + * @param object The query result object + * @param array Any preferences + * @return string + */ + function xml_from_result($query, $params = array()) + { + if ( ! is_object($query) OR ! method_exists($query, 'field_names')) + { + show_error('You must submit a valid result object'); + } + + // Set our default values + foreach (array('root' => 'root', 'element' => 'element', 'newline' => "\n", 'tab' => "\t") as $key => $val) + { + if ( ! isset($params[$key])) + { + $params[$key] = $val; + } + } + + // Create variables for convenience + extract($params); + + // Load the xml helper + $CI =& get_instance(); + $CI->load->helper('xml'); + + // Generate the result + $xml = "<{$root}>".$newline; + foreach ($query->result_array() as $row) + { + $xml .= $tab."<{$element}>".$newline; + + foreach ($row as $key => $val) + { + $xml .= $tab.$tab."<{$key}>".xml_convert($val)."".$newline; + } + $xml .= $tab."".$newline; + } + $xml .= "".$newline; + + return $xml; + } + + // -------------------------------------------------------------------- + + /** + * Database Backup + * + * @access public + * @return void + */ + function backup($params = array()) + { + // If the parameters have not been submitted as an + // array then we know that it is simply the table + // name, which is a valid short cut. + if (is_string($params)) + { + $params = array('tables' => $params); + } + + // ------------------------------------------------------ + + // 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" + ); + + // Did the user submit any preferences? If so set them.... + if (count($params) > 0) + { + foreach ($prefs as $key => $val) + { + if (isset($params[$key])) + { + $prefs[$key] = $params[$key]; + } + } + } + + // ------------------------------------------------------ + + // Are we backing up a complete database or individual tables? + // If no table names were submitted we'll fetch the entire table list + if (count($prefs['tables']) == 0) + { + $prefs['tables'] = $this->db->list_tables(); + } + + // ------------------------------------------------------ + + // Validate the format + if ( ! in_array($prefs['format'], array('gzip', 'zip', 'txt'), TRUE)) + { + $prefs['format'] = 'txt'; + } + + // ------------------------------------------------------ + + // Is the encoder supported? If not, we'll either issue an + // error or use plain text depending on the debug settings + if (($prefs['format'] == 'gzip' AND ! @function_exists('gzencode')) + OR ($prefs['format'] == 'zip' AND ! @function_exists('gzcompress'))) + { + if ($this->db->db_debug) + { + return $this->db->display_error('db_unsuported_compression'); + } + + $prefs['format'] = 'txt'; + } + + // ------------------------------------------------------ + + // Set the filename if not provided - Only needed with Zip files + if ($prefs['filename'] == '' AND $prefs['format'] == 'zip') + { + $prefs['filename'] = (count($prefs['tables']) == 1) ? $prefs['tables'] : $this->db->database; + $prefs['filename'] .= '_'.date('Y-m-d_H-i', time()); + } + + // ------------------------------------------------------ + + // Was a Gzip file requested? + if ($prefs['format'] == 'gzip') + { + return gzencode($this->_backup($prefs)); + } + + // ------------------------------------------------------ + + // Was a text file requested? + if ($prefs['format'] == 'txt') + { + return $this->_backup($prefs); + } + + // ------------------------------------------------------ + + // Was a Zip file requested? + if ($prefs['format'] == 'zip') + { + // If they included the .zip file extension we'll remove it + if (preg_match("|.+?\.zip$|", $prefs['filename'])) + { + $prefs['filename'] = str_replace('.zip', '', $prefs['filename']); + } + + // Tack on the ".sql" file extension if needed + if ( ! preg_match("|.+?\.sql$|", $prefs['filename'])) + { + $prefs['filename'] .= '.sql'; + } + + // Load the Zip class and output it + + $CI =& get_instance(); + $CI->load->library('zip'); + $CI->zip->add_data($prefs['filename'], $this->_backup($prefs)); + return $CI->zip->get_zip(); + } + + } + + + + + + +} + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 33d1056c454eeb5e4484ff4454f78da9dc2a3ec5 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 12 Jul 2007 18:44:13 +0000 Subject: sacked duplicate and incorrect version of _version()! --- system/database/drivers/mssql/mssql_driver.php | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index aef8da926..e4a2960e5 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -69,19 +69,6 @@ class CI_DB_mssql_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - /** * Execute the query * -- cgit v1.2.3-24-g4f1b From 060052de1f91b9b1fc533d0957eb18dab9057bfe Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sat, 14 Jul 2007 14:26:13 +0000 Subject: Fixed a bug in database driver where num_rows property wasn't getting updated --- system/database/DB_driver.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 8f238fc52..381b70f42 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -325,7 +325,8 @@ class CI_DB_driver { $RES = new $driver(); $RES->conn_id = $this->conn_id; $RES->result_id = $this->result_id; - + $RES->num_rows = $RES->num_rows(); + if ($this->dbdriver == 'oci8') { $RES->stmt_id = $this->stmt_id; -- cgit v1.2.3-24-g4f1b From 409904637cd661be6ceccb59af1046468da09802 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 17 Jul 2007 21:40:44 +0000 Subject: --- system/database/DB_driver.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 381b70f42..ee965b74c 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -44,6 +44,7 @@ class CI_DB_driver { var $benchmark = 0; var $query_count = 0; var $bind_marker = '?'; + var $save_queries = TRUE; var $queries = array(); var $data_cache = array(); var $trans_enabled = TRUE; @@ -264,7 +265,10 @@ class CI_DB_driver { } // Save the query for debugging - $this->queries[] = $sql; + if ($this->save_queries == TRUE) + { + $this->queries[] = $sql; + } // Start the Query Timer $time_start = list($sm, $ss) = explode(' ', microtime()); -- cgit v1.2.3-24-g4f1b From 9278249cd356411dc949dd5a6dacc5b07fd4be81 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 10 Aug 2007 11:26:01 +0000 Subject: Removed "rand()" as a listed option from orderby in the Active Record, as it was MySQL only. --- system/database/DB_active_rec.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index d79a068e3..82d5b63b7 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -405,7 +405,7 @@ class CI_DB_active_record extends CI_DB_driver { { if (trim($direction) != '') { - $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC', 'RAND()'), TRUE)) ? ' '.$direction : ' ASC'; + $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' '.$direction : ' ASC'; } $this->ar_orderby[] = $orderby.$direction; -- cgit v1.2.3-24-g4f1b From 6838f00a708f53f834fb8a98af560177db1d1454 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 4 Oct 2007 19:29:59 +0000 Subject: Fixed a typo in the docblock comments that had CodeIgniter spelled CodeIgnitor. --- system/database/DB.php | 2 +- system/database/DB_active_rec.php | 2 +- system/database/DB_cache.php | 2 +- system/database/DB_driver.php | 2 +- system/database/DB_result.php | 2 +- system/database/DB_utility.php | 908 ++++++++++----------- system/database/drivers/mssql/mssql_driver.php | 2 +- system/database/drivers/mssql/mssql_result.php | 2 +- system/database/drivers/mssql/mssql_utility.php | 2 +- system/database/drivers/mysql/mysql_driver.php | 2 +- system/database/drivers/mysql/mysql_result.php | 2 +- system/database/drivers/mysql/mysql_utility.php | 2 +- system/database/drivers/mysqli/mysqli_driver.php | 2 +- system/database/drivers/mysqli/mysqli_result.php | 2 +- system/database/drivers/mysqli/mysqli_utility.php | 2 +- system/database/drivers/oci8/oci8_driver.php | 2 +- system/database/drivers/oci8/oci8_result.php | 2 +- system/database/drivers/oci8/oci8_utility.php | 2 +- system/database/drivers/odbc/odbc_driver.php | 2 +- system/database/drivers/odbc/odbc_result.php | 2 +- system/database/drivers/odbc/odbc_utility.php | 2 +- system/database/drivers/postgre/postgre_driver.php | 2 +- system/database/drivers/postgre/postgre_result.php | 2 +- .../database/drivers/postgre/postgre_utility.php | 2 +- system/database/drivers/sqlite/sqlite_driver.php | 2 +- system/database/drivers/sqlite/sqlite_result.php | 2 +- system/database/drivers/sqlite/sqlite_utility.php | 2 +- 27 files changed, 480 insertions(+), 480 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index 4a119d042..9055a22c4 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 82d5b63b7..9e30a9fa5 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 33f408fb4..f8ea616cd 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index ee965b74c..fc700ec32 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 7d85ebb92..b438ad1d8 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 9533ec607..e9caf9f3e 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -1,455 +1,455 @@ -db - $CI =& get_instance(); - $this->db =& $CI->db; - - log_message('debug', "Database Utility Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Create database - * - * @access public - * @param string the database name - * @return bool - */ - function create_database($db_name) - { - $sql = $this->_create_database($db_name); - - if (is_bool($sql)) - { - return $sql; - } - - return $this->db->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access public - * @param string the database name - * @return bool - */ - function drop_database($db_name) - { - $sql = $this->_drop_database($db_name); - - if (is_bool($sql)) - { - return $sql; - } - - return $this->db->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * List databases - * - * @access public - * @return bool - */ - function list_databases() - { - // Is there a cached result? - if (isset($this->data_cache['db_names'])) - { - return $this->data_cache['db_names']; - } - - $query = $this->db->query($this->_list_databases()); - $dbs = array(); - if ($query->num_rows() > 0) - { - foreach ($query->result_array() as $row) - { - $dbs[] = current($row); - } - } - - $this->data_cache['db_names'] = $dbs; - return $this->data_cache['db_names']; - } - - // -------------------------------------------------------------------- - - /** - * Optimize Table - * - * @access public - * @param string the table name - * @return bool - */ - function optimize_table($table_name) - { - $sql = $this->_optimize_table($table_name); - - if (is_bool($sql)) - { - return $sql; - } - - $query = $this->db->query($sql); - $res = $query->result_array(); - - // Note: Due to a bug in current() that affects some versions - // of PHP we can not pass function call directly into it - return current($res); - } - - // -------------------------------------------------------------------- - - /** - * Optimize Database - * - * @access public - * @return array - */ - function optimize_database() - { - $result = array(); - foreach ($this->db->list_tables() as $table_name) - { - $sql = $this->_optimize_table($table_name); - - if (is_bool($sql)) - { - return $sql; - } - - $query = $this->db->query($sql); - - // Build the result array... - // Note: Due to a bug in current() that affects some versions - // of PHP we can not pass function call directly into it - $res = $query->result_array(); - $res = current($res); - $key = str_replace($this->db->database.'.', '', current($res)); - $keys = array_keys($res); - unset($res[$keys[0]]); - - $result[$key] = $res; - } - - return $result; - } - - // -------------------------------------------------------------------- - - /** - * Optimize Table - * - * @access public - * @param string the table name - * @return bool - */ - - function repair_table($table_name) - { - $sql = $this->_repair_table($table_name); - - if (is_bool($sql)) - { - return $sql; - } - - $query = $this->db->query($sql); - - // Note: Due to a bug in current() that affects some versions - // of PHP we can not pass function call directly into it - $res = $query->result_array(); - return current($res); - } - - // -------------------------------------------------------------------- - - /** - * Drop Table - * - * @access public - * @param string the table name - * @return bool - */ - function drop_table($table_name) - { - $sql = $this->_drop_table($table_name); - - if (is_bool($sql)) - { - return $sql; - } - - return $this->db->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Generate CSV from a query result object - * - * @access public - * @param object The query result object - * @param string The delimiter - tab by default - * @param string The newline character - \n by default - * @return string - */ - function csv_from_result($query, $delim = "\t", $newline = "\n") - { - if ( ! is_object($query) OR ! method_exists($query, 'field_names')) - { - show_error('You must submit a valid result object'); - } - - $out = ''; - - // First generate the headings from the table column names - foreach ($query->list_fields() as $name) - { - $out .= $name.$delim; - } - - $out = rtrim($out); - $out .= $newline; - - // Next blast through the result array and build out the rows - foreach ($query->result_array() as $row) - { - foreach ($row as $item) - { - $out .= $item.$delim; - } - $out = rtrim($out); - $out .= $newline; - } - - return $out; - } - - // -------------------------------------------------------------------- - - /** - * Generate XML data from a query result object - * - * @access public - * @param object The query result object - * @param array Any preferences - * @return string - */ - function xml_from_result($query, $params = array()) - { - if ( ! is_object($query) OR ! method_exists($query, 'field_names')) - { - show_error('You must submit a valid result object'); - } - - // Set our default values - foreach (array('root' => 'root', 'element' => 'element', 'newline' => "\n", 'tab' => "\t") as $key => $val) - { - if ( ! isset($params[$key])) - { - $params[$key] = $val; - } - } - - // Create variables for convenience - extract($params); - - // Load the xml helper - $CI =& get_instance(); - $CI->load->helper('xml'); - - // Generate the result - $xml = "<{$root}>".$newline; - foreach ($query->result_array() as $row) - { - $xml .= $tab."<{$element}>".$newline; - - foreach ($row as $key => $val) - { - $xml .= $tab.$tab."<{$key}>".xml_convert($val)."".$newline; - } - $xml .= $tab."".$newline; - } - $xml .= "".$newline; - - return $xml; - } - - // -------------------------------------------------------------------- - - /** - * Database Backup - * - * @access public - * @return void - */ - function backup($params = array()) - { - // If the parameters have not been submitted as an - // array then we know that it is simply the table - // name, which is a valid short cut. - if (is_string($params)) - { - $params = array('tables' => $params); - } - - // ------------------------------------------------------ - - // 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" - ); - - // Did the user submit any preferences? If so set them.... - if (count($params) > 0) - { - foreach ($prefs as $key => $val) - { - if (isset($params[$key])) - { - $prefs[$key] = $params[$key]; - } - } - } - - // ------------------------------------------------------ - - // Are we backing up a complete database or individual tables? - // If no table names were submitted we'll fetch the entire table list - if (count($prefs['tables']) == 0) - { - $prefs['tables'] = $this->db->list_tables(); - } - - // ------------------------------------------------------ - - // Validate the format - if ( ! in_array($prefs['format'], array('gzip', 'zip', 'txt'), TRUE)) - { - $prefs['format'] = 'txt'; - } - - // ------------------------------------------------------ - - // Is the encoder supported? If not, we'll either issue an - // error or use plain text depending on the debug settings - if (($prefs['format'] == 'gzip' AND ! @function_exists('gzencode')) - OR ($prefs['format'] == 'zip' AND ! @function_exists('gzcompress'))) - { - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_compression'); - } - - $prefs['format'] = 'txt'; - } - - // ------------------------------------------------------ - - // Set the filename if not provided - Only needed with Zip files - if ($prefs['filename'] == '' AND $prefs['format'] == 'zip') - { - $prefs['filename'] = (count($prefs['tables']) == 1) ? $prefs['tables'] : $this->db->database; - $prefs['filename'] .= '_'.date('Y-m-d_H-i', time()); - } - - // ------------------------------------------------------ - - // Was a Gzip file requested? - if ($prefs['format'] == 'gzip') - { - return gzencode($this->_backup($prefs)); - } - - // ------------------------------------------------------ - - // Was a text file requested? - if ($prefs['format'] == 'txt') - { - return $this->_backup($prefs); - } - - // ------------------------------------------------------ - - // Was a Zip file requested? - if ($prefs['format'] == 'zip') - { - // If they included the .zip file extension we'll remove it - if (preg_match("|.+?\.zip$|", $prefs['filename'])) - { - $prefs['filename'] = str_replace('.zip', '', $prefs['filename']); - } - - // Tack on the ".sql" file extension if needed - if ( ! preg_match("|.+?\.sql$|", $prefs['filename'])) - { - $prefs['filename'] .= '.sql'; - } - - // Load the Zip class and output it - - $CI =& get_instance(); - $CI->load->library('zip'); - $CI->zip->add_data($prefs['filename'], $this->_backup($prefs)); - return $CI->zip->get_zip(); - } - - } - - - - - - -} - +db + $CI =& get_instance(); + $this->db =& $CI->db; + + log_message('debug', "Database Utility Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Create database + * + * @access public + * @param string the database name + * @return bool + */ + function create_database($db_name) + { + $sql = $this->_create_database($db_name); + + if (is_bool($sql)) + { + return $sql; + } + + return $this->db->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access public + * @param string the database name + * @return bool + */ + function drop_database($db_name) + { + $sql = $this->_drop_database($db_name); + + if (is_bool($sql)) + { + return $sql; + } + + return $this->db->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access public + * @return bool + */ + function list_databases() + { + // Is there a cached result? + if (isset($this->data_cache['db_names'])) + { + return $this->data_cache['db_names']; + } + + $query = $this->db->query($this->_list_databases()); + $dbs = array(); + if ($query->num_rows() > 0) + { + foreach ($query->result_array() as $row) + { + $dbs[] = current($row); + } + } + + $this->data_cache['db_names'] = $dbs; + return $this->data_cache['db_names']; + } + + // -------------------------------------------------------------------- + + /** + * Optimize Table + * + * @access public + * @param string the table name + * @return bool + */ + function optimize_table($table_name) + { + $sql = $this->_optimize_table($table_name); + + if (is_bool($sql)) + { + return $sql; + } + + $query = $this->db->query($sql); + $res = $query->result_array(); + + // Note: Due to a bug in current() that affects some versions + // of PHP we can not pass function call directly into it + return current($res); + } + + // -------------------------------------------------------------------- + + /** + * Optimize Database + * + * @access public + * @return array + */ + function optimize_database() + { + $result = array(); + foreach ($this->db->list_tables() as $table_name) + { + $sql = $this->_optimize_table($table_name); + + if (is_bool($sql)) + { + return $sql; + } + + $query = $this->db->query($sql); + + // Build the result array... + // Note: Due to a bug in current() that affects some versions + // of PHP we can not pass function call directly into it + $res = $query->result_array(); + $res = current($res); + $key = str_replace($this->db->database.'.', '', current($res)); + $keys = array_keys($res); + unset($res[$keys[0]]); + + $result[$key] = $res; + } + + return $result; + } + + // -------------------------------------------------------------------- + + /** + * Optimize Table + * + * @access public + * @param string the table name + * @return bool + */ + + function repair_table($table_name) + { + $sql = $this->_repair_table($table_name); + + if (is_bool($sql)) + { + return $sql; + } + + $query = $this->db->query($sql); + + // Note: Due to a bug in current() that affects some versions + // of PHP we can not pass function call directly into it + $res = $query->result_array(); + return current($res); + } + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * @access public + * @param string the table name + * @return bool + */ + function drop_table($table_name) + { + $sql = $this->_drop_table($table_name); + + if (is_bool($sql)) + { + return $sql; + } + + return $this->db->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Generate CSV from a query result object + * + * @access public + * @param object The query result object + * @param string The delimiter - tab by default + * @param string The newline character - \n by default + * @return string + */ + function csv_from_result($query, $delim = "\t", $newline = "\n") + { + if ( ! is_object($query) OR ! method_exists($query, 'field_names')) + { + show_error('You must submit a valid result object'); + } + + $out = ''; + + // First generate the headings from the table column names + foreach ($query->list_fields() as $name) + { + $out .= $name.$delim; + } + + $out = rtrim($out); + $out .= $newline; + + // Next blast through the result array and build out the rows + foreach ($query->result_array() as $row) + { + foreach ($row as $item) + { + $out .= $item.$delim; + } + $out = rtrim($out); + $out .= $newline; + } + + return $out; + } + + // -------------------------------------------------------------------- + + /** + * Generate XML data from a query result object + * + * @access public + * @param object The query result object + * @param array Any preferences + * @return string + */ + function xml_from_result($query, $params = array()) + { + if ( ! is_object($query) OR ! method_exists($query, 'field_names')) + { + show_error('You must submit a valid result object'); + } + + // Set our default values + foreach (array('root' => 'root', 'element' => 'element', 'newline' => "\n", 'tab' => "\t") as $key => $val) + { + if ( ! isset($params[$key])) + { + $params[$key] = $val; + } + } + + // Create variables for convenience + extract($params); + + // Load the xml helper + $CI =& get_instance(); + $CI->load->helper('xml'); + + // Generate the result + $xml = "<{$root}>".$newline; + foreach ($query->result_array() as $row) + { + $xml .= $tab."<{$element}>".$newline; + + foreach ($row as $key => $val) + { + $xml .= $tab.$tab."<{$key}>".xml_convert($val)."".$newline; + } + $xml .= $tab."".$newline; + } + $xml .= "".$newline; + + return $xml; + } + + // -------------------------------------------------------------------- + + /** + * Database Backup + * + * @access public + * @return void + */ + function backup($params = array()) + { + // If the parameters have not been submitted as an + // array then we know that it is simply the table + // name, which is a valid short cut. + if (is_string($params)) + { + $params = array('tables' => $params); + } + + // ------------------------------------------------------ + + // 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" + ); + + // Did the user submit any preferences? If so set them.... + if (count($params) > 0) + { + foreach ($prefs as $key => $val) + { + if (isset($params[$key])) + { + $prefs[$key] = $params[$key]; + } + } + } + + // ------------------------------------------------------ + + // Are we backing up a complete database or individual tables? + // If no table names were submitted we'll fetch the entire table list + if (count($prefs['tables']) == 0) + { + $prefs['tables'] = $this->db->list_tables(); + } + + // ------------------------------------------------------ + + // Validate the format + if ( ! in_array($prefs['format'], array('gzip', 'zip', 'txt'), TRUE)) + { + $prefs['format'] = 'txt'; + } + + // ------------------------------------------------------ + + // Is the encoder supported? If not, we'll either issue an + // error or use plain text depending on the debug settings + if (($prefs['format'] == 'gzip' AND ! @function_exists('gzencode')) + OR ($prefs['format'] == 'zip' AND ! @function_exists('gzcompress'))) + { + if ($this->db->db_debug) + { + return $this->db->display_error('db_unsuported_compression'); + } + + $prefs['format'] = 'txt'; + } + + // ------------------------------------------------------ + + // Set the filename if not provided - Only needed with Zip files + if ($prefs['filename'] == '' AND $prefs['format'] == 'zip') + { + $prefs['filename'] = (count($prefs['tables']) == 1) ? $prefs['tables'] : $this->db->database; + $prefs['filename'] .= '_'.date('Y-m-d_H-i', time()); + } + + // ------------------------------------------------------ + + // Was a Gzip file requested? + if ($prefs['format'] == 'gzip') + { + return gzencode($this->_backup($prefs)); + } + + // ------------------------------------------------------ + + // Was a text file requested? + if ($prefs['format'] == 'txt') + { + return $this->_backup($prefs); + } + + // ------------------------------------------------------ + + // Was a Zip file requested? + if ($prefs['format'] == 'zip') + { + // If they included the .zip file extension we'll remove it + if (preg_match("|.+?\.zip$|", $prefs['filename'])) + { + $prefs['filename'] = str_replace('.zip', '', $prefs['filename']); + } + + // Tack on the ".sql" file extension if needed + if ( ! preg_match("|.+?\.sql$|", $prefs['filename'])) + { + $prefs['filename'] .= '.sql'; + } + + // Load the Zip class and output it + + $CI =& get_instance(); + $CI->load->library('zip'); + $CI->zip->add_data($prefs['filename'], $this->_backup($prefs)); + return $CI->zip->get_zip(); + } + + } + + + + + + +} + ?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index e4a2960e5..5140dd859 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index eb471e4be..66afd838a 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index 7f4e73084..3a102212b 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 50f4ecfbf..2e1f30f21 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index 7dcd5cb0e..d1d742a07 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index b357f47df..0d192147d 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 9cfc68ea6..4643cb2ac 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index 0f2eb5345..913a7dd3d 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 3e2b8da6e..55ffcb738 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 291e168eb..99b5ded13 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 07f154489..cb27caf58 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 1b49f4131..0f9e4e838 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index d6451e04a..3f42f7c35 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index cced4d482..e909fd743 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index f8d9e3c42..97e950fc1 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 798905126..a8a6ca169 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index 5b955ad12..9938d4069 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 9d56af363..fa5960e58 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index b82618c6a..f8a573b35 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index a16a5b054..9a2e2b6e8 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 9683b1756..85e74d05f 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource -- cgit v1.2.3-24-g4f1b From db43858f537722deef7c9ebc903534ea9be0df60 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sat, 13 Oct 2007 17:00:16 +0000 Subject: Added a check for NULL fields in the MySQL database backup utility --- system/database/drivers/mysql/mysql_utility.php | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 0d192147d..54c110e09 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -218,14 +218,31 @@ class CI_DB_mysql_utility extends CI_DB_utility { $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 .= ', '; + + // Is the value NULL? + if ($v == NULL) + { + $val_str .= 'NULL'; + } + else + { + // Escape the data if it's not an integer + if ($is_int[$i] == FALSE) + { + $val_str .= $this->db->escape($v); + } + 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 -- cgit v1.2.3-24-g4f1b From 218e2bcfd4c9c1ebb2454efc1179d047f40f5b34 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 17 Dec 2007 21:18:14 +0000 Subject: Added a third parameter to Active Record's like() clause to control where the wildcard goes. Deprecated from Active Record; getwhere() for get_where(); groupby() for group_by(); orderby() for order_by; orwhere() for or_where(); and orlike() for or_like(). --- system/database/DB_active_rec.php | 97 +++++++++++++++++++++++++++++++++------ 1 file changed, 83 insertions(+), 14 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 9e30a9fa5..c6e6039e0 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -185,10 +185,22 @@ class CI_DB_active_record extends CI_DB_driver { * @param mixed * @return object */ - function orwhere($key, $value = NULL) + function or_where($key, $value = NULL) { return $this->_where($key, $value, 'OR '); } + + // -------------------------------------------------------------------- + + /** + * orwhere() is an alias of or_where() + * this function is here for backwards compatibility, as + * orwhere() has been deprecated + */ + function orwhere($key, $value = NULL) + { + return $this->or_where($key, $value); + } // -------------------------------------------------------------------- @@ -244,9 +256,9 @@ class CI_DB_active_record extends CI_DB_driver { * @param mixed * @return object */ - function like($field, $match = '') + function like($field, $match = '', $side = 'both') { - return $this->_like($field, $match, 'AND '); + return $this->_like($field, $match, 'AND ', $side); } // -------------------------------------------------------------------- @@ -262,9 +274,21 @@ class CI_DB_active_record extends CI_DB_driver { * @param mixed * @return object */ - function orlike($field, $match = '') + function or_like($field, $match = '', $side = 'both') { - return $this->_like($field, $match, 'OR '); + return $this->_like($field, $match, 'OR ', $side); + } + + // -------------------------------------------------------------------- + + /** + * orlike() is an alias of or_like() + * this function is here for backwards compatibility, as + * orlike() has been deprecated + */ + function orlike($field, $match = '', $side = 'both') + { + return $this->orlike($field, $match, $side); } // -------------------------------------------------------------------- @@ -280,7 +304,7 @@ class CI_DB_active_record extends CI_DB_driver { * @param string * @return object */ - function _like($field, $match = '', $type = 'AND ') + function _like($field, $match = '', $type = 'AND ', $side = 'both') { if ( ! is_array($field)) { @@ -292,8 +316,19 @@ class CI_DB_active_record extends CI_DB_driver { $prefix = (count($this->ar_like) == 0) ? '' : $type; $v = $this->escape_str($v); - - $this->ar_like[] = $prefix." $k LIKE '%{$v}%'"; + + if ($side == 'before') + { + $this->ar_like[] = $prefix." $k LIKE '%{$v}'"; + } + elseif ($side == 'after') + { + $this->ar_like[] = $prefix." $k LIKE '{$v}%'"; + } + else + { + $this->ar_like[] = $prefix." $k LIKE '%{$v}%'"; + } } return $this; } @@ -307,7 +342,7 @@ class CI_DB_active_record extends CI_DB_driver { * @param string * @return object */ - function groupby($by) + function group_by($by) { if (is_string($by)) { @@ -323,7 +358,19 @@ class CI_DB_active_record extends CI_DB_driver { } return $this; } - + + // -------------------------------------------------------------------- + + /** + * groupby() is an alias of group_by() + * this function is here for backwards compatibility, as + * groupby() has been deprecated + */ + function groupby($by) + { + return $this->group_by($by); + } + // -------------------------------------------------------------------- /** @@ -401,7 +448,7 @@ class CI_DB_active_record extends CI_DB_driver { * @param string direction: asc or desc * @return object */ - function orderby($orderby, $direction = '') + function order_by($orderby, $direction = '') { if (trim($direction) != '') { @@ -411,7 +458,17 @@ class CI_DB_active_record extends CI_DB_driver { $this->ar_orderby[] = $orderby.$direction; return $this; } - + // -------------------------------------------------------------------- + + /** + * orderby() is an alias of order_by() + * this function is here for backwards compatibility, as + * orderby() has been deprecated + */ + function orderby($orderby, $direction = '') + { + return $this->order_by($orderby, $direction); + } // -------------------------------------------------------------------- /** @@ -509,7 +566,7 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- /** - * GetWhere + * Get_Where * * Allows the where clause, limit and offset to be added directly * @@ -519,7 +576,7 @@ class CI_DB_active_record extends CI_DB_driver { * @param string the offset clause * @return object */ - function getwhere($table = '', $where = null, $limit = null, $offset = null) + function get_where($table = '', $where = null, $limit = null, $offset = null) { if ($table != '') { @@ -542,6 +599,18 @@ class CI_DB_active_record extends CI_DB_driver { $this->_reset_select(); return $result; } + + // -------------------------------------------------------------------- + + /** + * getwhere() is an alias of get_where() + * this function is here for backwards compatibility, as + * getwhere() has been deprecated + */ + function getwhere($table = '', $where = null, $limit = null, $offset = null) + { + return $this->get_where($table, $where, $limit, $offset); + } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 04036f33f6af540ce371b1ebd1878018f0816ed8 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 17 Dec 2007 21:29:53 +0000 Subject: removed a duplicate function --- system/database/DB_active_rec.php | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index c6e6039e0..6a991a2ed 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -777,18 +777,6 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- - /** - * ORDER BY - DEPRECATED - * - * @deprecated use $this->db->orderby() instead - */ - function order_by($orderby, $direction = '') - { - return $this->orderby($orderby, $direction); - } - - // -------------------------------------------------------------------- - /** * Tests whether the string has an SQL operator * -- cgit v1.2.3-24-g4f1b From 694b5b8ee6a40b57c91be3c5448bc8f5540d32d8 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 18 Dec 2007 15:58:03 +0000 Subject: Added count_all_results() function to Active Record. --- system/database/DB_active_rec.php | 41 +++++++++++++++++++++- system/database/drivers/mssql/mssql_driver.php | 9 ++++- system/database/drivers/mysql/mysql_driver.php | 32 ++++++++++++++--- system/database/drivers/mysqli/mysqli_driver.php | 35 +++++++++++++++--- system/database/drivers/mysqli/mysqli_utility.php | 23 ++++++++++-- system/database/drivers/oci8/oci8_driver.php | 9 ++++- system/database/drivers/odbc/odbc_driver.php | 9 ++++- system/database/drivers/postgre/postgre_driver.php | 17 ++++++--- system/database/drivers/sqlite/sqlite_driver.php | 9 ++++- 9 files changed, 163 insertions(+), 21 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 6a991a2ed..cb134ea6a 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -540,6 +540,7 @@ class CI_DB_active_record extends CI_DB_driver { * and runs the query * * @access public + * @param string the table * @param string the limit clause * @param string the offset clause * @return object @@ -565,6 +566,39 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- + /** + * "Count All Results" query + * + * Generates a platform-specific query string that counts all records + * returned by an Active Record query. + * + * @access public + * @param string + * @return string + */ + function count_all_results($table = '') + { + if ($table != '') + { + $this->from($table); + } + + $sql = $this->_compile_select($this->count_string); + + $query = $this->query($sql); + $this->_reset_select(); + + if ($query->num_rows() == 0) + { + return '0'; + } + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + /** * Get_Where * @@ -806,12 +840,17 @@ class CI_DB_active_record extends CI_DB_driver { * @access private * @return string */ - function _compile_select() + function _compile_select($select_override = FALSE) { $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; $sql .= (count($this->ar_select) == 0) ? '*' : implode(', ', $this->ar_select); + if ($select_override !== FALSE) + { + $sql = $select_override; + } + if (count($this->ar_from) > 0) { $sql .= "\nFROM "; diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 5140dd859..051dd5bfe 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -30,6 +30,13 @@ */ class CI_DB_mssql_driver extends CI_DB { + /** + * The syntax to count rows is slightly different across different + * database engines, so this string appears in each driver and is + * used for the count_all() and count_all_results() functions. + */ + var $count_string = "SELECT COUNT(*) AS numrows "; + /** * Non-persistent database connection * @@ -273,7 +280,7 @@ class CI_DB_mssql_driver extends CI_DB { if ($table == '') return '0'; - $query = $this->query("SELECT COUNT(*) AS numrows FROM ".$this->dbprefix.$table); + $query = $this->query($this->count_string . "FROM ".$this->dbprefix.$table); if ($query->num_rows() == 0) return '0'; diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 2e1f30f21..69a238d94 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -30,6 +30,13 @@ */ class CI_DB_mysql_driver extends CI_DB { + /** + * The syntax to count rows is slightly different across different + * database engines, so this string appears in each driver and is + * used for the count_all() and count_all_results() functions. + */ + var $count_string = "SELECT COUNT(*) AS numrows "; + /** * Whether to use the MySQL "delete hack" which allows the number * of affected rows to be shown. Uses a preg_replace when enabled, @@ -222,7 +229,17 @@ class CI_DB_mysql_driver extends CI_DB { */ function escape_str($str) { - if (function_exists('mysql_real_escape_string')) + if (is_array($str)) + { + foreach($str as $key => $val) + { + $str[$key] = $this->escape_str($val); + } + + return $str; + } + + if (function_exists('mysql_real_escape_string') AND is_resource($this->conn_id)) { return mysql_real_escape_string($str, $this->conn_id); } @@ -279,7 +296,7 @@ class CI_DB_mysql_driver extends CI_DB { if ($table == '') return '0'; - $query = $this->query("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + $query = $this->query($this->count_string . "FROM `".$this->dbprefix.$table."`"); if ($query->num_rows() == 0) return '0'; @@ -298,9 +315,16 @@ class CI_DB_mysql_driver extends CI_DB { * @access private * @return string */ - function _list_tables() + function _list_tables($prefix_limit = FALSE) { - return "SHOW TABLES FROM `".$this->database."`"; + $sql = "SHOW TABLES FROM `".$this->database."`"; + + if ($prefix_limit !== FALSE AND $this->_stdprefix != '') + { + $sql .= " LIKE '".$this->_stdprefix."%'"; + } + + return $sql; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 4643cb2ac..30a256e05 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -30,6 +30,13 @@ */ class CI_DB_mysqli_driver extends CI_DB { + /** + * The syntax to count rows is slightly different across different + * database engines, so this string appears in each driver and is + * used for the count_all() and count_all_results() functions. + */ + var $count_string = "SELECT COUNT(*) AS numrows "; + /** * Whether to use the MySQL "delete hack" which allows the number * of affected rows to be shown. Uses a preg_replace when enabled, @@ -224,8 +231,19 @@ class CI_DB_mysqli_driver extends CI_DB { * @return string */ function escape_str($str) - { - return mysqli_real_escape_string($this->conn_id, $str); + { + if (function_exists('mysqli_real_escape_string') AND is_resource($this->conn_id)) + { + return mysqli_real_escape_string($this->conn_id, $str); + } + elseif (function_exists('mysql_escape_string')) + { + return mysql_escape_string($str); + } + else + { + return addslashes($str); + } } // -------------------------------------------------------------------- @@ -271,7 +289,7 @@ class CI_DB_mysqli_driver extends CI_DB { if ($table == '') return '0'; - $query = $this->query("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + $query = $this->query($this->count_string . "FROM `".$this->dbprefix.$table."`"); if ($query->num_rows() == 0) return '0'; @@ -290,9 +308,16 @@ class CI_DB_mysqli_driver extends CI_DB { * @access private * @return string */ - function _list_tables() + function _list_tables($prefix_limit = FALSE) { - return "SHOW TABLES FROM `".$this->database."`"; + $sql = "SHOW TABLES FROM `".$this->database."`"; + + if ($prefix_limit !== FALSE AND $this->_stdprefix != '') + { + $sql .= " LIKE '".$this->_stdprefix."%'"; + } + + return $sql; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 55ffcb738..c904e92d7 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -219,13 +219,30 @@ class CI_DB_mysqli_utility extends CI_DB_utility { $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 .= ', '; + // Is the value NULL? + if ($v == NULL) + { + $val_str .= 'NULL'; + } + else + { + // Escape the data if it's not an integer + if ($is_int[$i] == FALSE) + { + $val_str .= $this->db->escape($v); + } + 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 diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 99b5ded13..0cd04cc58 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -43,6 +43,13 @@ class CI_DB_oci8_driver extends CI_DB { + /** + * The syntax to count rows is slightly different across different + * database engines, so this string appears in each driver and is + * used for the count_all() and count_all_results() functions. + */ + var $count_string = "SELECT COUNT(1) AS numrows "; + // Set "auto commit" by default var $_commit = OCI_COMMIT_ON_SUCCESS; @@ -389,7 +396,7 @@ class CI_DB_oci8_driver extends CI_DB { if ($table == '') return '0'; - $query = $this->query("SELECT COUNT(1) AS numrows FROM ".$table); + $query = $this->query($this->count_string . "FROM ".$table); if ($query == FALSE) { diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 3f42f7c35..ef26ea1c6 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -30,6 +30,13 @@ */ class CI_DB_odbc_driver extends CI_DB { + /** + * The syntax to count rows is slightly different across different + * database engines, so this string appears in each driver and is + * used for the count_all() and count_all_results() functions. + */ + var $count_string = "SELECT COUNT(*) AS numrows "; + /** * Non-persistent database connection * @@ -251,7 +258,7 @@ class CI_DB_odbc_driver extends CI_DB { if ($table == '') return '0'; - $query = $this->query("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + $query = $this->query($this->count_string . "FROM `".$this->dbprefix.$table."`"); if ($query->num_rows() == 0) return '0'; diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index a8a6ca169..beaa7931c 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -30,6 +30,13 @@ */ class CI_DB_postgre_driver extends CI_DB { + /** + * The syntax to count rows is slightly different across different + * database engines, so this string appears in each driver and is + * used for the count_all() and count_all_results() functions. + */ + var $count_string = "SELECT COUNT(*) AS numrows "; + /** * Non-persistent database connection * @@ -277,9 +284,11 @@ class CI_DB_postgre_driver extends CI_DB { { if ($table == '') return '0'; - - $query = $this->query('SELECT COUNT(*) AS numrows FROM "'.$this->dbprefix.$table.'"'); - + + $query = $this->query($this->count_string .'FROM "'.$this->dbprefix.$table.'"'); +// original query before count_string was used. Kept for reference +// $query = $this->query('SELECT COUNT(*) AS numrows FROM "'.$this->dbprefix.$table.'"'); + if ($query->num_rows() == 0) return '0'; @@ -315,7 +324,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function _list_columns($table = '') { - return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->_escape_table($table)."'"; + return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->_escape_table($table)."'"; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index f8a573b35..5f86b8ec3 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -32,6 +32,13 @@ */ class CI_DB_sqlite_driver extends CI_DB { + /** + * The syntax to count rows is slightly different across different + * database engines, so this string appears in each driver and is + * used for the count_all() and count_all_results() functions. + */ + var $count_string = "SELECT COUNT(*) AS numrows "; + /** * Non-persistent database connection * @@ -274,7 +281,7 @@ class CI_DB_sqlite_driver extends CI_DB { if ($table == '') return '0'; - $query = $this->query("SELECT COUNT(*) AS numrows FROM `".$this->dbprefix.$table."`"); + $query = $this->query($this->count_string . "FROM `".$this->dbprefix.$table."`"); if ($query->num_rows() == 0) return '0'; -- cgit v1.2.3-24-g4f1b From 6ddb5a17ae1a0a75ca75f846dbb7d3a98f1902a3 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 18 Dec 2007 17:22:50 +0000 Subject: Added 'random' as an order_by() option in Active Record. --- system/database/DB_active_rec.php | 11 +++++++++-- system/database/drivers/mssql/mssql_driver.php | 4 ++-- system/database/drivers/mysql/mysql_driver.php | 17 +++++++++-------- system/database/drivers/mysqli/mysqli_driver.php | 7 ++++--- system/database/drivers/oci8/oci8_driver.php | 4 ++-- system/database/drivers/odbc/odbc_driver.php | 5 +++-- system/database/drivers/postgre/postgre_driver.php | 7 ++++--- system/database/drivers/sqlite/sqlite_driver.php | 5 +++-- 8 files changed, 36 insertions(+), 24 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index cb134ea6a..e8059ab76 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -450,7 +450,12 @@ class CI_DB_active_record extends CI_DB_driver { */ function order_by($orderby, $direction = '') { - if (trim($direction) != '') + if (strtolower($direction) == 'random') + { + $orderby = ''; // Random results want or don't need a field name + $direction = $this->_random_keyword; + } + elseif (trim($direction) != '') { $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' '.$direction : ' ASC'; } @@ -458,6 +463,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->ar_orderby[] = $orderby.$direction; return $this; } + // -------------------------------------------------------------------- /** @@ -469,6 +475,7 @@ class CI_DB_active_record extends CI_DB_driver { { return $this->order_by($orderby, $direction); } + // -------------------------------------------------------------------- /** @@ -583,7 +590,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->from($table); } - $sql = $this->_compile_select($this->count_string); + $sql = $this->_compile_select($this->_count_string); $query = $this->query($sql); $this->_reset_select(); diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 051dd5bfe..89610455b 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -35,7 +35,7 @@ class CI_DB_mssql_driver extends CI_DB { * database engines, so this string appears in each driver and is * used for the count_all() and count_all_results() functions. */ - var $count_string = "SELECT COUNT(*) AS numrows "; + var $_count_string = "SELECT COUNT(*) AS numrows "; /** * Non-persistent database connection @@ -280,7 +280,7 @@ class CI_DB_mssql_driver extends CI_DB { if ($table == '') return '0'; - $query = $this->query($this->count_string . "FROM ".$this->dbprefix.$table); + $query = $this->query($this->_count_string . "FROM ".$this->dbprefix.$table); if ($query->num_rows() == 0) return '0'; diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 69a238d94..2d91c5927 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -30,19 +30,20 @@ */ class CI_DB_mysql_driver extends CI_DB { - /** - * The syntax to count rows is slightly different across different - * database engines, so this string appears in each driver and is - * used for the count_all() and count_all_results() functions. - */ - var $count_string = "SELECT COUNT(*) AS numrows "; - /** * 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 + * used for the count_all() and count_all_results() functions. + */ + var $_count_string = "SELECT COUNT(*) AS numrows "; + var $_random_keyword = ' RAND()'; // database specific random keyword /** * Non-persistent database connection @@ -296,7 +297,7 @@ class CI_DB_mysql_driver extends CI_DB { if ($table == '') return '0'; - $query = $this->query($this->count_string . "FROM `".$this->dbprefix.$table."`"); + $query = $this->query($this->_count_string . "FROM `".$this->dbprefix.$table."`"); if ($query->num_rows() == 0) return '0'; diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 30a256e05..099117097 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -35,8 +35,9 @@ class CI_DB_mysqli_driver extends CI_DB { * database engines, so this string appears in each driver and is * used for the count_all() and count_all_results() functions. */ - var $count_string = "SELECT COUNT(*) AS numrows "; - + var $_count_string = "SELECT COUNT(*) AS numrows "; + var $_random_keyword = ' RAND()'; // database specific random keyword + /** * Whether to use the MySQL "delete hack" which allows the number * of affected rows to be shown. Uses a preg_replace when enabled, @@ -289,7 +290,7 @@ class CI_DB_mysqli_driver extends CI_DB { if ($table == '') return '0'; - $query = $this->query($this->count_string . "FROM `".$this->dbprefix.$table."`"); + $query = $this->query($this->_count_string . "FROM `".$this->dbprefix.$table."`"); if ($query->num_rows() == 0) return '0'; diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 0cd04cc58..e6bcefef1 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -48,7 +48,7 @@ class CI_DB_oci8_driver extends CI_DB { * database engines, so this string appears in each driver and is * used for the count_all() and count_all_results() functions. */ - var $count_string = "SELECT COUNT(1) AS numrows "; + var $_count_string = "SELECT COUNT(1) AS numrows "; // Set "auto commit" by default var $_commit = OCI_COMMIT_ON_SUCCESS; @@ -396,7 +396,7 @@ class CI_DB_oci8_driver extends CI_DB { if ($table == '') return '0'; - $query = $this->query($this->count_string . "FROM ".$table); + $query = $this->query($this->_count_string . "FROM ".$table); if ($query == FALSE) { diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index ef26ea1c6..5e1676244 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -35,7 +35,8 @@ class CI_DB_odbc_driver extends CI_DB { * database engines, so this string appears in each driver and is * used for the count_all() and count_all_results() functions. */ - var $count_string = "SELECT COUNT(*) AS numrows "; + var $_count_string = "SELECT COUNT(*) AS numrows "; + var $_random_keyword = ' RND('.time().')'; // database specific random keyword /** * Non-persistent database connection @@ -258,7 +259,7 @@ class CI_DB_odbc_driver extends CI_DB { if ($table == '') return '0'; - $query = $this->query($this->count_string . "FROM `".$this->dbprefix.$table."`"); + $query = $this->query($this->_count_string . "FROM `".$this->dbprefix.$table."`"); if ($query->num_rows() == 0) return '0'; diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index beaa7931c..e54f9cceb 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -35,7 +35,8 @@ class CI_DB_postgre_driver extends CI_DB { * database engines, so this string appears in each driver and is * used for the count_all() and count_all_results() functions. */ - var $count_string = "SELECT COUNT(*) AS numrows "; + var $_count_string = "SELECT COUNT(*) AS numrows "; + var $_random_keyword = ' RANDOM()'; // database specific random keyword /** * Non-persistent database connection @@ -285,8 +286,8 @@ class CI_DB_postgre_driver extends CI_DB { if ($table == '') return '0'; - $query = $this->query($this->count_string .'FROM "'.$this->dbprefix.$table.'"'); -// original query before count_string was used. Kept for reference + $query = $this->query($this->_count_string .'FROM "'.$this->dbprefix.$table.'"'); +// original query before _count_string was used. Kept for reference // $query = $this->query('SELECT COUNT(*) AS numrows FROM "'.$this->dbprefix.$table.'"'); if ($query->num_rows() == 0) diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 5f86b8ec3..aa6738c03 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -37,7 +37,8 @@ class CI_DB_sqlite_driver extends CI_DB { * database engines, so this string appears in each driver and is * used for the count_all() and count_all_results() functions. */ - var $count_string = "SELECT COUNT(*) AS numrows "; + var $_count_string = "SELECT COUNT(*) AS numrows "; + var $_random_keyword = ' Random()'; // database specific random keyword /** * Non-persistent database connection @@ -281,7 +282,7 @@ class CI_DB_sqlite_driver extends CI_DB { if ($table == '') return '0'; - $query = $this->query($this->count_string . "FROM `".$this->dbprefix.$table."`"); + $query = $this->query($this->_count_string . "FROM `".$this->dbprefix.$table."`"); if ($query->num_rows() == 0) return '0'; -- cgit v1.2.3-24-g4f1b From 80dd702d4c46552a3d1f94c5083c83eeff333b45 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 18 Dec 2007 23:55:06 +0000 Subject: Added where_in() to Active Record. --- system/database/DB_active_rec.php | 40 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index e8059ab76..c3279e8c3 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -41,6 +41,8 @@ class CI_DB_active_record extends CI_DB_driver { var $ar_order = FALSE; var $ar_orderby = array(); var $ar_set = array(); + var $ar_wherein = array(); + /** @@ -240,9 +242,41 @@ class CI_DB_active_record extends CI_DB_driver { } return $this; } - - - + + // -------------------------------------------------------------------- + + /** + * Where_in + * + * Generates a WHERE field IN ('item', 'item') SQL query + * + * @access public + * @param string The field to search + * @param array The values searched on + * @param string + * @return object + */ + function where_in($key = NULL, $values = NULL, $type = 'and') + { + if ($key === NULL || !is_array($values)) + { + return; + } + + $type = (strtolower($type) == 'or') ? ' OR ' : ' AND '; + + foreach ($values as $value) + { + $this->ar_wherein[] = $this->escape($value); + } + + $prefix = (count($this->ar_where) == 0) ? '' : $type; + + $this->ar_where[] = $prefix.$key. " IN (" . implode(", ", $this->ar_wherein) . ") "; + + return $this; + } + // -------------------------------------------------------------------- /** -- cgit v1.2.3-24-g4f1b From c6935514fbe8ead6aed2ee711e1ce106913a9f47 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 19 Dec 2007 14:23:19 +0000 Subject: Added where_in(), where_in_or(), where_not_in(), and where_not_in_or() to Active Record. --- system/database/DB_active_rec.php | 85 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 3 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index c3279e8c3..473685874 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -248,21 +248,99 @@ class CI_DB_active_record extends CI_DB_driver { /** * Where_in * - * Generates a WHERE field IN ('item', 'item') SQL query + * Generates a WHERE field IN ('item', 'item') SQL query joined with + * AND if appropriate * * @access public * @param string The field to search * @param array The values searched on + + * @return object + */ + function where_in($key = NULL, $values = NULL) + { + return $this->_where_in($key, $values); + } + + // -------------------------------------------------------------------- + + /** + * Where_in_or + * + * Generates a WHERE field IN ('item', 'item') SQL query joined with + * OR if appropriate + * + * @access public + * @param string The field to search + * @param array The values searched on + + * @return object + */ + function where_in_or($key = NULL, $values = NULL) + { + return $this->_where_in($key, $values, FALSE, 'or'); + } + + // -------------------------------------------------------------------- + + /** + * Where_not_in + * + * Generates a WHERE field NOT IN ('item', 'item') SQL query joined + * with AND if appropriate + * + * @access public + * @param string The field to search + * @param array The values searched on + + * @return object + */ + function where_not_in($key = NULL, $values = NULL) + { + return $this->_where_in($key, $values, TRUE); + } + + // -------------------------------------------------------------------- + + /** + * Where_not_in_or + * + * Generates a WHERE field NOT IN ('item', 'item') SQL query joined + * with OR if appropriate + * + * @access public + * @param string The field to search + * @param array The values searched on + + * @return object + */ + function where_not_in_or($key = NULL, $values = NULL) + { + return $this->_where_in($key, $values, FALSE, 'or'); + } + + // -------------------------------------------------------------------- + + /** + * Where_in + * + * Called by where_in, where_in_or, where_not_in, where_not_in_or + * + * @access public + * @param string The field to search + * @param array The values searched on + * @param boolean If the statement whould be IN or NOT IN * @param string * @return object */ - function where_in($key = NULL, $values = NULL, $type = 'and') + function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'and') { if ($key === NULL || !is_array($values)) { return; } + $not = ($not) ? ' NOT ' : ''; $type = (strtolower($type) == 'or') ? ' OR ' : ' AND '; foreach ($values as $value) @@ -272,7 +350,7 @@ class CI_DB_active_record extends CI_DB_driver { $prefix = (count($this->ar_where) == 0) ? '' : $type; - $this->ar_where[] = $prefix.$key. " IN (" . implode(", ", $this->ar_wherein) . ") "; + $this->ar_where[] = $prefix.$key.$not . " IN (" . implode(", ", $this->ar_wherein) . ") "; return $this; } @@ -1005,6 +1083,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->ar_offset = FALSE; $this->ar_order = FALSE; $this->ar_orderby = array(); + $this->ar_wherein = array(); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From da6d240d7b8615b5ae628496c42cb216658eb6e4 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 19 Dec 2007 14:49:29 +0000 Subject: Added support for limit() into update() statements in Active Record. --- system/database/DB_active_rec.php | 10 ++++++++-- system/database/drivers/mssql/mssql_driver.php | 6 ++++-- system/database/drivers/mysql/mysql_driver.php | 6 ++++-- system/database/drivers/mysqli/mysqli_driver.php | 6 ++++-- system/database/drivers/oci8/oci8_driver.php | 8 +++++--- system/database/drivers/odbc/odbc_driver.php | 6 ++++-- system/database/drivers/postgre/postgre_driver.php | 6 ++++-- system/database/drivers/sqlite/sqlite_driver.php | 6 ++++-- 8 files changed, 37 insertions(+), 17 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 473685874..4a88bd816 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -826,7 +826,7 @@ class CI_DB_active_record extends CI_DB_driver { * @param mixed the where clause * @return object */ - function update($table = '', $set = NULL, $where = null) + function update($table = '', $set = NULL, $where = null, $limit = NULL) { if ( ! is_null($set)) { @@ -860,8 +860,13 @@ class CI_DB_active_record extends CI_DB_driver { { $this->where($where); } + + if ($limit != null) + { + $this->limit($limit); + } - $sql = $this->_update($this->dbprefix.$table, $this->ar_set, $this->ar_where); + $sql = $this->_update($this->dbprefix.$table, $this->ar_set, $this->ar_where, $this->ar_limit); $this->_reset_write(); return $this->query($sql); @@ -1101,6 +1106,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->ar_set = array(); $this->ar_from = array(); $this->ar_where = array(); + $this->ar_limit = FALSE; } } diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 89610455b..613be69b5 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -421,14 +421,16 @@ class CI_DB_mssql_driver extends CI_DB { * @param array the where clause * @return string */ - function _update($table, $values, $where) + function _update($table, $values, $where, $limit = FALSE) { foreach($values as $key => $val) { $valstr[] = $key." = ".$val; } + + $limit = (!$limit) ? '' : ' LIMIT '.$limit; - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$limit; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 2d91c5927..aaa9cc635 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -439,14 +439,16 @@ class CI_DB_mysql_driver extends CI_DB { * @param array the where clause * @return string */ - function _update($table, $values, $where) + function _update($table, $values, $where, $limit = FALSE) { foreach($values as $key => $val) { $valstr[] = $key." = ".$val; } + + $limit = (!$limit) ? '' : ' LIMIT '.$limit; - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$limit; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 099117097..f6f106eba 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -432,14 +432,16 @@ class CI_DB_mysqli_driver extends CI_DB { * @param array the where clause * @return string */ - function _update($table, $values, $where) + function _update($table, $values, $where, $limit = FALSE) { foreach($values as $key => $val) { $valstr[] = $key." = ".$val; } + + $limit = (!$limit) ? '' : ' LIMIT '.$limit; - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$limit; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index e6bcefef1..1dd157cca 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -535,14 +535,16 @@ class CI_DB_oci8_driver extends CI_DB { * @param array the where clause * @return string */ - function _update($table, $values, $where) + function _update($table, $values, $where, $limit = FALSE) { foreach($values as $key => $val) { $valstr[] = $key." = ".$val; } - - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + + $limit = (!$limit) ? '' : ' LIMIT '.$limit; + + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$limit; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 5e1676244..66d5f89b9 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -394,14 +394,16 @@ class CI_DB_odbc_driver extends CI_DB { * @param array the where clause * @return string */ - function _update($table, $values, $where) + function _update($table, $values, $where, $limit = FALSE) { foreach($values as $key => $val) { $valstr[] = $key." = ".$val; } + + $limit = (!$limit) ? '' : ' LIMIT '.$limit; - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$limit; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index e54f9cceb..076d87a58 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -423,14 +423,16 @@ class CI_DB_postgre_driver extends CI_DB { * @param array the where clause * @return string */ - function _update($table, $values, $where) + function _update($table, $values, $where, $limit = FALSE) { foreach($values as $key => $val) { $valstr[] = $key." = ".$val; } + + $limit = (!$limit) ? '' : ' LIMIT '.$limit; - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$limit; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index aa6738c03..b701d6b96 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -418,14 +418,16 @@ class CI_DB_sqlite_driver extends CI_DB { * @param array the where clause * @return string */ - function _update($table, $values, $where) + function _update($table, $values, $where, $limit = FALSE) { foreach($values as $key => $val) { $valstr[] = $key." = ".$val; } + + $limit = (!$limit) ? '' : ' LIMIT '.$limit; - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$limit; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From e77d77c6b4c094483a3d85b23845436b77796d07 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 19 Dec 2007 15:01:55 +0000 Subject: Added support for limit() into update() and delete() statements in Active Record. --- system/database/DB_active_rec.php | 15 ++++++++++----- system/database/drivers/mssql/mssql_driver.php | 6 ++++-- system/database/drivers/mysql/mysql_driver.php | 6 ++++-- system/database/drivers/mysqli/mysqli_driver.php | 6 ++++-- system/database/drivers/oci8/oci8_driver.php | 6 ++++-- system/database/drivers/odbc/odbc_driver.php | 6 ++++-- system/database/drivers/postgre/postgre_driver.php | 6 ++++-- system/database/drivers/sqlite/sqlite_driver.php | 6 ++++-- 8 files changed, 38 insertions(+), 19 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 4a88bd816..cea9bddc5 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -856,12 +856,12 @@ class CI_DB_active_record extends CI_DB_driver { $table = $this->ar_from[0]; } - if ($where != null) + if ($where != NULL) { $this->where($where); } - if ($limit != null) + if ($limit != NULL) { $this->limit($limit); } @@ -884,7 +884,7 @@ class CI_DB_active_record extends CI_DB_driver { * @param mixed the where clause * @return object */ - function delete($table = '', $where = '') + function delete($table = '', $where = '', $limit = NULL) { if ($table == '') { @@ -905,6 +905,11 @@ class CI_DB_active_record extends CI_DB_driver { $this->where($where); } + if ($limit != NULL) + { + $this->limit($limit); + } + if (count($this->ar_where) == 0) { if ($this->db_debug) @@ -914,7 +919,7 @@ class CI_DB_active_record extends CI_DB_driver { return FALSE; } - $sql = $this->_delete($this->dbprefix.$table, $this->ar_where); + $sql = $this->_delete($this->dbprefix.$table, $this->ar_where, $this->ar_limit); $this->_reset_write(); return $this->query($sql); @@ -1096,7 +1101,7 @@ class CI_DB_active_record extends CI_DB_driver { /** * Resets the active record "write" values. * - * Called by the insert() or update() functions + * Called by the insert() update() and delete() functions * * @access private * @return void diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 613be69b5..044fb3ced 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -445,9 +445,11 @@ class CI_DB_mssql_driver extends CI_DB { * @param array the where clause * @return string */ - function _delete($table, $where) + function _delete($table, $where, $limit = FALSE) { - return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); + $limit = (!$limit) ? '' : ' LIMIT '.$limit; + + return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where).$limit; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index aaa9cc635..cd86ebf52 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -463,9 +463,11 @@ class CI_DB_mysql_driver extends CI_DB { * @param array the where clause * @return string */ - function _delete($table, $where) + function _delete($table, $where, $limit = FALSE) { - return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); + $limit = (!$limit) ? '' : ' LIMIT '.$limit; + + return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where).$limit; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index f6f106eba..ebed81390 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -456,9 +456,11 @@ class CI_DB_mysqli_driver extends CI_DB { * @param array the where clause * @return string */ - function _delete($table, $where) + function _delete($table, $where, $limit = FALSE) { - return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); + $limit = (!$limit) ? '' : ' LIMIT '.$limit; + + return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where).$limit; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 1dd157cca..c4ab70051 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -559,9 +559,11 @@ class CI_DB_oci8_driver extends CI_DB { * @param array the where clause * @return string */ - function _delete($table, $where) + function _delete($table, $where, $limit = FALSE) { - return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); + $limit = (!$limit) ? '' : ' LIMIT '.$limit; + + return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where).$limit; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 66d5f89b9..040ffed9e 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -418,9 +418,11 @@ class CI_DB_odbc_driver extends CI_DB { * @param array the where clause * @return string */ - function _delete($table, $where) + function _delete($table, $where, $limit = FALSE) { - return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); + $limit = (!$limit) ? '' : ' LIMIT '.$limit; + + return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where).$limit; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 076d87a58..88f08b2d7 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -447,9 +447,11 @@ class CI_DB_postgre_driver extends CI_DB { * @param array the where clause * @return string */ - function _delete($table, $where) + function _delete($table, $where, $limit = FALSE) { - return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); + $limit = (!$limit) ? '' : ' LIMIT '.$limit; + + return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where).$limit; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index b701d6b96..6189b1ff0 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -442,9 +442,11 @@ class CI_DB_sqlite_driver extends CI_DB { * @param array the where clause * @return string */ - function _delete($table, $where) + function _delete($table, $where, $limit = FALSE) { - return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); + $limit = (!$limit) ? '' : ' LIMIT '.$limit; + + return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where).$limit; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From e54e3d2786b76266e6b6dde481cc493ba002faae Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 19 Dec 2007 15:53:44 +0000 Subject: where_in_or became or_where_in(), where_not_in_or() became or_where_not_in() for consistency Added not_like() and or_not_like() --- system/database/DB_active_rec.php | 57 ++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 10 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index cea9bddc5..0a4327b42 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -276,7 +276,7 @@ class CI_DB_active_record extends CI_DB_driver { * @return object */ - function where_in_or($key = NULL, $values = NULL) + function or_where_in($key = NULL, $values = NULL) { return $this->_where_in($key, $values, FALSE, 'or'); } @@ -314,7 +314,7 @@ class CI_DB_active_record extends CI_DB_driver { * @return object */ - function where_not_in_or($key = NULL, $values = NULL) + function or_where_not_in($key = NULL, $values = NULL) { return $this->_where_in($key, $values, FALSE, 'or'); } @@ -372,7 +372,25 @@ class CI_DB_active_record extends CI_DB_driver { { return $this->_like($field, $match, 'AND ', $side); } - + + // -------------------------------------------------------------------- + + /** + * Not Like + * + * Generates a NOT LIKE portion of the query. Separates + * multiple calls with AND + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function not_like($field, $match = '', $side = 'both') + { + return $this->_like($field, $match, 'AND ', $side, ' NOT'); + } + // -------------------------------------------------------------------- /** @@ -393,6 +411,24 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- + /** + * OR Not Like + * + * Generates a NOT LIKE portion of the query. Separates + * multiple calls with OR + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function or_not_like($field, $match = '', $side = 'both') + { + return $this->_like($field, $match, 'OR ', $side, 'NOT '); + } + + // -------------------------------------------------------------------- + /** * orlike() is an alias of or_like() * this function is here for backwards compatibility, as @@ -416,7 +452,7 @@ class CI_DB_active_record extends CI_DB_driver { * @param string * @return object */ - function _like($field, $match = '', $type = 'AND ', $side = 'both') + function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '') { if ( ! is_array($field)) { @@ -424,22 +460,23 @@ class CI_DB_active_record extends CI_DB_driver { } foreach ($field as $k => $v) - { + { + $prefix = (count($this->ar_like) == 0) ? '' : $type; - + $v = $this->escape_str($v); - + if ($side == 'before') { - $this->ar_like[] = $prefix." $k LIKE '%{$v}'"; + $this->ar_like[] = $prefix." $k $not LIKE '%{$v}'"; } elseif ($side == 'after') { - $this->ar_like[] = $prefix." $k LIKE '{$v}%'"; + $this->ar_like[] = $prefix." $k $not LIKE '{$v}%'"; } else { - $this->ar_like[] = $prefix." $k LIKE '%{$v}%'"; + $this->ar_like[] = $prefix." $k $not LIKE '%{$v}%'"; } } return $this; -- cgit v1.2.3-24-g4f1b From 15ddc9d0c1971de92c0f80bfe12f157786f97895 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 20 Dec 2007 13:54:39 +0000 Subject: Changed the behaviour of variables submitted to the where() clause with no values to auto set "IS NULL" Added parenthesis around table names in SQL FROM --- system/database/DB_active_rec.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 0a4327b42..dfa0a3efb 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -226,16 +226,25 @@ class CI_DB_active_record extends CI_DB_driver { foreach ($key as $k => $v) { + $prefix = (count($this->ar_where) == 0) ? '' : $type; + + if (is_null($key[$k])) + { + // value appears not to have been set, assign the test to IS NULL + $k .= ' IS NULL'; + } if ( ! is_null($v)) { + if ( ! $this->_has_operator($k)) { $k .= ' ='; } - + $v = ' '.$this->escape($v); + } $this->ar_where[] = $prefix.$k.$v; @@ -278,7 +287,7 @@ class CI_DB_active_record extends CI_DB_driver { */ function or_where_in($key = NULL, $values = NULL) { - return $this->_where_in($key, $values, FALSE, 'or'); + return $this->_where_in($key, $values, FALSE, 'OR '); } // -------------------------------------------------------------------- @@ -316,7 +325,7 @@ class CI_DB_active_record extends CI_DB_driver { */ function or_where_not_in($key = NULL, $values = NULL) { - return $this->_where_in($key, $values, FALSE, 'or'); + return $this->_where_in($key, $values, FALSE, 'OR '); } // -------------------------------------------------------------------- @@ -333,7 +342,7 @@ class CI_DB_active_record extends CI_DB_driver { * @param string * @return object */ - function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'and') + function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ') { if ($key === NULL || !is_array($values)) { @@ -341,7 +350,6 @@ class CI_DB_active_record extends CI_DB_driver { } $not = ($not) ? ' NOT ' : ''; - $type = (strtolower($type) == 'or') ? ' OR ' : ' AND '; foreach ($values as $value) { @@ -955,13 +963,13 @@ class CI_DB_active_record extends CI_DB_driver { } return FALSE; } - + $sql = $this->_delete($this->dbprefix.$table, $this->ar_where, $this->ar_limit); $this->_reset_write(); return $this->query($sql); } - + // -------------------------------------------------------------------- /** @@ -1020,7 +1028,7 @@ class CI_DB_active_record extends CI_DB_driver { if (count($this->ar_from) > 0) { $sql .= "\nFROM "; - $sql .= implode(', ', $this->ar_from); + $sql .= '(' . implode(', ', $this->ar_from) . ')'; } if (count($this->ar_join) > 0) -- cgit v1.2.3-24-g4f1b From aa7f769c1e6f46171f2fbc15f43428207c02abcb Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 20 Dec 2007 14:38:56 +0000 Subject: fixed typo: $field_names[] vs $Ffield_names[] --- system/database/drivers/postgre/postgre_result.php | 2 +- system/database/drivers/sqlite/sqlite_result.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index 9938d4069..9fd2a7e93 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -65,7 +65,7 @@ class CI_DB_postgre_result extends CI_DB_result { $field_names = array(); for ($i = 0; $i < $this->num_fields(); $i++) { - $Ffield_names[] = pg_field_name($this->result_id, $i); + $field_names[] = pg_field_name($this->result_id, $i); } return $field_names; diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index 9a2e2b6e8..caa167813 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -65,7 +65,7 @@ class CI_DB_sqlite_result extends CI_DB_result { $field_names = array(); for ($i = 0; $i < $this->num_fields(); $i++) { - $Ffield_names[] = sqlite_field_name($this->result_id, $i); + $field_names[] = sqlite_field_name($this->result_id, $i); } return $field_names; -- cgit v1.2.3-24-g4f1b From 41f60d44e37cc52d41a49d0d640f71761a82abe7 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 20 Dec 2007 20:09:22 +0000 Subject: Added the ability to pass an array of tables to the delete() statement in Active Record. --- system/database/DB_active_rec.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index dfa0a3efb..d48d1c5bd 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -925,11 +925,13 @@ class CI_DB_active_record extends CI_DB_driver { * Compiles a delete string and runs the query * * @access public - * @param string the table to retrieve the results from + * @param mixed the table(s) to delete from. String or array * @param mixed the where clause + * @param mixed the limit clause + * @param boolean * @return object */ - function delete($table = '', $where = '', $limit = NULL) + function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE) { if ($table == '') { @@ -945,6 +947,16 @@ class CI_DB_active_record extends CI_DB_driver { $table = $this->ar_from[0]; } + if (is_array($table)) + { + foreach($table as $single_table) + { + $this->delete($this->dbprefix.$single_table, $where, $limit, FALSE); + } + $this->_reset_write(); + return; + } + if ($where != '') { $this->where($where); @@ -963,10 +975,13 @@ class CI_DB_active_record extends CI_DB_driver { } return FALSE; } - + $sql = $this->_delete($this->dbprefix.$table, $this->ar_where, $this->ar_limit); - $this->_reset_write(); + if ($reset_data) + { + $this->_reset_write(); + } return $this->query($sql); } -- cgit v1.2.3-24-g4f1b From 5e12894eb97cc902892b7c4de79bec55772f7b83 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 28 Dec 2007 21:33:03 +0000 Subject: Added the ability to use aliases with joins in Active Record. --- system/database/DB_active_rec.php | 107 +++++++++++++++++++++++++++++++++----- 1 file changed, 94 insertions(+), 13 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index d48d1c5bd..4bf3098d9 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -42,7 +42,7 @@ class CI_DB_active_record extends CI_DB_driver { var $ar_orderby = array(); var $ar_set = array(); var $ar_wherein = array(); - + var $ar_aliased_tables = array(); /** @@ -103,8 +103,10 @@ class CI_DB_active_record extends CI_DB_driver { { foreach ((array)$from as $val) { + $this->_track_aliases($val); $this->ar_from[] = $this->dbprefix.$val; } + return $this; } @@ -137,11 +139,6 @@ class CI_DB_active_record extends CI_DB_driver { } } - if ($this->dbprefix) - { - $cond = preg_replace('|([\w\.]+)([\W\s]+)(.+)|', $this->dbprefix . "$1$2" . $this->dbprefix . "$3", $cond); - } - // If a DB prefix is used we might need to add it to the column names if ($this->dbprefix) { @@ -150,8 +147,11 @@ class CI_DB_active_record extends CI_DB_driver { // Next we add the prefixes to the condition $cond = preg_replace('|([\w\.]+)([\W\s]+)(.+)|', $this->dbprefix . "$1$2" . $this->dbprefix . "$3", $cond); - } - + + $this->_track_aliases($table); + + } + $this->ar_join[] = $type.'JOIN '.$this->dbprefix.$table.' ON '.$cond; return $this; } @@ -511,7 +511,7 @@ class CI_DB_active_record extends CI_DB_driver { $val = trim($val); if ($val != '') - $this->ar_groupby[] = $val; + $this->ar_groupby[] = $this->dbprefix.$val; } return $this; } @@ -713,6 +713,7 @@ class CI_DB_active_record extends CI_DB_driver { { if ($table != '') { + $this->_track_aliases($table); $this->from($table); } @@ -744,6 +745,7 @@ class CI_DB_active_record extends CI_DB_driver { { if ($table != '') { + $this->_track_aliases($table); $this->from($table); } @@ -778,6 +780,7 @@ class CI_DB_active_record extends CI_DB_driver { { if ($table != '') { + $this->_track_aliases($table); $this->from($table); } @@ -871,7 +874,7 @@ class CI_DB_active_record extends CI_DB_driver { * @param mixed the where clause * @return object */ - function update($table = '', $set = NULL, $where = null, $limit = NULL) + function update($table = '', $set = NULL, $where = NULL, $limit = NULL) { if ( ! is_null($set)) { @@ -1020,6 +1023,63 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- + /** + * Track Aliases + * + * Used to track SQL statements written with aliased tables. + * + * @access private + * @param string The table to inspect + * @return string + */ + function _track_aliases($table) + { + // if a table alias is used we can recognize it by a space + if (strpos($table, " ") !== FALSE) + { + // if the alias is written with the AS keyowrd, get it out + $table = preg_replace('/AS/i', '', $table); + + $this->ar_aliased_tables[] = trim(strrchr($table, " ") . '.'); + } + + return $this->dbprefix.$table; + } + + // -------------------------------------------------------------------- + + /** + * Filter Table Aliases + * + * Intelligently removes database prefixes from aliased tables + * + * @access private + * @param array An array of compiled SQL + * @return array Cleaned up statement with aliases accounted for + */ + function _filter_table_aliases($statements) + { + $filter_tables_with_aliases = array(); + + foreach ($statements as $statement) + { + $tables_with_dbprefix = array(); + + foreach ($this->ar_aliased_tables as $k => $v) + { + $tables_with_dbprefix[$k] = '/'.$this->dbprefix.str_replace('.', '', $v).'\./'; + } + + $statement = preg_replace($tables_with_dbprefix, $this->ar_aliased_tables, $statement); + + $filter_tables_with_aliases[] = $statement; + } + + return $filter_tables_with_aliases; + } + + // -------------------------------------------------------------------- + /** * Compile the SELECT statement * @@ -1047,9 +1107,19 @@ class CI_DB_active_record extends CI_DB_driver { } if (count($this->ar_join) > 0) - { + { $sql .= "\n"; - $sql .= implode("\n", $this->ar_join); + + // special consideration for table aliases + if (count($this->ar_aliased_tables) > 0 && $this->dbprefix) + { + $sql .= implode("\n", $this->_filter_table_aliases($this->ar_join)); + } + else + { + $sql .= implode("\n", $this->ar_join); + } + } if (count($this->ar_where) > 0 OR count($this->ar_like) > 0) @@ -1071,8 +1141,18 @@ class CI_DB_active_record extends CI_DB_driver { if (count($this->ar_groupby) > 0) { + $sql .= "\nGROUP BY "; - $sql .= implode(', ', $this->ar_groupby); + + // special consideration for table aliases + if (count($this->ar_aliased_tables) > 0 && $this->dbprefix) + { + $sql .= implode(", ", $this->_filter_table_aliases($this->ar_groupby)); + } + else + { + $sql .= implode(', ', $this->ar_groupby); + } } if (count($this->ar_having) > 0) @@ -1154,6 +1234,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->ar_order = FALSE; $this->ar_orderby = array(); $this->ar_wherein = array(); + $this->ar_aliased_tables = array(); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 848b77685de0346da3f9fb8614e59f7d11552e61 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 31 Dec 2007 16:43:05 +0000 Subject: Fixed a bug in _object_to_array that broke some types of inserts and updates. --- system/database/DB_active_rec.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 4bf3098d9..b9594050e 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1202,7 +1202,9 @@ class CI_DB_active_record extends CI_DB_driver { $array = array(); foreach (get_object_vars($object) as $key => $val) { - if ( ! is_object($val) AND ! is_array($val)) + // There are some built in keys we need to ignore for this conversion + if ( ! is_object($val) && ! is_array($val) && $key != '_parent_name' && $key != '_ci_scaffolding' && $key != '_ci_scaff_table') + { $array[$key] = $val; } -- cgit v1.2.3-24-g4f1b From 67b44edaf539245ca12789f19cca1e7a9437f4f3 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sat, 12 Jan 2008 16:18:02 +0000 Subject: added raw_where() and raw_or_where() into AR --- system/database/DB_active_rec.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index b9594050e..683ded0a7 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -206,6 +206,44 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- + /** + * Raw Where + * + * Generates an unfiltered WHERE portion of the query. + * Separates multiple calls with AND + * + * @access public + * @param string + * @return string + */ + function raw_where($statement) + { + $prefix = (count($this->ar_where) == 0) ? '' : ' AND '; + $this->ar_where[] = $prefix.$statement; + return $statement; + } + + // -------------------------------------------------------------------- + + /** + * Raw OR Where + * + * Generates an unfiltered WHERE portion of the query. + * Separates multiple calls with OR + * + * @access public + * @param string + * @return string + */ + function raw_or_where($statement) + { + $prefix = (count($this->ar_where) == 0) ? '' : ' OR '; + $this->ar_where[] = $prefix.$statement; + return $statement; + } + + // -------------------------------------------------------------------- + /** * Where * -- cgit v1.2.3-24-g4f1b From 39af731090428b2a50bc196cc89931520483569f Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 14 Jan 2008 05:46:49 +0000 Subject: removed raw_where and raw_or_where. They duplicated existing functionality better left elsewhere. --- system/database/DB_active_rec.php | 38 -------------------------------------- 1 file changed, 38 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 683ded0a7..e697cac77 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -203,44 +203,6 @@ class CI_DB_active_record extends CI_DB_driver { { return $this->or_where($key, $value); } - - // -------------------------------------------------------------------- - - /** - * Raw Where - * - * Generates an unfiltered WHERE portion of the query. - * Separates multiple calls with AND - * - * @access public - * @param string - * @return string - */ - function raw_where($statement) - { - $prefix = (count($this->ar_where) == 0) ? '' : ' AND '; - $this->ar_where[] = $prefix.$statement; - return $statement; - } - - // -------------------------------------------------------------------- - - /** - * Raw OR Where - * - * Generates an unfiltered WHERE portion of the query. - * Separates multiple calls with OR - * - * @access public - * @param string - * @return string - */ - function raw_or_where($statement) - { - $prefix = (count($this->ar_where) == 0) ? '' : ' OR '; - $this->ar_where[] = $prefix.$statement; - return $statement; - } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 85c7c61523177bb9307c6ea8439090de4c39c457 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 14 Jan 2008 13:18:36 +0000 Subject: fix a segment db cache bug --- system/database/DB_cache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index f8ea616cd..1e7410708 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -163,7 +163,7 @@ class CI_DB_Cache { { if ($segment_one == '') { - $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(2); + $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); } if ($segment_two == '') -- cgit v1.2.3-24-g4f1b From 6e848ed2afa39b5c99fda7bc061c864bd619269f Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 15 Jan 2008 14:26:23 +0000 Subject: Fixed a bug in the Oracle driver that prevented num_rows from working. --- system/database/DB_driver.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index fc700ec32..a7f03e3e5 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -329,7 +329,6 @@ class CI_DB_driver { $RES = new $driver(); $RES->conn_id = $this->conn_id; $RES->result_id = $this->result_id; - $RES->num_rows = $RES->num_rows(); if ($this->dbdriver == 'oci8') { @@ -337,7 +336,9 @@ class CI_DB_driver { $RES->curs_id = NULL; $RES->limit_used = $this->limit_used; } - + + $RES->num_rows = $RES->num_rows(); + // Is query caching enabled? If so, we'll serialize the // result object and save it to a cache file. if ($this->cache_on == TRUE AND $this->_cache_init()) -- cgit v1.2.3-24-g4f1b From 39b622db9bda38282a32bb45623da63efe685729 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 16 Jan 2008 21:10:09 +0000 Subject: Many new Active Record functions, and another whack of stuff --- system/database/DB.php | 24 +- system/database/DB_active_rec.php | 321 +++++++++++++++++--- system/database/DB_cache.php | 12 +- system/database/DB_driver.php | 186 ++++++++---- system/database/DB_forge.php | 323 +++++++++++++++++++++ system/database/DB_result.php | 50 ++++ system/database/DB_utility.php | 79 +---- system/database/drivers/mssql/mssql_driver.php | 98 ++++++- system/database/drivers/mssql/mssql_forge.php | 219 ++++++++++++++ system/database/drivers/mssql/mssql_utility.php | 77 +++-- system/database/drivers/mysql/mysql_driver.php | 127 +++++++- system/database/drivers/mysql/mysql_forge.php | 223 ++++++++++++++ system/database/drivers/mysql/mysql_utility.php | 79 +++-- system/database/drivers/mysqli/mysqli_driver.php | 121 +++++++- system/database/drivers/mysqli/mysqli_forge.php | 217 ++++++++++++++ system/database/drivers/mysqli/mysqli_utility.php | 77 +++-- system/database/drivers/oci8/oci8_driver.php | 148 ++++++++-- system/database/drivers/oci8/oci8_forge.php | 216 ++++++++++++++ system/database/drivers/oci8/oci8_utility.php | 77 +++-- system/database/drivers/odbc/odbc_driver.php | 137 ++++++++- system/database/drivers/odbc/odbc_forge.php | 236 +++++++++++++++ system/database/drivers/odbc/odbc_result.php | 2 - system/database/drivers/odbc/odbc_utility.php | 101 +++---- system/database/drivers/postgre/postgre_driver.php | 129 +++++++- system/database/drivers/postgre/postgre_forge.php | 219 ++++++++++++++ .../database/drivers/postgre/postgre_utility.php | 77 +++-- system/database/drivers/sqlite/sqlite_driver.php | 129 +++++++- system/database/drivers/sqlite/sqlite_forge.php | 233 +++++++++++++++ system/database/drivers/sqlite/sqlite_result.php | 9 +- system/database/drivers/sqlite/sqlite_utility.php | 103 +++---- 30 files changed, 3463 insertions(+), 586 deletions(-) create mode 100644 system/database/DB_forge.php create mode 100644 system/database/drivers/mssql/mssql_forge.php create mode 100644 system/database/drivers/mysql/mysql_forge.php create mode 100644 system/database/drivers/mysqli/mysqli_forge.php create mode 100644 system/database/drivers/oci8/oci8_forge.php create mode 100644 system/database/drivers/odbc/odbc_forge.php create mode 100644 system/database/drivers/postgre/postgre_forge.php create mode 100644 system/database/drivers/sqlite/sqlite_forge.php (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index 9055a22c4..425c8077b 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -29,14 +29,22 @@ function &DB($params = '', $active_record = FALSE) { include(APPPATH.'config/database'.EXT); - $group = ($params == '') ? $active_group : $params; + if ( ! isset($db) OR count($db) == 0) + { + show_error('No database connection settings were found in the database config file.'); + } + + if ($params != '') + { + $active_group = $params; + } - if ( ! isset($db[$group])) + if ( ! isset($active_group) OR ! isset($db[$active_group])) { - show_error('You have specified an invalid database connection group: '.$group); + show_error('You have specified an invalid database connection group.'); } - $params = $db[$group]; + $params = $db[$active_group]; } // No DB specified yet? Beat them senseless... @@ -78,7 +86,13 @@ function &DB($params = '', $active_record = FALSE) // Instantiate the DB adapter $driver = 'CI_DB_'.$params['dbdriver'].'_driver'; - $DB =& new $driver($params); + $DB =& new $driver($params); + + if ($DB->autoinit == TRUE) + { + $DB->initialize(); + } + return $DB; } diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index e697cac77..3cc65aff4 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -44,7 +44,6 @@ class CI_DB_active_record extends CI_DB_driver { var $ar_wherein = array(); var $ar_aliased_tables = array(); - /** * Select * @@ -54,7 +53,7 @@ class CI_DB_active_record extends CI_DB_driver { * @param string * @return object */ - function select($select = '*') + function select($select = '*', $protect_identifiers = TRUE) { if (is_string($select)) { @@ -64,15 +63,136 @@ class CI_DB_active_record extends CI_DB_driver { foreach ($select as $val) { $val = trim($val); + + if ($val != '*' && $protect_identifiers !== FALSE) + { + $val = $this->_protect_identifiers($val); + } if ($val != '') + { $this->ar_select[] = $val; + } } return $this; } + + // -------------------------------------------------------------------- + + /** + * Select Max + * + * Generates a SELECT MAX(field) portion of a query + * + * @access public + * @param string the field + * @param string an alias + * @return object + */ + function select_max($select = '', $alias='') + { + if (!is_string($select) || $select == '') + { + $this->display_error('db_invalid_query'); + } + + $alias = ($alias != '') ? $alias : $select; + + $sql = 'MAX('.$this->_protect_identifiers(trim($select)).') AS '.$this->_protect_identifiers(trim($alias)); + + $this->ar_select[] = $sql; + + return $this; + + return $this; + } // -------------------------------------------------------------------- + /** + * Select Min + * + * Generates a SELECT MIN(field) portion of a query + * + * @access public + * @param string the field + * @param string an alias + * @return object + */ + function select_min($select = '', $alias='') + { + if (!is_string($select) || $select == '') + { + $this->display_error('db_invalid_query'); + } + + $alias = ($alias != '') ? $alias : $select; + + $sql = 'MIN('.$this->_protect_identifiers(trim($select)).') AS '.$this->_protect_identifiers(trim($alias)); + + $this->ar_select[] = $sql; + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Select Average + * + * Generates a SELECT AVG(field) portion of a query + * + * @access public + * @param string the field + * @param string an alias + * @return object + */ + function select_avg($select = '', $alias='') + { + if (!is_string($select) || $select == '') + { + $this->display_error('db_invalid_query'); + } + + $alias = ($alias != '') ? $alias : $select; + + $sql = 'AVG('.$this->_protect_identifiers(trim($select)).') AS '.$this->_protect_identifiers(trim($alias)); + + $this->ar_select[] = $sql; + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Select Sum + * + * Generates a SELECT SUM(field) portion of a query + * + * @access public + * @param string the field + * @param string an alias + * @return object + */ + function select_sum($select = '', $alias='') + { + if (!is_string($select) || $select == '') + { + $this->display_error('db_invalid_query'); + } + + $alias = ($alias != '') ? $alias : $select; + + $sql = 'SUM('.$this->_protect_identifiers(trim($select)).') AS '.$this->_protect_identifiers(trim($alias)); + + $this->ar_select[] = $sql; + + return $this; + } + + // -------------------------------------------------------------------- + /** * DISTINCT * @@ -103,8 +223,7 @@ class CI_DB_active_record extends CI_DB_driver { { foreach ((array)$from as $val) { - $this->_track_aliases($val); - $this->ar_from[] = $this->dbprefix.$val; + $this->ar_from[] = $this->_protect_identifiers($this->_track_aliases($val)); } return $this; @@ -142,17 +261,16 @@ class CI_DB_active_record extends CI_DB_driver { // If a DB prefix is used we might need to add it to the column names if ($this->dbprefix) { + $this->_track_aliases($table); + // First we remove any existing prefixes in the condition to avoid duplicates $cond = preg_replace('|('.$this->dbprefix.')([\w\.]+)([\W\s]+)|', "$2$3", $cond); // Next we add the prefixes to the condition $cond = preg_replace('|([\w\.]+)([\W\s]+)(.+)|', $this->dbprefix . "$1$2" . $this->dbprefix . "$3", $cond); - - $this->_track_aliases($table); - } - $this->ar_join[] = $type.'JOIN '.$this->dbprefix.$table.' ON '.$cond; + $this->ar_join[] = $type.'JOIN '.$this->_protect_identifiers($this->dbprefix.$table, TRUE).' ON '.$cond; return $this; } @@ -169,9 +287,9 @@ class CI_DB_active_record extends CI_DB_driver { * @param mixed * @return object */ - function where($key, $value = NULL) + function where($key, $value = NULL, $escape = TRUE) { - return $this->_where($key, $value, 'AND '); + return $this->_where($key, $value, 'AND ', $escape); } // -------------------------------------------------------------------- @@ -187,9 +305,9 @@ class CI_DB_active_record extends CI_DB_driver { * @param mixed * @return object */ - function or_where($key, $value = NULL) + function or_where($key, $value = NULL, $escape = TRUE) { - return $this->_where($key, $value, 'OR '); + return $this->_where($key, $value, 'OR ', $escape); } // -------------------------------------------------------------------- @@ -199,9 +317,9 @@ class CI_DB_active_record extends CI_DB_driver { * this function is here for backwards compatibility, as * orwhere() has been deprecated */ - function orwhere($key, $value = NULL) + function orwhere($key, $value = NULL, $escape = TRUE) { - return $this->or_where($key, $value); + return $this->or_where($key, $value, $escape); } // -------------------------------------------------------------------- @@ -217,7 +335,7 @@ class CI_DB_active_record extends CI_DB_driver { * @param string * @return object */ - function _where($key, $value = NULL, $type = 'AND ') + function _where($key, $value = NULL, $type = 'AND ', $escape = TRUE) { if ( ! is_array($key)) { @@ -226,10 +344,9 @@ class CI_DB_active_record extends CI_DB_driver { foreach ($key as $k => $v) { - $prefix = (count($this->ar_where) == 0) ? '' : $type; - if (is_null($key[$k])) + if ( ! $this->_has_operator($k) && is_null($key[$k])) { // value appears not to have been set, assign the test to IS NULL $k .= ' IS NULL'; @@ -237,12 +354,25 @@ class CI_DB_active_record extends CI_DB_driver { if ( ! is_null($v)) { - + + if ($escape === TRUE) + { + // exception for "field<=" keys + if ($this->_has_operator($k)) + { + $k = preg_replace("/([A-Za-z_0-9]+)/", $this->_protect_identifiers('$1'), $k); + } + else + { + $k = $this->_protect_identifiers($k); + } + } + if ( ! $this->_has_operator($k)) { $k .= ' ='; } - + $v = ' '.$this->escape($v); } @@ -358,7 +488,7 @@ class CI_DB_active_record extends CI_DB_driver { $prefix = (count($this->ar_where) == 0) ? '' : $type; - $this->ar_where[] = $prefix.$key.$not . " IN (" . implode(", ", $this->ar_wherein) . ") "; + $this->ar_where[] = $prefix . $this->_protect_identifiers($key) . $not . " IN (" . implode(", ", $this->ar_wherein) . ") "; return $this; } @@ -470,6 +600,8 @@ class CI_DB_active_record extends CI_DB_driver { foreach ($field as $k => $v) { + $k = $this->_protect_identifiers($k); + $prefix = (count($this->ar_like) == 0) ? '' : $type; $v = $this->escape_str($v); @@ -511,7 +643,7 @@ class CI_DB_active_record extends CI_DB_driver { $val = trim($val); if ($val != '') - $this->ar_groupby[] = $this->dbprefix.$val; + $this->ar_groupby[] = $this->_protect_identifiers($val); } return $this; } @@ -617,7 +749,7 @@ class CI_DB_active_record extends CI_DB_driver { $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' '.$direction : ' ASC'; } - $this->ar_orderby[] = $orderby.$direction; + $this->ar_orderby[] = $this->_protect_identifiers($orderby).$direction; return $this; } @@ -676,9 +808,10 @@ class CI_DB_active_record extends CI_DB_driver { * @access public * @param mixed * @param string + * @param boolean * @return object */ - function set($key, $value = '') + function set($key, $value = '', $escape = TRUE) { $key = $this->_object_to_array($key); @@ -689,7 +822,15 @@ class CI_DB_active_record extends CI_DB_driver { foreach ($key as $k => $v) { - $this->ar_set[$k] = $this->escape($v); + if ($escape === FALSE) + { + $this->ar_set[$this->_protect_identifiers($k)] = $v; + } + else + { + $this->ar_set[$this->_protect_identifiers($k)] = $this->escape($v); + } + } return $this; @@ -729,8 +870,6 @@ class CI_DB_active_record extends CI_DB_driver { return $result; } - // -------------------------------------------------------------------- - /** * "Count All Results" query * @@ -749,7 +888,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->from($table); } - $sql = $this->_compile_select($this->_count_string); + $sql = $this->_compile_select($this->_count_string . $this->_protect_identifiers('numrows')); $query = $this->query($sql); $this->_reset_select(); @@ -854,8 +993,8 @@ class CI_DB_active_record extends CI_DB_driver { $table = $this->ar_from[0]; } - - $sql = $this->_insert($this->dbprefix.$table, array_keys($this->ar_set), array_values($this->ar_set)); + + $sql = $this->_insert($this->_protect_identifiers($this->dbprefix.$table), array_keys($this->ar_set), array_values($this->ar_set)); $this->_reset_write(); return $this->query($sql); @@ -914,9 +1053,89 @@ class CI_DB_active_record extends CI_DB_driver { $this->limit($limit); } - $sql = $this->_update($this->dbprefix.$table, $this->ar_set, $this->ar_where, $this->ar_limit); + $sql = $this->_update($this->_protect_identifiers($this->dbprefix.$table), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit); + + $this->_reset_write(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Empty Table + * + * Compiles a delete string and runs "DELETE FROM table" + * + * @access public + * @param string the table to empty + * @return object + */ + function empty_table($table = '') + { + if ($table == '') + { + if ( ! isset($this->ar_from[0])) + { + if ($this->db_debug) + { + return $this->display_error('db_must_set_table'); + } + return FALSE; + } + + $table = $this->ar_from[0]; + } + else + { + $table = $this->_protect_identifiers($this->dbprefix.$table); + } + + + $sql = $this->_delete($table); + + $this->_reset_write(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Truncate + * + * Compiles a truncate string and runs the query + * If the database does not support the truncate() command + * This function maps to "DELETE FROM table" + * + * @access public + * @param string the table to truncate + * @return object + */ + function truncate($table = '') + { + if ($table == '') + { + if ( ! isset($this->ar_from[0])) + { + if ($this->db_debug) + { + return $this->display_error('db_must_set_table'); + } + return FALSE; + } + + $table = $this->ar_from[0]; + } + else + { + $table = $this->_protect_identifiers($this->dbprefix.$table); + } + + + $sql = $this->_truncate($table); + $this->_reset_write(); + return $this->query($sql); } @@ -946,19 +1165,23 @@ class CI_DB_active_record extends CI_DB_driver { } return FALSE; } - + $table = $this->ar_from[0]; } - - if (is_array($table)) + elseif (is_array($table)) { foreach($table as $single_table) { - $this->delete($this->dbprefix.$single_table, $where, $limit, FALSE); + $this->delete($single_table, $where, $limit, FALSE); } + $this->_reset_write(); return; } + else + { + $table = $this->_protect_identifiers($this->dbprefix.$table); + } if ($where != '') { @@ -970,21 +1193,23 @@ class CI_DB_active_record extends CI_DB_driver { $this->limit($limit); } - if (count($this->ar_where) == 0) + if (count($this->ar_where) == 0 && count($this->ar_like) == 0) { if ($this->db_debug) { return $this->display_error('db_del_must_use_where'); } + return FALSE; } - $sql = $this->_delete($this->dbprefix.$table, $this->ar_where, $this->ar_limit); + $sql = $this->_delete($table, $this->ar_where, $this->ar_like, $this->ar_limit); if ($reset_data) { $this->_reset_write(); } + return $this->query($sql); } @@ -1038,9 +1263,9 @@ class CI_DB_active_record extends CI_DB_driver { if (strpos($table, " ") !== FALSE) { // if the alias is written with the AS keyowrd, get it out - $table = preg_replace('/AS/i', '', $table); + $table = preg_replace('/ AS /i', ' ', $table); - $this->ar_aliased_tables[] = trim(strrchr($table, " ") . '.'); + $this->ar_aliased_tables[] = trim(strrchr($table, " ")); } return $this->dbprefix.$table; @@ -1059,23 +1284,20 @@ class CI_DB_active_record extends CI_DB_driver { */ function _filter_table_aliases($statements) { - $filter_tables_with_aliases = array(); + $statements_without_aliases = array(); - foreach ($statements as $statement) + foreach ($statements as $k => $v) { - $tables_with_dbprefix = array(); - - foreach ($this->ar_aliased_tables as $k => $v) + foreach ($this->ar_aliased_tables as $table) { - $tables_with_dbprefix[$k] = '/'.$this->dbprefix.str_replace('.', '', $v).'\./'; + $statement = preg_replace('/(\w+\.\w+)/', $this->_protect_identifiers('$0'), $v); // makes `table.field` + $statement = str_replace(array($this->dbprefix.$table, '.'), array($table, $this->_protect_identifiers('.')), $statement); } - $statement = preg_replace($tables_with_dbprefix, $this->ar_aliased_tables, $statement); - - $filter_tables_with_aliases[] = $statement; + $statements[$k] = $statement; } - return $filter_tables_with_aliases; + return $statements; } // -------------------------------------------------------------------- @@ -1254,7 +1476,10 @@ class CI_DB_active_record extends CI_DB_driver { $this->ar_set = array(); $this->ar_from = array(); $this->ar_where = array(); + $this->ar_like = array(); $this->ar_limit = FALSE; + $this->ar_order = FALSE; + $this->ar_orderby = array(); } } diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 1e7410708..77b951500 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -63,14 +63,12 @@ class CI_DB_Cache { // Add a trailing slash to the path if needed $path = preg_replace("/(.+?)\/*$/", "\\1/", $path); - - if ( ! is_dir($path) OR ! is_writable($path)) + + // Load the file helper + $this->CI->load->helper('file'); + + if ( ! is_dir($path) OR ! is_really_writable($path)) { - if ($this->CI->db->db_debug) - { - return $this->CI->db->display_error('db_invalid_cache_path'); - } - // If the path is wrong we'll turn off caching return $this->CI->db->cache_off(); } diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index a7f03e3e5..c2fa70a72 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -36,6 +36,8 @@ class CI_DB_driver { var $database; var $dbdriver = 'mysql'; var $dbprefix = ''; + var $autoinit = TRUE; // Whether to automatically initialize the DB + var $swap_pre = ''; var $port = ''; var $pconnect = FALSE; var $conn_id = FALSE; @@ -75,42 +77,12 @@ class CI_DB_driver { * @param mixed. Can be an array or a DSN string */ function CI_DB_driver($params) - { - $this->initialize($params); - log_message('debug', 'Database Driver Class Initialized'); - } - - // -------------------------------------------------------------------- - - /** - * Initialize Database Settings - * - * @access private Called by the constructor - * @param mixed - * @return void - */ - function initialize($params = '') { if (is_array($params)) { - $defaults = array( - 'hostname' => '', - 'username' => '', - 'password' => '', - 'database' => '', - 'conn_id' => FALSE, - 'dbdriver' => 'mysql', - 'dbprefix' => '', - 'port' => '', - 'pconnect' => FALSE, - 'db_debug' => FALSE, - 'cachedir' => '', - 'cache_on' => FALSE - ); - - foreach ($defaults as $key => $val) + foreach ($params as $key => $val) { - $this->$key = ( ! isset($params[$key])) ? $val : $params[$key]; + $this->$key = $val; } } elseif (strpos($params, '://')) @@ -131,7 +103,21 @@ class CI_DB_driver { $this->password = ( ! isset($dsn['pass'])) ? '' : rawurldecode($dsn['pass']); $this->database = ( ! isset($dsn['path'])) ? '' : rawurldecode(substr($dsn['path'], 1)); } - + + log_message('debug', 'Database Driver Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Initialize Database Settings + * + * @access private Called by the constructor + * @param mixed + * @return void + */ + function initialize($create_db = FALSE) + { // If an existing DB connection resource is supplied // there is no need to connect and select the database if (is_resource($this->conn_id)) @@ -159,6 +145,46 @@ class CI_DB_driver { { if ( ! $this->db_select()) { + // Should we attempt to create the database? + if ($create_db == TRUE) + { + // Load the DB utility class + $CI =& get_instance(); + $CI->load->dbutil(); + + // Create the DB + if ( ! $CI->dbutil->create_database($this->database)) + { + log_message('error', 'Unable to create database: '.$this->database); + + if ($this->db_debug) + { + $this->display_error('db_unable_to_create', $this->database); + } + return FALSE; + } + else + { + // In the event the DB was created we need to select it + if ($this->db_select()) + { + if (! $this->db_set_charset($this->char_set, $this->dbcollat)) + { + log_message('error', 'Unable to set database connection charset: '.$this->char_set); + + if ($this->db_debug) + { + $this->display_error('db_unable_to_set_charset', $this->char_set); + } + + return FALSE; + } + + return TRUE; + } + } + } + log_message('error', 'Unable to select database: '.$this->database); if ($this->db_debug) @@ -167,6 +193,18 @@ class CI_DB_driver { } return FALSE; } + + if (! $this->db_set_charset($this->char_set, $this->dbcollat)) + { + log_message('error', 'Unable to set database connection charset: '.$this->char_set); + + if ($this->db_debug) + { + $this->display_error('db_unable_to_set_charset', $this->char_set); + } + + return FALSE; + } } return TRUE; @@ -211,8 +249,7 @@ class CI_DB_driver { } $query = $this->query($sql); - $row = $query->row(); - return $row->ver; + return $query->row('ver'); } // -------------------------------------------------------------------- @@ -242,6 +279,12 @@ class CI_DB_driver { } return FALSE; } + + // Verify table prefix and replace if necessary + if ( ($this->dbprefix != '' AND $this->swap_pre != '') AND ($this->dbprefix != $this->swap_pre) ) + { + $sql = preg_replace("/(\W)".$this->swap_pre."(\S+?)/", "\\1".$this->dbprefix."\\2", $sql); + } // Is query caching enabled? If the query is a "read type" // we will load the caching class and return the previously @@ -269,7 +312,7 @@ class CI_DB_driver { { $this->queries[] = $sql; } - + // Start the Query Timer $time_start = list($sm, $ss) = explode(' ', microtime()); @@ -291,7 +334,7 @@ class CI_DB_driver { ); } - return FALSE; + return FALSE; } // Stop and aggregate the query time results @@ -329,6 +372,7 @@ class CI_DB_driver { $RES = new $driver(); $RES->conn_id = $this->conn_id; $RES->result_id = $this->result_id; + $RES->num_rows = $RES->num_rows(); if ($this->dbdriver == 'oci8') { @@ -336,9 +380,7 @@ class CI_DB_driver { $RES->curs_id = NULL; $RES->limit_used = $this->limit_used; } - - $RES->num_rows = $RES->num_rows(); - + // Is query caching enabled? If so, we'll serialize the // result object and save it to a cache file. if ($this->cache_on == TRUE AND $this->_cache_init()) @@ -592,6 +634,23 @@ class CI_DB_driver { // -------------------------------------------------------------------- + /** + * Protect Identifiers + * + * This function adds backticks if appropriate based on db type + * + * @access private + * @param mixed the item to escape + * @param boolean only affect the first word + * @return mixed the item with backticks + */ + function protect_identifiers($item, $first_word_only = FALSE) + { + return $this->_protect_identifiers($item, $first_word_only = FALSE); + } + + // -------------------------------------------------------------------- + /** * "Smart" Escape String * @@ -649,7 +708,7 @@ class CI_DB_driver { * @access public * @return array */ - function list_tables() + function list_tables($constrain_by_prefix = FALSE) { // Is there a cached result? if (isset($this->data_cache['table_names'])) @@ -657,7 +716,7 @@ class CI_DB_driver { return $this->data_cache['table_names']; } - if (FALSE === ($sql = $this->_list_tables())) + if (FALSE === ($sql = $this->_list_tables($constrain_by_prefix))) { if ($this->db_debug) { @@ -697,7 +756,7 @@ class CI_DB_driver { */ function table_exists($table_name) { - return ( ! in_array($this->dbprefix.$table_name, $this->list_tables())) ? FALSE : TRUE; + return ( ! in_array($this->prep_tablename($table_name), $this->list_tables())) ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -726,7 +785,7 @@ class CI_DB_driver { return FALSE; } - if (FALSE === ($sql = $this->_list_columns($this->dbprefix.$table))) + if (FALSE === ($sql = $this->_list_columns($this->prep_tablename($table)))) { if ($this->db_debug) { @@ -798,7 +857,7 @@ class CI_DB_driver { return FALSE; } - $query = $this->query($this->_field_data($this->dbprefix.$table)); + $query = $this->query($this->_field_data($this->prep_tablename($table))); return $query->field_data(); } @@ -822,9 +881,10 @@ class CI_DB_driver { $fields[] = $key; $values[] = $this->escape($val); } - - return $this->_insert($this->dbprefix.$table, $fields, $values); - } + + + return $this->_insert($this->prep_tablename($table), $fields, $values); + } // -------------------------------------------------------------------- @@ -859,7 +919,7 @@ class CI_DB_driver { { $prefix = (count($dest) == 0) ? '' : ' AND '; - if ($val != '') + if ($val !== '') { if ( ! $this->_has_operator($key)) { @@ -873,11 +933,34 @@ class CI_DB_driver { } } - return $this->_update($this->dbprefix.$table, $fields, $dest); + return $this->_update($this->prep_tablename($table), $fields, $dest); } // -------------------------------------------------------------------- + /** + * Prep the table name - simply adds the table prefix if needed + * + * @access public + * @param string the table name + * @return string + */ + function prep_tablename($table = '') + { + // Do we need to add the table prefix? + if ($this->dbprefix != '') + { + if (substr($table, 0, strlen($this->dbprefix)) != $this->dbprefix) + { + $table = $this->dbprefix.$table; + } + } + + return $table; + } + + // -------------------------------------------------------------------- + /** * Enables a native PHP function to be run, using a platform agnostic wrapper. * @@ -1013,7 +1096,6 @@ class CI_DB_driver { return TRUE; } - // -------------------------------------------------------------------- /** @@ -1044,6 +1126,7 @@ class CI_DB_driver { */ function display_error($error = '', $swap = '', $native = FALSE) { +// $LANG = new CI_Lang(); $LANG = new CI_Language(); $LANG->load('db'); @@ -1060,6 +1143,7 @@ class CI_DB_driver { if ( ! class_exists('CI_Exceptions')) { +// include(BASEPATH.'core/Exceptions'.EXT); include(BASEPATH.'libraries/Exceptions'.EXT); } diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php new file mode 100644 index 000000000..d02589457 --- /dev/null +++ b/system/database/DB_forge.php @@ -0,0 +1,323 @@ +db + $CI =& get_instance(); + $this->db =& $CI->db; + + log_message('debug', "Database Forge Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Create database + * + * @access public + * @param string the database name + * @return bool + */ + function create_database($db_name) + { + $sql = $this->_create_database($db_name); + + if (is_bool($sql)) + { + return $sql; + } + + return $this->db->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access public + * @param string the database name + * @return bool + */ + function drop_database($db_name) + { + $sql = $this->_drop_database($db_name); + + if (is_bool($sql)) + { + return $sql; + } + + return $this->db->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Add Key + * + * @access public + * @param string key + * @param string type + * @return void + */ + function add_key($key = '', $primary = FALSE) + { + if ($key == '') + { + show_error('Key information is required for that operation.'); + } + + if ($primary === TRUE) + { + $this->primary_keys[] = $key; + } + else + { + $this->keys[] = $key; + } + } + + // -------------------------------------------------------------------- + + /** + * Add Field + * + * @access public + * @param string collation + * @return void + */ + function add_field($field = '') + { + if ($field == '') + { + show_error('Field information is required.'); + } + + if (is_string($field)) + { + if ($field == 'id') + { + $this->fields[] = array('id' => array( + 'type' => 'INT', + 'constraint' => 9, + 'auto_increment' => TRUE + ) + ); + $this->add_key('id', TRUE); + } + else + { + if (strpos($field, ' ') === FALSE) + { + show_error('Field information is required for that operation.'); + } + + $this->fields[] = $field; + } + } + + if (is_array($field)) + { + $this->fields = array_merge($this->fields, $field); + } + + } + + // -------------------------------------------------------------------- + + /** + * Create Table + * + * @access public + * @param string the table name + * @return bool + */ + function create_table($table = '', $if_not_exists = FALSE) + { + if ($table == '') + { + show_error('A table name is required for that operation.'); + } + + if (count($this->fields) == 0) + { + show_error('Field information is required.'); + } + + $sql = $this->_create_table($table, $this->fields, $this->primary_keys, $this->keys, $if_not_exists); + + $this->_reset(); + return $this->db->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * @access public + * @param string the table name + * @return bool + */ + function drop_table($table_name) + { + $sql = $this->_drop_table($table_name); + + if (is_bool($sql)) + { + return $sql; + } + + return $this->db->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Column Add + * + * @access public + * @param string the table name + * @param string the column name + * @param string the column definition + * @return bool + */ + function add_column($table = '', $field = array(), $after_field = '') + { + if ($table == '') + { + show_error('A table name is required for that operation.'); + } + + // add field info into field array, but we can only do one at a time + // so only grab the first field in the event there are more then one + $this->add_field(array_slice($field, 0, 1)); + + if (count($this->fields) == 0) + { + show_error('Field information is required.'); + } + + $sql = $this->_alter_table('ADD', $table, $this->fields, $after_field); + + $this->_reset(); + return $this->db->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Column Drop + * + * @access public + * @param string the table name + * @param string the column name + * @return bool + */ + function drop_column($table = '', $column_name = '') + { + + if ($table == '') + { + show_error('A table name is required for that operation.'); + } + + if ($column_name == '') + { + show_error('A column name is required for that operation.'); + } + + $sql = $this->_alter_table('DROP', $table, $column_name); + + return $this->db->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Column Modify + * + * @access public + * @param string the table name + * @param string the column name + * @param string the column definition + * @return bool + */ + function modify_column($table = '', $field = array()) + { + + if ($table == '') + { + show_error('A table name is required for that operation.'); + } + + // add field info into field array, but we can only do one at a time + // so only grab the first field in the event there are more then one + $this->add_field(array_slice($field, 0, 1)); + + if (count($this->fields) == 0) + { + show_error('Field information is required.'); + } + + $sql = $this->_alter_table('CHANGE', $table, $this->fields); + + $this->_reset(); + return $this->db->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Reset + * + * Resets table creation vars + * + * @access private + * @return void + */ + function _reset() + { + $this->fields = array(); + $this->keys = array(); + $this->primary_keys = array(); + } + +} +?> \ No newline at end of file diff --git a/system/database/DB_result.php b/system/database/DB_result.php index b438ad1d8..36eddd840 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -34,6 +34,7 @@ class CI_DB_result { var $result_object = array(); var $current_row = 0; var $num_rows = 0; + var $row_data = NULL; /** @@ -118,16 +119,65 @@ class CI_DB_result { * Query result. Acts as a wrapper function for the following functions. * * @access public + * @param string * @param string can be "object" or "array" * @return mixed either a result object or array */ function row($n = 0, $type = 'object') { + if ( ! is_numeric($n)) + { + // We cache the row data for subsequent uses + if ( ! is_array($this->row_data)) + { + $this->row_data = $this->row_array(0); + } + + if (isset($this->row_data[$n])) + { + return $this->row_data[$n]; + } + // reset the $n variable if the result was not achieved + $n = 0; + } + return ($type == 'object') ? $this->row_object($n) : $this->row_array($n); } // -------------------------------------------------------------------- + /** + * Assigns an item into a particular column slot + * + * @access public + * @return object + */ + function set_row($key, $value = NULL) + { + // We cache the row data for subsequent uses + if ( ! is_array($this->row_data)) + { + $this->row_data = $this->row_array(0); + } + + if (is_array($key)) + { + foreach ($key as $k => $v) + { + $this->row_data[$k] = $v; + } + + return; + } + + if ($key != '' AND ! is_null($value)) + { + $this->row_data[$key] = $value; + } + } + + // -------------------------------------------------------------------- + /** * Returns a single result row - object version * diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index e9caf9f3e..372c88f1f 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author Rick Ellis - * @copyright Copyright (c) 2006, pMachine, Inc. + * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 @@ -22,10 +22,10 @@ * @author Rick Ellis * @link http://www.codeigniter.com/user_guide/database/ */ -class CI_DB_utility { +class CI_DB_utility extends CI_DB_forge { var $db; - var $data_cache = array(); + var $data_cache = array(); /** * Constructor @@ -44,48 +44,6 @@ class CI_DB_utility { // -------------------------------------------------------------------- - /** - * Create database - * - * @access public - * @param string the database name - * @return bool - */ - function create_database($db_name) - { - $sql = $this->_create_database($db_name); - - if (is_bool($sql)) - { - return $sql; - } - - return $this->db->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access public - * @param string the database name - * @return bool - */ - function drop_database($db_name) - { - $sql = $this->_drop_database($db_name); - - if (is_bool($sql)) - { - return $sql; - } - - return $this->db->query($sql); - } - - // -------------------------------------------------------------------- - /** * List databases * @@ -129,7 +87,7 @@ class CI_DB_utility { if (is_bool($sql)) { - return $sql; + show_error('db_must_use_set'); } $query = $this->db->query($sql); @@ -180,13 +138,12 @@ class CI_DB_utility { // -------------------------------------------------------------------- /** - * Optimize Table + * Repair Table * * @access public * @param string the table name * @return bool */ - function repair_table($table_name) { $sql = $this->_repair_table($table_name); @@ -203,28 +160,7 @@ class CI_DB_utility { $res = $query->result_array(); return current($res); } - - // -------------------------------------------------------------------- - - /** - * Drop Table - * - * @access public - * @param string the table name - * @return bool - */ - function drop_table($table_name) - { - $sql = $this->_drop_table($table_name); - - if (is_bool($sql)) - { - return $sql; - } - return $this->db->query($sql); - } - // -------------------------------------------------------------------- /** @@ -445,11 +381,6 @@ class CI_DB_utility { } - - - - - } ?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 044fb3ced..06a508e71 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -35,7 +35,8 @@ class CI_DB_mssql_driver extends CI_DB { * database engines, so this string appears in each driver and is * used for the count_all() and count_all_results() functions. */ - var $_count_string = "SELECT COUNT(*) AS numrows "; + var $_count_string = "SELECT COUNT(*) AS "; + var $_random_keyword = ' ASC'; // not currently supported /** * Non-persistent database connection @@ -76,6 +77,22 @@ class CI_DB_mssql_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Set client character set + * + * @access public + * @param string + * @param string + * @return resource + */ + function db_set_charset($charset, $collation) + { + // TODO - add support if needed + return TRUE; + } + + // -------------------------------------------------------------------- + /** * Execute the query * @@ -297,11 +314,21 @@ class CI_DB_mssql_driver extends CI_DB { * Generates a platform-specific query string so that the table names can be fetched * * @access private + * @param boolean * @return string */ - function _list_tables() + function _list_tables($prefix_limit = FALSE) { - return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; + $sql = "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; + + // for future compatibility + if ($prefix_limit !== FALSE AND $this->dbprefix != '') + { + //$sql .= " LIKE '".$this->dbprefix."%'"; + return FALSE; // not currently supported + } + + return $sql; } // -------------------------------------------------------------------- @@ -392,6 +419,25 @@ class CI_DB_mssql_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Protect Identifiers + * + * This function adds backticks if appropriate based on db type + * + * @access private + * @param mixed the item(s) + * @param boolean should spaces be backticked + * @param boolean only affect the first word + * @return mixed the item with backticks + */ + function _protect_identifiers($item, $affect_spaces = TRUE, $first_word_only = FALSE) + { + // MSSQL doesn't use backticks + return $item; + } + + // -------------------------------------------------------------------- + /** * Insert statement * @@ -419,9 +465,11 @@ class CI_DB_mssql_driver extends CI_DB { * @param string the table name * @param array the update data * @param array the where clause + * @param array the orderby clause + * @param array the limit clause * @return string */ - function _update($table, $values, $where, $limit = FALSE) + function _update($table, $values, $where, $orderby = array(), $limit = FALSE) { foreach($values as $key => $val) { @@ -429,8 +477,29 @@ class CI_DB_mssql_driver extends CI_DB { } $limit = (!$limit) ? '' : ' LIMIT '.$limit; + + $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$limit; + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$orderby.$limit; + } + + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * If the database does not support the truncate() command + * This function maps to "DELETE FROM table" + * + * @access public + * @param string the table name + * @return string + */ + function _truncate($table) + { + return "TRUNCATE ".$this->_escape_table($table); } // -------------------------------------------------------------------- @@ -443,13 +512,28 @@ class CI_DB_mssql_driver extends CI_DB { * @access public * @param string the table name * @param array the where clause + * @param string the limit clause * @return string */ - function _delete($table, $where, $limit = FALSE) + function _delete($table, $where = array(), $like = array(), $limit = FALSE) { + $conditions = ''; + + if (count($where) > 0 || count($like) > 0) + { + $conditions = "\nWHERE "; + $conditions .= implode("\n", $this->ar_where); + + if (count($where) > 0 && count($like) > 0) + { + $conditions .= " AND "; + } + $conditions .= implode("\n", $like); + } + $limit = (!$limit) ? '' : ' LIMIT '.$limit; - return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where).$limit; + return "DELETE FROM ".$table.$conditions.$limit; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php new file mode 100644 index 000000000..63a9d8396 --- /dev/null +++ b/system/database/drivers/mssql/mssql_forge.php @@ -0,0 +1,219 @@ +db->_escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * Create Table + * + * @access private + * @param string the table name + * @param array the fields + * @param mixed primary key(s) + * @param mixed key(s) + * @param boolean should 'IF NOT EXISTS' be added to the SQL + * @return bool + */ + 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_table($table)." ("; + $current_field_count = 0; + + foreach ($fields as $field=>$attributes) + { + // Numeric field names aren't allowed in databases, so if the key is + // numeric, we know it was assigned by PHP and the developer manually + // entered the field information, so we'll simply add it to the list + if (is_numeric($field)) + { + $sql .= "\n\t$attributes"; + } + else + { + $attributes = array_change_key_case($attributes, CASE_UPPER); + + $sql .= "\n\t".$this->db->_protect_identifiers($field); + + $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) && $attributes['NULL'] === TRUE) + { + $sql .= ' NULL'; + } + else + { + $sql .= ' 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 .= ','; + } + } + + if (count($primary_keys) > 0) + { + $primary_keys = $this->db->_protect_identifiers($primary_keys); + $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; + } + + if (is_array($keys) && count($keys) > 0) + { + $keys = $this->db->_protect_identifiers($keys); + foreach ($keys as $key) + { + $sql .= ",\n\tFOREIGN KEY ($key)"; + } + } + + $sql .= "\n)"; + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Alter table query + * + * Generates a platform-specific query so that a table can be altered + * Called by add_column(), drop_column(), and column_alter(), + * + * @access private + * @param string the ALTER type (ADD, DROP, CHANGE) + * @param string the column name + * @param string the table name + * @param string the column definition + * @param string the default value + * @param boolean should 'NOT NULL' be added + * @param string the field after which we should add the new field + * @return object + */ + function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') + { + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name); + + // DROP has everything it needs now. + if ($alter_type == 'DROP') + { + return $sql; + } + + $sql .= " $column_definition"; + + if ($default_value != '') + { + $sql .= " DEFAULT \"$default_value\""; + } + + if ($null === NULL) + { + $sql .= ' NULL'; + } + else + { + $sql .= ' NOT NULL'; + } + + if ($after_field != '') + { + $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); + } + + return $sql; + + } + +} +?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index 3a102212b..b020a2a6e 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -24,48 +24,6 @@ */ class CI_DB_mssql_utility extends CI_DB_utility { - - /** - * Create database - * - * @access private - * @param string the database name - * @return bool - */ - function _create_database($name) - { - return "CREATE DATABASE ".$name; - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access private - * @param string the database name - * @return bool - */ - function _drop_database($name) - { - return "DROP DATABASE ".$name; - } - - // -------------------------------------------------------------------- - - /** - * Drop Table - * - * @access private - * @return bool - */ - function _drop_table($table) - { - return "DROP TABLE ".$this->db->_escape_table($table); - } - - // -------------------------------------------------------------------- - /** * List databases * @@ -94,7 +52,7 @@ class CI_DB_mssql_utility extends CI_DB_utility { } // -------------------------------------------------------------------- - + /** * Repair table query * @@ -124,6 +82,39 @@ class CI_DB_mssql_utility extends CI_DB_utility { return $this->db->display_error('db_unsuported_feature'); } + /** + * + * The functions below have been deprecated as of 1.6, and are only here for backwards + * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation + * is STRONGLY discouraged in favour if using dbforge. + * + */ + + /** + * Create database + * + * @access private + * @param string the database name + * @return bool + */ + function _create_database($name) + { + return "CREATE DATABASE ".$name; + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access private + * @param string the database name + * @return bool + */ + function _drop_database($name) + { + return "DROP DATABASE ".$name; + } } diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index cd86ebf52..a164552ed 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -42,7 +42,7 @@ class CI_DB_mysql_driver extends CI_DB { * database engines, so this string appears in each driver and is * used for the count_all() and count_all_results() functions. */ - var $_count_string = "SELECT COUNT(*) AS numrows "; + var $_count_string = 'SELECT COUNT(*) AS '; var $_random_keyword = ' RAND()'; // database specific random keyword /** @@ -84,6 +84,21 @@ class CI_DB_mysql_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Set client character set + * + * @access public + * @param string + * @param string + * @return resource + */ + function db_set_charset($charset, $collation) + { + return @mysql_query("SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'", $this->conn_id); + } + + // -------------------------------------------------------------------- + /** * Version number query string * @@ -314,17 +329,18 @@ class CI_DB_mysql_driver extends CI_DB { * Generates a platform-specific query string so that the table names can be fetched * * @access private + * @param boolean * @return string */ function _list_tables($prefix_limit = FALSE) { $sql = "SHOW TABLES FROM `".$this->database."`"; - - if ($prefix_limit !== FALSE AND $this->_stdprefix != '') + + if ($prefix_limit !== FALSE AND $this->dbprefix != '') { - $sql .= " LIKE '".$this->_stdprefix."%'"; + $sql .= " LIKE '".$this->dbprefix."%'"; } - + return $sql; } @@ -400,14 +416,66 @@ class CI_DB_mysql_driver extends CI_DB { */ function _escape_table($table) { - if (stristr($table, '.')) + if (strpos($table, '.') !== FALSE) { - $table = preg_replace("/\./", "`.`", $table); + $table = str_replace('.', '`.`', $table); } return $table; } + + // -------------------------------------------------------------------- + + /** + * Protect Identifiers + * + * This function adds backticks if appropriate based on db type + * + * @access private + * @param mixed the item to escape + * @param boolean only affect the first word + * @return mixed the item with backticks + */ + function _protect_identifiers($item, $first_word_only = FALSE) + { + if (is_array($item)) + { + $escaped_array = array(); + + foreach($item as $k=>$v) + { + $escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v, $first_word_only); + } + + return $escaped_array; + } + + // This function may get "item1 item2" as a string, and so + // we may need "`item1` `item2`" and not "`item1 item2`" + if (strpos($item, ' ') !== FALSE) + { + // This function may get "field >= 1", and need it to return "`field` >= 1" + if ($first_word_only === TRUE) + { + return '`'.preg_replace('/ /', '` ', $item, 1); + } + + $item = preg_replace('/(^|\s|\()([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item); + } + + $exceptions = array('AS', '/', '-', '%', '+', '*'); + + foreach ($exceptions as $exception) + { + if (stristr($item, " `{$exception}` ") !== FALSE) + { + $item = preg_replace('/ `('.preg_quote($exception).')` /i', ' $1 ', $item); + } + } + return $item; + } + // -------------------------------------------------------------------- /** @@ -437,9 +505,11 @@ class CI_DB_mysql_driver extends CI_DB { * @param string the table name * @param array the update data * @param array the where clause + * @param array the orderby clause + * @param array the limit clause * @return string */ - function _update($table, $values, $where, $limit = FALSE) + function _update($table, $values, $where, $orderby = array(), $limit = FALSE) { foreach($values as $key => $val) { @@ -447,8 +517,28 @@ class CI_DB_mysql_driver extends CI_DB { } $limit = (!$limit) ? '' : ' LIMIT '.$limit; + + $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$limit; + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$orderby.$limit; + } + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * If the database does not support the truncate() command + * This function maps to "DELETE FROM table" + * + * @access public + * @param string the table name + * @return string + */ + function _truncate($table) + { + return "TRUNCATE ".$this->_escape_table($table); } // -------------------------------------------------------------------- @@ -461,13 +551,28 @@ class CI_DB_mysql_driver extends CI_DB { * @access public * @param string the table name * @param array the where clause + * @param string the limit clause * @return string */ - function _delete($table, $where, $limit = FALSE) + function _delete($table, $where = array(), $like = array(), $limit = FALSE) { + $conditions = ''; + + if (count($where) > 0 || count($like) > 0) + { + $conditions = "\nWHERE "; + $conditions .= implode("\n", $this->ar_where); + + if (count($where) > 0 && count($like) > 0) + { + $conditions .= " AND "; + } + $conditions .= implode("\n", $like); + } + $limit = (!$limit) ? '' : ' LIMIT '.$limit; - return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where).$limit; + return "DELETE FROM ".$table.$conditions.$limit; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php new file mode 100644 index 000000000..8a918c026 --- /dev/null +++ b/system/database/drivers/mysql/mysql_forge.php @@ -0,0 +1,223 @@ +$attributes) + { + // Numeric field names aren't allowed in databases, so if the key is + // numeric, we know it was assigned by PHP and the developer manually + // entered the field information, so we'll simply add it to the list + if (is_numeric($field)) + { + $sql .= "\n\t$attributes"; + } + 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; + } + + // -------------------------------------------------------------------- + + /** + * Create Table + * + * @access private + * @param string the table name + * @param mixed the fields + * @param mixed primary key(s) + * @param mixed key(s) + * @param boolean should 'IF NOT EXISTS' be added to the SQL + * @return bool + */ + 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_table($table)." ("; + + $sql .= $this->_process_fields($fields); + + if (count($primary_keys) > 0) + { + $primary_keys = $this->db->_protect_identifiers($primary_keys); + $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; + } + + if (is_array($keys) && count($keys) > 0) + { + $keys = $this->db->_protect_identifiers($keys); + foreach ($keys as $key) + { + $sql .= ",\n\tKEY ($key)"; + } + } + + $sql .= "\n) DEFAULT CHARACTER SET {$this->db->char_set} COLLATE {$this->db->dbcollat};"; + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * @access private + * @return bool + */ + function _drop_table($table) + { + return "DROP TABLE IF EXISTS ".$this->db->_escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * Alter table query + * + * Generates a platform-specific query so that a table can be altered + * Called by add_column(), drop_column(), and column_alter(), + * + * @access private + * @param string the ALTER type (ADD, DROP, CHANGE) + * @param string the column name + * @param array fields + * @param string the field after which we should add the new field + * @return object + */ + function _alter_table($alter_type, $table, $fields, $after_field = '') + { + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type "; + + // DROP has everything it needs now. + if ($alter_type == 'DROP') + { + return $sql.$this->db->_protect_identifiers($fields); + } + + $sql .= $this->_process_fields($fields); + + if ($after_field != '') + { + $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); + } + + return $sql; + } + +} +?> \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 54c110e09..c24a008fa 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -23,34 +23,6 @@ * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_mysql_utility extends CI_DB_utility { - - /** - * Create database - * - * @access private - * @param string the database name - * @return bool - */ - function _create_database($name) - { - return "CREATE DATABASE ".$name; - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access private - * @param string the database name - * @return bool - */ - function _drop_database($name) - { - return "DROP DATABASE ".$name; - } - - // -------------------------------------------------------------------- /** * List databases @@ -65,19 +37,6 @@ class CI_DB_mysql_utility extends CI_DB_utility { // -------------------------------------------------------------------- - /** - * Drop Table - * - * @access private - * @return bool - */ - function _drop_table($table) - { - return "DROP TABLE IF EXISTS ".$this->db->_escape_table($table); - } - - // -------------------------------------------------------------------- - /** * Optimize table query * @@ -109,7 +68,6 @@ class CI_DB_mysql_utility extends CI_DB_utility { } // -------------------------------------------------------------------- - /** * MySQL Export * @@ -187,9 +145,10 @@ class CI_DB_mysql_utility extends CI_DB_utility { $is_int = array(); while ($field = mysql_fetch_field($query->result_id)) { + // 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; @@ -255,7 +214,39 @@ class CI_DB_mysql_utility extends CI_DB_utility { return $output; } + /** + * + * The functions below have been deprecated as of 1.6, and are only here for backwards + * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation + * is STRONGLY discouraged in favour if using dbforge. + * + */ -} + /** + * Create database + * + * @access private + * @param string the database name + * @return bool + */ + function _create_database($name) + { + return "CREATE DATABASE ".$name; + } + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access private + * @param string the database name + * @return bool + */ + function _drop_database($name) + { + return "DROP DATABASE ".$name; + } + +} ?> \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index ebed81390..d295ca9f2 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -35,7 +35,7 @@ class CI_DB_mysqli_driver extends CI_DB { * database engines, so this string appears in each driver and is * used for the count_all() and count_all_results() functions. */ - var $_count_string = "SELECT COUNT(*) AS numrows "; + var $_count_string = "SELECT COUNT(*) AS "; var $_random_keyword = ' RAND()'; // database specific random keyword /** @@ -86,6 +86,22 @@ class CI_DB_mysqli_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Set client character set + * + * @access public + * @param string + * @param string + * @return resource + */ + function db_set_charset($charset, $collation) + { + // TODO - add support if needed + return TRUE; + } + + // -------------------------------------------------------------------- + /** * Version number query string * @@ -307,15 +323,16 @@ class CI_DB_mysqli_driver extends CI_DB { * Generates a platform-specific query string so that the table names can be fetched * * @access private + * @param boolean * @return string */ function _list_tables($prefix_limit = FALSE) { $sql = "SHOW TABLES FROM `".$this->database."`"; - if ($prefix_limit !== FALSE AND $this->_stdprefix != '') + if ($prefix_limit !== FALSE AND $this->dbprefix != '') { - $sql .= " LIKE '".$this->_stdprefix."%'"; + $sql .= " LIKE '".$this->dbprefix."%'"; } return $sql; @@ -403,6 +420,58 @@ class CI_DB_mysqli_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Protect Identifiers + * + * This function adds backticks if appropriate based on db type + * + * @access private + * @param mixed the item to escape + * @param boolean only affect the first word + * @return mixed the item with backticks + */ + function _protect_identifiers($item, $first_word_only = FALSE) + { + if (is_array($item)) + { + $escaped_array = array(); + + foreach($item as $k=>$v) + { + $escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v, $first_word_only); + } + + return $escaped_array; + } + + // This function may get "item1 item2" as a string, and so + // we may need "`item1` `item2`" and not "`item1 item2`" + if (strpos($item, ' ') !== FALSE) + { + // This function may get "field >= 1", and need it to return "`field` >= 1" + if ($first_word_only === TRUE) + { + return '`'.preg_replace('/ /', '` ', $item, 1); + } + + $item = preg_replace('/(^|\s|\()([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item); + } + + $exceptions = array('AS', '/', '-', '%', '+', '*'); + + foreach ($exceptions as $exception) + { + if (stristr($item, " `{$exception}` ") !== FALSE) + { + $item = preg_replace('/ `('.preg_quote($exception).')` /i', ' $1 ', $item); + } + } + + return $item; + } + + // -------------------------------------------------------------------- + /** * Insert statement * @@ -430,9 +499,11 @@ class CI_DB_mysqli_driver extends CI_DB { * @param string the table name * @param array the update data * @param array the where clause + * @param array the orderby clause + * @param array the limit clause * @return string */ - function _update($table, $values, $where, $limit = FALSE) + function _update($table, $values, $where, $orderby = array(), $limit = FALSE) { foreach($values as $key => $val) { @@ -440,8 +511,29 @@ class CI_DB_mysqli_driver extends CI_DB { } $limit = (!$limit) ? '' : ' LIMIT '.$limit; + + $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$limit; + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$orderby.$limit; + } + + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * If the database does not support the truncate() command + * This function maps to "DELETE FROM table" + * + * @access public + * @param string the table name + * @return string + */ + function _truncate($table) + { + return "TRUNCATE ".$this->_escape_table($table); } // -------------------------------------------------------------------- @@ -454,13 +546,28 @@ class CI_DB_mysqli_driver extends CI_DB { * @access public * @param string the table name * @param array the where clause + * @param string the limit clause * @return string */ - function _delete($table, $where, $limit = FALSE) + function _delete($table, $where = array(), $like = array(), $limit = FALSE) { + $conditions = ''; + + if (count($where) > 0 || count($like) > 0) + { + $conditions = "\nWHERE "; + $conditions .= implode("\n", $this->ar_where); + + if (count($where) > 0 && count($like) > 0) + { + $conditions .= " AND "; + } + $conditions .= implode("\n", $like); + } + $limit = (!$limit) ? '' : ' LIMIT '.$limit; - return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where).$limit; + return "DELETE FROM ".$table.$conditions.$limit; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php new file mode 100644 index 000000000..3da5d2c49 --- /dev/null +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -0,0 +1,217 @@ +db->_escape_table($table); + } + + // -------------------------------------------------------------------- + + /** + * Create Table + * + * @access private + * @param string the table name + * @param array the fields + * @param mixed primary key(s) + * @param mixed key(s) + * @param boolean should 'IF NOT EXISTS' be added to the SQL + * @return bool + */ + 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_table($table)." ("; + $current_field_count = 0; + + foreach ($fields as $field=>$attributes) + { + // Numeric field names aren't allowed in databases, so if the key is + // numeric, we know it was assigned by PHP and the developer manually + // entered the field information, so we'll simply add it to the list + if (is_numeric($field)) + { + $sql .= "\n\t$attributes"; + } + else + { + $attributes = array_change_key_case($attributes, CASE_UPPER); + + $sql .= "\n\t".$this->db->_protect_identifiers($field); + + $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) && $attributes['NULL'] === TRUE) + { + $sql .= ' NULL'; + } + else + { + $sql .= ' 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 .= ','; + } + } + + if (count($primary_keys) > 0) + { + $primary_keys = $this->db->_protect_identifiers($primary_keys); + $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; + } + + if (is_array($keys) && count($keys) > 0) + { + $keys = $this->db->_protect_identifiers($keys); + foreach ($keys as $key) + { + $sql .= ",\n\tKEY ($key)"; + } + } + + $sql .= "\n) DEFAULT CHARACTER SET {$this->db->char_set} COLLATE {$this->db->dbcollat};"; + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Alter table query + * + * Generates a platform-specific query so that a table can be altered + * Called by add_column(), drop_column(), and column_alter(), + * + * @access private + * @param string the ALTER type (ADD, DROP, CHANGE) + * @param string the column name + * @param string the table name + * @param string the column definition + * @param string the default value + * @param boolean should 'NOT NULL' be added + * @param string the field after which we should add the new field + * @return object + */ + function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') + { + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name); + + // DROP has everything it needs now. + if ($alter_type == 'DROP') + { + return $sql; + } + + $sql .= " $column_definition"; + + if ($default_value != '') + { + $sql .= " DEFAULT \"$default_value\""; + } + + if ($null === NULL) + { + $sql .= ' NULL'; + } + else + { + $sql .= ' NOT NULL'; + } + + if ($after_field != '') + { + $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); + } + + return $sql; + } +} +?> \ 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 c904e92d7..1d910638f 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -24,47 +24,6 @@ */ class CI_DB_mysqli_utility extends CI_DB_utility { - /** - * Create database - * - * @access private - * @param string the database name - * @return bool - */ - function _create_database($name) - { - return "CREATE DATABASE ".$name; - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access private - * @param string the database name - * @return bool - */ - function _drop_database($name) - { - return "DROP DATABASE ".$name; - } - - // -------------------------------------------------------------------- - - /** - * Drop Table - * - * @access private - * @return bool - */ - function _drop_table($table) - { - return "DROP TABLE IF EXISTS ".$this->db->_escape_table($table); - } - - // -------------------------------------------------------------------- - /** * List databases * @@ -187,9 +146,10 @@ class CI_DB_mysqli_utility extends CI_DB_utility { $is_int = array(); while ($field = mysqli_fetch_field($query->result_id)) { + // 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; @@ -255,8 +215,39 @@ class CI_DB_mysqli_utility extends CI_DB_utility { return $output; } + /** + * + * The functions below have been deprecated as of 1.6, and are only here for backwards + * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation + * is STRONGLY discouraged in favour if using dbforge. + * + */ + + /** + * Create database + * + * @access private + * @param string the database name + * @return bool + */ + function _create_database($name) + { + return "CREATE DATABASE ".$name; + } + + // -------------------------------------------------------------------- + /** + * Drop database + * + * @access private + * @param string the database name + * @return bool + */ + function _drop_database($name) + { + return "DROP DATABASE ".$name; + } } - ?> \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index c4ab70051..6d3b72261 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -48,7 +48,8 @@ class CI_DB_oci8_driver extends CI_DB { * database engines, so this string appears in each driver and is * used for the count_all() and count_all_results() functions. */ - var $_count_string = "SELECT COUNT(1) AS numrows "; + var $_count_string = "SELECT COUNT(1) AS "; + var $_random_keyword = ' ASC'; // not currently supported // Set "auto commit" by default var $_commit = OCI_COMMIT_ON_SUCCESS; @@ -100,6 +101,22 @@ class CI_DB_oci8_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Set client character set + * + * @access public + * @param string + * @param string + * @return resource + */ + function db_set_charset($charset, $collation) + { + // TODO - add support if needed + return TRUE; + } + + // -------------------------------------------------------------------- + /** * Version number query string * @@ -415,11 +432,19 @@ class CI_DB_oci8_driver extends CI_DB { * Generates a platform-specific query string so that the table names can be fetched * * @access private + * @param boolean * @return string */ - function _list_tables() + function _list_tables($prefix_limit = FALSE) { - return "SELECT TABLE_NAME FROM ALL_TABLES"; + $sql = "SELECT TABLE_NAME FROM ALL_TABLES"; + + if ($prefix_limit !== FALSE AND $this->dbprefix != '') + { + $sql .= " WHERE TABLE_NAME LIKE '".$this->dbprefix."%'"; + } + + return $sql; } // -------------------------------------------------------------------- @@ -506,6 +531,58 @@ class CI_DB_oci8_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Protect Identifiers + * + * This function adds backticks if appropriate based on db type + * + * @access private + * @param mixed the item to escape + * @param boolean only affect the first word + * @return mixed the item with backticks + */ + function _protect_identifiers($item, $first_word_only = FALSE) + { + if (is_array($item)) + { + $escaped_array = array(); + + foreach($item as $k=>$v) + { + $escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v, $first_word_only); + } + + return $escaped_array; + } + + // This function may get "item1 item2" as a string, and so + // we may need "`item1` `item2`" and not "`item1 item2`" + if (strpos($item, ' ') !== FALSE) + { + // This function may get "field >= 1", and need it to return "`field` >= 1" + if ($first_word_only === TRUE) + { + return '`'.preg_replace('/ /', '` ', $item, 1); + } + + $item = preg_replace('/(^|\s|\()([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item); + } + + $exceptions = array('AS', '/', '-', '%', '+', '*'); + + foreach ($exceptions as $exception) + { + if (stristr($item, " `{$exception}` ") !== FALSE) + { + $item = preg_replace('/ `('.preg_quote($exception).')` /i', ' $1 ', $item); + } + } + + return $item; + } + + // -------------------------------------------------------------------- + /** * Insert statement * @@ -529,13 +606,15 @@ class CI_DB_oci8_driver extends CI_DB { * * Generates a platform-specific update string from the supplied data * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @return string + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @param array the orderby clause + * @param array the limit clause + * @return string */ - function _update($table, $values, $where, $limit = FALSE) + function _update($table, $values, $where, $orderby = array(), $limit = FALSE) { foreach($values as $key => $val) { @@ -543,27 +622,62 @@ class CI_DB_oci8_driver extends CI_DB { } $limit = (!$limit) ? '' : ' LIMIT '.$limit; + + $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$limit; + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$orderby.$limit; } // -------------------------------------------------------------------- + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * If the database does not support the truncate() command + * This function maps to "DELETE FROM table" + * + * @access public + * @param string the table name + * @return string + */ + function _truncate($table) + { + return "TRUNCATE TABLE ".$this->_escape_table($table); + } + + // -------------------------------------------------------------------- + /** * Delete statement * * Generates a platform-specific delete string from the supplied data * - * @access public - * @param string the table name - * @param array the where clause - * @return string - */ - function _delete($table, $where, $limit = FALSE) + * @access public + * @param string the table name + * @param array the where clause + * @param string the limit clause + * @return string + */ + function _delete($table, $where = array(), $like = array(), $limit = FALSE) { + $conditions = ''; + + if (count($where) > 0 || count($like) > 0) + { + $conditions = "\nWHERE "; + $conditions .= implode("\n", $this->ar_where); + + if (count($where) > 0 && count($like) > 0) + { + $conditions .= " AND "; + } + $conditions .= implode("\n", $like); + } + $limit = (!$limit) ? '' : ' LIMIT '.$limit; - return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where).$limit; + return "DELETE FROM ".$table.$conditions.$limit; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php new file mode 100644 index 000000000..c982e66a3 --- /dev/null +++ b/system/database/drivers/oci8/oci8_forge.php @@ -0,0 +1,216 @@ +db->_escape_table($table)." ("; + $current_field_count = 0; + + foreach ($fields as $field=>$attributes) + { + // Numeric field names aren't allowed in databases, so if the key is + // numeric, we know it was assigned by PHP and the developer manually + // entered the field information, so we'll simply add it to the list + if (is_numeric($field)) + { + $sql .= "\n\t$attributes"; + } + else + { + $attributes = array_change_key_case($attributes, CASE_UPPER); + + $sql .= "\n\t".$this->db->_protect_identifiers($field); + + $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) && $attributes['NULL'] === TRUE) + { + $sql .= ' NULL'; + } + else + { + $sql .= ' 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 .= ','; + } + } + + if (count($primary_keys) > 0) + { + $primary_keys = $this->db->_protect_identifiers($primary_keys); + $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; + } + + if (count($keys) > 0) + { + $keys = $this->db->_protect_identifiers($keys); + $sql .= ",\n\tUNIQUE COLUMNS (" . implode(', ', $keys) . ")"; + } + + $sql .= "\n)"; + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * @access private + * @return bool + */ + function _drop_table($table) + { + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Alter table query + * + * Generates a platform-specific query so that a table can be altered + * Called by add_column(), drop_column(), and column_alter(), + * + * @access private + * @param string the ALTER type (ADD, DROP, CHANGE) + * @param string the column name + * @param string the table name + * @param string the column definition + * @param string the default value + * @param boolean should 'NOT NULL' be added + * @param string the field after which we should add the new field + * @return object + */ + function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') + { + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name); + + // DROP has everything it needs now. + if ($alter_type == 'DROP') + { + return $sql; + } + + $sql .= " $column_definition"; + + if ($default_value != '') + { + $sql .= " DEFAULT \"$default_value\""; + } + + if ($null === NULL) + { + $sql .= ' NULL'; + } + else + { + $sql .= ' NOT NULL'; + } + + if ($after_field != '') + { + $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); + } + + return $sql; + + } + +} +?> \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 0f9e4e838..67296da5b 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -24,35 +24,6 @@ */ class CI_DB_oci8_utility extends CI_DB_utility { - - /** - * Create database - * - * @access public - * @param string the database name - * @return bool - */ - function _create_database($name) - { - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access private - * @param string the database name - * @return bool - */ - function _drop_database($name) - { - return FALSE; - } - - // -------------------------------------------------------------------- - /** * List databases * @@ -66,19 +37,6 @@ class CI_DB_oci8_utility extends CI_DB_utility { // -------------------------------------------------------------------- - /** - * Drop Table - * - * @access private - * @return bool - */ - function _drop_table($table) - { - return FALSE; - } - - // -------------------------------------------------------------------- - /** * Optimize table query * @@ -124,6 +82,39 @@ class CI_DB_oci8_utility extends CI_DB_utility { return $this->db->display_error('db_unsuported_feature'); } -} + /** + * + * The functions below have been deprecated as of 1.6, and are only here for backwards + * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation + * is STRONGLY discouraged in favour if using dbforge. + * + */ + + /** + * Create database + * + * @access public + * @param string the database name + * @return bool + */ + function _create_database($name) + { + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access private + * @param string the database name + * @return bool + */ + function _drop_database($name) + { + return FALSE; + } +} ?> \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 040ffed9e..0bdfc41d5 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -35,8 +35,14 @@ class CI_DB_odbc_driver extends CI_DB { * database engines, so this string appears in each driver and is * used for the count_all() and count_all_results() functions. */ - var $_count_string = "SELECT COUNT(*) AS numrows "; - var $_random_keyword = ' RND('.time().')'; // database specific random keyword + var $_count_string = "SELECT COUNT(*) AS "; + var $_random_keyword; + + + function CI_DB_odbc_driver() + { + $_random_keyword = ' RND('.time().')'; // database specific random keyword + } /** * Non-persistent database connection @@ -78,6 +84,22 @@ class CI_DB_odbc_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Set client character set + * + * @access public + * @param string + * @param string + * @return resource + */ + function db_set_charset($charset, $collation) + { + // TODO - add support if needed + return TRUE; + } + + // -------------------------------------------------------------------- + /** * Version number query string * @@ -276,11 +298,20 @@ class CI_DB_odbc_driver extends CI_DB { * Generates a platform-specific query string so that the table names can be fetched * * @access private + * @param boolean * @return string */ - function _list_tables() + function _list_tables($prefix_limit = FALSE) { - return "SHOW TABLES FROM `".$this->database."`"; + $sql = "SHOW TABLES FROM `".$this->database."`"; + + if ($prefix_limit !== FALSE AND $this->dbprefix != '') + { + //$sql .= " LIKE '".$this->dbprefix."%'"; + return FALSE; // not currently supported + } + + return $sql; } // -------------------------------------------------------------------- @@ -365,6 +396,58 @@ class CI_DB_odbc_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Protect Identifiers + * + * This function adds backticks if appropriate based on db type + * + * @access private + * @param mixed the item to escape + * @param boolean only affect the first word + * @return mixed the item with backticks + */ + function _protect_identifiers($item, $first_word_only = FALSE) + { + if (is_array($item)) + { + $escaped_array = array(); + + foreach($item as $k=>$v) + { + $escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v, $first_word_only); + } + + return $escaped_array; + } + + // This function may get "item1 item2" as a string, and so + // we may need "`item1` `item2`" and not "`item1 item2`" + if (strpos($item, ' ') !== FALSE) + { + // This function may get "field >= 1", and need it to return "`field` >= 1" + if ($first_word_only === TRUE) + { + return '`'.preg_replace('/ /', '` ', $item, 1); + } + + $item = preg_replace('/(^|\s|\()([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item); + } + + $exceptions = array('AS', '/', '-', '%', '+', '*'); + + foreach ($exceptions as $exception) + { + if (stristr($item, " `{$exception}` ") !== FALSE) + { + $item = preg_replace('/ `('.preg_quote($exception).')` /i', ' $1 ', $item); + } + } + + return $item; + } + + // -------------------------------------------------------------------- + /** * Insert statement * @@ -392,9 +475,11 @@ class CI_DB_odbc_driver extends CI_DB { * @param string the table name * @param array the update data * @param array the where clause + * @param array the orderby clause + * @param array the limit clause * @return string */ - function _update($table, $values, $where, $limit = FALSE) + function _update($table, $values, $where, $orderby = array(), $limit = FALSE) { foreach($values as $key => $val) { @@ -402,8 +487,29 @@ class CI_DB_odbc_driver extends CI_DB { } $limit = (!$limit) ? '' : ' LIMIT '.$limit; + + $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; + + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$orderby.$limit; + } + - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$limit; + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * If the database does not support the truncate() command + * This function maps to "DELETE FROM table" + * + * @access public + * @param string the table name + * @return string + */ + function _truncate($table) + { + return $this->_delete($table); } // -------------------------------------------------------------------- @@ -416,13 +522,28 @@ class CI_DB_odbc_driver extends CI_DB { * @access public * @param string the table name * @param array the where clause + * @param string the limit clause * @return string */ - function _delete($table, $where, $limit = FALSE) + function _delete($table, $where = array(), $like = array(), $limit = FALSE) { + $conditions = ''; + + if (count($where) > 0 || count($like) > 0) + { + $conditions = "\nWHERE "; + $conditions .= implode("\n", $this->ar_where); + + if (count($where) > 0 && count($like) > 0) + { + $conditions .= " AND "; + } + $conditions .= implode("\n", $like); + } + $limit = (!$limit) ? '' : ' LIMIT '.$limit; - return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where).$limit; + return "DELETE FROM ".$table.$conditions.$limit; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php new file mode 100644 index 000000000..1d79344c1 --- /dev/null +++ b/system/database/drivers/odbc/odbc_forge.php @@ -0,0 +1,236 @@ +db->db_debug) + { + return $this->db->display_error('db_unsuported_feature'); + } + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access private + * @param string the database name + * @return bool + */ + function _drop_database($name) + { + // ODBC has no "drop database" command since it's + // designed to connect to an existing database + if ($this->db->db_debug) + { + return $this->db->display_error('db_unsuported_feature'); + } + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Create Table + * + * @access private + * @param string the table name + * @param array the fields + * @param mixed primary key(s) + * @param mixed key(s) + * @param boolean should 'IF NOT EXISTS' be added to the SQL + * @return bool + */ + 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_table($table)." ("; + $current_field_count = 0; + + foreach ($fields as $field=>$attributes) + { + // Numeric field names aren't allowed in databases, so if the key is + // numeric, we know it was assigned by PHP and the developer manually + // entered the field information, so we'll simply add it to the list + if (is_numeric($field)) + { + $sql .= "\n\t$attributes"; + } + else + { + $attributes = array_change_key_case($attributes, CASE_UPPER); + + $sql .= "\n\t".$this->db->_protect_identifiers($field); + + $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) && $attributes['NULL'] === TRUE) + { + $sql .= ' NULL'; + } + else + { + $sql .= ' 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 .= ','; + } + } + + if (count($primary_keys) > 0) + { + $primary_keys = $this->db->_protect_identifiers($primary_keys); + $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; + } + + if (is_array($keys) && count($keys) > 0) + { + $keys = $this->db->_protect_identifiers($keys); + foreach ($keys as $key) + { + $sql .= ",\n\tFOREIGN KEY ($key)"; + } + } + + $sql .= "\n)"; + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * @access private + * @return bool + */ + function _drop_table($table) + { + // Not a supported ODBC feature + if ($this->db->db_debug) + { + return $this->db->display_error('db_unsuported_feature'); + } + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Alter table query + * + * Generates a platform-specific query so that a table can be altered + * Called by add_column(), drop_column(), and column_alter(), + * + * @access private + * @param string the ALTER type (ADD, DROP, CHANGE) + * @param string the column name + * @param string the table name + * @param string the column definition + * @param string the default value + * @param boolean should 'NOT NULL' be added + * @param string the field after which we should add the new field + * @return object + */ + function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') + { + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name); + + // DROP has everything it needs now. + if ($alter_type == 'DROP') + { + return $sql; + } + + $sql .= " $column_definition"; + + if ($default_value != '') + { + $sql .= " DEFAULT \"$default_value\""; + } + + if ($null === NULL) + { + $sql .= ' NULL'; + } + else + { + $sql .= ' NOT NULL'; + } + + if ($after_field != '') + { + $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); + } + + return $sql; + + } + +} +?> \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index e909fd743..53c317356 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -192,7 +192,6 @@ class CI_DB_odbc_result extends CI_DB_result { * @access private * @return object */ - function _odbc_fetch_object(& $odbc_result) { $rs = array(); $rs_obj = false; @@ -215,7 +214,6 @@ class CI_DB_odbc_result extends CI_DB_result { * @access private * @return array */ - function _odbc_fetch_array(& $odbc_result) { $rs = array(); $rs_assoc = false; diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index 97e950fc1..d64d15af5 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -24,18 +24,15 @@ */ class CI_DB_odbc_utility extends CI_DB_utility { - /** - * Create database + * List databases * * @access private - * @param string the database name * @return bool */ - function _create_database() + function _list_databases() { - // ODBC has no "create database" command since it's - // designed to connect to an existing database + // Not sure if ODBC lets you list all databases... if ($this->db->db_debug) { return $this->db->display_error('db_unsuported_feature'); @@ -46,16 +43,17 @@ class CI_DB_odbc_utility extends CI_DB_utility { // -------------------------------------------------------------------- /** - * Drop database + * Optimize table query + * + * Generates a platform-specific query so that a table can be optimized * * @access private - * @param string the database name - * @return bool + * @param string the table name + * @return object */ - function _drop_database($name) + function _optimize_table($table) { - // ODBC has no "drop database" command since it's - // designed to connect to an existing database + // Not a supported ODBC feature if ($this->db->db_debug) { return $this->db->display_error('db_unsuported_feature'); @@ -66,14 +64,17 @@ class CI_DB_odbc_utility extends CI_DB_utility { // -------------------------------------------------------------------- /** - * List databases + * Repair table query + * + * Generates a platform-specific query so that a table can be repaired * * @access private - * @return bool + * @param string the table name + * @return object */ - function _list_databases() + function _repair_table($table) { - // Not sure if ODBC lets you list all databases... + // Not a supported ODBC feature if ($this->db->db_debug) { return $this->db->display_error('db_unsuported_feature'); @@ -84,35 +85,37 @@ class CI_DB_odbc_utility extends CI_DB_utility { // -------------------------------------------------------------------- /** - * Drop Table + * ODBC Export * * @access private - * @return bool + * @param array Preferences + * @return mixed */ - function _drop_table($table) + function _backup($params = array()) { - // Not a supported ODBC feature - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return FALSE; + // Currently unsupported + return $this->db->display_error('db_unsuported_feature'); } - - // -------------------------------------------------------------------- - + /** - * Optimize table query * - * Generates a platform-specific query so that a table can be optimized + * The functions below have been deprecated as of 1.6, and are only here for backwards + * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation + * is STRONGLY discouraged in favour if using dbforge. + * + */ + + /** + * Create database * * @access private - * @param string the table name - * @return object + * @param string the database name + * @return bool */ - function _optimize_table($table) + function _create_database() { - // Not a supported ODBC feature + // ODBC has no "create database" command since it's + // designed to connect to an existing database if ($this->db->db_debug) { return $this->db->display_error('db_unsuported_feature'); @@ -123,39 +126,21 @@ class CI_DB_odbc_utility extends CI_DB_utility { // -------------------------------------------------------------------- /** - * Repair table query - * - * Generates a platform-specific query so that a table can be repaired + * Drop database * * @access private - * @param string the table name - * @return object + * @param string the database name + * @return bool */ - function _repair_table($table) + function _drop_database($name) { - // Not a supported ODBC feature + // ODBC has no "drop database" command since it's + // designed to connect to an existing database if ($this->db->db_debug) { return $this->db->display_error('db_unsuported_feature'); } 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'); - } - } - ?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 88f08b2d7..63a72f5d3 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -35,7 +35,7 @@ class CI_DB_postgre_driver extends CI_DB { * database engines, so this string appears in each driver and is * used for the count_all() and count_all_results() functions. */ - var $_count_string = "SELECT COUNT(*) AS numrows "; + var $_count_string = "SELECT COUNT(*) AS "; var $_random_keyword = ' RANDOM()'; // database specific random keyword /** @@ -82,6 +82,22 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Set client character set + * + * @access public + * @param string + * @param string + * @return resource + */ + function db_set_charset($charset, $collation) + { + // TODO - add support if needed + return TRUE; + } + + // -------------------------------------------------------------------- + /** * Version number query string * @@ -305,11 +321,19 @@ class CI_DB_postgre_driver extends CI_DB { * Generates a platform-specific query string so that the table names can be fetched * * @access private + * @param boolean * @return string */ - function _list_tables() + function _list_tables($prefix_limit = FALSE) { - return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; + $sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; + + if ($prefix_limit !== FALSE AND $this->dbprefix != '') + { + $sql .= " AND table_name LIKE '".$this->dbprefix."%'"; + } + + return $sql; } // -------------------------------------------------------------------- @@ -394,6 +418,58 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Protect Identifiers + * + * This function adds backticks if appropriate based on db type + * + * @access private + * @param mixed the item to escape + * @param boolean only affect the first word + * @return mixed the item with backticks + */ + function _protect_identifiers($item, $first_word_only = FALSE) + { + if (is_array($item)) + { + $escaped_array = array(); + + foreach($item as $k=>$v) + { + $escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v, $first_word_only); + } + + return $escaped_array; + } + + // This function may get "item1 item2" as a string, and so + // we may need ""item1" "item2"" and not ""item1 item2"" + if (strpos($item, ' ') !== FALSE) + { + // This function may get "field >= 1", and need it to return ""field" >= 1" + if ($first_word_only === TRUE) + { + return '"'.preg_replace('/ /', '" ', $item, 1); + } + + $item = preg_replace('/(^|\s|\()([\w\d\-\_]+?)(\s|\)|$)/iS', '$1"$2"$3', $item); + } + + $exceptions = array('AS', '/', '-', '%', '+', '*'); + + foreach ($exceptions as $exception) + { + if (stristr($item, " "{$exception}" ") !== FALSE) + { + $item = preg_replace('/ "('.preg_quote($exception).')" /i', ' $1 ', $item); + } + } + + return $item; + } + + // -------------------------------------------------------------------- + /** * Insert statement * @@ -421,9 +497,11 @@ class CI_DB_postgre_driver extends CI_DB { * @param string the table name * @param array the update data * @param array the where clause + * @param array the orderby clause + * @param array the limit clause * @return string */ - function _update($table, $values, $where, $limit = FALSE) + function _update($table, $values, $where, $orderby = array(), $limit = FALSE) { foreach($values as $key => $val) { @@ -431,8 +509,29 @@ class CI_DB_postgre_driver extends CI_DB { } $limit = (!$limit) ? '' : ' LIMIT '.$limit; + + $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$limit; + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$orderby.$limit; + } + + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * If the database does not support the truncate() command + * This function maps to "DELETE FROM table" + * + * @access public + * @param string the table name + * @return string + */ + function _truncate($table) + { + return "TRUNCATE ".$this->_escape_table($table); } // -------------------------------------------------------------------- @@ -445,17 +544,31 @@ class CI_DB_postgre_driver extends CI_DB { * @access public * @param string the table name * @param array the where clause + * @param string the limit clause * @return string */ - function _delete($table, $where, $limit = FALSE) + function _delete($table, $where = array(), $like = array(), $limit = FALSE) { + $conditions = ''; + + if (count($where) > 0 || count($like) > 0) + { + $conditions = "\nWHERE "; + $conditions .= implode("\n", $this->ar_where); + + if (count($where) > 0 && count($like) > 0) + { + $conditions .= " AND "; + } + $conditions .= implode("\n", $like); + } + $limit = (!$limit) ? '' : ' LIMIT '.$limit; - return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where).$limit; + return "DELETE FROM ".$table.$conditions.$limit; } // -------------------------------------------------------------------- - /** * Limit string * diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php new file mode 100644 index 000000000..34bbe88b6 --- /dev/null +++ b/system/database/drivers/postgre/postgre_forge.php @@ -0,0 +1,219 @@ +db->_escape_table($table)." ("; + $current_field_count = 0; + + foreach ($fields as $field=>$attributes) + { + // Numeric field names aren't allowed in databases, so if the key is + // numeric, we know it was assigned by PHP and the developer manually + // entered the field information, so we'll simply add it to the list + if (is_numeric($field)) + { + $sql .= "\n\t$attributes"; + } + else + { + $attributes = array_change_key_case($attributes, CASE_UPPER); + + $sql .= "\n\t".$this->db->_protect_identifiers($field); + + $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) && $attributes['NULL'] === TRUE) + { + $sql .= ' NULL'; + } + else + { + $sql .= ' 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 .= ','; + } + } + + if (count($primary_keys) > 0) + { + $primary_keys = $this->db->_protect_identifiers($primary_keys); + $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; + } + + if (is_array($keys) && count($keys) > 0) + { + $keys = $this->db->_protect_identifiers($keys); + foreach ($keys as $key) + { + $sql .= ",\n\tFOREIGN KEY ($key)"; + } + } + + $sql .= "\n);"; + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * @access private + * @return bool + */ + function _drop_table($table) + { + return "DROP TABLE ".$this->db->_escape_table($table)." CASCADE"; + } + + // -------------------------------------------------------------------- + + /** + * Alter table query + * + * Generates a platform-specific query so that a table can be altered + * Called by add_column(), drop_column(), and column_alter(), + * + * @access private + * @param string the ALTER type (ADD, DROP, CHANGE) + * @param string the column name + * @param string the table name + * @param string the column definition + * @param string the default value + * @param boolean should 'NOT NULL' be added + * @param string the field after which we should add the new field + * @return object + */ + function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') + { + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name); + + // DROP has everything it needs now. + if ($alter_type == 'DROP') + { + return $sql; + } + + $sql .= " $column_definition"; + + if ($default_value != '') + { + $sql .= " DEFAULT \"$default_value\""; + } + + if ($null === NULL) + { + $sql .= ' NULL'; + } + else + { + $sql .= ' NOT NULL'; + } + + if ($after_field != '') + { + $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); + } + + return $sql; + + } + +} +?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index fa5960e58..a706d9505 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -24,35 +24,6 @@ */ class CI_DB_postgre_utility extends CI_DB_utility { - - /** - * Create database - * - * @access private - * @param string the database name - * @return bool - */ - function _create_database($name) - { - return "CREATE DATABASE ".$name; - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access private - * @param string the database name - * @return bool - */ - function _drop_database($name) - { - return "DROP DATABASE ".$name; - } - - // -------------------------------------------------------------------- - /** * List databases * @@ -66,19 +37,6 @@ class CI_DB_postgre_utility extends CI_DB_utility { // -------------------------------------------------------------------- - /** - * Drop Table - * - * @access private - * @return bool - */ - function _drop_table($table) - { - return "DROP TABLE ".$this->db->_escape_table($table)." CASCADE"; - } - - // -------------------------------------------------------------------- - /** * Optimize table query * @@ -124,6 +82,41 @@ class CI_DB_postgre_utility extends CI_DB_utility { return $this->db->display_error('db_unsuported_feature'); } + /** + * + * The functions below have been deprecated as of 1.6, and are only here for backwards + * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation + * is STRONGLY discouraged in favour if using dbforge. + * + */ + + /** + * Create database + * + * @access private + * @param string the database name + * @return bool + */ + function _create_database($name) + { + return "CREATE DATABASE ".$name; + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access private + * @param string the database name + * @return bool + */ + function _drop_database($name) + { + return "DROP DATABASE ".$name; + } + + } ?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 6189b1ff0..2d0ca157c 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -37,7 +37,7 @@ class CI_DB_sqlite_driver extends CI_DB { * database engines, so this string appears in each driver and is * used for the count_all() and count_all_results() functions. */ - var $_count_string = "SELECT COUNT(*) AS numrows "; + var $_count_string = "SELECT COUNT(*) AS "; var $_random_keyword = ' Random()'; // database specific random keyword /** @@ -103,6 +103,22 @@ class CI_DB_sqlite_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Set client character set + * + * @access public + * @param string + * @param string + * @return resource + */ + function db_set_charset($charset, $collation) + { + // TODO - add support if needed + return TRUE; + } + + // -------------------------------------------------------------------- + /** * Version number query string * @@ -299,11 +315,18 @@ class CI_DB_sqlite_driver extends CI_DB { * Generates a platform-specific query string so that the table names can be fetched * * @access private + * @param boolean * @return string */ - function _list_tables() + function _list_tables($prefix_limit = FALSE) { - return "SELECT name from sqlite_master WHERE type='table'"; + $sql = "SELECT name from sqlite_master WHERE type='table'"; + + if ($prefix_limit !== FALSE AND $this->dbprefix != '') + { + $sql .= " AND 'name' LIKE '".$this->dbprefix."%'"; + } + return $sql; } // -------------------------------------------------------------------- @@ -389,6 +412,58 @@ class CI_DB_sqlite_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Protect Identifiers + * + * This function adds backticks if appropriate based on db type + * + * @access private + * @param mixed the item to escape + * @param boolean only affect the first word + * @return mixed the item with backticks + */ + function _protect_identifiers($item, $first_word_only = FALSE) + { + if (is_array($item)) + { + $escaped_array = array(); + + foreach($item as $k=>$v) + { + $escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v, $first_word_only); + } + + return $escaped_array; + } + + // This function may get "item1 item2" as a string, and so + // we may need "`item1` `item2`" and not "`item1 item2`" + if (strpos($item, ' ') !== FALSE) + { + // This function may get "field >= 1", and need it to return "`field` >= 1" + if ($first_word_only === TRUE) + { + return '`'.preg_replace('/ /', '` ', $item, 1); + } + + $item = preg_replace('/(^|\s|\()([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item); + } + + $exceptions = array('AS', '/', '-', '%', '+', '*'); + + foreach ($exceptions as $exception) + { + if (stristr($item, " `{$exception}` ") !== FALSE) + { + $item = preg_replace('/ `('.preg_quote($exception).')` /i', ' $1 ', $item); + } + } + + return $item; + } + + // -------------------------------------------------------------------- + /** * Insert statement * @@ -416,9 +491,11 @@ class CI_DB_sqlite_driver extends CI_DB { * @param string the table name * @param array the update data * @param array the where clause + * @param array the orderby clause + * @param array the limit clause * @return string */ - function _update($table, $values, $where, $limit = FALSE) + function _update($table, $values, $where, $orderby = array(), $limit = FALSE) { foreach($values as $key => $val) { @@ -426,8 +503,29 @@ class CI_DB_sqlite_driver extends CI_DB { } $limit = (!$limit) ? '' : ' LIMIT '.$limit; + + $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; + + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$orderby.$limit; + } + - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$limit; + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * If the database does not support the truncate() command + * This function maps to "DELETE FROM table" + * + * @access public + * @param string the table name + * @return string + */ + function _truncate($table) + { + return $this->_delete($table); } // -------------------------------------------------------------------- @@ -440,15 +538,30 @@ class CI_DB_sqlite_driver extends CI_DB { * @access public * @param string the table name * @param array the where clause + * @param string the limit clause * @return string */ - function _delete($table, $where, $limit = FALSE) + function _delete($table, $where = array(), $like = array(), $limit = FALSE) { + $conditions = ''; + + if (count($where) > 0 || count($like) > 0) + { + $conditions = "\nWHERE "; + $conditions .= implode("\n", $this->ar_where); + + if (count($where) > 0 && count($like) > 0) + { + $conditions .= " AND "; + } + $conditions .= implode("\n", $like); + } + $limit = (!$limit) ? '' : ' LIMIT '.$limit; - return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where).$limit; + return "DELETE FROM ".$table.$conditions.$limit; } - + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php new file mode 100644 index 000000000..54b65987d --- /dev/null +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -0,0 +1,233 @@ +db->database) OR ! @unlink($this->db->database)) + { + if ($this->db->db_debug) + { + return $this->db->display_error('db_unable_to_drop'); + } + return FALSE; + } + return TRUE; + } + // -------------------------------------------------------------------- + + /** + * Create Table + * + * @access private + * @param string the table name + * @param array the fields + * @param mixed primary key(s) + * @param mixed key(s) + * @param boolean should 'IF NOT EXISTS' be added to the SQL + * @return bool + */ + 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_table($table)." ("; + $current_field_count = 0; + + foreach ($fields as $field=>$attributes) + { + // Numeric field names aren't allowed in databases, so if the key is + // numeric, we know it was assigned by PHP and the developer manually + // entered the field information, so we'll simply add it to the list + if (is_numeric($field)) + { + $sql .= "\n\t$attributes"; + } + else + { + $attributes = array_change_key_case($attributes, CASE_UPPER); + + $sql .= "\n\t".$this->db->_protect_identifiers($field); + + $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) && $attributes['NULL'] === TRUE) + { + $sql .= ' NULL'; + } + else + { + $sql .= ' 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 .= ','; + } + } + + if (count($primary_keys) > 0) + { + $primary_keys = $this->db->_protect_identifiers($primary_keys); + $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; + } + + if (count($keys) > 0) + { + $keys = $this->db->_protect_identifiers($keys); + $sql .= ",\n\tUNIQUE (" . implode(', ', $keys) . ")"; + } + + $sql .= "\n)"; + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * Unsupported feature in SQLite + * + * @access private + * @return bool + */ + function _drop_table($table) + { + if ($this->db->db_debug) + { + return $this->db->display_error('db_unsuported_feature'); + } + return array(); + } + + // -------------------------------------------------------------------- + + /** + * Alter table query + * + * Generates a platform-specific query so that a table can be altered + * Called by add_column(), drop_column(), and column_alter(), + * + * @access private + * @param string the ALTER type (ADD, DROP, CHANGE) + * @param string the column name + * @param string the table name + * @param string the column definition + * @param string the default value + * @param boolean should 'NOT NULL' be added + * @param string the field after which we should add the new field + * @return object + */ + function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') + { + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name); + + // DROP has everything it needs now. + if ($alter_type == 'DROP') + { + // SQLite does not support dropping columns + // http://www.sqlite.org/omitted.html + // http://www.sqlite.org/faq.html#q11 + return FALSE; + } + + $sql .= " $column_definition"; + + if ($default_value != '') + { + $sql .= " DEFAULT \"$default_value\""; + } + + if ($null === NULL) + { + $sql .= ' NULL'; + } + else + { + $sql .= ' NOT NULL'; + } + + if ($after_field != '') + { + $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); + } + + return $sql; + + } +} +?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index caa167813..0939c87b8 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -167,7 +167,14 @@ class CI_DB_sqlite_result extends CI_DB_result { } else { - return $this->_fetch_assoc(); + $arr = sqlite_fetch_array($this->result_id, SQLITE_ASSOC); + if (is_array($arr)) + { + $obj = (object) $arr; + return $obj; + } else { + return NULL; + } } } diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 85e74d05f..1c78c54b7 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -24,45 +24,6 @@ */ class CI_DB_sqlite_utility extends CI_DB_utility { - - /** - * Create database - * - * @access public - * @param string the database name - * @return bool - */ - function _create_database() - { - // In SQLite, a database is created when you connect to the database. - // We'll return TRUE so that an error isn't generated - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access private - * @param string the database name - * @return bool - */ - function _drop_database($name) - { - if ( ! @file_exists($this->db->database) OR ! @unlink($this->db->database)) - { - if ($this->db->db_debug) - { - return $this->db->display_error('db_unable_to_drop'); - } - return FALSE; - } - return TRUE; - } - - // -------------------------------------------------------------------- - /** * List databases * @@ -85,25 +46,6 @@ class CI_DB_sqlite_utility extends CI_DB_utility { // -------------------------------------------------------------------- - /** - * Drop Table - * - * Unsupported feature in SQLite - * - * @access private - * @return bool - */ - function _drop_table($table) - { - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return array(); - } - - // -------------------------------------------------------------------- - /** * Optimize table query * @@ -149,6 +91,49 @@ class CI_DB_sqlite_utility extends CI_DB_utility { return $this->db->display_error('db_unsuported_feature'); } -} + /** + * + * The functions below have been deprecated as of 1.6, and are only here for backwards + * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation + * is STRONGLY discouraged in favour if using dbforge. + * + */ + + /** + * Create database + * + * @access public + * @param string the database name + * @return bool + */ + function _create_database() + { + // In SQLite, a database is created when you connect to the database. + // We'll return TRUE so that an error isn't generated + return TRUE; + } + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access private + * @param string the database name + * @return bool + */ + function _drop_database($name) + { + if ( ! @file_exists($this->db->database) OR ! @unlink($this->db->database)) + { + if ($this->db->db_debug) + { + return $this->db->display_error('db_unable_to_drop'); + } + return FALSE; + } + return TRUE; + } + +} ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 91f50b626517ff34a0436df8e08f2dddfd2d5d7a Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 16 Jan 2008 21:48:18 +0000 Subject: fix for single word identifiers with no spaces that need protecting in _protect_identifiers() --- system/database/drivers/mysql/mysql_driver.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index a164552ed..9dc697670 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -452,7 +452,7 @@ class CI_DB_mysql_driver extends CI_DB { // This function may get "item1 item2" as a string, and so // we may need "`item1` `item2`" and not "`item1 item2`" - if (strpos($item, ' ') !== FALSE) + if (ctype_alnum($item) !== FALSE) { // This function may get "field >= 1", and need it to return "`field` >= 1" if ($first_word_only === TRUE) @@ -462,6 +462,10 @@ class CI_DB_mysql_driver extends CI_DB { $item = preg_replace('/(^|\s|\()([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item); } + else + { + return "`{$item}`"; + } $exceptions = array('AS', '/', '-', '%', '+', '*'); -- cgit v1.2.3-24-g4f1b From 68d021b7d83a9c9a991fc0cef8cddd8149487255 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 16 Jan 2008 21:58:37 +0000 Subject: === instead of !== ::blush:: --- system/database/drivers/mysql/mysql_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 9dc697670..4535e8cd4 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -452,7 +452,7 @@ class CI_DB_mysql_driver extends CI_DB { // This function may get "item1 item2" as a string, and so // we may need "`item1` `item2`" and not "`item1 item2`" - if (ctype_alnum($item) !== FALSE) + if (ctype_alnum($item) === FALSE) { // This function may get "field >= 1", and need it to return "`field` >= 1" if ($first_word_only === TRUE) -- cgit v1.2.3-24-g4f1b From cdbdf2d30dd1dd6aff2ea25e9875814080d416e2 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 16 Jan 2008 22:18:03 +0000 Subject: special fix for $first_word_only to work with other changes to _protect_identifiers() --- system/database/drivers/mysql/mysql_driver.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 4535e8cd4..36e365165 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -455,12 +455,9 @@ class CI_DB_mysql_driver extends CI_DB { if (ctype_alnum($item) === FALSE) { // This function may get "field >= 1", and need it to return "`field` >= 1" - if ($first_word_only === TRUE) - { - return '`'.preg_replace('/ /', '` ', $item, 1); - } + $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; - $item = preg_replace('/(^|\s|\()([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item); + $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item); } else { -- cgit v1.2.3-24-g4f1b From 6157938ad5dd9d48607921593ca4ed7bff3e3a8b Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 16 Jan 2008 22:22:42 +0000 Subject: --- system/database/drivers/mysqli/mysqli_driver.php | 15 ++++++++------- system/database/drivers/oci8/oci8_driver.php | 15 ++++++++------- system/database/drivers/odbc/odbc_driver.php | 15 ++++++++------- system/database/drivers/postgre/postgre_driver.php | 15 ++++++++------- system/database/drivers/sqlite/sqlite_driver.php | 15 ++++++++------- 5 files changed, 40 insertions(+), 35 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index d295ca9f2..94a29937b 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -446,27 +446,28 @@ class CI_DB_mysqli_driver extends CI_DB { // This function may get "item1 item2" as a string, and so // we may need "`item1` `item2`" and not "`item1 item2`" - if (strpos($item, ' ') !== FALSE) + if (ctype_alnum($item) === FALSE) { // This function may get "field >= 1", and need it to return "`field` >= 1" - if ($first_word_only === TRUE) - { - return '`'.preg_replace('/ /', '` ', $item, 1); - } + $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; - $item = preg_replace('/(^|\s|\()([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item); + $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item); + } + else + { + return "`{$item}`"; } $exceptions = array('AS', '/', '-', '%', '+', '*'); foreach ($exceptions as $exception) { + if (stristr($item, " `{$exception}` ") !== FALSE) { $item = preg_replace('/ `('.preg_quote($exception).')` /i', ' $1 ', $item); } } - return $item; } diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 6d3b72261..160a56d51 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -557,27 +557,28 @@ class CI_DB_oci8_driver extends CI_DB { // This function may get "item1 item2" as a string, and so // we may need "`item1` `item2`" and not "`item1 item2`" - if (strpos($item, ' ') !== FALSE) + if (ctype_alnum($item) === FALSE) { // This function may get "field >= 1", and need it to return "`field` >= 1" - if ($first_word_only === TRUE) - { - return '`'.preg_replace('/ /', '` ', $item, 1); - } + $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; - $item = preg_replace('/(^|\s|\()([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item); + $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item); + } + else + { + return "`{$item}`"; } $exceptions = array('AS', '/', '-', '%', '+', '*'); foreach ($exceptions as $exception) { + if (stristr($item, " `{$exception}` ") !== FALSE) { $item = preg_replace('/ `('.preg_quote($exception).')` /i', ' $1 ', $item); } } - return $item; } diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 0bdfc41d5..c5c582d0b 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -422,27 +422,28 @@ class CI_DB_odbc_driver extends CI_DB { // This function may get "item1 item2" as a string, and so // we may need "`item1` `item2`" and not "`item1 item2`" - if (strpos($item, ' ') !== FALSE) + if (ctype_alnum($item) === FALSE) { // This function may get "field >= 1", and need it to return "`field` >= 1" - if ($first_word_only === TRUE) - { - return '`'.preg_replace('/ /', '` ', $item, 1); - } + $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; - $item = preg_replace('/(^|\s|\()([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item); + $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item); + } + else + { + return "`{$item}`"; } $exceptions = array('AS', '/', '-', '%', '+', '*'); foreach ($exceptions as $exception) { + if (stristr($item, " `{$exception}` ") !== FALSE) { $item = preg_replace('/ `('.preg_quote($exception).')` /i', ' $1 ', $item); } } - return $item; } diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 63a72f5d3..fa27f03d5 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -444,27 +444,28 @@ class CI_DB_postgre_driver extends CI_DB { // This function may get "item1 item2" as a string, and so // we may need ""item1" "item2"" and not ""item1 item2"" - if (strpos($item, ' ') !== FALSE) + if (ctype_alnum($item) === FALSE) { // This function may get "field >= 1", and need it to return ""field" >= 1" - if ($first_word_only === TRUE) - { - return '"'.preg_replace('/ /', '" ', $item, 1); - } + $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; - $item = preg_replace('/(^|\s|\()([\w\d\-\_]+?)(\s|\)|$)/iS', '$1"$2"$3', $item); + $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1"$2"$3', $item); + } + else + { + return ""{$item}""; } $exceptions = array('AS', '/', '-', '%', '+', '*'); foreach ($exceptions as $exception) { + if (stristr($item, " "{$exception}" ") !== FALSE) { $item = preg_replace('/ "('.preg_quote($exception).')" /i', ' $1 ', $item); } } - return $item; } diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 2d0ca157c..110b208d2 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -438,27 +438,28 @@ class CI_DB_sqlite_driver extends CI_DB { // This function may get "item1 item2" as a string, and so // we may need "`item1` `item2`" and not "`item1 item2`" - if (strpos($item, ' ') !== FALSE) + if (ctype_alnum($item) === FALSE) { // This function may get "field >= 1", and need it to return "`field` >= 1" - if ($first_word_only === TRUE) - { - return '`'.preg_replace('/ /', '` ', $item, 1); - } + $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; - $item = preg_replace('/(^|\s|\()([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item); + $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item); + } + else + { + return "`{$item}`"; } $exceptions = array('AS', '/', '-', '%', '+', '*'); foreach ($exceptions as $exception) { + if (stristr($item, " `{$exception}` ") !== FALSE) { $item = preg_replace('/ `('.preg_quote($exception).')` /i', ' $1 ', $item); } } - return $item; } -- cgit v1.2.3-24-g4f1b From 05b3a5df12ec91f4762786c4b8a70136825b1e41 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 17 Jan 2008 20:25:46 +0000 Subject: orderby fix --- system/database/DB_active_rec.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 3cc65aff4..c899b7f4f 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -749,7 +749,8 @@ class CI_DB_active_record extends CI_DB_driver { $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' '.$direction : ' ASC'; } - $this->ar_orderby[] = $this->_protect_identifiers($orderby).$direction; + $this->ar_orderby[] = $this->_protect_identifiers($orderby, TRUE).$direction; + return $this; } -- cgit v1.2.3-24-g4f1b From f6cd45ccb9f8825eb44dd2fa736c7aa0082ff98c Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 18 Jan 2008 14:31:51 +0000 Subject: fix for count_all --- system/database/drivers/mssql/mssql_driver.php | 4 ++-- system/database/drivers/mysql/mysql_driver.php | 2 +- system/database/drivers/mysqli/mysqli_driver.php | 2 +- system/database/drivers/oci8/oci8_driver.php | 2 +- system/database/drivers/odbc/odbc_driver.php | 4 ++-- system/database/drivers/postgre/postgre_driver.php | 4 +--- system/database/drivers/sqlite/sqlite_driver.php | 2 +- 7 files changed, 9 insertions(+), 11 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 06a508e71..71d6c4276 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -297,8 +297,8 @@ class CI_DB_mssql_driver extends CI_DB { if ($table == '') return '0'; - $query = $this->query($this->_count_string . "FROM ".$this->dbprefix.$table); - + $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($this->dbprefix.$table)); + if ($query->num_rows() == 0) return '0'; diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 36e365165..9ba37b452 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -312,7 +312,7 @@ class CI_DB_mysql_driver extends CI_DB { if ($table == '') return '0'; - $query = $this->query($this->_count_string . "FROM `".$this->dbprefix.$table."`"); + $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($this->dbprefix.$table)); if ($query->num_rows() == 0) return '0'; diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 94a29937b..e548fb054 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -306,7 +306,7 @@ class CI_DB_mysqli_driver extends CI_DB { if ($table == '') return '0'; - $query = $this->query($this->_count_string . "FROM `".$this->dbprefix.$table."`"); + $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($this->dbprefix.$table)); if ($query->num_rows() == 0) return '0'; diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 160a56d51..56095e922 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -413,7 +413,7 @@ class CI_DB_oci8_driver extends CI_DB { if ($table == '') return '0'; - $query = $this->query($this->_count_string . "FROM ".$table); + $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($this->dbprefix.$table)); if ($query == FALSE) { diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index c5c582d0b..03f58e261 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -281,8 +281,8 @@ class CI_DB_odbc_driver extends CI_DB { if ($table == '') return '0'; - $query = $this->query($this->_count_string . "FROM `".$this->dbprefix.$table."`"); - + $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($this->dbprefix.$table)); + if ($query->num_rows() == 0) return '0'; diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index fa27f03d5..8ea76033c 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -302,9 +302,7 @@ class CI_DB_postgre_driver extends CI_DB { if ($table == '') return '0'; - $query = $this->query($this->_count_string .'FROM "'.$this->dbprefix.$table.'"'); -// original query before _count_string was used. Kept for reference -// $query = $this->query('SELECT COUNT(*) AS numrows FROM "'.$this->dbprefix.$table.'"'); + $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($this->dbprefix.$table)); if ($query->num_rows() == 0) return '0'; diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 110b208d2..31b29289f 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -298,7 +298,7 @@ class CI_DB_sqlite_driver extends CI_DB { if ($table == '') return '0'; - $query = $this->query($this->_count_string . "FROM `".$this->dbprefix.$table."`"); + $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($this->dbprefix.$table)); if ($query->num_rows() == 0) return '0'; -- cgit v1.2.3-24-g4f1b From 8f00021b55a87ec64a50d15f765160bd4e908c6b Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 18 Jan 2008 14:45:59 +0000 Subject: reset where_in array after a call (bug# 3259) --- system/database/DB_active_rec.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index c899b7f4f..c986ddec2 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -490,6 +490,8 @@ class CI_DB_active_record extends CI_DB_driver { $this->ar_where[] = $prefix . $this->_protect_identifiers($key) . $not . " IN (" . implode(", ", $this->ar_wherein) . ") "; + // reset the array for multiple calls + $this->ar_wherein = array(); return $this; } @@ -750,7 +752,6 @@ class CI_DB_active_record extends CI_DB_driver { } $this->ar_orderby[] = $this->_protect_identifiers($orderby, TRUE).$direction; - return $this; } -- cgit v1.2.3-24-g4f1b From 8435771a6f831fece5d4267e97c5e9c361dcb70b Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 18 Jan 2008 15:52:48 +0000 Subject: fixed bug #3260 tightened type checking before outputting MySQL field as NULL --- system/database/drivers/mysql/mysql_utility.php | 2 +- system/database/drivers/mysqli/mysqli_utility.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index c24a008fa..3c5b94013 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -179,7 +179,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { $v = str_replace('\\\t', '\t', $v); // Is the value NULL? - if ($v == NULL) + if ($v === NULL) { $val_str .= 'NULL'; } diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 1d910638f..3c9094611 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -180,7 +180,7 @@ class CI_DB_mysqli_utility extends CI_DB_utility { $v = str_replace('\\\t', '\t', $v); // Is the value NULL? - if ($v == NULL) + if ($v === NULL) { $val_str .= 'NULL'; } -- cgit v1.2.3-24-g4f1b From 4a9cb96df665485c1f5d0d98cd4723d4e2f45ce8 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 18 Jan 2008 18:13:13 +0000 Subject: Fixed the bugfix for #3260! --- system/database/drivers/mysql/mysql_utility.php | 18 +++++++++--------- system/database/drivers/mysqli/mysqli_utility.php | 20 ++++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 3c5b94013..220af866d 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -169,15 +169,6 @@ class CI_DB_mysql_utility extends CI_DB_utility { $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); - // Is the value NULL? if ($v === NULL) { @@ -185,6 +176,15 @@ class CI_DB_mysql_utility extends CI_DB_utility { } else { + // 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 if ($is_int[$i] == FALSE) { diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 3c9094611..869e26f52 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -170,15 +170,6 @@ class CI_DB_mysqli_utility extends CI_DB_utility { $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); - // Is the value NULL? if ($v === NULL) { @@ -186,6 +177,15 @@ class CI_DB_mysqli_utility extends CI_DB_utility { } else { + // 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 if ($is_int[$i] == FALSE) { @@ -195,7 +195,7 @@ class CI_DB_mysqli_utility extends CI_DB_utility { { $val_str .= $v; } - } + } // Append a comma $val_str .= ', '; -- cgit v1.2.3-24-g4f1b From 3d879d529107c0c9d3f1e6b894d9ed17b6e6c54f Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 18 Jan 2008 19:41:32 +0000 Subject: ExpressionEngine Dev Team in credit --- system/database/DB.php | 4 ++-- system/database/DB_active_rec.php | 4 ++-- system/database/DB_cache.php | 4 ++-- system/database/DB_driver.php | 4 ++-- system/database/DB_forge.php | 4 ++-- system/database/DB_result.php | 4 ++-- system/database/DB_utility.php | 4 ++-- system/database/drivers/mssql/mssql_driver.php | 4 ++-- system/database/drivers/mssql/mssql_forge.php | 4 ++-- system/database/drivers/mssql/mssql_result.php | 4 ++-- system/database/drivers/mssql/mssql_utility.php | 4 ++-- system/database/drivers/mysql/mysql_driver.php | 4 ++-- system/database/drivers/mysql/mysql_forge.php | 4 ++-- system/database/drivers/mysql/mysql_result.php | 4 ++-- system/database/drivers/mysql/mysql_utility.php | 4 ++-- system/database/drivers/mysqli/mysqli_driver.php | 4 ++-- system/database/drivers/mysqli/mysqli_forge.php | 4 ++-- system/database/drivers/mysqli/mysqli_result.php | 4 ++-- system/database/drivers/mysqli/mysqli_utility.php | 4 ++-- system/database/drivers/oci8/oci8_driver.php | 12 ++++++------ system/database/drivers/oci8/oci8_forge.php | 4 ++-- system/database/drivers/oci8/oci8_result.php | 10 +++++----- system/database/drivers/oci8/oci8_utility.php | 4 ++-- system/database/drivers/odbc/odbc_driver.php | 4 ++-- system/database/drivers/odbc/odbc_forge.php | 4 ++-- system/database/drivers/odbc/odbc_result.php | 4 ++-- system/database/drivers/odbc/odbc_utility.php | 4 ++-- system/database/drivers/postgre/postgre_driver.php | 4 ++-- system/database/drivers/postgre/postgre_forge.php | 4 ++-- system/database/drivers/postgre/postgre_result.php | 4 ++-- system/database/drivers/postgre/postgre_utility.php | 4 ++-- system/database/drivers/sqlite/sqlite_driver.php | 4 ++-- system/database/drivers/sqlite/sqlite_forge.php | 4 ++-- system/database/drivers/sqlite/sqlite_result.php | 4 ++-- system/database/drivers/sqlite/sqlite_utility.php | 4 ++-- 35 files changed, 77 insertions(+), 77 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index 425c8077b..b059e76a7 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -19,7 +19,7 @@ * Initialize the database * * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ function &DB($params = '', $active_record = FALSE) diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index c986ddec2..ace2a275c 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -23,7 +23,7 @@ * @package CodeIgniter * @subpackage Drivers * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_active_record extends CI_DB_driver { diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 77b951500..ac297acfe 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -19,7 +19,7 @@ * Database Cache Class * * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_Cache { diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index c2fa70a72..bffdfc639 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -25,7 +25,7 @@ * @package CodeIgniter * @subpackage Drivers * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_driver { diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index d02589457..d4f1faeba 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -19,7 +19,7 @@ * Database Utility Class * * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_forge { diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 36eddd840..7b5b384b7 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -23,7 +23,7 @@ * class for the specific database will extend and instantiate it. * * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_result { diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 372c88f1f..513664be8 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -19,7 +19,7 @@ * Database Utility Class * * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_utility extends CI_DB_forge { diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 71d6c4276..6b453abba 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -25,7 +25,7 @@ * @package CodeIgniter * @subpackage Drivers * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_mssql_driver extends CI_DB { diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php index 63a9d8396..eda308fb3 100644 --- a/system/database/drivers/mssql/mssql_forge.php +++ b/system/database/drivers/mssql/mssql_forge.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -19,7 +19,7 @@ * MS SQL Forge Class * * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_mssql_forge extends CI_DB_forge { diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index 66afd838a..ca3ca4b47 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -21,7 +21,7 @@ * This class extends the parent result class: CI_DB_result * * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_mssql_result extends CI_DB_result { diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index b020a2a6e..085271205 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -19,7 +19,7 @@ * MS SQL Utility Class * * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_mssql_utility extends CI_DB_utility { diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 9ba37b452..e876deb49 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -25,7 +25,7 @@ * @package CodeIgniter * @subpackage Drivers * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_mysql_driver extends CI_DB { diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index 8a918c026..71327f578 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -19,7 +19,7 @@ * MySQL Forge Class * * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_mysql_forge extends CI_DB_forge { diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index d1d742a07..bfbac29df 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -21,7 +21,7 @@ * This class extends the parent result class: CI_DB_result * * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_mysql_result extends CI_DB_result { diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 220af866d..38feaaff1 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -19,7 +19,7 @@ * MySQL Utility Class * * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_mysql_utility extends CI_DB_utility { diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index e548fb054..bfdabe19a 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -25,7 +25,7 @@ * @package CodeIgniter * @subpackage Drivers * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_mysqli_driver extends CI_DB { diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index 3da5d2c49..388c66525 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -19,7 +19,7 @@ * MySQLi Forge Class * * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_mysqli_forge extends CI_DB_forge { diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index 913a7dd3d..6861da793 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -21,7 +21,7 @@ * This class extends the parent result class: CI_DB_result * * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_mysqli_result extends CI_DB_result { diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 869e26f52..2aa5eccd9 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -19,7 +19,7 @@ * MySQLi Utility Class * * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_mysqli_utility extends CI_DB_utility { diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 56095e922..820501c04 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -4,12 +4,12 @@ * * An open source application development framework for PHP 4.3.2 or newer * - * @package CodeIgniter - * @author Rick Ellis + * @package CodeIgniter + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com - * @since Version 1.0 + * @since Version 1.0 * @filesource */ @@ -22,10 +22,10 @@ * creates dynamically based on whether the active record * class is being used or not. * - * @package CodeIgniter + * @package CodeIgniter * @subpackage Drivers * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index c982e66a3..57f2885b3 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -19,7 +19,7 @@ * Oracle Forge Class * * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_oci8_forge extends CI_DB_forge { diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index cb27caf58..b1a703b27 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -4,12 +4,12 @@ * * An open source application development framework for PHP 4.3.2 or newer * - * @package CodeIgniter - * @author Rick Ellis + * @package CodeIgniter + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com - * @since Version 1.0 + * @since Version 1.0 * @filesource */ @@ -21,7 +21,7 @@ * This class extends the parent result class: CI_DB_result * * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_oci8_result extends CI_DB_result { diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 67296da5b..6b53a4f24 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -19,7 +19,7 @@ * Oracle Utility Class * * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_oci8_utility extends CI_DB_utility { diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 03f58e261..c4a3df16f 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -25,7 +25,7 @@ * @package CodeIgniter * @subpackage Drivers * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_odbc_driver extends CI_DB { diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php index 1d79344c1..455cb0ff9 100644 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -19,7 +19,7 @@ * ODBC Forge Class * * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/database/ */ class CI_DB_odbc_forge extends CI_DB_forge { diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index 53c317356..c818c3379 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -21,7 +21,7 @@ * This class extends the parent result class: CI_DB_result * * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_odbc_result extends CI_DB_result { diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index d64d15af5..561a6e4b0 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -19,7 +19,7 @@ * ODBC Utility Class * * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/database/ */ class CI_DB_odbc_utility extends CI_DB_utility { diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 8ea76033c..5bf87c597 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -25,7 +25,7 @@ * @package CodeIgniter * @subpackage Drivers * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_postgre_driver extends CI_DB { diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index 34bbe88b6..e3d6a8f70 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -19,7 +19,7 @@ * Postgre Forge Class * * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_postgre_forge extends CI_DB_forge { diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index 9fd2a7e93..d09e5730b 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -21,7 +21,7 @@ * This class extends the parent result class: CI_DB_result * * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_postgre_result extends CI_DB_result { diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index a706d9505..240e1b7df 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -19,7 +19,7 @@ * Postgre Utility Class * * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_postgre_utility extends CI_DB_utility { diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 31b29289f..60289c742 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -27,7 +27,7 @@ * @package CodeIgniter * @subpackage Drivers * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_sqlite_driver extends CI_DB { diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php index 54b65987d..efc94fbf1 100644 --- a/system/database/drivers/sqlite/sqlite_forge.php +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -19,7 +19,7 @@ * SQLite Forge Class * * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_sqlite_forge extends CI_DB_forge { diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index 0939c87b8..859b65ff5 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -21,7 +21,7 @@ * This class extends the parent result class: CI_DB_result * * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_sqlite_result extends CI_DB_result { diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 1c78c54b7..c2f8b9bb7 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -19,7 +19,7 @@ * SQLite Utility Class * * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_sqlite_utility extends CI_DB_utility { -- cgit v1.2.3-24-g4f1b From df264429b7171da21524be93d38e334fadec801b Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 21 Jan 2008 16:48:11 +0000 Subject: added dbprefix to dbforge functions --- system/database/DB_forge.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index d4f1faeba..f8b74c089 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -180,7 +180,7 @@ class CI_DB_forge { show_error('Field information is required.'); } - $sql = $this->_create_table($table, $this->fields, $this->primary_keys, $this->keys, $if_not_exists); + $sql = $this->_create_table($this->db->dbprefix.$table, $this->fields, $this->primary_keys, $this->keys, $if_not_exists); $this->_reset(); return $this->db->query($sql); @@ -197,7 +197,7 @@ class CI_DB_forge { */ function drop_table($table_name) { - $sql = $this->_drop_table($table_name); + $sql = $this->_drop_table($this->db->dbprefix.$table_name); if (is_bool($sql)) { @@ -234,7 +234,7 @@ class CI_DB_forge { show_error('Field information is required.'); } - $sql = $this->_alter_table('ADD', $table, $this->fields, $after_field); + $sql = $this->_alter_table('ADD', $this->db->dbprefix.$table, $this->fields, $after_field); $this->_reset(); return $this->db->query($sql); @@ -263,7 +263,7 @@ class CI_DB_forge { show_error('A column name is required for that operation.'); } - $sql = $this->_alter_table('DROP', $table, $column_name); + $sql = $this->_alter_table('DROP', $this->db->dbprefix.$table, $column_name); return $this->db->query($sql); } @@ -296,7 +296,7 @@ class CI_DB_forge { show_error('Field information is required.'); } - $sql = $this->_alter_table('CHANGE', $table, $this->fields); + $sql = $this->_alter_table('CHANGE', $this->db->dbprefix.$table, $this->fields); $this->_reset(); return $this->db->query($sql); -- cgit v1.2.3-24-g4f1b From 7a9193afa6d890a91eb3528fa0e62df799b07ed6 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 21 Jan 2008 18:39:20 +0000 Subject: replaced www.codeigniter.com with codeigniter.com --- system/database/DB.php | 6 +++--- system/database/DB_active_rec.php | 6 +++--- system/database/DB_cache.php | 6 +++--- system/database/DB_driver.php | 6 +++--- system/database/DB_forge.php | 6 +++--- system/database/DB_result.php | 6 +++--- system/database/DB_utility.php | 6 +++--- system/database/drivers/mssql/mssql_driver.php | 6 +++--- system/database/drivers/mssql/mssql_forge.php | 6 +++--- system/database/drivers/mssql/mssql_result.php | 6 +++--- system/database/drivers/mssql/mssql_utility.php | 6 +++--- system/database/drivers/mysql/mysql_driver.php | 6 +++--- system/database/drivers/mysql/mysql_forge.php | 6 +++--- system/database/drivers/mysql/mysql_result.php | 6 +++--- system/database/drivers/mysql/mysql_utility.php | 6 +++--- system/database/drivers/mysqli/mysqli_driver.php | 6 +++--- system/database/drivers/mysqli/mysqli_forge.php | 6 +++--- system/database/drivers/mysqli/mysqli_result.php | 6 +++--- system/database/drivers/mysqli/mysqli_utility.php | 6 +++--- system/database/drivers/oci8/oci8_driver.php | 6 +++--- system/database/drivers/oci8/oci8_forge.php | 6 +++--- system/database/drivers/oci8/oci8_result.php | 6 +++--- system/database/drivers/oci8/oci8_utility.php | 6 +++--- system/database/drivers/odbc/odbc_driver.php | 6 +++--- system/database/drivers/odbc/odbc_forge.php | 6 +++--- system/database/drivers/odbc/odbc_result.php | 6 +++--- system/database/drivers/odbc/odbc_utility.php | 6 +++--- system/database/drivers/postgre/postgre_driver.php | 6 +++--- system/database/drivers/postgre/postgre_forge.php | 6 +++--- system/database/drivers/postgre/postgre_result.php | 6 +++--- system/database/drivers/postgre/postgre_utility.php | 6 +++--- system/database/drivers/sqlite/sqlite_driver.php | 6 +++--- system/database/drivers/sqlite/sqlite_forge.php | 6 +++--- system/database/drivers/sqlite/sqlite_result.php | 6 +++--- system/database/drivers/sqlite/sqlite_utility.php | 6 +++--- 35 files changed, 105 insertions(+), 105 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index b059e76a7..abd782c34 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -20,7 +20,7 @@ * * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ function &DB($params = '', $active_record = FALSE) { diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index ace2a275c..08213af5c 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -24,7 +24,7 @@ * @subpackage Drivers * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_active_record extends CI_DB_driver { diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index ac297acfe..44b8e815f 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -20,7 +20,7 @@ * * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_Cache { diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index bffdfc639..65be13dc9 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -26,7 +26,7 @@ * @subpackage Drivers * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_driver { diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index f8b74c089..7febb72c2 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -20,7 +20,7 @@ * * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_forge { diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 7b5b384b7..7d5097911 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -24,7 +24,7 @@ * * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_result { diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 513664be8..9b78aa8ec 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -20,7 +20,7 @@ * * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_utility extends CI_DB_forge { diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 6b453abba..e0c4db75c 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -26,7 +26,7 @@ * @subpackage Drivers * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_mssql_driver extends CI_DB { diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php index eda308fb3..baf776c74 100644 --- a/system/database/drivers/mssql/mssql_forge.php +++ b/system/database/drivers/mssql/mssql_forge.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -20,7 +20,7 @@ * * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_mssql_forge extends CI_DB_forge { diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index ca3ca4b47..c95fd91f6 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -22,7 +22,7 @@ * * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_mssql_result extends CI_DB_result { diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index 085271205..87f8196f7 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -20,7 +20,7 @@ * * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_mssql_utility extends CI_DB_utility { diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index e876deb49..6e53537b4 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -26,7 +26,7 @@ * @subpackage Drivers * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_mysql_driver extends CI_DB { diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index 71327f578..6e3a2d170 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -20,7 +20,7 @@ * * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_mysql_forge extends CI_DB_forge { diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index bfbac29df..9e6a3c3d1 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -22,7 +22,7 @@ * * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_mysql_result extends CI_DB_result { diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 38feaaff1..dc8fd0866 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -20,7 +20,7 @@ * * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_mysql_utility extends CI_DB_utility { diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index bfdabe19a..d645cc820 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -26,7 +26,7 @@ * @subpackage Drivers * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_mysqli_driver extends CI_DB { diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index 388c66525..cb315a450 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -20,7 +20,7 @@ * * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_mysqli_forge extends CI_DB_forge { diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index 6861da793..586c29252 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -22,7 +22,7 @@ * * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_mysqli_result extends CI_DB_result { diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 2aa5eccd9..bb1f6f917 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -20,7 +20,7 @@ * * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_mysqli_utility extends CI_DB_utility { diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 820501c04..bc0862b5e 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -26,7 +26,7 @@ * @subpackage Drivers * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ /** diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index 57f2885b3..b9d9e6354 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -20,7 +20,7 @@ * * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_oci8_forge extends CI_DB_forge { diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index b1a703b27..30dd0da09 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -22,7 +22,7 @@ * * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_oci8_result extends CI_DB_result { diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 6b53a4f24..117f8e629 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -20,7 +20,7 @@ * * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_oci8_utility extends CI_DB_utility { diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index c4a3df16f..daecabe13 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -26,7 +26,7 @@ * @subpackage Drivers * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_odbc_driver extends CI_DB { diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php index 455cb0ff9..374c15fcd 100644 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -20,7 +20,7 @@ * * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/database/ + * @link http://codeigniter.com/database/ */ class CI_DB_odbc_forge extends CI_DB_forge { diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index c818c3379..dd3f92382 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -22,7 +22,7 @@ * * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_odbc_result extends CI_DB_result { diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index 561a6e4b0..f74d031bd 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -20,7 +20,7 @@ * * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/database/ + * @link http://codeigniter.com/database/ */ class CI_DB_odbc_utility extends CI_DB_utility { diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 5bf87c597..34d76de61 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -26,7 +26,7 @@ * @subpackage Drivers * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_postgre_driver extends CI_DB { diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index e3d6a8f70..81ac8e92b 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -20,7 +20,7 @@ * * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_postgre_forge extends CI_DB_forge { diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index d09e5730b..fdce01aac 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -22,7 +22,7 @@ * * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_postgre_result extends CI_DB_result { diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 240e1b7df..573654f68 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -20,7 +20,7 @@ * * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_postgre_utility extends CI_DB_utility { diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 60289c742..9cc69bb63 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -28,7 +28,7 @@ * @subpackage Drivers * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_sqlite_driver extends CI_DB { diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php index efc94fbf1..e3196cce1 100644 --- a/system/database/drivers/sqlite/sqlite_forge.php +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -20,7 +20,7 @@ * * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_sqlite_forge extends CI_DB_forge { diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index 859b65ff5..b8f3dc5b7 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -22,7 +22,7 @@ * * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_sqlite_result extends CI_DB_result { diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index c2f8b9bb7..d1e1fe026 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -20,7 +20,7 @@ * * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_sqlite_utility extends CI_DB_utility { -- cgit v1.2.3-24-g4f1b From 2e061440560701f68dd2d65d8d56355f4bdfe6f4 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 22 Jan 2008 21:13:12 +0000 Subject: added enclosures to csv_from _result() --- system/database/DB_utility.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 9b78aa8ec..d9b8fed74 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -168,11 +168,12 @@ class CI_DB_utility extends CI_DB_forge { * * @access public * @param object The query result object - * @param string The delimiter - tab by default + * @param string The delimiter - comma by default * @param string The newline character - \n by default + * @param string The enclosure - double quote by default * @return string */ - function csv_from_result($query, $delim = "\t", $newline = "\n") + function csv_from_result($query, $delim = ",", $newline = "\n", $enclosure = '"') { if ( ! is_object($query) OR ! method_exists($query, 'field_names')) { @@ -184,7 +185,7 @@ class CI_DB_utility extends CI_DB_forge { // First generate the headings from the table column names foreach ($query->list_fields() as $name) { - $out .= $name.$delim; + $out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $name).$enclosure.$delim; } $out = rtrim($out); @@ -195,7 +196,7 @@ class CI_DB_utility extends CI_DB_forge { { foreach ($row as $item) { - $out .= $item.$delim; + $out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $item).$enclosure.$delim; } $out = rtrim($out); $out .= $newline; -- cgit v1.2.3-24-g4f1b From 3b11868b3aa56c83419d904435a5b7dfbf997063 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 22 Jan 2008 23:44:32 +0000 Subject: Added $this->db->dbprefix() to manually add database prefixes. --- system/database/DB_active_rec.php | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 08213af5c..ba68e1e8f 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://codeigniter.com/user_guide/license.html - * @link http://codeigniter.com + * @license http://www.codeigniter.com/user_guide/license.html + * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ @@ -24,7 +24,7 @@ * @subpackage Drivers * @category Database * @author ExpressionEngine Dev Team - * @link http://codeigniter.com/user_guide/database/ + * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_active_record extends CI_DB_driver { @@ -44,6 +44,27 @@ class CI_DB_active_record extends CI_DB_driver { var $ar_wherein = array(); var $ar_aliased_tables = array(); + /** + * DB Prefix + * + * Prepends a database prefix if one exists in configuration + * + * @access public + * @param string the table + * @return string + */ + function dbprefix($table = '') + { + if ($table == '') + { + $this->display_error('db_table_name_required'); + } + + return $this->dbprefix.$table; + } + + // -------------------------------------------------------------------- + /** * Select * -- cgit v1.2.3-24-g4f1b From cdd2ab25d134c67447e1f1f63c28992f8d0a5b68 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 23 Jan 2008 00:05:38 +0000 Subject: fixing www.codeigniter.com to codeigniter.com --- system/database/DB_active_rec.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index ba68e1e8f..0455b981e 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -24,7 +24,7 @@ * @subpackage Drivers * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_active_record extends CI_DB_driver { -- cgit v1.2.3-24-g4f1b From db708af87341897cbc7fd1157291377c253d371f Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 23 Jan 2008 17:18:41 +0000 Subject: added an "unsupported" error to insert_id() in oracle --- system/database/drivers/oci8/oci8_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index bc0862b5e..99f7d57bd 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -393,7 +393,7 @@ class CI_DB_oci8_driver extends CI_DB { function insert_id() { // not supported in oracle - return 0; + return $this->display_error('db_unsupported_function'); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 56e9fa581b9e7d590dfb56482b898339f29bd8f2 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 23 Jan 2008 17:26:37 +0000 Subject: added $query_times property to DB driver for profiling added individual query execution time to profiler output --- system/database/DB_driver.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 65be13dc9..dbd54bebe 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -48,6 +48,7 @@ class CI_DB_driver { var $bind_marker = '?'; var $save_queries = TRUE; var $queries = array(); + var $query_times = array(); var $data_cache = array(); var $trans_enabled = TRUE; var $_trans_depth = 0; @@ -341,6 +342,11 @@ class CI_DB_driver { $time_end = list($em, $es) = explode(' ', microtime()); $this->benchmark += ($em + $es) - ($sm + $ss); + if ($this->save_queries == TRUE) + { + $this->query_times[] = ($em + $es) - ($sm + $ss); + } + // Increment the query counter $this->query_count++; -- cgit v1.2.3-24-g4f1b From 4acd792e54f58a5d86269057b5a827440fc2efcd Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sat, 26 Jan 2008 19:33:59 +0000 Subject: fix a postgre escape error --- system/database/drivers/postgre/postgre_driver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 34d76de61..96cf2dfe9 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -451,7 +451,7 @@ class CI_DB_postgre_driver extends CI_DB { } else { - return ""{$item}""; + return "\"{$item}\""; } $exceptions = array('AS', '/', '-', '%', '+', '*'); @@ -459,7 +459,7 @@ class CI_DB_postgre_driver extends CI_DB { foreach ($exceptions as $exception) { - if (stristr($item, " "{$exception}" ") !== FALSE) + if (stristr($item, " \"{$exception}\" ") !== FALSE) { $item = preg_replace('/ "('.preg_quote($exception).')" /i', ' $1 ', $item); } -- cgit v1.2.3-24-g4f1b From b52bdc4e9e1b21ddfd0ff3231e09042258cb1399 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 27 Jan 2008 14:58:24 +0000 Subject: fixed a variable call to $this-> --- system/database/drivers/odbc/odbc_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index daecabe13..604dd778c 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -41,7 +41,7 @@ class CI_DB_odbc_driver extends CI_DB { function CI_DB_odbc_driver() { - $_random_keyword = ' RND('.time().')'; // database specific random keyword + $this->_random_keyword = ' RND('.time().')'; // database specific random keyword } /** -- cgit v1.2.3-24-g4f1b From 1a704ceb6712b7f27402f4806f3894f48564e131 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 27 Jan 2008 15:03:06 +0000 Subject: fixed an overwritten parameter in protect_identifiers --- system/database/DB_driver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index dbd54bebe..966fd3ad5 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -652,7 +652,7 @@ class CI_DB_driver { */ function protect_identifiers($item, $first_word_only = FALSE) { - return $this->_protect_identifiers($item, $first_word_only = FALSE); + return $this->_protect_identifiers($item, $first_word_only); } // -------------------------------------------------------------------- @@ -1136,7 +1136,7 @@ class CI_DB_driver { $LANG = new CI_Language(); $LANG->load('db'); - $heading = 'MySQL Error'; + $heading = 'Database Error'; if ($native == TRUE) { -- cgit v1.2.3-24-g4f1b From 50bce4e0745eda3d148ee8112c18c2b3ab2b6be8 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 27 Jan 2008 15:06:28 +0000 Subject: fix extraneous returns and variables --- system/database/DB_active_rec.php | 5 ----- 1 file changed, 5 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 0455b981e..1ad4f3d1f 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -124,8 +124,6 @@ class CI_DB_active_record extends CI_DB_driver { $this->ar_select[] = $sql; return $this; - - return $this; } // -------------------------------------------------------------------- @@ -1246,7 +1244,6 @@ class CI_DB_active_record extends CI_DB_driver { function use_table($table) { return $this->from($table); - return $this; } // -------------------------------------------------------------------- @@ -1307,8 +1304,6 @@ class CI_DB_active_record extends CI_DB_driver { */ function _filter_table_aliases($statements) { - $statements_without_aliases = array(); - foreach ($statements as $k => $v) { foreach ($this->ar_aliased_tables as $table) -- cgit v1.2.3-24-g4f1b From a25530f6594c7ba45b3faa9537fda9f807069759 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 28 Jan 2008 17:11:02 +0000 Subject: added is_really_writable() to Common.php, replaced is_writable() throughout application with is_really_writable() --- system/database/DB_cache.php | 3 --- 1 file changed, 3 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 44b8e815f..ad54fc315 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -63,9 +63,6 @@ class CI_DB_Cache { // Add a trailing slash to the path if needed $path = preg_replace("/(.+?)\/*$/", "\\1/", $path); - - // Load the file helper - $this->CI->load->helper('file'); if ( ! is_dir($path) OR ! is_really_writable($path)) { -- cgit v1.2.3-24-g4f1b From c6ad0237eb6957046343ca654ab1c7d26787d466 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 29 Jan 2008 18:44:54 +0000 Subject: Abstracted FROM table listing in Active Record for databases that do not support parenthetic grouping of tables to explicitly define operator precedence --- system/database/DB_active_rec.php | 2 +- system/database/drivers/mssql/mssql_driver.php | 22 ++++++++++++++++++++++ system/database/drivers/mysql/mysql_driver.php | 22 ++++++++++++++++++++++ system/database/drivers/mysqli/mysqli_driver.php | 22 ++++++++++++++++++++++ system/database/drivers/oci8/oci8_driver.php | 22 ++++++++++++++++++++++ system/database/drivers/odbc/odbc_driver.php | 22 ++++++++++++++++++++++ system/database/drivers/postgre/postgre_driver.php | 22 ++++++++++++++++++++++ system/database/drivers/sqlite/sqlite_driver.php | 22 ++++++++++++++++++++++ 8 files changed, 155 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 1ad4f3d1f..37bf9ed05 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1343,7 +1343,7 @@ class CI_DB_active_record extends CI_DB_driver { if (count($this->ar_from) > 0) { $sql .= "\nFROM "; - $sql .= '(' . implode(', ', $this->ar_from) . ')'; + $sql .= $this->_from_tables($this->ar_from); } if (count($this->ar_join) > 0) diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index e0c4db75c..ad747d4ad 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -438,6 +438,28 @@ class CI_DB_mssql_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * From Tables + * + * This function implicitly groups FROM tables so there is no confusion + * about operator precedence in harmony with SQL standards + * + * @access public + * @param type + * @return type + */ + function _from_tables($tables) + { + if (! is_array($tables)) + { + $tables = array($tables); + } + + return implode(', ', $tables); + } + + // -------------------------------------------------------------------- + /** * Insert statement * diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 6e53537b4..f00257250 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -479,6 +479,28 @@ class CI_DB_mysql_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * From Tables + * + * This function implicitly groups FROM tables so there is no confusion + * about operator precedence in harmony with SQL standards + * + * @access public + * @param type + * @return type + */ + function _from_tables($tables) + { + if (! is_array($tables)) + { + $tables = array($tables); + } + + return '('.implode(', ', $tables).')'; + } + + // -------------------------------------------------------------------- + /** * Insert statement * diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index d645cc820..b2e97f927 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -473,6 +473,28 @@ class CI_DB_mysqli_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * From Tables + * + * This function implicitly groups FROM tables so there is no confusion + * about operator precedence in harmony with SQL standards + * + * @access public + * @param type + * @return type + */ + function _from_tables($tables) + { + if (! is_array($tables)) + { + $tables = array($tables); + } + + return '('.implode(', ', $tables).')'; + } + + // -------------------------------------------------------------------- + /** * Insert statement * diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 99f7d57bd..ddc0fba99 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -584,6 +584,28 @@ class CI_DB_oci8_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * From Tables + * + * This function implicitly groups FROM tables so there is no confusion + * about operator precedence in harmony with SQL standards + * + * @access public + * @param type + * @return type + */ + function _from_tables($tables) + { + if (! is_array($tables)) + { + $tables = array($tables); + } + + return '('.implode(', ', $tables).')'; + } + + // -------------------------------------------------------------------- + /** * Insert statement * diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 604dd778c..03c0e6a86 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -449,6 +449,28 @@ class CI_DB_odbc_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * From Tables + * + * This function implicitly groups FROM tables so there is no confusion + * about operator precedence in harmony with SQL standards + * + * @access public + * @param type + * @return type + */ + function _from_tables($tables) + { + if (! is_array($tables)) + { + $tables = array($tables); + } + + return '('.implode(', ', $tables).')'; + } + + // -------------------------------------------------------------------- + /** * Insert statement * diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 96cf2dfe9..20f91650a 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -469,6 +469,28 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * From Tables + * + * This function implicitly groups FROM tables so there is no confusion + * about operator precedence in harmony with SQL standards + * + * @access public + * @param type + * @return type + */ + function _from_tables($tables) + { + if (! is_array($tables)) + { + $tables = array($tables); + } + + return '('.implode(', ', $tables).')'; + } + + // -------------------------------------------------------------------- + /** * Insert statement * diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 9cc69bb63..38febca29 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -465,6 +465,28 @@ class CI_DB_sqlite_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * From Tables + * + * This function implicitly groups FROM tables so there is no confusion + * about operator precedence in harmony with SQL standards + * + * @access public + * @param type + * @return type + */ + function _from_tables($tables) + { + if (! is_array($tables)) + { + $tables = array($tables); + } + + return '('.implode(', ', $tables).')'; + } + + // -------------------------------------------------------------------- + /** * Insert statement * -- cgit v1.2.3-24-g4f1b From 11c75eab4d04b9c88b0096015fb3c0711555bf9a Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 29 Jan 2008 19:35:31 +0000 Subject: Removed support for db_backup in MySQLi due to incompatible functions. --- system/database/drivers/mysqli/mysqli_utility.php | 138 +--------------------- 1 file changed, 3 insertions(+), 135 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index bb1f6f917..4ab2bb1d1 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -78,143 +78,11 @@ class CI_DB_mysqli_utility extends CI_DB_utility { */ 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)) - { - // 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'), - 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) - { - // Is the value NULL? - if ($v === NULL) - { - $val_str .= 'NULL'; - } - else - { - // 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 - if ($is_int[$i] == FALSE) - { - $val_str .= $this->db->escape($v); - } - 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; - } - - return $output; + // Currently unsupported + return $this->db->display_error('db_unsuported_feature'); } + /** * * The functions below have been deprecated as of 1.6, and are only here for backwards -- cgit v1.2.3-24-g4f1b From 75d568db823b8fe7526e416f5e3f1c2c235f5473 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 30 Jan 2008 20:26:25 +0000 Subject: removed 'active_r' db config variable, replaced with global $active_record setting. (bug report #1834) --- system/database/DB.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index abd782c34..8f25e5e1a 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -22,7 +22,7 @@ * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/database/ */ -function &DB($params = '', $active_record = FALSE) +function &DB($params = '', $active_record_override = FALSE) { // Load the DB config file if a DSN string wasn't passed if (is_string($params) AND strpos($params, '://') === FALSE) @@ -58,14 +58,14 @@ function &DB($params = '', $active_record = FALSE) // based on whether we're using the active record class or not. // Kudos to Paul for discovering this clever use of eval() - if ($active_record == TRUE) + if ($active_record_override == TRUE) { - $params['active_r'] = TRUE; + $active_record = TRUE; } require_once(BASEPATH.'database/DB_driver'.EXT); - if ( ! isset($params['active_r']) OR $params['active_r'] == TRUE) + if ($active_record == TRUE) { require_once(BASEPATH.'database/DB_active_rec'.EXT); -- cgit v1.2.3-24-g4f1b From 4e1241bbe6c0459c28d9a7cda89ef1c81dec1bd4 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 30 Jan 2008 21:00:33 +0000 Subject: added default value for $active_record when it's not set --- system/database/DB.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index 8f25e5e1a..078f1ef0f 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -65,7 +65,7 @@ function &DB($params = '', $active_record_override = FALSE) require_once(BASEPATH.'database/DB_driver'.EXT); - if ($active_record == TRUE) + if (! isset($active_record) OR $active_record == TRUE) { require_once(BASEPATH.'database/DB_active_rec'.EXT); -- cgit v1.2.3-24-g4f1b From 4a310b7aef013a02288fc0b37571c841c10323f7 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 30 Jan 2008 21:32:47 +0000 Subject: fix orlike to call or_like --- system/database/DB_active_rec.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 37bf9ed05..e93b99e3d 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -595,7 +595,7 @@ class CI_DB_active_record extends CI_DB_driver { */ function orlike($field, $match = '', $side = 'both') { - return $this->orlike($field, $match, $side); + return $this->or_like($field, $match, $side); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 7b80700a88e3e3a9ad46fe484e1cbfc3bd353b91 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 31 Jan 2008 23:52:01 +0000 Subject: remove parenthesis from postrgre _from_tables --- system/database/drivers/postgre/postgre_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 20f91650a..e72981348 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -486,7 +486,7 @@ class CI_DB_postgre_driver extends CI_DB { $tables = array($tables); } - return '('.implode(', ', $tables).')'; + return implode(', ', $tables); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 9b3e7b5f2d4ec4feae793ef90454506addbb19e1 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 4 Feb 2008 23:20:34 +0000 Subject: Added and documented Active Record caching. Made AR fully database-prefix aware --- system/database/DB_active_rec.php | 313 ++++++++++++++++++--- system/database/drivers/mssql/mssql_driver.php | 7 + system/database/drivers/mysql/mysql_driver.php | 7 + system/database/drivers/mysqli/mysqli_driver.php | 7 + system/database/drivers/oci8/oci8_driver.php | 7 + system/database/drivers/odbc/odbc_driver.php | 7 + system/database/drivers/postgre/postgre_driver.php | 9 +- system/database/drivers/sqlite/sqlite_driver.php | 7 + 8 files changed, 322 insertions(+), 42 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index e93b99e3d..b3bf02a8b 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -43,6 +43,23 @@ class CI_DB_active_record extends CI_DB_driver { var $ar_set = array(); var $ar_wherein = array(); var $ar_aliased_tables = array(); + var $ar_store_array = array(); + + // Active Record Caching variables + var $ar_caching = FALSE; + var $ar_cache_select = array(); + var $ar_cache_from = array(); + var $ar_cache_join = array(); + var $ar_cache_where = array(); + var $ar_cache_like = array(); + var $ar_cache_groupby = array(); + var $ar_cache_having = array(); + var $ar_cache_limit = FALSE; + var $ar_cache_offset = FALSE; + var $ar_cache_order = FALSE; + var $ar_cache_orderby = array(); + var $ar_cache_set = array(); + /** * DB Prefix @@ -87,12 +104,23 @@ class CI_DB_active_record extends CI_DB_driver { if ($val != '*' && $protect_identifiers !== FALSE) { - $val = $this->_protect_identifiers($val); + if (strpos($val, '.') !== FALSE) + { + $val = $this->dbprefix.$val; + } + else + { + $val = $this->_protect_identifiers($val); + } } if ($val != '') { $this->ar_select[] = $val; + if ($this->ar_caching === TRUE) + { + $this->ar_cache_select[] = $val; + } } } return $this; @@ -122,6 +150,10 @@ class CI_DB_active_record extends CI_DB_driver { $sql = 'MAX('.$this->_protect_identifiers(trim($select)).') AS '.$this->_protect_identifiers(trim($alias)); $this->ar_select[] = $sql; + if ($this->ar_caching === TRUE) + { + $this->ar_cache_select[] = $sql; + } return $this; } @@ -150,7 +182,11 @@ class CI_DB_active_record extends CI_DB_driver { $sql = 'MIN('.$this->_protect_identifiers(trim($select)).') AS '.$this->_protect_identifiers(trim($alias)); $this->ar_select[] = $sql; - + if ($this->ar_caching === TRUE) + { + $this->ar_cache_select[] = $sql; + } + return $this; } @@ -178,7 +214,11 @@ class CI_DB_active_record extends CI_DB_driver { $sql = 'AVG('.$this->_protect_identifiers(trim($select)).') AS '.$this->_protect_identifiers(trim($alias)); $this->ar_select[] = $sql; - + if ($this->ar_caching === TRUE) + { + $this->ar_cache_select[] = $sql; + } + return $this; } @@ -206,7 +246,11 @@ class CI_DB_active_record extends CI_DB_driver { $sql = 'SUM('.$this->_protect_identifiers(trim($select)).') AS '.$this->_protect_identifiers(trim($alias)); $this->ar_select[] = $sql; - + if ($this->ar_caching === TRUE) + { + $this->ar_cache_select[] = $sql; + } + return $this; } @@ -243,6 +287,10 @@ class CI_DB_active_record extends CI_DB_driver { foreach ((array)$from as $val) { $this->ar_from[] = $this->_protect_identifiers($this->_track_aliases($val)); + if ($this->ar_caching === TRUE) + { + $this->ar_cache_from[] = $this->_protect_identifiers($val); + } } return $this; @@ -289,7 +337,14 @@ class CI_DB_active_record extends CI_DB_driver { $cond = preg_replace('|([\w\.]+)([\W\s]+)(.+)|', $this->dbprefix . "$1$2" . $this->dbprefix . "$3", $cond); } - $this->ar_join[] = $type.'JOIN '.$this->_protect_identifiers($this->dbprefix.$table, TRUE).' ON '.$cond; + $join = $type.'JOIN '.$this->_protect_identifiers($this->dbprefix.$table, TRUE).' ON '.$cond; + + $this->ar_join[] = $join; + if ($this->ar_caching === TRUE) + { + $this->ar_cache_join[] = $join; + } + return $this; } @@ -360,7 +415,7 @@ class CI_DB_active_record extends CI_DB_driver { { $key = array($key => $value); } - + foreach ($key as $k => $v) { $prefix = (count($this->ar_where) == 0) ? '' : $type; @@ -393,10 +448,18 @@ class CI_DB_active_record extends CI_DB_driver { } $v = ' '.$this->escape($v); - } - + else + { + $k = $this->_protect_identifiers($k, TRUE); + } + $this->ar_where[] = $prefix.$k.$v; + if ($this->ar_caching === TRUE) + { + $this->ar_cache_where[] = $prefix.$k.$v; + } + } return $this; } @@ -507,7 +570,13 @@ class CI_DB_active_record extends CI_DB_driver { $prefix = (count($this->ar_where) == 0) ? '' : $type; - $this->ar_where[] = $prefix . $this->_protect_identifiers($key) . $not . " IN (" . implode(", ", $this->ar_wherein) . ") "; + $where_in = $prefix . $this->_protect_identifiers($key) . $not . " IN (" . implode(", ", $this->ar_wherein) . ") "; + + $this->ar_where[] = $where_in; + if ($this->ar_caching === TRUE) + { + $this->ar_cache_where[] = $where_in; + } // reset the array for multiple calls $this->ar_wherein = array(); @@ -629,16 +698,23 @@ class CI_DB_active_record extends CI_DB_driver { if ($side == 'before') { - $this->ar_like[] = $prefix." $k $not LIKE '%{$v}'"; + $like_statement = $prefix." $k $not LIKE '%{$v}'"; } elseif ($side == 'after') { - $this->ar_like[] = $prefix." $k $not LIKE '{$v}%'"; + $like_statement = $prefix." $k $not LIKE '{$v}%'"; } else { - $this->ar_like[] = $prefix." $k $not LIKE '%{$v}%'"; + $like_statement = $prefix." $k $not LIKE '%{$v}%'"; } + + $this->ar_like[] = $like_statement; + if ($this->ar_caching === TRUE) + { + $this->ar_cache_like[] = $like_statement; + } + } return $this; } @@ -664,7 +740,13 @@ class CI_DB_active_record extends CI_DB_driver { $val = trim($val); if ($val != '') + { $this->ar_groupby[] = $this->_protect_identifiers($val); + if ($this->ar_caching === TRUE) + { + $this->ar_cache_groupby[] = $this->_protect_identifiers($val); + } + } } return $this; } @@ -724,6 +806,7 @@ class CI_DB_active_record extends CI_DB_driver { * * @access private * @param string + * @param string * @return object */ @@ -737,14 +820,20 @@ class CI_DB_active_record extends CI_DB_driver { foreach ($key as $k => $v) { $prefix = (count($this->ar_having) == 0) ? '' : $type; + $k = $this->_protect_identifiers($k); if ($v != '') { - $v = ' '.$this->escape($v); + $v = ' '.$this->escape_str($v); } $this->ar_having[] = $prefix.$k.$v; + if ($this->ar_caching === TRUE) + { + $this->ar_cache_having[] = $prefix.$k.$v; + } } + return $this; } @@ -770,7 +859,14 @@ class CI_DB_active_record extends CI_DB_driver { $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' '.$direction : ' ASC'; } - $this->ar_orderby[] = $this->_protect_identifiers($orderby, TRUE).$direction; + $orderby_statement = $this->_protect_identifiers($orderby, TRUE).$direction; + + $this->ar_orderby[] = $orderby_statement; + if ($this->ar_caching === TRUE) + { + $this->ar_cache_orderby[] = $orderby_statement; + } + return $this; } @@ -799,9 +895,19 @@ class CI_DB_active_record extends CI_DB_driver { function limit($value, $offset = '') { $this->ar_limit = $value; - + if ($this->ar_caching === TRUE) + { + $this->ar_cache_limit[] = $value; + } + if ($offset != '') + { $this->ar_offset = $offset; + if ($this->ar_caching === TRUE) + { + $this->ar_cache_offset[] = $offset; + } + } return $this; } @@ -815,9 +921,14 @@ class CI_DB_active_record extends CI_DB_driver { * @param integer the offset value * @return object */ - function offset($value) + function offset($offset) { - $this->ar_offset = $value; + $this->ar_offset = $offset; + if ($this->ar_caching === TRUE) + { + $this->ar_cache_offset[] = $offset; + } + return $this; } @@ -846,12 +957,19 @@ class CI_DB_active_record extends CI_DB_driver { if ($escape === FALSE) { $this->ar_set[$this->_protect_identifiers($k)] = $v; + if ($this->ar_caching === TRUE) + { + $this->ar_cache_offset[$this->_protect_identifiers($k)] = $v; + } } else { $this->ar_set[$this->_protect_identifiers($k)] = $this->escape($v); + if ($this->ar_caching === TRUE) + { + $this->ar_cache_offset[$this->_protect_identifiers($k)] = $this->escape($v); + } } - } return $this; @@ -1331,6 +1449,11 @@ class CI_DB_active_record extends CI_DB_driver { */ function _compile_select($select_override = FALSE) { + if ($this->ar_caching === TRUE) + { + $this->_merge_cache(); + } + $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; $sql .= (count($this->ar_select) == 0) ? '*' : implode(', ', $this->ar_select); @@ -1455,6 +1578,107 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- + /** + * Start Cache + * + * Starts AR caching + * + * @access public + * @return void + */ + function start_cache() + { + $this->ar_caching = TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Stop Cache + * + * Stops AR caching + * + * @access public + * @return void + */ + function stop_cache() + { + $this->ar_caching = FALSE; + } + + + // -------------------------------------------------------------------- + + /** + * Flush Cache + * + * Empties the AR cache + * + * @access public + * @return void + */ + function flush_cache() + { + $ar_reset_items = array( + 'ar_cache_select' => array(), + 'ar_cache_from' => array(), + 'ar_cache_join' => array(), + 'ar_cache_where' => array(), + 'ar_cache_like' => array(), + 'ar_cache_groupby' => array(), + 'ar_cache_having' =>array(), + 'ar_cache_orderby' => array(), + 'ar_cache_set' => array() + ); + + $this->_reset_run($ar_reset_items); + } + + // -------------------------------------------------------------------- + + /** + * Merge Cache + * + * When called, this function merges any cached AR arrays with + * locally called ones. + * + * @access private + * @return void + */ + function _merge_cache() + { + $ar_items = array('select', 'from', 'join', 'where', 'like', 'groupby', 'having', 'orderby', 'set'); + + foreach ($ar_items as $ar_item) + { + $ar_cache_item = 'ar_cache_'.$ar_item; + $ar_item = 'ar_'.$ar_item; + $this->$ar_item = array_unique(array_merge($this->$ar_item, $this->$ar_cache_item)); + } + } + + // -------------------------------------------------------------------- + + /** + * Resets the active record values. Called by the get() function + * + * @access private + * @param array An array of fields to reset + * @return void + */ + function _reset_run($ar_reset_items) + { + foreach ($ar_reset_items as $item => $default_value) + { + if (!in_array($item, $this->ar_store_array)) + { + $this->$item = $default_value; + } + } + } + + // -------------------------------------------------------------------- + /** * Resets the active record values. Called by the get() function * @@ -1463,20 +1687,24 @@ class CI_DB_active_record extends CI_DB_driver { */ function _reset_select() { - $this->ar_select = array(); - $this->ar_distinct = FALSE; - $this->ar_from = array(); - $this->ar_join = array(); - $this->ar_where = array(); - $this->ar_like = array(); - $this->ar_groupby = array(); - $this->ar_having = array(); - $this->ar_limit = FALSE; - $this->ar_offset = FALSE; - $this->ar_order = FALSE; - $this->ar_orderby = array(); - $this->ar_wherein = array(); - $this->ar_aliased_tables = array(); + $ar_reset_items = array( + 'ar_select' => array(), + 'ar_from' => array(), + 'ar_join' => array(), + 'ar_where' => array(), + 'ar_like' => array(), + 'ar_groupby' => array(), + 'ar_having' => array(), + 'ar_orderby' => array(), + 'ar_wherein' => array(), + 'ar_aliased_tables' => array(), + 'ar_distinct' => FALSE, + 'ar_limit' => FALSE, + 'ar_offset' => FALSE, + 'ar_order' => FALSE, + ); + + $this->_reset_run($ar_reset_items); } // -------------------------------------------------------------------- @@ -1490,16 +1718,19 @@ class CI_DB_active_record extends CI_DB_driver { * @return void */ function _reset_write() - { - $this->ar_set = array(); - $this->ar_from = array(); - $this->ar_where = array(); - $this->ar_like = array(); - $this->ar_limit = FALSE; - $this->ar_order = FALSE; - $this->ar_orderby = array(); + { + $ar_reset_items = array( + 'ar_set' => array(), + 'ar_from' => array(), + 'ar_where' => array(), + 'ar_like' => array(), + 'ar_orderby' => array(), + 'ar_limit' => FALSE, + 'ar_order' => FALSE + ); + + $this->_reset_run($ar_reset_items); } } - ?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index ad747d4ad..ecd404b52 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -433,6 +433,13 @@ class CI_DB_mssql_driver extends CI_DB { function _protect_identifiers($item, $affect_spaces = TRUE, $first_word_only = FALSE) { // MSSQL doesn't use backticks + if (strpos($item, '.') !== FALSE) + { + $aliased_tables = implode(".",$this->ar_aliased_tables).'.'; + $table_name = substr($item, 0, strpos($item, '.')+1); + $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item; + } + return $item; } diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index f00257250..a5082d1b3 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -454,6 +454,13 @@ class CI_DB_mysql_driver extends CI_DB { // we may need "`item1` `item2`" and not "`item1 item2`" if (ctype_alnum($item) === FALSE) { + if (strpos($item, '.') !== FALSE) + { + $aliased_tables = implode(".",$this->ar_aliased_tables).'.'; + $table_name = substr($item, 0, strpos($item, '.')+1); + $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item; + } + // This function may get "field >= 1", and need it to return "`field` >= 1" $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index b2e97f927..9e7cc0c9f 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -448,6 +448,13 @@ class CI_DB_mysqli_driver extends CI_DB { // we may need "`item1` `item2`" and not "`item1 item2`" if (ctype_alnum($item) === FALSE) { + if (strpos($item, '.') !== FALSE) + { + $aliased_tables = implode(".",$this->ar_aliased_tables).'.'; + $table_name = substr($item, 0, strpos($item, '.')+1); + $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item; + } + // This function may get "field >= 1", and need it to return "`field` >= 1" $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index ddc0fba99..aa2aeca42 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -559,6 +559,13 @@ class CI_DB_oci8_driver extends CI_DB { // we may need "`item1` `item2`" and not "`item1 item2`" if (ctype_alnum($item) === FALSE) { + if (strpos($item, '.') !== FALSE) + { + $aliased_tables = implode(".",$this->ar_aliased_tables).'.'; + $table_name = substr($item, 0, strpos($item, '.')+1); + $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item; + } + // This function may get "field >= 1", and need it to return "`field` >= 1" $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 03c0e6a86..88fff4365 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -424,6 +424,13 @@ class CI_DB_odbc_driver extends CI_DB { // we may need "`item1` `item2`" and not "`item1 item2`" if (ctype_alnum($item) === FALSE) { + if (strpos($item, '.') !== FALSE) + { + $aliased_tables = implode(".",$this->ar_aliased_tables).'.'; + $table_name = substr($item, 0, strpos($item, '.')+1); + $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item; + } + // This function may get "field >= 1", and need it to return "`field` >= 1" $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index e72981348..ae8bd86eb 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -444,6 +444,13 @@ class CI_DB_postgre_driver extends CI_DB { // we may need ""item1" "item2"" and not ""item1 item2"" if (ctype_alnum($item) === FALSE) { + if (strpos($item, '.') !== FALSE) + { + $aliased_tables = implode(".",$this->ar_aliased_tables).'.'; + $table_name = substr($item, 0, strpos($item, '.')+1); + $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item; + } + // This function may get "field >= 1", and need it to return ""field" >= 1" $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; @@ -486,7 +493,7 @@ class CI_DB_postgre_driver extends CI_DB { $tables = array($tables); } - return implode(', ', $tables); + return '('.implode(', ', $tables).')'; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 38febca29..dad5eeedf 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -440,6 +440,13 @@ class CI_DB_sqlite_driver extends CI_DB { // we may need "`item1` `item2`" and not "`item1 item2`" if (ctype_alnum($item) === FALSE) { + if (strpos($item, '.') !== FALSE) + { + $aliased_tables = implode(".",$this->ar_aliased_tables).'.'; + $table_name = substr($item, 0, strpos($item, '.')+1); + $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item; + } + // This function may get "field >= 1", and need it to return "`field` >= 1" $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; -- cgit v1.2.3-24-g4f1b From 32cf7eb132ec688a3b0339f266efa3f064c58a60 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 5 Feb 2008 16:03:50 +0000 Subject: Changed the behaviour of Active Record's update() to make the WHERE clause optional (#3395) --- system/database/drivers/mssql/mssql_driver.php | 6 +++++- system/database/drivers/mysql/mysql_driver.php | 6 +++++- system/database/drivers/mysqli/mysqli_driver.php | 6 +++++- system/database/drivers/oci8/oci8_driver.php | 6 +++++- system/database/drivers/odbc/odbc_driver.php | 6 +++++- system/database/drivers/postgre/postgre_driver.php | 6 +++++- system/database/drivers/sqlite/sqlite_driver.php | 6 +++++- 7 files changed, 35 insertions(+), 7 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index ecd404b52..4cf444088 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -509,7 +509,11 @@ class CI_DB_mssql_driver extends CI_DB { $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$orderby.$limit; + $sql = "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr); + $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; + $sql .= $orderby.$limit; + + return $sql; } diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index a5082d1b3..372365aeb 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -550,7 +550,11 @@ class CI_DB_mysql_driver extends CI_DB { $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$orderby.$limit; + $sql = "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr); + $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; + $sql .= $orderby.$limit; + + return $sql; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 9e7cc0c9f..31c27117c 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -544,7 +544,11 @@ class CI_DB_mysqli_driver extends CI_DB { $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$orderby.$limit; + $sql = "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr); + $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; + $sql .= $orderby.$limit; + + return $sql; } diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index aa2aeca42..7aab37e82 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -655,7 +655,11 @@ class CI_DB_oci8_driver extends CI_DB { $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$orderby.$limit; + $sql = "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr); + $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; + $sql .= $orderby.$limit; + + return $sql; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 88fff4365..dd10fbdd3 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -520,7 +520,11 @@ class CI_DB_odbc_driver extends CI_DB { $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$orderby.$limit; + $sql = "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr); + $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; + $sql .= $orderby.$limit; + + return $sql; } diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index ae8bd86eb..cac0ecb60 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -540,7 +540,11 @@ class CI_DB_postgre_driver extends CI_DB { $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$orderby.$limit; + $sql = "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr); + $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; + $sql .= $orderby.$limit; + + return $sql; } diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index dad5eeedf..5290edeea 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -536,7 +536,11 @@ class CI_DB_sqlite_driver extends CI_DB { $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$orderby.$limit; + $sql = "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr); + $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; + $sql .= $orderby.$limit; + + return $sql; } -- cgit v1.2.3-24-g4f1b From 7825526a596b0db6a15fac519cf45e2e929c684d Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 6 Feb 2008 13:54:23 +0000 Subject: cache_stop() fix... --- system/database/DB_active_rec.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index b3bf02a8b..263172a86 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1449,10 +1449,7 @@ class CI_DB_active_record extends CI_DB_driver { */ function _compile_select($select_override = FALSE) { - if ($this->ar_caching === TRUE) - { - $this->_merge_cache(); - } + $this->_merge_cache(); $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; -- cgit v1.2.3-24-g4f1b From a47a2e26f3e8bcf96657ac343c224bd592ed32f8 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 7 Feb 2008 18:05:59 +0000 Subject: added functionality for setting client character set and collation in MySQLi driver --- system/database/drivers/mysqli/mysqli_driver.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 31c27117c..b6d1cba77 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -96,8 +96,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ function db_set_charset($charset, $collation) { - // TODO - add support if needed - return TRUE; + return @mysqli_query($this->conn_id, "SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'"); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 156481371306db532d6b3880d0914e9237b93685 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 10 Feb 2008 21:46:18 +0000 Subject: changes for enhanced database compatibility --- system/database/DB_forge.php | 1 - system/database/drivers/mssql/mssql_driver.php | 47 +++++++++++++++++++--- system/database/drivers/mysqli/mysqli_driver.php | 3 +- system/database/drivers/oci8/oci8_driver.php | 14 +++---- system/database/drivers/postgre/postgre_driver.php | 2 +- system/database/drivers/sqlite/sqlite_driver.php | 14 +++---- 6 files changed, 58 insertions(+), 23 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index 7febb72c2..cd468bc6a 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -40,7 +40,6 @@ class CI_DB_forge { // Assign the main database object to $this->db $CI =& get_instance(); $this->db =& $CI->db; - log_message('debug', "Database Forge Class Initialized"); } diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 4cf444088..8e12a2d21 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -430,16 +430,51 @@ class CI_DB_mssql_driver extends CI_DB { * @param boolean only affect the first word * @return mixed the item with backticks */ - function _protect_identifiers($item, $affect_spaces = TRUE, $first_word_only = FALSE) + function _protect_identifiers($item, $first_word_only = FALSE) { - // MSSQL doesn't use backticks - if (strpos($item, '.') !== FALSE) + if (is_array($item)) { - $aliased_tables = implode(".",$this->ar_aliased_tables).'.'; - $table_name = substr($item, 0, strpos($item, '.')+1); - $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item; + $escaped_array = array(); + + foreach($item as $k=>$v) + { + $escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v, $first_word_only); + } + + return $escaped_array; + } + + // This function may get "item1 item2" as a string, and so + // we may need ""item1" "item2"" and not ""item1 item2"" + if (ctype_alnum($item) === FALSE) + { + if (strpos($item, '.') !== FALSE) + { + $aliased_tables = implode(".",$this->ar_aliased_tables).'.'; + $table_name = substr($item, 0, strpos($item, '.')+1); + $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item; + } + + // This function may get "field >= 1", and need it to return ""field" >= 1" + $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; + + $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1"$2"$3', $item); + } + else + { + return "\"{$item}\""; } + $exceptions = array('AS', '/', '-', '%', '+', '*'); + + foreach ($exceptions as $exception) + { + + if (stristr($item, " \"{$exception}\" ") !== FALSE) + { + $item = preg_replace('/ "('.preg_quote($exception).')" /i', ' $1 ', $item); + } + } return $item; } diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index b6d1cba77..31c27117c 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -96,7 +96,8 @@ class CI_DB_mysqli_driver extends CI_DB { */ function db_set_charset($charset, $collation) { - return @mysqli_query($this->conn_id, "SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'"); + // TODO - add support if needed + return TRUE; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 7aab37e82..8f63c25a5 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -556,7 +556,7 @@ class CI_DB_oci8_driver extends CI_DB { } // This function may get "item1 item2" as a string, and so - // we may need "`item1` `item2`" and not "`item1 item2`" + // we may need ""item1" "item2"" and not ""item1 item2"" if (ctype_alnum($item) === FALSE) { if (strpos($item, '.') !== FALSE) @@ -566,14 +566,14 @@ class CI_DB_oci8_driver extends CI_DB { $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item; } - // This function may get "field >= 1", and need it to return "`field` >= 1" + // This function may get "field >= 1", and need it to return ""field" >= 1" $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; - $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item); + $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1"$2"$3', $item); } else { - return "`{$item}`"; + return "\"{$item}\""; } $exceptions = array('AS', '/', '-', '%', '+', '*'); @@ -581,9 +581,9 @@ class CI_DB_oci8_driver extends CI_DB { foreach ($exceptions as $exception) { - if (stristr($item, " `{$exception}` ") !== FALSE) + if (stristr($item, " \"{$exception}\" ") !== FALSE) { - $item = preg_replace('/ `('.preg_quote($exception).')` /i', ' $1 ', $item); + $item = preg_replace('/ "('.preg_quote($exception).')" /i', ' $1 ', $item); } } return $item; @@ -608,7 +608,7 @@ class CI_DB_oci8_driver extends CI_DB { $tables = array($tables); } - return '('.implode(', ', $tables).')'; + return implode(', ', $tables); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index cac0ecb60..a32c37ed8 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -493,7 +493,7 @@ class CI_DB_postgre_driver extends CI_DB { $tables = array($tables); } - return '('.implode(', ', $tables).')'; + return implode(', ', $tables); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 5290edeea..b6cb460b1 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -404,7 +404,7 @@ class CI_DB_sqlite_driver extends CI_DB { { if (stristr($table, '.')) { - $table = preg_replace("/\./", "`.`", $table); + $table = preg_replace("/\./", ".", $table); } return $table; @@ -437,7 +437,7 @@ class CI_DB_sqlite_driver extends CI_DB { } // This function may get "item1 item2" as a string, and so - // we may need "`item1` `item2`" and not "`item1 item2`" + // we may need "item1 item2" and not "item1 item2" if (ctype_alnum($item) === FALSE) { if (strpos($item, '.') !== FALSE) @@ -447,14 +447,14 @@ class CI_DB_sqlite_driver extends CI_DB { $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item; } - // This function may get "field >= 1", and need it to return "`field` >= 1" + // This function may get "field >= 1", and need it to return "field >= 1" $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; - $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item); + $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1$2$3', $item); } else { - return "`{$item}`"; + return "{$item}"; } $exceptions = array('AS', '/', '-', '%', '+', '*'); @@ -462,9 +462,9 @@ class CI_DB_sqlite_driver extends CI_DB { foreach ($exceptions as $exception) { - if (stristr($item, " `{$exception}` ") !== FALSE) + if (stristr($item, " {$exception} ") !== FALSE) { - $item = preg_replace('/ `('.preg_quote($exception).')` /i', ' $1 ', $item); + $item = preg_replace('/ ('.preg_quote($exception).') /i', ' $1 ', $item); } } return $item; -- cgit v1.2.3-24-g4f1b From 7555ade507982af16ed763e2e560a60892408bd2 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 10 Feb 2008 23:40:41 +0000 Subject: clarifying comment on sqlite escape table --- system/database/drivers/sqlite/sqlite_driver.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index b6cb460b1..c51edfb07 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -402,11 +402,9 @@ class CI_DB_sqlite_driver extends CI_DB { */ function _escape_table($table) { - if (stristr($table, '.')) - { - $table = preg_replace("/\./", ".", $table); - } - + + // other database drivers use this to add backticks, hence this + // function is simply going to return the tablename for sqlite return $table; } -- cgit v1.2.3-24-g4f1b From 41d4b592b9b0962e444938fcf106cccbbd8fda59 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 10 Feb 2008 23:47:13 +0000 Subject: escape_table made consistent with mysql driver across all drivers --- system/database/drivers/mssql/mssql_driver.php | 4 ++-- system/database/drivers/mysqli/mysqli_driver.php | 4 ++-- system/database/drivers/oci8/oci8_driver.php | 4 ++-- system/database/drivers/odbc/odbc_driver.php | 4 ++-- system/database/drivers/postgre/postgre_driver.php | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 8e12a2d21..e429d21a6 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -408,9 +408,9 @@ class CI_DB_mssql_driver extends CI_DB { // I don't believe this is necessary with MS SQL. Not sure, though. - Rick /* - if (stristr($table, '.')) + if (strpos($table, '.') !== FALSE) { - $table = preg_replace("/\./", "`.`", $table); + $table = str_replace('.', '`.`', $table); } */ diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 31c27117c..61848a674 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -410,9 +410,9 @@ class CI_DB_mysqli_driver extends CI_DB { */ function _escape_table($table) { - if (stristr($table, '.')) + if (strpos($table, '.') !== FALSE) { - $table = preg_replace("/\./", "`.`", $table); + $table = str_replace('.', '`.`', $table); } return $table; diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 8f63c25a5..33fe08725 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -521,9 +521,9 @@ class CI_DB_oci8_driver extends CI_DB { */ function _escape_table($table) { - if (stristr($table, '.')) + if (strpos($table, '.') !== FALSE) { - $table = preg_replace("/\./", "`.`", $table); + $table = str_replace('.', '`.`', $table); } return $table; diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index dd10fbdd3..c949a4670 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -386,9 +386,9 @@ class CI_DB_odbc_driver extends CI_DB { */ function _escape_table($table) { - if (stristr($table, '.')) + if (strpos($table, '.') !== FALSE) { - $table = preg_replace("/\./", "`.`", $table); + $table = str_replace('.', '`.`', $table); } return $table; diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index a32c37ed8..2472c5e92 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -406,9 +406,9 @@ class CI_DB_postgre_driver extends CI_DB { */ function _escape_table($table) { - if (stristr($table, '.')) + if (strpos($table, '.') !== FALSE) { - $table = '"'.preg_replace("/\./", '"."', $table).'"'; + $table = str_replace('.', '`.`', $table); } return $table; -- cgit v1.2.3-24-g4f1b From 70529a739dd0a73fc72124720390313d8a8b0dca Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 11 Feb 2008 03:54:42 +0000 Subject: driver escape_table fixes --- system/database/drivers/mssql/mssql_driver.php | 4 ++-- system/database/drivers/mysqli/mysqli_driver.php | 4 ++-- system/database/drivers/oci8/oci8_driver.php | 4 ++-- system/database/drivers/odbc/odbc_driver.php | 4 ++-- system/database/drivers/postgre/postgre_driver.php | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index e429d21a6..8e12a2d21 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -408,9 +408,9 @@ class CI_DB_mssql_driver extends CI_DB { // I don't believe this is necessary with MS SQL. Not sure, though. - Rick /* - if (strpos($table, '.') !== FALSE) + if (stristr($table, '.')) { - $table = str_replace('.', '`.`', $table); + $table = preg_replace("/\./", "`.`", $table); } */ diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 61848a674..31c27117c 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -410,9 +410,9 @@ class CI_DB_mysqli_driver extends CI_DB { */ function _escape_table($table) { - if (strpos($table, '.') !== FALSE) + if (stristr($table, '.')) { - $table = str_replace('.', '`.`', $table); + $table = preg_replace("/\./", "`.`", $table); } return $table; diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 33fe08725..8f63c25a5 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -521,9 +521,9 @@ class CI_DB_oci8_driver extends CI_DB { */ function _escape_table($table) { - if (strpos($table, '.') !== FALSE) + if (stristr($table, '.')) { - $table = str_replace('.', '`.`', $table); + $table = preg_replace("/\./", "`.`", $table); } return $table; diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index c949a4670..dd10fbdd3 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -386,9 +386,9 @@ class CI_DB_odbc_driver extends CI_DB { */ function _escape_table($table) { - if (strpos($table, '.') !== FALSE) + if (stristr($table, '.')) { - $table = str_replace('.', '`.`', $table); + $table = preg_replace("/\./", "`.`", $table); } return $table; diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 2472c5e92..a32c37ed8 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -406,9 +406,9 @@ class CI_DB_postgre_driver extends CI_DB { */ function _escape_table($table) { - if (strpos($table, '.') !== FALSE) + if (stristr($table, '.')) { - $table = str_replace('.', '`.`', $table); + $table = '"'.preg_replace("/\./", '"."', $table).'"'; } return $table; -- cgit v1.2.3-24-g4f1b From c0743381b20910a3fc23b391e8b2009ac5771ae8 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 11 Feb 2008 05:54:44 +0000 Subject: database enhancements, compatibility additions and bugfixes --- system/database/DB_driver.php | 28 ++++++++++++++-------- system/database/drivers/mssql/mssql_driver.php | 4 ++-- system/database/drivers/mysql/mysql_driver.php | 2 +- system/database/drivers/mysqli/mysqli_driver.php | 4 ++-- system/database/drivers/oci8/oci8_driver.php | 4 ++-- system/database/drivers/odbc/odbc_driver.php | 4 ++-- system/database/drivers/postgre/postgre_driver.php | 4 ++-- 7 files changed, 29 insertions(+), 21 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 966fd3ad5..6b3a74b94 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -556,8 +556,8 @@ class CI_DB_driver { * @return string */ function compile_binds($sql, $binds) - { - if (FALSE === strpos($sql, $this->bind_marker)) + { + if (strpos($sql, $this->bind_marker) === FALSE) { return $sql; } @@ -567,17 +567,25 @@ class CI_DB_driver { $binds = array($binds); } - foreach ($binds as $val) + // Get the sql segments around the bind markers + $segments = explode($this->bind_marker, $sql); + + // The count of bind should be 1 less then the count of segments + // If there are more bind arguments trim it down + if (count($binds) >= count($segments)) { + $binds = array_slice($binds, 0, count($segments)-1); + } + + // Construct the binded query + $result = $segments[0]; + $i = 0; + foreach ($binds as $bind) { - $val = $this->escape($val); - - // Just in case the replacement string contains the bind - // character we'll temporarily replace it with a marker - $val = str_replace($this->bind_marker, '{%bind_marker%}', $val); - $sql = preg_replace("#".preg_quote($this->bind_marker, '#')."#", str_replace('$', '\$', $val), $sql, 1); + $result .= $this->escape($bind); + $result .= $segments[++$i]; } - return str_replace('{%bind_marker%}', $this->bind_marker, $sql); + return $result; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 8e12a2d21..7b024d414 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -408,9 +408,9 @@ class CI_DB_mssql_driver extends CI_DB { // I don't believe this is necessary with MS SQL. Not sure, though. - Rick /* - if (stristr($table, '.')) + if (strpos($table, '.') !== FALSE) { - $table = preg_replace("/\./", "`.`", $table); + $table = '"' . str_replace('.', '"."', $table) . '"'; } */ diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 372365aeb..edf09a170 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -418,7 +418,7 @@ class CI_DB_mysql_driver extends CI_DB { { if (strpos($table, '.') !== FALSE) { - $table = str_replace('.', '`.`', $table); + $table = '`' . str_replace('.', '`.`', $table) . '`'; } return $table; diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 31c27117c..dab56c7e7 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -410,9 +410,9 @@ class CI_DB_mysqli_driver extends CI_DB { */ function _escape_table($table) { - if (stristr($table, '.')) + if (strpos($table, '.') !== FALSE) { - $table = preg_replace("/\./", "`.`", $table); + $table = '`' . str_replace('.', '`.`', $table) . '`'; } return $table; diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 8f63c25a5..ec26f5be6 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -521,9 +521,9 @@ class CI_DB_oci8_driver extends CI_DB { */ function _escape_table($table) { - if (stristr($table, '.')) + if (strpos($table, '.') !== FALSE) { - $table = preg_replace("/\./", "`.`", $table); + $table = '"' . str_replace('.', '"."', $table) . '"'; } return $table; diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index dd10fbdd3..fd2460853 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -386,9 +386,9 @@ class CI_DB_odbc_driver extends CI_DB { */ function _escape_table($table) { - if (stristr($table, '.')) + if (strpos($table, '.') !== FALSE) { - $table = preg_replace("/\./", "`.`", $table); + $table = '`' . str_replace('.', '`.`', $table) . '`'; } return $table; diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index a32c37ed8..ce8cb258a 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -406,9 +406,9 @@ class CI_DB_postgre_driver extends CI_DB { */ function _escape_table($table) { - if (stristr($table, '.')) + if (strpos($table, '.') !== FALSE) { - $table = '"'.preg_replace("/\./", '"."', $table).'"'; + $table = '"' . str_replace('.', '"."', $table) . '"'; } return $table; -- cgit v1.2.3-24-g4f1b From 903cc985da13463369a4cb1831ccbe5449316ee7 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 11 Feb 2008 06:06:59 +0000 Subject: remove backticks from ODBC --- system/database/drivers/odbc/odbc_driver.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index fd2460853..bdedab32f 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -386,11 +386,7 @@ class CI_DB_odbc_driver extends CI_DB { */ function _escape_table($table) { - if (strpos($table, '.') !== FALSE) - { - $table = '`' . str_replace('.', '`.`', $table) . '`'; - } - + // used to add backticks in other db drivers return $table; } @@ -438,7 +434,7 @@ class CI_DB_odbc_driver extends CI_DB { } else { - return "`{$item}`"; + return "{$item}"; } $exceptions = array('AS', '/', '-', '%', '+', '*'); @@ -446,9 +442,9 @@ class CI_DB_odbc_driver extends CI_DB { foreach ($exceptions as $exception) { - if (stristr($item, " `{$exception}` ") !== FALSE) + if (stristr($item, " {$exception} ") !== FALSE) { - $item = preg_replace('/ `('.preg_quote($exception).')` /i', ' $1 ', $item); + $item = preg_replace('/ ('.preg_quote($exception).') /i', ' $1 ', $item); } } return $item; -- cgit v1.2.3-24-g4f1b From d33972bed776a8e95d1e5602534898672eb56cae Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 13 Feb 2008 04:16:27 +0000 Subject: changed escape_str() in mysqli_driver() to use is_object() instead of is_resource() to test $this->conn_id --- system/database/drivers/mysqli/mysqli_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index dab56c7e7..aaeab5765 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -249,7 +249,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ function escape_str($str) { - if (function_exists('mysqli_real_escape_string') AND is_resource($this->conn_id)) + if (function_exists('mysqli_real_escape_string') AND is_object($this->conn_id)) { return mysqli_real_escape_string($this->conn_id, $str); } -- cgit v1.2.3-24-g4f1b From 5b4d53271a841c60e43d64f4b6b3c32794b41ac7 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 13 Feb 2008 04:34:10 +0000 Subject: fixes to _create_table() in sqlite_forge.php: removed space between table name and parenthesis added version check for IF NOT EXISTS --- system/database/drivers/sqlite/sqlite_forge.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php index e3196cce1..1fd2a2bd4 100644 --- a/system/database/drivers/sqlite/sqlite_forge.php +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -76,12 +76,13 @@ class CI_DB_sqlite_forge extends CI_DB_forge { { $sql = 'CREATE TABLE '; - if ($if_not_exists === TRUE) + // IF NOT EXISTS added to SQLite in 3.3.0 + if ($if_not_exists === TRUE && version_compare($this->_version(), '3.3.0', '>=') === TRUE) { $sql .= 'IF NOT EXISTS '; } - $sql .= $this->db->_escape_table($table)." ("; + $sql .= $this->db->_escape_table($table)."("; $current_field_count = 0; foreach ($fields as $field=>$attributes) -- cgit v1.2.3-24-g4f1b From 7dd3838f188f35d63a30c30b435fbb7f2e2d3d7e Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 13 Feb 2008 04:52:58 +0000 Subject: fixed bug #3419, moved DSN parsing to DB.php so the driver could properly be set to instantiate the correct db driver class. --- system/database/DB.php | 23 +++++++++++++++++++++++ system/database/DB_driver.php | 25 +------------------------ 2 files changed, 24 insertions(+), 24 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index 078f1ef0f..c3e7722d3 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -46,6 +46,29 @@ function &DB($params = '', $active_record_override = FALSE) $params = $db[$active_group]; } + else + { + + /* parse the URL from the DSN string + * Database settings can be passed as discreet + * parameters or as a data source name in the first + * parameter. DSNs must have this prototype: + * $dsn = 'driver://username:password@hostname/database'; + */ + + if (($dns = @parse_url($params)) === FALSE) + { + show_error('Invalid DB Connection String'); + } + + $params = array( + 'dbdriver' => $dns['scheme'], + 'hostname' => (isset($dns['host'])) ? rawurldecode($dns['host']) : '', + 'username' => (isset($dns['user'])) ? rawurldecode($dns['user']) : '', + 'password' => (isset($dns['pass'])) ? rawurldecode($dns['pass']) : '', + 'database' => (isset($dns['path'])) ? rawurldecode(substr($dns['host'], 1)) : '' + ); + } // No DB specified yet? Beat them senseless... if ( ! isset($params['dbdriver']) OR $params['dbdriver'] == '') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 6b3a74b94..b1013178e 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -70,12 +70,7 @@ class CI_DB_driver { * Constructor. Accepts one parameter containing the database * connection settings. * - * Database settings can be passed as discreet - * parameters or as a data source name in the first - * parameter. DSNs must have this prototype: - * $dsn = 'driver://username:password@hostname/database'; - * - * @param mixed. Can be an array or a DSN string + * @param array */ function CI_DB_driver($params) { @@ -86,24 +81,6 @@ class CI_DB_driver { $this->$key = $val; } } - elseif (strpos($params, '://')) - { - if (FALSE === ($dsn = @parse_url($params))) - { - log_message('error', 'Invalid DB Connection String'); - - if ($this->db_debug) - { - return $this->display_error('db_invalid_connection_str'); - } - return FALSE; - } - - $this->hostname = ( ! isset($dsn['host'])) ? '' : rawurldecode($dsn['host']); - $this->username = ( ! isset($dsn['user'])) ? '' : rawurldecode($dsn['user']); - $this->password = ( ! isset($dsn['pass'])) ? '' : rawurldecode($dsn['pass']); - $this->database = ( ! isset($dsn['path'])) ? '' : rawurldecode(substr($dsn['path'], 1)); - } log_message('debug', 'Database Driver Class Initialized'); } -- cgit v1.2.3-24-g4f1b From b1f90dbfd5fb7610865c4ff31b9d75bc821560a7 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 13 Feb 2008 05:22:38 +0000 Subject: reapplied implementation of db_set_charset() for MySQLi... --- system/database/drivers/mysqli/mysqli_driver.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index aaeab5765..73396c594 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -96,8 +96,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ function db_set_charset($charset, $collation) { - // TODO - add support if needed - return TRUE; + return @mysqli_query($this->conn_id, "SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'"); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 63eac3eb96563336612c69452745190e8af3c813 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 14 Feb 2008 20:23:37 +0000 Subject: little protection in case an array is provided as the $params for the DB class --- system/database/DB.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index c3e7722d3..16ca1c888 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -46,7 +46,7 @@ function &DB($params = '', $active_record_override = FALSE) $params = $db[$active_group]; } - else + elseif (is_string($params)) { /* parse the URL from the DSN string -- cgit v1.2.3-24-g4f1b From 9a4d1da5fa823b6bb58cdd1d210f782e95830e91 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 25 Feb 2008 14:18:38 +0000 Subject: Fixed an AR_caching error where it wasn't tracking table aliases (#3463) --- system/database/DB_active_rec.php | 2 +- system/database/drivers/mssql/mssql_driver.php | 2 +- system/database/drivers/mysql/mysql_driver.php | 2 +- system/database/drivers/mysqli/mysqli_driver.php | 2 +- system/database/drivers/oci8/oci8_driver.php | 2 +- system/database/drivers/odbc/odbc_driver.php | 2 +- system/database/drivers/postgre/postgre_driver.php | 2 +- system/database/drivers/sqlite/sqlite_driver.php | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 263172a86..903584200 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -289,7 +289,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->ar_from[] = $this->_protect_identifiers($this->_track_aliases($val)); if ($this->ar_caching === TRUE) { - $this->ar_cache_from[] = $this->_protect_identifiers($val); + $this->ar_cache_from[] = $this->_protect_identifiers($this->_track_aliases($val)); } } diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 7b024d414..1ed333de0 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -465,7 +465,7 @@ class CI_DB_mssql_driver extends CI_DB { return "\"{$item}\""; } - $exceptions = array('AS', '/', '-', '%', '+', '*'); + $exceptions = array('AS', '/', '-', '%', '+', '*', 'OR', 'IS'); foreach ($exceptions as $exception) { diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index edf09a170..2bc66ecf2 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -471,7 +471,7 @@ class CI_DB_mysql_driver extends CI_DB { return "`{$item}`"; } - $exceptions = array('AS', '/', '-', '%', '+', '*'); + $exceptions = array('AS', '/', '-', '%', '+', '*', 'OR', 'IS'); foreach ($exceptions as $exception) { diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 73396c594..6ff37f7e2 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -464,7 +464,7 @@ class CI_DB_mysqli_driver extends CI_DB { return "`{$item}`"; } - $exceptions = array('AS', '/', '-', '%', '+', '*'); + $exceptions = array('AS', '/', '-', '%', '+', '*', 'OR', 'IS'); foreach ($exceptions as $exception) { diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index ec26f5be6..364268b98 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -576,7 +576,7 @@ class CI_DB_oci8_driver extends CI_DB { return "\"{$item}\""; } - $exceptions = array('AS', '/', '-', '%', '+', '*'); + $exceptions = array('AS', '/', '-', '%', '+', '*', 'OR', 'IS'); foreach ($exceptions as $exception) { diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index bdedab32f..82fe36b5d 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -437,7 +437,7 @@ class CI_DB_odbc_driver extends CI_DB { return "{$item}"; } - $exceptions = array('AS', '/', '-', '%', '+', '*'); + $exceptions = array('AS', '/', '-', '%', '+', '*', 'OR', 'IS'); foreach ($exceptions as $exception) { diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index ce8cb258a..4eff97fcc 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -461,7 +461,7 @@ class CI_DB_postgre_driver extends CI_DB { return "\"{$item}\""; } - $exceptions = array('AS', '/', '-', '%', '+', '*'); + $exceptions = array('AS', '/', '-', '%', '+', '*', 'OR', 'IS'); foreach ($exceptions as $exception) { diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index c51edfb07..c859dea6e 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -455,7 +455,7 @@ class CI_DB_sqlite_driver extends CI_DB { return "{$item}"; } - $exceptions = array('AS', '/', '-', '%', '+', '*'); + $exceptions = array('AS', '/', '-', '%', '+', '*', 'OR', 'IS'); foreach ($exceptions as $exception) { -- cgit v1.2.3-24-g4f1b From 43e8cbf51bfdca8bc29acc23208f1018d7af913a Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sat, 1 Mar 2008 23:14:43 +0000 Subject: added or_having, deprecated orhaving --- system/database/DB_active_rec.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 903584200..b97fb11cd 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -779,7 +779,19 @@ class CI_DB_active_record extends CI_DB_driver { { return $this->_having($key, $value, 'AND '); } - + + // -------------------------------------------------------------------- + + /** + * orhaving() is an alias of or_having() + * this function is here for backwards compatibility, as + * orhaving() has been deprecated + */ + + function orhaving($key, $value = '') + { + return $this->or_havinggroup_by($key, $value = ''); + } // -------------------------------------------------------------------- /** @@ -792,7 +804,7 @@ class CI_DB_active_record extends CI_DB_driver { * @param string * @return object */ - function orhaving($key, $value = '') + function or_having($key, $value = '') { return $this->_having($key, $value, 'OR '); } -- cgit v1.2.3-24-g4f1b From 49ef042b211b41e4a24815bbf6fd65fb41f86021 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 4 Mar 2008 21:31:16 +0000 Subject: fix silly copy-paste error in active record --- system/database/DB_active_rec.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index b97fb11cd..add0b8c94 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -790,7 +790,7 @@ class CI_DB_active_record extends CI_DB_driver { function orhaving($key, $value = '') { - return $this->or_havinggroup_by($key, $value = ''); + return $this->or_having($key, $value = ''); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 8b2f19b7b2671526c8e5eca74251b6339932e5bf Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 6 Mar 2008 15:51:55 +0000 Subject: change to the way AR handles aliased tables --- system/database/DB_active_rec.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index add0b8c94..bde43abf0 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1434,17 +1434,15 @@ class CI_DB_active_record extends CI_DB_driver { */ function _filter_table_aliases($statements) { + foreach ($statements as $k => $v) { foreach ($this->ar_aliased_tables as $table) { - $statement = preg_replace('/(\w+\.\w+)/', $this->_protect_identifiers('$0'), $v); // makes `table.field` - $statement = str_replace(array($this->dbprefix.$table, '.'), array($table, $this->_protect_identifiers('.')), $statement); + $statements[$k] = preg_replace('/(\w+\.\w+)/', $this->_protect_identifiers('$0'), $statements[$k]); // makes `table.field` + $statements[$k] = str_replace($this->dbprefix.$table.'.', $table.'.', $statements[$k]); } - - $statements[$k] = $statement; } - return $statements; } -- cgit v1.2.3-24-g4f1b From e97b13635f8985ac88add9659ae6a78e67006b9b Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 3 Apr 2008 21:23:13 +0000 Subject: replaced isset() with array_key_exists() in row() to allow retrieval of individual fields with MySQL NULL values --- system/database/DB_result.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 7d5097911..6461431e2 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -133,7 +133,8 @@ class CI_DB_result { $this->row_data = $this->row_array(0); } - if (isset($this->row_data[$n])) + // array_key_exists() instead of isset() to allow for MySQL NULL values + if (array_key_exists($n, $this->row_data))) { return $this->row_data[$n]; } -- cgit v1.2.3-24-g4f1b From 43cbdaaf9dc073b7e6bcf6416650c3249ea37d5d Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 3 Apr 2008 21:54:15 +0000 Subject: syntax error: extraneous closing parenthesis --- system/database/DB_result.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 6461431e2..c2eeefb94 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -134,7 +134,7 @@ class CI_DB_result { } // array_key_exists() instead of isset() to allow for MySQL NULL values - if (array_key_exists($n, $this->row_data))) + if (array_key_exists($n, $this->row_data)) { return $this->row_data[$n]; } -- cgit v1.2.3-24-g4f1b From 3ad8efe07deb3ec27a205815dc9097c20c728e9b Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 4 Apr 2008 18:56:04 +0000 Subject: added constants.php file and implemented constants for file system modes --- system/database/DB_cache.php | 6 +++--- system/database/drivers/sqlite/sqlite_driver.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index ad54fc315..08394da29 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -129,12 +129,12 @@ class CI_DB_Cache { if ( ! @is_dir($dir_path)) { - if ( ! @mkdir($dir_path, 0777)) + if ( ! @mkdir($dir_path, DIR_WRITE_MODE)) { return FALSE; } - @chmod($dir_path, 0777); + @chmod($dir_path, DIR_WRITE_MODE); } if (write_file($dir_path.$filename, serialize($object)) === FALSE) @@ -142,7 +142,7 @@ class CI_DB_Cache { return FALSE; } - @chmod($dir_path.$filename, 0777); + @chmod($dir_path.$filename, DIR_WRITE_MODE); return TRUE; } diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index c859dea6e..16a8308c1 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -48,7 +48,7 @@ class CI_DB_sqlite_driver extends CI_DB { */ function db_connect() { - if ( ! $conn_id = @sqlite_open($this->database, 0666, $error)) + if ( ! $conn_id = @sqlite_open($this->database, FILE_WRITE_MODE, $error)) { log_message('error', $error); @@ -73,7 +73,7 @@ class CI_DB_sqlite_driver extends CI_DB { */ function db_pconnect() { - if ( ! $conn_id = @sqlite_popen($this->database, 0666, $error)) + if ( ! $conn_id = @sqlite_popen($this->database, FILE_WRITE_MODE, $error)) { log_message('error', $error); -- cgit v1.2.3-24-g4f1b From e808aac2627c35d50082f814d9778c4bf976011c Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 6 Apr 2008 18:22:00 +0000 Subject: Added the ability to prevent escaping in having() clauses. --- system/database/DB_active_rec.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index bde43abf0..23a5a7adf 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -775,9 +775,9 @@ class CI_DB_active_record extends CI_DB_driver { * @param string * @return object */ - function having($key, $value = '') + function having($key, $value = '', $escape = TRUE) { - return $this->_having($key, $value, 'AND '); + return $this->_having($key, $value, 'AND ', $escape); } // -------------------------------------------------------------------- @@ -788,9 +788,9 @@ class CI_DB_active_record extends CI_DB_driver { * orhaving() has been deprecated */ - function orhaving($key, $value = '') + function orhaving($key, $value = '', $escape = TRUE) { - return $this->or_having($key, $value = ''); + return $this->or_having($key, $value = '', $escape); } // -------------------------------------------------------------------- @@ -804,9 +804,9 @@ class CI_DB_active_record extends CI_DB_driver { * @param string * @return object */ - function or_having($key, $value = '') + function or_having($key, $value = '', $escape = TRUE) { - return $this->_having($key, $value, 'OR '); + return $this->_having($key, $value, 'OR ', $escape); } // -------------------------------------------------------------------- @@ -822,7 +822,7 @@ class CI_DB_active_record extends CI_DB_driver { * @param string * @return object */ - function _having($key, $value = '', $type = 'AND ') + function _having($key, $value = '', $type = 'AND ', $escape = TRUE) { if ( ! is_array($key)) { @@ -832,7 +832,12 @@ class CI_DB_active_record extends CI_DB_driver { foreach ($key as $k => $v) { $prefix = (count($this->ar_having) == 0) ? '' : $type; - $k = $this->_protect_identifiers($k); + + if ($escape === TRUE) + { + $k = $this->_protect_identifiers($k); + } + if ($v != '') { -- cgit v1.2.3-24-g4f1b From 96863ce12d88b2126b80bf1b00a73eed1ad6be86 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 6 Apr 2008 19:20:17 +0000 Subject: testing an escape issue --- system/database/DB_active_rec.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 23a5a7adf..b2638f25c 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -447,7 +447,10 @@ class CI_DB_active_record extends CI_DB_driver { $k .= ' ='; } - $v = ' '.$this->escape($v); + if ($v != '') + { + $v = ' '.$this->escape($v); + } } else { -- cgit v1.2.3-24-g4f1b From 16629b1cef61db05646839d6789d98ddc5aaf16b Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 6 Apr 2008 19:58:20 +0000 Subject: Fixed a bug that wasn't allowing escaping to be turned off if the value of a query was NULL. --- system/database/DB_active_rec.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index b2638f25c..d58580637 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -447,14 +447,19 @@ class CI_DB_active_record extends CI_DB_driver { $k .= ' ='; } - if ($v != '') + if ($v !== '' AND $v !== NULL) { $v = ' '.$this->escape($v); } } else { - $k = $this->_protect_identifiers($k, TRUE); + + if ($escape === TRUE) + { + $k = $this->_protect_identifiers($k, TRUE); + } + } $this->ar_where[] = $prefix.$k.$v; -- cgit v1.2.3-24-g4f1b From 2385d30422b865052bbc6f333e6a189f46215a61 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 7 Apr 2008 14:01:01 +0000 Subject: Added rename_table() into DBForge. --- system/database/DB_forge.php | 21 +++++++++++++++++++++ system/database/drivers/mssql/mssql_forge.php | 19 +++++++++++++++++++ system/database/drivers/mysql/mysql_forge.php | 20 +++++++++++++++++++- system/database/drivers/mysqli/mysqli_forge.php | 19 +++++++++++++++++++ system/database/drivers/oci8/oci8_forge.php | 19 +++++++++++++++++++ system/database/drivers/odbc/odbc_forge.php | 20 ++++++++++++++++++++ system/database/drivers/postgre/postgre_forge.php | 19 +++++++++++++++++++ system/database/drivers/sqlite/sqlite_driver.php | 18 ++++++++++++++++++ 8 files changed, 154 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index cd468bc6a..5f25ebedc 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -208,6 +208,27 @@ class CI_DB_forge { // -------------------------------------------------------------------- + /** + * Rename Table + * + * @access public + * @param string the old table name + * @param string the new table name + * @return bool + */ + function rename_table($table_name, $new_table_name) + { + if ($table_name == '' OR $new_table_name == '') + { + show_error('A table name is required for that operation.'); + } + + $sql = $this->_rename_table($table_name, $new_table_name); + return $this->db->query($sql); + } + + // -------------------------------------------------------------------- + /** * Column Add * diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php index baf776c74..63063f259 100644 --- a/system/database/drivers/mssql/mssql_forge.php +++ b/system/database/drivers/mssql/mssql_forge.php @@ -215,5 +215,24 @@ class CI_DB_mssql_forge extends CI_DB_forge { } + // -------------------------------------------------------------------- + + /** + * Rename a table + * + * Generates a platform-specific query so that a table can be renamed + * + * @access private + * @param string the old table name + * @param string the new table name + * @return string + */ + function _rename_table($table_name, $new_table_name) + { + // I think this syntax will work, but can find little documentation on renaming tables in MSSQL + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); + return $sql; + } + } ?> \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index 6e3a2d170..4eb449ef2 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -177,7 +177,7 @@ class CI_DB_mysql_forge extends CI_DB_forge { * Drop Table * * @access private - * @return bool + * @return string */ function _drop_table($table) { @@ -219,5 +219,23 @@ class CI_DB_mysql_forge extends CI_DB_forge { return $sql; } + // -------------------------------------------------------------------- + + /** + * Rename a table + * + * Generates a platform-specific query so that a table can be renamed + * + * @access private + * @param string the old table name + * @param string the new table name + * @return string + */ + function _rename_table($table_name, $new_table_name) + { + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); + return $sql; + } + } ?> \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index cb315a450..46a107565 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -213,5 +213,24 @@ class CI_DB_mysqli_forge extends CI_DB_forge { return $sql; } + + // -------------------------------------------------------------------- + + /** + * Rename a table + * + * Generates a platform-specific query so that a table can be renamed + * + * @access private + * @param string the old table name + * @param string the new table name + * @return string + */ + function _rename_table($table_name, $new_table_name) + { + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); + return $sql; + } + } ?> \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index b9d9e6354..a3940aedb 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -212,5 +212,24 @@ class CI_DB_oci8_forge extends CI_DB_forge { } + // -------------------------------------------------------------------- + + /** + * Rename a table + * + * Generates a platform-specific query so that a table can be renamed + * + * @access private + * @param string the old table name + * @param string the new table name + * @return string + */ + function _rename_table($table_name, $new_table_name) + { + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); + return $sql; + } + + } ?> \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php index 374c15fcd..66e1722d8 100644 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -232,5 +232,25 @@ class CI_DB_odbc_forge extends CI_DB_forge { } + + // -------------------------------------------------------------------- + + /** + * Rename a table + * + * Generates a platform-specific query so that a table can be renamed + * + * @access private + * @param string the old table name + * @param string the new table name + * @return string + */ + function _rename_table($table_name, $new_table_name) + { + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); + return $sql; + } + + } ?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index 81ac8e92b..72a61748d 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -215,5 +215,24 @@ class CI_DB_postgre_forge extends CI_DB_forge { } + // -------------------------------------------------------------------- + + /** + * Rename a table + * + * Generates a platform-specific query so that a table can be renamed + * + * @access private + * @param string the old table name + * @param string the new table name + * @return string + */ + function _rename_table($table_name, $new_table_name) + { + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); + return $sql; + } + + } ?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 16a8308c1..2ad5d6120 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -635,6 +635,24 @@ class CI_DB_sqlite_driver extends CI_DB { @sqlite_close($conn_id); } + // -------------------------------------------------------------------- + + /** + * Rename a table + * + * Generates a platform-specific query so that a table can be renamed + * + * @access private + * @param string the old table name + * @param string the new table name + * @return string + */ + function _rename_table($table_name, $new_table_name) + { + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); + return $sql; + } + } -- cgit v1.2.3-24-g4f1b From d7f421133d78156a8587f9c244b4bebb4d2c6a8c Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 11 Apr 2008 11:43:11 +0000 Subject: The MySQLi forge class is now in sync with MySQL forge. --- system/database/drivers/mysqli/mysqli_forge.php | 125 ++++++++++++------------ 1 file changed, 65 insertions(+), 60 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index 46a107565..e6bc0093f 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -53,40 +53,16 @@ class CI_DB_mysqli_forge extends CI_DB_forge { // -------------------------------------------------------------------- /** - * Drop Table - * - * @access private - * @return bool - */ - function _drop_table($table) - { - return "DROP TABLE IF EXISTS ".$this->db->_escape_table($table); - } - - // -------------------------------------------------------------------- - - /** - * Create Table + * Process Fields * * @access private - * @param string the table name - * @param array the fields - * @param mixed primary key(s) - * @param mixed key(s) - * @param boolean should 'IF NOT EXISTS' be added to the SQL - * @return bool + * @param mixed the fields + * @return string */ - function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) + function _process_fields($fields) { - $sql = 'CREATE TABLE '; - - if ($if_not_exists === TRUE) - { - $sql .= 'IF NOT EXISTS '; - } - - $sql .= $this->db->_escape_table($table)." ("; $current_field_count = 0; + $sql = ''; foreach ($fields as $field=>$attributes) { @@ -102,8 +78,16 @@ class CI_DB_mysqli_forge extends CI_DB_forge { $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']).' '; + } - $sql .= ' '.$attributes['TYPE']; + if (array_key_exists('TYPE', $attributes)) + { + $sql .= ' '.$attributes['TYPE']; + } if (array_key_exists('CONSTRAINT', $attributes)) { @@ -120,13 +104,9 @@ class CI_DB_mysqli_forge extends CI_DB_forge { $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; } - if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) - { - $sql .= ' NULL'; - } - else + if (array_key_exists('NULL', $attributes)) { - $sql .= ' NOT NULL'; + $sql .= ($attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL'; } if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) @@ -141,6 +121,35 @@ class CI_DB_mysqli_forge extends CI_DB_forge { $sql .= ','; } } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Create Table + * + * @access private + * @param string the table name + * @param mixed the fields + * @param mixed primary key(s) + * @param mixed key(s) + * @param boolean should 'IF NOT EXISTS' be added to the SQL + * @return bool + */ + 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_table($table)." ("; + + $sql .= $this->_process_fields($fields); if (count($primary_keys) > 0) { @@ -164,6 +173,19 @@ class CI_DB_mysqli_forge extends CI_DB_forge { // -------------------------------------------------------------------- + /** + * Drop Table + * + * @access private + * @return string + */ + function _drop_table($table) + { + return "DROP TABLE IF EXISTS ".$this->db->_escape_table($table); + } + + // -------------------------------------------------------------------- + /** * Alter table query * @@ -173,45 +195,28 @@ class CI_DB_mysqli_forge extends CI_DB_forge { * @access private * @param string the ALTER type (ADD, DROP, CHANGE) * @param string the column name - * @param string the table name - * @param string the column definition - * @param string the default value - * @param boolean should 'NOT NULL' be added + * @param array fields * @param string the field after which we should add the new field * @return object */ - function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') + function _alter_table($alter_type, $table, $fields, $after_field = '') { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name); + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type "; // DROP has everything it needs now. if ($alter_type == 'DROP') { - return $sql; + return $sql.$this->db->_protect_identifiers($fields); } - $sql .= " $column_definition"; - - if ($default_value != '') - { - $sql .= " DEFAULT \"$default_value\""; - } - - if ($null === NULL) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } + $sql .= $this->_process_fields($fields); if ($after_field != '') { $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); } - return $sql; + return $sql; } // -------------------------------------------------------------------- @@ -231,6 +236,6 @@ class CI_DB_mysqli_forge extends CI_DB_forge { $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); return $sql; } - + } ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 5162fc778acb1ecc8f879578e48bde9ce767775c Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 15 Apr 2008 20:05:37 +0000 Subject: Fixed an AR bug when joining with a table alias and table prefix (#4400). --- system/database/DB_active_rec.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index d58580637..6f50c110d 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1476,7 +1476,7 @@ class CI_DB_active_record extends CI_DB_driver { $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; - $sql .= (count($this->ar_select) == 0) ? '*' : implode(', ', $this->ar_select); + $sql .= (count($this->ar_select) == 0) ? '*' : implode(', ', $this->_filter_table_aliases($this->ar_select)); if ($select_override !== FALSE) { -- cgit v1.2.3-24-g4f1b From b94b89c69195a0708add8dedb1721f12bcafbf8c Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 28 Apr 2008 23:18:00 +0000 Subject: Added a valid_emails rule to the Validation class. --- system/database/drivers/mysql/mysql_driver.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 2bc66ecf2..f435c0bc4 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -314,11 +314,8 @@ class CI_DB_mysql_driver extends CI_DB { $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($this->dbprefix.$table)); - if ($query->num_rows() == 0) - return '0'; - $row = $query->row(); - return $row->numrows; + return (int)$row->numrows; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 7327499064ae165468c7440f8571c3e570b58a0b Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 5 May 2008 16:39:18 +0000 Subject: Added get_dir_file_info(), get_file_info(), and get_mime_by_extension() to the File Helper. Changed ( ! condition) into (! condition) within the code --- system/database/DB.php | 10 ++--- system/database/DB_active_rec.php | 44 +++++++++++----------- system/database/DB_cache.php | 10 ++--- system/database/DB_driver.php | 40 ++++++++++---------- system/database/DB_result.php | 6 +-- system/database/DB_utility.php | 10 ++--- system/database/drivers/mssql/mssql_driver.php | 6 +-- system/database/drivers/mysql/mysql_driver.php | 6 +-- system/database/drivers/mysqli/mysqli_driver.php | 6 +-- system/database/drivers/oci8/oci8_driver.php | 12 +++--- system/database/drivers/odbc/odbc_driver.php | 6 +-- system/database/drivers/postgre/postgre_driver.php | 6 +-- system/database/drivers/sqlite/sqlite_driver.php | 10 ++--- system/database/drivers/sqlite/sqlite_forge.php | 2 +- system/database/drivers/sqlite/sqlite_utility.php | 2 +- 15 files changed, 88 insertions(+), 88 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index 16ca1c888..8efe05560 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -29,7 +29,7 @@ function &DB($params = '', $active_record_override = FALSE) { include(APPPATH.'config/database'.EXT); - if ( ! isset($db) OR count($db) == 0) + if (! isset($db) OR count($db) == 0) { show_error('No database connection settings were found in the database config file.'); } @@ -39,7 +39,7 @@ function &DB($params = '', $active_record_override = FALSE) $active_group = $params; } - if ( ! isset($active_group) OR ! isset($db[$active_group])) + if (! isset($active_group) OR ! isset($db[$active_group])) { show_error('You have specified an invalid database connection group.'); } @@ -71,7 +71,7 @@ function &DB($params = '', $active_record_override = FALSE) } // No DB specified yet? Beat them senseless... - if ( ! isset($params['dbdriver']) OR $params['dbdriver'] == '') + if (! isset($params['dbdriver']) OR $params['dbdriver'] == '') { show_error('You have not selected a database type to connect to.'); } @@ -92,14 +92,14 @@ function &DB($params = '', $active_record_override = FALSE) { require_once(BASEPATH.'database/DB_active_rec'.EXT); - if ( ! class_exists('CI_DB')) + if (! class_exists('CI_DB')) { eval('class CI_DB extends CI_DB_active_record { }'); } } else { - if ( ! class_exists('CI_DB')) + if (! class_exists('CI_DB')) { eval('class CI_DB extends CI_DB_driver { }'); } diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 6f50c110d..1820bd202 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -315,7 +315,7 @@ class CI_DB_active_record extends CI_DB_driver { { $type = strtoupper(trim($type)); - if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'), TRUE)) + if (! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'), TRUE)) { $type = ''; } @@ -411,7 +411,7 @@ class CI_DB_active_record extends CI_DB_driver { */ function _where($key, $value = NULL, $type = 'AND ', $escape = TRUE) { - if ( ! is_array($key)) + if (! is_array($key)) { $key = array($key => $value); } @@ -420,13 +420,13 @@ class CI_DB_active_record extends CI_DB_driver { { $prefix = (count($this->ar_where) == 0) ? '' : $type; - if ( ! $this->_has_operator($k) && is_null($key[$k])) + if (! $this->_has_operator($k) && is_null($key[$k])) { // value appears not to have been set, assign the test to IS NULL $k .= ' IS NULL'; } - if ( ! is_null($v)) + if (! is_null($v)) { if ($escape === TRUE) @@ -442,7 +442,7 @@ class CI_DB_active_record extends CI_DB_driver { } } - if ( ! $this->_has_operator($k)) + if (! $this->_has_operator($k)) { $k .= ' ='; } @@ -690,7 +690,7 @@ class CI_DB_active_record extends CI_DB_driver { */ function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '') { - if ( ! is_array($field)) + if (! is_array($field)) { $field = array($field => $match); } @@ -832,7 +832,7 @@ class CI_DB_active_record extends CI_DB_driver { */ function _having($key, $value = '', $type = 'AND ', $escape = TRUE) { - if ( ! is_array($key)) + if (! is_array($key)) { $key = array($key => $value); } @@ -972,7 +972,7 @@ class CI_DB_active_record extends CI_DB_driver { { $key = $this->_object_to_array($key); - if ( ! is_array($key)) + if (! is_array($key)) { $key = array($key => $value); } @@ -1022,7 +1022,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->from($table); } - if ( ! is_null($limit)) + if (! is_null($limit)) { $this->limit($limit, $offset); } @@ -1087,12 +1087,12 @@ class CI_DB_active_record extends CI_DB_driver { $this->from($table); } - if ( ! is_null($where)) + if (! is_null($where)) { $this->where($where); } - if ( ! is_null($limit)) + if (! is_null($limit)) { $this->limit($limit, $offset); } @@ -1130,7 +1130,7 @@ class CI_DB_active_record extends CI_DB_driver { */ function insert($table = '', $set = NULL) { - if ( ! is_null($set)) + if (! is_null($set)) { $this->set($set); } @@ -1146,7 +1146,7 @@ class CI_DB_active_record extends CI_DB_driver { if ($table == '') { - if ( ! isset($this->ar_from[0])) + if (! isset($this->ar_from[0])) { if ($this->db_debug) { @@ -1179,7 +1179,7 @@ class CI_DB_active_record extends CI_DB_driver { */ function update($table = '', $set = NULL, $where = NULL, $limit = NULL) { - if ( ! is_null($set)) + if (! is_null($set)) { $this->set($set); } @@ -1195,7 +1195,7 @@ class CI_DB_active_record extends CI_DB_driver { if ($table == '') { - if ( ! isset($this->ar_from[0])) + if (! isset($this->ar_from[0])) { if ($this->db_debug) { @@ -1238,7 +1238,7 @@ class CI_DB_active_record extends CI_DB_driver { { if ($table == '') { - if ( ! isset($this->ar_from[0])) + if (! isset($this->ar_from[0])) { if ($this->db_debug) { @@ -1279,7 +1279,7 @@ class CI_DB_active_record extends CI_DB_driver { { if ($table == '') { - if ( ! isset($this->ar_from[0])) + if (! isset($this->ar_from[0])) { if ($this->db_debug) { @@ -1321,7 +1321,7 @@ class CI_DB_active_record extends CI_DB_driver { { if ($table == '') { - if ( ! isset($this->ar_from[0])) + if (! isset($this->ar_from[0])) { if ($this->db_debug) { @@ -1401,7 +1401,7 @@ class CI_DB_active_record extends CI_DB_driver { function _has_operator($str) { $str = trim($str); - if ( ! preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str)) + if (! preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str)) { return FALSE; } @@ -1474,7 +1474,7 @@ class CI_DB_active_record extends CI_DB_driver { { $this->_merge_cache(); - $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; + $sql = (! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; $sql .= (count($this->ar_select) == 0) ? '*' : implode(', ', $this->_filter_table_aliases($this->ar_select)); @@ -1577,7 +1577,7 @@ class CI_DB_active_record extends CI_DB_driver { */ function _object_to_array($object) { - if ( ! is_object($object)) + if (! is_object($object)) { return $object; } @@ -1586,7 +1586,7 @@ class CI_DB_active_record extends CI_DB_driver { foreach (get_object_vars($object) as $key => $val) { // There are some built in keys we need to ignore for this conversion - if ( ! is_object($val) && ! is_array($val) && $key != '_parent_name' && $key != '_ci_scaffolding' && $key != '_ci_scaff_table') + if (! is_object($val) && ! is_array($val) && $key != '_parent_name' && $key != '_ci_scaffolding' && $key != '_ci_scaff_table') { $array[$key] = $val; diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 08394da29..982725aaa 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -64,7 +64,7 @@ class CI_DB_Cache { // Add a trailing slash to the path if needed $path = preg_replace("/(.+?)\/*$/", "\\1/", $path); - if ( ! is_dir($path) OR ! is_really_writable($path)) + if (! is_dir($path) OR ! is_really_writable($path)) { // If the path is wrong we'll turn off caching return $this->CI->db->cache_off(); @@ -87,7 +87,7 @@ class CI_DB_Cache { */ function read($sql) { - if ( ! $this->check_path()) + if (! $this->check_path()) { return $this->CI->db->cache_off(); } @@ -115,7 +115,7 @@ class CI_DB_Cache { */ function write($sql, $object) { - if ( ! $this->check_path()) + if (! $this->check_path()) { return $this->CI->db->cache_off(); } @@ -127,9 +127,9 @@ class CI_DB_Cache { $filename = md5($sql); - if ( ! @is_dir($dir_path)) + if (! @is_dir($dir_path)) { - if ( ! @mkdir($dir_path, DIR_WRITE_MODE)) + if (! @mkdir($dir_path, DIR_WRITE_MODE)) { return FALSE; } diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index b1013178e..0f3a1ea0a 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -107,7 +107,7 @@ class CI_DB_driver { $this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect(); // No connection? Throw an error - if ( ! $this->conn_id) + if (! $this->conn_id) { log_message('error', 'Unable to connect to the database'); @@ -121,7 +121,7 @@ class CI_DB_driver { // Select the database if ($this->database != '') { - if ( ! $this->db_select()) + if (! $this->db_select()) { // Should we attempt to create the database? if ($create_db == TRUE) @@ -131,7 +131,7 @@ class CI_DB_driver { $CI->load->dbutil(); // Create the DB - if ( ! $CI->dbutil->create_database($this->database)) + if (! $CI->dbutil->create_database($this->database)) { log_message('error', 'Unable to create database: '.$this->database); @@ -401,7 +401,7 @@ class CI_DB_driver { { $driver = 'CI_DB_'.$this->dbdriver.'_result'; - if ( ! class_exists($driver)) + if (! class_exists($driver)) { include_once(BASEPATH.'database/DB_result'.EXT); include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result'.EXT); @@ -424,7 +424,7 @@ class CI_DB_driver { */ function simple_query($sql) { - if ( ! $this->conn_id) + if (! $this->conn_id) { $this->initialize(); } @@ -456,7 +456,7 @@ class CI_DB_driver { */ function trans_start($test_mode = FALSE) { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return FALSE; } @@ -481,7 +481,7 @@ class CI_DB_driver { */ function trans_complete() { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return FALSE; } @@ -539,7 +539,7 @@ class CI_DB_driver { return $sql; } - if ( ! is_array($binds)) + if (! is_array($binds)) { $binds = array($binds); } @@ -576,7 +576,7 @@ class CI_DB_driver { */ function is_write_type($sql) { - if ( ! preg_match('/^\s*"?(INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql)) + if (! preg_match('/^\s*"?(INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql)) { return FALSE; } @@ -683,7 +683,7 @@ class CI_DB_driver { { $fields = $this->list_fields($table); - if ( ! is_array($fields)) + if (! is_array($fields)) { return FALSE; } @@ -747,7 +747,7 @@ class CI_DB_driver { */ function table_exists($table_name) { - return ( ! in_array($this->prep_tablename($table_name), $this->list_tables())) ? FALSE : TRUE; + return (! in_array($this->prep_tablename($table_name), $this->list_tables())) ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -815,7 +815,7 @@ class CI_DB_driver { */ function field_exists($field_name, $table_name) { - return ( ! in_array($field_name, $this->list_fields($table_name))) ? FALSE : TRUE; + return (! in_array($field_name, $this->list_fields($table_name))) ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -899,7 +899,7 @@ class CI_DB_driver { $fields[$key] = $this->escape($val); } - if ( ! is_array($where)) + if (! is_array($where)) { $dest = array($where); } @@ -912,7 +912,7 @@ class CI_DB_driver { if ($val !== '') { - if ( ! $this->_has_operator($key)) + if (! $this->_has_operator($key)) { $key .= ' ='; } @@ -969,7 +969,7 @@ class CI_DB_driver { $function = $driver.$function; } - if ( ! function_exists($function)) + if (! function_exists($function)) { if ($this->db_debug) { @@ -1038,7 +1038,7 @@ class CI_DB_driver { */ function cache_delete($segment_one = '', $segment_two = '') { - if ( ! $this->_cache_init()) + if (! $this->_cache_init()) { return FALSE; } @@ -1055,7 +1055,7 @@ class CI_DB_driver { */ function cache_delete_all() { - if ( ! $this->_cache_init()) + if (! $this->_cache_init()) { return FALSE; } @@ -1078,7 +1078,7 @@ class CI_DB_driver { return TRUE; } - if ( ! @include(BASEPATH.'database/DB_cache'.EXT)) + if (! @include(BASEPATH.'database/DB_cache'.EXT)) { return $this->cache_off(); } @@ -1129,10 +1129,10 @@ class CI_DB_driver { } else { - $message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error; + $message = (! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error; } - if ( ! class_exists('CI_Exceptions')) + if (! class_exists('CI_Exceptions')) { // include(BASEPATH.'core/Exceptions'.EXT); include(BASEPATH.'libraries/Exceptions'.EXT); diff --git a/system/database/DB_result.php b/system/database/DB_result.php index c2eeefb94..cfe9d2a32 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -125,10 +125,10 @@ class CI_DB_result { */ function row($n = 0, $type = 'object') { - if ( ! is_numeric($n)) + if (! is_numeric($n)) { // We cache the row data for subsequent uses - if ( ! is_array($this->row_data)) + if (! is_array($this->row_data)) { $this->row_data = $this->row_array(0); } @@ -156,7 +156,7 @@ class CI_DB_result { function set_row($key, $value = NULL) { // We cache the row data for subsequent uses - if ( ! is_array($this->row_data)) + if (! is_array($this->row_data)) { $this->row_data = $this->row_array(0); } diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index d9b8fed74..11f1fb4de 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -175,7 +175,7 @@ class CI_DB_utility extends CI_DB_forge { */ function csv_from_result($query, $delim = ",", $newline = "\n", $enclosure = '"') { - if ( ! is_object($query) OR ! method_exists($query, 'field_names')) + if (! is_object($query) OR ! method_exists($query, 'field_names')) { show_error('You must submit a valid result object'); } @@ -217,7 +217,7 @@ class CI_DB_utility extends CI_DB_forge { */ function xml_from_result($query, $params = array()) { - if ( ! is_object($query) OR ! method_exists($query, 'field_names')) + if (! is_object($query) OR ! method_exists($query, 'field_names')) { show_error('You must submit a valid result object'); } @@ -225,7 +225,7 @@ class CI_DB_utility extends CI_DB_forge { // Set our default values foreach (array('root' => 'root', 'element' => 'element', 'newline' => "\n", 'tab' => "\t") as $key => $val) { - if ( ! isset($params[$key])) + if (! isset($params[$key])) { $params[$key] = $val; } @@ -310,7 +310,7 @@ class CI_DB_utility extends CI_DB_forge { // ------------------------------------------------------ // Validate the format - if ( ! in_array($prefs['format'], array('gzip', 'zip', 'txt'), TRUE)) + if (! in_array($prefs['format'], array('gzip', 'zip', 'txt'), TRUE)) { $prefs['format'] = 'txt'; } @@ -367,7 +367,7 @@ class CI_DB_utility extends CI_DB_forge { } // Tack on the ".sql" file extension if needed - if ( ! preg_match("|.+?\.sql$|", $prefs['filename'])) + if (! preg_match("|.+?\.sql$|", $prefs['filename'])) { $prefs['filename'] .= '.sql'; } diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 1ed333de0..6e67c57c0 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -132,7 +132,7 @@ class CI_DB_mssql_driver extends CI_DB { */ function trans_begin($test_mode = FALSE) { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } @@ -162,7 +162,7 @@ class CI_DB_mssql_driver extends CI_DB { */ function trans_commit() { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } @@ -187,7 +187,7 @@ class CI_DB_mssql_driver extends CI_DB { */ function trans_rollback() { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index f435c0bc4..f15983d2b 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -161,7 +161,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function trans_begin($test_mode = FALSE) { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } @@ -192,7 +192,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function trans_commit() { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } @@ -218,7 +218,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function trans_rollback() { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 6ff37f7e2..a196f755a 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -164,7 +164,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ function trans_begin($test_mode = FALSE) { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } @@ -195,7 +195,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ function trans_commit() { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } @@ -221,7 +221,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ function trans_rollback() { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 364268b98..8fc20449f 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -155,7 +155,7 @@ class CI_DB_oci8_driver extends CI_DB { */ function _set_stmt_id($sql) { - if ( ! is_resource($this->stmt_id)) + if (! is_resource($this->stmt_id)) { $this->stmt_id = ociparse($this->conn_id, $this->_prep_query($sql)); } @@ -254,7 +254,7 @@ class CI_DB_oci8_driver extends CI_DB { */ function _bind_params($params) { - if ( ! is_array($params) OR ! is_resource($this->stmt_id)) + if (! is_array($params) OR ! is_resource($this->stmt_id)) { return; } @@ -263,7 +263,7 @@ class CI_DB_oci8_driver extends CI_DB { { foreach (array('name', 'value', 'type', 'length') as $val) { - if ( ! isset($param[$val])) + if (! isset($param[$val])) { $param[$val] = ''; } @@ -283,7 +283,7 @@ class CI_DB_oci8_driver extends CI_DB { */ function trans_begin($test_mode = FALSE) { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } @@ -313,7 +313,7 @@ class CI_DB_oci8_driver extends CI_DB { */ function trans_commit() { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } @@ -339,7 +339,7 @@ class CI_DB_oci8_driver extends CI_DB { */ function trans_rollback() { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 82fe36b5d..20e34ec7b 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -152,7 +152,7 @@ class CI_DB_odbc_driver extends CI_DB { */ function trans_begin($test_mode = FALSE) { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } @@ -181,7 +181,7 @@ class CI_DB_odbc_driver extends CI_DB { */ function trans_commit() { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } @@ -207,7 +207,7 @@ class CI_DB_odbc_driver extends CI_DB { */ function trans_rollback() { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 4eff97fcc..46ba1d009 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -150,7 +150,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function trans_begin($test_mode = FALSE) { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } @@ -179,7 +179,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function trans_commit() { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } @@ -203,7 +203,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function trans_rollback() { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 2ad5d6120..70148f360 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -48,7 +48,7 @@ class CI_DB_sqlite_driver extends CI_DB { */ function db_connect() { - if ( ! $conn_id = @sqlite_open($this->database, FILE_WRITE_MODE, $error)) + if (! $conn_id = @sqlite_open($this->database, FILE_WRITE_MODE, $error)) { log_message('error', $error); @@ -73,7 +73,7 @@ class CI_DB_sqlite_driver extends CI_DB { */ function db_pconnect() { - if ( ! $conn_id = @sqlite_popen($this->database, FILE_WRITE_MODE, $error)) + if (! $conn_id = @sqlite_popen($this->database, FILE_WRITE_MODE, $error)) { log_message('error', $error); @@ -171,7 +171,7 @@ class CI_DB_sqlite_driver extends CI_DB { */ function trans_begin($test_mode = FALSE) { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } @@ -201,7 +201,7 @@ class CI_DB_sqlite_driver extends CI_DB { */ function trans_commit() { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } @@ -226,7 +226,7 @@ class CI_DB_sqlite_driver extends CI_DB { */ function trans_rollback() { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php index 1fd2a2bd4..44950bfc7 100644 --- a/system/database/drivers/sqlite/sqlite_forge.php +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -49,7 +49,7 @@ class CI_DB_sqlite_forge extends CI_DB_forge { */ function _drop_database($name) { - if ( ! @file_exists($this->db->database) OR ! @unlink($this->db->database)) + if (! @file_exists($this->db->database) OR ! @unlink($this->db->database)) { if ($this->db->db_debug) { diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index d1e1fe026..ab58f8fd7 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -124,7 +124,7 @@ class CI_DB_sqlite_utility extends CI_DB_utility { */ function _drop_database($name) { - if ( ! @file_exists($this->db->database) OR ! @unlink($this->db->database)) + if (! @file_exists($this->db->database) OR ! @unlink($this->db->database)) { if ($this->db->db_debug) { -- cgit v1.2.3-24-g4f1b From 7f309810a6d3da76c1a2c4ef8e900c88f47afee4 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 6 May 2008 00:17:10 +0000 Subject: Fixed a bug in DB Forge, when inserting an id field (#3456). --- system/database/DB_forge.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index 5f25ebedc..2ddb21be7 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -132,12 +132,13 @@ class CI_DB_forge { { if ($field == 'id') { - $this->fields[] = array('id' => array( - 'type' => 'INT', - 'constraint' => 9, - 'auto_increment' => TRUE - ) - ); + $this->add_field(array( + 'id' => array( + 'type' => 'INT', + 'constraint' => 9, + 'auto_increment' => TRUE + ) + )); $this->add_key('id', TRUE); } else -- cgit v1.2.3-24-g4f1b From 05097759476d3e18f2699503c1c47a30dba702af Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 7 May 2008 19:58:23 +0000 Subject: Added checks for objects in DB driver instead of just resources to accommodate MySQLi, and fixed check in mysqli_result.php checking for a resource. http://codeigniter.com/bug_tracker/bug/3461/ --- system/database/DB_driver.php | 4 ++-- system/database/drivers/mysqli/mysqli_result.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 0f3a1ea0a..5a55002f7 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -98,7 +98,7 @@ class CI_DB_driver { { // If an existing DB connection resource is supplied // there is no need to connect and select the database - if (is_resource($this->conn_id)) + if (is_resource($this->conn_id) OR is_object($this->conn_id)) { return TRUE; } @@ -1097,7 +1097,7 @@ class CI_DB_driver { */ function close() { - if (is_resource($this->conn_id)) + if (is_resource($this->conn_id) OR is_object($this->conn_id)) { $this->_close($this->conn_id); } diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index 586c29252..692d4f729 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -114,7 +114,7 @@ class CI_DB_mysqli_result extends CI_DB_result { */ function free_result() { - if (is_resource($this->result_id)) + if (is_object($this->result_id)) { mysqli_free_result($this->result_id); $this->result_id = FALSE; -- cgit v1.2.3-24-g4f1b From d007243f15002bac68291fc7e8acbe6303f81a78 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 7 May 2008 22:06:51 +0000 Subject: flipped the $not flag for or_where_not_in() http://codeigniter.com/bug_tracker/bug/4171/ --- system/database/DB_active_rec.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 1820bd202..49d438727 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -483,7 +483,6 @@ class CI_DB_active_record extends CI_DB_driver { * @access public * @param string The field to search * @param array The values searched on - * @return object */ function where_in($key = NULL, $values = NULL) @@ -502,7 +501,6 @@ class CI_DB_active_record extends CI_DB_driver { * @access public * @param string The field to search * @param array The values searched on - * @return object */ function or_where_in($key = NULL, $values = NULL) @@ -521,7 +519,6 @@ class CI_DB_active_record extends CI_DB_driver { * @access public * @param string The field to search * @param array The values searched on - * @return object */ function where_not_in($key = NULL, $values = NULL) @@ -540,12 +537,11 @@ class CI_DB_active_record extends CI_DB_driver { * @access public * @param string The field to search * @param array The values searched on - * @return object */ function or_where_not_in($key = NULL, $values = NULL) { - return $this->_where_in($key, $values, FALSE, 'OR '); + return $this->_where_in($key, $values, TRUE, 'OR '); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 0f13a13bbf7bc54dc2ef4dda44bbe2f3890af8c6 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 8 May 2008 18:54:03 +0000 Subject: added SET to the list of write type queries --- system/database/DB_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 5a55002f7..a5ca75dd6 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -576,7 +576,7 @@ class CI_DB_driver { */ function is_write_type($sql) { - if (! preg_match('/^\s*"?(INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql)) + if (! preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql)) { return FALSE; } -- cgit v1.2.3-24-g4f1b From 5583e1aae64ff7e902136c4ba610d438dc2015d4 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Sun, 11 May 2008 15:48:20 +0000 Subject: removed closing PHP tag from all framework files --- system/database/DB.php | 1 - system/database/DB_active_rec.php | 1 - system/database/DB_cache.php | 1 - system/database/DB_driver.php | 1 - system/database/DB_forge.php | 1 - system/database/DB_result.php | 1 - system/database/DB_utility.php | 1 - system/database/drivers/mssql/mssql_driver.php | 1 - system/database/drivers/mssql/mssql_forge.php | 1 - system/database/drivers/mssql/mssql_result.php | 1 - system/database/drivers/mssql/mssql_utility.php | 1 - system/database/drivers/mysql/mysql_driver.php | 1 - system/database/drivers/mysql/mysql_forge.php | 1 - system/database/drivers/mysql/mysql_result.php | 1 - system/database/drivers/mysql/mysql_utility.php | 1 - system/database/drivers/mysqli/mysqli_driver.php | 1 - system/database/drivers/mysqli/mysqli_forge.php | 1 - system/database/drivers/mysqli/mysqli_result.php | 1 - system/database/drivers/mysqli/mysqli_utility.php | 1 - system/database/drivers/oci8/oci8_driver.php | 1 - system/database/drivers/oci8/oci8_forge.php | 1 - system/database/drivers/oci8/oci8_result.php | 1 - system/database/drivers/oci8/oci8_utility.php | 1 - system/database/drivers/odbc/odbc_driver.php | 1 - system/database/drivers/odbc/odbc_forge.php | 1 - system/database/drivers/odbc/odbc_result.php | 1 - system/database/drivers/odbc/odbc_utility.php | 1 - system/database/drivers/postgre/postgre_driver.php | 1 - system/database/drivers/postgre/postgre_forge.php | 1 - system/database/drivers/postgre/postgre_result.php | 1 - system/database/drivers/postgre/postgre_utility.php | 1 - system/database/drivers/sqlite/sqlite_driver.php | 1 - system/database/drivers/sqlite/sqlite_forge.php | 1 - system/database/drivers/sqlite/sqlite_result.php | 1 - system/database/drivers/sqlite/sqlite_utility.php | 1 - 35 files changed, 35 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index 8efe05560..55d73ba0b 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -120,4 +120,3 @@ function &DB($params = '', $active_record_override = FALSE) } -?> \ No newline at end of file diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 49d438727..af042dcd2 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1749,4 +1749,3 @@ class CI_DB_active_record extends CI_DB_driver { } } -?> \ No newline at end of file diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 982725aaa..a154ba86d 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -186,4 +186,3 @@ class CI_DB_Cache { } -?> \ No newline at end of file diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index a5ca75dd6..dd235103e 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1145,4 +1145,3 @@ class CI_DB_driver { } -?> \ No newline at end of file diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index 2ddb21be7..258da346d 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -341,4 +341,3 @@ class CI_DB_forge { } } -?> \ No newline at end of file diff --git a/system/database/DB_result.php b/system/database/DB_result.php index cfe9d2a32..90338d0c4 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -338,4 +338,3 @@ class CI_DB_result { } // END DB_result class -?> \ No newline at end of file diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 11f1fb4de..2604a3e76 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -384,4 +384,3 @@ class CI_DB_utility extends CI_DB_forge { } -?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 6e67c57c0..3a9bb31cc 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -641,4 +641,3 @@ class CI_DB_mssql_driver extends CI_DB { } -?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php index 63063f259..b81b565eb 100644 --- a/system/database/drivers/mssql/mssql_forge.php +++ b/system/database/drivers/mssql/mssql_forge.php @@ -235,4 +235,3 @@ class CI_DB_mssql_forge extends CI_DB_forge { } } -?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index c95fd91f6..9044bc095 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -170,4 +170,3 @@ class CI_DB_mssql_result extends CI_DB_result { } -?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index 87f8196f7..9ba65742c 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -118,4 +118,3 @@ class CI_DB_mssql_utility extends CI_DB_utility { } -?> \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index f15983d2b..9fd042151 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -649,4 +649,3 @@ class CI_DB_mysql_driver extends CI_DB { } -?> \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index 4eb449ef2..e9ea94706 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -238,4 +238,3 @@ class CI_DB_mysql_forge extends CI_DB_forge { } } -?> \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index 9e6a3c3d1..7c5125fc4 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -170,4 +170,3 @@ class CI_DB_mysql_result extends CI_DB_result { } -?> \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index dc8fd0866..22bc23383 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -249,4 +249,3 @@ class CI_DB_mysql_utility extends CI_DB_utility { } } -?> \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index a196f755a..4ffbbaca1 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -645,4 +645,3 @@ class CI_DB_mysqli_driver extends CI_DB { } -?> \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index e6bc0093f..a0ff9f574 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -238,4 +238,3 @@ class CI_DB_mysqli_forge extends CI_DB_forge { } } -?> \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index 692d4f729..b1a060405 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -170,4 +170,3 @@ class CI_DB_mysqli_result extends CI_DB_result { } -?> \ 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 4ab2bb1d1..75f4a4192 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -118,4 +118,3 @@ class CI_DB_mysqli_utility extends CI_DB_utility { } } -?> \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 8fc20449f..fb288087c 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -761,4 +761,3 @@ class CI_DB_oci8_driver extends CI_DB { } -?> \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index a3940aedb..6ca6c5434 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -232,4 +232,3 @@ class CI_DB_oci8_forge extends CI_DB_forge { } -?> \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 30dd0da09..9f1257642 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -248,4 +248,3 @@ class CI_DB_oci8_result extends CI_DB_result { } -?> \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 117f8e629..c361c5ec3 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -117,4 +117,3 @@ class CI_DB_oci8_utility extends CI_DB_utility { } } -?> \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 20e34ec7b..93a1d4e05 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -613,4 +613,3 @@ class CI_DB_odbc_driver extends CI_DB { } -?> \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php index 66e1722d8..ee4745ccc 100644 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -253,4 +253,3 @@ class CI_DB_odbc_forge extends CI_DB_forge { } -?> \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index dd3f92382..d513171d0 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -229,4 +229,3 @@ class CI_DB_odbc_result extends CI_DB_result { } -?> \ 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 f74d031bd..75d1ca283 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -143,4 +143,3 @@ class CI_DB_odbc_utility extends CI_DB_utility { return FALSE; } } -?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 46ba1d009..7c46e7a4b 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -641,4 +641,3 @@ class CI_DB_postgre_driver extends CI_DB { } -?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index 72a61748d..ad4c5cdae 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -235,4 +235,3 @@ class CI_DB_postgre_forge extends CI_DB_forge { } -?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index fdce01aac..f3fb89951 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -170,4 +170,3 @@ class CI_DB_postgre_result extends CI_DB_result { } -?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 573654f68..25f44f06c 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -119,4 +119,3 @@ class CI_DB_postgre_utility extends CI_DB_utility { } -?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 70148f360..f84ee2095 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -656,4 +656,3 @@ class CI_DB_sqlite_driver extends CI_DB { } -?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php index 44950bfc7..8afd39e99 100644 --- a/system/database/drivers/sqlite/sqlite_forge.php +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -231,4 +231,3 @@ class CI_DB_sqlite_forge extends CI_DB_forge { } } -?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index b8f3dc5b7..92bc3872a 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -180,4 +180,3 @@ class CI_DB_sqlite_result extends CI_DB_result { } -?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index ab58f8fd7..8d2b44362 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -136,4 +136,3 @@ class CI_DB_sqlite_utility extends CI_DB_utility { } } -?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c7deac9f2f9e43cedb18202542e8a46061df046e Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Sun, 11 May 2008 16:27:41 +0000 Subject: Undoing change committed in r1115 --- system/database/DB.php | 1 + system/database/DB_active_rec.php | 1 + system/database/DB_cache.php | 1 + system/database/DB_driver.php | 1 + system/database/DB_forge.php | 1 + system/database/DB_result.php | 1 + system/database/DB_utility.php | 1 + system/database/drivers/mssql/mssql_driver.php | 1 + system/database/drivers/mssql/mssql_forge.php | 1 + system/database/drivers/mssql/mssql_result.php | 1 + system/database/drivers/mssql/mssql_utility.php | 1 + system/database/drivers/mysql/mysql_driver.php | 1 + system/database/drivers/mysql/mysql_forge.php | 1 + system/database/drivers/mysql/mysql_result.php | 1 + system/database/drivers/mysql/mysql_utility.php | 1 + system/database/drivers/mysqli/mysqli_driver.php | 1 + system/database/drivers/mysqli/mysqli_forge.php | 1 + system/database/drivers/mysqli/mysqli_result.php | 1 + system/database/drivers/mysqli/mysqli_utility.php | 1 + system/database/drivers/oci8/oci8_driver.php | 1 + system/database/drivers/oci8/oci8_forge.php | 1 + system/database/drivers/oci8/oci8_result.php | 1 + system/database/drivers/oci8/oci8_utility.php | 1 + system/database/drivers/odbc/odbc_driver.php | 1 + system/database/drivers/odbc/odbc_forge.php | 1 + system/database/drivers/odbc/odbc_result.php | 1 + system/database/drivers/odbc/odbc_utility.php | 1 + system/database/drivers/postgre/postgre_driver.php | 1 + system/database/drivers/postgre/postgre_forge.php | 1 + system/database/drivers/postgre/postgre_result.php | 1 + system/database/drivers/postgre/postgre_utility.php | 1 + system/database/drivers/sqlite/sqlite_driver.php | 1 + system/database/drivers/sqlite/sqlite_forge.php | 1 + system/database/drivers/sqlite/sqlite_result.php | 1 + system/database/drivers/sqlite/sqlite_utility.php | 1 + 35 files changed, 35 insertions(+) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index 55d73ba0b..8efe05560 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -120,3 +120,4 @@ function &DB($params = '', $active_record_override = FALSE) } +?> \ No newline at end of file diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index af042dcd2..49d438727 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1749,3 +1749,4 @@ class CI_DB_active_record extends CI_DB_driver { } } +?> \ No newline at end of file diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index a154ba86d..982725aaa 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -186,3 +186,4 @@ class CI_DB_Cache { } +?> \ No newline at end of file diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index dd235103e..a5ca75dd6 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1145,3 +1145,4 @@ class CI_DB_driver { } +?> \ No newline at end of file diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index 258da346d..2ddb21be7 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -341,3 +341,4 @@ class CI_DB_forge { } } +?> \ No newline at end of file diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 90338d0c4..cfe9d2a32 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -338,3 +338,4 @@ class CI_DB_result { } // END DB_result class +?> \ No newline at end of file diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 2604a3e76..11f1fb4de 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -384,3 +384,4 @@ class CI_DB_utility extends CI_DB_forge { } +?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 3a9bb31cc..6e67c57c0 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -641,3 +641,4 @@ class CI_DB_mssql_driver extends CI_DB { } +?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php index b81b565eb..63063f259 100644 --- a/system/database/drivers/mssql/mssql_forge.php +++ b/system/database/drivers/mssql/mssql_forge.php @@ -235,3 +235,4 @@ class CI_DB_mssql_forge extends CI_DB_forge { } } +?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index 9044bc095..c95fd91f6 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -170,3 +170,4 @@ class CI_DB_mssql_result extends CI_DB_result { } +?> \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index 9ba65742c..87f8196f7 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -118,3 +118,4 @@ class CI_DB_mssql_utility extends CI_DB_utility { } +?> \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 9fd042151..f15983d2b 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -649,3 +649,4 @@ class CI_DB_mysql_driver extends CI_DB { } +?> \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index e9ea94706..4eb449ef2 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -238,3 +238,4 @@ class CI_DB_mysql_forge extends CI_DB_forge { } } +?> \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index 7c5125fc4..9e6a3c3d1 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -170,3 +170,4 @@ class CI_DB_mysql_result extends CI_DB_result { } +?> \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 22bc23383..dc8fd0866 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -249,3 +249,4 @@ class CI_DB_mysql_utility extends CI_DB_utility { } } +?> \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 4ffbbaca1..a196f755a 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -645,3 +645,4 @@ class CI_DB_mysqli_driver extends CI_DB { } +?> \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index a0ff9f574..e6bc0093f 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -238,3 +238,4 @@ class CI_DB_mysqli_forge extends CI_DB_forge { } } +?> \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index b1a060405..692d4f729 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -170,3 +170,4 @@ class CI_DB_mysqli_result extends CI_DB_result { } +?> \ 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 75f4a4192..4ab2bb1d1 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -118,3 +118,4 @@ class CI_DB_mysqli_utility extends CI_DB_utility { } } +?> \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index fb288087c..8fc20449f 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -761,3 +761,4 @@ class CI_DB_oci8_driver extends CI_DB { } +?> \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index 6ca6c5434..a3940aedb 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -232,3 +232,4 @@ class CI_DB_oci8_forge extends CI_DB_forge { } +?> \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 9f1257642..30dd0da09 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -248,3 +248,4 @@ class CI_DB_oci8_result extends CI_DB_result { } +?> \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index c361c5ec3..117f8e629 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -117,3 +117,4 @@ class CI_DB_oci8_utility extends CI_DB_utility { } } +?> \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 93a1d4e05..20e34ec7b 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -613,3 +613,4 @@ class CI_DB_odbc_driver extends CI_DB { } +?> \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php index ee4745ccc..66e1722d8 100644 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -253,3 +253,4 @@ class CI_DB_odbc_forge extends CI_DB_forge { } +?> \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index d513171d0..dd3f92382 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -229,3 +229,4 @@ class CI_DB_odbc_result extends CI_DB_result { } +?> \ 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 75d1ca283..f74d031bd 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -143,3 +143,4 @@ class CI_DB_odbc_utility extends CI_DB_utility { return FALSE; } } +?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 7c46e7a4b..46ba1d009 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -641,3 +641,4 @@ class CI_DB_postgre_driver extends CI_DB { } +?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index ad4c5cdae..72a61748d 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -235,3 +235,4 @@ class CI_DB_postgre_forge extends CI_DB_forge { } +?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index f3fb89951..fdce01aac 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -170,3 +170,4 @@ class CI_DB_postgre_result extends CI_DB_result { } +?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 25f44f06c..573654f68 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -119,3 +119,4 @@ class CI_DB_postgre_utility extends CI_DB_utility { } +?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index f84ee2095..70148f360 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -656,3 +656,4 @@ class CI_DB_sqlite_driver extends CI_DB { } +?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php index 8afd39e99..44950bfc7 100644 --- a/system/database/drivers/sqlite/sqlite_forge.php +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -231,3 +231,4 @@ class CI_DB_sqlite_forge extends CI_DB_forge { } } +?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index 92bc3872a..b8f3dc5b7 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -180,3 +180,4 @@ class CI_DB_sqlite_result extends CI_DB_result { } +?> \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 8d2b44362..ab58f8fd7 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -136,3 +136,4 @@ class CI_DB_sqlite_utility extends CI_DB_utility { } } +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From a3ffbbb75ab9403941e4f810703313432b3993cc Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Sun, 11 May 2008 18:18:29 +0000 Subject: Removed closing PHP tags, replaced with a comment block identifying the end of the file --- system/database/DB.php | 4 +++- system/database/DB_active_rec.php | 4 +++- system/database/DB_cache.php | 4 +++- system/database/DB_driver.php | 4 +++- system/database/DB_forge.php | 4 +++- system/database/DB_result.php | 4 +++- system/database/DB_utility.php | 4 +++- system/database/drivers/mssql/mssql_driver.php | 4 +++- system/database/drivers/mssql/mssql_forge.php | 4 +++- system/database/drivers/mssql/mssql_result.php | 4 +++- system/database/drivers/mssql/mssql_utility.php | 4 +++- system/database/drivers/mysql/mysql_driver.php | 4 +++- system/database/drivers/mysql/mysql_forge.php | 4 +++- system/database/drivers/mysql/mysql_result.php | 4 +++- system/database/drivers/mysql/mysql_utility.php | 4 +++- system/database/drivers/mysqli/mysqli_driver.php | 4 +++- system/database/drivers/mysqli/mysqli_forge.php | 4 +++- system/database/drivers/mysqli/mysqli_result.php | 4 +++- system/database/drivers/mysqli/mysqli_utility.php | 4 +++- system/database/drivers/oci8/oci8_driver.php | 4 +++- system/database/drivers/oci8/oci8_forge.php | 4 +++- system/database/drivers/oci8/oci8_result.php | 4 +++- system/database/drivers/oci8/oci8_utility.php | 4 +++- system/database/drivers/odbc/odbc_driver.php | 4 +++- system/database/drivers/odbc/odbc_forge.php | 4 +++- system/database/drivers/odbc/odbc_result.php | 4 +++- system/database/drivers/odbc/odbc_utility.php | 4 +++- system/database/drivers/postgre/postgre_driver.php | 4 +++- system/database/drivers/postgre/postgre_forge.php | 4 +++- system/database/drivers/postgre/postgre_result.php | 4 +++- system/database/drivers/postgre/postgre_utility.php | 4 +++- system/database/drivers/sqlite/sqlite_driver.php | 4 +++- system/database/drivers/sqlite/sqlite_forge.php | 4 +++- system/database/drivers/sqlite/sqlite_result.php | 4 +++- system/database/drivers/sqlite/sqlite_utility.php | 4 +++- 35 files changed, 105 insertions(+), 35 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index 8efe05560..d603805a5 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -120,4 +120,6 @@ function &DB($params = '', $active_record_override = FALSE) } -?> \ No newline at end of file + +/* End of file DB.php */ +/* Location: ./system/database/DB.php */ \ No newline at end of file diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 49d438727..a4ef2e4db 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1749,4 +1749,6 @@ class CI_DB_active_record extends CI_DB_driver { } } -?> \ No newline at end of file + +/* End of file DB_active_rec.php */ +/* Location: ./system/database/DB_active_rec.php */ \ No newline at end of file diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 982725aaa..21113aff3 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -186,4 +186,6 @@ class CI_DB_Cache { } -?> \ No newline at end of file + +/* End of file DB_cache.php */ +/* Location: ./system/database/DB_cache.php */ \ No newline at end of file diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index a5ca75dd6..c296d4ca8 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1145,4 +1145,6 @@ class CI_DB_driver { } -?> \ No newline at end of file + +/* End of file DB_driver.php */ +/* Location: ./system/database/DB_driver.php */ \ No newline at end of file diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index 2ddb21be7..d7259c08c 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -341,4 +341,6 @@ class CI_DB_forge { } } -?> \ No newline at end of file + +/* End of file DB_forge.php */ +/* Location: ./system/database/DB_forge.php */ \ No newline at end of file diff --git a/system/database/DB_result.php b/system/database/DB_result.php index cfe9d2a32..b98d7a97b 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -338,4 +338,6 @@ class CI_DB_result { } // END DB_result class -?> \ No newline at end of file + +/* End of file DB_result.php */ +/* Location: ./system/database/DB_result.php */ \ No newline at end of file diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 11f1fb4de..5d4c2de45 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -384,4 +384,6 @@ class CI_DB_utility extends CI_DB_forge { } -?> \ No newline at end of file + +/* End of file DB_utility.php */ +/* Location: ./system/database/DB_utility.php */ \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 6e67c57c0..f789634f8 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -641,4 +641,6 @@ class CI_DB_mssql_driver extends CI_DB { } -?> \ No newline at end of file + +/* End of file mssql_driver.php */ +/* Location: ./system/database/drivers/mssql/mssql_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php index 63063f259..d42fd5ee6 100644 --- a/system/database/drivers/mssql/mssql_forge.php +++ b/system/database/drivers/mssql/mssql_forge.php @@ -235,4 +235,6 @@ class CI_DB_mssql_forge extends CI_DB_forge { } } -?> \ No newline at end of file + +/* End of file mssql_forge.php */ +/* Location: ./system/database/drivers/mssql/mssql_forge.php */ \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index c95fd91f6..fded4cf37 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -170,4 +170,6 @@ class CI_DB_mssql_result extends CI_DB_result { } -?> \ No newline at end of file + +/* End of file mssql_result.php */ +/* Location: ./system/database/drivers/mssql/mssql_result.php */ \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index 87f8196f7..75a8fb4cd 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -118,4 +118,6 @@ class CI_DB_mssql_utility extends CI_DB_utility { } -?> \ No newline at end of file + +/* End of file mssql_utility.php */ +/* Location: ./system/database/drivers/mssql/mssql_utility.php */ \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index f15983d2b..397af02f5 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -649,4 +649,6 @@ class CI_DB_mysql_driver extends CI_DB { } -?> \ No newline at end of file + +/* End of file mysql_driver.php */ +/* Location: ./system/database/drivers/mysql/mysql_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index 4eb449ef2..6701c42d5 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -238,4 +238,6 @@ class CI_DB_mysql_forge extends CI_DB_forge { } } -?> \ No newline at end of file + +/* End of file mysql_forge.php */ +/* Location: ./system/database/drivers/mysql/mysql_forge.php */ \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index 9e6a3c3d1..01b57e1e7 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -170,4 +170,6 @@ class CI_DB_mysql_result extends CI_DB_result { } -?> \ No newline at end of file + +/* End of file mysql_result.php */ +/* Location: ./system/database/drivers/mysql/mysql_result.php */ \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index dc8fd0866..0804f291c 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -249,4 +249,6 @@ class CI_DB_mysql_utility extends CI_DB_utility { } } -?> \ No newline at end of file + +/* End of file mysql_utility.php */ +/* Location: ./system/database/drivers/mysql/mysql_utility.php */ \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index a196f755a..c993e3368 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -645,4 +645,6 @@ class CI_DB_mysqli_driver extends CI_DB { } -?> \ No newline at end of file + +/* End of file mysqli_driver.php */ +/* Location: ./system/database/drivers/mysqli/mysqli_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index e6bc0093f..087f9b80b 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -238,4 +238,6 @@ class CI_DB_mysqli_forge extends CI_DB_forge { } } -?> \ No newline at end of file + +/* End of file mysqli_forge.php */ +/* Location: ./system/database/drivers/mysqli/mysqli_forge.php */ \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index 692d4f729..6b42d35e9 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -170,4 +170,6 @@ class CI_DB_mysqli_result extends CI_DB_result { } -?> \ No newline at end of file + +/* End of file mysqli_result.php */ +/* Location: ./system/database/drivers/mysqli/mysqli_result.php */ \ 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 4ab2bb1d1..24b05b7af 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -118,4 +118,6 @@ class CI_DB_mysqli_utility extends CI_DB_utility { } } -?> \ No newline at end of file + +/* End of file mysqli_utility.php */ +/* Location: ./system/database/drivers/mysqli/mysqli_utility.php */ \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 8fc20449f..367095990 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -761,4 +761,6 @@ class CI_DB_oci8_driver extends CI_DB { } -?> \ No newline at end of file + +/* End of file oci8_driver.php */ +/* Location: ./system/database/drivers/oci8/oci8_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index a3940aedb..64dd2a202 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -232,4 +232,6 @@ class CI_DB_oci8_forge extends CI_DB_forge { } -?> \ No newline at end of file + +/* End of file oci8_forge.php */ +/* Location: ./system/database/drivers/oci8/oci8_forge.php */ \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 30dd0da09..416c57de0 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -248,4 +248,6 @@ class CI_DB_oci8_result extends CI_DB_result { } -?> \ No newline at end of file + +/* End of file oci8_result.php */ +/* Location: ./system/database/drivers/oci8/oci8_result.php */ \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 117f8e629..93eaa226f 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -117,4 +117,6 @@ class CI_DB_oci8_utility extends CI_DB_utility { } } -?> \ No newline at end of file + +/* End of file oci8_utility.php */ +/* Location: ./system/database/drivers/oci8/oci8_utility.php */ \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 20e34ec7b..4511592bb 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -613,4 +613,6 @@ class CI_DB_odbc_driver extends CI_DB { } -?> \ No newline at end of file + +/* End of file odbc_driver.php */ +/* Location: ./system/database/drivers/odbc/odbc_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php index 66e1722d8..fb011f298 100644 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -253,4 +253,6 @@ class CI_DB_odbc_forge extends CI_DB_forge { } -?> \ No newline at end of file + +/* End of file odbc_forge.php */ +/* Location: ./system/database/drivers/odbc/odbc_forge.php */ \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index dd3f92382..4acfb056e 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -229,4 +229,6 @@ class CI_DB_odbc_result extends CI_DB_result { } -?> \ No newline at end of file + +/* End of file odbc_result.php */ +/* Location: ./system/database/drivers/odbc/odbc_result.php */ \ 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 f74d031bd..ac8b5d808 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -143,4 +143,6 @@ class CI_DB_odbc_utility extends CI_DB_utility { return FALSE; } } -?> \ No newline at end of file + +/* End of file odbc_utility.php */ +/* Location: ./system/database/drivers/odbc/odbc_utility.php */ \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 46ba1d009..4fd92f0c0 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -641,4 +641,6 @@ class CI_DB_postgre_driver extends CI_DB { } -?> \ No newline at end of file + +/* End of file postgre_driver.php */ +/* Location: ./system/database/drivers/postgre/postgre_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index 72a61748d..fb4fcf128 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -235,4 +235,6 @@ class CI_DB_postgre_forge extends CI_DB_forge { } -?> \ No newline at end of file + +/* End of file postgre_forge.php */ +/* Location: ./system/database/drivers/postgre/postgre_forge.php */ \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index fdce01aac..25360b3f3 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -170,4 +170,6 @@ class CI_DB_postgre_result extends CI_DB_result { } -?> \ No newline at end of file + +/* End of file postgre_result.php */ +/* Location: ./system/database/drivers/postgre/postgre_result.php */ \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 573654f68..17df599b6 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -119,4 +119,6 @@ class CI_DB_postgre_utility extends CI_DB_utility { } -?> \ No newline at end of file + +/* End of file postgre_utility.php */ +/* Location: ./system/database/drivers/postgre/postgre_utility.php */ \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 70148f360..cb53ad91a 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -656,4 +656,6 @@ class CI_DB_sqlite_driver extends CI_DB { } -?> \ No newline at end of file + +/* End of file sqlite_driver.php */ +/* Location: ./system/database/drivers/sqlite/sqlite_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php index 44950bfc7..8a1a4da01 100644 --- a/system/database/drivers/sqlite/sqlite_forge.php +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -231,4 +231,6 @@ class CI_DB_sqlite_forge extends CI_DB_forge { } } -?> \ No newline at end of file + +/* End of file sqlite_forge.php */ +/* Location: ./system/database/drivers/sqlite/sqlite_forge.php */ \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index b8f3dc5b7..72c93fd48 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -180,4 +180,6 @@ class CI_DB_sqlite_result extends CI_DB_result { } -?> \ No newline at end of file + +/* End of file sqlite_result.php */ +/* Location: ./system/database/drivers/sqlite/sqlite_result.php */ \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index ab58f8fd7..c85e36575 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -136,4 +136,6 @@ class CI_DB_sqlite_utility extends CI_DB_utility { } } -?> \ No newline at end of file + +/* End of file sqlite_utility.php */ +/* Location: ./system/database/drivers/sqlite/sqlite_utility.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 7f88aa51fb56cb6e0d50f55f07fd8638d7a625b2 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 12 May 2008 00:03:51 +0000 Subject: changed class instantiations to reference global $LANG and fetch existing Exceptions class, and added language variable for database error heading http://codeigniter.com/bug_tracker/bug/4421/ --- system/database/DB_driver.php | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index c296d4ca8..35bdc29b6 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1117,12 +1117,11 @@ class CI_DB_driver { */ function display_error($error = '', $swap = '', $native = FALSE) { -// $LANG = new CI_Lang(); - $LANG = new CI_Language(); + global $LANG; $LANG->load('db'); - $heading = 'Database Error'; - + $heading = $LANG->line('db_error_heading'); + if ($native == TRUE) { $message = $error; @@ -1131,20 +1130,14 @@ class CI_DB_driver { { $message = (! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error; } - - if (! class_exists('CI_Exceptions')) - { -// include(BASEPATH.'core/Exceptions'.EXT); - include(BASEPATH.'libraries/Exceptions'.EXT); - } - $error = new CI_Exceptions(); - echo $error->show_error('An Error Was Encountered', $message, 'error_db'); + $error =& load_class('Exceptions'); + echo $error->show_error($heading, $message, 'error_db'); exit; } } - -/* End of file DB_driver.php */ + +/* End of file DB_driver.php */ /* Location: ./system/database/DB_driver.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From d36ade01b57ac39c328d9e0278b28b04fbef895e Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 12 May 2008 15:17:41 +0000 Subject: passed db object by reference to DB Cache class, and changed the cache class to use that db object instead of $CI->db, to support returned db objects and multiple db connections http://codeigniter.com/bug_tracker/bug/4223/ --- system/database/DB_cache.php | 30 ++++++++++++++++-------------- system/database/DB_driver.php | 2 +- 2 files changed, 17 insertions(+), 15 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 21113aff3..448727fd0 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -25,6 +25,7 @@ class CI_DB_Cache { var $CI; + var $db; // allows passing of db object so that multiple database connections and returned db objects can be supported /** * Constructor @@ -32,11 +33,12 @@ class CI_DB_Cache { * Grabs the CI super object instance so we can access it. * */ - function CI_DB_Cache() + function CI_DB_Cache(&$db) { // Assign the main CI object to $this->CI // and load the file helper since we use it a lot $this->CI =& get_instance(); + $this->db =& $db; $this->CI->load->helper('file'); } @@ -53,12 +55,12 @@ class CI_DB_Cache { { if ($path == '') { - if ($this->CI->db->cachedir == '') + if ($this->db->cachedir == '') { - return $this->CI->db->cache_off(); + return $this->db->cache_off(); } - $path = $this->CI->db->cachedir; + $path = $this->db->cachedir; } // Add a trailing slash to the path if needed @@ -67,10 +69,10 @@ class CI_DB_Cache { if (! is_dir($path) OR ! is_really_writable($path)) { // If the path is wrong we'll turn off caching - return $this->CI->db->cache_off(); + return $this->db->cache_off(); } - $this->CI->db->cachedir = $path; + $this->db->cachedir = $path; return TRUE; } @@ -89,7 +91,7 @@ class CI_DB_Cache { { if (! $this->check_path()) { - return $this->CI->db->cache_off(); + return $this->db->cache_off(); } $uri = ($this->CI->uri->segment(1) == FALSE) ? 'default.' : $this->CI->uri->segment(1).'+'; @@ -97,7 +99,7 @@ class CI_DB_Cache { $filepath = $uri.'/'.md5($sql); - if (FALSE === ($cachedata = read_file($this->CI->db->cachedir.$filepath))) + if (FALSE === ($cachedata = read_file($this->db->cachedir.$filepath))) { return FALSE; } @@ -117,13 +119,13 @@ class CI_DB_Cache { { if (! $this->check_path()) { - return $this->CI->db->cache_off(); + return $this->db->cache_off(); } $uri = ($this->CI->uri->segment(1) == FALSE) ? 'default.' : $this->CI->uri->segment(1).'+'; $uri .= ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); - $dir_path = $this->CI->db->cachedir.$uri.'/'; + $dir_path = $this->db->cachedir.$uri.'/'; $filename = md5($sql); @@ -166,7 +168,7 @@ class CI_DB_Cache { $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); } - $dir_path = $this->CI->db->cachedir.$segment_one.'+'.$segment_two.'/'; + $dir_path = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'; delete_files($dir_path, TRUE); } @@ -181,11 +183,11 @@ class CI_DB_Cache { */ function delete_all() { - delete_files($this->CI->db->cachedir, TRUE); + delete_files($this->db->cachedir, TRUE); } } - -/* End of file DB_cache.php */ + +/* End of file DB_cache.php */ /* Location: ./system/database/DB_cache.php */ \ No newline at end of file diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 35bdc29b6..b055d6dc3 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1083,7 +1083,7 @@ class CI_DB_driver { return $this->cache_off(); } - $this->CACHE = new CI_DB_Cache; + $this->CACHE = new CI_DB_Cache($this); // pass db object to support multiple db connections and returned db objects return TRUE; } -- cgit v1.2.3-24-g4f1b From a632589001aa9ec769f9a80871097ce3a09b74d1 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 12 May 2008 17:51:47 +0000 Subject: Fixed a bug in AR compiling, where select statements with arguments got incorrectly escaped (#3478). --- system/database/DB_active_rec.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index a4ef2e4db..9a7ef5def 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -95,7 +95,14 @@ class CI_DB_active_record extends CI_DB_driver { { if (is_string($select)) { - $select = explode(',', $select); + if ($protect_identifiers !== FALSE) + { + $select = explode(',', $select); + } + else + { + $select = array($select); + } } foreach ($select as $val) @@ -1749,6 +1756,6 @@ class CI_DB_active_record extends CI_DB_driver { } } - -/* End of file DB_active_rec.php */ + +/* End of file DB_active_rec.php */ /* Location: ./system/database/DB_active_rec.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 244b4c7bcf88b2ed10cb48ca961d615e5a5002ed Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 12 May 2008 18:21:33 +0000 Subject: --- system/database/DB_driver.php | 79 +++++++++++++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 22 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index b055d6dc3..9ad235ded 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -51,6 +51,7 @@ class CI_DB_driver { var $query_times = array(); var $data_cache = array(); var $trans_enabled = TRUE; + var $trans_strict = TRUE; var $_trans_depth = 0; var $_trans_status = TRUE; // Used with transactions to determine if a rollback should occur var $cache_on = FALSE; @@ -107,7 +108,7 @@ class CI_DB_driver { $this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect(); // No connection? Throw an error - if (! $this->conn_id) + if ( ! $this->conn_id) { log_message('error', 'Unable to connect to the database'); @@ -121,7 +122,7 @@ class CI_DB_driver { // Select the database if ($this->database != '') { - if (! $this->db_select()) + if ( ! $this->db_select()) { // Should we attempt to create the database? if ($create_db == TRUE) @@ -131,7 +132,7 @@ class CI_DB_driver { $CI->load->dbutil(); // Create the DB - if (! $CI->dbutil->create_database($this->database)) + if ( ! $CI->dbutil->create_database($this->database)) { log_message('error', 'Unable to create database: '.$this->database); @@ -297,11 +298,23 @@ class CI_DB_driver { // Run the Query if (FALSE === ($this->result_id = $this->simple_query($sql))) { + if ($this->save_queries == TRUE) + { + $this->query_times[] = 0; + } + // This will trigger a rollback if transactions are being used $this->_trans_status = FALSE; - + if ($this->db_debug) { + // We call this function in order to roll-back queries + // if transactions are enabled. If we don't call this here + // the error message will trigger an exit, causing the + // transactions to remain in limbo. + $this->trans_complete(); + + // Log and display errors log_message('error', 'Query error: '.$this->_error_message()); return $this->display_error( array( @@ -401,7 +414,7 @@ class CI_DB_driver { { $driver = 'CI_DB_'.$this->dbdriver.'_result'; - if (! class_exists($driver)) + if ( ! class_exists($driver)) { include_once(BASEPATH.'database/DB_result'.EXT); include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result'.EXT); @@ -424,7 +437,7 @@ class CI_DB_driver { */ function simple_query($sql) { - if (! $this->conn_id) + if ( ! $this->conn_id) { $this->initialize(); } @@ -448,6 +461,23 @@ class CI_DB_driver { // -------------------------------------------------------------------- + /** + * Enable/disable Transaction Strict Mode + * When strict mode is enabled, if you are running multiple groups of + * transactions, if one group fails all groups will be rolled back. + * If strict mode is disabled, each group is treated autonomously, meaning + * a failure of one group will not affect any others + * + * @access public + * @return void + */ + function trans_strict($mode = TRUE) + { + $this->trans_strict = is_bool($mode) ? $mode : TRUE; + } + + // -------------------------------------------------------------------- + /** * Start Transaction * @@ -456,7 +486,7 @@ class CI_DB_driver { */ function trans_start($test_mode = FALSE) { - if (! $this->trans_enabled) + if ( ! $this->trans_enabled) { return FALSE; } @@ -481,7 +511,7 @@ class CI_DB_driver { */ function trans_complete() { - if (! $this->trans_enabled) + if ( ! $this->trans_enabled) { return FALSE; } @@ -493,15 +523,20 @@ class CI_DB_driver { return TRUE; } - // The query() function will set this flag to TRUE in the event that a query failed + // The query() function will set this flag to FALSE in the event that a query failed if ($this->_trans_status === FALSE) { $this->trans_rollback(); - if ($this->db_debug) + // If we are NOT running in strict mode, we will reset + // the _trans_status flag so that subsequent groups of transactions + // will be permitted. + if ($this->trans_strict === FALSE) { - return $this->display_error('db_transaction_failure'); + $this->_trans_status = TRUE; } + + log_message('debug', 'DB Transaction Failure'); return FALSE; } @@ -539,7 +574,7 @@ class CI_DB_driver { return $sql; } - if (! is_array($binds)) + if ( ! is_array($binds)) { $binds = array($binds); } @@ -576,7 +611,7 @@ class CI_DB_driver { */ function is_write_type($sql) { - if (! preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql)) + if ( ! preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql)) { return FALSE; } @@ -683,7 +718,7 @@ class CI_DB_driver { { $fields = $this->list_fields($table); - if (! is_array($fields)) + if ( ! is_array($fields)) { return FALSE; } @@ -747,7 +782,7 @@ class CI_DB_driver { */ function table_exists($table_name) { - return (! in_array($this->prep_tablename($table_name), $this->list_tables())) ? FALSE : TRUE; + return ( ! in_array($this->prep_tablename($table_name), $this->list_tables())) ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -815,7 +850,7 @@ class CI_DB_driver { */ function field_exists($field_name, $table_name) { - return (! in_array($field_name, $this->list_fields($table_name))) ? FALSE : TRUE; + return ( ! in_array($field_name, $this->list_fields($table_name))) ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -899,7 +934,7 @@ class CI_DB_driver { $fields[$key] = $this->escape($val); } - if (! is_array($where)) + if ( ! is_array($where)) { $dest = array($where); } @@ -912,7 +947,7 @@ class CI_DB_driver { if ($val !== '') { - if (! $this->_has_operator($key)) + if ( ! $this->_has_operator($key)) { $key .= ' ='; } @@ -969,7 +1004,7 @@ class CI_DB_driver { $function = $driver.$function; } - if (! function_exists($function)) + if ( ! function_exists($function)) { if ($this->db_debug) { @@ -1038,7 +1073,7 @@ class CI_DB_driver { */ function cache_delete($segment_one = '', $segment_two = '') { - if (! $this->_cache_init()) + if ( ! $this->_cache_init()) { return FALSE; } @@ -1055,7 +1090,7 @@ class CI_DB_driver { */ function cache_delete_all() { - if (! $this->_cache_init()) + if ( ! $this->_cache_init()) { return FALSE; } @@ -1078,7 +1113,7 @@ class CI_DB_driver { return TRUE; } - if (! @include(BASEPATH.'database/DB_cache'.EXT)) + if ( ! @include(BASEPATH.'database/DB_cache'.EXT)) { return $this->cache_off(); } -- cgit v1.2.3-24-g4f1b From 5fe155ecd05af4ee68ef093200fb6a241baa89ce Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 12 May 2008 19:14:57 +0000 Subject: Escape behaviour in where() clauses has changed; values in those with the "FALSE" argument are no longer escaped (ie: quoted). --- system/database/DB_active_rec.php | 41 +++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 9a7ef5def..b53158577 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -69,14 +69,14 @@ class CI_DB_active_record extends CI_DB_driver { * @access public * @param string the table * @return string - */ + */ function dbprefix($table = '') { if ($table == '') { $this->display_error('db_table_name_required'); } - + return $this->dbprefix.$table; } @@ -104,7 +104,7 @@ class CI_DB_active_record extends CI_DB_driver { $select = array($select); } } - + foreach ($select as $val) { $val = trim($val); @@ -120,7 +120,7 @@ class CI_DB_active_record extends CI_DB_driver { $val = $this->_protect_identifiers($val); } } - + if ($val != '') { $this->ar_select[] = $val; @@ -183,7 +183,7 @@ class CI_DB_active_record extends CI_DB_driver { { $this->display_error('db_invalid_query'); } - + $alias = ($alias != '') ? $alias : $select; $sql = 'MIN('.$this->_protect_identifiers(trim($select)).') AS '.$this->_protect_identifiers(trim($alias)); @@ -217,7 +217,7 @@ class CI_DB_active_record extends CI_DB_driver { } $alias = ($alias != '') ? $alias : $select; - + $sql = 'AVG('.$this->_protect_identifiers(trim($select)).') AS '.$this->_protect_identifiers(trim($alias)); $this->ar_select[] = $sql; @@ -230,7 +230,7 @@ class CI_DB_active_record extends CI_DB_driver { } // -------------------------------------------------------------------- - + /** * Select Sum * @@ -302,7 +302,7 @@ class CI_DB_active_record extends CI_DB_driver { return $this; } - + // -------------------------------------------------------------------- /** @@ -339,10 +339,10 @@ class CI_DB_active_record extends CI_DB_driver { // First we remove any existing prefixes in the condition to avoid duplicates $cond = preg_replace('|('.$this->dbprefix.')([\w\.]+)([\W\s]+)|', "$2$3", $cond); - + // Next we add the prefixes to the condition $cond = preg_replace('|([\w\.]+)([\W\s]+)(.+)|', $this->dbprefix . "$1$2" . $this->dbprefix . "$3", $cond); - } + } $join = $type.'JOIN '.$this->_protect_identifiers($this->dbprefix.$table, TRUE).' ON '.$cond; @@ -354,7 +354,7 @@ class CI_DB_active_record extends CI_DB_driver { return $this; } - + // -------------------------------------------------------------------- /** @@ -453,15 +453,18 @@ class CI_DB_active_record extends CI_DB_driver { { $k .= ' ='; } - + if ($v !== '' AND $v !== NULL) { - $v = ' '.$this->escape($v); + if ($escape === TRUE) + { + $v = ' '.$this->escape($v); + } } } else { - + if ($escape === TRUE) { $k = $this->_protect_identifiers($k, TRUE); @@ -511,7 +514,7 @@ class CI_DB_active_record extends CI_DB_driver { * @return object */ function or_where_in($key = NULL, $values = NULL) - { + { return $this->_where_in($key, $values, FALSE, 'OR '); } @@ -529,7 +532,7 @@ class CI_DB_active_record extends CI_DB_driver { * @return object */ function where_not_in($key = NULL, $values = NULL) - { + { return $this->_where_in($key, $values, TRUE); } @@ -547,7 +550,7 @@ class CI_DB_active_record extends CI_DB_driver { * @return object */ function or_where_not_in($key = NULL, $values = NULL) - { + { return $this->_where_in($key, $values, TRUE, 'OR '); } @@ -566,7 +569,7 @@ class CI_DB_active_record extends CI_DB_driver { * @return object */ function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ') - { + { if ($key === NULL || !is_array($values)) { return; @@ -580,7 +583,7 @@ class CI_DB_active_record extends CI_DB_driver { } $prefix = (count($this->ar_where) == 0) ? '' : $type; - + $where_in = $prefix . $this->_protect_identifiers($key) . $not . " IN (" . implode(", ", $this->ar_wherein) . ") "; $this->ar_where[] = $where_in; -- cgit v1.2.3-24-g4f1b From 0b59f270a432f8c7b6128981f0a39b4a2e2fbd34 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 13 May 2008 04:22:33 +0000 Subject: Some sweeping syntax changes for consistency: (! foo) changed to ( ! foo) || changed to OR changed newline standardization code in various places from preg_replace to str_replace --- system/database/DB.php | 18 +++---- system/database/DB_active_rec.php | 58 +++++++++++----------- system/database/DB_cache.php | 12 ++--- system/database/DB_driver.php | 8 +-- system/database/DB_forge.php | 6 +-- system/database/DB_result.php | 12 ++--- system/database/DB_utility.php | 16 +++--- system/database/drivers/mssql/mssql_driver.php | 20 ++++---- system/database/drivers/mssql/mssql_forge.php | 6 +-- system/database/drivers/mssql/mssql_result.php | 6 +-- system/database/drivers/mssql/mssql_utility.php | 6 +-- system/database/drivers/mysql/mysql_driver.php | 20 ++++---- system/database/drivers/mysql/mysql_forge.php | 6 +-- system/database/drivers/mysql/mysql_result.php | 6 +-- system/database/drivers/mysql/mysql_utility.php | 6 +-- system/database/drivers/mysqli/mysqli_driver.php | 20 ++++---- system/database/drivers/mysqli/mysqli_forge.php | 6 +-- system/database/drivers/mysqli/mysqli_result.php | 6 +-- system/database/drivers/mysqli/mysqli_utility.php | 6 +-- system/database/drivers/oci8/oci8_driver.php | 26 +++++----- system/database/drivers/oci8/oci8_forge.php | 6 +-- system/database/drivers/oci8/oci8_result.php | 6 +-- system/database/drivers/oci8/oci8_utility.php | 6 +-- system/database/drivers/odbc/odbc_driver.php | 20 ++++---- system/database/drivers/odbc/odbc_forge.php | 6 +-- system/database/drivers/odbc/odbc_result.php | 6 +-- system/database/drivers/odbc/odbc_utility.php | 6 +-- system/database/drivers/postgre/postgre_driver.php | 20 ++++---- system/database/drivers/postgre/postgre_forge.php | 6 +-- system/database/drivers/postgre/postgre_result.php | 6 +-- .../database/drivers/postgre/postgre_utility.php | 6 +-- system/database/drivers/sqlite/sqlite_driver.php | 24 ++++----- system/database/drivers/sqlite/sqlite_forge.php | 8 +-- system/database/drivers/sqlite/sqlite_result.php | 6 +-- system/database/drivers/sqlite/sqlite_utility.php | 8 +-- 35 files changed, 205 insertions(+), 205 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index d603805a5..2446645a7 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -1,4 +1,4 @@ -display_error('db_invalid_query'); } @@ -179,7 +179,7 @@ class CI_DB_active_record extends CI_DB_driver { */ function select_min($select = '', $alias='') { - if (!is_string($select) || $select == '') + if ( ! is_string($select) OR $select == '') { $this->display_error('db_invalid_query'); } @@ -211,7 +211,7 @@ class CI_DB_active_record extends CI_DB_driver { */ function select_avg($select = '', $alias='') { - if (!is_string($select) || $select == '') + if ( ! is_string($select) OR $select == '') { $this->display_error('db_invalid_query'); } @@ -243,7 +243,7 @@ class CI_DB_active_record extends CI_DB_driver { */ function select_sum($select = '', $alias='') { - if (!is_string($select) || $select == '') + if ( ! is_string($select) OR $select == '') { $this->display_error('db_invalid_query'); } @@ -322,7 +322,7 @@ class CI_DB_active_record extends CI_DB_driver { { $type = strtoupper(trim($type)); - if (! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'), TRUE)) + if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'), TRUE)) { $type = ''; } @@ -418,7 +418,7 @@ class CI_DB_active_record extends CI_DB_driver { */ function _where($key, $value = NULL, $type = 'AND ', $escape = TRUE) { - if (! is_array($key)) + if ( ! is_array($key)) { $key = array($key => $value); } @@ -427,13 +427,13 @@ class CI_DB_active_record extends CI_DB_driver { { $prefix = (count($this->ar_where) == 0) ? '' : $type; - if (! $this->_has_operator($k) && is_null($key[$k])) + if ( ! $this->_has_operator($k) && is_null($key[$k])) { // value appears not to have been set, assign the test to IS NULL $k .= ' IS NULL'; } - if (! is_null($v)) + if ( ! is_null($v)) { if ($escape === TRUE) @@ -449,7 +449,7 @@ class CI_DB_active_record extends CI_DB_driver { } } - if (! $this->_has_operator($k)) + if ( ! $this->_has_operator($k)) { $k .= ' ='; } @@ -570,7 +570,7 @@ class CI_DB_active_record extends CI_DB_driver { */ function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ') { - if ($key === NULL || !is_array($values)) + if ($key === NULL OR ! is_array($values)) { return; } @@ -696,7 +696,7 @@ class CI_DB_active_record extends CI_DB_driver { */ function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '') { - if (! is_array($field)) + if ( ! is_array($field)) { $field = array($field => $match); } @@ -838,7 +838,7 @@ class CI_DB_active_record extends CI_DB_driver { */ function _having($key, $value = '', $type = 'AND ', $escape = TRUE) { - if (! is_array($key)) + if ( ! is_array($key)) { $key = array($key => $value); } @@ -978,7 +978,7 @@ class CI_DB_active_record extends CI_DB_driver { { $key = $this->_object_to_array($key); - if (! is_array($key)) + if ( ! is_array($key)) { $key = array($key => $value); } @@ -1028,7 +1028,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->from($table); } - if (! is_null($limit)) + if ( ! is_null($limit)) { $this->limit($limit, $offset); } @@ -1093,12 +1093,12 @@ class CI_DB_active_record extends CI_DB_driver { $this->from($table); } - if (! is_null($where)) + if ( ! is_null($where)) { $this->where($where); } - if (! is_null($limit)) + if ( ! is_null($limit)) { $this->limit($limit, $offset); } @@ -1136,7 +1136,7 @@ class CI_DB_active_record extends CI_DB_driver { */ function insert($table = '', $set = NULL) { - if (! is_null($set)) + if ( ! is_null($set)) { $this->set($set); } @@ -1152,7 +1152,7 @@ class CI_DB_active_record extends CI_DB_driver { if ($table == '') { - if (! isset($this->ar_from[0])) + if ( ! isset($this->ar_from[0])) { if ($this->db_debug) { @@ -1185,7 +1185,7 @@ class CI_DB_active_record extends CI_DB_driver { */ function update($table = '', $set = NULL, $where = NULL, $limit = NULL) { - if (! is_null($set)) + if ( ! is_null($set)) { $this->set($set); } @@ -1201,7 +1201,7 @@ class CI_DB_active_record extends CI_DB_driver { if ($table == '') { - if (! isset($this->ar_from[0])) + if ( ! isset($this->ar_from[0])) { if ($this->db_debug) { @@ -1244,7 +1244,7 @@ class CI_DB_active_record extends CI_DB_driver { { if ($table == '') { - if (! isset($this->ar_from[0])) + if ( ! isset($this->ar_from[0])) { if ($this->db_debug) { @@ -1285,7 +1285,7 @@ class CI_DB_active_record extends CI_DB_driver { { if ($table == '') { - if (! isset($this->ar_from[0])) + if ( ! isset($this->ar_from[0])) { if ($this->db_debug) { @@ -1327,7 +1327,7 @@ class CI_DB_active_record extends CI_DB_driver { { if ($table == '') { - if (! isset($this->ar_from[0])) + if ( ! isset($this->ar_from[0])) { if ($this->db_debug) { @@ -1407,7 +1407,7 @@ class CI_DB_active_record extends CI_DB_driver { function _has_operator($str) { $str = trim($str); - if (! preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str)) + if ( ! preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str)) { return FALSE; } @@ -1480,7 +1480,7 @@ class CI_DB_active_record extends CI_DB_driver { { $this->_merge_cache(); - $sql = (! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; + $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; $sql .= (count($this->ar_select) == 0) ? '*' : implode(', ', $this->_filter_table_aliases($this->ar_select)); @@ -1583,7 +1583,7 @@ class CI_DB_active_record extends CI_DB_driver { */ function _object_to_array($object) { - if (! is_object($object)) + if ( ! is_object($object)) { return $object; } @@ -1592,7 +1592,7 @@ class CI_DB_active_record extends CI_DB_driver { foreach (get_object_vars($object) as $key => $val) { // There are some built in keys we need to ignore for this conversion - if (! is_object($val) && ! is_array($val) && $key != '_parent_name' && $key != '_ci_scaffolding' && $key != '_ci_scaff_table') + if ( ! is_object($val) && ! is_array($val) && $key != '_parent_name' && $key != '_ci_scaffolding' && $key != '_ci_scaff_table') { $array[$key] = $val; @@ -1696,7 +1696,7 @@ class CI_DB_active_record extends CI_DB_driver { { foreach ($ar_reset_items as $item => $default_value) { - if (!in_array($item, $this->ar_store_array)) + if ( ! in_array($item, $this->ar_store_array)) { $this->$item = $default_value; } diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 448727fd0..977327a8d 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -1,4 +1,4 @@ -db->cache_off(); @@ -89,7 +89,7 @@ class CI_DB_Cache { */ function read($sql) { - if (! $this->check_path()) + if ( ! $this->check_path()) { return $this->db->cache_off(); } @@ -117,7 +117,7 @@ class CI_DB_Cache { */ function write($sql, $object) { - if (! $this->check_path()) + if ( ! $this->check_path()) { return $this->db->cache_off(); } @@ -129,9 +129,9 @@ class CI_DB_Cache { $filename = md5($sql); - if (! @is_dir($dir_path)) + if ( ! @is_dir($dir_path)) { - if (! @mkdir($dir_path, DIR_WRITE_MODE)) + if ( ! @mkdir($dir_path, DIR_WRITE_MODE)) { return FALSE; } diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 9ad235ded..306f09d7d 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1,4 +1,4 @@ -db_select()) { - if (! $this->db_set_charset($this->char_set, $this->dbcollat)) + if ( ! $this->db_set_charset($this->char_set, $this->dbcollat)) { log_message('error', 'Unable to set database connection charset: '.$this->char_set); @@ -173,7 +173,7 @@ class CI_DB_driver { return FALSE; } - if (! $this->db_set_charset($this->char_set, $this->dbcollat)) + if ( ! $this->db_set_charset($this->char_set, $this->dbcollat)) { log_message('error', 'Unable to set database connection charset: '.$this->char_set); @@ -1163,7 +1163,7 @@ class CI_DB_driver { } else { - $message = (! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error; + $message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error; } $error =& load_class('Exceptions'); diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index d7259c08c..d3ef326b6 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -1,4 +1,4 @@ -row_data)) + if ( ! is_array($this->row_data)) { $this->row_data = $this->row_array(0); } @@ -156,7 +156,7 @@ class CI_DB_result { function set_row($key, $value = NULL) { // We cache the row data for subsequent uses - if (! is_array($this->row_data)) + if ( ! is_array($this->row_data)) { $this->row_data = $this->row_array(0); } @@ -338,6 +338,6 @@ class CI_DB_result { } // END DB_result class - -/* End of file DB_result.php */ + +/* End of file DB_result.php */ /* Location: ./system/database/DB_result.php */ \ No newline at end of file diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 5d4c2de45..d273df158 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -1,4 +1,4 @@ - 'root', 'element' => 'element', 'newline' => "\n", 'tab' => "\t") as $key => $val) { - if (! isset($params[$key])) + if ( ! isset($params[$key])) { $params[$key] = $val; } @@ -310,7 +310,7 @@ class CI_DB_utility extends CI_DB_forge { // ------------------------------------------------------ // Validate the format - if (! in_array($prefs['format'], array('gzip', 'zip', 'txt'), TRUE)) + if ( ! in_array($prefs['format'], array('gzip', 'zip', 'txt'), TRUE)) { $prefs['format'] = 'txt'; } @@ -367,7 +367,7 @@ class CI_DB_utility extends CI_DB_forge { } // Tack on the ".sql" file extension if needed - if (! preg_match("|.+?\.sql$|", $prefs['filename'])) + if ( ! preg_match("|.+?\.sql$|", $prefs['filename'])) { $prefs['filename'] .= '.sql'; } @@ -384,6 +384,6 @@ class CI_DB_utility extends CI_DB_forge { } - -/* End of file DB_utility.php */ + +/* End of file DB_utility.php */ /* Location: ./system/database/DB_utility.php */ \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index f789634f8..34ad9799e 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -1,4 +1,4 @@ -trans_enabled) + if ( ! $this->trans_enabled) { return TRUE; } @@ -162,7 +162,7 @@ class CI_DB_mssql_driver extends CI_DB { */ function trans_commit() { - if (! $this->trans_enabled) + if ( ! $this->trans_enabled) { return TRUE; } @@ -187,7 +187,7 @@ class CI_DB_mssql_driver extends CI_DB { */ function trans_rollback() { - if (! $this->trans_enabled) + if ( ! $this->trans_enabled) { return TRUE; } @@ -492,7 +492,7 @@ class CI_DB_mssql_driver extends CI_DB { */ function _from_tables($tables) { - if (! is_array($tables)) + if ( ! is_array($tables)) { $tables = array($tables); } @@ -540,7 +540,7 @@ class CI_DB_mssql_driver extends CI_DB { $valstr[] = $key." = ".$val; } - $limit = (!$limit) ? '' : ' LIMIT '.$limit; + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; @@ -587,7 +587,7 @@ class CI_DB_mssql_driver extends CI_DB { { $conditions = ''; - if (count($where) > 0 || count($like) > 0) + if (count($where) > 0 OR count($like) > 0) { $conditions = "\nWHERE "; $conditions .= implode("\n", $this->ar_where); @@ -599,7 +599,7 @@ class CI_DB_mssql_driver extends CI_DB { $conditions .= implode("\n", $like); } - $limit = (!$limit) ? '' : ' LIMIT '.$limit; + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; return "DELETE FROM ".$table.$conditions.$limit; } @@ -641,6 +641,6 @@ class CI_DB_mssql_driver extends CI_DB { } - -/* End of file mssql_driver.php */ + +/* End of file mssql_driver.php */ /* Location: ./system/database/drivers/mssql/mssql_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php index d42fd5ee6..ddd1bb6ae 100644 --- a/system/database/drivers/mssql/mssql_forge.php +++ b/system/database/drivers/mssql/mssql_forge.php @@ -1,4 +1,4 @@ -trans_enabled) + if ( ! $this->trans_enabled) { return TRUE; } @@ -192,7 +192,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function trans_commit() { - if (! $this->trans_enabled) + if ( ! $this->trans_enabled) { return TRUE; } @@ -218,7 +218,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function trans_rollback() { - if (! $this->trans_enabled) + if ( ! $this->trans_enabled) { return TRUE; } @@ -495,7 +495,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function _from_tables($tables) { - if (! is_array($tables)) + if ( ! is_array($tables)) { $tables = array($tables); } @@ -543,7 +543,7 @@ class CI_DB_mysql_driver extends CI_DB { $valstr[] = $key." = ".$val; } - $limit = (!$limit) ? '' : ' LIMIT '.$limit; + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; @@ -589,7 +589,7 @@ class CI_DB_mysql_driver extends CI_DB { { $conditions = ''; - if (count($where) > 0 || count($like) > 0) + if (count($where) > 0 OR count($like) > 0) { $conditions = "\nWHERE "; $conditions .= implode("\n", $this->ar_where); @@ -601,7 +601,7 @@ class CI_DB_mysql_driver extends CI_DB { $conditions .= implode("\n", $like); } - $limit = (!$limit) ? '' : ' LIMIT '.$limit; + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; return "DELETE FROM ".$table.$conditions.$limit; } @@ -649,6 +649,6 @@ class CI_DB_mysql_driver extends CI_DB { } - -/* End of file mysql_driver.php */ + +/* End of file mysql_driver.php */ /* Location: ./system/database/drivers/mysql/mysql_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index 6701c42d5..a631e4301 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -1,4 +1,4 @@ -trans_enabled) + if ( ! $this->trans_enabled) { return TRUE; } @@ -195,7 +195,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ function trans_commit() { - if (! $this->trans_enabled) + if ( ! $this->trans_enabled) { return TRUE; } @@ -221,7 +221,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ function trans_rollback() { - if (! $this->trans_enabled) + if ( ! $this->trans_enabled) { return TRUE; } @@ -491,7 +491,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ function _from_tables($tables) { - if (! is_array($tables)) + if ( ! is_array($tables)) { $tables = array($tables); } @@ -539,7 +539,7 @@ class CI_DB_mysqli_driver extends CI_DB { $valstr[] = $key." = ".$val; } - $limit = (!$limit) ? '' : ' LIMIT '.$limit; + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; @@ -586,7 +586,7 @@ class CI_DB_mysqli_driver extends CI_DB { { $conditions = ''; - if (count($where) > 0 || count($like) > 0) + if (count($where) > 0 OR count($like) > 0) { $conditions = "\nWHERE "; $conditions .= implode("\n", $this->ar_where); @@ -598,7 +598,7 @@ class CI_DB_mysqli_driver extends CI_DB { $conditions .= implode("\n", $like); } - $limit = (!$limit) ? '' : ' LIMIT '.$limit; + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; return "DELETE FROM ".$table.$conditions.$limit; } @@ -645,6 +645,6 @@ class CI_DB_mysqli_driver extends CI_DB { } - -/* End of file mysqli_driver.php */ + +/* End of file mysqli_driver.php */ /* Location: ./system/database/drivers/mysqli/mysqli_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index 087f9b80b..f767acbea 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -1,4 +1,4 @@ -stmt_id)) + if ( ! is_resource($this->stmt_id)) { $this->stmt_id = ociparse($this->conn_id, $this->_prep_query($sql)); } @@ -254,7 +254,7 @@ class CI_DB_oci8_driver extends CI_DB { */ function _bind_params($params) { - if (! is_array($params) OR ! is_resource($this->stmt_id)) + if ( ! is_array($params) OR ! is_resource($this->stmt_id)) { return; } @@ -263,7 +263,7 @@ class CI_DB_oci8_driver extends CI_DB { { foreach (array('name', 'value', 'type', 'length') as $val) { - if (! isset($param[$val])) + if ( ! isset($param[$val])) { $param[$val] = ''; } @@ -283,7 +283,7 @@ class CI_DB_oci8_driver extends CI_DB { */ function trans_begin($test_mode = FALSE) { - if (! $this->trans_enabled) + if ( ! $this->trans_enabled) { return TRUE; } @@ -313,7 +313,7 @@ class CI_DB_oci8_driver extends CI_DB { */ function trans_commit() { - if (! $this->trans_enabled) + if ( ! $this->trans_enabled) { return TRUE; } @@ -339,7 +339,7 @@ class CI_DB_oci8_driver extends CI_DB { */ function trans_rollback() { - if (! $this->trans_enabled) + if ( ! $this->trans_enabled) { return TRUE; } @@ -603,7 +603,7 @@ class CI_DB_oci8_driver extends CI_DB { */ function _from_tables($tables) { - if (! is_array($tables)) + if ( ! is_array($tables)) { $tables = array($tables); } @@ -651,7 +651,7 @@ class CI_DB_oci8_driver extends CI_DB { $valstr[] = $key." = ".$val; } - $limit = (!$limit) ? '' : ' LIMIT '.$limit; + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; @@ -697,7 +697,7 @@ class CI_DB_oci8_driver extends CI_DB { { $conditions = ''; - if (count($where) > 0 || count($like) > 0) + if (count($where) > 0 OR count($like) > 0) { $conditions = "\nWHERE "; $conditions .= implode("\n", $this->ar_where); @@ -709,7 +709,7 @@ class CI_DB_oci8_driver extends CI_DB { $conditions .= implode("\n", $like); } - $limit = (!$limit) ? '' : ' LIMIT '.$limit; + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; return "DELETE FROM ".$table.$conditions.$limit; } @@ -761,6 +761,6 @@ class CI_DB_oci8_driver extends CI_DB { } - -/* End of file oci8_driver.php */ + +/* End of file oci8_driver.php */ /* Location: ./system/database/drivers/oci8/oci8_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index 64dd2a202..9f3fac54f 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -1,4 +1,4 @@ -trans_enabled) + if ( ! $this->trans_enabled) { return TRUE; } @@ -181,7 +181,7 @@ class CI_DB_odbc_driver extends CI_DB { */ function trans_commit() { - if (! $this->trans_enabled) + if ( ! $this->trans_enabled) { return TRUE; } @@ -207,7 +207,7 @@ class CI_DB_odbc_driver extends CI_DB { */ function trans_rollback() { - if (! $this->trans_enabled) + if ( ! $this->trans_enabled) { return TRUE; } @@ -464,7 +464,7 @@ class CI_DB_odbc_driver extends CI_DB { */ function _from_tables($tables) { - if (! is_array($tables)) + if ( ! is_array($tables)) { $tables = array($tables); } @@ -512,7 +512,7 @@ class CI_DB_odbc_driver extends CI_DB { $valstr[] = $key." = ".$val; } - $limit = (!$limit) ? '' : ' LIMIT '.$limit; + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; @@ -559,7 +559,7 @@ class CI_DB_odbc_driver extends CI_DB { { $conditions = ''; - if (count($where) > 0 || count($like) > 0) + if (count($where) > 0 OR count($like) > 0) { $conditions = "\nWHERE "; $conditions .= implode("\n", $this->ar_where); @@ -571,7 +571,7 @@ class CI_DB_odbc_driver extends CI_DB { $conditions .= implode("\n", $like); } - $limit = (!$limit) ? '' : ' LIMIT '.$limit; + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; return "DELETE FROM ".$table.$conditions.$limit; } @@ -613,6 +613,6 @@ class CI_DB_odbc_driver extends CI_DB { } - -/* End of file odbc_driver.php */ + +/* End of file odbc_driver.php */ /* Location: ./system/database/drivers/odbc/odbc_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php index fb011f298..60df616c3 100644 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -1,4 +1,4 @@ -trans_enabled) + if ( ! $this->trans_enabled) { return TRUE; } @@ -179,7 +179,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function trans_commit() { - if (! $this->trans_enabled) + if ( ! $this->trans_enabled) { return TRUE; } @@ -203,7 +203,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function trans_rollback() { - if (! $this->trans_enabled) + if ( ! $this->trans_enabled) { return TRUE; } @@ -488,7 +488,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function _from_tables($tables) { - if (! is_array($tables)) + if ( ! is_array($tables)) { $tables = array($tables); } @@ -536,7 +536,7 @@ class CI_DB_postgre_driver extends CI_DB { $valstr[] = $key." = ".$val; } - $limit = (!$limit) ? '' : ' LIMIT '.$limit; + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; @@ -583,7 +583,7 @@ class CI_DB_postgre_driver extends CI_DB { { $conditions = ''; - if (count($where) > 0 || count($like) > 0) + if (count($where) > 0 OR count($like) > 0) { $conditions = "\nWHERE "; $conditions .= implode("\n", $this->ar_where); @@ -595,7 +595,7 @@ class CI_DB_postgre_driver extends CI_DB { $conditions .= implode("\n", $like); } - $limit = (!$limit) ? '' : ' LIMIT '.$limit; + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; return "DELETE FROM ".$table.$conditions.$limit; } @@ -641,6 +641,6 @@ class CI_DB_postgre_driver extends CI_DB { } - -/* End of file postgre_driver.php */ + +/* End of file postgre_driver.php */ /* Location: ./system/database/drivers/postgre/postgre_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index fb4fcf128..f8dfca8a1 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -1,4 +1,4 @@ -database, FILE_WRITE_MODE, $error)) + if ( ! $conn_id = @sqlite_open($this->database, FILE_WRITE_MODE, $error)) { log_message('error', $error); @@ -73,7 +73,7 @@ class CI_DB_sqlite_driver extends CI_DB { */ function db_pconnect() { - if (! $conn_id = @sqlite_popen($this->database, FILE_WRITE_MODE, $error)) + if ( ! $conn_id = @sqlite_popen($this->database, FILE_WRITE_MODE, $error)) { log_message('error', $error); @@ -171,7 +171,7 @@ class CI_DB_sqlite_driver extends CI_DB { */ function trans_begin($test_mode = FALSE) { - if (! $this->trans_enabled) + if ( ! $this->trans_enabled) { return TRUE; } @@ -201,7 +201,7 @@ class CI_DB_sqlite_driver extends CI_DB { */ function trans_commit() { - if (! $this->trans_enabled) + if ( ! $this->trans_enabled) { return TRUE; } @@ -226,7 +226,7 @@ class CI_DB_sqlite_driver extends CI_DB { */ function trans_rollback() { - if (! $this->trans_enabled) + if ( ! $this->trans_enabled) { return TRUE; } @@ -482,7 +482,7 @@ class CI_DB_sqlite_driver extends CI_DB { */ function _from_tables($tables) { - if (! is_array($tables)) + if ( ! is_array($tables)) { $tables = array($tables); } @@ -530,7 +530,7 @@ class CI_DB_sqlite_driver extends CI_DB { $valstr[] = $key." = ".$val; } - $limit = (!$limit) ? '' : ' LIMIT '.$limit; + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; @@ -577,7 +577,7 @@ class CI_DB_sqlite_driver extends CI_DB { { $conditions = ''; - if (count($where) > 0 || count($like) > 0) + if (count($where) > 0 OR count($like) > 0) { $conditions = "\nWHERE "; $conditions .= implode("\n", $this->ar_where); @@ -589,7 +589,7 @@ class CI_DB_sqlite_driver extends CI_DB { $conditions .= implode("\n", $like); } - $limit = (!$limit) ? '' : ' LIMIT '.$limit; + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; return "DELETE FROM ".$table.$conditions.$limit; } @@ -656,6 +656,6 @@ class CI_DB_sqlite_driver extends CI_DB { } - -/* End of file sqlite_driver.php */ + +/* End of file sqlite_driver.php */ /* Location: ./system/database/drivers/sqlite/sqlite_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php index 8a1a4da01..25c74a731 100644 --- a/system/database/drivers/sqlite/sqlite_forge.php +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -1,4 +1,4 @@ -db->database) OR ! @unlink($this->db->database)) + if ( ! @file_exists($this->db->database) OR ! @unlink($this->db->database)) { if ($this->db->db_debug) { @@ -231,6 +231,6 @@ class CI_DB_sqlite_forge extends CI_DB_forge { } } - -/* End of file sqlite_forge.php */ + +/* End of file sqlite_forge.php */ /* Location: ./system/database/drivers/sqlite/sqlite_forge.php */ \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index 72c93fd48..8bb0d9d0b 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -1,4 +1,4 @@ -db->database) OR ! @unlink($this->db->database)) + if ( ! @file_exists($this->db->database) OR ! @unlink($this->db->database)) { if ($this->db->db_debug) { @@ -136,6 +136,6 @@ class CI_DB_sqlite_utility extends CI_DB_utility { } } - -/* End of file sqlite_utility.php */ + +/* End of file sqlite_utility.php */ /* Location: ./system/database/drivers/sqlite/sqlite_utility.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From f38fe09dfecde176dc2803dd6a55177666f7d616 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 13 May 2008 20:28:11 +0000 Subject: hotfix for a bug in database error display introduced by 1.6.2 fix for bugs #4451, #4299, and #4339 --- system/database/DB_driver.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 306f09d7d..a0833d0ce 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -308,18 +308,23 @@ class CI_DB_driver { if ($this->db_debug) { + // grab the error number and message now, as we might run some + // additional queries before displaying the error + $error_no = $this->_error_number(); + $error_msg = $this->_error_message(); + // We call this function in order to roll-back queries // if transactions are enabled. If we don't call this here // the error message will trigger an exit, causing the // transactions to remain in limbo. $this->trans_complete(); - + // Log and display errors log_message('error', 'Query error: '.$this->_error_message()); return $this->display_error( array( - 'Error Number: '.$this->_error_number(), - $this->_error_message(), + 'Error Number: '.$error_no, + $error_msg, $sql ) ); -- cgit v1.2.3-24-g4f1b From 97bc010749830b183fffa7c5faf29744c095864e Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 14 May 2008 15:01:50 +0000 Subject: fixed bug #3419 where the 'database' setting for DSN connections was using the host portion of the URL instead of the path. Added ability to set other db config values in DSN connections via query string --- system/database/DB.php | 25 +++++++++++++++++++++++-- system/database/DB_driver.php | 2 ++ 2 files changed, 25 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index 2446645a7..eb25273a1 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -66,10 +66,31 @@ function &DB($params = '', $active_record_override = FALSE) 'hostname' => (isset($dns['host'])) ? rawurldecode($dns['host']) : '', 'username' => (isset($dns['user'])) ? rawurldecode($dns['user']) : '', 'password' => (isset($dns['pass'])) ? rawurldecode($dns['pass']) : '', - 'database' => (isset($dns['path'])) ? rawurldecode(substr($dns['host'], 1)) : '' + 'database' => (isset($dns['path'])) ? rawurldecode(substr($dns['path'], 1)) : '' ); + + // were additional config items set? + if (isset($dns['query'])) + { + parse_str($dns['query'], $extra); + + foreach($extra as $key => $val) + { + // booleans please + if (strtoupper($val) == "TRUE") + { + $val = TRUE; + } + elseif (strtoupper($val) == "FALSE") + { + $val = FALSE; + } + + $params[$key] = $val; + } + } } - + // No DB specified yet? Beat them senseless... if ( ! isset($params['dbdriver']) OR $params['dbdriver'] == '') { diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index a0833d0ce..c9cece621 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -36,6 +36,8 @@ class CI_DB_driver { var $database; var $dbdriver = 'mysql'; var $dbprefix = ''; + var $char_set = ''; + var $dbcollat = ''; var $autoinit = TRUE; // Whether to automatically initialize the DB var $swap_pre = ''; var $port = ''; -- cgit v1.2.3-24-g4f1b From cafd63e83b20c40b1d9bd234dd2c20b2cdaab2c1 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 14 May 2008 15:08:17 +0000 Subject: set $DB->char_set and $DB->dbcollat defaults to utf8 and utf8_general_ci respectively --- system/database/DB_driver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index c9cece621..eeaf6ea78 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -36,8 +36,8 @@ class CI_DB_driver { var $database; var $dbdriver = 'mysql'; var $dbprefix = ''; - var $char_set = ''; - var $dbcollat = ''; + var $char_set = 'utf8'; + var $dbcollat = 'utf8_general_ci'; var $autoinit = TRUE; // Whether to automatically initialize the DB var $swap_pre = ''; var $port = ''; -- cgit v1.2.3-24-g4f1b From 513ce070bfcbb2b59d0aabd1732b7666b90b4d83 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 18 May 2008 12:23:11 +0000 Subject: Moved the _has_operators() function into DB_driver from DB_active_rec. --- system/database/DB_active_rec.php | 20 -------------------- system/database/DB_driver.php | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 20 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 3cb39822c..dcf9d3868 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1394,27 +1394,7 @@ class CI_DB_active_record extends CI_DB_driver { { return $this->from($table); } - - // -------------------------------------------------------------------- - - /** - * Tests whether the string has an SQL operator - * - * @access private - * @param string - * @return bool - */ - function _has_operator($str) - { - $str = trim($str); - if ( ! preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str)) - { - return FALSE; - } - return TRUE; - } - // -------------------------------------------------------------------- /** diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index eeaf6ea78..60f51d757 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -933,7 +933,9 @@ class CI_DB_driver { function update_string($table, $data, $where) { if ($where == '') + { return false; + } $fields = array(); foreach($data as $key => $val) @@ -971,6 +973,26 @@ class CI_DB_driver { // -------------------------------------------------------------------- + /** + * Tests whether the string has an SQL operator + * + * @access private + * @param string + * @return bool + */ + function _has_operator($str) + { + $str = trim($str); + if ( ! preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str)) + { + return FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + /** * Prep the table name - simply adds the table prefix if needed * -- cgit v1.2.3-24-g4f1b From a459b46e7a5f67a96d0ea85e0778f1bf8858dbdd Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 22 May 2008 13:01:39 +0000 Subject: Fixed a bug (#4561) where orhaving() wasn't properly passing values. Removed some unused variables from the code (#4563). Fixed a bug where having() was not adding an = into the statement (#4568). --- system/database/DB_active_rec.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index dcf9d3868..05a04350d 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -804,7 +804,7 @@ class CI_DB_active_record extends CI_DB_driver { function orhaving($key, $value = '', $escape = TRUE) { - return $this->or_having($key, $value = '', $escape); + return $this->or_having($key, $value, $escape); } // -------------------------------------------------------------------- @@ -852,7 +852,11 @@ class CI_DB_active_record extends CI_DB_driver { $k = $this->_protect_identifiers($k); } - + if ( ! $this->_has_operator($k)) + { + $k .= ' = '; + } + if ($v != '') { $v = ' '.$this->escape_str($v); -- cgit v1.2.3-24-g4f1b From bd4400988922b2560975a80498404d7ecd000c0b Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 29 May 2008 17:52:11 +0000 Subject: made MySQL/MySQLi forge use explicitly named KEYs, added ability to specify multi-column non-primary keys in table creation --- system/database/drivers/mssql/mssql_forge.php | 16 ++++++++++++---- system/database/drivers/mysql/mysql_forge.php | 17 ++++++++++++++--- system/database/drivers/mysqli/mysqli_forge.php | 17 ++++++++++++++--- system/database/drivers/oci8/oci8_forge.php | 17 ++++++++++++++--- system/database/drivers/odbc/odbc_forge.php | 16 ++++++++++++---- system/database/drivers/postgre/postgre_forge.php | 14 +++++++++++--- system/database/drivers/sqlite/sqlite_forge.php | 21 ++++++++++++++++----- 7 files changed, 93 insertions(+), 25 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php index ddd1bb6ae..6995d3422 100644 --- a/system/database/drivers/mssql/mssql_forge.php +++ b/system/database/drivers/mssql/mssql_forge.php @@ -147,16 +147,24 @@ class CI_DB_mssql_forge extends CI_DB_forge { $primary_keys = $this->db->_protect_identifiers($primary_keys); $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; } - + if (is_array($keys) && count($keys) > 0) { - $keys = $this->db->_protect_identifiers($keys); foreach ($keys as $key) { - $sql .= ",\n\tFOREIGN KEY ($key)"; + if (is_array($key)) + { + $key = $this->db->_protect_identifiers($key); + } + else + { + $key = array($this->db->_protect_identifiers($key)); + } + + $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")"; } } - + $sql .= "\n)"; return $sql; diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index a631e4301..28143a04d 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -153,16 +153,27 @@ class CI_DB_mysql_forge extends CI_DB_forge { if (count($primary_keys) > 0) { + $key_name = $this->db->_protect_identifiers(implode('_', $primary_keys)); $primary_keys = $this->db->_protect_identifiers($primary_keys); - $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; + $sql .= ",\n\tPRIMARY KEY ".$key_name." (" . implode(', ', $primary_keys) . ")"; } if (is_array($keys) && count($keys) > 0) { - $keys = $this->db->_protect_identifiers($keys); foreach ($keys as $key) { - $sql .= ",\n\tKEY ($key)"; + if (is_array($key)) + { + $key_name = $this->db->_protect_identifiers(implode('_', $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) . ")"; } } diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index f767acbea..da79bc6ac 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -153,16 +153,27 @@ class CI_DB_mysqli_forge extends CI_DB_forge { if (count($primary_keys) > 0) { + $key_name = $this->db->_protect_identifiers(implode('_', $primary_keys)); $primary_keys = $this->db->_protect_identifiers($primary_keys); - $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; + $sql .= ",\n\tPRIMARY KEY ".$key_name." (" . implode(', ', $primary_keys) . ")"; } if (is_array($keys) && count($keys) > 0) { - $keys = $this->db->_protect_identifiers($keys); foreach ($keys as $key) { - $sql .= ",\n\tKEY ($key)"; + if (is_array($key)) + { + $key_name = $this->db->_protect_identifiers(implode('_', $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) . ")"; } } diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index 9f3fac54f..6266c75a3 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -135,10 +135,21 @@ class CI_DB_oci8_forge extends CI_DB_forge { $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; } - if (count($keys) > 0) + if (is_array($keys) && count($keys) > 0) { - $keys = $this->db->_protect_identifiers($keys); - $sql .= ",\n\tUNIQUE COLUMNS (" . implode(', ', $keys) . ")"; + foreach ($keys as $key) + { + if (is_array($key)) + { + $key = $this->db->_protect_identifiers($key); + } + else + { + $key = array($this->db->_protect_identifiers($key)); + } + + $sql .= ",\n\tUNIQUE COLUMNS (" . implode(', ', $key) . ")"; + } } $sql .= "\n)"; diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php index 60df616c3..10924abe2 100644 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -146,16 +146,24 @@ class CI_DB_odbc_forge extends CI_DB_forge { $primary_keys = $this->db->_protect_identifiers($primary_keys); $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; } - + if (is_array($keys) && count($keys) > 0) { - $keys = $this->db->_protect_identifiers($keys); foreach ($keys as $key) { - $sql .= ",\n\tFOREIGN KEY ($key)"; + if (is_array($key)) + { + $key = $this->db->_protect_identifiers($key); + } + else + { + $key = array($this->db->_protect_identifiers($key)); + } + + $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")"; } } - + $sql .= "\n)"; return $sql; diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index f8dfca8a1..ef5783451 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -134,13 +134,21 @@ class CI_DB_postgre_forge extends CI_DB_forge { $primary_keys = $this->db->_protect_identifiers($primary_keys); $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; } - + if (is_array($keys) && count($keys) > 0) { - $keys = $this->db->_protect_identifiers($keys); foreach ($keys as $key) { - $sql .= ",\n\tFOREIGN KEY ($key)"; + if (is_array($key)) + { + $key = $this->db->_protect_identifiers($key); + } + else + { + $key = array($this->db->_protect_identifiers($key)); + } + + $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")"; } } diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php index 25c74a731..a6866c877 100644 --- a/system/database/drivers/sqlite/sqlite_forge.php +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -144,13 +144,24 @@ class CI_DB_sqlite_forge extends CI_DB_forge { $primary_keys = $this->db->_protect_identifiers($primary_keys); $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; } - - if (count($keys) > 0) + + if (is_array($keys) && count($keys) > 0) { - $keys = $this->db->_protect_identifiers($keys); - $sql .= ",\n\tUNIQUE (" . implode(', ', $keys) . ")"; + foreach ($keys as $key) + { + if (is_array($key)) + { + $key = $this->db->_protect_identifiers($key); + } + else + { + $key = array($this->db->_protect_identifiers($key)); + } + + $sql .= ",\n\tUNIQUE (" . implode(', ', $key) . ")"; + } } - + $sql .= "\n)"; return $sql; -- cgit v1.2.3-24-g4f1b From 694096e5923057bec182726ef6fc8dbd2908978d Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 4 Jun 2008 16:37:00 +0000 Subject: change AR behaviour so that blank values result in empty quotes --- system/database/DB_active_rec.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 05a04350d..17cdc3220 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -454,13 +454,11 @@ class CI_DB_active_record extends CI_DB_driver { $k .= ' ='; } - if ($v !== '' AND $v !== NULL) - { - if ($escape === TRUE) - { - $v = ' '.$this->escape($v); - } + if ($v !== NULL AND $escape === TRUE) + { + $v = ' '.$this->escape($v); } + } else { -- cgit v1.2.3-24-g4f1b From d8364c4267ddccb64ac330067162a3ce0d4e08c2 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 4 Jun 2008 17:01:00 +0000 Subject: bit of a code cleanup --- system/database/DB_active_rec.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 17cdc3220..4eff400c1 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -427,7 +427,7 @@ class CI_DB_active_record extends CI_DB_driver { { $prefix = (count($this->ar_where) == 0) ? '' : $type; - if ( ! $this->_has_operator($k) && is_null($key[$k])) + if (is_null($v) && ! $this->_has_operator($k)) { // value appears not to have been set, assign the test to IS NULL $k .= ' IS NULL'; @@ -447,6 +447,9 @@ class CI_DB_active_record extends CI_DB_driver { { $k = $this->_protect_identifiers($k); } + + $v = ' '.$this->escape($v); + } if ( ! $this->_has_operator($k)) @@ -454,11 +457,6 @@ class CI_DB_active_record extends CI_DB_driver { $k .= ' ='; } - if ($v !== NULL AND $escape === TRUE) - { - $v = ' '.$this->escape($v); - } - } else { @@ -471,6 +469,7 @@ class CI_DB_active_record extends CI_DB_driver { } $this->ar_where[] = $prefix.$k.$v; + if ($this->ar_caching === TRUE) { $this->ar_cache_where[] = $prefix.$k.$v; -- cgit v1.2.3-24-g4f1b From c06f58e19ba52820ca400e3f1a139f8f86961724 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 4 Jun 2008 17:04:48 +0000 Subject: compacting some whitespace --- system/database/DB_active_rec.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 4eff400c1..818c8dd83 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -435,7 +435,6 @@ class CI_DB_active_record extends CI_DB_driver { if ( ! is_null($v)) { - if ($escape === TRUE) { // exception for "field<=" keys @@ -456,16 +455,13 @@ class CI_DB_active_record extends CI_DB_driver { { $k .= ' ='; } - } else { - if ($escape === TRUE) { $k = $this->_protect_identifiers($k, TRUE); - } - + } } $this->ar_where[] = $prefix.$k.$v; -- cgit v1.2.3-24-g4f1b From 7e98a2780131b01d7ecea5e3e4d363ae9601149d Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 4 Jun 2008 17:05:44 +0000 Subject: whitespace, whitespace, schmeitespace --- system/database/DB_active_rec.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 818c8dd83..8d8b23c40 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -448,7 +448,6 @@ class CI_DB_active_record extends CI_DB_driver { } $v = ' '.$this->escape($v); - } if ( ! $this->_has_operator($k)) @@ -472,6 +471,7 @@ class CI_DB_active_record extends CI_DB_driver { } } + return $this; } -- cgit v1.2.3-24-g4f1b From fd7943aaac8f35956e30874291e211d2a3c48453 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 27 Jun 2008 07:44:45 +0000 Subject: Fixed a double opening <p> tag in the index pages of each system directory. --- system/database/drivers/index.html | 11 +++-------- system/database/drivers/mssql/index.html | 11 +++-------- system/database/drivers/mysql/index.html | 11 +++-------- system/database/drivers/mysqli/index.html | 11 +++-------- system/database/drivers/oci8/index.html | 11 +++-------- system/database/drivers/odbc/index.html | 11 +++-------- system/database/drivers/postgre/index.html | 11 +++-------- system/database/drivers/sqlite/index.html | 11 +++-------- system/database/index.html | 11 +++-------- 9 files changed, 27 insertions(+), 72 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/index.html b/system/database/drivers/index.html index 5a1f5d6ae..065d2da5e 100644 --- a/system/database/drivers/index.html +++ b/system/database/drivers/index.html @@ -1,15 +1,10 @@ - - -403 Forbidden - + 403 Forbidden + - - -

Directory access is forbidden.

+

Directory access is forbidden.

- \ No newline at end of file diff --git a/system/database/drivers/mssql/index.html b/system/database/drivers/mssql/index.html index 5a1f5d6ae..065d2da5e 100644 --- a/system/database/drivers/mssql/index.html +++ b/system/database/drivers/mssql/index.html @@ -1,15 +1,10 @@ - - -403 Forbidden - + 403 Forbidden + - - -

Directory access is forbidden.

+

Directory access is forbidden.

- \ No newline at end of file diff --git a/system/database/drivers/mysql/index.html b/system/database/drivers/mysql/index.html index 5a1f5d6ae..065d2da5e 100644 --- a/system/database/drivers/mysql/index.html +++ b/system/database/drivers/mysql/index.html @@ -1,15 +1,10 @@ - - -403 Forbidden - + 403 Forbidden + - - -

Directory access is forbidden.

+

Directory access is forbidden.

- \ No newline at end of file diff --git a/system/database/drivers/mysqli/index.html b/system/database/drivers/mysqli/index.html index 5a1f5d6ae..065d2da5e 100644 --- a/system/database/drivers/mysqli/index.html +++ b/system/database/drivers/mysqli/index.html @@ -1,15 +1,10 @@ - - -403 Forbidden - + 403 Forbidden + - - -

Directory access is forbidden.

+

Directory access is forbidden.

- \ No newline at end of file diff --git a/system/database/drivers/oci8/index.html b/system/database/drivers/oci8/index.html index 5a1f5d6ae..065d2da5e 100644 --- a/system/database/drivers/oci8/index.html +++ b/system/database/drivers/oci8/index.html @@ -1,15 +1,10 @@ - - -403 Forbidden - + 403 Forbidden + - - -

Directory access is forbidden.

+

Directory access is forbidden.

- \ No newline at end of file diff --git a/system/database/drivers/odbc/index.html b/system/database/drivers/odbc/index.html index 5a1f5d6ae..065d2da5e 100644 --- a/system/database/drivers/odbc/index.html +++ b/system/database/drivers/odbc/index.html @@ -1,15 +1,10 @@ - - -403 Forbidden - + 403 Forbidden + - - -

Directory access is forbidden.

+

Directory access is forbidden.

- \ No newline at end of file diff --git a/system/database/drivers/postgre/index.html b/system/database/drivers/postgre/index.html index 5a1f5d6ae..065d2da5e 100644 --- a/system/database/drivers/postgre/index.html +++ b/system/database/drivers/postgre/index.html @@ -1,15 +1,10 @@ - - -403 Forbidden - + 403 Forbidden + - - -

Directory access is forbidden.

+

Directory access is forbidden.

- \ No newline at end of file diff --git a/system/database/drivers/sqlite/index.html b/system/database/drivers/sqlite/index.html index 5a1f5d6ae..065d2da5e 100644 --- a/system/database/drivers/sqlite/index.html +++ b/system/database/drivers/sqlite/index.html @@ -1,15 +1,10 @@ - - -403 Forbidden - + 403 Forbidden + - - -

Directory access is forbidden.

+

Directory access is forbidden.

- \ No newline at end of file diff --git a/system/database/index.html b/system/database/index.html index 5a1f5d6ae..065d2da5e 100644 --- a/system/database/index.html +++ b/system/database/index.html @@ -1,15 +1,10 @@ - - -403 Forbidden - + 403 Forbidden + - - -

Directory access is forbidden.

+

Directory access is forbidden.

- \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 993925b47a0bfb08e79961c47bcc3d247a03a5dd Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 21 Aug 2008 12:43:31 +0000 Subject: whitespace fixes a minor re-ordering of the changelog --- system/database/DB.php | 3 +-- system/database/DB_driver.php | 24 ++++++++++++------------ system/database/DB_result.php | 2 +- system/database/drivers/mysql/mysql_driver.php | 18 +++++++++--------- system/database/drivers/oci8/oci8_result.php | 10 ++++++---- 5 files changed, 29 insertions(+), 28 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index eb25273a1..ef67c80c8 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -44,8 +44,7 @@ function &DB($params = '', $active_record_override = FALSE) show_error('You have specified an invalid database connection group.'); } - $params = $db[$active_group]; - } + $params = $db[$active_group] } elseif (is_string($params)) { diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 60f51d757..1678cffd5 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -142,7 +142,7 @@ class CI_DB_driver { { $this->display_error('db_unable_to_create', $this->database); } - return FALSE; + return FALSE; } else { @@ -221,7 +221,7 @@ class CI_DB_driver { { return $this->display_error('db_unsupported_function'); } - return FALSE; + return FALSE; } if ($this->dbdriver == 'oci8') @@ -258,7 +258,7 @@ class CI_DB_driver { log_message('error', 'Invalid query: '.$sql); return $this->display_error('db_invalid_query'); } - return FALSE; + return FALSE; } // Verify table prefix and replace if necessary @@ -543,12 +543,12 @@ class CI_DB_driver { $this->_trans_status = TRUE; } - log_message('debug', 'DB Transaction Failure'); - return FALSE; + log_message('debug', 'DB Transaction Failure'); + return FALSE; } $this->trans_commit(); - return TRUE; + return TRUE; } // -------------------------------------------------------------------- @@ -755,7 +755,7 @@ class CI_DB_driver { { return $this->display_error('db_unsupported_function'); } - return FALSE; + return FALSE; } $retval = array(); @@ -815,7 +815,7 @@ class CI_DB_driver { { return $this->display_error('db_field_param_missing'); } - return FALSE; + return FALSE; } if (FALSE === ($sql = $this->_list_columns($this->prep_tablename($table)))) @@ -824,7 +824,7 @@ class CI_DB_driver { { return $this->display_error('db_unsupported_function'); } - return FALSE; + return FALSE; } $query = $this->query($sql); @@ -887,7 +887,7 @@ class CI_DB_driver { { return $this->display_error('db_field_param_missing'); } - return FALSE; + return FALSE; } $query = $this->query($this->_field_data($this->prep_tablename($table))); @@ -906,7 +906,7 @@ class CI_DB_driver { */ function insert_string($table, $data) { - $fields = array(); + $fields = array(); $values = array(); foreach($data as $key => $val) @@ -1039,7 +1039,7 @@ class CI_DB_driver { { return $this->display_error('db_unsupported_function'); } - return FALSE; + return FALSE; } else { diff --git a/system/database/DB_result.php b/system/database/DB_result.php index d8d0d0d97..2a7824ff5 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -104,7 +104,7 @@ class CI_DB_result { return array(); } - $this->_data_seek(0); + $this->_data_seek(0); while ($row = $this->_fetch_assoc()) { $this->result_array[] = $row; diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 8df6c1b70..889ea17fb 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -246,15 +246,15 @@ class CI_DB_mysql_driver extends CI_DB { function escape_str($str) { if (is_array($str)) - { - foreach($str as $key => $val) - { - $str[$key] = $this->escape_str($val); - } - - return $str; - } - + { + foreach($str as $key => $val) + { + $str[$key] = $this->escape_str($val); + } + + return $str; + } + if (function_exists('mysql_real_escape_string') AND is_resource($this->conn_id)) { return mysql_real_escape_string($str, $this->conn_id); diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 73373c882..20ab925fd 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -42,13 +42,15 @@ class CI_DB_oci8_result extends CI_DB_result { */ function num_rows() { - $rowcount = count($this->result_array()); - @ociexecute($this->stmt_id); - if ($this->curs_id) + $rowcount = count($this->result_array()); + @ociexecute($this->stmt_id); + + if ($this->curs_id) { @ociexecute($this->curs_id); } - return $rowcount; + + return $rowcount; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From f65308f36173d7924f1460e0383e5a6c46e626b5 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 21 Aug 2008 23:11:23 +0000 Subject: fixed a missing semi colon --- system/database/DB.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index ef67c80c8..2dd86e14e 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -44,7 +44,8 @@ function &DB($params = '', $active_record_override = FALSE) show_error('You have specified an invalid database connection group.'); } - $params = $db[$active_group] } + $params = $db[$active_group]; + } elseif (is_string($params)) { -- cgit v1.2.3-24-g4f1b From 37b3ecff3043b3cf8359446052ec723e52944742 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Fri, 12 Sep 2008 23:34:18 +0000 Subject: updated copyright --- system/database/DB.php | 2 +- system/database/DB_active_rec.php | 2 +- system/database/DB_driver.php | 2 +- system/database/DB_forge.php | 2 +- system/database/DB_result.php | 2 +- system/database/drivers/mssql/mssql_driver.php | 2 +- system/database/drivers/mssql/mssql_forge.php | 2 +- system/database/drivers/mssql/mssql_result.php | 2 +- system/database/drivers/mssql/mssql_utility.php | 2 +- system/database/drivers/oci8/oci8_driver.php | 2 +- system/database/drivers/oci8/oci8_forge.php | 2 +- system/database/drivers/oci8/oci8_result.php | 2 +- system/database/drivers/oci8/oci8_utility.php | 2 +- system/database/drivers/sqlite/sqlite_driver.php | 2 +- system/database/drivers/sqlite/sqlite_forge.php | 2 +- system/database/drivers/sqlite/sqlite_result.php | 2 +- system/database/drivers/sqlite/sqlite_utility.php | 2 +- 17 files changed, 17 insertions(+), 17 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index 2dd86e14e..27eb336f7 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 8d8b23c40..fccf1b0a2 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 1678cffd5..1450a0644 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index d3ef326b6..cc88c32f9 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 2a7824ff5..0ec59d568 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 34ad9799e..98c03c56e 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php index 6995d3422..c842ac1e2 100644 --- a/system/database/drivers/mssql/mssql_forge.php +++ b/system/database/drivers/mssql/mssql_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index 7532d2053..b4c22bec9 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index c62146bf6..1736fbafa 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 2bc45258d..d6bc512be 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index 6266c75a3..1a66978d6 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 20ab925fd..9bc982fbf 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 69d07f437..a3b6d8157 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index b323e4154..5cac04dfa 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php index a6866c877..05f366a6f 100644 --- a/system/database/drivers/sqlite/sqlite_forge.php +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index 8bb0d9d0b..9fbd72556 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index fff24a715..3527b5b1b 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b From 9ba2bf2e2094c12533887fe77c0ef5006e41c960 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Fri, 12 Sep 2008 23:34:39 +0000 Subject: updated copyright --- system/database/DB_cache.php | 2 +- system/database/DB_utility.php | 2 +- system/database/drivers/mysql/mysql_driver.php | 2 +- system/database/drivers/mysql/mysql_forge.php | 2 +- system/database/drivers/mysql/mysql_result.php | 2 +- system/database/drivers/mysql/mysql_utility.php | 2 +- system/database/drivers/mysqli/mysqli_driver.php | 2 +- system/database/drivers/mysqli/mysqli_forge.php | 2 +- system/database/drivers/mysqli/mysqli_result.php | 2 +- system/database/drivers/mysqli/mysqli_utility.php | 2 +- system/database/drivers/odbc/odbc_driver.php | 2 +- system/database/drivers/odbc/odbc_forge.php | 2 +- system/database/drivers/odbc/odbc_result.php | 2 +- system/database/drivers/odbc/odbc_utility.php | 2 +- system/database/drivers/postgre/postgre_driver.php | 2 +- system/database/drivers/postgre/postgre_forge.php | 2 +- system/database/drivers/postgre/postgre_result.php | 2 +- system/database/drivers/postgre/postgre_utility.php | 2 +- 18 files changed, 18 insertions(+), 18 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 977327a8d..ecb2b13a1 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index d273df158..a37522d90 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 889ea17fb..9d9b6512b 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index 28143a04d..e2a222565 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index 4d9dd82bd..ec75955e8 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 6bae52791..6fb1ab4bb 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 4e840e749..cd683dfe7 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index da79bc6ac..ce6ab45b2 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index 4b8115d8e..0a97454f0 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 235ee4b67..0080bfc3d 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 48a143271..647171696 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php index 10924abe2..de67b9478 100644 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index 809887a43..8b485ec55 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index 5d9010506..6f4376ed2 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 9a260a5ac..7574ded13 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index ef5783451..b9e1cd9bb 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index 1613da9b8..d018a9b2b 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 261050b2d..f9b0f22e0 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b From d16bab12339fe2746e1ead72ba96351c3423c27c Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 24 Sep 2008 18:22:03 +0000 Subject: added removal of non-printing characters to escape_str() of drivers that do not have native PHP escaping mechanisms --- system/database/drivers/mssql/mssql_driver.php | 2 +- system/database/drivers/oci8/oci8_driver.php | 2 +- system/database/drivers/odbc/odbc_driver.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 98c03c56e..5ac90b451 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -214,7 +214,7 @@ class CI_DB_mssql_driver extends CI_DB { function escape_str($str) { // Escape single quotes - return str_replace("'", "''", $str); + return str_replace("'", "''", $this->input->_remove_invisible_characters($str)); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index d6bc512be..765c3f6c9 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -366,7 +366,7 @@ class CI_DB_oci8_driver extends CI_DB { */ function escape_str($str) { - return $str; + return $this->input->_remove_invisible_characters($str); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 647171696..f89000d83 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -235,7 +235,7 @@ class CI_DB_odbc_driver extends CI_DB { function escape_str($str) { // ODBC doesn't require escaping - return $str; + return $this->input->_remove_invisible_characters($str); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From b3a3bf342903b32a79e8799860a61b93d7f28581 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 26 Sep 2008 17:20:53 +0000 Subject: removed some legacy escaping code from _backup() in the MySQL utility, fixing bug 4536 http://codeigniter.com/bug_tracker/bug/4536/ --- system/database/drivers/mysql/mysql_utility.php | 9 --------- 1 file changed, 9 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 6fb1ab4bb..e035e0cf6 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -176,15 +176,6 @@ class CI_DB_mysql_utility extends CI_DB_utility { } else { - // 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 if ($is_int[$i] == FALSE) { -- cgit v1.2.3-24-g4f1b From 52dc8ca4372eb36e9186cef0e34bf0cafe5b1cd8 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 30 Sep 2008 19:53:52 +0000 Subject: Added backticks to column names when using insert_string and update_string. Relates to this bug report: http://codeigniter.com/bug_tracker/bug/4509/ --- system/database/DB_driver.php | 5 ++-- system/database/drivers/mssql/mssql_driver.php | 29 ++++++++++++++-------- system/database/drivers/mysql/mysql_driver.php | 16 ++++++++++++ system/database/drivers/mysqli/mysqli_driver.php | 16 ++++++++++++ system/database/drivers/oci8/oci8_driver.php | 17 +++++++++++++ system/database/drivers/odbc/odbc_driver.php | 22 +++++++++++++--- system/database/drivers/postgre/postgre_driver.php | 18 +++++++++++++- system/database/drivers/sqlite/sqlite_driver.php | 20 +++++++++++++-- 8 files changed, 124 insertions(+), 19 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 1450a0644..b937ffd6a 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -911,11 +911,10 @@ class CI_DB_driver { foreach($data as $key => $val) { - $fields[] = $key; + $fields[] = $this->_escape_column($key); $values[] = $this->escape($val); } - return $this->_insert($this->prep_tablename($table), $fields, $values); } @@ -940,7 +939,7 @@ class CI_DB_driver { $fields = array(); foreach($data as $key => $val) { - $fields[$key] = $this->escape($val); + $fields[$this->_escape_column($key)] = $this->escape($val); } if ( ! is_array($where)) diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 5ac90b451..9a912a320 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -390,7 +390,24 @@ class CI_DB_mssql_driver extends CI_DB { // Are error numbers supported? return ''; } - + + // -------------------------------------------------------------------- + + /** + * Escape Column Name + * + * This function adds backticks around supplied column name + * + * @access private + * @param string the column name + * @return string + */ + function _escape_column($column) + { + // Not necessary with MS SQL so we simply return the value + return $column; + } + // -------------------------------------------------------------------- /** @@ -405,15 +422,7 @@ class CI_DB_mssql_driver extends CI_DB { */ function _escape_table($table) { - // I don't believe this is necessary with MS SQL. Not sure, though. - Rick - - /* - if (strpos($table, '.') !== FALSE) - { - $table = '"' . str_replace('.', '"."', $table) . '"'; - } - */ - + // Not necessary with MS SQL so we simply return the value return $table; } diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 9d9b6512b..de372e669 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -398,6 +398,22 @@ class CI_DB_mysql_driver extends CI_DB { { return mysql_errno($this->conn_id); } + + // -------------------------------------------------------------------- + + /** + * Escape Column Name + * + * This function adds backticks around supplied column name + * + * @access private + * @param string the column name + * @return string + */ + function _escape_column($column) + { + return '`' .$column. '`'; + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index cd683dfe7..35a7fc077 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -394,6 +394,22 @@ class CI_DB_mysqli_driver extends CI_DB { { return mysqli_errno($this->conn_id); } + + // -------------------------------------------------------------------- + + /** + * Escape Column Name + * + * This function adds backticks around supplied column name + * + * @access private + * @param string the column name + * @return string + */ + function _escape_column($column) + { + return '`' .$column. '`'; + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 765c3f6c9..b45b00326 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -506,6 +506,23 @@ class CI_DB_oci8_driver extends CI_DB { $error = ocierror($this->conn_id); return $error['code']; } + + // -------------------------------------------------------------------- + + /** + * Escape Column Name + * + * This function adds backticks around supplied column name + * + * @access private + * @param string the column name + * @return string + */ + function _escape_column($column) + { + // Probably not necessary with Oracle so we simply return the value + return $column; + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index f89000d83..ed8f81cb9 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -371,7 +371,23 @@ class CI_DB_odbc_driver extends CI_DB { { return odbc_error($this->conn_id); } - + // -------------------------------------------------------------------- + + /** + * Escape Column Name + * + * This function adds backticks around supplied column name + * + * @access private + * @param string the column name + * @return string + */ + function _escape_column($column) + { + // Not necessary with ODBC so we simply return the value + return $column; + } + // -------------------------------------------------------------------- /** @@ -386,9 +402,9 @@ class CI_DB_odbc_driver extends CI_DB { */ function _escape_table($table) { - // used to add backticks in other db drivers + // Not necessary with ODBC so we simply return the value return $table; - } + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 7574ded13..3d006d3d6 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -391,7 +391,23 @@ class CI_DB_postgre_driver extends CI_DB { { return ''; } - + // -------------------------------------------------------------------- + + /** + * Escape Column Name + * + * This function adds backticks around supplied column name + * + * @access private + * @param string the column name + * @return string + */ + function _escape_column($column) + { + // Probably not necessary with Postgres so we simply return the value + return $column; + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 5cac04dfa..46e0fae49 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -387,7 +387,24 @@ class CI_DB_sqlite_driver extends CI_DB { { return sqlite_last_error($this->conn_id); } - + + // -------------------------------------------------------------------- + + /** + * Escape Column Name + * + * This function adds backticks around supplied column name + * + * @access private + * @param string the column name + * @return string + */ + function _escape_column($column) + { + // Not necessary with SQLite so we simply return the value + return $column; + } + // -------------------------------------------------------------------- /** @@ -402,7 +419,6 @@ class CI_DB_sqlite_driver extends CI_DB { */ function _escape_table($table) { - // other database drivers use this to add backticks, hence this // function is simply going to return the tablename for sqlite return $table; -- cgit v1.2.3-24-g4f1b From ff73401cdef0136c15c6dab95d4d722123668e7a Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 30 Sep 2008 20:38:12 +0000 Subject: Did a little clean up. Nothing that affected functionality --- system/database/DB_active_rec.php | 3 +-- system/database/DB_forge.php | 10 ++++++++++ system/database/drivers/mssql/mssql_driver.php | 2 +- system/database/drivers/mysql/mysql_driver.php | 3 +++ system/database/drivers/oci8/oci8_driver.php | 2 +- system/database/drivers/odbc/odbc_driver.php | 2 +- system/database/drivers/postgre/postgre_driver.php | 2 +- system/database/drivers/sqlite/sqlite_driver.php | 20 +------------------- system/database/drivers/sqlite/sqlite_forge.php | 22 ++++++++++++++++++++-- 9 files changed, 39 insertions(+), 27 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index fccf1b0a2..355868386 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -821,11 +821,10 @@ class CI_DB_active_record extends CI_DB_driver { /** * Sets the HAVING values * - * Called by having() or orhaving() + * Called by having() or or_having() * * @access private * @param string - * @param string * @return object */ diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index cc88c32f9..d48165e2b 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -97,6 +97,16 @@ class CI_DB_forge { */ function add_key($key = '', $primary = FALSE) { + if (is_array($key)) + { + foreach($key as $one) + { + $this->add_key($one, $primary); + } + + return; + } + if ($key == '') { show_error('Key information is required for that operation.'); diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 9a912a320..fd3f9638a 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -87,7 +87,7 @@ class CI_DB_mssql_driver extends CI_DB { */ function db_set_charset($charset, $collation) { - // TODO - add support if needed + // @todo - add support if needed return TRUE; } diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index de372e669..52df1e591 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -314,6 +314,9 @@ class CI_DB_mysql_driver extends CI_DB { $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($this->dbprefix.$table)); + if ($query->num_rows() == 0) + return '0'; + $row = $query->row(); return (int)$row->numrows; } diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index b45b00326..9d9193252 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -111,7 +111,7 @@ class CI_DB_oci8_driver extends CI_DB { */ function db_set_charset($charset, $collation) { - // TODO - add support if needed + // @todo - add support if needed return TRUE; } diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index ed8f81cb9..06282e55c 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -94,7 +94,7 @@ class CI_DB_odbc_driver extends CI_DB { */ function db_set_charset($charset, $collation) { - // TODO - add support if needed + // @todo - add support if needed return TRUE; } diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 3d006d3d6..55f650280 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -92,7 +92,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function db_set_charset($charset, $collation) { - // TODO - add support if needed + // @todo - add support if needed return TRUE; } diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 46e0fae49..782156949 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -113,7 +113,7 @@ class CI_DB_sqlite_driver extends CI_DB { */ function db_set_charset($charset, $collation) { - // TODO - add support if needed + // @todo - add support if needed return TRUE; } @@ -651,24 +651,6 @@ class CI_DB_sqlite_driver extends CI_DB { @sqlite_close($conn_id); } - // -------------------------------------------------------------------- - - /** - * Rename a table - * - * Generates a platform-specific query so that a table can be renamed - * - * @access private - * @param string the old table name - * @param string the new table name - * @return string - */ - function _rename_table($table_name, $new_table_name) - { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); - return $sql; - } - } diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php index 05f366a6f..631c9c771 100644 --- a/system/database/drivers/sqlite/sqlite_forge.php +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -144,7 +144,7 @@ class CI_DB_sqlite_forge extends CI_DB_forge { $primary_keys = $this->db->_protect_identifiers($primary_keys); $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; } - + if (is_array($keys) && count($keys) > 0) { foreach ($keys as $key) @@ -161,7 +161,7 @@ class CI_DB_sqlite_forge extends CI_DB_forge { $sql .= ",\n\tUNIQUE (" . implode(', ', $key) . ")"; } } - + $sql .= "\n)"; return $sql; @@ -241,6 +241,24 @@ class CI_DB_sqlite_forge extends CI_DB_forge { return $sql; } + + // -------------------------------------------------------------------- + + /** + * Rename a table + * + * Generates a platform-specific query so that a table can be renamed + * + * @access private + * @param string the old table name + * @param string the new table name + * @return string + */ + function _rename_table($table_name, $new_table_name) + { + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); + return $sql; + } } /* End of file sqlite_forge.php */ -- cgit v1.2.3-24-g4f1b From 1346aac56e4c5effee5a66780095ea9d4ea8cf52 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 30 Sep 2008 20:46:58 +0000 Subject: Removed some spaces --- system/database/DB.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index 27eb336f7..2b3ff3dc6 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -73,7 +73,7 @@ function &DB($params = '', $active_record_override = FALSE) if (isset($dns['query'])) { parse_str($dns['query'], $extra); - + foreach($extra as $key => $val) { // booleans please @@ -85,12 +85,12 @@ function &DB($params = '', $active_record_override = FALSE) { $val = FALSE; } - + $params[$key] = $val; } } } - + // No DB specified yet? Beat them senseless... if ( ! isset($params['dbdriver']) OR $params['dbdriver'] == '') { -- cgit v1.2.3-24-g4f1b From 9f02e3c852a38b4e17ac1ade26144d0b9d554693 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 30 Sep 2008 21:51:01 +0000 Subject: Added backticks around column names in where clause. Bug report number: 4668 --- system/database/DB_active_rec.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 355868386..cd616336d 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -440,7 +440,7 @@ class CI_DB_active_record extends CI_DB_driver { // exception for "field<=" keys if ($this->_has_operator($k)) { - $k = preg_replace("/([A-Za-z_0-9]+)/", $this->_protect_identifiers('$1'), $k); + $k = preg_replace("/([A-Za-z_0-9]+)/", $this->_escape_column($this->_protect_identifiers('$1')), $k); } else { -- cgit v1.2.3-24-g4f1b From 852160a27ba330f9e47f4fb16d8042c6074f435c Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 30 Sep 2008 21:55:34 +0000 Subject: Swiched to escape() rather then escape_str(), as per bug report #4680 --- system/database/DB_active_rec.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index cd616336d..e7920d083 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -701,7 +701,7 @@ class CI_DB_active_record extends CI_DB_driver { $prefix = (count($this->ar_like) == 0) ? '' : $type; - $v = $this->escape_str($v); + $v = $this->escape($v); if ($side == 'before') { @@ -851,7 +851,7 @@ class CI_DB_active_record extends CI_DB_driver { if ($v != '') { - $v = ' '.$this->escape_str($v); + $v = ' '.$this->escape($v); } $this->ar_having[] = $prefix.$k.$v; -- cgit v1.2.3-24-g4f1b From 2cad6e9da8b94833503d0d2f545bcaa29d50bd5d Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 7 Oct 2008 00:19:34 +0000 Subject: There was a call to $this->input->_remove_invisible_characters($str); It should have been: $this->input->CI->_remove_invisible_characters($str); --- system/database/DB_forge.php | 2 +- system/database/drivers/mssql/mssql_driver.php | 2 +- system/database/drivers/oci8/oci8_driver.php | 2 +- system/database/drivers/odbc/odbc_driver.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index d48165e2b..64f95d635 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -191,7 +191,7 @@ class CI_DB_forge { } $sql = $this->_create_table($this->db->dbprefix.$table, $this->fields, $this->primary_keys, $this->keys, $if_not_exists); - + $this->_reset(); return $this->db->query($sql); } diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index fd3f9638a..9d7e072a4 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -214,7 +214,7 @@ class CI_DB_mssql_driver extends CI_DB { function escape_str($str) { // Escape single quotes - return str_replace("'", "''", $this->input->_remove_invisible_characters($str)); + return str_replace("'", "''", $this->CI->input->_remove_invisible_characters($str)); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 9d9193252..98c993291 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -366,7 +366,7 @@ class CI_DB_oci8_driver extends CI_DB { */ function escape_str($str) { - return $this->input->_remove_invisible_characters($str); + return $this->input->CI->_remove_invisible_characters($str); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 06282e55c..a64eb56b9 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -235,7 +235,7 @@ class CI_DB_odbc_driver extends CI_DB { function escape_str($str) { // ODBC doesn't require escaping - return $this->input->_remove_invisible_characters($str); + return $this->input->CI->_remove_invisible_characters($str); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From b6ba6a3a8ef3d594ff3f32f2d128a8211f1d2db3 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 7 Oct 2008 00:44:41 +0000 Subject: Added support for empty connection strings, based on bug # 3135 --- system/database/drivers/postgre/postgre_driver.php | 39 ++++++++++++++++++---- 1 file changed, 32 insertions(+), 7 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 55f650280..aada164d0 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -38,6 +38,35 @@ class CI_DB_postgre_driver extends CI_DB { var $_count_string = "SELECT COUNT(*) AS "; var $_random_keyword = ' RANDOM()'; // database specific random keyword + /** + * Connection String + * + * @access private + * @return string + */ + function _connect_string() + { + $components = array( + 'hostname' => 'host', + 'port' => 'port', + 'database' => 'dbname', + 'username' => 'user', + 'password' => 'password' + ); + + $connect_string = ""; + foreach ($components as $key => $val) + { + if (isset($this->$key) && $this->$key != '') + { + $connect_string .= " $val=".$this->$key; + } + } + return trim($connect_string); + } + + // -------------------------------------------------------------------- + /** * Non-persistent database connection * @@ -45,10 +74,8 @@ class CI_DB_postgre_driver extends CI_DB { * @return resource */ function db_connect() - { - $port = ($this->port == '') ? '' : " port=".$this->port; - - return @pg_connect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); + { + return @pg_connect($this->_connect_string()); } // -------------------------------------------------------------------- @@ -61,9 +88,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function db_pconnect() { - $port = ($this->port == '') ? '' : " port=".$this->port; - - return @pg_pconnect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); + return @pg_pconnect($this->_connect_string()); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From ceb6f0bfdeaad23bad419ff4e62519342cc03d05 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 7 Oct 2008 00:48:19 +0000 Subject: Added $params to ODBC constructor, based on bug report #3374 --- system/database/drivers/odbc/odbc_driver.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index a64eb56b9..7c59c3060 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -39,8 +39,16 @@ class CI_DB_odbc_driver extends CI_DB { var $_random_keyword; - function CI_DB_odbc_driver() + function CI_DB_odbc_driver($params) { + if (is_array($params)) + { + foreach ($params as $key => $val) + { + $this->$key = $val; + } + } + $this->_random_keyword = ' RND('.time().')'; // database specific random keyword } -- cgit v1.2.3-24-g4f1b From a2a240a87baa0cf6a425837158880f5235e3bca6 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 7 Oct 2008 00:55:41 +0000 Subject: Fixed a bug (#2985) in which multiple queries using a single request were not being honored --- system/database/DB_driver.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index b937ffd6a..257f1ee9b 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -382,6 +382,7 @@ class CI_DB_driver { $RES->stmt_id = $this->stmt_id; $RES->curs_id = NULL; $RES->limit_used = $this->limit_used; + $this->stmt_id = FALSE; } // Is query caching enabled? If so, we'll serialize the -- cgit v1.2.3-24-g4f1b From 482ee4325894bb05b4f97bb9e9ded14e5fce93ba Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 7 Oct 2008 00:59:08 +0000 Subject: Fixed Oracle bug (#3306) that was preventing multiple queries in one action --- system/database/drivers/oci8/oci8_driver.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system/database') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 98c993291..362da58fb 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -141,6 +141,7 @@ class CI_DB_oci8_driver extends CI_DB { { // oracle must parse the query before it is run. All of the actions with // the query are based on the statement id returned by ociparse + $this->stmt_id = FALSE; $this->_set_stmt_id($sql); ocisetprefetch($this->stmt_id, 1000); return @ociexecute($this->stmt_id, $this->_commit); -- cgit v1.2.3-24-g4f1b From 06a2e74e8834e88e4639d17dc756403985ca00f8 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 7 Oct 2008 01:04:15 +0000 Subject: Oops! Didn't realize that the CI super object was not being used by the main Driver. Fixed... --- system/database/drivers/mssql/mssql_driver.php | 7 +++++-- system/database/drivers/oci8/oci8_driver.php | 5 ++++- system/database/drivers/odbc/odbc_driver.php | 5 ++++- 3 files changed, 13 insertions(+), 4 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 9d7e072a4..1c6249aef 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -212,9 +212,12 @@ class CI_DB_mssql_driver extends CI_DB { * @return string */ function escape_str($str) - { + { + // Access the CI object + $CI->get_instance(); + // Escape single quotes - return str_replace("'", "''", $this->CI->input->_remove_invisible_characters($str)); + return str_replace("'", "''", $CI->input->_remove_invisible_characters($str)); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 362da58fb..82bc51bf3 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -367,7 +367,10 @@ class CI_DB_oci8_driver extends CI_DB { */ function escape_str($str) { - return $this->input->CI->_remove_invisible_characters($str); + // Access the CI object + $CI->get_instance(); + + return $CI->_remove_invisible_characters($str); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 7c59c3060..985c975ce 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -242,8 +242,11 @@ class CI_DB_odbc_driver extends CI_DB { */ function escape_str($str) { + // Access the CI object + $CI->get_instance(); + // ODBC doesn't require escaping - return $this->input->CI->_remove_invisible_characters($str); + return $CI->_remove_invisible_characters($str); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 218839a7f4910834e4e991c6650da05b1bd7f743 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 7 Oct 2008 01:15:48 +0000 Subject: Fixed bug (#3472) that was adding quotes incorrectly. --- system/database/drivers/mssql/mssql_driver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 1c6249aef..d0e1092e6 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -470,11 +470,11 @@ class CI_DB_mssql_driver extends CI_DB { // This function may get "field >= 1", and need it to return ""field" >= 1" $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; - $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1"$2"$3', $item); + $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1$2$3', $item); } else { - return "\"{$item}\""; + return $item; } $exceptions = array('AS', '/', '-', '%', '+', '*', 'OR', 'IS'); -- cgit v1.2.3-24-g4f1b From ca86a7cf108fe13b89ba22b727a10ab3ac58db19 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 7 Oct 2008 01:16:57 +0000 Subject: --- system/database/drivers/mssql/mssql_driver.php | 2 +- system/database/drivers/oci8/oci8_driver.php | 2 +- system/database/drivers/odbc/odbc_driver.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index d0e1092e6..ed6eadbf8 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -214,7 +214,7 @@ class CI_DB_mssql_driver extends CI_DB { function escape_str($str) { // Access the CI object - $CI->get_instance(); + $CI =& get_instance(); // Escape single quotes return str_replace("'", "''", $CI->input->_remove_invisible_characters($str)); diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 82bc51bf3..96a6a1352 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -368,7 +368,7 @@ class CI_DB_oci8_driver extends CI_DB { function escape_str($str) { // Access the CI object - $CI->get_instance(); + $CI =& get_instance(); return $CI->_remove_invisible_characters($str); } diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 985c975ce..29928807b 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -243,7 +243,7 @@ class CI_DB_odbc_driver extends CI_DB { function escape_str($str) { // Access the CI object - $CI->get_instance(); + $CI =& get_instance(); // ODBC doesn't require escaping return $CI->_remove_invisible_characters($str); -- cgit v1.2.3-24-g4f1b From 5aa8c60392a89140448691b838a90b7d1c644774 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 7 Oct 2008 01:24:07 +0000 Subject: Explicitly added driver name variable in each DB driver, based on this bug report: #4436 --- system/database/drivers/mssql/mssql_driver.php | 3 ++- system/database/drivers/mysql/mysql_driver.php | 2 ++ system/database/drivers/mysqli/mysqli_driver.php | 2 ++ system/database/drivers/oci8/oci8_driver.php | 2 ++ system/database/drivers/odbc/odbc_driver.php | 2 ++ system/database/drivers/postgre/postgre_driver.php | 2 ++ system/database/drivers/sqlite/sqlite_driver.php | 2 ++ 7 files changed, 14 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index ed6eadbf8..02b975ad2 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -37,7 +37,8 @@ class CI_DB_mssql_driver extends CI_DB { */ var $_count_string = "SELECT COUNT(*) AS "; var $_random_keyword = ' ASC'; // not currently supported - + var $dbdriver = 'mssql'; + /** * Non-persistent database connection * diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 52df1e591..db04c6de8 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -30,6 +30,8 @@ */ class CI_DB_mysql_driver extends CI_DB { + var $dbdriver = 'mysql'; + /** * Whether to use the MySQL "delete hack" which allows the number * of affected rows to be shown. Uses a preg_replace when enabled, diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 35a7fc077..a5d104cc2 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -30,6 +30,8 @@ */ class CI_DB_mysqli_driver extends CI_DB { + var $dbdriver = 'mysqli'; + /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 96a6a1352..006e6ef1f 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -43,6 +43,8 @@ class CI_DB_oci8_driver extends CI_DB { + var $dbdriver = 'oci8'; + /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 29928807b..cc8d3347b 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -30,6 +30,8 @@ */ class CI_DB_odbc_driver extends CI_DB { + var $dbdriver = 'odbc'; + /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index aada164d0..c5c70a736 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -30,6 +30,8 @@ */ class CI_DB_postgre_driver extends CI_DB { + var $dbdriver = 'postgre'; + /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 782156949..df19dba78 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -32,6 +32,8 @@ */ class CI_DB_sqlite_driver extends CI_DB { + var $dbdriver = 'sqlite'; + /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is -- cgit v1.2.3-24-g4f1b From a8664295b31968aa29556b93b13bb6a6080be19e Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 8 Oct 2008 22:38:31 +0000 Subject: moved call to $RES->num_rows() further down in code so that oracle-specific class variables would be set properly as needed before executing --- system/database/DB_driver.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 257f1ee9b..572595f42 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -375,7 +375,6 @@ class CI_DB_driver { $RES = new $driver(); $RES->conn_id = $this->conn_id; $RES->result_id = $this->result_id; - $RES->num_rows = $RES->num_rows(); if ($this->dbdriver == 'oci8') { @@ -385,6 +384,9 @@ class CI_DB_driver { $this->stmt_id = FALSE; } + // oci8 vars must be set before calling this + $RES->num_rows = $RES->num_rows(); + // Is query caching enabled? If so, we'll serialize the // result object and save it to a cache file. if ($this->cache_on == TRUE AND $this->_cache_init()) -- cgit v1.2.3-24-g4f1b From 59523592c58abc303a6eae1904c80fa6a428c3d3 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Fri, 17 Oct 2008 04:07:40 +0000 Subject: Fixed a number of bug reports related to table/db names not being escaped or prefixed correctly. --- system/database/DB_active_rec.php | 569 ++++++++++++----------- system/database/DB_driver.php | 334 ++++++++----- system/database/DB_forge.php | 9 +- system/database/DB_result.php | 1 - system/database/drivers/mssql/mssql_driver.php | 112 ++--- system/database/drivers/mssql/mssql_forge.php | 4 +- system/database/drivers/mssql/mssql_result.php | 6 - system/database/drivers/oci8/oci8_driver.php | 109 +---- system/database/drivers/sqlite/sqlite_driver.php | 104 +---- system/database/drivers/sqlite/sqlite_forge.php | 2 +- system/database/drivers/sqlite/sqlite_result.php | 6 - 11 files changed, 601 insertions(+), 655 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index e7920d083..f4c13cc42 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -28,57 +28,38 @@ */ class CI_DB_active_record extends CI_DB_driver { - var $ar_select = array(); - var $ar_distinct = FALSE; - var $ar_from = array(); - var $ar_join = array(); - var $ar_where = array(); - var $ar_like = array(); - var $ar_groupby = array(); - var $ar_having = array(); - var $ar_limit = FALSE; - var $ar_offset = FALSE; - var $ar_order = FALSE; - var $ar_orderby = array(); - var $ar_set = array(); - var $ar_wherein = array(); + var $ar_select = array(); + var $ar_distinct = FALSE; + var $ar_from = array(); + var $ar_join = array(); + var $ar_where = array(); + var $ar_like = array(); + var $ar_groupby = array(); + var $ar_having = array(); + var $ar_limit = FALSE; + var $ar_offset = FALSE; + var $ar_order = FALSE; + var $ar_orderby = array(); + var $ar_set = array(); + var $ar_wherein = array(); var $ar_aliased_tables = array(); - var $ar_store_array = array(); - + var $ar_store_array = array(); + // Active Record Caching variables - var $ar_caching = FALSE; - var $ar_cache_select = array(); - var $ar_cache_from = array(); - var $ar_cache_join = array(); - var $ar_cache_where = array(); - var $ar_cache_like = array(); - var $ar_cache_groupby = array(); - var $ar_cache_having = array(); - var $ar_cache_limit = FALSE; - var $ar_cache_offset = FALSE; - var $ar_cache_order = FALSE; - var $ar_cache_orderby = array(); - var $ar_cache_set = array(); - - - /** - * DB Prefix - * - * Prepends a database prefix if one exists in configuration - * - * @access public - * @param string the table - * @return string - */ - function dbprefix($table = '') - { - if ($table == '') - { - $this->display_error('db_table_name_required'); - } + var $ar_caching = FALSE; + var $ar_cache_select = array(); + var $ar_cache_from = array(); + var $ar_cache_join = array(); + var $ar_cache_where = array(); + var $ar_cache_like = array(); + var $ar_cache_groupby = array(); + var $ar_cache_having = array(); + var $ar_cache_limit = FALSE; + var $ar_cache_offset = FALSE; + var $ar_cache_order = FALSE; + var $ar_cache_orderby = array(); + var $ar_cache_set = array(); - return $this->dbprefix.$table; - } // -------------------------------------------------------------------- @@ -91,39 +72,27 @@ class CI_DB_active_record extends CI_DB_driver { * @param string * @return object */ - function select($select = '*', $protect_identifiers = TRUE) + function select($select = '*', $escape = NULL) { + // Set the global value if this was sepecified + if (is_bool($escape)) + { + $this->_protect_identifiers = $escape; + } + if (is_string($select)) { - if ($protect_identifiers !== FALSE) - { - $select = explode(',', $select); - } - else - { - $select = array($select); - } + $select = explode(',', $select); } foreach ($select as $val) { $val = trim($val); - if ($val != '*' && $protect_identifiers !== FALSE) - { - if (strpos($val, '.') !== FALSE) - { - $val = $this->dbprefix.$val; - } - else - { - $val = $this->_protect_identifiers($val); - } - } - if ($val != '') { $this->ar_select[] = $val; + if ($this->ar_caching === TRUE) { $this->ar_cache_select[] = $val; @@ -145,26 +114,11 @@ class CI_DB_active_record extends CI_DB_driver { * @param string an alias * @return object */ - function select_max($select = '', $alias='') + function select_max($select = '', $alias = '') { - if ( ! is_string($select) OR $select == '') - { - $this->display_error('db_invalid_query'); - } - - $alias = ($alias != '') ? $alias : $select; - - $sql = 'MAX('.$this->_protect_identifiers(trim($select)).') AS '.$this->_protect_identifiers(trim($alias)); - - $this->ar_select[] = $sql; - if ($this->ar_caching === TRUE) - { - $this->ar_cache_select[] = $sql; - } - - return $this; + return $this->_max_min_avg_sum($select, $alias, 'MAX'); } - + // -------------------------------------------------------------------- /** @@ -177,24 +131,9 @@ class CI_DB_active_record extends CI_DB_driver { * @param string an alias * @return object */ - function select_min($select = '', $alias='') + function select_min($select = '', $alias = '') { - if ( ! is_string($select) OR $select == '') - { - $this->display_error('db_invalid_query'); - } - - $alias = ($alias != '') ? $alias : $select; - - $sql = 'MIN('.$this->_protect_identifiers(trim($select)).') AS '.$this->_protect_identifiers(trim($alias)); - - $this->ar_select[] = $sql; - if ($this->ar_caching === TRUE) - { - $this->ar_cache_select[] = $sql; - } - - return $this; + return $this->_max_min_avg_sum($select, $alias, 'MIN'); } // -------------------------------------------------------------------- @@ -209,24 +148,9 @@ class CI_DB_active_record extends CI_DB_driver { * @param string an alias * @return object */ - function select_avg($select = '', $alias='') + function select_avg($select = '', $alias = '') { - if ( ! is_string($select) OR $select == '') - { - $this->display_error('db_invalid_query'); - } - - $alias = ($alias != '') ? $alias : $select; - - $sql = 'AVG('.$this->_protect_identifiers(trim($select)).') AS '.$this->_protect_identifiers(trim($alias)); - - $this->ar_select[] = $sql; - if ($this->ar_caching === TRUE) - { - $this->ar_cache_select[] = $sql; - } - - return $this; + return $this->_max_min_avg_sum($select, $alias, 'AVG'); } // -------------------------------------------------------------------- @@ -241,28 +165,78 @@ class CI_DB_active_record extends CI_DB_driver { * @param string an alias * @return object */ - function select_sum($select = '', $alias='') + function select_sum($select = '', $alias = '') + { + return $this->_max_min_avg_sum($select, $alias, 'SUM'); + } + + // -------------------------------------------------------------------- + + /** + * Processing Function for the four functions above: + * + * select_max() + * select_min() + * select_avg() + * select_sum() + * + * @access public + * @param string the field + * @param string an alias + * @return object + */ + function _max_min_avg_sum($select = '', $alias = '', $type = 'MAX') { if ( ! is_string($select) OR $select == '') { $this->display_error('db_invalid_query'); } - - $alias = ($alias != '') ? $alias : $select; - $sql = 'SUM('.$this->_protect_identifiers(trim($select)).') AS '.$this->_protect_identifiers(trim($alias)); + $type = strtoupper($type); + + if ( ! in_array($type, array('MAX', 'MIN', 'AVG', 'SUM'))) + { + show_error('Invalid function type: '.$type); + } + + if ($alias == '') + { + $alias = $this->_create_alias_from_table(trim($select)); + } + + $sql = $type.'('.$this->_protect_identifiers(trim($select)).') AS '.$alias; $this->ar_select[] = $sql; + if ($this->ar_caching === TRUE) { $this->ar_cache_select[] = $sql; } - + return $this; } // -------------------------------------------------------------------- + /** + * Determines the alias name based on the table + * + * @access private + * @param string + * @return string + */ + function _create_alias_from_table($item) + { + if (strpos($item, '.') !== FALSE) + { + return end(explode('.', $item)); + } + + return $item; + } + + // -------------------------------------------------------------------- + /** * DISTINCT * @@ -293,10 +267,15 @@ class CI_DB_active_record extends CI_DB_driver { { foreach ((array)$from as $val) { - $this->ar_from[] = $this->_protect_identifiers($this->_track_aliases($val)); + // Extract any aliases that might exist. We use this information + // in the _protect_identifiers to know whether to add a table prefix + $this->_track_aliases($val); + + $this->ar_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE); + if ($this->ar_caching === TRUE) { - $this->ar_cache_from[] = $this->_protect_identifiers($this->_track_aliases($val)); + $this->ar_cache_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE); } } @@ -322,7 +301,7 @@ class CI_DB_active_record extends CI_DB_driver { { $type = strtoupper(trim($type)); - if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'), TRUE)) + if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'))) { $type = ''; } @@ -332,19 +311,21 @@ class CI_DB_active_record extends CI_DB_driver { } } - // If a DB prefix is used we might need to add it to the column names - if ($this->dbprefix) - { - $this->_track_aliases($table); - - // First we remove any existing prefixes in the condition to avoid duplicates - $cond = preg_replace('|('.$this->dbprefix.')([\w\.]+)([\W\s]+)|', "$2$3", $cond); + // Extract any aliases that might exist. We use this information + // in the _protect_identifiers to know whether to add a table prefix + $this->_track_aliases($table); - // Next we add the prefixes to the condition - $cond = preg_replace('|([\w\.]+)([\W\s]+)(.+)|', $this->dbprefix . "$1$2" . $this->dbprefix . "$3", $cond); + // Strip apart the condition and protect the identifiers + if (preg_match('/([\w\.]+)([\W\s]+)(.+)/', $cond, $match)) + { + $match[1] = $this->_protect_identifiers($match[1]); + $match[3] = $this->_protect_identifiers($match[3]); + + $cond = $match[1].$match[2].$match[3]; } - - $join = $type.'JOIN '.$this->_protect_identifiers($this->dbprefix.$table, TRUE).' ON '.$cond; + + // Assemble the JOIN statement + $join = $type.'JOIN '.$this->_protect_identifiers($table, TRUE, NULL, FALSE).' ON '.$cond; $this->ar_join[] = $join; if ($this->ar_caching === TRUE) @@ -416,12 +397,18 @@ class CI_DB_active_record extends CI_DB_driver { * @param string * @return object */ - function _where($key, $value = NULL, $type = 'AND ', $escape = TRUE) + function _where($key, $value = NULL, $type = 'AND ', $escape = NULL) { if ( ! is_array($key)) { $key = array($key => $value); } + + // If the escape value was not set will will base it on the global setting + if ( ! is_bool($escape)) + { + $escape = $this->_protect_identifiers; + } foreach ($key as $k => $v) { @@ -437,15 +424,7 @@ class CI_DB_active_record extends CI_DB_driver { { if ($escape === TRUE) { - // exception for "field<=" keys - if ($this->_has_operator($k)) - { - $k = preg_replace("/([A-Za-z_0-9]+)/", $this->_escape_column($this->_protect_identifiers('$1')), $k); - } - else - { - $k = $this->_protect_identifiers($k); - } + $k = $this->_protect_identifiers($k, FALSE, $escape); $v = ' '.$this->escape($v); } @@ -457,10 +436,7 @@ class CI_DB_active_record extends CI_DB_driver { } else { - if ($escape === TRUE) - { - $k = $this->_protect_identifiers($k, TRUE); - } + $k = $this->_protect_identifiers($k, FALSE, $escape); } $this->ar_where[] = $prefix.$k.$v; @@ -489,7 +465,7 @@ class CI_DB_active_record extends CI_DB_driver { * @return object */ function where_in($key = NULL, $values = NULL) - { + { return $this->_where_in($key, $values); } @@ -557,18 +533,23 @@ class CI_DB_active_record extends CI_DB_driver { * @access public * @param string The field to search * @param array The values searched on - * @param boolean If the statement whould be IN or NOT IN + * @param boolean If the statement would be IN or NOT IN * @param string * @return object */ function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ') { - if ($key === NULL OR ! is_array($values)) + if ($key === NULL OR $values === NULL) { return; } - - $not = ($not) ? ' NOT ' : ''; + + if ( ! is_array($values)) + { + $values = array($values); + } + + $not = ($not) ? ' NOT' : ''; foreach ($values as $value) { @@ -623,7 +604,7 @@ class CI_DB_active_record extends CI_DB_driver { */ function not_like($field, $match = '', $side = 'both') { - return $this->_like($field, $match, 'AND ', $side, ' NOT'); + return $this->_like($field, $match, 'AND ', $side, 'NOT'); } // -------------------------------------------------------------------- @@ -659,7 +640,7 @@ class CI_DB_active_record extends CI_DB_driver { */ function or_not_like($field, $match = '', $side = 'both') { - return $this->_like($field, $match, 'OR ', $side, 'NOT '); + return $this->_like($field, $match, 'OR ', $side, 'NOT'); } // -------------------------------------------------------------------- @@ -695,13 +676,12 @@ class CI_DB_active_record extends CI_DB_driver { } foreach ($field as $k => $v) - { - + { $k = $this->_protect_identifiers($k); $prefix = (count($this->ar_like) == 0) ? '' : $type; - $v = $this->escape($v); + $v = $this->escape_str($v); if ($side == 'before') { @@ -749,6 +729,7 @@ class CI_DB_active_record extends CI_DB_driver { if ($val != '') { $this->ar_groupby[] = $this->_protect_identifiers($val); + if ($this->ar_caching === TRUE) { $this->ar_cache_groupby[] = $this->_protect_identifiers($val); @@ -851,7 +832,7 @@ class CI_DB_active_record extends CI_DB_driver { if ($v != '') { - $v = ' '.$this->escape($v); + $v = ' '.$this->escape_str($v); } $this->ar_having[] = $prefix.$k.$v; @@ -886,7 +867,7 @@ class CI_DB_active_record extends CI_DB_driver { $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' '.$direction : ' ASC'; } - $orderby_statement = $this->_protect_identifiers($orderby, TRUE).$direction; + $orderby_statement = $this->_protect_identifiers($orderby).$direction; $this->ar_orderby[] = $orderby_statement; if ($this->ar_caching === TRUE) @@ -984,6 +965,7 @@ class CI_DB_active_record extends CI_DB_driver { if ($escape === FALSE) { $this->ar_set[$this->_protect_identifiers($k)] = $v; + if ($this->ar_caching === TRUE) { $this->ar_cache_offset[$this->_protect_identifiers($k)] = $v; @@ -992,6 +974,7 @@ class CI_DB_active_record extends CI_DB_driver { else { $this->ar_set[$this->_protect_identifiers($k)] = $this->escape($v); + if ($this->ar_caching === TRUE) { $this->ar_cache_offset[$this->_protect_identifiers($k)] = $this->escape($v); @@ -1085,7 +1068,6 @@ class CI_DB_active_record extends CI_DB_driver { { if ($table != '') { - $this->_track_aliases($table); $this->from($table); } @@ -1160,7 +1142,7 @@ class CI_DB_active_record extends CI_DB_driver { $table = $this->ar_from[0]; } - $sql = $this->_insert($this->_protect_identifiers($this->dbprefix.$table), array_keys($this->ar_set), array_values($this->ar_set)); + $sql = $this->_insert($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->ar_set), array_values($this->ar_set)); $this->_reset_write(); return $this->query($sql); @@ -1219,7 +1201,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->limit($limit); } - $sql = $this->_update($this->_protect_identifiers($this->dbprefix.$table), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit); + $sql = $this->_update($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit); $this->_reset_write(); return $this->query($sql); @@ -1253,10 +1235,9 @@ class CI_DB_active_record extends CI_DB_driver { } else { - $table = $this->_protect_identifiers($this->dbprefix.$table); + $table = $this->_protect_identifiers($table, TRUE, NULL, FALSE); } - $sql = $this->_delete($table); $this->_reset_write(); @@ -1294,10 +1275,9 @@ class CI_DB_active_record extends CI_DB_driver { } else { - $table = $this->_protect_identifiers($this->dbprefix.$table); + $table = $this->_protect_identifiers($table, TRUE, NULL, FALSE); } - $sql = $this->_truncate($table); $this->_reset_write(); @@ -1346,7 +1326,7 @@ class CI_DB_active_record extends CI_DB_driver { } else { - $table = $this->_protect_identifiers($this->dbprefix.$table); + $table = $this->_protect_identifiers($table, TRUE, NULL, FALSE); } if ($where != '') @@ -1382,13 +1362,22 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- /** - * Use Table - DEPRECATED + * DB Prefix * - * @deprecated use $this->db->from instead + * Prepends a database prefix if one exists in configuration + * + * @access public + * @param string the table + * @return string */ - function use_table($table) + function dbprefix($table = '') { - return $this->from($table); + if ($table == '') + { + $this->display_error('db_table_name_required'); + } + + return $this->dbprefix.$table; } // -------------------------------------------------------------------- @@ -1404,41 +1393,37 @@ class CI_DB_active_record extends CI_DB_driver { */ function _track_aliases($table) { - // if a table alias is used we can recognize it by a space - if (strpos($table, " ") !== FALSE) + if (is_array($table)) { - // if the alias is written with the AS keyowrd, get it out - $table = preg_replace('/ AS /i', ' ', $table); - - $this->ar_aliased_tables[] = trim(strrchr($table, " ")); + foreach ($table as $t) + { + $this->_track_aliases($t); + } + return; } - - return $this->dbprefix.$table; - } - - // -------------------------------------------------------------------- - - /** - * Filter Table Aliases - * - * Intelligently removes database prefixes from aliased tables - * - * @access private - * @param array An array of compiled SQL - * @return array Cleaned up statement with aliases accounted for - */ - function _filter_table_aliases($statements) - { - - foreach ($statements as $k => $v) + + // Does the string contain a comma? If so, we need to separate + // the string into discreet statements + if (strpos($table, ',') !== FALSE) + { + return $this->_track_aliases(explode(',', $table)); + } + + // if a table alias is used we can recognize it by a space + if (strpos($table, " ") !== FALSE) { - foreach ($this->ar_aliased_tables as $table) + // if the alias is written with the AS keyword, remove it + $table = preg_replace('/ AS /i', ' ', $table); + + // Grab the alias + $table = trim(strrchr($table, " ")); + + // Store the alias, if it doesn't already exist + if ( ! in_array($table, $this->ar_aliased_tables)) { - $statements[$k] = preg_replace('/(\w+\.\w+)/', $this->_protect_identifiers('$0'), $statements[$k]); // makes `table.field` - $statements[$k] = str_replace($this->dbprefix.$table.'.', $table.'.', $statements[$k]); + $this->ar_aliased_tables[] = $table; } } - return $statements; } // -------------------------------------------------------------------- @@ -1456,69 +1441,99 @@ class CI_DB_active_record extends CI_DB_driver { { $this->_merge_cache(); - $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; - - $sql .= (count($this->ar_select) == 0) ? '*' : implode(', ', $this->_filter_table_aliases($this->ar_select)); + // ---------------------------------------------------------------- + + // Write the "select" portion of the query if ($select_override !== FALSE) { $sql = $select_override; } + else + { + $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; + + if (count($this->ar_select) == 0) + { + $sql .= '*'; + } + else + { + // Cycle through the "select" portion of the query and prep each column name. + // The reason we protect identifiers here rather then in the select() function + // is because until the user calls the from() function we don't know if there are aliases + foreach ($this->ar_select as $key => $val) + { + $this->ar_select[$key] = $this->_protect_identifiers($val); + } + + $sql .= implode(', ', $this->ar_select); + } + } + + // ---------------------------------------------------------------- + + // Write the "FROM" portion of the query if (count($this->ar_from) > 0) { $sql .= "\nFROM "; + $sql .= $this->_from_tables($this->ar_from); } + // ---------------------------------------------------------------- + + // Write the "JOIN" portion of the query + if (count($this->ar_join) > 0) { $sql .= "\n"; - // special consideration for table aliases - if (count($this->ar_aliased_tables) > 0 && $this->dbprefix) - { - $sql .= implode("\n", $this->_filter_table_aliases($this->ar_join)); - } - else - { - $sql .= implode("\n", $this->ar_join); - } - + $sql .= implode("\n", $this->ar_join); } + // ---------------------------------------------------------------- + + // Write the "WHERE" portion of the query + if (count($this->ar_where) > 0 OR count($this->ar_like) > 0) { - $sql .= "\nWHERE "; + $sql .= "\n"; + + $sql .= "WHERE "; } $sql .= implode("\n", $this->ar_where); + + // ---------------------------------------------------------------- + // Write the "LIKE" portion of the query + if (count($this->ar_like) > 0) { if (count($this->ar_where) > 0) { - $sql .= " AND "; + $sql .= "\nAND "; } $sql .= implode("\n", $this->ar_like); } + + // ---------------------------------------------------------------- + // Write the "GROUP BY" portion of the query + if (count($this->ar_groupby) > 0) { - $sql .= "\nGROUP BY "; - // special consideration for table aliases - if (count($this->ar_aliased_tables) > 0 && $this->dbprefix) - { - $sql .= implode(", ", $this->_filter_table_aliases($this->ar_groupby)); - } - else - { - $sql .= implode(', ', $this->ar_groupby); - } + $sql .= implode(', ', $this->ar_groupby); } + + // ---------------------------------------------------------------- + + // Write the "HAVING" portion of the query if (count($this->ar_having) > 0) { @@ -1526,6 +1541,10 @@ class CI_DB_active_record extends CI_DB_driver { $sql .= implode("\n", $this->ar_having); } + // ---------------------------------------------------------------- + + // Write the "ORDER BY" portion of the query + if (count($this->ar_orderby) > 0) { $sql .= "\nORDER BY "; @@ -1536,6 +1555,10 @@ class CI_DB_active_record extends CI_DB_driver { $sql .= ($this->ar_order == 'desc') ? ' DESC' : ' ASC'; } } + + // ---------------------------------------------------------------- + + // Write the "LIMIT" portion of the query if (is_numeric($this->ar_limit)) { @@ -1569,7 +1592,6 @@ class CI_DB_active_record extends CI_DB_driver { { // There are some built in keys we need to ignore for this conversion if ( ! is_object($val) && ! is_array($val) && $key != '_parent_name' && $key != '_ci_scaffolding' && $key != '_ci_scaff_table') - { $array[$key] = $val; } @@ -1608,7 +1630,6 @@ class CI_DB_active_record extends CI_DB_driver { $this->ar_caching = FALSE; } - // -------------------------------------------------------------------- /** @@ -1622,16 +1643,16 @@ class CI_DB_active_record extends CI_DB_driver { function flush_cache() { $ar_reset_items = array( - 'ar_cache_select' => array(), - 'ar_cache_from' => array(), - 'ar_cache_join' => array(), - 'ar_cache_where' => array(), - 'ar_cache_like' => array(), - 'ar_cache_groupby' => array(), - 'ar_cache_having' =>array(), - 'ar_cache_orderby' => array(), - 'ar_cache_set' => array() - ); + 'ar_cache_select' => array(), + 'ar_cache_from' => array(), + 'ar_cache_join' => array(), + 'ar_cache_where' => array(), + 'ar_cache_like' => array(), + 'ar_cache_groupby' => array(), + 'ar_cache_having' =>array(), + 'ar_cache_orderby' => array(), + 'ar_cache_set' => array() + ); $this->_reset_run($ar_reset_items); } @@ -1649,6 +1670,11 @@ class CI_DB_active_record extends CI_DB_driver { */ function _merge_cache() { + if ($this->ar_caching == FALSE) + { + return; + } + $ar_items = array('select', 'from', 'join', 'where', 'like', 'groupby', 'having', 'orderby', 'set'); foreach ($ar_items as $ar_item) @@ -1657,6 +1683,13 @@ class CI_DB_active_record extends CI_DB_driver { $ar_item = 'ar_'.$ar_item; $this->$ar_item = array_unique(array_merge($this->$ar_item, $this->$ar_cache_item)); } + + // If we are "protecting identifiers" we need to examine the "from" + // portion of the query to determine if there are any aliases + if ($this->_protect_identifiers === TRUE) + { + $this->_track_aliases($this->ar_from); + } } // -------------------------------------------------------------------- @@ -1678,7 +1711,7 @@ class CI_DB_active_record extends CI_DB_driver { } } } - + // -------------------------------------------------------------------- /** @@ -1690,21 +1723,21 @@ class CI_DB_active_record extends CI_DB_driver { function _reset_select() { $ar_reset_items = array( - 'ar_select' => array(), - 'ar_from' => array(), - 'ar_join' => array(), - 'ar_where' => array(), - 'ar_like' => array(), - 'ar_groupby' => array(), - 'ar_having' => array(), - 'ar_orderby' => array(), - 'ar_wherein' => array(), - 'ar_aliased_tables' => array(), - 'ar_distinct' => FALSE, - 'ar_limit' => FALSE, - 'ar_offset' => FALSE, - 'ar_order' => FALSE, - ); + 'ar_select' => array(), + 'ar_from' => array(), + 'ar_join' => array(), + 'ar_where' => array(), + 'ar_like' => array(), + 'ar_groupby' => array(), + 'ar_having' => array(), + 'ar_orderby' => array(), + 'ar_wherein' => array(), + 'ar_aliased_tables' => array(), + 'ar_distinct' => FALSE, + 'ar_limit' => FALSE, + 'ar_offset' => FALSE, + 'ar_order' => FALSE, + ); $this->_reset_run($ar_reset_items); } @@ -1722,14 +1755,14 @@ class CI_DB_active_record extends CI_DB_driver { function _reset_write() { $ar_reset_items = array( - 'ar_set' => array(), - 'ar_from' => array(), - 'ar_where' => array(), - 'ar_like' => array(), - 'ar_orderby' => array(), - 'ar_limit' => FALSE, - 'ar_order' => FALSE - ); + 'ar_set' => array(), + 'ar_from' => array(), + 'ar_where' => array(), + 'ar_like' => array(), + 'ar_orderby' => array(), + 'ar_limit' => FALSE, + 'ar_order' => FALSE + ); $this->_reset_run($ar_reset_items); } diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 572595f42..9508ded8c 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -61,6 +61,9 @@ class CI_DB_driver { var $cache_autodel = FALSE; var $CACHE; // The cache class object + // Private variables + var $_protect_identifiers = TRUE; + var $_reserved_identifiers = array('*'); // Identifiers that should NOT be escaped // These are use with Oracle var $stmt_id; @@ -97,19 +100,21 @@ class CI_DB_driver { * @param mixed * @return void */ - function initialize($create_db = FALSE) + function initialize() { - // If an existing DB connection resource is supplied + // If an existing connection resource is available // there is no need to connect and select the database if (is_resource($this->conn_id) OR is_object($this->conn_id)) { return TRUE; } + + // ---------------------------------------------------------------- - // Connect to the database + // Connect to the database and set the connection ID $this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect(); - // No connection? Throw an error + // No connection resource? Throw an error if ( ! $this->conn_id) { log_message('error', 'Unable to connect to the database'); @@ -121,70 +126,30 @@ class CI_DB_driver { return FALSE; } - // Select the database + // ---------------------------------------------------------------- + + // Select the DB... assuming a database name is specified in the config file if ($this->database != '') { if ( ! $this->db_select()) { - // Should we attempt to create the database? - if ($create_db == TRUE) - { - // Load the DB utility class - $CI =& get_instance(); - $CI->load->dbutil(); - - // Create the DB - if ( ! $CI->dbutil->create_database($this->database)) - { - log_message('error', 'Unable to create database: '.$this->database); - - if ($this->db_debug) - { - $this->display_error('db_unable_to_create', $this->database); - } - return FALSE; - } - else - { - // In the event the DB was created we need to select it - if ($this->db_select()) - { - if ( ! $this->db_set_charset($this->char_set, $this->dbcollat)) - { - log_message('error', 'Unable to set database connection charset: '.$this->char_set); - - if ($this->db_debug) - { - $this->display_error('db_unable_to_set_charset', $this->char_set); - } - - return FALSE; - } - - return TRUE; - } - } - } - log_message('error', 'Unable to select database: '.$this->database); if ($this->db_debug) { $this->display_error('db_unable_to_select', $this->database); } - return FALSE; + return FALSE; } - - if ( ! $this->db_set_charset($this->char_set, $this->dbcollat)) + else { - log_message('error', 'Unable to set database connection charset: '.$this->char_set); - - if ($this->db_debug) + // We've selected the DB. Now we set the character set + if ( ! $this->db_set_charset($this->char_set, $this->dbcollat)) { - $this->display_error('db_unable_to_set_charset', $this->char_set); + return FALSE; } - - return FALSE; + + return TRUE; } } @@ -193,6 +158,33 @@ class CI_DB_driver { // -------------------------------------------------------------------- + /** + * Set client character set + * + * @access public + * @param string + * @param string + * @return resource + */ + function db_set_charset($charset, $collation) + { + if ( ! $this->_db_set_charset($this->char_set, $this->dbcollat)) + { + log_message('error', 'Unable to set database connection charset: '.$this->char_set); + + if ($this->db_debug) + { + $this->display_error('db_unable_to_set_charset', $this->char_set); + } + + return FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + /** * The name of the platform in use (mysql, mssql, etc...) * @@ -667,23 +659,6 @@ class CI_DB_driver { { return end($this->queries); } - - // -------------------------------------------------------------------- - - /** - * Protect Identifiers - * - * This function adds backticks if appropriate based on db type - * - * @access private - * @param mixed the item to escape - * @param boolean only affect the first word - * @return mixed the item with backticks - */ - function protect_identifiers($item, $first_word_only = FALSE) - { - return $this->_protect_identifiers($item, $first_word_only); - } // -------------------------------------------------------------------- @@ -791,8 +766,8 @@ class CI_DB_driver { * @return boolean */ function table_exists($table_name) - { - return ( ! in_array($this->prep_tablename($table_name), $this->list_tables())) ? FALSE : TRUE; + { + return ( ! in_array($this->_protect_identifiers($table_name, TRUE, NULL, FALSE), $this->list_tables())) ? FALSE : TRUE; } // -------------------------------------------------------------------- @@ -821,7 +796,7 @@ class CI_DB_driver { return FALSE; } - if (FALSE === ($sql = $this->_list_columns($this->prep_tablename($table)))) + if (FALSE === ($sql = $this->_list_columns($this->_protect_identifiers($table, TRUE, NULL, FALSE)))) { if ($this->db_debug) { @@ -865,16 +840,6 @@ class CI_DB_driver { // -------------------------------------------------------------------- - /** - * DEPRECATED - use list_fields() - */ - function field_names($table = '') - { - return $this->list_fields($table); - } - - // -------------------------------------------------------------------- - /** * Returns an object with field data * @@ -893,7 +858,8 @@ class CI_DB_driver { return FALSE; } - $query = $this->query($this->_field_data($this->prep_tablename($table))); + $query = $this->query($this->_field_data($this->_protect_identifiers($table, TRUE, NULL, FALSE))); + return $query->field_data(); } @@ -914,11 +880,11 @@ class CI_DB_driver { foreach($data as $key => $val) { - $fields[] = $this->_escape_column($key); + $fields[] = $this->_escape_identifiers($key); $values[] = $this->escape($val); } - return $this->_insert($this->prep_tablename($table), $fields, $values); + return $this->_insert($this->_protect_identifiers($table, TRUE, NULL, FALSE), $fields, $values); } // -------------------------------------------------------------------- @@ -942,7 +908,7 @@ class CI_DB_driver { $fields = array(); foreach($data as $key => $val) { - $fields[$this->_escape_column($key)] = $this->escape($val); + $fields[$this->_protect_identifiers($key)] = $this->escape($val); } if ( ! is_array($where)) @@ -970,7 +936,7 @@ class CI_DB_driver { } } - return $this->_update($this->prep_tablename($table), $fields, $dest); + return $this->_update($this->_protect_identifiers($table, TRUE, NULL, FALSE), $fields, $dest); } // -------------------------------------------------------------------- @@ -992,29 +958,6 @@ class CI_DB_driver { return TRUE; } - - // -------------------------------------------------------------------- - - /** - * Prep the table name - simply adds the table prefix if needed - * - * @access public - * @param string the table name - * @return string - */ - function prep_tablename($table = '') - { - // Do we need to add the table prefix? - if ($this->dbprefix != '') - { - if (substr($table, 0, strlen($this->dbprefix)) != $this->dbprefix) - { - $table = $this->dbprefix.$table; - } - } - - return $table; - } // -------------------------------------------------------------------- @@ -1201,7 +1144,174 @@ class CI_DB_driver { echo $error->show_error($heading, $message, 'error_db'); exit; } + + // -------------------------------------------------------------------- + + /** + * Protect Identifiers + * + * This function adds backticks if appropriate based on db type + * + * @access private + * @param mixed the item to escape + * @return mixed the item with backticks + */ + function protect_identifiers($item, $prefix_single = FALSE) + { + return $this->_protect_identifiers($item, $prefix_single); + } + + // -------------------------------------------------------------------- + + /** + * Protect Identifiers + * + * This function is used extensively by the Active Record class, and by + * a couple functions in this class. + * It takes a column or table name (optionally with an alias) and inserts + * the table prefix onto it. Some logic is necessary in order to deal with + * column names that include the path. Consider a query like this: + * + * SELECT * FROM hostname.database.table.column AS c FROM hostname.database.table + * + * Or a query with aliasing: + * + * SELECT m.member_id, m.member_name FROM members AS m + * + * Since the column name can include up to four segments (host, DB, table, column) + * or also have an alias prefix, we need to do a bit of work to figure this out and + * insert the table prefix (if it exists) in the proper position, and escape only + * the correct identifiers. + * + * @access private + * @param string + * @param bool + * @param mixed + * @param bool + * @return string + */ + function _protect_identifiers($item, $prefix_single = FALSE, $protect_identifiers = NULL, $field_exists = TRUE) + { + if ( ! is_bool($protect_identifiers)) + { + $protect_identifiers = $this->_protect_identifiers; + } + + // Convert tabs or multiple spaces into single spaces + $item = preg_replace('/[\t| ]+/', ' ', $item); + // If the item has an alias declaration we remove it and set it aside. + // Basically we remove everything to the right of the first space + $alias = ''; + if (strpos($item, ' ') !== FALSE) + { + $alias = strstr($item, " "); + $item = substr($item, 0, - strlen($alias)); + } + + // Break the string apart if it contains periods, then insert the table prefix + // in the correct location, assuming the period doesn't indicate that we're dealing + // with an alias. While we're at it, we will escape the components + if (strpos($item, '.') !== FALSE) + { + $parts = explode('.', $item); + + // Does the first segment of the exploded item match + // one of the aliases previously identified? If so, + // we have nothing more to do other then escape the item + if (in_array($parts[0], $this->ar_aliased_tables)) + { + if ($protect_identifiers === TRUE) + { + foreach ($parts as $key => $val) + { + if ( ! in_array($val, $this->_reserved_identifiers)) + { + $parts[$key] = $this->_escape_identifiers($val); + } + } + + $item = implode('.', $parts); + } + return $item.$alias; + } + + // Is there a table prefix defined in the config file? If not, no need to do anything + if ($this->dbprefix != '') + { + // We now add the table prefix based on some logic. + // Do we have 4 segments (hostname.database.table.column)? + // If so, we add the table prefix to the column name in the 3rd segment. + if (isset($parts[3])) + { + $i = 2; + } + // Do we have 3 segments (database.table.column)? + // If so, we add the table prefix to the column name in 2nd position + elseif (isset($parts[2])) + { + $i = 1; + } + // Do we have 2 segments (table.column)? + // If so, we add the table prefix to the column name in 1st segment + else + { + $i = 0; + } + + // This flag is set when the supplied $item does not contain a field name. + // This can happen when this function is being called from a JOIN. + if ($field_exists == FALSE) + { + $i++; + } + + // We only add the table prefix if it does not already exist + if (substr($parts[$i], 0, strlen($this->dbprefix)) != $this->dbprefix) + { + $parts[$i] = $this->dbprefix.$parts[$i]; + } + + // Put the parts back together + $item = implode('.', $parts); + } + + if ($protect_identifiers === TRUE) + { + $item = $this->_escape_identifiers($item); + } + + return $item.$alias; + } + + // This is basically a bug fix for queries that use MAX, MIN, etc. + // If a parenthesis is found we know that we do not need to + // escape the data or add a prefix. There's probably a more graceful + // way to deal with this, but I'm not thinking of it -- Rick + if (strpos($item, '(') !== FALSE) + { + return $item.$alias; + } + + // Is there a table prefix? If not, no need to insert it + if ($this->dbprefix != '') + { + // Do we prefix an item with no segments? + if ($prefix_single == TRUE AND substr($item, 0, strlen($this->dbprefix)) != $this->dbprefix) + { + $item = $this->dbprefix.$item; + } + } + + if ($protect_identifiers === TRUE AND ! in_array($item, $this->_reserved_identifiers)) + { + $item = $this->_escape_identifiers($item); + } + + return $item.$alias; + } + + } diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index 64f95d635..20f0a3087 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -253,7 +253,7 @@ class CI_DB_forge { { if ($table == '') { - show_error('A table name is required for that operation.'); + show_error('A table name is required for that operation.'); } // add field info into field array, but we can only do one at a time @@ -286,12 +286,12 @@ class CI_DB_forge { if ($table == '') { - show_error('A table name is required for that operation.'); + show_error('A table name is required for that operation.'); } if ($column_name == '') { - show_error('A column name is required for that operation.'); + show_error('A column name is required for that operation.'); } $sql = $this->_alter_table('DROP', $this->db->dbprefix.$table, $column_name); @@ -312,10 +312,9 @@ class CI_DB_forge { */ function modify_column($table = '', $field = array()) { - if ($table == '') { - show_error('A table name is required for that operation.'); + show_error('A table name is required for that operation.'); } // add field info into field array, but we can only do one at a time diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 0ec59d568..8f55f6718 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -329,7 +329,6 @@ class CI_DB_result { function num_rows() { return $this->num_rows; } function num_fields() { return 0; } function list_fields() { return array(); } - function field_names() { return array(); } // Deprecated function field_data() { return array(); } function free_result() { return TRUE; } function _data_seek() { return TRUE; } diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 02b975ad2..fbc0701c0 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -30,6 +30,10 @@ */ class CI_DB_mssql_driver extends CI_DB { + var $dbdriver = 'mssql'; + + // The character used for escaping + var $_escape_char = ''; /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is @@ -37,7 +41,6 @@ class CI_DB_mssql_driver extends CI_DB { */ var $_count_string = "SELECT COUNT(*) AS "; var $_random_keyword = ' ASC'; // not currently supported - var $dbdriver = 'mssql'; /** * Non-persistent database connection @@ -301,7 +304,7 @@ class CI_DB_mssql_driver extends CI_DB { if ($table == '') return '0'; - $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($this->dbprefix.$table)); + $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); if ($query->num_rows() == 0) return '0'; @@ -348,7 +351,7 @@ class CI_DB_mssql_driver extends CI_DB { */ function _list_columns($table = '') { - return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$this->_escape_table($table)."'"; + return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$table."'"; } // -------------------------------------------------------------------- @@ -364,7 +367,7 @@ class CI_DB_mssql_driver extends CI_DB { */ function _field_data($table) { - return "SELECT TOP 1 * FROM ".$this->_escape_table($table); + return "SELECT TOP 1 * FROM ".$table; } // -------------------------------------------------------------------- @@ -398,99 +401,34 @@ class CI_DB_mssql_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Escape Column Name - * - * This function adds backticks around supplied column name - * - * @access private - * @param string the column name - * @return string - */ - function _escape_column($column) - { - // Not necessary with MS SQL so we simply return the value - return $column; - } - - // -------------------------------------------------------------------- - - /** - * Escape Table Name + * Escape the SQL Identifiers * - * This function adds backticks if the table name has a period - * in it. Some DBs will get cranky unless periods are escaped + * This function escapes column and table names * * @access private - * @param string the table name + * @param string * @return string */ - function _escape_table($table) - { - // Not necessary with MS SQL so we simply return the value - return $table; - } - - // -------------------------------------------------------------------- - - /** - * Protect Identifiers - * - * This function adds backticks if appropriate based on db type - * - * @access private - * @param mixed the item(s) - * @param boolean should spaces be backticked - * @param boolean only affect the first word - * @return mixed the item with backticks - */ - function _protect_identifiers($item, $first_word_only = FALSE) + function _escape_identifiers($item) { - if (is_array($item)) + if ($this->_escape_char == '') { - $escaped_array = array(); - - foreach($item as $k=>$v) - { - $escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v, $first_word_only); - } - - return $escaped_array; - } - - // This function may get "item1 item2" as a string, and so - // we may need ""item1" "item2"" and not ""item1 item2"" - if (ctype_alnum($item) === FALSE) + return $item; + } + + if (strpos($item, '.') !== FALSE) { - if (strpos($item, '.') !== FALSE) - { - $aliased_tables = implode(".",$this->ar_aliased_tables).'.'; - $table_name = substr($item, 0, strpos($item, '.')+1); - $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item; - } - - // This function may get "field >= 1", and need it to return ""field" >= 1" - $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; - - $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1$2$3', $item); + $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; } else { - return $item; + $str = $this->_escape_char.$item.$this->_escape_char; } - - $exceptions = array('AS', '/', '-', '%', '+', '*', 'OR', 'IS'); - foreach ($exceptions as $exception) - { - - if (stristr($item, " \"{$exception}\" ") !== FALSE) - { - $item = preg_replace('/ "('.preg_quote($exception).')" /i', ' $1 ', $item); - } - } - return $item; + // remove duplicates if the user already included the escape + return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); } - + // -------------------------------------------------------------------- /** @@ -528,7 +466,7 @@ class CI_DB_mssql_driver extends CI_DB { */ function _insert($table, $keys, $values) { - return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -557,8 +495,10 @@ class CI_DB_mssql_driver extends CI_DB { $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - $sql = "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr); + $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); + $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; + $sql .= $orderby.$limit; return $sql; @@ -580,7 +520,7 @@ class CI_DB_mssql_driver extends CI_DB { */ function _truncate($table) { - return "TRUNCATE ".$this->_escape_table($table); + return "TRUNCATE ".$table; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php index c842ac1e2..8665dc055 100644 --- a/system/database/drivers/mssql/mssql_forge.php +++ b/system/database/drivers/mssql/mssql_forge.php @@ -60,7 +60,7 @@ class CI_DB_mssql_forge extends CI_DB_forge { */ function _drop_table($table) { - return "DROP TABLE ".$this->db->_escape_table($table); + return "DROP TABLE ".$this->db->_escape_identifiers($table); } // -------------------------------------------------------------------- @@ -85,7 +85,7 @@ class CI_DB_mssql_forge extends CI_DB_forge { $sql .= 'IF NOT EXISTS '; } - $sql .= $this->db->_escape_table($table)." ("; + $sql .= $this->db->_escape_identifiers($table)." ("; $current_field_count = 0; foreach ($fields as $field=>$attributes) diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index b4c22bec9..33fdda9d4 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -70,12 +70,6 @@ class CI_DB_mssql_result extends CI_DB_result { return $field_names; } - - // Deprecated - function field_names() - { - return $this->list_fields(); - } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 006e6ef1f..0c51a5ea7 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -44,6 +44,9 @@ class CI_DB_oci8_driver extends CI_DB { var $dbdriver = 'oci8'; + + // The character used for excaping + var $_escape_char = '"'; /** * The syntax to count rows is slightly different across different @@ -419,7 +422,7 @@ class CI_DB_oci8_driver extends CI_DB { if ($table == '') return '0'; - $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($this->dbprefix.$table)); + $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); if ($query == FALSE) { @@ -482,7 +485,7 @@ class CI_DB_oci8_driver extends CI_DB { */ function _field_data($table) { - return "SELECT * FROM ".$this->_escape_table($table)." where rownum = 1"; + return "SELECT * FROM ".$table." where rownum = 1"; } // -------------------------------------------------------------------- @@ -516,102 +519,34 @@ class CI_DB_oci8_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Escape Column Name + * Escape the SQL Identifiers * - * This function adds backticks around supplied column name + * This function escapes column and table names * * @access private - * @param string the column name + * @param string * @return string */ - function _escape_column($column) + function _escape_identifiers($item) { - // Probably not necessary with Oracle so we simply return the value - return $column; - } - - // -------------------------------------------------------------------- - - /** - * Escape Table Name - * - * This function adds backticks if the table name has a period - * in it. Some DBs will get cranky unless periods are escaped - * - * @access private - * @param string the table name - * @return string - */ - function _escape_table($table) - { - if (strpos($table, '.') !== FALSE) + if ($this->_escape_char == '') { - $table = '"' . str_replace('.', '"."', $table) . '"'; + return $item; } - - return $table; - } - - // -------------------------------------------------------------------- - - /** - * Protect Identifiers - * - * This function adds backticks if appropriate based on db type - * - * @access private - * @param mixed the item to escape - * @param boolean only affect the first word - * @return mixed the item with backticks - */ - function _protect_identifiers($item, $first_word_only = FALSE) - { - if (is_array($item)) - { - $escaped_array = array(); - - foreach($item as $k=>$v) - { - $escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v, $first_word_only); - } - - return $escaped_array; - } - - // This function may get "item1 item2" as a string, and so - // we may need ""item1" "item2"" and not ""item1 item2"" - if (ctype_alnum($item) === FALSE) + + if (strpos($item, '.') !== FALSE) { - if (strpos($item, '.') !== FALSE) - { - $aliased_tables = implode(".",$this->ar_aliased_tables).'.'; - $table_name = substr($item, 0, strpos($item, '.')+1); - $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item; - } - - // This function may get "field >= 1", and need it to return ""field" >= 1" - $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; - - $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1"$2"$3', $item); + $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; } else { - return "\"{$item}\""; + $str = $this->_escape_char.$item.$this->_escape_char; } - - $exceptions = array('AS', '/', '-', '%', '+', '*', 'OR', 'IS'); - - foreach ($exceptions as $exception) - { - if (stristr($item, " \"{$exception}\" ") !== FALSE) - { - $item = preg_replace('/ "('.preg_quote($exception).')" /i', ' $1 ', $item); - } - } - return $item; + // remove duplicates if the user already included the escape + return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); } - + // -------------------------------------------------------------------- /** @@ -649,7 +584,7 @@ class CI_DB_oci8_driver extends CI_DB { */ function _insert($table, $keys, $values) { - return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -678,8 +613,10 @@ class CI_DB_oci8_driver extends CI_DB { $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - $sql = "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr); + $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); + $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; + $sql .= $orderby.$limit; return $sql; @@ -700,7 +637,7 @@ class CI_DB_oci8_driver extends CI_DB { */ function _truncate($table) { - return "TRUNCATE TABLE ".$this->_escape_table($table); + return "TRUNCATE TABLE ".$table; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index df19dba78..0ba483f8b 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -33,6 +33,9 @@ class CI_DB_sqlite_driver extends CI_DB { var $dbdriver = 'sqlite'; + + // The character used to escape with - not needed for SQLite + var $_escape_char = ''; /** * The syntax to count rows is slightly different across different @@ -300,7 +303,7 @@ class CI_DB_sqlite_driver extends CI_DB { if ($table == '') return '0'; - $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($this->dbprefix.$table)); + $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); if ($query->num_rows() == 0) return '0'; @@ -361,7 +364,7 @@ class CI_DB_sqlite_driver extends CI_DB { */ function _field_data($table) { - return "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; + return "SELECT * FROM ".$table." LIMIT 1"; } // -------------------------------------------------------------------- @@ -393,97 +396,32 @@ class CI_DB_sqlite_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Escape Column Name - * - * This function adds backticks around supplied column name - * - * @access private - * @param string the column name - * @return string - */ - function _escape_column($column) - { - // Not necessary with SQLite so we simply return the value - return $column; - } - - // -------------------------------------------------------------------- - - /** - * Escape Table Name + * Escape the SQL Identifiers * - * This function adds backticks if the table name has a period - * in it. Some DBs will get cranky unless periods are escaped + * This function escapes column and table names * * @access private - * @param string the table name + * @param string * @return string */ - function _escape_table($table) + function _escape_identifiers($item) { - // other database drivers use this to add backticks, hence this - // function is simply going to return the tablename for sqlite - return $table; - } - - // -------------------------------------------------------------------- - - /** - * Protect Identifiers - * - * This function adds backticks if appropriate based on db type - * - * @access private - * @param mixed the item to escape - * @param boolean only affect the first word - * @return mixed the item with backticks - */ - function _protect_identifiers($item, $first_word_only = FALSE) - { - if (is_array($item)) + if ($this->_escape_char == '') { - $escaped_array = array(); - - foreach($item as $k=>$v) - { - $escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v, $first_word_only); - } - - return $escaped_array; - } - - // This function may get "item1 item2" as a string, and so - // we may need "item1 item2" and not "item1 item2" - if (ctype_alnum($item) === FALSE) + return $item; + } + + if (strpos($item, '.') !== FALSE) { - if (strpos($item, '.') !== FALSE) - { - $aliased_tables = implode(".",$this->ar_aliased_tables).'.'; - $table_name = substr($item, 0, strpos($item, '.')+1); - $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item; - } - - // This function may get "field >= 1", and need it to return "field >= 1" - $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; - - $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1$2$3', $item); + $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; } else { - return "{$item}"; + $str = $this->_escape_char.$item.$this->_escape_char; } - - $exceptions = array('AS', '/', '-', '%', '+', '*', 'OR', 'IS'); - - foreach ($exceptions as $exception) - { - if (stristr($item, " {$exception} ") !== FALSE) - { - $item = preg_replace('/ ('.preg_quote($exception).') /i', ' $1 ', $item); - } - } - return $item; + // remove duplicates if the user already included the escape + return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); } // -------------------------------------------------------------------- @@ -523,7 +461,7 @@ class CI_DB_sqlite_driver extends CI_DB { */ function _insert($table, $keys, $values) { - return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -552,8 +490,10 @@ class CI_DB_sqlite_driver extends CI_DB { $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - $sql = "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr); + $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); + $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; + $sql .= $orderby.$limit; return $sql; diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php index 631c9c771..2039525be 100644 --- a/system/database/drivers/sqlite/sqlite_forge.php +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -82,7 +82,7 @@ class CI_DB_sqlite_forge extends CI_DB_forge { $sql .= 'IF NOT EXISTS '; } - $sql .= $this->db->_escape_table($table)."("; + $sql .= $this->db->_escape_identifiers($table)."("; $current_field_count = 0; foreach ($fields as $field=>$attributes) diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index 9fbd72556..735a0736a 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -71,12 +71,6 @@ class CI_DB_sqlite_result extends CI_DB_result { return $field_names; } - // Deprecated - function field_names() - { - return $this->list_fields(); - } - // -------------------------------------------------------------------- /** -- cgit v1.2.3-24-g4f1b From 605a07a2ea479a8761588f7775b500a7e8d9e098 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Fri, 17 Oct 2008 04:07:54 +0000 Subject: Fixed a number of bug reports related to table/db names not being escaped or prefixed correctly. --- system/database/drivers/mysql/mysql_driver.php | 110 +++++-------------- system/database/drivers/mysql/mysql_forge.php | 4 +- system/database/drivers/mysql/mysql_result.php | 6 -- system/database/drivers/mysql/mysql_utility.php | 4 +- system/database/drivers/mysqli/mysqli_driver.php | 116 +++++---------------- system/database/drivers/mysqli/mysqli_forge.php | 4 +- system/database/drivers/mysqli/mysqli_result.php | 6 -- system/database/drivers/mysqli/mysqli_utility.php | 4 +- system/database/drivers/oci8/oci8_forge.php | 2 +- system/database/drivers/oci8/oci8_result.php | 6 -- system/database/drivers/odbc/odbc_driver.php | 104 ++++-------------- system/database/drivers/odbc/odbc_forge.php | 2 +- system/database/drivers/odbc/odbc_result.php | 6 -- system/database/drivers/postgre/postgre_driver.php | 106 ++++--------------- system/database/drivers/postgre/postgre_forge.php | 4 +- system/database/drivers/postgre/postgre_result.php | 6 -- 16 files changed, 107 insertions(+), 383 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index db04c6de8..34b6012cd 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -32,6 +32,9 @@ class CI_DB_mysql_driver extends CI_DB { var $dbdriver = 'mysql'; + // The character used for escaping + var $_escape_char = '`'; + /** * Whether to use the MySQL "delete hack" which allows the number * of affected rows to be shown. Uses a preg_replace when enabled, @@ -314,7 +317,7 @@ class CI_DB_mysql_driver extends CI_DB { if ($table == '') return '0'; - $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($this->dbprefix.$table)); + $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); if ($query->num_rows() == 0) return '0'; @@ -336,7 +339,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function _list_tables($prefix_limit = FALSE) { - $sql = "SHOW TABLES FROM `".$this->database."`"; + $sql = "SHOW TABLES FROM ".$this->_escape_char.$this->database.$this->_escape_char; if ($prefix_limit !== FALSE AND $this->dbprefix != '') { @@ -359,7 +362,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function _list_columns($table = '') { - return "SHOW COLUMNS FROM ".$this->_escape_table($table); + return "SHOW COLUMNS FROM ".$table; } // -------------------------------------------------------------------- @@ -375,7 +378,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function _field_data($table) { - return "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; + return "SELECT * FROM ".$table." LIMIT 1"; } // -------------------------------------------------------------------- @@ -407,99 +410,32 @@ class CI_DB_mysql_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Escape Column Name - * - * This function adds backticks around supplied column name - * - * @access private - * @param string the column name - * @return string - */ - function _escape_column($column) - { - return '`' .$column. '`'; - } - - // -------------------------------------------------------------------- - - /** - * Escape Table Name + * Escape the SQL Identifiers * - * This function adds backticks if the table name has a period - * in it. Some DBs will get cranky unless periods are escaped + * This function escapes column and table names * * @access private - * @param string the table name + * @param string * @return string */ - function _escape_table($table) + function _escape_identifiers($item) { - if (strpos($table, '.') !== FALSE) + if ($this->_escape_char == '') { - $table = '`' . str_replace('.', '`.`', $table) . '`'; + return $item; } - - return $table; - } - - // -------------------------------------------------------------------- - - /** - * Protect Identifiers - * - * This function adds backticks if appropriate based on db type - * - * @access private - * @param mixed the item to escape - * @param boolean only affect the first word - * @return mixed the item with backticks - */ - function _protect_identifiers($item, $first_word_only = FALSE) - { - if (is_array($item)) - { - $escaped_array = array(); - - foreach($item as $k=>$v) - { - $escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v, $first_word_only); - } - - return $escaped_array; - } - - // This function may get "item1 item2" as a string, and so - // we may need "`item1` `item2`" and not "`item1 item2`" - if (ctype_alnum($item) === FALSE) + + if (strpos($item, '.') !== FALSE) { - if (strpos($item, '.') !== FALSE) - { - $aliased_tables = implode(".",$this->ar_aliased_tables).'.'; - $table_name = substr($item, 0, strpos($item, '.')+1); - $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item; - } - - // This function may get "field >= 1", and need it to return "`field` >= 1" - $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; - - $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item); + $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; } else { - return "`{$item}`"; + $str = $this->_escape_char.$item.$this->_escape_char; } - - $exceptions = array('AS', '/', '-', '%', '+', '*', 'OR', 'IS'); - - foreach ($exceptions as $exception) - { - if (stristr($item, " `{$exception}` ") !== FALSE) - { - $item = preg_replace('/ `('.preg_quote($exception).')` /i', ' $1 ', $item); - } - } - return $item; + // remove duplicates if the user already included the escape + return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); } // -------------------------------------------------------------------- @@ -539,7 +475,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function _insert($table, $keys, $values) { - return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -568,8 +504,10 @@ class CI_DB_mysql_driver extends CI_DB { $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - $sql = "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr); + $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); + $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; + $sql .= $orderby.$limit; return $sql; @@ -590,7 +528,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function _truncate($table) { - return "TRUNCATE ".$this->_escape_table($table); + return "TRUNCATE ".$table; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index e2a222565..28a77b3b3 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -147,7 +147,7 @@ class CI_DB_mysql_forge extends CI_DB_forge { $sql .= 'IF NOT EXISTS '; } - $sql .= $this->db->_escape_table($table)." ("; + $sql .= $this->db->_escape_identifiers($table)." ("; $sql .= $this->_process_fields($fields); @@ -192,7 +192,7 @@ class CI_DB_mysql_forge extends CI_DB_forge { */ function _drop_table($table) { - return "DROP TABLE IF EXISTS ".$this->db->_escape_table($table); + return "DROP TABLE IF EXISTS ".$this->db->_escape_identifiers($table); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index ec75955e8..a28a19855 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -70,12 +70,6 @@ class CI_DB_mysql_result extends CI_DB_result { return $field_names; } - - // Deprecated - function field_names() - { - return $this->list_fields(); - } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index e035e0cf6..62a77b711 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -48,7 +48,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { */ function _optimize_table($table) { - return "OPTIMIZE TABLE ".$this->db->_escape_table($table); + return "OPTIMIZE TABLE ".$this->db->_escape_identifiers($table); } // -------------------------------------------------------------------- @@ -64,7 +64,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { */ function _repair_table($table) { - return "REPAIR TABLE ".$this->db->_escape_table($table); + return "REPAIR TABLE ".$this->db->_escape_identifiers($table); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index a5d104cc2..f7c986fc8 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -31,6 +31,9 @@ class CI_DB_mysqli_driver extends CI_DB { var $dbdriver = 'mysqli'; + + // The character used for escaping + var $_escape_char = '`'; /** * The syntax to count rows is slightly different across different @@ -91,12 +94,12 @@ class CI_DB_mysqli_driver extends CI_DB { /** * Set client character set * - * @access public + * @access private * @param string * @param string * @return resource */ - function db_set_charset($charset, $collation) + function _db_set_charset($charset, $collation) { return @mysqli_query($this->conn_id, "SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'"); } @@ -306,8 +309,8 @@ class CI_DB_mysqli_driver extends CI_DB { { if ($table == '') return '0'; - - $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($this->dbprefix.$table)); + + $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); if ($query->num_rows() == 0) return '0'; @@ -329,7 +332,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ function _list_tables($prefix_limit = FALSE) { - $sql = "SHOW TABLES FROM `".$this->database."`"; + $sql = "SHOW TABLES FROM ".$this->_escape_char.$this->database.$this->_escape_char; if ($prefix_limit !== FALSE AND $this->dbprefix != '') { @@ -352,7 +355,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ function _list_columns($table = '') { - return "SHOW COLUMNS FROM ".$this->_escape_table($table); + return "SHOW COLUMNS FROM ".$table; } // -------------------------------------------------------------------- @@ -368,7 +371,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ function _field_data($table) { - return "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; + return "SELECT * FROM ".$table." LIMIT 1"; } // -------------------------------------------------------------------- @@ -400,99 +403,32 @@ class CI_DB_mysqli_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Escape Column Name - * - * This function adds backticks around supplied column name - * - * @access private - * @param string the column name - * @return string - */ - function _escape_column($column) - { - return '`' .$column. '`'; - } - - // -------------------------------------------------------------------- - - /** - * Escape Table Name + * Escape the SQL Identifiers * - * This function adds backticks if the table name has a period - * in it. Some DBs will get cranky unless periods are escaped + * This function escapes column and table names * * @access private - * @param string the table name + * @param string * @return string */ - function _escape_table($table) + function _escape_identifiers($item) { - if (strpos($table, '.') !== FALSE) + if ($this->_escape_char == '') { - $table = '`' . str_replace('.', '`.`', $table) . '`'; + return $item; } - - return $table; - } - - // -------------------------------------------------------------------- - - /** - * Protect Identifiers - * - * This function adds backticks if appropriate based on db type - * - * @access private - * @param mixed the item to escape - * @param boolean only affect the first word - * @return mixed the item with backticks - */ - function _protect_identifiers($item, $first_word_only = FALSE) - { - if (is_array($item)) - { - $escaped_array = array(); - - foreach($item as $k=>$v) - { - $escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v, $first_word_only); - } - - return $escaped_array; - } - - // This function may get "item1 item2" as a string, and so - // we may need "`item1` `item2`" and not "`item1 item2`" - if (ctype_alnum($item) === FALSE) + + if (strpos($item, '.') !== FALSE) { - if (strpos($item, '.') !== FALSE) - { - $aliased_tables = implode(".",$this->ar_aliased_tables).'.'; - $table_name = substr($item, 0, strpos($item, '.')+1); - $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item; - } - - // This function may get "field >= 1", and need it to return "`field` >= 1" - $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; - - $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item); + $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; } else { - return "`{$item}`"; + $str = $this->_escape_char.$item.$this->_escape_char; } - - $exceptions = array('AS', '/', '-', '%', '+', '*', 'OR', 'IS'); - - foreach ($exceptions as $exception) - { - if (stristr($item, " `{$exception}` ") !== FALSE) - { - $item = preg_replace('/ `('.preg_quote($exception).')` /i', ' $1 ', $item); - } - } - return $item; + // remove duplicates if the user already included the escape + return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); } // -------------------------------------------------------------------- @@ -532,7 +468,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ function _insert($table, $keys, $values) { - return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -561,8 +497,10 @@ class CI_DB_mysqli_driver extends CI_DB { $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - $sql = "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr); + $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); + $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; + $sql .= $orderby.$limit; return $sql; @@ -584,7 +522,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ function _truncate($table) { - return "TRUNCATE ".$this->_escape_table($table); + return "TRUNCATE ".$table; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index ce6ab45b2..c7889bf48 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -147,7 +147,7 @@ class CI_DB_mysqli_forge extends CI_DB_forge { $sql .= 'IF NOT EXISTS '; } - $sql .= $this->db->_escape_table($table)." ("; + $sql .= $this->db->_escape_identifiers($table)." ("; $sql .= $this->_process_fields($fields); @@ -192,7 +192,7 @@ class CI_DB_mysqli_forge extends CI_DB_forge { */ function _drop_table($table) { - return "DROP TABLE IF EXISTS ".$this->db->_escape_table($table); + return "DROP TABLE IF EXISTS ".$this->db->_escape_identifiers($table); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index 0a97454f0..b690914b7 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -71,12 +71,6 @@ class CI_DB_mysqli_result extends CI_DB_result { return $field_names; } - // Deprecated - function field_names() - { - return $this->list_fields(); - } - // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 0080bfc3d..d19b64374 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -48,7 +48,7 @@ class CI_DB_mysqli_utility extends CI_DB_utility { */ function _optimize_table($table) { - return "OPTIMIZE TABLE ".$this->db->_escape_table($table); + return "OPTIMIZE TABLE ".$this->db->_escape_identifiers($table); } // -------------------------------------------------------------------- @@ -64,7 +64,7 @@ class CI_DB_mysqli_utility extends CI_DB_utility { */ function _repair_table($table) { - return "REPAIR TABLE ".$this->db->_escape_table($table); + return "REPAIR TABLE ".$this->db->_escape_identifiers($table); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index 1a66978d6..4b073d07f 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -72,7 +72,7 @@ class CI_DB_oci8_forge extends CI_DB_forge { $sql .= 'IF NOT EXISTS '; } - $sql .= $this->db->_escape_table($table)." ("; + $sql .= $this->db->_escape_identifiers($table)." ("; $current_field_count = 0; foreach ($fields as $field=>$attributes) diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 9bc982fbf..4cfbfa4b4 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -95,12 +95,6 @@ class CI_DB_oci8_result extends CI_DB_result { return $field_names; } - // Deprecated - function field_names() - { - return $this->list_fields(); - } - // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index cc8d3347b..50412685d 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -31,6 +31,9 @@ class CI_DB_odbc_driver extends CI_DB { var $dbdriver = 'odbc'; + + // the character used to excape - not necessary for ODBC + var $_escape_char = ''; /** * The syntax to count rows is slightly different across different @@ -294,7 +297,7 @@ class CI_DB_odbc_driver extends CI_DB { if ($table == '') return '0'; - $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($this->dbprefix.$table)); + $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); if ($query->num_rows() == 0) return '0'; @@ -340,7 +343,7 @@ class CI_DB_odbc_driver extends CI_DB { */ function _list_columns($table = '') { - return "SHOW COLUMNS FROM ".$this->_escape_table($table); + return "SHOW COLUMNS FROM ".$table; } // -------------------------------------------------------------------- @@ -356,7 +359,7 @@ class CI_DB_odbc_driver extends CI_DB { */ function _field_data($table) { - return "SELECT TOP 1 FROM ".$this->_escape_table($table); + return "SELECT TOP 1 FROM ".$table; } // -------------------------------------------------------------------- @@ -384,99 +387,36 @@ class CI_DB_odbc_driver extends CI_DB { { return odbc_error($this->conn_id); } - // -------------------------------------------------------------------- - - /** - * Escape Column Name - * - * This function adds backticks around supplied column name - * - * @access private - * @param string the column name - * @return string - */ - function _escape_column($column) - { - // Not necessary with ODBC so we simply return the value - return $column; - } // -------------------------------------------------------------------- /** - * Escape Table Name + * Escape the SQL Identifiers * - * This function adds backticks if the table name has a period - * in it. Some DBs will get cranky unless periods are escaped + * This function escapes column and table names * * @access private - * @param string the table name + * @param string * @return string */ - function _escape_table($table) + function _escape_identifiers($item) { - // Not necessary with ODBC so we simply return the value - return $table; - } - - // -------------------------------------------------------------------- - - /** - * Protect Identifiers - * - * This function adds backticks if appropriate based on db type - * - * @access private - * @param mixed the item to escape - * @param boolean only affect the first word - * @return mixed the item with backticks - */ - function _protect_identifiers($item, $first_word_only = FALSE) - { - if (is_array($item)) + if ($this->_escape_char == '') { - $escaped_array = array(); - - foreach($item as $k=>$v) - { - $escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v, $first_word_only); - } - - return $escaped_array; - } - - // This function may get "item1 item2" as a string, and so - // we may need "`item1` `item2`" and not "`item1 item2`" - if (ctype_alnum($item) === FALSE) + return $item; + } + + if (strpos($item, '.') !== FALSE) { - if (strpos($item, '.') !== FALSE) - { - $aliased_tables = implode(".",$this->ar_aliased_tables).'.'; - $table_name = substr($item, 0, strpos($item, '.')+1); - $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item; - } - - // This function may get "field >= 1", and need it to return "`field` >= 1" - $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; - - $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item); + $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; } else { - return "{$item}"; + $str = $this->_escape_char.$item.$this->_escape_char; } - - $exceptions = array('AS', '/', '-', '%', '+', '*', 'OR', 'IS'); - - foreach ($exceptions as $exception) - { - if (stristr($item, " {$exception} ") !== FALSE) - { - $item = preg_replace('/ ('.preg_quote($exception).') /i', ' $1 ', $item); - } - } - return $item; + // remove duplicates if the user already included the escape + return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); } // -------------------------------------------------------------------- @@ -516,7 +456,7 @@ class CI_DB_odbc_driver extends CI_DB { */ function _insert($table, $keys, $values) { - return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -545,8 +485,10 @@ class CI_DB_odbc_driver extends CI_DB { $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - $sql = "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr); + $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); + $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; + $sql .= $orderby.$limit; return $sql; diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php index de67b9478..099925caf 100644 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -84,7 +84,7 @@ class CI_DB_odbc_forge extends CI_DB_forge { $sql .= 'IF NOT EXISTS '; } - $sql .= $this->db->_escape_table($table)." ("; + $sql .= $this->db->_escape_identifiers($table)." ("; $current_field_count = 0; foreach ($fields as $field=>$attributes) diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index 8b485ec55..6d6542e77 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -71,12 +71,6 @@ class CI_DB_odbc_result extends CI_DB_result { return $field_names; } - // Deprecated - function field_names() - { - return $this->list_fields(); - } - // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index c5c70a736..d94cce149 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -31,6 +31,8 @@ class CI_DB_postgre_driver extends CI_DB { var $dbdriver = 'postgre'; + + var $_escape_char = '"'; /** * The syntax to count rows is slightly different across different @@ -329,7 +331,7 @@ class CI_DB_postgre_driver extends CI_DB { if ($table == '') return '0'; - $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($this->dbprefix.$table)); + $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); if ($query->num_rows() == 0) return '0'; @@ -374,7 +376,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function _list_columns($table = '') { - return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->_escape_table($table)."'"; + return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$table."'"; } // -------------------------------------------------------------------- @@ -390,7 +392,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function _field_data($table) { - return "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; + return "SELECT * FROM ".$table." LIMIT 1"; } // -------------------------------------------------------------------- @@ -418,103 +420,36 @@ class CI_DB_postgre_driver extends CI_DB { { return ''; } - // -------------------------------------------------------------------- - - /** - * Escape Column Name - * - * This function adds backticks around supplied column name - * - * @access private - * @param string the column name - * @return string - */ - function _escape_column($column) - { - // Probably not necessary with Postgres so we simply return the value - return $column; - } // -------------------------------------------------------------------- /** - * Escape Table Name + * Escape the SQL Identifiers * - * This function adds backticks if the table name has a period - * in it. Some DBs will get cranky unless periods are escaped. + * This function escapes column and table names * * @access private - * @param string the table name + * @param string * @return string */ - function _escape_table($table) + function _escape_identifiers($item) { - if (strpos($table, '.') !== FALSE) + if ($this->_escape_char == '') { - $table = '"' . str_replace('.', '"."', $table) . '"'; + return $item; } - - return $table; - } - // -------------------------------------------------------------------- - - /** - * Protect Identifiers - * - * This function adds backticks if appropriate based on db type - * - * @access private - * @param mixed the item to escape - * @param boolean only affect the first word - * @return mixed the item with backticks - */ - function _protect_identifiers($item, $first_word_only = FALSE) - { - if (is_array($item)) + if (strpos($item, '.') !== FALSE) { - $escaped_array = array(); - - foreach($item as $k=>$v) - { - $escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v, $first_word_only); - } - - return $escaped_array; - } - - // This function may get "item1 item2" as a string, and so - // we may need ""item1" "item2"" and not ""item1 item2"" - if (ctype_alnum($item) === FALSE) - { - if (strpos($item, '.') !== FALSE) - { - $aliased_tables = implode(".",$this->ar_aliased_tables).'.'; - $table_name = substr($item, 0, strpos($item, '.')+1); - $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item; - } - - // This function may get "field >= 1", and need it to return ""field" >= 1" - $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; - - $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1"$2"$3', $item); + $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; } else { - return "\"{$item}\""; + $str = $this->_escape_char.$item.$this->_escape_char; } - - $exceptions = array('AS', '/', '-', '%', '+', '*', 'OR', 'IS'); - foreach ($exceptions as $exception) - { - - if (stristr($item, " \"{$exception}\" ") !== FALSE) - { - $item = preg_replace('/ "('.preg_quote($exception).')" /i', ' $1 ', $item); - } - } - return $item; + // remove duplicates if the user already included the escape + return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); } // -------------------------------------------------------------------- @@ -554,7 +489,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function _insert($table, $keys, $values) { - return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -583,14 +518,15 @@ class CI_DB_postgre_driver extends CI_DB { $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - $sql = "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr); + $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); + $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; + $sql .= $orderby.$limit; return $sql; } - // -------------------------------------------------------------------- /** @@ -606,7 +542,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function _truncate($table) { - return "TRUNCATE ".$this->_escape_table($table); + return "TRUNCATE ".$table; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index b9e1cd9bb..5b4bcc295 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -72,7 +72,7 @@ class CI_DB_postgre_forge extends CI_DB_forge { $sql .= 'IF NOT EXISTS '; } - $sql .= $this->db->_escape_table($table)." ("; + $sql .= $this->db->_escape_identifiers($table)." ("; $current_field_count = 0; foreach ($fields as $field=>$attributes) @@ -167,7 +167,7 @@ class CI_DB_postgre_forge extends CI_DB_forge { */ function _drop_table($table) { - return "DROP TABLE ".$this->db->_escape_table($table)." CASCADE"; + return "DROP TABLE ".$this->db->_escape_identifiers($table)." CASCADE"; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index d018a9b2b..2e1e00330 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -71,12 +71,6 @@ class CI_DB_postgre_result extends CI_DB_result { return $field_names; } - // Deprecated - function field_names() - { - return $this->list_fields(); - } - // -------------------------------------------------------------------- /** -- cgit v1.2.3-24-g4f1b From cba158c75954079e593732f8479563d4dfb6ecb3 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Fri, 17 Oct 2008 04:18:04 +0000 Subject: Added brackets around database name in MS SQL driver when selecting the database, in the event that reserved characters are used in the name (bug report: 4915) --- system/database/drivers/mssql/mssql_driver.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index fbc0701c0..6130bf4cb 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -76,7 +76,9 @@ class CI_DB_mssql_driver extends CI_DB { */ function db_select() { - return @mssql_select_db($this->database, $this->conn_id); + // Note: The brackets are required in the event that the DB name + // contains reserved characters + return @mssql_select_db('['.$this->database.']', $this->conn_id); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 5e189cc5bf2081a54474262e06d0add8d5ed389c Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Fri, 17 Oct 2008 04:30:55 +0000 Subject: Added a call to the parent contructor, as this was causing errors. --- system/database/drivers/odbc/odbc_driver.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 50412685d..16c72d828 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -46,13 +46,7 @@ class CI_DB_odbc_driver extends CI_DB { function CI_DB_odbc_driver($params) { - if (is_array($params)) - { - foreach ($params as $key => $val) - { - $this->$key = $val; - } - } + parent::CI_DB($params); $this->_random_keyword = ' RND('.time().')'; // database specific random keyword } -- cgit v1.2.3-24-g4f1b From e5ff3dcd795f8a9a27e8c2026a93571e65a5961d Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Fri, 17 Oct 2008 04:57:16 +0000 Subject: Fixed a bug (4718) in which the path to the files was being set in correctly. --- system/database/DB_cache.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index ecb2b13a1..9bb1b165b 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -93,13 +93,14 @@ class CI_DB_Cache { { return $this->db->cache_off(); } - - $uri = ($this->CI->uri->segment(1) == FALSE) ? 'default.' : $this->CI->uri->segment(1).'+'; - $uri .= ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); + + $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); - $filepath = $uri.'/'.md5($sql); + $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); + + $filepath = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'.md5($sql); - if (FALSE === ($cachedata = read_file($this->db->cachedir.$filepath))) + if (FALSE === ($cachedata = read_file($filepath))) { return FALSE; } @@ -122,10 +123,11 @@ class CI_DB_Cache { return $this->db->cache_off(); } - $uri = ($this->CI->uri->segment(1) == FALSE) ? 'default.' : $this->CI->uri->segment(1).'+'; - $uri .= ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); + $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); - $dir_path = $this->db->cachedir.$uri.'/'; + $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); + + $dir_path = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'; $filename = md5($sql); -- cgit v1.2.3-24-g4f1b From 63c361dfd8693aa080acfe81b3e4edf82c5499ca Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Fri, 17 Oct 2008 05:48:57 +0000 Subject: Fixed a tab issue --- system/database/drivers/oci8/oci8_driver.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 0c51a5ea7..365c9e78b 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -211,11 +211,11 @@ class CI_DB_oci8_driver extends CI_DB { * params array keys * * KEY OPTIONAL NOTES - * name no the name of the parameter should be in : format - * value no the value of the parameter. If this is an OUT or IN OUT parameter, - * this should be a reference to a variable - * type yes the type of the parameter - * length yes the max size of the parameter + * name no the name of the parameter should be in : format + * value no the value of the parameter. If this is an OUT or IN OUT parameter, + * this should be a reference to a variable + * type yes the type of the parameter + * length yes the max size of the parameter */ function stored_procedure($package, $procedure, $params) { -- cgit v1.2.3-24-g4f1b From 62637e9383bc21a38a49e4ce236ee9baf9c20f65 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Fri, 17 Oct 2008 06:48:16 +0000 Subject: Fixed an error reporting bug: 4900 --- system/database/DB_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 9508ded8c..6b60d67dd 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -314,7 +314,7 @@ class CI_DB_driver { $this->trans_complete(); // Log and display errors - log_message('error', 'Query error: '.$this->_error_message()); + log_message('error', 'Query error: '.$error_msg); return $this->display_error( array( 'Error Number: '.$error_no, -- cgit v1.2.3-24-g4f1b From 7799f52d9ba6efc0c309b04d23178f5c84d12e94 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Fri, 17 Oct 2008 07:08:31 +0000 Subject: Fixed bug: 5043 --- system/database/DB_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 6b60d67dd..1682b5963 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1126,7 +1126,7 @@ class CI_DB_driver { */ function display_error($error = '', $swap = '', $native = FALSE) { - global $LANG; + $LANG =& load_class('Language'); $LANG->load('db'); $heading = $LANG->line('db_error_heading'); -- cgit v1.2.3-24-g4f1b From 1cd997a3ab7edc02c557abcb2e5fcb05d5dd5144 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Fri, 17 Oct 2008 07:13:21 +0000 Subject: Added backticks to field names --- system/database/drivers/mysql/mysql_utility.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 62a77b711..d2c10dbb2 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -153,7 +153,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { ) ? TRUE : FALSE; // Create a string of field names - $field_str .= $field->name.', '; + $field_str .= '`'.$field->name.'`, '; $i++; } -- cgit v1.2.3-24-g4f1b From 1e2c33ef74005b25530a201b44bb95b7fbf26d19 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Fri, 17 Oct 2008 08:10:19 +0000 Subject: --- system/database/drivers/odbc/odbc_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 16c72d828..1f0377145 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -47,7 +47,7 @@ class CI_DB_odbc_driver extends CI_DB { function CI_DB_odbc_driver($params) { parent::CI_DB($params); - + $this->_random_keyword = ' RND('.time().')'; // database specific random keyword } -- cgit v1.2.3-24-g4f1b From d22e53b6c5ea602900199360454b29c6e72d5b86 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Fri, 17 Oct 2008 22:30:31 +0000 Subject: Added support for the port setting in mysql --- system/database/drivers/mysql/mysql_driver.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'system/database') diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 34b6012cd..e0a1cee7d 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -58,6 +58,11 @@ class CI_DB_mysql_driver extends CI_DB { */ function db_connect() { + if ($this->port != '') + { + $this->hostname .= ':'.$this->port; + } + return @mysql_connect($this->hostname, $this->username, $this->password, TRUE); } @@ -71,6 +76,11 @@ class CI_DB_mysql_driver extends CI_DB { */ function db_pconnect() { + if ($this->port != '') + { + $this->hostname .= ':'.$this->port; + } + return @mysql_pconnect($this->hostname, $this->username, $this->password); } -- cgit v1.2.3-24-g4f1b From d63414872ef6fc14b3a9ab65a8624d5e3fee3bc8 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Fri, 17 Oct 2008 22:39:11 +0000 Subject: Added port support to mysqli --- system/database/drivers/mysqli/mysqli_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index f7c986fc8..4bbe5ebf6 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -60,7 +60,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ function db_connect() { - return @mysqli_connect($this->hostname, $this->username, $this->password); + return @mysqli_connect($this->hostname, $this->username, $this->password, $this->database, $this->port); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From c8bde826c13f41a5cdd4ebefb23b690896ac6706 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Fri, 17 Oct 2008 22:43:42 +0000 Subject: Added port support to MS SQL --- system/database/drivers/mssql/mssql_driver.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'system/database') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 6130bf4cb..72dc263f3 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -50,6 +50,11 @@ class CI_DB_mssql_driver extends CI_DB { */ function db_connect() { + if ($this->port != '') + { + $this->hostname .= ','.$this->port; + } + return @mssql_connect($this->hostname, $this->username, $this->password); } @@ -63,6 +68,11 @@ class CI_DB_mssql_driver extends CI_DB { */ function db_pconnect() { + if ($this->port != '') + { + $this->hostname .= ','.$this->port; + } + return @mssql_pconnect($this->hostname, $this->username, $this->password); } -- cgit v1.2.3-24-g4f1b From 000f89d16ca48e5dd6a858911fd91484d7f1251f Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Fri, 17 Oct 2008 23:26:15 +0000 Subject: --- system/database/DB_active_rec.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index f4c13cc42..47933ed78 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -412,7 +412,7 @@ class CI_DB_active_record extends CI_DB_driver { foreach ($key as $k => $v) { - $prefix = (count($this->ar_where) == 0) ? '' : $type; + $prefix = (count($this->ar_where) == 0 AND count($this->ar_cache_where) == 0) ? '' : $type; if (is_null($v) && ! $this->_has_operator($k)) { @@ -1675,13 +1675,20 @@ class CI_DB_active_record extends CI_DB_driver { return; } - $ar_items = array('select', 'from', 'join', 'where', 'like', 'groupby', 'having', 'orderby', 'set'); - - foreach ($ar_items as $ar_item) + foreach (array('select', 'from', 'join', 'where', 'like', 'groupby', 'having', 'orderby', 'set') as $val) { - $ar_cache_item = 'ar_cache_'.$ar_item; - $ar_item = 'ar_'.$ar_item; - $this->$ar_item = array_unique(array_merge($this->$ar_item, $this->$ar_cache_item)); + $ar_variable = 'ar_'.$val; + $ar_cache_var = 'ar_cache_'.$val; + + if (count($this->$ar_cache_var) == 0) + { + continue; + } + + // This doesn't seem to work right, per bug report #4995 + // $this->$ar_variable = array_unique(array_merge($this->$ar_variable, $this->$ar_cache_var)); + + $this->$ar_variable = array_unique(array_merge($this->$ar_cache_var, $this->$ar_variable)); } // If we are "protecting identifiers" we need to examine the "from" -- cgit v1.2.3-24-g4f1b From 392f09ddfc99bed44ee69715626a49b2ad5f3e47 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Sat, 18 Oct 2008 02:03:14 +0000 Subject: Fixed an AR caching bug: 4995 --- system/database/DB_active_rec.php | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 47933ed78..5b118ce1d 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -47,6 +47,7 @@ class CI_DB_active_record extends CI_DB_driver { // Active Record Caching variables var $ar_caching = FALSE; + var $ar_cache_exists = array(); var $ar_cache_select = array(); var $ar_cache_from = array(); var $ar_cache_join = array(); @@ -96,6 +97,7 @@ class CI_DB_active_record extends CI_DB_driver { if ($this->ar_caching === TRUE) { $this->ar_cache_select[] = $val; + $this->ar_cache_exists[] = 'select'; } } } @@ -211,6 +213,7 @@ class CI_DB_active_record extends CI_DB_driver { if ($this->ar_caching === TRUE) { $this->ar_cache_select[] = $sql; + $this->ar_cache_exists[] = 'select'; } return $this; @@ -276,6 +279,7 @@ class CI_DB_active_record extends CI_DB_driver { if ($this->ar_caching === TRUE) { $this->ar_cache_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE); + $this->ar_cache_exists[] = 'from'; } } @@ -331,6 +335,7 @@ class CI_DB_active_record extends CI_DB_driver { if ($this->ar_caching === TRUE) { $this->ar_cache_join[] = $join; + $this->ar_cache_exists[] = 'join'; } return $this; @@ -444,6 +449,7 @@ class CI_DB_active_record extends CI_DB_driver { if ($this->ar_caching === TRUE) { $this->ar_cache_where[] = $prefix.$k.$v; + $this->ar_cache_exists[] = 'where'; } } @@ -564,6 +570,7 @@ class CI_DB_active_record extends CI_DB_driver { if ($this->ar_caching === TRUE) { $this->ar_cache_where[] = $where_in; + $this->ar_cache_exists[] = 'where'; } // reset the array for multiple calls @@ -700,6 +707,7 @@ class CI_DB_active_record extends CI_DB_driver { if ($this->ar_caching === TRUE) { $this->ar_cache_like[] = $like_statement; + $this->ar_cache_exists[] = 'like'; } } @@ -733,6 +741,7 @@ class CI_DB_active_record extends CI_DB_driver { if ($this->ar_caching === TRUE) { $this->ar_cache_groupby[] = $this->_protect_identifiers($val); + $this->ar_cache_exists[] = 'groupby'; } } } @@ -839,6 +848,7 @@ class CI_DB_active_record extends CI_DB_driver { if ($this->ar_caching === TRUE) { $this->ar_cache_having[] = $prefix.$k.$v; + $this->ar_cache_exists[] = 'having'; } } @@ -873,6 +883,7 @@ class CI_DB_active_record extends CI_DB_driver { if ($this->ar_caching === TRUE) { $this->ar_cache_orderby[] = $orderby_statement; + $this->ar_cache_exists[] = 'orderby'; } return $this; @@ -906,6 +917,7 @@ class CI_DB_active_record extends CI_DB_driver { if ($this->ar_caching === TRUE) { $this->ar_cache_limit[] = $value; + $this->ar_cache_exists[] = 'limit'; } if ($offset != '') @@ -914,6 +926,7 @@ class CI_DB_active_record extends CI_DB_driver { if ($this->ar_caching === TRUE) { $this->ar_cache_offset[] = $offset; + $this->ar_cache_exists[] = 'limit'; } } @@ -935,6 +948,7 @@ class CI_DB_active_record extends CI_DB_driver { if ($this->ar_caching === TRUE) { $this->ar_cache_offset[] = $offset; + $this->ar_cache_exists[] = 'offset'; } return $this; @@ -969,6 +983,7 @@ class CI_DB_active_record extends CI_DB_driver { if ($this->ar_caching === TRUE) { $this->ar_cache_offset[$this->_protect_identifiers($k)] = $v; + $this->ar_cache_exists[] = 'offset'; } } else @@ -978,6 +993,7 @@ class CI_DB_active_record extends CI_DB_driver { if ($this->ar_caching === TRUE) { $this->ar_cache_offset[$this->_protect_identifiers($k)] = $this->escape($v); + $this->ar_cache_exists[] = 'offset'; } } } @@ -1670,12 +1686,12 @@ class CI_DB_active_record extends CI_DB_driver { */ function _merge_cache() { - if ($this->ar_caching == FALSE) + if (count($this->ar_cache_exists) == 0) { return; } - - foreach (array('select', 'from', 'join', 'where', 'like', 'groupby', 'having', 'orderby', 'set') as $val) + + foreach ($this->ar_cache_exists as $val) { $ar_variable = 'ar_'.$val; $ar_cache_var = 'ar_cache_'.$val; @@ -1684,16 +1700,13 @@ class CI_DB_active_record extends CI_DB_driver { { continue; } - - // This doesn't seem to work right, per bug report #4995 - // $this->$ar_variable = array_unique(array_merge($this->$ar_variable, $this->$ar_cache_var)); - + $this->$ar_variable = array_unique(array_merge($this->$ar_cache_var, $this->$ar_variable)); } - + // If we are "protecting identifiers" we need to examine the "from" // portion of the query to determine if there are any aliases - if ($this->_protect_identifiers === TRUE) + if ($this->_protect_identifiers === TRUE AND count($this->ar_cache_from) > 0) { $this->_track_aliases($this->ar_from); } -- cgit v1.2.3-24-g4f1b From 23012599aa8f668b515387eccae6bc540e136bd8 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Sat, 18 Oct 2008 02:11:06 +0000 Subject: Oops! I missed resetting the cache array in the flush function in my last commit. --- system/database/DB_active_rec.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 5b118ce1d..d2d2632a7 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1665,9 +1665,10 @@ class CI_DB_active_record extends CI_DB_driver { 'ar_cache_where' => array(), 'ar_cache_like' => array(), 'ar_cache_groupby' => array(), - 'ar_cache_having' =>array(), + 'ar_cache_having' => array(), 'ar_cache_orderby' => array(), - 'ar_cache_set' => array() + 'ar_cache_set' => array(), + 'ar_cache_exists' => array() ); $this->_reset_run($ar_reset_items); -- cgit v1.2.3-24-g4f1b From b5a9acabee5472637f962b776e3c01c1f3d7e205 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Sat, 18 Oct 2008 02:25:45 +0000 Subject: Set primary key to zero, since there isn't a good way to retrieve it. Bug report: 5172 --- system/database/drivers/postgre/postgre_result.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index 2e1e00330..78b9a6040 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -90,7 +90,7 @@ class CI_DB_postgre_result extends CI_DB_result { $F->name = pg_field_name($this->result_id, $i); $F->type = pg_field_type($this->result_id, $i); $F->max_length = pg_field_size($this->result_id, $i); - $F->primary_key = $i == 0; + $F->primary_key = 0; $F->default = ''; $retval[] = $F; -- cgit v1.2.3-24-g4f1b From 65837c7d6fe0e89b93b102382da264ef8830ca32 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Sat, 18 Oct 2008 06:39:49 +0000 Subject: Removed limit and order from the AR caching routine, as these are not supported. --- system/database/DB_active_rec.php | 40 +++++---------------------------------- 1 file changed, 5 insertions(+), 35 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index d2d2632a7..0f5d2b226 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -55,9 +55,6 @@ class CI_DB_active_record extends CI_DB_driver { var $ar_cache_like = array(); var $ar_cache_groupby = array(); var $ar_cache_having = array(); - var $ar_cache_limit = FALSE; - var $ar_cache_offset = FALSE; - var $ar_cache_order = FALSE; var $ar_cache_orderby = array(); var $ar_cache_set = array(); @@ -914,20 +911,10 @@ class CI_DB_active_record extends CI_DB_driver { function limit($value, $offset = '') { $this->ar_limit = $value; - if ($this->ar_caching === TRUE) - { - $this->ar_cache_limit[] = $value; - $this->ar_cache_exists[] = 'limit'; - } if ($offset != '') { $this->ar_offset = $offset; - if ($this->ar_caching === TRUE) - { - $this->ar_cache_offset[] = $offset; - $this->ar_cache_exists[] = 'limit'; - } } return $this; @@ -945,12 +932,6 @@ class CI_DB_active_record extends CI_DB_driver { function offset($offset) { $this->ar_offset = $offset; - if ($this->ar_caching === TRUE) - { - $this->ar_cache_offset[] = $offset; - $this->ar_cache_exists[] = 'offset'; - } - return $this; } @@ -979,22 +960,10 @@ class CI_DB_active_record extends CI_DB_driver { if ($escape === FALSE) { $this->ar_set[$this->_protect_identifiers($k)] = $v; - - if ($this->ar_caching === TRUE) - { - $this->ar_cache_offset[$this->_protect_identifiers($k)] = $v; - $this->ar_cache_exists[] = 'offset'; - } } else { $this->ar_set[$this->_protect_identifiers($k)] = $this->escape($v); - - if ($this->ar_caching === TRUE) - { - $this->ar_cache_offset[$this->_protect_identifiers($k)] = $this->escape($v); - $this->ar_cache_exists[] = 'offset'; - } } } @@ -1455,6 +1424,7 @@ class CI_DB_active_record extends CI_DB_driver { */ function _compile_select($select_override = FALSE) { + // Combine any cached components with the current statements $this->_merge_cache(); // ---------------------------------------------------------------- @@ -1658,7 +1628,8 @@ class CI_DB_active_record extends CI_DB_driver { */ function flush_cache() { - $ar_reset_items = array( + $this->_reset_run( + array( 'ar_cache_select' => array(), 'ar_cache_from' => array(), 'ar_cache_join' => array(), @@ -1669,9 +1640,8 @@ class CI_DB_active_record extends CI_DB_driver { 'ar_cache_orderby' => array(), 'ar_cache_set' => array(), 'ar_cache_exists' => array() - ); - - $this->_reset_run($ar_reset_items); + ) + ); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 849ecdefeb2dab583669bd5b79e8f2a18906c95e Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Sat, 18 Oct 2008 06:47:53 +0000 Subject: Added AR caching features to update and delete functions --- system/database/DB_active_rec.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 0f5d2b226..e3798254c 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1098,7 +1098,7 @@ class CI_DB_active_record extends CI_DB_driver { * @return object */ function insert($table = '', $set = NULL) - { + { if ( ! is_null($set)) { $this->set($set); @@ -1148,6 +1148,9 @@ class CI_DB_active_record extends CI_DB_driver { */ function update($table = '', $set = NULL, $where = NULL, $limit = NULL) { + // Combine any cached components with the current statements + $this->_merge_cache(); + if ( ! is_null($set)) { $this->set($set); @@ -1286,6 +1289,9 @@ class CI_DB_active_record extends CI_DB_driver { */ function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE) { + // Combine any cached components with the current statements + $this->_merge_cache(); + if ($table == '') { if ( ! isset($this->ar_from[0])) -- cgit v1.2.3-24-g4f1b From 7709aca4a8325da5906a7585a831456cbd8abf47 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Wed, 22 Oct 2008 21:07:22 +0000 Subject: Fixed a bug in the table_exists function --- system/database/DB_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 1682b5963..07c19c51b 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -767,7 +767,7 @@ class CI_DB_driver { */ function table_exists($table_name) { - return ( ! in_array($this->_protect_identifiers($table_name, TRUE, NULL, FALSE), $this->list_tables())) ? FALSE : TRUE; + return ( ! in_array($this->_protect_identifiers($table_name, TRUE, FALSE, FALSE), $this->list_tables())) ? FALSE : TRUE; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 4ba802d8f0a28ba138c21cd90d336e220f81a099 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 24 Oct 2008 16:43:02 +0000 Subject: added a conditional for $this->port in the mysqli driver. Apparently it doesn't like being sent an empty string. --- system/database/drivers/mysqli/mysqli_driver.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 4bbe5ebf6..f72db64b6 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -60,7 +60,15 @@ class CI_DB_mysqli_driver extends CI_DB { */ function db_connect() { - return @mysqli_connect($this->hostname, $this->username, $this->password, $this->database, $this->port); + if ($this->port != '') + { + return @mysqli_connect($this->hostname, $this->username, $this->password, $this->database, $this->port); + } + else + { + return @mysqli_connect($this->hostname, $this->username, $this->password, $this->database); + } + } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From ac91bd701c11e8c9e5cb42b1120eb9f88f73456a Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Sun, 26 Oct 2008 21:52:41 +0000 Subject: Fixed some typos --- system/database/DB_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 07c19c51b..866b95612 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1218,7 +1218,7 @@ class CI_DB_driver { // Does the first segment of the exploded item match // one of the aliases previously identified? If so, - // we have nothing more to do other then escape the item + // we have nothing more to do other than escape the item if (in_array($parts[0], $this->ar_aliased_tables)) { if ($protect_identifiers === TRUE) -- cgit v1.2.3-24-g4f1b From a0e86293949ff7761cca573853e54146d76f9ba7 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Sun, 26 Oct 2008 22:46:55 +0000 Subject: Fixed a bug in which identifers were not being escaped properly when reserved characters were used --- system/database/DB_driver.php | 2 +- system/database/drivers/mssql/mssql_driver.php | 13 ++++++++++++- system/database/drivers/mysql/mysql_driver.php | 15 +++++++++++++-- system/database/drivers/mysqli/mysqli_driver.php | 13 ++++++++++++- system/database/drivers/oci8/oci8_driver.php | 11 +++++++++++ system/database/drivers/odbc/odbc_driver.php | 11 +++++++++++ system/database/drivers/postgre/postgre_driver.php | 11 +++++++++++ system/database/drivers/sqlite/sqlite_driver.php | 11 +++++++++++ 8 files changed, 82 insertions(+), 5 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 866b95612..dbd82dbc4 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1302,7 +1302,7 @@ class CI_DB_driver { $item = $this->dbprefix.$item; } } - + if ($protect_identifiers === TRUE AND ! in_array($item, $this->_reserved_identifiers)) { $item = $this->_escape_identifiers($item); diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 72dc263f3..6ad0880ff 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -427,7 +427,18 @@ class CI_DB_mssql_driver extends CI_DB { { return $item; } - + + foreach ($this->_reserved_identifiers as $id) + { + if (strpos($item, '.'.$id) !== FALSE) + { + $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; diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index e0a1cee7d..45bf77149 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -434,7 +434,18 @@ class CI_DB_mysql_driver extends CI_DB { { return $item; } - + + foreach ($this->_reserved_identifiers as $id) + { + if (strpos($item, '.'.$id) !== FALSE) + { + $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; @@ -443,7 +454,7 @@ class CI_DB_mysql_driver extends CI_DB { { $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); } diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index f72db64b6..1b3da7a6b 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -425,7 +425,18 @@ class CI_DB_mysqli_driver extends CI_DB { { return $item; } - + + foreach ($this->_reserved_identifiers as $id) + { + if (strpos($item, '.'.$id) !== FALSE) + { + $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; diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 365c9e78b..0c1467783 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -533,6 +533,17 @@ class CI_DB_oci8_driver extends CI_DB { { return $item; } + + foreach ($this->_reserved_identifiers as $id) + { + if (strpos($item, '.'.$id) !== FALSE) + { + $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) { diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 1f0377145..3c6f01542 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -399,6 +399,17 @@ class CI_DB_odbc_driver extends CI_DB { { return $item; } + + foreach ($this->_reserved_identifiers as $id) + { + if (strpos($item, '.'.$id) !== FALSE) + { + $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) { diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index d94cce149..68622a22b 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -438,6 +438,17 @@ class CI_DB_postgre_driver extends CI_DB { { return $item; } + + foreach ($this->_reserved_identifiers as $id) + { + if (strpos($item, '.'.$id) !== FALSE) + { + $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) { diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 0ba483f8b..992e2479e 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -410,6 +410,17 @@ class CI_DB_sqlite_driver extends CI_DB { { return $item; } + + foreach ($this->_reserved_identifiers as $id) + { + if (strpos($item, '.'.$id) !== FALSE) + { + $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) { -- cgit v1.2.3-24-g4f1b From 0efc4d331fa1e8212c0aa01bf9c220810d14f61c Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Sun, 26 Oct 2008 23:55:00 +0000 Subject: Fixed order_by bug #5704 --- system/database/DB_active_rec.php | 64 +++++++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 10 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index e3798254c..b270b6fc1 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -267,16 +267,38 @@ class CI_DB_active_record extends CI_DB_driver { { foreach ((array)$from as $val) { - // Extract any aliases that might exist. We use this information - // in the _protect_identifiers to know whether to add a table prefix - $this->_track_aliases($val); + if (strpos($val, ',') !== FALSE) + { + foreach (explode(',', $val) as $v) + { + $v = trim($v); + $this->_track_aliases($v); - $this->ar_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE); - - if ($this->ar_caching === TRUE) + $this->ar_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE); + + if ($this->ar_caching === TRUE) + { + $this->ar_cache_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE); + $this->ar_cache_exists[] = 'from'; + } + } + + } + else { - $this->ar_cache_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE); - $this->ar_cache_exists[] = 'from'; + $val = trim($val); + + // Extract any aliases that might exist. We use this information + // in the _protect_identifiers to know whether to add a table prefix + $this->_track_aliases($val); + + $this->ar_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE); + + if ($this->ar_caching === TRUE) + { + $this->ar_cache_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE); + $this->ar_cache_exists[] = 'from'; + } } } @@ -873,8 +895,30 @@ class CI_DB_active_record extends CI_DB_driver { { $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' '.$direction : ' ASC'; } - - $orderby_statement = $this->_protect_identifiers($orderby).$direction; + + + if (strpos($orderby, ',') !== FALSE) + { + $temp = array(); + foreach (explode(',', $orderby) as $part) + { + $part = trim($part); + if ( ! in_array($part, $this->ar_aliased_tables)) + { + $part = $this->_protect_identifiers(trim($part)); + } + + $temp[] = $part; + } + + $orderby = implode(', ', $temp); + } + else + { + $orderby = $this->_protect_identifiers($orderby); + } + + $orderby_statement = $orderby.$direction; $this->ar_orderby[] = $orderby_statement; if ($this->ar_caching === TRUE) -- cgit v1.2.3-24-g4f1b From 2067d1a727e7eb5e5ffb40e967f3d1fc4c8a41b2 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 13 Nov 2008 22:59:24 +0000 Subject: Changing EOL style to LF --- system/database/DB.php | 290 +- system/database/DB_active_rec.php | 3626 ++++++++++---------- system/database/DB_cache.php | 388 +-- system/database/DB_driver.php | 2636 +++++++------- system/database/DB_forge.php | 708 ++-- system/database/DB_result.php | 682 ++-- system/database/DB_utility.php | 776 ++--- system/database/drivers/index.html | 18 +- system/database/drivers/mssql/index.html | 18 +- system/database/drivers/mssql/mssql_driver.php | 1242 +++---- system/database/drivers/mssql/mssql_forge.php | 494 +-- system/database/drivers/mssql/mssql_result.php | 336 +- system/database/drivers/mssql/mssql_utility.php | 244 +- system/database/drivers/mysql/index.html | 18 +- system/database/drivers/mysql/mysql_driver.php | 1266 +++---- system/database/drivers/mysql/mysql_forge.php | 506 +-- system/database/drivers/mysql/mysql_result.php | 336 +- system/database/drivers/mysql/mysql_utility.php | 488 +-- system/database/drivers/mysqli/index.html | 18 +- system/database/drivers/mysqli/mysqli_driver.php | 1248 +++---- system/database/drivers/mysqli/mysqli_forge.php | 506 +-- system/database/drivers/mysqli/mysqli_result.php | 336 +- system/database/drivers/mysqli/mysqli_utility.php | 244 +- system/database/drivers/oci8/index.html | 18 +- system/database/drivers/oci8/oci8_driver.php | 1472 ++++---- system/database/drivers/oci8/oci8_forge.php | 494 +-- system/database/drivers/oci8/oci8_result.php | 496 +-- system/database/drivers/oci8/oci8_utility.php | 242 +- system/database/drivers/odbc/index.html | 18 +- system/database/drivers/odbc/odbc_driver.php | 1186 +++---- system/database/drivers/odbc/odbc_forge.php | 530 +-- system/database/drivers/odbc/odbc_result.php | 454 +-- system/database/drivers/odbc/odbc_utility.php | 294 +- system/database/drivers/postgre/index.html | 18 +- system/database/drivers/postgre/postgre_driver.php | 1270 +++---- system/database/drivers/postgre/postgre_forge.php | 494 +-- system/database/drivers/postgre/postgre_result.php | 336 +- .../database/drivers/postgre/postgre_utility.php | 246 +- system/database/drivers/sqlite/index.html | 18 +- system/database/drivers/sqlite/sqlite_driver.php | 1222 +++---- system/database/drivers/sqlite/sqlite_forge.php | 528 +-- system/database/drivers/sqlite/sqlite_result.php | 356 +- system/database/drivers/sqlite/sqlite_utility.php | 280 +- system/database/index.html | 18 +- 44 files changed, 13207 insertions(+), 13207 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index 2b3ff3dc6..ca0cfc2e6 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -1,146 +1,146 @@ - $dns['scheme'], - 'hostname' => (isset($dns['host'])) ? rawurldecode($dns['host']) : '', - 'username' => (isset($dns['user'])) ? rawurldecode($dns['user']) : '', - 'password' => (isset($dns['pass'])) ? rawurldecode($dns['pass']) : '', - 'database' => (isset($dns['path'])) ? rawurldecode(substr($dns['path'], 1)) : '' - ); - - // were additional config items set? - if (isset($dns['query'])) - { - parse_str($dns['query'], $extra); - - foreach($extra as $key => $val) - { - // booleans please - if (strtoupper($val) == "TRUE") - { - $val = TRUE; - } - elseif (strtoupper($val) == "FALSE") - { - $val = FALSE; - } - - $params[$key] = $val; - } - } - } - - // No DB specified yet? Beat them senseless... - if ( ! isset($params['dbdriver']) OR $params['dbdriver'] == '') - { - show_error('You have not selected a database type to connect to.'); - } - - // Load the DB classes. Note: Since the active record class is optional - // we need to dynamically create a class that extends proper parent class - // based on whether we're using the active record class or not. - // Kudos to Paul for discovering this clever use of eval() - - if ($active_record_override == TRUE) - { - $active_record = TRUE; - } - - require_once(BASEPATH.'database/DB_driver'.EXT); - - if ( ! isset($active_record) OR $active_record == TRUE) - { - require_once(BASEPATH.'database/DB_active_rec'.EXT); - - if ( ! class_exists('CI_DB')) - { - eval('class CI_DB extends CI_DB_active_record { }'); - } - } - else - { - if ( ! class_exists('CI_DB')) - { - eval('class CI_DB extends CI_DB_driver { }'); - } - } - - require_once(BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver'.EXT); - - // Instantiate the DB adapter - $driver = 'CI_DB_'.$params['dbdriver'].'_driver'; - $DB =& new $driver($params); - - if ($DB->autoinit == TRUE) - { - $DB->initialize(); - } - - return $DB; -} - - - -/* End of file DB.php */ + $dns['scheme'], + 'hostname' => (isset($dns['host'])) ? rawurldecode($dns['host']) : '', + 'username' => (isset($dns['user'])) ? rawurldecode($dns['user']) : '', + 'password' => (isset($dns['pass'])) ? rawurldecode($dns['pass']) : '', + 'database' => (isset($dns['path'])) ? rawurldecode(substr($dns['path'], 1)) : '' + ); + + // were additional config items set? + if (isset($dns['query'])) + { + parse_str($dns['query'], $extra); + + foreach($extra as $key => $val) + { + // booleans please + if (strtoupper($val) == "TRUE") + { + $val = TRUE; + } + elseif (strtoupper($val) == "FALSE") + { + $val = FALSE; + } + + $params[$key] = $val; + } + } + } + + // No DB specified yet? Beat them senseless... + if ( ! isset($params['dbdriver']) OR $params['dbdriver'] == '') + { + show_error('You have not selected a database type to connect to.'); + } + + // Load the DB classes. Note: Since the active record class is optional + // we need to dynamically create a class that extends proper parent class + // based on whether we're using the active record class or not. + // Kudos to Paul for discovering this clever use of eval() + + if ($active_record_override == TRUE) + { + $active_record = TRUE; + } + + require_once(BASEPATH.'database/DB_driver'.EXT); + + if ( ! isset($active_record) OR $active_record == TRUE) + { + require_once(BASEPATH.'database/DB_active_rec'.EXT); + + if ( ! class_exists('CI_DB')) + { + eval('class CI_DB extends CI_DB_active_record { }'); + } + } + else + { + if ( ! class_exists('CI_DB')) + { + eval('class CI_DB extends CI_DB_driver { }'); + } + } + + require_once(BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver'.EXT); + + // Instantiate the DB adapter + $driver = 'CI_DB_'.$params['dbdriver'].'_driver'; + $DB =& new $driver($params); + + if ($DB->autoinit == TRUE) + { + $DB->initialize(); + } + + return $DB; +} + + + +/* End of file DB.php */ /* Location: ./system/database/DB.php */ \ No newline at end of file diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index b270b6fc1..e8cefa2db 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1,1814 +1,1814 @@ -_protect_identifiers = $escape; - } - - if (is_string($select)) - { - $select = explode(',', $select); - } - - foreach ($select as $val) - { - $val = trim($val); - - if ($val != '') - { - $this->ar_select[] = $val; - - if ($this->ar_caching === TRUE) - { - $this->ar_cache_select[] = $val; - $this->ar_cache_exists[] = 'select'; - } - } - } - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Select Max - * - * Generates a SELECT MAX(field) portion of a query - * - * @access public - * @param string the field - * @param string an alias - * @return object - */ - function select_max($select = '', $alias = '') - { - return $this->_max_min_avg_sum($select, $alias, 'MAX'); - } - - // -------------------------------------------------------------------- - - /** - * Select Min - * - * Generates a SELECT MIN(field) portion of a query - * - * @access public - * @param string the field - * @param string an alias - * @return object - */ - function select_min($select = '', $alias = '') - { - return $this->_max_min_avg_sum($select, $alias, 'MIN'); - } - - // -------------------------------------------------------------------- - - /** - * Select Average - * - * Generates a SELECT AVG(field) portion of a query - * - * @access public - * @param string the field - * @param string an alias - * @return object - */ - function select_avg($select = '', $alias = '') - { - return $this->_max_min_avg_sum($select, $alias, 'AVG'); - } - - // -------------------------------------------------------------------- - - /** - * Select Sum - * - * Generates a SELECT SUM(field) portion of a query - * - * @access public - * @param string the field - * @param string an alias - * @return object - */ - function select_sum($select = '', $alias = '') - { - return $this->_max_min_avg_sum($select, $alias, 'SUM'); - } - - // -------------------------------------------------------------------- - - /** - * Processing Function for the four functions above: - * - * select_max() - * select_min() - * select_avg() - * select_sum() - * - * @access public - * @param string the field - * @param string an alias - * @return object - */ - function _max_min_avg_sum($select = '', $alias = '', $type = 'MAX') - { - if ( ! is_string($select) OR $select == '') - { - $this->display_error('db_invalid_query'); - } - - $type = strtoupper($type); - - if ( ! in_array($type, array('MAX', 'MIN', 'AVG', 'SUM'))) - { - show_error('Invalid function type: '.$type); - } - - if ($alias == '') - { - $alias = $this->_create_alias_from_table(trim($select)); - } - - $sql = $type.'('.$this->_protect_identifiers(trim($select)).') AS '.$alias; - - $this->ar_select[] = $sql; - - if ($this->ar_caching === TRUE) - { - $this->ar_cache_select[] = $sql; - $this->ar_cache_exists[] = 'select'; - } - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Determines the alias name based on the table - * - * @access private - * @param string - * @return string - */ - function _create_alias_from_table($item) - { - if (strpos($item, '.') !== FALSE) - { - return end(explode('.', $item)); - } - - return $item; - } - - // -------------------------------------------------------------------- - - /** - * DISTINCT - * - * Sets a flag which tells the query string compiler to add DISTINCT - * - * @access public - * @param bool - * @return object - */ - function distinct($val = TRUE) - { - $this->ar_distinct = (is_bool($val)) ? $val : TRUE; - return $this; - } - - // -------------------------------------------------------------------- - - /** - * From - * - * Generates the FROM portion of the query - * - * @access public - * @param mixed can be a string or array - * @return object - */ - function from($from) - { - foreach ((array)$from as $val) - { - if (strpos($val, ',') !== FALSE) - { - foreach (explode(',', $val) as $v) - { - $v = trim($v); - $this->_track_aliases($v); - - $this->ar_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE); - - if ($this->ar_caching === TRUE) - { - $this->ar_cache_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE); - $this->ar_cache_exists[] = 'from'; - } - } - - } - else - { - $val = trim($val); - - // Extract any aliases that might exist. We use this information - // in the _protect_identifiers to know whether to add a table prefix - $this->_track_aliases($val); - - $this->ar_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE); - - if ($this->ar_caching === TRUE) - { - $this->ar_cache_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE); - $this->ar_cache_exists[] = 'from'; - } - } - } - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Join - * - * Generates the JOIN portion of the query - * - * @access public - * @param string - * @param string the join condition - * @param string the type of join - * @return object - */ - function join($table, $cond, $type = '') - { - if ($type != '') - { - $type = strtoupper(trim($type)); - - if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'))) - { - $type = ''; - } - else - { - $type .= ' '; - } - } - - // Extract any aliases that might exist. We use this information - // in the _protect_identifiers to know whether to add a table prefix - $this->_track_aliases($table); - - // Strip apart the condition and protect the identifiers - if (preg_match('/([\w\.]+)([\W\s]+)(.+)/', $cond, $match)) - { - $match[1] = $this->_protect_identifiers($match[1]); - $match[3] = $this->_protect_identifiers($match[3]); - - $cond = $match[1].$match[2].$match[3]; - } - - // Assemble the JOIN statement - $join = $type.'JOIN '.$this->_protect_identifiers($table, TRUE, NULL, FALSE).' ON '.$cond; - - $this->ar_join[] = $join; - if ($this->ar_caching === TRUE) - { - $this->ar_cache_join[] = $join; - $this->ar_cache_exists[] = 'join'; - } - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Where - * - * Generates the WHERE portion of the query. Separates - * multiple calls with AND - * - * @access public - * @param mixed - * @param mixed - * @return object - */ - function where($key, $value = NULL, $escape = TRUE) - { - return $this->_where($key, $value, 'AND ', $escape); - } - - // -------------------------------------------------------------------- - - /** - * OR Where - * - * Generates the WHERE portion of the query. Separates - * multiple calls with OR - * - * @access public - * @param mixed - * @param mixed - * @return object - */ - function or_where($key, $value = NULL, $escape = TRUE) - { - return $this->_where($key, $value, 'OR ', $escape); - } - - // -------------------------------------------------------------------- - - /** - * orwhere() is an alias of or_where() - * this function is here for backwards compatibility, as - * orwhere() has been deprecated - */ - function orwhere($key, $value = NULL, $escape = TRUE) - { - return $this->or_where($key, $value, $escape); - } - - // -------------------------------------------------------------------- - - /** - * Where - * - * Called by where() or orwhere() - * - * @access private - * @param mixed - * @param mixed - * @param string - * @return object - */ - function _where($key, $value = NULL, $type = 'AND ', $escape = NULL) - { - if ( ! is_array($key)) - { - $key = array($key => $value); - } - - // If the escape value was not set will will base it on the global setting - if ( ! is_bool($escape)) - { - $escape = $this->_protect_identifiers; - } - - foreach ($key as $k => $v) - { - $prefix = (count($this->ar_where) == 0 AND count($this->ar_cache_where) == 0) ? '' : $type; - - if (is_null($v) && ! $this->_has_operator($k)) - { - // value appears not to have been set, assign the test to IS NULL - $k .= ' IS NULL'; - } - - if ( ! is_null($v)) - { - if ($escape === TRUE) - { - $k = $this->_protect_identifiers($k, FALSE, $escape); - - $v = ' '.$this->escape($v); - } - - if ( ! $this->_has_operator($k)) - { - $k .= ' ='; - } - } - else - { - $k = $this->_protect_identifiers($k, FALSE, $escape); - } - - $this->ar_where[] = $prefix.$k.$v; - - if ($this->ar_caching === TRUE) - { - $this->ar_cache_where[] = $prefix.$k.$v; - $this->ar_cache_exists[] = 'where'; - } - - } - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Where_in - * - * Generates a WHERE field IN ('item', 'item') SQL query joined with - * AND if appropriate - * - * @access public - * @param string The field to search - * @param array The values searched on - * @return object - */ - function where_in($key = NULL, $values = NULL) - { - return $this->_where_in($key, $values); - } - - // -------------------------------------------------------------------- - - /** - * Where_in_or - * - * Generates a WHERE field IN ('item', 'item') SQL query joined with - * OR if appropriate - * - * @access public - * @param string The field to search - * @param array The values searched on - * @return object - */ - function or_where_in($key = NULL, $values = NULL) - { - return $this->_where_in($key, $values, FALSE, 'OR '); - } - - // -------------------------------------------------------------------- - - /** - * Where_not_in - * - * Generates a WHERE field NOT IN ('item', 'item') SQL query joined - * with AND if appropriate - * - * @access public - * @param string The field to search - * @param array The values searched on - * @return object - */ - function where_not_in($key = NULL, $values = NULL) - { - return $this->_where_in($key, $values, TRUE); - } - - // -------------------------------------------------------------------- - - /** - * Where_not_in_or - * - * Generates a WHERE field NOT IN ('item', 'item') SQL query joined - * with OR if appropriate - * - * @access public - * @param string The field to search - * @param array The values searched on - * @return object - */ - function or_where_not_in($key = NULL, $values = NULL) - { - return $this->_where_in($key, $values, TRUE, 'OR '); - } - - // -------------------------------------------------------------------- - - /** - * Where_in - * - * Called by where_in, where_in_or, where_not_in, where_not_in_or - * - * @access public - * @param string The field to search - * @param array The values searched on - * @param boolean If the statement would be IN or NOT IN - * @param string - * @return object - */ - function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ') - { - if ($key === NULL OR $values === NULL) - { - return; - } - - if ( ! is_array($values)) - { - $values = array($values); - } - - $not = ($not) ? ' NOT' : ''; - - foreach ($values as $value) - { - $this->ar_wherein[] = $this->escape($value); - } - - $prefix = (count($this->ar_where) == 0) ? '' : $type; - - $where_in = $prefix . $this->_protect_identifiers($key) . $not . " IN (" . implode(", ", $this->ar_wherein) . ") "; - - $this->ar_where[] = $where_in; - if ($this->ar_caching === TRUE) - { - $this->ar_cache_where[] = $where_in; - $this->ar_cache_exists[] = 'where'; - } - - // reset the array for multiple calls - $this->ar_wherein = array(); - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Like - * - * Generates a %LIKE% portion of the query. Separates - * multiple calls with AND - * - * @access public - * @param mixed - * @param mixed - * @return object - */ - function like($field, $match = '', $side = 'both') - { - return $this->_like($field, $match, 'AND ', $side); - } - - // -------------------------------------------------------------------- - - /** - * Not Like - * - * Generates a NOT LIKE portion of the query. Separates - * multiple calls with AND - * - * @access public - * @param mixed - * @param mixed - * @return object - */ - function not_like($field, $match = '', $side = 'both') - { - return $this->_like($field, $match, 'AND ', $side, 'NOT'); - } - - // -------------------------------------------------------------------- - - /** - * OR Like - * - * Generates a %LIKE% portion of the query. Separates - * multiple calls with OR - * - * @access public - * @param mixed - * @param mixed - * @return object - */ - function or_like($field, $match = '', $side = 'both') - { - return $this->_like($field, $match, 'OR ', $side); - } - - // -------------------------------------------------------------------- - - /** - * OR Not Like - * - * Generates a NOT LIKE portion of the query. Separates - * multiple calls with OR - * - * @access public - * @param mixed - * @param mixed - * @return object - */ - function or_not_like($field, $match = '', $side = 'both') - { - return $this->_like($field, $match, 'OR ', $side, 'NOT'); - } - - // -------------------------------------------------------------------- - - /** - * orlike() is an alias of or_like() - * this function is here for backwards compatibility, as - * orlike() has been deprecated - */ - function orlike($field, $match = '', $side = 'both') - { - return $this->or_like($field, $match, $side); - } - - // -------------------------------------------------------------------- - - /** - * Like - * - * Called by like() or orlike() - * - * @access private - * @param mixed - * @param mixed - * @param string - * @return object - */ - function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '') - { - if ( ! is_array($field)) - { - $field = array($field => $match); - } - - foreach ($field as $k => $v) - { - $k = $this->_protect_identifiers($k); - - $prefix = (count($this->ar_like) == 0) ? '' : $type; - - $v = $this->escape_str($v); - - if ($side == 'before') - { - $like_statement = $prefix." $k $not LIKE '%{$v}'"; - } - elseif ($side == 'after') - { - $like_statement = $prefix." $k $not LIKE '{$v}%'"; - } - else - { - $like_statement = $prefix." $k $not LIKE '%{$v}%'"; - } - - $this->ar_like[] = $like_statement; - if ($this->ar_caching === TRUE) - { - $this->ar_cache_like[] = $like_statement; - $this->ar_cache_exists[] = 'like'; - } - - } - return $this; - } - - // -------------------------------------------------------------------- - - /** - * GROUP BY - * - * @access public - * @param string - * @return object - */ - function group_by($by) - { - if (is_string($by)) - { - $by = explode(',', $by); - } - - foreach ($by as $val) - { - $val = trim($val); - - if ($val != '') - { - $this->ar_groupby[] = $this->_protect_identifiers($val); - - if ($this->ar_caching === TRUE) - { - $this->ar_cache_groupby[] = $this->_protect_identifiers($val); - $this->ar_cache_exists[] = 'groupby'; - } - } - } - return $this; - } - - // -------------------------------------------------------------------- - - /** - * groupby() is an alias of group_by() - * this function is here for backwards compatibility, as - * groupby() has been deprecated - */ - function groupby($by) - { - return $this->group_by($by); - } - - // -------------------------------------------------------------------- - - /** - * Sets the HAVING value - * - * Separates multiple calls with AND - * - * @access public - * @param string - * @param string - * @return object - */ - function having($key, $value = '', $escape = TRUE) - { - return $this->_having($key, $value, 'AND ', $escape); - } - - // -------------------------------------------------------------------- - - /** - * orhaving() is an alias of or_having() - * this function is here for backwards compatibility, as - * orhaving() has been deprecated - */ - - function orhaving($key, $value = '', $escape = TRUE) - { - return $this->or_having($key, $value, $escape); - } - // -------------------------------------------------------------------- - - /** - * Sets the OR HAVING value - * - * Separates multiple calls with OR - * - * @access public - * @param string - * @param string - * @return object - */ - function or_having($key, $value = '', $escape = TRUE) - { - return $this->_having($key, $value, 'OR ', $escape); - } - - // -------------------------------------------------------------------- - - /** - * Sets the HAVING values - * - * Called by having() or or_having() - * - * @access private - * @param string - * @param string - * @return object - */ - function _having($key, $value = '', $type = 'AND ', $escape = TRUE) - { - if ( ! is_array($key)) - { - $key = array($key => $value); - } - - foreach ($key as $k => $v) - { - $prefix = (count($this->ar_having) == 0) ? '' : $type; - - if ($escape === TRUE) - { - $k = $this->_protect_identifiers($k); - } - - if ( ! $this->_has_operator($k)) - { - $k .= ' = '; - } - - if ($v != '') - { - $v = ' '.$this->escape_str($v); - } - - $this->ar_having[] = $prefix.$k.$v; - if ($this->ar_caching === TRUE) - { - $this->ar_cache_having[] = $prefix.$k.$v; - $this->ar_cache_exists[] = 'having'; - } - } - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Sets the ORDER BY value - * - * @access public - * @param string - * @param string direction: asc or desc - * @return object - */ - function order_by($orderby, $direction = '') - { - if (strtolower($direction) == 'random') - { - $orderby = ''; // Random results want or don't need a field name - $direction = $this->_random_keyword; - } - elseif (trim($direction) != '') - { - $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' '.$direction : ' ASC'; - } - - - if (strpos($orderby, ',') !== FALSE) - { - $temp = array(); - foreach (explode(',', $orderby) as $part) - { - $part = trim($part); - if ( ! in_array($part, $this->ar_aliased_tables)) - { - $part = $this->_protect_identifiers(trim($part)); - } - - $temp[] = $part; - } - - $orderby = implode(', ', $temp); - } - else - { - $orderby = $this->_protect_identifiers($orderby); - } - - $orderby_statement = $orderby.$direction; - - $this->ar_orderby[] = $orderby_statement; - if ($this->ar_caching === TRUE) - { - $this->ar_cache_orderby[] = $orderby_statement; - $this->ar_cache_exists[] = 'orderby'; - } - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * orderby() is an alias of order_by() - * this function is here for backwards compatibility, as - * orderby() has been deprecated - */ - function orderby($orderby, $direction = '') - { - return $this->order_by($orderby, $direction); - } - - // -------------------------------------------------------------------- - - /** - * Sets the LIMIT value - * - * @access public - * @param integer the limit value - * @param integer the offset value - * @return object - */ - function limit($value, $offset = '') - { - $this->ar_limit = $value; - - if ($offset != '') - { - $this->ar_offset = $offset; - } - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Sets the OFFSET value - * - * @access public - * @param integer the offset value - * @return object - */ - function offset($offset) - { - $this->ar_offset = $offset; - return $this; - } - - // -------------------------------------------------------------------- - - /** - * The "set" function. Allows key/value pairs to be set for inserting or updating - * - * @access public - * @param mixed - * @param string - * @param boolean - * @return object - */ - function set($key, $value = '', $escape = TRUE) - { - $key = $this->_object_to_array($key); - - if ( ! is_array($key)) - { - $key = array($key => $value); - } - - foreach ($key as $k => $v) - { - if ($escape === FALSE) - { - $this->ar_set[$this->_protect_identifiers($k)] = $v; - } - else - { - $this->ar_set[$this->_protect_identifiers($k)] = $this->escape($v); - } - } - - return $this; - } - - // -------------------------------------------------------------------- - - /** - * Get - * - * Compiles the select statement based on the other functions called - * and runs the query - * - * @access public - * @param string the table - * @param string the limit clause - * @param string the offset clause - * @return object - */ - function get($table = '', $limit = null, $offset = null) - { - if ($table != '') - { - $this->_track_aliases($table); - $this->from($table); - } - - if ( ! is_null($limit)) - { - $this->limit($limit, $offset); - } - - $sql = $this->_compile_select(); - - $result = $this->query($sql); - $this->_reset_select(); - return $result; - } - - /** - * "Count All Results" query - * - * Generates a platform-specific query string that counts all records - * returned by an Active Record query. - * - * @access public - * @param string - * @return string - */ - function count_all_results($table = '') - { - if ($table != '') - { - $this->_track_aliases($table); - $this->from($table); - } - - $sql = $this->_compile_select($this->_count_string . $this->_protect_identifiers('numrows')); - - $query = $this->query($sql); - $this->_reset_select(); - - if ($query->num_rows() == 0) - { - return '0'; - } - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * Get_Where - * - * Allows the where clause, limit and offset to be added directly - * - * @access public - * @param string the where clause - * @param string the limit clause - * @param string the offset clause - * @return object - */ - function get_where($table = '', $where = null, $limit = null, $offset = null) - { - if ($table != '') - { - $this->from($table); - } - - if ( ! is_null($where)) - { - $this->where($where); - } - - if ( ! is_null($limit)) - { - $this->limit($limit, $offset); - } - - $sql = $this->_compile_select(); - - $result = $this->query($sql); - $this->_reset_select(); - return $result; - } - - // -------------------------------------------------------------------- - - /** - * getwhere() is an alias of get_where() - * this function is here for backwards compatibility, as - * getwhere() has been deprecated - */ - function getwhere($table = '', $where = null, $limit = null, $offset = null) - { - return $this->get_where($table, $where, $limit, $offset); - } - - // -------------------------------------------------------------------- - - /** - * Insert - * - * Compiles an insert string and runs the query - * - * @access public - * @param string the table to retrieve the results from - * @param array an associative array of insert values - * @return object - */ - function insert($table = '', $set = NULL) - { - if ( ! is_null($set)) - { - $this->set($set); - } - - if (count($this->ar_set) == 0) - { - if ($this->db_debug) - { - return $this->display_error('db_must_use_set'); - } - return FALSE; - } - - if ($table == '') - { - if ( ! isset($this->ar_from[0])) - { - if ($this->db_debug) - { - return $this->display_error('db_must_set_table'); - } - return FALSE; - } - - $table = $this->ar_from[0]; - } - - $sql = $this->_insert($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->ar_set), array_values($this->ar_set)); - - $this->_reset_write(); - return $this->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Update - * - * Compiles an update string and runs the query - * - * @access public - * @param string the table to retrieve the results from - * @param array an associative array of update values - * @param mixed the where clause - * @return object - */ - function update($table = '', $set = NULL, $where = NULL, $limit = NULL) - { - // Combine any cached components with the current statements - $this->_merge_cache(); - - if ( ! is_null($set)) - { - $this->set($set); - } - - if (count($this->ar_set) == 0) - { - if ($this->db_debug) - { - return $this->display_error('db_must_use_set'); - } - return FALSE; - } - - if ($table == '') - { - if ( ! isset($this->ar_from[0])) - { - if ($this->db_debug) - { - return $this->display_error('db_must_set_table'); - } - return FALSE; - } - - $table = $this->ar_from[0]; - } - - if ($where != NULL) - { - $this->where($where); - } - - if ($limit != NULL) - { - $this->limit($limit); - } - - $sql = $this->_update($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit); - - $this->_reset_write(); - return $this->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Empty Table - * - * Compiles a delete string and runs "DELETE FROM table" - * - * @access public - * @param string the table to empty - * @return object - */ - function empty_table($table = '') - { - if ($table == '') - { - if ( ! isset($this->ar_from[0])) - { - if ($this->db_debug) - { - return $this->display_error('db_must_set_table'); - } - return FALSE; - } - - $table = $this->ar_from[0]; - } - else - { - $table = $this->_protect_identifiers($table, TRUE, NULL, FALSE); - } - - $sql = $this->_delete($table); - - $this->_reset_write(); - - return $this->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Truncate - * - * Compiles a truncate string and runs the query - * If the database does not support the truncate() command - * This function maps to "DELETE FROM table" - * - * @access public - * @param string the table to truncate - * @return object - */ - function truncate($table = '') - { - if ($table == '') - { - if ( ! isset($this->ar_from[0])) - { - if ($this->db_debug) - { - return $this->display_error('db_must_set_table'); - } - return FALSE; - } - - $table = $this->ar_from[0]; - } - else - { - $table = $this->_protect_identifiers($table, TRUE, NULL, FALSE); - } - - $sql = $this->_truncate($table); - - $this->_reset_write(); - - return $this->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Delete - * - * Compiles a delete string and runs the query - * - * @access public - * @param mixed the table(s) to delete from. String or array - * @param mixed the where clause - * @param mixed the limit clause - * @param boolean - * @return object - */ - function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE) - { - // Combine any cached components with the current statements - $this->_merge_cache(); - - if ($table == '') - { - if ( ! isset($this->ar_from[0])) - { - if ($this->db_debug) - { - return $this->display_error('db_must_set_table'); - } - return FALSE; - } - - $table = $this->ar_from[0]; - } - elseif (is_array($table)) - { - foreach($table as $single_table) - { - $this->delete($single_table, $where, $limit, FALSE); - } - - $this->_reset_write(); - return; - } - else - { - $table = $this->_protect_identifiers($table, TRUE, NULL, FALSE); - } - - if ($where != '') - { - $this->where($where); - } - - if ($limit != NULL) - { - $this->limit($limit); - } - - if (count($this->ar_where) == 0 && count($this->ar_like) == 0) - { - if ($this->db_debug) - { - return $this->display_error('db_del_must_use_where'); - } - - return FALSE; - } - - $sql = $this->_delete($table, $this->ar_where, $this->ar_like, $this->ar_limit); - - if ($reset_data) - { - $this->_reset_write(); - } - - return $this->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * DB Prefix - * - * Prepends a database prefix if one exists in configuration - * - * @access public - * @param string the table - * @return string - */ - function dbprefix($table = '') - { - if ($table == '') - { - $this->display_error('db_table_name_required'); - } - - return $this->dbprefix.$table; - } - - // -------------------------------------------------------------------- - - /** - * Track Aliases - * - * Used to track SQL statements written with aliased tables. - * - * @access private - * @param string The table to inspect - * @return string - */ - function _track_aliases($table) - { - if (is_array($table)) - { - foreach ($table as $t) - { - $this->_track_aliases($t); - } - return; - } - - // Does the string contain a comma? If so, we need to separate - // the string into discreet statements - if (strpos($table, ',') !== FALSE) - { - return $this->_track_aliases(explode(',', $table)); - } - - // if a table alias is used we can recognize it by a space - if (strpos($table, " ") !== FALSE) - { - // if the alias is written with the AS keyword, remove it - $table = preg_replace('/ AS /i', ' ', $table); - - // Grab the alias - $table = trim(strrchr($table, " ")); - - // Store the alias, if it doesn't already exist - if ( ! in_array($table, $this->ar_aliased_tables)) - { - $this->ar_aliased_tables[] = $table; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Compile the SELECT statement - * - * Generates a query string based on which functions were used. - * Should not be called directly. The get() function calls it. - * - * @access private - * @return string - */ - function _compile_select($select_override = FALSE) - { - // Combine any cached components with the current statements - $this->_merge_cache(); - - // ---------------------------------------------------------------- - - // Write the "select" portion of the query - - if ($select_override !== FALSE) - { - $sql = $select_override; - } - else - { - $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; - - if (count($this->ar_select) == 0) - { - $sql .= '*'; - } - else - { - // Cycle through the "select" portion of the query and prep each column name. - // The reason we protect identifiers here rather then in the select() function - // is because until the user calls the from() function we don't know if there are aliases - foreach ($this->ar_select as $key => $val) - { - $this->ar_select[$key] = $this->_protect_identifiers($val); - } - - $sql .= implode(', ', $this->ar_select); - } - } - - // ---------------------------------------------------------------- - - // Write the "FROM" portion of the query - - if (count($this->ar_from) > 0) - { - $sql .= "\nFROM "; - - $sql .= $this->_from_tables($this->ar_from); - } - - // ---------------------------------------------------------------- - - // Write the "JOIN" portion of the query - - if (count($this->ar_join) > 0) - { - $sql .= "\n"; - - $sql .= implode("\n", $this->ar_join); - } - - // ---------------------------------------------------------------- - - // Write the "WHERE" portion of the query - - if (count($this->ar_where) > 0 OR count($this->ar_like) > 0) - { - $sql .= "\n"; - - $sql .= "WHERE "; - } - - $sql .= implode("\n", $this->ar_where); - - // ---------------------------------------------------------------- - - // Write the "LIKE" portion of the query - - if (count($this->ar_like) > 0) - { - if (count($this->ar_where) > 0) - { - $sql .= "\nAND "; - } - - $sql .= implode("\n", $this->ar_like); - } - - // ---------------------------------------------------------------- - - // Write the "GROUP BY" portion of the query - - if (count($this->ar_groupby) > 0) - { - $sql .= "\nGROUP BY "; - - $sql .= implode(', ', $this->ar_groupby); - } - - // ---------------------------------------------------------------- - - // Write the "HAVING" portion of the query - - if (count($this->ar_having) > 0) - { - $sql .= "\nHAVING "; - $sql .= implode("\n", $this->ar_having); - } - - // ---------------------------------------------------------------- - - // Write the "ORDER BY" portion of the query - - if (count($this->ar_orderby) > 0) - { - $sql .= "\nORDER BY "; - $sql .= implode(', ', $this->ar_orderby); - - if ($this->ar_order !== FALSE) - { - $sql .= ($this->ar_order == 'desc') ? ' DESC' : ' ASC'; - } - } - - // ---------------------------------------------------------------- - - // Write the "LIMIT" portion of the query - - if (is_numeric($this->ar_limit)) - { - $sql .= "\n"; - $sql = $this->_limit($sql, $this->ar_limit, $this->ar_offset); - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Object to Array - * - * Takes an object as input and converts the class variables to array key/vals - * - * @access public - * @param object - * @return array - */ - function _object_to_array($object) - { - if ( ! is_object($object)) - { - return $object; - } - - $array = array(); - foreach (get_object_vars($object) as $key => $val) - { - // There are some built in keys we need to ignore for this conversion - if ( ! is_object($val) && ! is_array($val) && $key != '_parent_name' && $key != '_ci_scaffolding' && $key != '_ci_scaff_table') - { - $array[$key] = $val; - } - } - - return $array; - } - - // -------------------------------------------------------------------- - - /** - * Start Cache - * - * Starts AR caching - * - * @access public - * @return void - */ - function start_cache() - { - $this->ar_caching = TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Stop Cache - * - * Stops AR caching - * - * @access public - * @return void - */ - function stop_cache() - { - $this->ar_caching = FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Flush Cache - * - * Empties the AR cache - * - * @access public - * @return void - */ - function flush_cache() - { - $this->_reset_run( - array( - 'ar_cache_select' => array(), - 'ar_cache_from' => array(), - 'ar_cache_join' => array(), - 'ar_cache_where' => array(), - 'ar_cache_like' => array(), - 'ar_cache_groupby' => array(), - 'ar_cache_having' => array(), - 'ar_cache_orderby' => array(), - 'ar_cache_set' => array(), - 'ar_cache_exists' => array() - ) - ); - } - - // -------------------------------------------------------------------- - - /** - * Merge Cache - * - * When called, this function merges any cached AR arrays with - * locally called ones. - * - * @access private - * @return void - */ - function _merge_cache() - { - if (count($this->ar_cache_exists) == 0) - { - return; - } - - foreach ($this->ar_cache_exists as $val) - { - $ar_variable = 'ar_'.$val; - $ar_cache_var = 'ar_cache_'.$val; - - if (count($this->$ar_cache_var) == 0) - { - continue; - } - - $this->$ar_variable = array_unique(array_merge($this->$ar_cache_var, $this->$ar_variable)); - } - - // If we are "protecting identifiers" we need to examine the "from" - // portion of the query to determine if there are any aliases - if ($this->_protect_identifiers === TRUE AND count($this->ar_cache_from) > 0) - { - $this->_track_aliases($this->ar_from); - } - } - - // -------------------------------------------------------------------- - - /** - * Resets the active record values. Called by the get() function - * - * @access private - * @param array An array of fields to reset - * @return void - */ - function _reset_run($ar_reset_items) - { - foreach ($ar_reset_items as $item => $default_value) - { - if ( ! in_array($item, $this->ar_store_array)) - { - $this->$item = $default_value; - } - } - } - - // -------------------------------------------------------------------- - - /** - * Resets the active record values. Called by the get() function - * - * @access private - * @return void - */ - function _reset_select() - { - $ar_reset_items = array( - 'ar_select' => array(), - 'ar_from' => array(), - 'ar_join' => array(), - 'ar_where' => array(), - 'ar_like' => array(), - 'ar_groupby' => array(), - 'ar_having' => array(), - 'ar_orderby' => array(), - 'ar_wherein' => array(), - 'ar_aliased_tables' => array(), - 'ar_distinct' => FALSE, - 'ar_limit' => FALSE, - 'ar_offset' => FALSE, - 'ar_order' => FALSE, - ); - - $this->_reset_run($ar_reset_items); - } - - // -------------------------------------------------------------------- - - /** - * Resets the active record "write" values. - * - * Called by the insert() update() and delete() functions - * - * @access private - * @return void - */ - function _reset_write() - { - $ar_reset_items = array( - 'ar_set' => array(), - 'ar_from' => array(), - 'ar_where' => array(), - 'ar_like' => array(), - 'ar_orderby' => array(), - 'ar_limit' => FALSE, - 'ar_order' => FALSE - ); - - $this->_reset_run($ar_reset_items); - } - -} - -/* End of file DB_active_rec.php */ +_protect_identifiers = $escape; + } + + if (is_string($select)) + { + $select = explode(',', $select); + } + + foreach ($select as $val) + { + $val = trim($val); + + if ($val != '') + { + $this->ar_select[] = $val; + + if ($this->ar_caching === TRUE) + { + $this->ar_cache_select[] = $val; + $this->ar_cache_exists[] = 'select'; + } + } + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Select Max + * + * Generates a SELECT MAX(field) portion of a query + * + * @access public + * @param string the field + * @param string an alias + * @return object + */ + function select_max($select = '', $alias = '') + { + return $this->_max_min_avg_sum($select, $alias, 'MAX'); + } + + // -------------------------------------------------------------------- + + /** + * Select Min + * + * Generates a SELECT MIN(field) portion of a query + * + * @access public + * @param string the field + * @param string an alias + * @return object + */ + function select_min($select = '', $alias = '') + { + return $this->_max_min_avg_sum($select, $alias, 'MIN'); + } + + // -------------------------------------------------------------------- + + /** + * Select Average + * + * Generates a SELECT AVG(field) portion of a query + * + * @access public + * @param string the field + * @param string an alias + * @return object + */ + function select_avg($select = '', $alias = '') + { + return $this->_max_min_avg_sum($select, $alias, 'AVG'); + } + + // -------------------------------------------------------------------- + + /** + * Select Sum + * + * Generates a SELECT SUM(field) portion of a query + * + * @access public + * @param string the field + * @param string an alias + * @return object + */ + function select_sum($select = '', $alias = '') + { + return $this->_max_min_avg_sum($select, $alias, 'SUM'); + } + + // -------------------------------------------------------------------- + + /** + * Processing Function for the four functions above: + * + * select_max() + * select_min() + * select_avg() + * select_sum() + * + * @access public + * @param string the field + * @param string an alias + * @return object + */ + function _max_min_avg_sum($select = '', $alias = '', $type = 'MAX') + { + if ( ! is_string($select) OR $select == '') + { + $this->display_error('db_invalid_query'); + } + + $type = strtoupper($type); + + if ( ! in_array($type, array('MAX', 'MIN', 'AVG', 'SUM'))) + { + show_error('Invalid function type: '.$type); + } + + if ($alias == '') + { + $alias = $this->_create_alias_from_table(trim($select)); + } + + $sql = $type.'('.$this->_protect_identifiers(trim($select)).') AS '.$alias; + + $this->ar_select[] = $sql; + + if ($this->ar_caching === TRUE) + { + $this->ar_cache_select[] = $sql; + $this->ar_cache_exists[] = 'select'; + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Determines the alias name based on the table + * + * @access private + * @param string + * @return string + */ + function _create_alias_from_table($item) + { + if (strpos($item, '.') !== FALSE) + { + return end(explode('.', $item)); + } + + return $item; + } + + // -------------------------------------------------------------------- + + /** + * DISTINCT + * + * Sets a flag which tells the query string compiler to add DISTINCT + * + * @access public + * @param bool + * @return object + */ + function distinct($val = TRUE) + { + $this->ar_distinct = (is_bool($val)) ? $val : TRUE; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * From + * + * Generates the FROM portion of the query + * + * @access public + * @param mixed can be a string or array + * @return object + */ + function from($from) + { + foreach ((array)$from as $val) + { + if (strpos($val, ',') !== FALSE) + { + foreach (explode(',', $val) as $v) + { + $v = trim($v); + $this->_track_aliases($v); + + $this->ar_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE); + + if ($this->ar_caching === TRUE) + { + $this->ar_cache_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE); + $this->ar_cache_exists[] = 'from'; + } + } + + } + else + { + $val = trim($val); + + // Extract any aliases that might exist. We use this information + // in the _protect_identifiers to know whether to add a table prefix + $this->_track_aliases($val); + + $this->ar_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE); + + if ($this->ar_caching === TRUE) + { + $this->ar_cache_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE); + $this->ar_cache_exists[] = 'from'; + } + } + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Join + * + * Generates the JOIN portion of the query + * + * @access public + * @param string + * @param string the join condition + * @param string the type of join + * @return object + */ + function join($table, $cond, $type = '') + { + if ($type != '') + { + $type = strtoupper(trim($type)); + + if ( ! in_array($type, array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'))) + { + $type = ''; + } + else + { + $type .= ' '; + } + } + + // Extract any aliases that might exist. We use this information + // in the _protect_identifiers to know whether to add a table prefix + $this->_track_aliases($table); + + // Strip apart the condition and protect the identifiers + if (preg_match('/([\w\.]+)([\W\s]+)(.+)/', $cond, $match)) + { + $match[1] = $this->_protect_identifiers($match[1]); + $match[3] = $this->_protect_identifiers($match[3]); + + $cond = $match[1].$match[2].$match[3]; + } + + // Assemble the JOIN statement + $join = $type.'JOIN '.$this->_protect_identifiers($table, TRUE, NULL, FALSE).' ON '.$cond; + + $this->ar_join[] = $join; + if ($this->ar_caching === TRUE) + { + $this->ar_cache_join[] = $join; + $this->ar_cache_exists[] = 'join'; + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Where + * + * Generates the WHERE portion of the query. Separates + * multiple calls with AND + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function where($key, $value = NULL, $escape = TRUE) + { + return $this->_where($key, $value, 'AND ', $escape); + } + + // -------------------------------------------------------------------- + + /** + * OR Where + * + * Generates the WHERE portion of the query. Separates + * multiple calls with OR + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function or_where($key, $value = NULL, $escape = TRUE) + { + return $this->_where($key, $value, 'OR ', $escape); + } + + // -------------------------------------------------------------------- + + /** + * orwhere() is an alias of or_where() + * this function is here for backwards compatibility, as + * orwhere() has been deprecated + */ + function orwhere($key, $value = NULL, $escape = TRUE) + { + return $this->or_where($key, $value, $escape); + } + + // -------------------------------------------------------------------- + + /** + * Where + * + * Called by where() or orwhere() + * + * @access private + * @param mixed + * @param mixed + * @param string + * @return object + */ + function _where($key, $value = NULL, $type = 'AND ', $escape = NULL) + { + if ( ! is_array($key)) + { + $key = array($key => $value); + } + + // If the escape value was not set will will base it on the global setting + if ( ! is_bool($escape)) + { + $escape = $this->_protect_identifiers; + } + + foreach ($key as $k => $v) + { + $prefix = (count($this->ar_where) == 0 AND count($this->ar_cache_where) == 0) ? '' : $type; + + if (is_null($v) && ! $this->_has_operator($k)) + { + // value appears not to have been set, assign the test to IS NULL + $k .= ' IS NULL'; + } + + if ( ! is_null($v)) + { + if ($escape === TRUE) + { + $k = $this->_protect_identifiers($k, FALSE, $escape); + + $v = ' '.$this->escape($v); + } + + if ( ! $this->_has_operator($k)) + { + $k .= ' ='; + } + } + else + { + $k = $this->_protect_identifiers($k, FALSE, $escape); + } + + $this->ar_where[] = $prefix.$k.$v; + + if ($this->ar_caching === TRUE) + { + $this->ar_cache_where[] = $prefix.$k.$v; + $this->ar_cache_exists[] = 'where'; + } + + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Where_in + * + * Generates a WHERE field IN ('item', 'item') SQL query joined with + * AND if appropriate + * + * @access public + * @param string The field to search + * @param array The values searched on + * @return object + */ + function where_in($key = NULL, $values = NULL) + { + return $this->_where_in($key, $values); + } + + // -------------------------------------------------------------------- + + /** + * Where_in_or + * + * Generates a WHERE field IN ('item', 'item') SQL query joined with + * OR if appropriate + * + * @access public + * @param string The field to search + * @param array The values searched on + * @return object + */ + function or_where_in($key = NULL, $values = NULL) + { + return $this->_where_in($key, $values, FALSE, 'OR '); + } + + // -------------------------------------------------------------------- + + /** + * Where_not_in + * + * Generates a WHERE field NOT IN ('item', 'item') SQL query joined + * with AND if appropriate + * + * @access public + * @param string The field to search + * @param array The values searched on + * @return object + */ + function where_not_in($key = NULL, $values = NULL) + { + return $this->_where_in($key, $values, TRUE); + } + + // -------------------------------------------------------------------- + + /** + * Where_not_in_or + * + * Generates a WHERE field NOT IN ('item', 'item') SQL query joined + * with OR if appropriate + * + * @access public + * @param string The field to search + * @param array The values searched on + * @return object + */ + function or_where_not_in($key = NULL, $values = NULL) + { + return $this->_where_in($key, $values, TRUE, 'OR '); + } + + // -------------------------------------------------------------------- + + /** + * Where_in + * + * Called by where_in, where_in_or, where_not_in, where_not_in_or + * + * @access public + * @param string The field to search + * @param array The values searched on + * @param boolean If the statement would be IN or NOT IN + * @param string + * @return object + */ + function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ') + { + if ($key === NULL OR $values === NULL) + { + return; + } + + if ( ! is_array($values)) + { + $values = array($values); + } + + $not = ($not) ? ' NOT' : ''; + + foreach ($values as $value) + { + $this->ar_wherein[] = $this->escape($value); + } + + $prefix = (count($this->ar_where) == 0) ? '' : $type; + + $where_in = $prefix . $this->_protect_identifiers($key) . $not . " IN (" . implode(", ", $this->ar_wherein) . ") "; + + $this->ar_where[] = $where_in; + if ($this->ar_caching === TRUE) + { + $this->ar_cache_where[] = $where_in; + $this->ar_cache_exists[] = 'where'; + } + + // reset the array for multiple calls + $this->ar_wherein = array(); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Like + * + * Generates a %LIKE% portion of the query. Separates + * multiple calls with AND + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function like($field, $match = '', $side = 'both') + { + return $this->_like($field, $match, 'AND ', $side); + } + + // -------------------------------------------------------------------- + + /** + * Not Like + * + * Generates a NOT LIKE portion of the query. Separates + * multiple calls with AND + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function not_like($field, $match = '', $side = 'both') + { + return $this->_like($field, $match, 'AND ', $side, 'NOT'); + } + + // -------------------------------------------------------------------- + + /** + * OR Like + * + * Generates a %LIKE% portion of the query. Separates + * multiple calls with OR + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function or_like($field, $match = '', $side = 'both') + { + return $this->_like($field, $match, 'OR ', $side); + } + + // -------------------------------------------------------------------- + + /** + * OR Not Like + * + * Generates a NOT LIKE portion of the query. Separates + * multiple calls with OR + * + * @access public + * @param mixed + * @param mixed + * @return object + */ + function or_not_like($field, $match = '', $side = 'both') + { + return $this->_like($field, $match, 'OR ', $side, 'NOT'); + } + + // -------------------------------------------------------------------- + + /** + * orlike() is an alias of or_like() + * this function is here for backwards compatibility, as + * orlike() has been deprecated + */ + function orlike($field, $match = '', $side = 'both') + { + return $this->or_like($field, $match, $side); + } + + // -------------------------------------------------------------------- + + /** + * Like + * + * Called by like() or orlike() + * + * @access private + * @param mixed + * @param mixed + * @param string + * @return object + */ + function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '') + { + if ( ! is_array($field)) + { + $field = array($field => $match); + } + + foreach ($field as $k => $v) + { + $k = $this->_protect_identifiers($k); + + $prefix = (count($this->ar_like) == 0) ? '' : $type; + + $v = $this->escape_str($v); + + if ($side == 'before') + { + $like_statement = $prefix." $k $not LIKE '%{$v}'"; + } + elseif ($side == 'after') + { + $like_statement = $prefix." $k $not LIKE '{$v}%'"; + } + else + { + $like_statement = $prefix." $k $not LIKE '%{$v}%'"; + } + + $this->ar_like[] = $like_statement; + if ($this->ar_caching === TRUE) + { + $this->ar_cache_like[] = $like_statement; + $this->ar_cache_exists[] = 'like'; + } + + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * GROUP BY + * + * @access public + * @param string + * @return object + */ + function group_by($by) + { + if (is_string($by)) + { + $by = explode(',', $by); + } + + foreach ($by as $val) + { + $val = trim($val); + + if ($val != '') + { + $this->ar_groupby[] = $this->_protect_identifiers($val); + + if ($this->ar_caching === TRUE) + { + $this->ar_cache_groupby[] = $this->_protect_identifiers($val); + $this->ar_cache_exists[] = 'groupby'; + } + } + } + return $this; + } + + // -------------------------------------------------------------------- + + /** + * groupby() is an alias of group_by() + * this function is here for backwards compatibility, as + * groupby() has been deprecated + */ + function groupby($by) + { + return $this->group_by($by); + } + + // -------------------------------------------------------------------- + + /** + * Sets the HAVING value + * + * Separates multiple calls with AND + * + * @access public + * @param string + * @param string + * @return object + */ + function having($key, $value = '', $escape = TRUE) + { + return $this->_having($key, $value, 'AND ', $escape); + } + + // -------------------------------------------------------------------- + + /** + * orhaving() is an alias of or_having() + * this function is here for backwards compatibility, as + * orhaving() has been deprecated + */ + + function orhaving($key, $value = '', $escape = TRUE) + { + return $this->or_having($key, $value, $escape); + } + // -------------------------------------------------------------------- + + /** + * Sets the OR HAVING value + * + * Separates multiple calls with OR + * + * @access public + * @param string + * @param string + * @return object + */ + function or_having($key, $value = '', $escape = TRUE) + { + return $this->_having($key, $value, 'OR ', $escape); + } + + // -------------------------------------------------------------------- + + /** + * Sets the HAVING values + * + * Called by having() or or_having() + * + * @access private + * @param string + * @param string + * @return object + */ + function _having($key, $value = '', $type = 'AND ', $escape = TRUE) + { + if ( ! is_array($key)) + { + $key = array($key => $value); + } + + foreach ($key as $k => $v) + { + $prefix = (count($this->ar_having) == 0) ? '' : $type; + + if ($escape === TRUE) + { + $k = $this->_protect_identifiers($k); + } + + if ( ! $this->_has_operator($k)) + { + $k .= ' = '; + } + + if ($v != '') + { + $v = ' '.$this->escape_str($v); + } + + $this->ar_having[] = $prefix.$k.$v; + if ($this->ar_caching === TRUE) + { + $this->ar_cache_having[] = $prefix.$k.$v; + $this->ar_cache_exists[] = 'having'; + } + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Sets the ORDER BY value + * + * @access public + * @param string + * @param string direction: asc or desc + * @return object + */ + function order_by($orderby, $direction = '') + { + if (strtolower($direction) == 'random') + { + $orderby = ''; // Random results want or don't need a field name + $direction = $this->_random_keyword; + } + elseif (trim($direction) != '') + { + $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' '.$direction : ' ASC'; + } + + + if (strpos($orderby, ',') !== FALSE) + { + $temp = array(); + foreach (explode(',', $orderby) as $part) + { + $part = trim($part); + if ( ! in_array($part, $this->ar_aliased_tables)) + { + $part = $this->_protect_identifiers(trim($part)); + } + + $temp[] = $part; + } + + $orderby = implode(', ', $temp); + } + else + { + $orderby = $this->_protect_identifiers($orderby); + } + + $orderby_statement = $orderby.$direction; + + $this->ar_orderby[] = $orderby_statement; + if ($this->ar_caching === TRUE) + { + $this->ar_cache_orderby[] = $orderby_statement; + $this->ar_cache_exists[] = 'orderby'; + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * orderby() is an alias of order_by() + * this function is here for backwards compatibility, as + * orderby() has been deprecated + */ + function orderby($orderby, $direction = '') + { + return $this->order_by($orderby, $direction); + } + + // -------------------------------------------------------------------- + + /** + * Sets the LIMIT value + * + * @access public + * @param integer the limit value + * @param integer the offset value + * @return object + */ + function limit($value, $offset = '') + { + $this->ar_limit = $value; + + if ($offset != '') + { + $this->ar_offset = $offset; + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Sets the OFFSET value + * + * @access public + * @param integer the offset value + * @return object + */ + function offset($offset) + { + $this->ar_offset = $offset; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * The "set" function. Allows key/value pairs to be set for inserting or updating + * + * @access public + * @param mixed + * @param string + * @param boolean + * @return object + */ + function set($key, $value = '', $escape = TRUE) + { + $key = $this->_object_to_array($key); + + if ( ! is_array($key)) + { + $key = array($key => $value); + } + + foreach ($key as $k => $v) + { + if ($escape === FALSE) + { + $this->ar_set[$this->_protect_identifiers($k)] = $v; + } + else + { + $this->ar_set[$this->_protect_identifiers($k)] = $this->escape($v); + } + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Get + * + * Compiles the select statement based on the other functions called + * and runs the query + * + * @access public + * @param string the table + * @param string the limit clause + * @param string the offset clause + * @return object + */ + function get($table = '', $limit = null, $offset = null) + { + if ($table != '') + { + $this->_track_aliases($table); + $this->from($table); + } + + if ( ! is_null($limit)) + { + $this->limit($limit, $offset); + } + + $sql = $this->_compile_select(); + + $result = $this->query($sql); + $this->_reset_select(); + return $result; + } + + /** + * "Count All Results" query + * + * Generates a platform-specific query string that counts all records + * returned by an Active Record query. + * + * @access public + * @param string + * @return string + */ + function count_all_results($table = '') + { + if ($table != '') + { + $this->_track_aliases($table); + $this->from($table); + } + + $sql = $this->_compile_select($this->_count_string . $this->_protect_identifiers('numrows')); + + $query = $this->query($sql); + $this->_reset_select(); + + if ($query->num_rows() == 0) + { + return '0'; + } + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * Get_Where + * + * Allows the where clause, limit and offset to be added directly + * + * @access public + * @param string the where clause + * @param string the limit clause + * @param string the offset clause + * @return object + */ + function get_where($table = '', $where = null, $limit = null, $offset = null) + { + if ($table != '') + { + $this->from($table); + } + + if ( ! is_null($where)) + { + $this->where($where); + } + + if ( ! is_null($limit)) + { + $this->limit($limit, $offset); + } + + $sql = $this->_compile_select(); + + $result = $this->query($sql); + $this->_reset_select(); + return $result; + } + + // -------------------------------------------------------------------- + + /** + * getwhere() is an alias of get_where() + * this function is here for backwards compatibility, as + * getwhere() has been deprecated + */ + function getwhere($table = '', $where = null, $limit = null, $offset = null) + { + return $this->get_where($table, $where, $limit, $offset); + } + + // -------------------------------------------------------------------- + + /** + * Insert + * + * Compiles an insert string and runs the query + * + * @access public + * @param string the table to retrieve the results from + * @param array an associative array of insert values + * @return object + */ + function insert($table = '', $set = NULL) + { + if ( ! is_null($set)) + { + $this->set($set); + } + + if (count($this->ar_set) == 0) + { + if ($this->db_debug) + { + return $this->display_error('db_must_use_set'); + } + return FALSE; + } + + if ($table == '') + { + if ( ! isset($this->ar_from[0])) + { + if ($this->db_debug) + { + return $this->display_error('db_must_set_table'); + } + return FALSE; + } + + $table = $this->ar_from[0]; + } + + $sql = $this->_insert($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->ar_set), array_values($this->ar_set)); + + $this->_reset_write(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Update + * + * Compiles an update string and runs the query + * + * @access public + * @param string the table to retrieve the results from + * @param array an associative array of update values + * @param mixed the where clause + * @return object + */ + function update($table = '', $set = NULL, $where = NULL, $limit = NULL) + { + // Combine any cached components with the current statements + $this->_merge_cache(); + + if ( ! is_null($set)) + { + $this->set($set); + } + + if (count($this->ar_set) == 0) + { + if ($this->db_debug) + { + return $this->display_error('db_must_use_set'); + } + return FALSE; + } + + if ($table == '') + { + if ( ! isset($this->ar_from[0])) + { + if ($this->db_debug) + { + return $this->display_error('db_must_set_table'); + } + return FALSE; + } + + $table = $this->ar_from[0]; + } + + if ($where != NULL) + { + $this->where($where); + } + + if ($limit != NULL) + { + $this->limit($limit); + } + + $sql = $this->_update($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit); + + $this->_reset_write(); + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Empty Table + * + * Compiles a delete string and runs "DELETE FROM table" + * + * @access public + * @param string the table to empty + * @return object + */ + function empty_table($table = '') + { + if ($table == '') + { + if ( ! isset($this->ar_from[0])) + { + if ($this->db_debug) + { + return $this->display_error('db_must_set_table'); + } + return FALSE; + } + + $table = $this->ar_from[0]; + } + else + { + $table = $this->_protect_identifiers($table, TRUE, NULL, FALSE); + } + + $sql = $this->_delete($table); + + $this->_reset_write(); + + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Truncate + * + * Compiles a truncate string and runs the query + * If the database does not support the truncate() command + * This function maps to "DELETE FROM table" + * + * @access public + * @param string the table to truncate + * @return object + */ + function truncate($table = '') + { + if ($table == '') + { + if ( ! isset($this->ar_from[0])) + { + if ($this->db_debug) + { + return $this->display_error('db_must_set_table'); + } + return FALSE; + } + + $table = $this->ar_from[0]; + } + else + { + $table = $this->_protect_identifiers($table, TRUE, NULL, FALSE); + } + + $sql = $this->_truncate($table); + + $this->_reset_write(); + + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Delete + * + * Compiles a delete string and runs the query + * + * @access public + * @param mixed the table(s) to delete from. String or array + * @param mixed the where clause + * @param mixed the limit clause + * @param boolean + * @return object + */ + function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE) + { + // Combine any cached components with the current statements + $this->_merge_cache(); + + if ($table == '') + { + if ( ! isset($this->ar_from[0])) + { + if ($this->db_debug) + { + return $this->display_error('db_must_set_table'); + } + return FALSE; + } + + $table = $this->ar_from[0]; + } + elseif (is_array($table)) + { + foreach($table as $single_table) + { + $this->delete($single_table, $where, $limit, FALSE); + } + + $this->_reset_write(); + return; + } + else + { + $table = $this->_protect_identifiers($table, TRUE, NULL, FALSE); + } + + if ($where != '') + { + $this->where($where); + } + + if ($limit != NULL) + { + $this->limit($limit); + } + + if (count($this->ar_where) == 0 && count($this->ar_like) == 0) + { + if ($this->db_debug) + { + return $this->display_error('db_del_must_use_where'); + } + + return FALSE; + } + + $sql = $this->_delete($table, $this->ar_where, $this->ar_like, $this->ar_limit); + + if ($reset_data) + { + $this->_reset_write(); + } + + return $this->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * DB Prefix + * + * Prepends a database prefix if one exists in configuration + * + * @access public + * @param string the table + * @return string + */ + function dbprefix($table = '') + { + if ($table == '') + { + $this->display_error('db_table_name_required'); + } + + return $this->dbprefix.$table; + } + + // -------------------------------------------------------------------- + + /** + * Track Aliases + * + * Used to track SQL statements written with aliased tables. + * + * @access private + * @param string The table to inspect + * @return string + */ + function _track_aliases($table) + { + if (is_array($table)) + { + foreach ($table as $t) + { + $this->_track_aliases($t); + } + return; + } + + // Does the string contain a comma? If so, we need to separate + // the string into discreet statements + if (strpos($table, ',') !== FALSE) + { + return $this->_track_aliases(explode(',', $table)); + } + + // if a table alias is used we can recognize it by a space + if (strpos($table, " ") !== FALSE) + { + // if the alias is written with the AS keyword, remove it + $table = preg_replace('/ AS /i', ' ', $table); + + // Grab the alias + $table = trim(strrchr($table, " ")); + + // Store the alias, if it doesn't already exist + if ( ! in_array($table, $this->ar_aliased_tables)) + { + $this->ar_aliased_tables[] = $table; + } + } + } + + // -------------------------------------------------------------------- + + /** + * Compile the SELECT statement + * + * Generates a query string based on which functions were used. + * Should not be called directly. The get() function calls it. + * + * @access private + * @return string + */ + function _compile_select($select_override = FALSE) + { + // Combine any cached components with the current statements + $this->_merge_cache(); + + // ---------------------------------------------------------------- + + // Write the "select" portion of the query + + if ($select_override !== FALSE) + { + $sql = $select_override; + } + else + { + $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; + + if (count($this->ar_select) == 0) + { + $sql .= '*'; + } + else + { + // Cycle through the "select" portion of the query and prep each column name. + // The reason we protect identifiers here rather then in the select() function + // is because until the user calls the from() function we don't know if there are aliases + foreach ($this->ar_select as $key => $val) + { + $this->ar_select[$key] = $this->_protect_identifiers($val); + } + + $sql .= implode(', ', $this->ar_select); + } + } + + // ---------------------------------------------------------------- + + // Write the "FROM" portion of the query + + if (count($this->ar_from) > 0) + { + $sql .= "\nFROM "; + + $sql .= $this->_from_tables($this->ar_from); + } + + // ---------------------------------------------------------------- + + // Write the "JOIN" portion of the query + + if (count($this->ar_join) > 0) + { + $sql .= "\n"; + + $sql .= implode("\n", $this->ar_join); + } + + // ---------------------------------------------------------------- + + // Write the "WHERE" portion of the query + + if (count($this->ar_where) > 0 OR count($this->ar_like) > 0) + { + $sql .= "\n"; + + $sql .= "WHERE "; + } + + $sql .= implode("\n", $this->ar_where); + + // ---------------------------------------------------------------- + + // Write the "LIKE" portion of the query + + if (count($this->ar_like) > 0) + { + if (count($this->ar_where) > 0) + { + $sql .= "\nAND "; + } + + $sql .= implode("\n", $this->ar_like); + } + + // ---------------------------------------------------------------- + + // Write the "GROUP BY" portion of the query + + if (count($this->ar_groupby) > 0) + { + $sql .= "\nGROUP BY "; + + $sql .= implode(', ', $this->ar_groupby); + } + + // ---------------------------------------------------------------- + + // Write the "HAVING" portion of the query + + if (count($this->ar_having) > 0) + { + $sql .= "\nHAVING "; + $sql .= implode("\n", $this->ar_having); + } + + // ---------------------------------------------------------------- + + // Write the "ORDER BY" portion of the query + + if (count($this->ar_orderby) > 0) + { + $sql .= "\nORDER BY "; + $sql .= implode(', ', $this->ar_orderby); + + if ($this->ar_order !== FALSE) + { + $sql .= ($this->ar_order == 'desc') ? ' DESC' : ' ASC'; + } + } + + // ---------------------------------------------------------------- + + // Write the "LIMIT" portion of the query + + if (is_numeric($this->ar_limit)) + { + $sql .= "\n"; + $sql = $this->_limit($sql, $this->ar_limit, $this->ar_offset); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Object to Array + * + * Takes an object as input and converts the class variables to array key/vals + * + * @access public + * @param object + * @return array + */ + function _object_to_array($object) + { + if ( ! is_object($object)) + { + return $object; + } + + $array = array(); + foreach (get_object_vars($object) as $key => $val) + { + // There are some built in keys we need to ignore for this conversion + if ( ! is_object($val) && ! is_array($val) && $key != '_parent_name' && $key != '_ci_scaffolding' && $key != '_ci_scaff_table') + { + $array[$key] = $val; + } + } + + return $array; + } + + // -------------------------------------------------------------------- + + /** + * Start Cache + * + * Starts AR caching + * + * @access public + * @return void + */ + function start_cache() + { + $this->ar_caching = TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Stop Cache + * + * Stops AR caching + * + * @access public + * @return void + */ + function stop_cache() + { + $this->ar_caching = FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Flush Cache + * + * Empties the AR cache + * + * @access public + * @return void + */ + function flush_cache() + { + $this->_reset_run( + array( + 'ar_cache_select' => array(), + 'ar_cache_from' => array(), + 'ar_cache_join' => array(), + 'ar_cache_where' => array(), + 'ar_cache_like' => array(), + 'ar_cache_groupby' => array(), + 'ar_cache_having' => array(), + 'ar_cache_orderby' => array(), + 'ar_cache_set' => array(), + 'ar_cache_exists' => array() + ) + ); + } + + // -------------------------------------------------------------------- + + /** + * Merge Cache + * + * When called, this function merges any cached AR arrays with + * locally called ones. + * + * @access private + * @return void + */ + function _merge_cache() + { + if (count($this->ar_cache_exists) == 0) + { + return; + } + + foreach ($this->ar_cache_exists as $val) + { + $ar_variable = 'ar_'.$val; + $ar_cache_var = 'ar_cache_'.$val; + + if (count($this->$ar_cache_var) == 0) + { + continue; + } + + $this->$ar_variable = array_unique(array_merge($this->$ar_cache_var, $this->$ar_variable)); + } + + // If we are "protecting identifiers" we need to examine the "from" + // portion of the query to determine if there are any aliases + if ($this->_protect_identifiers === TRUE AND count($this->ar_cache_from) > 0) + { + $this->_track_aliases($this->ar_from); + } + } + + // -------------------------------------------------------------------- + + /** + * Resets the active record values. Called by the get() function + * + * @access private + * @param array An array of fields to reset + * @return void + */ + function _reset_run($ar_reset_items) + { + foreach ($ar_reset_items as $item => $default_value) + { + if ( ! in_array($item, $this->ar_store_array)) + { + $this->$item = $default_value; + } + } + } + + // -------------------------------------------------------------------- + + /** + * Resets the active record values. Called by the get() function + * + * @access private + * @return void + */ + function _reset_select() + { + $ar_reset_items = array( + 'ar_select' => array(), + 'ar_from' => array(), + 'ar_join' => array(), + 'ar_where' => array(), + 'ar_like' => array(), + 'ar_groupby' => array(), + 'ar_having' => array(), + 'ar_orderby' => array(), + 'ar_wherein' => array(), + 'ar_aliased_tables' => array(), + 'ar_distinct' => FALSE, + 'ar_limit' => FALSE, + 'ar_offset' => FALSE, + 'ar_order' => FALSE, + ); + + $this->_reset_run($ar_reset_items); + } + + // -------------------------------------------------------------------- + + /** + * Resets the active record "write" values. + * + * Called by the insert() update() and delete() functions + * + * @access private + * @return void + */ + function _reset_write() + { + $ar_reset_items = array( + 'ar_set' => array(), + 'ar_from' => array(), + 'ar_where' => array(), + 'ar_like' => array(), + 'ar_orderby' => array(), + 'ar_limit' => FALSE, + 'ar_order' => FALSE + ); + + $this->_reset_run($ar_reset_items); + } + +} + +/* End of file DB_active_rec.php */ /* Location: ./system/database/DB_active_rec.php */ \ No newline at end of file diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 9bb1b165b..70a2d95e3 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -1,195 +1,195 @@ -CI - // and load the file helper since we use it a lot - $this->CI =& get_instance(); - $this->db =& $db; - $this->CI->load->helper('file'); - } - - // -------------------------------------------------------------------- - - /** - * Set Cache Directory Path - * - * @access public - * @param string the path to the cache directory - * @return bool - */ - function check_path($path = '') - { - if ($path == '') - { - if ($this->db->cachedir == '') - { - return $this->db->cache_off(); - } - - $path = $this->db->cachedir; - } - - // Add a trailing slash to the path if needed - $path = preg_replace("/(.+?)\/*$/", "\\1/", $path); - - if ( ! is_dir($path) OR ! is_really_writable($path)) - { - // If the path is wrong we'll turn off caching - return $this->db->cache_off(); - } - - $this->db->cachedir = $path; - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Retrieve a cached query - * - * The URI being requested will become the name of the cache sub-folder. - * An MD5 hash of the SQL statement will become the cache file name - * - * @access public - * @return string - */ - function read($sql) - { - if ( ! $this->check_path()) - { - return $this->db->cache_off(); - } - - $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); - - $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); - - $filepath = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'.md5($sql); - - if (FALSE === ($cachedata = read_file($filepath))) - { - return FALSE; - } - - return unserialize($cachedata); - } - - // -------------------------------------------------------------------- - - /** - * Write a query to a cache file - * - * @access public - * @return bool - */ - function write($sql, $object) - { - if ( ! $this->check_path()) - { - return $this->db->cache_off(); - } - - $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); - - $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); - - $dir_path = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'; - - $filename = md5($sql); - - if ( ! @is_dir($dir_path)) - { - if ( ! @mkdir($dir_path, DIR_WRITE_MODE)) - { - return FALSE; - } - - @chmod($dir_path, DIR_WRITE_MODE); - } - - if (write_file($dir_path.$filename, serialize($object)) === FALSE) - { - return FALSE; - } - - @chmod($dir_path.$filename, DIR_WRITE_MODE); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Delete cache files within a particular directory - * - * @access public - * @return bool - */ - function delete($segment_one = '', $segment_two = '') - { - if ($segment_one == '') - { - $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); - } - - if ($segment_two == '') - { - $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); - } - - $dir_path = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'; - - delete_files($dir_path, TRUE); - } - - // -------------------------------------------------------------------- - - /** - * Delete all existing cache files - * - * @access public - * @return bool - */ - function delete_all() - { - delete_files($this->db->cachedir, TRUE); - } - -} - - -/* End of file DB_cache.php */ +CI + // and load the file helper since we use it a lot + $this->CI =& get_instance(); + $this->db =& $db; + $this->CI->load->helper('file'); + } + + // -------------------------------------------------------------------- + + /** + * Set Cache Directory Path + * + * @access public + * @param string the path to the cache directory + * @return bool + */ + function check_path($path = '') + { + if ($path == '') + { + if ($this->db->cachedir == '') + { + return $this->db->cache_off(); + } + + $path = $this->db->cachedir; + } + + // Add a trailing slash to the path if needed + $path = preg_replace("/(.+?)\/*$/", "\\1/", $path); + + if ( ! is_dir($path) OR ! is_really_writable($path)) + { + // If the path is wrong we'll turn off caching + return $this->db->cache_off(); + } + + $this->db->cachedir = $path; + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Retrieve a cached query + * + * The URI being requested will become the name of the cache sub-folder. + * An MD5 hash of the SQL statement will become the cache file name + * + * @access public + * @return string + */ + function read($sql) + { + if ( ! $this->check_path()) + { + return $this->db->cache_off(); + } + + $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); + + $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); + + $filepath = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'.md5($sql); + + if (FALSE === ($cachedata = read_file($filepath))) + { + return FALSE; + } + + return unserialize($cachedata); + } + + // -------------------------------------------------------------------- + + /** + * Write a query to a cache file + * + * @access public + * @return bool + */ + function write($sql, $object) + { + if ( ! $this->check_path()) + { + return $this->db->cache_off(); + } + + $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); + + $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); + + $dir_path = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'; + + $filename = md5($sql); + + if ( ! @is_dir($dir_path)) + { + if ( ! @mkdir($dir_path, DIR_WRITE_MODE)) + { + return FALSE; + } + + @chmod($dir_path, DIR_WRITE_MODE); + } + + if (write_file($dir_path.$filename, serialize($object)) === FALSE) + { + return FALSE; + } + + @chmod($dir_path.$filename, DIR_WRITE_MODE); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Delete cache files within a particular directory + * + * @access public + * @return bool + */ + function delete($segment_one = '', $segment_two = '') + { + if ($segment_one == '') + { + $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); + } + + if ($segment_two == '') + { + $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); + } + + $dir_path = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'; + + delete_files($dir_path, TRUE); + } + + // -------------------------------------------------------------------- + + /** + * Delete all existing cache files + * + * @access public + * @return bool + */ + function delete_all() + { + delete_files($this->db->cachedir, TRUE); + } + +} + + +/* End of file DB_cache.php */ /* Location: ./system/database/DB_cache.php */ \ No newline at end of file diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index dbd82dbc4..4293acc91 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1,1319 +1,1319 @@ - $val) - { - $this->$key = $val; - } - } - - log_message('debug', 'Database Driver Class Initialized'); - } - - // -------------------------------------------------------------------- - - /** - * Initialize Database Settings - * - * @access private Called by the constructor - * @param mixed - * @return void - */ - function initialize() - { - // If an existing connection resource is available - // there is no need to connect and select the database - if (is_resource($this->conn_id) OR is_object($this->conn_id)) - { - return TRUE; - } - - // ---------------------------------------------------------------- - - // Connect to the database and set the connection ID - $this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect(); - - // No connection resource? Throw an error - if ( ! $this->conn_id) - { - log_message('error', 'Unable to connect to the database'); - - if ($this->db_debug) - { - $this->display_error('db_unable_to_connect'); - } - return FALSE; - } - - // ---------------------------------------------------------------- - - // Select the DB... assuming a database name is specified in the config file - if ($this->database != '') - { - if ( ! $this->db_select()) - { - log_message('error', 'Unable to select database: '.$this->database); - - if ($this->db_debug) - { - $this->display_error('db_unable_to_select', $this->database); - } - return FALSE; - } - else - { - // We've selected the DB. Now we set the character set - if ( ! $this->db_set_charset($this->char_set, $this->dbcollat)) - { - return FALSE; - } - - return TRUE; - } - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Set client character set - * - * @access public - * @param string - * @param string - * @return resource - */ - function db_set_charset($charset, $collation) - { - if ( ! $this->_db_set_charset($this->char_set, $this->dbcollat)) - { - log_message('error', 'Unable to set database connection charset: '.$this->char_set); - - if ($this->db_debug) - { - $this->display_error('db_unable_to_set_charset', $this->char_set); - } - - return FALSE; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * The name of the platform in use (mysql, mssql, etc...) - * - * @access public - * @return string - */ - function platform() - { - return $this->dbdriver; - } - - // -------------------------------------------------------------------- - - /** - * Database Version Number. Returns a string containing the - * version of the database being used - * - * @access public - * @return string - */ - function version() - { - if (FALSE === ($sql = $this->_version())) - { - if ($this->db_debug) - { - return $this->display_error('db_unsupported_function'); - } - return FALSE; - } - - if ($this->dbdriver == 'oci8') - { - return $sql; - } - - $query = $this->query($sql); - return $query->row('ver'); - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * Accepts an SQL string as input and returns a result object upon - * successful execution of a "read" type query. Returns boolean TRUE - * upon successful execution of a "write" type query. Returns boolean - * FALSE upon failure, and if the $db_debug variable is set to TRUE - * will raise an error. - * - * @access public - * @param string An SQL query string - * @param array An array of binding data - * @return mixed - */ - function query($sql, $binds = FALSE, $return_object = TRUE) - { - if ($sql == '') - { - if ($this->db_debug) - { - log_message('error', 'Invalid query: '.$sql); - return $this->display_error('db_invalid_query'); - } - return FALSE; - } - - // Verify table prefix and replace if necessary - if ( ($this->dbprefix != '' AND $this->swap_pre != '') AND ($this->dbprefix != $this->swap_pre) ) - { - $sql = preg_replace("/(\W)".$this->swap_pre."(\S+?)/", "\\1".$this->dbprefix."\\2", $sql); - } - - // Is query caching enabled? If the query is a "read type" - // we will load the caching class and return the previously - // cached query if it exists - if ($this->cache_on == TRUE AND stristr($sql, 'SELECT')) - { - if ($this->_cache_init()) - { - $this->load_rdriver(); - if (FALSE !== ($cache = $this->CACHE->read($sql))) - { - return $cache; - } - } - } - - // Compile binds if needed - if ($binds !== FALSE) - { - $sql = $this->compile_binds($sql, $binds); - } - - // Save the query for debugging - if ($this->save_queries == TRUE) - { - $this->queries[] = $sql; - } - - // Start the Query Timer - $time_start = list($sm, $ss) = explode(' ', microtime()); - - // Run the Query - if (FALSE === ($this->result_id = $this->simple_query($sql))) - { - if ($this->save_queries == TRUE) - { - $this->query_times[] = 0; - } - - // This will trigger a rollback if transactions are being used - $this->_trans_status = FALSE; - - if ($this->db_debug) - { - // grab the error number and message now, as we might run some - // additional queries before displaying the error - $error_no = $this->_error_number(); - $error_msg = $this->_error_message(); - - // We call this function in order to roll-back queries - // if transactions are enabled. If we don't call this here - // the error message will trigger an exit, causing the - // transactions to remain in limbo. - $this->trans_complete(); - - // Log and display errors - log_message('error', 'Query error: '.$error_msg); - return $this->display_error( - array( - 'Error Number: '.$error_no, - $error_msg, - $sql - ) - ); - } - - return FALSE; - } - - // Stop and aggregate the query time results - $time_end = list($em, $es) = explode(' ', microtime()); - $this->benchmark += ($em + $es) - ($sm + $ss); - - if ($this->save_queries == TRUE) - { - $this->query_times[] = ($em + $es) - ($sm + $ss); - } - - // Increment the query counter - $this->query_count++; - - // Was the query a "write" type? - // If so we'll simply return true - if ($this->is_write_type($sql) === TRUE) - { - // If caching is enabled we'll auto-cleanup any - // existing files related to this particular URI - if ($this->cache_on == TRUE AND $this->cache_autodel == TRUE AND $this->_cache_init()) - { - $this->CACHE->delete(); - } - - return TRUE; - } - - // Return TRUE if we don't need to create a result object - // Currently only the Oracle driver uses this when stored - // procedures are used - if ($return_object !== TRUE) - { - return TRUE; - } - - // Load and instantiate the result driver - - $driver = $this->load_rdriver(); - $RES = new $driver(); - $RES->conn_id = $this->conn_id; - $RES->result_id = $this->result_id; - - if ($this->dbdriver == 'oci8') - { - $RES->stmt_id = $this->stmt_id; - $RES->curs_id = NULL; - $RES->limit_used = $this->limit_used; - $this->stmt_id = FALSE; - } - - // oci8 vars must be set before calling this - $RES->num_rows = $RES->num_rows(); - - // Is query caching enabled? If so, we'll serialize the - // result object and save it to a cache file. - if ($this->cache_on == TRUE AND $this->_cache_init()) - { - // We'll create a new instance of the result object - // only without the platform specific driver since - // we can't use it with cached data (the query result - // resource ID won't be any good once we've cached the - // result object, so we'll have to compile the data - // and save it) - $CR = new CI_DB_result(); - $CR->num_rows = $RES->num_rows(); - $CR->result_object = $RES->result_object(); - $CR->result_array = $RES->result_array(); - - // Reset these since cached objects can not utilize resource IDs. - $CR->conn_id = NULL; - $CR->result_id = NULL; - - $this->CACHE->write($sql, $CR); - } - - return $RES; - } - - // -------------------------------------------------------------------- - - /** - * Load the result drivers - * - * @access public - * @return string the name of the result class - */ - function load_rdriver() - { - $driver = 'CI_DB_'.$this->dbdriver.'_result'; - - if ( ! class_exists($driver)) - { - include_once(BASEPATH.'database/DB_result'.EXT); - include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result'.EXT); - } - - return $driver; - } - - // -------------------------------------------------------------------- - - /** - * Simple Query - * This is a simplified version of the query() function. Internally - * we only use it when running transaction commands since they do - * not require all the features of the main query() function. - * - * @access public - * @param string the sql query - * @return mixed - */ - function simple_query($sql) - { - if ( ! $this->conn_id) - { - $this->initialize(); - } - - return $this->_execute($sql); - } - - // -------------------------------------------------------------------- - - /** - * Disable Transactions - * This permits transactions to be disabled at run-time. - * - * @access public - * @return void - */ - function trans_off() - { - $this->trans_enabled = FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Enable/disable Transaction Strict Mode - * When strict mode is enabled, if you are running multiple groups of - * transactions, if one group fails all groups will be rolled back. - * If strict mode is disabled, each group is treated autonomously, meaning - * a failure of one group will not affect any others - * - * @access public - * @return void - */ - function trans_strict($mode = TRUE) - { - $this->trans_strict = is_bool($mode) ? $mode : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Start Transaction - * - * @access public - * @return void - */ - function trans_start($test_mode = FALSE) - { - if ( ! $this->trans_enabled) - { - return FALSE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - $this->_trans_depth += 1; - return; - } - - $this->trans_begin($test_mode); - } - - // -------------------------------------------------------------------- - - /** - * Complete Transaction - * - * @access public - * @return bool - */ - function trans_complete() - { - if ( ! $this->trans_enabled) - { - return FALSE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 1) - { - $this->_trans_depth -= 1; - return TRUE; - } - - // The query() function will set this flag to FALSE in the event that a query failed - if ($this->_trans_status === FALSE) - { - $this->trans_rollback(); - - // If we are NOT running in strict mode, we will reset - // the _trans_status flag so that subsequent groups of transactions - // will be permitted. - if ($this->trans_strict === FALSE) - { - $this->_trans_status = TRUE; - } - - log_message('debug', 'DB Transaction Failure'); - return FALSE; - } - - $this->trans_commit(); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Lets you retrieve the transaction flag to determine if it has failed - * - * @access public - * @return bool - */ - function trans_status() - { - return $this->_trans_status; - } - - // -------------------------------------------------------------------- - - /** - * Compile Bindings - * - * @access public - * @param string the sql statement - * @param array an array of bind data - * @return string - */ - function compile_binds($sql, $binds) - { - if (strpos($sql, $this->bind_marker) === FALSE) - { - return $sql; - } - - if ( ! is_array($binds)) - { - $binds = array($binds); - } - - // Get the sql segments around the bind markers - $segments = explode($this->bind_marker, $sql); - - // The count of bind should be 1 less then the count of segments - // If there are more bind arguments trim it down - if (count($binds) >= count($segments)) { - $binds = array_slice($binds, 0, count($segments)-1); - } - - // Construct the binded query - $result = $segments[0]; - $i = 0; - foreach ($binds as $bind) - { - $result .= $this->escape($bind); - $result .= $segments[++$i]; - } - - return $result; - } - - // -------------------------------------------------------------------- - - /** - * Determines if a query is a "write" type. - * - * @access public - * @param string An SQL query string - * @return boolean - */ - function is_write_type($sql) - { - if ( ! preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql)) - { - return FALSE; - } - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Calculate the aggregate query elapsed time - * - * @access public - * @param integer The number of decimal places - * @return integer - */ - function elapsed_time($decimals = 6) - { - return number_format($this->benchmark, $decimals); - } - - // -------------------------------------------------------------------- - - /** - * Returns the total number of queries - * - * @access public - * @return integer - */ - function total_queries() - { - return $this->query_count; - } - - // -------------------------------------------------------------------- - - /** - * Returns the last query that was executed - * - * @access public - * @return void - */ - function last_query() - { - return end($this->queries); - } - - // -------------------------------------------------------------------- - - /** - * "Smart" Escape String - * - * Escapes data based on type - * Sets boolean and null types - * - * @access public - * @param string - * @return integer - */ - function escape($str) - { - switch (gettype($str)) - { - case 'string' : $str = "'".$this->escape_str($str)."'"; - break; - case 'boolean' : $str = ($str === FALSE) ? 0 : 1; - break; - default : $str = ($str === NULL) ? 'NULL' : $str; - break; - } - - return $str; - } - - // -------------------------------------------------------------------- - - /** - * Primary - * - * Retrieves the primary key. It assumes that the row in the first - * position is the primary key - * - * @access public - * @param string the table name - * @return string - */ - function primary($table = '') - { - $fields = $this->list_fields($table); - - if ( ! is_array($fields)) - { - return FALSE; - } - - return current($fields); - } - - // -------------------------------------------------------------------- - - /** - * Returns an array of table names - * - * @access public - * @return array - */ - function list_tables($constrain_by_prefix = FALSE) - { - // Is there a cached result? - if (isset($this->data_cache['table_names'])) - { - return $this->data_cache['table_names']; - } - - if (FALSE === ($sql = $this->_list_tables($constrain_by_prefix))) - { - if ($this->db_debug) - { - return $this->display_error('db_unsupported_function'); - } - return FALSE; - } - - $retval = array(); - $query = $this->query($sql); - - if ($query->num_rows() > 0) - { - foreach($query->result_array() as $row) - { - if (isset($row['TABLE_NAME'])) - { - $retval[] = $row['TABLE_NAME']; - } - else - { - $retval[] = array_shift($row); - } - } - } - - $this->data_cache['table_names'] = $retval; - return $this->data_cache['table_names']; - } - - // -------------------------------------------------------------------- - - /** - * Determine if a particular table exists - * @access public - * @return boolean - */ - function table_exists($table_name) - { - return ( ! in_array($this->_protect_identifiers($table_name, TRUE, FALSE, FALSE), $this->list_tables())) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Fetch MySQL Field Names - * - * @access public - * @param string the table name - * @return array - */ - function list_fields($table = '') - { - // Is there a cached result? - if (isset($this->data_cache['field_names'][$table])) - { - return $this->data_cache['field_names'][$table]; - } - - if ($table == '') - { - if ($this->db_debug) - { - return $this->display_error('db_field_param_missing'); - } - return FALSE; - } - - if (FALSE === ($sql = $this->_list_columns($this->_protect_identifiers($table, TRUE, NULL, FALSE)))) - { - if ($this->db_debug) - { - return $this->display_error('db_unsupported_function'); - } - return FALSE; - } - - $query = $this->query($sql); - - $retval = array(); - foreach($query->result_array() as $row) - { - if (isset($row['COLUMN_NAME'])) - { - $retval[] = $row['COLUMN_NAME']; - } - else - { - $retval[] = current($row); - } - } - - $this->data_cache['field_names'][$table] = $retval; - return $this->data_cache['field_names'][$table]; - } - - // -------------------------------------------------------------------- - - /** - * Determine if a particular field exists - * @access public - * @param string - * @param string - * @return boolean - */ - function field_exists($field_name, $table_name) - { - return ( ! in_array($field_name, $this->list_fields($table_name))) ? FALSE : TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Returns an object with field data - * - * @access public - * @param string the table name - * @return object - */ - function field_data($table = '') - { - if ($table == '') - { - if ($this->db_debug) - { - return $this->display_error('db_field_param_missing'); - } - return FALSE; - } - - $query = $this->query($this->_field_data($this->_protect_identifiers($table, TRUE, NULL, FALSE))); - - return $query->field_data(); - } - - // -------------------------------------------------------------------- - - /** - * Generate an insert string - * - * @access public - * @param string the table upon which the query will be performed - * @param array an associative array data of key/values - * @return string - */ - function insert_string($table, $data) - { - $fields = array(); - $values = array(); - - foreach($data as $key => $val) - { - $fields[] = $this->_escape_identifiers($key); - $values[] = $this->escape($val); - } - - return $this->_insert($this->_protect_identifiers($table, TRUE, NULL, FALSE), $fields, $values); - } - - // -------------------------------------------------------------------- - - /** - * Generate an update string - * - * @access public - * @param string the table upon which the query will be performed - * @param array an associative array data of key/values - * @param mixed the "where" statement - * @return string - */ - function update_string($table, $data, $where) - { - if ($where == '') - { - return false; - } - - $fields = array(); - foreach($data as $key => $val) - { - $fields[$this->_protect_identifiers($key)] = $this->escape($val); - } - - if ( ! is_array($where)) - { - $dest = array($where); - } - else - { - $dest = array(); - foreach ($where as $key => $val) - { - $prefix = (count($dest) == 0) ? '' : ' AND '; - - if ($val !== '') - { - if ( ! $this->_has_operator($key)) - { - $key .= ' ='; - } - - $val = ' '.$this->escape($val); - } - - $dest[] = $prefix.$key.$val; - } - } - - return $this->_update($this->_protect_identifiers($table, TRUE, NULL, FALSE), $fields, $dest); - } - - // -------------------------------------------------------------------- - - /** - * Tests whether the string has an SQL operator - * - * @access private - * @param string - * @return bool - */ - function _has_operator($str) - { - $str = trim($str); - if ( ! preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str)) - { - return FALSE; - } - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Enables a native PHP function to be run, using a platform agnostic wrapper. - * - * @access public - * @param string the function name - * @param mixed any parameters needed by the function - * @return mixed - */ - function call_function($function) - { - $driver = ($this->dbdriver == 'postgre') ? 'pg_' : $this->dbdriver.'_'; - - if (FALSE === strpos($driver, $function)) - { - $function = $driver.$function; - } - - if ( ! function_exists($function)) - { - if ($this->db_debug) - { - return $this->display_error('db_unsupported_function'); - } - return FALSE; - } - else - { - $args = (func_num_args() > 1) ? array_splice(func_get_args(), 1) : null; - - return call_user_func_array($function, $args); - } - } - - // -------------------------------------------------------------------- - - /** - * Set Cache Directory Path - * - * @access public - * @param string the path to the cache directory - * @return void - */ - function cache_set_path($path = '') - { - $this->cachedir = $path; - } - - // -------------------------------------------------------------------- - - /** - * Enable Query Caching - * - * @access public - * @return void - */ - function cache_on() - { - $this->cache_on = TRUE; - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Disable Query Caching - * - * @access public - * @return void - */ - function cache_off() - { - $this->cache_on = FALSE; - return FALSE; - } - - - // -------------------------------------------------------------------- - - /** - * Delete the cache files associated with a particular URI - * - * @access public - * @return void - */ - function cache_delete($segment_one = '', $segment_two = '') - { - if ( ! $this->_cache_init()) - { - return FALSE; - } - return $this->CACHE->delete($segment_one, $segment_two); - } - - // -------------------------------------------------------------------- - - /** - * Delete All cache files - * - * @access public - * @return void - */ - function cache_delete_all() - { - if ( ! $this->_cache_init()) - { - return FALSE; - } - - return $this->CACHE->delete_all(); - } - - // -------------------------------------------------------------------- - - /** - * Initialize the Cache Class - * - * @access private - * @return void - */ - function _cache_init() - { - if (is_object($this->CACHE) AND class_exists('CI_DB_Cache')) - { - return TRUE; - } - - if ( ! @include(BASEPATH.'database/DB_cache'.EXT)) - { - return $this->cache_off(); - } - - $this->CACHE = new CI_DB_Cache($this); // pass db object to support multiple db connections and returned db objects - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @return void - */ - function close() - { - if (is_resource($this->conn_id) OR is_object($this->conn_id)) - { - $this->_close($this->conn_id); - } - $this->conn_id = FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Display an error message - * - * @access public - * @param string the error message - * @param string any "swap" values - * @param boolean whether to localize the message - * @return string sends the application/error_db.php template - */ - function display_error($error = '', $swap = '', $native = FALSE) - { - $LANG =& load_class('Language'); - $LANG->load('db'); - - $heading = $LANG->line('db_error_heading'); - - if ($native == TRUE) - { - $message = $error; - } - else - { - $message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error; - } - - $error =& load_class('Exceptions'); - echo $error->show_error($heading, $message, 'error_db'); - exit; - } - - // -------------------------------------------------------------------- - - /** - * Protect Identifiers - * - * This function adds backticks if appropriate based on db type - * - * @access private - * @param mixed the item to escape - * @return mixed the item with backticks - */ - function protect_identifiers($item, $prefix_single = FALSE) - { - return $this->_protect_identifiers($item, $prefix_single); - } - - // -------------------------------------------------------------------- - - /** - * Protect Identifiers - * - * This function is used extensively by the Active Record class, and by - * a couple functions in this class. - * It takes a column or table name (optionally with an alias) and inserts - * the table prefix onto it. Some logic is necessary in order to deal with - * column names that include the path. Consider a query like this: - * - * SELECT * FROM hostname.database.table.column AS c FROM hostname.database.table - * - * Or a query with aliasing: - * - * SELECT m.member_id, m.member_name FROM members AS m - * - * Since the column name can include up to four segments (host, DB, table, column) - * or also have an alias prefix, we need to do a bit of work to figure this out and - * insert the table prefix (if it exists) in the proper position, and escape only - * the correct identifiers. - * - * @access private - * @param string - * @param bool - * @param mixed - * @param bool - * @return string - */ - function _protect_identifiers($item, $prefix_single = FALSE, $protect_identifiers = NULL, $field_exists = TRUE) - { - if ( ! is_bool($protect_identifiers)) - { - $protect_identifiers = $this->_protect_identifiers; - } - - // Convert tabs or multiple spaces into single spaces - $item = preg_replace('/[\t| ]+/', ' ', $item); - - // If the item has an alias declaration we remove it and set it aside. - // Basically we remove everything to the right of the first space - $alias = ''; - if (strpos($item, ' ') !== FALSE) - { - $alias = strstr($item, " "); - $item = substr($item, 0, - strlen($alias)); - } - - // Break the string apart if it contains periods, then insert the table prefix - // in the correct location, assuming the period doesn't indicate that we're dealing - // with an alias. While we're at it, we will escape the components - if (strpos($item, '.') !== FALSE) - { - $parts = explode('.', $item); - - // Does the first segment of the exploded item match - // one of the aliases previously identified? If so, - // we have nothing more to do other than escape the item - if (in_array($parts[0], $this->ar_aliased_tables)) - { - if ($protect_identifiers === TRUE) - { - foreach ($parts as $key => $val) - { - if ( ! in_array($val, $this->_reserved_identifiers)) - { - $parts[$key] = $this->_escape_identifiers($val); - } - } - - $item = implode('.', $parts); - } - return $item.$alias; - } - - // Is there a table prefix defined in the config file? If not, no need to do anything - if ($this->dbprefix != '') - { - // We now add the table prefix based on some logic. - // Do we have 4 segments (hostname.database.table.column)? - // If so, we add the table prefix to the column name in the 3rd segment. - if (isset($parts[3])) - { - $i = 2; - } - // Do we have 3 segments (database.table.column)? - // If so, we add the table prefix to the column name in 2nd position - elseif (isset($parts[2])) - { - $i = 1; - } - // Do we have 2 segments (table.column)? - // If so, we add the table prefix to the column name in 1st segment - else - { - $i = 0; - } - - // This flag is set when the supplied $item does not contain a field name. - // This can happen when this function is being called from a JOIN. - if ($field_exists == FALSE) - { - $i++; - } - - // We only add the table prefix if it does not already exist - if (substr($parts[$i], 0, strlen($this->dbprefix)) != $this->dbprefix) - { - $parts[$i] = $this->dbprefix.$parts[$i]; - } - - // Put the parts back together - $item = implode('.', $parts); - } - - if ($protect_identifiers === TRUE) - { - $item = $this->_escape_identifiers($item); - } - - return $item.$alias; - } - - // This is basically a bug fix for queries that use MAX, MIN, etc. - // If a parenthesis is found we know that we do not need to - // escape the data or add a prefix. There's probably a more graceful - // way to deal with this, but I'm not thinking of it -- Rick - if (strpos($item, '(') !== FALSE) - { - return $item.$alias; - } - - // Is there a table prefix? If not, no need to insert it - if ($this->dbprefix != '') - { - // Do we prefix an item with no segments? - if ($prefix_single == TRUE AND substr($item, 0, strlen($this->dbprefix)) != $this->dbprefix) - { - $item = $this->dbprefix.$item; - } - } - - if ($protect_identifiers === TRUE AND ! in_array($item, $this->_reserved_identifiers)) - { - $item = $this->_escape_identifiers($item); - } - - return $item.$alias; - } - - -} - - -/* End of file DB_driver.php */ + $val) + { + $this->$key = $val; + } + } + + log_message('debug', 'Database Driver Class Initialized'); + } + + // -------------------------------------------------------------------- + + /** + * Initialize Database Settings + * + * @access private Called by the constructor + * @param mixed + * @return void + */ + function initialize() + { + // If an existing connection resource is available + // there is no need to connect and select the database + if (is_resource($this->conn_id) OR is_object($this->conn_id)) + { + return TRUE; + } + + // ---------------------------------------------------------------- + + // Connect to the database and set the connection ID + $this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect(); + + // No connection resource? Throw an error + if ( ! $this->conn_id) + { + log_message('error', 'Unable to connect to the database'); + + if ($this->db_debug) + { + $this->display_error('db_unable_to_connect'); + } + return FALSE; + } + + // ---------------------------------------------------------------- + + // Select the DB... assuming a database name is specified in the config file + if ($this->database != '') + { + if ( ! $this->db_select()) + { + log_message('error', 'Unable to select database: '.$this->database); + + if ($this->db_debug) + { + $this->display_error('db_unable_to_select', $this->database); + } + return FALSE; + } + else + { + // We've selected the DB. Now we set the character set + if ( ! $this->db_set_charset($this->char_set, $this->dbcollat)) + { + return FALSE; + } + + return TRUE; + } + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Set client character set + * + * @access public + * @param string + * @param string + * @return resource + */ + function db_set_charset($charset, $collation) + { + if ( ! $this->_db_set_charset($this->char_set, $this->dbcollat)) + { + log_message('error', 'Unable to set database connection charset: '.$this->char_set); + + if ($this->db_debug) + { + $this->display_error('db_unable_to_set_charset', $this->char_set); + } + + return FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * The name of the platform in use (mysql, mssql, etc...) + * + * @access public + * @return string + */ + function platform() + { + return $this->dbdriver; + } + + // -------------------------------------------------------------------- + + /** + * Database Version Number. Returns a string containing the + * version of the database being used + * + * @access public + * @return string + */ + function version() + { + if (FALSE === ($sql = $this->_version())) + { + if ($this->db_debug) + { + return $this->display_error('db_unsupported_function'); + } + return FALSE; + } + + if ($this->dbdriver == 'oci8') + { + return $sql; + } + + $query = $this->query($sql); + return $query->row('ver'); + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * Accepts an SQL string as input and returns a result object upon + * successful execution of a "read" type query. Returns boolean TRUE + * upon successful execution of a "write" type query. Returns boolean + * FALSE upon failure, and if the $db_debug variable is set to TRUE + * will raise an error. + * + * @access public + * @param string An SQL query string + * @param array An array of binding data + * @return mixed + */ + function query($sql, $binds = FALSE, $return_object = TRUE) + { + if ($sql == '') + { + if ($this->db_debug) + { + log_message('error', 'Invalid query: '.$sql); + return $this->display_error('db_invalid_query'); + } + return FALSE; + } + + // Verify table prefix and replace if necessary + if ( ($this->dbprefix != '' AND $this->swap_pre != '') AND ($this->dbprefix != $this->swap_pre) ) + { + $sql = preg_replace("/(\W)".$this->swap_pre."(\S+?)/", "\\1".$this->dbprefix."\\2", $sql); + } + + // Is query caching enabled? If the query is a "read type" + // we will load the caching class and return the previously + // cached query if it exists + if ($this->cache_on == TRUE AND stristr($sql, 'SELECT')) + { + if ($this->_cache_init()) + { + $this->load_rdriver(); + if (FALSE !== ($cache = $this->CACHE->read($sql))) + { + return $cache; + } + } + } + + // Compile binds if needed + if ($binds !== FALSE) + { + $sql = $this->compile_binds($sql, $binds); + } + + // Save the query for debugging + if ($this->save_queries == TRUE) + { + $this->queries[] = $sql; + } + + // Start the Query Timer + $time_start = list($sm, $ss) = explode(' ', microtime()); + + // Run the Query + if (FALSE === ($this->result_id = $this->simple_query($sql))) + { + if ($this->save_queries == TRUE) + { + $this->query_times[] = 0; + } + + // This will trigger a rollback if transactions are being used + $this->_trans_status = FALSE; + + if ($this->db_debug) + { + // grab the error number and message now, as we might run some + // additional queries before displaying the error + $error_no = $this->_error_number(); + $error_msg = $this->_error_message(); + + // We call this function in order to roll-back queries + // if transactions are enabled. If we don't call this here + // the error message will trigger an exit, causing the + // transactions to remain in limbo. + $this->trans_complete(); + + // Log and display errors + log_message('error', 'Query error: '.$error_msg); + return $this->display_error( + array( + 'Error Number: '.$error_no, + $error_msg, + $sql + ) + ); + } + + return FALSE; + } + + // Stop and aggregate the query time results + $time_end = list($em, $es) = explode(' ', microtime()); + $this->benchmark += ($em + $es) - ($sm + $ss); + + if ($this->save_queries == TRUE) + { + $this->query_times[] = ($em + $es) - ($sm + $ss); + } + + // Increment the query counter + $this->query_count++; + + // Was the query a "write" type? + // If so we'll simply return true + if ($this->is_write_type($sql) === TRUE) + { + // If caching is enabled we'll auto-cleanup any + // existing files related to this particular URI + if ($this->cache_on == TRUE AND $this->cache_autodel == TRUE AND $this->_cache_init()) + { + $this->CACHE->delete(); + } + + return TRUE; + } + + // Return TRUE if we don't need to create a result object + // Currently only the Oracle driver uses this when stored + // procedures are used + if ($return_object !== TRUE) + { + return TRUE; + } + + // Load and instantiate the result driver + + $driver = $this->load_rdriver(); + $RES = new $driver(); + $RES->conn_id = $this->conn_id; + $RES->result_id = $this->result_id; + + if ($this->dbdriver == 'oci8') + { + $RES->stmt_id = $this->stmt_id; + $RES->curs_id = NULL; + $RES->limit_used = $this->limit_used; + $this->stmt_id = FALSE; + } + + // oci8 vars must be set before calling this + $RES->num_rows = $RES->num_rows(); + + // Is query caching enabled? If so, we'll serialize the + // result object and save it to a cache file. + if ($this->cache_on == TRUE AND $this->_cache_init()) + { + // We'll create a new instance of the result object + // only without the platform specific driver since + // we can't use it with cached data (the query result + // resource ID won't be any good once we've cached the + // result object, so we'll have to compile the data + // and save it) + $CR = new CI_DB_result(); + $CR->num_rows = $RES->num_rows(); + $CR->result_object = $RES->result_object(); + $CR->result_array = $RES->result_array(); + + // Reset these since cached objects can not utilize resource IDs. + $CR->conn_id = NULL; + $CR->result_id = NULL; + + $this->CACHE->write($sql, $CR); + } + + return $RES; + } + + // -------------------------------------------------------------------- + + /** + * Load the result drivers + * + * @access public + * @return string the name of the result class + */ + function load_rdriver() + { + $driver = 'CI_DB_'.$this->dbdriver.'_result'; + + if ( ! class_exists($driver)) + { + include_once(BASEPATH.'database/DB_result'.EXT); + include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result'.EXT); + } + + return $driver; + } + + // -------------------------------------------------------------------- + + /** + * Simple Query + * This is a simplified version of the query() function. Internally + * we only use it when running transaction commands since they do + * not require all the features of the main query() function. + * + * @access public + * @param string the sql query + * @return mixed + */ + function simple_query($sql) + { + if ( ! $this->conn_id) + { + $this->initialize(); + } + + return $this->_execute($sql); + } + + // -------------------------------------------------------------------- + + /** + * Disable Transactions + * This permits transactions to be disabled at run-time. + * + * @access public + * @return void + */ + function trans_off() + { + $this->trans_enabled = FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Enable/disable Transaction Strict Mode + * When strict mode is enabled, if you are running multiple groups of + * transactions, if one group fails all groups will be rolled back. + * If strict mode is disabled, each group is treated autonomously, meaning + * a failure of one group will not affect any others + * + * @access public + * @return void + */ + function trans_strict($mode = TRUE) + { + $this->trans_strict = is_bool($mode) ? $mode : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Start Transaction + * + * @access public + * @return void + */ + function trans_start($test_mode = FALSE) + { + if ( ! $this->trans_enabled) + { + return FALSE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + $this->_trans_depth += 1; + return; + } + + $this->trans_begin($test_mode); + } + + // -------------------------------------------------------------------- + + /** + * Complete Transaction + * + * @access public + * @return bool + */ + function trans_complete() + { + if ( ! $this->trans_enabled) + { + return FALSE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 1) + { + $this->_trans_depth -= 1; + return TRUE; + } + + // The query() function will set this flag to FALSE in the event that a query failed + if ($this->_trans_status === FALSE) + { + $this->trans_rollback(); + + // If we are NOT running in strict mode, we will reset + // the _trans_status flag so that subsequent groups of transactions + // will be permitted. + if ($this->trans_strict === FALSE) + { + $this->_trans_status = TRUE; + } + + log_message('debug', 'DB Transaction Failure'); + return FALSE; + } + + $this->trans_commit(); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Lets you retrieve the transaction flag to determine if it has failed + * + * @access public + * @return bool + */ + function trans_status() + { + return $this->_trans_status; + } + + // -------------------------------------------------------------------- + + /** + * Compile Bindings + * + * @access public + * @param string the sql statement + * @param array an array of bind data + * @return string + */ + function compile_binds($sql, $binds) + { + if (strpos($sql, $this->bind_marker) === FALSE) + { + return $sql; + } + + if ( ! is_array($binds)) + { + $binds = array($binds); + } + + // Get the sql segments around the bind markers + $segments = explode($this->bind_marker, $sql); + + // The count of bind should be 1 less then the count of segments + // If there are more bind arguments trim it down + if (count($binds) >= count($segments)) { + $binds = array_slice($binds, 0, count($segments)-1); + } + + // Construct the binded query + $result = $segments[0]; + $i = 0; + foreach ($binds as $bind) + { + $result .= $this->escape($bind); + $result .= $segments[++$i]; + } + + return $result; + } + + // -------------------------------------------------------------------- + + /** + * Determines if a query is a "write" type. + * + * @access public + * @param string An SQL query string + * @return boolean + */ + function is_write_type($sql) + { + if ( ! preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql)) + { + return FALSE; + } + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Calculate the aggregate query elapsed time + * + * @access public + * @param integer The number of decimal places + * @return integer + */ + function elapsed_time($decimals = 6) + { + return number_format($this->benchmark, $decimals); + } + + // -------------------------------------------------------------------- + + /** + * Returns the total number of queries + * + * @access public + * @return integer + */ + function total_queries() + { + return $this->query_count; + } + + // -------------------------------------------------------------------- + + /** + * Returns the last query that was executed + * + * @access public + * @return void + */ + function last_query() + { + return end($this->queries); + } + + // -------------------------------------------------------------------- + + /** + * "Smart" Escape String + * + * Escapes data based on type + * Sets boolean and null types + * + * @access public + * @param string + * @return integer + */ + function escape($str) + { + switch (gettype($str)) + { + case 'string' : $str = "'".$this->escape_str($str)."'"; + break; + case 'boolean' : $str = ($str === FALSE) ? 0 : 1; + break; + default : $str = ($str === NULL) ? 'NULL' : $str; + break; + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Primary + * + * Retrieves the primary key. It assumes that the row in the first + * position is the primary key + * + * @access public + * @param string the table name + * @return string + */ + function primary($table = '') + { + $fields = $this->list_fields($table); + + if ( ! is_array($fields)) + { + return FALSE; + } + + return current($fields); + } + + // -------------------------------------------------------------------- + + /** + * Returns an array of table names + * + * @access public + * @return array + */ + function list_tables($constrain_by_prefix = FALSE) + { + // Is there a cached result? + if (isset($this->data_cache['table_names'])) + { + return $this->data_cache['table_names']; + } + + if (FALSE === ($sql = $this->_list_tables($constrain_by_prefix))) + { + if ($this->db_debug) + { + return $this->display_error('db_unsupported_function'); + } + return FALSE; + } + + $retval = array(); + $query = $this->query($sql); + + if ($query->num_rows() > 0) + { + foreach($query->result_array() as $row) + { + if (isset($row['TABLE_NAME'])) + { + $retval[] = $row['TABLE_NAME']; + } + else + { + $retval[] = array_shift($row); + } + } + } + + $this->data_cache['table_names'] = $retval; + return $this->data_cache['table_names']; + } + + // -------------------------------------------------------------------- + + /** + * Determine if a particular table exists + * @access public + * @return boolean + */ + function table_exists($table_name) + { + return ( ! in_array($this->_protect_identifiers($table_name, TRUE, FALSE, FALSE), $this->list_tables())) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Fetch MySQL Field Names + * + * @access public + * @param string the table name + * @return array + */ + function list_fields($table = '') + { + // Is there a cached result? + if (isset($this->data_cache['field_names'][$table])) + { + return $this->data_cache['field_names'][$table]; + } + + if ($table == '') + { + if ($this->db_debug) + { + return $this->display_error('db_field_param_missing'); + } + return FALSE; + } + + if (FALSE === ($sql = $this->_list_columns($this->_protect_identifiers($table, TRUE, NULL, FALSE)))) + { + if ($this->db_debug) + { + return $this->display_error('db_unsupported_function'); + } + return FALSE; + } + + $query = $this->query($sql); + + $retval = array(); + foreach($query->result_array() as $row) + { + if (isset($row['COLUMN_NAME'])) + { + $retval[] = $row['COLUMN_NAME']; + } + else + { + $retval[] = current($row); + } + } + + $this->data_cache['field_names'][$table] = $retval; + return $this->data_cache['field_names'][$table]; + } + + // -------------------------------------------------------------------- + + /** + * Determine if a particular field exists + * @access public + * @param string + * @param string + * @return boolean + */ + function field_exists($field_name, $table_name) + { + return ( ! in_array($field_name, $this->list_fields($table_name))) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Returns an object with field data + * + * @access public + * @param string the table name + * @return object + */ + function field_data($table = '') + { + if ($table == '') + { + if ($this->db_debug) + { + return $this->display_error('db_field_param_missing'); + } + return FALSE; + } + + $query = $this->query($this->_field_data($this->_protect_identifiers($table, TRUE, NULL, FALSE))); + + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * Generate an insert string + * + * @access public + * @param string the table upon which the query will be performed + * @param array an associative array data of key/values + * @return string + */ + function insert_string($table, $data) + { + $fields = array(); + $values = array(); + + foreach($data as $key => $val) + { + $fields[] = $this->_escape_identifiers($key); + $values[] = $this->escape($val); + } + + return $this->_insert($this->_protect_identifiers($table, TRUE, NULL, FALSE), $fields, $values); + } + + // -------------------------------------------------------------------- + + /** + * Generate an update string + * + * @access public + * @param string the table upon which the query will be performed + * @param array an associative array data of key/values + * @param mixed the "where" statement + * @return string + */ + function update_string($table, $data, $where) + { + if ($where == '') + { + return false; + } + + $fields = array(); + foreach($data as $key => $val) + { + $fields[$this->_protect_identifiers($key)] = $this->escape($val); + } + + if ( ! is_array($where)) + { + $dest = array($where); + } + else + { + $dest = array(); + foreach ($where as $key => $val) + { + $prefix = (count($dest) == 0) ? '' : ' AND '; + + if ($val !== '') + { + if ( ! $this->_has_operator($key)) + { + $key .= ' ='; + } + + $val = ' '.$this->escape($val); + } + + $dest[] = $prefix.$key.$val; + } + } + + return $this->_update($this->_protect_identifiers($table, TRUE, NULL, FALSE), $fields, $dest); + } + + // -------------------------------------------------------------------- + + /** + * Tests whether the string has an SQL operator + * + * @access private + * @param string + * @return bool + */ + function _has_operator($str) + { + $str = trim($str); + if ( ! preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str)) + { + return FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Enables a native PHP function to be run, using a platform agnostic wrapper. + * + * @access public + * @param string the function name + * @param mixed any parameters needed by the function + * @return mixed + */ + function call_function($function) + { + $driver = ($this->dbdriver == 'postgre') ? 'pg_' : $this->dbdriver.'_'; + + if (FALSE === strpos($driver, $function)) + { + $function = $driver.$function; + } + + if ( ! function_exists($function)) + { + if ($this->db_debug) + { + return $this->display_error('db_unsupported_function'); + } + return FALSE; + } + else + { + $args = (func_num_args() > 1) ? array_splice(func_get_args(), 1) : null; + + return call_user_func_array($function, $args); + } + } + + // -------------------------------------------------------------------- + + /** + * Set Cache Directory Path + * + * @access public + * @param string the path to the cache directory + * @return void + */ + function cache_set_path($path = '') + { + $this->cachedir = $path; + } + + // -------------------------------------------------------------------- + + /** + * Enable Query Caching + * + * @access public + * @return void + */ + function cache_on() + { + $this->cache_on = TRUE; + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Disable Query Caching + * + * @access public + * @return void + */ + function cache_off() + { + $this->cache_on = FALSE; + return FALSE; + } + + + // -------------------------------------------------------------------- + + /** + * Delete the cache files associated with a particular URI + * + * @access public + * @return void + */ + function cache_delete($segment_one = '', $segment_two = '') + { + if ( ! $this->_cache_init()) + { + return FALSE; + } + return $this->CACHE->delete($segment_one, $segment_two); + } + + // -------------------------------------------------------------------- + + /** + * Delete All cache files + * + * @access public + * @return void + */ + function cache_delete_all() + { + if ( ! $this->_cache_init()) + { + return FALSE; + } + + return $this->CACHE->delete_all(); + } + + // -------------------------------------------------------------------- + + /** + * Initialize the Cache Class + * + * @access private + * @return void + */ + function _cache_init() + { + if (is_object($this->CACHE) AND class_exists('CI_DB_Cache')) + { + return TRUE; + } + + if ( ! @include(BASEPATH.'database/DB_cache'.EXT)) + { + return $this->cache_off(); + } + + $this->CACHE = new CI_DB_Cache($this); // pass db object to support multiple db connections and returned db objects + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @return void + */ + function close() + { + if (is_resource($this->conn_id) OR is_object($this->conn_id)) + { + $this->_close($this->conn_id); + } + $this->conn_id = FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Display an error message + * + * @access public + * @param string the error message + * @param string any "swap" values + * @param boolean whether to localize the message + * @return string sends the application/error_db.php template + */ + function display_error($error = '', $swap = '', $native = FALSE) + { + $LANG =& load_class('Language'); + $LANG->load('db'); + + $heading = $LANG->line('db_error_heading'); + + if ($native == TRUE) + { + $message = $error; + } + else + { + $message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error; + } + + $error =& load_class('Exceptions'); + echo $error->show_error($heading, $message, 'error_db'); + exit; + } + + // -------------------------------------------------------------------- + + /** + * Protect Identifiers + * + * This function adds backticks if appropriate based on db type + * + * @access private + * @param mixed the item to escape + * @return mixed the item with backticks + */ + function protect_identifiers($item, $prefix_single = FALSE) + { + return $this->_protect_identifiers($item, $prefix_single); + } + + // -------------------------------------------------------------------- + + /** + * Protect Identifiers + * + * This function is used extensively by the Active Record class, and by + * a couple functions in this class. + * It takes a column or table name (optionally with an alias) and inserts + * the table prefix onto it. Some logic is necessary in order to deal with + * column names that include the path. Consider a query like this: + * + * SELECT * FROM hostname.database.table.column AS c FROM hostname.database.table + * + * Or a query with aliasing: + * + * SELECT m.member_id, m.member_name FROM members AS m + * + * Since the column name can include up to four segments (host, DB, table, column) + * or also have an alias prefix, we need to do a bit of work to figure this out and + * insert the table prefix (if it exists) in the proper position, and escape only + * the correct identifiers. + * + * @access private + * @param string + * @param bool + * @param mixed + * @param bool + * @return string + */ + function _protect_identifiers($item, $prefix_single = FALSE, $protect_identifiers = NULL, $field_exists = TRUE) + { + if ( ! is_bool($protect_identifiers)) + { + $protect_identifiers = $this->_protect_identifiers; + } + + // Convert tabs or multiple spaces into single spaces + $item = preg_replace('/[\t| ]+/', ' ', $item); + + // If the item has an alias declaration we remove it and set it aside. + // Basically we remove everything to the right of the first space + $alias = ''; + if (strpos($item, ' ') !== FALSE) + { + $alias = strstr($item, " "); + $item = substr($item, 0, - strlen($alias)); + } + + // Break the string apart if it contains periods, then insert the table prefix + // in the correct location, assuming the period doesn't indicate that we're dealing + // with an alias. While we're at it, we will escape the components + if (strpos($item, '.') !== FALSE) + { + $parts = explode('.', $item); + + // Does the first segment of the exploded item match + // one of the aliases previously identified? If so, + // we have nothing more to do other than escape the item + if (in_array($parts[0], $this->ar_aliased_tables)) + { + if ($protect_identifiers === TRUE) + { + foreach ($parts as $key => $val) + { + if ( ! in_array($val, $this->_reserved_identifiers)) + { + $parts[$key] = $this->_escape_identifiers($val); + } + } + + $item = implode('.', $parts); + } + return $item.$alias; + } + + // Is there a table prefix defined in the config file? If not, no need to do anything + if ($this->dbprefix != '') + { + // We now add the table prefix based on some logic. + // Do we have 4 segments (hostname.database.table.column)? + // If so, we add the table prefix to the column name in the 3rd segment. + if (isset($parts[3])) + { + $i = 2; + } + // Do we have 3 segments (database.table.column)? + // If so, we add the table prefix to the column name in 2nd position + elseif (isset($parts[2])) + { + $i = 1; + } + // Do we have 2 segments (table.column)? + // If so, we add the table prefix to the column name in 1st segment + else + { + $i = 0; + } + + // This flag is set when the supplied $item does not contain a field name. + // This can happen when this function is being called from a JOIN. + if ($field_exists == FALSE) + { + $i++; + } + + // We only add the table prefix if it does not already exist + if (substr($parts[$i], 0, strlen($this->dbprefix)) != $this->dbprefix) + { + $parts[$i] = $this->dbprefix.$parts[$i]; + } + + // Put the parts back together + $item = implode('.', $parts); + } + + if ($protect_identifiers === TRUE) + { + $item = $this->_escape_identifiers($item); + } + + return $item.$alias; + } + + // This is basically a bug fix for queries that use MAX, MIN, etc. + // If a parenthesis is found we know that we do not need to + // escape the data or add a prefix. There's probably a more graceful + // way to deal with this, but I'm not thinking of it -- Rick + if (strpos($item, '(') !== FALSE) + { + return $item.$alias; + } + + // Is there a table prefix? If not, no need to insert it + if ($this->dbprefix != '') + { + // Do we prefix an item with no segments? + if ($prefix_single == TRUE AND substr($item, 0, strlen($this->dbprefix)) != $this->dbprefix) + { + $item = $this->dbprefix.$item; + } + } + + if ($protect_identifiers === TRUE AND ! in_array($item, $this->_reserved_identifiers)) + { + $item = $this->_escape_identifiers($item); + } + + return $item.$alias; + } + + +} + + +/* End of file DB_driver.php */ /* Location: ./system/database/DB_driver.php */ \ No newline at end of file diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index 20f0a3087..f708910f8 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -1,355 +1,355 @@ -db - $CI =& get_instance(); - $this->db =& $CI->db; - log_message('debug', "Database Forge Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * Create database - * - * @access public - * @param string the database name - * @return bool - */ - function create_database($db_name) - { - $sql = $this->_create_database($db_name); - - if (is_bool($sql)) - { - return $sql; - } - - return $this->db->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access public - * @param string the database name - * @return bool - */ - function drop_database($db_name) - { - $sql = $this->_drop_database($db_name); - - if (is_bool($sql)) - { - return $sql; - } - - return $this->db->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Add Key - * - * @access public - * @param string key - * @param string type - * @return void - */ - function add_key($key = '', $primary = FALSE) - { - if (is_array($key)) - { - foreach($key as $one) - { - $this->add_key($one, $primary); - } - - return; - } - - if ($key == '') - { - show_error('Key information is required for that operation.'); - } - - if ($primary === TRUE) - { - $this->primary_keys[] = $key; - } - else - { - $this->keys[] = $key; - } - } - - // -------------------------------------------------------------------- - - /** - * Add Field - * - * @access public - * @param string collation - * @return void - */ - function add_field($field = '') - { - if ($field == '') - { - show_error('Field information is required.'); - } - - if (is_string($field)) - { - if ($field == 'id') - { - $this->add_field(array( - 'id' => array( - 'type' => 'INT', - 'constraint' => 9, - 'auto_increment' => TRUE - ) - )); - $this->add_key('id', TRUE); - } - else - { - if (strpos($field, ' ') === FALSE) - { - show_error('Field information is required for that operation.'); - } - - $this->fields[] = $field; - } - } - - if (is_array($field)) - { - $this->fields = array_merge($this->fields, $field); - } - - } - - // -------------------------------------------------------------------- - - /** - * Create Table - * - * @access public - * @param string the table name - * @return bool - */ - function create_table($table = '', $if_not_exists = FALSE) - { - if ($table == '') - { - show_error('A table name is required for that operation.'); - } - - if (count($this->fields) == 0) - { - show_error('Field information is required.'); - } - - $sql = $this->_create_table($this->db->dbprefix.$table, $this->fields, $this->primary_keys, $this->keys, $if_not_exists); - - $this->_reset(); - return $this->db->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Drop Table - * - * @access public - * @param string the table name - * @return bool - */ - function drop_table($table_name) - { - $sql = $this->_drop_table($this->db->dbprefix.$table_name); - - if (is_bool($sql)) - { - return $sql; - } - - return $this->db->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Rename Table - * - * @access public - * @param string the old table name - * @param string the new table name - * @return bool - */ - function rename_table($table_name, $new_table_name) - { - if ($table_name == '' OR $new_table_name == '') - { - show_error('A table name is required for that operation.'); - } - - $sql = $this->_rename_table($table_name, $new_table_name); - return $this->db->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Column Add - * - * @access public - * @param string the table name - * @param string the column name - * @param string the column definition - * @return bool - */ - function add_column($table = '', $field = array(), $after_field = '') - { - if ($table == '') - { - show_error('A table name is required for that operation.'); - } - - // add field info into field array, but we can only do one at a time - // so only grab the first field in the event there are more then one - $this->add_field(array_slice($field, 0, 1)); - - if (count($this->fields) == 0) - { - show_error('Field information is required.'); - } - - $sql = $this->_alter_table('ADD', $this->db->dbprefix.$table, $this->fields, $after_field); - - $this->_reset(); - return $this->db->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Column Drop - * - * @access public - * @param string the table name - * @param string the column name - * @return bool - */ - function drop_column($table = '', $column_name = '') - { - - if ($table == '') - { - show_error('A table name is required for that operation.'); - } - - if ($column_name == '') - { - show_error('A column name is required for that operation.'); - } - - $sql = $this->_alter_table('DROP', $this->db->dbprefix.$table, $column_name); - - return $this->db->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Column Modify - * - * @access public - * @param string the table name - * @param string the column name - * @param string the column definition - * @return bool - */ - function modify_column($table = '', $field = array()) - { - if ($table == '') - { - show_error('A table name is required for that operation.'); - } - - // add field info into field array, but we can only do one at a time - // so only grab the first field in the event there are more then one - $this->add_field(array_slice($field, 0, 1)); - - if (count($this->fields) == 0) - { - show_error('Field information is required.'); - } - - $sql = $this->_alter_table('CHANGE', $this->db->dbprefix.$table, $this->fields); - - $this->_reset(); - return $this->db->query($sql); - } - - // -------------------------------------------------------------------- - - /** - * Reset - * - * Resets table creation vars - * - * @access private - * @return void - */ - function _reset() - { - $this->fields = array(); - $this->keys = array(); - $this->primary_keys = array(); - } - -} - -/* End of file DB_forge.php */ +db + $CI =& get_instance(); + $this->db =& $CI->db; + log_message('debug', "Database Forge Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * Create database + * + * @access public + * @param string the database name + * @return bool + */ + function create_database($db_name) + { + $sql = $this->_create_database($db_name); + + if (is_bool($sql)) + { + return $sql; + } + + return $this->db->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access public + * @param string the database name + * @return bool + */ + function drop_database($db_name) + { + $sql = $this->_drop_database($db_name); + + if (is_bool($sql)) + { + return $sql; + } + + return $this->db->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Add Key + * + * @access public + * @param string key + * @param string type + * @return void + */ + function add_key($key = '', $primary = FALSE) + { + if (is_array($key)) + { + foreach($key as $one) + { + $this->add_key($one, $primary); + } + + return; + } + + if ($key == '') + { + show_error('Key information is required for that operation.'); + } + + if ($primary === TRUE) + { + $this->primary_keys[] = $key; + } + else + { + $this->keys[] = $key; + } + } + + // -------------------------------------------------------------------- + + /** + * Add Field + * + * @access public + * @param string collation + * @return void + */ + function add_field($field = '') + { + if ($field == '') + { + show_error('Field information is required.'); + } + + if (is_string($field)) + { + if ($field == 'id') + { + $this->add_field(array( + 'id' => array( + 'type' => 'INT', + 'constraint' => 9, + 'auto_increment' => TRUE + ) + )); + $this->add_key('id', TRUE); + } + else + { + if (strpos($field, ' ') === FALSE) + { + show_error('Field information is required for that operation.'); + } + + $this->fields[] = $field; + } + } + + if (is_array($field)) + { + $this->fields = array_merge($this->fields, $field); + } + + } + + // -------------------------------------------------------------------- + + /** + * Create Table + * + * @access public + * @param string the table name + * @return bool + */ + function create_table($table = '', $if_not_exists = FALSE) + { + if ($table == '') + { + show_error('A table name is required for that operation.'); + } + + if (count($this->fields) == 0) + { + show_error('Field information is required.'); + } + + $sql = $this->_create_table($this->db->dbprefix.$table, $this->fields, $this->primary_keys, $this->keys, $if_not_exists); + + $this->_reset(); + return $this->db->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * @access public + * @param string the table name + * @return bool + */ + function drop_table($table_name) + { + $sql = $this->_drop_table($this->db->dbprefix.$table_name); + + if (is_bool($sql)) + { + return $sql; + } + + return $this->db->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Rename Table + * + * @access public + * @param string the old table name + * @param string the new table name + * @return bool + */ + function rename_table($table_name, $new_table_name) + { + if ($table_name == '' OR $new_table_name == '') + { + show_error('A table name is required for that operation.'); + } + + $sql = $this->_rename_table($table_name, $new_table_name); + return $this->db->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Column Add + * + * @access public + * @param string the table name + * @param string the column name + * @param string the column definition + * @return bool + */ + function add_column($table = '', $field = array(), $after_field = '') + { + if ($table == '') + { + show_error('A table name is required for that operation.'); + } + + // add field info into field array, but we can only do one at a time + // so only grab the first field in the event there are more then one + $this->add_field(array_slice($field, 0, 1)); + + if (count($this->fields) == 0) + { + show_error('Field information is required.'); + } + + $sql = $this->_alter_table('ADD', $this->db->dbprefix.$table, $this->fields, $after_field); + + $this->_reset(); + return $this->db->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Column Drop + * + * @access public + * @param string the table name + * @param string the column name + * @return bool + */ + function drop_column($table = '', $column_name = '') + { + + if ($table == '') + { + show_error('A table name is required for that operation.'); + } + + if ($column_name == '') + { + show_error('A column name is required for that operation.'); + } + + $sql = $this->_alter_table('DROP', $this->db->dbprefix.$table, $column_name); + + return $this->db->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Column Modify + * + * @access public + * @param string the table name + * @param string the column name + * @param string the column definition + * @return bool + */ + function modify_column($table = '', $field = array()) + { + if ($table == '') + { + show_error('A table name is required for that operation.'); + } + + // add field info into field array, but we can only do one at a time + // so only grab the first field in the event there are more then one + $this->add_field(array_slice($field, 0, 1)); + + if (count($this->fields) == 0) + { + show_error('Field information is required.'); + } + + $sql = $this->_alter_table('CHANGE', $this->db->dbprefix.$table, $this->fields); + + $this->_reset(); + return $this->db->query($sql); + } + + // -------------------------------------------------------------------- + + /** + * Reset + * + * Resets table creation vars + * + * @access private + * @return void + */ + function _reset() + { + $this->fields = array(); + $this->keys = array(); + $this->primary_keys = array(); + } + +} + +/* End of file DB_forge.php */ /* Location: ./system/database/DB_forge.php */ \ No newline at end of file diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 8f55f6718..412814181 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -1,342 +1,342 @@ -result_object() : $this->result_array(); - } - - // -------------------------------------------------------------------- - - /** - * Query result. "object" version. - * - * @access public - * @return object - */ - function result_object() - { - if (count($this->result_object) > 0) - { - return $this->result_object; - } - - // In the event that query caching is on the result_id variable - // will return FALSE since there isn't a valid SQL resource so - // we'll simply return an empty array. - if ($this->result_id === FALSE OR $this->num_rows() == 0) - { - return array(); - } - - $this->_data_seek(0); - while ($row = $this->_fetch_object()) - { - $this->result_object[] = $row; - } - - return $this->result_object; - } - - // -------------------------------------------------------------------- - - /** - * Query result. "array" version. - * - * @access public - * @return array - */ - function result_array() - { - if (count($this->result_array) > 0) - { - return $this->result_array; - } - - // In the event that query caching is on the result_id variable - // will return FALSE since there isn't a valid SQL resource so - // we'll simply return an empty array. - if ($this->result_id === FALSE OR $this->num_rows() == 0) - { - return array(); - } - - $this->_data_seek(0); - while ($row = $this->_fetch_assoc()) - { - $this->result_array[] = $row; - } - - return $this->result_array; - } - - // -------------------------------------------------------------------- - - /** - * Query result. Acts as a wrapper function for the following functions. - * - * @access public - * @param string - * @param string can be "object" or "array" - * @return mixed either a result object or array - */ - function row($n = 0, $type = 'object') - { - if ( ! is_numeric($n)) - { - // We cache the row data for subsequent uses - if ( ! is_array($this->row_data)) - { - $this->row_data = $this->row_array(0); - } - - // array_key_exists() instead of isset() to allow for MySQL NULL values - if (array_key_exists($n, $this->row_data)) - { - return $this->row_data[$n]; - } - // reset the $n variable if the result was not achieved - $n = 0; - } - - return ($type == 'object') ? $this->row_object($n) : $this->row_array($n); - } - - // -------------------------------------------------------------------- - - /** - * Assigns an item into a particular column slot - * - * @access public - * @return object - */ - function set_row($key, $value = NULL) - { - // We cache the row data for subsequent uses - if ( ! is_array($this->row_data)) - { - $this->row_data = $this->row_array(0); - } - - if (is_array($key)) - { - foreach ($key as $k => $v) - { - $this->row_data[$k] = $v; - } - - return; - } - - if ($key != '' AND ! is_null($value)) - { - $this->row_data[$key] = $value; - } - } - - // -------------------------------------------------------------------- - - /** - * Returns a single result row - object version - * - * @access public - * @return object - */ - function row_object($n = 0) - { - $result = $this->result_object(); - - if (count($result) == 0) - { - return $result; - } - - if ($n != $this->current_row AND isset($result[$n])) - { - $this->current_row = $n; - } - - return $result[$this->current_row]; - } - - // -------------------------------------------------------------------- - - /** - * Returns a single result row - array version - * - * @access public - * @return array - */ - function row_array($n = 0) - { - $result = $this->result_array(); - - if (count($result) == 0) - { - return $result; - } - - if ($n != $this->current_row AND isset($result[$n])) - { - $this->current_row = $n; - } - - return $result[$this->current_row]; - } - - - // -------------------------------------------------------------------- - - /** - * Returns the "first" row - * - * @access public - * @return object - */ - function first_row($type = 'object') - { - $result = $this->result($type); - - if (count($result) == 0) - { - return $result; - } - return $result[0]; - } - - // -------------------------------------------------------------------- - - /** - * Returns the "last" row - * - * @access public - * @return object - */ - function last_row($type = 'object') - { - $result = $this->result($type); - - if (count($result) == 0) - { - return $result; - } - return $result[count($result) -1]; - } - - // -------------------------------------------------------------------- - - /** - * Returns the "next" row - * - * @access public - * @return object - */ - function next_row($type = 'object') - { - $result = $this->result($type); - - if (count($result) == 0) - { - return $result; - } - - if (isset($result[$this->current_row + 1])) - { - ++$this->current_row; - } - - return $result[$this->current_row]; - } - - // -------------------------------------------------------------------- - - /** - * Returns the "previous" row - * - * @access public - * @return object - */ - function previous_row($type = 'object') - { - $result = $this->result($type); - - if (count($result) == 0) - { - return $result; - } - - if (isset($result[$this->current_row - 1])) - { - --$this->current_row; - } - return $result[$this->current_row]; - } - - // -------------------------------------------------------------------- - - /** - * The following functions are normally overloaded by the identically named - * methods in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver. - * These functions are primarily here to prevent undefined function errors - * when a cached result object is in use. They are not otherwise fully - * operational due to the unavailability of the database resource IDs with - * cached results. - */ - function num_rows() { return $this->num_rows; } - function num_fields() { return 0; } - function list_fields() { return array(); } - function field_data() { return array(); } - function free_result() { return TRUE; } - function _data_seek() { return TRUE; } - function _fetch_assoc() { return array(); } - function _fetch_object() { return array(); } - -} -// END DB_result class - -/* End of file DB_result.php */ +result_object() : $this->result_array(); + } + + // -------------------------------------------------------------------- + + /** + * Query result. "object" version. + * + * @access public + * @return object + */ + function result_object() + { + if (count($this->result_object) > 0) + { + return $this->result_object; + } + + // In the event that query caching is on the result_id variable + // will return FALSE since there isn't a valid SQL resource so + // we'll simply return an empty array. + if ($this->result_id === FALSE OR $this->num_rows() == 0) + { + return array(); + } + + $this->_data_seek(0); + while ($row = $this->_fetch_object()) + { + $this->result_object[] = $row; + } + + return $this->result_object; + } + + // -------------------------------------------------------------------- + + /** + * Query result. "array" version. + * + * @access public + * @return array + */ + function result_array() + { + if (count($this->result_array) > 0) + { + return $this->result_array; + } + + // In the event that query caching is on the result_id variable + // will return FALSE since there isn't a valid SQL resource so + // we'll simply return an empty array. + if ($this->result_id === FALSE OR $this->num_rows() == 0) + { + return array(); + } + + $this->_data_seek(0); + while ($row = $this->_fetch_assoc()) + { + $this->result_array[] = $row; + } + + return $this->result_array; + } + + // -------------------------------------------------------------------- + + /** + * Query result. Acts as a wrapper function for the following functions. + * + * @access public + * @param string + * @param string can be "object" or "array" + * @return mixed either a result object or array + */ + function row($n = 0, $type = 'object') + { + if ( ! is_numeric($n)) + { + // We cache the row data for subsequent uses + if ( ! is_array($this->row_data)) + { + $this->row_data = $this->row_array(0); + } + + // array_key_exists() instead of isset() to allow for MySQL NULL values + if (array_key_exists($n, $this->row_data)) + { + return $this->row_data[$n]; + } + // reset the $n variable if the result was not achieved + $n = 0; + } + + return ($type == 'object') ? $this->row_object($n) : $this->row_array($n); + } + + // -------------------------------------------------------------------- + + /** + * Assigns an item into a particular column slot + * + * @access public + * @return object + */ + function set_row($key, $value = NULL) + { + // We cache the row data for subsequent uses + if ( ! is_array($this->row_data)) + { + $this->row_data = $this->row_array(0); + } + + if (is_array($key)) + { + foreach ($key as $k => $v) + { + $this->row_data[$k] = $v; + } + + return; + } + + if ($key != '' AND ! is_null($value)) + { + $this->row_data[$key] = $value; + } + } + + // -------------------------------------------------------------------- + + /** + * Returns a single result row - object version + * + * @access public + * @return object + */ + function row_object($n = 0) + { + $result = $this->result_object(); + + if (count($result) == 0) + { + return $result; + } + + if ($n != $this->current_row AND isset($result[$n])) + { + $this->current_row = $n; + } + + return $result[$this->current_row]; + } + + // -------------------------------------------------------------------- + + /** + * Returns a single result row - array version + * + * @access public + * @return array + */ + function row_array($n = 0) + { + $result = $this->result_array(); + + if (count($result) == 0) + { + return $result; + } + + if ($n != $this->current_row AND isset($result[$n])) + { + $this->current_row = $n; + } + + return $result[$this->current_row]; + } + + + // -------------------------------------------------------------------- + + /** + * Returns the "first" row + * + * @access public + * @return object + */ + function first_row($type = 'object') + { + $result = $this->result($type); + + if (count($result) == 0) + { + return $result; + } + return $result[0]; + } + + // -------------------------------------------------------------------- + + /** + * Returns the "last" row + * + * @access public + * @return object + */ + function last_row($type = 'object') + { + $result = $this->result($type); + + if (count($result) == 0) + { + return $result; + } + return $result[count($result) -1]; + } + + // -------------------------------------------------------------------- + + /** + * Returns the "next" row + * + * @access public + * @return object + */ + function next_row($type = 'object') + { + $result = $this->result($type); + + if (count($result) == 0) + { + return $result; + } + + if (isset($result[$this->current_row + 1])) + { + ++$this->current_row; + } + + return $result[$this->current_row]; + } + + // -------------------------------------------------------------------- + + /** + * Returns the "previous" row + * + * @access public + * @return object + */ + function previous_row($type = 'object') + { + $result = $this->result($type); + + if (count($result) == 0) + { + return $result; + } + + if (isset($result[$this->current_row - 1])) + { + --$this->current_row; + } + return $result[$this->current_row]; + } + + // -------------------------------------------------------------------- + + /** + * The following functions are normally overloaded by the identically named + * methods in the platform-specific driver -- except when query caching + * is used. When caching is enabled we do not load the other driver. + * These functions are primarily here to prevent undefined function errors + * when a cached result object is in use. They are not otherwise fully + * operational due to the unavailability of the database resource IDs with + * cached results. + */ + function num_rows() { return $this->num_rows; } + function num_fields() { return 0; } + function list_fields() { return array(); } + function field_data() { return array(); } + function free_result() { return TRUE; } + function _data_seek() { return TRUE; } + function _fetch_assoc() { return array(); } + function _fetch_object() { return array(); } + +} +// END DB_result class + +/* End of file DB_result.php */ /* Location: ./system/database/DB_result.php */ \ No newline at end of file diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index a37522d90..195e4c46a 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -1,389 +1,389 @@ -db - $CI =& get_instance(); - $this->db =& $CI->db; - - log_message('debug', "Database Utility Class Initialized"); - } - - // -------------------------------------------------------------------- - - /** - * List databases - * - * @access public - * @return bool - */ - function list_databases() - { - // Is there a cached result? - if (isset($this->data_cache['db_names'])) - { - return $this->data_cache['db_names']; - } - - $query = $this->db->query($this->_list_databases()); - $dbs = array(); - if ($query->num_rows() > 0) - { - foreach ($query->result_array() as $row) - { - $dbs[] = current($row); - } - } - - $this->data_cache['db_names'] = $dbs; - return $this->data_cache['db_names']; - } - - // -------------------------------------------------------------------- - - /** - * Optimize Table - * - * @access public - * @param string the table name - * @return bool - */ - function optimize_table($table_name) - { - $sql = $this->_optimize_table($table_name); - - if (is_bool($sql)) - { - show_error('db_must_use_set'); - } - - $query = $this->db->query($sql); - $res = $query->result_array(); - - // Note: Due to a bug in current() that affects some versions - // of PHP we can not pass function call directly into it - return current($res); - } - - // -------------------------------------------------------------------- - - /** - * Optimize Database - * - * @access public - * @return array - */ - function optimize_database() - { - $result = array(); - foreach ($this->db->list_tables() as $table_name) - { - $sql = $this->_optimize_table($table_name); - - if (is_bool($sql)) - { - return $sql; - } - - $query = $this->db->query($sql); - - // Build the result array... - // Note: Due to a bug in current() that affects some versions - // of PHP we can not pass function call directly into it - $res = $query->result_array(); - $res = current($res); - $key = str_replace($this->db->database.'.', '', current($res)); - $keys = array_keys($res); - unset($res[$keys[0]]); - - $result[$key] = $res; - } - - return $result; - } - - // -------------------------------------------------------------------- - - /** - * Repair Table - * - * @access public - * @param string the table name - * @return bool - */ - function repair_table($table_name) - { - $sql = $this->_repair_table($table_name); - - if (is_bool($sql)) - { - return $sql; - } - - $query = $this->db->query($sql); - - // Note: Due to a bug in current() that affects some versions - // of PHP we can not pass function call directly into it - $res = $query->result_array(); - return current($res); - } - - // -------------------------------------------------------------------- - - /** - * Generate CSV from a query result object - * - * @access public - * @param object The query result object - * @param string The delimiter - comma by default - * @param string The newline character - \n by default - * @param string The enclosure - double quote by default - * @return string - */ - function csv_from_result($query, $delim = ",", $newline = "\n", $enclosure = '"') - { - if ( ! is_object($query) OR ! method_exists($query, 'field_names')) - { - show_error('You must submit a valid result object'); - } - - $out = ''; - - // First generate the headings from the table column names - foreach ($query->list_fields() as $name) - { - $out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $name).$enclosure.$delim; - } - - $out = rtrim($out); - $out .= $newline; - - // Next blast through the result array and build out the rows - foreach ($query->result_array() as $row) - { - foreach ($row as $item) - { - $out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $item).$enclosure.$delim; - } - $out = rtrim($out); - $out .= $newline; - } - - return $out; - } - - // -------------------------------------------------------------------- - - /** - * Generate XML data from a query result object - * - * @access public - * @param object The query result object - * @param array Any preferences - * @return string - */ - function xml_from_result($query, $params = array()) - { - if ( ! is_object($query) OR ! method_exists($query, 'field_names')) - { - show_error('You must submit a valid result object'); - } - - // Set our default values - foreach (array('root' => 'root', 'element' => 'element', 'newline' => "\n", 'tab' => "\t") as $key => $val) - { - if ( ! isset($params[$key])) - { - $params[$key] = $val; - } - } - - // Create variables for convenience - extract($params); - - // Load the xml helper - $CI =& get_instance(); - $CI->load->helper('xml'); - - // Generate the result - $xml = "<{$root}>".$newline; - foreach ($query->result_array() as $row) - { - $xml .= $tab."<{$element}>".$newline; - - foreach ($row as $key => $val) - { - $xml .= $tab.$tab."<{$key}>".xml_convert($val)."".$newline; - } - $xml .= $tab."".$newline; - } - $xml .= "".$newline; - - return $xml; - } - - // -------------------------------------------------------------------- - - /** - * Database Backup - * - * @access public - * @return void - */ - function backup($params = array()) - { - // If the parameters have not been submitted as an - // array then we know that it is simply the table - // name, which is a valid short cut. - if (is_string($params)) - { - $params = array('tables' => $params); - } - - // ------------------------------------------------------ - - // 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" - ); - - // Did the user submit any preferences? If so set them.... - if (count($params) > 0) - { - foreach ($prefs as $key => $val) - { - if (isset($params[$key])) - { - $prefs[$key] = $params[$key]; - } - } - } - - // ------------------------------------------------------ - - // Are we backing up a complete database or individual tables? - // If no table names were submitted we'll fetch the entire table list - if (count($prefs['tables']) == 0) - { - $prefs['tables'] = $this->db->list_tables(); - } - - // ------------------------------------------------------ - - // Validate the format - if ( ! in_array($prefs['format'], array('gzip', 'zip', 'txt'), TRUE)) - { - $prefs['format'] = 'txt'; - } - - // ------------------------------------------------------ - - // Is the encoder supported? If not, we'll either issue an - // error or use plain text depending on the debug settings - if (($prefs['format'] == 'gzip' AND ! @function_exists('gzencode')) - OR ($prefs['format'] == 'zip' AND ! @function_exists('gzcompress'))) - { - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_compression'); - } - - $prefs['format'] = 'txt'; - } - - // ------------------------------------------------------ - - // Set the filename if not provided - Only needed with Zip files - if ($prefs['filename'] == '' AND $prefs['format'] == 'zip') - { - $prefs['filename'] = (count($prefs['tables']) == 1) ? $prefs['tables'] : $this->db->database; - $prefs['filename'] .= '_'.date('Y-m-d_H-i', time()); - } - - // ------------------------------------------------------ - - // Was a Gzip file requested? - if ($prefs['format'] == 'gzip') - { - return gzencode($this->_backup($prefs)); - } - - // ------------------------------------------------------ - - // Was a text file requested? - if ($prefs['format'] == 'txt') - { - return $this->_backup($prefs); - } - - // ------------------------------------------------------ - - // Was a Zip file requested? - if ($prefs['format'] == 'zip') - { - // If they included the .zip file extension we'll remove it - if (preg_match("|.+?\.zip$|", $prefs['filename'])) - { - $prefs['filename'] = str_replace('.zip', '', $prefs['filename']); - } - - // Tack on the ".sql" file extension if needed - if ( ! preg_match("|.+?\.sql$|", $prefs['filename'])) - { - $prefs['filename'] .= '.sql'; - } - - // Load the Zip class and output it - - $CI =& get_instance(); - $CI->load->library('zip'); - $CI->zip->add_data($prefs['filename'], $this->_backup($prefs)); - return $CI->zip->get_zip(); - } - - } - -} - - -/* End of file DB_utility.php */ +db + $CI =& get_instance(); + $this->db =& $CI->db; + + log_message('debug', "Database Utility Class Initialized"); + } + + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access public + * @return bool + */ + function list_databases() + { + // Is there a cached result? + if (isset($this->data_cache['db_names'])) + { + return $this->data_cache['db_names']; + } + + $query = $this->db->query($this->_list_databases()); + $dbs = array(); + if ($query->num_rows() > 0) + { + foreach ($query->result_array() as $row) + { + $dbs[] = current($row); + } + } + + $this->data_cache['db_names'] = $dbs; + return $this->data_cache['db_names']; + } + + // -------------------------------------------------------------------- + + /** + * Optimize Table + * + * @access public + * @param string the table name + * @return bool + */ + function optimize_table($table_name) + { + $sql = $this->_optimize_table($table_name); + + if (is_bool($sql)) + { + show_error('db_must_use_set'); + } + + $query = $this->db->query($sql); + $res = $query->result_array(); + + // Note: Due to a bug in current() that affects some versions + // of PHP we can not pass function call directly into it + return current($res); + } + + // -------------------------------------------------------------------- + + /** + * Optimize Database + * + * @access public + * @return array + */ + function optimize_database() + { + $result = array(); + foreach ($this->db->list_tables() as $table_name) + { + $sql = $this->_optimize_table($table_name); + + if (is_bool($sql)) + { + return $sql; + } + + $query = $this->db->query($sql); + + // Build the result array... + // Note: Due to a bug in current() that affects some versions + // of PHP we can not pass function call directly into it + $res = $query->result_array(); + $res = current($res); + $key = str_replace($this->db->database.'.', '', current($res)); + $keys = array_keys($res); + unset($res[$keys[0]]); + + $result[$key] = $res; + } + + return $result; + } + + // -------------------------------------------------------------------- + + /** + * Repair Table + * + * @access public + * @param string the table name + * @return bool + */ + function repair_table($table_name) + { + $sql = $this->_repair_table($table_name); + + if (is_bool($sql)) + { + return $sql; + } + + $query = $this->db->query($sql); + + // Note: Due to a bug in current() that affects some versions + // of PHP we can not pass function call directly into it + $res = $query->result_array(); + return current($res); + } + + // -------------------------------------------------------------------- + + /** + * Generate CSV from a query result object + * + * @access public + * @param object The query result object + * @param string The delimiter - comma by default + * @param string The newline character - \n by default + * @param string The enclosure - double quote by default + * @return string + */ + function csv_from_result($query, $delim = ",", $newline = "\n", $enclosure = '"') + { + if ( ! is_object($query) OR ! method_exists($query, 'field_names')) + { + show_error('You must submit a valid result object'); + } + + $out = ''; + + // First generate the headings from the table column names + foreach ($query->list_fields() as $name) + { + $out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $name).$enclosure.$delim; + } + + $out = rtrim($out); + $out .= $newline; + + // Next blast through the result array and build out the rows + foreach ($query->result_array() as $row) + { + foreach ($row as $item) + { + $out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $item).$enclosure.$delim; + } + $out = rtrim($out); + $out .= $newline; + } + + return $out; + } + + // -------------------------------------------------------------------- + + /** + * Generate XML data from a query result object + * + * @access public + * @param object The query result object + * @param array Any preferences + * @return string + */ + function xml_from_result($query, $params = array()) + { + if ( ! is_object($query) OR ! method_exists($query, 'field_names')) + { + show_error('You must submit a valid result object'); + } + + // Set our default values + foreach (array('root' => 'root', 'element' => 'element', 'newline' => "\n", 'tab' => "\t") as $key => $val) + { + if ( ! isset($params[$key])) + { + $params[$key] = $val; + } + } + + // Create variables for convenience + extract($params); + + // Load the xml helper + $CI =& get_instance(); + $CI->load->helper('xml'); + + // Generate the result + $xml = "<{$root}>".$newline; + foreach ($query->result_array() as $row) + { + $xml .= $tab."<{$element}>".$newline; + + foreach ($row as $key => $val) + { + $xml .= $tab.$tab."<{$key}>".xml_convert($val)."".$newline; + } + $xml .= $tab."".$newline; + } + $xml .= "".$newline; + + return $xml; + } + + // -------------------------------------------------------------------- + + /** + * Database Backup + * + * @access public + * @return void + */ + function backup($params = array()) + { + // If the parameters have not been submitted as an + // array then we know that it is simply the table + // name, which is a valid short cut. + if (is_string($params)) + { + $params = array('tables' => $params); + } + + // ------------------------------------------------------ + + // 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" + ); + + // Did the user submit any preferences? If so set them.... + if (count($params) > 0) + { + foreach ($prefs as $key => $val) + { + if (isset($params[$key])) + { + $prefs[$key] = $params[$key]; + } + } + } + + // ------------------------------------------------------ + + // Are we backing up a complete database or individual tables? + // If no table names were submitted we'll fetch the entire table list + if (count($prefs['tables']) == 0) + { + $prefs['tables'] = $this->db->list_tables(); + } + + // ------------------------------------------------------ + + // Validate the format + if ( ! in_array($prefs['format'], array('gzip', 'zip', 'txt'), TRUE)) + { + $prefs['format'] = 'txt'; + } + + // ------------------------------------------------------ + + // Is the encoder supported? If not, we'll either issue an + // error or use plain text depending on the debug settings + if (($prefs['format'] == 'gzip' AND ! @function_exists('gzencode')) + OR ($prefs['format'] == 'zip' AND ! @function_exists('gzcompress'))) + { + if ($this->db->db_debug) + { + return $this->db->display_error('db_unsuported_compression'); + } + + $prefs['format'] = 'txt'; + } + + // ------------------------------------------------------ + + // Set the filename if not provided - Only needed with Zip files + if ($prefs['filename'] == '' AND $prefs['format'] == 'zip') + { + $prefs['filename'] = (count($prefs['tables']) == 1) ? $prefs['tables'] : $this->db->database; + $prefs['filename'] .= '_'.date('Y-m-d_H-i', time()); + } + + // ------------------------------------------------------ + + // Was a Gzip file requested? + if ($prefs['format'] == 'gzip') + { + return gzencode($this->_backup($prefs)); + } + + // ------------------------------------------------------ + + // Was a text file requested? + if ($prefs['format'] == 'txt') + { + return $this->_backup($prefs); + } + + // ------------------------------------------------------ + + // Was a Zip file requested? + if ($prefs['format'] == 'zip') + { + // If they included the .zip file extension we'll remove it + if (preg_match("|.+?\.zip$|", $prefs['filename'])) + { + $prefs['filename'] = str_replace('.zip', '', $prefs['filename']); + } + + // Tack on the ".sql" file extension if needed + if ( ! preg_match("|.+?\.sql$|", $prefs['filename'])) + { + $prefs['filename'] .= '.sql'; + } + + // Load the Zip class and output it + + $CI =& get_instance(); + $CI->load->library('zip'); + $CI->zip->add_data($prefs['filename'], $this->_backup($prefs)); + return $CI->zip->get_zip(); + } + + } + +} + + +/* End of file DB_utility.php */ /* Location: ./system/database/DB_utility.php */ \ No newline at end of file diff --git a/system/database/drivers/index.html b/system/database/drivers/index.html index 065d2da5e..c942a79ce 100644 --- a/system/database/drivers/index.html +++ b/system/database/drivers/index.html @@ -1,10 +1,10 @@ - - - 403 Forbidden - - - -

Directory access is forbidden.

- - + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + \ No newline at end of file diff --git a/system/database/drivers/mssql/index.html b/system/database/drivers/mssql/index.html index 065d2da5e..c942a79ce 100644 --- a/system/database/drivers/mssql/index.html +++ b/system/database/drivers/mssql/index.html @@ -1,10 +1,10 @@ - - - 403 Forbidden - - - -

Directory access is forbidden.

- - + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 6ad0880ff..78f81daf7 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -1,622 +1,622 @@ -port != '') - { - $this->hostname .= ','.$this->port; - } - - return @mssql_connect($this->hostname, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - if ($this->port != '') - { - $this->hostname .= ','.$this->port; - } - - return @mssql_pconnect($this->hostname, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - // Note: The brackets are required in the event that the DB name - // contains reserved characters - return @mssql_select_db('['.$this->database.']', $this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Set client character set - * - * @access public - * @param string - * @param string - * @return resource - */ - function db_set_charset($charset, $collation) - { - // @todo - add support if needed - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return resource - */ - function _execute($sql) - { - $sql = $this->_prep_query($sql); - return @mssql_query($sql, $this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @access private called by execute() - * @param string an SQL query - * @return string - */ - function _prep_query($sql) - { - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @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) - { - return TRUE; - } - - // Reset the transaction failure flag. - // 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('BEGIN TRAN'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $this->simple_query('COMMIT TRAN'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $this->simple_query('ROLLBACK TRAN'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @return string - */ - function escape_str($str) - { - // Access the CI object - $CI =& get_instance(); - - // Escape single quotes - return str_replace("'", "''", $CI->input->_remove_invisible_characters($str)); - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @mssql_rows_affected($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * Returns the last id created in the Identity column. - * - * @access public - * @return integer - */ - function insert_id() - { - $ver = self::_parse_major_version($this->version()); - $sql = ($ver >= 8 ? "SELECT SCOPE_IDENTITY() AS last_id" : "SELECT @@IDENTITY AS last_id"); - $query = $this->query($sql); - $row = $query->row(); - return $row->last_id; - } - - // -------------------------------------------------------------------- - - /** - * Parse major version - * - * Grabs the major version number from the - * database server version string passed in. - * - * @access private - * @param string $version - * @return int16 major version number - */ - function _parse_major_version($version) - { - preg_match('/([0-9]+)\.([0-9]+)\.([0-9]+)/', $version, $ver_info); - return $ver_info[1]; // return the major version b/c that's all we're interested in. - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT @@VERSION AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - 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) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * List table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @param boolean - * @return string - */ - function _list_tables($prefix_limit = FALSE) - { - $sql = "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; - - // for future compatibility - if ($prefix_limit !== FALSE AND $this->dbprefix != '') - { - //$sql .= " LIKE '".$this->dbprefix."%'"; - return FALSE; // not currently supported - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * List column query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access private - * @param string the table name - * @return string - */ - function _list_columns($table = '') - { - return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$table."'"; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - return "SELECT TOP 1 * FROM ".$table; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access private - * @return string - */ - function _error_message() - { - // Are errros even supported in MS SQL? - return ''; - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access private - * @return integer - */ - function _error_number() - { - // Are error numbers supported? - return ''; - } - - // -------------------------------------------------------------------- - - /** - * Escape the SQL Identifiers - * - * This function escapes column and table names - * - * @access private - * @param string - * @return string - */ - function _escape_identifiers($item) - { - if ($this->_escape_char == '') - { - return $item; - } - - foreach ($this->_reserved_identifiers as $id) - { - if (strpos($item, '.'.$id) !== FALSE) - { - $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; - } - 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); - } - - // -------------------------------------------------------------------- - - /** - * From Tables - * - * This function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @access public - * @param type - * @return type - */ - function _from_tables($tables) - { - if ( ! is_array($tables)) - { - $tables = array($tables); - } - - return implode(', ', $tables); - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @param array the orderby clause - * @param array the limit clause - * @return string - */ - function _update($table, $values, $where, $orderby = array(), $limit = FALSE) - { - foreach($values as $key => $val) - { - $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; - } - - - // -------------------------------------------------------------------- - - /** - * Truncate statement - * - * Generates a platform-specific truncate string from the supplied data - * If the database does not support the truncate() command - * This function maps to "DELETE FROM table" - * - * @access public - * @param string the table name - * @return string - */ - function _truncate($table) - { - return "TRUNCATE ".$table; - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @param string the limit clause - * @return string - */ - function _delete($table, $where = array(), $like = array(), $limit = FALSE) - { - $conditions = ''; - - if (count($where) > 0 OR count($like) > 0) - { - $conditions = "\nWHERE "; - $conditions .= implode("\n", $this->ar_where); - - if (count($where) > 0 && count($like) > 0) - { - $conditions .= " AND "; - } - $conditions .= implode("\n", $like); - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - return "DELETE FROM ".$table.$conditions.$limit; - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - $i = $limit + $offset; - - return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql); - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - @mssql_close($conn_id); - } - -} - - - -/* End of file mssql_driver.php */ +port != '') + { + $this->hostname .= ','.$this->port; + } + + return @mssql_connect($this->hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + if ($this->port != '') + { + $this->hostname .= ','.$this->port; + } + + return @mssql_pconnect($this->hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + // Note: The brackets are required in the event that the DB name + // contains reserved characters + return @mssql_select_db('['.$this->database.']', $this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Set client character set + * + * @access public + * @param string + * @param string + * @return resource + */ + function db_set_charset($charset, $collation) + { + // @todo - add support if needed + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + function _execute($sql) + { + $sql = $this->_prep_query($sql); + return @mssql_query($sql, $this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @access private called by execute() + * @param string an SQL query + * @return string + */ + function _prep_query($sql) + { + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @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) + { + return TRUE; + } + + // Reset the transaction failure flag. + // 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('BEGIN TRAN'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @access public + * @return bool + */ + function trans_commit() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $this->simple_query('COMMIT TRAN'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @access public + * @return bool + */ + function trans_rollback() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $this->simple_query('ROLLBACK TRAN'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + // Access the CI object + $CI =& get_instance(); + + // Escape single quotes + return str_replace("'", "''", $CI->input->_remove_invisible_characters($str)); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @mssql_rows_affected($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * Returns the last id created in the Identity column. + * + * @access public + * @return integer + */ + function insert_id() + { + $ver = self::_parse_major_version($this->version()); + $sql = ($ver >= 8 ? "SELECT SCOPE_IDENTITY() AS last_id" : "SELECT @@IDENTITY AS last_id"); + $query = $this->query($sql); + $row = $query->row(); + return $row->last_id; + } + + // -------------------------------------------------------------------- + + /** + * Parse major version + * + * Grabs the major version number from the + * database server version string passed in. + * + * @access private + * @param string $version + * @return int16 major version number + */ + function _parse_major_version($version) + { + preg_match('/([0-9]+)\.([0-9]+)\.([0-9]+)/', $version, $ver_info); + return $ver_info[1]; // return the major version b/c that's all we're interested in. + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT @@VERSION AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + 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) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @param boolean + * @return string + */ + function _list_tables($prefix_limit = FALSE) + { + $sql = "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; + + // for future compatibility + if ($prefix_limit !== FALSE AND $this->dbprefix != '') + { + //$sql .= " LIKE '".$this->dbprefix."%'"; + return FALSE; // not currently supported + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * List column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access private + * @param string the table name + * @return string + */ + function _list_columns($table = '') + { + return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$table."'"; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + return "SELECT TOP 1 * FROM ".$table; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access private + * @return string + */ + function _error_message() + { + // Are errros even supported in MS SQL? + return ''; + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access private + * @return integer + */ + function _error_number() + { + // Are error numbers supported? + return ''; + } + + // -------------------------------------------------------------------- + + /** + * Escape the SQL Identifiers + * + * This function escapes column and table names + * + * @access private + * @param string + * @return string + */ + function _escape_identifiers($item) + { + if ($this->_escape_char == '') + { + return $item; + } + + foreach ($this->_reserved_identifiers as $id) + { + if (strpos($item, '.'.$id) !== FALSE) + { + $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; + } + 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); + } + + // -------------------------------------------------------------------- + + /** + * From Tables + * + * This function implicitly groups FROM tables so there is no confusion + * about operator precedence in harmony with SQL standards + * + * @access public + * @param type + * @return type + */ + function _from_tables($tables) + { + if ( ! is_array($tables)) + { + $tables = array($tables); + } + + return implode(', ', $tables); + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @param array the orderby clause + * @param array the limit clause + * @return string + */ + function _update($table, $values, $where, $orderby = array(), $limit = FALSE) + { + foreach($values as $key => $val) + { + $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; + } + + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * If the database does not support the truncate() command + * This function maps to "DELETE FROM table" + * + * @access public + * @param string the table name + * @return string + */ + function _truncate($table) + { + return "TRUNCATE ".$table; + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @param string the limit clause + * @return string + */ + function _delete($table, $where = array(), $like = array(), $limit = FALSE) + { + $conditions = ''; + + if (count($where) > 0 OR count($like) > 0) + { + $conditions = "\nWHERE "; + $conditions .= implode("\n", $this->ar_where); + + if (count($where) > 0 && count($like) > 0) + { + $conditions .= " AND "; + } + $conditions .= implode("\n", $like); + } + + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; + + return "DELETE FROM ".$table.$conditions.$limit; + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + $i = $limit + $offset; + + return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql); + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + @mssql_close($conn_id); + } + +} + + + +/* End of file mssql_driver.php */ /* Location: ./system/database/drivers/mssql/mssql_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php index 8665dc055..512fc47d5 100644 --- a/system/database/drivers/mssql/mssql_forge.php +++ b/system/database/drivers/mssql/mssql_forge.php @@ -1,248 +1,248 @@ -db->_escape_identifiers($table); - } - - // -------------------------------------------------------------------- - - /** - * Create Table - * - * @access private - * @param string the table name - * @param array the fields - * @param mixed primary key(s) - * @param mixed key(s) - * @param boolean should 'IF NOT EXISTS' be added to the SQL - * @return bool - */ - 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)." ("; - $current_field_count = 0; - - foreach ($fields as $field=>$attributes) - { - // Numeric field names aren't allowed in databases, so if the key is - // numeric, we know it was assigned by PHP and the developer manually - // entered the field information, so we'll simply add it to the list - if (is_numeric($field)) - { - $sql .= "\n\t$attributes"; - } - else - { - $attributes = array_change_key_case($attributes, CASE_UPPER); - - $sql .= "\n\t".$this->db->_protect_identifiers($field); - - $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) && $attributes['NULL'] === TRUE) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' 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 .= ','; - } - } - - if (count($primary_keys) > 0) - { - $primary_keys = $this->db->_protect_identifiers($primary_keys); - $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; - } - - if (is_array($keys) && count($keys) > 0) - { - foreach ($keys as $key) - { - if (is_array($key)) - { - $key = $this->db->_protect_identifiers($key); - } - else - { - $key = array($this->db->_protect_identifiers($key)); - } - - $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")"; - } - } - - $sql .= "\n)"; - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Alter table query - * - * Generates a platform-specific query so that a table can be altered - * Called by add_column(), drop_column(), and column_alter(), - * - * @access private - * @param string the ALTER type (ADD, DROP, CHANGE) - * @param string the column name - * @param string the table name - * @param string the column definition - * @param string the default value - * @param boolean should 'NOT NULL' be added - * @param string the field after which we should add the new field - * @return object - */ - function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') - { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name); - - // DROP has everything it needs now. - if ($alter_type == 'DROP') - { - return $sql; - } - - $sql .= " $column_definition"; - - if ($default_value != '') - { - $sql .= " DEFAULT \"$default_value\""; - } - - if ($null === NULL) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } - - if ($after_field != '') - { - $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); - } - - return $sql; - - } - - // -------------------------------------------------------------------- - - /** - * Rename a table - * - * Generates a platform-specific query so that a table can be renamed - * - * @access private - * @param string the old table name - * @param string the new table name - * @return string - */ - function _rename_table($table_name, $new_table_name) - { - // I think this syntax will work, but can find little documentation on renaming tables in MSSQL - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); - return $sql; - } - -} - -/* End of file mssql_forge.php */ +db->_escape_identifiers($table); + } + + // -------------------------------------------------------------------- + + /** + * Create Table + * + * @access private + * @param string the table name + * @param array the fields + * @param mixed primary key(s) + * @param mixed key(s) + * @param boolean should 'IF NOT EXISTS' be added to the SQL + * @return bool + */ + 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)." ("; + $current_field_count = 0; + + foreach ($fields as $field=>$attributes) + { + // Numeric field names aren't allowed in databases, so if the key is + // numeric, we know it was assigned by PHP and the developer manually + // entered the field information, so we'll simply add it to the list + if (is_numeric($field)) + { + $sql .= "\n\t$attributes"; + } + else + { + $attributes = array_change_key_case($attributes, CASE_UPPER); + + $sql .= "\n\t".$this->db->_protect_identifiers($field); + + $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) && $attributes['NULL'] === TRUE) + { + $sql .= ' NULL'; + } + else + { + $sql .= ' 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 .= ','; + } + } + + if (count($primary_keys) > 0) + { + $primary_keys = $this->db->_protect_identifiers($primary_keys); + $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; + } + + if (is_array($keys) && count($keys) > 0) + { + foreach ($keys as $key) + { + if (is_array($key)) + { + $key = $this->db->_protect_identifiers($key); + } + else + { + $key = array($this->db->_protect_identifiers($key)); + } + + $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")"; + } + } + + $sql .= "\n)"; + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Alter table query + * + * Generates a platform-specific query so that a table can be altered + * Called by add_column(), drop_column(), and column_alter(), + * + * @access private + * @param string the ALTER type (ADD, DROP, CHANGE) + * @param string the column name + * @param string the table name + * @param string the column definition + * @param string the default value + * @param boolean should 'NOT NULL' be added + * @param string the field after which we should add the new field + * @return object + */ + function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') + { + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name); + + // DROP has everything it needs now. + if ($alter_type == 'DROP') + { + return $sql; + } + + $sql .= " $column_definition"; + + if ($default_value != '') + { + $sql .= " DEFAULT \"$default_value\""; + } + + if ($null === NULL) + { + $sql .= ' NULL'; + } + else + { + $sql .= ' NOT NULL'; + } + + if ($after_field != '') + { + $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); + } + + return $sql; + + } + + // -------------------------------------------------------------------- + + /** + * Rename a table + * + * Generates a platform-specific query so that a table can be renamed + * + * @access private + * @param string the old table name + * @param string the new table name + * @return string + */ + function _rename_table($table_name, $new_table_name) + { + // I think this syntax will work, but can find little documentation on renaming tables in MSSQL + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); + return $sql; + } + +} + +/* End of file mssql_forge.php */ /* Location: ./system/database/drivers/mssql/mssql_forge.php */ \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index 33fdda9d4..e9679cb14 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -1,169 +1,169 @@ -result_id); - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - return @mssql_num_fields($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Fetch Field Names - * - * Generates an array of column names - * - * @access public - * @return array - */ - function list_fields() - { - $field_names = array(); - while ($field = mssql_fetch_field($this->result_id)) - { - $field_names[] = $field->name; - } - - return $field_names; - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - function field_data() - { - $retval = array(); - while ($field = mssql_fetch_field($this->result_id)) - { - $F = new stdClass(); - $F->name = $field->name; - $F->type = $field->type; - $F->max_length = $field->max_length; - $F->primary_key = 0; - $F->default = ''; - - $retval[] = $F; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Free the result - * - * @return null - */ - function free_result() - { - if (is_resource($this->result_id)) - { - mssql_free_result($this->result_id); - $this->result_id = FALSE; - } - } - - // -------------------------------------------------------------------- - - /** - * Data Seek - * - * Moves the internal pointer to the desired offset. We call - * this internally before fetching results to make sure the - * result set starts at zero - * - * @access private - * @return array - */ - function _data_seek($n = 0) - { - return mssql_data_seek($this->result_id, $n); - } - - // -------------------------------------------------------------------- - - /** - * Result - associative array - * - * Returns the result set as an array - * - * @access private - * @return array - */ - function _fetch_assoc() - { - return mssql_fetch_assoc($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Result - object - * - * Returns the result set as an object - * - * @access private - * @return object - */ - function _fetch_object() - { - return mssql_fetch_object($this->result_id); - } - -} - - -/* End of file mssql_result.php */ +result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @mssql_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function list_fields() + { + $field_names = array(); + while ($field = mssql_fetch_field($this->result_id)) + { + $field_names[] = $field->name; + } + + return $field_names; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + while ($field = mssql_fetch_field($this->result_id)) + { + $F = new stdClass(); + $F->name = $field->name; + $F->type = $field->type; + $F->max_length = $field->max_length; + $F->primary_key = 0; + $F->default = ''; + + $retval[] = $F; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return null + */ + function free_result() + { + if (is_resource($this->result_id)) + { + mssql_free_result($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero + * + * @access private + * @return array + */ + function _data_seek($n = 0) + { + return mssql_data_seek($this->result_id, $n); + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @access private + * @return array + */ + function _fetch_assoc() + { + return mssql_fetch_assoc($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + function _fetch_object() + { + return mssql_fetch_object($this->result_id); + } + +} + + +/* End of file mssql_result.php */ /* Location: ./system/database/drivers/mssql/mssql_result.php */ \ No newline at end of file diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index 1736fbafa..38118accc 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -1,123 +1,123 @@ -db->display_error('db_unsuported_feature'); - } - - /** - * - * The functions below have been deprecated as of 1.6, and are only here for backwards - * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation - * is STRONGLY discouraged in favour if using dbforge. - * - */ - - /** - * Create database - * - * @access private - * @param string the database name - * @return bool - */ - function _create_database($name) - { - return "CREATE DATABASE ".$name; - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access private - * @param string the database name - * @return bool - */ - function _drop_database($name) - { - return "DROP DATABASE ".$name; - } - -} - - -/* End of file mssql_utility.php */ +db->display_error('db_unsuported_feature'); + } + + /** + * + * The functions below have been deprecated as of 1.6, and are only here for backwards + * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation + * is STRONGLY discouraged in favour if using dbforge. + * + */ + + /** + * Create database + * + * @access private + * @param string the database name + * @return bool + */ + function _create_database($name) + { + return "CREATE DATABASE ".$name; + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access private + * @param string the database name + * @return bool + */ + function _drop_database($name) + { + return "DROP DATABASE ".$name; + } + +} + + +/* End of file mssql_utility.php */ /* Location: ./system/database/drivers/mssql/mssql_utility.php */ \ No newline at end of file diff --git a/system/database/drivers/mysql/index.html b/system/database/drivers/mysql/index.html index 065d2da5e..c942a79ce 100644 --- a/system/database/drivers/mysql/index.html +++ b/system/database/drivers/mysql/index.html @@ -1,10 +1,10 @@ - - - 403 Forbidden - - - -

Directory access is forbidden.

- - + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 45bf77149..943b3c037 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -1,634 +1,634 @@ -port != '') - { - $this->hostname .= ':'.$this->port; - } - - return @mysql_connect($this->hostname, $this->username, $this->password, TRUE); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - if ($this->port != '') - { - $this->hostname .= ':'.$this->port; - } - - return @mysql_pconnect($this->hostname, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - return @mysql_select_db($this->database, $this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Set client character set - * - * @access public - * @param string - * @param string - * @return resource - */ - function db_set_charset($charset, $collation) - { - return @mysql_query("SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'", $this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @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); - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @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 - // the query so that it returns the number of affected rows - if ($this->delete_hack === TRUE) - { - if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql)) - { - $sql = preg_replace("/^\s*DELETE\s+FROM\s+(\S+)\s*$/", "DELETE FROM \\1 WHERE 1=1", $sql); - } - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @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) - { - return TRUE; - } - - // Reset the transaction failure flag. - // 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; - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $this->simple_query('COMMIT'); - $this->simple_query('SET AUTOCOMMIT=1'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $this->simple_query('ROLLBACK'); - $this->simple_query('SET AUTOCOMMIT=1'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @return string - */ - function escape_str($str) - { - if (is_array($str)) - { - foreach($str as $key => $val) - { - $str[$key] = $this->escape_str($val); - } - - return $str; - } - - if (function_exists('mysql_real_escape_string') AND is_resource($this->conn_id)) - { - return mysql_real_escape_string($str, $this->conn_id); - } - elseif (function_exists('mysql_escape_string')) - { - return mysql_escape_string($str); - } - else - { - return addslashes($str); - } - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @mysql_affected_rows($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - return @mysql_insert_id($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - 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) - return '0'; - - $row = $query->row(); - return (int)$row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * List table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @param boolean - * @return string - */ - function _list_tables($prefix_limit = FALSE) - { - $sql = "SHOW TABLES FROM ".$this->_escape_char.$this->database.$this->_escape_char; - - if ($prefix_limit !== FALSE AND $this->dbprefix != '') - { - $sql .= " LIKE '".$this->dbprefix."%'"; - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Show column query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _list_columns($table = '') - { - return "SHOW COLUMNS FROM ".$table; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - return "SELECT * FROM ".$table." LIMIT 1"; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access private - * @return string - */ - function _error_message() - { - return mysql_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access private - * @return integer - */ - function _error_number() - { - return mysql_errno($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Escape the SQL Identifiers - * - * This function escapes column and table names - * - * @access private - * @param string - * @return string - */ - function _escape_identifiers($item) - { - if ($this->_escape_char == '') - { - return $item; - } - - foreach ($this->_reserved_identifiers as $id) - { - if (strpos($item, '.'.$id) !== FALSE) - { - $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; - } - 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); - } - - // -------------------------------------------------------------------- - - /** - * From Tables - * - * This function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @access public - * @param type - * @return type - */ - function _from_tables($tables) - { - if ( ! is_array($tables)) - { - $tables = array($tables); - } - - return '('.implode(', ', $tables).')'; - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @param array the orderby clause - * @param array the limit clause - * @return string - */ - function _update($table, $values, $where, $orderby = array(), $limit = FALSE) - { - foreach($values as $key => $val) - { - $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; - } - - // -------------------------------------------------------------------- - - /** - * Truncate statement - * - * Generates a platform-specific truncate string from the supplied data - * If the database does not support the truncate() command - * This function maps to "DELETE FROM table" - * - * @access public - * @param string the table name - * @return string - */ - function _truncate($table) - { - return "TRUNCATE ".$table; - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @param string the limit clause - * @return string - */ - function _delete($table, $where = array(), $like = array(), $limit = FALSE) - { - $conditions = ''; - - if (count($where) > 0 OR count($like) > 0) - { - $conditions = "\nWHERE "; - $conditions .= implode("\n", $this->ar_where); - - if (count($where) > 0 && count($like) > 0) - { - $conditions .= " AND "; - } - $conditions .= implode("\n", $like); - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - return "DELETE FROM ".$table.$conditions.$limit; - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - if ($offset == 0) - { - $offset = ''; - } - else - { - $offset .= ", "; - } - - return $sql."LIMIT ".$offset.$limit; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - @mysql_close($conn_id); - } - -} - - -/* End of file mysql_driver.php */ +port != '') + { + $this->hostname .= ':'.$this->port; + } + + return @mysql_connect($this->hostname, $this->username, $this->password, TRUE); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + if ($this->port != '') + { + $this->hostname .= ':'.$this->port; + } + + return @mysql_pconnect($this->hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return @mysql_select_db($this->database, $this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Set client character set + * + * @access public + * @param string + * @param string + * @return resource + */ + function db_set_charset($charset, $collation) + { + return @mysql_query("SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'", $this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @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); + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @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 + // the query so that it returns the number of affected rows + if ($this->delete_hack === TRUE) + { + if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql)) + { + $sql = preg_replace("/^\s*DELETE\s+FROM\s+(\S+)\s*$/", "DELETE FROM \\1 WHERE 1=1", $sql); + } + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @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) + { + return TRUE; + } + + // Reset the transaction failure flag. + // 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; + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @access public + * @return bool + */ + function trans_commit() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $this->simple_query('COMMIT'); + $this->simple_query('SET AUTOCOMMIT=1'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @access public + * @return bool + */ + function trans_rollback() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $this->simple_query('ROLLBACK'); + $this->simple_query('SET AUTOCOMMIT=1'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + if (is_array($str)) + { + foreach($str as $key => $val) + { + $str[$key] = $this->escape_str($val); + } + + return $str; + } + + if (function_exists('mysql_real_escape_string') AND is_resource($this->conn_id)) + { + return mysql_real_escape_string($str, $this->conn_id); + } + elseif (function_exists('mysql_escape_string')) + { + return mysql_escape_string($str); + } + else + { + return addslashes($str); + } + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @mysql_affected_rows($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + return @mysql_insert_id($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + 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) + return '0'; + + $row = $query->row(); + return (int)$row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @param boolean + * @return string + */ + function _list_tables($prefix_limit = FALSE) + { + $sql = "SHOW TABLES FROM ".$this->_escape_char.$this->database.$this->_escape_char; + + if ($prefix_limit !== FALSE AND $this->dbprefix != '') + { + $sql .= " LIKE '".$this->dbprefix."%'"; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _list_columns($table = '') + { + return "SHOW COLUMNS FROM ".$table; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + return "SELECT * FROM ".$table." LIMIT 1"; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access private + * @return string + */ + function _error_message() + { + return mysql_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access private + * @return integer + */ + function _error_number() + { + return mysql_errno($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Escape the SQL Identifiers + * + * This function escapes column and table names + * + * @access private + * @param string + * @return string + */ + function _escape_identifiers($item) + { + if ($this->_escape_char == '') + { + return $item; + } + + foreach ($this->_reserved_identifiers as $id) + { + if (strpos($item, '.'.$id) !== FALSE) + { + $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; + } + 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); + } + + // -------------------------------------------------------------------- + + /** + * From Tables + * + * This function implicitly groups FROM tables so there is no confusion + * about operator precedence in harmony with SQL standards + * + * @access public + * @param type + * @return type + */ + function _from_tables($tables) + { + if ( ! is_array($tables)) + { + $tables = array($tables); + } + + return '('.implode(', ', $tables).')'; + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @param array the orderby clause + * @param array the limit clause + * @return string + */ + function _update($table, $values, $where, $orderby = array(), $limit = FALSE) + { + foreach($values as $key => $val) + { + $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; + } + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * If the database does not support the truncate() command + * This function maps to "DELETE FROM table" + * + * @access public + * @param string the table name + * @return string + */ + function _truncate($table) + { + return "TRUNCATE ".$table; + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @param string the limit clause + * @return string + */ + function _delete($table, $where = array(), $like = array(), $limit = FALSE) + { + $conditions = ''; + + if (count($where) > 0 OR count($like) > 0) + { + $conditions = "\nWHERE "; + $conditions .= implode("\n", $this->ar_where); + + if (count($where) > 0 && count($like) > 0) + { + $conditions .= " AND "; + } + $conditions .= implode("\n", $like); + } + + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; + + return "DELETE FROM ".$table.$conditions.$limit; + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + if ($offset == 0) + { + $offset = ''; + } + else + { + $offset .= ", "; + } + + return $sql."LIMIT ".$offset.$limit; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + @mysql_close($conn_id); + } + +} + + +/* End of file mysql_driver.php */ /* Location: ./system/database/drivers/mysql/mysql_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index 28a77b3b3..d8cb77ea6 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -1,254 +1,254 @@ -$attributes) - { - // Numeric field names aren't allowed in databases, so if the key is - // numeric, we know it was assigned by PHP and the developer manually - // entered the field information, so we'll simply add it to the list - if (is_numeric($field)) - { - $sql .= "\n\t$attributes"; - } - 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; - } - - // -------------------------------------------------------------------- - - /** - * Create Table - * - * @access private - * @param string the table name - * @param mixed the fields - * @param mixed primary key(s) - * @param mixed key(s) - * @param boolean should 'IF NOT EXISTS' be added to the SQL - * @return bool - */ - 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); - - if (count($primary_keys) > 0) - { - $key_name = $this->db->_protect_identifiers(implode('_', $primary_keys)); - $primary_keys = $this->db->_protect_identifiers($primary_keys); - $sql .= ",\n\tPRIMARY KEY ".$key_name." (" . implode(', ', $primary_keys) . ")"; - } - - if (is_array($keys) && count($keys) > 0) - { - foreach ($keys as $key) - { - if (is_array($key)) - { - $key_name = $this->db->_protect_identifiers(implode('_', $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) . ")"; - } - } - - $sql .= "\n) DEFAULT CHARACTER SET {$this->db->char_set} COLLATE {$this->db->dbcollat};"; - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Drop Table - * - * @access private - * @return string - */ - function _drop_table($table) - { - return "DROP TABLE IF EXISTS ".$this->db->_escape_identifiers($table); - } - - // -------------------------------------------------------------------- - - /** - * Alter table query - * - * Generates a platform-specific query so that a table can be altered - * Called by add_column(), drop_column(), and column_alter(), - * - * @access private - * @param string the ALTER type (ADD, DROP, CHANGE) - * @param string the column name - * @param array fields - * @param string the field after which we should add the new field - * @return object - */ - function _alter_table($alter_type, $table, $fields, $after_field = '') - { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type "; - - // DROP has everything it needs now. - if ($alter_type == 'DROP') - { - return $sql.$this->db->_protect_identifiers($fields); - } - - $sql .= $this->_process_fields($fields); - - if ($after_field != '') - { - $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Rename a table - * - * Generates a platform-specific query so that a table can be renamed - * - * @access private - * @param string the old table name - * @param string the new table name - * @return string - */ - function _rename_table($table_name, $new_table_name) - { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); - return $sql; - } - -} - -/* End of file mysql_forge.php */ +$attributes) + { + // Numeric field names aren't allowed in databases, so if the key is + // numeric, we know it was assigned by PHP and the developer manually + // entered the field information, so we'll simply add it to the list + if (is_numeric($field)) + { + $sql .= "\n\t$attributes"; + } + 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; + } + + // -------------------------------------------------------------------- + + /** + * Create Table + * + * @access private + * @param string the table name + * @param mixed the fields + * @param mixed primary key(s) + * @param mixed key(s) + * @param boolean should 'IF NOT EXISTS' be added to the SQL + * @return bool + */ + 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); + + if (count($primary_keys) > 0) + { + $key_name = $this->db->_protect_identifiers(implode('_', $primary_keys)); + $primary_keys = $this->db->_protect_identifiers($primary_keys); + $sql .= ",\n\tPRIMARY KEY ".$key_name." (" . implode(', ', $primary_keys) . ")"; + } + + if (is_array($keys) && count($keys) > 0) + { + foreach ($keys as $key) + { + if (is_array($key)) + { + $key_name = $this->db->_protect_identifiers(implode('_', $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) . ")"; + } + } + + $sql .= "\n) DEFAULT CHARACTER SET {$this->db->char_set} COLLATE {$this->db->dbcollat};"; + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * @access private + * @return string + */ + function _drop_table($table) + { + return "DROP TABLE IF EXISTS ".$this->db->_escape_identifiers($table); + } + + // -------------------------------------------------------------------- + + /** + * Alter table query + * + * Generates a platform-specific query so that a table can be altered + * Called by add_column(), drop_column(), and column_alter(), + * + * @access private + * @param string the ALTER type (ADD, DROP, CHANGE) + * @param string the column name + * @param array fields + * @param string the field after which we should add the new field + * @return object + */ + function _alter_table($alter_type, $table, $fields, $after_field = '') + { + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type "; + + // DROP has everything it needs now. + if ($alter_type == 'DROP') + { + return $sql.$this->db->_protect_identifiers($fields); + } + + $sql .= $this->_process_fields($fields); + + if ($after_field != '') + { + $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Rename a table + * + * Generates a platform-specific query so that a table can be renamed + * + * @access private + * @param string the old table name + * @param string the new table name + * @return string + */ + function _rename_table($table_name, $new_table_name) + { + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); + return $sql; + } + +} + +/* End of file mysql_forge.php */ /* Location: ./system/database/drivers/mysql/mysql_forge.php */ \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index a28a19855..673aeac87 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -1,169 +1,169 @@ -result_id); - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - return @mysql_num_fields($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Fetch Field Names - * - * Generates an array of column names - * - * @access public - * @return array - */ - function list_fields() - { - $field_names = array(); - while ($field = mysql_fetch_field($this->result_id)) - { - $field_names[] = $field->name; - } - - return $field_names; - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - function field_data() - { - $retval = array(); - while ($field = mysql_fetch_field($this->result_id)) - { - $F = new stdClass(); - $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)) - { - mysql_free_result($this->result_id); - $this->result_id = FALSE; - } - } - - // -------------------------------------------------------------------- - - /** - * Data Seek - * - * Moves the internal pointer to the desired offset. We call - * this internally before fetching results to make sure the - * result set starts at zero - * - * @access private - * @return array - */ - function _data_seek($n = 0) - { - return mysql_data_seek($this->result_id, $n); - } - - // -------------------------------------------------------------------- - - /** - * Result - associative array - * - * Returns the result set as an array - * - * @access private - * @return array - */ - function _fetch_assoc() - { - return mysql_fetch_assoc($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Result - object - * - * Returns the result set as an object - * - * @access private - * @return object - */ - function _fetch_object() - { - return mysql_fetch_object($this->result_id); - } - -} - - -/* End of file mysql_result.php */ +result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @mysql_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function list_fields() + { + $field_names = array(); + while ($field = mysql_fetch_field($this->result_id)) + { + $field_names[] = $field->name; + } + + return $field_names; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + while ($field = mysql_fetch_field($this->result_id)) + { + $F = new stdClass(); + $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)) + { + mysql_free_result($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero + * + * @access private + * @return array + */ + function _data_seek($n = 0) + { + return mysql_data_seek($this->result_id, $n); + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @access private + * @return array + */ + function _fetch_assoc() + { + return mysql_fetch_assoc($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + function _fetch_object() + { + return mysql_fetch_object($this->result_id); + } + +} + + +/* End of file mysql_result.php */ /* Location: ./system/database/drivers/mysql/mysql_result.php */ \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index d2c10dbb2..003b1dd66 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -1,245 +1,245 @@ -db->_escape_identifiers($table); - } - - // -------------------------------------------------------------------- - - /** - * Repair table query - * - * Generates a platform-specific query so that a table can be repaired - * - * @access private - * @param string the table name - * @return object - */ - function _repair_table($table) - { - return "REPAIR TABLE ".$this->db->_escape_identifiers($table); - } - - // -------------------------------------------------------------------- - /** - * MySQL 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 = mysql_fetch_field($query->result_id)) - { - // 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'), - 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) - { - // Is the value NULL? - if ($v === NULL) - { - $val_str .= 'NULL'; - } - else - { - // Escape the data if it's not an integer - if ($is_int[$i] == FALSE) - { - $val_str .= $this->db->escape($v); - } - 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; - } - - return $output; - } - - /** - * - * The functions below have been deprecated as of 1.6, and are only here for backwards - * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation - * is STRONGLY discouraged in favour if using dbforge. - * - */ - - /** - * Create database - * - * @access private - * @param string the database name - * @return bool - */ - function _create_database($name) - { - return "CREATE DATABASE ".$name; - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access private - * @param string the database name - * @return bool - */ - function _drop_database($name) - { - return "DROP DATABASE ".$name; - } - -} - -/* End of file mysql_utility.php */ +db->_escape_identifiers($table); + } + + // -------------------------------------------------------------------- + + /** + * Repair table query + * + * Generates a platform-specific query so that a table can be repaired + * + * @access private + * @param string the table name + * @return object + */ + function _repair_table($table) + { + return "REPAIR TABLE ".$this->db->_escape_identifiers($table); + } + + // -------------------------------------------------------------------- + /** + * MySQL 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 = mysql_fetch_field($query->result_id)) + { + // 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'), + 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) + { + // Is the value NULL? + if ($v === NULL) + { + $val_str .= 'NULL'; + } + else + { + // Escape the data if it's not an integer + if ($is_int[$i] == FALSE) + { + $val_str .= $this->db->escape($v); + } + 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; + } + + return $output; + } + + /** + * + * The functions below have been deprecated as of 1.6, and are only here for backwards + * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation + * is STRONGLY discouraged in favour if using dbforge. + * + */ + + /** + * Create database + * + * @access private + * @param string the database name + * @return bool + */ + function _create_database($name) + { + return "CREATE DATABASE ".$name; + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access private + * @param string the database name + * @return bool + */ + function _drop_database($name) + { + return "DROP DATABASE ".$name; + } + +} + +/* End of file mysql_utility.php */ /* Location: ./system/database/drivers/mysql/mysql_utility.php */ \ No newline at end of file diff --git a/system/database/drivers/mysqli/index.html b/system/database/drivers/mysqli/index.html index 065d2da5e..c942a79ce 100644 --- a/system/database/drivers/mysqli/index.html +++ b/system/database/drivers/mysqli/index.html @@ -1,10 +1,10 @@ - - - 403 Forbidden - - - -

Directory access is forbidden.

- - + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 1b3da7a6b..ce458f292 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -1,625 +1,625 @@ -port != '') - { - return @mysqli_connect($this->hostname, $this->username, $this->password, $this->database, $this->port); - } - else - { - return @mysqli_connect($this->hostname, $this->username, $this->password, $this->database); - } - - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return $this->db_connect(); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - return @mysqli_select_db($this->conn_id, $this->database); - } - - // -------------------------------------------------------------------- - - /** - * Set client character set - * - * @access private - * @param string - * @param string - * @return resource - */ - function _db_set_charset($charset, $collation) - { - return @mysqli_query($this->conn_id, "SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'"); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return resource - */ - function _execute($sql) - { - $sql = $this->_prep_query($sql); - $result = @mysqli_query($this->conn_id, $sql); - return $result; - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @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 - // the query so that it returns the number of affected rows - if ($this->delete_hack === TRUE) - { - if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql)) - { - $sql = preg_replace("/^\s*DELETE\s+FROM\s+(\S+)\s*$/", "DELETE FROM \\1 WHERE 1=1", $sql); - } - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @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) - { - return TRUE; - } - - // Reset the transaction failure flag. - // 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; - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $this->simple_query('COMMIT'); - $this->simple_query('SET AUTOCOMMIT=1'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $this->simple_query('ROLLBACK'); - $this->simple_query('SET AUTOCOMMIT=1'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @return string - */ - function escape_str($str) - { - if (function_exists('mysqli_real_escape_string') AND is_object($this->conn_id)) - { - return mysqli_real_escape_string($this->conn_id, $str); - } - elseif (function_exists('mysql_escape_string')) - { - return mysql_escape_string($str); - } - else - { - return addslashes($str); - } - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @mysqli_affected_rows($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - return @mysqli_insert_id($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - 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) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * List table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @param boolean - * @return string - */ - function _list_tables($prefix_limit = FALSE) - { - $sql = "SHOW TABLES FROM ".$this->_escape_char.$this->database.$this->_escape_char; - - if ($prefix_limit !== FALSE AND $this->dbprefix != '') - { - $sql .= " LIKE '".$this->dbprefix."%'"; - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Show column query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _list_columns($table = '') - { - return "SHOW COLUMNS FROM ".$table; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - return "SELECT * FROM ".$table." LIMIT 1"; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access private - * @return string - */ - function _error_message() - { - return mysqli_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access private - * @return integer - */ - function _error_number() - { - return mysqli_errno($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Escape the SQL Identifiers - * - * This function escapes column and table names - * - * @access private - * @param string - * @return string - */ - function _escape_identifiers($item) - { - if ($this->_escape_char == '') - { - return $item; - } - - foreach ($this->_reserved_identifiers as $id) - { - if (strpos($item, '.'.$id) !== FALSE) - { - $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; - } - 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); - } - - // -------------------------------------------------------------------- - - /** - * From Tables - * - * This function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @access public - * @param type - * @return type - */ - function _from_tables($tables) - { - if ( ! is_array($tables)) - { - $tables = array($tables); - } - - return '('.implode(', ', $tables).')'; - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @param array the orderby clause - * @param array the limit clause - * @return string - */ - function _update($table, $values, $where, $orderby = array(), $limit = FALSE) - { - foreach($values as $key => $val) - { - $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; - } - - - // -------------------------------------------------------------------- - - /** - * Truncate statement - * - * Generates a platform-specific truncate string from the supplied data - * If the database does not support the truncate() command - * This function maps to "DELETE FROM table" - * - * @access public - * @param string the table name - * @return string - */ - function _truncate($table) - { - return "TRUNCATE ".$table; - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @param string the limit clause - * @return string - */ - function _delete($table, $where = array(), $like = array(), $limit = FALSE) - { - $conditions = ''; - - if (count($where) > 0 OR count($like) > 0) - { - $conditions = "\nWHERE "; - $conditions .= implode("\n", $this->ar_where); - - if (count($where) > 0 && count($like) > 0) - { - $conditions .= " AND "; - } - $conditions .= implode("\n", $like); - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - return "DELETE FROM ".$table.$conditions.$limit; - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - $sql .= "LIMIT ".$limit; - - if ($offset > 0) - { - $sql .= " OFFSET ".$offset; - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - @mysqli_close($conn_id); - } - - -} - - -/* End of file mysqli_driver.php */ +port != '') + { + return @mysqli_connect($this->hostname, $this->username, $this->password, $this->database, $this->port); + } + else + { + return @mysqli_connect($this->hostname, $this->username, $this->password, $this->database); + } + + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return $this->db_connect(); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return @mysqli_select_db($this->conn_id, $this->database); + } + + // -------------------------------------------------------------------- + + /** + * Set client character set + * + * @access private + * @param string + * @param string + * @return resource + */ + function _db_set_charset($charset, $collation) + { + return @mysqli_query($this->conn_id, "SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'"); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + function _execute($sql) + { + $sql = $this->_prep_query($sql); + $result = @mysqli_query($this->conn_id, $sql); + return $result; + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @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 + // the query so that it returns the number of affected rows + if ($this->delete_hack === TRUE) + { + if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql)) + { + $sql = preg_replace("/^\s*DELETE\s+FROM\s+(\S+)\s*$/", "DELETE FROM \\1 WHERE 1=1", $sql); + } + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @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) + { + return TRUE; + } + + // Reset the transaction failure flag. + // 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; + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @access public + * @return bool + */ + function trans_commit() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $this->simple_query('COMMIT'); + $this->simple_query('SET AUTOCOMMIT=1'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @access public + * @return bool + */ + function trans_rollback() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $this->simple_query('ROLLBACK'); + $this->simple_query('SET AUTOCOMMIT=1'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + if (function_exists('mysqli_real_escape_string') AND is_object($this->conn_id)) + { + return mysqli_real_escape_string($this->conn_id, $str); + } + elseif (function_exists('mysql_escape_string')) + { + return mysql_escape_string($str); + } + else + { + return addslashes($str); + } + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @mysqli_affected_rows($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + return @mysqli_insert_id($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + 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) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @param boolean + * @return string + */ + function _list_tables($prefix_limit = FALSE) + { + $sql = "SHOW TABLES FROM ".$this->_escape_char.$this->database.$this->_escape_char; + + if ($prefix_limit !== FALSE AND $this->dbprefix != '') + { + $sql .= " LIKE '".$this->dbprefix."%'"; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _list_columns($table = '') + { + return "SHOW COLUMNS FROM ".$table; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + return "SELECT * FROM ".$table." LIMIT 1"; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access private + * @return string + */ + function _error_message() + { + return mysqli_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access private + * @return integer + */ + function _error_number() + { + return mysqli_errno($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Escape the SQL Identifiers + * + * This function escapes column and table names + * + * @access private + * @param string + * @return string + */ + function _escape_identifiers($item) + { + if ($this->_escape_char == '') + { + return $item; + } + + foreach ($this->_reserved_identifiers as $id) + { + if (strpos($item, '.'.$id) !== FALSE) + { + $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; + } + 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); + } + + // -------------------------------------------------------------------- + + /** + * From Tables + * + * This function implicitly groups FROM tables so there is no confusion + * about operator precedence in harmony with SQL standards + * + * @access public + * @param type + * @return type + */ + function _from_tables($tables) + { + if ( ! is_array($tables)) + { + $tables = array($tables); + } + + return '('.implode(', ', $tables).')'; + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @param array the orderby clause + * @param array the limit clause + * @return string + */ + function _update($table, $values, $where, $orderby = array(), $limit = FALSE) + { + foreach($values as $key => $val) + { + $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; + } + + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * If the database does not support the truncate() command + * This function maps to "DELETE FROM table" + * + * @access public + * @param string the table name + * @return string + */ + function _truncate($table) + { + return "TRUNCATE ".$table; + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @param string the limit clause + * @return string + */ + function _delete($table, $where = array(), $like = array(), $limit = FALSE) + { + $conditions = ''; + + if (count($where) > 0 OR count($like) > 0) + { + $conditions = "\nWHERE "; + $conditions .= implode("\n", $this->ar_where); + + if (count($where) > 0 && count($like) > 0) + { + $conditions .= " AND "; + } + $conditions .= implode("\n", $like); + } + + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; + + return "DELETE FROM ".$table.$conditions.$limit; + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + $sql .= "LIMIT ".$limit; + + if ($offset > 0) + { + $sql .= " OFFSET ".$offset; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + @mysqli_close($conn_id); + } + + +} + + +/* End of file mysqli_driver.php */ /* Location: ./system/database/drivers/mysqli/mysqli_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index c7889bf48..99c2ebc3f 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -1,254 +1,254 @@ -$attributes) - { - // Numeric field names aren't allowed in databases, so if the key is - // numeric, we know it was assigned by PHP and the developer manually - // entered the field information, so we'll simply add it to the list - if (is_numeric($field)) - { - $sql .= "\n\t$attributes"; - } - 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; - } - - // -------------------------------------------------------------------- - - /** - * Create Table - * - * @access private - * @param string the table name - * @param mixed the fields - * @param mixed primary key(s) - * @param mixed key(s) - * @param boolean should 'IF NOT EXISTS' be added to the SQL - * @return bool - */ - 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); - - if (count($primary_keys) > 0) - { - $key_name = $this->db->_protect_identifiers(implode('_', $primary_keys)); - $primary_keys = $this->db->_protect_identifiers($primary_keys); - $sql .= ",\n\tPRIMARY KEY ".$key_name." (" . implode(', ', $primary_keys) . ")"; - } - - if (is_array($keys) && count($keys) > 0) - { - foreach ($keys as $key) - { - if (is_array($key)) - { - $key_name = $this->db->_protect_identifiers(implode('_', $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) . ")"; - } - } - - $sql .= "\n) DEFAULT CHARACTER SET {$this->db->char_set} COLLATE {$this->db->dbcollat};"; - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Drop Table - * - * @access private - * @return string - */ - function _drop_table($table) - { - return "DROP TABLE IF EXISTS ".$this->db->_escape_identifiers($table); - } - - // -------------------------------------------------------------------- - - /** - * Alter table query - * - * Generates a platform-specific query so that a table can be altered - * Called by add_column(), drop_column(), and column_alter(), - * - * @access private - * @param string the ALTER type (ADD, DROP, CHANGE) - * @param string the column name - * @param array fields - * @param string the field after which we should add the new field - * @return object - */ - function _alter_table($alter_type, $table, $fields, $after_field = '') - { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type "; - - // DROP has everything it needs now. - if ($alter_type == 'DROP') - { - return $sql.$this->db->_protect_identifiers($fields); - } - - $sql .= $this->_process_fields($fields); - - if ($after_field != '') - { - $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Rename a table - * - * Generates a platform-specific query so that a table can be renamed - * - * @access private - * @param string the old table name - * @param string the new table name - * @return string - */ - function _rename_table($table_name, $new_table_name) - { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); - return $sql; - } - -} - -/* End of file mysqli_forge.php */ +$attributes) + { + // Numeric field names aren't allowed in databases, so if the key is + // numeric, we know it was assigned by PHP and the developer manually + // entered the field information, so we'll simply add it to the list + if (is_numeric($field)) + { + $sql .= "\n\t$attributes"; + } + 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; + } + + // -------------------------------------------------------------------- + + /** + * Create Table + * + * @access private + * @param string the table name + * @param mixed the fields + * @param mixed primary key(s) + * @param mixed key(s) + * @param boolean should 'IF NOT EXISTS' be added to the SQL + * @return bool + */ + 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); + + if (count($primary_keys) > 0) + { + $key_name = $this->db->_protect_identifiers(implode('_', $primary_keys)); + $primary_keys = $this->db->_protect_identifiers($primary_keys); + $sql .= ",\n\tPRIMARY KEY ".$key_name." (" . implode(', ', $primary_keys) . ")"; + } + + if (is_array($keys) && count($keys) > 0) + { + foreach ($keys as $key) + { + if (is_array($key)) + { + $key_name = $this->db->_protect_identifiers(implode('_', $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) . ")"; + } + } + + $sql .= "\n) DEFAULT CHARACTER SET {$this->db->char_set} COLLATE {$this->db->dbcollat};"; + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * @access private + * @return string + */ + function _drop_table($table) + { + return "DROP TABLE IF EXISTS ".$this->db->_escape_identifiers($table); + } + + // -------------------------------------------------------------------- + + /** + * Alter table query + * + * Generates a platform-specific query so that a table can be altered + * Called by add_column(), drop_column(), and column_alter(), + * + * @access private + * @param string the ALTER type (ADD, DROP, CHANGE) + * @param string the column name + * @param array fields + * @param string the field after which we should add the new field + * @return object + */ + function _alter_table($alter_type, $table, $fields, $after_field = '') + { + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type "; + + // DROP has everything it needs now. + if ($alter_type == 'DROP') + { + return $sql.$this->db->_protect_identifiers($fields); + } + + $sql .= $this->_process_fields($fields); + + if ($after_field != '') + { + $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Rename a table + * + * Generates a platform-specific query so that a table can be renamed + * + * @access private + * @param string the old table name + * @param string the new table name + * @return string + */ + function _rename_table($table_name, $new_table_name) + { + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); + return $sql; + } + +} + +/* End of file mysqli_forge.php */ /* Location: ./system/database/drivers/mysqli/mysqli_forge.php */ \ No newline at end of file diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index b690914b7..5b1f79361 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -1,169 +1,169 @@ -result_id); - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - return @mysqli_num_fields($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Fetch Field Names - * - * Generates an array of column names - * - * @access public - * @return array - */ - function list_fields() - { - $field_names = array(); - while ($field = mysqli_fetch_field($this->result_id)) - { - $field_names[] = $field->name; - } - - return $field_names; - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - function field_data() - { - $retval = array(); - while ($field = mysqli_fetch_field($this->result_id)) - { - $F = new stdClass(); - $F->name = $field->name; - $F->type = $field->type; - $F->default = $field->def; - $F->max_length = $field->max_length; - $F->primary_key = ($field->flags & MYSQLI_PRI_KEY_FLAG) ? 1 : 0; - - $retval[] = $F; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Free the result - * - * @return null - */ - function free_result() - { - if (is_object($this->result_id)) - { - mysqli_free_result($this->result_id); - $this->result_id = FALSE; - } - } - - // -------------------------------------------------------------------- - - /** - * Data Seek - * - * Moves the internal pointer to the desired offset. We call - * this internally before fetching results to make sure the - * result set starts at zero - * - * @access private - * @return array - */ - function _data_seek($n = 0) - { - return mysqli_data_seek($this->result_id, $n); - } - - // -------------------------------------------------------------------- - - /** - * Result - associative array - * - * Returns the result set as an array - * - * @access private - * @return array - */ - function _fetch_assoc() - { - return mysqli_fetch_assoc($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Result - object - * - * Returns the result set as an object - * - * @access private - * @return object - */ - function _fetch_object() - { - return mysqli_fetch_object($this->result_id); - } - -} - - -/* End of file mysqli_result.php */ +result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @mysqli_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function list_fields() + { + $field_names = array(); + while ($field = mysqli_fetch_field($this->result_id)) + { + $field_names[] = $field->name; + } + + return $field_names; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + while ($field = mysqli_fetch_field($this->result_id)) + { + $F = new stdClass(); + $F->name = $field->name; + $F->type = $field->type; + $F->default = $field->def; + $F->max_length = $field->max_length; + $F->primary_key = ($field->flags & MYSQLI_PRI_KEY_FLAG) ? 1 : 0; + + $retval[] = $F; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return null + */ + function free_result() + { + if (is_object($this->result_id)) + { + mysqli_free_result($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero + * + * @access private + * @return array + */ + function _data_seek($n = 0) + { + return mysqli_data_seek($this->result_id, $n); + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @access private + * @return array + */ + function _fetch_assoc() + { + return mysqli_fetch_assoc($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + function _fetch_object() + { + return mysqli_fetch_object($this->result_id); + } + +} + + +/* End of file mysqli_result.php */ /* Location: ./system/database/drivers/mysqli/mysqli_result.php */ \ 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 d19b64374..c1d191d14 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -1,123 +1,123 @@ -db->_escape_identifiers($table); - } - - // -------------------------------------------------------------------- - - /** - * Repair table query - * - * Generates a platform-specific query so that a table can be repaired - * - * @access private - * @param string the table name - * @return object - */ - function _repair_table($table) - { - return "REPAIR TABLE ".$this->db->_escape_identifiers($table); - } - - // -------------------------------------------------------------------- - - /** - * MySQLi Export - * - * @access private - * @param array Preferences - * @return mixed - */ - function _backup($params = array()) - { - // Currently unsupported - return $this->db->display_error('db_unsuported_feature'); - } - - - /** - * - * The functions below have been deprecated as of 1.6, and are only here for backwards - * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation - * is STRONGLY discouraged in favour if using dbforge. - * - */ - - /** - * Create database - * - * @access private - * @param string the database name - * @return bool - */ - function _create_database($name) - { - return "CREATE DATABASE ".$name; - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access private - * @param string the database name - * @return bool - */ - function _drop_database($name) - { - return "DROP DATABASE ".$name; - } - -} - -/* End of file mysqli_utility.php */ +db->_escape_identifiers($table); + } + + // -------------------------------------------------------------------- + + /** + * Repair table query + * + * Generates a platform-specific query so that a table can be repaired + * + * @access private + * @param string the table name + * @return object + */ + function _repair_table($table) + { + return "REPAIR TABLE ".$this->db->_escape_identifiers($table); + } + + // -------------------------------------------------------------------- + + /** + * MySQLi Export + * + * @access private + * @param array Preferences + * @return mixed + */ + function _backup($params = array()) + { + // Currently unsupported + return $this->db->display_error('db_unsuported_feature'); + } + + + /** + * + * The functions below have been deprecated as of 1.6, and are only here for backwards + * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation + * is STRONGLY discouraged in favour if using dbforge. + * + */ + + /** + * Create database + * + * @access private + * @param string the database name + * @return bool + */ + function _create_database($name) + { + return "CREATE DATABASE ".$name; + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access private + * @param string the database name + * @return bool + */ + function _drop_database($name) + { + return "DROP DATABASE ".$name; + } + +} + +/* End of file mysqli_utility.php */ /* Location: ./system/database/drivers/mysqli/mysqli_utility.php */ \ No newline at end of file diff --git a/system/database/drivers/oci8/index.html b/system/database/drivers/oci8/index.html index 065d2da5e..c942a79ce 100644 --- a/system/database/drivers/oci8/index.html +++ b/system/database/drivers/oci8/index.html @@ -1,10 +1,10 @@ - - - 403 Forbidden - - - -

Directory access is forbidden.

- - + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 0c1467783..0629a5940 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -1,737 +1,737 @@ -username, $this->password, $this->hostname); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return @ociplogon($this->username, $this->password, $this->hostname); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Set client character set - * - * @access public - * @param string - * @param string - * @return resource - */ - function db_set_charset($charset, $collation) - { - // @todo - add support if needed - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return ociserverversion($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return resource - */ - function _execute($sql) - { - // oracle must parse the query before it is run. All of the actions with - // the query are based on the statement id returned by ociparse - $this->stmt_id = FALSE; - $this->_set_stmt_id($sql); - ocisetprefetch($this->stmt_id, 1000); - return @ociexecute($this->stmt_id, $this->_commit); - } - - /** - * Generate a statement ID - * - * @access private - * @param string an SQL query - * @return none - */ - function _set_stmt_id($sql) - { - if ( ! is_resource($this->stmt_id)) - { - $this->stmt_id = ociparse($this->conn_id, $this->_prep_query($sql)); - } - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @access private called by execute() - * @param string an SQL query - * @return string - */ - function _prep_query($sql) - { - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * getCursor. Returns a cursor from the datbase - * - * @access public - * @return cursor id - */ - function get_cursor() - { - $this->curs_id = ocinewcursor($this->conn_id); - return $this->curs_id; - } - - // -------------------------------------------------------------------- - - /** - * Stored Procedure. Executes a stored procedure - * - * @access public - * @param package package stored procedure is in - * @param procedure stored procedure to execute - * @param params array of parameters - * @return array - * - * params array keys - * - * KEY OPTIONAL NOTES - * name no the name of the parameter should be in : format - * value no the value of the parameter. If this is an OUT or IN OUT parameter, - * this should be a reference to a variable - * type yes the type of the parameter - * length yes the max size of the parameter - */ - function stored_procedure($package, $procedure, $params) - { - if ($package == '' OR $procedure == '' OR ! is_array($params)) - { - if ($this->db_debug) - { - log_message('error', 'Invalid query: '.$package.'.'.$procedure); - return $this->display_error('db_invalid_query'); - } - return FALSE; - } - - // build the query string - $sql = "begin $package.$procedure("; - - $have_cursor = FALSE; - foreach($params as $param) - { - $sql .= $param['name'] . ","; - - if (array_key_exists('type', $param) && ($param['type'] == OCI_B_CURSOR)) - { - $have_cursor = TRUE; - } - } - $sql = trim($sql, ",") . "); end;"; - - $this->stmt_id = FALSE; - $this->_set_stmt_id($sql); - $this->_bind_params($params); - $this->query($sql, FALSE, $have_cursor); - } - - // -------------------------------------------------------------------- - - /** - * Bind parameters - * - * @access private - * @return none - */ - function _bind_params($params) - { - if ( ! is_array($params) OR ! is_resource($this->stmt_id)) - { - return; - } - - foreach ($params as $param) - { - foreach (array('name', 'value', 'type', 'length') as $val) - { - if ( ! isset($param[$val])) - { - $param[$val] = ''; - } - } - - ocibindbyname($this->stmt_id, $param['name'], $param['value'], $param['length'], $param['type']); - } - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @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) - { - return TRUE; - } - - // Reset the transaction failure flag. - // 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->_commit = OCI_DEFAULT; - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $ret = OCIcommit($this->conn_id); - $this->_commit = OCI_COMMIT_ON_SUCCESS; - return $ret; - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $ret = OCIrollback($this->conn_id); - $this->_commit = OCI_COMMIT_ON_SUCCESS; - return $ret; - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @return string - */ - function escape_str($str) - { - // Access the CI object - $CI =& get_instance(); - - return $CI->_remove_invisible_characters($str); - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @ocirowcount($this->stmt_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - // not supported in oracle - return $this->display_error('db_unsupported_function'); - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - return '0'; - - $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); - - if ($query == FALSE) - { - return 0; - } - - $row = $query->row(); - return $row->NUMROWS; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @param boolean - * @return string - */ - function _list_tables($prefix_limit = FALSE) - { - $sql = "SELECT TABLE_NAME FROM ALL_TABLES"; - - if ($prefix_limit !== FALSE AND $this->dbprefix != '') - { - $sql .= " WHERE TABLE_NAME LIKE '".$this->dbprefix."%'"; - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Show column query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _list_columns($table = '') - { - return "SELECT COLUMN_NAME FROM all_tab_columns WHERE table_name = '$table'"; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - return "SELECT * FROM ".$table." where rownum = 1"; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access private - * @return string - */ - function _error_message() - { - $error = ocierror($this->conn_id); - return $error['message']; - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access private - * @return integer - */ - function _error_number() - { - $error = ocierror($this->conn_id); - return $error['code']; - } - - // -------------------------------------------------------------------- - - /** - * Escape the SQL Identifiers - * - * This function escapes column and table names - * - * @access private - * @param string - * @return string - */ - function _escape_identifiers($item) - { - if ($this->_escape_char == '') - { - return $item; - } - - foreach ($this->_reserved_identifiers as $id) - { - if (strpos($item, '.'.$id) !== FALSE) - { - $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; - } - 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); - } - - // -------------------------------------------------------------------- - - /** - * From Tables - * - * This function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @access public - * @param type - * @return type - */ - function _from_tables($tables) - { - if ( ! is_array($tables)) - { - $tables = array($tables); - } - - return implode(', ', $tables); - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @param array the orderby clause - * @param array the limit clause - * @return string - */ - function _update($table, $values, $where, $orderby = array(), $limit = FALSE) - { - foreach($values as $key => $val) - { - $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; - } - - // -------------------------------------------------------------------- - - /** - * Truncate statement - * - * Generates a platform-specific truncate string from the supplied data - * If the database does not support the truncate() command - * This function maps to "DELETE FROM table" - * - * @access public - * @param string the table name - * @return string - */ - function _truncate($table) - { - return "TRUNCATE TABLE ".$table; - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @param string the limit clause - * @return string - */ - function _delete($table, $where = array(), $like = array(), $limit = FALSE) - { - $conditions = ''; - - if (count($where) > 0 OR count($like) > 0) - { - $conditions = "\nWHERE "; - $conditions .= implode("\n", $this->ar_where); - - if (count($where) > 0 && count($like) > 0) - { - $conditions .= " AND "; - } - $conditions .= implode("\n", $like); - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - return "DELETE FROM ".$table.$conditions.$limit; - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - $limit = $offset + $limit; - $newsql = "SELECT * FROM (select inner_query.*, rownum rnum FROM ($sql) inner_query WHERE rownum < $limit)"; - - if ($offset != 0) - { - $newsql .= " WHERE rnum >= $offset"; - } - - // remember that we used limits - $this->limit_used = TRUE; - - return $newsql; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - @ocilogoff($conn_id); - } - - -} - - - -/* End of file oci8_driver.php */ +username, $this->password, $this->hostname); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return @ociplogon($this->username, $this->password, $this->hostname); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Set client character set + * + * @access public + * @param string + * @param string + * @return resource + */ + function db_set_charset($charset, $collation) + { + // @todo - add support if needed + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return ociserverversion($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + function _execute($sql) + { + // oracle must parse the query before it is run. All of the actions with + // the query are based on the statement id returned by ociparse + $this->stmt_id = FALSE; + $this->_set_stmt_id($sql); + ocisetprefetch($this->stmt_id, 1000); + return @ociexecute($this->stmt_id, $this->_commit); + } + + /** + * Generate a statement ID + * + * @access private + * @param string an SQL query + * @return none + */ + function _set_stmt_id($sql) + { + if ( ! is_resource($this->stmt_id)) + { + $this->stmt_id = ociparse($this->conn_id, $this->_prep_query($sql)); + } + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @access private called by execute() + * @param string an SQL query + * @return string + */ + function _prep_query($sql) + { + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * getCursor. Returns a cursor from the datbase + * + * @access public + * @return cursor id + */ + function get_cursor() + { + $this->curs_id = ocinewcursor($this->conn_id); + return $this->curs_id; + } + + // -------------------------------------------------------------------- + + /** + * Stored Procedure. Executes a stored procedure + * + * @access public + * @param package package stored procedure is in + * @param procedure stored procedure to execute + * @param params array of parameters + * @return array + * + * params array keys + * + * KEY OPTIONAL NOTES + * name no the name of the parameter should be in : format + * value no the value of the parameter. If this is an OUT or IN OUT parameter, + * this should be a reference to a variable + * type yes the type of the parameter + * length yes the max size of the parameter + */ + function stored_procedure($package, $procedure, $params) + { + if ($package == '' OR $procedure == '' OR ! is_array($params)) + { + if ($this->db_debug) + { + log_message('error', 'Invalid query: '.$package.'.'.$procedure); + return $this->display_error('db_invalid_query'); + } + return FALSE; + } + + // build the query string + $sql = "begin $package.$procedure("; + + $have_cursor = FALSE; + foreach($params as $param) + { + $sql .= $param['name'] . ","; + + if (array_key_exists('type', $param) && ($param['type'] == OCI_B_CURSOR)) + { + $have_cursor = TRUE; + } + } + $sql = trim($sql, ",") . "); end;"; + + $this->stmt_id = FALSE; + $this->_set_stmt_id($sql); + $this->_bind_params($params); + $this->query($sql, FALSE, $have_cursor); + } + + // -------------------------------------------------------------------- + + /** + * Bind parameters + * + * @access private + * @return none + */ + function _bind_params($params) + { + if ( ! is_array($params) OR ! is_resource($this->stmt_id)) + { + return; + } + + foreach ($params as $param) + { + foreach (array('name', 'value', 'type', 'length') as $val) + { + if ( ! isset($param[$val])) + { + $param[$val] = ''; + } + } + + ocibindbyname($this->stmt_id, $param['name'], $param['value'], $param['length'], $param['type']); + } + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @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) + { + return TRUE; + } + + // Reset the transaction failure flag. + // 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->_commit = OCI_DEFAULT; + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @access public + * @return bool + */ + function trans_commit() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $ret = OCIcommit($this->conn_id); + $this->_commit = OCI_COMMIT_ON_SUCCESS; + return $ret; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @access public + * @return bool + */ + function trans_rollback() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $ret = OCIrollback($this->conn_id); + $this->_commit = OCI_COMMIT_ON_SUCCESS; + return $ret; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + // Access the CI object + $CI =& get_instance(); + + return $CI->_remove_invisible_characters($str); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @ocirowcount($this->stmt_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + // not supported in oracle + return $this->display_error('db_unsupported_function'); + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + return '0'; + + $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); + + if ($query == FALSE) + { + return 0; + } + + $row = $query->row(); + return $row->NUMROWS; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @param boolean + * @return string + */ + function _list_tables($prefix_limit = FALSE) + { + $sql = "SELECT TABLE_NAME FROM ALL_TABLES"; + + if ($prefix_limit !== FALSE AND $this->dbprefix != '') + { + $sql .= " WHERE TABLE_NAME LIKE '".$this->dbprefix."%'"; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _list_columns($table = '') + { + return "SELECT COLUMN_NAME FROM all_tab_columns WHERE table_name = '$table'"; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + return "SELECT * FROM ".$table." where rownum = 1"; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access private + * @return string + */ + function _error_message() + { + $error = ocierror($this->conn_id); + return $error['message']; + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access private + * @return integer + */ + function _error_number() + { + $error = ocierror($this->conn_id); + return $error['code']; + } + + // -------------------------------------------------------------------- + + /** + * Escape the SQL Identifiers + * + * This function escapes column and table names + * + * @access private + * @param string + * @return string + */ + function _escape_identifiers($item) + { + if ($this->_escape_char == '') + { + return $item; + } + + foreach ($this->_reserved_identifiers as $id) + { + if (strpos($item, '.'.$id) !== FALSE) + { + $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; + } + 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); + } + + // -------------------------------------------------------------------- + + /** + * From Tables + * + * This function implicitly groups FROM tables so there is no confusion + * about operator precedence in harmony with SQL standards + * + * @access public + * @param type + * @return type + */ + function _from_tables($tables) + { + if ( ! is_array($tables)) + { + $tables = array($tables); + } + + return implode(', ', $tables); + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @param array the orderby clause + * @param array the limit clause + * @return string + */ + function _update($table, $values, $where, $orderby = array(), $limit = FALSE) + { + foreach($values as $key => $val) + { + $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; + } + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * If the database does not support the truncate() command + * This function maps to "DELETE FROM table" + * + * @access public + * @param string the table name + * @return string + */ + function _truncate($table) + { + return "TRUNCATE TABLE ".$table; + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @param string the limit clause + * @return string + */ + function _delete($table, $where = array(), $like = array(), $limit = FALSE) + { + $conditions = ''; + + if (count($where) > 0 OR count($like) > 0) + { + $conditions = "\nWHERE "; + $conditions .= implode("\n", $this->ar_where); + + if (count($where) > 0 && count($like) > 0) + { + $conditions .= " AND "; + } + $conditions .= implode("\n", $like); + } + + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; + + return "DELETE FROM ".$table.$conditions.$limit; + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + $limit = $offset + $limit; + $newsql = "SELECT * FROM (select inner_query.*, rownum rnum FROM ($sql) inner_query WHERE rownum < $limit)"; + + if ($offset != 0) + { + $newsql .= " WHERE rnum >= $offset"; + } + + // remember that we used limits + $this->limit_used = TRUE; + + return $newsql; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + @ocilogoff($conn_id); + } + + +} + + + +/* End of file oci8_driver.php */ /* Location: ./system/database/drivers/oci8/oci8_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index 4b073d07f..bbc11f332 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -1,248 +1,248 @@ -db->_escape_identifiers($table)." ("; - $current_field_count = 0; - - foreach ($fields as $field=>$attributes) - { - // Numeric field names aren't allowed in databases, so if the key is - // numeric, we know it was assigned by PHP and the developer manually - // entered the field information, so we'll simply add it to the list - if (is_numeric($field)) - { - $sql .= "\n\t$attributes"; - } - else - { - $attributes = array_change_key_case($attributes, CASE_UPPER); - - $sql .= "\n\t".$this->db->_protect_identifiers($field); - - $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) && $attributes['NULL'] === TRUE) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' 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 .= ','; - } - } - - if (count($primary_keys) > 0) - { - $primary_keys = $this->db->_protect_identifiers($primary_keys); - $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; - } - - if (is_array($keys) && count($keys) > 0) - { - foreach ($keys as $key) - { - if (is_array($key)) - { - $key = $this->db->_protect_identifiers($key); - } - else - { - $key = array($this->db->_protect_identifiers($key)); - } - - $sql .= ",\n\tUNIQUE COLUMNS (" . implode(', ', $key) . ")"; - } - } - - $sql .= "\n)"; - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Drop Table - * - * @access private - * @return bool - */ - function _drop_table($table) - { - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Alter table query - * - * Generates a platform-specific query so that a table can be altered - * Called by add_column(), drop_column(), and column_alter(), - * - * @access private - * @param string the ALTER type (ADD, DROP, CHANGE) - * @param string the column name - * @param string the table name - * @param string the column definition - * @param string the default value - * @param boolean should 'NOT NULL' be added - * @param string the field after which we should add the new field - * @return object - */ - function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') - { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name); - - // DROP has everything it needs now. - if ($alter_type == 'DROP') - { - return $sql; - } - - $sql .= " $column_definition"; - - if ($default_value != '') - { - $sql .= " DEFAULT \"$default_value\""; - } - - if ($null === NULL) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } - - if ($after_field != '') - { - $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); - } - - return $sql; - - } - - // -------------------------------------------------------------------- - - /** - * Rename a table - * - * Generates a platform-specific query so that a table can be renamed - * - * @access private - * @param string the old table name - * @param string the new table name - * @return string - */ - function _rename_table($table_name, $new_table_name) - { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); - return $sql; - } - - -} - -/* End of file oci8_forge.php */ +db->_escape_identifiers($table)." ("; + $current_field_count = 0; + + foreach ($fields as $field=>$attributes) + { + // Numeric field names aren't allowed in databases, so if the key is + // numeric, we know it was assigned by PHP and the developer manually + // entered the field information, so we'll simply add it to the list + if (is_numeric($field)) + { + $sql .= "\n\t$attributes"; + } + else + { + $attributes = array_change_key_case($attributes, CASE_UPPER); + + $sql .= "\n\t".$this->db->_protect_identifiers($field); + + $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) && $attributes['NULL'] === TRUE) + { + $sql .= ' NULL'; + } + else + { + $sql .= ' 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 .= ','; + } + } + + if (count($primary_keys) > 0) + { + $primary_keys = $this->db->_protect_identifiers($primary_keys); + $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; + } + + if (is_array($keys) && count($keys) > 0) + { + foreach ($keys as $key) + { + if (is_array($key)) + { + $key = $this->db->_protect_identifiers($key); + } + else + { + $key = array($this->db->_protect_identifiers($key)); + } + + $sql .= ",\n\tUNIQUE COLUMNS (" . implode(', ', $key) . ")"; + } + } + + $sql .= "\n)"; + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * @access private + * @return bool + */ + function _drop_table($table) + { + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Alter table query + * + * Generates a platform-specific query so that a table can be altered + * Called by add_column(), drop_column(), and column_alter(), + * + * @access private + * @param string the ALTER type (ADD, DROP, CHANGE) + * @param string the column name + * @param string the table name + * @param string the column definition + * @param string the default value + * @param boolean should 'NOT NULL' be added + * @param string the field after which we should add the new field + * @return object + */ + function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') + { + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name); + + // DROP has everything it needs now. + if ($alter_type == 'DROP') + { + return $sql; + } + + $sql .= " $column_definition"; + + if ($default_value != '') + { + $sql .= " DEFAULT \"$default_value\""; + } + + if ($null === NULL) + { + $sql .= ' NULL'; + } + else + { + $sql .= ' NOT NULL'; + } + + if ($after_field != '') + { + $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); + } + + return $sql; + + } + + // -------------------------------------------------------------------- + + /** + * Rename a table + * + * Generates a platform-specific query so that a table can be renamed + * + * @access private + * @param string the old table name + * @param string the new table name + * @return string + */ + function _rename_table($table_name, $new_table_name) + { + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); + return $sql; + } + + +} + +/* End of file oci8_forge.php */ /* Location: ./system/database/drivers/oci8/oci8_forge.php */ \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 4cfbfa4b4..7d7cd1c3a 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -1,249 +1,249 @@ -result_array()); - @ociexecute($this->stmt_id); - - if ($this->curs_id) - { - @ociexecute($this->curs_id); - } - - return $rowcount; - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - $count = @ocinumcols($this->stmt_id); - - // if we used a limit we subtract it - if ($this->limit_used) - { - $count = $count - 1; - } - - return $count; - } - - // -------------------------------------------------------------------- - - /** - * Fetch Field Names - * - * Generates an array of column names - * - * @access public - * @return array - */ - function list_fields() - { - $field_names = array(); - $fieldCount = $this->num_fields(); - for ($c = 1; $c <= $fieldCount; $c++) - { - $field_names[] = ocicolumnname($this->stmt_id, $c); - } - return $field_names; - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - function field_data() - { - $retval = array(); - $fieldCount = $this->num_fields(); - for ($c = 1; $c <= $fieldCount; $c++) - { - $F = new stdClass(); - $F->name = ocicolumnname($this->stmt_id, $c); - $F->type = ocicolumntype($this->stmt_id, $c); - $F->max_length = ocicolumnsize($this->stmt_id, $c); - - $retval[] = $F; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Free the result - * - * @return null - */ - function free_result() - { - if (is_resource($this->result_id)) - { - ocifreestatement($this->result_id); - $this->result_id = FALSE; - } - } - - // -------------------------------------------------------------------- - - /** - * Result - associative array - * - * Returns the result set as an array - * - * @access private - * @return array - */ - function _fetch_assoc(&$row) - { - $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; - - return ocifetchinto($id, $row, OCI_ASSOC + OCI_RETURN_NULLS); - } - - // -------------------------------------------------------------------- - - /** - * Result - object - * - * Returns the result set as an object - * - * @access private - * @return object - */ - function _fetch_object() - { - $result = array(); - - // If PHP 5 is being used we can fetch an result object - if (function_exists('oci_fetch_object')) - { - $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; - - return @oci_fetch_object($id); - } - - // If PHP 4 is being used we have to build our own result - foreach ($this->result_array() as $key => $val) - { - $obj = new stdClass(); - if (is_array($val)) - { - foreach ($val as $k => $v) - { - $obj->$k = $v; - } - } - else - { - $obj->$key = $val; - } - - $result[] = $obj; - } - - return $result; - } - - // -------------------------------------------------------------------- - - /** - * Query result. "array" version. - * - * @access public - * @return array - */ - function result_array() - { - if (count($this->result_array) > 0) - { - return $this->result_array; - } - - // oracle's fetch functions do not return arrays. - // The information is returned in reference parameters - $row = NULL; - while ($this->_fetch_assoc($row)) - { - $this->result_array[] = $row; - } - - return $this->result_array; - } - - // -------------------------------------------------------------------- - - /** - * Data Seek - * - * Moves the internal pointer to the desired offset. We call - * this internally before fetching results to make sure the - * result set starts at zero - * - * @access private - * @return array - */ - function _data_seek($n = 0) - { - return FALSE; // Not needed - } - -} - - -/* End of file oci8_result.php */ +result_array()); + @ociexecute($this->stmt_id); + + if ($this->curs_id) + { + @ociexecute($this->curs_id); + } + + return $rowcount; + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + $count = @ocinumcols($this->stmt_id); + + // if we used a limit we subtract it + if ($this->limit_used) + { + $count = $count - 1; + } + + return $count; + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function list_fields() + { + $field_names = array(); + $fieldCount = $this->num_fields(); + for ($c = 1; $c <= $fieldCount; $c++) + { + $field_names[] = ocicolumnname($this->stmt_id, $c); + } + return $field_names; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + $fieldCount = $this->num_fields(); + for ($c = 1; $c <= $fieldCount; $c++) + { + $F = new stdClass(); + $F->name = ocicolumnname($this->stmt_id, $c); + $F->type = ocicolumntype($this->stmt_id, $c); + $F->max_length = ocicolumnsize($this->stmt_id, $c); + + $retval[] = $F; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return null + */ + function free_result() + { + if (is_resource($this->result_id)) + { + ocifreestatement($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @access private + * @return array + */ + function _fetch_assoc(&$row) + { + $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; + + return ocifetchinto($id, $row, OCI_ASSOC + OCI_RETURN_NULLS); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + function _fetch_object() + { + $result = array(); + + // If PHP 5 is being used we can fetch an result object + if (function_exists('oci_fetch_object')) + { + $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; + + return @oci_fetch_object($id); + } + + // If PHP 4 is being used we have to build our own result + foreach ($this->result_array() as $key => $val) + { + $obj = new stdClass(); + if (is_array($val)) + { + foreach ($val as $k => $v) + { + $obj->$k = $v; + } + } + else + { + $obj->$key = $val; + } + + $result[] = $obj; + } + + return $result; + } + + // -------------------------------------------------------------------- + + /** + * Query result. "array" version. + * + * @access public + * @return array + */ + function result_array() + { + if (count($this->result_array) > 0) + { + return $this->result_array; + } + + // oracle's fetch functions do not return arrays. + // The information is returned in reference parameters + $row = NULL; + while ($this->_fetch_assoc($row)) + { + $this->result_array[] = $row; + } + + return $this->result_array; + } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero + * + * @access private + * @return array + */ + function _data_seek($n = 0) + { + return FALSE; // Not needed + } + +} + + +/* End of file oci8_result.php */ /* Location: ./system/database/drivers/oci8/oci8_result.php */ \ No newline at end of file diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index a3b6d8157..cf6e9e640 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -1,122 +1,122 @@ -db->display_error('db_unsuported_feature'); - } - - /** - * - * The functions below have been deprecated as of 1.6, and are only here for backwards - * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation - * is STRONGLY discouraged in favour if using dbforge. - * - */ - - /** - * Create database - * - * @access public - * @param string the database name - * @return bool - */ - function _create_database($name) - { - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access private - * @param string the database name - * @return bool - */ - function _drop_database($name) - { - return FALSE; - } - -} - -/* End of file oci8_utility.php */ +db->display_error('db_unsuported_feature'); + } + + /** + * + * The functions below have been deprecated as of 1.6, and are only here for backwards + * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation + * is STRONGLY discouraged in favour if using dbforge. + * + */ + + /** + * Create database + * + * @access public + * @param string the database name + * @return bool + */ + function _create_database($name) + { + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access private + * @param string the database name + * @return bool + */ + function _drop_database($name) + { + return FALSE; + } + +} + +/* End of file oci8_utility.php */ /* Location: ./system/database/drivers/oci8/oci8_utility.php */ \ No newline at end of file diff --git a/system/database/drivers/odbc/index.html b/system/database/drivers/odbc/index.html index 065d2da5e..c942a79ce 100644 --- a/system/database/drivers/odbc/index.html +++ b/system/database/drivers/odbc/index.html @@ -1,10 +1,10 @@ - - - 403 Forbidden - - - -

Directory access is forbidden.

- - + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 3c6f01542..8fcbcfe0d 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -1,594 +1,594 @@ -_random_keyword = ' RND('.time().')'; // database specific random keyword - } - - /** - * Non-persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_connect() - { - return @odbc_connect($this->hostname, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return @odbc_pconnect($this->hostname, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - // Not needed for ODBC - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Set client character set - * - * @access public - * @param string - * @param string - * @return resource - */ - function db_set_charset($charset, $collation) - { - // @todo - add support if needed - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return resource - */ - function _execute($sql) - { - $sql = $this->_prep_query($sql); - return @odbc_exec($this->conn_id, $sql); - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @access private called by execute() - * @param string an SQL query - * @return string - */ - function _prep_query($sql) - { - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @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) - { - return TRUE; - } - - // Reset the transaction failure flag. - // 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; - - return odbc_autocommit($this->conn_id, FALSE); - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $ret = odbc_commit($this->conn_id); - odbc_autocommit($this->conn_id, TRUE); - return $ret; - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $ret = odbc_rollback($this->conn_id); - odbc_autocommit($this->conn_id, TRUE); - return $ret; - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @return string - */ - function escape_str($str) - { - // Access the CI object - $CI =& get_instance(); - - // ODBC doesn't require escaping - return $CI->_remove_invisible_characters($str); - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @odbc_num_rows($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - return @odbc_insert_id($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - 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) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @param boolean - * @return string - */ - function _list_tables($prefix_limit = FALSE) - { - $sql = "SHOW TABLES FROM `".$this->database."`"; - - if ($prefix_limit !== FALSE AND $this->dbprefix != '') - { - //$sql .= " LIKE '".$this->dbprefix."%'"; - return FALSE; // not currently supported - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Show column query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _list_columns($table = '') - { - return "SHOW COLUMNS FROM ".$table; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - return "SELECT TOP 1 FROM ".$table; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access private - * @return string - */ - function _error_message() - { - return odbc_errormsg($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access private - * @return integer - */ - function _error_number() - { - return odbc_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Escape the SQL Identifiers - * - * This function escapes column and table names - * - * @access private - * @param string - * @return string - */ - function _escape_identifiers($item) - { - if ($this->_escape_char == '') - { - return $item; - } - - foreach ($this->_reserved_identifiers as $id) - { - if (strpos($item, '.'.$id) !== FALSE) - { - $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; - } - 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); - } - - // -------------------------------------------------------------------- - - /** - * From Tables - * - * This function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @access public - * @param type - * @return type - */ - function _from_tables($tables) - { - if ( ! is_array($tables)) - { - $tables = array($tables); - } - - return '('.implode(', ', $tables).')'; - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @param array the orderby clause - * @param array the limit clause - * @return string - */ - function _update($table, $values, $where, $orderby = array(), $limit = FALSE) - { - foreach($values as $key => $val) - { - $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; - } - - - // -------------------------------------------------------------------- - - /** - * Truncate statement - * - * Generates a platform-specific truncate string from the supplied data - * If the database does not support the truncate() command - * This function maps to "DELETE FROM table" - * - * @access public - * @param string the table name - * @return string - */ - function _truncate($table) - { - return $this->_delete($table); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @param string the limit clause - * @return string - */ - function _delete($table, $where = array(), $like = array(), $limit = FALSE) - { - $conditions = ''; - - if (count($where) > 0 OR count($like) > 0) - { - $conditions = "\nWHERE "; - $conditions .= implode("\n", $this->ar_where); - - if (count($where) > 0 && count($like) > 0) - { - $conditions .= " AND "; - } - $conditions .= implode("\n", $like); - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - return "DELETE FROM ".$table.$conditions.$limit; - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - // Does ODBC doesn't use the LIMIT clause? - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - @odbc_close($conn_id); - } - - -} - - - -/* End of file odbc_driver.php */ +_random_keyword = ' RND('.time().')'; // database specific random keyword + } + + /** + * Non-persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_connect() + { + return @odbc_connect($this->hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return @odbc_pconnect($this->hostname, $this->username, $this->password); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + // Not needed for ODBC + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Set client character set + * + * @access public + * @param string + * @param string + * @return resource + */ + function db_set_charset($charset, $collation) + { + // @todo - add support if needed + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + function _execute($sql) + { + $sql = $this->_prep_query($sql); + return @odbc_exec($this->conn_id, $sql); + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @access private called by execute() + * @param string an SQL query + * @return string + */ + function _prep_query($sql) + { + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @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) + { + return TRUE; + } + + // Reset the transaction failure flag. + // 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; + + return odbc_autocommit($this->conn_id, FALSE); + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @access public + * @return bool + */ + function trans_commit() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $ret = odbc_commit($this->conn_id); + odbc_autocommit($this->conn_id, TRUE); + return $ret; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @access public + * @return bool + */ + function trans_rollback() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $ret = odbc_rollback($this->conn_id); + odbc_autocommit($this->conn_id, TRUE); + return $ret; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + // Access the CI object + $CI =& get_instance(); + + // ODBC doesn't require escaping + return $CI->_remove_invisible_characters($str); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @odbc_num_rows($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + return @odbc_insert_id($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + 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) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @param boolean + * @return string + */ + function _list_tables($prefix_limit = FALSE) + { + $sql = "SHOW TABLES FROM `".$this->database."`"; + + if ($prefix_limit !== FALSE AND $this->dbprefix != '') + { + //$sql .= " LIKE '".$this->dbprefix."%'"; + return FALSE; // not currently supported + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _list_columns($table = '') + { + return "SHOW COLUMNS FROM ".$table; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + return "SELECT TOP 1 FROM ".$table; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access private + * @return string + */ + function _error_message() + { + return odbc_errormsg($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access private + * @return integer + */ + function _error_number() + { + return odbc_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Escape the SQL Identifiers + * + * This function escapes column and table names + * + * @access private + * @param string + * @return string + */ + function _escape_identifiers($item) + { + if ($this->_escape_char == '') + { + return $item; + } + + foreach ($this->_reserved_identifiers as $id) + { + if (strpos($item, '.'.$id) !== FALSE) + { + $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; + } + 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); + } + + // -------------------------------------------------------------------- + + /** + * From Tables + * + * This function implicitly groups FROM tables so there is no confusion + * about operator precedence in harmony with SQL standards + * + * @access public + * @param type + * @return type + */ + function _from_tables($tables) + { + if ( ! is_array($tables)) + { + $tables = array($tables); + } + + return '('.implode(', ', $tables).')'; + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @param array the orderby clause + * @param array the limit clause + * @return string + */ + function _update($table, $values, $where, $orderby = array(), $limit = FALSE) + { + foreach($values as $key => $val) + { + $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; + } + + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * If the database does not support the truncate() command + * This function maps to "DELETE FROM table" + * + * @access public + * @param string the table name + * @return string + */ + function _truncate($table) + { + return $this->_delete($table); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @param string the limit clause + * @return string + */ + function _delete($table, $where = array(), $like = array(), $limit = FALSE) + { + $conditions = ''; + + if (count($where) > 0 OR count($like) > 0) + { + $conditions = "\nWHERE "; + $conditions .= implode("\n", $this->ar_where); + + if (count($where) > 0 && count($like) > 0) + { + $conditions .= " AND "; + } + $conditions .= implode("\n", $like); + } + + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; + + return "DELETE FROM ".$table.$conditions.$limit; + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + // Does ODBC doesn't use the LIMIT clause? + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + @odbc_close($conn_id); + } + + +} + + + +/* End of file odbc_driver.php */ /* Location: ./system/database/drivers/odbc/odbc_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php index 099925caf..5305afbe4 100644 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -1,266 +1,266 @@ -db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access private - * @param string the database name - * @return bool - */ - function _drop_database($name) - { - // ODBC has no "drop database" command since it's - // designed to connect to an existing database - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Create Table - * - * @access private - * @param string the table name - * @param array the fields - * @param mixed primary key(s) - * @param mixed key(s) - * @param boolean should 'IF NOT EXISTS' be added to the SQL - * @return bool - */ - 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)." ("; - $current_field_count = 0; - - foreach ($fields as $field=>$attributes) - { - // Numeric field names aren't allowed in databases, so if the key is - // numeric, we know it was assigned by PHP and the developer manually - // entered the field information, so we'll simply add it to the list - if (is_numeric($field)) - { - $sql .= "\n\t$attributes"; - } - else - { - $attributes = array_change_key_case($attributes, CASE_UPPER); - - $sql .= "\n\t".$this->db->_protect_identifiers($field); - - $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) && $attributes['NULL'] === TRUE) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' 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 .= ','; - } - } - - if (count($primary_keys) > 0) - { - $primary_keys = $this->db->_protect_identifiers($primary_keys); - $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; - } - - if (is_array($keys) && count($keys) > 0) - { - foreach ($keys as $key) - { - if (is_array($key)) - { - $key = $this->db->_protect_identifiers($key); - } - else - { - $key = array($this->db->_protect_identifiers($key)); - } - - $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")"; - } - } - - $sql .= "\n)"; - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Drop Table - * - * @access private - * @return bool - */ - function _drop_table($table) - { - // Not a supported ODBC feature - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Alter table query - * - * Generates a platform-specific query so that a table can be altered - * Called by add_column(), drop_column(), and column_alter(), - * - * @access private - * @param string the ALTER type (ADD, DROP, CHANGE) - * @param string the column name - * @param string the table name - * @param string the column definition - * @param string the default value - * @param boolean should 'NOT NULL' be added - * @param string the field after which we should add the new field - * @return object - */ - function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') - { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name); - - // DROP has everything it needs now. - if ($alter_type == 'DROP') - { - return $sql; - } - - $sql .= " $column_definition"; - - if ($default_value != '') - { - $sql .= " DEFAULT \"$default_value\""; - } - - if ($null === NULL) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } - - if ($after_field != '') - { - $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); - } - - return $sql; - - } - - - // -------------------------------------------------------------------- - - /** - * Rename a table - * - * Generates a platform-specific query so that a table can be renamed - * - * @access private - * @param string the old table name - * @param string the new table name - * @return string - */ - function _rename_table($table_name, $new_table_name) - { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); - return $sql; - } - - -} - -/* End of file odbc_forge.php */ +db->db_debug) + { + return $this->db->display_error('db_unsuported_feature'); + } + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access private + * @param string the database name + * @return bool + */ + function _drop_database($name) + { + // ODBC has no "drop database" command since it's + // designed to connect to an existing database + if ($this->db->db_debug) + { + return $this->db->display_error('db_unsuported_feature'); + } + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Create Table + * + * @access private + * @param string the table name + * @param array the fields + * @param mixed primary key(s) + * @param mixed key(s) + * @param boolean should 'IF NOT EXISTS' be added to the SQL + * @return bool + */ + 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)." ("; + $current_field_count = 0; + + foreach ($fields as $field=>$attributes) + { + // Numeric field names aren't allowed in databases, so if the key is + // numeric, we know it was assigned by PHP and the developer manually + // entered the field information, so we'll simply add it to the list + if (is_numeric($field)) + { + $sql .= "\n\t$attributes"; + } + else + { + $attributes = array_change_key_case($attributes, CASE_UPPER); + + $sql .= "\n\t".$this->db->_protect_identifiers($field); + + $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) && $attributes['NULL'] === TRUE) + { + $sql .= ' NULL'; + } + else + { + $sql .= ' 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 .= ','; + } + } + + if (count($primary_keys) > 0) + { + $primary_keys = $this->db->_protect_identifiers($primary_keys); + $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; + } + + if (is_array($keys) && count($keys) > 0) + { + foreach ($keys as $key) + { + if (is_array($key)) + { + $key = $this->db->_protect_identifiers($key); + } + else + { + $key = array($this->db->_protect_identifiers($key)); + } + + $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")"; + } + } + + $sql .= "\n)"; + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * @access private + * @return bool + */ + function _drop_table($table) + { + // Not a supported ODBC feature + if ($this->db->db_debug) + { + return $this->db->display_error('db_unsuported_feature'); + } + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Alter table query + * + * Generates a platform-specific query so that a table can be altered + * Called by add_column(), drop_column(), and column_alter(), + * + * @access private + * @param string the ALTER type (ADD, DROP, CHANGE) + * @param string the column name + * @param string the table name + * @param string the column definition + * @param string the default value + * @param boolean should 'NOT NULL' be added + * @param string the field after which we should add the new field + * @return object + */ + function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') + { + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name); + + // DROP has everything it needs now. + if ($alter_type == 'DROP') + { + return $sql; + } + + $sql .= " $column_definition"; + + if ($default_value != '') + { + $sql .= " DEFAULT \"$default_value\""; + } + + if ($null === NULL) + { + $sql .= ' NULL'; + } + else + { + $sql .= ' NOT NULL'; + } + + if ($after_field != '') + { + $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); + } + + return $sql; + + } + + + // -------------------------------------------------------------------- + + /** + * Rename a table + * + * Generates a platform-specific query so that a table can be renamed + * + * @access private + * @param string the old table name + * @param string the new table name + * @return string + */ + function _rename_table($table_name, $new_table_name) + { + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); + return $sql; + } + + +} + +/* End of file odbc_forge.php */ /* Location: ./system/database/drivers/odbc/odbc_forge.php */ \ No newline at end of file diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index 6d6542e77..9a59cfc20 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -1,228 +1,228 @@ -result_id); - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - return @odbc_num_fields($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Fetch Field Names - * - * Generates an array of column names - * - * @access public - * @return array - */ - function list_fields() - { - $field_names = array(); - for ($i = 0; $i < $this->num_fields(); $i++) - { - $field_names[] = odbc_field_name($this->result_id, $i); - } - - return $field_names; - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - function field_data() - { - $retval = array(); - for ($i = 0; $i < $this->num_fields(); $i++) - { - $F = new stdClass(); - $F->name = odbc_field_name($this->result_id, $i); - $F->type = odbc_field_type($this->result_id, $i); - $F->max_length = odbc_field_len($this->result_id, $i); - $F->primary_key = 0; - $F->default = ''; - - $retval[] = $F; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Free the result - * - * @return null - */ - function free_result() - { - if (is_resource($this->result_id)) - { - odbc_free_result($this->result_id); - $this->result_id = FALSE; - } - } - - // -------------------------------------------------------------------- - - /** - * Data Seek - * - * Moves the internal pointer to the desired offset. We call - * this internally before fetching results to make sure the - * result set starts at zero - * - * @access private - * @return array - */ - function _data_seek($n = 0) - { - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Result - associative array - * - * Returns the result set as an array - * - * @access private - * @return array - */ - function _fetch_assoc() - { - if (function_exists('odbc_fetch_object')) - { - return odbc_fetch_array($this->result_id); - } - else - { - return $this->_odbc_fetch_array($this->result_id); - } - } - - // -------------------------------------------------------------------- - - /** - * Result - object - * - * Returns the result set as an object - * - * @access private - * @return object - */ - function _fetch_object() - { - if (function_exists('odbc_fetch_object')) - { - return odbc_fetch_object($this->result_id); - } - else - { - return $this->_odbc_fetch_object($this->result_id); - } - } - - - /** - * Result - object - * - * subsititutes the odbc_fetch_object function when - * not available (odbc_fetch_object requires unixODBC) - * - * @access private - * @return object - */ - function _odbc_fetch_object(& $odbc_result) { - $rs = array(); - $rs_obj = false; - if (odbc_fetch_into($odbc_result, $rs)) { - foreach ($rs as $k=>$v) { - $field_name= odbc_field_name($odbc_result, $k+1); - $rs_obj->$field_name = $v; - } - } - return $rs_obj; - } - - - /** - * Result - array - * - * subsititutes the odbc_fetch_array function when - * not available (odbc_fetch_array requires unixODBC) - * - * @access private - * @return array - */ - function _odbc_fetch_array(& $odbc_result) { - $rs = array(); - $rs_assoc = false; - if (odbc_fetch_into($odbc_result, $rs)) { - $rs_assoc=array(); - foreach ($rs as $k=>$v) { - $field_name= odbc_field_name($odbc_result, $k+1); - $rs_assoc[$field_name] = $v; - } - } - return $rs_assoc; - } - -} - - -/* End of file odbc_result.php */ +result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @odbc_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function list_fields() + { + $field_names = array(); + for ($i = 0; $i < $this->num_fields(); $i++) + { + $field_names[] = odbc_field_name($this->result_id, $i); + } + + return $field_names; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + for ($i = 0; $i < $this->num_fields(); $i++) + { + $F = new stdClass(); + $F->name = odbc_field_name($this->result_id, $i); + $F->type = odbc_field_type($this->result_id, $i); + $F->max_length = odbc_field_len($this->result_id, $i); + $F->primary_key = 0; + $F->default = ''; + + $retval[] = $F; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return null + */ + function free_result() + { + if (is_resource($this->result_id)) + { + odbc_free_result($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero + * + * @access private + * @return array + */ + function _data_seek($n = 0) + { + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @access private + * @return array + */ + function _fetch_assoc() + { + if (function_exists('odbc_fetch_object')) + { + return odbc_fetch_array($this->result_id); + } + else + { + return $this->_odbc_fetch_array($this->result_id); + } + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + function _fetch_object() + { + if (function_exists('odbc_fetch_object')) + { + return odbc_fetch_object($this->result_id); + } + else + { + return $this->_odbc_fetch_object($this->result_id); + } + } + + + /** + * Result - object + * + * subsititutes the odbc_fetch_object function when + * not available (odbc_fetch_object requires unixODBC) + * + * @access private + * @return object + */ + function _odbc_fetch_object(& $odbc_result) { + $rs = array(); + $rs_obj = false; + if (odbc_fetch_into($odbc_result, $rs)) { + foreach ($rs as $k=>$v) { + $field_name= odbc_field_name($odbc_result, $k+1); + $rs_obj->$field_name = $v; + } + } + return $rs_obj; + } + + + /** + * Result - array + * + * subsititutes the odbc_fetch_array function when + * not available (odbc_fetch_array requires unixODBC) + * + * @access private + * @return array + */ + function _odbc_fetch_array(& $odbc_result) { + $rs = array(); + $rs_assoc = false; + if (odbc_fetch_into($odbc_result, $rs)) { + $rs_assoc=array(); + foreach ($rs as $k=>$v) { + $field_name= odbc_field_name($odbc_result, $k+1); + $rs_assoc[$field_name] = $v; + } + } + return $rs_assoc; + } + +} + + +/* End of file odbc_result.php */ /* Location: ./system/database/drivers/odbc/odbc_result.php */ \ 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 6f4376ed2..67aee6420 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -1,148 +1,148 @@ -db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Optimize table query - * - * Generates a platform-specific query so that a table can be optimized - * - * @access private - * @param string the table name - * @return object - */ - function _optimize_table($table) - { - // Not a supported ODBC feature - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Repair table query - * - * Generates a platform-specific query so that a table can be repaired - * - * @access private - * @param string the table name - * @return object - */ - function _repair_table($table) - { - // Not a supported ODBC feature - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - 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'); - } - - /** - * - * The functions below have been deprecated as of 1.6, and are only here for backwards - * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation - * is STRONGLY discouraged in favour if using dbforge. - * - */ - - /** - * Create database - * - * @access private - * @param string the database name - * @return bool - */ - function _create_database() - { - // ODBC has no "create database" command since it's - // designed to connect to an existing database - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access private - * @param string the database name - * @return bool - */ - function _drop_database($name) - { - // ODBC has no "drop database" command since it's - // designed to connect to an existing database - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return FALSE; - } -} - -/* End of file odbc_utility.php */ +db->db_debug) + { + return $this->db->display_error('db_unsuported_feature'); + } + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Optimize table query + * + * Generates a platform-specific query so that a table can be optimized + * + * @access private + * @param string the table name + * @return object + */ + function _optimize_table($table) + { + // Not a supported ODBC feature + if ($this->db->db_debug) + { + return $this->db->display_error('db_unsuported_feature'); + } + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Repair table query + * + * Generates a platform-specific query so that a table can be repaired + * + * @access private + * @param string the table name + * @return object + */ + function _repair_table($table) + { + // Not a supported ODBC feature + if ($this->db->db_debug) + { + return $this->db->display_error('db_unsuported_feature'); + } + 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'); + } + + /** + * + * The functions below have been deprecated as of 1.6, and are only here for backwards + * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation + * is STRONGLY discouraged in favour if using dbforge. + * + */ + + /** + * Create database + * + * @access private + * @param string the database name + * @return bool + */ + function _create_database() + { + // ODBC has no "create database" command since it's + // designed to connect to an existing database + if ($this->db->db_debug) + { + return $this->db->display_error('db_unsuported_feature'); + } + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access private + * @param string the database name + * @return bool + */ + function _drop_database($name) + { + // ODBC has no "drop database" command since it's + // designed to connect to an existing database + if ($this->db->db_debug) + { + return $this->db->display_error('db_unsuported_feature'); + } + return FALSE; + } +} + +/* End of file odbc_utility.php */ /* Location: ./system/database/drivers/odbc/odbc_utility.php */ \ No newline at end of file diff --git a/system/database/drivers/postgre/index.html b/system/database/drivers/postgre/index.html index 065d2da5e..c942a79ce 100644 --- a/system/database/drivers/postgre/index.html +++ b/system/database/drivers/postgre/index.html @@ -1,10 +1,10 @@ - - - 403 Forbidden - - - -

Directory access is forbidden.

- - + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 68622a22b..da0b0f23a 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -1,636 +1,636 @@ - 'host', - 'port' => 'port', - 'database' => 'dbname', - 'username' => 'user', - 'password' => 'password' - ); - - $connect_string = ""; - foreach ($components as $key => $val) - { - if (isset($this->$key) && $this->$key != '') - { - $connect_string .= " $val=".$this->$key; - } - } - return trim($connect_string); - } - - // -------------------------------------------------------------------- - - /** - * Non-persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_connect() - { - return @pg_connect($this->_connect_string()); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return @pg_pconnect($this->_connect_string()); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - // Not needed for Postgre so we'll return TRUE - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Set client character set - * - * @access public - * @param string - * @param string - * @return resource - */ - function db_set_charset($charset, $collation) - { - // @todo - add support if needed - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return resource - */ - function _execute($sql) - { - $sql = $this->_prep_query($sql); - return @pg_query($this->conn_id, $sql); - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @access private called by execute() - * @param string an SQL query - * @return string - */ - function _prep_query($sql) - { - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @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) - { - return TRUE; - } - - // Reset the transaction failure flag. - // 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; - - return @pg_exec($this->conn_id, "begin"); - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - return @pg_exec($this->conn_id, "commit"); - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - return @pg_exec($this->conn_id, "rollback"); - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @return string - */ - function escape_str($str) - { - return pg_escape_string($str); - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @pg_affected_rows($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - $v = $this->_version(); - $v = $v['server']; - - $table = func_num_args() > 0 ? func_get_arg(0) : null; - $column = func_num_args() > 1 ? func_get_arg(1) : null; - - if ($table == null && $v >= '8.1') - { - $sql='SELECT LASTVAL() as ins_id'; - } - elseif ($table != null && $column != null && $v >= '8.0') - { - $sql = sprintf("SELECT pg_get_serial_sequence('%s','%s') as seq", $table, $column); - $query = $this->query($sql); - $row = $query->row(); - $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $row->seq); - } - elseif ($table != null) - { - // seq_name passed in table parameter - $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $table); - } - else - { - return pg_last_oid($this->result_id); - } - $query = $this->query($sql); - $row = $query->row(); - return $row->ins_id; - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - 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) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @param boolean - * @return string - */ - function _list_tables($prefix_limit = FALSE) - { - $sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; - - if ($prefix_limit !== FALSE AND $this->dbprefix != '') - { - $sql .= " AND table_name LIKE '".$this->dbprefix."%'"; - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Show column query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _list_columns($table = '') - { - return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$table."'"; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - return "SELECT * FROM ".$table." LIMIT 1"; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access private - * @return string - */ - function _error_message() - { - return pg_last_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access private - * @return integer - */ - function _error_number() - { - return ''; - } - - // -------------------------------------------------------------------- - - /** - * Escape the SQL Identifiers - * - * This function escapes column and table names - * - * @access private - * @param string - * @return string - */ - function _escape_identifiers($item) - { - if ($this->_escape_char == '') - { - return $item; - } - - foreach ($this->_reserved_identifiers as $id) - { - if (strpos($item, '.'.$id) !== FALSE) - { - $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; - } - 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); - } - - // -------------------------------------------------------------------- - - /** - * From Tables - * - * This function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @access public - * @param type - * @return type - */ - function _from_tables($tables) - { - if ( ! is_array($tables)) - { - $tables = array($tables); - } - - return implode(', ', $tables); - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @param array the orderby clause - * @param array the limit clause - * @return string - */ - function _update($table, $values, $where, $orderby = array(), $limit = FALSE) - { - foreach($values as $key => $val) - { - $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; - } - - // -------------------------------------------------------------------- - - /** - * Truncate statement - * - * Generates a platform-specific truncate string from the supplied data - * If the database does not support the truncate() command - * This function maps to "DELETE FROM table" - * - * @access public - * @param string the table name - * @return string - */ - function _truncate($table) - { - return "TRUNCATE ".$table; - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @param string the limit clause - * @return string - */ - function _delete($table, $where = array(), $like = array(), $limit = FALSE) - { - $conditions = ''; - - if (count($where) > 0 OR count($like) > 0) - { - $conditions = "\nWHERE "; - $conditions .= implode("\n", $this->ar_where); - - if (count($where) > 0 && count($like) > 0) - { - $conditions .= " AND "; - } - $conditions .= implode("\n", $like); - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - return "DELETE FROM ".$table.$conditions.$limit; - } - - // -------------------------------------------------------------------- - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - $sql .= "LIMIT ".$limit; - - if ($offset > 0) - { - $sql .= " OFFSET ".$offset; - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - @pg_close($conn_id); - } - - -} - - -/* End of file postgre_driver.php */ + 'host', + 'port' => 'port', + 'database' => 'dbname', + 'username' => 'user', + 'password' => 'password' + ); + + $connect_string = ""; + foreach ($components as $key => $val) + { + if (isset($this->$key) && $this->$key != '') + { + $connect_string .= " $val=".$this->$key; + } + } + return trim($connect_string); + } + + // -------------------------------------------------------------------- + + /** + * Non-persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_connect() + { + return @pg_connect($this->_connect_string()); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return @pg_pconnect($this->_connect_string()); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + // Not needed for Postgre so we'll return TRUE + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Set client character set + * + * @access public + * @param string + * @param string + * @return resource + */ + function db_set_charset($charset, $collation) + { + // @todo - add support if needed + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + function _execute($sql) + { + $sql = $this->_prep_query($sql); + return @pg_query($this->conn_id, $sql); + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @access private called by execute() + * @param string an SQL query + * @return string + */ + function _prep_query($sql) + { + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @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) + { + return TRUE; + } + + // Reset the transaction failure flag. + // 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; + + return @pg_exec($this->conn_id, "begin"); + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @access public + * @return bool + */ + function trans_commit() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + return @pg_exec($this->conn_id, "commit"); + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @access public + * @return bool + */ + function trans_rollback() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + return @pg_exec($this->conn_id, "rollback"); + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + return pg_escape_string($str); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @pg_affected_rows($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + $v = $this->_version(); + $v = $v['server']; + + $table = func_num_args() > 0 ? func_get_arg(0) : null; + $column = func_num_args() > 1 ? func_get_arg(1) : null; + + if ($table == null && $v >= '8.1') + { + $sql='SELECT LASTVAL() as ins_id'; + } + elseif ($table != null && $column != null && $v >= '8.0') + { + $sql = sprintf("SELECT pg_get_serial_sequence('%s','%s') as seq", $table, $column); + $query = $this->query($sql); + $row = $query->row(); + $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $row->seq); + } + elseif ($table != null) + { + // seq_name passed in table parameter + $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $table); + } + else + { + return pg_last_oid($this->result_id); + } + $query = $this->query($sql); + $row = $query->row(); + return $row->ins_id; + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + 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) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @param boolean + * @return string + */ + function _list_tables($prefix_limit = FALSE) + { + $sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; + + if ($prefix_limit !== FALSE AND $this->dbprefix != '') + { + $sql .= " AND table_name LIKE '".$this->dbprefix."%'"; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _list_columns($table = '') + { + return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$table."'"; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + return "SELECT * FROM ".$table." LIMIT 1"; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access private + * @return string + */ + function _error_message() + { + return pg_last_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access private + * @return integer + */ + function _error_number() + { + return ''; + } + + // -------------------------------------------------------------------- + + /** + * Escape the SQL Identifiers + * + * This function escapes column and table names + * + * @access private + * @param string + * @return string + */ + function _escape_identifiers($item) + { + if ($this->_escape_char == '') + { + return $item; + } + + foreach ($this->_reserved_identifiers as $id) + { + if (strpos($item, '.'.$id) !== FALSE) + { + $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; + } + 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); + } + + // -------------------------------------------------------------------- + + /** + * From Tables + * + * This function implicitly groups FROM tables so there is no confusion + * about operator precedence in harmony with SQL standards + * + * @access public + * @param type + * @return type + */ + function _from_tables($tables) + { + if ( ! is_array($tables)) + { + $tables = array($tables); + } + + return implode(', ', $tables); + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @param array the orderby clause + * @param array the limit clause + * @return string + */ + function _update($table, $values, $where, $orderby = array(), $limit = FALSE) + { + foreach($values as $key => $val) + { + $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; + } + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * If the database does not support the truncate() command + * This function maps to "DELETE FROM table" + * + * @access public + * @param string the table name + * @return string + */ + function _truncate($table) + { + return "TRUNCATE ".$table; + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @param string the limit clause + * @return string + */ + function _delete($table, $where = array(), $like = array(), $limit = FALSE) + { + $conditions = ''; + + if (count($where) > 0 OR count($like) > 0) + { + $conditions = "\nWHERE "; + $conditions .= implode("\n", $this->ar_where); + + if (count($where) > 0 && count($like) > 0) + { + $conditions .= " AND "; + } + $conditions .= implode("\n", $like); + } + + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; + + return "DELETE FROM ".$table.$conditions.$limit; + } + + // -------------------------------------------------------------------- + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + $sql .= "LIMIT ".$limit; + + if ($offset > 0) + { + $sql .= " OFFSET ".$offset; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + @pg_close($conn_id); + } + + +} + + +/* End of file postgre_driver.php */ /* Location: ./system/database/drivers/postgre/postgre_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index 5b4bcc295..72c2dd797 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -1,248 +1,248 @@ -db->_escape_identifiers($table)." ("; - $current_field_count = 0; - - foreach ($fields as $field=>$attributes) - { - // Numeric field names aren't allowed in databases, so if the key is - // numeric, we know it was assigned by PHP and the developer manually - // entered the field information, so we'll simply add it to the list - if (is_numeric($field)) - { - $sql .= "\n\t$attributes"; - } - else - { - $attributes = array_change_key_case($attributes, CASE_UPPER); - - $sql .= "\n\t".$this->db->_protect_identifiers($field); - - $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) && $attributes['NULL'] === TRUE) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' 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 .= ','; - } - } - - if (count($primary_keys) > 0) - { - $primary_keys = $this->db->_protect_identifiers($primary_keys); - $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; - } - - if (is_array($keys) && count($keys) > 0) - { - foreach ($keys as $key) - { - if (is_array($key)) - { - $key = $this->db->_protect_identifiers($key); - } - else - { - $key = array($this->db->_protect_identifiers($key)); - } - - $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")"; - } - } - - $sql .= "\n);"; - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Drop Table - * - * @access private - * @return bool - */ - function _drop_table($table) - { - return "DROP TABLE ".$this->db->_escape_identifiers($table)." CASCADE"; - } - - // -------------------------------------------------------------------- - - /** - * Alter table query - * - * Generates a platform-specific query so that a table can be altered - * Called by add_column(), drop_column(), and column_alter(), - * - * @access private - * @param string the ALTER type (ADD, DROP, CHANGE) - * @param string the column name - * @param string the table name - * @param string the column definition - * @param string the default value - * @param boolean should 'NOT NULL' be added - * @param string the field after which we should add the new field - * @return object - */ - function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') - { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name); - - // DROP has everything it needs now. - if ($alter_type == 'DROP') - { - return $sql; - } - - $sql .= " $column_definition"; - - if ($default_value != '') - { - $sql .= " DEFAULT \"$default_value\""; - } - - if ($null === NULL) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } - - if ($after_field != '') - { - $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); - } - - return $sql; - - } - - // -------------------------------------------------------------------- - - /** - * Rename a table - * - * Generates a platform-specific query so that a table can be renamed - * - * @access private - * @param string the old table name - * @param string the new table name - * @return string - */ - function _rename_table($table_name, $new_table_name) - { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); - return $sql; - } - - -} - -/* End of file postgre_forge.php */ +db->_escape_identifiers($table)." ("; + $current_field_count = 0; + + foreach ($fields as $field=>$attributes) + { + // Numeric field names aren't allowed in databases, so if the key is + // numeric, we know it was assigned by PHP and the developer manually + // entered the field information, so we'll simply add it to the list + if (is_numeric($field)) + { + $sql .= "\n\t$attributes"; + } + else + { + $attributes = array_change_key_case($attributes, CASE_UPPER); + + $sql .= "\n\t".$this->db->_protect_identifiers($field); + + $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) && $attributes['NULL'] === TRUE) + { + $sql .= ' NULL'; + } + else + { + $sql .= ' 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 .= ','; + } + } + + if (count($primary_keys) > 0) + { + $primary_keys = $this->db->_protect_identifiers($primary_keys); + $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; + } + + if (is_array($keys) && count($keys) > 0) + { + foreach ($keys as $key) + { + if (is_array($key)) + { + $key = $this->db->_protect_identifiers($key); + } + else + { + $key = array($this->db->_protect_identifiers($key)); + } + + $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")"; + } + } + + $sql .= "\n);"; + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * @access private + * @return bool + */ + function _drop_table($table) + { + return "DROP TABLE ".$this->db->_escape_identifiers($table)." CASCADE"; + } + + // -------------------------------------------------------------------- + + /** + * Alter table query + * + * Generates a platform-specific query so that a table can be altered + * Called by add_column(), drop_column(), and column_alter(), + * + * @access private + * @param string the ALTER type (ADD, DROP, CHANGE) + * @param string the column name + * @param string the table name + * @param string the column definition + * @param string the default value + * @param boolean should 'NOT NULL' be added + * @param string the field after which we should add the new field + * @return object + */ + function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') + { + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name); + + // DROP has everything it needs now. + if ($alter_type == 'DROP') + { + return $sql; + } + + $sql .= " $column_definition"; + + if ($default_value != '') + { + $sql .= " DEFAULT \"$default_value\""; + } + + if ($null === NULL) + { + $sql .= ' NULL'; + } + else + { + $sql .= ' NOT NULL'; + } + + if ($after_field != '') + { + $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); + } + + return $sql; + + } + + // -------------------------------------------------------------------- + + /** + * Rename a table + * + * Generates a platform-specific query so that a table can be renamed + * + * @access private + * @param string the old table name + * @param string the new table name + * @return string + */ + function _rename_table($table_name, $new_table_name) + { + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); + return $sql; + } + + +} + +/* End of file postgre_forge.php */ /* Location: ./system/database/drivers/postgre/postgre_forge.php */ \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index 78b9a6040..3206c1330 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -1,169 +1,169 @@ -result_id); - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - return @pg_num_fields($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Fetch Field Names - * - * Generates an array of column names - * - * @access public - * @return array - */ - function list_fields() - { - $field_names = array(); - for ($i = 0; $i < $this->num_fields(); $i++) - { - $field_names[] = pg_field_name($this->result_id, $i); - } - - return $field_names; - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - function field_data() - { - $retval = array(); - for ($i = 0; $i < $this->num_fields(); $i++) - { - $F = new stdClass(); - $F->name = pg_field_name($this->result_id, $i); - $F->type = pg_field_type($this->result_id, $i); - $F->max_length = pg_field_size($this->result_id, $i); - $F->primary_key = 0; - $F->default = ''; - - $retval[] = $F; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Free the result - * - * @return null - */ - function free_result() - { - if (is_resource($this->result_id)) - { - pg_free_result($this->result_id); - $this->result_id = FALSE; - } - } - - // -------------------------------------------------------------------- - - /** - * Data Seek - * - * Moves the internal pointer to the desired offset. We call - * this internally before fetching results to make sure the - * result set starts at zero - * - * @access private - * @return array - */ - function _data_seek($n = 0) - { - return pg_result_seek($this->result_id, $n); - } - - // -------------------------------------------------------------------- - - /** - * Result - associative array - * - * Returns the result set as an array - * - * @access private - * @return array - */ - function _fetch_assoc() - { - return pg_fetch_assoc($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Result - object - * - * Returns the result set as an object - * - * @access private - * @return object - */ - function _fetch_object() - { - return pg_fetch_object($this->result_id); - } - -} - - -/* End of file postgre_result.php */ +result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @pg_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function list_fields() + { + $field_names = array(); + for ($i = 0; $i < $this->num_fields(); $i++) + { + $field_names[] = pg_field_name($this->result_id, $i); + } + + return $field_names; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + for ($i = 0; $i < $this->num_fields(); $i++) + { + $F = new stdClass(); + $F->name = pg_field_name($this->result_id, $i); + $F->type = pg_field_type($this->result_id, $i); + $F->max_length = pg_field_size($this->result_id, $i); + $F->primary_key = 0; + $F->default = ''; + + $retval[] = $F; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return null + */ + function free_result() + { + if (is_resource($this->result_id)) + { + pg_free_result($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero + * + * @access private + * @return array + */ + function _data_seek($n = 0) + { + return pg_result_seek($this->result_id, $n); + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @access private + * @return array + */ + function _fetch_assoc() + { + return pg_fetch_assoc($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + function _fetch_object() + { + return pg_fetch_object($this->result_id); + } + +} + + +/* End of file postgre_result.php */ /* Location: ./system/database/drivers/postgre/postgre_result.php */ \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index f9b0f22e0..06292f22a 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -1,124 +1,124 @@ -db->display_error('db_unsuported_feature'); - } - - /** - * - * The functions below have been deprecated as of 1.6, and are only here for backwards - * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation - * is STRONGLY discouraged in favour if using dbforge. - * - */ - - /** - * Create database - * - * @access private - * @param string the database name - * @return bool - */ - function _create_database($name) - { - return "CREATE DATABASE ".$name; - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access private - * @param string the database name - * @return bool - */ - function _drop_database($name) - { - return "DROP DATABASE ".$name; - } - - -} - - -/* End of file postgre_utility.php */ +db->display_error('db_unsuported_feature'); + } + + /** + * + * The functions below have been deprecated as of 1.6, and are only here for backwards + * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation + * is STRONGLY discouraged in favour if using dbforge. + * + */ + + /** + * Create database + * + * @access private + * @param string the database name + * @return bool + */ + function _create_database($name) + { + return "CREATE DATABASE ".$name; + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access private + * @param string the database name + * @return bool + */ + function _drop_database($name) + { + return "DROP DATABASE ".$name; + } + + +} + + +/* End of file postgre_utility.php */ /* Location: ./system/database/drivers/postgre/postgre_utility.php */ \ No newline at end of file diff --git a/system/database/drivers/sqlite/index.html b/system/database/drivers/sqlite/index.html index 065d2da5e..c942a79ce 100644 --- a/system/database/drivers/sqlite/index.html +++ b/system/database/drivers/sqlite/index.html @@ -1,10 +1,10 @@ - - - 403 Forbidden - - - -

Directory access is forbidden.

- - + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 992e2479e..058cef77a 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -1,612 +1,612 @@ -database, FILE_WRITE_MODE, $error)) - { - log_message('error', $error); - - if ($this->db_debug) - { - $this->display_error($error, '', TRUE); - } - - return FALSE; - } - - return $conn_id; - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - if ( ! $conn_id = @sqlite_popen($this->database, FILE_WRITE_MODE, $error)) - { - log_message('error', $error); - - if ($this->db_debug) - { - $this->display_error($error, '', TRUE); - } - - return FALSE; - } - - return $conn_id; - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Set client character set - * - * @access public - * @param string - * @param string - * @return resource - */ - function db_set_charset($charset, $collation) - { - // @todo - add support if needed - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return sqlite_libversion(); - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return resource - */ - function _execute($sql) - { - $sql = $this->_prep_query($sql); - return @sqlite_query($this->conn_id, $sql); - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @access private called by execute() - * @param string an SQL query - * @return string - */ - function _prep_query($sql) - { - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @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) - { - return TRUE; - } - - // Reset the transaction failure flag. - // 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('BEGIN TRANSACTION'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $this->simple_query('COMMIT'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - $this->simple_query('ROLLBACK'); - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @return string - */ - function escape_str($str) - { - return sqlite_escape_string($str); - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return sqlite_changes($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - return @sqlite_last_insert_rowid($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - 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) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * List table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @param boolean - * @return string - */ - function _list_tables($prefix_limit = FALSE) - { - $sql = "SELECT name from sqlite_master WHERE type='table'"; - - if ($prefix_limit !== FALSE AND $this->dbprefix != '') - { - $sql .= " AND 'name' LIKE '".$this->dbprefix."%'"; - } - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Show column query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _list_columns($table = '') - { - // Not supported - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - return "SELECT * FROM ".$table." LIMIT 1"; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access private - * @return string - */ - function _error_message() - { - return sqlite_error_string(sqlite_last_error($this->conn_id)); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access private - * @return integer - */ - function _error_number() - { - return sqlite_last_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * Escape the SQL Identifiers - * - * This function escapes column and table names - * - * @access private - * @param string - * @return string - */ - function _escape_identifiers($item) - { - if ($this->_escape_char == '') - { - return $item; - } - - foreach ($this->_reserved_identifiers as $id) - { - if (strpos($item, '.'.$id) !== FALSE) - { - $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; - } - 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); - } - - // -------------------------------------------------------------------- - - /** - * From Tables - * - * This function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @access public - * @param type - * @return type - */ - function _from_tables($tables) - { - if ( ! is_array($tables)) - { - $tables = array($tables); - } - - return '('.implode(', ', $tables).')'; - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @param array the orderby clause - * @param array the limit clause - * @return string - */ - function _update($table, $values, $where, $orderby = array(), $limit = FALSE) - { - foreach($values as $key => $val) - { - $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; - } - - - // -------------------------------------------------------------------- - - /** - * Truncate statement - * - * Generates a platform-specific truncate string from the supplied data - * If the database does not support the truncate() command - * This function maps to "DELETE FROM table" - * - * @access public - * @param string the table name - * @return string - */ - function _truncate($table) - { - return $this->_delete($table); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @param string the limit clause - * @return string - */ - function _delete($table, $where = array(), $like = array(), $limit = FALSE) - { - $conditions = ''; - - if (count($where) > 0 OR count($like) > 0) - { - $conditions = "\nWHERE "; - $conditions .= implode("\n", $this->ar_where); - - if (count($where) > 0 && count($like) > 0) - { - $conditions .= " AND "; - } - $conditions .= implode("\n", $like); - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - return "DELETE FROM ".$table.$conditions.$limit; - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - if ($offset == 0) - { - $offset = ''; - } - else - { - $offset .= ", "; - } - - return $sql."LIMIT ".$offset.$limit; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - @sqlite_close($conn_id); - } - - -} - - -/* End of file sqlite_driver.php */ +database, FILE_WRITE_MODE, $error)) + { + log_message('error', $error); + + if ($this->db_debug) + { + $this->display_error($error, '', TRUE); + } + + return FALSE; + } + + return $conn_id; + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + if ( ! $conn_id = @sqlite_popen($this->database, FILE_WRITE_MODE, $error)) + { + log_message('error', $error); + + if ($this->db_debug) + { + $this->display_error($error, '', TRUE); + } + + return FALSE; + } + + return $conn_id; + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Set client character set + * + * @access public + * @param string + * @param string + * @return resource + */ + function db_set_charset($charset, $collation) + { + // @todo - add support if needed + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return sqlite_libversion(); + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + function _execute($sql) + { + $sql = $this->_prep_query($sql); + return @sqlite_query($this->conn_id, $sql); + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @access private called by execute() + * @param string an SQL query + * @return string + */ + function _prep_query($sql) + { + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @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) + { + return TRUE; + } + + // Reset the transaction failure flag. + // 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('BEGIN TRANSACTION'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @access public + * @return bool + */ + function trans_commit() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $this->simple_query('COMMIT'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @access public + * @return bool + */ + function trans_rollback() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $this->simple_query('ROLLBACK'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + return sqlite_escape_string($str); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return sqlite_changes($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + return @sqlite_last_insert_rowid($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + 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) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @param boolean + * @return string + */ + function _list_tables($prefix_limit = FALSE) + { + $sql = "SELECT name from sqlite_master WHERE type='table'"; + + if ($prefix_limit !== FALSE AND $this->dbprefix != '') + { + $sql .= " AND 'name' LIKE '".$this->dbprefix."%'"; + } + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _list_columns($table = '') + { + // Not supported + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + return "SELECT * FROM ".$table." LIMIT 1"; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access private + * @return string + */ + function _error_message() + { + return sqlite_error_string(sqlite_last_error($this->conn_id)); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access private + * @return integer + */ + function _error_number() + { + return sqlite_last_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Escape the SQL Identifiers + * + * This function escapes column and table names + * + * @access private + * @param string + * @return string + */ + function _escape_identifiers($item) + { + if ($this->_escape_char == '') + { + return $item; + } + + foreach ($this->_reserved_identifiers as $id) + { + if (strpos($item, '.'.$id) !== FALSE) + { + $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; + } + 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); + } + + // -------------------------------------------------------------------- + + /** + * From Tables + * + * This function implicitly groups FROM tables so there is no confusion + * about operator precedence in harmony with SQL standards + * + * @access public + * @param type + * @return type + */ + function _from_tables($tables) + { + if ( ! is_array($tables)) + { + $tables = array($tables); + } + + return '('.implode(', ', $tables).')'; + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @param array the orderby clause + * @param array the limit clause + * @return string + */ + function _update($table, $values, $where, $orderby = array(), $limit = FALSE) + { + foreach($values as $key => $val) + { + $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; + } + + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * If the database does not support the truncate() command + * This function maps to "DELETE FROM table" + * + * @access public + * @param string the table name + * @return string + */ + function _truncate($table) + { + return $this->_delete($table); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @param string the limit clause + * @return string + */ + function _delete($table, $where = array(), $like = array(), $limit = FALSE) + { + $conditions = ''; + + if (count($where) > 0 OR count($like) > 0) + { + $conditions = "\nWHERE "; + $conditions .= implode("\n", $this->ar_where); + + if (count($where) > 0 && count($like) > 0) + { + $conditions .= " AND "; + } + $conditions .= implode("\n", $like); + } + + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; + + return "DELETE FROM ".$table.$conditions.$limit; + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + if ($offset == 0) + { + $offset = ''; + } + else + { + $offset .= ", "; + } + + return $sql."LIMIT ".$offset.$limit; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + @sqlite_close($conn_id); + } + + +} + + +/* End of file sqlite_driver.php */ /* Location: ./system/database/drivers/sqlite/sqlite_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php index 2039525be..73630defb 100644 --- a/system/database/drivers/sqlite/sqlite_forge.php +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -1,265 +1,265 @@ -db->database) OR ! @unlink($this->db->database)) - { - if ($this->db->db_debug) - { - return $this->db->display_error('db_unable_to_drop'); - } - return FALSE; - } - return TRUE; - } - // -------------------------------------------------------------------- - - /** - * Create Table - * - * @access private - * @param string the table name - * @param array the fields - * @param mixed primary key(s) - * @param mixed key(s) - * @param boolean should 'IF NOT EXISTS' be added to the SQL - * @return bool - */ - function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) - { - $sql = 'CREATE TABLE '; - - // IF NOT EXISTS added to SQLite in 3.3.0 - if ($if_not_exists === TRUE && version_compare($this->_version(), '3.3.0', '>=') === TRUE) - { - $sql .= 'IF NOT EXISTS '; - } - - $sql .= $this->db->_escape_identifiers($table)."("; - $current_field_count = 0; - - foreach ($fields as $field=>$attributes) - { - // Numeric field names aren't allowed in databases, so if the key is - // numeric, we know it was assigned by PHP and the developer manually - // entered the field information, so we'll simply add it to the list - if (is_numeric($field)) - { - $sql .= "\n\t$attributes"; - } - else - { - $attributes = array_change_key_case($attributes, CASE_UPPER); - - $sql .= "\n\t".$this->db->_protect_identifiers($field); - - $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) && $attributes['NULL'] === TRUE) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' 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 .= ','; - } - } - - if (count($primary_keys) > 0) - { - $primary_keys = $this->db->_protect_identifiers($primary_keys); - $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; - } - - if (is_array($keys) && count($keys) > 0) - { - foreach ($keys as $key) - { - if (is_array($key)) - { - $key = $this->db->_protect_identifiers($key); - } - else - { - $key = array($this->db->_protect_identifiers($key)); - } - - $sql .= ",\n\tUNIQUE (" . implode(', ', $key) . ")"; - } - } - - $sql .= "\n)"; - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Drop Table - * - * Unsupported feature in SQLite - * - * @access private - * @return bool - */ - function _drop_table($table) - { - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return array(); - } - - // -------------------------------------------------------------------- - - /** - * Alter table query - * - * Generates a platform-specific query so that a table can be altered - * Called by add_column(), drop_column(), and column_alter(), - * - * @access private - * @param string the ALTER type (ADD, DROP, CHANGE) - * @param string the column name - * @param string the table name - * @param string the column definition - * @param string the default value - * @param boolean should 'NOT NULL' be added - * @param string the field after which we should add the new field - * @return object - */ - function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') - { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name); - - // DROP has everything it needs now. - if ($alter_type == 'DROP') - { - // SQLite does not support dropping columns - // http://www.sqlite.org/omitted.html - // http://www.sqlite.org/faq.html#q11 - return FALSE; - } - - $sql .= " $column_definition"; - - if ($default_value != '') - { - $sql .= " DEFAULT \"$default_value\""; - } - - if ($null === NULL) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } - - if ($after_field != '') - { - $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); - } - - return $sql; - - } - - // -------------------------------------------------------------------- - - /** - * Rename a table - * - * Generates a platform-specific query so that a table can be renamed - * - * @access private - * @param string the old table name - * @param string the new table name - * @return string - */ - function _rename_table($table_name, $new_table_name) - { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); - return $sql; - } -} - -/* End of file sqlite_forge.php */ +db->database) OR ! @unlink($this->db->database)) + { + if ($this->db->db_debug) + { + return $this->db->display_error('db_unable_to_drop'); + } + return FALSE; + } + return TRUE; + } + // -------------------------------------------------------------------- + + /** + * Create Table + * + * @access private + * @param string the table name + * @param array the fields + * @param mixed primary key(s) + * @param mixed key(s) + * @param boolean should 'IF NOT EXISTS' be added to the SQL + * @return bool + */ + function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) + { + $sql = 'CREATE TABLE '; + + // IF NOT EXISTS added to SQLite in 3.3.0 + if ($if_not_exists === TRUE && version_compare($this->_version(), '3.3.0', '>=') === TRUE) + { + $sql .= 'IF NOT EXISTS '; + } + + $sql .= $this->db->_escape_identifiers($table)."("; + $current_field_count = 0; + + foreach ($fields as $field=>$attributes) + { + // Numeric field names aren't allowed in databases, so if the key is + // numeric, we know it was assigned by PHP and the developer manually + // entered the field information, so we'll simply add it to the list + if (is_numeric($field)) + { + $sql .= "\n\t$attributes"; + } + else + { + $attributes = array_change_key_case($attributes, CASE_UPPER); + + $sql .= "\n\t".$this->db->_protect_identifiers($field); + + $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) && $attributes['NULL'] === TRUE) + { + $sql .= ' NULL'; + } + else + { + $sql .= ' 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 .= ','; + } + } + + if (count($primary_keys) > 0) + { + $primary_keys = $this->db->_protect_identifiers($primary_keys); + $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; + } + + if (is_array($keys) && count($keys) > 0) + { + foreach ($keys as $key) + { + if (is_array($key)) + { + $key = $this->db->_protect_identifiers($key); + } + else + { + $key = array($this->db->_protect_identifiers($key)); + } + + $sql .= ",\n\tUNIQUE (" . implode(', ', $key) . ")"; + } + } + + $sql .= "\n)"; + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * Unsupported feature in SQLite + * + * @access private + * @return bool + */ + function _drop_table($table) + { + if ($this->db->db_debug) + { + return $this->db->display_error('db_unsuported_feature'); + } + return array(); + } + + // -------------------------------------------------------------------- + + /** + * Alter table query + * + * Generates a platform-specific query so that a table can be altered + * Called by add_column(), drop_column(), and column_alter(), + * + * @access private + * @param string the ALTER type (ADD, DROP, CHANGE) + * @param string the column name + * @param string the table name + * @param string the column definition + * @param string the default value + * @param boolean should 'NOT NULL' be added + * @param string the field after which we should add the new field + * @return object + */ + function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') + { + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name); + + // DROP has everything it needs now. + if ($alter_type == 'DROP') + { + // SQLite does not support dropping columns + // http://www.sqlite.org/omitted.html + // http://www.sqlite.org/faq.html#q11 + return FALSE; + } + + $sql .= " $column_definition"; + + if ($default_value != '') + { + $sql .= " DEFAULT \"$default_value\""; + } + + if ($null === NULL) + { + $sql .= ' NULL'; + } + else + { + $sql .= ' NOT NULL'; + } + + if ($after_field != '') + { + $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); + } + + return $sql; + + } + + // -------------------------------------------------------------------- + + /** + * Rename a table + * + * Generates a platform-specific query so that a table can be renamed + * + * @access private + * @param string the old table name + * @param string the new table name + * @return string + */ + function _rename_table($table_name, $new_table_name) + { + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); + return $sql; + } +} + +/* End of file sqlite_forge.php */ /* Location: ./system/database/drivers/sqlite/sqlite_forge.php */ \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index 735a0736a..bed16982c 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -1,179 +1,179 @@ -result_id); - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - return @sqlite_num_fields($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Fetch Field Names - * - * Generates an array of column names - * - * @access public - * @return array - */ - function list_fields() - { - $field_names = array(); - for ($i = 0; $i < $this->num_fields(); $i++) - { - $field_names[] = sqlite_field_name($this->result_id, $i); - } - - return $field_names; - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - function field_data() - { - $retval = array(); - for ($i = 0; $i < $this->num_fields(); $i++) - { - $F = new stdClass(); - $F->name = sqlite_field_name($this->result_id, $i); - $F->type = 'varchar'; - $F->max_length = 0; - $F->primary_key = 0; - $F->default = ''; - - $retval[] = $F; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Free the result - * - * @return null - */ - function free_result() - { - // Not implemented in SQLite - } - - // -------------------------------------------------------------------- - - /** - * Data Seek - * - * Moves the internal pointer to the desired offset. We call - * this internally before fetching results to make sure the - * result set starts at zero - * - * @access private - * @return array - */ - function _data_seek($n = 0) - { - return sqlite_seek($this->result_id, $n); - } - - // -------------------------------------------------------------------- - - /** - * Result - associative array - * - * Returns the result set as an array - * - * @access private - * @return array - */ - function _fetch_assoc() - { - return sqlite_fetch_array($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Result - object - * - * Returns the result set as an object - * - * @access private - * @return object - */ - function _fetch_object() - { - if (function_exists('sqlite_fetch_object')) - { - return sqlite_fetch_object($this->result_id); - } - else - { - $arr = sqlite_fetch_array($this->result_id, SQLITE_ASSOC); - if (is_array($arr)) - { - $obj = (object) $arr; - return $obj; - } else { - return NULL; - } - } - } - -} - - -/* End of file sqlite_result.php */ +result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @sqlite_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function list_fields() + { + $field_names = array(); + for ($i = 0; $i < $this->num_fields(); $i++) + { + $field_names[] = sqlite_field_name($this->result_id, $i); + } + + return $field_names; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + for ($i = 0; $i < $this->num_fields(); $i++) + { + $F = new stdClass(); + $F->name = sqlite_field_name($this->result_id, $i); + $F->type = 'varchar'; + $F->max_length = 0; + $F->primary_key = 0; + $F->default = ''; + + $retval[] = $F; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return null + */ + function free_result() + { + // Not implemented in SQLite + } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero + * + * @access private + * @return array + */ + function _data_seek($n = 0) + { + return sqlite_seek($this->result_id, $n); + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @access private + * @return array + */ + function _fetch_assoc() + { + return sqlite_fetch_array($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + function _fetch_object() + { + if (function_exists('sqlite_fetch_object')) + { + return sqlite_fetch_object($this->result_id); + } + else + { + $arr = sqlite_fetch_array($this->result_id, SQLITE_ASSOC); + if (is_array($arr)) + { + $obj = (object) $arr; + return $obj; + } else { + return NULL; + } + } + } + +} + + +/* End of file sqlite_result.php */ /* Location: ./system/database/drivers/sqlite/sqlite_result.php */ \ No newline at end of file diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 3527b5b1b..c067403f7 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -1,141 +1,141 @@ -db_debug) - { - return $this->display_error('db_unsuported_feature'); - } - return array(); - } - - // -------------------------------------------------------------------- - - /** - * Optimize table query - * - * Is optimization even supported in SQLite? - * - * @access private - * @param string the table name - * @return object - */ - function _optimize_table($table) - { - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Repair table query - * - * Are table repairs even supported in SQLite? - * - * @access private - * @param string the table name - * @return object - */ - function _repair_table($table) - { - 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'); - } - - /** - * - * The functions below have been deprecated as of 1.6, and are only here for backwards - * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation - * is STRONGLY discouraged in favour if using dbforge. - * - */ - - /** - * Create database - * - * @access public - * @param string the database name - * @return bool - */ - function _create_database() - { - // In SQLite, a database is created when you connect to the database. - // We'll return TRUE so that an error isn't generated - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access private - * @param string the database name - * @return bool - */ - function _drop_database($name) - { - if ( ! @file_exists($this->db->database) OR ! @unlink($this->db->database)) - { - if ($this->db->db_debug) - { - return $this->db->display_error('db_unable_to_drop'); - } - return FALSE; - } - return TRUE; - } - -} - -/* End of file sqlite_utility.php */ +db_debug) + { + return $this->display_error('db_unsuported_feature'); + } + return array(); + } + + // -------------------------------------------------------------------- + + /** + * Optimize table query + * + * Is optimization even supported in SQLite? + * + * @access private + * @param string the table name + * @return object + */ + function _optimize_table($table) + { + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Repair table query + * + * Are table repairs even supported in SQLite? + * + * @access private + * @param string the table name + * @return object + */ + function _repair_table($table) + { + 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'); + } + + /** + * + * The functions below have been deprecated as of 1.6, and are only here for backwards + * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation + * is STRONGLY discouraged in favour if using dbforge. + * + */ + + /** + * Create database + * + * @access public + * @param string the database name + * @return bool + */ + function _create_database() + { + // In SQLite, a database is created when you connect to the database. + // We'll return TRUE so that an error isn't generated + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access private + * @param string the database name + * @return bool + */ + function _drop_database($name) + { + if ( ! @file_exists($this->db->database) OR ! @unlink($this->db->database)) + { + if ($this->db->db_debug) + { + return $this->db->display_error('db_unable_to_drop'); + } + return FALSE; + } + return TRUE; + } + +} + +/* End of file sqlite_utility.php */ /* Location: ./system/database/drivers/sqlite/sqlite_utility.php */ \ No newline at end of file diff --git a/system/database/index.html b/system/database/index.html index 065d2da5e..c942a79ce 100644 --- a/system/database/index.html +++ b/system/database/index.html @@ -1,10 +1,10 @@ - - - 403 Forbidden - - - -

Directory access is forbidden.

- - + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From ef22efd7c7b0a9006d43ef207450768722815453 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 20 Nov 2008 15:25:45 +0000 Subject: Added where_in to the list of expected arguments received by delete() --- system/database/DB_active_rec.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index e8cefa2db..b8dce6df5 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1374,7 +1374,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->limit($limit); } - if (count($this->ar_where) == 0 && count($this->ar_like) == 0) + if (count($this->ar_where) == 0 && count($this->ar_wherein) == 0 && count($this->ar_like)) { if ($this->db_debug) { -- cgit v1.2.3-24-g4f1b From 911d3e0fdd26ebdcb7c862a2a39ddcaef935d6f7 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 15 Dec 2008 14:08:35 +0000 Subject: Fixed a bug in database escaping where a compound statement (ie: SUM()) wasn't handled correctly with database prefixes. --- system/database/DB_driver.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 4293acc91..fde0a435f 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1204,11 +1204,20 @@ class CI_DB_driver { // Basically we remove everything to the right of the first space $alias = ''; if (strpos($item, ' ') !== FALSE) - { + { $alias = strstr($item, " "); $item = substr($item, 0, - strlen($alias)); } + // This is basically a bug fix for queries that use MAX, MIN, etc. + // If a parenthesis is found we know that we do not need to + // escape the data or add a prefix. There's probably a more graceful + // way to deal with this, but I'm not thinking of it -- Rick + if (strpos($item, '(') !== FALSE) + { + return $item.$alias; + } + // Break the string apart if it contains periods, then insert the table prefix // in the correct location, assuming the period doesn't indicate that we're dealing // with an alias. While we're at it, we will escape the components @@ -1220,7 +1229,7 @@ class CI_DB_driver { // one of the aliases previously identified? If so, // we have nothing more to do other than escape the item if (in_array($parts[0], $this->ar_aliased_tables)) - { + { if ($protect_identifiers === TRUE) { foreach ($parts as $key => $val) @@ -1284,15 +1293,6 @@ class CI_DB_driver { return $item.$alias; } - // This is basically a bug fix for queries that use MAX, MIN, etc. - // If a parenthesis is found we know that we do not need to - // escape the data or add a prefix. There's probably a more graceful - // way to deal with this, but I'm not thinking of it -- Rick - if (strpos($item, '(') !== FALSE) - { - return $item.$alias; - } - // Is there a table prefix? If not, no need to insert it if ($this->dbprefix != '') { -- cgit v1.2.3-24-g4f1b From e37ab385f5c9ef8824d2ad4e31f544dbe6089095 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 3 Feb 2009 16:13:57 +0000 Subject: DB count_all() not returns an integer always Added some syntactical improvements within DB (braces) Fixed a bug when doing 'random' on order_by() (#5706). Fixed a bug where adding a primary key through Forge could fail (#5731). Fixed a bug when using DB cache on multiple databases (#5737). --- system/database/DB_active_rec.php | 2 +- system/database/DB_driver.php | 27 +++++++++++++++++----- system/database/drivers/mssql/mssql_driver.php | 14 +++++++---- system/database/drivers/mysql/mysql_driver.php | 14 +++++++---- system/database/drivers/mysqli/mysqli_driver.php | 16 ++++++++----- system/database/drivers/oci8/oci8_driver.php | 12 ++++++---- system/database/drivers/odbc/odbc_driver.php | 16 ++++++++----- system/database/drivers/postgre/postgre_driver.php | 14 +++++++---- system/database/drivers/sqlite/sqlite_driver.php | 14 +++++++---- 9 files changed, 85 insertions(+), 44 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index b8dce6df5..c757e6ae6 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -913,7 +913,7 @@ class CI_DB_active_record extends CI_DB_driver { $orderby = implode(', ', $temp); } - else + else if ($direction != $this->_random_keyword) { $orderby = $this->_protect_identifiers($orderby); } diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index fde0a435f..dac4c8bdf 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -613,7 +613,7 @@ class CI_DB_driver { */ function is_write_type($sql) { - if ( ! preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql)) + if ( ! preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql)) { return FALSE; } @@ -1086,12 +1086,15 @@ class CI_DB_driver { { return TRUE; } - - if ( ! @include(BASEPATH.'database/DB_cache'.EXT)) + + if ( ! class_exists('CI_DB_Cache')) { - return $this->cache_off(); + if ( ! @include(BASEPATH.'database/DB_cache'.EXT)) + { + return $this->cache_off(); + } } - + $this->CACHE = new CI_DB_Cache($this); // pass db object to support multiple db connections and returned db objects return TRUE; } @@ -1196,7 +1199,19 @@ class CI_DB_driver { { $protect_identifiers = $this->_protect_identifiers; } - + + if (is_array($item)) + { + $escaped_array = array(); + + foreach($item as $k => $v) + { + $escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v); + } + + return $escaped_array; + } + // Convert tabs or multiple spaces into single spaces $item = preg_replace('/[\t| ]+/', ' ', $item); diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 78f81daf7..addbd6b92 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -314,15 +314,19 @@ class CI_DB_mssql_driver extends CI_DB { function count_all($table = '') { if ($table == '') - return '0'; - - $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); + { + 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) - return '0'; + { + return 0; + } $row = $query->row(); - return $row->numrows; + return (int) $row->numrows; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 943b3c037..a0cdb58af 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -325,15 +325,19 @@ class CI_DB_mysql_driver extends CI_DB { function count_all($table = '') { if ($table == '') - return '0'; + { + return 0; + } - $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); - + $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); + if ($query->num_rows() == 0) - return '0'; + { + return 0; + } $row = $query->row(); - return (int)$row->numrows; + return (int) $row->numrows; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index ce458f292..9ef18e025 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -316,15 +316,19 @@ class CI_DB_mysqli_driver extends CI_DB { function count_all($table = '') { if ($table == '') - return '0'; - - $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); - + { + 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) - return '0'; + { + return 0; + } $row = $query->row(); - return $row->numrows; + return (int) $row->numrows; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 0629a5940..b949a962d 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -420,17 +420,19 @@ class CI_DB_oci8_driver extends CI_DB { function count_all($table = '') { if ($table == '') - return '0'; + { + return 0; + } - $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); + $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); if ($query == FALSE) - { + { return 0; - } + } $row = $query->row(); - return $row->NUMROWS; + return (int) $row->numrows; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 8fcbcfe0d..0f8b42007 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -289,15 +289,19 @@ class CI_DB_odbc_driver extends CI_DB { function count_all($table = '') { if ($table == '') - return '0'; - - $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); - + { + 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) - return '0'; + { + return 0; + } $row = $query->row(); - return $row->numrows; + return (int) $row->numrows; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index da0b0f23a..9d53b1ef8 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -329,15 +329,19 @@ class CI_DB_postgre_driver extends CI_DB { function count_all($table = '') { if ($table == '') - return '0'; + { + return 0; + } + + $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); - $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); - if ($query->num_rows() == 0) - return '0'; + { + return 0; + } $row = $query->row(); - return $row->numrows; + return (int) $row->numrows; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 058cef77a..3ef88dbba 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -301,15 +301,19 @@ class CI_DB_sqlite_driver extends CI_DB { function count_all($table = '') { if ($table == '') - return '0'; - - $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); + { + 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) - return '0'; + { + return 0; + } $row = $query->row(); - return $row->numrows; + return (int) $row->numrows; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 4787413c06ec11bff1ba4b1c7a4fe667038595d0 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 10 Feb 2009 17:32:15 +0000 Subject: fixed check for a method named 'field_names' which doesn't exist to 'list_fields' which is the correct method. http://codeigniter.com/bug_tracker/bug/5787/ --- system/database/DB_utility.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 195e4c46a..6619e80e7 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -175,7 +175,7 @@ class CI_DB_utility extends CI_DB_forge { */ function csv_from_result($query, $delim = ",", $newline = "\n", $enclosure = '"') { - if ( ! is_object($query) OR ! method_exists($query, 'field_names')) + if ( ! is_object($query) OR ! method_exists($query, 'list_fields')) { show_error('You must submit a valid result object'); } -- cgit v1.2.3-24-g4f1b From 7b3b96cff8d0b1b36caaaef5cd58fcfea5e3537e Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 10 Feb 2009 21:01:47 +0000 Subject: fixed a bug in the regex pattern to converts tabs and spaces into a single space http://codeigniter.com/bug_tracker/bug/6662/ --- system/database/DB_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index dac4c8bdf..42b6a7577 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1213,7 +1213,7 @@ class CI_DB_driver { } // Convert tabs or multiple spaces into single spaces - $item = preg_replace('/[\t| ]+/', ' ', $item); + $item = preg_replace('/[\t ]+/', ' ', $item); // If the item has an alias declaration we remove it and set it aside. // Basically we remove everything to the right of the first space -- cgit v1.2.3-24-g4f1b From a377bdd47e57ddde51e90641d961f00af4a71fa1 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 11 Feb 2009 18:55:24 +0000 Subject: switched from gettype() to is_* for testing type in escape() --- system/database/DB_driver.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 42b6a7577..9385870e9 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -673,16 +673,19 @@ class CI_DB_driver { * @return integer */ function escape($str) - { - switch (gettype($str)) + { + if (is_string($str)) { - case 'string' : $str = "'".$this->escape_str($str)."'"; - break; - case 'boolean' : $str = ($str === FALSE) ? 0 : 1; - break; - default : $str = ($str === NULL) ? 'NULL' : $str; - break; - } + $str = "'".$this->escape_str($str)."'"; + } + elseif (is_bool($str)) + { + $str = ($str === FALSE) ? 0 : 1; + } + elseif (is_null($str)) + { + $str = 'NULL'; + } return $str; } -- cgit v1.2.3-24-g4f1b From 436e6e2583c574a4628984c4a95c5d3da5fcce1f Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 20 Feb 2009 20:10:00 +0000 Subject: $CI->_remove_invisible_characters($str); fixed to $CI->input->_remove_invisible_characters($str); --- system/database/drivers/oci8/oci8_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index b949a962d..42dd51769 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -375,7 +375,7 @@ class CI_DB_oci8_driver extends CI_DB { // Access the CI object $CI =& get_instance(); - return $CI->_remove_invisible_characters($str); + return $CI->input->_remove_invisible_characters($str); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From e4ed583067095144eb20aefc61d4499d8386532a Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 20 Feb 2009 21:44:59 +0000 Subject: added LIKE condition escaping to all drivers and Active Record updated all DB drivers to accept arrays in escape_str() --- system/database/DB_active_rec.php | 8 +++++- system/database/DB_driver.php | 19 ++++++++++++- system/database/drivers/mssql/mssql_driver.php | 30 ++++++++++++++++++-- system/database/drivers/mysql/mysql_driver.php | 25 ++++++++++++---- system/database/drivers/mysqli/mysqli_driver.php | 31 +++++++++++++++++--- system/database/drivers/oci8/oci8_driver.php | 31 ++++++++++++++++++-- system/database/drivers/odbc/odbc_driver.php | 33 +++++++++++++++++++--- system/database/drivers/postgre/postgre_driver.php | 31 ++++++++++++++++++-- system/database/drivers/sqlite/sqlite_driver.php | 29 +++++++++++++++++-- 9 files changed, 211 insertions(+), 26 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index c757e6ae6..d48f43e51 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -707,7 +707,7 @@ class CI_DB_active_record extends CI_DB_driver { $prefix = (count($this->ar_like) == 0) ? '' : $type; - $v = $this->escape_str($v); + $v = $this->escape_like_str($v); if ($side == 'before') { @@ -722,6 +722,12 @@ class CI_DB_active_record extends CI_DB_driver { $like_statement = $prefix." $k $not LIKE '%{$v}%'"; } + // some platforms require an escape sequence definition for LIKE wildcards + if ($this->_like_escape_str != '') + { + $like_statement = $like_statement.sprintf($this->_like_escape_str, $this->_like_escape_char); + } + $this->ar_like[] = $like_statement; if ($this->ar_caching === TRUE) { diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 9385870e9..729af5bf6 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -670,7 +670,7 @@ class CI_DB_driver { * * @access public * @param string - * @return integer + * @return mixed */ function escape($str) { @@ -691,7 +691,24 @@ class CI_DB_driver { } // -------------------------------------------------------------------- + + /** + * Smart Escape LIKE String + * + * Calls the individual driver for platform + * specific escaping for LIKE conditions + * + * @access public + * @param string + * @return mixed + */ + function escape_like_str($str) + { + return $this->escape_str($str, TRUE); + } + // -------------------------------------------------------------------- + /** * Primary * diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index addbd6b92..c89e2549e 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -34,6 +34,11 @@ class CI_DB_mssql_driver extends CI_DB { // The character used for escaping var $_escape_char = ''; + + // clause and character used for LIKE escape sequences + var $_like_escape_str = " ESCAPE '%s' "; + var $_like_escape_chr = '!'; + /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is @@ -225,15 +230,36 @@ class CI_DB_mssql_driver extends CI_DB { * * @access public * @param string + * @param bool whether or not the string will be used in a LIKE condition * @return string */ - function escape_str($str) + function escape_str($str, $like = FALSE) { + if (is_array($str)) + { + foreach($str as $key => $val) + { + $str[$key] = $this->escape_str($val, $like); + } + + return $str; + } + // Access the CI object $CI =& get_instance(); // Escape single quotes - return str_replace("'", "''", $CI->input->_remove_invisible_characters($str)); + $str = str_replace("'", "''", $CI->input->_remove_invisible_characters($str)); + + // escape LIKE condition wildcards + if ($like === TRUE) + { + $str = str_replace( array('%', '_', $this->_like_escape_chr), + array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr), + $str); + } + + return $str; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index a0cdb58af..5b2ba62b8 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -34,7 +34,11 @@ class CI_DB_mysql_driver extends CI_DB { // The character used for escaping var $_escape_char = '`'; - + + // clause and character used for LIKE escape sequences - not used in MySQL + var $_like_escape_str = ''; + var $_like_escape_chr = ''; + /** * Whether to use the MySQL "delete hack" which allows the number * of affected rows to be shown. Uses a preg_replace when enabled, @@ -256,15 +260,16 @@ class CI_DB_mysql_driver extends CI_DB { * * @access public * @param string + * @param bool whether or not the string will be used in a LIKE condition * @return string */ - function escape_str($str) + function escape_str($str, $like = FALSE) { if (is_array($str)) { foreach($str as $key => $val) { - $str[$key] = $this->escape_str($val); + $str[$key] = $this->escape_str($val, $like); } return $str; @@ -272,16 +277,24 @@ class CI_DB_mysql_driver extends CI_DB { if (function_exists('mysql_real_escape_string') AND is_resource($this->conn_id)) { - return mysql_real_escape_string($str, $this->conn_id); + $str = mysql_real_escape_string($str, $this->conn_id); } elseif (function_exists('mysql_escape_string')) { - return mysql_escape_string($str); + $str = mysql_escape_string($str); } else { - return addslashes($str); + $str = addslashes($str); } + + // escape LIKE condition wildcards + if ($like === TRUE) + { + $str = str_replace(array('%', '_'), array('\\%', '\\_'), $str); + } + + return $str; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 9ef18e025..92d871111 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -35,6 +35,10 @@ class CI_DB_mysqli_driver extends CI_DB { // The character used for escaping var $_escape_char = '`'; + // clause and character used for LIKE escape sequences - not used in MySQL + var $_like_escape_str = ''; + var $_like_escape_chr = ''; + /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is @@ -257,22 +261,41 @@ class CI_DB_mysqli_driver extends CI_DB { * * @access public * @param string + * @param bool whether or not the string will be used in a LIKE condition * @return string */ - function escape_str($str) + function escape_str($str, $like = FALSE) { + if (is_array($str)) + { + foreach($str as $key => $val) + { + $str[$key] = $this->escape_str($val, $like); + } + + return $str; + } + if (function_exists('mysqli_real_escape_string') AND is_object($this->conn_id)) { - return mysqli_real_escape_string($this->conn_id, $str); + $str = mysqli_real_escape_string($this->conn_id, $str); } elseif (function_exists('mysql_escape_string')) { - return mysql_escape_string($str); + $str = mysql_escape_string($str); } else { - return addslashes($str); + $str = addslashes($str); } + + // escape LIKE condition wildcards + if ($like === TRUE) + { + $str = str_replace(array('%', '_'), array('\\%', '\\_'), $str); + } + + return $str; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 42dd51769..1fdb1bc45 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -47,7 +47,11 @@ class CI_DB_oci8_driver extends CI_DB { // The character used for excaping var $_escape_char = '"'; - + + // clause and character used for LIKE escape sequences + var $_like_escape_str = " escape '%s' "; + var $_like_escape_chr = '!'; + /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is @@ -368,14 +372,35 @@ class CI_DB_oci8_driver extends CI_DB { * * @access public * @param string + * @param bool whether or not the string will be used in a LIKE condition * @return string */ - function escape_str($str) + function escape_str($str, $like = FALSE) { + if (is_array($str)) + { + foreach($str as $key => $val) + { + $str[$key] = $this->escape_str($val, $like); + } + + return $str; + } + // Access the CI object $CI =& get_instance(); - return $CI->input->_remove_invisible_characters($str); + $str = $CI->input->_remove_invisible_characters($str); + + // escape LIKE condition wildcards + if ($like === TRUE) + { + $str = str_replace( array('%', '_', $this->_like_escape_chr), + array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr), + $str); + } + + return $str; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 0f8b42007..a14aaa1f3 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -34,7 +34,11 @@ class CI_DB_odbc_driver extends CI_DB { // the character used to excape - not necessary for ODBC var $_escape_char = ''; - + + // clause and character used for LIKE escape sequences + var $_like_escape_str = " {escape '%s'} "; + var $_like_escape_chr = '!'; + /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is @@ -237,15 +241,36 @@ class CI_DB_odbc_driver extends CI_DB { * * @access public * @param string + * @param bool whether or not the string will be used in a LIKE condition * @return string */ - function escape_str($str) + function escape_str($str, $like = FALSE) { + if (is_array($str)) + { + foreach($str as $key => $val) + { + $str[$key] = $this->escape_str($val, $like); + } + + return $str; + } + // Access the CI object $CI =& get_instance(); - + // ODBC doesn't require escaping - return $CI->_remove_invisible_characters($str); + $str = $CI->input->_remove_invisible_characters($str); + + // escape LIKE condition wildcards + if ($like === TRUE) + { + $str = str_replace( array('%', '_', $this->_like_escape_chr), + array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr), + $str); + } + + return $str; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 9d53b1ef8..8d0d8901c 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -34,6 +34,10 @@ class CI_DB_postgre_driver extends CI_DB { var $_escape_char = '"'; + // clause and character used for LIKE escape sequences + var $_like_escape_str = " ESCAPE '%s' "; + var $_like_escape_chr = '!'; + /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is @@ -253,11 +257,32 @@ class CI_DB_postgre_driver extends CI_DB { * * @access public * @param string + * @param bool whether or not the string will be used in a LIKE condition * @return string */ - function escape_str($str) - { - return pg_escape_string($str); + function escape_str($str, $like = FALSE) + { + if (is_array($str)) + { + foreach($str as $key => $val) + { + $str[$key] = $this->escape_str($val, $like); + } + + return $str; + } + + $str = pg_escape_string($str); + + // escape LIKE condition wildcards + if ($like === TRUE) + { + $str = str_replace( array('%', '_', $this->_like_escape_chr), + array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr), + $str); + } + + return $str; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 3ef88dbba..104a3bc36 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -37,6 +37,10 @@ class CI_DB_sqlite_driver extends CI_DB { // The character used to escape with - not needed for SQLite var $_escape_char = ''; + // clause and character used for LIKE escape sequences + var $_like_escape_str = " ESCAPE '%s' "; + var $_like_escape_chr = '!'; + /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is @@ -253,11 +257,32 @@ class CI_DB_sqlite_driver extends CI_DB { * * @access public * @param string + * @param bool whether or not the string will be used in a LIKE condition * @return string */ - function escape_str($str) + function escape_str($str, $like = FALSE) { - return sqlite_escape_string($str); + if (is_array($str)) + { + foreach($str as $key => $val) + { + $str[$key] = $this->escape_str($val, $like); + } + + return $str; + } + + $str = sqlite_escape_string($str); + + // escape LIKE condition wildcards + if ($like === TRUE) + { + $str = str_replace( array('%', '_', $this->_like_escape_chr), + array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr), + $str); + } + + return $str; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From bdc7fb907f04469f526868058103e35460f4e52d Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 20 Feb 2009 21:55:10 +0000 Subject: fixed docblock --- system/database/DB_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 729af5bf6..161569d3c 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -693,7 +693,7 @@ class CI_DB_driver { // -------------------------------------------------------------------- /** - * Smart Escape LIKE String + * Escape LIKE String * * Calls the individual driver for platform * specific escaping for LIKE conditions -- cgit v1.2.3-24-g4f1b From 3c11b6f5dee83ebe11dfdcec3022313c45a4a4e2 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 20 Feb 2009 22:36:27 +0000 Subject: updated _list_tables() in db drivers to escape the db prefix for LIKE wildcards --- system/database/drivers/mssql/mssql_driver.php | 2 +- system/database/drivers/mysql/mysql_driver.php | 2 +- system/database/drivers/mysqli/mysqli_driver.php | 2 +- system/database/drivers/oci8/oci8_driver.php | 2 +- system/database/drivers/odbc/odbc_driver.php | 2 +- system/database/drivers/postgre/postgre_driver.php | 2 +- system/database/drivers/sqlite/sqlite_driver.php | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index c89e2549e..ddc036da9 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -373,7 +373,7 @@ class CI_DB_mssql_driver extends CI_DB { // for future compatibility if ($prefix_limit !== FALSE AND $this->dbprefix != '') { - //$sql .= " LIKE '".$this->dbprefix."%'"; + //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_char); return FALSE; // not currently supported } diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 5b2ba62b8..2b05c3f15 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -370,7 +370,7 @@ class CI_DB_mysql_driver extends CI_DB { if ($prefix_limit !== FALSE AND $this->dbprefix != '') { - $sql .= " LIKE '".$this->dbprefix."%'"; + $sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%'"; } return $sql; diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 92d871111..6558112cd 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -371,7 +371,7 @@ class CI_DB_mysqli_driver extends CI_DB { if ($prefix_limit !== FALSE AND $this->dbprefix != '') { - $sql .= " LIKE '".$this->dbprefix."%'"; + $sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%'"; } return $sql; diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 1fdb1bc45..4dfec2e3f 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -477,7 +477,7 @@ class CI_DB_oci8_driver extends CI_DB { if ($prefix_limit !== FALSE AND $this->dbprefix != '') { - $sql .= " WHERE TABLE_NAME LIKE '".$this->dbprefix."%'"; + $sql .= " WHERE TABLE_NAME LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_char); } return $sql; diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index a14aaa1f3..f7db4ca4b 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -346,7 +346,7 @@ class CI_DB_odbc_driver extends CI_DB { if ($prefix_limit !== FALSE AND $this->dbprefix != '') { - //$sql .= " LIKE '".$this->dbprefix."%'"; + //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_char); return FALSE; // not currently supported } diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 8d0d8901c..4bc5b7d94 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -386,7 +386,7 @@ class CI_DB_postgre_driver extends CI_DB { if ($prefix_limit !== FALSE AND $this->dbprefix != '') { - $sql .= " AND table_name LIKE '".$this->dbprefix."%'"; + $sql .= " AND table_name LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_char); } return $sql; diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 104a3bc36..bb1e6d02e 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -358,7 +358,7 @@ class CI_DB_sqlite_driver extends CI_DB { if ($prefix_limit !== FALSE AND $this->dbprefix != '') { - $sql .= " AND 'name' LIKE '".$this->dbprefix."%'"; + $sql .= " AND 'name' LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_char); } return $sql; } -- cgit v1.2.3-24-g4f1b From 87cbafce2d6803af78714baf8bba64309c01fc33 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 27 Feb 2009 16:29:59 +0000 Subject: added reconnect() method to db drivers --- system/database/drivers/mssql/mssql_driver.php | 16 ++++++++++++++++ system/database/drivers/mysql/mysql_driver.php | 19 +++++++++++++++++++ system/database/drivers/mysqli/mysqli_driver.php | 19 +++++++++++++++++++ system/database/drivers/oci8/oci8_driver.php | 16 ++++++++++++++++ system/database/drivers/odbc/odbc_driver.php | 16 ++++++++++++++++ system/database/drivers/postgre/postgre_driver.php | 19 +++++++++++++++++++ system/database/drivers/sqlite/sqlite_driver.php | 16 ++++++++++++++++ 7 files changed, 121 insertions(+) (limited to 'system/database') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index ddc036da9..241b280d0 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -82,7 +82,23 @@ class CI_DB_mssql_driver extends CI_DB { } // -------------------------------------------------------------------- + + /** + * Reconnect + * + * Keep / reestablish the db connection if no queries have been + * sent for a length of time exceeding the server's idle timeout + * + * @access public + * @return void + */ + function reconnect() + { + // not implemented in MSSQL + } + // -------------------------------------------------------------------- + /** * Select the database * diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 2b05c3f15..334daf3a6 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -90,6 +90,25 @@ class CI_DB_mysql_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Reconnect + * + * Keep / reestablish the db connection if no queries have been + * sent for a length of time exceeding the server's idle timeout + * + * @access public + * @return void + */ + function reconnect() + { + if (mysql_ping($this->conn_id) === FALSE) + { + $this->conn_id = FALSE; + } + } + + // -------------------------------------------------------------------- + /** * Select the database * diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 6558112cd..74cfff44a 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -90,6 +90,25 @@ class CI_DB_mysqli_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Reconnect + * + * Keep / reestablish the db connection if no queries have been + * sent for a length of time exceeding the server's idle timeout + * + * @access public + * @return void + */ + function reconnect() + { + if (mysqli_ping($this->conn_id) === FALSE) + { + $this->conn_id = FALSE; + } + } + + // -------------------------------------------------------------------- + /** * Select the database * diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 4dfec2e3f..f4ef42a18 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -97,6 +97,22 @@ class CI_DB_oci8_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Reconnect + * + * Keep / reestablish the db connection if no queries have been + * sent for a length of time exceeding the server's idle timeout + * + * @access public + * @return void + */ + function reconnect() + { + // not implemented in oracle + } + + // -------------------------------------------------------------------- + /** * Select the database * diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index f7db4ca4b..2e529f32d 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -81,6 +81,22 @@ class CI_DB_odbc_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Reconnect + * + * Keep / reestablish the db connection if no queries have been + * sent for a length of time exceeding the server's idle timeout + * + * @access public + * @return void + */ + function reconnect() + { + // not implemented in odbc + } + + // -------------------------------------------------------------------- + /** * Select the database * diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 4bc5b7d94..db3a3f29d 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -101,6 +101,25 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Reconnect + * + * Keep / reestablish the db connection if no queries have been + * sent for a length of time exceeding the server's idle timeout + * + * @access public + * @return void + */ + function reconnect() + { + if (pg_ping($this->conn_id) === FALSE) + { + $this->conn_id = FALSE; + } + } + + // -------------------------------------------------------------------- + /** * Select the database * diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index bb1e6d02e..cd7b26bc4 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -99,6 +99,22 @@ class CI_DB_sqlite_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Reconnect + * + * Keep / reestablish the db connection if no queries have been + * sent for a length of time exceeding the server's idle timeout + * + * @access public + * @return void + */ + function reconnect() + { + // not implemented in SQLite + } + + // -------------------------------------------------------------------- + /** * Select the database * -- cgit v1.2.3-24-g4f1b From 8a54ef21839dd970c85491cddff836b391d48882 Mon Sep 17 00:00:00 2001 From: Robin Sowell Date: Wed, 4 Mar 2009 14:49:53 +0000 Subject: Altered modify_column and add_column to loop through multiple fields rather than returning after first field. --- system/database/DB_forge.php | 56 ++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 18 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index f708910f8..c4597bd1b 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -257,18 +257,28 @@ class CI_DB_forge { } // add field info into field array, but we can only do one at a time - // so only grab the first field in the event there are more then one - $this->add_field(array_slice($field, 0, 1)); + // so we cycle through - if (count($this->fields) == 0) - { - show_error('Field information is required.'); - } + foreach ($field as $k => $v) + { + $this->add_field(array($k => $field[$k])); - $sql = $this->_alter_table('ADD', $this->db->dbprefix.$table, $this->fields, $after_field); + if (count($this->fields) == 0) + { + show_error('Field information is required.'); + } + + $sql = $this->_alter_table('ADD', $this->db->dbprefix.$table, $this->fields, $after_field); - $this->_reset(); - return $this->db->query($sql); + $this->_reset(); + + if ($this->db->query($sql) === FALSE) + { + return FALSE; + } + } + + return TRUE; } // -------------------------------------------------------------------- @@ -318,18 +328,28 @@ class CI_DB_forge { } // add field info into field array, but we can only do one at a time - // so only grab the first field in the event there are more then one - $this->add_field(array_slice($field, 0, 1)); + // so we cycle through - if (count($this->fields) == 0) - { - show_error('Field information is required.'); - } + foreach ($field as $k => $v) + { + $this->add_field(array($k => $field[$k])); - $sql = $this->_alter_table('CHANGE', $this->db->dbprefix.$table, $this->fields); + if (count($this->fields) == 0) + { + show_error('Field information is required.'); + } + + $sql = $this->_alter_table('CHANGE', $this->db->dbprefix.$table, $this->fields); - $this->_reset(); - return $this->db->query($sql); + $this->_reset(); + + if ($this->db->query($sql) === FALSE) + { + return FALSE; + } + } + + return TRUE; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From fc395a1046441cb584cbcfe42651dacece7eca3e Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 22 Apr 2009 14:15:09 +0000 Subject: updated copyrights to 2009 --- system/database/DB.php | 2 +- system/database/DB_active_rec.php | 2 +- system/database/DB_cache.php | 2 +- system/database/DB_driver.php | 2 +- system/database/DB_forge.php | 2 +- system/database/DB_result.php | 2 +- system/database/DB_utility.php | 2 +- system/database/drivers/mssql/mssql_driver.php | 2 +- system/database/drivers/mssql/mssql_forge.php | 2 +- system/database/drivers/mssql/mssql_result.php | 2 +- system/database/drivers/mssql/mssql_utility.php | 2 +- system/database/drivers/mysql/mysql_driver.php | 2 +- system/database/drivers/mysql/mysql_forge.php | 2 +- system/database/drivers/mysql/mysql_result.php | 2 +- system/database/drivers/mysql/mysql_utility.php | 2 +- system/database/drivers/mysqli/mysqli_driver.php | 2 +- system/database/drivers/mysqli/mysqli_forge.php | 2 +- system/database/drivers/mysqli/mysqli_result.php | 2 +- system/database/drivers/mysqli/mysqli_utility.php | 2 +- system/database/drivers/oci8/oci8_driver.php | 2 +- system/database/drivers/oci8/oci8_forge.php | 2 +- system/database/drivers/oci8/oci8_result.php | 2 +- system/database/drivers/oci8/oci8_utility.php | 2 +- system/database/drivers/odbc/odbc_driver.php | 2 +- system/database/drivers/odbc/odbc_forge.php | 2 +- system/database/drivers/odbc/odbc_result.php | 2 +- system/database/drivers/odbc/odbc_utility.php | 2 +- system/database/drivers/postgre/postgre_driver.php | 2 +- system/database/drivers/postgre/postgre_forge.php | 2 +- system/database/drivers/postgre/postgre_result.php | 2 +- system/database/drivers/postgre/postgre_utility.php | 2 +- system/database/drivers/sqlite/sqlite_driver.php | 2 +- system/database/drivers/sqlite/sqlite_forge.php | 2 +- system/database/drivers/sqlite/sqlite_result.php | 2 +- system/database/drivers/sqlite/sqlite_utility.php | 2 +- 35 files changed, 35 insertions(+), 35 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index ca0cfc2e6..efe1d388a 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index d48f43e51..d07255855 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 70a2d95e3..8b0ad4fb4 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 161569d3c..54aa5ed7a 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index c4597bd1b..4050e300f 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 412814181..4614e29f6 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 6619e80e7..4ba69adbd 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 241b280d0..4748d5683 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php index 512fc47d5..632b4d907 100644 --- a/system/database/drivers/mssql/mssql_forge.php +++ b/system/database/drivers/mssql/mssql_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index e9679cb14..a56a3a9e2 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index 38118accc..9fa257a69 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 334daf3a6..fe1859805 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index d8cb77ea6..d343b36a0 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index 673aeac87..2e9550702 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 003b1dd66..2c8b264ce 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 74cfff44a..488b074a3 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index 99c2ebc3f..0992274e9 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index 5b1f79361..00fc0db47 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index c1d191d14..7ebda4c56 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index f4ef42a18..614571940 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index bbc11f332..c3e9cb98f 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 7d7cd1c3a..1d0b7db26 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index cf6e9e640..c8049c248 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 2e529f32d..dacbaaba9 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php index 5305afbe4..99cb282af 100644 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index 9a59cfc20..d6f15015e 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index 67aee6420..85707a073 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index db3a3f29d..9258da684 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index 72c2dd797..471dd80c9 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index 3206c1330..8e45eb1cf 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 06292f22a..235954fa6 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index cd7b26bc4..0cb799775 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php index 73630defb..0688ba368 100644 --- a/system/database/drivers/sqlite/sqlite_forge.php +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index bed16982c..c1c24c78e 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index c067403f7..f66464e3e 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b From 03d783ba0bbee1a5f76b6ad686bbcee59a2e21fb Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 3 May 2009 19:45:45 +0000 Subject: bug fix and typo fixes --- system/database/DB_active_rec.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index d07255855..07021999f 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1380,7 +1380,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->limit($limit); } - if (count($this->ar_where) == 0 && count($this->ar_wherein) == 0 && count($this->ar_like)) + if (count($this->ar_where) == 0 && count($this->ar_wherein) == 0 && count($this->ar_like) == 0) { if ($this->db_debug) { -- cgit v1.2.3-24-g4f1b From 55acc8b4d980c43e4bde04f0e0b99a594dea28ff Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Sat, 11 Jul 2009 03:38:13 +0000 Subject: fixed a bug with _protect_identifiers() and db/swap prefixes. It was appending the prefix, but not accounting for the need to swap --- system/database/DB_driver.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 54aa5ed7a..014dfd44e 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1309,7 +1309,13 @@ class CI_DB_driver { { $i++; } - + + // Verify table prefix and replace if necessary + if ($this->swap_pre != '' && strncmp($parts[$i], $this->swap_pre, strlen($this->swap_pre)) === 0) + { + $parts[$i] = preg_replace("/^".$this->swap_pre."(\S+?)/", $this->dbprefix."\\1", $parts[$i]); + } + // We only add the table prefix if it does not already exist if (substr($parts[$i], 0, strlen($this->dbprefix)) != $this->dbprefix) { @@ -1331,6 +1337,12 @@ class CI_DB_driver { // Is there a table prefix? If not, no need to insert it if ($this->dbprefix != '') { + // Verify table prefix and replace if necessary + if ($this->swap_pre != '' && strncmp($item, $this->swap_pre, strlen($this->swap_pre)) === 0) + { + $item = preg_replace("/^".$this->swap_pre."(\S+?)/", $this->dbprefix."\\1", $item); + } + // Do we prefix an item with no segments? if ($prefix_single == TRUE AND substr($item, 0, strlen($this->dbprefix)) != $this->dbprefix) { -- cgit v1.2.3-24-g4f1b From f0a9b332445977cfb05fee2dacc02667946a9cd2 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 29 Jul 2009 14:19:18 +0000 Subject: PHP 5.3.0 compatibility changes --- system/database/DB.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index efe1d388a..0f734d748 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -130,7 +130,7 @@ function &DB($params = '', $active_record_override = FALSE) // Instantiate the DB adapter $driver = 'CI_DB_'.$params['dbdriver'].'_driver'; - $DB =& new $driver($params); + $DB =& instantiate_class(new $driver($params)); if ($DB->autoinit == TRUE) { -- cgit v1.2.3-24-g4f1b From 64c398bde1ac0332737980a66a780624ab069be2 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 17 Aug 2009 15:13:45 +0000 Subject: Modified MSSQL driver to use mssql_get_last_message() for error messages. --- system/database/drivers/mssql/mssql_driver.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 4748d5683..97ac971bd 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -438,8 +438,7 @@ class CI_DB_mssql_driver extends CI_DB { */ function _error_message() { - // Are errros even supported in MS SQL? - return ''; + return mssql_get_last_message(); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 69b1fcc0b26c181b24aed8c347db94563328a83e Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Mon, 24 Aug 2009 16:42:52 +0000 Subject: updating xml_from_result to check for list_fields instead of field_names --- system/database/DB_utility.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 4ba69adbd..33c68faea 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -217,7 +217,7 @@ class CI_DB_utility extends CI_DB_forge { */ function xml_from_result($query, $params = array()) { - if ( ! is_object($query) OR ! method_exists($query, 'field_names')) + if ( ! is_object($query) OR ! method_exists($query, 'list_fields')) { show_error('You must submit a valid result object'); } -- cgit v1.2.3-24-g4f1b From 172e16191889558ca6f6710cf34755200d3e6334 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 13 Oct 2009 14:32:48 +0000 Subject: numerous changes from DIR_WRITE_MODE to FILE_WRITE_MODE chmod operations on files were using the DIR_ constant permisisons --- system/database/DB_cache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 8b0ad4fb4..f01bc8212 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -146,7 +146,7 @@ class CI_DB_Cache { return FALSE; } - @chmod($dir_path.$filename, DIR_WRITE_MODE); + @chmod($dir_path.$filename, FILE_WRITE_MODE); return TRUE; } -- cgit v1.2.3-24-g4f1b From ffca6c2202f89249d3bc50b5645b94c772ff3b0d Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Sat, 5 Dec 2009 15:31:44 +0000 Subject: fixed bug where active record override wasn't being honored properly --- system/database/DB.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index 0f734d748..0451c18e6 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -22,7 +22,7 @@ * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/database/ */ -function &DB($params = '', $active_record_override = FALSE) +function &DB($params = '', $active_record_override = NULL) { // Load the DB config file if a DSN string wasn't passed if (is_string($params) AND strpos($params, '://') === FALSE) @@ -102,9 +102,9 @@ function &DB($params = '', $active_record_override = FALSE) // based on whether we're using the active record class or not. // Kudos to Paul for discovering this clever use of eval() - if ($active_record_override == TRUE) + if ($active_record_override !== NULL) { - $active_record = TRUE; + $active_record = $active_record_override; } require_once(BASEPATH.'database/DB_driver'.EXT); -- cgit v1.2.3-24-g4f1b From 3683f775bec4993b3777b012a087e82d6bff8d3f Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 16 Dec 2009 17:32:33 +0000 Subject: Change to CI's db->version() function to allow a list of exceptions for dbs with functions to return version string, vs SQL queries to return version strings. Currently this list only includes Oracle and SQLite. --- system/database/DB_driver.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 014dfd44e..aee06205b 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -215,14 +215,20 @@ class CI_DB_driver { } return FALSE; } - - if ($this->dbdriver == 'oci8') + + // Some DBs have functions that return the version, and don't run special + // SQL queries per se. In these instances, just return the result. + $driver_version_exceptions = array('oci8', 'sqlite'); + + if (in_array($this->dbdriver, $driver_version_exceptions)) { return $sql; } - - $query = $this->query($sql); - return $query->row('ver'); + else + { + $query = $this->query($sql); + return $query->row('ver'); + } } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 7f3719faf120dc15f3d7b45e132ab3192f60ad62 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 5 Jan 2010 13:35:37 +0000 Subject: updated copyrights --- system/database/DB.php | 2 +- system/database/DB_active_rec.php | 2 +- system/database/DB_cache.php | 2 +- system/database/DB_driver.php | 2 +- system/database/DB_forge.php | 2 +- system/database/DB_result.php | 2 +- system/database/DB_utility.php | 2 +- system/database/drivers/mssql/mssql_driver.php | 2 +- system/database/drivers/mssql/mssql_forge.php | 2 +- system/database/drivers/mssql/mssql_result.php | 2 +- system/database/drivers/mssql/mssql_utility.php | 2 +- system/database/drivers/mysql/mysql_driver.php | 2 +- system/database/drivers/mysql/mysql_forge.php | 2 +- system/database/drivers/mysql/mysql_result.php | 2 +- system/database/drivers/mysql/mysql_utility.php | 2 +- system/database/drivers/mysqli/mysqli_driver.php | 2 +- system/database/drivers/mysqli/mysqli_forge.php | 2 +- system/database/drivers/mysqli/mysqli_result.php | 2 +- system/database/drivers/mysqli/mysqli_utility.php | 2 +- system/database/drivers/oci8/oci8_driver.php | 2 +- system/database/drivers/oci8/oci8_forge.php | 2 +- system/database/drivers/oci8/oci8_result.php | 2 +- system/database/drivers/oci8/oci8_utility.php | 2 +- system/database/drivers/odbc/odbc_driver.php | 2 +- system/database/drivers/odbc/odbc_forge.php | 2 +- system/database/drivers/odbc/odbc_result.php | 2 +- system/database/drivers/odbc/odbc_utility.php | 2 +- system/database/drivers/postgre/postgre_driver.php | 2 +- system/database/drivers/postgre/postgre_forge.php | 2 +- system/database/drivers/postgre/postgre_result.php | 2 +- system/database/drivers/postgre/postgre_utility.php | 2 +- system/database/drivers/sqlite/sqlite_driver.php | 2 +- system/database/drivers/sqlite/sqlite_forge.php | 2 +- system/database/drivers/sqlite/sqlite_result.php | 2 +- system/database/drivers/sqlite/sqlite_utility.php | 2 +- 35 files changed, 35 insertions(+), 35 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index 0451c18e6..6930411c7 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 07021999f..bf4d5117e 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index f01bc8212..2606df842 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index aee06205b..390d5570b 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index 4050e300f..c5931db27 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 4614e29f6..b9e64feeb 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 33c68faea..94e7a0bda 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 97ac971bd..f301ba533 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php index 632b4d907..f6a17811f 100644 --- a/system/database/drivers/mssql/mssql_forge.php +++ b/system/database/drivers/mssql/mssql_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index a56a3a9e2..e7b338045 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index 9fa257a69..da887b815 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index fe1859805..85a6ef4a0 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index d343b36a0..ccacf99f8 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index 2e9550702..acc586626 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 2c8b264ce..3277b0ff7 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 488b074a3..5d7200fbd 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index 0992274e9..262d491ed 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index 00fc0db47..81d22cc9c 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 7ebda4c56..44fd0f7aa 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 614571940..758192358 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index c3e9cb98f..d77ed8de6 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 1d0b7db26..cab538e21 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index c8049c248..74670eaab 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index dacbaaba9..6cb3080d4 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php index 99cb282af..1ae559b6e 100644 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index d6f15015e..5ae46df62 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index 85707a073..4e6848e82 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 9258da684..bac179d40 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index 471dd80c9..c98ef425d 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index 8e45eb1cf..545f413e8 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 235954fa6..dda22ddb0 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 0cb799775..05e38848a 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php index 0688ba368..b7d25e755 100644 --- a/system/database/drivers/sqlite/sqlite_forge.php +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index c1c24c78e..7b0631221 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index f66464e3e..5629dac99 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b From 1edde30e4443bdcb54a16bf220a5a359825ab549 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Tue, 26 Jan 2010 00:17:01 +0000 Subject: Fixing bug in DB Driver where identifiers could be escaped in some drivers that can't accept it in the list_fields() function. http://codeigniter.com/bug_tracker/bug/5865/ http://codeigniter.com/bug_tracker/bug/11218/ --- system/database/DB_driver.php | 2 +- system/database/drivers/mysql/mysql_driver.php | 2 +- system/database/drivers/mysqli/mysqli_driver.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 390d5570b..d7f17ccb8 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -822,7 +822,7 @@ class CI_DB_driver { return FALSE; } - if (FALSE === ($sql = $this->_list_columns($this->_protect_identifiers($table, TRUE, NULL, FALSE)))) + if (FALSE === ($sql = $this->_list_columns($table))) { if ($this->db_debug) { diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 85a6ef4a0..bd60d9ffe 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -408,7 +408,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function _list_columns($table = '') { - return "SHOW COLUMNS FROM ".$table; + return "SHOW COLUMNS FROM ".$this->_protect_identifiers($table, TRUE, NULL, FALSE); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 5d7200fbd..d0e2defec 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -409,7 +409,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ function _list_columns($table = '') { - return "SHOW COLUMNS FROM ".$table; + return "SHOW COLUMNS FROM ".$this->_protect_identifiers($table, TRUE, NULL, FALSE); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 0d42489234e0fdfecd11f46b1d3573e60db3918c Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Tue, 26 Jan 2010 02:14:44 +0000 Subject: Misspelled class property in db class. _like_escape_chr, not _like_escape_char http://codeigniter.com/bug_tracker/bug/9518/ --- system/database/DB_active_rec.php | 2 +- system/database/drivers/mssql/mssql_driver.php | 2 +- system/database/drivers/oci8/oci8_driver.php | 2 +- system/database/drivers/odbc/odbc_driver.php | 2 +- system/database/drivers/postgre/postgre_driver.php | 2 +- system/database/drivers/sqlite/sqlite_driver.php | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index bf4d5117e..a3abff11e 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -725,7 +725,7 @@ class CI_DB_active_record extends CI_DB_driver { // some platforms require an escape sequence definition for LIKE wildcards if ($this->_like_escape_str != '') { - $like_statement = $like_statement.sprintf($this->_like_escape_str, $this->_like_escape_char); + $like_statement = $like_statement.sprintf($this->_like_escape_str, $this->_like_escape_chr); } $this->ar_like[] = $like_statement; diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index f301ba533..0c74726a2 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -389,7 +389,7 @@ class CI_DB_mssql_driver extends CI_DB { // for future compatibility if ($prefix_limit !== FALSE AND $this->dbprefix != '') { - //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_char); + //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); return FALSE; // not currently supported } diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 758192358..cd0e09577 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -493,7 +493,7 @@ class CI_DB_oci8_driver extends CI_DB { if ($prefix_limit !== FALSE AND $this->dbprefix != '') { - $sql .= " WHERE TABLE_NAME LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_char); + $sql .= " WHERE TABLE_NAME LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); } return $sql; diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 6cb3080d4..d5df8ef8c 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -362,7 +362,7 @@ class CI_DB_odbc_driver extends CI_DB { if ($prefix_limit !== FALSE AND $this->dbprefix != '') { - //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_char); + //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); return FALSE; // not currently supported } diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index bac179d40..9f991e4a0 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -405,7 +405,7 @@ class CI_DB_postgre_driver extends CI_DB { if ($prefix_limit !== FALSE AND $this->dbprefix != '') { - $sql .= " AND table_name LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_char); + $sql .= " AND table_name LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); } return $sql; diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 05e38848a..c08ed2a56 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -374,7 +374,7 @@ class CI_DB_sqlite_driver extends CI_DB { if ($prefix_limit !== FALSE AND $this->dbprefix != '') { - $sql .= " AND 'name' LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_char); + $sql .= " AND 'name' LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); } return $sql; } -- cgit v1.2.3-24-g4f1b From e7f0325af984392aa4c509dc5a5ca409f5e9474a Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 4 Feb 2010 16:47:01 +0000 Subject: database exists function in dbutil --- system/database/DB_utility.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'system/database') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 94e7a0bda..af62dcf3d 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -74,6 +74,20 @@ class CI_DB_utility extends CI_DB_forge { // -------------------------------------------------------------------- + /** + * Determine if a particular database exists + * + * @access public + * @param string + * @return boolean + */ + function database_exists($database_name) + { + return ( ! in_array($database_name, $this->list_databases())) ? FALSE : TRUE; + } + + // -------------------------------------------------------------------- + /** * Optimize Table * -- cgit v1.2.3-24-g4f1b From 62396232658467b463f37e55bec159aadc188edd Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 4 Feb 2010 17:45:47 +0000 Subject: database_exists extension to allow for databases without list_databases() functionality --- system/database/DB_utility.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index af62dcf3d..124967a5a 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -82,10 +82,21 @@ class CI_DB_utility extends CI_DB_forge { * @return boolean */ function database_exists($database_name) - { - return ( ! in_array($database_name, $this->list_databases())) ? FALSE : TRUE; + { + // Some databases won't have access to the list_databases() function, so + // this is intended to allow them to override with their own functions as + // defined in $driver_utility.php + if (method_exists($this, '_database_exists')) + { + return $this->_database_exists($database_name); + } + else + { + return ( ! in_array($database_name, $this->list_databases())) ? FALSE : TRUE; + } } + // -------------------------------------------------------------------- /** -- cgit v1.2.3-24-g4f1b From 4860ec52f5bdf917d12f511ecd07b7d4797f0d91 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 4 Feb 2010 21:29:03 +0000 Subject: fixing a series of errors in (ironically) error display in some database drivers --- system/database/drivers/oci8/oci8_driver.php | 4 ++-- system/database/drivers/sqlite/sqlite_driver.php | 4 ++-- system/database/drivers/sqlite/sqlite_utility.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index cd0e09577..1ad05a793 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -244,7 +244,7 @@ class CI_DB_oci8_driver extends CI_DB { if ($this->db_debug) { log_message('error', 'Invalid query: '.$package.'.'.$procedure); - return $this->display_error('db_invalid_query'); + return $this->db->display_error('db_invalid_query'); } return FALSE; } @@ -443,7 +443,7 @@ class CI_DB_oci8_driver extends CI_DB { function insert_id() { // not supported in oracle - return $this->display_error('db_unsupported_function'); + return $this->db->display_error('db_unsupported_function'); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index c08ed2a56..4309c1656 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -63,7 +63,7 @@ class CI_DB_sqlite_driver extends CI_DB { if ($this->db_debug) { - $this->display_error($error, '', TRUE); + $this->db->display_error($error, '', TRUE); } return FALSE; @@ -88,7 +88,7 @@ class CI_DB_sqlite_driver extends CI_DB { if ($this->db_debug) { - $this->display_error($error, '', TRUE); + $this->db->display_error($error, '', TRUE); } return FALSE; diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 5629dac99..fe63362ee 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -39,7 +39,7 @@ class CI_DB_sqlite_utility extends CI_DB_utility { { if ($this->db_debug) { - return $this->display_error('db_unsuported_feature'); + return $this->db->display_error('db_unsuported_feature'); } return array(); } -- cgit v1.2.3-24-g4f1b From fac8fbc8bd60399110c8daf4b87dddc9397f5dc7 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 5 Feb 2010 16:14:49 +0000 Subject: display_error in driver needs no db reference --- system/database/drivers/oci8/oci8_driver.php | 4 ++-- system/database/drivers/sqlite/sqlite_driver.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 1ad05a793..cd0e09577 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -244,7 +244,7 @@ class CI_DB_oci8_driver extends CI_DB { if ($this->db_debug) { log_message('error', 'Invalid query: '.$package.'.'.$procedure); - return $this->db->display_error('db_invalid_query'); + return $this->display_error('db_invalid_query'); } return FALSE; } @@ -443,7 +443,7 @@ class CI_DB_oci8_driver extends CI_DB { function insert_id() { // not supported in oracle - return $this->db->display_error('db_unsupported_function'); + return $this->display_error('db_unsupported_function'); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 4309c1656..c08ed2a56 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -63,7 +63,7 @@ class CI_DB_sqlite_driver extends CI_DB { if ($this->db_debug) { - $this->db->display_error($error, '', TRUE); + $this->display_error($error, '', TRUE); } return FALSE; @@ -88,7 +88,7 @@ class CI_DB_sqlite_driver extends CI_DB { if ($this->db_debug) { - $this->db->display_error($error, '', TRUE); + $this->display_error($error, '', TRUE); } return FALSE; -- cgit v1.2.3-24-g4f1b From d10e89666380d717e3e40dda046be78dbb7a38c4 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 17:10:36 -0600 Subject: added batch insert/update and a replace method to active record --- system/database/DB_active_rec.php | 327 +++++++++++++++++++++++++++++++++++++- 1 file changed, 325 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index a3abff11e..88690a8f9 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -721,13 +721,13 @@ class CI_DB_active_record extends CI_DB_driver { { $like_statement = $prefix." $k $not LIKE '%{$v}%'"; } - + // some platforms require an escape sequence definition for LIKE wildcards if ($this->_like_escape_str != '') { $like_statement = $like_statement.sprintf($this->_like_escape_str, $this->_like_escape_chr); } - + $this->ar_like[] = $like_statement; if ($this->ar_caching === TRUE) { @@ -1134,7 +1134,127 @@ class CI_DB_active_record extends CI_DB_driver { { return $this->get_where($table, $where, $limit, $offset); } + + // -------------------------------------------------------------------- + + /** + * Insert_Batch + * + * Compiles batch insert strings and runs the queries + * + * @access public + * @param string the table to retrieve the results from + * @param array an associative array of insert values + * @return object + */ + function insert_batch($table = '', $set = NULL) + { + if ( ! is_null($set)) + { + $this->set_insert_batch($set); + } + if (count($this->ar_set) == 0) + { + if ($this->db_debug) + { + //No valid data array. Folds in cases where keys and values did not match up + return $this->display_error('db_must_use_set'); + } + return FALSE; + } + + if ($table == '') + { + if ( ! isset($this->ar_from[0])) + { + if ($this->db_debug) + { + return $this->display_error('db_must_set_table'); + } + return FALSE; + } + + $table = $this->ar_from[0]; + } + + // Batch this baby + for ($i = 0, $total = count($this->ar_set); $i < $total; $i = $i + 100) + { + + $sql = $this->_insert_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_keys, array_slice($this->ar_set, $i, 100)); + + //echo $sql; + + $this->query($sql); + } + + $this->_reset_write(); + + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * The "set_insert_batch" function. Allows key/value pairs to be set for batch inserts + * + * @access public + * @param mixed + * @param string + * @param boolean + * @return object + */ + + function set_insert_batch($key, $value = '', $escape = TRUE) + { + $key = $this->_object_to_array_batch($key); + + if ( ! is_array($key)) + { + $key = array($key => $value); + } + + $keys = array_keys(current($key)); + sort($keys); + + foreach ($key as $row) + { + if (count(array_diff($keys, array_keys($row))) > 0 OR count(array_diff(array_keys($row), $keys)) > 0) + { + // batch function above returns an error on an empty array + $this->ar_set[] = array(); + return; + } + + ksort($row); // puts $row in the same order as our keys + + if ($escape === FALSE) + { + $this->ar_set[] = '('.implode(',', $row).')'; + } + else + { + $clean = array(); + + foreach($row as $value) + { + $clean[] = $this->escape($value); + } + + $this->ar_set[] = '('.implode(',', $clean).')'; + } + } + + foreach ($keys as $k) + { + $this->ar_keys[] = $this->_protect_identifiers($k); + } + + return $this; + } + // -------------------------------------------------------------------- /** @@ -1183,6 +1303,42 @@ class CI_DB_active_record extends CI_DB_driver { return $this->query($sql); } + function replace($table = '', $set = NULL) + { + if ( ! is_null($set)) + { + $this->set($set); + } + + if (count($this->ar_set) == 0) + { + if ($this->db_debug) + { + return $this->display_error('db_must_use_set'); + } + return FALSE; + } + + if ($table == '') + { + if ( ! isset($this->ar_from[0])) + { + if ($this->db_debug) + { + return $this->display_error('db_must_set_table'); + } + return FALSE; + } + + $table = $this->ar_from[0]; + } + + $sql = $this->_replace($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->ar_set), array_values($this->ar_set)); + + $this->_reset_write(); + return $this->query($sql); + } + // -------------------------------------------------------------------- /** @@ -1245,6 +1401,133 @@ class CI_DB_active_record extends CI_DB_driver { return $this->query($sql); } + + // -------------------------------------------------------------------- + + /** + * Update_Batch + * + * Compiles an update string and runs the query + * + * @access public + * @param string the table to retrieve the results from + * @param array an associative array of update values + * @param string the where key + * @return object + */ + function update_batch($table = '', $set = NULL, $index = NULL) + { + // Combine any cached components with the current statements + $this->_merge_cache(); + + if (is_null($index)) + { + if ($this->db_debug) + { + return $this->display_error('db_myst_use_index'); + } + + return FALSE; + } + + if ( ! is_null($set)) + { + $this->set_update_batch($set, $index); + } + + if (count($this->ar_set) == 0) + { + if ($this->db_debug) + { + return $this->display_error('db_must_use_set'); + } + + return FALSE; + } + + if ($table == '') + { + if ( ! isset($this->ar_from[0])) + { + if ($this->db_debug) + { + return $this->display_error('db_must_set_table'); + } + return FALSE; + } + + $table = $this->ar_from[0]; + } + + // Batch this baby + for ($i = 0, $total = count($this->ar_set); $i < $total; $i = $i + 100) + { + $sql = $this->_update_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->ar_set, $i, 100), $this->_protect_identifiers($index), $this->ar_where); + + $this->query($sql); + } + + $this->_reset_write(); + } + + // -------------------------------------------------------------------- + + /** + * The "set_update_batch" function. Allows key/value pairs to be set for batch updating + * + * @access public + * @param array + * @param string + * @param boolean + * @return object + */ + + function set_update_batch($key, $index = '', $escape = TRUE) + { + $key = $this->_object_to_array_batch($key); + + if ( ! is_array($key)) + { + // @todo error + } + + foreach ($key as $k => $v) + { + $index_set = FALSE; + $clean = array(); + + foreach($v as $k2 => $v2) + { + if ($k2 == $index) + { + $index_set = TRUE; + } + else + { + $not[] = $k.'-'.$v; + } + + if ($escape === FALSE) + { + $clean[$this->_protect_identifiers($k2)] = $v2; + } + else + { + $clean[$this->_protect_identifiers($k2)] = $this->escape($v2); + } + } + + if ($index_set == FALSE) + { + return $this->display_error('db_batch_missing_index'); + } + + $this->ar_set[] = $clean; + } + + return $this; + } + // -------------------------------------------------------------------- /** @@ -1638,7 +1921,47 @@ class CI_DB_active_record extends CI_DB_driver { $array[$key] = $val; } } + + return $array; + } + // -------------------------------------------------------------------- + + /** + * Object to Array + * + * Takes an object as input and converts the class variables to array key/vals + * + * @access public + * @param object + * @return array + */ + function _object_to_array_batch($object) + { + if ( ! is_object($object)) + { + return $object; + } + + $array = array(); + $out = get_object_vars($object); + $fields = array_keys($out); + + foreach ($fields as $val) + { + // There are some built in keys we need to ignore for this conversion + if ($val != '_parent_name' && $val != '_ci_scaffolding' && $val != '_ci_scaff_table') + { + + $i = 0; + foreach ($out[$val] as $data) + { + $array[$i][$val] = $data; + $i++; + } + } + } + return $array; } -- cgit v1.2.3-24-g4f1b From e77922026939fed28a607338e24c1c37066a97b4 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 17:24:46 -0600 Subject: whitespace and changes to load_class() to use core --- system/database/DB_driver.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index d7f17ccb8..dfef42757 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -261,10 +261,10 @@ class CI_DB_driver { // Verify table prefix and replace if necessary if ( ($this->dbprefix != '' AND $this->swap_pre != '') AND ($this->dbprefix != $this->swap_pre) ) - { + { $sql = preg_replace("/(\W)".$this->swap_pre."(\S+?)/", "\\1".$this->dbprefix."\\2", $sql); } - + // Is query caching enabled? If the query is a "read type" // we will load the caching class and return the previously // cached query if it exists @@ -679,7 +679,7 @@ class CI_DB_driver { * @return mixed */ function escape($str) - { + { if (is_string($str)) { $str = "'".$this->escape_str($str)."'"; @@ -697,7 +697,7 @@ class CI_DB_driver { } // -------------------------------------------------------------------- - + /** * Escape LIKE String * @@ -714,7 +714,7 @@ class CI_DB_driver { } // -------------------------------------------------------------------- - + /** * Primary * @@ -1155,7 +1155,7 @@ class CI_DB_driver { */ function display_error($error = '', $swap = '', $native = FALSE) { - $LANG =& load_class('Language'); + $LANG =& load_class('Lang', 'core'); $LANG->load('db'); $heading = $LANG->line('db_error_heading'); @@ -1169,7 +1169,7 @@ class CI_DB_driver { $message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error; } - $error =& load_class('Exceptions'); + $error =& load_class('Exceptions', 'core'); echo $error->show_error($heading, $message, 'error_db'); exit; } @@ -1315,13 +1315,13 @@ class CI_DB_driver { { $i++; } - + // Verify table prefix and replace if necessary if ($this->swap_pre != '' && strncmp($parts[$i], $this->swap_pre, strlen($this->swap_pre)) === 0) { $parts[$i] = preg_replace("/^".$this->swap_pre."(\S+?)/", $this->dbprefix."\\1", $parts[$i]); } - + // We only add the table prefix if it does not already exist if (substr($parts[$i], 0, strlen($this->dbprefix)) != $this->dbprefix) { -- cgit v1.2.3-24-g4f1b From 30b35eb12edef6018fe61f383a002d895683e468 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 17:25:41 -0600 Subject: whitespace --- system/database/DB_forge.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index c5931db27..8be65e0d6 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -259,8 +259,8 @@ class CI_DB_forge { // add field info into field array, but we can only do one at a time // so we cycle through - foreach ($field as $k => $v) - { + foreach ($field as $k => $v) + { $this->add_field(array($k => $field[$k])); if (count($this->fields) == 0) @@ -279,6 +279,7 @@ class CI_DB_forge { } return TRUE; + } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 20aa2bd6d852530b3d4b2e76076fe7e7b48bf148 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 17:28:07 -0600 Subject: added batch insert/update and replace methods to MySQL driver --- system/database/drivers/mysql/mysql_driver.php | 92 ++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) (limited to 'system/database') diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index bd60d9ffe..d684c8a49 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -537,6 +537,44 @@ class CI_DB_mysql_driver extends CI_DB { // -------------------------------------------------------------------- + + /** + * Replace statement + * + * Generates a platform-specific replace string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _replace($table, $keys, $values) + { + return "REPLACE INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Insert_batch statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert_batch($table, $keys, $values) + { + return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values); + } + + // -------------------------------------------------------------------- + + /** * Update statement * @@ -572,6 +610,60 @@ class CI_DB_mysql_driver extends CI_DB { // -------------------------------------------------------------------- + + /** + * Update_Batch statement + * + * Generates a platform-specific batch update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @return string + */ + function _update_batch($table, $values, $index, $where = NULL) + { + $ids = array(); + $where = ($where != '' AND count($where) >=1) ? implode(" ", $where).' AND ' : ''; + + 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 = ''; + + foreach($final as $k => $v) + { + $cases .= $k.' = CASE '."\n"; + foreach ($v as $row) + { + $cases .= $row."\n"; + } + + $cases .= 'ELSE '.$k.' END, '; + } + + $sql .= substr($cases, 0, -2); + + $sql .= ' WHERE '.$where.$index.' IN ('.implode(',', $ids).')'; + + return $sql; + } + + // -------------------------------------------------------------------- + + /** * Truncate statement * -- cgit v1.2.3-24-g4f1b From c34e578c4bf993481381b1efb8f95089482135a4 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 17:35:55 -0600 Subject: added stricton db config item to force strict mode - good for ensuring strict sql during development --- system/database/DB.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index 6930411c7..a91ca08fa 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -137,6 +137,11 @@ function &DB($params = '', $active_record_override = NULL) $DB->initialize(); } + if (isset($params['stricton']) && $params['stricton'] == TRUE) + { + $DB->query('SET SESSION sql_mode="STRICT_ALL_TABLES"'); + } + return $DB; } -- cgit v1.2.3-24-g4f1b From cf579558fa8c1e20af748146e4fe196d7c772c34 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 11 Mar 2010 09:13:34 -0600 Subject: full on scaffolding removal --- system/database/DB_active_rec.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 88690a8f9..3e9923e6f 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1916,7 +1916,7 @@ class CI_DB_active_record extends CI_DB_driver { foreach (get_object_vars($object) as $key => $val) { // There are some built in keys we need to ignore for this conversion - if ( ! is_object($val) && ! is_array($val) && $key != '_parent_name' && $key != '_ci_scaffolding' && $key != '_ci_scaff_table') + if ( ! is_object($val) && ! is_array($val) && $key != '_parent_name') { $array[$key] = $val; } @@ -1950,7 +1950,7 @@ class CI_DB_active_record extends CI_DB_driver { foreach ($fields as $val) { // There are some built in keys we need to ignore for this conversion - if ($val != '_parent_name' && $val != '_ci_scaffolding' && $val != '_ci_scaff_table') + if ($val != '_parent_name') { $i = 0; -- cgit v1.2.3-24-g4f1b From 4bde110ec6769fe0fd0194be602fd3ed85c52bc7 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 30 Mar 2010 08:56:53 -0500 Subject: fixed a fatal PHP error in SQLite Forge _create_table() --- system/database/drivers/sqlite/sqlite_forge.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php index b7d25e755..53b20a3c7 100644 --- a/system/database/drivers/sqlite/sqlite_forge.php +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -77,7 +77,7 @@ class CI_DB_sqlite_forge extends CI_DB_forge { $sql = 'CREATE TABLE '; // IF NOT EXISTS added to SQLite in 3.3.0 - if ($if_not_exists === TRUE && version_compare($this->_version(), '3.3.0', '>=') === TRUE) + if ($if_not_exists === TRUE && version_compare($this->db->_version(), '3.3.0', '>=') === TRUE) { $sql .= 'IF NOT EXISTS '; } -- cgit v1.2.3-24-g4f1b From 757dda61aa0556aca8172dc2a8175596afe28ce2 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Wed, 14 Apr 2010 19:06:19 -0500 Subject: Fixing a bug where odbc/mssql/oci8 db drivers would encounter a PHP error due to a function being moved from the input to security class. Moving remove_invisible_characters() to Common.php so the entire class does not need to be instantiated in those database drivers. --- system/database/drivers/mssql/mssql_driver.php | 5 +---- system/database/drivers/oci8/oci8_driver.php | 5 +---- system/database/drivers/odbc/odbc_driver.php | 5 +---- 3 files changed, 3 insertions(+), 12 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 0c74726a2..40900e832 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -260,12 +260,9 @@ class CI_DB_mssql_driver extends CI_DB { return $str; } - - // Access the CI object - $CI =& get_instance(); // Escape single quotes - $str = str_replace("'", "''", $CI->input->_remove_invisible_characters($str)); + $str = str_replace("'", "''", remove_invisible_characters($str)); // escape LIKE condition wildcards if ($like === TRUE) diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index cd0e09577..6f317d2e6 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -403,10 +403,7 @@ class CI_DB_oci8_driver extends CI_DB { return $str; } - // Access the CI object - $CI =& get_instance(); - - $str = $CI->input->_remove_invisible_characters($str); + $str = remove_invisible_characters($str); // escape LIKE condition wildcards if ($like === TRUE) diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index d5df8ef8c..6e682313f 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -271,12 +271,9 @@ class CI_DB_odbc_driver extends CI_DB { return $str; } - - // Access the CI object - $CI =& get_instance(); // ODBC doesn't require escaping - $str = $CI->input->_remove_invisible_characters($str); + $str = remove_invisible_characters($str); // escape LIKE condition wildcards if ($like === TRUE) -- cgit v1.2.3-24-g4f1b From 88f8d9f4c9d590cc14e71cd77f34e5e2abe57e21 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Fri, 6 Aug 2010 13:01:38 -0500 Subject: Removing the following deprecated database methods: orwhere, orlike, groupby, orhaving, orderby, getwhere. --- system/database/DB_active_rec.php | 74 +-------------------------------------- 1 file changed, 1 insertion(+), 73 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 3e9923e6f..953cc9548 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -398,18 +398,6 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- - /** - * orwhere() is an alias of or_where() - * this function is here for backwards compatibility, as - * orwhere() has been deprecated - */ - function orwhere($key, $value = NULL, $escape = TRUE) - { - return $this->or_where($key, $value, $escape); - } - - // -------------------------------------------------------------------- - /** * Where * @@ -671,18 +659,6 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- - /** - * orlike() is an alias of or_like() - * this function is here for backwards compatibility, as - * orlike() has been deprecated - */ - function orlike($field, $match = '', $side = 'both') - { - return $this->or_like($field, $match, $side); - } - - // -------------------------------------------------------------------- - /** * Like * @@ -775,18 +751,6 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- - /** - * groupby() is an alias of group_by() - * this function is here for backwards compatibility, as - * groupby() has been deprecated - */ - function groupby($by) - { - return $this->group_by($by); - } - - // -------------------------------------------------------------------- - /** * Sets the HAVING value * @@ -801,19 +765,7 @@ class CI_DB_active_record extends CI_DB_driver { { return $this->_having($key, $value, 'AND ', $escape); } - - // -------------------------------------------------------------------- - - /** - * orhaving() is an alias of or_having() - * this function is here for backwards compatibility, as - * orhaving() has been deprecated - */ - - function orhaving($key, $value = '', $escape = TRUE) - { - return $this->or_having($key, $value, $escape); - } + // -------------------------------------------------------------------- /** @@ -938,18 +890,6 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- - /** - * orderby() is an alias of order_by() - * this function is here for backwards compatibility, as - * orderby() has been deprecated - */ - function orderby($orderby, $direction = '') - { - return $this->order_by($orderby, $direction); - } - - // -------------------------------------------------------------------- - /** * Sets the LIMIT value * @@ -1125,18 +1065,6 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- - /** - * getwhere() is an alias of get_where() - * this function is here for backwards compatibility, as - * getwhere() has been deprecated - */ - function getwhere($table = '', $where = null, $limit = null, $offset = null) - { - return $this->get_where($table, $where, $limit, $offset); - } - - // -------------------------------------------------------------------- - /** * Insert_Batch * -- cgit v1.2.3-24-g4f1b From c5b044b739234c1e1635d4a4647b3440c44f4fa3 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Fri, 6 Aug 2010 13:06:32 -0500 Subject: Removed deprecated _drop_database() and _create_database() functions from db utility drivers. --- system/database/drivers/mssql/mssql_utility.php | 35 ----------------- system/database/drivers/mysql/mysql_utility.php | 35 ----------------- system/database/drivers/mysqli/mysqli_utility.php | 36 ----------------- system/database/drivers/oci8/oci8_utility.php | 35 ----------------- system/database/drivers/odbc/odbc_utility.php | 45 ---------------------- .../database/drivers/postgre/postgre_utility.php | 36 ----------------- system/database/drivers/sqlite/sqlite_utility.php | 45 ---------------------- 7 files changed, 267 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index da887b815..751be146c 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -82,42 +82,7 @@ class CI_DB_mssql_utility extends CI_DB_utility { return $this->db->display_error('db_unsuported_feature'); } - /** - * - * The functions below have been deprecated as of 1.6, and are only here for backwards - * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation - * is STRONGLY discouraged in favour if using dbforge. - * - */ - - /** - * Create database - * - * @access private - * @param string the database name - * @return bool - */ - function _create_database($name) - { - return "CREATE DATABASE ".$name; - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access private - * @param string the database name - * @return bool - */ - function _drop_database($name) - { - return "DROP DATABASE ".$name; - } - } - /* End of file mssql_utility.php */ /* Location: ./system/database/drivers/mssql/mssql_utility.php */ \ No newline at end of file diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 3277b0ff7..c4a970cfd 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -204,41 +204,6 @@ class CI_DB_mysql_utility extends CI_DB_utility { return $output; } - - /** - * - * The functions below have been deprecated as of 1.6, and are only here for backwards - * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation - * is STRONGLY discouraged in favour if using dbforge. - * - */ - - /** - * Create database - * - * @access private - * @param string the database name - * @return bool - */ - function _create_database($name) - { - return "CREATE DATABASE ".$name; - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access private - * @param string the database name - * @return bool - */ - function _drop_database($name) - { - return "DROP DATABASE ".$name; - } - } /* End of file mysql_utility.php */ diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 44fd0f7aa..3ba14d25a 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -81,42 +81,6 @@ class CI_DB_mysqli_utility extends CI_DB_utility { // Currently unsupported return $this->db->display_error('db_unsuported_feature'); } - - - /** - * - * The functions below have been deprecated as of 1.6, and are only here for backwards - * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation - * is STRONGLY discouraged in favour if using dbforge. - * - */ - - /** - * Create database - * - * @access private - * @param string the database name - * @return bool - */ - function _create_database($name) - { - return "CREATE DATABASE ".$name; - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access private - * @param string the database name - * @return bool - */ - function _drop_database($name) - { - return "DROP DATABASE ".$name; - } - } /* End of file mysqli_utility.php */ diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 74670eaab..cc1793531 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -81,41 +81,6 @@ class CI_DB_oci8_utility extends CI_DB_utility { // Currently unsupported return $this->db->display_error('db_unsuported_feature'); } - - /** - * - * The functions below have been deprecated as of 1.6, and are only here for backwards - * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation - * is STRONGLY discouraged in favour if using dbforge. - * - */ - - /** - * Create database - * - * @access public - * @param string the database name - * @return bool - */ - function _create_database($name) - { - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access private - * @param string the database name - * @return bool - */ - function _drop_database($name) - { - return FALSE; - } - } /* End of file oci8_utility.php */ diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index 4e6848e82..5b874d88f 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -96,52 +96,7 @@ class CI_DB_odbc_utility extends CI_DB_utility { // Currently unsupported return $this->db->display_error('db_unsuported_feature'); } - - /** - * - * The functions below have been deprecated as of 1.6, and are only here for backwards - * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation - * is STRONGLY discouraged in favour if using dbforge. - * - */ - /** - * Create database - * - * @access private - * @param string the database name - * @return bool - */ - function _create_database() - { - // ODBC has no "create database" command since it's - // designed to connect to an existing database - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access private - * @param string the database name - * @return bool - */ - function _drop_database($name) - { - // ODBC has no "drop database" command since it's - // designed to connect to an existing database - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return FALSE; - } } /* End of file odbc_utility.php */ diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index dda22ddb0..84b089af0 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -81,42 +81,6 @@ class CI_DB_postgre_utility extends CI_DB_utility { // Currently unsupported return $this->db->display_error('db_unsuported_feature'); } - - /** - * - * The functions below have been deprecated as of 1.6, and are only here for backwards - * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation - * is STRONGLY discouraged in favour if using dbforge. - * - */ - - /** - * Create database - * - * @access private - * @param string the database name - * @return bool - */ - function _create_database($name) - { - return "CREATE DATABASE ".$name; - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access private - * @param string the database name - * @return bool - */ - function _drop_database($name) - { - return "DROP DATABASE ".$name; - } - - } diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index fe63362ee..956d2130f 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -90,51 +90,6 @@ class CI_DB_sqlite_utility extends CI_DB_utility { // Currently unsupported return $this->db->display_error('db_unsuported_feature'); } - - /** - * - * The functions below have been deprecated as of 1.6, and are only here for backwards - * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation - * is STRONGLY discouraged in favour if using dbforge. - * - */ - - /** - * Create database - * - * @access public - * @param string the database name - * @return bool - */ - function _create_database() - { - // In SQLite, a database is created when you connect to the database. - // We'll return TRUE so that an error isn't generated - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access private - * @param string the database name - * @return bool - */ - function _drop_database($name) - { - if ( ! @file_exists($this->db->database) OR ! @unlink($this->db->database)) - { - if ($this->db->db_debug) - { - return $this->db->display_error('db_unable_to_drop'); - } - return FALSE; - } - return TRUE; - } - } /* End of file sqlite_utility.php */ -- cgit v1.2.3-24-g4f1b From 60f8c395f24ba6db80d510892bcc53ce5bf9f4eb Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Wed, 25 Aug 2010 18:03:28 +0200 Subject: Modified the database driver's display_error() method to show the filename and line number of the failed query. --- system/database/DB_driver.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index dfef42757..8e6f88801 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1169,6 +1169,24 @@ class CI_DB_driver { $message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error; } + // Find the most likely culprit of the error by going through + // the backtrace until the source file is no longer in the + // database folder. + + $trace = debug_backtrace(); + + foreach($trace as $call) + { + if (isset($call['file']) && strpos($call['file'], BASEPATH.'database') === FALSE) + { + // Found it - use a relative path for safety + $message[] = 'Filename: '.str_replace(array(BASEPATH, APPPATH), '', $call['file']); + $message[] = 'Line Number: '.$call['line']; + + break; + } + } + $error =& load_class('Exceptions', 'core'); echo $error->show_error($heading, $message, 'error_db'); exit; -- cgit v1.2.3-24-g4f1b From 43753fde8ce6c07478a013b32dc4a833fb0d1ed7 Mon Sep 17 00:00:00 2001 From: Robin Sowell Date: Thu, 16 Sep 2010 12:52:07 -0400 Subject: Added $ar_keys clearing out to _reset_write(). --- system/database/DB_active_rec.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 953cc9548..25645a050 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -36,6 +36,7 @@ class CI_DB_active_record extends CI_DB_driver { var $ar_like = array(); var $ar_groupby = array(); var $ar_having = array(); + var $ar_keys = array(); var $ar_limit = FALSE; var $ar_offset = FALSE; var $ar_order = FALSE; @@ -2045,7 +2046,7 @@ class CI_DB_active_record extends CI_DB_driver { /** * Resets the active record "write" values. * - * Called by the insert() update() and delete() functions + * Called by the insert() update() insert_batch() update_batch() and delete() functions * * @access private * @return void @@ -2057,7 +2058,8 @@ class CI_DB_active_record extends CI_DB_driver { 'ar_from' => array(), 'ar_where' => array(), 'ar_like' => array(), - 'ar_orderby' => array(), + 'ar_orderby' => array(), + 'ar_keys' => array(), 'ar_limit' => FALSE, 'ar_order' => FALSE ); -- cgit v1.2.3-24-g4f1b From dd6719738936be31cdaa1758ca86d5eb14dcab3d Mon Sep 17 00:00:00 2001 From: Barry Mieny Date: Mon, 4 Oct 2010 16:33:58 +0200 Subject: Cleanup of stray spaces and tabs --- system/database/DB.php | 46 +-- system/database/DB_active_rec.php | 378 ++++++++++----------- system/database/DB_cache.php | 54 +-- system/database/DB_driver.php | 332 +++++++++--------- system/database/DB_forge.php | 72 ++-- system/database/DB_result.php | 80 ++--- system/database/DB_utility.php | 84 ++--- system/database/drivers/mssql/mssql_driver.php | 120 +++---- system/database/drivers/mssql/mssql_forge.php | 34 +- system/database/drivers/mssql/mssql_result.php | 24 +- system/database/drivers/mssql/mssql_utility.php | 2 +- system/database/drivers/mysql/mysql_driver.php | 144 ++++---- system/database/drivers/mysql/mysql_forge.php | 30 +- system/database/drivers/mysql/mysql_result.php | 24 +- system/database/drivers/mysql/mysql_utility.php | 46 +-- system/database/drivers/mysqli/mysqli_driver.php | 120 +++---- system/database/drivers/mysqli/mysqli_forge.php | 30 +- system/database/drivers/mysqli/mysqli_result.php | 24 +- system/database/drivers/mysqli/mysqli_utility.php | 4 +- system/database/drivers/oci8/oci8_driver.php | 104 +++--- system/database/drivers/oci8/oci8_forge.php | 32 +- system/database/drivers/oci8/oci8_result.php | 30 +- system/database/drivers/odbc/odbc_driver.php | 108 +++--- system/database/drivers/odbc/odbc_forge.php | 38 +-- system/database/drivers/odbc/odbc_result.php | 18 +- system/database/drivers/odbc/odbc_utility.php | 6 +- system/database/drivers/postgre/postgre_driver.php | 116 +++---- system/database/drivers/postgre/postgre_forge.php | 32 +- system/database/drivers/postgre/postgre_result.php | 18 +- system/database/drivers/sqlite/sqlite_driver.php | 124 +++---- system/database/drivers/sqlite/sqlite_forge.php | 30 +- system/database/drivers/sqlite/sqlite_result.php | 20 +- 32 files changed, 1162 insertions(+), 1162 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index a91ca08fa..1b4eb8bec 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -28,39 +28,39 @@ function &DB($params = '', $active_record_override = NULL) if (is_string($params) AND strpos($params, '://') === FALSE) { include(APPPATH.'config/database'.EXT); - + if ( ! isset($db) OR count($db) == 0) { show_error('No database connection settings were found in the database config file.'); } - + if ($params != '') { $active_group = $params; } - + if ( ! isset($active_group) OR ! isset($db[$active_group])) { show_error('You have specified an invalid database connection group.'); } - + $params = $db[$active_group]; } elseif (is_string($params)) { - + /* parse the URL from the DSN string - * Database settings can be passed as discreet - * parameters or as a data source name in the first - * parameter. DSNs must have this prototype: - * $dsn = 'driver://username:password@hostname/database'; - */ - + * Database settings can be passed as discreet + * parameters or as a data source name in the first + * parameter. DSNs must have this prototype: + * $dsn = 'driver://username:password@hostname/database'; + */ + if (($dns = @parse_url($params)) === FALSE) { show_error('Invalid DB Connection String'); } - + $params = array( 'dbdriver' => $dns['scheme'], 'hostname' => (isset($dns['host'])) ? rawurldecode($dns['host']) : '', @@ -68,7 +68,7 @@ function &DB($params = '', $active_record_override = NULL) 'password' => (isset($dns['pass'])) ? rawurldecode($dns['pass']) : '', 'database' => (isset($dns['path'])) ? rawurldecode(substr($dns['path'], 1)) : '' ); - + // were additional config items set? if (isset($dns['query'])) { @@ -90,7 +90,7 @@ function &DB($params = '', $active_record_override = NULL) } } } - + // No DB specified yet? Beat them senseless... if ( ! isset($params['dbdriver']) OR $params['dbdriver'] == '') { @@ -101,18 +101,18 @@ function &DB($params = '', $active_record_override = NULL) // we need to dynamically create a class that extends proper parent class // based on whether we're using the active record class or not. // Kudos to Paul for discovering this clever use of eval() - + if ($active_record_override !== NULL) { $active_record = $active_record_override; } - + require_once(BASEPATH.'database/DB_driver'.EXT); if ( ! isset($active_record) OR $active_record == TRUE) { require_once(BASEPATH.'database/DB_active_rec'.EXT); - + if ( ! class_exists('CI_DB')) { eval('class CI_DB extends CI_DB_active_record { }'); @@ -125,25 +125,25 @@ function &DB($params = '', $active_record_override = NULL) eval('class CI_DB extends CI_DB_driver { }'); } } - + require_once(BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver'.EXT); // Instantiate the DB adapter $driver = 'CI_DB_'.$params['dbdriver'].'_driver'; $DB =& instantiate_class(new $driver($params)); - + if ($DB->autoinit == TRUE) { $DB->initialize(); } - + if (isset($params['stricton']) && $params['stricton'] == TRUE) { - $DB->query('SET SESSION sql_mode="STRICT_ALL_TABLES"'); + $DB->query('SET SESSION sql_mode="STRICT_ALL_TABLES"'); } - + return $DB; -} +} diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 25645a050..ce50479cc 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -41,13 +41,13 @@ class CI_DB_active_record extends CI_DB_driver { var $ar_offset = FALSE; var $ar_order = FALSE; var $ar_orderby = array(); - var $ar_set = array(); + var $ar_set = array(); var $ar_wherein = array(); var $ar_aliased_tables = array(); var $ar_store_array = array(); - + // Active Record Caching variables - var $ar_caching = FALSE; + var $ar_caching = FALSE; var $ar_cache_exists = array(); var $ar_cache_select = array(); var $ar_cache_from = array(); @@ -57,7 +57,7 @@ class CI_DB_active_record extends CI_DB_driver { var $ar_cache_groupby = array(); var $ar_cache_having = array(); var $ar_cache_orderby = array(); - var $ar_cache_set = array(); + var $ar_cache_set = array(); // -------------------------------------------------------------------- @@ -73,12 +73,12 @@ class CI_DB_active_record extends CI_DB_driver { */ function select($select = '*', $escape = NULL) { - // Set the global value if this was sepecified + // Set the global value if this was sepecified if (is_bool($escape)) { $this->_protect_identifiers = $escape; } - + if (is_string($select)) { $select = explode(',', $select); @@ -118,7 +118,7 @@ class CI_DB_active_record extends CI_DB_driver { { return $this->_max_min_avg_sum($select, $alias, 'MAX'); } - + // -------------------------------------------------------------------- /** @@ -179,7 +179,7 @@ class CI_DB_active_record extends CI_DB_driver { * select_min() * select_avg() * select_sum() - * + * * @access public * @param string the field * @param string an alias @@ -191,29 +191,29 @@ class CI_DB_active_record extends CI_DB_driver { { $this->display_error('db_invalid_query'); } - + $type = strtoupper($type); - + if ( ! in_array($type, array('MAX', 'MIN', 'AVG', 'SUM'))) { show_error('Invalid function type: '.$type); } - + if ($alias == '') { $alias = $this->_create_alias_from_table(trim($select)); } - + $sql = $type.'('.$this->_protect_identifiers(trim($select)).') AS '.$alias; $this->ar_select[] = $sql; - + if ($this->ar_caching === TRUE) { $this->ar_cache_select[] = $sql; $this->ar_cache_exists[] = 'select'; } - + return $this; } @@ -232,7 +232,7 @@ class CI_DB_active_record extends CI_DB_driver { { return end(explode('.', $item)); } - + return $item; } @@ -252,7 +252,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->ar_distinct = (is_bool($val)) ? $val : TRUE; return $this; } - + // -------------------------------------------------------------------- /** @@ -276,12 +276,12 @@ class CI_DB_active_record extends CI_DB_driver { $this->_track_aliases($v); $this->ar_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE); - + if ($this->ar_caching === TRUE) { $this->ar_cache_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE); $this->ar_cache_exists[] = 'from'; - } + } } } @@ -290,11 +290,11 @@ class CI_DB_active_record extends CI_DB_driver { $val = trim($val); // Extract any aliases that might exist. We use this information - // in the _protect_identifiers to know whether to add a table prefix + // in the _protect_identifiers to know whether to add a table prefix $this->_track_aliases($val); - + $this->ar_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE); - + if ($this->ar_caching === TRUE) { $this->ar_cache_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE); @@ -320,7 +320,7 @@ class CI_DB_active_record extends CI_DB_driver { * @return object */ function join($table, $cond, $type = '') - { + { if ($type != '') { $type = strtoupper(trim($type)); @@ -336,7 +336,7 @@ class CI_DB_active_record extends CI_DB_driver { } // Extract any aliases that might exist. We use this information - // in the _protect_identifiers to know whether to add a table prefix + // in the _protect_identifiers to know whether to add a table prefix $this->_track_aliases($table); // Strip apart the condition and protect the identifiers @@ -344,10 +344,10 @@ class CI_DB_active_record extends CI_DB_driver { { $match[1] = $this->_protect_identifiers($match[1]); $match[3] = $this->_protect_identifiers($match[3]); - - $cond = $match[1].$match[2].$match[3]; + + $cond = $match[1].$match[2].$match[3]; } - + // Assemble the JOIN statement $join = $type.'JOIN '.$this->_protect_identifiers($table, TRUE, NULL, FALSE).' ON '.$cond; @@ -378,7 +378,7 @@ class CI_DB_active_record extends CI_DB_driver { { return $this->_where($key, $value, 'AND ', $escape); } - + // -------------------------------------------------------------------- /** @@ -416,7 +416,7 @@ class CI_DB_active_record extends CI_DB_driver { { $key = array($key => $value); } - + // If the escape value was not set will will base it on the global setting if ( ! is_bool($escape)) { @@ -432,13 +432,13 @@ class CI_DB_active_record extends CI_DB_driver { // value appears not to have been set, assign the test to IS NULL $k .= ' IS NULL'; } - + if ( ! is_null($v)) { if ($escape === TRUE) { $k = $this->_protect_identifiers($k, FALSE, $escape); - + $v = ' '.$this->escape($v); } @@ -449,19 +449,19 @@ class CI_DB_active_record extends CI_DB_driver { } else { - $k = $this->_protect_identifiers($k, FALSE, $escape); + $k = $this->_protect_identifiers($k, FALSE, $escape); } $this->ar_where[] = $prefix.$k.$v; - + if ($this->ar_caching === TRUE) { $this->ar_cache_where[] = $prefix.$k.$v; $this->ar_cache_exists[] = 'where'; } - + } - + return $this; } @@ -482,7 +482,7 @@ class CI_DB_active_record extends CI_DB_driver { { return $this->_where_in($key, $values); } - + // -------------------------------------------------------------------- /** @@ -518,7 +518,7 @@ class CI_DB_active_record extends CI_DB_driver { { return $this->_where_in($key, $values, TRUE); } - + // -------------------------------------------------------------------- /** @@ -548,7 +548,7 @@ class CI_DB_active_record extends CI_DB_driver { * @param string The field to search * @param array The values searched on * @param boolean If the statement would be IN or NOT IN - * @param string + * @param string * @return object */ function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ') @@ -557,12 +557,12 @@ class CI_DB_active_record extends CI_DB_driver { { return; } - + if ( ! is_array($values)) { $values = array($values); } - + $not = ($not) ? ' NOT' : ''; foreach ($values as $value) @@ -571,7 +571,7 @@ class CI_DB_active_record extends CI_DB_driver { } $prefix = (count($this->ar_where) == 0) ? '' : $type; - + $where_in = $prefix . $this->_protect_identifiers($key) . $not . " IN (" . implode(", ", $this->ar_wherein) . ") "; $this->ar_where[] = $where_in; @@ -585,7 +585,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->ar_wherein = array(); return $this; } - + // -------------------------------------------------------------------- /** @@ -621,7 +621,7 @@ class CI_DB_active_record extends CI_DB_driver { { return $this->_like($field, $match, 'AND ', $side, 'NOT'); } - + // -------------------------------------------------------------------- /** @@ -657,7 +657,7 @@ class CI_DB_active_record extends CI_DB_driver { { return $this->_like($field, $match, 'OR ', $side, 'NOT'); } - + // -------------------------------------------------------------------- /** @@ -677,7 +677,7 @@ class CI_DB_active_record extends CI_DB_driver { { $field = array($field => $match); } - + foreach ($field as $k => $v) { $k = $this->_protect_identifiers($k); @@ -711,11 +711,11 @@ class CI_DB_active_record extends CI_DB_driver { $this->ar_cache_like[] = $like_statement; $this->ar_cache_exists[] = 'like'; } - + } return $this; } - + // -------------------------------------------------------------------- /** @@ -731,15 +731,15 @@ class CI_DB_active_record extends CI_DB_driver { { $by = explode(',', $by); } - + foreach ($by as $val) { $val = trim($val); - + if ($val != '') { $this->ar_groupby[] = $this->_protect_identifiers($val); - + if ($this->ar_caching === TRUE) { $this->ar_cache_groupby[] = $this->_protect_identifiers($val); @@ -766,7 +766,7 @@ class CI_DB_active_record extends CI_DB_driver { { return $this->_having($key, $value, 'AND ', $escape); } - + // -------------------------------------------------------------------- /** @@ -783,7 +783,7 @@ class CI_DB_active_record extends CI_DB_driver { { return $this->_having($key, $value, 'OR ', $escape); } - + // -------------------------------------------------------------------- /** @@ -802,7 +802,7 @@ class CI_DB_active_record extends CI_DB_driver { { $key = array($key => $value); } - + foreach ($key as $k => $v) { $prefix = (count($this->ar_having) == 0) ? '' : $type; @@ -821,7 +821,7 @@ class CI_DB_active_record extends CI_DB_driver { { $v = ' '.$this->escape_str($v); } - + $this->ar_having[] = $prefix.$k.$v; if ($this->ar_caching === TRUE) { @@ -829,10 +829,10 @@ class CI_DB_active_record extends CI_DB_driver { $this->ar_cache_exists[] = 'having'; } } - + return $this; } - + // -------------------------------------------------------------------- /** @@ -854,8 +854,8 @@ class CI_DB_active_record extends CI_DB_driver { { $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' '.$direction : ' ASC'; } - - + + if (strpos($orderby, ',') !== FALSE) { $temp = array(); @@ -866,19 +866,19 @@ class CI_DB_active_record extends CI_DB_driver { { $part = $this->_protect_identifiers(trim($part)); } - + $temp[] = $part; } - - $orderby = implode(', ', $temp); + + $orderby = implode(', ', $temp); } else if ($direction != $this->_random_keyword) { $orderby = $this->_protect_identifiers($orderby); } - + $orderby_statement = $orderby.$direction; - + $this->ar_orderby[] = $orderby_statement; if ($this->ar_caching === TRUE) { @@ -888,7 +888,7 @@ class CI_DB_active_record extends CI_DB_driver { return $this; } - + // -------------------------------------------------------------------- /** @@ -907,10 +907,10 @@ class CI_DB_active_record extends CI_DB_driver { { $this->ar_offset = $offset; } - + return $this; } - + // -------------------------------------------------------------------- /** @@ -925,7 +925,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->ar_offset = $offset; return $this; } - + // -------------------------------------------------------------------- /** @@ -940,11 +940,11 @@ class CI_DB_active_record extends CI_DB_driver { function set($key, $value = '', $escape = TRUE) { $key = $this->_object_to_array($key); - + if ( ! is_array($key)) { $key = array($key => $value); - } + } foreach ($key as $k => $v) { @@ -957,10 +957,10 @@ class CI_DB_active_record extends CI_DB_driver { $this->ar_set[$this->_protect_identifiers($k)] = $this->escape($v); } } - + return $this; } - + // -------------------------------------------------------------------- /** @@ -982,12 +982,12 @@ class CI_DB_active_record extends CI_DB_driver { $this->_track_aliases($table); $this->from($table); } - + if ( ! is_null($limit)) { $this->limit($limit, $offset); } - + $sql = $this->_compile_select(); $result = $this->query($sql); @@ -998,7 +998,7 @@ class CI_DB_active_record extends CI_DB_driver { /** * "Count All Results" query * - * Generates a platform-specific query string that counts all records + * Generates a platform-specific query string that counts all records * returned by an Active Record query. * * @access public @@ -1012,12 +1012,12 @@ class CI_DB_active_record extends CI_DB_driver { $this->_track_aliases($table); $this->from($table); } - + $sql = $this->_compile_select($this->_count_string . $this->_protect_identifiers('numrows')); $query = $this->query($sql); $this->_reset_select(); - + if ($query->num_rows() == 0) { return '0'; @@ -1051,12 +1051,12 @@ class CI_DB_active_record extends CI_DB_driver { { $this->where($where); } - + if ( ! is_null($limit)) { $this->limit($limit, $offset); } - + $sql = $this->_compile_select(); $result = $this->query($sql); @@ -1077,17 +1077,17 @@ class CI_DB_active_record extends CI_DB_driver { * @return object */ function insert_batch($table = '', $set = NULL) - { + { if ( ! is_null($set)) { $this->set_insert_batch($set); } - + if (count($this->ar_set) == 0) { if ($this->db_debug) { - //No valid data array. Folds in cases where keys and values did not match up + //No valid data array. Folds in cases where keys and values did not match up return $this->display_error('db_must_use_set'); } return FALSE; @@ -1103,25 +1103,25 @@ class CI_DB_active_record extends CI_DB_driver { } return FALSE; } - + $table = $this->ar_from[0]; } // Batch this baby for ($i = 0, $total = count($this->ar_set); $i < $total; $i = $i + 100) { - + $sql = $this->_insert_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_keys, array_slice($this->ar_set, $i, 100)); //echo $sql; $this->query($sql); } - + $this->_reset_write(); - return TRUE; + return TRUE; } // -------------------------------------------------------------------- @@ -1139,26 +1139,26 @@ class CI_DB_active_record extends CI_DB_driver { function set_insert_batch($key, $value = '', $escape = TRUE) { $key = $this->_object_to_array_batch($key); - + if ( ! is_array($key)) { $key = array($key => $value); - } + } $keys = array_keys(current($key)); sort($keys); foreach ($key as $row) { - if (count(array_diff($keys, array_keys($row))) > 0 OR count(array_diff(array_keys($row), $keys)) > 0) - { - // batch function above returns an error on an empty array - $this->ar_set[] = array(); - return; - } - - ksort($row); // puts $row in the same order as our keys + if (count(array_diff($keys, array_keys($row))) > 0 OR count(array_diff(array_keys($row), $keys)) > 0) + { + // batch function above returns an error on an empty array + $this->ar_set[] = array(); + return; + } + ksort($row); // puts $row in the same order as our keys + if ($escape === FALSE) { $this->ar_set[] = '('.implode(',', $row).')'; @@ -1169,18 +1169,18 @@ class CI_DB_active_record extends CI_DB_driver { foreach($row as $value) { - $clean[] = $this->escape($value); + $clean[] = $this->escape($value); } - $this->ar_set[] = '('.implode(',', $clean).')'; - } + $this->ar_set[] = '('.implode(',', $clean).')'; + } } foreach ($keys as $k) { $this->ar_keys[] = $this->_protect_identifiers($k); } - + return $this; } @@ -1197,12 +1197,12 @@ class CI_DB_active_record extends CI_DB_driver { * @return object */ function insert($table = '', $set = NULL) - { + { if ( ! is_null($set)) { $this->set($set); } - + if (count($this->ar_set) == 0) { if ($this->db_debug) @@ -1222,23 +1222,23 @@ class CI_DB_active_record extends CI_DB_driver { } return FALSE; } - + $table = $this->ar_from[0]; } $sql = $this->_insert($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->ar_set), array_values($this->ar_set)); - + $this->_reset_write(); - return $this->query($sql); + return $this->query($sql); } - + function replace($table = '', $set = NULL) { if ( ! is_null($set)) { $this->set($set); } - + if (count($this->ar_set) == 0) { if ($this->db_debug) @@ -1258,14 +1258,14 @@ class CI_DB_active_record extends CI_DB_driver { } return FALSE; } - + $table = $this->ar_from[0]; } $sql = $this->_replace($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->ar_set), array_values($this->ar_set)); - + $this->_reset_write(); - return $this->query($sql); + return $this->query($sql); } // -------------------------------------------------------------------- @@ -1290,7 +1290,7 @@ class CI_DB_active_record extends CI_DB_driver { { $this->set($set); } - + if (count($this->ar_set) == 0) { if ($this->db_debug) @@ -1310,10 +1310,10 @@ class CI_DB_active_record extends CI_DB_driver { } return FALSE; } - + $table = $this->ar_from[0]; } - + if ($where != NULL) { $this->where($where); @@ -1323,9 +1323,9 @@ class CI_DB_active_record extends CI_DB_driver { { $this->limit($limit); } - + $sql = $this->_update($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit); - + $this->_reset_write(); return $this->query($sql); } @@ -1348,7 +1348,7 @@ class CI_DB_active_record extends CI_DB_driver { { // Combine any cached components with the current statements $this->_merge_cache(); - + if (is_null($index)) { if ($this->db_debug) @@ -1384,10 +1384,10 @@ class CI_DB_active_record extends CI_DB_driver { } return FALSE; } - + $table = $this->ar_from[0]; } - + // Batch this baby for ($i = 0, $total = count($this->ar_set); $i < $total; $i = $i + 100) { @@ -1395,7 +1395,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->query($sql); } - + $this->_reset_write(); } @@ -1414,11 +1414,11 @@ class CI_DB_active_record extends CI_DB_driver { function set_update_batch($key, $index = '', $escape = TRUE) { $key = $this->_object_to_array_batch($key); - + if ( ! is_array($key)) { // @todo error - } + } foreach ($key as $k => $v) { @@ -1442,7 +1442,7 @@ class CI_DB_active_record extends CI_DB_driver { } else { - $clean[$this->_protect_identifiers($k2)] = $this->escape($v2); + $clean[$this->_protect_identifiers($k2)] = $this->escape($v2); } } @@ -1453,7 +1453,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->ar_set[] = $clean; } - + return $this; } @@ -1491,7 +1491,7 @@ class CI_DB_active_record extends CI_DB_driver { $sql = $this->_delete($table); $this->_reset_write(); - + return $this->query($sql); } @@ -1531,10 +1531,10 @@ class CI_DB_active_record extends CI_DB_driver { $sql = $this->_truncate($table); $this->_reset_write(); - + return $this->query($sql); } - + // -------------------------------------------------------------------- /** @@ -1600,7 +1600,7 @@ class CI_DB_active_record extends CI_DB_driver { } return FALSE; - } + } $sql = $this->_delete($table, $this->ar_where, $this->ar_like, $this->ar_limit); @@ -1608,7 +1608,7 @@ class CI_DB_active_record extends CI_DB_driver { { $this->_reset_write(); } - + return $this->query($sql); } @@ -1643,7 +1643,7 @@ class CI_DB_active_record extends CI_DB_driver { * @access private * @param string The table to inspect * @return string - */ + */ function _track_aliases($table) { if (is_array($table)) @@ -1654,23 +1654,23 @@ class CI_DB_active_record extends CI_DB_driver { } return; } - + // Does the string contain a comma? If so, we need to separate // the string into discreet statements if (strpos($table, ',') !== FALSE) { return $this->_track_aliases(explode(',', $table)); } - + // if a table alias is used we can recognize it by a space if (strpos($table, " ") !== FALSE) { // if the alias is written with the AS keyword, remove it $table = preg_replace('/ AS /i', ' ', $table); - + // Grab the alias $table = trim(strrchr($table, " ")); - + // Store the alias, if it doesn't already exist if ( ! in_array($table, $this->ar_aliased_tables)) { @@ -1696,7 +1696,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->_merge_cache(); // ---------------------------------------------------------------- - + // Write the "select" portion of the query if ($select_override !== FALSE) @@ -1706,13 +1706,13 @@ class CI_DB_active_record extends CI_DB_driver { else { $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; - + if (count($this->ar_select) == 0) { - $sql .= '*'; + $sql .= '*'; } else - { + { // Cycle through the "select" portion of the query and prep each column name. // The reason we protect identifiers here rather then in the select() function // is because until the user calls the from() function we don't know if there are aliases @@ -1720,13 +1720,13 @@ class CI_DB_active_record extends CI_DB_driver { { $this->ar_select[$key] = $this->_protect_identifiers($val); } - + $sql .= implode(', ', $this->ar_select); } } // ---------------------------------------------------------------- - + // Write the "FROM" portion of the query if (count($this->ar_from) > 0) @@ -1737,7 +1737,7 @@ class CI_DB_active_record extends CI_DB_driver { } // ---------------------------------------------------------------- - + // Write the "JOIN" portion of the query if (count($this->ar_join) > 0) @@ -1748,7 +1748,7 @@ class CI_DB_active_record extends CI_DB_driver { } // ---------------------------------------------------------------- - + // Write the "WHERE" portion of the query if (count($this->ar_where) > 0 OR count($this->ar_like) > 0) @@ -1761,9 +1761,9 @@ class CI_DB_active_record extends CI_DB_driver { $sql .= implode("\n", $this->ar_where); // ---------------------------------------------------------------- - + // Write the "LIKE" portion of the query - + if (count($this->ar_like) > 0) { if (count($this->ar_where) > 0) @@ -1775,20 +1775,20 @@ class CI_DB_active_record extends CI_DB_driver { } // ---------------------------------------------------------------- - + // Write the "GROUP BY" portion of the query - + if (count($this->ar_groupby) > 0) { $sql .= "\nGROUP BY "; - + $sql .= implode(', ', $this->ar_groupby); } // ---------------------------------------------------------------- - + // Write the "HAVING" portion of the query - + if (count($this->ar_having) > 0) { $sql .= "\nHAVING "; @@ -1796,24 +1796,24 @@ class CI_DB_active_record extends CI_DB_driver { } // ---------------------------------------------------------------- - + // Write the "ORDER BY" portion of the query if (count($this->ar_orderby) > 0) { $sql .= "\nORDER BY "; $sql .= implode(', ', $this->ar_orderby); - + if ($this->ar_order !== FALSE) { $sql .= ($this->ar_order == 'desc') ? ' DESC' : ' ASC'; - } + } } // ---------------------------------------------------------------- - + // Write the "LIMIT" portion of the query - + if (is_numeric($this->ar_limit)) { $sql .= "\n"; @@ -1840,7 +1840,7 @@ class CI_DB_active_record extends CI_DB_driver { { return $object; } - + $array = array(); foreach (get_object_vars($object) as $key => $val) { @@ -1853,7 +1853,7 @@ class CI_DB_active_record extends CI_DB_driver { return $array; } - + // -------------------------------------------------------------------- /** @@ -1871,7 +1871,7 @@ class CI_DB_active_record extends CI_DB_driver { { return $object; } - + $array = array(); $out = get_object_vars($object); $fields = array_keys($out); @@ -1893,7 +1893,7 @@ class CI_DB_active_record extends CI_DB_driver { return $array; } - + // -------------------------------------------------------------------- /** @@ -1903,7 +1903,7 @@ class CI_DB_active_record extends CI_DB_driver { * * @access public * @return void - */ + */ function start_cache() { $this->ar_caching = TRUE; @@ -1918,7 +1918,7 @@ class CI_DB_active_record extends CI_DB_driver { * * @access public * @return void - */ + */ function stop_cache() { $this->ar_caching = FALSE; @@ -1933,23 +1933,23 @@ class CI_DB_active_record extends CI_DB_driver { * * @access public * @return void - */ + */ function flush_cache() - { + { $this->_reset_run( array( - 'ar_cache_select' => array(), - 'ar_cache_from' => array(), + 'ar_cache_select' => array(), + 'ar_cache_from' => array(), 'ar_cache_join' => array(), - 'ar_cache_where' => array(), - 'ar_cache_like' => array(), - 'ar_cache_groupby' => array(), - 'ar_cache_having' => array(), - 'ar_cache_orderby' => array(), + 'ar_cache_where' => array(), + 'ar_cache_like' => array(), + 'ar_cache_groupby' => array(), + 'ar_cache_having' => array(), + 'ar_cache_orderby' => array(), 'ar_cache_set' => array(), 'ar_cache_exists' => array() ) - ); + ); } // -------------------------------------------------------------------- @@ -1957,7 +1957,7 @@ class CI_DB_active_record extends CI_DB_driver { /** * Merge Cache * - * When called, this function merges any cached AR arrays with + * When called, this function merges any cached AR arrays with * locally called ones. * * @access private @@ -2022,25 +2022,25 @@ class CI_DB_active_record extends CI_DB_driver { function _reset_select() { $ar_reset_items = array( - 'ar_select' => array(), - 'ar_from' => array(), - 'ar_join' => array(), - 'ar_where' => array(), - 'ar_like' => array(), - 'ar_groupby' => array(), - 'ar_having' => array(), - 'ar_orderby' => array(), - 'ar_wherein' => array(), + 'ar_select' => array(), + 'ar_from' => array(), + 'ar_join' => array(), + 'ar_where' => array(), + 'ar_like' => array(), + 'ar_groupby' => array(), + 'ar_having' => array(), + 'ar_orderby' => array(), + 'ar_wherein' => array(), 'ar_aliased_tables' => array(), - 'ar_distinct' => FALSE, - 'ar_limit' => FALSE, - 'ar_offset' => FALSE, + 'ar_distinct' => FALSE, + 'ar_limit' => FALSE, + 'ar_offset' => FALSE, 'ar_order' => FALSE, ); - + $this->_reset_run($ar_reset_items); } - + // -------------------------------------------------------------------- /** @@ -2052,21 +2052,21 @@ class CI_DB_active_record extends CI_DB_driver { * @return void */ function _reset_write() - { + { $ar_reset_items = array( - 'ar_set' => array(), - 'ar_from' => array(), - 'ar_where' => array(), + 'ar_set' => array(), + 'ar_from' => array(), + 'ar_where' => array(), 'ar_like' => array(), 'ar_orderby' => array(), - 'ar_keys' => array(), - 'ar_limit' => FALSE, + 'ar_keys' => array(), + 'ar_limit' => FALSE, 'ar_order' => FALSE ); $this->_reset_run($ar_reset_items); } - + } /* End of file DB_active_rec.php */ diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 2606df842..6eff5943e 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -32,14 +32,14 @@ class CI_DB_Cache { * * Grabs the CI super object instance so we can access it. * - */ + */ function CI_DB_Cache(&$db) { // Assign the main CI object to $this->CI // and load the file helper since we use it a lot $this->CI =& get_instance(); $this->db =& $db; - $this->CI->load->helper('file'); + $this->CI->load->helper('file'); } // -------------------------------------------------------------------- @@ -50,7 +50,7 @@ class CI_DB_Cache { * @access public * @param string the path to the cache directory * @return bool - */ + */ function check_path($path = '') { if ($path == '') @@ -59,10 +59,10 @@ class CI_DB_Cache { { return $this->db->cache_off(); } - + $path = $this->db->cachedir; } - + // Add a trailing slash to the path if needed $path = preg_replace("/(.+?)\/*$/", "\\1/", $path); @@ -71,11 +71,11 @@ class CI_DB_Cache { // If the path is wrong we'll turn off caching return $this->db->cache_off(); } - + $this->db->cachedir = $path; return TRUE; } - + // -------------------------------------------------------------------- /** @@ -95,18 +95,18 @@ class CI_DB_Cache { } $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); - + $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); - - $filepath = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'.md5($sql); - + + $filepath = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'.md5($sql); + if (FALSE === ($cachedata = read_file($filepath))) - { + { return FALSE; } - - return unserialize($cachedata); - } + + return unserialize($cachedata); + } // -------------------------------------------------------------------- @@ -124,28 +124,28 @@ class CI_DB_Cache { } $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); - + $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); - + $dir_path = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'; - + $filename = md5($sql); - + if ( ! @is_dir($dir_path)) { if ( ! @mkdir($dir_path, DIR_WRITE_MODE)) { return FALSE; } - - @chmod($dir_path, DIR_WRITE_MODE); + + @chmod($dir_path, DIR_WRITE_MODE); } - + if (write_file($dir_path.$filename, serialize($object)) === FALSE) { return FALSE; } - + @chmod($dir_path.$filename, FILE_WRITE_MODE); return TRUE; } @@ -159,19 +159,19 @@ class CI_DB_Cache { * @return bool */ function delete($segment_one = '', $segment_two = '') - { + { if ($segment_one == '') { $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); } - + if ($segment_two == '') { $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); } - + $dir_path = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'; - + delete_files($dir_path, TRUE); } diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 8e6f88801..cbfa33e78 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -71,13 +71,13 @@ class CI_DB_driver { var $limit_used; - + /** * Constructor. Accepts one parameter containing the database * connection settings. * * @param array - */ + */ function CI_DB_driver($params) { if (is_array($params)) @@ -90,7 +90,7 @@ class CI_DB_driver { log_message('debug', 'Database Driver Class Initialized'); } - + // -------------------------------------------------------------------- /** @@ -99,7 +99,7 @@ class CI_DB_driver { * @access private Called by the constructor * @param mixed * @return void - */ + */ function initialize() { // If an existing connection resource is available @@ -108,9 +108,9 @@ class CI_DB_driver { { return TRUE; } - + // ---------------------------------------------------------------- - + // Connect to the database and set the connection ID $this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect(); @@ -118,7 +118,7 @@ class CI_DB_driver { if ( ! $this->conn_id) { log_message('error', 'Unable to connect to the database'); - + if ($this->db_debug) { $this->display_error('db_unable_to_connect'); @@ -134,12 +134,12 @@ class CI_DB_driver { if ( ! $this->db_select()) { log_message('error', 'Unable to select database: '.$this->database); - + if ($this->db_debug) { $this->display_error('db_unable_to_select', $this->database); } - return FALSE; + return FALSE; } else { @@ -148,14 +148,14 @@ class CI_DB_driver { { return FALSE; } - + return TRUE; } } return TRUE; } - + // -------------------------------------------------------------------- /** @@ -171,26 +171,26 @@ class CI_DB_driver { if ( ! $this->_db_set_charset($this->char_set, $this->dbcollat)) { log_message('error', 'Unable to set database connection charset: '.$this->char_set); - + if ($this->db_debug) { $this->display_error('db_unable_to_set_charset', $this->char_set); } - + return FALSE; } - + return TRUE; } - + // -------------------------------------------------------------------- /** * The name of the platform in use (mysql, mssql, etc...) * * @access public - * @return string - */ + * @return string + */ function platform() { return $this->dbdriver; @@ -203,8 +203,8 @@ class CI_DB_driver { * version of the database being used * * @access public - * @return string - */ + * @return string + */ function version() { if (FALSE === ($sql = $this->_version())) @@ -230,7 +230,7 @@ class CI_DB_driver { return $query->row('ver'); } } - + // -------------------------------------------------------------------- /** @@ -245,8 +245,8 @@ class CI_DB_driver { * @access public * @param string An SQL query string * @param array An array of binding data - * @return mixed - */ + * @return mixed + */ function query($sql, $binds = FALSE, $return_object = TRUE) { if ($sql == '') @@ -279,7 +279,7 @@ class CI_DB_driver { } } } - + // Compile binds if needed if ($binds !== FALSE) { @@ -291,10 +291,10 @@ class CI_DB_driver { { $this->queries[] = $sql; } - + // Start the Query Timer $time_start = list($sm, $ss) = explode(' ', microtime()); - + // Run the Query if (FALSE === ($this->result_id = $this->simple_query($sql))) { @@ -302,7 +302,7 @@ class CI_DB_driver { { $this->query_times[] = 0; } - + // This will trigger a rollback if transactions are being used $this->_trans_status = FALSE; @@ -312,10 +312,10 @@ class CI_DB_driver { // additional queries before displaying the error $error_no = $this->_error_number(); $error_msg = $this->_error_message(); - + // We call this function in order to roll-back queries // if transactions are enabled. If we don't call this here - // the error message will trigger an exit, causing the + // the error message will trigger an exit, causing the // transactions to remain in limbo. $this->trans_complete(); @@ -329,10 +329,10 @@ class CI_DB_driver { ) ); } - + return FALSE; } - + // Stop and aggregate the query time results $time_end = list($em, $es) = explode(' ', microtime()); $this->benchmark += ($em + $es) - ($sm + $ss); @@ -341,10 +341,10 @@ class CI_DB_driver { { $this->query_times[] = ($em + $es) - ($sm + $ss); } - + // Increment the query counter $this->query_count++; - + // Was the query a "write" type? // If so we'll simply return true if ($this->is_write_type($sql) === TRUE) @@ -355,10 +355,10 @@ class CI_DB_driver { { $this->CACHE->delete(); } - + return TRUE; } - + // Return TRUE if we don't need to create a result object // Currently only the Oracle driver uses this when stored // procedures are used @@ -366,11 +366,11 @@ class CI_DB_driver { { return TRUE; } - - // Load and instantiate the result driver - - $driver = $this->load_rdriver(); - $RES = new $driver(); + + // Load and instantiate the result driver + + $driver = $this->load_rdriver(); + $RES = new $driver(); $RES->conn_id = $this->conn_id; $RES->result_id = $this->result_id; @@ -381,10 +381,10 @@ class CI_DB_driver { $RES->limit_used = $this->limit_used; $this->stmt_id = FALSE; } - + // oci8 vars must be set before calling this $RES->num_rows = $RES->num_rows(); - + // Is query caching enabled? If so, we'll serialize the // result object and save it to a cache file. if ($this->cache_on == TRUE AND $this->_cache_init()) @@ -396,17 +396,17 @@ class CI_DB_driver { // result object, so we'll have to compile the data // and save it) $CR = new CI_DB_result(); - $CR->num_rows = $RES->num_rows(); + $CR->num_rows = $RES->num_rows(); $CR->result_object = $RES->result_object(); $CR->result_array = $RES->result_array(); - + // Reset these since cached objects can not utilize resource IDs. $CR->conn_id = NULL; $CR->result_id = NULL; $this->CACHE->write($sql, $CR); } - + return $RES; } @@ -416,8 +416,8 @@ class CI_DB_driver { * Load the result drivers * * @access public - * @return string the name of the result class - */ + * @return string the name of the result class + */ function load_rdriver() { $driver = 'CI_DB_'.$this->dbdriver.'_result'; @@ -427,10 +427,10 @@ class CI_DB_driver { include_once(BASEPATH.'database/DB_result'.EXT); include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result'.EXT); } - + return $driver; } - + // -------------------------------------------------------------------- /** @@ -441,8 +441,8 @@ class CI_DB_driver { * * @access public * @param string the sql query - * @return mixed - */ + * @return mixed + */ function simple_query($sql) { if ( ! $this->conn_id) @@ -452,7 +452,7 @@ class CI_DB_driver { return $this->_execute($sql); } - + // -------------------------------------------------------------------- /** @@ -460,8 +460,8 @@ class CI_DB_driver { * This permits transactions to be disabled at run-time. * * @access public - * @return void - */ + * @return void + */ function trans_off() { $this->trans_enabled = FALSE; @@ -477,23 +477,23 @@ class CI_DB_driver { * a failure of one group will not affect any others * * @access public - * @return void - */ + * @return void + */ function trans_strict($mode = TRUE) { $this->trans_strict = is_bool($mode) ? $mode : TRUE; } - + // -------------------------------------------------------------------- /** * Start Transaction * * @access public - * @return void - */ + * @return void + */ function trans_start($test_mode = FALSE) - { + { if ( ! $this->trans_enabled) { return FALSE; @@ -505,7 +505,7 @@ class CI_DB_driver { $this->_trans_depth += 1; return; } - + $this->trans_begin($test_mode); } @@ -515,27 +515,27 @@ class CI_DB_driver { * Complete Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_complete() { if ( ! $this->trans_enabled) { return FALSE; } - + // When transactions are nested we only begin/commit/rollback the outermost ones if ($this->_trans_depth > 1) { $this->_trans_depth -= 1; return TRUE; } - + // The query() function will set this flag to FALSE in the event that a query failed if ($this->_trans_status === FALSE) { $this->trans_rollback(); - + // If we are NOT running in strict mode, we will reset // the _trans_status flag so that subsequent groups of transactions // will be permitted. @@ -547,7 +547,7 @@ class CI_DB_driver { log_message('debug', 'DB Transaction Failure'); return FALSE; } - + $this->trans_commit(); return TRUE; } @@ -558,8 +558,8 @@ class CI_DB_driver { * Lets you retrieve the transaction flag to determine if it has failed * * @access public - * @return bool - */ + * @return bool + */ function trans_status() { return $this->_trans_status; @@ -573,20 +573,20 @@ class CI_DB_driver { * @access public * @param string the sql statement * @param array an array of bind data - * @return string - */ + * @return string + */ function compile_binds($sql, $binds) { if (strpos($sql, $this->bind_marker) === FALSE) { return $sql; } - + if ( ! is_array($binds)) { $binds = array($binds); } - + // Get the sql segments around the bind markers $segments = explode($this->bind_marker, $sql); @@ -607,7 +607,7 @@ class CI_DB_driver { return $result; } - + // -------------------------------------------------------------------- /** @@ -615,8 +615,8 @@ class CI_DB_driver { * * @access public * @param string An SQL query string - * @return boolean - */ + * @return boolean + */ function is_write_type($sql) { if ( ! preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql)) @@ -625,7 +625,7 @@ class CI_DB_driver { } return TRUE; } - + // -------------------------------------------------------------------- /** @@ -633,34 +633,34 @@ class CI_DB_driver { * * @access public * @param integer The number of decimal places - * @return integer - */ + * @return integer + */ function elapsed_time($decimals = 6) { return number_format($this->benchmark, $decimals); } - + // -------------------------------------------------------------------- /** * Returns the total number of queries * * @access public - * @return integer - */ + * @return integer + */ function total_queries() { return $this->query_count; } - + // -------------------------------------------------------------------- /** * Returns the last query that was executed * * @access public - * @return void - */ + * @return void + */ function last_query() { return end($this->queries); @@ -676,10 +676,10 @@ class CI_DB_driver { * * @access public * @param string - * @return mixed - */ + * @return mixed + */ function escape($str) - { + { if (is_string($str)) { $str = "'".$this->escape_str($str)."'"; @@ -703,14 +703,14 @@ class CI_DB_driver { * * Calls the individual driver for platform * specific escaping for LIKE conditions - * + * * @access public * @param string * @return mixed */ - function escape_like_str($str) - { - return $this->escape_str($str, TRUE); + function escape_like_str($str) + { + return $this->escape_str($str, TRUE); } // -------------------------------------------------------------------- @@ -723,12 +723,12 @@ class CI_DB_driver { * * @access public * @param string the table name - * @return string - */ + * @return string + */ function primary($table = '') - { + { $fields = $this->list_fields($table); - + if ( ! is_array($fields)) { return FALSE; @@ -743,8 +743,8 @@ class CI_DB_driver { * Returns an array of table names * * @access public - * @return array - */ + * @return array + */ function list_tables($constrain_by_prefix = FALSE) { // Is there a cached result? @@ -752,7 +752,7 @@ class CI_DB_driver { { return $this->data_cache['table_names']; } - + if (FALSE === ($sql = $this->_list_tables($constrain_by_prefix))) { if ($this->db_debug) @@ -764,7 +764,7 @@ class CI_DB_driver { $retval = array(); $query = $this->query($sql); - + if ($query->num_rows() > 0) { foreach($query->result_array() as $row) @@ -783,7 +783,7 @@ class CI_DB_driver { $this->data_cache['table_names'] = $retval; return $this->data_cache['table_names']; } - + // -------------------------------------------------------------------- /** @@ -792,10 +792,10 @@ class CI_DB_driver { * @return boolean */ function table_exists($table_name) - { + { return ( ! in_array($this->_protect_identifiers($table_name, TRUE, FALSE, FALSE), $this->list_tables())) ? FALSE : TRUE; } - + // -------------------------------------------------------------------- /** @@ -803,7 +803,7 @@ class CI_DB_driver { * * @access public * @param string the table name - * @return array + * @return array */ function list_fields($table = '') { @@ -812,7 +812,7 @@ class CI_DB_driver { { return $this->data_cache['field_names'][$table]; } - + if ($table == '') { if ($this->db_debug) @@ -821,7 +821,7 @@ class CI_DB_driver { } return FALSE; } - + if (FALSE === ($sql = $this->_list_columns($table))) { if ($this->db_debug) @@ -830,9 +830,9 @@ class CI_DB_driver { } return FALSE; } - + $query = $this->query($sql); - + $retval = array(); foreach($query->result_array() as $row) { @@ -843,9 +843,9 @@ class CI_DB_driver { else { $retval[] = current($row); - } + } } - + $this->data_cache['field_names'][$table] = $retval; return $this->data_cache['field_names'][$table]; } @@ -860,10 +860,10 @@ class CI_DB_driver { * @return boolean */ function field_exists($field_name, $table_name) - { + { return ( ! in_array($field_name, $this->list_fields($table_name))) ? FALSE : TRUE; } - + // -------------------------------------------------------------------- /** @@ -871,8 +871,8 @@ class CI_DB_driver { * * @access public * @param string the table name - * @return object - */ + * @return object + */ function field_data($table = '') { if ($table == '') @@ -883,36 +883,36 @@ class CI_DB_driver { } return FALSE; } - + $query = $this->query($this->_field_data($this->_protect_identifiers($table, TRUE, NULL, FALSE))); return $query->field_data(); - } + } // -------------------------------------------------------------------- - + /** * Generate an insert string * * @access public * @param string the table upon which the query will be performed * @param array an associative array data of key/values - * @return string - */ + * @return string + */ function insert_string($table, $data) { $fields = array(); $values = array(); - + foreach($data as $key => $val) { $fields[] = $this->_escape_identifiers($key); $values[] = $this->escape($val); } - + return $this->_insert($this->_protect_identifiers($table, TRUE, NULL, FALSE), $fields, $values); - } - + } + // -------------------------------------------------------------------- /** @@ -922,15 +922,15 @@ class CI_DB_driver { * @param string the table upon which the query will be performed * @param array an associative array data of key/values * @param mixed the "where" statement - * @return string - */ + * @return string + */ function update_string($table, $data, $where) { if ($where == '') { return false; } - + $fields = array(); foreach($data as $key => $val) { @@ -947,23 +947,23 @@ class CI_DB_driver { foreach ($where as $key => $val) { $prefix = (count($dest) == 0) ? '' : ' AND '; - + if ($val !== '') { if ( ! $this->_has_operator($key)) { $key .= ' ='; } - + $val = ' '.$this->escape($val); } - + $dest[] = $prefix.$key.$val; } - } + } return $this->_update($this->_protect_identifiers($table, TRUE, NULL, FALSE), $fields, $dest); - } + } // -------------------------------------------------------------------- @@ -993,17 +993,17 @@ class CI_DB_driver { * @access public * @param string the function name * @param mixed any parameters needed by the function - * @return mixed - */ + * @return mixed + */ function call_function($function) { $driver = ($this->dbdriver == 'postgre') ? 'pg_' : $this->dbdriver.'_'; - + if (FALSE === strpos($driver, $function)) { $function = $driver.$function; } - + if ( ! function_exists($function)) { if ($this->db_debug) @@ -1028,7 +1028,7 @@ class CI_DB_driver { * @access public * @param string the path to the cache directory * @return void - */ + */ function cache_set_path($path = '') { $this->cachedir = $path; @@ -1041,7 +1041,7 @@ class CI_DB_driver { * * @access public * @return void - */ + */ function cache_on() { $this->cache_on = TRUE; @@ -1055,13 +1055,13 @@ class CI_DB_driver { * * @access public * @return void - */ + */ function cache_off() { $this->cache_on = FALSE; return FALSE; } - + // -------------------------------------------------------------------- @@ -1070,7 +1070,7 @@ class CI_DB_driver { * * @access public * @return void - */ + */ function cache_delete($segment_one = '', $segment_two = '') { if ( ! $this->_cache_init()) @@ -1087,7 +1087,7 @@ class CI_DB_driver { * * @access public * @return void - */ + */ function cache_delete_all() { if ( ! $this->_cache_init()) @@ -1105,7 +1105,7 @@ class CI_DB_driver { * * @access private * @return void - */ + */ function _cache_init() { if (is_object($this->CACHE) AND class_exists('CI_DB_Cache')) @@ -1131,8 +1131,8 @@ class CI_DB_driver { * Close DB Connection * * @access public - * @return void - */ + * @return void + */ function close() { if (is_resource($this->conn_id) OR is_object($this->conn_id)) @@ -1141,7 +1141,7 @@ class CI_DB_driver { } $this->conn_id = FALSE; } - + // -------------------------------------------------------------------- /** @@ -1151,8 +1151,8 @@ class CI_DB_driver { * @param string the error message * @param string any "swap" values * @param boolean whether to localize the message - * @return string sends the application/error_db.php template - */ + * @return string sends the application/error_db.php template + */ function display_error($error = '', $swap = '', $native = FALSE) { $LANG =& load_class('Lang', 'core'); @@ -1168,11 +1168,11 @@ class CI_DB_driver { { $message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error; } - + // Find the most likely culprit of the error by going through // the backtrace until the source file is no longer in the // database folder. - + $trace = debug_backtrace(); foreach($trace as $call) @@ -1182,11 +1182,11 @@ class CI_DB_driver { // Found it - use a relative path for safety $message[] = 'Filename: '.str_replace(array(BASEPATH, APPPATH), '', $call['file']); $message[] = 'Line Number: '.$call['line']; - + break; } } - + $error =& load_class('Exceptions', 'core'); echo $error->show_error($heading, $message, 'error_db'); exit; @@ -1214,7 +1214,7 @@ class CI_DB_driver { * Protect Identifiers * * This function is used extensively by the Active Record class, and by - * a couple functions in this class. + * a couple functions in this class. * It takes a column or table name (optionally with an alias) and inserts * the table prefix onto it. Some logic is necessary in order to deal with * column names that include the path. Consider a query like this: @@ -1236,7 +1236,7 @@ class CI_DB_driver { * @param mixed * @param bool * @return string - */ + */ function _protect_identifiers($item, $prefix_single = FALSE, $protect_identifiers = NULL, $field_exists = TRUE) { if ( ! is_bool($protect_identifiers)) @@ -1258,7 +1258,7 @@ class CI_DB_driver { // Convert tabs or multiple spaces into single spaces $item = preg_replace('/[\t ]+/', ' ', $item); - + // If the item has an alias declaration we remove it and set it aside. // Basically we remove everything to the right of the first space $alias = ''; @@ -1269,7 +1269,7 @@ class CI_DB_driver { } // This is basically a bug fix for queries that use MAX, MIN, etc. - // If a parenthesis is found we know that we do not need to + // If a parenthesis is found we know that we do not need to // escape the data or add a prefix. There's probably a more graceful // way to deal with this, but I'm not thinking of it -- Rick if (strpos($item, '(') !== FALSE) @@ -1283,7 +1283,7 @@ class CI_DB_driver { if (strpos($item, '.') !== FALSE) { $parts = explode('.', $item); - + // Does the first segment of the exploded item match // one of the aliases previously identified? If so, // we have nothing more to do other than escape the item @@ -1298,12 +1298,12 @@ class CI_DB_driver { $parts[$key] = $this->_escape_identifiers($val); } } - + $item = implode('.', $parts); - } + } return $item.$alias; } - + // Is there a table prefix defined in the config file? If not, no need to do anything if ($this->dbprefix != '') { @@ -1326,35 +1326,35 @@ class CI_DB_driver { { $i = 0; } - + // This flag is set when the supplied $item does not contain a field name. // This can happen when this function is being called from a JOIN. if ($field_exists == FALSE) { $i++; } - + // Verify table prefix and replace if necessary if ($this->swap_pre != '' && strncmp($parts[$i], $this->swap_pre, strlen($this->swap_pre)) === 0) { $parts[$i] = preg_replace("/^".$this->swap_pre."(\S+?)/", $this->dbprefix."\\1", $parts[$i]); } - + // We only add the table prefix if it does not already exist if (substr($parts[$i], 0, strlen($this->dbprefix)) != $this->dbprefix) { $parts[$i] = $this->dbprefix.$parts[$i]; } - + // Put the parts back together $item = implode('.', $parts); } - + if ($protect_identifiers === TRUE) { $item = $this->_escape_identifiers($item); } - + return $item.$alias; } @@ -1371,14 +1371,14 @@ class CI_DB_driver { if ($prefix_single == TRUE AND substr($item, 0, strlen($this->dbprefix)) != $this->dbprefix) { $item = $this->dbprefix.$item; - } + } } if ($protect_identifiers === TRUE AND ! in_array($item, $this->_reserved_identifiers)) { $item = $this->_escape_identifiers($item); } - + return $item.$alias; } diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index 8be65e0d6..74aed8610 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -24,9 +24,9 @@ */ class CI_DB_forge { - var $fields = array(); + var $fields = array(); var $keys = array(); - var $primary_keys = array(); + var $primary_keys = array(); var $db_char_set = ''; /** @@ -34,7 +34,7 @@ class CI_DB_forge { * * Grabs the CI super object instance so we can access it. * - */ + */ function CI_DB_forge() { // Assign the main database object to $this->db @@ -55,12 +55,12 @@ class CI_DB_forge { function create_database($db_name) { $sql = $this->_create_database($db_name); - + if (is_bool($sql)) { return $sql; } - + return $this->db->query($sql); } @@ -76,12 +76,12 @@ class CI_DB_forge { function drop_database($db_name) { $sql = $this->_drop_database($db_name); - + if (is_bool($sql)) { return $sql; } - + return $this->db->query($sql); } @@ -103,15 +103,15 @@ class CI_DB_forge { { $this->add_key($one, $primary); } - + return; } - + if ($key == '') { show_error('Key information is required for that operation.'); } - + if ($primary === TRUE) { $this->primary_keys[] = $key; @@ -137,7 +137,7 @@ class CI_DB_forge { { show_error('Field information is required.'); } - + if (is_string($field)) { if ($field == 'id') @@ -157,16 +157,16 @@ class CI_DB_forge { { show_error('Field information is required for that operation.'); } - + $this->fields[] = $field; } } - + if (is_array($field)) { $this->fields = array_merge($this->fields, $field); } - + } // -------------------------------------------------------------------- @@ -179,19 +179,19 @@ class CI_DB_forge { * @return bool */ function create_table($table = '', $if_not_exists = FALSE) - { + { if ($table == '') { show_error('A table name is required for that operation.'); } - + if (count($this->fields) == 0) - { + { show_error('Field information is required.'); } $sql = $this->_create_table($this->db->dbprefix.$table, $this->fields, $this->primary_keys, $this->keys, $if_not_exists); - + $this->_reset(); return $this->db->query($sql); } @@ -208,12 +208,12 @@ class CI_DB_forge { function drop_table($table_name) { $sql = $this->_drop_table($this->db->dbprefix.$table_name); - + if (is_bool($sql)) { return $sql; } - + return $this->db->query($sql); } @@ -233,7 +233,7 @@ class CI_DB_forge { { show_error('A table name is required for that operation.'); } - + $sql = $this->_rename_table($table_name, $new_table_name); return $this->db->query($sql); } @@ -259,25 +259,25 @@ class CI_DB_forge { // add field info into field array, but we can only do one at a time // so we cycle through - foreach ($field as $k => $v) - { - $this->add_field(array($k => $field[$k])); + foreach ($field as $k => $v) + { + $this->add_field(array($k => $field[$k])); if (count($this->fields) == 0) - { + { show_error('Field information is required.'); } - + $sql = $this->_alter_table('ADD', $this->db->dbprefix.$table, $this->fields, $after_field); $this->_reset(); - + if ($this->db->query($sql) === FALSE) { return FALSE; } } - + return TRUE; } @@ -294,7 +294,7 @@ class CI_DB_forge { */ function drop_column($table = '', $column_name = '') { - + if ($table == '') { show_error('A table name is required for that operation.'); @@ -306,7 +306,7 @@ class CI_DB_forge { } $sql = $this->_alter_table('DROP', $this->db->dbprefix.$table, $column_name); - + return $this->db->query($sql); } @@ -336,20 +336,20 @@ class CI_DB_forge { $this->add_field(array($k => $field[$k])); if (count($this->fields) == 0) - { + { show_error('Field information is required.'); } - + $sql = $this->_alter_table('CHANGE', $this->db->dbprefix.$table, $this->fields); $this->_reset(); - + if ($this->db->query($sql) === FALSE) { return FALSE; } } - + return TRUE; } @@ -365,9 +365,9 @@ class CI_DB_forge { */ function _reset() { - $this->fields = array(); + $this->fields = array(); $this->keys = array(); - $this->primary_keys = array(); + $this->primary_keys = array(); } } diff --git a/system/database/DB_result.php b/system/database/DB_result.php index b9e64feeb..406afb1b8 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -32,7 +32,7 @@ class CI_DB_result { var $result_id = NULL; var $result_array = array(); var $result_object = array(); - var $current_row = 0; + var $current_row = 0; var $num_rows = 0; var $row_data = NULL; @@ -42,10 +42,10 @@ class CI_DB_result { * * @access public * @param string can be "object" or "array" - * @return mixed either a result object or array - */ + * @return mixed either a result object or array + */ function result($type = 'object') - { + { return ($type == 'object') ? $this->result_object() : $this->result_array(); } @@ -56,16 +56,16 @@ class CI_DB_result { * * @access public * @return object - */ + */ function result_object() { if (count($this->result_object) > 0) { return $this->result_object; } - - // In the event that query caching is on the result_id variable - // will return FALSE since there isn't a valid SQL resource so + + // In the event that query caching is on the result_id variable + // will return FALSE since there isn't a valid SQL resource so // we'll simply return an empty array. if ($this->result_id === FALSE OR $this->num_rows() == 0) { @@ -77,10 +77,10 @@ class CI_DB_result { { $this->result_object[] = $row; } - + return $this->result_object; } - + // -------------------------------------------------------------------- /** @@ -88,7 +88,7 @@ class CI_DB_result { * * @access public * @return array - */ + */ function result_array() { if (count($this->result_array) > 0) @@ -96,8 +96,8 @@ class CI_DB_result { return $this->result_array; } - // In the event that query caching is on the result_id variable - // will return FALSE since there isn't a valid SQL resource so + // In the event that query caching is on the result_id variable + // will return FALSE since there isn't a valid SQL resource so // we'll simply return an empty array. if ($this->result_id === FALSE OR $this->num_rows() == 0) { @@ -109,7 +109,7 @@ class CI_DB_result { { $this->result_array[] = $row; } - + return $this->result_array; } @@ -121,8 +121,8 @@ class CI_DB_result { * @access public * @param string * @param string can be "object" or "array" - * @return mixed either a result object or array - */ + * @return mixed either a result object or array + */ function row($n = 0, $type = 'object') { if ( ! is_numeric($n)) @@ -132,16 +132,16 @@ class CI_DB_result { { $this->row_data = $this->row_array(0); } - + // array_key_exists() instead of isset() to allow for MySQL NULL values if (array_key_exists($n, $this->row_data)) { return $this->row_data[$n]; } - // reset the $n variable if the result was not achieved + // reset the $n variable if the result was not achieved $n = 0; } - + return ($type == 'object') ? $this->row_object($n) : $this->row_array($n); } @@ -152,7 +152,7 @@ class CI_DB_result { * * @access public * @return object - */ + */ function set_row($key, $value = NULL) { // We cache the row data for subsequent uses @@ -160,17 +160,17 @@ class CI_DB_result { { $this->row_data = $this->row_array(0); } - + if (is_array($key)) { foreach ($key as $k => $v) { $this->row_data[$k] = $v; } - + return; } - + if ($key != '' AND ! is_null($value)) { $this->row_data[$key] = $value; @@ -184,11 +184,11 @@ class CI_DB_result { * * @access public * @return object - */ + */ function row_object($n = 0) { $result = $this->result_object(); - + if (count($result) == 0) { return $result; @@ -209,7 +209,7 @@ class CI_DB_result { * * @access public * @return array - */ + */ function row_array($n = 0) { $result = $this->result_array(); @@ -218,16 +218,16 @@ class CI_DB_result { { return $result; } - + if ($n != $this->current_row AND isset($result[$n])) { $this->current_row = $n; } - + return $result[$this->current_row]; } - + // -------------------------------------------------------------------- /** @@ -235,7 +235,7 @@ class CI_DB_result { * * @access public * @return object - */ + */ function first_row($type = 'object') { $result = $this->result($type); @@ -246,7 +246,7 @@ class CI_DB_result { } return $result[0]; } - + // -------------------------------------------------------------------- /** @@ -254,7 +254,7 @@ class CI_DB_result { * * @access public * @return object - */ + */ function last_row($type = 'object') { $result = $this->result($type); @@ -264,7 +264,7 @@ class CI_DB_result { return $result; } return $result[count($result) -1]; - } + } // -------------------------------------------------------------------- @@ -273,7 +273,7 @@ class CI_DB_result { * * @access public * @return object - */ + */ function next_row($type = 'object') { $result = $this->result($type); @@ -287,10 +287,10 @@ class CI_DB_result { { ++$this->current_row; } - + return $result[$this->current_row]; } - + // -------------------------------------------------------------------- /** @@ -298,7 +298,7 @@ class CI_DB_result { * * @access public * @return object - */ + */ function previous_row($type = 'object') { $result = $this->result($type); @@ -329,12 +329,12 @@ class CI_DB_result { function num_rows() { return $this->num_rows; } function num_fields() { return 0; } function list_fields() { return array(); } - function field_data() { return array(); } + function field_data() { return array(); } function free_result() { return TRUE; } function _data_seek() { return TRUE; } - function _fetch_assoc() { return array(); } + function _fetch_assoc() { return array(); } function _fetch_object() { return array(); } - + } // END DB_result class diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 124967a5a..2811d8802 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -25,20 +25,20 @@ class CI_DB_utility extends CI_DB_forge { var $db; - var $data_cache = array(); + var $data_cache = array(); /** * Constructor * * Grabs the CI super object instance so we can access it. * - */ + */ function CI_DB_utility() { // Assign the main database object to $this->db $CI =& get_instance(); $this->db =& $CI->db; - + log_message('debug', "Database Utility Class Initialized"); } @@ -51,13 +51,13 @@ class CI_DB_utility extends CI_DB_forge { * @return bool */ function list_databases() - { + { // Is there a cached result? if (isset($this->data_cache['db_names'])) { return $this->data_cache['db_names']; } - + $query = $this->db->query($this->_list_databases()); $dbs = array(); if ($query->num_rows() > 0) @@ -67,7 +67,7 @@ class CI_DB_utility extends CI_DB_forge { $dbs[] = current($row); } } - + $this->data_cache['db_names'] = $dbs; return $this->data_cache['db_names']; } @@ -109,15 +109,15 @@ class CI_DB_utility extends CI_DB_forge { function optimize_table($table_name) { $sql = $this->_optimize_table($table_name); - + if (is_bool($sql)) { show_error('db_must_use_set'); } - + $query = $this->db->query($sql); $res = $query->result_array(); - + // Note: Due to a bug in current() that affects some versions // of PHP we can not pass function call directly into it return current($res); @@ -137,14 +137,14 @@ class CI_DB_utility extends CI_DB_forge { foreach ($this->db->list_tables() as $table_name) { $sql = $this->_optimize_table($table_name); - + if (is_bool($sql)) { return $sql; } - + $query = $this->db->query($sql); - + // Build the result array... // Note: Due to a bug in current() that affects some versions // of PHP we can not pass function call directly into it @@ -153,7 +153,7 @@ class CI_DB_utility extends CI_DB_forge { $key = str_replace($this->db->database.'.', '', current($res)); $keys = array_keys($res); unset($res[$keys[0]]); - + $result[$key] = $res; } @@ -172,20 +172,20 @@ class CI_DB_utility extends CI_DB_forge { function repair_table($table_name) { $sql = $this->_repair_table($table_name); - + if (is_bool($sql)) { return $sql; } - + $query = $this->db->query($sql); - + // Note: Due to a bug in current() that affects some versions // of PHP we can not pass function call directly into it $res = $query->result_array(); return current($res); } - + // -------------------------------------------------------------------- /** @@ -203,25 +203,25 @@ class CI_DB_utility extends CI_DB_forge { if ( ! is_object($query) OR ! method_exists($query, 'list_fields')) { show_error('You must submit a valid result object'); - } - + } + $out = ''; - + // First generate the headings from the table column names foreach ($query->list_fields() as $name) { $out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $name).$enclosure.$delim; } - + $out = rtrim($out); $out .= $newline; - + // Next blast through the result array and build out the rows foreach ($query->result_array() as $row) { foreach ($row as $item) { - $out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $item).$enclosure.$delim; + $out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $item).$enclosure.$delim; } $out = rtrim($out); $out .= $newline; @@ -229,7 +229,7 @@ class CI_DB_utility extends CI_DB_forge { return $out; } - + // -------------------------------------------------------------------- /** @@ -246,7 +246,7 @@ class CI_DB_utility extends CI_DB_forge { { show_error('You must submit a valid result object'); } - + // Set our default values foreach (array('root' => 'root', 'element' => 'element', 'newline' => "\n", 'tab' => "\t") as $key => $val) { @@ -255,10 +255,10 @@ class CI_DB_utility extends CI_DB_forge { $params[$key] = $val; } } - + // Create variables for convenience extract($params); - + // Load the xml helper $CI =& get_instance(); $CI->load->helper('xml'); @@ -268,7 +268,7 @@ class CI_DB_utility extends CI_DB_forge { foreach ($query->result_array() as $row) { $xml .= $tab."<{$element}>".$newline; - + foreach ($row as $key => $val) { $xml .= $tab.$tab."<{$key}>".xml_convert($val)."".$newline; @@ -276,7 +276,7 @@ class CI_DB_utility extends CI_DB_forge { $xml .= $tab."".$newline; } $xml .= "".$newline; - + return $xml; } @@ -297,9 +297,9 @@ class CI_DB_utility extends CI_DB_forge { { $params = array('tables' => $params); } - + // ------------------------------------------------------ - + // Set up our default preferences $prefs = array( 'tables' => array(), @@ -325,13 +325,13 @@ class CI_DB_utility extends CI_DB_forge { // ------------------------------------------------------ - // Are we backing up a complete database or individual tables? + // Are we backing up a complete database or individual tables? // If no table names were submitted we'll fetch the entire table list if (count($prefs['tables']) == 0) { $prefs['tables'] = $this->db->list_tables(); } - + // ------------------------------------------------------ // Validate the format @@ -345,13 +345,13 @@ class CI_DB_utility extends CI_DB_forge { // Is the encoder supported? If not, we'll either issue an // error or use plain text depending on the debug settings if (($prefs['format'] == 'gzip' AND ! @function_exists('gzencode')) - OR ($prefs['format'] == 'zip' AND ! @function_exists('gzcompress'))) + OR ($prefs['format'] == 'zip' AND ! @function_exists('gzcompress'))) { if ($this->db->db_debug) { return $this->db->display_error('db_unsuported_compression'); } - + $prefs['format'] = 'txt'; } @@ -365,7 +365,7 @@ class CI_DB_utility extends CI_DB_forge { } // ------------------------------------------------------ - + // Was a Gzip file requested? if ($prefs['format'] == 'gzip') { @@ -373,7 +373,7 @@ class CI_DB_utility extends CI_DB_forge { } // ------------------------------------------------------ - + // Was a text file requested? if ($prefs['format'] == 'txt') { @@ -382,7 +382,7 @@ class CI_DB_utility extends CI_DB_forge { // ------------------------------------------------------ - // Was a Zip file requested? + // Was a Zip file requested? if ($prefs['format'] == 'zip') { // If they included the .zip file extension we'll remove it @@ -390,7 +390,7 @@ class CI_DB_utility extends CI_DB_forge { { $prefs['filename'] = str_replace('.zip', '', $prefs['filename']); } - + // Tack on the ".sql" file extension if needed if ( ! preg_match("|.+?\.sql$|", $prefs['filename'])) { @@ -398,13 +398,13 @@ class CI_DB_utility extends CI_DB_forge { } // Load the Zip class and output it - + $CI =& get_instance(); $CI->load->library('zip'); - $CI->zip->add_data($prefs['filename'], $this->_backup($prefs)); + $CI->zip->add_data($prefs['filename'], $this->_backup($prefs)); return $CI->zip->get_zip(); } - + } } diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 40900e832..63f9e9cc3 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -31,14 +31,14 @@ class CI_DB_mssql_driver extends CI_DB { var $dbdriver = 'mssql'; - + // The character used for escaping var $_escape_char = ''; // clause and character used for LIKE escape sequences var $_like_escape_str = " ESCAPE '%s' "; var $_like_escape_chr = '!'; - + /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is @@ -52,7 +52,7 @@ class CI_DB_mssql_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_connect() { if ($this->port != '') @@ -62,7 +62,7 @@ class CI_DB_mssql_driver extends CI_DB { return @mssql_connect($this->hostname, $this->username, $this->password); } - + // -------------------------------------------------------------------- /** @@ -70,7 +70,7 @@ class CI_DB_mssql_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_pconnect() { if ($this->port != '') @@ -80,9 +80,9 @@ class CI_DB_mssql_driver extends CI_DB { return @mssql_pconnect($this->hostname, $this->username, $this->password); } - + // -------------------------------------------------------------------- - + /** * Reconnect * @@ -98,13 +98,13 @@ class CI_DB_mssql_driver extends CI_DB { } // -------------------------------------------------------------------- - + /** * Select the database * * @access private called by the base class * @return resource - */ + */ function db_select() { // Note: The brackets are required in the event that the DB name @@ -113,7 +113,7 @@ class CI_DB_mssql_driver extends CI_DB { } // -------------------------------------------------------------------- - + /** * Set client character set * @@ -129,20 +129,20 @@ class CI_DB_mssql_driver extends CI_DB { } // -------------------------------------------------------------------- - + /** * Execute the query * * @access private called by the base class * @param string an SQL query * @return resource - */ + */ function _execute($sql) { $sql = $this->_prep_query($sql); return @mssql_query($sql, $this->conn_id); } - + // -------------------------------------------------------------------- /** @@ -153,7 +153,7 @@ class CI_DB_mssql_driver extends CI_DB { * @access private called by execute() * @param string an SQL query * @return string - */ + */ function _prep_query($sql) { return $sql; @@ -165,15 +165,15 @@ class CI_DB_mssql_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) { @@ -195,8 +195,8 @@ class CI_DB_mssql_driver extends CI_DB { * Commit Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_commit() { if ( ! $this->trans_enabled) @@ -220,8 +220,8 @@ class CI_DB_mssql_driver extends CI_DB { * Rollback Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_rollback() { if ( ! $this->trans_enabled) @@ -238,7 +238,7 @@ class CI_DB_mssql_driver extends CI_DB { $this->simple_query('ROLLBACK TRAN'); return TRUE; } - + // -------------------------------------------------------------------- /** @@ -254,16 +254,16 @@ class CI_DB_mssql_driver extends CI_DB { if (is_array($str)) { foreach($str as $key => $val) - { + { $str[$key] = $this->escape_str($val, $like); - } - - return $str; - } - + } + + return $str; + } + // Escape single quotes $str = str_replace("'", "''", remove_invisible_characters($str)); - + // escape LIKE condition wildcards if ($like === TRUE) { @@ -271,10 +271,10 @@ class CI_DB_mssql_driver extends CI_DB { array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr), $str); } - + return $str; } - + // -------------------------------------------------------------------- /** @@ -287,7 +287,7 @@ class CI_DB_mssql_driver extends CI_DB { { return @mssql_rows_affected($this->conn_id); } - + // -------------------------------------------------------------------- /** @@ -312,7 +312,7 @@ class CI_DB_mssql_driver extends CI_DB { /** * Parse major version * - * Grabs the major version number from the + * Grabs the major version number from the * database server version string passed in. * * @access private @@ -382,14 +382,14 @@ class CI_DB_mssql_driver extends CI_DB { function _list_tables($prefix_limit = FALSE) { $sql = "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; - + // for future compatibility if ($prefix_limit !== FALSE AND $this->dbprefix != '') { //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); return FALSE; // not currently supported } - + return $sql; } @@ -406,7 +406,7 @@ class CI_DB_mssql_driver extends CI_DB { */ function _list_columns($table = '') { - return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$table."'"; + return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$table."'"; } // -------------------------------------------------------------------- @@ -422,7 +422,7 @@ class CI_DB_mssql_driver extends CI_DB { */ function _field_data($table) { - return "SELECT TOP 1 * FROM ".$table; + return "SELECT TOP 1 * FROM ".$table; } // -------------------------------------------------------------------- @@ -437,7 +437,7 @@ class CI_DB_mssql_driver extends CI_DB { { return mssql_get_last_message(); } - + // -------------------------------------------------------------------- /** @@ -474,26 +474,26 @@ class CI_DB_mssql_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); } - + // -------------------------------------------------------------------- /** @@ -512,12 +512,12 @@ class CI_DB_mssql_driver extends CI_DB { { $tables = array($tables); } - + return implode(', ', $tables); } // -------------------------------------------------------------------- - + /** * Insert statement * @@ -530,10 +530,10 @@ class CI_DB_mssql_driver extends CI_DB { * @return string */ function _insert($table, $keys, $values) - { + { return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } - + // -------------------------------------------------------------------- /** @@ -555,21 +555,21 @@ class CI_DB_mssql_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; } - + // -------------------------------------------------------------------- /** @@ -582,12 +582,12 @@ class CI_DB_mssql_driver extends CI_DB { * @access public * @param string the table name * @return string - */ + */ function _truncate($table) { return "TRUNCATE ".$table; } - + // -------------------------------------------------------------------- /** @@ -600,7 +600,7 @@ class CI_DB_mssql_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 = ''; @@ -618,7 +618,7 @@ class CI_DB_mssql_driver extends CI_DB { } $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - + return "DELETE FROM ".$table.$conditions.$limit; } @@ -638,8 +638,8 @@ class CI_DB_mssql_driver extends CI_DB { function _limit($sql, $limit, $offset) { $i = $limit + $offset; - - return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql); + + return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql); } // -------------------------------------------------------------------- @@ -654,7 +654,7 @@ class CI_DB_mssql_driver extends CI_DB { function _close($conn_id) { @mssql_close($conn_id); - } + } } diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php index f6a17811f..5aa4406b1 100644 --- a/system/database/drivers/mssql/mssql_forge.php +++ b/system/database/drivers/mssql/mssql_forge.php @@ -79,12 +79,12 @@ class CI_DB_mssql_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)." ("; $current_field_count = 0; @@ -100,41 +100,41 @@ class CI_DB_mssql_forge extends CI_DB_forge { else { $attributes = array_change_key_case($attributes, CASE_UPPER); - + $sql .= "\n\t".$this->db->_protect_identifiers($field); - + $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) && $attributes['NULL'] === TRUE) { $sql .= ' NULL'; } else { - $sql .= ' NOT NULL'; + $sql .= ' 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)) { @@ -147,24 +147,24 @@ class CI_DB_mssql_forge extends CI_DB_forge { $primary_keys = $this->db->_protect_identifiers($primary_keys); $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; } - + if (is_array($keys) && count($keys) > 0) { foreach ($keys as $key) { if (is_array($key)) { - $key = $this->db->_protect_identifiers($key); + $key = $this->db->_protect_identifiers($key); } else { $key = array($this->db->_protect_identifiers($key)); } - + $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")"; } } - + $sql .= "\n)"; return $sql; @@ -218,9 +218,9 @@ class CI_DB_mssql_forge extends CI_DB_forge { { $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); } - + return $sql; - + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index e7b338045..09b1ec80b 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -25,7 +25,7 @@ * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_mssql_result extends CI_DB_result { - + /** * Number of rows in the result set * @@ -36,7 +36,7 @@ class CI_DB_mssql_result extends CI_DB_result { { return @mssql_num_rows($this->result_id); } - + // -------------------------------------------------------------------- /** @@ -67,7 +67,7 @@ class CI_DB_mssql_result extends CI_DB_result { { $field_names[] = $field->name; } - + return $field_names; } @@ -85,17 +85,17 @@ class CI_DB_mssql_result extends CI_DB_result { { $retval = array(); while ($field = mssql_fetch_field($this->result_id)) - { - $F = new stdClass(); - $F->name = $field->name; - $F->type = $field->type; + { + $F = new stdClass(); + $F->name = $field->name; + $F->type = $field->type; $F->max_length = $field->max_length; $F->primary_key = 0; $F->default = ''; - + $retval[] = $F; } - + return $retval; } @@ -105,7 +105,7 @@ class CI_DB_mssql_result extends CI_DB_result { * Free the result * * @return null - */ + */ function free_result() { if (is_resource($this->result_id)) @@ -131,7 +131,7 @@ class CI_DB_mssql_result extends CI_DB_result { { return mssql_data_seek($this->result_id, $n); } - + // -------------------------------------------------------------------- /** @@ -146,7 +146,7 @@ class CI_DB_mssql_result extends CI_DB_result { { return mssql_fetch_assoc($this->result_id); } - + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index 751be146c..e58c7e0c3 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -52,7 +52,7 @@ class CI_DB_mssql_utility extends CI_DB_utility { } // -------------------------------------------------------------------- - + /** * Repair table query * 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; } diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index d0e2defec..69e092839 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -31,7 +31,7 @@ class CI_DB_mysqli_driver extends CI_DB { var $dbdriver = 'mysqli'; - + // The character used for escaping var $_escape_char = '`'; @@ -51,7 +51,7 @@ class CI_DB_mysqli_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; // -------------------------------------------------------------------- @@ -61,12 +61,12 @@ class CI_DB_mysqli_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_connect() { if ($this->port != '') { - return @mysqli_connect($this->hostname, $this->username, $this->password, $this->database, $this->port); + return @mysqli_connect($this->hostname, $this->username, $this->password, $this->database, $this->port); } else { @@ -82,12 +82,12 @@ class CI_DB_mysqli_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_pconnect() { return $this->db_connect(); } - + // -------------------------------------------------------------------- /** @@ -114,7 +114,7 @@ class CI_DB_mysqli_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_select() { return @mysqli_select_db($this->conn_id, $this->database); @@ -136,7 +136,7 @@ class CI_DB_mysqli_driver extends CI_DB { } // -------------------------------------------------------------------- - + /** * Version number query string * @@ -156,14 +156,14 @@ class CI_DB_mysqli_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); + $sql = $this->_prep_query($sql); $result = @mysqli_query($this->conn_id, $sql); return $result; } - + // -------------------------------------------------------------------- /** @@ -174,7 +174,7 @@ class CI_DB_mysqli_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 @@ -186,7 +186,7 @@ class CI_DB_mysqli_driver extends CI_DB { $sql = preg_replace("/^\s*DELETE\s+FROM\s+(\S+)\s*$/", "DELETE FROM \\1 WHERE 1=1", $sql); } } - + return $sql; } @@ -196,15 +196,15 @@ class CI_DB_mysqli_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) { @@ -227,8 +227,8 @@ class CI_DB_mysqli_driver extends CI_DB { * Commit Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_commit() { if ( ! $this->trans_enabled) @@ -253,8 +253,8 @@ class CI_DB_mysqli_driver extends CI_DB { * Rollback Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_rollback() { if ( ! $this->trans_enabled) @@ -283,17 +283,17 @@ class CI_DB_mysqli_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('mysqli_real_escape_string') AND is_object($this->conn_id)) { @@ -307,16 +307,16 @@ class CI_DB_mysqli_driver extends CI_DB { { $str = addslashes($str); } - + // escape LIKE condition wildcards if ($like === TRUE) { $str = str_replace(array('%', '_'), array('\\%', '\\_'), $str); } - + return $str; } - + // -------------------------------------------------------------------- /** @@ -329,7 +329,7 @@ class CI_DB_mysqli_driver extends CI_DB { { return @mysqli_affected_rows($this->conn_id); } - + // -------------------------------------------------------------------- /** @@ -386,13 +386,13 @@ class CI_DB_mysqli_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 != '') { $sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%'"; } - + return $sql; } @@ -440,7 +440,7 @@ class CI_DB_mysqli_driver extends CI_DB { { return mysqli_error($this->conn_id); } - + // -------------------------------------------------------------------- /** @@ -471,31 +471,31 @@ class CI_DB_mysqli_driver extends CI_DB { { return $item; } - + foreach ($this->_reserved_identifiers as $id) { 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); } - + // -------------------------------------------------------------------- /** @@ -514,12 +514,12 @@ class CI_DB_mysqli_driver extends CI_DB { { $tables = array($tables); } - + return '('.implode(', ', $tables).')'; } // -------------------------------------------------------------------- - + /** * Insert statement * @@ -532,10 +532,10 @@ class CI_DB_mysqli_driver extends CI_DB { * @return string */ function _insert($table, $keys, $values) - { + { return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } - + // -------------------------------------------------------------------- /** @@ -557,21 +557,21 @@ class CI_DB_mysqli_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; } - + // -------------------------------------------------------------------- /** @@ -584,12 +584,12 @@ class CI_DB_mysqli_driver extends CI_DB { * @access public * @param string the table name * @return string - */ + */ function _truncate($table) { return "TRUNCATE ".$table; } - + // -------------------------------------------------------------------- /** @@ -602,7 +602,7 @@ class CI_DB_mysqli_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 = ''; @@ -620,7 +620,7 @@ class CI_DB_mysqli_driver extends CI_DB { } $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - + return "DELETE FROM ".$table.$conditions.$limit; } @@ -638,14 +638,14 @@ class CI_DB_mysqli_driver extends CI_DB { * @return string */ function _limit($sql, $limit, $offset) - { + { $sql .= "LIMIT ".$limit; - + if ($offset > 0) { $sql .= " OFFSET ".$offset; } - + return $sql; } diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index 262d491ed..85491a873 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -23,7 +23,7 @@ * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_mysqli_forge extends CI_DB_forge { - + /** * Create database * @@ -76,52 +76,52 @@ class CI_DB_mysqli_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_mysqli_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_mysqli_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_mysqli_forge extends CI_DB_forge { { $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); } - + return $sql; } diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index 81d22cc9c..dd58ed878 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -25,7 +25,7 @@ * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_mysqli_result extends CI_DB_result { - + /** * Number of rows in the result set * @@ -36,7 +36,7 @@ class CI_DB_mysqli_result extends CI_DB_result { { return @mysqli_num_rows($this->result_id); } - + // -------------------------------------------------------------------- /** @@ -67,7 +67,7 @@ class CI_DB_mysqli_result extends CI_DB_result { { $field_names[] = $field->name; } - + return $field_names; } @@ -85,17 +85,17 @@ class CI_DB_mysqli_result extends CI_DB_result { { $retval = array(); while ($field = mysqli_fetch_field($this->result_id)) - { - $F = new stdClass(); - $F->name = $field->name; - $F->type = $field->type; + { + $F = new stdClass(); + $F->name = $field->name; + $F->type = $field->type; $F->default = $field->def; $F->max_length = $field->max_length; $F->primary_key = ($field->flags & MYSQLI_PRI_KEY_FLAG) ? 1 : 0; - + $retval[] = $F; } - + return $retval; } @@ -105,7 +105,7 @@ class CI_DB_mysqli_result extends CI_DB_result { * Free the result * * @return null - */ + */ function free_result() { if (is_object($this->result_id)) @@ -146,7 +146,7 @@ class CI_DB_mysqli_result extends CI_DB_result { { return mysqli_fetch_assoc($this->result_id); } - + // -------------------------------------------------------------------- /** @@ -161,7 +161,7 @@ class CI_DB_mysqli_result extends CI_DB_result { { return mysqli_fetch_object($this->result_id); } - + } diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 3ba14d25a..e0dbca7c0 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -23,7 +23,7 @@ * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_mysqli_utility extends CI_DB_utility { - + /** * List databases * @@ -34,7 +34,7 @@ class CI_DB_mysqli_utility extends CI_DB_utility { { return "SHOW DATABASES"; } - + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 6f317d2e6..fb65ad8a1 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -4,12 +4,12 @@ * * An open source application development framework for PHP 4.3.2 or newer * - * @package CodeIgniter - * @author ExpressionEngine Dev Team + * @package CodeIgniter + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. - * @license http://codeigniter.com/user_guide/license.html + * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com - * @since Version 1.0 + * @since Version 1.0 * @filesource */ @@ -22,10 +22,10 @@ * creates dynamically based on whether the active record * class is being used or not. * - * @package CodeIgniter + * @package CodeIgniter * @subpackage Drivers * @category Database - * @author ExpressionEngine Dev Team + * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/database/ */ @@ -44,14 +44,14 @@ class CI_DB_oci8_driver extends CI_DB { var $dbdriver = 'oci8'; - + // The character used for excaping var $_escape_char = '"'; - + // clause and character used for LIKE escape sequences var $_like_escape_str = " escape '%s' "; var $_like_escape_chr = '!'; - + /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is @@ -141,7 +141,7 @@ class CI_DB_oci8_driver extends CI_DB { } // -------------------------------------------------------------------- - + /** * Version number query string * @@ -248,7 +248,7 @@ class CI_DB_oci8_driver extends CI_DB { } return FALSE; } - + // build the query string $sql = "begin $package.$procedure("; @@ -256,20 +256,20 @@ class CI_DB_oci8_driver extends CI_DB { foreach($params as $param) { $sql .= $param['name'] . ","; - + if (array_key_exists('type', $param) && ($param['type'] == OCI_B_CURSOR)) { $have_cursor = TRUE; } } $sql = trim($sql, ",") . "); end;"; - + $this->stmt_id = FALSE; $this->_set_stmt_id($sql); $this->_bind_params($params); $this->query($sql, FALSE, $have_cursor); } - + // -------------------------------------------------------------------- /** @@ -284,10 +284,10 @@ class CI_DB_oci8_driver extends CI_DB { { return; } - + foreach ($params as $param) { - foreach (array('name', 'value', 'type', 'length') as $val) + foreach (array('name', 'value', 'type', 'length') as $val) { if ( ! isset($param[$val])) { @@ -305,26 +305,26 @@ class CI_DB_oci8_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) { return TRUE; } - + // Reset the transaction failure flag. // 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->_commit = OCI_DEFAULT; return TRUE; } @@ -335,8 +335,8 @@ class CI_DB_oci8_driver extends CI_DB { * Commit Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_commit() { if ( ! $this->trans_enabled) @@ -361,8 +361,8 @@ class CI_DB_oci8_driver extends CI_DB { * Rollback Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_rollback() { if ( ! $this->trans_enabled) @@ -396,15 +396,15 @@ class CI_DB_oci8_driver extends CI_DB { if (is_array($str)) { foreach($str as $key => $val) - { + { $str[$key] = $this->escape_str($val, $like); - } - - return $str; - } + } + + return $str; + } $str = remove_invisible_characters($str); - + // escape LIKE condition wildcards if ($like === TRUE) { @@ -412,7 +412,7 @@ class CI_DB_oci8_driver extends CI_DB { array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr), $str); } - + return $str; } @@ -492,7 +492,7 @@ class CI_DB_oci8_driver extends CI_DB { { $sql .= " WHERE TABLE_NAME LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); } - + return $sql; } @@ -555,7 +555,7 @@ class CI_DB_oci8_driver extends CI_DB { $error = ocierror($this->conn_id); return $error['code']; } - + // -------------------------------------------------------------------- /** @@ -578,26 +578,26 @@ class CI_DB_oci8_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); } - + // -------------------------------------------------------------------- /** @@ -616,12 +616,12 @@ class CI_DB_oci8_driver extends CI_DB { { $tables = array($tables); } - + return implode(', ', $tables); } // -------------------------------------------------------------------- - + /** * Insert statement * @@ -659,17 +659,17 @@ class CI_DB_oci8_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; } @@ -685,12 +685,12 @@ class CI_DB_oci8_driver extends CI_DB { * @access public * @param string the table name * @return string - */ + */ function _truncate($table) { return "TRUNCATE TABLE ".$table; } - + // -------------------------------------------------------------------- /** @@ -703,7 +703,7 @@ class CI_DB_oci8_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 = ''; @@ -721,7 +721,7 @@ class CI_DB_oci8_driver extends CI_DB { } $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - + return "DELETE FROM ".$table.$conditions.$limit; } @@ -752,7 +752,7 @@ class CI_DB_oci8_driver extends CI_DB { $this->limit_used = TRUE; return $newsql; - } + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index d77ed8de6..1d369ae32 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -66,12 +66,12 @@ class CI_DB_oci8_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)." ("; $current_field_count = 0; @@ -87,41 +87,41 @@ class CI_DB_oci8_forge extends CI_DB_forge { else { $attributes = array_change_key_case($attributes, CASE_UPPER); - + $sql .= "\n\t".$this->db->_protect_identifiers($field); - + $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) && $attributes['NULL'] === TRUE) { $sql .= ' NULL'; } else { - $sql .= ' NOT NULL'; + $sql .= ' 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)) { @@ -141,17 +141,17 @@ class CI_DB_oci8_forge extends CI_DB_forge { { if (is_array($key)) { - $key = $this->db->_protect_identifiers($key); + $key = $this->db->_protect_identifiers($key); } else { $key = array($this->db->_protect_identifiers($key)); } - + $sql .= ",\n\tUNIQUE COLUMNS (" . implode(', ', $key) . ")"; } } - + $sql .= "\n)"; return $sql; @@ -218,9 +218,9 @@ class CI_DB_oci8_forge extends CI_DB_forge { { $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); } - + return $sql; - + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index cab538e21..647ec6e43 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -4,12 +4,12 @@ * * An open source application development framework for PHP 4.3.2 or newer * - * @package CodeIgniter - * @author ExpressionEngine Dev Team + * @package CodeIgniter + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. - * @license http://codeigniter.com/user_guide/license.html + * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com - * @since Version 1.0 + * @since Version 1.0 * @filesource */ @@ -21,7 +21,7 @@ * This class extends the parent result class: CI_DB_result * * @category Database - * @author ExpressionEngine Dev Team + * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_oci8_result extends CI_DB_result { @@ -35,7 +35,7 @@ class CI_DB_oci8_result extends CI_DB_result { * * Oracle doesn't have a graceful way to retun the number of rows * so we have to use what amounts to a hack. - * + * * * @access public * @return integer @@ -111,7 +111,7 @@ class CI_DB_oci8_result extends CI_DB_result { $fieldCount = $this->num_fields(); for ($c = 1; $c <= $fieldCount; $c++) { - $F = new stdClass(); + $F = new stdClass(); $F->name = ocicolumnname($this->stmt_id, $c); $F->type = ocicolumntype($this->stmt_id, $c); $F->max_length = ocicolumnsize($this->stmt_id, $c); @@ -128,12 +128,12 @@ class CI_DB_oci8_result extends CI_DB_result { * Free the result * * @return null - */ + */ function free_result() { if (is_resource($this->result_id)) { - ocifreestatement($this->result_id); + ocifreestatement($this->result_id); $this->result_id = FALSE; } } @@ -151,8 +151,8 @@ class CI_DB_oci8_result extends CI_DB_result { function _fetch_assoc(&$row) { $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; - - return ocifetchinto($id, $row, OCI_ASSOC + OCI_RETURN_NULLS); + + return ocifetchinto($id, $row, OCI_ASSOC + OCI_RETURN_NULLS); } // -------------------------------------------------------------------- @@ -166,17 +166,17 @@ class CI_DB_oci8_result extends CI_DB_result { * @return object */ function _fetch_object() - { + { $result = array(); // If PHP 5 is being used we can fetch an result object if (function_exists('oci_fetch_object')) { $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; - + return @oci_fetch_object($id); } - + // If PHP 4 is being used we have to build our own result foreach ($this->result_array() as $key => $val) { @@ -192,7 +192,7 @@ class CI_DB_oci8_result extends CI_DB_result { { $obj->$key = $val; } - + $result[] = $obj; } diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 6e682313f..0e2c7de5f 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -31,14 +31,14 @@ class CI_DB_odbc_driver extends CI_DB { var $dbdriver = 'odbc'; - + // the character used to excape - not necessary for ODBC var $_escape_char = ''; - + // clause and character used for LIKE escape sequences var $_like_escape_str = " {escape '%s'} "; var $_like_escape_chr = '!'; - + /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is @@ -51,7 +51,7 @@ class CI_DB_odbc_driver extends CI_DB { function CI_DB_odbc_driver($params) { parent::CI_DB($params); - + $this->_random_keyword = ' RND('.time().')'; // database specific random keyword } @@ -60,12 +60,12 @@ class CI_DB_odbc_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_connect() { return @odbc_connect($this->hostname, $this->username, $this->password); } - + // -------------------------------------------------------------------- /** @@ -73,12 +73,12 @@ class CI_DB_odbc_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_pconnect() { return @odbc_pconnect($this->hostname, $this->username, $this->password); } - + // -------------------------------------------------------------------- /** @@ -102,7 +102,7 @@ class CI_DB_odbc_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_select() { // Not needed for ODBC @@ -126,7 +126,7 @@ class CI_DB_odbc_driver extends CI_DB { } // -------------------------------------------------------------------- - + /** * Version number query string * @@ -146,13 +146,13 @@ class CI_DB_odbc_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 @odbc_exec($this->conn_id, $sql); } - + // -------------------------------------------------------------------- /** @@ -163,7 +163,7 @@ class CI_DB_odbc_driver extends CI_DB { * @access private called by execute() * @param string an SQL query * @return string - */ + */ function _prep_query($sql) { return $sql; @@ -175,15 +175,15 @@ class CI_DB_odbc_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) { @@ -204,8 +204,8 @@ class CI_DB_odbc_driver extends CI_DB { * Commit Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_commit() { if ( ! $this->trans_enabled) @@ -230,8 +230,8 @@ class CI_DB_odbc_driver extends CI_DB { * Rollback Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_rollback() { if ( ! $this->trans_enabled) @@ -265,16 +265,16 @@ class CI_DB_odbc_driver extends CI_DB { if (is_array($str)) { foreach($str as $key => $val) - { + { $str[$key] = $this->escape_str($val, $like); - } - - return $str; - } - + } + + return $str; + } + // ODBC doesn't require escaping $str = remove_invisible_characters($str); - + // escape LIKE condition wildcards if ($like === TRUE) { @@ -282,10 +282,10 @@ class CI_DB_odbc_driver extends CI_DB { array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr), $str); } - + return $str; } - + // -------------------------------------------------------------------- /** @@ -298,7 +298,7 @@ class CI_DB_odbc_driver extends CI_DB { { return @odbc_num_rows($this->conn_id); } - + // -------------------------------------------------------------------- /** @@ -362,10 +362,10 @@ class CI_DB_odbc_driver extends CI_DB { //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); return FALSE; // not currently supported } - + return $sql; } - + // -------------------------------------------------------------------- /** @@ -410,7 +410,7 @@ class CI_DB_odbc_driver extends CI_DB { { return odbc_errormsg($this->conn_id); } - + // -------------------------------------------------------------------- /** @@ -446,26 +446,26 @@ class CI_DB_odbc_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); } - + // -------------------------------------------------------------------- /** @@ -484,12 +484,12 @@ class CI_DB_odbc_driver extends CI_DB { { $tables = array($tables); } - + return '('.implode(', ', $tables).')'; } // -------------------------------------------------------------------- - + /** * Insert statement * @@ -502,10 +502,10 @@ class CI_DB_odbc_driver extends CI_DB { * @return string */ function _insert($table, $keys, $values) - { + { return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } - + // -------------------------------------------------------------------- /** @@ -527,21 +527,21 @@ class CI_DB_odbc_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; } - + // -------------------------------------------------------------------- /** @@ -554,12 +554,12 @@ class CI_DB_odbc_driver extends CI_DB { * @access public * @param string the table name * @return string - */ + */ function _truncate($table) { return $this->_delete($table); } - + // -------------------------------------------------------------------- /** @@ -572,7 +572,7 @@ class CI_DB_odbc_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 = ''; @@ -590,7 +590,7 @@ class CI_DB_odbc_driver extends CI_DB { } $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - + return "DELETE FROM ".$table.$conditions.$limit; } @@ -627,7 +627,7 @@ class CI_DB_odbc_driver extends CI_DB { @odbc_close($conn_id); } - + } diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php index 1ae559b6e..49a2401f1 100644 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -54,7 +54,7 @@ class CI_DB_odbc_forge extends CI_DB_forge { function _drop_database($name) { // ODBC has no "drop database" command since it's - // designed to connect to an existing database + // designed to connect to an existing database if ($this->db->db_debug) { return $this->db->display_error('db_unsuported_feature'); @@ -78,12 +78,12 @@ class CI_DB_odbc_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)." ("; $current_field_count = 0; @@ -99,41 +99,41 @@ class CI_DB_odbc_forge extends CI_DB_forge { else { $attributes = array_change_key_case($attributes, CASE_UPPER); - + $sql .= "\n\t".$this->db->_protect_identifiers($field); - + $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) && $attributes['NULL'] === TRUE) { $sql .= ' NULL'; } else { - $sql .= ' NOT NULL'; + $sql .= ' 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)) { @@ -146,24 +146,24 @@ class CI_DB_odbc_forge extends CI_DB_forge { $primary_keys = $this->db->_protect_identifiers($primary_keys); $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; } - + if (is_array($keys) && count($keys) > 0) { foreach ($keys as $key) { if (is_array($key)) { - $key = $this->db->_protect_identifiers($key); + $key = $this->db->_protect_identifiers($key); } else { $key = array($this->db->_protect_identifiers($key)); } - + $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")"; } } - + $sql .= "\n)"; return $sql; @@ -179,7 +179,7 @@ class CI_DB_odbc_forge extends CI_DB_forge { */ function _drop_table($table) { - // Not a supported ODBC feature + // Not a supported ODBC feature if ($this->db->db_debug) { return $this->db->display_error('db_unsuported_feature'); @@ -235,9 +235,9 @@ class CI_DB_odbc_forge extends CI_DB_forge { { $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); } - + return $sql; - + } diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index 5ae46df62..e2dc8415f 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -25,7 +25,7 @@ * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_odbc_result extends CI_DB_result { - + /** * Number of rows in the result set * @@ -36,7 +36,7 @@ class CI_DB_odbc_result extends CI_DB_result { { return @odbc_num_rows($this->result_id); } - + // -------------------------------------------------------------------- /** @@ -65,9 +65,9 @@ class CI_DB_odbc_result extends CI_DB_result { $field_names = array(); for ($i = 0; $i < $this->num_fields(); $i++) { - $field_names[] = odbc_field_name($this->result_id, $i); + $field_names[] = odbc_field_name($this->result_id, $i); } - + return $field_names; } @@ -86,16 +86,16 @@ class CI_DB_odbc_result extends CI_DB_result { $retval = array(); for ($i = 0; $i < $this->num_fields(); $i++) { - $F = new stdClass(); - $F->name = odbc_field_name($this->result_id, $i); - $F->type = odbc_field_type($this->result_id, $i); + $F = new stdClass(); + $F->name = odbc_field_name($this->result_id, $i); + $F->type = odbc_field_type($this->result_id, $i); $F->max_length = odbc_field_len($this->result_id, $i); $F->primary_key = 0; $F->default = ''; $retval[] = $F; } - + return $retval; } @@ -105,7 +105,7 @@ class CI_DB_odbc_result extends CI_DB_result { * Free the result * * @return null - */ + */ function free_result() { if (is_resource($this->result_id)) diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index 5b874d88f..deeb0320a 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -32,7 +32,7 @@ class CI_DB_odbc_utility extends CI_DB_utility { */ function _list_databases() { - // Not sure if ODBC lets you list all databases... + // Not sure if ODBC lets you list all databases... if ($this->db->db_debug) { return $this->db->display_error('db_unsuported_feature'); @@ -53,7 +53,7 @@ class CI_DB_odbc_utility extends CI_DB_utility { */ function _optimize_table($table) { - // Not a supported ODBC feature + // Not a supported ODBC feature if ($this->db->db_debug) { return $this->db->display_error('db_unsuported_feature'); @@ -74,7 +74,7 @@ class CI_DB_odbc_utility extends CI_DB_utility { */ function _repair_table($table) { - // Not a supported ODBC feature + // Not a supported ODBC feature if ($this->db->db_debug) { return $this->db->display_error('db_unsuported_feature'); diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 9f991e4a0..cf865432b 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -31,7 +31,7 @@ class CI_DB_postgre_driver extends CI_DB { var $dbdriver = 'postgre'; - + var $_escape_char = '"'; // clause and character used for LIKE escape sequences @@ -51,7 +51,7 @@ class CI_DB_postgre_driver extends CI_DB { * * @access private * @return string - */ + */ function _connect_string() { $components = array( @@ -61,7 +61,7 @@ class CI_DB_postgre_driver extends CI_DB { 'username' => 'user', 'password' => 'password' ); - + $connect_string = ""; foreach ($components as $key => $val) { @@ -80,9 +80,9 @@ class CI_DB_postgre_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_connect() - { + { return @pg_connect($this->_connect_string()); } @@ -93,12 +93,12 @@ class CI_DB_postgre_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_pconnect() { return @pg_pconnect($this->_connect_string()); } - + // -------------------------------------------------------------------- /** @@ -125,7 +125,7 @@ class CI_DB_postgre_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_select() { // Not needed for Postgre so we'll return TRUE @@ -149,7 +149,7 @@ class CI_DB_postgre_driver extends CI_DB { } // -------------------------------------------------------------------- - + /** * Version number query string * @@ -169,13 +169,13 @@ class CI_DB_postgre_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 @pg_query($this->conn_id, $sql); } - + // -------------------------------------------------------------------- /** @@ -186,7 +186,7 @@ class CI_DB_postgre_driver extends CI_DB { * @access private called by execute() * @param string an SQL query * @return string - */ + */ function _prep_query($sql) { return $sql; @@ -198,15 +198,15 @@ class CI_DB_postgre_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) { @@ -227,8 +227,8 @@ class CI_DB_postgre_driver extends CI_DB { * Commit Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_commit() { if ( ! $this->trans_enabled) @@ -251,8 +251,8 @@ class CI_DB_postgre_driver extends CI_DB { * Rollback Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_rollback() { if ( ! $this->trans_enabled) @@ -284,15 +284,15 @@ class CI_DB_postgre_driver extends CI_DB { if (is_array($str)) { foreach($str as $key => $val) - { + { $str[$key] = $this->escape_str($val, $like); - } - - return $str; - } + } + + return $str; + } $str = pg_escape_string($str); - + // escape LIKE condition wildcards if ($like === TRUE) { @@ -300,10 +300,10 @@ class CI_DB_postgre_driver extends CI_DB { array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr), $str); } - + return $str; } - + // -------------------------------------------------------------------- /** @@ -316,7 +316,7 @@ class CI_DB_postgre_driver extends CI_DB { { return @pg_affected_rows($this->result_id); } - + // -------------------------------------------------------------------- /** @@ -329,10 +329,10 @@ class CI_DB_postgre_driver extends CI_DB { { $v = $this->_version(); $v = $v['server']; - + $table = func_num_args() > 0 ? func_get_arg(0) : null; $column = func_num_args() > 1 ? func_get_arg(1) : null; - + if ($table == null && $v >= '8.1') { $sql='SELECT LASTVAL() as ins_id'; @@ -400,17 +400,17 @@ class CI_DB_postgre_driver extends CI_DB { * @return string */ function _list_tables($prefix_limit = FALSE) - { - $sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; - + { + $sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; + if ($prefix_limit !== FALSE AND $this->dbprefix != '') { $sql .= " AND table_name LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); } - + return $sql; } - + // -------------------------------------------------------------------- /** @@ -455,7 +455,7 @@ class CI_DB_postgre_driver extends CI_DB { { return pg_last_error($this->conn_id); } - + // -------------------------------------------------------------------- /** @@ -491,26 +491,26 @@ class CI_DB_postgre_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); } - + // -------------------------------------------------------------------- /** @@ -529,12 +529,12 @@ class CI_DB_postgre_driver extends CI_DB { { $tables = array($tables); } - + return implode(', ', $tables); } // -------------------------------------------------------------------- - + /** * Insert statement * @@ -547,10 +547,10 @@ class CI_DB_postgre_driver extends CI_DB { * @return string */ function _insert($table, $keys, $values) - { + { return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } - + // -------------------------------------------------------------------- /** @@ -572,17 +572,17 @@ class CI_DB_postgre_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; } @@ -598,12 +598,12 @@ class CI_DB_postgre_driver extends CI_DB { * @access public * @param string the table name * @return string - */ + */ function _truncate($table) { return "TRUNCATE ".$table; } - + // -------------------------------------------------------------------- /** @@ -616,7 +616,7 @@ class CI_DB_postgre_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 = ''; @@ -634,7 +634,7 @@ class CI_DB_postgre_driver extends CI_DB { } $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - + return "DELETE FROM ".$table.$conditions.$limit; } @@ -651,14 +651,14 @@ class CI_DB_postgre_driver extends CI_DB { * @return string */ function _limit($sql, $limit, $offset) - { + { $sql .= "LIMIT ".$limit; - + if ($offset > 0) { $sql .= " OFFSET ".$offset; } - + return $sql; } diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index c98ef425d..12eef2923 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -66,12 +66,12 @@ class CI_DB_postgre_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)." ("; $current_field_count = 0; @@ -87,41 +87,41 @@ class CI_DB_postgre_forge extends CI_DB_forge { else { $attributes = array_change_key_case($attributes, CASE_UPPER); - + $sql .= "\n\t".$this->db->_protect_identifiers($field); - + $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) && $attributes['NULL'] === TRUE) { $sql .= ' NULL'; } else { - $sql .= ' NOT NULL'; + $sql .= ' 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)) { @@ -134,20 +134,20 @@ class CI_DB_postgre_forge extends CI_DB_forge { $primary_keys = $this->db->_protect_identifiers($primary_keys); $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; } - + if (is_array($keys) && count($keys) > 0) { foreach ($keys as $key) { if (is_array($key)) { - $key = $this->db->_protect_identifiers($key); + $key = $this->db->_protect_identifiers($key); } else { $key = array($this->db->_protect_identifiers($key)); } - + $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")"; } } @@ -218,9 +218,9 @@ class CI_DB_postgre_forge extends CI_DB_forge { { $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); } - + return $sql; - + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index 545f413e8..b60ad7dd3 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -36,7 +36,7 @@ class CI_DB_postgre_result extends CI_DB_result { { return @pg_num_rows($this->result_id); } - + // -------------------------------------------------------------------- /** @@ -67,7 +67,7 @@ class CI_DB_postgre_result extends CI_DB_result { { $field_names[] = pg_field_name($this->result_id, $i); } - + return $field_names; } @@ -86,16 +86,16 @@ class CI_DB_postgre_result extends CI_DB_result { $retval = array(); for ($i = 0; $i < $this->num_fields(); $i++) { - $F = new stdClass(); - $F->name = pg_field_name($this->result_id, $i); - $F->type = pg_field_type($this->result_id, $i); + $F = new stdClass(); + $F->name = pg_field_name($this->result_id, $i); + $F->type = pg_field_type($this->result_id, $i); $F->max_length = pg_field_size($this->result_id, $i); $F->primary_key = 0; $F->default = ''; $retval[] = $F; } - + return $retval; } @@ -105,7 +105,7 @@ class CI_DB_postgre_result extends CI_DB_result { * Free the result * * @return null - */ + */ function free_result() { if (is_resource($this->result_id)) @@ -146,7 +146,7 @@ class CI_DB_postgre_result extends CI_DB_result { { return pg_fetch_assoc($this->result_id); } - + // -------------------------------------------------------------------- /** @@ -161,7 +161,7 @@ class CI_DB_postgre_result extends CI_DB_result { { return pg_fetch_object($this->result_id); } - + } diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index c08ed2a56..ea0583e9e 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -33,14 +33,14 @@ class CI_DB_sqlite_driver extends CI_DB { var $dbdriver = 'sqlite'; - + // The character used to escape with - not needed for SQLite var $_escape_char = ''; // clause and character used for LIKE escape sequences - var $_like_escape_str = " ESCAPE '%s' "; + var $_like_escape_str = " ESCAPE '%s' "; var $_like_escape_chr = '!'; - + /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is @@ -54,24 +54,24 @@ class CI_DB_sqlite_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_connect() { if ( ! $conn_id = @sqlite_open($this->database, FILE_WRITE_MODE, $error)) { log_message('error', $error); - + if ($this->db_debug) { $this->display_error($error, '', TRUE); } - + return FALSE; } - + return $conn_id; } - + // -------------------------------------------------------------------- /** @@ -79,24 +79,24 @@ class CI_DB_sqlite_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_pconnect() { if ( ! $conn_id = @sqlite_popen($this->database, FILE_WRITE_MODE, $error)) { log_message('error', $error); - + if ($this->db_debug) { $this->display_error($error, '', TRUE); } - + return FALSE; } - + return $conn_id; } - + // -------------------------------------------------------------------- /** @@ -120,7 +120,7 @@ class CI_DB_sqlite_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_select() { return TRUE; @@ -143,7 +143,7 @@ class CI_DB_sqlite_driver extends CI_DB { } // -------------------------------------------------------------------- - + /** * Version number query string * @@ -154,7 +154,7 @@ class CI_DB_sqlite_driver extends CI_DB { { return sqlite_libversion(); } - + // -------------------------------------------------------------------- /** @@ -163,13 +163,13 @@ class CI_DB_sqlite_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 @sqlite_query($this->conn_id, $sql); } - + // -------------------------------------------------------------------- /** @@ -180,7 +180,7 @@ class CI_DB_sqlite_driver extends CI_DB { * @access private called by execute() * @param string an SQL query * @return string - */ + */ function _prep_query($sql) { return $sql; @@ -192,15 +192,15 @@ class CI_DB_sqlite_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) { @@ -222,8 +222,8 @@ class CI_DB_sqlite_driver extends CI_DB { * Commit Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_commit() { if ( ! $this->trans_enabled) @@ -247,8 +247,8 @@ class CI_DB_sqlite_driver extends CI_DB { * Rollback Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_rollback() { if ( ! $this->trans_enabled) @@ -265,7 +265,7 @@ class CI_DB_sqlite_driver extends CI_DB { $this->simple_query('ROLLBACK'); return TRUE; } - + // -------------------------------------------------------------------- /** @@ -281,15 +281,15 @@ class CI_DB_sqlite_driver extends CI_DB { if (is_array($str)) { foreach($str as $key => $val) - { + { $str[$key] = $this->escape_str($val, $like); - } - - return $str; - } - + } + + return $str; + } + $str = sqlite_escape_string($str); - + // escape LIKE condition wildcards if ($like === TRUE) { @@ -297,10 +297,10 @@ class CI_DB_sqlite_driver extends CI_DB { array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr), $str); } - + return $str; } - + // -------------------------------------------------------------------- /** @@ -313,7 +313,7 @@ class CI_DB_sqlite_driver extends CI_DB { { return sqlite_changes($this->conn_id); } - + // -------------------------------------------------------------------- /** @@ -347,7 +347,7 @@ class CI_DB_sqlite_driver extends CI_DB { } $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); - + if ($query->num_rows() == 0) { return 0; @@ -424,7 +424,7 @@ class CI_DB_sqlite_driver extends CI_DB { { return sqlite_error_string(sqlite_last_error($this->conn_id)); } - + // -------------------------------------------------------------------- /** @@ -460,26 +460,26 @@ class CI_DB_sqlite_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); } - + // -------------------------------------------------------------------- /** @@ -498,12 +498,12 @@ class CI_DB_sqlite_driver extends CI_DB { { $tables = array($tables); } - + return '('.implode(', ', $tables).')'; } // -------------------------------------------------------------------- - + /** * Insert statement * @@ -516,10 +516,10 @@ class CI_DB_sqlite_driver extends CI_DB { * @return string */ function _insert($table, $keys, $values) - { + { return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } - + // -------------------------------------------------------------------- /** @@ -541,21 +541,21 @@ class CI_DB_sqlite_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; } - + // -------------------------------------------------------------------- /** @@ -568,12 +568,12 @@ class CI_DB_sqlite_driver extends CI_DB { * @access public * @param string the table name * @return string - */ + */ function _truncate($table) { return $this->_delete($table); } - + // -------------------------------------------------------------------- /** @@ -586,7 +586,7 @@ class CI_DB_sqlite_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 = ''; @@ -604,10 +604,10 @@ class CI_DB_sqlite_driver extends CI_DB { } $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - + return "DELETE FROM ".$table.$conditions.$limit; } - + // -------------------------------------------------------------------- /** @@ -622,7 +622,7 @@ class CI_DB_sqlite_driver extends CI_DB { * @return string */ function _limit($sql, $limit, $offset) - { + { if ($offset == 0) { $offset = ''; @@ -631,7 +631,7 @@ class CI_DB_sqlite_driver extends CI_DB { { $offset .= ", "; } - + return $sql."LIMIT ".$offset.$limit; } diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php index 53b20a3c7..7b5c894f6 100644 --- a/system/database/drivers/sqlite/sqlite_forge.php +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -75,13 +75,13 @@ class CI_DB_sqlite_forge extends CI_DB_forge { function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) { $sql = 'CREATE TABLE '; - + // IF NOT EXISTS added to SQLite in 3.3.0 if ($if_not_exists === TRUE && version_compare($this->db->_version(), '3.3.0', '>=') === TRUE) { $sql .= 'IF NOT EXISTS '; } - + $sql .= $this->db->_escape_identifiers($table)."("; $current_field_count = 0; @@ -97,41 +97,41 @@ class CI_DB_sqlite_forge extends CI_DB_forge { else { $attributes = array_change_key_case($attributes, CASE_UPPER); - + $sql .= "\n\t".$this->db->_protect_identifiers($field); - + $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) && $attributes['NULL'] === TRUE) { $sql .= ' NULL'; } else { - $sql .= ' NOT NULL'; + $sql .= ' 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)) { @@ -151,13 +151,13 @@ class CI_DB_sqlite_forge extends CI_DB_forge { { if (is_array($key)) { - $key = $this->db->_protect_identifiers($key); + $key = $this->db->_protect_identifiers($key); } else { $key = array($this->db->_protect_identifiers($key)); } - + $sql .= ",\n\tUNIQUE (" . implode(', ', $key) . ")"; } } @@ -237,9 +237,9 @@ class CI_DB_sqlite_forge extends CI_DB_forge { { $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); } - + return $sql; - + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index 7b0631221..fd6d83d0c 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -25,7 +25,7 @@ * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_sqlite_result extends CI_DB_result { - + /** * Number of rows in the result set * @@ -36,7 +36,7 @@ class CI_DB_sqlite_result extends CI_DB_result { { return @sqlite_num_rows($this->result_id); } - + // -------------------------------------------------------------------- /** @@ -67,7 +67,7 @@ class CI_DB_sqlite_result extends CI_DB_result { { $field_names[] = sqlite_field_name($this->result_id, $i); } - + return $field_names; } @@ -86,16 +86,16 @@ class CI_DB_sqlite_result extends CI_DB_result { $retval = array(); for ($i = 0; $i < $this->num_fields(); $i++) { - $F = new stdClass(); - $F->name = sqlite_field_name($this->result_id, $i); - $F->type = 'varchar'; + $F = new stdClass(); + $F->name = sqlite_field_name($this->result_id, $i); + $F->type = 'varchar'; $F->max_length = 0; $F->primary_key = 0; $F->default = ''; $retval[] = $F; } - + return $retval; } @@ -105,7 +105,7 @@ class CI_DB_sqlite_result extends CI_DB_result { * Free the result * * @return null - */ + */ function free_result() { // Not implemented in SQLite @@ -142,7 +142,7 @@ class CI_DB_sqlite_result extends CI_DB_result { { return sqlite_fetch_array($this->result_id); } - + // -------------------------------------------------------------------- /** @@ -168,7 +168,7 @@ class CI_DB_sqlite_result extends CI_DB_result { return $obj; } else { return NULL; - } + } } } -- cgit v1.2.3-24-g4f1b From 741de1c1319dd13de75348863cca591713dd46ce Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Wed, 10 Nov 2010 14:52:57 -0600 Subject: Updating PHP requirements in files 5.1.6 --- system/database/DB.php | 2 +- system/database/DB_active_rec.php | 2 +- system/database/DB_cache.php | 2 +- system/database/DB_driver.php | 2 +- system/database/DB_forge.php | 2 +- system/database/DB_result.php | 2 +- system/database/DB_utility.php | 2 +- system/database/drivers/mssql/mssql_driver.php | 2 +- system/database/drivers/mssql/mssql_forge.php | 2 +- system/database/drivers/mssql/mssql_result.php | 2 +- system/database/drivers/mssql/mssql_utility.php | 2 +- system/database/drivers/mysql/mysql_driver.php | 2 +- system/database/drivers/mysql/mysql_forge.php | 2 +- system/database/drivers/mysql/mysql_result.php | 2 +- system/database/drivers/mysql/mysql_utility.php | 2 +- system/database/drivers/mysqli/mysqli_driver.php | 2 +- system/database/drivers/mysqli/mysqli_forge.php | 2 +- system/database/drivers/mysqli/mysqli_result.php | 2 +- system/database/drivers/mysqli/mysqli_utility.php | 2 +- system/database/drivers/oci8/oci8_driver.php | 2 +- system/database/drivers/oci8/oci8_forge.php | 2 +- system/database/drivers/oci8/oci8_result.php | 2 +- system/database/drivers/oci8/oci8_utility.php | 2 +- system/database/drivers/odbc/odbc_driver.php | 2 +- system/database/drivers/odbc/odbc_forge.php | 2 +- system/database/drivers/odbc/odbc_result.php | 2 +- system/database/drivers/odbc/odbc_utility.php | 2 +- system/database/drivers/postgre/postgre_driver.php | 2 +- system/database/drivers/postgre/postgre_forge.php | 2 +- system/database/drivers/postgre/postgre_result.php | 2 +- system/database/drivers/postgre/postgre_utility.php | 2 +- system/database/drivers/sqlite/sqlite_driver.php | 2 +- system/database/drivers/sqlite/sqlite_forge.php | 2 +- system/database/drivers/sqlite/sqlite_result.php | 2 +- system/database/drivers/sqlite/sqlite_utility.php | 2 +- 35 files changed, 35 insertions(+), 35 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index 1b4eb8bec..b51995b68 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index ce50479cc..dd46981b1 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 6eff5943e..6042e0673 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index cbfa33e78..7fe5695b0 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index 74aed8610..f40eac82d 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -2,7 +2,7 @@ /** * Code Igniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 406afb1b8..05f06af66 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 2811d8802..c4d537a3b 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -2,7 +2,7 @@ /** * Code Igniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 63f9e9cc3..eade10ee8 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php index 5aa4406b1..6b02e1eb2 100644 --- a/system/database/drivers/mssql/mssql_forge.php +++ b/system/database/drivers/mssql/mssql_forge.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index 09b1ec80b..c0a20dbde 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index e58c7e0c3..b867dd7b1 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index cb985a764..f27a1eef6 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index 973f32dcb..8faf69550 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index 0140ec647..c3aa4ccd7 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 3b574c6f4..1259fee6f 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 69e092839..b50fe5f77 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index 85491a873..5d5b78089 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index dd58ed878..16f57c079 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index e0dbca7c0..84ff0daf4 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index fb65ad8a1..44d5dec7e 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index 1d369ae32..4bcb081b2 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 647ec6e43..058524f4c 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index cc1793531..48d4acec8 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 0e2c7de5f..af90f0c7a 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php index 49a2401f1..602016ad4 100644 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index e2dc8415f..b673464b7 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index deeb0320a..9f9ef5a3d 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index cf865432b..b61a9d75b 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index 12eef2923..41858f36e 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index b60ad7dd3..126631201 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 84b089af0..f04c7f083 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index ea0583e9e..d6c6897c6 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php index 7b5c894f6..0aa5d382a 100644 --- a/system/database/drivers/sqlite/sqlite_forge.php +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index fd6d83d0c..9a86aa99c 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index 956d2130f..b76c1b366 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team -- cgit v1.2.3-24-g4f1b From 585600207a79c1d9a7b0af5883bf384629b753a3 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Wed, 10 Nov 2010 16:01:20 -0500 Subject: Removing instantiate_class(), which was needed to make php 4 and 5.3 play together nicely. Removed all instantiations by reference. --- system/database/DB.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index b51995b68..60a67e821 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -130,7 +130,7 @@ function &DB($params = '', $active_record_override = NULL) // Instantiate the DB adapter $driver = 'CI_DB_'.$params['dbdriver'].'_driver'; - $DB =& instantiate_class(new $driver($params)); + $DB = new $driver($params); if ($DB->autoinit == TRUE) { -- cgit v1.2.3-24-g4f1b From a58ecae8e149fe8e1fa9ee3cc9c9ad23a67ab8b6 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Wed, 15 Dec 2010 10:32:10 +0000 Subject: Name can be omiitted from ->dbforge->modify_column()'s 2nd param if you aren't changing the name. --- system/database/DB_forge.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'system/database') diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index f40eac82d..ce505f4ee 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -333,6 +333,12 @@ class CI_DB_forge { foreach ($field as $k => $v) { + // If no name provided, use the current name + if ( ! isset($field[$k]['name'])) + { + $field[$k]['name'] = $k; + } + $this->add_field(array($k => $field[$k])); if (count($this->fields) == 0) -- cgit v1.2.3-24-g4f1b From 678256c2007b06452b581fb692d948b7c9c94a7b Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Tue, 21 Dec 2010 12:05:12 -0600 Subject: Fix #93 Updating postgres dbforge create table method. Thanks to James Gifford for the patch. http://codeigniter.com/forums/viewthread/73392/ --- system/database/drivers/postgre/postgre_forge.php | 81 ++++++++++++++++++----- 1 file changed, 66 insertions(+), 15 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index 41858f36e..16127ffd7 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -69,7 +69,10 @@ class CI_DB_postgre_forge extends CI_DB_forge { if ($if_not_exists === TRUE) { - $sql .= 'IF NOT EXISTS '; + if ($this->db->table_exists($table)) + { + return "SELECT * FROM $table"; // Needs to return innocous but valid SQL statement + } } $sql .= $this->db->_escape_identifiers($table)." ("; @@ -90,16 +93,55 @@ class CI_DB_postgre_forge extends CI_DB_forge { $sql .= "\n\t".$this->db->_protect_identifiers($field); - $sql .= ' '.$attributes['TYPE']; + $is_unsigned = (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE); - if (array_key_exists('CONSTRAINT', $attributes)) + // Convert datatypes to be PostgreSQL-compatible + switch (strtoupper($attributes['TYPE'])) { - $sql .= '('.$attributes['CONSTRAINT'].')'; + case 'TINYINT': + $attributes['TYPE'] = 'SMALLINT'; + break; + case 'SMALLINT': + $attributes['TYPE'] = ($is_unsigned) ? 'INTEGER' : 'SMALLINT'; + break; + case 'MEDIUMINT': + $attributes['TYPE'] = 'INTEGER'; + break; + case 'INT': + $attributes['TYPE'] = ($is_unsigned) ? 'BIGINT' : 'INTEGER'; + break; + case 'BIGINT': + $attributes['TYPE'] = ($is_unsigned) ? 'NUMERIC' : 'BIGINT'; + break; + case 'DOUBLE': + $attributes['TYPE'] = 'DOUBLE PRECISION'; + break; + case 'DATETIME': + $attributes['TYPE'] = 'TIMESTAMP'; + break; + case 'LONGTEXT': + $attributes['TYPE'] = 'TEXT'; + break; + case 'BLOB': + $attributes['TYPE'] = 'BYTEA'; + break; } - if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) + // If this is an auto-incrementing primary key, use the serial data type instead + if (in_array($field, $primary_keys) && array_key_exists('AUTO_INCREMENT', $attributes) + && $attributes['AUTO_INCREMENT'] === TRUE) + { + $sql .= ' SERIAL'; + } + else { - $sql .= ' UNSIGNED'; + $sql .= ' '.$attributes['TYPE']; + } + + // Modified to prevent constraints with integer data types + if (array_key_exists('CONSTRAINT', $attributes) && strpos($attributes['TYPE'], 'INT') === false) + { + $sql .= '('.$attributes['CONSTRAINT'].')'; } if (array_key_exists('DEFAULT', $attributes)) @@ -116,9 +158,10 @@ class CI_DB_postgre_forge extends CI_DB_forge { $sql .= ' NOT NULL'; } - if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) + // Added new attribute to create unqite fields. Also works with MySQL + if (array_key_exists('UNIQUE', $attributes) && $attributes['UNIQUE'] === TRUE) { - $sql .= ' AUTO_INCREMENT'; + $sql .= ' UNIQUE'; } } @@ -131,10 +174,17 @@ class CI_DB_postgre_forge extends CI_DB_forge { if (count($primary_keys) > 0) { - $primary_keys = $this->db->_protect_identifiers($primary_keys); + // Something seems to break when passing an array to _protect_identifiers() + foreach ($primary_keys as $index => $key) + { + $primary_keys[$index] = $this->db->_protect_identifiers($key); + } + $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; } + $sql .= "\n);"; + if (is_array($keys) && count($keys) > 0) { foreach ($keys as $key) @@ -148,12 +198,13 @@ class CI_DB_postgre_forge extends CI_DB_forge { $key = array($this->db->_protect_identifiers($key)); } - $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")"; + foreach ($key as $field) + { + $sql .= "CREATE INDEX " . $table . "_" . str_replace(array('"', "'"), '', $field) . "_index ON $table ($field); "; + } } } - $sql .= "\n);"; - return $sql; } @@ -162,12 +213,12 @@ class CI_DB_postgre_forge extends CI_DB_forge { /** * Drop Table * - * @access private - * @return bool + * @access private + * @return bool */ function _drop_table($table) { - return "DROP TABLE ".$this->db->_escape_identifiers($table)." CASCADE"; + return "DROP TABLE IF EXISTS ".$this->db->_escape_identifiers($table)." CASCADE"; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 27324cd6ae2b076d3346e3585f312f7a61a5a897 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Wed, 5 Jan 2011 16:32:57 +0000 Subject: Use arrays in DBForge for constraint for things like decimal, float, numeric, enum and set. --- system/database/drivers/mysql/mysql_forge.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index 8faf69550..35845d6af 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -87,11 +87,26 @@ class CI_DB_mysql_forge extends CI_DB_forge { if (array_key_exists('TYPE', $attributes)) { $sql .= ' '.$attributes['TYPE']; - } - if (array_key_exists('CONSTRAINT', $attributes)) - { - $sql .= '('.$attributes['CONSTRAINT'].')'; + if (array_key_exists('CONSTRAINT', $attributes)) + { + switch ($attributes['TYPE']) + { + case 'decimal': + case 'float': + case 'numeric': + $sql .= '('.implode(',', $attributes['CONSTRAINT']).')'; + break; + + case 'enum': + case 'set': + $sql .= '("'.implode('","', $attributes['CONSTRAINT']).'")'; + break; + + default: + $sql .= '('.$attributes['CONSTRAINT'].')'; + } + } } if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) -- cgit v1.2.3-24-g4f1b From 0711dc87d98ce20d3a87f7ac43d78af8fba1dca7 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Wed, 5 Jan 2011 10:49:40 -0600 Subject: Hey look, it's 2011 --- system/database/DB.php | 2 +- system/database/DB_active_rec.php | 2 +- system/database/DB_cache.php | 2 +- system/database/DB_driver.php | 2 +- system/database/DB_forge.php | 2 +- system/database/DB_result.php | 2 +- system/database/DB_utility.php | 2 +- system/database/drivers/mssql/mssql_driver.php | 2 +- system/database/drivers/mssql/mssql_forge.php | 2 +- system/database/drivers/mssql/mssql_result.php | 2 +- system/database/drivers/mssql/mssql_utility.php | 2 +- system/database/drivers/mysql/mysql_driver.php | 2 +- system/database/drivers/mysql/mysql_forge.php | 2 +- system/database/drivers/mysql/mysql_result.php | 2 +- system/database/drivers/mysql/mysql_utility.php | 2 +- system/database/drivers/mysqli/mysqli_driver.php | 2 +- system/database/drivers/mysqli/mysqli_forge.php | 2 +- system/database/drivers/mysqli/mysqli_result.php | 2 +- system/database/drivers/mysqli/mysqli_utility.php | 2 +- system/database/drivers/oci8/oci8_driver.php | 2 +- system/database/drivers/oci8/oci8_forge.php | 2 +- system/database/drivers/oci8/oci8_result.php | 2 +- system/database/drivers/oci8/oci8_utility.php | 2 +- system/database/drivers/odbc/odbc_driver.php | 2 +- system/database/drivers/odbc/odbc_forge.php | 2 +- system/database/drivers/odbc/odbc_result.php | 2 +- system/database/drivers/odbc/odbc_utility.php | 2 +- system/database/drivers/postgre/postgre_driver.php | 2 +- system/database/drivers/postgre/postgre_forge.php | 2 +- system/database/drivers/postgre/postgre_result.php | 2 +- system/database/drivers/postgre/postgre_utility.php | 2 +- system/database/drivers/sqlite/sqlite_driver.php | 2 +- system/database/drivers/sqlite/sqlite_forge.php | 2 +- system/database/drivers/sqlite/sqlite_result.php | 2 +- system/database/drivers/sqlite/sqlite_utility.php | 2 +- 35 files changed, 35 insertions(+), 35 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index 60a67e821..fb0516ba4 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index dd46981b1..ce9d1c1af 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 6042e0673..3bf065ca5 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 7fe5695b0..2d8f592e3 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index f40eac82d..e6a64f3b8 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 05f06af66..fb791cf30 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index c4d537a3b..a5f174f0a 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index eade10ee8..5a69132cd 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php index 6b02e1eb2..70b20ecf8 100644 --- a/system/database/drivers/mssql/mssql_forge.php +++ b/system/database/drivers/mssql/mssql_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index c0a20dbde..2897ca5a5 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mssql/mssql_utility.php b/system/database/drivers/mssql/mssql_utility.php index b867dd7b1..48ecbc72a 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index f27a1eef6..df18c912e 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index 8faf69550..c02b8cb3a 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index c3aa4ccd7..507389603 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 1259fee6f..e9747c540 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index b50fe5f77..9946ad53f 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index 5d5b78089..d5097335e 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index 16f57c079..c4d8f5d58 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 84ff0daf4..e17889b8c 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 44d5dec7e..64f53cc3f 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index 4bcb081b2..3cd17585a 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 058524f4c..88531b436 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 48d4acec8..854b467e1 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index af90f0c7a..c8e03c356 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php index 602016ad4..3ec86b4e9 100644 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index b673464b7..a81a2b8b7 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/odbc/odbc_utility.php b/system/database/drivers/odbc/odbc_utility.php index 9f9ef5a3d..d335bed99 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index b61a9d75b..0bb7974d8 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index 16127ffd7..91a1c6861 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index 126631201..e9a1d1607 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index f04c7f083..741c52ea8 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index d6c6897c6..5bfc1f558 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php index 0aa5d382a..56904082e 100644 --- a/system/database/drivers/sqlite/sqlite_forge.php +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index 9a86aa99c..7bd30db7c 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index b76c1b366..508023e2f 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b From 43ded2351b2703bf6fc6d9d0b2311cb08194d4bf Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Fri, 7 Jan 2011 15:05:40 -0500 Subject: Adding batch insert and batch update to the mysqli driver. --- system/database/drivers/mysqli/mysqli_driver.php | 69 ++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'system/database') diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index b50fe5f77..e9ec873b7 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -538,6 +538,24 @@ class CI_DB_mysqli_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Insert_batch statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert_batch($table, $keys, $values) + { + return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values); + } + + // -------------------------------------------------------------------- + /** * Update statement * @@ -571,6 +589,57 @@ class CI_DB_mysqli_driver extends CI_DB { return $sql; } + // -------------------------------------------------------------------- + + /** + * Update_Batch statement + * + * Generates a platform-specific batch update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @return string + */ + function _update_batch($table, $values, $index, $where = NULL) + { + $ids = array(); + $where = ($where != '' AND count($where) >=1) ? implode(" ", $where).' AND ' : ''; + + 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 = ''; + + foreach($final as $k => $v) + { + $cases .= $k.' = CASE '."\n"; + foreach ($v as $row) + { + $cases .= $row."\n"; + } + + $cases .= 'ELSE '.$k.' END, '; + } + + $sql .= substr($cases, 0, -2); + + $sql .= ' WHERE '.$where.$index.' IN ('.implode(',', $ids).')'; + + return $sql; + } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 7b47430b6e2ab7bd60b27f22e6073b4c914a59f5 Mon Sep 17 00:00:00 2001 From: John Crepezzi Date: Sat, 15 Jan 2011 18:17:01 -0500 Subject: sharing some work on model instances --- system/database/DB_result.php | 85 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 74 insertions(+), 11 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 05f06af66..0cb89b91a 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -28,13 +28,14 @@ */ class CI_DB_result { - var $conn_id = NULL; - var $result_id = NULL; - var $result_array = array(); - var $result_object = array(); - var $current_row = 0; - var $num_rows = 0; - var $row_data = NULL; + var $conn_id = NULL; + var $result_id = NULL; + var $result_array = array(); + var $result_object = array(); + var $custom_result_object = array(); + var $current_row = 0; + var $num_rows = 0; + var $row_data = NULL; /** @@ -46,11 +47,48 @@ class CI_DB_result { */ function result($type = 'object') { - return ($type == 'object') ? $this->result_object() : $this->result_array(); + if ($type == 'array') return $this->result_array(); + else if ($type == 'object') return $this->result_object(); + else return $this->custom_result_object($type); } // -------------------------------------------------------------------- + /** + * Custom query result. + * + * @param class_name A string that represents the type of object you want back + * @return array of objects + */ + function custom_result_object($class_name) + { + if (array_key_exists($class_name, $this->custom_result_object)) + { + return $this->custom_result_object[$class_name]; + } + + if ($this->result_id === FALSE OR $this->num_rows() == 0) + { + return array(); + } + + // add the data to the object + $this->_data_seek(0); + $result_object = array(); + while ($row = $this->_fetch_object()) + { + $object = new $class_name(); + foreach($row as $key => $value) + { + $object->$key = $value; + } + $result_object[] = $object; + } + + // return the array + return $this->custom_result_object[$class_name] = $result_object; + } + /** * Query result. "object" version. * @@ -142,7 +180,9 @@ class CI_DB_result { $n = 0; } - return ($type == 'object') ? $this->row_object($n) : $this->row_array($n); + if ($type == 'object') return $this->row_object($n); + else if ($type == 'array') return $this->row_array($n); + else return $this->custom_row_object($n, $type); } // -------------------------------------------------------------------- @@ -179,7 +219,30 @@ class CI_DB_result { // -------------------------------------------------------------------- - /** + /** + * Returns a single result row - custom object version + * + * @access public + * @return object + */ + function custom_row_object($n, $type) + { + $result = $this->custom_result_object($type); + + if (count($result) == 0) + { + return $result; + } + + if ($n != $this->current_row AND isset($result[$n])) + { + $this->current_row = $n; + } + + return $result[$this->current_row]; + } + + /** * Returns a single result row - object version * * @access public @@ -339,4 +402,4 @@ class CI_DB_result { // END DB_result class /* End of file DB_result.php */ -/* Location: ./system/database/DB_result.php */ \ No newline at end of file +/* Location: ./system/database/DB_result.php */ -- cgit v1.2.3-24-g4f1b From e3da4283b8b0aa96ee6f877c85c62d05dea8c778 Mon Sep 17 00:00:00 2001 From: joelcox Date: Sun, 16 Jan 2011 15:00:04 +0100 Subject: Changed loading process for database config to check for config for the set environment first. --- system/database/DB.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index 60a67e821..739e9d08e 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -27,7 +27,21 @@ function &DB($params = '', $active_record_override = NULL) // Load the DB config file if a DSN string wasn't passed if (is_string($params) AND strpos($params, '://') === FALSE) { - include(APPPATH.'config/database'.EXT); + + $file_path = APPPATH.'config/'.ENVIRONMENT.'/database'.EXT; + + if ( ! file_exists($file_path)) + { + log_message('debug', 'Database config for '.ENVIRONMENT.' environment is not found. Trying global config.'); + $file_path = APPPATH.'config/database'.EXT; + + if ( ! file_exists($file_path)) + { + continue; + } + } + + include($file_path); if ( ! isset($db) OR count($db) == 0) { -- cgit v1.2.3-24-g4f1b From 3167eebb81d740e0a74b28ff0353dd4fcf110d0e Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Tue, 8 Feb 2011 21:19:28 +0000 Subject: MySQL Driver will now wrap field names for insert(), update() and replace() with backticks (`) so fields like "default" and "order" will not cause SQL errors. --- system/database/drivers/mysql/mysql_driver.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index df18c912e..c9fc1ecab 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -287,12 +287,12 @@ class CI_DB_mysql_driver extends CI_DB { 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)) { @@ -532,7 +532,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function _insert($table, $keys, $values) { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return "INSERT INTO ".$table." (`".implode('`, `', $keys)."`) VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -551,7 +551,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function _replace($table, $keys, $values) { - return "REPLACE INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return "REPLACE INTO ".$table." (`".implode('`, `', $keys)."`) VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -569,7 +569,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function _insert_batch($table, $keys, $values) { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values); + return "INSERT INTO ".$table." (`".implode('`, `', $keys)."`) VALUES ".implode(', ', $values); } // -------------------------------------------------------------------- @@ -592,7 +592,7 @@ class CI_DB_mysql_driver extends CI_DB { { foreach($values as $key => $val) { - $valstr[] = $key." = ".$val; + $valstr[] = sprintf('`%s` = %s', $key, $val); } $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; -- cgit v1.2.3-24-g4f1b From a12216baff3aef18413a84e3d37aba2096b5ebe8 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Wed, 9 Feb 2011 16:09:31 +0000 Subject: Reverted recent MySQL backtick escaping as some queries were double-escaping. --- system/database/drivers/mysql/mysql_driver.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index c9fc1ecab..72c834b8f 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -532,7 +532,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function _insert($table, $keys, $values) { - return "INSERT INTO ".$table." (`".implode('`, `', $keys)."`) VALUES (".implode(', ', $values).")"; + return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -551,7 +551,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function _replace($table, $keys, $values) { - return "REPLACE INTO ".$table." (`".implode('`, `', $keys)."`) VALUES (".implode(', ', $values).")"; + return "REPLACE INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -569,7 +569,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function _insert_batch($table, $keys, $values) { - return "INSERT INTO ".$table." (`".implode('`, `', $keys)."`) VALUES ".implode(', ', $values); + return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values); } // -------------------------------------------------------------------- @@ -592,7 +592,7 @@ class CI_DB_mysql_driver extends CI_DB { { foreach($values as $key => $val) { - $valstr[] = sprintf('`%s` = %s', $key, $val); + $valstr[] = $key . ' = ' . $val; } $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; -- cgit v1.2.3-24-g4f1b From 8761ef56b465a190489ed555c6a0ab58470bfc73 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Mon, 14 Feb 2011 13:13:52 -0500 Subject: Uppercasing some stray lowercase keywords for code consistency --- system/database/drivers/odbc/odbc_result.php | 4 ++-- system/database/drivers/postgre/postgre_driver.php | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index a81a2b8b7..5d64a464f 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -188,7 +188,7 @@ class CI_DB_odbc_result extends CI_DB_result { */ function _odbc_fetch_object(& $odbc_result) { $rs = array(); - $rs_obj = false; + $rs_obj = FALSE; if (odbc_fetch_into($odbc_result, $rs)) { foreach ($rs as $k=>$v) { $field_name= odbc_field_name($odbc_result, $k+1); @@ -210,7 +210,7 @@ class CI_DB_odbc_result extends CI_DB_result { */ function _odbc_fetch_array(& $odbc_result) { $rs = array(); - $rs_assoc = false; + $rs_assoc = FALSE; if (odbc_fetch_into($odbc_result, $rs)) { $rs_assoc=array(); foreach ($rs as $k=>$v) { diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 0bb7974d8..81ca6e051 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -330,21 +330,21 @@ class CI_DB_postgre_driver extends CI_DB { $v = $this->_version(); $v = $v['server']; - $table = func_num_args() > 0 ? func_get_arg(0) : null; - $column = func_num_args() > 1 ? func_get_arg(1) : null; + $table = func_num_args() > 0 ? func_get_arg(0) : NULL; + $column = func_num_args() > 1 ? func_get_arg(1) : NULL; - if ($table == null && $v >= '8.1') + if ($table == NULL && $v >= '8.1') { $sql='SELECT LASTVAL() as ins_id'; } - elseif ($table != null && $column != null && $v >= '8.0') + elseif ($table != NULL && $column != NULL && $v >= '8.0') { $sql = sprintf("SELECT pg_get_serial_sequence('%s','%s') as seq", $table, $column); $query = $this->query($sql); $row = $query->row(); $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $row->seq); } - elseif ($table != null) + elseif ($table != NULL) { // seq_name passed in table parameter $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $table); -- cgit v1.2.3-24-g4f1b From c3a4a8d973b9c0a7cc935d150b8b1c6898037c45 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Mon, 14 Feb 2011 13:40:08 -0500 Subject: Whitespace cleanup in db classes --- system/database/DB.php | 2 +- system/database/DB_active_rec.php | 6 +++--- system/database/DB_driver.php | 12 ++++++------ system/database/DB_forge.php | 2 +- system/database/DB_result.php | 2 +- system/database/drivers/mssql/mssql_driver.php | 4 ++-- system/database/drivers/mysql/mysql_driver.php | 10 +++++----- system/database/drivers/mysqli/mysqli_driver.php | 10 +++++----- system/database/drivers/oci8/oci8_driver.php | 6 +++--- system/database/drivers/odbc/odbc_driver.php | 4 ++-- system/database/drivers/postgre/postgre_driver.php | 4 ++-- system/database/drivers/sqlite/sqlite_driver.php | 4 ++-- 12 files changed, 33 insertions(+), 33 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index 513e5aefd..93ee3922a 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -88,7 +88,7 @@ function &DB($params = '', $active_record_override = NULL) { parse_str($dns['query'], $extra); - foreach($extra as $key => $val) + foreach ($extra as $key => $val) { // booleans please if (strtoupper($val) == "TRUE") diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index ce9d1c1af..06ec3cd95 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1167,7 +1167,7 @@ class CI_DB_active_record extends CI_DB_driver { { $clean = array(); - foreach($row as $value) + foreach ($row as $value) { $clean[] = $this->escape($value); } @@ -1425,7 +1425,7 @@ class CI_DB_active_record extends CI_DB_driver { $index_set = FALSE; $clean = array(); - foreach($v as $k2 => $v2) + foreach ($v as $k2 => $v2) { if ($k2 == $index) { @@ -1569,7 +1569,7 @@ class CI_DB_active_record extends CI_DB_driver { } elseif (is_array($table)) { - foreach($table as $single_table) + foreach ($table as $single_table) { $this->delete($single_table, $where, $limit, FALSE); } diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 2d8f592e3..e7a9de475 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -767,7 +767,7 @@ class CI_DB_driver { if ($query->num_rows() > 0) { - foreach($query->result_array() as $row) + foreach ($query->result_array() as $row) { if (isset($row['TABLE_NAME'])) { @@ -834,7 +834,7 @@ class CI_DB_driver { $query = $this->query($sql); $retval = array(); - foreach($query->result_array() as $row) + foreach ($query->result_array() as $row) { if (isset($row['COLUMN_NAME'])) { @@ -904,7 +904,7 @@ class CI_DB_driver { $fields = array(); $values = array(); - foreach($data as $key => $val) + foreach ($data as $key => $val) { $fields[] = $this->_escape_identifiers($key); $values[] = $this->escape($val); @@ -932,7 +932,7 @@ class CI_DB_driver { } $fields = array(); - foreach($data as $key => $val) + foreach ($data as $key => $val) { $fields[$this->_protect_identifiers($key)] = $this->escape($val); } @@ -1175,7 +1175,7 @@ class CI_DB_driver { $trace = debug_backtrace(); - foreach($trace as $call) + foreach ($trace as $call) { if (isset($call['file']) && strpos($call['file'], BASEPATH.'database') === FALSE) { @@ -1248,7 +1248,7 @@ class CI_DB_driver { { $escaped_array = array(); - foreach($item as $k => $v) + foreach ($item as $k => $v) { $escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v); } diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index 27f2c372d..a71fca78f 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -99,7 +99,7 @@ class CI_DB_forge { { if (is_array($key)) { - foreach($key as $one) + foreach ($key as $one) { $this->add_key($one, $primary); } diff --git a/system/database/DB_result.php b/system/database/DB_result.php index fb4268c21..76e1d6abb 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -78,7 +78,7 @@ class CI_DB_result { while ($row = $this->_fetch_object()) { $object = new $class_name(); - foreach($row as $key => $value) + foreach ($row as $key => $value) { $object->$key = $value; } diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 5a69132cd..5048c0b4a 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -253,7 +253,7 @@ class CI_DB_mssql_driver extends CI_DB { { if (is_array($str)) { - foreach($str as $key => $val) + foreach ($str as $key => $val) { $str[$key] = $this->escape_str($val, $like); } @@ -551,7 +551,7 @@ class CI_DB_mssql_driver extends CI_DB { */ function _update($table, $values, $where, $orderby = array(), $limit = FALSE) { - foreach($values as $key => $val) + foreach ($values as $key => $val) { $valstr[] = $key." = ".$val; } diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 72c834b8f..4ff9b0a11 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -286,7 +286,7 @@ class CI_DB_mysql_driver extends CI_DB { { if (is_array($str)) { - foreach($str as $key => $val) + foreach ($str as $key => $val) { $str[$key] = $this->escape_str($val, $like); } @@ -590,7 +590,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function _update($table, $values, $where, $orderby = array(), $limit = FALSE) { - foreach($values as $key => $val) + foreach ($values as $key => $val) { $valstr[] = $key . ' = ' . $val; } @@ -627,11 +627,11 @@ class CI_DB_mysql_driver extends CI_DB { $ids = array(); $where = ($where != '' AND count($where) >=1) ? implode(" ", $where).' AND ' : ''; - foreach($values as $key => $val) + foreach ($values as $key => $val) { $ids[] = $val[$index]; - foreach(array_keys($val) as $field) + foreach (array_keys($val) as $field) { if ($field != $index) { @@ -643,7 +643,7 @@ class CI_DB_mysql_driver extends CI_DB { $sql = "UPDATE ".$table." SET "; $cases = ''; - foreach($final as $k => $v) + foreach ($final as $k => $v) { $cases .= $k.' = CASE '."\n"; foreach ($v as $row) diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 8942100d4..ccdabce1a 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -287,7 +287,7 @@ class CI_DB_mysqli_driver extends CI_DB { { if (is_array($str)) { - foreach($str as $key => $val) + foreach ($str as $key => $val) { $str[$key] = $this->escape_str($val, $like); } @@ -571,7 +571,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ function _update($table, $values, $where, $orderby = array(), $limit = FALSE) { - foreach($values as $key => $val) + foreach ($values as $key => $val) { $valstr[] = $key." = ".$val; } @@ -607,11 +607,11 @@ class CI_DB_mysqli_driver extends CI_DB { $ids = array(); $where = ($where != '' AND count($where) >=1) ? implode(" ", $where).' AND ' : ''; - foreach($values as $key => $val) + foreach ($values as $key => $val) { $ids[] = $val[$index]; - foreach(array_keys($val) as $field) + foreach (array_keys($val) as $field) { if ($field != $index) { @@ -623,7 +623,7 @@ class CI_DB_mysqli_driver extends CI_DB { $sql = "UPDATE ".$table." SET "; $cases = ''; - foreach($final as $k => $v) + foreach ($final as $k => $v) { $cases .= $k.' = CASE '."\n"; foreach ($v as $row) diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 64f53cc3f..14df104ff 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -253,7 +253,7 @@ class CI_DB_oci8_driver extends CI_DB { $sql = "begin $package.$procedure("; $have_cursor = FALSE; - foreach($params as $param) + foreach ($params as $param) { $sql .= $param['name'] . ","; @@ -395,7 +395,7 @@ class CI_DB_oci8_driver extends CI_DB { { if (is_array($str)) { - foreach($str as $key => $val) + foreach ($str as $key => $val) { $str[$key] = $this->escape_str($val, $like); } @@ -655,7 +655,7 @@ class CI_DB_oci8_driver extends CI_DB { */ function _update($table, $values, $where, $orderby = array(), $limit = FALSE) { - foreach($values as $key => $val) + foreach ($values as $key => $val) { $valstr[] = $key." = ".$val; } diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index c8e03c356..81e0d7cf2 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -264,7 +264,7 @@ class CI_DB_odbc_driver extends CI_DB { { if (is_array($str)) { - foreach($str as $key => $val) + foreach ($str as $key => $val) { $str[$key] = $this->escape_str($val, $like); } @@ -523,7 +523,7 @@ class CI_DB_odbc_driver extends CI_DB { */ function _update($table, $values, $where, $orderby = array(), $limit = FALSE) { - foreach($values as $key => $val) + foreach ($values as $key => $val) { $valstr[] = $key." = ".$val; } diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 81ca6e051..47ff36246 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -283,7 +283,7 @@ class CI_DB_postgre_driver extends CI_DB { { if (is_array($str)) { - foreach($str as $key => $val) + foreach ($str as $key => $val) { $str[$key] = $this->escape_str($val, $like); } @@ -568,7 +568,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function _update($table, $values, $where, $orderby = array(), $limit = FALSE) { - foreach($values as $key => $val) + foreach ($values as $key => $val) { $valstr[] = $key." = ".$val; } diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 5bfc1f558..eb4e585b3 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -280,7 +280,7 @@ class CI_DB_sqlite_driver extends CI_DB { { if (is_array($str)) { - foreach($str as $key => $val) + foreach ($str as $key => $val) { $str[$key] = $this->escape_str($val, $like); } @@ -537,7 +537,7 @@ class CI_DB_sqlite_driver extends CI_DB { */ function _update($table, $values, $where, $orderby = array(), $limit = FALSE) { - foreach($values as $key => $val) + foreach ($values as $key => $val) { $valstr[] = $key." = ".$val; } -- cgit v1.2.3-24-g4f1b From d0ac1a250608c1fe21f11bb96c4291e38962b187 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Tue, 15 Feb 2011 22:54:08 +0000 Subject: Better potential fix for escaping MySQL keywords with backticks on insert/update. --- system/database/DB_active_rec.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 06ec3cd95..ee72dbbf4 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -954,7 +954,7 @@ class CI_DB_active_record extends CI_DB_driver { } else { - $this->ar_set[$this->_protect_identifiers($k)] = $this->escape($v); + $this->ar_set[$this->_protect_identifiers($k, FALSE, TRUE)] = $this->escape($v); } } @@ -1156,7 +1156,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->ar_set[] = array(); return; } - + ksort($row); // puts $row in the same order as our keys if ($escape === FALSE) -- cgit v1.2.3-24-g4f1b From 64f96e3a96878bbddfc01960cbde12957f243d6e Mon Sep 17 00:00:00 2001 From: davidhart Date: Tue, 8 Mar 2011 12:00:21 +0000 Subject: Fixed bug in escaping underscores etc in MSSQL LIKE conditions. --- system/database/drivers/mssql/mssql_driver.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 5048c0b4a..b581a478c 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -267,9 +267,9 @@ class CI_DB_mssql_driver extends CI_DB { // escape LIKE condition wildcards if ($like === TRUE) { - $str = str_replace( array('%', '_', $this->_like_escape_chr), - array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr), - $str); + $str = str_replace( array('%', $this->_like_escape_chr, '_'), + array($this->_like_escape_chr.'%', $this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'_'), + $str); } return $str; -- cgit v1.2.3-24-g4f1b From 84445d08e31c4d538d5a25023b8e5861804a8f14 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Thu, 10 Mar 2011 16:43:39 +0000 Subject: Added sqlsrv folder, added necessary files, started altering queries in sqlsrv_driver.php --- system/database/drivers/sqlsrv/index.html | 10 + system/database/drivers/sqlsrv/sqlsrv_driver.php | 664 ++++++++++++++++++++++ system/database/drivers/sqlsrv/sqlsrv_forge.php | 248 ++++++++ system/database/drivers/sqlsrv/sqlsrv_result.php | 169 ++++++ system/database/drivers/sqlsrv/sqlsrv_utility.php | 88 +++ 5 files changed, 1179 insertions(+) create mode 100644 system/database/drivers/sqlsrv/index.html create mode 100644 system/database/drivers/sqlsrv/sqlsrv_driver.php create mode 100644 system/database/drivers/sqlsrv/sqlsrv_forge.php create mode 100644 system/database/drivers/sqlsrv/sqlsrv_result.php create mode 100644 system/database/drivers/sqlsrv/sqlsrv_utility.php (limited to 'system/database') diff --git a/system/database/drivers/sqlsrv/index.html b/system/database/drivers/sqlsrv/index.html new file mode 100644 index 000000000..c942a79ce --- /dev/null +++ b/system/database/drivers/sqlsrv/index.html @@ -0,0 +1,10 @@ + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + \ No newline at end of file diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php new file mode 100644 index 000000000..d64e98108 --- /dev/null +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -0,0 +1,664 @@ +port != '') + { + $this->hostname .= ','.$this->port; + } + + return @sqlsrv_connect($this->hostname, array('UID' => $this->username, 'PWD' => $this->password, 'Database' => $this->database, 'ConnectionPooling' => 0)); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + if ($this->port != '') + { + $this->hostname .= ','.$this->port; + } + + return @sqlsrv_connect($this->hostname, array('UID' => $this->username, 'PWD' => $this->password, 'Database' => $this->database, 'ConnectionPooling' => 1)); + } + + // -------------------------------------------------------------------- + + /** + * Reconnect + * + * Keep / reestablish the db connection if no queries have been + * sent for a length of time exceeding the server's idle timeout + * + * @access public + * @return void + */ + function reconnect() + { + // not implemented in MSSQL + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + // Note: The brackets are required in the event that the DB name + // contains reserved characters + return @mssql_select_db('['.$this->database.']', $this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Set client character set + * + * @access public + * @param string + * @param string + * @return resource + */ + function db_set_charset($charset, $collation) + { + // @todo - add support if needed + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + function _execute($sql) + { + $sql = $this->_prep_query($sql); + return @sqlsrv_query($this->conn_id, $sql); + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @access private called by execute() + * @param string an SQL query + * @return string + */ + function _prep_query($sql) + { + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @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) + { + return TRUE; + } + + // Reset the transaction failure flag. + // 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('BEGIN TRAN'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @access public + * @return bool + */ + function trans_commit() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $this->simple_query('COMMIT TRAN'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @access public + * @return bool + */ + function trans_rollback() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + $this->simple_query('ROLLBACK TRAN'); + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @param bool whether or not the string will be used in a LIKE condition + * @return string + */ + function escape_str($str, $like = FALSE) + { + if (is_array($str)) + { + foreach ($str as $key => $val) + { + $str[$key] = $this->escape_str($val, $like); + } + + return $str; + } + + // Escape single quotes + $str = str_replace("'", "''", remove_invisible_characters($str)); + + // escape LIKE condition wildcards + if ($like === TRUE) + { + $str = str_replace( array('%', '_', $this->_like_escape_chr), + array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr), + $str); + } + + return $str; + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @mssql_rows_affected($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * Returns the last id created in the Identity column. + * + * @access public + * @return integer + */ + function insert_id() + { + $ver = self::_parse_major_version($this->version()); + $sql = ($ver >= 8 ? "SELECT SCOPE_IDENTITY() AS last_id" : "SELECT @@IDENTITY AS last_id"); + $query = $this->query($sql); + $row = $query->row(); + return $row->last_id; + } + + // -------------------------------------------------------------------- + + /** + * Parse major version + * + * Grabs the major version number from the + * database server version string passed in. + * + * @access private + * @param string $version + * @return int16 major version number + */ + function _parse_major_version($version) + { + preg_match('/([0-9]+)\.([0-9]+)\.([0-9]+)/', $version, $ver_info); + return $ver_info[1]; // return the major version b/c that's all we're interested in. + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT @@VERSION AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + { + 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) + { + return 0; + } + + $row = $query->row(); + return (int) $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * List table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @param boolean + * @return string + */ + function _list_tables($prefix_limit = FALSE) + { + $sql = "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; + + // for future compatibility + if ($prefix_limit !== FALSE AND $this->dbprefix != '') + { + //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); + return FALSE; // not currently supported + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * List column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access private + * @param string the table name + * @return string + */ + function _list_columns($table = '') + { + return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$table."'"; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + return "SELECT TOP 1 * FROM ".$table; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access private + * @return string + */ + function _error_message() + { + return sqlsrv_errors(); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access private + * @return integer + */ + function _error_number() + { + // Are error numbers supported? + return ''; + } + + // -------------------------------------------------------------------- + + /** + * Escape the SQL Identifiers + * + * This function escapes column and table names + * + * @access private + * @param string + * @return string + */ + function _escape_identifiers($item) + { + if ($this->_escape_char == '') + { + return $item; + } + + foreach ($this->_reserved_identifiers as $id) + { + if (strpos($item, '.'.$id) !== FALSE) + { + $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; + } + 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); + } + + // -------------------------------------------------------------------- + + /** + * From Tables + * + * This function implicitly groups FROM tables so there is no confusion + * about operator precedence in harmony with SQL standards + * + * @access public + * @param type + * @return type + */ + function _from_tables($tables) + { + if ( ! is_array($tables)) + { + $tables = array($tables); + } + + return implode(', ', $tables); + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @param array the orderby clause + * @param array the limit clause + * @return string + */ + function _update($table, $values, $where, $orderby = array(), $limit = FALSE) + { + foreach ($values as $key => $val) + { + $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; + } + + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * If the database does not support the truncate() command + * This function maps to "DELETE FROM table" + * + * @access public + * @param string the table name + * @return string + */ + function _truncate($table) + { + return "TRUNCATE ".$table; + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @param string the limit clause + * @return string + */ + function _delete($table, $where = array(), $like = array(), $limit = FALSE) + { + $conditions = ''; + + if (count($where) > 0 OR count($like) > 0) + { + $conditions = "\nWHERE "; + $conditions .= implode("\n", $this->ar_where); + + if (count($where) > 0 && count($like) > 0) + { + $conditions .= " AND "; + } + $conditions .= implode("\n", $like); + } + + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; + + return "DELETE FROM ".$table.$conditions.$limit; + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + $i = $limit + $offset; + + return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql); + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + @sqlsrv_close($conn_id); + } + +} + + + +/* End of file mssql_driver.php */ +/* Location: ./system/database/drivers/mssql/mssql_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/sqlsrv/sqlsrv_forge.php b/system/database/drivers/sqlsrv/sqlsrv_forge.php new file mode 100644 index 000000000..70b20ecf8 --- /dev/null +++ b/system/database/drivers/sqlsrv/sqlsrv_forge.php @@ -0,0 +1,248 @@ +db->_escape_identifiers($table); + } + + // -------------------------------------------------------------------- + + /** + * Create Table + * + * @access private + * @param string the table name + * @param array the fields + * @param mixed primary key(s) + * @param mixed key(s) + * @param boolean should 'IF NOT EXISTS' be added to the SQL + * @return bool + */ + 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)." ("; + $current_field_count = 0; + + foreach ($fields as $field=>$attributes) + { + // Numeric field names aren't allowed in databases, so if the key is + // numeric, we know it was assigned by PHP and the developer manually + // entered the field information, so we'll simply add it to the list + if (is_numeric($field)) + { + $sql .= "\n\t$attributes"; + } + else + { + $attributes = array_change_key_case($attributes, CASE_UPPER); + + $sql .= "\n\t".$this->db->_protect_identifiers($field); + + $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) && $attributes['NULL'] === TRUE) + { + $sql .= ' NULL'; + } + else + { + $sql .= ' 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 .= ','; + } + } + + if (count($primary_keys) > 0) + { + $primary_keys = $this->db->_protect_identifiers($primary_keys); + $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; + } + + if (is_array($keys) && count($keys) > 0) + { + foreach ($keys as $key) + { + if (is_array($key)) + { + $key = $this->db->_protect_identifiers($key); + } + else + { + $key = array($this->db->_protect_identifiers($key)); + } + + $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")"; + } + } + + $sql .= "\n)"; + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Alter table query + * + * Generates a platform-specific query so that a table can be altered + * Called by add_column(), drop_column(), and column_alter(), + * + * @access private + * @param string the ALTER type (ADD, DROP, CHANGE) + * @param string the column name + * @param string the table name + * @param string the column definition + * @param string the default value + * @param boolean should 'NOT NULL' be added + * @param string the field after which we should add the new field + * @return object + */ + function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') + { + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name); + + // DROP has everything it needs now. + if ($alter_type == 'DROP') + { + return $sql; + } + + $sql .= " $column_definition"; + + if ($default_value != '') + { + $sql .= " DEFAULT \"$default_value\""; + } + + if ($null === NULL) + { + $sql .= ' NULL'; + } + else + { + $sql .= ' NOT NULL'; + } + + if ($after_field != '') + { + $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); + } + + return $sql; + + } + + // -------------------------------------------------------------------- + + /** + * Rename a table + * + * Generates a platform-specific query so that a table can be renamed + * + * @access private + * @param string the old table name + * @param string the new table name + * @return string + */ + function _rename_table($table_name, $new_table_name) + { + // I think this syntax will work, but can find little documentation on renaming tables in MSSQL + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); + return $sql; + } + +} + +/* End of file mssql_forge.php */ +/* Location: ./system/database/drivers/mssql/mssql_forge.php */ \ No newline at end of file diff --git a/system/database/drivers/sqlsrv/sqlsrv_result.php b/system/database/drivers/sqlsrv/sqlsrv_result.php new file mode 100644 index 000000000..2897ca5a5 --- /dev/null +++ b/system/database/drivers/sqlsrv/sqlsrv_result.php @@ -0,0 +1,169 @@ +result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @mssql_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function list_fields() + { + $field_names = array(); + while ($field = mssql_fetch_field($this->result_id)) + { + $field_names[] = $field->name; + } + + return $field_names; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + while ($field = mssql_fetch_field($this->result_id)) + { + $F = new stdClass(); + $F->name = $field->name; + $F->type = $field->type; + $F->max_length = $field->max_length; + $F->primary_key = 0; + $F->default = ''; + + $retval[] = $F; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return null + */ + function free_result() + { + if (is_resource($this->result_id)) + { + mssql_free_result($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero + * + * @access private + * @return array + */ + function _data_seek($n = 0) + { + return mssql_data_seek($this->result_id, $n); + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @access private + * @return array + */ + function _fetch_assoc() + { + return mssql_fetch_assoc($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + function _fetch_object() + { + return mssql_fetch_object($this->result_id); + } + +} + + +/* End of file mssql_result.php */ +/* Location: ./system/database/drivers/mssql/mssql_result.php */ \ No newline at end of file diff --git a/system/database/drivers/sqlsrv/sqlsrv_utility.php b/system/database/drivers/sqlsrv/sqlsrv_utility.php new file mode 100644 index 000000000..48ecbc72a --- /dev/null +++ b/system/database/drivers/sqlsrv/sqlsrv_utility.php @@ -0,0 +1,88 @@ +db->display_error('db_unsuported_feature'); + } + +} + +/* End of file mssql_utility.php */ +/* Location: ./system/database/drivers/mssql/mssql_utility.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 079069c2fa70b142fb4313f12f1fdf3f11713ff5 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Thu, 10 Mar 2011 19:36:58 +0000 Subject: Think I've finished converting mssql commands to sqlsrv where appropriate --- system/database/drivers/sqlsrv/sqlsrv_driver.php | 4 +--- system/database/drivers/sqlsrv/sqlsrv_result.php | 16 ++++++++-------- 2 files changed, 9 insertions(+), 11 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index d64e98108..53d974837 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -107,9 +107,7 @@ class CI_DB_mssql_driver extends CI_DB { */ function db_select() { - // Note: The brackets are required in the event that the DB name - // contains reserved characters - return @mssql_select_db('['.$this->database.']', $this->conn_id); + // not implemented in sqlsrv } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlsrv/sqlsrv_result.php b/system/database/drivers/sqlsrv/sqlsrv_result.php index 2897ca5a5..058c6f478 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_result.php +++ b/system/database/drivers/sqlsrv/sqlsrv_result.php @@ -34,7 +34,7 @@ class CI_DB_mssql_result extends CI_DB_result { */ function num_rows() { - return @mssql_num_rows($this->result_id); + return @sqlsrv_num_rows($this->result_id); } // -------------------------------------------------------------------- @@ -47,7 +47,7 @@ class CI_DB_mssql_result extends CI_DB_result { */ function num_fields() { - return @mssql_num_fields($this->result_id); + return @sqlsrv_num_fields($this->result_id); } // -------------------------------------------------------------------- @@ -63,7 +63,7 @@ class CI_DB_mssql_result extends CI_DB_result { function list_fields() { $field_names = array(); - while ($field = mssql_fetch_field($this->result_id)) + while ($field = sqlsrv_get_field($this->result_id)) { $field_names[] = $field->name; } @@ -84,7 +84,7 @@ class CI_DB_mssql_result extends CI_DB_result { function field_data() { $retval = array(); - while ($field = mssql_fetch_field($this->result_id)) + while ($field = sqlsrv_get_field($this->result_id)) { $F = new stdClass(); $F->name = $field->name; @@ -110,7 +110,7 @@ class CI_DB_mssql_result extends CI_DB_result { { if (is_resource($this->result_id)) { - mssql_free_result($this->result_id); + sqlsrv_free_stmt($this->result_id); $this->result_id = FALSE; } } @@ -129,7 +129,7 @@ class CI_DB_mssql_result extends CI_DB_result { */ function _data_seek($n = 0) { - return mssql_data_seek($this->result_id, $n); + // Not implemented } // -------------------------------------------------------------------- @@ -144,7 +144,7 @@ class CI_DB_mssql_result extends CI_DB_result { */ function _fetch_assoc() { - return mssql_fetch_assoc($this->result_id); + return sqlsrv_fetch_array($this->result_id, SQLSRV_FETCH_ASSOC); } // -------------------------------------------------------------------- @@ -159,7 +159,7 @@ class CI_DB_mssql_result extends CI_DB_result { */ function _fetch_object() { - return mssql_fetch_object($this->result_id); + return sqlsrv_fetch_object($this->result_id); } } -- cgit v1.2.3-24-g4f1b From 5336ee283c764a8f3ef9baa746324d7f6a26499f Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sat, 12 Mar 2011 23:35:29 +0000 Subject: Added flag to return dates as strings instead of PHP date objects. Updated db_select --- system/database/drivers/sqlsrv/sqlsrv_driver.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index 53d974837..25cc628df 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -60,7 +60,7 @@ class CI_DB_mssql_driver extends CI_DB { $this->hostname .= ','.$this->port; } - return @sqlsrv_connect($this->hostname, array('UID' => $this->username, 'PWD' => $this->password, 'Database' => $this->database, 'ConnectionPooling' => 0)); + return @sqlsrv_connect($this->hostname, array('UID' => $this->username, 'PWD' => $this->password, 'Database' => $this->database, 'ConnectionPooling' => 0, 'ReturnDatesAsStrings' => 1)); } // -------------------------------------------------------------------- @@ -78,7 +78,7 @@ class CI_DB_mssql_driver extends CI_DB { $this->hostname .= ','.$this->port; } - return @sqlsrv_connect($this->hostname, array('UID' => $this->username, 'PWD' => $this->password, 'Database' => $this->database, 'ConnectionPooling' => 1)); + return @sqlsrv_connect($this->hostname, array('UID' => $this->username, 'PWD' => $this->password, 'Database' => $this->database, 'ConnectionPooling' => 1, 'ReturnDatesAsStrings' => 1)); } // -------------------------------------------------------------------- @@ -107,7 +107,7 @@ class CI_DB_mssql_driver extends CI_DB { */ function db_select() { - // not implemented in sqlsrv + return $this->_execute('USE ' . $this->database); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 56e204079b8b3951abca5165ca815b75d37bf03d Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sat, 12 Mar 2011 23:43:54 +0000 Subject: Updated affected_rows --- system/database/drivers/sqlsrv/sqlsrv_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index 25cc628df..e9c391786 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -283,7 +283,7 @@ class CI_DB_mssql_driver extends CI_DB { */ function affected_rows() { - return @mssql_rows_affected($this->conn_id); + return @sqlrv_rows_affected($this->conn_id); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 01ab00469c80a26c22c61f896f0514dfcedccb67 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Fri, 18 Mar 2011 19:24:30 +0000 Subject: Renamed some classes in the driver --- system/database/drivers/sqlsrv/sqlsrv_driver.php | 4 ++-- system/database/drivers/sqlsrv/sqlsrv_forge.php | 4 ++-- system/database/drivers/sqlsrv/sqlsrv_result.php | 4 ++-- system/database/drivers/sqlsrv/sqlsrv_utility.php | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index e9c391786..116907123 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -16,7 +16,7 @@ // ------------------------------------------------------------------------ /** - * MS SQL Database Adapter Class + * SQLSRV Database Adapter Class * * Note: _DB is an extender class that the app controller * creates dynamically based on whether the active record @@ -28,7 +28,7 @@ * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/database/ */ -class CI_DB_mssql_driver extends CI_DB { +class CI_DB_sqlsrv_driver extends CI_DB { var $dbdriver = 'sqlsrv'; diff --git a/system/database/drivers/sqlsrv/sqlsrv_forge.php b/system/database/drivers/sqlsrv/sqlsrv_forge.php index 70b20ecf8..cc88ec5ca 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_forge.php +++ b/system/database/drivers/sqlsrv/sqlsrv_forge.php @@ -16,13 +16,13 @@ // ------------------------------------------------------------------------ /** - * MS SQL Forge Class + * SQLSRV Forge Class * * @category Database * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/database/ */ -class CI_DB_mssql_forge extends CI_DB_forge { +class CI_DB_sqlsrv_forge extends CI_DB_forge { /** * Create database diff --git a/system/database/drivers/sqlsrv/sqlsrv_result.php b/system/database/drivers/sqlsrv/sqlsrv_result.php index 058c6f478..458200383 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_result.php +++ b/system/database/drivers/sqlsrv/sqlsrv_result.php @@ -16,7 +16,7 @@ // ------------------------------------------------------------------------ /** - * MS SQL Result Class + * SQLSRV Result Class * * This class extends the parent result class: CI_DB_result * @@ -24,7 +24,7 @@ * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/database/ */ -class CI_DB_mssql_result extends CI_DB_result { +class CI_DB_sqlsrv_result extends CI_DB_result { /** * Number of rows in the result set diff --git a/system/database/drivers/sqlsrv/sqlsrv_utility.php b/system/database/drivers/sqlsrv/sqlsrv_utility.php index 48ecbc72a..13a1850c4 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_utility.php +++ b/system/database/drivers/sqlsrv/sqlsrv_utility.php @@ -16,13 +16,13 @@ // ------------------------------------------------------------------------ /** - * MS SQL Utility Class + * SQLSRV Utility Class * * @category Database * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/database/ */ -class CI_DB_mssql_utility extends CI_DB_utility { +class CI_DB_sqlsrv_utility extends CI_DB_utility { /** * List databases -- cgit v1.2.3-24-g4f1b From 3a43c7adae7737d68a0eeca663cc2dd3fc5b0cf3 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Fri, 18 Mar 2011 19:48:04 +0000 Subject: Updates --- system/database/drivers/sqlsrv/sqlsrv_driver.php | 206 ++++++++--------------- system/database/drivers/sqlsrv/sqlsrv_result.php | 20 +-- 2 files changed, 81 insertions(+), 145 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index 116907123..1d32792ce 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -53,14 +53,27 @@ class CI_DB_sqlsrv_driver extends CI_DB { * @access private called by the base class * @return resource */ - function db_connect() + function db_connect($pooling = false) { - if ($this->port != '') - { - $this->hostname .= ','.$this->port; + // Check for a UTF-8 charset being passed as CI's default 'utf8'. + $character_set = (0 === strcasecmp('utf8', $this->char_set)) ? 'UTF-8' : $this->char_set; + + $connection = array( + 'UID' => empty($this->username) ? '' : $this->username, + 'PWD' => empty($this->password) ? '' : $this->password, + 'Database' => $this->database, + 'ConnectionPooling' => $pooling ? 1 : 0, + 'CharacterSet' => $character_set, + 'ReturnDatesAsStrings' => 1 + ); + + // If the username and password are both empty, assume this is a + // 'Windows Authentication Mode' connection. + if(empty($connection['UID']) && empty($connection['PWD'])) { + unset($connection['UID'], $connection['PWD']); } - return @sqlsrv_connect($this->hostname, array('UID' => $this->username, 'PWD' => $this->password, 'Database' => $this->database, 'ConnectionPooling' => 0, 'ReturnDatesAsStrings' => 1)); + return sqlsrv_connect($this->hostname, $connection); } // -------------------------------------------------------------------- @@ -73,12 +86,7 @@ class CI_DB_sqlsrv_driver extends CI_DB { */ function db_pconnect() { - if ($this->port != '') - { - $this->hostname .= ','.$this->port; - } - - return @sqlsrv_connect($this->hostname, array('UID' => $this->username, 'PWD' => $this->password, 'Database' => $this->database, 'ConnectionPooling' => 1, 'ReturnDatesAsStrings' => 1)); + $this->db_connect(TRUE); } // -------------------------------------------------------------------- @@ -138,7 +146,10 @@ class CI_DB_sqlsrv_driver extends CI_DB { function _execute($sql) { $sql = $this->_prep_query($sql); - return @sqlsrv_query($this->conn_id, $sql); + return sqlsrv_query($this->conn_id, $sql, null, array( + 'Scrollable' => SQLSRV_CURSOR_STATIC, + 'SendStreamParamsAtExec' => true + )); } // -------------------------------------------------------------------- @@ -183,8 +194,7 @@ class CI_DB_sqlsrv_driver extends CI_DB { // even if the queries produce a successful result. $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; - $this->simple_query('BEGIN TRAN'); - return TRUE; + return sqlsrv_begin_transaction($this->conn_id); } // -------------------------------------------------------------------- @@ -208,8 +218,7 @@ class CI_DB_sqlsrv_driver extends CI_DB { return TRUE; } - $this->simple_query('COMMIT TRAN'); - return TRUE; + return sqlsrv_commit($this->conn_id); } // -------------------------------------------------------------------- @@ -233,8 +242,7 @@ class CI_DB_sqlsrv_driver extends CI_DB { return TRUE; } - $this->simple_query('ROLLBACK TRAN'); - return TRUE; + return sqlsrv_rollback($this->conn_id); } // -------------------------------------------------------------------- @@ -249,28 +257,8 @@ class CI_DB_sqlsrv_driver extends CI_DB { */ function escape_str($str, $like = FALSE) { - if (is_array($str)) - { - foreach ($str as $key => $val) - { - $str[$key] = $this->escape_str($val, $like); - } - - return $str; - } - // Escape single quotes - $str = str_replace("'", "''", remove_invisible_characters($str)); - - // escape LIKE condition wildcards - if ($like === TRUE) - { - $str = str_replace( array('%', '_', $this->_like_escape_chr), - array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr), - $str); - } - - return $str; + return str_replace("'", "''", $str); } // -------------------------------------------------------------------- @@ -298,11 +286,7 @@ class CI_DB_sqlsrv_driver extends CI_DB { */ function insert_id() { - $ver = self::_parse_major_version($this->version()); - $sql = ($ver >= 8 ? "SELECT SCOPE_IDENTITY() AS last_id" : "SELECT @@IDENTITY AS last_id"); - $query = $this->query($sql); - $row = $query->row(); - return $row->last_id; + return $this->query('select @@IDENTITY as insert_id')->row('insert_id'); } // -------------------------------------------------------------------- @@ -333,7 +317,8 @@ class CI_DB_sqlsrv_driver extends CI_DB { */ function _version() { - return "SELECT @@VERSION AS ver"; + $info = sqlsrv_server_info($this->conn_id); + return sprintf("select '%s' as ver", $info['SQLServerVersion']); } // -------------------------------------------------------------------- @@ -351,19 +336,15 @@ class CI_DB_sqlsrv_driver extends CI_DB { function count_all($table = '') { if ($table == '') - { - return 0; - } - - $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); - + return '0'; + + $query = $this->query("SELECT COUNT(*) AS numrows FROM " . $this->dbprefix . $table); + if ($query->num_rows() == 0) - { - return 0; - } + return '0'; $row = $query->row(); - return (int) $row->numrows; + return $row->numrows; } // -------------------------------------------------------------------- @@ -379,16 +360,7 @@ class CI_DB_sqlsrv_driver extends CI_DB { */ function _list_tables($prefix_limit = FALSE) { - $sql = "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; - - // for future compatibility - if ($prefix_limit !== FALSE AND $this->dbprefix != '') - { - //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); - return FALSE; // not currently supported - } - - return $sql; + return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; } // -------------------------------------------------------------------- @@ -404,7 +376,7 @@ class CI_DB_sqlsrv_driver extends CI_DB { */ function _list_columns($table = '') { - return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$table."'"; + return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$this->_escape_table($table)."'"; } // -------------------------------------------------------------------- @@ -420,7 +392,7 @@ class CI_DB_sqlsrv_driver extends CI_DB { */ function _field_data($table) { - return "SELECT TOP 1 * FROM ".$table; + return "SELECT TOP 1 * FROM " . $this->_escape_table($table); } // -------------------------------------------------------------------- @@ -433,7 +405,8 @@ class CI_DB_sqlsrv_driver extends CI_DB { */ function _error_message() { - return sqlsrv_errors(); + $error = array_shift(sqlsrv_errors()); + return !empty($error['message']) ? $error['message'] : null; } // -------------------------------------------------------------------- @@ -446,12 +419,28 @@ class CI_DB_sqlsrv_driver extends CI_DB { */ function _error_number() { - // Are error numbers supported? - return ''; + $error = array_shift(sqlsrv_errors()); + return isset($error['SQLSTATE']) ? $error['SQLSTATE'] : null; } // -------------------------------------------------------------------- + /** + * Escape Table Name + * + * This function adds backticks if the table name has a period + * in it. Some DBs will get cranky unless periods are escaped + * + * @access private + * @param string the table name + * @return string + */ + function _escape_table($table) + { + return $table; + } + + /** * Escape the SQL Identifiers * @@ -463,33 +452,7 @@ class CI_DB_sqlsrv_driver extends CI_DB { */ function _escape_identifiers($item) { - if ($this->_escape_char == '') - { - return $item; - } - - foreach ($this->_reserved_identifiers as $id) - { - if (strpos($item, '.'.$id) !== FALSE) - { - $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; - } - 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); + return $item; } // -------------------------------------------------------------------- @@ -528,8 +491,8 @@ class CI_DB_sqlsrv_driver extends CI_DB { * @return string */ function _insert($table, $keys, $values) - { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + { + return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -547,27 +510,16 @@ class CI_DB_sqlsrv_driver extends CI_DB { * @param array the limit clause * @return string */ - function _update($table, $values, $where, $orderby = array(), $limit = FALSE) + function _update($table, $values, $where) { - foreach ($values as $key => $val) + foreach($values as $key => $val) { $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; + + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); } - - + // -------------------------------------------------------------------- /** @@ -599,25 +551,9 @@ class CI_DB_sqlsrv_driver extends CI_DB { * @param string the limit clause * @return string */ - function _delete($table, $where = array(), $like = array(), $limit = FALSE) + function _delete($table, $where) { - $conditions = ''; - - if (count($where) > 0 OR count($like) > 0) - { - $conditions = "\nWHERE "; - $conditions .= implode("\n", $this->ar_where); - - if (count($where) > 0 && count($like) > 0) - { - $conditions .= " AND "; - } - $conditions .= implode("\n", $like); - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - return "DELETE FROM ".$table.$conditions.$limit; + return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); } // -------------------------------------------------------------------- @@ -636,8 +572,8 @@ class CI_DB_sqlsrv_driver extends CI_DB { function _limit($sql, $limit, $offset) { $i = $limit + $offset; - - return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql); + + return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlsrv/sqlsrv_result.php b/system/database/drivers/sqlsrv/sqlsrv_result.php index 458200383..bf0abd1c6 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_result.php +++ b/system/database/drivers/sqlsrv/sqlsrv_result.php @@ -63,11 +63,11 @@ class CI_DB_sqlsrv_result extends CI_DB_result { function list_fields() { $field_names = array(); - while ($field = sqlsrv_get_field($this->result_id)) + foreach(sqlsrv_field_metadata($this->result_id) as $offset => $field) { - $field_names[] = $field->name; + $field_names[] = $field['Name']; } - + return $field_names; } @@ -84,18 +84,18 @@ class CI_DB_sqlsrv_result extends CI_DB_result { function field_data() { $retval = array(); - while ($field = sqlsrv_get_field($this->result_id)) + foreach(sqlsrv_field_metadata($this->result_id) as $offset => $field) { - $F = new stdClass(); - $F->name = $field->name; - $F->type = $field->type; - $F->max_length = $field->max_length; + $F = new stdClass(); + $F->name = $field['Name']; + $F->type = $field['Type']; + $F->max_length = $field['Size']; $F->primary_key = 0; $F->default = ''; - + $retval[] = $F; } - + return $retval; } -- cgit v1.2.3-24-g4f1b From af6f34489a9dc6b22cc9fe02eb53e13014ced38f Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Tue, 22 Mar 2011 19:12:23 +0000 Subject: ->db->count_all_results() will now return an integer instead of a string. --- system/database/DB_active_rec.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index ee72dbbf4..db8471364 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1020,11 +1020,11 @@ class CI_DB_active_record extends CI_DB_driver { if ($query->num_rows() == 0) { - return '0'; + return 0; } $row = $query->row(); - return $row->numrows; + return (int) $row->numrows; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 36b0c949fdb16163e4b57b1db0cbc777941eff6f Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Sat, 2 Apr 2011 12:16:41 +0100 Subject: Fixed issue #153 Escape Str Bug in MSSQL driver --- system/database/drivers/mssql/mssql_driver.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index b581a478c..65397ed8f 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -267,9 +267,11 @@ class CI_DB_mssql_driver extends CI_DB { // escape LIKE condition wildcards if ($like === TRUE) { - $str = str_replace( array('%', $this->_like_escape_chr, '_'), - array($this->_like_escape_chr.'%', $this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'_'), - $str); + $str = str_replace( + array($this->_like_escape_chr, '%', '_'), + array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'), + $str + ); } return $str; -- cgit v1.2.3-24-g4f1b From 05fa61144667c85b0463f7e8baa6af00aa195dc6 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Wed, 6 Apr 2011 22:57:43 +0100 Subject: Made Environment Support optional. Comment out or delete the constant to stop environment checks. --- system/database/DB.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index 93ee3922a..8bf1ba8ba 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -27,17 +27,12 @@ function &DB($params = '', $active_record_override = NULL) // Load the DB config file if a DSN string wasn't passed if (is_string($params) AND strpos($params, '://') === FALSE) { - - $file_path = APPPATH.'config/'.ENVIRONMENT.'/database'.EXT; - - if ( ! file_exists($file_path)) + // Is the config file in the environment folder? + if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/database'.EXT)) { - log_message('debug', 'Database config for '.ENVIRONMENT.' environment is not found. Trying global config.'); - $file_path = APPPATH.'config/database'.EXT; - - if ( ! file_exists($file_path)) + if ( ! file_exists($file_path = APPPATH.'config/database'.EXT)) { - continue; + show_error('The configuration file database'.EXT.' does not exist.'); } } -- cgit v1.2.3-24-g4f1b From e70e92bab1de57a0749a31f2889b55cafb46d58e Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Mon, 25 Apr 2011 10:50:53 -0500 Subject: Fixing up a tabs vs spaces inconsistency in DB_Result --- system/database/DB_result.php | 83 +++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 39 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 06eec5124..e83228386 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -32,7 +32,7 @@ class CI_DB_result { var $result_id = NULL; var $result_array = array(); var $result_object = array(); - var $custom_result_object = array(); + var $custom_result_object = array(); var $current_row = 0; var $num_rows = 0; var $row_data = NULL; @@ -47,47 +47,52 @@ class CI_DB_result { */ function result($type = 'object') { - if ($type == 'array') return $this->result_array(); - else if ($type == 'object') return $this->result_object(); - else return $this->custom_result_object($type); + if ($type == 'array') return $this->result_array(); + else if ($type == 'object') return $this->result_object(); + else return $this->custom_result_object($type); } // -------------------------------------------------------------------- - /** - * Custom query result. - * - * @param class_name A string that represents the type of object you want back - * @return array of objects - */ - function custom_result_object($class_name) - { - if (array_key_exists($class_name, $this->custom_result_object)) - { - return $this->custom_result_object[$class_name]; - } - - if ($this->result_id === FALSE OR $this->num_rows() == 0) - { - return array(); - } - - // add the data to the object - $this->_data_seek(0); - $result_object = array(); + /** + * Custom query result. + * + * @param class_name A string that represents the type of object you want back + * @return array of objects + */ + function custom_result_object($class_name) + { + if (array_key_exists($class_name, $this->custom_result_object)) + { + return $this->custom_result_object[$class_name]; + } + + if ($this->result_id === FALSE OR $this->num_rows() == 0) + { + return array(); + } + + // add the data to the object + $this->_data_seek(0); + $result_object = array(); + while ($row = $this->_fetch_object()) - { - $object = new $class_name(); - foreach ($row as $key => $value) - { - $object->$key = $value; - } + { + $object = new $class_name(); + + foreach ($row as $key => $value) + { + $object->$key = $value; + } + $result_object[] = $object; } - // return the array - return $this->custom_result_object[$class_name] = $result_object; - } + // return the array + return $this->custom_result_object[$class_name] = $result_object; + } + + // -------------------------------------------------------------------- /** * Query result. "object" version. @@ -180,9 +185,9 @@ class CI_DB_result { $n = 0; } - if ($type == 'object') return $this->row_object($n); - else if ($type == 'array') return $this->row_array($n); - else return $this->custom_row_object($n, $type); + if ($type == 'object') return $this->row_object($n); + else if ($type == 'array') return $this->row_array($n); + else return $this->custom_row_object($n, $type); } // -------------------------------------------------------------------- @@ -219,7 +224,7 @@ class CI_DB_result { // -------------------------------------------------------------------- - /** + /** * Returns a single result row - custom object version * * @access public @@ -242,7 +247,7 @@ class CI_DB_result { return $result[$this->current_row]; } - /** + /** * Returns a single result row - object version * * @access public -- cgit v1.2.3-24-g4f1b From 3a746655e92ec59ee7e731c3535673a9aedc5d3e Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Tue, 19 Apr 2011 10:59:47 -0500 Subject: Removing internal references to the EXT constant. Additionally, marked the constant as deprecated. Use ".php" instead. Also adding upgrade notes from 2.0.2 to 2.0.3. --- system/database/DB.php | 12 ++++++------ system/database/DB_driver.php | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index 8bf1ba8ba..33207d885 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -28,11 +28,11 @@ function &DB($params = '', $active_record_override = NULL) if (is_string($params) AND strpos($params, '://') === FALSE) { // Is the config file in the environment folder? - if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/database'.EXT)) + if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/database.php')) { - if ( ! file_exists($file_path = APPPATH.'config/database'.EXT)) + if ( ! file_exists($file_path = APPPATH.'config/database.php')) { - show_error('The configuration file database'.EXT.' does not exist.'); + show_error('The configuration file database.php does not exist.'); } } @@ -116,11 +116,11 @@ function &DB($params = '', $active_record_override = NULL) $active_record = $active_record_override; } - require_once(BASEPATH.'database/DB_driver'.EXT); + require_once(BASEPATH.'database/DB_driver.php'); if ( ! isset($active_record) OR $active_record == TRUE) { - require_once(BASEPATH.'database/DB_active_rec'.EXT); + require_once(BASEPATH.'database/DB_active_rec.php'); if ( ! class_exists('CI_DB')) { @@ -135,7 +135,7 @@ function &DB($params = '', $active_record_override = NULL) } } - require_once(BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver'.EXT); + require_once(BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver.php'); // Instantiate the DB adapter $driver = 'CI_DB_'.$params['dbdriver'].'_driver'; diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index e7a9de475..10e8ed0c0 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -424,8 +424,8 @@ class CI_DB_driver { if ( ! class_exists($driver)) { - include_once(BASEPATH.'database/DB_result'.EXT); - include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result'.EXT); + include_once(BASEPATH.'database/DB_result.php'); + include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result.php'); } return $driver; @@ -1115,7 +1115,7 @@ class CI_DB_driver { if ( ! class_exists('CI_DB_Cache')) { - if ( ! @include(BASEPATH.'database/DB_cache'.EXT)) + if ( ! @include(BASEPATH.'database/DB_cache.php')) { return $this->cache_off(); } -- cgit v1.2.3-24-g4f1b From 6ae70cc8499499b5d77d77ec8974f95873edb861 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 19 Apr 2011 16:13:48 -0500 Subject: modified MySQL and MySQLi drivers to address a potential SQL injection attack vector when multi-byte character set connections are employed. (Does not impact Latin-1, UTF-8, etc. encodings) --- system/database/drivers/mysql/mysql_driver.php | 17 ++++++++++++++++- system/database/drivers/mysqli/mysqli_driver.php | 17 ++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 4ff9b0a11..b7d547cc0 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -132,7 +132,22 @@ class CI_DB_mysql_driver extends CI_DB { */ function db_set_charset($charset, $collation) { - return @mysql_query("SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'", $this->conn_id); + static $use_set_names; + + if ( ! isset($use_set_names)) + { + // mysql_set_charset() requires PHP >= 5.2.3 and MySQL >= 5.0.7, use SET NAMES as fallback + $use_set_names = (version_compare(PHP_VERSION, '5.2.3', '>=') && version_compare(mysql_get_server_info(), '5.0.7', '>=')) ? FALSE : TRUE; + } + + if ($use_set_names) + { + return @mysql_query("SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'", $this->conn_id); + } + else + { + return @mysql_set_charset($charset, $this->conn_id); + } } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index ccdabce1a..1949acb6e 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -132,7 +132,22 @@ class CI_DB_mysqli_driver extends CI_DB { */ function _db_set_charset($charset, $collation) { - return @mysqli_query($this->conn_id, "SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'"); + static $use_set_names; + + if ( ! isset($use_set_names)) + { + // mysqli_set_charset() requires MySQL >= 5.0.7, use SET NAMES as fallback + $use_set_names = (version_compare(mysql_get_server_info(), '5.0.7', '>=')) ? FALSE : TRUE; + } + + if ($use_set_names) + { + return @mysqli_query($this->conn_id, "SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'"); + } + else + { + return @mysqli_set_charset($this->conn_id, $charset); + } } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From e156c6eb4a018a91d3cfcaa2d1fd3b3e67dc2808 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Wed, 20 Apr 2011 16:03:04 -0500 Subject: Fixed a bug (Core #340) where when passing in the second parameter to $this->db->select(), column names in subsequent queries would not be properly escaped. --- system/database/DB_active_rec.php | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index db8471364..9ceac0b76 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -58,6 +58,8 @@ class CI_DB_active_record extends CI_DB_driver { var $ar_cache_having = array(); var $ar_cache_orderby = array(); var $ar_cache_set = array(); + + var $ar_no_escape = array(); // -------------------------------------------------------------------- @@ -73,12 +75,6 @@ class CI_DB_active_record extends CI_DB_driver { */ function select($select = '*', $escape = NULL) { - // Set the global value if this was sepecified - if (is_bool($escape)) - { - $this->_protect_identifiers = $escape; - } - if (is_string($select)) { $select = explode(',', $select); @@ -91,6 +87,7 @@ class CI_DB_active_record extends CI_DB_driver { if ($val != '') { $this->ar_select[] = $val; + $this->ar_no_escape[] = $escape; if ($this->ar_caching === TRUE) { @@ -441,10 +438,10 @@ class CI_DB_active_record extends CI_DB_driver { $v = ' '.$this->escape($v); } - + if ( ! $this->_has_operator($k)) { - $k .= ' ='; + $k .= ' = '; } } else @@ -1718,7 +1715,7 @@ class CI_DB_active_record extends CI_DB_driver { // is because until the user calls the from() function we don't know if there are aliases foreach ($this->ar_select as $key => $val) { - $this->ar_select[$key] = $this->_protect_identifiers($val); + $this->ar_select[$key] = $this->_protect_identifiers($val, FALSE, $this->ar_no_escape[$key]); } $sql .= implode(', ', $this->ar_select); @@ -1753,9 +1750,7 @@ class CI_DB_active_record extends CI_DB_driver { if (count($this->ar_where) > 0 OR count($this->ar_like) > 0) { - $sql .= "\n"; - - $sql .= "WHERE "; + $sql .= "\nWHERE "; } $sql .= implode("\n", $this->ar_where); @@ -2032,6 +2027,7 @@ class CI_DB_active_record extends CI_DB_driver { 'ar_orderby' => array(), 'ar_wherein' => array(), 'ar_aliased_tables' => array(), + 'ar_no_escape' => array(), 'ar_distinct' => FALSE, 'ar_limit' => FALSE, 'ar_offset' => FALSE, -- cgit v1.2.3-24-g4f1b From ee21a0eebfac7f3de810d9f8c4f8271944b336bf Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 22 Apr 2011 17:37:19 -0500 Subject: typo in modification to MySQLi driver. Fixes #236 --- system/database/drivers/mysqli/mysqli_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 1949acb6e..b8586c21d 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -137,7 +137,7 @@ class CI_DB_mysqli_driver extends CI_DB { if ( ! isset($use_set_names)) { // mysqli_set_charset() requires MySQL >= 5.0.7, use SET NAMES as fallback - $use_set_names = (version_compare(mysql_get_server_info(), '5.0.7', '>=')) ? FALSE : TRUE; + $use_set_names = (version_compare(mysqli_get_server_info($this->conn_id), '5.0.7', '>=')) ? FALSE : TRUE; } if ($use_set_names) -- cgit v1.2.3-24-g4f1b From 114ab0988e20ac6be39ad363ff897a1a3b85e565 Mon Sep 17 00:00:00 2001 From: Razican Date: Mon, 25 Apr 2011 17:26:45 +0200 Subject: Fixed double-space typo. --- system/database/DB.php | 16 +-- system/database/DB_active_rec.php | 32 ++--- system/database/DB_cache.php | 6 +- system/database/DB_driver.php | 34 ++--- system/database/DB_forge.php | 2 +- system/database/DB_result.php | 106 ++++++++-------- system/database/DB_utility.php | 6 +- system/database/drivers/mssql/mssql_driver.php | 2 +- system/database/drivers/mssql/mssql_forge.php | 4 +- system/database/drivers/mssql/mssql_result.php | 4 +- system/database/drivers/mssql/mssql_utility.php | 2 +- system/database/drivers/mysql/mysql_driver.php | 14 +-- system/database/drivers/mysql/mysql_forge.php | 4 +- system/database/drivers/mysql/mysql_result.php | 4 +- system/database/drivers/mysql/mysql_utility.php | 4 +- system/database/drivers/mysqli/mysqli_driver.php | 8 +- system/database/drivers/mysqli/mysqli_forge.php | 4 +- system/database/drivers/mysqli/mysqli_result.php | 4 +- system/database/drivers/mysqli/mysqli_utility.php | 2 +- system/database/drivers/oci8/oci8_driver.php | 138 ++++++++++----------- system/database/drivers/oci8/oci8_forge.php | 4 +- system/database/drivers/oci8/oci8_result.php | 34 ++--- system/database/drivers/oci8/oci8_utility.php | 2 +- system/database/drivers/odbc/odbc_driver.php | 2 +- system/database/drivers/odbc/odbc_forge.php | 4 +- system/database/drivers/odbc/odbc_result.php | 4 +- system/database/drivers/odbc/odbc_utility.php | 2 +- system/database/drivers/postgre/postgre_driver.php | 2 +- system/database/drivers/postgre/postgre_forge.php | 10 +- system/database/drivers/postgre/postgre_result.php | 4 +- .../database/drivers/postgre/postgre_utility.php | 2 +- system/database/drivers/sqlite/sqlite_driver.php | 2 +- system/database/drivers/sqlite/sqlite_forge.php | 6 +- system/database/drivers/sqlite/sqlite_result.php | 4 +- system/database/drivers/sqlite/sqlite_utility.php | 4 +- 35 files changed, 241 insertions(+), 241 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index 33207d885..4481cef63 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -1,4 +1,4 @@ -_track_aliases($val); @@ -332,7 +332,7 @@ class CI_DB_active_record extends CI_DB_driver { } } - // Extract any aliases that might exist. We use this information + // Extract any aliases that might exist. We use this information // in the _protect_identifiers to know whether to add a table prefix $this->_track_aliases($table); @@ -438,7 +438,7 @@ class CI_DB_active_record extends CI_DB_driver { $v = ' '.$this->escape($v); } - + if ( ! $this->_has_operator($k)) { $k .= ' = '; @@ -926,7 +926,7 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- /** - * The "set" function. Allows key/value pairs to be set for inserting or updating + * The "set" function. Allows key/value pairs to be set for inserting or updating * * @access public * @param mixed @@ -1084,7 +1084,7 @@ class CI_DB_active_record extends CI_DB_driver { { if ($this->db_debug) { - //No valid data array. Folds in cases where keys and values did not match up + //No valid data array. Folds in cases where keys and values did not match up return $this->display_error('db_must_use_set'); } return FALSE; @@ -1124,7 +1124,7 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- /** - * The "set_insert_batch" function. Allows key/value pairs to be set for batch inserts + * The "set_insert_batch" function. Allows key/value pairs to be set for batch inserts * * @access public * @param mixed @@ -1158,7 +1158,7 @@ class CI_DB_active_record extends CI_DB_driver { if ($escape === FALSE) { - $this->ar_set[] = '('.implode(',', $row).')'; + $this->ar_set[] = '('.implode(',', $row).')'; } else { @@ -1169,7 +1169,7 @@ class CI_DB_active_record extends CI_DB_driver { $clean[] = $this->escape($value); } - $this->ar_set[] = '('.implode(',', $clean).')'; + $this->ar_set[] = '('.implode(',', $clean).')'; } } @@ -1399,7 +1399,7 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- /** - * The "set_update_batch" function. Allows key/value pairs to be set for batch updating + * The "set_update_batch" function. Allows key/value pairs to be set for batch updating * * @access public * @param array @@ -1652,7 +1652,7 @@ class CI_DB_active_record extends CI_DB_driver { return; } - // Does the string contain a comma? If so, we need to separate + // Does the string contain a comma? If so, we need to separate // the string into discreet statements if (strpos($table, ',') !== FALSE) { @@ -1682,7 +1682,7 @@ class CI_DB_active_record extends CI_DB_driver { * Compile the SELECT statement * * Generates a query string based on which functions were used. - * Should not be called directly. The get() function calls it. + * Should not be called directly. The get() function calls it. * * @access private * @return string @@ -1989,7 +1989,7 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- /** - * Resets the active record values. Called by the get() function + * Resets the active record values. Called by the get() function * * @access private * @param array An array of fields to reset @@ -2009,7 +2009,7 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- /** - * Resets the active record values. Called by the get() function + * Resets the active record values. Called by the get() function * * @access private * @return void diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 3bf065ca5..3249e9d8e 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -1,4 +1,4 @@ -CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); + $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); } if ($segment_two == '') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 10e8ed0c0..40be2f903 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1,4 +1,4 @@ -conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect(); - // No connection resource? Throw an error + // No connection resource? Throw an error if ( ! $this->conn_id) { log_message('error', 'Unable to connect to the database'); @@ -199,7 +199,7 @@ class CI_DB_driver { // -------------------------------------------------------------------- /** - * Database Version Number. Returns a string containing the + * Database Version Number. Returns a string containing the * version of the database being used * * @access public @@ -237,7 +237,7 @@ class CI_DB_driver { * Execute the query * * Accepts an SQL string as input and returns a result object upon - * successful execution of a "read" type query. Returns boolean TRUE + * successful execution of a "read" type query. Returns boolean TRUE * upon successful execution of a "write" type query. Returns boolean * FALSE upon failure, and if the $db_debug variable is set to TRUE * will raise an error. @@ -265,7 +265,7 @@ class CI_DB_driver { $sql = preg_replace("/(\W)".$this->swap_pre."(\S+?)/", "\\1".$this->dbprefix."\\2", $sql); } - // Is query caching enabled? If the query is a "read type" + // Is query caching enabled? If the query is a "read type" // we will load the caching class and return the previously // cached query if it exists if ($this->cache_on == TRUE AND stristr($sql, 'SELECT')) @@ -286,7 +286,7 @@ class CI_DB_driver { $sql = $this->compile_binds($sql, $binds); } - // Save the query for debugging + // Save the query for debugging if ($this->save_queries == TRUE) { $this->queries[] = $sql; @@ -314,7 +314,7 @@ class CI_DB_driver { $error_msg = $this->_error_message(); // We call this function in order to roll-back queries - // if transactions are enabled. If we don't call this here + // if transactions are enabled. If we don't call this here // the error message will trigger an exit, causing the // transactions to remain in limbo. $this->trans_complete(); @@ -385,7 +385,7 @@ class CI_DB_driver { // oci8 vars must be set before calling this $RES->num_rows = $RES->num_rows(); - // Is query caching enabled? If so, we'll serialize the + // Is query caching enabled? If so, we'll serialize the // result object and save it to a cache file. if ($this->cache_on == TRUE AND $this->_cache_init()) { @@ -435,7 +435,7 @@ class CI_DB_driver { /** * Simple Query - * This is a simplified version of the query() function. Internally + * This is a simplified version of the query() function. Internally * we only use it when running transaction commands since they do * not require all the features of the main query() function. * @@ -718,7 +718,7 @@ class CI_DB_driver { /** * Primary * - * Retrieves the primary key. It assumes that the row in the first + * Retrieves the primary key. It assumes that the row in the first * position is the primary key * * @access public @@ -1216,8 +1216,8 @@ class CI_DB_driver { * This function is used extensively by the Active Record class, and by * a couple functions in this class. * It takes a column or table name (optionally with an alias) and inserts - * the table prefix onto it. Some logic is necessary in order to deal with - * column names that include the path. Consider a query like this: + * the table prefix onto it. Some logic is necessary in order to deal with + * column names that include the path. Consider a query like this: * * SELECT * FROM hostname.database.table.column AS c FROM hostname.database.table * @@ -1270,7 +1270,7 @@ class CI_DB_driver { // This is basically a bug fix for queries that use MAX, MIN, etc. // If a parenthesis is found we know that we do not need to - // escape the data or add a prefix. There's probably a more graceful + // escape the data or add a prefix. There's probably a more graceful // way to deal with this, but I'm not thinking of it -- Rick if (strpos($item, '(') !== FALSE) { @@ -1285,7 +1285,7 @@ class CI_DB_driver { $parts = explode('.', $item); // Does the first segment of the exploded item match - // one of the aliases previously identified? If so, + // one of the aliases previously identified? If so, // we have nothing more to do other than escape the item if (in_array($parts[0], $this->ar_aliased_tables)) { @@ -1304,7 +1304,7 @@ class CI_DB_driver { return $item.$alias; } - // Is there a table prefix defined in the config file? If not, no need to do anything + // Is there a table prefix defined in the config file? If not, no need to do anything if ($this->dbprefix != '') { // We now add the table prefix based on some logic. @@ -1358,7 +1358,7 @@ class CI_DB_driver { return $item.$alias; } - // Is there a table prefix? If not, no need to insert it + // Is there a table prefix? If not, no need to insert it if ($this->dbprefix != '') { // Verify table prefix and replace if necessary diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index a71fca78f..9730c7761 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -1,4 +1,4 @@ -result_array(); - else if ($type == 'object') return $this->result_object(); - else return $this->custom_result_object($type); + if ($type == 'array') return $this->result_array(); + else if ($type == 'object') return $this->result_object(); + else return $this->custom_result_object($type); } // -------------------------------------------------------------------- - /** - * Custom query result. - * - * @param class_name A string that represents the type of object you want back - * @return array of objects - */ - function custom_result_object($class_name) - { - if (array_key_exists($class_name, $this->custom_result_object)) - { - return $this->custom_result_object[$class_name]; - } - - if ($this->result_id === FALSE OR $this->num_rows() == 0) - { - return array(); - } - - // add the data to the object - $this->_data_seek(0); - $result_object = array(); + /** + * Custom query result. + * + * @param class_name A string that represents the type of object you want back + * @return array of objects + */ + function custom_result_object($class_name) + { + if (array_key_exists($class_name, $this->custom_result_object)) + { + return $this->custom_result_object[$class_name]; + } + + if ($this->result_id === FALSE OR $this->num_rows() == 0) + { + return array(); + } + + // add the data to the object + $this->_data_seek(0); + $result_object = array(); while ($row = $this->_fetch_object()) - { - $object = new $class_name(); - foreach ($row as $key => $value) - { - $object->$key = $value; - } + { + $object = new $class_name(); + foreach ($row as $key => $value) + { + $object->$key = $value; + } $result_object[] = $object; } - // return the array - return $this->custom_result_object[$class_name] = $result_object; - } + // return the array + return $this->custom_result_object[$class_name] = $result_object; + } /** - * Query result. "object" version. + * Query result. "object" version. * * @access public * @return object @@ -122,7 +122,7 @@ class CI_DB_result { // -------------------------------------------------------------------- /** - * Query result. "array" version. + * Query result. "array" version. * * @access public * @return array @@ -154,7 +154,7 @@ class CI_DB_result { // -------------------------------------------------------------------- /** - * Query result. Acts as a wrapper function for the following functions. + * Query result. Acts as a wrapper function for the following functions. * * @access public * @param string @@ -180,9 +180,9 @@ class CI_DB_result { $n = 0; } - if ($type == 'object') return $this->row_object($n); - else if ($type == 'array') return $this->row_array($n); - else return $this->custom_row_object($n, $type); + if ($type == 'object') return $this->row_object($n); + else if ($type == 'array') return $this->row_array($n); + else return $this->custom_row_object($n, $type); } // -------------------------------------------------------------------- @@ -219,7 +219,7 @@ class CI_DB_result { // -------------------------------------------------------------------- - /** + /** * Returns a single result row - custom object version * * @access public @@ -242,7 +242,7 @@ class CI_DB_result { return $result[$this->current_row]; } - /** + /** * Returns a single result row - object version * * @access public @@ -383,9 +383,9 @@ class CI_DB_result { /** * The following functions are normally overloaded by the identically named * methods in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver. + * is used. When caching is enabled we do not load the other driver. * These functions are primarily here to prevent undefined function errors - * when a cached result object is in use. They are not otherwise fully + * when a cached result object is in use. They are not otherwise fully * operational due to the unavailability of the database resource IDs with * cached results. */ diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index a5f174f0a..a3c00a5a6 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -1,4 +1,4 @@ -db->db_debug) { diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 65397ed8f..56ecf32d1 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -1,4 +1,4 @@ -db->_protect_identifiers($field); - $sql .= ' '.$attributes['TYPE']; + $sql .= ' '.$attributes['TYPE']; if (array_key_exists('CONSTRAINT', $attributes)) { diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index 2897ca5a5..f1f6dbb84 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -1,4 +1,4 @@ -= 5.2.3 and MySQL >= 5.0.7, use SET NAMES as fallback @@ -302,12 +302,12 @@ class CI_DB_mysql_driver extends CI_DB { 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)) { @@ -650,7 +650,7 @@ class CI_DB_mysql_driver extends CI_DB { { if ($field != $index) { - $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field]; + $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field]; } } } diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index 529ec980d..5328a7b4e 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -1,4 +1,4 @@ -= 5.0.7, use SET NAMES as fallback @@ -568,7 +568,7 @@ class CI_DB_mysqli_driver extends CI_DB { { return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values); } - + // -------------------------------------------------------------------- /** @@ -630,7 +630,7 @@ class CI_DB_mysqli_driver extends CI_DB { { if ($field != $index) { - $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field]; + $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field]; } } } diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index d5097335e..6450968dd 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -1,4 +1,4 @@ - format - * value no the value of the parameter. If this is an OUT or IN OUT parameter, + * value no the value of the parameter. If this is an OUT or IN OUT parameter, * this should be a reference to a variable * type yes the type of the parameter * length yes the max size of the parameter @@ -275,8 +275,8 @@ class CI_DB_oci8_driver extends CI_DB { /** * Bind parameters * - * @access private - * @return none + * @access private + * @return none */ function _bind_params($params) { @@ -386,10 +386,10 @@ class CI_DB_oci8_driver extends CI_DB { /** * Escape String * - * @access public - * @param string + * @access public + * @param string * @param bool whether or not the string will be used in a LIKE condition - * @return string + * @return string */ function escape_str($str, $like = FALSE) { @@ -421,8 +421,8 @@ class CI_DB_oci8_driver extends CI_DB { /** * Affected Rows * - * @access public - * @return integer + * @access public + * @return integer */ function affected_rows() { @@ -434,8 +434,8 @@ class CI_DB_oci8_driver extends CI_DB { /** * Insert ID * - * @access public - * @return integer + * @access public + * @return integer */ function insert_id() { @@ -451,9 +451,9 @@ class CI_DB_oci8_driver extends CI_DB { * Generates a platform-specific query string that counts all records in * the specified database * - * @access public - * @param string - * @return string + * @access public + * @param string + * @return string */ function count_all($table = '') { @@ -480,9 +480,9 @@ class CI_DB_oci8_driver extends CI_DB { * * Generates a platform-specific query string so that the table names can be fetched * - * @access private + * @access private * @param boolean - * @return string + * @return string */ function _list_tables($prefix_limit = FALSE) { @@ -503,9 +503,9 @@ class CI_DB_oci8_driver extends CI_DB { * * Generates a platform-specific query string so that the column names can be fetched * - * @access public - * @param string the table name - * @return string + * @access public + * @param string the table name + * @return string */ function _list_columns($table = '') { @@ -519,9 +519,9 @@ class CI_DB_oci8_driver extends CI_DB { * * Generates a platform-specific query so that the column data can be retrieved * - * @access public - * @param string the table name - * @return object + * @access public + * @param string the table name + * @return object */ function _field_data($table) { @@ -533,8 +533,8 @@ class CI_DB_oci8_driver extends CI_DB { /** * The error message string * - * @access private - * @return string + * @access private + * @return string */ function _error_message() { @@ -547,8 +547,8 @@ class CI_DB_oci8_driver extends CI_DB { /** * The error message number * - * @access private - * @return integer + * @access private + * @return integer */ function _error_number() { @@ -627,11 +627,11 @@ class CI_DB_oci8_driver extends CI_DB { * * Generates a platform-specific insert string from the supplied data * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string */ function _insert($table, $keys, $values) { @@ -732,11 +732,11 @@ class CI_DB_oci8_driver extends CI_DB { * * Generates a platform-specific LIMIT clause * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string */ function _limit($sql, $limit, $offset) { @@ -759,9 +759,9 @@ class CI_DB_oci8_driver extends CI_DB { /** * Close DB Connection * - * @access public - * @param resource - * @return void + * @access public + * @param resource + * @return void */ function _close($conn_id) { diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index 3cd17585a..589e3c29d 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -1,4 +1,4 @@ -db->_protect_identifiers($field); - $sql .= ' '.$attributes['TYPE']; + $sql .= ' '.$attributes['TYPE']; if (array_key_exists('CONSTRAINT', $attributes)) { diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 88531b436..60d8396ef 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -1,4 +1,4 @@ -name = ocicolumnname($this->stmt_id, $c); $F->type = ocicolumntype($this->stmt_id, $c); - $F->max_length = ocicolumnsize($this->stmt_id, $c); + $F->max_length = ocicolumnsize($this->stmt_id, $c); $retval[] = $F; } @@ -145,8 +145,8 @@ class CI_DB_oci8_result extends CI_DB_result { * * Returns the result set as an array * - * @access private - * @return array + * @access private + * @return array */ function _fetch_assoc(&$row) { @@ -162,8 +162,8 @@ class CI_DB_oci8_result extends CI_DB_result { * * Returns the result set as an object * - * @access private - * @return object + * @access private + * @return object */ function _fetch_object() { @@ -202,10 +202,10 @@ class CI_DB_oci8_result extends CI_DB_result { // -------------------------------------------------------------------- /** - * Query result. "array" version. + * Query result. "array" version. * - * @access public - * @return array + * @access public + * @return array */ function result_array() { @@ -230,7 +230,7 @@ class CI_DB_oci8_result extends CI_DB_result { /** * Data Seek * - * Moves the internal pointer to the desired offset. We call + * Moves the internal pointer to the desired offset. We call * this internally before fetching results to make sure the * result set starts at zero * diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index 854b467e1..f1fe5dc00 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -1,4 +1,4 @@ -db->_protect_identifiers($field); - $sql .= ' '.$attributes['TYPE']; + $sql .= ' '.$attributes['TYPE']; if (array_key_exists('CONSTRAINT', $attributes)) { diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index 5d64a464f..d83b2e5f0 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -1,4 +1,4 @@ -db->_protect_identifiers($field); - $sql .= ' '.$attributes['TYPE']; + $sql .= ' '.$attributes['TYPE']; if (array_key_exists('CONSTRAINT', $attributes)) { @@ -172,7 +172,7 @@ class CI_DB_sqlite_forge extends CI_DB_forge { /** * Drop Table * - * Unsupported feature in SQLite + * Unsupported feature in SQLite * * @access private * @return bool diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index 7bd30db7c..62204946c 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -1,4 +1,4 @@ - Date: Wed, 27 Apr 2011 01:45:38 -0500 Subject: Added insert_batch() function to the PostgreSQL database driver. Thanks to epallerols for the patch. --- system/database/drivers/postgre/postgre_driver.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'system/database') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 47ff36246..140396885 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -553,6 +553,24 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Insert_batch statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert_batch($table, $keys, $values) + { + return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values); + } + + // -------------------------------------------------------------------- + /** * Update statement * -- cgit v1.2.3-24-g4f1b From 2e1837a3afabe7e6c71fc88d7a4f5e430fa96744 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Fri, 6 May 2011 12:17:04 -0500 Subject: Fix #275 -- regression in db::_compile_select(). Thanks @patwork for the patch --- system/database/DB_active_rec.php | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 508f6bedf..d94d4a13c 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -60,7 +60,7 @@ class CI_DB_active_record extends CI_DB_driver { var $ar_cache_set = array(); var $ar_no_escape = array(); - + var $ar_cache_no_escape = array(); // -------------------------------------------------------------------- @@ -93,6 +93,7 @@ class CI_DB_active_record extends CI_DB_driver { { $this->ar_cache_select[] = $val; $this->ar_cache_exists[] = 'select'; + $this->ar_cache_no_escape[] = $escape; } } } @@ -1933,16 +1934,17 @@ class CI_DB_active_record extends CI_DB_driver { { $this->_reset_run( array( - 'ar_cache_select' => array(), - 'ar_cache_from' => array(), - 'ar_cache_join' => array(), - 'ar_cache_where' => array(), - 'ar_cache_like' => array(), - 'ar_cache_groupby' => array(), - 'ar_cache_having' => array(), - 'ar_cache_orderby' => array(), - 'ar_cache_set' => array(), - 'ar_cache_exists' => array() + 'ar_cache_select' => array(), + 'ar_cache_from' => array(), + 'ar_cache_join' => array(), + 'ar_cache_where' => array(), + 'ar_cache_like' => array(), + 'ar_cache_groupby' => array(), + 'ar_cache_having' => array(), + 'ar_cache_orderby' => array(), + 'ar_cache_set' => array(), + 'ar_cache_exists' => array(), + 'ar_cache_no_escape' => array() ) ); } @@ -1984,6 +1986,8 @@ class CI_DB_active_record extends CI_DB_driver { { $this->_track_aliases($this->ar_from); } + + $this->ar_no_escape = $this->ar_cache_no_escape; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 4b9c62980599228f070b401c7673dce8085b0c61 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 1 Jul 2011 17:40:48 -0500 Subject: backed out 648b42a75739, which was a NON-trivial whitespace commit. It broke the Typography class's string replacements, for instance --- system/database/DB.php | 16 +-- system/database/DB_active_rec.php | 32 ++--- system/database/DB_cache.php | 6 +- system/database/DB_driver.php | 34 ++--- system/database/DB_forge.php | 2 +- system/database/DB_result.php | 106 ++++++++-------- system/database/DB_utility.php | 6 +- system/database/drivers/mssql/mssql_driver.php | 2 +- system/database/drivers/mssql/mssql_forge.php | 4 +- system/database/drivers/mssql/mssql_result.php | 4 +- system/database/drivers/mssql/mssql_utility.php | 2 +- system/database/drivers/mysql/mysql_driver.php | 14 +-- system/database/drivers/mysql/mysql_forge.php | 4 +- system/database/drivers/mysql/mysql_result.php | 4 +- system/database/drivers/mysql/mysql_utility.php | 4 +- system/database/drivers/mysqli/mysqli_driver.php | 8 +- system/database/drivers/mysqli/mysqli_forge.php | 4 +- system/database/drivers/mysqli/mysqli_result.php | 4 +- system/database/drivers/mysqli/mysqli_utility.php | 2 +- system/database/drivers/oci8/oci8_driver.php | 138 ++++++++++----------- system/database/drivers/oci8/oci8_forge.php | 4 +- system/database/drivers/oci8/oci8_result.php | 34 ++--- system/database/drivers/oci8/oci8_utility.php | 2 +- system/database/drivers/odbc/odbc_driver.php | 2 +- system/database/drivers/odbc/odbc_forge.php | 4 +- system/database/drivers/odbc/odbc_result.php | 4 +- system/database/drivers/odbc/odbc_utility.php | 2 +- system/database/drivers/postgre/postgre_driver.php | 2 +- system/database/drivers/postgre/postgre_forge.php | 10 +- system/database/drivers/postgre/postgre_result.php | 4 +- .../database/drivers/postgre/postgre_utility.php | 2 +- system/database/drivers/sqlite/sqlite_driver.php | 2 +- system/database/drivers/sqlite/sqlite_forge.php | 6 +- system/database/drivers/sqlite/sqlite_result.php | 4 +- system/database/drivers/sqlite/sqlite_utility.php | 4 +- 35 files changed, 241 insertions(+), 241 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index 4481cef63..33207d885 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -1,4 +1,4 @@ -_track_aliases($val); @@ -332,7 +332,7 @@ class CI_DB_active_record extends CI_DB_driver { } } - // Extract any aliases that might exist. We use this information + // Extract any aliases that might exist. We use this information // in the _protect_identifiers to know whether to add a table prefix $this->_track_aliases($table); @@ -438,7 +438,7 @@ class CI_DB_active_record extends CI_DB_driver { $v = ' '.$this->escape($v); } - + if ( ! $this->_has_operator($k)) { $k .= ' = '; @@ -926,7 +926,7 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- /** - * The "set" function. Allows key/value pairs to be set for inserting or updating + * The "set" function. Allows key/value pairs to be set for inserting or updating * * @access public * @param mixed @@ -1084,7 +1084,7 @@ class CI_DB_active_record extends CI_DB_driver { { if ($this->db_debug) { - //No valid data array. Folds in cases where keys and values did not match up + //No valid data array. Folds in cases where keys and values did not match up return $this->display_error('db_must_use_set'); } return FALSE; @@ -1124,7 +1124,7 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- /** - * The "set_insert_batch" function. Allows key/value pairs to be set for batch inserts + * The "set_insert_batch" function. Allows key/value pairs to be set for batch inserts * * @access public * @param mixed @@ -1158,7 +1158,7 @@ class CI_DB_active_record extends CI_DB_driver { if ($escape === FALSE) { - $this->ar_set[] = '('.implode(',', $row).')'; + $this->ar_set[] = '('.implode(',', $row).')'; } else { @@ -1169,7 +1169,7 @@ class CI_DB_active_record extends CI_DB_driver { $clean[] = $this->escape($value); } - $this->ar_set[] = '('.implode(',', $clean).')'; + $this->ar_set[] = '('.implode(',', $clean).')'; } } @@ -1399,7 +1399,7 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- /** - * The "set_update_batch" function. Allows key/value pairs to be set for batch updating + * The "set_update_batch" function. Allows key/value pairs to be set for batch updating * * @access public * @param array @@ -1652,7 +1652,7 @@ class CI_DB_active_record extends CI_DB_driver { return; } - // Does the string contain a comma? If so, we need to separate + // Does the string contain a comma? If so, we need to separate // the string into discreet statements if (strpos($table, ',') !== FALSE) { @@ -1682,7 +1682,7 @@ class CI_DB_active_record extends CI_DB_driver { * Compile the SELECT statement * * Generates a query string based on which functions were used. - * Should not be called directly. The get() function calls it. + * Should not be called directly. The get() function calls it. * * @access private * @return string @@ -1989,7 +1989,7 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- /** - * Resets the active record values. Called by the get() function + * Resets the active record values. Called by the get() function * * @access private * @param array An array of fields to reset @@ -2009,7 +2009,7 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- /** - * Resets the active record values. Called by the get() function + * Resets the active record values. Called by the get() function * * @access private * @return void diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 3249e9d8e..3bf065ca5 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -1,4 +1,4 @@ -CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); + $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); } if ($segment_two == '') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 40be2f903..10e8ed0c0 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1,4 +1,4 @@ -conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect(); - // No connection resource? Throw an error + // No connection resource? Throw an error if ( ! $this->conn_id) { log_message('error', 'Unable to connect to the database'); @@ -199,7 +199,7 @@ class CI_DB_driver { // -------------------------------------------------------------------- /** - * Database Version Number. Returns a string containing the + * Database Version Number. Returns a string containing the * version of the database being used * * @access public @@ -237,7 +237,7 @@ class CI_DB_driver { * Execute the query * * Accepts an SQL string as input and returns a result object upon - * successful execution of a "read" type query. Returns boolean TRUE + * successful execution of a "read" type query. Returns boolean TRUE * upon successful execution of a "write" type query. Returns boolean * FALSE upon failure, and if the $db_debug variable is set to TRUE * will raise an error. @@ -265,7 +265,7 @@ class CI_DB_driver { $sql = preg_replace("/(\W)".$this->swap_pre."(\S+?)/", "\\1".$this->dbprefix."\\2", $sql); } - // Is query caching enabled? If the query is a "read type" + // Is query caching enabled? If the query is a "read type" // we will load the caching class and return the previously // cached query if it exists if ($this->cache_on == TRUE AND stristr($sql, 'SELECT')) @@ -286,7 +286,7 @@ class CI_DB_driver { $sql = $this->compile_binds($sql, $binds); } - // Save the query for debugging + // Save the query for debugging if ($this->save_queries == TRUE) { $this->queries[] = $sql; @@ -314,7 +314,7 @@ class CI_DB_driver { $error_msg = $this->_error_message(); // We call this function in order to roll-back queries - // if transactions are enabled. If we don't call this here + // if transactions are enabled. If we don't call this here // the error message will trigger an exit, causing the // transactions to remain in limbo. $this->trans_complete(); @@ -385,7 +385,7 @@ class CI_DB_driver { // oci8 vars must be set before calling this $RES->num_rows = $RES->num_rows(); - // Is query caching enabled? If so, we'll serialize the + // Is query caching enabled? If so, we'll serialize the // result object and save it to a cache file. if ($this->cache_on == TRUE AND $this->_cache_init()) { @@ -435,7 +435,7 @@ class CI_DB_driver { /** * Simple Query - * This is a simplified version of the query() function. Internally + * This is a simplified version of the query() function. Internally * we only use it when running transaction commands since they do * not require all the features of the main query() function. * @@ -718,7 +718,7 @@ class CI_DB_driver { /** * Primary * - * Retrieves the primary key. It assumes that the row in the first + * Retrieves the primary key. It assumes that the row in the first * position is the primary key * * @access public @@ -1216,8 +1216,8 @@ class CI_DB_driver { * This function is used extensively by the Active Record class, and by * a couple functions in this class. * It takes a column or table name (optionally with an alias) and inserts - * the table prefix onto it. Some logic is necessary in order to deal with - * column names that include the path. Consider a query like this: + * the table prefix onto it. Some logic is necessary in order to deal with + * column names that include the path. Consider a query like this: * * SELECT * FROM hostname.database.table.column AS c FROM hostname.database.table * @@ -1270,7 +1270,7 @@ class CI_DB_driver { // This is basically a bug fix for queries that use MAX, MIN, etc. // If a parenthesis is found we know that we do not need to - // escape the data or add a prefix. There's probably a more graceful + // escape the data or add a prefix. There's probably a more graceful // way to deal with this, but I'm not thinking of it -- Rick if (strpos($item, '(') !== FALSE) { @@ -1285,7 +1285,7 @@ class CI_DB_driver { $parts = explode('.', $item); // Does the first segment of the exploded item match - // one of the aliases previously identified? If so, + // one of the aliases previously identified? If so, // we have nothing more to do other than escape the item if (in_array($parts[0], $this->ar_aliased_tables)) { @@ -1304,7 +1304,7 @@ class CI_DB_driver { return $item.$alias; } - // Is there a table prefix defined in the config file? If not, no need to do anything + // Is there a table prefix defined in the config file? If not, no need to do anything if ($this->dbprefix != '') { // We now add the table prefix based on some logic. @@ -1358,7 +1358,7 @@ class CI_DB_driver { return $item.$alias; } - // Is there a table prefix? If not, no need to insert it + // Is there a table prefix? If not, no need to insert it if ($this->dbprefix != '') { // Verify table prefix and replace if necessary diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index 9730c7761..a71fca78f 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -1,4 +1,4 @@ -result_array(); - else if ($type == 'object') return $this->result_object(); - else return $this->custom_result_object($type); + if ($type == 'array') return $this->result_array(); + else if ($type == 'object') return $this->result_object(); + else return $this->custom_result_object($type); } // -------------------------------------------------------------------- - /** - * Custom query result. - * - * @param class_name A string that represents the type of object you want back - * @return array of objects - */ - function custom_result_object($class_name) - { - if (array_key_exists($class_name, $this->custom_result_object)) - { - return $this->custom_result_object[$class_name]; - } - - if ($this->result_id === FALSE OR $this->num_rows() == 0) - { - return array(); - } - - // add the data to the object - $this->_data_seek(0); - $result_object = array(); + /** + * Custom query result. + * + * @param class_name A string that represents the type of object you want back + * @return array of objects + */ + function custom_result_object($class_name) + { + if (array_key_exists($class_name, $this->custom_result_object)) + { + return $this->custom_result_object[$class_name]; + } + + if ($this->result_id === FALSE OR $this->num_rows() == 0) + { + return array(); + } + + // add the data to the object + $this->_data_seek(0); + $result_object = array(); while ($row = $this->_fetch_object()) - { - $object = new $class_name(); - foreach ($row as $key => $value) - { - $object->$key = $value; - } + { + $object = new $class_name(); + foreach ($row as $key => $value) + { + $object->$key = $value; + } $result_object[] = $object; } - // return the array - return $this->custom_result_object[$class_name] = $result_object; - } + // return the array + return $this->custom_result_object[$class_name] = $result_object; + } /** - * Query result. "object" version. + * Query result. "object" version. * * @access public * @return object @@ -122,7 +122,7 @@ class CI_DB_result { // -------------------------------------------------------------------- /** - * Query result. "array" version. + * Query result. "array" version. * * @access public * @return array @@ -154,7 +154,7 @@ class CI_DB_result { // -------------------------------------------------------------------- /** - * Query result. Acts as a wrapper function for the following functions. + * Query result. Acts as a wrapper function for the following functions. * * @access public * @param string @@ -180,9 +180,9 @@ class CI_DB_result { $n = 0; } - if ($type == 'object') return $this->row_object($n); - else if ($type == 'array') return $this->row_array($n); - else return $this->custom_row_object($n, $type); + if ($type == 'object') return $this->row_object($n); + else if ($type == 'array') return $this->row_array($n); + else return $this->custom_row_object($n, $type); } // -------------------------------------------------------------------- @@ -219,7 +219,7 @@ class CI_DB_result { // -------------------------------------------------------------------- - /** + /** * Returns a single result row - custom object version * * @access public @@ -242,7 +242,7 @@ class CI_DB_result { return $result[$this->current_row]; } - /** + /** * Returns a single result row - object version * * @access public @@ -383,9 +383,9 @@ class CI_DB_result { /** * The following functions are normally overloaded by the identically named * methods in the platform-specific driver -- except when query caching - * is used. When caching is enabled we do not load the other driver. + * is used. When caching is enabled we do not load the other driver. * These functions are primarily here to prevent undefined function errors - * when a cached result object is in use. They are not otherwise fully + * when a cached result object is in use. They are not otherwise fully * operational due to the unavailability of the database resource IDs with * cached results. */ diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index a3c00a5a6..a5f174f0a 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -1,4 +1,4 @@ -db->db_debug) { diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 56ecf32d1..65397ed8f 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -1,4 +1,4 @@ -db->_protect_identifiers($field); - $sql .= ' '.$attributes['TYPE']; + $sql .= ' '.$attributes['TYPE']; if (array_key_exists('CONSTRAINT', $attributes)) { diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index f1f6dbb84..2897ca5a5 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -1,4 +1,4 @@ -= 5.2.3 and MySQL >= 5.0.7, use SET NAMES as fallback @@ -302,12 +302,12 @@ class CI_DB_mysql_driver extends CI_DB { 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)) { @@ -650,7 +650,7 @@ class CI_DB_mysql_driver extends CI_DB { { if ($field != $index) { - $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field]; + $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field]; } } } diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index 5328a7b4e..529ec980d 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -1,4 +1,4 @@ -= 5.0.7, use SET NAMES as fallback @@ -568,7 +568,7 @@ class CI_DB_mysqli_driver extends CI_DB { { return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values); } - + // -------------------------------------------------------------------- /** @@ -630,7 +630,7 @@ class CI_DB_mysqli_driver extends CI_DB { { if ($field != $index) { - $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field]; + $final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field]; } } } diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index 6450968dd..d5097335e 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -1,4 +1,4 @@ - format - * value no the value of the parameter. If this is an OUT or IN OUT parameter, + * value no the value of the parameter. If this is an OUT or IN OUT parameter, * this should be a reference to a variable * type yes the type of the parameter * length yes the max size of the parameter @@ -275,8 +275,8 @@ class CI_DB_oci8_driver extends CI_DB { /** * Bind parameters * - * @access private - * @return none + * @access private + * @return none */ function _bind_params($params) { @@ -386,10 +386,10 @@ class CI_DB_oci8_driver extends CI_DB { /** * Escape String * - * @access public - * @param string + * @access public + * @param string * @param bool whether or not the string will be used in a LIKE condition - * @return string + * @return string */ function escape_str($str, $like = FALSE) { @@ -421,8 +421,8 @@ class CI_DB_oci8_driver extends CI_DB { /** * Affected Rows * - * @access public - * @return integer + * @access public + * @return integer */ function affected_rows() { @@ -434,8 +434,8 @@ class CI_DB_oci8_driver extends CI_DB { /** * Insert ID * - * @access public - * @return integer + * @access public + * @return integer */ function insert_id() { @@ -451,9 +451,9 @@ class CI_DB_oci8_driver extends CI_DB { * Generates a platform-specific query string that counts all records in * the specified database * - * @access public - * @param string - * @return string + * @access public + * @param string + * @return string */ function count_all($table = '') { @@ -480,9 +480,9 @@ class CI_DB_oci8_driver extends CI_DB { * * Generates a platform-specific query string so that the table names can be fetched * - * @access private + * @access private * @param boolean - * @return string + * @return string */ function _list_tables($prefix_limit = FALSE) { @@ -503,9 +503,9 @@ class CI_DB_oci8_driver extends CI_DB { * * Generates a platform-specific query string so that the column names can be fetched * - * @access public - * @param string the table name - * @return string + * @access public + * @param string the table name + * @return string */ function _list_columns($table = '') { @@ -519,9 +519,9 @@ class CI_DB_oci8_driver extends CI_DB { * * Generates a platform-specific query so that the column data can be retrieved * - * @access public - * @param string the table name - * @return object + * @access public + * @param string the table name + * @return object */ function _field_data($table) { @@ -533,8 +533,8 @@ class CI_DB_oci8_driver extends CI_DB { /** * The error message string * - * @access private - * @return string + * @access private + * @return string */ function _error_message() { @@ -547,8 +547,8 @@ class CI_DB_oci8_driver extends CI_DB { /** * The error message number * - * @access private - * @return integer + * @access private + * @return integer */ function _error_number() { @@ -627,11 +627,11 @@ class CI_DB_oci8_driver extends CI_DB { * * Generates a platform-specific insert string from the supplied data * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string */ function _insert($table, $keys, $values) { @@ -732,11 +732,11 @@ class CI_DB_oci8_driver extends CI_DB { * * Generates a platform-specific LIMIT clause * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string */ function _limit($sql, $limit, $offset) { @@ -759,9 +759,9 @@ class CI_DB_oci8_driver extends CI_DB { /** * Close DB Connection * - * @access public - * @param resource - * @return void + * @access public + * @param resource + * @return void */ function _close($conn_id) { diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index 589e3c29d..3cd17585a 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -1,4 +1,4 @@ -db->_protect_identifiers($field); - $sql .= ' '.$attributes['TYPE']; + $sql .= ' '.$attributes['TYPE']; if (array_key_exists('CONSTRAINT', $attributes)) { diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 60d8396ef..88531b436 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -1,4 +1,4 @@ -name = ocicolumnname($this->stmt_id, $c); $F->type = ocicolumntype($this->stmt_id, $c); - $F->max_length = ocicolumnsize($this->stmt_id, $c); + $F->max_length = ocicolumnsize($this->stmt_id, $c); $retval[] = $F; } @@ -145,8 +145,8 @@ class CI_DB_oci8_result extends CI_DB_result { * * Returns the result set as an array * - * @access private - * @return array + * @access private + * @return array */ function _fetch_assoc(&$row) { @@ -162,8 +162,8 @@ class CI_DB_oci8_result extends CI_DB_result { * * Returns the result set as an object * - * @access private - * @return object + * @access private + * @return object */ function _fetch_object() { @@ -202,10 +202,10 @@ class CI_DB_oci8_result extends CI_DB_result { // -------------------------------------------------------------------- /** - * Query result. "array" version. + * Query result. "array" version. * - * @access public - * @return array + * @access public + * @return array */ function result_array() { @@ -230,7 +230,7 @@ class CI_DB_oci8_result extends CI_DB_result { /** * Data Seek * - * Moves the internal pointer to the desired offset. We call + * Moves the internal pointer to the desired offset. We call * this internally before fetching results to make sure the * result set starts at zero * diff --git a/system/database/drivers/oci8/oci8_utility.php b/system/database/drivers/oci8/oci8_utility.php index f1fe5dc00..854b467e1 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -1,4 +1,4 @@ -db->_protect_identifiers($field); - $sql .= ' '.$attributes['TYPE']; + $sql .= ' '.$attributes['TYPE']; if (array_key_exists('CONSTRAINT', $attributes)) { diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index d83b2e5f0..5d64a464f 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -1,4 +1,4 @@ -db->_protect_identifiers($field); - $sql .= ' '.$attributes['TYPE']; + $sql .= ' '.$attributes['TYPE']; if (array_key_exists('CONSTRAINT', $attributes)) { @@ -172,7 +172,7 @@ class CI_DB_sqlite_forge extends CI_DB_forge { /** * Drop Table * - * Unsupported feature in SQLite + * Unsupported feature in SQLite * * @access private * @return bool diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index 62204946c..7bd30db7c 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -1,4 +1,4 @@ - Date: Fri, 15 Jul 2011 15:14:05 -0600 Subject: Was working on this file so PHP5ified the method visibility scopes. Pointless, but was adding... --- system/database/DB_active_rec.php | 260 ++++++++++++++++---------------------- 1 file changed, 106 insertions(+), 154 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 52bad260a..7ddf20d07 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -69,11 +69,10 @@ class CI_DB_active_record extends CI_DB_driver { * * Generates the SELECT portion of the query * - * @access public * @param string * @return object */ - function select($select = '*', $escape = NULL) + public function select($select = '*', $escape = NULL) { if (is_string($select)) { @@ -107,12 +106,11 @@ class CI_DB_active_record extends CI_DB_driver { * * Generates a SELECT MAX(field) portion of a query * - * @access public * @param string the field * @param string an alias * @return object */ - function select_max($select = '', $alias = '') + public function select_max($select = '', $alias = '') { return $this->_max_min_avg_sum($select, $alias, 'MAX'); } @@ -124,12 +122,11 @@ class CI_DB_active_record extends CI_DB_driver { * * Generates a SELECT MIN(field) portion of a query * - * @access public * @param string the field * @param string an alias * @return object */ - function select_min($select = '', $alias = '') + public function select_min($select = '', $alias = '') { return $this->_max_min_avg_sum($select, $alias, 'MIN'); } @@ -141,12 +138,11 @@ class CI_DB_active_record extends CI_DB_driver { * * Generates a SELECT AVG(field) portion of a query * - * @access public * @param string the field * @param string an alias * @return object */ - function select_avg($select = '', $alias = '') + public function select_avg($select = '', $alias = '') { return $this->_max_min_avg_sum($select, $alias, 'AVG'); } @@ -158,12 +154,11 @@ class CI_DB_active_record extends CI_DB_driver { * * Generates a SELECT SUM(field) portion of a query * - * @access public * @param string the field * @param string an alias * @return object */ - function select_sum($select = '', $alias = '') + public function select_sum($select = '', $alias = '') { return $this->_max_min_avg_sum($select, $alias, 'SUM'); } @@ -178,12 +173,11 @@ class CI_DB_active_record extends CI_DB_driver { * select_avg() * select_sum() * - * @access public * @param string the field * @param string an alias * @return object */ - function _max_min_avg_sum($select = '', $alias = '', $type = 'MAX') + protected function _max_min_avg_sum($select = '', $alias = '', $type = 'MAX') { if ( ! is_string($select) OR $select == '') { @@ -220,11 +214,10 @@ class CI_DB_active_record extends CI_DB_driver { /** * Determines the alias name based on the table * - * @access private * @param string * @return string */ - function _create_alias_from_table($item) + protected function _create_alias_from_table($item) { if (strpos($item, '.') !== FALSE) { @@ -241,11 +234,10 @@ class CI_DB_active_record extends CI_DB_driver { * * Sets a flag which tells the query string compiler to add DISTINCT * - * @access public * @param bool * @return object */ - function distinct($val = TRUE) + public function distinct($val = TRUE) { $this->ar_distinct = (is_bool($val)) ? $val : TRUE; return $this; @@ -258,11 +250,10 @@ class CI_DB_active_record extends CI_DB_driver { * * Generates the FROM portion of the query * - * @access public * @param mixed can be a string or array * @return object */ - function from($from) + public function from($from) { foreach ((array)$from as $val) { @@ -311,13 +302,12 @@ class CI_DB_active_record extends CI_DB_driver { * * Generates the JOIN portion of the query * - * @access public * @param string * @param string the join condition * @param string the type of join * @return object */ - function join($table, $cond, $type = '') + public function join($table, $cond, $type = '') { if ($type != '') { @@ -367,12 +357,11 @@ class CI_DB_active_record extends CI_DB_driver { * Generates the WHERE portion of the query. Separates * multiple calls with AND * - * @access public * @param mixed * @param mixed * @return object */ - function where($key, $value = NULL, $escape = TRUE) + public function where($key, $value = NULL, $escape = TRUE) { return $this->_where($key, $value, 'AND ', $escape); } @@ -385,12 +374,11 @@ class CI_DB_active_record extends CI_DB_driver { * Generates the WHERE portion of the query. Separates * multiple calls with OR * - * @access public * @param mixed * @param mixed * @return object */ - function or_where($key, $value = NULL, $escape = TRUE) + public function or_where($key, $value = NULL, $escape = TRUE) { return $this->_where($key, $value, 'OR ', $escape); } @@ -400,15 +388,14 @@ class CI_DB_active_record extends CI_DB_driver { /** * Where * - * Called by where() or orwhere() + * Called by where() or or_where() * - * @access private * @param mixed * @param mixed * @param string * @return object */ - function _where($key, $value = NULL, $type = 'AND ', $escape = NULL) + protected function _where($key, $value = NULL, $type = 'AND ', $escape = NULL) { if ( ! is_array($key)) { @@ -471,12 +458,11 @@ class CI_DB_active_record extends CI_DB_driver { * Generates a WHERE field IN ('item', 'item') SQL query joined with * AND if appropriate * - * @access public * @param string The field to search * @param array The values searched on * @return object */ - function where_in($key = NULL, $values = NULL) + public function where_in($key = NULL, $values = NULL) { return $this->_where_in($key, $values); } @@ -489,12 +475,11 @@ class CI_DB_active_record extends CI_DB_driver { * Generates a WHERE field IN ('item', 'item') SQL query joined with * OR if appropriate * - * @access public * @param string The field to search * @param array The values searched on * @return object */ - function or_where_in($key = NULL, $values = NULL) + public function or_where_in($key = NULL, $values = NULL) { return $this->_where_in($key, $values, FALSE, 'OR '); } @@ -507,12 +492,11 @@ class CI_DB_active_record extends CI_DB_driver { * Generates a WHERE field NOT IN ('item', 'item') SQL query joined * with AND if appropriate * - * @access public * @param string The field to search * @param array The values searched on * @return object */ - function where_not_in($key = NULL, $values = NULL) + public function where_not_in($key = NULL, $values = NULL) { return $this->_where_in($key, $values, TRUE); } @@ -525,12 +509,11 @@ class CI_DB_active_record extends CI_DB_driver { * Generates a WHERE field NOT IN ('item', 'item') SQL query joined * with OR if appropriate * - * @access public * @param string The field to search * @param array The values searched on * @return object */ - function or_where_not_in($key = NULL, $values = NULL) + public function or_where_not_in($key = NULL, $values = NULL) { return $this->_where_in($key, $values, TRUE, 'OR '); } @@ -542,14 +525,13 @@ class CI_DB_active_record extends CI_DB_driver { * * Called by where_in, where_in_or, where_not_in, where_not_in_or * - * @access public * @param string The field to search * @param array The values searched on * @param boolean If the statement would be IN or NOT IN * @param string * @return object */ - function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ') + protected function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ') { if ($key === NULL OR $values === NULL) { @@ -592,12 +574,11 @@ class CI_DB_active_record extends CI_DB_driver { * Generates a %LIKE% portion of the query. Separates * multiple calls with AND * - * @access public * @param mixed * @param mixed * @return object */ - function like($field, $match = '', $side = 'both') + public function like($field, $match = '', $side = 'both') { return $this->_like($field, $match, 'AND ', $side); } @@ -610,12 +591,11 @@ class CI_DB_active_record extends CI_DB_driver { * Generates a NOT LIKE portion of the query. Separates * multiple calls with AND * - * @access public * @param mixed * @param mixed * @return object */ - function not_like($field, $match = '', $side = 'both') + public function not_like($field, $match = '', $side = 'both') { return $this->_like($field, $match, 'AND ', $side, 'NOT'); } @@ -628,12 +608,11 @@ class CI_DB_active_record extends CI_DB_driver { * Generates a %LIKE% portion of the query. Separates * multiple calls with OR * - * @access public * @param mixed * @param mixed * @return object */ - function or_like($field, $match = '', $side = 'both') + public function or_like($field, $match = '', $side = 'both') { return $this->_like($field, $match, 'OR ', $side); } @@ -646,12 +625,11 @@ class CI_DB_active_record extends CI_DB_driver { * Generates a NOT LIKE portion of the query. Separates * multiple calls with OR * - * @access public * @param mixed * @param mixed * @return object */ - function or_not_like($field, $match = '', $side = 'both') + public function or_not_like($field, $match = '', $side = 'both') { return $this->_like($field, $match, 'OR ', $side, 'NOT'); } @@ -663,13 +641,12 @@ class CI_DB_active_record extends CI_DB_driver { * * Called by like() or orlike() * - * @access private * @param mixed * @param mixed * @param string * @return object */ - function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '') + protected function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '') { if ( ! is_array($field)) { @@ -719,11 +696,10 @@ class CI_DB_active_record extends CI_DB_driver { /** * GROUP BY * - * @access public * @param string * @return object */ - function group_by($by) + public function group_by($by) { if (is_string($by)) { @@ -755,12 +731,11 @@ class CI_DB_active_record extends CI_DB_driver { * * Separates multiple calls with AND * - * @access public * @param string * @param string * @return object */ - function having($key, $value = '', $escape = TRUE) + public function having($key, $value = '', $escape = TRUE) { return $this->_having($key, $value, 'AND ', $escape); } @@ -772,12 +747,11 @@ class CI_DB_active_record extends CI_DB_driver { * * Separates multiple calls with OR * - * @access public * @param string * @param string * @return object */ - function or_having($key, $value = '', $escape = TRUE) + public function or_having($key, $value = '', $escape = TRUE) { return $this->_having($key, $value, 'OR ', $escape); } @@ -789,12 +763,11 @@ class CI_DB_active_record extends CI_DB_driver { * * Called by having() or or_having() * - * @access private * @param string * @param string * @return object */ - function _having($key, $value = '', $type = 'AND ', $escape = TRUE) + protected function _having($key, $value = '', $type = 'AND ', $escape = TRUE) { if ( ! is_array($key)) { @@ -836,12 +809,11 @@ class CI_DB_active_record extends CI_DB_driver { /** * Sets the ORDER BY value * - * @access public * @param string * @param string direction: asc or desc * @return object */ - function order_by($orderby, $direction = '') + public function order_by($orderby, $direction = '') { if (strtolower($direction) == 'random') { @@ -892,12 +864,11 @@ class CI_DB_active_record extends CI_DB_driver { /** * Sets the LIMIT value * - * @access public * @param integer the limit value * @param integer the offset value * @return object */ - function limit($value, $offset = '') + public function limit($value, $offset = '') { $this->ar_limit = $value; @@ -914,11 +885,10 @@ class CI_DB_active_record extends CI_DB_driver { /** * Sets the OFFSET value * - * @access public * @param integer the offset value * @return object */ - function offset($offset) + public function offset($offset) { $this->ar_offset = $offset; return $this; @@ -929,13 +899,12 @@ class CI_DB_active_record extends CI_DB_driver { /** * The "set" function. Allows key/value pairs to be set for inserting or updating * - * @access public * @param mixed * @param string * @param boolean * @return object */ - function set($key, $value = '', $escape = TRUE) + public function set($key, $value = '', $escape = TRUE) { $key = $this->_object_to_array($key); @@ -967,13 +936,12 @@ class CI_DB_active_record extends CI_DB_driver { * Compiles the select statement based on the other functions called * and runs the query * - * @access public * @param string the table * @param string the limit clause * @param string the offset clause * @return object */ - function get($table = '', $limit = null, $offset = null) + public function get($table = '', $limit = null, $offset = null) { if ($table != '') { @@ -999,11 +967,10 @@ class CI_DB_active_record extends CI_DB_driver { * Generates a platform-specific query string that counts all records * returned by an Active Record query. * - * @access public * @param string * @return string */ - function count_all_results($table = '') + public function count_all_results($table = '') { if ($table != '') { @@ -1032,13 +999,12 @@ class CI_DB_active_record extends CI_DB_driver { * * Allows the where clause, limit and offset to be added directly * - * @access public * @param string the where clause * @param string the limit clause * @param string the offset clause * @return object */ - function get_where($table = '', $where = null, $limit = null, $offset = null) + public function get_where($table = '', $where = null, $limit = null, $offset = null) { if ($table != '') { @@ -1069,12 +1035,11 @@ class CI_DB_active_record extends CI_DB_driver { * * Compiles batch insert strings and runs the queries * - * @access public * @param string the table to retrieve the results from * @param array an associative array of insert values * @return object */ - function insert_batch($table = '', $set = NULL) + public function insert_batch($table = '', $set = NULL) { if ( ! is_null($set)) { @@ -1127,14 +1092,12 @@ class CI_DB_active_record extends CI_DB_driver { /** * The "set_insert_batch" function. Allows key/value pairs to be set for batch inserts * - * @access public * @param mixed * @param string * @param boolean * @return object */ - - function set_insert_batch($key, $value = '', $escape = TRUE) + public function set_insert_batch($key, $value = '', $escape = TRUE) { $key = $this->_object_to_array_batch($key); @@ -1189,8 +1152,7 @@ class CI_DB_active_record extends CI_DB_driver { * * Compiles an insert string and runs the query * - * @access public - * @param string the table to retrieve the results from + * @param string the table to insert data into * @param array an associative array of insert values * @return object */ @@ -1230,7 +1192,18 @@ class CI_DB_active_record extends CI_DB_driver { return $this->query($sql); } - function replace($table = '', $set = NULL) + // -------------------------------------------------------------------- + + /** + * Replace + * + * Compiles an replace into string and runs the query + * + * @param string the table to replace data into + * @param array an associative array of insert values + * @return object + */ + public function replace($table = '', $set = NULL) { if ( ! is_null($set)) { @@ -1273,13 +1246,12 @@ class CI_DB_active_record extends CI_DB_driver { * * Compiles an update string and runs the query * - * @access public * @param string the table to retrieve the results from * @param array an associative array of update values * @param mixed the where clause * @return object */ - function update($table = '', $set = NULL, $where = NULL, $limit = NULL) + public function update($table = '', $set = NULL, $where = NULL, $limit = NULL) { // Combine any cached components with the current statements $this->_merge_cache(); @@ -1336,13 +1308,12 @@ class CI_DB_active_record extends CI_DB_driver { * * Compiles an update string and runs the query * - * @access public * @param string the table to retrieve the results from * @param array an associative array of update values * @param string the where key * @return object */ - function update_batch($table = '', $set = NULL, $index = NULL) + public function update_batch($table = '', $set = NULL, $index = NULL) { // Combine any cached components with the current statements $this->_merge_cache(); @@ -1402,14 +1373,12 @@ class CI_DB_active_record extends CI_DB_driver { /** * The "set_update_batch" function. Allows key/value pairs to be set for batch updating * - * @access public * @param array * @param string * @param boolean * @return object */ - - function set_update_batch($key, $index = '', $escape = TRUE) + public function set_update_batch($key, $index = '', $escape = TRUE) { $key = $this->_object_to_array_batch($key); @@ -1462,11 +1431,10 @@ class CI_DB_active_record extends CI_DB_driver { * * Compiles a delete string and runs "DELETE FROM table" * - * @access public * @param string the table to empty * @return object */ - function empty_table($table = '') + public function empty_table($table = '') { if ($table == '') { @@ -1502,11 +1470,10 @@ class CI_DB_active_record extends CI_DB_driver { * If the database does not support the truncate() command * This function maps to "DELETE FROM table" * - * @access public * @param string the table to truncate * @return object */ - function truncate($table = '') + public function truncate($table = '') { if ($table == '') { @@ -1540,14 +1507,13 @@ class CI_DB_active_record extends CI_DB_driver { * * Compiles a delete string and runs the query * - * @access public * @param mixed the table(s) to delete from. String or array * @param mixed the where clause * @param mixed the limit clause * @param boolean * @return object */ - function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE) + public function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE) { // Combine any cached components with the current statements $this->_merge_cache(); @@ -1617,11 +1583,10 @@ class CI_DB_active_record extends CI_DB_driver { * * Prepends a database prefix if one exists in configuration * - * @access public * @param string the table * @return string */ - function dbprefix($table = '') + public function dbprefix($table = '') { if ($table == '') { @@ -1638,11 +1603,10 @@ class CI_DB_active_record extends CI_DB_driver { * * Used to track SQL statements written with aliased tables. * - * @access private * @param string The table to inspect * @return string */ - function _track_aliases($table) + protected function _track_aliases($table) { if (is_array($table)) { @@ -1685,10 +1649,9 @@ class CI_DB_active_record extends CI_DB_driver { * Generates a query string based on which functions were used. * Should not be called directly. The get() function calls it. * - * @access private * @return string */ - function _compile_select($select_override = FALSE) + protected function _compile_select($select_override = FALSE) { // Combine any cached components with the current statements $this->_merge_cache(); @@ -1826,11 +1789,10 @@ class CI_DB_active_record extends CI_DB_driver { * * Takes an object as input and converts the class variables to array key/vals * - * @access public * @param object * @return array */ - function _object_to_array($object) + public function _object_to_array($object) { if ( ! is_object($object)) { @@ -1857,11 +1819,10 @@ class CI_DB_active_record extends CI_DB_driver { * * Takes an object as input and converts the class variables to array key/vals * - * @access public * @param object * @return array */ - function _object_to_array_batch($object) + public function _object_to_array_batch($object) { if ( ! is_object($object)) { @@ -1897,10 +1858,9 @@ class CI_DB_active_record extends CI_DB_driver { * * Starts AR caching * - * @access public * @return void */ - function start_cache() + public function start_cache() { $this->ar_caching = TRUE; } @@ -1912,10 +1872,9 @@ class CI_DB_active_record extends CI_DB_driver { * * Stops AR caching * - * @access public * @return void */ - function stop_cache() + public function stop_cache() { $this->ar_caching = FALSE; } @@ -1930,23 +1889,21 @@ class CI_DB_active_record extends CI_DB_driver { * @access public * @return void */ - function flush_cache() + public function flush_cache() { - $this->_reset_run( - array( - 'ar_cache_select' => array(), - 'ar_cache_from' => array(), - 'ar_cache_join' => array(), - 'ar_cache_where' => array(), - 'ar_cache_like' => array(), - 'ar_cache_groupby' => array(), - 'ar_cache_having' => array(), - 'ar_cache_orderby' => array(), - 'ar_cache_set' => array(), - 'ar_cache_exists' => array(), - 'ar_cache_no_escape' => array() - ) - ); + $this->_reset_run(array( + 'ar_cache_select' => array(), + 'ar_cache_from' => array(), + 'ar_cache_join' => array(), + 'ar_cache_where' => array(), + 'ar_cache_like' => array(), + 'ar_cache_groupby' => array(), + 'ar_cache_having' => array(), + 'ar_cache_orderby' => array(), + 'ar_cache_set' => array(), + 'ar_cache_exists' => array(), + 'ar_cache_no_escape' => array() + )); } // -------------------------------------------------------------------- @@ -1957,10 +1914,9 @@ class CI_DB_active_record extends CI_DB_driver { * When called, this function merges any cached AR arrays with * locally called ones. * - * @access private * @return void */ - function _merge_cache() + protected function _merge_cache() { if (count($this->ar_cache_exists) == 0) { @@ -1995,11 +1951,10 @@ class CI_DB_active_record extends CI_DB_driver { /** * Resets the active record values. Called by the get() function * - * @access private * @param array An array of fields to reset * @return void */ - function _reset_run($ar_reset_items) + protected function _reset_run($ar_reset_items) { foreach ($ar_reset_items as $item => $default_value) { @@ -2015,28 +1970,27 @@ class CI_DB_active_record extends CI_DB_driver { /** * Resets the active record values. Called by the get() function * - * @access private * @return void */ - function _reset_select() + protected function _reset_select() { $ar_reset_items = array( - 'ar_select' => array(), - 'ar_from' => array(), - 'ar_join' => array(), - 'ar_where' => array(), - 'ar_like' => array(), - 'ar_groupby' => array(), - 'ar_having' => array(), - 'ar_orderby' => array(), - 'ar_wherein' => array(), - 'ar_aliased_tables' => array(), - 'ar_no_escape' => array(), - 'ar_distinct' => FALSE, - 'ar_limit' => FALSE, - 'ar_offset' => FALSE, - 'ar_order' => FALSE, - ); + 'ar_select' => array(), + 'ar_from' => array(), + 'ar_join' => array(), + 'ar_where' => array(), + 'ar_like' => array(), + 'ar_groupby' => array(), + 'ar_having' => array(), + 'ar_orderby' => array(), + 'ar_wherein' => array(), + 'ar_aliased_tables' => array(), + 'ar_no_escape' => array(), + 'ar_distinct' => FALSE, + 'ar_limit' => FALSE, + 'ar_offset' => FALSE, + 'ar_order' => FALSE, + ); $this->_reset_run($ar_reset_items); } @@ -2048,25 +2002,23 @@ class CI_DB_active_record extends CI_DB_driver { * * Called by the insert() update() insert_batch() update_batch() and delete() functions * - * @access private * @return void */ - function _reset_write() + protected function _reset_write() { $ar_reset_items = array( - 'ar_set' => array(), - 'ar_from' => array(), - 'ar_where' => array(), - 'ar_like' => array(), - 'ar_orderby' => array(), - 'ar_keys' => array(), - 'ar_limit' => FALSE, - 'ar_order' => FALSE - ); + 'ar_set' => array(), + 'ar_from' => array(), + 'ar_where' => array(), + 'ar_like' => array(), + 'ar_orderby' => array(), + 'ar_keys' => array(), + 'ar_limit' => FALSE, + 'ar_order' => FALSE + ); $this->_reset_run($ar_reset_items); } - } /* End of file DB_active_rec.php */ -- cgit v1.2.3-24-g4f1b From 5025929d76172efd6dd3a7b0f4da7611a3df9391 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Fri, 15 Jul 2011 15:25:15 -0600 Subject: Fixed conflicted changelog. --- system/database/DB_active_rec.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 7ddf20d07..bc11ff436 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1598,6 +1598,21 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- + /** + * Set DB Prefix + * + * Set's the DB Prefix to something new without needing to reconnect + * + * @param string the prefix + * @return string + */ + public function set_dbprefix($prefix = '') + { + return $this->dbprefix = $prefix; + } + + // -------------------------------------------------------------------- + /** * Track Aliases * -- cgit v1.2.3-24-g4f1b From 40b28e9139f3486971fe6f13594d3f615a37862c Mon Sep 17 00:00:00 2001 From: Adam Jackett Date: Sat, 23 Jul 2011 11:45:05 -0400 Subject: Fixed having method to insert quotes. --- system/database/DB_active_rec.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index bc11ff436..0a25b3cb5 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -790,7 +790,7 @@ class CI_DB_active_record extends CI_DB_driver { if ($v != '') { - $v = ' '.$this->escape_str($v); + $v = ' '.$this->escape($v); } $this->ar_having[] = $prefix.$k.$v; -- cgit v1.2.3-24-g4f1b From c5961e7d778d5a9361df4cfbc7da5fc4370d883f Mon Sep 17 00:00:00 2001 From: Adam Jackett Date: Sat, 23 Jul 2011 09:50:34 -0400 Subject: Fixed mysql and mysqli drivers to set NOT NULL as default for creating fields. All other drivers were correct. --- system/database/drivers/mysql/mysql_forge.php | 8 ++++++-- system/database/drivers/mysqli/mysqli_forge.php | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index 529ec980d..c1cae136c 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -119,9 +119,13 @@ class CI_DB_mysql_forge extends CI_DB_forge { $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; } - if (array_key_exists('NULL', $attributes)) + if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) { - $sql .= ($attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL'; + $sql .= ' NULL'; + } + else + { + $sql .= ' NOT NULL'; } if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index d5097335e..260549457 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -104,9 +104,13 @@ class CI_DB_mysqli_forge extends CI_DB_forge { $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; } - if (array_key_exists('NULL', $attributes)) + if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) { - $sql .= ($attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL'; + $sql .= ' NULL'; + } + else + { + $sql .= ' NOT NULL'; } if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) -- cgit v1.2.3-24-g4f1b From 76e621786007907192c3e84cbde3e1a12dbf83fb Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Tue, 9 Aug 2011 16:03:49 -0600 Subject: Fixed conflict in changelog. --- system/database/DB_active_rec.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 0a25b3cb5..2af3553ed 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1694,7 +1694,8 @@ class CI_DB_active_record extends CI_DB_driver { // is because until the user calls the from() function we don't know if there are aliases foreach ($this->ar_select as $key => $val) { - $this->ar_select[$key] = $this->_protect_identifiers($val, FALSE, $this->ar_no_escape[$key]); + $no_escape = isset($this->ar_no_escape[$key]) ? $this->ar_no_escape[$key] : NULL; + $this->ar_select[$key] = $this->_protect_identifiers($val, FALSE, $no_escape); } $sql .= implode(', ', $this->ar_select); -- cgit v1.2.3-24-g4f1b