From 511f225d855919b78df42ff802a513d84afa0693 Mon Sep 17 00:00:00 2001 From: Túbal Martín Date: Thu, 24 Nov 2011 14:43:45 +0100 Subject: Added dummy _reset_select() method to CI_DB_Driver class to allow Active Record class to be disabled. Otherwise a fatal error is triggered. --- system/database/DB_driver.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 3680b85c2..8f530b482 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1381,7 +1381,21 @@ class CI_DB_driver { return $item.$alias; } + + // -------------------------------------------------------------------- + /** + * Dummy method that allows Active Record class to be disabled + * + * This function is used extensively by every db driver. + * + * @access private + * @return void + */ + protected function _reset_select() + { + + } } -- cgit v1.2.3-24-g4f1b From d92bd57f007e9561a37be8a8ccaf93a4f8948343 Mon Sep 17 00:00:00 2001 From: Repox Date: Thu, 1 Dec 2011 10:08:52 +0100 Subject: This fixes issue #725 --- system/database/DB_driver.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 3680b85c2..3952d7276 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1015,8 +1015,14 @@ class CI_DB_driver { else { $args = (func_num_args() > 1) ? array_splice(func_get_args(), 1) : null; - - return call_user_func_array($function, $args); + if (is_null($args)) + { + return call_user_func($function); + } + else + { + return call_user_func_array($function, $args); + } } } -- cgit v1.2.3-24-g4f1b From 92f019cd6ba0c11ab2d9fee4c1909be99068e74e Mon Sep 17 00:00:00 2001 From: GDmac Date: Mon, 26 Dec 2011 14:55:41 +0100 Subject: No need for eval to extend a class --- system/database/DB.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index 5c90f44f3..27142c877 100755 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -138,14 +138,14 @@ function &DB($params = '', $active_record_override = NULL) if ( ! class_exists('CI_DB')) { - eval('class CI_DB extends CI_DB_active_record { }'); + class CI_DB extends CI_DB_active_record { } } } else { if ( ! class_exists('CI_DB')) { - eval('class CI_DB extends CI_DB_driver { }'); + class CI_DB extends CI_DB_driver { } } } -- cgit v1.2.3-24-g4f1b From 0cbcc1aecab7aaea719eafc58e68e0a81987ceeb Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Tue, 27 Dec 2011 17:11:38 -0600 Subject: Fix #808 Postgresql DBForge Driver errors. - _process_fields() was missing and add_column(), drop_column() was producing malformed queries. --- system/database/drivers/postgre/postgre_forge.php | 106 +++++++++++----------- 1 file changed, 51 insertions(+), 55 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index f86ba2dda..7368b9447 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -63,32 +63,13 @@ class CI_DB_postgre_forge extends CI_DB_forge { } // -------------------------------------------------------------------- - + /** - * 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 + * Process Fields */ - function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) + function _process_fields($fields, $primary_keys=array()) { - $sql = 'CREATE TABLE '; - - if ($if_not_exists === TRUE) - { - // PostgreSQL doesn't support IF NOT EXISTS syntax so we check if table exists manually - if ($this->db->table_exists($table)) - { - return TRUE; - } - } - - $sql .= $this->db->_escape_identifiers($table)." ("; + $sql = ''; $current_field_count = 0; foreach ($fields as $field=>$attributes) @@ -184,6 +165,38 @@ class CI_DB_postgre_forge extends CI_DB_forge { $sql .= ','; } } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * 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) + { + // PostgreSQL doesn't support IF NOT EXISTS syntax so we check if table exists manually + if ($this->db->table_exists($table)) + { + return TRUE; + } + } + + $sql .= $this->db->_escape_identifiers($table)." ("; + $sql .= $this->_process_fields($fields, $primary_keys); if (count($primary_keys) > 0) { @@ -249,40 +262,25 @@ class CI_DB_postgre_forge extends CI_DB_forge { * @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); + 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; - } + // DROP has everything it needs now. + if ($alter_type == 'DROP') + { + return $sql.$this->db->_protect_identifiers($fields); + } - $sql .= " $column_definition"; + $sql .= $this->_process_fields($fields); - if ($default_value != '') - { - $sql .= " DEFAULT \"$default_value\""; - } + if ($after_field != '') + { + $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); + } - if ($null === NULL) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } - - if ($after_field != '') - { - $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); - } - - return $sql; - - } + return $sql; + } // -------------------------------------------------------------------- @@ -301,8 +299,6 @@ class CI_DB_postgre_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; } - - } /* End of file postgre_forge.php */ -- cgit v1.2.3-24-g4f1b From 6924e40a4841eeb87d4c38294cfbe452bb6368cb Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Tue, 27 Dec 2011 17:19:50 -0600 Subject: Adding docblock to _process_fields() in the postgres dbforge file. --- system/database/drivers/postgre/postgre_forge.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'system/database') diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index 7368b9447..d54b99b23 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -66,6 +66,9 @@ class CI_DB_postgre_forge extends CI_DB_forge { /** * Process Fields + * + * @param mixed the fields + * @return string */ function _process_fields($fields, $primary_keys=array()) { -- cgit v1.2.3-24-g4f1b From 7219c07e9e6be839cbf9931a17d587ef4b2895b1 Mon Sep 17 00:00:00 2001 From: WanWizard Date: Wed, 28 Dec 2011 14:09:05 +0100 Subject: added query grouping to Active Record this is a feature that has been lacking for a very long time. lots of people complained about it over the years, but it never got added so you'd have to resort to handcrafted queries when you needed this feature. This is a port of code from DataMapper, in use since CI 1.6. --- system/database/DB_active_rec.php | 258 +++++++++++++++++++++++++++----------- 1 file changed, 186 insertions(+), 72 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 530b44e09..b7f43945c 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -5,9 +5,9 @@ * An open source application development framework for PHP 5.1.6 or newer * * NOTICE OF LICENSE - * + * * Licensed under the Open Software License version 3.0 - * + * * This source file is subject to the Open Software License (OSL 3.0) that is * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: @@ -40,42 +40,44 @@ */ class CI_DB_active_record extends CI_DB_driver { - protected $return_delete_sql = FALSE; - protected $reset_delete_data = FALSE; - - protected $ar_select = array(); - protected $ar_distinct = FALSE; - protected $ar_from = array(); - protected $ar_join = array(); - protected $ar_where = array(); - protected $ar_like = array(); - protected $ar_groupby = array(); - protected $ar_having = array(); - protected $ar_keys = array(); - protected $ar_limit = FALSE; - protected $ar_offset = FALSE; - protected $ar_order = FALSE; - protected $ar_orderby = array(); - protected $ar_set = array(); - protected $ar_wherein = array(); - protected $ar_aliased_tables = array(); - protected $ar_store_array = array(); + protected $return_delete_sql = FALSE; + protected $reset_delete_data = FALSE; + + protected $ar_select = array(); + protected $ar_distinct = FALSE; + protected $ar_from = array(); + protected $ar_join = array(); + protected $ar_where = array(); + protected $ar_like = array(); + protected $ar_groupby = array(); + protected $ar_having = array(); + protected $ar_keys = array(); + protected $ar_limit = FALSE; + protected $ar_offset = FALSE; + protected $ar_order = FALSE; + protected $ar_orderby = array(); + protected $ar_set = array(); + protected $ar_wherein = array(); + protected $ar_aliased_tables = array(); + protected $ar_store_array = array(); + protected $ar_where_group_started = FALSE; + protected $ar_where_group_count = 0; // Active Record Caching variables - protected $ar_caching = FALSE; - protected $ar_cache_exists = array(); - protected $ar_cache_select = array(); - protected $ar_cache_from = array(); - protected $ar_cache_join = array(); - protected $ar_cache_where = array(); - protected $ar_cache_like = array(); - protected $ar_cache_groupby = array(); - protected $ar_cache_having = array(); - protected $ar_cache_orderby = array(); - protected $ar_cache_set = array(); - - protected $ar_no_escape = array(); - protected $ar_cache_no_escape = array(); + protected $ar_caching = FALSE; + protected $ar_cache_exists = array(); + protected $ar_cache_select = array(); + protected $ar_cache_from = array(); + protected $ar_cache_join = array(); + protected $ar_cache_where = array(); + protected $ar_cache_like = array(); + protected $ar_cache_groupby = array(); + protected $ar_cache_having = array(); + protected $ar_cache_orderby = array(); + protected $ar_cache_set = array(); + + protected $ar_no_escape = array(); + protected $ar_cache_no_escape = array(); // -------------------------------------------------------------------- @@ -412,6 +414,8 @@ class CI_DB_active_record extends CI_DB_driver { */ protected function _where($key, $value = NULL, $type = 'AND ', $escape = NULL) { + $type = $this->_group_get_type($type); + if ( ! is_array($key)) { $key = array($key => $value); @@ -441,7 +445,7 @@ class CI_DB_active_record extends CI_DB_driver { $v = ' '.$this->escape($v); } - + if ( ! $this->_has_operator($k)) { $k .= ' = '; @@ -553,6 +557,8 @@ class CI_DB_active_record extends CI_DB_driver { return; } + $type = $this->_group_get_type($type); + if ( ! is_array($values)) { $values = array($values); @@ -663,6 +669,8 @@ class CI_DB_active_record extends CI_DB_driver { */ protected function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '') { + $type = $this->_group_get_type($type); + if ( ! is_array($field)) { $field = array($field => $match); @@ -712,6 +720,112 @@ class CI_DB_active_record extends CI_DB_driver { // -------------------------------------------------------------------- + /** + * Starts a query group. + * + * @param string (Internal use only) + * @param string (Internal use only) + * @return object + */ + public function group_start($not = '', $type = 'AND ') + { + $type = $this->_group_get_type($type); + + $this->ar_where_group_started = TRUE; + + $prefix = (count($this->ar_where) == 0 AND count($this->ar_cache_where) == 0) ? '' : $type; + $value = $prefix . $not . str_repeat(' ', ++$this->ar_where_group_count) . ' ('; + + $this->ar_where[] = $value; + if ($this->ar_caching) + { + $this->ar_cache_where[] = $value; + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Starts a query group, but ORs the group + * + * @return object + */ + public function or_group_start() + { + return $this->group_start('', 'OR '); + } + + // -------------------------------------------------------------------- + + /** + * Starts a query group, but NOTs the group + * + * @return object + */ + public function not_group_start() + { + return $this->group_start('NOT ', 'AND '); + } + + // -------------------------------------------------------------------- + + /** + * Starts a query group, but OR NOTs the group + * + * @return object + */ + public function or_not_group_start() + { + return $this->group_start('NOT ', 'OR '); + } + + // -------------------------------------------------------------------- + + /** + * Ends a query group + * + * @return object + */ + public function group_end() + { + $value = str_repeat(' ', $this->ar_where_group_count--) . ')'; + + $this->ar_where[] = $value; + if ($this->ar_caching) + { + $this->ar_cache_where[] = $value; + } + + $this->ar_where_group_started = FALSE; + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Group_get_type + * + * Called by group_start(), _like(), _where() and _where_in() + * + * @param string + * @return string + */ + protected function _group_get_type($type) + { + if ($this->ar_where_group_started) + { + $type = ''; + $this->ar_where_group_started = FALSE; + } + + return $type; + } + + // -------------------------------------------------------------------- + /** * GROUP BY * @@ -950,7 +1064,7 @@ class CI_DB_active_record extends CI_DB_driver { return $this; } - + // -------------------------------------------------------------------- /** @@ -963,24 +1077,24 @@ class CI_DB_active_record extends CI_DB_driver { * @param boolean TRUE: resets AR values; FALSE: leave AR vaules alone * @return string */ - public function get_compiled_select($table = '', $reset = TRUE) + public function get_compiled_select($table = '', $reset = TRUE) { if ($table != '') { $this->_track_aliases($table); $this->from($table); } - + $select = $this->_compile_select(); - + if ($reset === TRUE) { $this->_reset_select(); } - + return $select; } - + // -------------------------------------------------------------------- /** @@ -1197,7 +1311,7 @@ class CI_DB_active_record extends CI_DB_driver { return $this; } - + // -------------------------------------------------------------------- /** @@ -1211,25 +1325,25 @@ class CI_DB_active_record extends CI_DB_driver { * @return string */ public function get_compiled_insert($table = '', $reset = TRUE) - { + { if ($this->_validate_insert($table) === FALSE) { return FALSE; } - + $sql = $this->_insert( $this->_protect_identifiers( $this->ar_from[0], TRUE, NULL, FALSE ), - array_keys($this->ar_set), + array_keys($this->ar_set), array_values($this->ar_set) ); - + if ($reset === TRUE) { $this->_reset_write(); } - + return $sql; } @@ -1251,24 +1365,24 @@ class CI_DB_active_record extends CI_DB_driver { { $this->set($set); } - + if ($this->_validate_insert($table) === FALSE) { return FALSE; } - + $sql = $this->_insert( $this->_protect_identifiers( $this->ar_from[0], TRUE, NULL, FALSE - ), - array_keys($this->ar_set), + ), + array_keys($this->ar_set), array_values($this->ar_set) ); $this->_reset_write(); return $this->query($sql); } - + // -------------------------------------------------------------------- /** @@ -1282,7 +1396,7 @@ class CI_DB_active_record extends CI_DB_driver { * @param string the table to insert data into * @return string */ - protected function _validate_insert($table = '') + protected function _validate_insert($table = '') { if (count($this->ar_set) == 0) { @@ -1308,7 +1422,7 @@ class CI_DB_active_record extends CI_DB_driver { { $this->ar_from[0] = $table; } - + return TRUE; } @@ -1358,7 +1472,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->_reset_write(); return $this->query($sql); } - + // -------------------------------------------------------------------- /** @@ -1375,22 +1489,22 @@ class CI_DB_active_record extends CI_DB_driver { { // Combine any cached components with the current statements $this->_merge_cache(); - + if ($this->_validate_update($table) === FALSE) { return FALSE; } - + $sql = $this->_update($this->_protect_identifiers($this->ar_from[0], TRUE, NULL, FALSE), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit); - + if ($reset === TRUE) { $this->_reset_write(); } - + return $sql; } - + // -------------------------------------------------------------------- /** @@ -1433,7 +1547,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->_reset_write(); return $this->query($sql); } - + // -------------------------------------------------------------------- /** @@ -1474,7 +1588,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->ar_from[0] = $table; } } - + // -------------------------------------------------------------------- /** @@ -1673,7 +1787,7 @@ class CI_DB_active_record extends CI_DB_driver { return $this->query($sql); } - + // -------------------------------------------------------------------- /** @@ -1693,7 +1807,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->return_delete_sql = FALSE; return $sql; } - + // -------------------------------------------------------------------- /** @@ -1766,7 +1880,7 @@ class CI_DB_active_record extends CI_DB_driver { { $this->_reset_write(); } - + if ($this->return_delete_sql === true) { return $sql; @@ -1774,7 +1888,7 @@ class CI_DB_active_record extends CI_DB_driver { return $this->query($sql); } - + // -------------------------------------------------------------------- /** @@ -1854,7 +1968,7 @@ class CI_DB_active_record extends CI_DB_driver { } } } - + // -------------------------------------------------------------------- /** @@ -2160,12 +2274,12 @@ class CI_DB_active_record extends CI_DB_driver { $this->ar_no_escape = $this->ar_cache_no_escape; } - + // -------------------------------------------------------------------- /** * Reset Active Record values. - * + * * Publicly-visible method to reset the AR values. * * @access public @@ -2253,4 +2367,4 @@ class CI_DB_active_record extends CI_DB_driver { } /* End of file DB_active_rec.php */ -/* Location: ./system/database/DB_active_rec.php */ \ No newline at end of file +/* Location: ./system/database/DB_active_rec.php */ -- cgit v1.2.3-24-g4f1b From a7de97e74cbfe21cd2606c2253134a3bc8dda1f7 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Sat, 31 Dec 2011 18:41:08 +0000 Subject: Added method chaining to DBForge. --- system/database/DB_forge.php | 49 +++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 28 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index 78bf77a9f..c74fa4068 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -102,12 +102,11 @@ class CI_DB_forge { /** * Add Key * - * @access public * @param string key * @param string type - * @return void + * @return object */ - function add_key($key = '', $primary = FALSE) + public function add_key($key = '', $primary = FALSE) { if (is_array($key)) { @@ -132,6 +131,8 @@ class CI_DB_forge { { $this->keys[] = $key; } + + return $this; } // -------------------------------------------------------------------- @@ -139,11 +140,10 @@ class CI_DB_forge { /** * Add Field * - * @access public * @param string collation - * @return void + * @return object */ - function add_field($field = '') + public function add_field($field = '') { if ($field == '') { @@ -155,12 +155,12 @@ class CI_DB_forge { if ($field == 'id') { $this->add_field(array( - 'id' => array( - 'type' => 'INT', - 'constraint' => 9, - 'auto_increment' => TRUE - ) - )); + 'id' => array( + 'type' => 'INT', + 'constraint' => 9, + 'auto_increment' => TRUE + ) + )); $this->add_key('id', TRUE); } else @@ -178,7 +178,8 @@ class CI_DB_forge { { $this->fields = array_merge($this->fields, $field); } - + + return $this; } // -------------------------------------------------------------------- @@ -186,11 +187,10 @@ class CI_DB_forge { /** * Create Table * - * @access public * @param string the table name * @return bool */ - function create_table($table = '', $if_not_exists = FALSE) + public function create_table($table = '', $if_not_exists = FALSE) { if ($table == '') { @@ -219,11 +219,10 @@ class CI_DB_forge { /** * Drop Table * - * @access public * @param string the table name * @return bool */ - function drop_table($table_name) + public function drop_table($table_name) { $sql = $this->_drop_table($this->db->dbprefix.$table_name); @@ -240,12 +239,11 @@ 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) + public function rename_table($table_name, $new_table_name) { if ($table_name == '' OR $new_table_name == '') { @@ -261,13 +259,12 @@ class CI_DB_forge { /** * 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 = '') + public function add_column($table = '', $field = array(), $after_field = '') { if ($table == '') { @@ -297,7 +294,6 @@ class CI_DB_forge { } return TRUE; - } // -------------------------------------------------------------------- @@ -305,12 +301,11 @@ class CI_DB_forge { /** * Column Drop * - * @access public * @param string the table name * @param string the column name * @return bool */ - function drop_column($table = '', $column_name = '') + public function drop_column($table = '', $column_name = '') { if ($table == '') @@ -333,13 +328,12 @@ class CI_DB_forge { /** * 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()) + public function modify_column($table = '', $field = array()) { if ($table == '') { @@ -384,10 +378,9 @@ class CI_DB_forge { * * Resets table creation vars * - * @access private * @return void */ - function _reset() + protected function _reset() { $this->fields = array(); $this->keys = array(); -- cgit v1.2.3-24-g4f1b From 0defe5d33ee2633f377a109519ca818becc60f64 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Sun, 1 Jan 2012 18:46:41 -0600 Subject: Updating copyright date to 2012 --- 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/cubrid/cubrid_driver.php | 2 +- system/database/drivers/cubrid/cubrid_forge.php | 2 +- system/database/drivers/cubrid/cubrid_result.php | 2 +- system/database/drivers/cubrid/cubrid_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/pdo/pdo_driver.php | 2 +- system/database/drivers/pdo/pdo_forge.php | 2 +- system/database/drivers/pdo/pdo_result.php | 2 +- system/database/drivers/pdo/pdo_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 +- system/database/drivers/sqlsrv/sqlsrv_driver.php | 2 +- system/database/drivers/sqlsrv/sqlsrv_forge.php | 2 +- system/database/drivers/sqlsrv/sqlsrv_result.php | 2 +- system/database/drivers/sqlsrv/sqlsrv_utility.php | 2 +- 47 files changed, 47 insertions(+), 47 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index 5c90f44f3..1fb666fae 100755 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @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 b7f43945c..486b4d775 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 6c1ffc0f3..1ff046c21 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 9d92f2f87..661b42ced 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index c74fa4068..762d18a46 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 9f0b0187c..c4ed20b76 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 60ecb5269..8db4f3bac 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php index 8181bd605..cde719eae 100644 --- a/system/database/drivers/cubrid/cubrid_driver.php +++ b/system/database/drivers/cubrid/cubrid_driver.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 2.0.2 diff --git a/system/database/drivers/cubrid/cubrid_forge.php b/system/database/drivers/cubrid/cubrid_forge.php index 410d0652c..85e740057 100644 --- a/system/database/drivers/cubrid/cubrid_forge.php +++ b/system/database/drivers/cubrid/cubrid_forge.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/cubrid/cubrid_result.php b/system/database/drivers/cubrid/cubrid_result.php index b2f1bcf71..4c0fede10 100644 --- a/system/database/drivers/cubrid/cubrid_result.php +++ b/system/database/drivers/cubrid/cubrid_result.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 2.0.2 diff --git a/system/database/drivers/cubrid/cubrid_utility.php b/system/database/drivers/cubrid/cubrid_utility.php index 1fa0390a8..750c0d8dd 100644 --- a/system/database/drivers/cubrid/cubrid_utility.php +++ b/system/database/drivers/cubrid/cubrid_utility.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @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 87e7c9d37..2a1098932 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @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 0a893f68f..dd8aa3448 100644 --- a/system/database/drivers/mssql/mssql_forge.php +++ b/system/database/drivers/mssql/mssql_forge.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @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 a8cd7c982..bba2e6243 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @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 576d13f86..be6ed5bb0 100644 --- a/system/database/drivers/mssql/mssql_utility.php +++ b/system/database/drivers/mssql/mssql_utility.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @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 6ded6e531..0f69a0723 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @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 89aaf5de3..a41a7b446 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @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 29297b6a4..dcb99cd60 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @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 9cb6645eb..703524165 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @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 fb5953bd7..aff62a37d 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @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 cdd5399f2..590efa939 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @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 163788b6c..89dd4ded8 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @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 ef7c89fab..76bd49e31 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @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 9c38dcbd6..c6621901b 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @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 bafab3d1b..b4a24cdca 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @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 f32559289..0f69fa9ef 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @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 28c374d99..d60f98bc4 100644 --- a/system/database/drivers/oci8/oci8_utility.php +++ b/system/database/drivers/oci8/oci8_utility.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @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 0e9d46d3f..6ba39f0cd 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @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 e326a2801..e0ec687c8 100644 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @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 b23a821d3..ba660856e 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @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 94666acbf..bae3fe853 100644 --- a/system/database/drivers/odbc/odbc_utility.php +++ b/system/database/drivers/odbc/odbc_utility.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 457cf714a..4f4f44ba7 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 2.1.0 diff --git a/system/database/drivers/pdo/pdo_forge.php b/system/database/drivers/pdo/pdo_forge.php index bf3066529..076415928 100644 --- a/system/database/drivers/pdo/pdo_forge.php +++ b/system/database/drivers/pdo/pdo_forge.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 2.1.0 diff --git a/system/database/drivers/pdo/pdo_result.php b/system/database/drivers/pdo/pdo_result.php index 559c2edb3..6b523b001 100644 --- a/system/database/drivers/pdo/pdo_result.php +++ b/system/database/drivers/pdo/pdo_result.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 2.1.0 diff --git a/system/database/drivers/pdo/pdo_utility.php b/system/database/drivers/pdo/pdo_utility.php index 90b46af3e..971ec8803 100644 --- a/system/database/drivers/pdo/pdo_utility.php +++ b/system/database/drivers/pdo/pdo_utility.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 2.1.0 diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 50f096b5d..42329bded 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @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 d54b99b23..756fd347a 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @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 808e8bf72..9161bf955 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @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 f81f85782..dffd8c549 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @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 a6257cb1f..28c3caecd 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @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 96a5e0edb..2b723be0b 100644 --- a/system/database/drivers/sqlite/sqlite_forge.php +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @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 2bbd1dbc0..74c0dc549 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @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 c9914f28d..f00687e38 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index 340cd3a66..6fd52ef70 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/sqlsrv/sqlsrv_forge.php b/system/database/drivers/sqlsrv/sqlsrv_forge.php index 4fa0596cd..2a7766927 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_forge.php +++ b/system/database/drivers/sqlsrv/sqlsrv_forge.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/sqlsrv/sqlsrv_result.php b/system/database/drivers/sqlsrv/sqlsrv_result.php index 38aaec723..1ee19c2d1 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_result.php +++ b/system/database/drivers/sqlsrv/sqlsrv_result.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/sqlsrv/sqlsrv_utility.php b/system/database/drivers/sqlsrv/sqlsrv_utility.php index f58b5bd04..e96df96f9 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_utility.php +++ b/system/database/drivers/sqlsrv/sqlsrv_utility.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b From 24276a3a204ddf5947c66bd74f183d8058c1171e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 8 Jan 2012 02:44:38 +0200 Subject: Improve database classes --- system/database/DB.php | 54 ++--- system/database/DB_active_rec.php | 404 ++++++++++++-------------------------- system/database/DB_cache.php | 49 ++--- system/database/DB_forge.php | 94 +++------ system/database/DB_result.php | 83 +++----- system/database/DB_utility.php | 159 ++++++--------- 6 files changed, 270 insertions(+), 573 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index a0106c133..ed6afd7ed 100755 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -1,13 +1,13 @@ - $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)) : '' - ); + '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['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") + if (strtoupper($val) === 'TRUE') { $val = TRUE; } - elseif (strtoupper($val) == "FALSE") + elseif (strtoupper($val) === 'FALSE') { $val = FALSE; } @@ -114,17 +108,15 @@ function &DB($params = '', $active_record_override = NULL) } } - // No DB specified yet? Beat them senseless... + // 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 + // 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 !== NULL) { $active_record = $active_record_override; @@ -135,18 +127,14 @@ function &DB($params = '', $active_record_override = NULL) if ( ! isset($active_record) OR $active_record == TRUE) { require_once(BASEPATH.'database/DB_active_rec.php'); - if ( ! class_exists('CI_DB')) { class CI_DB extends CI_DB_active_record { } } } - else + elseif ( ! class_exists('CI_DB')) { - if ( ! class_exists('CI_DB')) - { - class CI_DB extends CI_DB_driver { } - } + class CI_DB extends CI_DB_driver { } } require_once(BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver.php'); @@ -168,7 +156,5 @@ function &DB($params = '', $active_record_override = NULL) return $DB; } - - /* End of file DB.php */ -/* Location: ./system/database/DB.php */ \ No newline at end of file +/* Location: ./system/database/DB.php */ diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 486b4d775..30a17d11a 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1,4 +1,4 @@ -_protect_identifiers($type.'('.trim($select).')').' AS '.$this->_protect_identifiers(trim($alias)); - $this->ar_select[] = $sql; if ($this->ar_caching === TRUE) @@ -280,30 +278,27 @@ class CI_DB_active_record extends CI_DB_driver { { $v = trim($v); $this->_track_aliases($v); - - $this->ar_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE); + $this->ar_from[] = $v = $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_from[] = $v; $this->ar_cache_exists[] = 'from'; } } - } else { $val = trim($val); - // 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($val); - - $this->ar_from[] = $this->_protect_identifiers($val, TRUE, NULL, FALSE); + $this->ar_from[] = $val = $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_from[] = $val; $this->ar_cache_exists[] = 'from'; } } @@ -340,23 +335,19 @@ 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); // 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]; + $cond = $this->_protect_identifiers($match[1]).$match[2].$this->_protect_identifiers($match[3]); } // Assemble the JOIN statement - $join = $type.'JOIN '.$this->_protect_identifiers($table, TRUE, NULL, FALSE).' ON '.$cond; + $this->ar_join[] = $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; @@ -429,7 +420,7 @@ class CI_DB_active_record extends CI_DB_driver { foreach ($key as $k => $v) { - $prefix = (count($this->ar_where) == 0 AND count($this->ar_cache_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)) { @@ -442,7 +433,6 @@ class CI_DB_active_record extends CI_DB_driver { if ($escape === TRUE) { $k = $this->_protect_identifiers($k, FALSE, $escape); - $v = ' '.$this->escape($v); } @@ -457,7 +447,6 @@ 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; @@ -571,11 +560,9 @@ class CI_DB_active_record extends CI_DB_driver { $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) . ") "; + $prefix = (count($this->ar_where) === 0) ? '' : $type; + $this->ar_where[] = $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; @@ -679,20 +666,18 @@ 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; - + $prefix = (count($this->ar_like) === 0) ? '' : $type; $v = $this->escape_like_str($v); - if ($side == 'none') + if ($side === 'none') { $like_statement = $prefix." $k $not LIKE '{$v}'"; } - elseif ($side == 'before') + elseif ($side === 'before') { $like_statement = $prefix." $k $not LIKE '%{$v}'"; } - elseif ($side == 'after') + elseif ($side === 'after') { $like_statement = $prefix." $k $not LIKE '{$v}%'"; } @@ -715,6 +700,7 @@ class CI_DB_active_record extends CI_DB_driver { } } + return $this; } @@ -730,13 +716,10 @@ class CI_DB_active_record extends CI_DB_driver { public function group_start($not = '', $type = 'AND ') { $type = $this->_group_get_type($type); - $this->ar_where_group_started = TRUE; + $prefix = (count($this->ar_where) === 0 AND count($this->ar_cache_where) === 0) ? '' : $type; + $this->ar_where[] = $value = $prefix.$not.str_repeat(' ', ++$this->ar_where_group_count).' ('; - $prefix = (count($this->ar_where) == 0 AND count($this->ar_cache_where) == 0) ? '' : $type; - $value = $prefix . $not . str_repeat(' ', ++$this->ar_where_group_count) . ' ('; - - $this->ar_where[] = $value; if ($this->ar_caching) { $this->ar_cache_where[] = $value; @@ -790,16 +773,14 @@ class CI_DB_active_record extends CI_DB_driver { */ public function group_end() { - $value = str_repeat(' ', $this->ar_where_group_count--) . ')'; + $this->ar_where_group_started = FALSE; + $this->ar_where[] = $value = str_repeat(' ', $this->ar_where_group_count--) . ')'; - $this->ar_where[] = $value; if ($this->ar_caching) { $this->ar_cache_where[] = $value; } - $this->ar_where_group_started = FALSE; - return $this; } @@ -845,15 +826,16 @@ class CI_DB_active_record extends CI_DB_driver { if ($val != '') { - $this->ar_groupby[] = $this->_protect_identifiers($val); + $this->ar_groupby[] = $val = $this->_protect_identifiers($val); if ($this->ar_caching === TRUE) { - $this->ar_cache_groupby[] = $this->_protect_identifiers($val); + $this->ar_cache_groupby[] = $val; $this->ar_cache_exists[] = 'groupby'; } } } + return $this; } @@ -909,7 +891,7 @@ class CI_DB_active_record extends CI_DB_driver { foreach ($key as $k => $v) { - $prefix = (count($this->ar_having) == 0) ? '' : $type; + $prefix = (count($this->ar_having) === 0) ? '' : $type; if ($escape === TRUE) { @@ -949,7 +931,7 @@ class CI_DB_active_record extends CI_DB_driver { */ public function order_by($orderby, $direction = '', $escape = TRUE) { - if (strtolower($direction) == 'random') + if (strtolower($direction) === 'random') { $orderby = ''; // Random results want or don't need a field name $direction = $this->_random_keyword; @@ -960,7 +942,7 @@ class CI_DB_active_record extends CI_DB_driver { } - if ((strpos($orderby, ',') !== FALSE) && ($escape === TRUE)) + if ((strpos($orderby, ',') !== FALSE) && $escape === TRUE) { $temp = array(); foreach (explode(',', $orderby) as $part) @@ -976,7 +958,7 @@ class CI_DB_active_record extends CI_DB_driver { $orderby = implode(', ', $temp); } - else if ($direction != $this->_random_keyword) + elseif ($direction != $this->_random_keyword) { if ($escape === TRUE) { @@ -984,9 +966,8 @@ class CI_DB_active_record extends CI_DB_driver { } } - $orderby_statement = $orderby.$direction; + $this->ar_orderby[] = $orderby_statement = $orderby.$direction; - $this->ar_orderby[] = $orderby_statement; if ($this->ar_caching === TRUE) { $this->ar_cache_orderby[] = $orderby_statement; @@ -1121,9 +1102,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->limit($limit, $offset); } - $sql = $this->_compile_select(); - - $result = $this->query($sql); + $result = $this->query($this->_compile_select()); $this->_reset_select(); return $result; } @@ -1145,12 +1124,10 @@ class CI_DB_active_record extends CI_DB_driver { $this->from($table); } - $sql = $this->_compile_select($this->_count_string . $this->_protect_identifiers('numrows')); - - $query = $this->query($sql); + $result = $this->query($this->_compile_select($this->_count_string.$this->_protect_identifiers('numrows'))); $this->_reset_select(); - if ($query->num_rows() == 0) + if ($query->num_rows() === 0) { return 0; } @@ -1188,9 +1165,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->limit($limit, $offset); } - $sql = $this->_compile_select(); - - $result = $this->query($sql); + $result = $this->query($this->_compile_select()); $this->_reset_select(); return $result; } @@ -1213,11 +1188,11 @@ class CI_DB_active_record extends CI_DB_driver { $this->set_insert_batch($set); } - if (count($this->ar_set) == 0) + 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; @@ -1227,30 +1202,19 @@ class CI_DB_active_record extends CI_DB_driver { { if ( ! isset($this->ar_from[0])) { - if ($this->db_debug) - { - return $this->display_error('db_must_set_table'); - } - return FALSE; + return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; } $table = $this->ar_from[0]; } // Batch this baby - for ($i = 0, $total = count($this->ar_set); $i < $total; $i = $i + 100) + for ($i = 0, $total = count($this->ar_set); $i < $total; $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->query($this->_insert_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_keys, array_slice($this->ar_set, $i, 100))); } $this->_reset_write(); - - return TRUE; } @@ -1294,7 +1258,6 @@ class CI_DB_active_record extends CI_DB_driver { else { $clean = array(); - foreach ($row as $value) { $clean[] = $this->escape($value); @@ -1398,24 +1361,16 @@ class CI_DB_active_record extends CI_DB_driver { */ protected function _validate_insert($table = '') { - if (count($this->ar_set) == 0) + if (count($this->ar_set) === 0) { - if ($this->db_debug) - { - return $this->display_error('db_must_use_set'); - } - return FALSE; + return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE; } if ($table == '') { if ( ! isset($this->ar_from[0])) { - if ($this->db_debug) - { - return $this->display_error('db_must_set_table'); - } - return FALSE; + return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; } } else @@ -1444,31 +1399,22 @@ class CI_DB_active_record extends CI_DB_driver { $this->set($set); } - if (count($this->ar_set) == 0) + if (count($this->ar_set) === 0) { - if ($this->db_debug) - { - return $this->display_error('db_must_use_set'); - } - return FALSE; + return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE; } if ($table == '') { if ( ! isset($this->ar_from[0])) { - if ($this->db_debug) - { - return $this->display_error('db_must_set_table'); - } - return FALSE; + return ($this->db_debug) ? $this->display_error('db_must_set_table') : 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); } @@ -1543,7 +1489,6 @@ class CI_DB_active_record extends CI_DB_driver { } $sql = $this->_update($this->_protect_identifiers($this->ar_from[0], TRUE, NULL, FALSE), $this->ar_set, $this->ar_where, $this->ar_orderby, $this->ar_limit, $this->ar_like); - $this->_reset_write(); return $this->query($sql); } @@ -1559,34 +1504,28 @@ class CI_DB_active_record extends CI_DB_driver { * * @access public * @param string the table to update data on - * @return string + * @return bool */ protected function _validate_update($table = '') { if (count($this->ar_set) == 0) { - if ($this->db_debug) - { - return $this->display_error('db_must_use_set'); - } - return FALSE; + return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE; } if ($table == '') { if ( ! isset($this->ar_from[0])) { - if ($this->db_debug) - { - return $this->display_error('db_must_set_table'); - } - return FALSE; + return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; } } else { $this->ar_from[0] = $table; } + + return TRUE; } // -------------------------------------------------------------------- @@ -1599,7 +1538,7 @@ class CI_DB_active_record extends CI_DB_driver { * @param string the table to retrieve the results from * @param array an associative array of update values * @param string the where key - * @return object + * @return bool */ public function update_batch($table = '', $set = NULL, $index = NULL) { @@ -1608,12 +1547,7 @@ class CI_DB_active_record extends CI_DB_driver { if (is_null($index)) { - if ($this->db_debug) - { - return $this->display_error('db_must_use_index'); - } - - return FALSE; + return ($this->db_debug) ? $this->display_error('db_must_use_index') : FALSE; } if ( ! is_null($set)) @@ -1621,39 +1555,29 @@ class CI_DB_active_record extends CI_DB_driver { $this->set_update_batch($set, $index); } - if (count($this->ar_set) == 0) + if (count($this->ar_set) === 0) { - if ($this->db_debug) - { - return $this->display_error('db_must_use_set'); - } - - return FALSE; + return ($this->db_debug) ? $this->display_error('db_must_use_set') : FALSE; } if ($table == '') { if ( ! isset($this->ar_from[0])) { - if ($this->db_debug) - { - return $this->display_error('db_must_set_table'); - } - return FALSE; + return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; } $table = $this->ar_from[0]; } // Batch this baby - for ($i = 0, $total = count($this->ar_set); $i < $total; $i = $i + 100) + for ($i = 0, $total = count($this->ar_set); $i < $total; $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->query($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->_reset_write(); + return TRUE; } // -------------------------------------------------------------------- @@ -1679,7 +1603,6 @@ class CI_DB_active_record extends CI_DB_driver { { $index_set = FALSE; $clean = array(); - foreach ($v as $k2 => $v2) { if ($k2 == $index) @@ -1691,14 +1614,7 @@ class CI_DB_active_record extends CI_DB_driver { $not[] = $k.'-'.$v; } - if ($escape === FALSE) - { - $clean[$this->_protect_identifiers($k2)] = $v2; - } - else - { - $clean[$this->_protect_identifiers($k2)] = $this->escape($v2); - } + $clean[$this->_protect_identifiers($k2)] = ($escape === FALSE) ? $v2 : $this->escape($v2); } if ($index_set == FALSE) @@ -1728,11 +1644,7 @@ class CI_DB_active_record extends CI_DB_driver { { if ( ! isset($this->ar_from[0])) { - if ($this->db_debug) - { - return $this->display_error('db_must_set_table'); - } - return FALSE; + return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; } $table = $this->ar_from[0]; @@ -1743,9 +1655,7 @@ class CI_DB_active_record extends CI_DB_driver { } $sql = $this->_delete($table); - $this->_reset_write(); - return $this->query($sql); } @@ -1767,11 +1677,7 @@ class CI_DB_active_record extends CI_DB_driver { { if ( ! isset($this->ar_from[0])) { - if ($this->db_debug) - { - return $this->display_error('db_must_set_table'); - } - return FALSE; + return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; } $table = $this->ar_from[0]; @@ -1782,9 +1688,7 @@ class CI_DB_active_record extends CI_DB_driver { } $sql = $this->_truncate($table); - $this->_reset_write(); - return $this->query($sql); } @@ -1830,11 +1734,7 @@ class CI_DB_active_record extends CI_DB_driver { { if ( ! isset($this->ar_from[0])) { - if ($this->db_debug) - { - return $this->display_error('db_must_set_table'); - } - return FALSE; + return ($this->db_debug) ? $this->display_error('db_must_set_table') : FALSE; } $table = $this->ar_from[0]; @@ -1864,29 +1764,18 @@ 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) == 0) + if (count($this->ar_where) === 0 && count($this->ar_wherein) === 0 && count($this->ar_like) === 0) { - if ($this->db_debug) - { - return $this->display_error('db_del_must_use_where'); - } - - return FALSE; + return ($this->db_debug) ? $this->display_error('db_del_must_use_where') : FALSE; } $sql = $this->_delete($table, $this->ar_where, $this->ar_like, $this->ar_limit); - if ($reset_data) { $this->_reset_write(); } - if ($this->return_delete_sql === true) - { - return $sql; - } - - return $this->query($sql); + return ($this->return_delete_sql === TRUE) ? $sql : $this->query($sql); } // -------------------------------------------------------------------- @@ -1953,13 +1842,13 @@ class CI_DB_active_record extends CI_DB_driver { } // if a table alias is used we can recognize it by a space - if (strpos($table, " ") !== FALSE) + 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, " ")); + $table = trim(strrchr($table, ' ')); // Store the alias, if it doesn't already exist if ( ! in_array($table, $this->ar_aliased_tables)) @@ -1984,10 +1873,7 @@ class CI_DB_active_record extends CI_DB_driver { // 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; @@ -1996,7 +1882,7 @@ class CI_DB_active_record extends CI_DB_driver { { $sql = ( ! $this->ar_distinct) ? 'SELECT ' : 'SELECT DISTINCT '; - if (count($this->ar_select) == 0) + if (count($this->ar_select) === 0) { $sql .= '*'; } @@ -2015,32 +1901,19 @@ class CI_DB_active_record extends CI_DB_driver { } } - // ---------------------------------------------------------------- - // Write the "FROM" portion of the query - if (count($this->ar_from) > 0) { - $sql .= "\nFROM "; - - $sql .= $this->_from_tables($this->ar_from); + $sql .= "\nFROM ".$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); + $sql .= "\n".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 "; @@ -2048,10 +1921,7 @@ 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) @@ -2062,50 +1932,32 @@ class CI_DB_active_record extends CI_DB_driver { $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); + $sql .= "\nGROUP BY ".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); + $sql .= "\nHAVING ".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); - + $sql .= "\nORDER BY ".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 $this->_limit($sql."\n", $this->ar_limit, $this->ar_offset); } return $sql; @@ -2165,14 +2017,12 @@ 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') + if ($val !== '_parent_name') { - $i = 0; foreach ($out[$val] as $data) { - $array[$i][$val] = $data; - $i++; + $array[$i++][$val] = $data; } } } @@ -2247,7 +2097,7 @@ class CI_DB_active_record extends CI_DB_driver { */ protected function _merge_cache() { - if (count($this->ar_cache_exists) == 0) + if (count($this->ar_cache_exists) === 0) { return; } @@ -2257,7 +2107,7 @@ class CI_DB_active_record extends CI_DB_driver { $ar_variable = 'ar_'.$val; $ar_cache_var = 'ar_cache_'.$val; - if (count($this->$ar_cache_var) == 0) + if (count($this->$ar_cache_var) === 0) { continue; } @@ -2282,7 +2132,6 @@ class CI_DB_active_record extends CI_DB_driver { * * Publicly-visible method to reset the AR values. * - * @access public * @return void */ public function reset_query() @@ -2319,25 +2168,24 @@ class CI_DB_active_record extends CI_DB_driver { */ 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, - ); - - $this->_reset_run($ar_reset_items); + $this->_reset_run(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 + ) + ); } // -------------------------------------------------------------------- @@ -2351,19 +2199,19 @@ class CI_DB_active_record extends CI_DB_driver { */ 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 - ); - - $this->_reset_run($ar_reset_items); + $this->_reset_run(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 + ) + ); } + } /* End of file DB_active_rec.php */ diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 1ff046c21..79651fcb0 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -1,13 +1,13 @@ -CI - // and load the file helper since we use it a lot + // 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'); @@ -59,11 +50,10 @@ class CI_DB_Cache { /** * Set Cache Directory Path * - * @access public * @param string the path to the cache directory * @return bool */ - function check_path($path = '') + public function check_path($path = '') { if ($path == '') { @@ -76,7 +66,7 @@ class CI_DB_Cache { } // Add a trailing slash to the path if needed - $path = preg_replace("/(.+?)\/*$/", "\\1/", $path); + $path = preg_replace('/(.+?)\/*$/', '\\1/', $path); if ( ! is_dir($path) OR ! is_really_writable($path)) { @@ -96,10 +86,9 @@ class CI_DB_Cache { * 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) + public function read($sql) { if ( ! $this->check_path()) { @@ -107,9 +96,7 @@ 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); if (FALSE === ($cachedata = read_file($filepath))) @@ -125,10 +112,9 @@ class CI_DB_Cache { /** * Write a query to a cache file * - * @access public * @return bool */ - function write($sql, $object) + public function write($sql, $object) { if ( ! $this->check_path()) { @@ -136,11 +122,8 @@ 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)) @@ -167,10 +150,9 @@ class CI_DB_Cache { /** * Delete cache files within a particular directory * - * @access public * @return bool */ - function delete($segment_one = '', $segment_two = '') + public function delete($segment_one = '', $segment_two = '') { if ($segment_one == '') { @@ -183,7 +165,6 @@ class CI_DB_Cache { } $dir_path = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'; - delete_files($dir_path, TRUE); } @@ -192,16 +173,14 @@ class CI_DB_Cache { /** * Delete all existing cache files * - * @access public * @return bool */ - function delete_all() + public 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 +/* Location: ./system/database/DB_cache.php */ diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index 762d18a46..336e9497d 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -1,13 +1,13 @@ -db $CI =& get_instance(); $this->db =& $CI->db; - log_message('debug', "Database Forge Class Initialized"); + log_message('debug', 'Database Forge Class Initialized'); } // -------------------------------------------------------------------- @@ -60,20 +54,13 @@ class CI_DB_forge { /** * Create database * - * @access public * @param string the database name * @return bool */ - function create_database($db_name) + public function create_database($db_name) { $sql = $this->_create_database($db_name); - - if (is_bool($sql)) - { - return $sql; - } - - return $this->db->query($sql); + return is_bool($sql) ? $sql : $this->db->query($sql); } // -------------------------------------------------------------------- @@ -81,20 +68,13 @@ class CI_DB_forge { /** * Drop database * - * @access public * @param string the database name * @return bool */ - function drop_database($db_name) + public function drop_database($db_name) { $sql = $this->_drop_database($db_name); - - if (is_bool($sql)) - { - return $sql; - } - - return $this->db->query($sql); + return is_bool($sql) ? $sql : $this->db->query($sql); } // -------------------------------------------------------------------- @@ -152,7 +132,7 @@ class CI_DB_forge { if (is_string($field)) { - if ($field == 'id') + if ($field === 'id') { $this->add_field(array( 'id' => array( @@ -178,7 +158,7 @@ class CI_DB_forge { { $this->fields = array_merge($this->fields, $field); } - + return $this; } @@ -197,21 +177,14 @@ class CI_DB_forge { show_error('A table name is required for that operation.'); } - if (count($this->fields) == 0) + 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(); - - if (is_bool($sql)) - { - return $sql; - } - - return $this->db->query($sql); + return is_bool($sql) ? $sql : $this->db->query($sql); } // -------------------------------------------------------------------- @@ -225,13 +198,7 @@ class CI_DB_forge { public 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); + return is_bool($sql) ? $sql : $this->db->query($sql); } // -------------------------------------------------------------------- @@ -250,8 +217,7 @@ class CI_DB_forge { show_error('A table name is required for that operation.'); } - $sql = $this->_rename_table($this->db->dbprefix.$table_name, $this->db->dbprefix.$new_table_name); - return $this->db->query($sql); + return $this->db->query($this->_rename_table($this->db->dbprefix.$table_name, $this->db->dbprefix.$new_table_name)); } // -------------------------------------------------------------------- @@ -273,8 +239,7 @@ 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 (array_keys($field) as $k) { $this->add_field(array($k => $field[$k])); @@ -284,7 +249,6 @@ class CI_DB_forge { } $sql = $this->_alter_table('ADD', $this->db->dbprefix.$table, $this->fields, $after_field); - $this->_reset(); if ($this->db->query($sql) === FALSE) @@ -307,7 +271,6 @@ class CI_DB_forge { */ public function drop_column($table = '', $column_name = '') { - if ($table == '') { show_error('A table name is required for that operation.'); @@ -318,9 +281,7 @@ class CI_DB_forge { 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); + return $this->db->query($this->_alter_table('DROP', $this->db->dbprefix.$table, $column_name)); } // -------------------------------------------------------------------- @@ -342,8 +303,7 @@ 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 (array_keys($field) as $k) { // If no name provided, use the current name if ( ! isset($field[$k]['name'])) @@ -352,14 +312,12 @@ class CI_DB_forge { } $this->add_field(array($k => $field[$k])); - - if (count($this->fields) == 0) + 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) @@ -382,12 +340,10 @@ class CI_DB_forge { */ protected function _reset() { - $this->fields = array(); - $this->keys = array(); - $this->primary_keys = array(); + $this->fields = $this->keys = $this->primary_keys = array(); } } /* End of file DB_forge.php */ -/* Location: ./system/database/DB_forge.php */ \ No newline at end of file +/* Location: ./system/database/DB_forge.php */ diff --git a/system/database/DB_result.php b/system/database/DB_result.php index c4ed20b76..730443222 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -1,13 +1,13 @@ -result_array(); - else if ($type == 'object') return $this->result_object(); + if ($type === 'array') return $this->result_array(); + elseif ($type === 'object') return $this->result_object(); else return $this->custom_result_object($type); } @@ -69,8 +65,8 @@ class CI_DB_result { /** * Custom query result. * - * @param class_name A string that represents the type of object you want back - * @return array of objects + * @param string A string that represents the type of object you want back + * @return array of objects */ public function custom_result_object($class_name) { @@ -91,7 +87,6 @@ class CI_DB_result { while ($row = $this->_fetch_object()) { $object = new $class_name(); - foreach ($row as $key => $value) { $object->$key = $value; @@ -109,7 +104,6 @@ class CI_DB_result { /** * Query result. "object" version. * - * @access public * @return object */ public function result_object() @@ -141,7 +135,6 @@ class CI_DB_result { /** * Query result. "array" version. * - * @access public * @return array */ public function result_array() @@ -173,7 +166,6 @@ 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 @@ -197,8 +189,8 @@ class CI_DB_result { $n = 0; } - if ($type == 'object') return $this->row_object($n); - else if ($type == 'array') return $this->row_array($n); + if ($type === 'object') return $this->row_object($n); + elseif ($type === 'array') return $this->row_array($n); else return $this->custom_row_object($n, $type); } @@ -207,8 +199,7 @@ class CI_DB_result { /** * Assigns an item into a particular column slot * - * @access public - * @return object + * @return void */ public function set_row($key, $value = NULL) { @@ -224,7 +215,6 @@ class CI_DB_result { { $this->row_data[$k] = $v; } - return; } @@ -239,14 +229,12 @@ class CI_DB_result { /** * Returns a single result row - custom object version * - * @access public * @return object */ public function custom_row_object($n, $type) { $result = $this->custom_result_object($type); - - if (count($result) == 0) + if (count($result) === 0) { return $result; } @@ -262,14 +250,12 @@ class CI_DB_result { /** * Returns a single result row - object version * - * @access public * @return object */ public function row_object($n = 0) { $result = $this->result_object(); - - if (count($result) == 0) + if (count($result) === 0) { return $result; } @@ -287,14 +273,12 @@ class CI_DB_result { /** * Returns a single result row - array version * - * @access public * @return array */ public function row_array($n = 0) { $result = $this->result_array(); - - if (count($result) == 0) + if (count($result) === 0) { return $result; } @@ -313,18 +297,12 @@ class CI_DB_result { /** * Returns the "first" row * - * @access public * @return object */ public function first_row($type = 'object') { $result = $this->result($type); - - if (count($result) == 0) - { - return $result; - } - return $result[0]; + return (count($result) === 0) ? $result : $result[0]; } // -------------------------------------------------------------------- @@ -332,18 +310,12 @@ class CI_DB_result { /** * Returns the "last" row * - * @access public * @return object */ public function last_row($type = 'object') { $result = $this->result($type); - - if (count($result) == 0) - { - return $result; - } - return $result[count($result) -1]; + return (count($result) === 0) ? $result : $result[count($result) - 1]; } // -------------------------------------------------------------------- @@ -351,14 +323,12 @@ class CI_DB_result { /** * Returns the "next" row * - * @access public * @return object */ public function next_row($type = 'object') { $result = $this->result($type); - - if (count($result) == 0) + if (count($result) === 0) { return $result; } @@ -376,14 +346,12 @@ class CI_DB_result { /** * Returns the "previous" row * - * @access public * @return object */ public function previous_row($type = 'object') { $result = $this->result($type); - - if (count($result) == 0) + if (count($result) === 0) { return $result; } @@ -416,7 +384,6 @@ class CI_DB_result { protected function _fetch_object() { return array(); } } -// END DB_result class /* End of file DB_result.php */ /* Location: ./system/database/DB_result.php */ diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 8db4f3bac..4c881d8a1 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -1,13 +1,13 @@ -db $CI =& get_instance(); $this->db =& $CI->db; - - log_message('debug', "Database Utility Class Initialized"); + log_message('debug', 'Database Utility Class Initialized'); } // -------------------------------------------------------------------- @@ -59,10 +50,9 @@ class CI_DB_utility extends CI_DB_forge { /** * List databases * - * @access public * @return bool */ - function list_databases() + public function list_databases() { // Is there a cached result? if (isset($this->data_cache['db_names'])) @@ -80,8 +70,7 @@ class CI_DB_utility extends CI_DB_forge { } } - $this->data_cache['db_names'] = $dbs; - return $this->data_cache['db_names']; + return $this->data_cache['db_names'] = $dbs; } // -------------------------------------------------------------------- @@ -89,11 +78,10 @@ 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) + public function database_exists($database_name) { // 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 @@ -114,17 +102,17 @@ class CI_DB_utility extends CI_DB_forge { /** * Optimize Table * - * @access public * @param string the table name * @return bool */ - function optimize_table($table_name) + public function optimize_table($table_name) { $sql = $this->_optimize_table($table_name); if (is_bool($sql)) { - show_error('db_must_use_set'); + show_error('db_must_use_set'); + return FALSE; } $query = $this->db->query($sql); @@ -140,10 +128,9 @@ class CI_DB_utility extends CI_DB_forge { /** * Optimize Database * - * @access public * @return array */ - function optimize_database() + public function optimize_database() { $result = array(); foreach ($this->db->list_tables() as $table_name) @@ -177,11 +164,10 @@ class CI_DB_utility extends CI_DB_forge { /** * Repair Table * - * @access public * @param string the table name * @return bool */ - function repair_table($table_name) + public function repair_table($table_name) { $sql = $this->_repair_table($table_name); @@ -203,14 +189,13 @@ class CI_DB_utility extends CI_DB_forge { /** * 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 = '"') + public function csv_from_result($query, $delim = ',', $newline = "\n", $enclosure = '"') { if ( ! is_object($query) OR ! method_exists($query, 'list_fields')) { @@ -218,15 +203,13 @@ class CI_DB_utility extends CI_DB_forge { } $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; + $out = rtrim($out).$newline; // Next blast through the result array and build out the rows foreach ($query->result_array() as $row) @@ -235,8 +218,7 @@ class CI_DB_utility extends CI_DB_forge { { $out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $item).$enclosure.$delim; } - $out = rtrim($out); - $out .= $newline; + $out = rtrim($out).$newline; } return $out; @@ -247,12 +229,11 @@ class CI_DB_utility extends CI_DB_forge { /** * 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()) + public function xml_from_result($query, $params = array()) { if ( ! is_object($query) OR ! method_exists($query, 'list_fields')) { @@ -280,16 +261,14 @@ 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; } $xml .= $tab."".$newline; } - $xml .= "".$newline; - return $xml; + return $xml .= "".$newline; } // -------------------------------------------------------------------- @@ -297,10 +276,9 @@ class CI_DB_utility extends CI_DB_forge { /** * Database Backup * - * @access public * @return void */ - function backup($params = array()) + public function backup($params = array()) { // If the parameters have not been submitted as an // array then we know that it is simply the table @@ -314,14 +292,14 @@ class CI_DB_utility extends CI_DB_forge { // 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" - ); + '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) @@ -335,29 +313,23 @@ class CI_DB_utility extends CI_DB_forge { } } - // ------------------------------------------------------ - // 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) + 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 + // 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) { @@ -367,60 +339,49 @@ class CI_DB_utility extends CI_DB_forge { $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 ($prefs['format'] === 'zip') { - // If they included the .zip file extension we'll remove it - if (preg_match("|.+?\.zip$|", $prefs['filename'])) + // Set the filename if not provided (only needed with Zip files) + if ($prefs['filename'] == '') { - $prefs['filename'] = str_replace('.zip', '', $prefs['filename']); + $prefs['filename'] = (count($prefs['tables']) === 1 ? $prefs['tables'] : $this->db->database) + .date('Y-m-d_H-i', time()).'.sql'; } - - // Tack on the ".sql" file extension if needed - if ( ! preg_match("|.+?\.sql$|", $prefs['filename'])) + else { - $prefs['filename'] .= '.sql'; + // 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(); } + elseif ($prefs['format'] == 'txt') // Was a text file requested? + { + return $this->_backup($prefs); + } + elseif ($prefs['format'] === 'gzip') // Was a Gzip file requested? + { + return gzencode($this->_backup($prefs)); + } + return; } } - /* End of file DB_utility.php */ -/* Location: ./system/database/DB_utility.php */ \ No newline at end of file +/* Location: ./system/database/DB_utility.php */ -- cgit v1.2.3-24-g4f1b From 0f7decce7cb64566e63bd910557006f041514d89 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 8 Jan 2012 04:40:29 +0200 Subject: Swap two vars for readability --- 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 30a17d11a..71762a4de 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -278,7 +278,7 @@ class CI_DB_active_record extends CI_DB_driver { { $v = trim($v); $this->_track_aliases($v); - $this->ar_from[] = $v = $this->_protect_identifiers($v, TRUE, NULL, FALSE); + $v = $this->ar_from[] = $this->_protect_identifiers($v, TRUE, NULL, FALSE); if ($this->ar_caching === TRUE) { -- cgit v1.2.3-24-g4f1b From 1d160e78619574bf7fcb3c9b5d6a4bc9f93f2db6 Mon Sep 17 00:00:00 2001 From: Purwandi Date: Mon, 9 Jan 2012 16:33:28 +0700 Subject: Fix error undefined variable query on count_all_results db active record --- system/database/DB_active_rec.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 71762a4de..424735157 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1127,15 +1127,14 @@ class CI_DB_active_record extends CI_DB_driver { $result = $this->query($this->_compile_select($this->_count_string.$this->_protect_identifiers('numrows'))); $this->_reset_select(); - if ($query->num_rows() === 0) + if ($result->num_rows() === 0) { return 0; } - $row = $query->row(); + $row = $result->row(); return (int) $row->numrows; } - // -------------------------------------------------------------------- /** -- cgit v1.2.3-24-g4f1b From 2caf289a893b8af69bbdce3f29d84d29e5433b58 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 27 Jan 2012 00:12:03 +0200 Subject: Improve the MySQL database driver --- system/database/drivers/mysql/mysql_driver.php | 322 +++++++++--------------- system/database/drivers/mysql/mysql_forge.php | 131 ++++------ system/database/drivers/mysql/mysql_result.php | 57 ++--- system/database/drivers/mysql/mysql_utility.php | 70 ++---- 4 files changed, 205 insertions(+), 375 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 0f69a0723..067710ff0 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -1,13 +1,13 @@ -port != '') { $this->hostname .= ':'.$this->port; } + } + /** + * Non-persistent database connection + * + * @return resource + */ + public function db_connect() + { return @mysql_connect($this->hostname, $this->username, $this->password, TRUE); } @@ -90,16 +89,10 @@ class CI_DB_mysql_driver extends CI_DB { /** * Persistent database connection * - * @access private called by the base class * @return resource */ - function db_pconnect() + public function db_pconnect() { - if ($this->port != '') - { - $this->hostname .= ':'.$this->port; - } - return @mysql_pconnect($this->hostname, $this->username, $this->password); } @@ -111,10 +104,9 @@ class CI_DB_mysql_driver extends CI_DB { * 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() + public function reconnect() { if (mysql_ping($this->conn_id) === FALSE) { @@ -127,10 +119,9 @@ class CI_DB_mysql_driver extends CI_DB { /** * Select the database * - * @access private called by the base class - * @return resource + * @return bool */ - function db_select() + public function db_select() { return @mysql_select_db($this->database, $this->conn_id); } @@ -140,12 +131,11 @@ class CI_DB_mysql_driver extends CI_DB { /** * Set client character set * - * @access public * @param string * @param string - * @return resource + * @return bool */ - function db_set_charset($charset, $collation) + public function db_set_charset($charset, $collation) { return function_exists('mysql_set_charset') ? @mysql_set_charset($charset, $this->conn_id) @@ -157,12 +147,11 @@ class CI_DB_mysql_driver extends CI_DB { /** * Version number query string * - * @access public * @return string */ - function _version() + protected function _version() { - return "SELECT version() AS ver"; + return 'SELECT version() AS ver'; } // -------------------------------------------------------------------- @@ -170,14 +159,12 @@ class CI_DB_mysql_driver extends CI_DB { /** * Execute the query * - * @access private called by the base class * @param string an SQL query - * @return resource + * @return mixed */ - function _execute($sql) + protected function _execute($sql) { - $sql = $this->_prep_query($sql); - return @mysql_query($sql, $this->conn_id); + return @mysql_query($this->_prep_query($sql), $this->conn_id); } // -------------------------------------------------------------------- @@ -187,20 +174,16 @@ class CI_DB_mysql_driver extends CI_DB { * * 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) + protected 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) + // mysql_affected_rows() returns 0 for "DELETE FROM TABLE" queries. This hack + // modifies the query so that it a proper number of affected rows is returned. + if ($this->delete_hack === TRUE && 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 preg_replace('/^\s*DELETE\s+FROM\s+(\S+)\s*$/', 'DELETE FROM \\1 WHERE 1=1', $sql); } return $sql; @@ -211,18 +194,12 @@ class CI_DB_mysql_driver extends CI_DB { /** * Begin Transaction * - * @access public * @return bool */ - function trans_begin($test_mode = FALSE) + public 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) + if ( ! $this->trans_enabled OR $this->_trans_depth > 0) { return TRUE; } @@ -230,7 +207,7 @@ 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. - $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; + $this->_trans_failure = ($test_mode === TRUE); $this->simple_query('SET AUTOCOMMIT=0'); $this->simple_query('START TRANSACTION'); // can also be BEGIN or BEGIN WORK @@ -242,18 +219,12 @@ class CI_DB_mysql_driver extends CI_DB { /** * Commit Transaction * - * @access public * @return bool */ - function trans_commit() + public 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) + if ( ! $this->trans_enabled OR $this->_trans_depth > 0) { return TRUE; } @@ -268,18 +239,12 @@ class CI_DB_mysql_driver extends CI_DB { /** * Rollback Transaction * - * @access public * @return bool */ - function trans_rollback() + public 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) + if ( ! $this->trans_enabled OR $this->_trans_depth > 0) { return TRUE; } @@ -294,12 +259,11 @@ class CI_DB_mysql_driver extends CI_DB { /** * 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) + public function escape_str($str, $like = FALSE) { if (is_array($str)) { @@ -311,7 +275,7 @@ class CI_DB_mysql_driver extends CI_DB { return $str; } - if (function_exists('mysql_real_escape_string') AND is_resource($this->conn_id)) + if (function_exists('mysql_real_escape_string') && is_resource($this->conn_id)) { $str = mysql_real_escape_string($str, $this->conn_id); } @@ -327,7 +291,7 @@ class CI_DB_mysql_driver extends CI_DB { // escape LIKE condition wildcards if ($like === TRUE) { - $str = str_replace(array('%', '_'), array('\\%', '\\_'), $str); + return str_replace(array('%', '_'), array('\\%', '\\_'), $str); } return $str; @@ -338,10 +302,9 @@ class CI_DB_mysql_driver extends CI_DB { /** * Affected Rows * - * @access public - * @return integer + * @return int */ - function affected_rows() + public function affected_rows() { return @mysql_affected_rows($this->conn_id); } @@ -351,10 +314,9 @@ class CI_DB_mysql_driver extends CI_DB { /** * Insert ID * - * @access public - * @return integer + * @return int */ - function insert_id() + public function insert_id() { return @mysql_insert_id($this->conn_id); } @@ -367,27 +329,25 @@ class CI_DB_mysql_driver extends CI_DB { * Generates a platform-specific query string that counts all records in * the specified database * - * @access public * @param string * @return string */ - function count_all($table = '') + public 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)); - + $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(); + $query = $query->row(); $this->_reset_select(); - return (int) $row->numrows; + return (int) $query->numrows; } // -------------------------------------------------------------------- @@ -397,17 +357,16 @@ 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 + * @param bool * @return string */ - function _list_tables($prefix_limit = FALSE) + protected 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 != '') + if ($prefix_limit !== FALSE && $this->dbprefix != '') { - $sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%'"; + return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'"; } return $sql; @@ -420,13 +379,12 @@ class CI_DB_mysql_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 */ - function _list_columns($table = '') + public function _list_columns($table = '') { - return "SHOW COLUMNS FROM ".$this->_protect_identifiers($table, TRUE, NULL, FALSE); + return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE); } // -------------------------------------------------------------------- @@ -436,13 +394,12 @@ class CI_DB_mysql_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 + * @return string */ - function _field_data($table) + public function _field_data($table) { - return "DESCRIBE ".$table; + return 'DESCRIBE '.$table; } // -------------------------------------------------------------------- @@ -450,10 +407,9 @@ class CI_DB_mysql_driver extends CI_DB { /** * The error message string * - * @access private * @return string */ - function _error_message() + protected function _error_message() { return mysql_error($this->conn_id); } @@ -463,10 +419,9 @@ class CI_DB_mysql_driver extends CI_DB { /** * The error message number * - * @access private - * @return integer + * @return int */ - function _error_number() + protected function _error_number() { return mysql_errno($this->conn_id); } @@ -478,11 +433,10 @@ class CI_DB_mysql_driver extends CI_DB { * * This function escapes column and table names * - * @access private * @param string * @return string */ - function _escape_identifiers($item) + public function _escape_identifiers($item) { if ($this->_escape_char == '') { @@ -493,24 +447,20 @@ class CI_DB_mysql_driver extends CI_DB { { if (strpos($item, '.'.$id) !== FALSE) { - $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); + $item = 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); + return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item); } } 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; + $item = str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item); } // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); + return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item.$this->_escape_char); } // -------------------------------------------------------------------- @@ -521,11 +471,10 @@ class CI_DB_mysql_driver extends CI_DB { * 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 + * @param string table name + * @return string */ - function _from_tables($tables) + protected function _from_tables($tables) { if ( ! is_array($tables)) { @@ -542,15 +491,14 @@ class CI_DB_mysql_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 */ - function _insert($table, $keys, $values) + protected function _insert($table, $keys, $values) { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')'; } // -------------------------------------------------------------------- @@ -561,15 +509,14 @@ class CI_DB_mysql_driver extends CI_DB { * * 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) + protected function _replace($table, $keys, $values) { - return "REPLACE INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return 'REPLACE INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')'; } // -------------------------------------------------------------------- @@ -579,15 +526,14 @@ class CI_DB_mysql_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 */ - function _insert_batch($table, $keys, $values) + protected function _insert_batch($table, $keys, $values) { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values); + return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES '.implode(', ', $values); } // -------------------------------------------------------------------- @@ -598,7 +544,6 @@ class CI_DB_mysql_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 @@ -606,34 +551,22 @@ class CI_DB_mysql_driver extends CI_DB { * @param array the limit clause * @return string */ - function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array()) + protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array()) { foreach ($values as $key => $val) { - $valstr[] = $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) : ''; - - if (count($like) > 0) + $where = ($where != '' && count($where) > 0) ? ' WHERE '.implode(' ', $where) : ''; + if (count($like) > 0) { - $sql .= ($where == '' AND count($where) <1) ? " WHERE " : ' AND '; - - foreach ($like as $st_like) - { - $sql .= " " . $st_like; - } + $where .= ($where == '' ? ' WHERE ' : ' AND ').implode(' ', $like); } - $sql .= $orderby.$limit; - - return $sql; + return 'UPDATE '.$table.' SET '.implode(', ', $valstr).$where + .(count($orderby) > 0 ? ' ORDER BY '.implode(', ', $orderby) : '') + .( ! $limit ? '' : ' LIMIT '.$limit); } // -------------------------------------------------------------------- @@ -644,17 +577,14 @@ class CI_DB_mysql_driver extends CI_DB { * * 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) + protected 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]; @@ -668,30 +598,21 @@ class CI_DB_mysql_driver extends CI_DB { } } - $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, '; + $cases .= $k." = CASE \n" + .implode("\n", $v)."\n" + .'ELSE '.$k.' END, '; } - $sql .= substr($cases, 0, -2); - - $sql .= ' WHERE '.$where.$index.' IN ('.implode(',', $ids).')'; - - return $sql; + return 'UPDATE '.$table.' SET '.substr($cases, 0, -2) + .' WHERE '.(($where != '' && count($where) > 0) ? implode(' ', $where).' AND ' : '') + .$index.' IN('.implode(',', $ids).')'; } // -------------------------------------------------------------------- - /** * Truncate statement * @@ -699,13 +620,12 @@ class CI_DB_mysql_driver extends CI_DB { * 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) + protected function _truncate($table) { - return "TRUNCATE ".$table; + return 'TRUNCATE '.$table; } // -------------------------------------------------------------------- @@ -715,31 +635,27 @@ class CI_DB_mysql_driver extends CI_DB { * * 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) + protected 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); + $conditions = "\nWHERE ".implode("\n", $this->ar_where); if (count($where) > 0 && count($like) > 0) { - $conditions .= " AND "; + $conditions .= ' AND '; } $conditions .= implode("\n", $like); } - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - return "DELETE FROM ".$table.$conditions.$limit; + return 'DELETE FROM '.$table.$conditions.( ! $limit ? '' : ' LIMIT '.$limit); } // -------------------------------------------------------------------- @@ -749,24 +665,14 @@ class CI_DB_mysql_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 + * @param int the number of rows to limit the query to + * @param int the offset value * @return string */ - function _limit($sql, $limit, $offset) + protected function _limit($sql, $limit, $offset) { - if ($offset == 0) - { - $offset = ''; - } - else - { - $offset .= ", "; - } - - return $sql."LIMIT ".$offset.$limit; + return $sql.' LIMIT '.($offset == 0 ? '' : $offset.', ').$limit; } // -------------------------------------------------------------------- @@ -774,17 +680,15 @@ class CI_DB_mysql_driver extends CI_DB { /** * Close DB Connection * - * @access public * @param resource * @return void */ - function _close($conn_id) + protected 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 +/* Location: ./system/database/drivers/mysql/mysql_driver.php */ diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index a41a7b446..d3107134e 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -1,13 +1,13 @@ -$attributes) + 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"; + $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']).' '; - } + $sql .= "\n\t".$this->db->protect_identifiers($field) + .( ! empty($attributes['NAME']) ? ' '.$this->db->protect_identifiers($attributes['NAME']).' ' : ''); - if (array_key_exists('TYPE', $attributes)) + if ( ! empty($attributes['TYPE'])) { $sql .= ' '.$attributes['TYPE']; - if (array_key_exists('CONSTRAINT', $attributes)) + if ( ! empty($attributes['CONSTRAINT'])) { - switch ($attributes['TYPE']) + switch (strtolower($attributes['TYPE'])) { case 'decimal': case 'float': case 'numeric': $sql .= '('.implode(',', $attributes['CONSTRAINT']).')'; - break; - + break; case 'enum': case 'set': $sql .= '("'.implode('","', $attributes['CONSTRAINT']).'")'; - break; - + break; default: $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'; - } + $sql .= (( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '') + .(isset($attributes['DEFAULT']) ? " DEFAULT '".$attributes['DEFAULT']."'" : '') + .(( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL') + .(( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : ''); } // don't add a comma on the end of the last field @@ -161,15 +131,14 @@ class CI_DB_mysql_forge extends CI_DB_forge { /** * 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 + * @param bool should 'IF NOT EXISTS' be added to the SQL * @return bool */ - function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) + public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) { $sql = 'CREATE TABLE '; @@ -178,15 +147,12 @@ class CI_DB_mysql_forge extends CI_DB_forge { $sql .= 'IF NOT EXISTS '; } - $sql .= $this->db->_escape_identifiers($table)." ("; - - $sql .= $this->_process_fields($fields); + $sql .= $this->db->_escape_identifiers($table).' ('.$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) . ")"; + $sql .= ",\n\tPRIMARY KEY ".$key_name.' ('.implode(', ', $this->db->protect_identifiers($primary_keys)).')'; } if (is_array($keys) && count($keys) > 0) @@ -204,13 +170,11 @@ class CI_DB_mysql_forge extends CI_DB_forge { $key = array($key_name); } - $sql .= ",\n\tKEY {$key_name} (" . implode(', ', $key) . ")"; + $sql .= ",\n\tKEY ".$key_name.' ('.implode(', ', $key).')'; } } - $sql .= "\n) DEFAULT CHARACTER SET {$this->db->char_set} COLLATE {$this->db->dbcollat};"; - - return $sql; + return $sql."\n) DEFAULT CHARACTER SET ".$this->db->char_set.' COLLATE '.$this->db->dbcollat.';'; } // -------------------------------------------------------------------- @@ -218,12 +182,12 @@ class CI_DB_mysql_forge extends CI_DB_forge { /** * Drop Table * - * @access private + * @param string table name * @return string */ - function _drop_table($table) + public function _drop_table($table) { - return "DROP TABLE IF EXISTS ".$this->db->_escape_identifiers($table); + return 'DROP TABLE IF EXISTS '.$this->db->_escape_identifiers($table); } // -------------------------------------------------------------------- @@ -232,33 +196,26 @@ class CI_DB_mysql_forge extends CI_DB_forge { * Alter table query * * Generates a platform-specific query so that a table can be altered - * Called by add_column(), drop_column(), and column_alter(), + * 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 + * @return string */ - function _alter_table($alter_type, $table, $fields, $after_field = '') + public function _alter_table($alter_type, $table, $fields, $after_field = '') { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type "; + $sql = 'ALTER TABLE '.$this->db->protect_identifiers($table).' '.$alter_type.' '; // DROP has everything it needs now. - if ($alter_type == 'DROP') + if ($alter_type === 'DROP') { - return $sql.$this->db->_protect_identifiers($fields); + 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; + return $sql.$this->_process_fields($fields) + .($after_field != '' ? ' AFTER '.$this->db->protect_identifiers($after_field) : ''); } // -------------------------------------------------------------------- @@ -268,18 +225,16 @@ class CI_DB_mysql_forge extends CI_DB_forge { * * 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) + public 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; + return 'ALTER TABLE '.$this->db->protect_identifiers($table_name).' RENAME TO '.$this->db->protect_identifiers($new_table_name); } } /* End of file mysql_forge.php */ -/* Location: ./system/database/drivers/mysql/mysql_forge.php */ \ No newline at end of file +/* Location: ./system/database/drivers/mysql/mysql_forge.php */ diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index dcb99cd60..8f04a936d 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -1,13 +1,13 @@ -result_id); } @@ -54,10 +51,9 @@ class CI_DB_mysql_result extends CI_DB_result { /** * Number of fields in the result set * - * @access public - * @return integer + * @return int */ - function num_fields() + public function num_fields() { return @mysql_num_fields($this->result_id); } @@ -69,10 +65,9 @@ class CI_DB_mysql_result extends CI_DB_result { * * Generates an array of column names * - * @access public * @return array */ - function list_fields() + public function list_fields() { $field_names = array(); while ($field = mysql_fetch_field($this->result_id)) @@ -90,25 +85,21 @@ class CI_DB_mysql_result extends CI_DB_result { * * Generates an array of objects containing field meta-data * - * @access public * @return array */ - function field_data() + public function field_data() { $retval = array(); while ($field = mysql_fetch_object($this->result_id)) { preg_match('/([a-zA-Z]+)(\(\d+\))?/', $field->Type, $matches); - $type = (array_key_exists(1, $matches)) ? $matches[1] : NULL; - $length = (array_key_exists(2, $matches)) ? preg_replace('/[^\d]/', '', $matches[2]) : NULL; - - $F = new stdClass(); - $F->name = $field->Field; - $F->type = $type; - $F->default = $field->Default; - $F->max_length = $length; - $F->primary_key = ( $field->Key == 'PRI' ? 1 : 0 ); + $F = new stdClass(); + $F->name = $field->Field; + $F->type = ( ! empty($matches[1])) ? $matches[1] : NULL; + $F->default = $field->Default; + $F->max_length = ( ! empty($matches[2])) ? preg_replace('/[^\d]/', '', $matches[2]) : NULL; + $F->primary_key = (int) ($field->Key === 'PRI'); $retval[] = $F; } @@ -121,9 +112,9 @@ class CI_DB_mysql_result extends CI_DB_result { /** * Free the result * - * @return null + * @return void */ - function free_result() + public function free_result() { if (is_resource($this->result_id)) { @@ -137,14 +128,13 @@ class CI_DB_mysql_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 * - * @access private * @return array */ - function _data_seek($n = 0) + protected function _data_seek($n = 0) { return mysql_data_seek($this->result_id, $n); } @@ -156,10 +146,9 @@ class CI_DB_mysql_result extends CI_DB_result { * * Returns the result set as an array * - * @access private * @return array */ - function _fetch_assoc() + protected function _fetch_assoc() { return mysql_fetch_assoc($this->result_id); } @@ -171,16 +160,14 @@ class CI_DB_mysql_result extends CI_DB_result { * * Returns the result set as an object * - * @access private * @return object */ - function _fetch_object() + protected 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 +/* Location: ./system/database/drivers/mysql/mysql_result.php */ diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 703524165..0e7c18e16 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -1,13 +1,13 @@ -db->_escape_identifiers($table); + return 'OPTIMIZE TABLE '.$this->db->_escape_identifiers($table); } // -------------------------------------------------------------------- @@ -70,26 +66,24 @@ class CI_DB_mysql_utility extends CI_DB_utility { * * Generates a platform-specific query so that a table can be repaired * - * @access private * @param string the table name - * @return object + * @return string */ - function _repair_table($table) + public function _repair_table($table) { - return "REPAIR TABLE ".$this->db->_escape_identifiers($table); + return 'REPAIR TABLE '.$this->db->_escape_identifiers($table); } // -------------------------------------------------------------------- /** * MySQL Export * - * @access private * @param array Preferences * @return mixed */ - function _backup($params = array()) + public function _backup($params = array()) { - if (count($params) == 0) + if (count($params) === 0) { return FALSE; } @@ -99,16 +93,16 @@ class CI_DB_mysql_utility extends CI_DB_utility { // Build the output $output = ''; - foreach ((array)$tables as $table) + foreach ( (array) $tables as $table) { // Is the table in the "ignore" list? - if (in_array($table, (array)$ignore, TRUE)) + if (in_array($table, (array) $ignore, TRUE)) { continue; } // Get the table schema - $query = $this->db->query("SHOW CREATE TABLE `".$this->db->database.'`.`'.$table.'`'); + $query = $this->db->query('SHOW CREATE TABLE `'.$this->db->database.'`.`'.$table.'`'); // No result means the table name was invalid if ($query === FALSE) @@ -141,7 +135,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { } // Grab all the data from the current table - $query = $this->db->query("SELECT * FROM $table"); + $query = $this->db->query('SELECT * FROM '.$table); if ($query->num_rows() == 0) { @@ -149,7 +143,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; @@ -158,11 +152,9 @@ class CI_DB_mysql_utility extends CI_DB_utility { 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; + $is_int[$i] = in_array(strtolower(mysql_field_type($query->result_id, $i)), + array('tinyint', 'smallint', 'mediumint', 'int', 'bigint'), //, 'timestamp'), + TRUE); // Create a string of field names $field_str .= '`'.$field->name.'`, '; @@ -170,8 +162,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { } // Trim off the end comma - $field_str = preg_replace( "/, $/" , "" , $field_str); - + $field_str = preg_replace('/, $/' , '', $field_str); // Build the insert string foreach ($query->result_array() as $row) @@ -189,14 +180,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { 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; - } + $val_str .= ($is_int[$i] == FALSE) ? $this->db->escape($v) : $v; } // Append a comma @@ -205,13 +189,13 @@ class CI_DB_mysql_utility extends CI_DB_utility { } // Remove the comma at the end of the string - $val_str = preg_replace( "/, $/" , "" , $val_str); + $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.$newline.$newline; } return $output; @@ -219,4 +203,4 @@ class CI_DB_mysql_utility extends CI_DB_utility { } /* End of file mysql_utility.php */ -/* Location: ./system/database/drivers/mysql/mysql_utility.php */ \ No newline at end of file +/* Location: ./system/database/drivers/mysql/mysql_utility.php */ -- cgit v1.2.3-24-g4f1b From 1ff49e05b8cb6a7d41a5ed36ff477b8d51b4ef12 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 27 Jan 2012 11:30:41 +0200 Subject: Improve the MySQLi database driver --- system/database/DB_driver.php | 2 +- system/database/drivers/mysqli/mysqli_driver.php | 313 ++++++++-------------- system/database/drivers/mysqli/mysqli_forge.php | 137 +++------- system/database/drivers/mysqli/mysqli_result.php | 57 ++-- system/database/drivers/mysqli/mysqli_utility.php | 34 +-- 5 files changed, 189 insertions(+), 354 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 661b42ced..7445a5069 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -257,7 +257,7 @@ class CI_DB_driver { // 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', 'cubrid', 'pdo'); + $driver_version_exceptions = array('oci8', 'sqlite', 'cubrid', 'pdo', 'mysqli'); if (in_array($this->dbdriver, $driver_version_exceptions)) { diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index aff62a37d..c6ffb4929 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -1,13 +1,13 @@ -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); - } - + return ($this->port != '') + ? @mysqli_connect($this->hostname, $this->username, $this->password, $this->database, $this->port) + : @mysqli_connect($this->hostname, $this->username, $this->password, $this->database); } // -------------------------------------------------------------------- @@ -95,12 +81,13 @@ class CI_DB_mysqli_driver extends CI_DB { /** * Persistent database connection * - * @access private called by the base class - * @return resource + * @return object */ - function db_pconnect() + public function db_pconnect() { - return $this->db_connect(); + return ($this->port != '') + ? @mysqli_connect('p:'.$this->hostname, $this->username, $this->password, $this->database, $this->port) + : @mysqli_connect('p:'.$this->hostname, $this->username, $this->password, $this->database); } // -------------------------------------------------------------------- @@ -111,10 +98,9 @@ class CI_DB_mysqli_driver extends CI_DB { * 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() + public function reconnect() { if (mysqli_ping($this->conn_id) === FALSE) { @@ -127,10 +113,9 @@ class CI_DB_mysqli_driver extends CI_DB { /** * Select the database * - * @access private called by the base class - * @return resource + * @return bool */ - function db_select() + public function db_select() { return @mysqli_select_db($this->conn_id, $this->database); } @@ -140,12 +125,11 @@ class CI_DB_mysqli_driver extends CI_DB { /** * Set client character set * - * @access private * @param string * @param string - * @return resource + * @return bool */ - function _db_set_charset($charset, $collation) + protected function _db_set_charset($charset, $collation) { return function_exists('mysqli_set_charset') ? @mysqli_set_charset($this->conn_id, $charset) @@ -157,12 +141,11 @@ class CI_DB_mysqli_driver extends CI_DB { /** * Version number query string * - * @access public * @return string */ - function _version() + protected function _version() { - return "SELECT version() AS ver"; + return @mysqli_get_server_info($this->conn_id); } // -------------------------------------------------------------------- @@ -170,15 +153,12 @@ class CI_DB_mysqli_driver extends CI_DB { /** * Execute the query * - * @access private called by the base class * @param string an SQL query - * @return resource + * @return mixed */ - function _execute($sql) + protected function _execute($sql) { - $sql = $this->_prep_query($sql); - $result = @mysqli_query($this->conn_id, $sql); - return $result; + return @mysqli_query($this->conn_id, $this->_prep_query($sql)); } // -------------------------------------------------------------------- @@ -188,20 +168,16 @@ class CI_DB_mysqli_driver extends CI_DB { * * 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) + protected 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) + // mysqli_affected_rows() returns 0 for "DELETE FROM TABLE" queries. This hack + // modifies the query so that it a proper number of affected rows is returned. + if ($this->delete_hack === TRUE && 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 preg_replace('/^\s*DELETE\s+FROM\s+(\S+)\s*$/', 'DELETE FROM \\1 WHERE 1=1', $sql); } return $sql; @@ -212,18 +188,12 @@ class CI_DB_mysqli_driver extends CI_DB { /** * Begin Transaction * - * @access public * @return bool */ - function trans_begin($test_mode = FALSE) + public 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) + if ( ! $this->trans_enabled OR $this->_trans_depth > 0) { return TRUE; } @@ -231,7 +201,7 @@ 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. - $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; + $this->_trans_failure = ($test_mode === TRUE); $this->simple_query('SET AUTOCOMMIT=0'); $this->simple_query('START TRANSACTION'); // can also be BEGIN or BEGIN WORK @@ -243,18 +213,12 @@ class CI_DB_mysqli_driver extends CI_DB { /** * Commit Transaction * - * @access public * @return bool */ - function trans_commit() + public 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) + if ( ! $this->trans_enabled OR $this->_trans_depth > 0) { return TRUE; } @@ -269,18 +233,12 @@ class CI_DB_mysqli_driver extends CI_DB { /** * Rollback Transaction * - * @access public * @return bool */ - function trans_rollback() + public 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) + if ( ! $this->trans_enabled OR $this->_trans_depth > 0) { return TRUE; } @@ -295,12 +253,11 @@ class CI_DB_mysqli_driver extends CI_DB { /** * 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) + public function escape_str($str, $like = FALSE) { if (is_array($str)) { @@ -312,7 +269,7 @@ class CI_DB_mysqli_driver extends CI_DB { return $str; } - if (function_exists('mysqli_real_escape_string') AND is_object($this->conn_id)) + if (function_exists('mysqli_real_escape_string') && is_object($this->conn_id)) { $str = mysqli_real_escape_string($this->conn_id, $str); } @@ -328,7 +285,7 @@ class CI_DB_mysqli_driver extends CI_DB { // escape LIKE condition wildcards if ($like === TRUE) { - $str = str_replace(array('%', '_'), array('\\%', '\\_'), $str); + return str_replace(array('%', '_'), array('\\%', '\\_'), $str); } return $str; @@ -339,10 +296,9 @@ class CI_DB_mysqli_driver extends CI_DB { /** * Affected Rows * - * @access public - * @return integer + * @return int */ - function affected_rows() + public function affected_rows() { return @mysqli_affected_rows($this->conn_id); } @@ -352,10 +308,9 @@ class CI_DB_mysqli_driver extends CI_DB { /** * Insert ID * - * @access public - * @return integer + * @return int */ - function insert_id() + public function insert_id() { return @mysqli_insert_id($this->conn_id); } @@ -368,27 +323,25 @@ class CI_DB_mysqli_driver extends CI_DB { * Generates a platform-specific query string that counts all records in * the specified database * - * @access public * @param string * @return string */ - function count_all($table = '') + public 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)); - + $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(); + $query = $query->row(); $this->_reset_select(); - return (int) $row->numrows; + return (int) $query->numrows; } // -------------------------------------------------------------------- @@ -399,16 +352,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 + * @param bool * @return string */ - function _list_tables($prefix_limit = FALSE) + protected 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 != '') + if ($prefix_limit !== FALSE && $this->dbprefix != '') { - $sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%'"; + return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'"; } return $sql; @@ -421,13 +374,12 @@ class CI_DB_mysqli_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 */ - function _list_columns($table = '') + protected function _list_columns($table = '') { - return "SHOW COLUMNS FROM ".$this->_protect_identifiers($table, TRUE, NULL, FALSE); + return 'SHOW COLUMNS FROM '.$this->_protect_identifiers($table, TRUE, NULL, FALSE); } // -------------------------------------------------------------------- @@ -437,13 +389,12 @@ class CI_DB_mysqli_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 + * @return string */ - function _field_data($table) + protected function _field_data($table) { - return "DESCRIBE ".$table; + return 'DESCRIBE '.$table; } // -------------------------------------------------------------------- @@ -451,10 +402,9 @@ class CI_DB_mysqli_driver extends CI_DB { /** * The error message string * - * @access private * @return string */ - function _error_message() + protected function _error_message() { return mysqli_error($this->conn_id); } @@ -464,10 +414,9 @@ class CI_DB_mysqli_driver extends CI_DB { /** * The error message number * - * @access private - * @return integer + * @return int */ - function _error_number() + protected function _error_number() { return mysqli_errno($this->conn_id); } @@ -479,11 +428,10 @@ class CI_DB_mysqli_driver extends CI_DB { * * This function escapes column and table names * - * @access private * @param string * @return string */ - function _escape_identifiers($item) + public function _escape_identifiers($item) { if ($this->_escape_char == '') { @@ -494,24 +442,20 @@ class CI_DB_mysqli_driver extends CI_DB { { if (strpos($item, '.'.$id) !== FALSE) { - $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); + $item = 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); + return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item); } } 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; + $item = str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item); } // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); + return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item.$this->_escape_char); } // -------------------------------------------------------------------- @@ -522,11 +466,10 @@ class CI_DB_mysqli_driver extends CI_DB { * 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 + * @param string + * @return string */ - function _from_tables($tables) + protected function _from_tables($tables) { if ( ! is_array($tables)) { @@ -543,15 +486,14 @@ class CI_DB_mysqli_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 */ - function _insert($table, $keys, $values) + protected function _insert($table, $keys, $values) { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')'; } // -------------------------------------------------------------------- @@ -561,15 +503,14 @@ class CI_DB_mysqli_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 */ - function _insert_batch($table, $keys, $values) + protected function _insert_batch($table, $keys, $values) { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values); + return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES '.implode(', ', $values); } // -------------------------------------------------------------------- @@ -580,17 +521,16 @@ class CI_DB_mysqli_driver extends CI_DB { * * 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) + protected function _replace($table, $keys, $values) { - return "REPLACE INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return 'REPLACE INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')'; } - + // -------------------------------------------------------------------- /** @@ -598,7 +538,6 @@ class CI_DB_mysqli_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 @@ -606,24 +545,17 @@ class CI_DB_mysqli_driver extends CI_DB { * @param array the limit clause * @return string */ - function _update($table, $values, $where, $orderby = array(), $limit = FALSE) + protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE) { foreach ($values as $key => $val) { - $valstr[] = $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 '.$table.' SET '.implode(', ', $valstr) + .(($where != '' && count($where) > 0) ? ' WHERE '.implode(' ', $where) : '') + .(count($orderby) > 0 ? ' ORDER BY '.implode(', ', $orderby) : '') + .( ! $limit ? '' : ' LIMIT '.$limit); } // -------------------------------------------------------------------- @@ -633,17 +565,14 @@ class CI_DB_mysqli_driver extends CI_DB { * * 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) + protected 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]; @@ -657,25 +586,19 @@ class CI_DB_mysqli_driver extends CI_DB { } } - $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, '; + $cases .= $k.' = CASE '."\n" + .implode("\n", $v)."\n" + .'ELSE '.$k.' END, '; } - $sql .= substr($cases, 0, -2); - - $sql .= ' WHERE '.$where.$index.' IN ('.implode(',', $ids).')'; + $where = ($where != '' && count($where) > 0) ? implode(' ', $where).' AND ' : ''; - return $sql; + return 'UPDATE '.$table.' SET '.substr($cases, 0, -2) + .' WHERE '.(($where != '' && count($where) > 0) ? implode(' ', $where).' AND ' : '') + .$index.' IN('.implode(',', $ids).')'; } // -------------------------------------------------------------------- @@ -687,13 +610,12 @@ class CI_DB_mysqli_driver extends CI_DB { * 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) + protected function _truncate($table) { - return "TRUNCATE ".$table; + return 'TRUNCATE '.$table; } // -------------------------------------------------------------------- @@ -703,31 +625,26 @@ class CI_DB_mysqli_driver extends CI_DB { * * 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) + protected 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); + $conditions = "\nWHERE ".implode("\n", $this->ar_where); if (count($where) > 0 && count($like) > 0) { - $conditions .= " AND "; + $conditions .= ' AND '; } $conditions .= implode("\n", $like); } - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - return "DELETE FROM ".$table.$conditions.$limit; + return 'DELETE FROM '.$table.$conditions.( ! $limit ? '' : ' LIMIT '.$limit); } // -------------------------------------------------------------------- @@ -737,22 +654,15 @@ class CI_DB_mysqli_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 + * @param int the number of rows to limit the query to + * @param int the offset value * @return string */ - function _limit($sql, $limit, $offset) + protected function _limit($sql, $limit, $offset) { - $sql .= "LIMIT ".$limit; - - if ($offset > 0) - { - $sql .= " OFFSET ".$offset; - } - - return $sql; + return $sql.' LIMIT '.$limit + .($offset > 0 ? ' OFFSET '.$offset : ''); } // -------------------------------------------------------------------- @@ -760,18 +670,15 @@ class CI_DB_mysqli_driver extends CI_DB { /** * Close DB Connection * - * @access public - * @param resource + * @param object * @return void */ - function _close($conn_id) + protected 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 +/* Location: ./system/database/drivers/mysqli/mysqli_driver.php */ diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index 590efa939..319c6fdac 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -1,13 +1,13 @@ -$attributes) + 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"; + $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) && $attributes['NULL'] === TRUE) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } - - if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) - { - $sql .= ' AUTO_INCREMENT'; - } + $sql .= "\n\t".$this->db->protect_identifiers($field) + .( ! empty($attributes['NAME']) ? ' '.$this->db->protect_identifiers($attributes['NAME']).' ' : '') + .( ! empty($attributes['TYPE']) ? ' '.$attributes['TYPE'] : '') + .( ! empty($attributes['CONSTRAINT']) ? '('.$attributes['CONSTRAINT'].')' : '') + .(( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '') + .(isset($attributes['DEFAULT']) ? " DEFAULT '".$attributes['DEFAULT']."'" : '') + .(( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL') + .(( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : ''); } // don't add a comma on the end of the last field @@ -146,15 +109,14 @@ class CI_DB_mysqli_forge extends CI_DB_forge { /** * 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 + * @param bool should 'IF NOT EXISTS' be added to the SQL * @return bool */ - function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) + public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) { $sql = 'CREATE TABLE '; @@ -163,15 +125,12 @@ class CI_DB_mysqli_forge extends CI_DB_forge { $sql .= 'IF NOT EXISTS '; } - $sql .= $this->db->_escape_identifiers($table)." ("; - - $sql .= $this->_process_fields($fields); + $sql .= $this->db->_escape_identifiers($table).' ('.$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) . ")"; + $key_name = $this->db->protect_identifiers(implode('_', $primary_keys)); + $sql .= ",\n\tPRIMARY KEY ".$key_name.' ('.implode(', ', $this->db->protect_identifiers($primary_keys)).')'; } if (is_array($keys) && count($keys) > 0) @@ -180,22 +139,20 @@ 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_name = $this->db->protect_identifiers(implode('_', $key)); + $key = $this->db->protect_identifiers($key); } else { - $key_name = $this->db->_protect_identifiers($key); + $key_name = $this->db->protect_identifiers($key); $key = array($key_name); } - $sql .= ",\n\tKEY {$key_name} (" . implode(', ', $key) . ")"; + $sql .= ",\n\tKEY ".$key_name.' ('.implode(', ', $key).')'; } } - $sql .= "\n) DEFAULT CHARACTER SET {$this->db->char_set} COLLATE {$this->db->dbcollat};"; - - return $sql; + return $sql."\n) DEFAULT CHARACTER SET ".$this->db->char_set.' COLLATE '.$this->db->dbcollat.';'; } // -------------------------------------------------------------------- @@ -203,12 +160,11 @@ class CI_DB_mysqli_forge extends CI_DB_forge { /** * Drop Table * - * @access private * @return string */ - function _drop_table($table) + public function _drop_table($table) { - return "DROP TABLE IF EXISTS ".$this->db->_escape_identifiers($table); + return 'DROP TABLE IF EXISTS '.$this->db->_escape_identifiers($table); } // -------------------------------------------------------------------- @@ -219,31 +175,24 @@ class CI_DB_mysqli_forge extends CI_DB_forge { * 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 + * @return string */ - function _alter_table($alter_type, $table, $fields, $after_field = '') + public function _alter_table($alter_type, $table, $fields, $after_field = '') { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type "; + $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 != '') + if ($alter_type === 'DROP') { - $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); + return $sql.$this->db->protect_identifiers($fields); } - return $sql; + return $sql.$this->_process_fields($fields) + .($after_field != '' ? ' AFTER '.$this->db->protect_identifiers($after_field) : ''); } // -------------------------------------------------------------------- @@ -253,18 +202,16 @@ class CI_DB_mysqli_forge extends CI_DB_forge { * * 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) + public 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; + return 'ALTER TABLE '.$this->db->protect_identifiers($table_name).' RENAME TO '.$this->db->protect_identifiers($new_table_name); } } /* End of file mysqli_forge.php */ -/* Location: ./system/database/drivers/mysqli/mysqli_forge.php */ \ No newline at end of file +/* Location: ./system/database/drivers/mysqli/mysqli_forge.php */ diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index 89dd4ded8..0a50cccac 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -1,13 +1,13 @@ -result_id); } @@ -54,10 +51,9 @@ class CI_DB_mysqli_result extends CI_DB_result { /** * Number of fields in the result set * - * @access public - * @return integer + * @return int */ - function num_fields() + public function num_fields() { return @mysqli_num_fields($this->result_id); } @@ -69,10 +65,9 @@ class CI_DB_mysqli_result extends CI_DB_result { * * Generates an array of column names * - * @access public * @return array */ - function list_fields() + public function list_fields() { $field_names = array(); while ($field = mysqli_fetch_field($this->result_id)) @@ -90,40 +85,36 @@ class CI_DB_mysqli_result extends CI_DB_result { * * Generates an array of objects containing field meta-data * - * @access public * @return array */ - function field_data() + public function field_data() { $retval = array(); while ($field = mysqli_fetch_object($this->result_id)) { preg_match('/([a-zA-Z]+)(\(\d+\))?/', $field->Type, $matches); - $type = (array_key_exists(1, $matches)) ? $matches[1] : NULL; - $length = (array_key_exists(2, $matches)) ? preg_replace('/[^\d]/', '', $matches[2]) : NULL; - - $F = new stdClass(); - $F->name = $field->Field; - $F->type = $type; - $F->default = $field->Default; - $F->max_length = $length; - $F->primary_key = ( $field->Key == 'PRI' ? 1 : 0 ); + $F = new stdClass(); + $F->name = $field->Field; + $F->type = ( ! empty($matches[1])) ? $matches[1] : NULL; + $F->default = $field->Default; + $F->max_length = ( ! empty($matches[2])) ? preg_replace('/[^\d]/', '', $matches[2]) : NULL; + $F->primary_key = (int) ($field->Key === 'PRI'); $retval[] = $F; } return $retval; } - + // -------------------------------------------------------------------- /** * Free the result * - * @return null + * @return void */ - function free_result() + public function free_result() { if (is_object($this->result_id)) { @@ -141,10 +132,9 @@ class CI_DB_mysqli_result extends CI_DB_result { * this internally before fetching results to make sure the * result set starts at zero * - * @access private * @return array */ - function _data_seek($n = 0) + protected function _data_seek($n = 0) { return mysqli_data_seek($this->result_id, $n); } @@ -156,10 +146,9 @@ class CI_DB_mysqli_result extends CI_DB_result { * * Returns the result set as an array * - * @access private * @return array */ - function _fetch_assoc() + protected function _fetch_assoc() { return mysqli_fetch_assoc($this->result_id); } @@ -171,16 +160,14 @@ class CI_DB_mysqli_result extends CI_DB_result { * * Returns the result set as an object * - * @access private * @return object */ - function _fetch_object() + protected 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 +/* Location: ./system/database/drivers/mysqli/mysqli_result.php */ diff --git a/system/database/drivers/mysqli/mysqli_utility.php b/system/database/drivers/mysqli/mysqli_utility.php index 76bd49e31..3fdc5c723 100644 --- a/system/database/drivers/mysqli/mysqli_utility.php +++ b/system/database/drivers/mysqli/mysqli_utility.php @@ -1,13 +1,13 @@ -db->_escape_identifiers($table); + return 'OPTIMIZE TABLE '.$this->db->_escape_identifiers($table); } // -------------------------------------------------------------------- @@ -70,13 +66,12 @@ class CI_DB_mysqli_utility extends CI_DB_utility { * * Generates a platform-specific query so that a table can be repaired * - * @access private * @param string the table name - * @return object + * @return string */ - function _repair_table($table) + public function _repair_table($table) { - return "REPAIR TABLE ".$this->db->_escape_identifiers($table); + return 'REPAIR TABLE '.$this->db->_escape_identifiers($table); } // -------------------------------------------------------------------- @@ -84,11 +79,10 @@ class CI_DB_mysqli_utility extends CI_DB_utility { /** * MySQLi Export * - * @access private * @param array Preferences * @return mixed */ - function _backup($params = array()) + public function _backup($params = array()) { // Currently unsupported return $this->db->display_error('db_unsuported_feature'); @@ -96,4 +90,4 @@ class CI_DB_mysqli_utility extends CI_DB_utility { } /* End of file mysqli_utility.php */ -/* Location: ./system/database/drivers/mysqli/mysqli_utility.php */ \ No newline at end of file +/* Location: ./system/database/drivers/mysqli/mysqli_utility.php */ -- cgit v1.2.3-24-g4f1b From f055fa98c7c7dbdd44ca485cde9efe112f713123 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 27 Jan 2012 20:36:23 +0200 Subject: Add PHP version check in db_pconnect() --- system/database/drivers/mysqli/mysqli_driver.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'system/database') diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index c6ffb4929..a79b2a4ad 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -85,6 +85,12 @@ class CI_DB_mysqli_driver extends CI_DB { */ public function db_pconnect() { + // Persistent connection support was added in PHP 5.3.0 + if ( ! is_php('5.3')) + { + return $this->db_connect(); + } + return ($this->port != '') ? @mysqli_connect('p:'.$this->hostname, $this->username, $this->password, $this->database, $this->port) : @mysqli_connect('p:'.$this->hostname, $this->username, $this->password, $this->database); -- cgit v1.2.3-24-g4f1b From a3c5cfca6b4a1ec183f3b3c9af88c7f686cf167e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 27 Jan 2012 20:50:33 +0200 Subject: Switch _process_fields() from private to protected --- system/database/drivers/mysqli/mysqli_forge.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index 319c6fdac..7de036127 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -66,7 +66,7 @@ class CI_DB_mysqli_forge extends CI_DB_forge { * @param mixed the fields * @return string */ - private function _process_fields($fields) + public function _process_fields($fields) { $current_field_count = 0; $sql = ''; -- cgit v1.2.3-24-g4f1b From 1820933505d6aa8def25d0e74344f878c3ec76ad Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 9 Feb 2012 16:07:27 +0700 Subject: Fixed PDO --- system/database/DB.php | 1 + system/database/DB_driver.php | 27 ++- system/database/drivers/pdo/pdo_driver.php | 272 +++++++++++++++++++++-------- system/database/drivers/pdo/pdo_forge.php | 12 +- system/database/drivers/pdo/pdo_result.php | 67 ++++++- 5 files changed, 286 insertions(+), 93 deletions(-) (limited to 'system/database') diff --git a/system/database/DB.php b/system/database/DB.php index ed6afd7ed..d06ffb40e 100755 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -82,6 +82,7 @@ function &DB($params = '', $active_record_override = NULL) $params = array( 'dbdriver' => $dns['scheme'], 'hostname' => (isset($dns['host'])) ? rawurldecode($dns['host']) : '', + 'port' => (isset($dns['port'])) ? rawurldecode($dns['port']) : '', 'username' => (isset($dns['user'])) ? rawurldecode($dns['user']) : '', 'password' => (isset($dns['pass'])) ? rawurldecode($dns['pass']) : '', 'database' => (isset($dns['path'])) ? rawurldecode(substr($dns['path'], 1)) : '' diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 7445a5069..b829bbe46 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -81,8 +81,7 @@ class CI_DB_driver { var $stmt_id; var $curs_id; var $limit_used; - - + /** * Constructor. Accepts one parameter containing the database @@ -814,20 +813,23 @@ class CI_DB_driver { if ($query->num_rows() > 0) { - foreach ($query->result_array() as $row) + $table = FALSE; + $rows = $query->result_array(); + $key = (($row = current($rows)) && in_array('table_name', array_map('strtolower', array_keys($row)))); + + if ($key) { - if (isset($row['TABLE_NAME'])) - { - $retval[] = $row['TABLE_NAME']; - } - else - { - $retval[] = array_shift($row); - } + $table = array_key_exists('TABLE_NAME', $row) ? 'TABLE_NAME' : 'table_name'; + } + + foreach ($rows as $row) + { + $retval[] = ( ! $table) ? current($row) : $row[$table]; } } $this->data_cache['table_names'] = $retval; + return $this->data_cache['table_names']; } @@ -1436,10 +1438,7 @@ class CI_DB_driver { return $item.$alias; } - - } - /* End of file DB_driver.php */ /* Location: ./system/database/DB_driver.php */ diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 4f4f44ba7..e1602c4c5 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -46,9 +46,10 @@ class CI_DB_pdo_driver extends CI_DB { // the character used to excape - not necessary for PDO var $_escape_char = ''; + + // clause and character used for LIKE escape sequences var $_like_escape_str; var $_like_escape_chr; - /** * The syntax to count rows is slightly different across different @@ -57,29 +58,36 @@ class CI_DB_pdo_driver extends CI_DB { */ var $_count_string = "SELECT COUNT(*) AS "; var $_random_keyword; - + + // need to track the pdo DSN, driver and options + var $dsn; + var $pdodriver; var $options = array(); function __construct($params) { parent::__construct($params); - + + if (preg_match('/([^;]+):/', $this->dsn, $match) && count($match) == 2) + { + // If there is a minimum valid dsn string pattern found, we're done + // This for general PDO users, who tend to have full DSN string. + $this->pdodriver = end($match); + } + else + { + // Try to build a complete DSN string from params + $this->_connect_string($params); + } + // clause and character used for LIKE escape sequences - if (strpos($this->hostname, 'mysql') !== FALSE) + // this one depends on the driver being used + if ($this->pdodriver == 'mysql') { $this->_like_escape_str = ''; $this->_like_escape_chr = ''; - - //Prior to this version, the charset can't be set in the dsn - if(is_php('5.3.6')) - { - $this->hostname .= ";charset={$this->char_set}"; - } - - //Set the charset with the connection options - $this->options['PDO::MYSQL_ATTR_INIT_COMMAND'] = "SET NAMES {$this->char_set}"; } - else if (strpos($this->hostname, 'odbc') !== FALSE) + elseif ($this->pdodriver == 'odbc') { $this->_like_escape_str = " {escape '%s'} "; $this->_like_escape_chr = '!'; @@ -90,14 +98,85 @@ class CI_DB_pdo_driver extends CI_DB { $this->_like_escape_chr = '!'; } - if (strpos($this->hostname, 'sqlite') === FALSE) + $this->trans_enabled = FALSE; + $this->_random_keyword = ' RND('.time().')'; // database specific random keyword + } + + /** + * Connection String + * + * @access private + * @param array + * @return void + */ + function _connect_string($params) + { + if (strpos($this->hostname, ':')) { - $this->hostname .= ";dbname=".$this->database; + // hostname generally would have this prototype + // $db['hostname'] = 'pdodriver:host(/Server(/DSN))=hostname(/DSN);'; + // We need to get the prefix (pdodriver used by PDO). + $this->dsn = $this->hostname; + $this->pdodriver = substr($this->hostname, 0, strpos($this->hostname, ':')); } - - $this->trans_enabled = FALSE; + else + { + // Invalid DSN, display an error + if ( ! array_key_exists('pdodriver', $params)) + { + show_error('Invalid DB Connection String for PDO'); + } - $this->_random_keyword = ' RND('.time().')'; // database specific random keyword + // Assuming that the following DSN string format is used: + // $dsn = 'pdo://username:password@hostname:port/database?pdodriver=pgsql'; + $this->dsn = $this->pdodriver.':'; + + // Add hostname to the DSN for databases that need it + if ( ! empty($this->hostname) && in_array($this->pdodriver, array('informix', 'mysql', 'pgsql', 'sybase', 'mssql', 'dblib', 'cubrid'))) + { + $this->dsn .= 'host='.$this->hostname.';'; + } + + // Add a port to the DSN for databases that can use it + if ( ! empty($this->port) && in_array($this->pdodriver, array('informix', 'mysql', 'pgsql', 'ibm', 'cubrid'))) + { + $this->dsn .= 'port='.$this->port.';'; + } + } + + // Add the database name to the DSN, if needed + if (stripos($this->dsn, 'dbname') === FALSE + && in_array($this->pdodriver, array('4D', 'pgsql', 'mysql', 'firebird', 'sybase', 'mssql', 'dblib', 'cubrid'))) + { + $this->dsn .= 'dbname='.$this->database.';'; + } + elseif (stripos($this->dsn, 'database') === FALSE && in_array($this->pdodriver, array('ibm', 'sqlsrv'))) + { + if (stripos($this->dsn, 'dsn') === FALSE) + { + $this->dsn .= 'database='.$this->database.';'; + } + } + elseif ($this->pdodriver === 'sqlite' && $this->dsn === 'sqlite:') + { + if ($this->database !== ':memory') + { + if ( ! file_exists($this->database)) + { + show_error('Invalid DB Connection string for PDO SQLite'); + } + + $this->dsn .= (strpos($this->database, DIRECTORY_SEPARATOR) !== 0) ? DIRECTORY_SEPARATOR : ''; + } + + $this->dsn .= $this->database; + } + + // Add charset to the DSN, if needed + if ( ! empty($this->char_set) && in_array($this->pdodriver, array('4D', 'mysql', 'sybase', 'mssql', 'dblib', 'oci'))) + { + $this->dsn .= 'charset='.$this->char_set.';'; + } } /** @@ -108,9 +187,9 @@ class CI_DB_pdo_driver extends CI_DB { */ function db_connect() { - $this->options['PDO::ATTR_ERRMODE'] = PDO::ERRMODE_SILENT; - - return new PDO($this->hostname, $this->username, $this->password, $this->options); + $this->options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_SILENT; + + return $this->pdo_connect(); } // -------------------------------------------------------------------- @@ -123,10 +202,44 @@ class CI_DB_pdo_driver extends CI_DB { */ function db_pconnect() { - $this->options['PDO::ATTR_ERRMODE'] = PDO::ERRMODE_SILENT; - $this->options['PDO::ATTR_PERSISTENT'] = TRUE; + $this->options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_SILENT; + $this->options[PDO::ATTR_PERSISTENT] = TRUE; - return new PDO($this->hostname, $this->username, $this->password, $this->options); + return $this->pdo_connect(); + } + + // -------------------------------------------------------------------- + + /** + * PDO connection + * + * @access private called by the PDO driver class + * @return resource + */ + function pdo_connect() + { + // Refer : http://ch2.php.net/manual/en/ref.pdo-mysql.connection.php + if ($this->pdodriver == 'mysql' && is_php('5.3.6')) + { + $this->options[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES $this->char_set COLLATE '$this->dbcollat'"; + } + + // Connecting... + try + { + $db = new PDO($this->dsn, $this->username, $this->password, $this->options); + } + catch (PDOException $e) + { + if ($this->db_debug && empty($this->failover)) + { + $this->display_error($e->getMessage(), '', TRUE); + } + + return FALSE; + } + + return $db; } // -------------------------------------------------------------------- @@ -146,6 +259,7 @@ class CI_DB_pdo_driver extends CI_DB { { return $this->db->display_error('db_unsuported_feature'); } + return FALSE; } @@ -175,7 +289,6 @@ class CI_DB_pdo_driver extends CI_DB { */ function db_set_charset($charset, $collation) { - // @todo - add support if needed return TRUE; } @@ -204,6 +317,7 @@ class CI_DB_pdo_driver extends CI_DB { function _execute($sql) { $sql = $this->_prep_query($sql); + $result_id = $this->conn_id->query($sql); if (is_object($result_id)) @@ -231,6 +345,17 @@ class CI_DB_pdo_driver extends CI_DB { */ function _prep_query($sql) { + if ($this->pdodriver === 'pgsql') + { + // Change the backtick(s) for Postgre + $sql = str_replace('`', '"', $sql); + } + elseif ($this->pdodriver === 'sqlite') + { + // Change the backtick(s) for SQLite + $sql = str_replace('`', '', $sql); + } + return $sql; } @@ -285,6 +410,7 @@ class CI_DB_pdo_driver extends CI_DB { } $ret = $this->conn->commit(); + return $ret; } @@ -310,6 +436,7 @@ class CI_DB_pdo_driver extends CI_DB { } $ret = $this->conn_id->rollBack(); + return $ret; } @@ -348,7 +475,9 @@ class CI_DB_pdo_driver extends CI_DB { 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), + array($this->_like_escape_chr.'%', + $this->_like_escape_chr.'_', + $this->_like_escape_chr.$this->_like_escape_chr), $str); } @@ -378,9 +507,9 @@ class CI_DB_pdo_driver extends CI_DB { */ function insert_id($name=NULL) { - //Convenience method for postgres insertid - if (strpos($this->hostname, 'pgsql') !== FALSE) + if ($this->pdodriver == 'pgsql') { + //Convenience method for postgres insertid $v = $this->_version(); $table = func_num_args() > 0 ? func_get_arg(0) : NULL; @@ -389,8 +518,10 @@ class CI_DB_pdo_driver extends CI_DB { { $sql='SELECT LASTVAL() as ins_id'; } + $query = $this->query($sql); - $row = $query->row(); + $row = $query->row(); + return $row->ins_id; } else @@ -418,7 +549,9 @@ class CI_DB_pdo_driver extends CI_DB { return 0; } - $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); + $sql = $this->_count_string.$this->_protect_identifiers('numrows').' FROM '; + $sql .= $this->_protect_identifiers($table, TRUE, NULL, FALSE); + $query = $this->query($sql); if ($query->num_rows() == 0) { @@ -427,6 +560,7 @@ class CI_DB_pdo_driver extends CI_DB { $row = $query->row(); $this->_reset_select(); + return (int) $row->numrows; } @@ -443,12 +577,19 @@ class CI_DB_pdo_driver extends CI_DB { */ function _list_tables($prefix_limit = FALSE) { - $sql = "SHOW TABLES FROM `".$this->database."`"; + if ($this->pdodriver == 'pgsql') + { + // Analog function to show all tables in postgre + $sql = "SELECT * FROM information_schema.tables WHERE table_schema = 'public'"; + } + else + { + $sql = "SHOW TABLES FROM `".$this->database."`"; + } 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 FALSE; } return $sql; @@ -467,7 +608,7 @@ class CI_DB_pdo_driver extends CI_DB { */ function _list_columns($table = '') { - return "SHOW COLUMNS FROM ".$table; + return 'SHOW COLUMNS FROM '.$this->_from_tables($table); } // -------------------------------------------------------------------- @@ -483,7 +624,7 @@ class CI_DB_pdo_driver extends CI_DB { */ function _field_data($table) { - return "SELECT TOP 1 FROM ".$table; + return 'SELECT TOP 1 FROM '.$this->_from_tables($table); } // -------------------------------------------------------------------- @@ -497,6 +638,7 @@ class CI_DB_pdo_driver extends CI_DB { function _error_message() { $error_array = $this->conn_id->errorInfo(); + return $error_array[2]; } @@ -544,8 +686,8 @@ class CI_DB_pdo_driver extends CI_DB { 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); + $str .= $this->_escape_char; } else { @@ -575,7 +717,7 @@ class CI_DB_pdo_driver extends CI_DB { $tables = array($tables); } - return (count($tables) == 1) ? $tables[0] : '('.implode(', ', $tables).')'; + return (count($tables) == 1) ? '`'.$tables[0].'`' : '('.implode(', ', $tables).')'; } // -------------------------------------------------------------------- @@ -593,7 +735,7 @@ class CI_DB_pdo_driver extends CI_DB { */ function _insert($table, $keys, $values) { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return 'INSERT INTO '.$this->_from_tables($table).' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')'; } // -------------------------------------------------------------------- @@ -611,7 +753,7 @@ class CI_DB_pdo_driver extends CI_DB { */ function _insert_batch($table, $keys, $values) { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values); + return 'INSERT INTO '.$this->_from_tables($table).' ('.implode(', ', $keys).') VALUES '.implode(', ', $values); } // -------------------------------------------------------------------- @@ -636,14 +778,11 @@ class CI_DB_pdo_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) : ''; + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; + $orderby = (count($orderby) >= 1) ? ' ORDER BY '.implode(', ', $orderby) : ''; + $sql = 'UPDATE '.$this->_from_tables($table).' SET '.implode(', ', $valstr); + $sql .= ($where != '' && count($where) >= 1) ? ' WHERE '.implode(' ', $where) : ''; $sql .= $orderby.$limit; return $sql; @@ -664,8 +803,8 @@ class CI_DB_pdo_driver extends CI_DB { */ function _update_batch($table, $values, $index, $where = NULL) { - $ids = array(); - $where = ($where != '' AND count($where) >=1) ? implode(" ", $where).' AND ' : ''; + $ids = array(); + $where = ($where != '' && count($where) >=1) ? implode(" ", $where).' AND ' : ''; foreach ($values as $key => $val) { @@ -680,12 +819,13 @@ class CI_DB_pdo_driver extends CI_DB { } } - $sql = "UPDATE ".$table." SET "; + $sql = 'UPDATE '.$this->_from_tables($table).' SET '; $cases = ''; foreach ($final as $k => $v) { $cases .= $k.' = CASE '."\n"; + foreach ($v as $row) { $cases .= $row."\n"; @@ -695,7 +835,6 @@ class CI_DB_pdo_driver extends CI_DB { } $sql .= substr($cases, 0, -2); - $sql .= ' WHERE '.$where.$index.' IN ('.implode(',', $ids).')'; return $sql; @@ -739,19 +878,20 @@ class CI_DB_pdo_driver extends CI_DB { if (count($where) > 0 OR count($like) > 0) { - $conditions = "\nWHERE "; + $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->_from_tables($table).$conditions.$limit; } // -------------------------------------------------------------------- @@ -769,27 +909,16 @@ class CI_DB_pdo_driver extends CI_DB { */ function _limit($sql, $limit, $offset) { - if (strpos($this->hostname, 'cubrid') !== FALSE || strpos($this->hostname, 'sqlite') !== FALSE) + if ($this->pdodriver == 'cubrid' OR $this->pdodriver == 'sqlite') { - if ($offset == 0) - { - $offset = ''; - } - else - { - $offset .= ", "; - } + $offset = ($offset == 0) ? '' : $offset.', '; - return $sql."LIMIT ".$offset.$limit; + return $sql.'LIMIT '.$offset.$limit; } else { - $sql .= "LIMIT ".$limit; - - if ($offset > 0) - { - $sql .= " OFFSET ".$offset; - } + $sql .= 'LIMIT '.$limit; + $sql .= ($offset > 0) ? ' OFFSET '.$offset : ''; return $sql; } @@ -809,10 +938,7 @@ class CI_DB_pdo_driver extends CI_DB { $this->conn_id = null; } - } - - /* End of file pdo_driver.php */ /* Location: ./system/database/drivers/pdo/pdo_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/pdo/pdo_forge.php b/system/database/drivers/pdo/pdo_forge.php index 076415928..478b2dbfb 100644 --- a/system/database/drivers/pdo/pdo_forge.php +++ b/system/database/drivers/pdo/pdo_forge.php @@ -96,7 +96,7 @@ class CI_DB_pdo_forge extends CI_DB_forge { $sql .= 'IF NOT EXISTS '; } - $sql .= $this->db->_escape_identifiers($table)." ("; + $sql .= '`'.$this->db->_escape_identifiers($table).'` ('; $current_field_count = 0; foreach ($fields as $field=>$attributes) @@ -111,6 +111,7 @@ class CI_DB_pdo_forge extends CI_DB_forge { else { $attributes = array_change_key_case($attributes, CASE_UPPER); + $numeric = array('SERIAL', 'INTEGER'); $sql .= "\n\t".$this->db->_protect_identifiers($field); @@ -118,7 +119,11 @@ class CI_DB_pdo_forge extends CI_DB_forge { if (array_key_exists('CONSTRAINT', $attributes)) { - $sql .= '('.$attributes['CONSTRAINT'].')'; + // Exception for Postgre numeric which not too happy with constraint within those type + if ( ! ($this->db->pdodriver == 'pgsql' && in_array($attributes['TYPE'], $numeric))) + { + $sql .= '('.$attributes['CONSTRAINT'].')'; + } } if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) @@ -219,7 +224,7 @@ class CI_DB_pdo_forge extends CI_DB_forge { */ 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); + $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') @@ -271,7 +276,6 @@ class CI_DB_pdo_forge extends CI_DB_forge { return $sql; } - } /* End of file pdo_forge.php */ diff --git a/system/database/drivers/pdo/pdo_result.php b/system/database/drivers/pdo/pdo_result.php index 6b523b001..c333abc40 100644 --- a/system/database/drivers/pdo/pdo_result.php +++ b/system/database/drivers/pdo/pdo_result.php @@ -38,6 +38,16 @@ */ class CI_DB_pdo_result extends CI_DB_result { + /** + * @var bool Hold the flag whether a result handler already fetched before + */ + protected $is_fetched = FALSE; + + /** + * @var mixed Hold the fetched assoc array of a result handler + */ + protected $result_assoc; + /** * Number of rows in the result set * @@ -46,7 +56,59 @@ class CI_DB_pdo_result extends CI_DB_result { */ function num_rows() { - return $this->result_id->rowCount(); + if (empty($this->result_id) OR ! is_object($this->result_id)) + { + // invalid result handler + return 0; + } + elseif (($num_rows = $this->result_id->rowCount()) && $num_rows > 0) + { + // If rowCount return something, we're done. + return $num_rows; + } + + // Fetch the result, instead perform another extra query + return ($this->is_fetched && is_array($this->result_assoc)) ? count($this->result_assoc) : count($this->result_assoc()); + } + + /** + * Fetch the result handler + * + * @access public + * @return mixed + */ + function result_assoc() + { + // If the result already fetched before, use that one + if (count($this->result_array) > 0 OR $this->is_fetched) + { + return $this->result_array(); + } + + // Define the output + $output = array('assoc', 'object'); + + // Fetch the result + foreach ($output as $type) + { + // Define the method and handler + $res_method = '_fetch_'.$type; + $res_handler = 'result_'.$type; + + $this->$res_handler = array(); + $this->_data_seek(0); + + while ($row = $this->$res_method()) + { + $this->{$res_handler}[] = $row; + } + } + + // Save this as buffer and marked the fetch flag + $this->result_array = $this->result_assoc; + $this->is_fetched = TRUE; + + return $this->result_assoc; } // -------------------------------------------------------------------- @@ -78,6 +140,7 @@ class CI_DB_pdo_result extends CI_DB_result { { return $this->db->display_error('db_unsuported_feature'); } + return FALSE; } @@ -110,6 +173,7 @@ class CI_DB_pdo_result extends CI_DB_result { { return $this->db->display_error('db_unsuported_feature'); } + return FALSE; } } @@ -178,6 +242,5 @@ class CI_DB_pdo_result extends CI_DB_result { } - /* End of file pdo_result.php */ /* Location: ./system/database/drivers/pdo/pdo_result.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 62b8cae55d69775f09e3d64a6d35420c30241f98 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 9 Feb 2012 16:40:39 +0700 Subject: Change PHP.net mirror to the main mirror --- system/database/drivers/pdo/pdo_driver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index e1602c4c5..46b5e543d 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -218,10 +218,10 @@ class CI_DB_pdo_driver extends CI_DB { */ function pdo_connect() { - // Refer : http://ch2.php.net/manual/en/ref.pdo-mysql.connection.php + // Refer : http://php.net/manual/en/ref.pdo-mysql.connection.php if ($this->pdodriver == 'mysql' && is_php('5.3.6')) { - $this->options[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES $this->char_set COLLATE '$this->dbcollat'"; + $this->options[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES $this->char_set COLLATE '.$this->dbcollat.'"; } // Connecting... -- cgit v1.2.3-24-g4f1b From 55bb97e6196f2d7f50a2d3f24968a94de3f64c87 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 9 Feb 2012 16:43:26 +0700 Subject: Typo --- system/database/drivers/pdo/pdo_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 46b5e543d..9973bc007 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -221,7 +221,7 @@ class CI_DB_pdo_driver extends CI_DB { // Refer : http://php.net/manual/en/ref.pdo-mysql.connection.php if ($this->pdodriver == 'mysql' && is_php('5.3.6')) { - $this->options[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES $this->char_set COLLATE '.$this->dbcollat.'"; + $this->options[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES $this->char_set COLLATE '$this->dbcollat'"; } // Connecting... -- cgit v1.2.3-24-g4f1b From fdd6ad088cd5c6f29974f23e1a2747c243ecb278 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 10 Feb 2012 13:10:27 +0700 Subject: Grammar correction --- system/database/drivers/pdo/pdo_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 9973bc007..fc378daeb 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -71,7 +71,7 @@ class CI_DB_pdo_driver extends CI_DB { if (preg_match('/([^;]+):/', $this->dsn, $match) && count($match) == 2) { // If there is a minimum valid dsn string pattern found, we're done - // This for general PDO users, who tend to have full DSN string. + // This is for general PDO users, who tend to have a full DSN string. $this->pdodriver = end($match); } else -- cgit v1.2.3-24-g4f1b From 1c175c8d9697d6e8163770c45643f97e557149e6 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 10 Feb 2012 08:37:45 -0500 Subject: Fixed old-style pdo connection string --- system/database/drivers/pdo/pdo_driver.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index fc378daeb..5e5c01ef9 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -117,7 +117,11 @@ class CI_DB_pdo_driver extends CI_DB { // $db['hostname'] = 'pdodriver:host(/Server(/DSN))=hostname(/DSN);'; // We need to get the prefix (pdodriver used by PDO). $this->dsn = $this->hostname; - $this->pdodriver = substr($this->hostname, 0, strpos($this->hostname, ':')); + $split_dsn = explode(":", $this->hostname); + $this->pdodriver = $split_dsn[0]; + + // End this part of the dsn with a semicolon + $this->dsn .= rtrim(';', $this->dsn) . ';'; } else { -- cgit v1.2.3-24-g4f1b From 7d7b304bd98b310957d5077048899ea6e908583a Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 10 Feb 2012 09:11:59 -0500 Subject: Changed double quotes to single --- system/database/drivers/pdo/pdo_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 5e5c01ef9..e84c1aaaf 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -117,7 +117,7 @@ class CI_DB_pdo_driver extends CI_DB { // $db['hostname'] = 'pdodriver:host(/Server(/DSN))=hostname(/DSN);'; // We need to get the prefix (pdodriver used by PDO). $this->dsn = $this->hostname; - $split_dsn = explode(":", $this->hostname); + $split_dsn = explode(':', $this->hostname); $this->pdodriver = $split_dsn[0]; // End this part of the dsn with a semicolon -- cgit v1.2.3-24-g4f1b From 9c2947a339f24e13aaf85f115bcea9f27fa10a83 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Mon, 13 Feb 2012 04:04:56 +0700 Subject: Fixed rtrim issue in hostname fragment, for backward compability --- system/database/drivers/pdo/pdo_driver.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index e84c1aaaf..2138ed665 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -117,11 +117,7 @@ class CI_DB_pdo_driver extends CI_DB { // $db['hostname'] = 'pdodriver:host(/Server(/DSN))=hostname(/DSN);'; // We need to get the prefix (pdodriver used by PDO). $this->dsn = $this->hostname; - $split_dsn = explode(':', $this->hostname); - $this->pdodriver = $split_dsn[0]; - - // End this part of the dsn with a semicolon - $this->dsn .= rtrim(';', $this->dsn) . ';'; + $this->pdodriver = current(explode(':', $this->hostname)); } else { @@ -179,6 +175,8 @@ class CI_DB_pdo_driver extends CI_DB { // Add charset to the DSN, if needed if ( ! empty($this->char_set) && in_array($this->pdodriver, array('4D', 'mysql', 'sybase', 'mssql', 'dblib', 'oci'))) { + // End dsn with a semicolon for extra backward compability + $this->dsn .= rtrim($this->dsn, ';').';'; $this->dsn .= 'charset='.$this->char_set.';'; } } -- cgit v1.2.3-24-g4f1b From 5dcdbc30649d8f8320953f3eb728a3eb5a7f7765 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Mon, 13 Feb 2012 21:15:56 +0700 Subject: Semicolon automatically added if not exists after hostname, if only database was not empty --- system/database/drivers/pdo/pdo_driver.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 2138ed665..5991586c7 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -118,6 +118,13 @@ class CI_DB_pdo_driver extends CI_DB { // We need to get the prefix (pdodriver used by PDO). $this->dsn = $this->hostname; $this->pdodriver = current(explode(':', $this->hostname)); + + // End dsn with a semicolon for extra backward compability + // if database property was not empty. + if ( ! empty($this->database)) + { + $this->dsn .= rtrim($this->dsn, ';').';'; + } } else { @@ -175,8 +182,6 @@ class CI_DB_pdo_driver extends CI_DB { // Add charset to the DSN, if needed if ( ! empty($this->char_set) && in_array($this->pdodriver, array('4D', 'mysql', 'sybase', 'mssql', 'dblib', 'oci'))) { - // End dsn with a semicolon for extra backward compability - $this->dsn .= rtrim($this->dsn, ';').';'; $this->dsn .= 'charset='.$this->char_set.';'; } } -- cgit v1.2.3-24-g4f1b From 928d83ce1590f14aadfa7a1805c00bb84bd9ef1c Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 13 Feb 2012 14:07:57 -0500 Subject: Refixed Old-style pdo connection string --- system/database/drivers/pdo/pdo_driver.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 5991586c7..c5940ddc8 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -116,15 +116,12 @@ class CI_DB_pdo_driver extends CI_DB { // hostname generally would have this prototype // $db['hostname'] = 'pdodriver:host(/Server(/DSN))=hostname(/DSN);'; // We need to get the prefix (pdodriver used by PDO). - $this->dsn = $this->hostname; - $this->pdodriver = current(explode(':', $this->hostname)); + $dsnarray = explode(':', $this->hostname); + $this->pdodriver = $dsnarray[0]; // End dsn with a semicolon for extra backward compability // if database property was not empty. - if ( ! empty($this->database)) - { - $this->dsn .= rtrim($this->dsn, ';').';'; - } + $this->dsn .= rtrim($this->hostname, ';').';'; } else { @@ -139,7 +136,9 @@ class CI_DB_pdo_driver extends CI_DB { $this->dsn = $this->pdodriver.':'; // Add hostname to the DSN for databases that need it - if ( ! empty($this->hostname) && in_array($this->pdodriver, array('informix', 'mysql', 'pgsql', 'sybase', 'mssql', 'dblib', 'cubrid'))) + if ( ! empty($this->hostname) + && strpos($this->hostname, ':') === FALSE + && in_array($this->pdodriver, array('informix', 'mysql', 'pgsql', 'sybase', 'mssql', 'dblib', 'cubrid'))) { $this->dsn .= 'host='.$this->hostname.';'; } -- cgit v1.2.3-24-g4f1b From 25dc75595dd3550a6c20f3d34d8f5259465b545f Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 13 Feb 2012 14:12:35 -0500 Subject: Re-added if ! empty clause --- system/database/drivers/pdo/pdo_driver.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index c5940ddc8..8516cc6fe 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -121,7 +121,10 @@ class CI_DB_pdo_driver extends CI_DB { // End dsn with a semicolon for extra backward compability // if database property was not empty. - $this->dsn .= rtrim($this->hostname, ';').';'; + if( ! empty($this->database)) + { + $this->dsn .= rtrim($this->hostname, ';').';'; + } } else { -- cgit v1.2.3-24-g4f1b From f4524694418b0203e93c6b0ca1a9f28a9c6e4ba7 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 13 Feb 2012 14:13:28 -0500 Subject: Added missing space --- system/database/drivers/pdo/pdo_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 8516cc6fe..de2b0abeb 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -121,7 +121,7 @@ class CI_DB_pdo_driver extends CI_DB { // End dsn with a semicolon for extra backward compability // if database property was not empty. - if( ! empty($this->database)) + if ( ! empty($this->database)) { $this->dsn .= rtrim($this->hostname, ';').';'; } -- cgit v1.2.3-24-g4f1b From 93cac5cc7bd1537788506d577c69852b4895a932 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 14 Feb 2012 14:45:02 +0200 Subject: Fix issue #1039 --- system/database/drivers/mysql/mysql_forge.php | 4 ++-- system/database/drivers/mysql/mysql_utility.php | 15 ++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index d3107134e..0f251b086 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_identifiers($table).' ('.$this->_process_fields($fields); + $sql .= $this->db->protect_identifiers($table).' ('.$this->_process_fields($fields); if (count($primary_keys) > 0) { @@ -187,7 +187,7 @@ class CI_DB_mysql_forge extends CI_DB_forge { */ public function _drop_table($table) { - return 'DROP TABLE IF EXISTS '.$this->db->_escape_identifiers($table); + return 'DROP TABLE IF EXISTS '.$this->db->protect_identifiers($table); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysql/mysql_utility.php b/system/database/drivers/mysql/mysql_utility.php index 0e7c18e16..538aaa0f7 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -56,7 +56,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { */ public function _optimize_table($table) { - return 'OPTIMIZE TABLE '.$this->db->_escape_identifiers($table); + return 'OPTIMIZE TABLE '.$this->db->protect_identifiers($table); } // -------------------------------------------------------------------- @@ -71,7 +71,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { */ public function _repair_table($table) { - return 'REPAIR TABLE '.$this->db->_escape_identifiers($table); + return 'REPAIR TABLE '.$this->db->protect_identifiers($table); } // -------------------------------------------------------------------- @@ -102,7 +102,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { } // Get the table schema - $query = $this->db->query('SHOW CREATE TABLE `'.$this->db->database.'`.`'.$table.'`'); + $query = $this->db->query('SHOW CREATE TABLE '.$this->db->protect_identifiers($this->db->database).'.'.$this->db->protect_identifiers($table)); // No result means the table name was invalid if ($query === FALSE) @@ -115,7 +115,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { if ($add_drop == TRUE) { - $output .= 'DROP TABLE IF EXISTS '.$table.';'.$newline.$newline; + $output .= 'DROP TABLE IF EXISTS '.($this->db->protect_identifiers($table).';'.$newline.$newline; } $i = 0; @@ -135,7 +135,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { } // Grab all the data from the current table - $query = $this->db->query('SELECT * FROM '.$table); + $query = $this->db->query('SELECT * FROM '.$this->db->protect_identifiers($table)); if ($query->num_rows() == 0) { @@ -157,7 +157,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { TRUE); // Create a string of field names - $field_str .= '`'.$field->name.'`, '; + $field_str .= $this->db->protect_identifiers($field->name).', '; $i++; } @@ -192,7 +192,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { $val_str = preg_replace('/, $/' , '', $val_str); // Build the INSERT string - $output .= 'INSERT INTO '.$table.' ('.$field_str.') VALUES ('.$val_str.');'.$newline; + $output .= 'INSERT INTO '.$this->db->protect_identifiers($table).' ('.$field_str.') VALUES ('.$val_str.');'.$newline; } return $output.$newline.$newline; @@ -200,6 +200,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { return $output; } + } /* End of file mysql_utility.php */ -- cgit v1.2.3-24-g4f1b From c51816da79d4b7a1c517142d7380234a9d8bae77 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 14 Feb 2012 16:55:42 +0200 Subject: Fix another issue --- 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 538aaa0f7..9d7cb679c 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -195,7 +195,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { $output .= 'INSERT INTO '.$this->db->protect_identifiers($table).' ('.$field_str.') VALUES ('.$val_str.');'.$newline; } - return $output.$newline.$newline; + $output .= $newline.$newline; } return $output; -- cgit v1.2.3-24-g4f1b From 76e0435af10579afdc3ed4956aeafa83a17decd3 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 14 Feb 2012 11:55:17 -0500 Subject: First iteration of interbase driver --- system/database/drivers/interbase/index.html | 10 + .../drivers/interbase/interbase_driver.php | 676 +++++++++++++++++++++ .../database/drivers/interbase/interbase_forge.php | 262 ++++++++ .../drivers/interbase/interbase_result.php | 190 ++++++ .../drivers/interbase/interbase_utility.php | 108 ++++ 5 files changed, 1246 insertions(+) create mode 100644 system/database/drivers/interbase/index.html create mode 100644 system/database/drivers/interbase/interbase_driver.php create mode 100644 system/database/drivers/interbase/interbase_forge.php create mode 100644 system/database/drivers/interbase/interbase_result.php create mode 100644 system/database/drivers/interbase/interbase_utility.php (limited to 'system/database') diff --git a/system/database/drivers/interbase/index.html b/system/database/drivers/interbase/index.html new file mode 100644 index 000000000..c942a79ce --- /dev/null +++ b/system/database/drivers/interbase/index.html @@ -0,0 +1,10 @@ + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + \ No newline at end of file diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php new file mode 100644 index 000000000..bc9cb8f08 --- /dev/null +++ b/system/database/drivers/interbase/interbase_driver.php @@ -0,0 +1,676 @@ +database, $this->username, $this->password, $this->charset)) + { + 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 = @ibase_pconnect($this->database, $this->username, $this->password, $this->charset)) + { + log_message('error', $error); + + if ($this->db_debug) + { + $this->display_error($error, '', TRUE); + } + + return FALSE; + } + + return $conn_id; + } + + // -------------------------------------------------------------------- + + /** + * 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 Interbase/Firebird + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + // Connection selects the database + 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() + { + //@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 @ibase_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->trans = @ibase_trans($this->conn_id); + + 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; + } + + @ibase_commit($this->trans); + + 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; + } + + @ibase_rollback($this->trans); + + 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 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 @ibase_affected_rows($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + //@todo Implement manually + 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($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(); + $this->_reset_select(); + 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 = <<dbprefix != '') + { + $sql .= " AND 'name' LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); + } + 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 ibase_errmsg(); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access private + * @return integer + */ + function _error_number() + { + return ibase_errcode(); + } + + // -------------------------------------------------------------------- + + /** + * Escape the SQL Identifiers + * + * This function escapes column and table names + * + * @access private + * @param string + * @return string + */ + function _escape_identifiers($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) + { + @ibase_close($conn_id); + } + + +} + + +/* End of file interbase_driver.php */ +/* Location: ./system/database/drivers/interbase/interbase_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/interbase/interbase_forge.php b/system/database/drivers/interbase/interbase_forge.php new file mode 100644 index 000000000..36d980b67 --- /dev/null +++ b/system/database/drivers/interbase/interbase_forge.php @@ -0,0 +1,262 @@ +conn_id); + } + // -------------------------------------------------------------------- + + /** + * 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 '; + + $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 + * + * @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 interbase_forge.php */ +/* Location: ./system/database/drivers/interbase/interbase_forge.php */ \ No newline at end of file diff --git a/system/database/drivers/interbase/interbase_result.php b/system/database/drivers/interbase/interbase_result.php new file mode 100644 index 000000000..d811fc608 --- /dev/null +++ b/system/database/drivers/interbase/interbase_result.php @@ -0,0 +1,190 @@ +result_id)) + { + $count++; + } + + return $count; + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @ibase_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++) + { + $info = ibase_field_info($this->result_id, $i); + $field_names[] = $info['name']; + } + + 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++) + { + $info = ibase_field_info($this->result_id, $i); + + $F = new stdClass(); + $F->name = $info['name']; + $F->type = $info['type']; + $F->max_length = $info['length']; + $F->primary_key = 0; + $F->default = ''; + + $retval[] = $F; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return null + */ + function free_result() + { + @ibase_free_result($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * 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) + { + //Interbase driver doesn't implement a sutable function + return array(); + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @access private + * @return array + */ + function _fetch_assoc() + { + return @ibase_fetch_assoc($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + function _fetch_object() + { + return @ibase_fetch_object($this->result_id); + } + +} + + +/* End of file interbase_result.php */ +/* Location: ./system/database/drivers/interbase/interbase_result.php */ \ No newline at end of file diff --git a/system/database/drivers/interbase/interbase_utility.php b/system/database/drivers/interbase/interbase_utility.php new file mode 100644 index 000000000..533a269b2 --- /dev/null +++ b/system/database/drivers/interbase/interbase_utility.php @@ -0,0 +1,108 @@ +db_debug) + { + return $this->db->display_error('db_unsuported_feature'); + } + return array(); + } + + // -------------------------------------------------------------------- + + /** + * Optimize table query + * + * Is optimization even supported in Interbase/Firebird? + * + * @access private + * @param string the table name + * @return object + */ + function _optimize_table($table) + { + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Repair table query + * + * Table repairs are not supported in Interbase/Firebird + * + * @access private + * @param string the table name + * @return object + */ + function _repair_table($table) + { + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Interbase/Firebird Export + * + * @access private + * @param array Preferences + * @return mixed + */ + function _backup($params = array()) + { + // Currently unsupported + return $this->db->display_error('db_unsuported_feature'); + } +} + +/* End of file interbase_utility.php */ +/* Location: ./system/database/drivers/interbase/interbase_utility.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 4be822bcca94273967abf010ef67f64ead5e6bf2 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 14 Feb 2012 12:07:34 -0500 Subject: Added public declarations --- .../drivers/interbase/interbase_driver.php | 62 +++++++++++----------- .../database/drivers/interbase/interbase_forge.php | 12 ++--- .../drivers/interbase/interbase_result.php | 16 +++--- .../drivers/interbase/interbase_utility.php | 8 +-- 4 files changed, 49 insertions(+), 49 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php index bc9cb8f08..671b128ea 100644 --- a/system/database/drivers/interbase/interbase_driver.php +++ b/system/database/drivers/interbase/interbase_driver.php @@ -70,7 +70,7 @@ class CI_DB_interbase_driver extends CI_DB { * @access private called by the base class * @return resource */ - function db_connect() + public function db_connect() { if ( ! $conn_id = @ibase_connect($this->database, $this->username, $this->password, $this->charset)) { @@ -95,7 +95,7 @@ class CI_DB_interbase_driver extends CI_DB { * @access private called by the base class * @return resource */ - function db_pconnect() + public function db_pconnect() { if ( ! $conn_id = @ibase_pconnect($this->database, $this->username, $this->password, $this->charset)) { @@ -123,7 +123,7 @@ class CI_DB_interbase_driver extends CI_DB { * @access public * @return void */ - function reconnect() + public function reconnect() { // not implemented in Interbase/Firebird } @@ -136,7 +136,7 @@ class CI_DB_interbase_driver extends CI_DB { * @access private called by the base class * @return resource */ - function db_select() + public function db_select() { // Connection selects the database return TRUE; @@ -152,7 +152,7 @@ class CI_DB_interbase_driver extends CI_DB { * @param string * @return resource */ - function db_set_charset($charset, $collation) + public function db_set_charset($charset, $collation) { // @todo - add support if needed return TRUE; @@ -166,7 +166,7 @@ class CI_DB_interbase_driver extends CI_DB { * @access public * @return string */ - function _version() + public function _version() { //@todo - add support if needed return TRUE; @@ -181,7 +181,7 @@ class CI_DB_interbase_driver extends CI_DB { * @param string an SQL query * @return resource */ - function _execute($sql) + public function _execute($sql) { $sql = $this->_prep_query($sql); return @ibase_query($this->conn_id, $sql); @@ -198,7 +198,7 @@ class CI_DB_interbase_driver extends CI_DB { * @param string an SQL query * @return string */ - function _prep_query($sql) + public function _prep_query($sql) { return $sql; } @@ -211,7 +211,7 @@ class CI_DB_interbase_driver extends CI_DB { * @access public * @return bool */ - function trans_begin($test_mode = FALSE) + public function trans_begin($test_mode = FALSE) { if ( ! $this->trans_enabled) { @@ -242,7 +242,7 @@ class CI_DB_interbase_driver extends CI_DB { * @access public * @return bool */ - function trans_commit() + public function trans_commit() { if ( ! $this->trans_enabled) { @@ -268,7 +268,7 @@ class CI_DB_interbase_driver extends CI_DB { * @access public * @return bool */ - function trans_rollback() + public function trans_rollback() { if ( ! $this->trans_enabled) { @@ -296,7 +296,7 @@ class CI_DB_interbase_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) + public function escape_str($str, $like = FALSE) { if (is_array($str)) { @@ -327,7 +327,7 @@ class CI_DB_interbase_driver extends CI_DB { * @access public * @return integer */ - function affected_rows() + public function affected_rows() { return @ibase_affected_rows($this->conn_id); } @@ -340,7 +340,7 @@ class CI_DB_interbase_driver extends CI_DB { * @access public * @return integer */ - function insert_id() + public function insert_id() { //@todo Implement manually return 0; @@ -358,7 +358,7 @@ class CI_DB_interbase_driver extends CI_DB { * @param string * @return string */ - function count_all($table = '') + public function count_all($table = '') { if ($table == '') { @@ -388,7 +388,7 @@ class CI_DB_interbase_driver extends CI_DB { * @param boolean * @return string */ - function _list_tables($prefix_limit = FALSE) + public function _list_tables($prefix_limit = FALSE) { $sql = <<_reserved_identifiers as $id) { @@ -504,14 +504,14 @@ SQL; /** * From Tables * - * This function implicitly groups FROM tables so there is no confusion + * This public 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) + public function _from_tables($tables) { if ( ! is_array($tables)) { @@ -534,7 +534,7 @@ SQL; * @param array the insert values * @return string */ - function _insert($table, $keys, $values) + public function _insert($table, $keys, $values) { return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } @@ -554,7 +554,7 @@ SQL; * @param array the limit clause * @return string */ - function _update($table, $values, $where, $orderby = array(), $limit = FALSE) + public function _update($table, $values, $where, $orderby = array(), $limit = FALSE) { foreach ($values as $key => $val) { @@ -582,13 +582,13 @@ SQL; * * 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" + * This public function maps to "DELETE FROM table" * * @access public * @param string the table name * @return string */ - function _truncate($table) + public function _truncate($table) { return $this->_delete($table); } @@ -606,7 +606,7 @@ SQL; * @param string the limit clause * @return string */ - function _delete($table, $where = array(), $like = array(), $limit = FALSE) + public function _delete($table, $where = array(), $like = array(), $limit = FALSE) { $conditions = ''; @@ -640,7 +640,7 @@ SQL; * @param integer the offset value * @return string */ - function _limit($sql, $limit, $offset) + public function _limit($sql, $limit, $offset) { if ($offset == 0) { @@ -663,7 +663,7 @@ SQL; * @param resource * @return void */ - function _close($conn_id) + public function _close($conn_id) { @ibase_close($conn_id); } diff --git a/system/database/drivers/interbase/interbase_forge.php b/system/database/drivers/interbase/interbase_forge.php index 36d980b67..815107d85 100644 --- a/system/database/drivers/interbase/interbase_forge.php +++ b/system/database/drivers/interbase/interbase_forge.php @@ -43,7 +43,7 @@ class CI_DB_interbase_forge extends CI_DB_forge { * @param string the database name * @return bool */ - function _create_database() + public function _create_database() { // In Interbase/Firebird, a database is created when you connect to the database. // We'll return TRUE so that an error isn't generated @@ -60,7 +60,7 @@ class CI_DB_interbase_forge extends CI_DB_forge { * - the current db is dropped * @return bool */ - function _drop_database($name='') + public function _drop_database($name='') { return ibase_drop_db($this->conn_id); } @@ -77,7 +77,7 @@ class CI_DB_interbase_forge extends CI_DB_forge { * @param boolean should 'IF NOT EXISTS' be added to the SQL * @return bool */ - function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) + public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) { $sql = 'CREATE TABLE '; @@ -174,7 +174,7 @@ class CI_DB_interbase_forge extends CI_DB_forge { * @access private * @return bool */ - function _drop_table($table) + public function _drop_table($table) { if ($this->db->db_debug) { @@ -201,7 +201,7 @@ class CI_DB_interbase_forge extends CI_DB_forge { * @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 = '') + public 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); @@ -251,7 +251,7 @@ class CI_DB_interbase_forge extends CI_DB_forge { * @param string the new table name * @return string */ - function _rename_table($table_name, $new_table_name) + public 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/interbase/interbase_result.php b/system/database/drivers/interbase/interbase_result.php index d811fc608..9d827895d 100644 --- a/system/database/drivers/interbase/interbase_result.php +++ b/system/database/drivers/interbase/interbase_result.php @@ -44,7 +44,7 @@ class CI_DB_interbase_result extends CI_DB_result { * @access public * @return integer */ - function num_rows() + public function num_rows() { //Will have to manually calculate :( $count = 0; @@ -65,7 +65,7 @@ class CI_DB_interbase_result extends CI_DB_result { * @access public * @return integer */ - function num_fields() + public function num_fields() { return @ibase_num_fields($this->result_id); } @@ -80,7 +80,7 @@ class CI_DB_interbase_result extends CI_DB_result { * @access public * @return array */ - function list_fields() + public function list_fields() { $field_names = array(); for ($i = 0; $i < $this->num_fields(); $i++) @@ -102,7 +102,7 @@ class CI_DB_interbase_result extends CI_DB_result { * @access public * @return array */ - function field_data() + public function field_data() { $retval = array(); @@ -130,7 +130,7 @@ class CI_DB_interbase_result extends CI_DB_result { * * @return null */ - function free_result() + public function free_result() { @ibase_free_result($this->result_id); } @@ -147,7 +147,7 @@ class CI_DB_interbase_result extends CI_DB_result { * @access private * @return array */ - function _data_seek($n = 0) + public function _data_seek($n = 0) { //Interbase driver doesn't implement a sutable function return array(); @@ -163,7 +163,7 @@ class CI_DB_interbase_result extends CI_DB_result { * @access private * @return array */ - function _fetch_assoc() + public function _fetch_assoc() { return @ibase_fetch_assoc($this->result_id); } @@ -178,7 +178,7 @@ class CI_DB_interbase_result extends CI_DB_result { * @access private * @return object */ - function _fetch_object() + public function _fetch_object() { return @ibase_fetch_object($this->result_id); } diff --git a/system/database/drivers/interbase/interbase_utility.php b/system/database/drivers/interbase/interbase_utility.php index 533a269b2..d90ecae71 100644 --- a/system/database/drivers/interbase/interbase_utility.php +++ b/system/database/drivers/interbase/interbase_utility.php @@ -47,7 +47,7 @@ class CI_DB_interbase_utility extends CI_DB_utility { * @access private * @return bool */ - function _list_databases() + public function _list_databases() { if ($this->db_debug) { @@ -67,7 +67,7 @@ class CI_DB_interbase_utility extends CI_DB_utility { * @param string the table name * @return object */ - function _optimize_table($table) + public function _optimize_table($table) { return FALSE; } @@ -83,7 +83,7 @@ class CI_DB_interbase_utility extends CI_DB_utility { * @param string the table name * @return object */ - function _repair_table($table) + public function _repair_table($table) { return FALSE; } @@ -97,7 +97,7 @@ class CI_DB_interbase_utility extends CI_DB_utility { * @param array Preferences * @return mixed */ - function _backup($params = array()) + public function _backup($params = array()) { // Currently unsupported return $this->db->display_error('db_unsuported_feature'); -- cgit v1.2.3-24-g4f1b From 2d6ae793daf6eafe72c33f2bc39e18a22f699264 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 14 Feb 2012 15:00:52 -0500 Subject: Various fixes --- .../drivers/interbase/interbase_driver.php | 226 +++++++++++---------- 1 file changed, 115 insertions(+), 111 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php index 671b128ea..ff9f2d5bf 100644 --- a/system/database/drivers/interbase/interbase_driver.php +++ b/system/database/drivers/interbase/interbase_driver.php @@ -14,15 +14,15 @@ * http://opensource.org/licenses/OSL-3.0 * If you did not receive a copy of the license and are unable to obtain it * through the world wide web, please send an email to - * licensing@ellislab.com so we can send you a copy immediately. + * licensingellislab.com so we can send you a copy immediately. * - * @package CodeIgniter - * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) - * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) - * @link http://codeigniter.com - * @since Version 3.0 - * @filesource + * package CodeIgniter + * author EllisLab Dev Team + * copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) + * license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) + * link http://codeigniter.com + * since Version 3.0 + * filesource */ // ------------------------------------------------------------------------ @@ -36,11 +36,11 @@ * creates dynamically based on whether the active record * class is being used or not. * - * @package CodeIgniter - * @subpackage Drivers - * @category Database - * @author EllisLab Dev Team - * @link http://codeigniter.com/user_guide/database/ + * package CodeIgniter + * subpackage Drivers + * category Database + * author EllisLab Dev Team + * link http://codeigniter.com/user_guide/database/ */ class CI_DB_interbase_driver extends CI_DB { @@ -67,12 +67,12 @@ class CI_DB_interbase_driver extends CI_DB { /** * Non-persistent database connection * - * @access private called by the base class - * @return resource + * access private called by the base class + * return resource */ public function db_connect() { - if ( ! $conn_id = @ibase_connect($this->database, $this->username, $this->password, $this->charset)) + if ( ! $conn_id = ibase_connect($this->database, $this->username, $this->password, $this->char_set)) { log_message('error', $error); @@ -92,12 +92,12 @@ class CI_DB_interbase_driver extends CI_DB { /** * Persistent database connection * - * @access private called by the base class - * @return resource + * access private called by the base class + * return resource */ public function db_pconnect() { - if ( ! $conn_id = @ibase_pconnect($this->database, $this->username, $this->password, $this->charset)) + if ( ! $conn_id = ibase_pconnect($this->database, $this->username, $this->password, $this->char_set)) { log_message('error', $error); @@ -120,8 +120,8 @@ class CI_DB_interbase_driver extends CI_DB { * 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 + * access public + * return void */ public function reconnect() { @@ -133,8 +133,8 @@ class CI_DB_interbase_driver extends CI_DB { /** * Select the database * - * @access private called by the base class - * @return resource + * access private called by the base class + * return resource */ public function db_select() { @@ -147,14 +147,14 @@ class CI_DB_interbase_driver extends CI_DB { /** * Set client character set * - * @access public - * @param string - * @param string - * @return resource + * access public + * param string + * param string + * return resource */ public function db_set_charset($charset, $collation) { - // @todo - add support if needed + // todo - add support if needed return TRUE; } @@ -163,12 +163,12 @@ class CI_DB_interbase_driver extends CI_DB { /** * Version number query string * - * @access public - * @return string + * access public + * return string */ public function _version() { - //@todo - add support if needed + //todo - add support if needed return TRUE; } @@ -177,14 +177,14 @@ class CI_DB_interbase_driver extends CI_DB { /** * Execute the query * - * @access private called by the base class - * @param string an SQL query - * @return resource + * access private called by the base class + * param string an SQL query + * return resource */ public function _execute($sql) { $sql = $this->_prep_query($sql); - return @ibase_query($this->conn_id, $sql); + return ibase_query($this->conn_id, $sql); } // -------------------------------------------------------------------- @@ -194,9 +194,9 @@ class CI_DB_interbase_driver extends CI_DB { * * If needed, each database adapter can prep the query string * - * @access private called by execute() - * @param string an SQL query - * @return string + * access private called by execute() + * param string an SQL query + * return string */ public function _prep_query($sql) { @@ -208,8 +208,8 @@ class CI_DB_interbase_driver extends CI_DB { /** * Begin Transaction * - * @access public - * @return bool + * access public + * return bool */ public function trans_begin($test_mode = FALSE) { @@ -229,7 +229,7 @@ class CI_DB_interbase_driver extends CI_DB { // even if the queries produce a successful result. $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; - $this->trans = @ibase_trans($this->conn_id); + $this->trans = ibase_trans($this->conn_id); return TRUE; } @@ -239,8 +239,8 @@ class CI_DB_interbase_driver extends CI_DB { /** * Commit Transaction * - * @access public - * @return bool + * access public + * return bool */ public function trans_commit() { @@ -255,7 +255,7 @@ class CI_DB_interbase_driver extends CI_DB { return TRUE; } - @ibase_commit($this->trans); + ibase_commit($this->trans); return TRUE; } @@ -265,8 +265,8 @@ class CI_DB_interbase_driver extends CI_DB { /** * Rollback Transaction * - * @access public - * @return bool + * access public + * return bool */ public function trans_rollback() { @@ -281,7 +281,7 @@ class CI_DB_interbase_driver extends CI_DB { return TRUE; } - @ibase_rollback($this->trans); + ibase_rollback($this->trans); return TRUE; } @@ -291,10 +291,10 @@ class CI_DB_interbase_driver extends CI_DB { /** * Escape String * - * @access public - * @param string - * @param bool whether or not the string will be used in a LIKE condition - * @return string + * access public + * param string + * param bool whether or not the string will be used in a LIKE condition + * return string */ public function escape_str($str, $like = FALSE) { @@ -324,12 +324,12 @@ class CI_DB_interbase_driver extends CI_DB { /** * Affected Rows * - * @access public - * @return integer + * access public + * return integer */ public function affected_rows() { - return @ibase_affected_rows($this->conn_id); + return ibase_affected_rows($this->conn_id); } // -------------------------------------------------------------------- @@ -337,12 +337,12 @@ class CI_DB_interbase_driver extends CI_DB { /** * Insert ID * - * @access public - * @return integer + * access public + * return integer */ public function insert_id() { - //@todo Implement manually + //todo Implement manually return 0; } @@ -354,9 +354,9 @@ class CI_DB_interbase_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 */ public function count_all($table = '') { @@ -384,9 +384,9 @@ class CI_DB_interbase_driver extends CI_DB { * * Generates a platform-specific query string so that the table names can be fetched * - * @access private - * @param boolean - * @return string + * access private + * param boolean + * return string */ public function _list_tables($prefix_limit = FALSE) { @@ -410,9 +410,9 @@ SQL; * * 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 */ public function _list_columns($table = '') { @@ -427,9 +427,9 @@ SQL; * * 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 */ public function _field_data($table) { @@ -441,8 +441,8 @@ SQL; /** * The error message string * - * @access private - * @return string + * access private + * return string */ public function _error_message() { @@ -454,8 +454,8 @@ SQL; /** * The error message number * - * @access private - * @return integer + * access private + * return integer */ public function _error_number() { @@ -469,9 +469,9 @@ SQL; * * This public function escapes column and table names * - * @access private - * @param string - * @return string + * access private + * param string + * return string */ public function _escape_identifiers($item) { @@ -496,7 +496,7 @@ SQL; } // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); + return strtoupper(preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str)); } // -------------------------------------------------------------------- @@ -507,9 +507,9 @@ SQL; * This public function implicitly groups FROM tables so there is no confusion * about operator precedence in harmony with SQL standards * - * @access public - * @param type - * @return type + * access public + * param type + * return type */ public function _from_tables($tables) { @@ -518,7 +518,7 @@ SQL; $tables = array($tables); } - return '('.implode(', ', $tables).')'; + return strtolower(implode(', ', $tables)); } // -------------------------------------------------------------------- @@ -528,15 +528,15 @@ SQL; * * 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 */ public function _insert($table, $keys, $values) { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return "INSERT INTO ".strtolower($table)." (".strtoupper(implode(', ', $keys)).") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -546,16 +546,18 @@ SQL; * * 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 + * 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 */ public function _update($table, $values, $where, $orderby = array(), $limit = FALSE) { + $table = strtolower($table); + foreach ($values as $key => $val) { $valstr[] = $key." = ".$val; @@ -584,9 +586,9 @@ SQL; * If the database does not support the truncate() command * This public function maps to "DELETE FROM table" * - * @access public - * @param string the table name - * @return string + * access public + * param string the table name + * return string */ public function _truncate($table) { @@ -600,14 +602,16 @@ SQL; * * 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 + * access public + * param string the table name + * param array the where clause + * param string the limit clause + * return string */ public function _delete($table, $where = array(), $like = array(), $limit = FALSE) { + $table = strtolower($table); + $conditions = ''; if (count($where) > 0 OR count($like) > 0) @@ -634,11 +638,11 @@ SQL; * * 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 */ public function _limit($sql, $limit, $offset) { @@ -659,13 +663,13 @@ SQL; /** * Close DB Connection * - * @access public - * @param resource - * @return void + * access public + * param resource + * return void */ public function _close($conn_id) { - @ibase_close($conn_id); + ibase_close($conn_id); } -- cgit v1.2.3-24-g4f1b From 7221f9455b3ffe89474d1728583b656c176b5ba4 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 14 Feb 2012 15:02:33 -0500 Subject: Restored '@' characters --- .../drivers/interbase/interbase_driver.php | 218 ++++++++++----------- 1 file changed, 108 insertions(+), 110 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php index ff9f2d5bf..525294db4 100644 --- a/system/database/drivers/interbase/interbase_driver.php +++ b/system/database/drivers/interbase/interbase_driver.php @@ -14,15 +14,15 @@ * http://opensource.org/licenses/OSL-3.0 * If you did not receive a copy of the license and are unable to obtain it * through the world wide web, please send an email to - * licensingellislab.com so we can send you a copy immediately. + * licensing@ellislab.com so we can send you a copy immediately. * - * package CodeIgniter - * author EllisLab Dev Team - * copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) - * license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) - * link http://codeigniter.com - * since Version 3.0 - * filesource + * @package CodeIgniter + * @author EllisLab Dev Team + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) + * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) + * @link http://codeigniter.com + * @since Version 3.0 + * @filesource */ // ------------------------------------------------------------------------ @@ -36,11 +36,11 @@ * creates dynamically based on whether the active record * class is being used or not. * - * package CodeIgniter - * subpackage Drivers - * category Database - * author EllisLab Dev Team - * link http://codeigniter.com/user_guide/database/ + * @package CodeIgniter + * @subpackage Drivers + * @category Database + * @author EllisLab Dev Team + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_interbase_driver extends CI_DB { @@ -67,12 +67,12 @@ class CI_DB_interbase_driver extends CI_DB { /** * Non-persistent database connection * - * access private called by the base class - * return resource + * @access private called by the base class + * @return resource */ public function db_connect() { - if ( ! $conn_id = ibase_connect($this->database, $this->username, $this->password, $this->char_set)) + if ( ! $conn_id = @ibase_connect($this->database, $this->username, $this->password, $this->char_set)) { log_message('error', $error); @@ -92,12 +92,12 @@ class CI_DB_interbase_driver extends CI_DB { /** * Persistent database connection * - * access private called by the base class - * return resource + * @access private called by the base class + * @return resource */ public function db_pconnect() { - if ( ! $conn_id = ibase_pconnect($this->database, $this->username, $this->password, $this->char_set)) + if ( ! $conn_id = @ibase_pconnect($this->database, $this->username, $this->password, $this->char_set)) { log_message('error', $error); @@ -120,8 +120,8 @@ class CI_DB_interbase_driver extends CI_DB { * 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 + * @access public + * @return void */ public function reconnect() { @@ -133,8 +133,8 @@ class CI_DB_interbase_driver extends CI_DB { /** * Select the database * - * access private called by the base class - * return resource + * @access private called by the base class + * @return resource */ public function db_select() { @@ -147,14 +147,14 @@ class CI_DB_interbase_driver extends CI_DB { /** * Set client character set * - * access public - * param string - * param string - * return resource + * @access public + * @param string + * @param string + * @return resource */ public function db_set_charset($charset, $collation) { - // todo - add support if needed + // @todo - add support if needed return TRUE; } @@ -163,12 +163,12 @@ class CI_DB_interbase_driver extends CI_DB { /** * Version number query string * - * access public - * return string + * @access public + * @return string */ public function _version() { - //todo - add support if needed + //@todo - add support if needed return TRUE; } @@ -177,14 +177,14 @@ class CI_DB_interbase_driver extends CI_DB { /** * Execute the query * - * access private called by the base class - * param string an SQL query - * return resource + * @access private called by the base class + * @param string an SQL query + * @return resource */ public function _execute($sql) { $sql = $this->_prep_query($sql); - return ibase_query($this->conn_id, $sql); + return @ibase_query($this->conn_id, $sql); } // -------------------------------------------------------------------- @@ -194,9 +194,9 @@ class CI_DB_interbase_driver extends CI_DB { * * If needed, each database adapter can prep the query string * - * access private called by execute() - * param string an SQL query - * return string + * @access private called by execute() + * @param string an SQL query + * @return string */ public function _prep_query($sql) { @@ -208,8 +208,8 @@ class CI_DB_interbase_driver extends CI_DB { /** * Begin Transaction * - * access public - * return bool + * @access public + * @return bool */ public function trans_begin($test_mode = FALSE) { @@ -229,7 +229,7 @@ class CI_DB_interbase_driver extends CI_DB { // even if the queries produce a successful result. $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; - $this->trans = ibase_trans($this->conn_id); + $this->trans = @ibase_trans($this->conn_id); return TRUE; } @@ -239,8 +239,8 @@ class CI_DB_interbase_driver extends CI_DB { /** * Commit Transaction * - * access public - * return bool + * @access public + * @return bool */ public function trans_commit() { @@ -255,7 +255,7 @@ class CI_DB_interbase_driver extends CI_DB { return TRUE; } - ibase_commit($this->trans); + @ibase_commit($this->trans); return TRUE; } @@ -265,8 +265,8 @@ class CI_DB_interbase_driver extends CI_DB { /** * Rollback Transaction * - * access public - * return bool + * @access public + * @return bool */ public function trans_rollback() { @@ -281,7 +281,7 @@ class CI_DB_interbase_driver extends CI_DB { return TRUE; } - ibase_rollback($this->trans); + @ibase_rollback($this->trans); return TRUE; } @@ -291,10 +291,10 @@ class CI_DB_interbase_driver extends CI_DB { /** * Escape String * - * access public - * param string - * param bool whether or not the string will be used in a LIKE condition - * return string + * @access public + * @param string + * @param bool whether or not the string will be used in a LIKE condition + * @return string */ public function escape_str($str, $like = FALSE) { @@ -324,12 +324,12 @@ class CI_DB_interbase_driver extends CI_DB { /** * Affected Rows * - * access public - * return integer + * @access public + * @return integer */ public function affected_rows() { - return ibase_affected_rows($this->conn_id); + return @ibase_affected_rows($this->conn_id); } // -------------------------------------------------------------------- @@ -337,12 +337,12 @@ class CI_DB_interbase_driver extends CI_DB { /** * Insert ID * - * access public - * return integer + * @access public + * @return integer */ public function insert_id() { - //todo Implement manually + //@todo Implement manually return 0; } @@ -354,9 +354,9 @@ class CI_DB_interbase_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 */ public function count_all($table = '') { @@ -384,9 +384,9 @@ class CI_DB_interbase_driver extends CI_DB { * * Generates a platform-specific query string so that the table names can be fetched * - * access private - * param boolean - * return string + * @access private + * @param boolean + * @return string */ public function _list_tables($prefix_limit = FALSE) { @@ -410,9 +410,9 @@ SQL; * * 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 */ public function _list_columns($table = '') { @@ -427,9 +427,9 @@ SQL; * * 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 */ public function _field_data($table) { @@ -441,8 +441,8 @@ SQL; /** * The error message string * - * access private - * return string + * @access private + * @return string */ public function _error_message() { @@ -454,8 +454,8 @@ SQL; /** * The error message number * - * access private - * return integer + * @access private + * @return integer */ public function _error_number() { @@ -469,9 +469,9 @@ SQL; * * This public function escapes column and table names * - * access private - * param string - * return string + * @access private + * @param string + * @return string */ public function _escape_identifiers($item) { @@ -507,9 +507,9 @@ SQL; * This public function implicitly groups FROM tables so there is no confusion * about operator precedence in harmony with SQL standards * - * access public - * param type - * return type + * @access public + * @param type + * @return type */ public function _from_tables($tables) { @@ -528,11 +528,11 @@ SQL; * * 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 */ public function _insert($table, $keys, $values) { @@ -546,13 +546,13 @@ SQL; * * 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 + * @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 */ public function _update($table, $values, $where, $orderby = array(), $limit = FALSE) { @@ -586,9 +586,9 @@ SQL; * If the database does not support the truncate() command * This public function maps to "DELETE FROM table" * - * access public - * param string the table name - * return string + * @access public + * @param string the table name + * @return string */ public function _truncate($table) { @@ -602,11 +602,11 @@ SQL; * * 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 + * @access public + * @param string the table name + * @param array the where clause + * @param string the limit clause + * @return string */ public function _delete($table, $where = array(), $like = array(), $limit = FALSE) { @@ -638,11 +638,11 @@ SQL; * * 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 */ public function _limit($sql, $limit, $offset) { @@ -663,16 +663,14 @@ SQL; /** * Close DB Connection * - * access public - * param resource - * return void + * @access public + * @param resource + * @return void */ public function _close($conn_id) { - ibase_close($conn_id); + @ibase_close($conn_id); } - - } -- cgit v1.2.3-24-g4f1b From d19e47a3152c0a3e6a9aa13261b4c843c946523b Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 14 Feb 2012 23:40:40 -0500 Subject: Removed string case manipulation functions --- system/database/drivers/interbase/interbase_driver.php | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php index 525294db4..6f889d91e 100644 --- a/system/database/drivers/interbase/interbase_driver.php +++ b/system/database/drivers/interbase/interbase_driver.php @@ -74,11 +74,11 @@ class CI_DB_interbase_driver extends CI_DB { { if ( ! $conn_id = @ibase_connect($this->database, $this->username, $this->password, $this->char_set)) { - log_message('error', $error); + log_message('error', $this->_error_message()); if ($this->db_debug) { - $this->display_error($error, '', TRUE); + $this->display_error($this->_error_message(), '', TRUE); } return FALSE; @@ -99,11 +99,11 @@ class CI_DB_interbase_driver extends CI_DB { { if ( ! $conn_id = @ibase_pconnect($this->database, $this->username, $this->password, $this->char_set)) { - log_message('error', $error); + log_message('error', $this->_error_message()); if ($this->db_debug) { - $this->display_error($error, '', TRUE); + $this->display_error($this->_error_message(), '', TRUE); } return FALSE; @@ -496,7 +496,7 @@ SQL; } // remove duplicates if the user already included the escape - return strtoupper(preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str)); + return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); } // -------------------------------------------------------------------- @@ -518,7 +518,7 @@ SQL; $tables = array($tables); } - return strtolower(implode(', ', $tables)); + return implode(', ', $tables); } // -------------------------------------------------------------------- @@ -536,7 +536,7 @@ SQL; */ public function _insert($table, $keys, $values) { - return "INSERT INTO ".strtolower($table)." (".strtoupper(implode(', ', $keys)).") VALUES (".implode(', ', $values).")"; + return "INSERT INTO {$table} (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -556,8 +556,6 @@ SQL; */ public function _update($table, $values, $where, $orderby = array(), $limit = FALSE) { - $table = strtolower($table); - foreach ($values as $key => $val) { $valstr[] = $key." = ".$val; @@ -610,8 +608,6 @@ SQL; */ public function _delete($table, $where = array(), $like = array(), $limit = FALSE) { - $table = strtolower($table); - $conditions = ''; if (count($where) > 0 OR count($like) > 0) -- cgit v1.2.3-24-g4f1b From 498fa354888c1fc4083d1e464b651498d9338b64 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Wed, 15 Feb 2012 10:05:49 -0500 Subject: Minor codestyle fix --- system/database/drivers/interbase/interbase_driver.php | 2 -- system/database/drivers/interbase/interbase_utility.php | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php index 6f889d91e..a011f103d 100644 --- a/system/database/drivers/interbase/interbase_driver.php +++ b/system/database/drivers/interbase/interbase_driver.php @@ -27,8 +27,6 @@ // ------------------------------------------------------------------------ - - /** * Firebird/Interbase Database Adapter Class * diff --git a/system/database/drivers/interbase/interbase_utility.php b/system/database/drivers/interbase/interbase_utility.php index d90ecae71..764275567 100644 --- a/system/database/drivers/interbase/interbase_utility.php +++ b/system/database/drivers/interbase/interbase_utility.php @@ -100,6 +100,7 @@ class CI_DB_interbase_utility extends CI_DB_utility { public function _backup($params = array()) { // Currently unsupported + // @todo See if can be implemented return $this->db->display_error('db_unsuported_feature'); } } -- cgit v1.2.3-24-g4f1b From 3d985a19ac05a8f5141b51fed9b1b37946733792 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Wed, 15 Feb 2012 11:38:00 -0500 Subject: Syntax fixes --- .../drivers/interbase/interbase_driver.php | 27 ++++++++++------------ .../database/drivers/interbase/interbase_forge.php | 13 ++--------- 2 files changed, 14 insertions(+), 26 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php index a011f103d..36ef42ef3 100644 --- a/system/database/drivers/interbase/interbase_driver.php +++ b/system/database/drivers/interbase/interbase_driver.php @@ -152,7 +152,7 @@ class CI_DB_interbase_driver extends CI_DB { */ public function db_set_charset($charset, $collation) { - // @todo - add support if needed + // Must be determined at connection return TRUE; } @@ -166,8 +166,13 @@ class CI_DB_interbase_driver extends CI_DB { */ public function _version() { - //@todo - add support if needed - return TRUE; + if (($service = ibase_service_attach($this->hostname, $this->username, $this->password))) + { + $version = ibase_server_info($service, IBASE_SVC_SERVER_VERSION); + return $version; + } + + return FALSE; } // -------------------------------------------------------------------- @@ -396,7 +401,7 @@ SQL; 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_chr); + $sql .= ' AND "RDB$RELATION_NAME" LIKE \''.$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); } return $sql; } @@ -620,7 +625,7 @@ SQL; $conditions .= implode("\n", $like); } - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; + //$limit = ( ! $limit) ? '' : ' LIMIT '.$limit; return "DELETE FROM ".$table.$conditions.$limit; } @@ -640,16 +645,8 @@ SQL; */ public function _limit($sql, $limit, $offset) { - if ($offset == 0) - { - $offset = ''; - } - else - { - $offset .= ", "; - } - - return $sql."LIMIT ".$offset.$limit; + //There doesn't seem to be a limit clause? + return $sql; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/interbase/interbase_forge.php b/system/database/drivers/interbase/interbase_forge.php index 815107d85..177433fc4 100644 --- a/system/database/drivers/interbase/interbase_forge.php +++ b/system/database/drivers/interbase/interbase_forge.php @@ -205,20 +205,11 @@ class CI_DB_interbase_forge extends CI_DB_forge { { $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"; + $sql .= " {$column_definition}"; if ($default_value != '') { - $sql .= " DEFAULT \"$default_value\""; + $sql .= " DEFAULT \"{$default_value}\""; } if ($null === NULL) -- cgit v1.2.3-24-g4f1b From 8be31a92758959d7fd7b035e36b9799da13426ae Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Wed, 15 Feb 2012 11:48:57 -0500 Subject: Limit clause fixes --- system/database/drivers/interbase/interbase_driver.php | 12 +++++++----- system/database/drivers/interbase/interbase_result.php | 3 +-- 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php index 36ef42ef3..197c01401 100644 --- a/system/database/drivers/interbase/interbase_driver.php +++ b/system/database/drivers/interbase/interbase_driver.php @@ -436,7 +436,10 @@ SQL; */ public function _field_data($table) { - return "SELECT * FROM ".$table." LIMIT 1"; + // Need to find a more efficient way to do this + // but Interbase/Firebird seems to lack the + // limit clause + return "SELECT * FROM {$table}"; } // -------------------------------------------------------------------- @@ -564,7 +567,7 @@ SQL; $valstr[] = $key." = ".$val; } - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; + //$limit = ( ! $limit) ? '' : ' LIMIT '.$limit; $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; @@ -572,7 +575,7 @@ SQL; $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; - $sql .= $orderby.$limit; + $sql .= $orderby; return $sql; } @@ -627,7 +630,7 @@ SQL; //$limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - return "DELETE FROM ".$table.$conditions.$limit; + return "DELETE FROM {$table}{$conditions}"; } // -------------------------------------------------------------------- @@ -664,6 +667,5 @@ SQL; } } - /* End of file interbase_driver.php */ /* Location: ./system/database/drivers/interbase/interbase_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/interbase/interbase_result.php b/system/database/drivers/interbase/interbase_result.php index 9d827895d..f2465ab5d 100644 --- a/system/database/drivers/interbase/interbase_result.php +++ b/system/database/drivers/interbase/interbase_result.php @@ -149,7 +149,7 @@ class CI_DB_interbase_result extends CI_DB_result { */ public function _data_seek($n = 0) { - //Interbase driver doesn't implement a sutable function + //Interbase driver doesn't implement a suitable function return array(); } @@ -185,6 +185,5 @@ class CI_DB_interbase_result extends CI_DB_result { } - /* End of file interbase_result.php */ /* Location: ./system/database/drivers/interbase/interbase_result.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From eb6dcf058bd0cc6e5f3b6a793491d4a1c144155b Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Wed, 15 Feb 2012 16:48:51 -0500 Subject: Implemented _list_columns() method --- system/database/drivers/interbase/interbase_driver.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php index 197c01401..8a156af53 100644 --- a/system/database/drivers/interbase/interbase_driver.php +++ b/system/database/drivers/interbase/interbase_driver.php @@ -419,8 +419,17 @@ SQL; */ public function _list_columns($table = '') { - // Not supported - return FALSE; + $sql = << Date: Wed, 15 Feb 2012 18:40:39 -0500 Subject: Implemented insert_id() method --- system/database/drivers/interbase/interbase_driver.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php index 8a156af53..97bf722db 100644 --- a/system/database/drivers/interbase/interbase_driver.php +++ b/system/database/drivers/interbase/interbase_driver.php @@ -341,12 +341,13 @@ class CI_DB_interbase_driver extends CI_DB { * Insert ID * * @access public + * @param string $generator_name + * @param integer $inc_by * @return integer */ - public function insert_id() + public function insert_id($generator_name, $inc_by=1) { - //@todo Implement manually - return 0; + return ibase_gen_id($generator_name, $inc_by); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 817af19bb12b88bae361034e00ce3a02da595f94 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 16 Feb 2012 08:28:00 -0500 Subject: narfbg suggested fixes --- system/database/DB_driver.php | 2 +- .../drivers/interbase/interbase_driver.php | 86 ++++++---------------- .../database/drivers/interbase/interbase_forge.php | 20 ++--- .../drivers/interbase/interbase_result.php | 30 +++----- .../drivers/interbase/interbase_utility.php | 12 +-- 5 files changed, 44 insertions(+), 106 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index b829bbe46..7c73fc257 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -256,7 +256,7 @@ class CI_DB_driver { // 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', 'cubrid', 'pdo', 'mysqli'); + $driver_version_exceptions = array('oci8', 'sqlite', 'cubrid', 'pdo', 'mysqli', 'interbase'); if (in_array($this->dbdriver, $driver_version_exceptions)) { diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php index 97bf722db..a6f192ad1 100644 --- a/system/database/drivers/interbase/interbase_driver.php +++ b/system/database/drivers/interbase/interbase_driver.php @@ -1,13 +1,13 @@ -hostname) && $this->hostname !== "localhost") + { + $this->database = $this->hostname.':'.$this->database; + } + } /** * Non-persistent database connection * - * @access private called by the base class * @return resource */ public function db_connect() { - if ( ! $conn_id = @ibase_connect($this->database, $this->username, $this->password, $this->char_set)) - { - log_message('error', $this->_error_message()); - - if ($this->db_debug) - { - $this->display_error($this->_error_message(), '', TRUE); - } - - return FALSE; - } - - return $conn_id; + return @ibase_connect($this->database, $this->username, $this->password, $this->char_set); } // -------------------------------------------------------------------- @@ -90,24 +88,11 @@ class CI_DB_interbase_driver extends CI_DB { /** * Persistent database connection * - * @access private called by the base class * @return resource */ public function db_pconnect() { - if ( ! $conn_id = @ibase_pconnect($this->database, $this->username, $this->password, $this->char_set)) - { - log_message('error', $this->_error_message()); - - if ($this->db_debug) - { - $this->display_error($this->_error_message(), '', TRUE); - } - - return FALSE; - } - - return $conn_id; + return @ibase_pconnect($this->database, $this->username, $this->password, $this->char_set); } // -------------------------------------------------------------------- @@ -118,7 +103,6 @@ class CI_DB_interbase_driver extends CI_DB { * 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 */ public function reconnect() @@ -131,7 +115,6 @@ class CI_DB_interbase_driver extends CI_DB { /** * Select the database * - * @access private called by the base class * @return resource */ public function db_select() @@ -145,7 +128,6 @@ class CI_DB_interbase_driver extends CI_DB { /** * Set client character set * - * @access public * @param string * @param string * @return resource @@ -161,7 +143,6 @@ class CI_DB_interbase_driver extends CI_DB { /** * Version number query string * - * @access public * @return string */ public function _version() @@ -180,7 +161,6 @@ class CI_DB_interbase_driver extends CI_DB { /** * Execute the query * - * @access private called by the base class * @param string an SQL query * @return resource */ @@ -197,7 +177,6 @@ class CI_DB_interbase_driver extends CI_DB { * * If needed, each database adapter can prep the query string * - * @access private called by execute() * @param string an SQL query * @return string */ @@ -211,7 +190,6 @@ class CI_DB_interbase_driver extends CI_DB { /** * Begin Transaction * - * @access public * @return bool */ public function trans_begin($test_mode = FALSE) @@ -242,7 +220,6 @@ class CI_DB_interbase_driver extends CI_DB { /** * Commit Transaction * - * @access public * @return bool */ public function trans_commit() @@ -268,7 +245,6 @@ class CI_DB_interbase_driver extends CI_DB { /** * Rollback Transaction * - * @access public * @return bool */ public function trans_rollback() @@ -294,7 +270,6 @@ class CI_DB_interbase_driver extends CI_DB { /** * Escape String * - * @access public * @param string * @param bool whether or not the string will be used in a LIKE condition * @return string @@ -327,7 +302,6 @@ class CI_DB_interbase_driver extends CI_DB { /** * Affected Rows * - * @access public * @return integer */ public function affected_rows() @@ -340,12 +314,11 @@ class CI_DB_interbase_driver extends CI_DB { /** * Insert ID * - * @access public * @param string $generator_name * @param integer $inc_by * @return integer */ - public function insert_id($generator_name, $inc_by=1) + public function insert_id($generator_name, $inc_by=0) { return ibase_gen_id($generator_name, $inc_by); } @@ -358,7 +331,6 @@ class CI_DB_interbase_driver extends CI_DB { * Generates a platform-specific query string that counts all records in * the specified database * - * @access public * @param string * @return string */ @@ -369,7 +341,7 @@ class CI_DB_interbase_driver extends CI_DB { 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) { @@ -388,7 +360,6 @@ class CI_DB_interbase_driver extends CI_DB { * * Generates a platform-specific query string so that the table names can be fetched * - * @access private * @param boolean * @return string */ @@ -414,7 +385,6 @@ SQL; * * Generates a platform-specific query string so that the column names can be fetched * - * @access public * @param string the table name * @return string */ @@ -440,7 +410,6 @@ SQL; * * Generates a platform-specific query so that the column data can be retrieved * - * @access public * @param string the table name * @return object */ @@ -457,7 +426,6 @@ SQL; /** * The error message string * - * @access private * @return string */ public function _error_message() @@ -470,7 +438,6 @@ SQL; /** * The error message number * - * @access private * @return integer */ public function _error_number() @@ -485,7 +452,6 @@ SQL; * * This public function escapes column and table names * - * @access private * @param string * @return string */ @@ -523,7 +489,6 @@ SQL; * This public function implicitly groups FROM tables so there is no confusion * about operator precedence in harmony with SQL standards * - * @access public * @param type * @return type */ @@ -534,6 +499,7 @@ SQL; $tables = array($tables); } + //Interbase/Firebird doesn't like grouped tables return implode(', ', $tables); } @@ -544,7 +510,6 @@ SQL; * * 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 @@ -552,7 +517,7 @@ SQL; */ public function _insert($table, $keys, $values) { - return "INSERT INTO {$table} (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return "INSERT INTO {$table} (".implode(', ', $keys).') VALUES ('.implode(', ', $values).')'; } // -------------------------------------------------------------------- @@ -562,7 +527,6 @@ SQL; * * 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 @@ -581,9 +545,9 @@ SQL; $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); + $sql = "UPDATE {$table} SET ".implode(', ', $valstr); - $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; + $sql .= ($where != '' AND count($where) >=1) ? ' WHERE '.implode(' ', $where) : ''; $sql .= $orderby; @@ -600,7 +564,6 @@ SQL; * If the database does not support the truncate() command * This public function maps to "DELETE FROM table" * - * @access public * @param string the table name * @return string */ @@ -616,7 +579,6 @@ SQL; * * 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 @@ -633,7 +595,7 @@ SQL; if (count($where) > 0 && count($like) > 0) { - $conditions .= " AND "; + $conditions .= ' AND '; } $conditions .= implode("\n", $like); } @@ -650,7 +612,6 @@ SQL; * * 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 @@ -667,7 +628,6 @@ SQL; /** * Close DB Connection * - * @access public * @param resource * @return void */ diff --git a/system/database/drivers/interbase/interbase_forge.php b/system/database/drivers/interbase/interbase_forge.php index 177433fc4..6301481c5 100644 --- a/system/database/drivers/interbase/interbase_forge.php +++ b/system/database/drivers/interbase/interbase_forge.php @@ -1,13 +1,13 @@ -db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return array(); + return 'DROP TABLE '.$name; } // -------------------------------------------------------------------- @@ -191,7 +183,6 @@ class CI_DB_interbase_forge extends CI_DB_forge { * 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 @@ -237,14 +228,13 @@ class CI_DB_interbase_forge extends CI_DB_forge { * * 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 */ public 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); + $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/interbase/interbase_result.php b/system/database/drivers/interbase/interbase_result.php index f2465ab5d..7d56c56c6 100644 --- a/system/database/drivers/interbase/interbase_result.php +++ b/system/database/drivers/interbase/interbase_result.php @@ -1,13 +1,13 @@ -result_id)) + if( ! is_null($this->num_rows)) { - $count++; + return $this->num_rows; } - return $count; + return $this->num_rows = (isset($this->result_array()) ? count($this->result_array()) : 0; } // -------------------------------------------------------------------- @@ -62,7 +60,6 @@ class CI_DB_interbase_result extends CI_DB_result { /** * Number of fields in the result set * - * @access public * @return integer */ public function num_fields() @@ -77,13 +74,12 @@ class CI_DB_interbase_result extends CI_DB_result { * * Generates an array of column names * - * @access public * @return array */ public function list_fields() { $field_names = array(); - for ($i = 0; $i < $this->num_fields(); $i++) + for ($i = 0, $num_fields=$this->num_fields(); $i < $num_fields; $i++) { $info = ibase_field_info($this->result_id, $i); $field_names[] = $info['name']; @@ -99,14 +95,13 @@ class CI_DB_interbase_result extends CI_DB_result { * * Generates an array of objects containing field meta-data * - * @access public * @return array */ public function field_data() { $retval = array(); - for ($i = 0; $i < $this->num_fields(); $i++) + for ($i = 0, $num_fields=$this->num_fields(); $i < $num_fields; $i++) { $info = ibase_field_info($this->result_id, $i); @@ -144,13 +139,12 @@ class CI_DB_interbase_result extends CI_DB_result { * this internally before fetching results to make sure the * result set starts at zero * - * @access private * @return array */ public function _data_seek($n = 0) { //Interbase driver doesn't implement a suitable function - return array(); + return FALSE; } // -------------------------------------------------------------------- @@ -160,7 +154,6 @@ class CI_DB_interbase_result extends CI_DB_result { * * Returns the result set as an array * - * @access private * @return array */ public function _fetch_assoc() @@ -175,7 +168,6 @@ class CI_DB_interbase_result extends CI_DB_result { * * Returns the result set as an object * - * @access private * @return object */ public function _fetch_object() diff --git a/system/database/drivers/interbase/interbase_utility.php b/system/database/drivers/interbase/interbase_utility.php index 764275567..e31021acb 100644 --- a/system/database/drivers/interbase/interbase_utility.php +++ b/system/database/drivers/interbase/interbase_utility.php @@ -1,13 +1,13 @@ -db->display_error('db_unsuported_feature'); } - return array(); + return FALSE; } // -------------------------------------------------------------------- @@ -63,7 +62,6 @@ class CI_DB_interbase_utility extends CI_DB_utility { * * Is optimization even supported in Interbase/Firebird? * - * @access private * @param string the table name * @return object */ @@ -79,7 +77,6 @@ class CI_DB_interbase_utility extends CI_DB_utility { * * Table repairs are not supported in Interbase/Firebird * - * @access private * @param string the table name * @return object */ @@ -93,7 +90,6 @@ class CI_DB_interbase_utility extends CI_DB_utility { /** * Interbase/Firebird Export * - * @access private * @param array Preferences * @return mixed */ -- cgit v1.2.3-24-g4f1b From e27216f88443775534e185e192996353d4958387 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 16 Feb 2012 12:15:45 -0500 Subject: Num rows fix --- system/database/drivers/interbase/interbase_result.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/interbase/interbase_result.php b/system/database/drivers/interbase/interbase_result.php index 7d56c56c6..3d5721138 100644 --- a/system/database/drivers/interbase/interbase_result.php +++ b/system/database/drivers/interbase/interbase_result.php @@ -52,7 +52,7 @@ class CI_DB_interbase_result extends CI_DB_result { return $this->num_rows; } - return $this->num_rows = (isset($this->result_array()) ? count($this->result_array()) : 0; + return 0; } // -------------------------------------------------------------------- @@ -143,6 +143,9 @@ class CI_DB_interbase_result extends CI_DB_result { */ public function _data_seek($n = 0) { + //Set the row count to 0 + $this->num_rows = 0; + //Interbase driver doesn't implement a suitable function return FALSE; } @@ -158,6 +161,9 @@ class CI_DB_interbase_result extends CI_DB_result { */ public function _fetch_assoc() { + //Increment row count + $this->num_rows++; + return @ibase_fetch_assoc($this->result_id); } @@ -172,6 +178,9 @@ class CI_DB_interbase_result extends CI_DB_result { */ public function _fetch_object() { + //Increment row count + $this->num_rows++; + return @ibase_fetch_object($this->result_id); } -- cgit v1.2.3-24-g4f1b From 3c4281f09dce0a97ab700d79e26308fdab350b73 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 16 Feb 2012 19:00:10 -0500 Subject: Simplified hostname connection logic --- system/database/drivers/interbase/interbase_driver.php | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php index a6f192ad1..20663d8bb 100644 --- a/system/database/drivers/interbase/interbase_driver.php +++ b/system/database/drivers/interbase/interbase_driver.php @@ -61,17 +61,6 @@ class CI_DB_interbase_driver extends CI_DB { // Keeps track of the resource for the current transaction protected $trans; - - /** - * Constructor for some overall setup - */ - public function __construct() - { - if( ! empty($this->hostname) && $this->hostname !== "localhost") - { - $this->database = $this->hostname.':'.$this->database; - } - } /** * Non-persistent database connection @@ -80,7 +69,7 @@ class CI_DB_interbase_driver extends CI_DB { */ public function db_connect() { - return @ibase_connect($this->database, $this->username, $this->password, $this->char_set); + return @ibase_connect($this->hostname.':'.$this->database, $this->username, $this->password, $this->char_set); } // -------------------------------------------------------------------- @@ -92,7 +81,7 @@ class CI_DB_interbase_driver extends CI_DB { */ public function db_pconnect() { - return @ibase_pconnect($this->database, $this->username, $this->password, $this->char_set); + return @ibase_pconnect($this->hostname.':'.$this->database, $this->username, $this->password, $this->char_set); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 24dd2f9c5cc4476f19c67fe8df6b3ae9cc8a4bb3 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 17 Feb 2012 17:08:31 +0700 Subject: Syntax error, causing MySQL utility could not used --- 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 9d7cb679c..952f887fe 100644 --- a/system/database/drivers/mysql/mysql_utility.php +++ b/system/database/drivers/mysql/mysql_utility.php @@ -115,7 +115,7 @@ class CI_DB_mysql_utility extends CI_DB_utility { if ($add_drop == TRUE) { - $output .= 'DROP TABLE IF EXISTS '.($this->db->protect_identifiers($table).';'.$newline.$newline; + $output .= 'DROP TABLE IF EXISTS '.$this->db->protect_identifiers($table).';'.$newline.$newline; } $i = 0; -- cgit v1.2.3-24-g4f1b From 3a4cdc62042c56da9527e6d1d4c1ab5417839e1c Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 17 Feb 2012 13:59:44 -0500 Subject: Workaround to fix method --- .../drivers/interbase/interbase_driver.php | 53 ++++++++++++++++++ .../drivers/interbase/interbase_result.php | 62 ++++++++++++++++++++++ 2 files changed, 115 insertions(+) (limited to 'system/database') diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php index 20663d8bb..7bd4f6f4b 100644 --- a/system/database/drivers/interbase/interbase_driver.php +++ b/system/database/drivers/interbase/interbase_driver.php @@ -624,6 +624,59 @@ SQL; { @ibase_close($conn_id); } + + // -------------------------------------------------------------------------- + + /** + * 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); + + $table = FALSE; + $rows = $query->result_array(); + + // This has to be called after getting the result due to the + // limitations of the database driver + if ($query->num_rows() > 0) + { + $key = (($row = current($rows)) && in_array('table_name', array_map('strtolower', array_keys($row)))); + + if ($key) + { + $table = array_key_exists('TABLE_NAME', $row) ? 'TABLE_NAME' : 'table_name'; + } + + foreach ($rows as $row) + { + $retval[] = ( ! $table) ? current($row) : $row[$table]; + } + } + + $this->data_cache['table_names'] = $retval; + + return $this->data_cache['table_names']; + } } /* End of file interbase_driver.php */ diff --git a/system/database/drivers/interbase/interbase_result.php b/system/database/drivers/interbase/interbase_result.php index 3d5721138..37f0a108c 100644 --- a/system/database/drivers/interbase/interbase_result.php +++ b/system/database/drivers/interbase/interbase_result.php @@ -183,6 +183,68 @@ class CI_DB_interbase_result extends CI_DB_result { return @ibase_fetch_object($this->result_id); } + + // -------------------------------------------------------------------- + + /** + * Query result. "object" version. + * + * @return object + */ + public 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) + { + return array(); + } + + $this->num_rows = 0; + while ($row = $this->_fetch_object()) + { + $this->result_object[] = $row; + } + + return $this->result_object; + } + + // -------------------------------------------------------------------- + + /** + * Query result. "array" version. + * + * @return array + */ + public 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) + { + return array(); + } + + $this->num_rows = 0; + while ($row = $this->_fetch_assoc()) + { + $this->result_array[] = $row; + } + + return $this->result_array; + } } -- cgit v1.2.3-24-g4f1b From 7d42eb39484a784496868f4446a2d47b0c52410d Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 17 Feb 2012 14:21:18 -0500 Subject: More general fix for num_rows --- .../drivers/interbase/interbase_driver.php | 53 ---------------------- .../drivers/interbase/interbase_result.php | 5 +- 2 files changed, 4 insertions(+), 54 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php index 7bd4f6f4b..20663d8bb 100644 --- a/system/database/drivers/interbase/interbase_driver.php +++ b/system/database/drivers/interbase/interbase_driver.php @@ -624,59 +624,6 @@ SQL; { @ibase_close($conn_id); } - - // -------------------------------------------------------------------------- - - /** - * 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); - - $table = FALSE; - $rows = $query->result_array(); - - // This has to be called after getting the result due to the - // limitations of the database driver - if ($query->num_rows() > 0) - { - $key = (($row = current($rows)) && in_array('table_name', array_map('strtolower', array_keys($row)))); - - if ($key) - { - $table = array_key_exists('TABLE_NAME', $row) ? 'TABLE_NAME' : 'table_name'; - } - - foreach ($rows as $row) - { - $retval[] = ( ! $table) ? current($row) : $row[$table]; - } - } - - $this->data_cache['table_names'] = $retval; - - return $this->data_cache['table_names']; - } } /* End of file interbase_driver.php */ diff --git a/system/database/drivers/interbase/interbase_result.php b/system/database/drivers/interbase/interbase_result.php index 37f0a108c..9093029dd 100644 --- a/system/database/drivers/interbase/interbase_result.php +++ b/system/database/drivers/interbase/interbase_result.php @@ -52,7 +52,10 @@ class CI_DB_interbase_result extends CI_DB_result { return $this->num_rows; } - return 0; + //Get the results so that you can get an accurate rowcount + $this->result_array(); + + return $this->num_rows; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From c2b712eb5230fc247ef81b4b88de789b9dd08cb4 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 17 Feb 2012 15:58:08 -0500 Subject: implemented create_database, misc cleanup --- .../database/drivers/interbase/interbase_driver.php | 17 ++++++----------- .../database/drivers/interbase/interbase_forge.php | 20 ++++++++++---------- 2 files changed, 16 insertions(+), 21 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php index 20663d8bb..bc7365e4d 100644 --- a/system/database/drivers/interbase/interbase_driver.php +++ b/system/database/drivers/interbase/interbase_driver.php @@ -104,7 +104,7 @@ class CI_DB_interbase_driver extends CI_DB { /** * Select the database * - * @return resource + * @return bool */ public function db_select() { @@ -119,7 +119,7 @@ class CI_DB_interbase_driver extends CI_DB { * * @param string * @param string - * @return resource + * @return bool */ public function db_set_charset($charset, $collation) { @@ -332,6 +332,8 @@ class CI_DB_interbase_driver extends CI_DB { $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . ' FROM ' . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); + $query->result_array(); + if ($query->num_rows() == 0) { return 0; @@ -379,17 +381,10 @@ SQL; */ public function _list_columns($table = '') { - $sql = <<hostname.':'.$filename.'"'; + } // -------------------------------------------------------------------- @@ -72,7 +73,7 @@ class CI_DB_interbase_forge extends CI_DB_forge { * @param mixed primary key(s) * @param mixed key(s) * @param boolean should 'IF NOT EXISTS' be added to the SQL - * @return bool + * @return string */ public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) { @@ -168,7 +169,7 @@ class CI_DB_interbase_forge extends CI_DB_forge { /** * Drop Table * - * @return bool + * @return string */ public function _drop_table($table) { @@ -190,7 +191,7 @@ class CI_DB_interbase_forge extends CI_DB_forge { * @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 + * @return string */ public function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') { @@ -234,8 +235,7 @@ class CI_DB_interbase_forge extends CI_DB_forge { */ public 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; + return 'ALTER TABLE '.$this->db->_protect_identifiers($table_name).' RENAME TO '.$this->db->_protect_identifiers($new_table_name); } } -- cgit v1.2.3-24-g4f1b From 0dcfd778350ce397b034f44e34397ea255b35809 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 17 Feb 2012 17:42:34 -0500 Subject: Automatic retreival of blob fields --- system/database/drivers/interbase/interbase_result.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/interbase/interbase_result.php b/system/database/drivers/interbase/interbase_result.php index 9093029dd..c5608d977 100644 --- a/system/database/drivers/interbase/interbase_result.php +++ b/system/database/drivers/interbase/interbase_result.php @@ -167,7 +167,7 @@ class CI_DB_interbase_result extends CI_DB_result { //Increment row count $this->num_rows++; - return @ibase_fetch_assoc($this->result_id); + return @ibase_fetch_assoc($this->result_id, IBASE_FETCH_BLOBS); } // -------------------------------------------------------------------- @@ -184,7 +184,7 @@ class CI_DB_interbase_result extends CI_DB_result { //Increment row count $this->num_rows++; - return @ibase_fetch_object($this->result_id); + return @ibase_fetch_object($this->result_id, IBASE_FETCH_BLOBS); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 53e24f08f930d53dc0e23d180e14d452f97addf9 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 20 Feb 2012 11:55:31 -0500 Subject: Properly escape generator name --- system/database/drivers/interbase/interbase_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php index bc7365e4d..fcefa6d97 100644 --- a/system/database/drivers/interbase/interbase_driver.php +++ b/system/database/drivers/interbase/interbase_driver.php @@ -309,7 +309,7 @@ class CI_DB_interbase_driver extends CI_DB { */ public function insert_id($generator_name, $inc_by=0) { - return ibase_gen_id($generator_name, $inc_by); + return ibase_gen_id('"'.$generator_name.'"', $inc_by); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From fa84d6186b7f61353d04132871a5223f80fa12ee Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 20 Feb 2012 12:51:45 -0500 Subject: Fixed result array fetching --- system/database/drivers/interbase/interbase_result.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/interbase/interbase_result.php b/system/database/drivers/interbase/interbase_result.php index c5608d977..c7b40d2ea 100644 --- a/system/database/drivers/interbase/interbase_result.php +++ b/system/database/drivers/interbase/interbase_result.php @@ -53,7 +53,7 @@ class CI_DB_interbase_result extends CI_DB_result { } //Get the results so that you can get an accurate rowcount - $this->result_array(); + $this->result(); return $this->num_rows; } @@ -231,6 +231,14 @@ class CI_DB_interbase_result extends CI_DB_result { { return $this->result_array; } + + // Since the object and array are really similar, just case + // the result object to an array if need be + if(count($this->result_object) > 0) + { + $this->result_array = (array)$this->result_object; + 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 -- cgit v1.2.3-24-g4f1b From 53d109dbd831506c4b9ca77f10bc1b2dba9c28d5 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 20 Feb 2012 13:04:48 -0500 Subject: Fix previous commit --- system/database/drivers/interbase/interbase_result.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/interbase/interbase_result.php b/system/database/drivers/interbase/interbase_result.php index c7b40d2ea..de4a10b62 100644 --- a/system/database/drivers/interbase/interbase_result.php +++ b/system/database/drivers/interbase/interbase_result.php @@ -236,7 +236,11 @@ class CI_DB_interbase_result extends CI_DB_result { // the result object to an array if need be if(count($this->result_object) > 0) { - $this->result_array = (array)$this->result_object; + foreach($this->result_object as $obj) + { + $this->result_array[] = (array)$obj; + } + return $this->result_array; } -- cgit v1.2.3-24-g4f1b From 07b660b56dcf608b64fc1811c602c4072c276e70 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 20 Feb 2012 13:23:06 -0500 Subject: Fixed insert_id possibly returning 0 --- system/database/drivers/interbase/interbase_driver.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php index fcefa6d97..4044c4529 100644 --- a/system/database/drivers/interbase/interbase_driver.php +++ b/system/database/drivers/interbase/interbase_driver.php @@ -309,7 +309,12 @@ class CI_DB_interbase_driver extends CI_DB { */ public function insert_id($generator_name, $inc_by=0) { - return ibase_gen_id('"'.$generator_name.'"', $inc_by); + //If a generator hasn't been used before it will return 0 + if($id = ibase_gen_id('"'.$generator_name.'"', $inc_by) !== 0) + { + return $id; + } + return ibase_gen_id('"'.$generator_name.'"', 1); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 934e853d9a3a491911b72f40cb371edfaddb9c94 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 20 Feb 2012 15:42:14 -0500 Subject: Revert "Fix previous commit" This reverts commit 53d109dbd831506c4b9ca77f10bc1b2dba9c28d5. --- system/database/drivers/interbase/interbase_result.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/interbase/interbase_result.php b/system/database/drivers/interbase/interbase_result.php index de4a10b62..c7b40d2ea 100644 --- a/system/database/drivers/interbase/interbase_result.php +++ b/system/database/drivers/interbase/interbase_result.php @@ -236,11 +236,7 @@ class CI_DB_interbase_result extends CI_DB_result { // the result object to an array if need be if(count($this->result_object) > 0) { - foreach($this->result_object as $obj) - { - $this->result_array[] = (array)$obj; - } - + $this->result_array = (array)$this->result_object; return $this->result_array; } -- cgit v1.2.3-24-g4f1b From fed2d1ddecae1886486915718cb9878b7d5aea45 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 20 Feb 2012 15:42:45 -0500 Subject: Revert previous commit --- system/database/drivers/interbase/interbase_driver.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php index 4044c4529..aeea00d7f 100644 --- a/system/database/drivers/interbase/interbase_driver.php +++ b/system/database/drivers/interbase/interbase_driver.php @@ -310,11 +310,7 @@ class CI_DB_interbase_driver extends CI_DB { public function insert_id($generator_name, $inc_by=0) { //If a generator hasn't been used before it will return 0 - if($id = ibase_gen_id('"'.$generator_name.'"', $inc_by) !== 0) - { - return $id; - } - return ibase_gen_id('"'.$generator_name.'"', 1); + return ibase_gen_id('"'.$generator_name.'"', $inc_by); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 51ed4ed7f6097a34ce1db7b225272bfc1b0f0bcf Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 20 Feb 2012 16:01:42 -0500 Subject: Convert result_array to result_object instead of re-fetching --- .../drivers/interbase/interbase_result.php | 27 +++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/interbase/interbase_result.php b/system/database/drivers/interbase/interbase_result.php index c7b40d2ea..e1332ba93 100644 --- a/system/database/drivers/interbase/interbase_result.php +++ b/system/database/drivers/interbase/interbase_result.php @@ -200,6 +200,27 @@ class CI_DB_interbase_result extends CI_DB_result { { return $this->result_object; } + + // Convert result array to object so that + // We don't have to get the result again + if(count($this->result_array) > 0) + { + $i = 0; + + foreach($this->result_array as $array) + { + $this->result_object[$i] = new StdClass(); + + foreach($array as $key => $val) + { + $this->result_object[$i]->{$key} = $val; + } + + ++$i; + } + + 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 @@ -236,7 +257,11 @@ class CI_DB_interbase_result extends CI_DB_result { // the result object to an array if need be if(count($this->result_object) > 0) { - $this->result_array = (array)$this->result_object; + foreach($this->result_object as $obj) + { + $this->result_array[] = (array)$obj; + } + return $this->result_array; } -- cgit v1.2.3-24-g4f1b From 95562144da88784588fb2477fa0070576bd386a0 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 20 Feb 2012 17:37:21 -0500 Subject: Set protected visibility on applicable functions/properties --- .../drivers/interbase/interbase_driver.php | 44 +++++++++++----------- .../database/drivers/interbase/interbase_forge.php | 12 +++--- .../drivers/interbase/interbase_result.php | 6 +-- 3 files changed, 30 insertions(+), 32 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php index aeea00d7f..ba4f9d8d9 100644 --- a/system/database/drivers/interbase/interbase_driver.php +++ b/system/database/drivers/interbase/interbase_driver.php @@ -45,19 +45,19 @@ class CI_DB_interbase_driver extends CI_DB { public $dbdriver = 'interbase'; // The character used to escape with - public $_escape_char = '"'; + protected $_escape_char = '"'; // clause and character used for LIKE escape sequences - public $_like_escape_str = " ESCAPE '%s' "; - public $_like_escape_chr = '!'; + protected $_like_escape_str = " ESCAPE '%s' "; + protected $_like_escape_chr = '!'; /** * 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. */ - public $_count_string = "SELECT COUNT(*) AS "; - public $_random_keyword = ' Random()'; // database specific random keyword + protected $_count_string = "SELECT COUNT(*) AS "; + protected $_random_keyword = ' Random()'; // database specific random keyword // Keeps track of the resource for the current transaction protected $trans; @@ -134,7 +134,7 @@ class CI_DB_interbase_driver extends CI_DB { * * @return string */ - public function _version() + protected function _version() { if (($service = ibase_service_attach($this->hostname, $this->username, $this->password))) { @@ -153,7 +153,7 @@ class CI_DB_interbase_driver extends CI_DB { * @param string an SQL query * @return resource */ - public function _execute($sql) + protected function _execute($sql) { $sql = $this->_prep_query($sql); return @ibase_query($this->conn_id, $sql); @@ -169,7 +169,7 @@ class CI_DB_interbase_driver extends CI_DB { * @param string an SQL query * @return string */ - public function _prep_query($sql) + protected function _prep_query($sql) { return $sql; } @@ -333,8 +333,6 @@ class CI_DB_interbase_driver extends CI_DB { $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . ' FROM ' . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); - $query->result_array(); - if ($query->num_rows() == 0) { return 0; @@ -355,7 +353,7 @@ class CI_DB_interbase_driver extends CI_DB { * @param boolean * @return string */ - public function _list_tables($prefix_limit = FALSE) + protected function _list_tables($prefix_limit = FALSE) { $sql = <<_reserved_identifiers as $id) { @@ -477,7 +475,7 @@ SQL; * @param type * @return type */ - public function _from_tables($tables) + protected function _from_tables($tables) { if ( ! is_array($tables)) { @@ -500,7 +498,7 @@ SQL; * @param array the insert values * @return string */ - public function _insert($table, $keys, $values) + protected function _insert($table, $keys, $values) { return "INSERT INTO {$table} (".implode(', ', $keys).') VALUES ('.implode(', ', $values).')'; } @@ -519,7 +517,7 @@ SQL; * @param array the limit clause * @return string */ - public function _update($table, $values, $where, $orderby = array(), $limit = FALSE) + protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE) { foreach ($values as $key => $val) { @@ -552,7 +550,7 @@ SQL; * @param string the table name * @return string */ - public function _truncate($table) + protected function _truncate($table) { return $this->_delete($table); } @@ -569,7 +567,7 @@ SQL; * @param string the limit clause * @return string */ - public function _delete($table, $where = array(), $like = array(), $limit = FALSE) + protected function _delete($table, $where = array(), $like = array(), $limit = FALSE) { $conditions = ''; @@ -602,7 +600,7 @@ SQL; * @param integer the offset value * @return string */ - public function _limit($sql, $limit, $offset) + protected function _limit($sql, $limit, $offset) { //There doesn't seem to be a limit clause? return $sql; @@ -616,7 +614,7 @@ SQL; * @param resource * @return void */ - public function _close($conn_id) + protected function _close($conn_id) { @ibase_close($conn_id); } diff --git a/system/database/drivers/interbase/interbase_forge.php b/system/database/drivers/interbase/interbase_forge.php index d9b55a87f..c7372a0bf 100644 --- a/system/database/drivers/interbase/interbase_forge.php +++ b/system/database/drivers/interbase/interbase_forge.php @@ -42,7 +42,7 @@ class CI_DB_interbase_forge extends CI_DB_forge { * @param string the database name * @return string */ - public function _create_database($filename='') + protected function _create_database($filename='') { // Firebird databases are flat files, so a path is required // Hostname is needed for remote access @@ -59,7 +59,7 @@ class CI_DB_interbase_forge extends CI_DB_forge { * - the current db is dropped * @return bool */ - public function _drop_database($name='') + protected function _drop_database($name='') { return ibase_drop_db($this->conn_id); } @@ -75,7 +75,7 @@ class CI_DB_interbase_forge extends CI_DB_forge { * @param boolean should 'IF NOT EXISTS' be added to the SQL * @return string */ - public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) + protected function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) { $sql = 'CREATE TABLE '; @@ -171,7 +171,7 @@ class CI_DB_interbase_forge extends CI_DB_forge { * * @return string */ - public function _drop_table($table) + protected function _drop_table($table) { return 'DROP TABLE '.$name; } @@ -193,7 +193,7 @@ class CI_DB_interbase_forge extends CI_DB_forge { * @param string the field after which we should add the new field * @return string */ - public function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') + protected 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); @@ -233,7 +233,7 @@ class CI_DB_interbase_forge extends CI_DB_forge { * @param string the new table name * @return string */ - public function _rename_table($table_name, $new_table_name) + protected function _rename_table($table_name, $new_table_name) { return 'ALTER TABLE '.$this->db->_protect_identifiers($table_name).' RENAME TO '.$this->db->_protect_identifiers($new_table_name); } diff --git a/system/database/drivers/interbase/interbase_result.php b/system/database/drivers/interbase/interbase_result.php index e1332ba93..7a3a41f2c 100644 --- a/system/database/drivers/interbase/interbase_result.php +++ b/system/database/drivers/interbase/interbase_result.php @@ -144,7 +144,7 @@ class CI_DB_interbase_result extends CI_DB_result { * * @return array */ - public function _data_seek($n = 0) + protected function _data_seek($n = 0) { //Set the row count to 0 $this->num_rows = 0; @@ -162,7 +162,7 @@ class CI_DB_interbase_result extends CI_DB_result { * * @return array */ - public function _fetch_assoc() + protected function _fetch_assoc() { //Increment row count $this->num_rows++; @@ -179,7 +179,7 @@ class CI_DB_interbase_result extends CI_DB_result { * * @return object */ - public function _fetch_object() + protected function _fetch_object() { //Increment row count $this->num_rows++; -- cgit v1.2.3-24-g4f1b From 2da66edce7c249c0305153a65c4292311f49a546 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 20 Feb 2012 17:54:39 -0500 Subject: Fix counting issue, minor formatting --- .../database/drivers/interbase/interbase_forge.php | 2 +- .../drivers/interbase/interbase_result.php | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/interbase/interbase_forge.php b/system/database/drivers/interbase/interbase_forge.php index c7372a0bf..d21a5551b 100644 --- a/system/database/drivers/interbase/interbase_forge.php +++ b/system/database/drivers/interbase/interbase_forge.php @@ -79,7 +79,7 @@ class CI_DB_interbase_forge extends CI_DB_forge { { $sql = 'CREATE TABLE '; - $sql .= $this->db->_escape_identifiers($table)."("; + $sql .= $this->db->_protect_identifiers($table)."("; $current_field_count = 0; foreach ($fields as $field=>$attributes) diff --git a/system/database/drivers/interbase/interbase_result.php b/system/database/drivers/interbase/interbase_result.php index 7a3a41f2c..9caf1ce91 100644 --- a/system/database/drivers/interbase/interbase_result.php +++ b/system/database/drivers/interbase/interbase_result.php @@ -82,7 +82,7 @@ class CI_DB_interbase_result extends CI_DB_result { public function list_fields() { $field_names = array(); - for ($i = 0, $num_fields=$this->num_fields(); $i < $num_fields; $i++) + for ($i = 0, $num_fields = $this->num_fields(); $i < $num_fields; $i++) { $info = ibase_field_info($this->result_id, $i); $field_names[] = $info['name']; @@ -104,7 +104,7 @@ class CI_DB_interbase_result extends CI_DB_result { { $retval = array(); - for ($i = 0, $num_fields=$this->num_fields(); $i < $num_fields; $i++) + for ($i = 0, $num_fields = $this->num_fields(); $i < $num_fields; $i++) { $info = ibase_field_info($this->result_id, $i); @@ -164,10 +164,13 @@ class CI_DB_interbase_result extends CI_DB_result { */ protected function _fetch_assoc() { - //Increment row count - $this->num_rows++; + if(($row = @ibase_fetch_assoc($this->result_id, IBASE_FETCH_BLOBS)) !== FALSE) + { + //Increment row count + $this->num_rows++; + } - return @ibase_fetch_assoc($this->result_id, IBASE_FETCH_BLOBS); + return $row; } // -------------------------------------------------------------------- @@ -181,10 +184,13 @@ class CI_DB_interbase_result extends CI_DB_result { */ protected function _fetch_object() { - //Increment row count - $this->num_rows++; + if(($row = @ibase_fetch_object($this->result_id, IBASE_FETCH_BLOBS)) !== FALSE) + { + //Increment row count + $this->num_rows++; + } - return @ibase_fetch_object($this->result_id, IBASE_FETCH_BLOBS); + return $row; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 41a439bf75bdd277e153d44788b732cf2e8c7ee3 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 20 Feb 2012 18:40:00 -0500 Subject: Minor formatting fixes --- system/database/drivers/interbase/interbase_result.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/interbase/interbase_result.php b/system/database/drivers/interbase/interbase_result.php index 9caf1ce91..01f0e52b2 100644 --- a/system/database/drivers/interbase/interbase_result.php +++ b/system/database/drivers/interbase/interbase_result.php @@ -164,7 +164,7 @@ class CI_DB_interbase_result extends CI_DB_result { */ protected function _fetch_assoc() { - if(($row = @ibase_fetch_assoc($this->result_id, IBASE_FETCH_BLOBS)) !== FALSE) + if (($row = @ibase_fetch_assoc($this->result_id, IBASE_FETCH_BLOBS)) !== FALSE) { //Increment row count $this->num_rows++; @@ -184,7 +184,7 @@ class CI_DB_interbase_result extends CI_DB_result { */ protected function _fetch_object() { - if(($row = @ibase_fetch_object($this->result_id, IBASE_FETCH_BLOBS)) !== FALSE) + if (($row = @ibase_fetch_object($this->result_id, IBASE_FETCH_BLOBS)) !== FALSE) { //Increment row count $this->num_rows++; @@ -209,7 +209,7 @@ class CI_DB_interbase_result extends CI_DB_result { // Convert result array to object so that // We don't have to get the result again - if(count($this->result_array) > 0) + if (count($this->result_array) > 0) { $i = 0; @@ -261,7 +261,7 @@ class CI_DB_interbase_result extends CI_DB_result { // Since the object and array are really similar, just case // the result object to an array if need be - if(count($this->result_object) > 0) + if (count($this->result_object) > 0) { foreach($this->result_object as $obj) { -- cgit v1.2.3-24-g4f1b From dd044b317fc2db52f3812792a256497a2f0e94fb Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 20 Feb 2012 18:58:24 -0500 Subject: More style fixes, replaced _protect_identifiers with protect_identifiers in db_forge --- system/database/drivers/interbase/interbase_forge.php | 16 ++++++++-------- system/database/drivers/interbase/interbase_result.php | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/interbase/interbase_forge.php b/system/database/drivers/interbase/interbase_forge.php index d21a5551b..b8ea6a05d 100644 --- a/system/database/drivers/interbase/interbase_forge.php +++ b/system/database/drivers/interbase/interbase_forge.php @@ -79,7 +79,7 @@ class CI_DB_interbase_forge extends CI_DB_forge { { $sql = 'CREATE TABLE '; - $sql .= $this->db->_protect_identifiers($table)."("; + $sql .= $this->db->protect_identifiers($table)."("; $current_field_count = 0; foreach ($fields as $field=>$attributes) @@ -95,7 +95,7 @@ class CI_DB_interbase_forge extends CI_DB_forge { { $attributes = array_change_key_case($attributes, CASE_UPPER); - $sql .= "\n\t".$this->db->_protect_identifiers($field); + $sql .= "\n\t".$this->db->protect_identifiers($field); $sql .= ' '.$attributes['TYPE']; @@ -138,7 +138,7 @@ class CI_DB_interbase_forge extends CI_DB_forge { if (count($primary_keys) > 0) { - $primary_keys = $this->db->_protect_identifiers($primary_keys); + $primary_keys = $this->db->protect_identifiers($primary_keys); $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; } @@ -148,11 +148,11 @@ class CI_DB_interbase_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)); + $key = array($this->db->protect_identifiers($key)); } $sql .= ",\n\tUNIQUE (" . implode(', ', $key) . ")"; @@ -195,7 +195,7 @@ class CI_DB_interbase_forge extends CI_DB_forge { */ protected 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); + $sql = 'ALTER TABLE '.$this->db->protect_identifiers($table)." $alter_type ".$this->db->protect_identifiers($column_name); $sql .= " {$column_definition}"; @@ -215,7 +215,7 @@ class CI_DB_interbase_forge extends CI_DB_forge { if ($after_field != '') { - $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); + $sql .= ' AFTER ' . $this->db->protect_identifiers($after_field); } return $sql; @@ -235,7 +235,7 @@ class CI_DB_interbase_forge extends CI_DB_forge { */ protected function _rename_table($table_name, $new_table_name) { - return 'ALTER TABLE '.$this->db->_protect_identifiers($table_name).' RENAME TO '.$this->db->_protect_identifiers($new_table_name); + return 'ALTER TABLE '.$this->db->protect_identifiers($table_name).' RENAME TO '.$this->db->protect_identifiers($new_table_name); } } diff --git a/system/database/drivers/interbase/interbase_result.php b/system/database/drivers/interbase/interbase_result.php index 01f0e52b2..be9cb6547 100644 --- a/system/database/drivers/interbase/interbase_result.php +++ b/system/database/drivers/interbase/interbase_result.php @@ -213,11 +213,11 @@ class CI_DB_interbase_result extends CI_DB_result { { $i = 0; - foreach($this->result_array as $array) + foreach ($this->result_array as $array) { $this->result_object[$i] = new StdClass(); - foreach($array as $key => $val) + foreach ($array as $key => $val) { $this->result_object[$i]->{$key} = $val; } @@ -263,7 +263,7 @@ class CI_DB_interbase_result extends CI_DB_result { // the result object to an array if need be if (count($this->result_object) > 0) { - foreach($this->result_object as $obj) + foreach ($this->result_object as $obj) { $this->result_array[] = (array)$obj; } -- cgit v1.2.3-24-g4f1b From 2062a8693e1ba44c4530254f63c3936894aad526 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 20 Feb 2012 19:38:10 -0500 Subject: Made tranaaction functions return their actual value --- system/database/drivers/interbase/interbase_driver.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php index ba4f9d8d9..7258e605e 100644 --- a/system/database/drivers/interbase/interbase_driver.php +++ b/system/database/drivers/interbase/interbase_driver.php @@ -224,9 +224,7 @@ class CI_DB_interbase_driver extends CI_DB { return TRUE; } - @ibase_commit($this->trans); - - return TRUE; + return @ibase_commit($this->trans); } // -------------------------------------------------------------------- @@ -249,9 +247,7 @@ class CI_DB_interbase_driver extends CI_DB { return TRUE; } - @ibase_rollback($this->trans); - - return TRUE; + return @ibase_rollback($this->trans); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 125fe732c09f82a0702f29c9309f726bdd5a33c3 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 21 Feb 2012 07:58:25 -0500 Subject: More formatting fixes --- system/database/drivers/interbase/interbase_driver.php | 4 ++-- system/database/drivers/interbase/interbase_forge.php | 2 +- system/database/drivers/interbase/interbase_result.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php index 7258e605e..33038ad80 100644 --- a/system/database/drivers/interbase/interbase_driver.php +++ b/system/database/drivers/interbase/interbase_driver.php @@ -299,8 +299,8 @@ class CI_DB_interbase_driver extends CI_DB { /** * Insert ID * - * @param string $generator_name - * @param integer $inc_by + * @param string $generator_name + * @param integer $inc_by * @return integer */ public function insert_id($generator_name, $inc_by=0) diff --git a/system/database/drivers/interbase/interbase_forge.php b/system/database/drivers/interbase/interbase_forge.php index b8ea6a05d..023d278ce 100644 --- a/system/database/drivers/interbase/interbase_forge.php +++ b/system/database/drivers/interbase/interbase_forge.php @@ -82,7 +82,7 @@ class CI_DB_interbase_forge extends CI_DB_forge { $sql .= $this->db->protect_identifiers($table)."("; $current_field_count = 0; - foreach ($fields as $field=>$attributes) + 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 diff --git a/system/database/drivers/interbase/interbase_result.php b/system/database/drivers/interbase/interbase_result.php index be9cb6547..4b15eee20 100644 --- a/system/database/drivers/interbase/interbase_result.php +++ b/system/database/drivers/interbase/interbase_result.php @@ -265,7 +265,7 @@ class CI_DB_interbase_result extends CI_DB_result { { foreach ($this->result_object as $obj) { - $this->result_array[] = (array)$obj; + $this->result_array[] = (array) $obj; } return $this->result_array; -- cgit v1.2.3-24-g4f1b From 11454e039fd82f2fd4ee2f186ad0317e3435f187 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 22 Feb 2012 16:05:47 +0200 Subject: Add an optional database name parameter to db_select() --- system/database/drivers/mssql/mssql_driver.php | 10 +++++----- system/database/drivers/mysql/mysql_driver.php | 5 +++-- system/database/drivers/mysqli/mysqli_driver.php | 5 +++-- system/database/drivers/sqlsrv/sqlsrv_driver.php | 10 +++++----- 4 files changed, 16 insertions(+), 14 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 2a1098932..27b492f96 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -114,14 +114,14 @@ class CI_DB_mssql_driver extends CI_DB { /** * Select the database * - * @access private called by the base class - * @return resource + * @param string database name + * @return bool */ - function db_select() + public function db_select($database = '') { // Note: The brackets are required in the event that the DB name // contains reserved characters - return @mssql_select_db('['.$this->database.']', $this->conn_id); + return @mssql_select_db('['.($database == '' ? $this->database : $database).']', $this->conn_id); } // -------------------------------------------------------------------- @@ -676,4 +676,4 @@ class CI_DB_mssql_driver extends CI_DB { /* End of file mssql_driver.php */ -/* Location: ./system/database/drivers/mssql/mssql_driver.php */ \ No newline at end of file +/* Location: ./system/database/drivers/mssql/mssql_driver.php */ diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 067710ff0..207a68f14 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -119,11 +119,12 @@ class CI_DB_mysql_driver extends CI_DB { /** * Select the database * + * @param string database name * @return bool */ - public function db_select() + public function db_select($database = '') { - return @mysql_select_db($this->database, $this->conn_id); + return @mysql_select_db(($database == '' ? $this->database : $database), $this->conn_id); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index a79b2a4ad..0b80f55be 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -119,11 +119,12 @@ class CI_DB_mysqli_driver extends CI_DB { /** * Select the database * + * @param string database name * @return bool */ - public function db_select() + public function db_select($database = '') { - return @mysqli_select_db($this->conn_id, $this->database); + return @mysqli_select_db($this->conn_id, ($database == '' ? $this->database : $database)); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index 6fd52ef70..390840094 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -122,12 +122,12 @@ class CI_DB_sqlsrv_driver extends CI_DB { /** * Select the database * - * @access private called by the base class - * @return resource + * @param string database name + * @return bool */ - function db_select() + public function db_select($database = '') { - return $this->_execute('USE ' . $this->database); + return $this->_execute('USE '.($database == '' ? $this->database : $database)); } // -------------------------------------------------------------------- @@ -608,4 +608,4 @@ class CI_DB_sqlsrv_driver extends CI_DB { /* End of file mssql_driver.php */ -/* Location: ./system/database/drivers/mssql/mssql_driver.php */ \ No newline at end of file +/* Location: ./system/database/drivers/mssql/mssql_driver.php */ -- cgit v1.2.3-24-g4f1b From ab189e162f20f1a7daae8bfd2b921e694c3f9df3 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Wed, 22 Feb 2012 10:34:23 -0500 Subject: Close services after using them, added dbutil->backup() method --- .../database/drivers/interbase/interbase_driver.php | 3 +++ .../database/drivers/interbase/interbase_utility.php | 20 +++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php index 33038ad80..b49d1fa74 100644 --- a/system/database/drivers/interbase/interbase_driver.php +++ b/system/database/drivers/interbase/interbase_driver.php @@ -139,6 +139,9 @@ class CI_DB_interbase_driver extends CI_DB { if (($service = ibase_service_attach($this->hostname, $this->username, $this->password))) { $version = ibase_server_info($service, IBASE_SVC_SERVER_VERSION); + + // Don't keep the service open + ibase_service_detach($service); return $version; } diff --git a/system/database/drivers/interbase/interbase_utility.php b/system/database/drivers/interbase/interbase_utility.php index e31021acb..76a0497c1 100644 --- a/system/database/drivers/interbase/interbase_utility.php +++ b/system/database/drivers/interbase/interbase_utility.php @@ -90,14 +90,24 @@ class CI_DB_interbase_utility extends CI_DB_utility { /** * Interbase/Firebird Export * - * @param array Preferences + * @param string $filename * @return mixed */ - public function _backup($params = array()) + public function backup($filename) { - // Currently unsupported - // @todo See if can be implemented - return $this->db->display_error('db_unsuported_feature'); + if ($service = ibase_service_attach($this->db->hostname, $this->db->username, $this->db->password)) + { + $res = ibase_backup($service, $this->db->database, $filename.'.fbk'); + + //Close the service connection + ibase_service_detach($service); + + return $res; + } + else + { + return FALSE; + } } } -- cgit v1.2.3-24-g4f1b From 82e8ac19d0ffeb3edd56b09d7a272d13903af7cc Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 22 Feb 2012 19:35:34 +0200 Subject: Fix issue 1070 --- system/database/DB_driver.php | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index b829bbe46..271a70ec4 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -107,11 +107,9 @@ class CI_DB_driver { /** * Initialize Database Settings * - * @access private Called by the constructor - * @param mixed - * @return void + * @return bool */ - function initialize() + public function initialize() { // If an existing connection resource is available // there is no need to connect and select the database @@ -125,7 +123,7 @@ class CI_DB_driver { // Connect to the database and set the connection ID $this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect(); - // No connection resource? Check if there is a failover else throw an error + // No connection resource? Check if there is a failover else throw an error if ( ! $this->conn_id) { // Check if there is a failover set @@ -167,31 +165,19 @@ class CI_DB_driver { // ---------------------------------------------------------------- // Select the DB... assuming a database name is specified in the config file - if ($this->database != '') + if ($this->database !== '' && ! $this->db_select()) { - if ( ! $this->db_select()) - { - log_message('error', 'Unable to select database: '.$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; - } - else + 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)) - { - return FALSE; - } - - return TRUE; + $this->display_error('db_unable_to_select', $this->database); } + return FALSE; } - return TRUE; + // Now we set the character set and that's all + return $this->db_set_charset($this->char_set, $this->dbcollat); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 024ba2dffd49e26f68468acd69feebd685f63f68 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 24 Feb 2012 11:40:36 +0200 Subject: Update database property when switching to a new one --- system/database/drivers/mssql/mssql_driver.php | 13 ++++++++++++- system/database/drivers/mysql/mysql_driver.php | 13 ++++++++++++- system/database/drivers/mysqli/mysqli_driver.php | 13 ++++++++++++- system/database/drivers/sqlsrv/sqlsrv_driver.php | 13 ++++++++++++- 4 files changed, 48 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 27b492f96..25a32f364 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -119,9 +119,20 @@ class CI_DB_mssql_driver extends CI_DB { */ public function db_select($database = '') { + if ($database === '') + { + $database = $this->database; + } + // Note: The brackets are required in the event that the DB name // contains reserved characters - return @mssql_select_db('['.($database == '' ? $this->database : $database).']', $this->conn_id); + if (@mssql_select_db('['.$database.']', $this->conn_id)) + { + $this->database = $database; + return TRUE; + } + + return FALSE; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 207a68f14..c88a8a766 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -124,7 +124,18 @@ class CI_DB_mysql_driver extends CI_DB { */ public function db_select($database = '') { - return @mysql_select_db(($database == '' ? $this->database : $database), $this->conn_id); + if ($database === '') + { + $database = $this->database; + } + + if (@mysql_select_db($database, $this->conn_id)) + { + $this->database = $database; + return TRUE; + } + + return FALSE; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 0b80f55be..dbba12e15 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -124,7 +124,18 @@ class CI_DB_mysqli_driver extends CI_DB { */ public function db_select($database = '') { - return @mysqli_select_db($this->conn_id, ($database == '' ? $this->database : $database)); + if ($database === '') + { + $database = $this->database; + } + + if (@mysqli_select_db($this->conn_id, $database)) + { + $this->database = $database; + return TRUE; + } + + return FALSE; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index 390840094..9c50209ec 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -127,7 +127,18 @@ class CI_DB_sqlsrv_driver extends CI_DB { */ public function db_select($database = '') { - return $this->_execute('USE '.($database == '' ? $this->database : $database)); + if ($database === '') + { + $database = $this->database; + } + + if ($this->_execute('USE '.$database)) + { + $this->database = $database; + return TRUE; + } + + return FALSE; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 063f5963b01f9c19a2ed070d9e3aa077a2515c21 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 27 Feb 2012 12:20:52 +0200 Subject: Fixed a db_set_charset() bug --- system/database/DB_driver.php | 11 +++++------ system/database/drivers/cubrid/cubrid_driver.php | 20 +------------------- system/database/drivers/mssql/mssql_driver.php | 16 ---------------- system/database/drivers/oci8/oci8_driver.php | 16 ---------------- system/database/drivers/odbc/odbc_driver.php | 18 +----------------- system/database/drivers/pdo/pdo_driver.php | 17 +---------------- system/database/drivers/postgre/postgre_driver.php | 18 +----------------- system/database/drivers/sqlite/sqlite_driver.php | 18 +----------------- system/database/drivers/sqlsrv/sqlsrv_driver.php | 16 ---------------- 9 files changed, 10 insertions(+), 140 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 271a70ec4..f1e9e7239 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -185,20 +185,19 @@ class CI_DB_driver { /** * Set client character set * - * @access public * @param string * @param string - * @return resource + * @return bool */ - function db_set_charset($charset, $collation) + public function db_set_charset($charset, $collation = '') { - if ( ! $this->_db_set_charset($this->char_set, $this->dbcollat)) + if (method_exists($this, '_db_set_charset') && ! $this->_db_set_charset($charset, $collation)) { - log_message('error', 'Unable to set database connection charset: '.$this->char_set); + log_message('error', 'Unable to set database connection charset: '.$charset); if ($this->db_debug) { - $this->display_error('db_unable_to_set_charset', $this->char_set); + $this->display_error('db_unable_to_set_charset', $charset); } return FALSE; diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php index cde719eae..a589ded0c 100644 --- a/system/database/drivers/cubrid/cubrid_driver.php +++ b/system/database/drivers/cubrid/cubrid_driver.php @@ -155,24 +155,6 @@ class CI_DB_cubrid_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * Set client character set - * - * @access public - * @param string - * @param string - * @return resource - */ - function db_set_charset($charset, $collation) - { - // In CUBRID, there is no need to set charset or collation. - // This is why returning true will allow the application continue - // its normal process. - return TRUE; - } - - // -------------------------------------------------------------------- - /** * Version number query string * @@ -801,4 +783,4 @@ class CI_DB_cubrid_driver extends CI_DB { /* End of file cubrid_driver.php */ -/* Location: ./system/database/drivers/cubrid/cubrid_driver.php */ \ No newline at end of file +/* Location: ./system/database/drivers/cubrid/cubrid_driver.php */ diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 25a32f364..2a4f2b575 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -137,22 +137,6 @@ 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 * diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index c6621901b..292ccd0fd 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -138,22 +138,6 @@ class CI_DB_oci8_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * Set client character set - * - * @access public - * @param string - * @param string - * @return resource - */ - public function db_set_charset($charset, $collation) - { - // this is done upon connect - return TRUE; - } - - // -------------------------------------------------------------------- - /** * Version number query string * diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 6ba39f0cd..abb660324 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -123,22 +123,6 @@ 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 * @@ -646,4 +630,4 @@ class CI_DB_odbc_driver extends CI_DB { /* End of file odbc_driver.php */ -/* Location: ./system/database/drivers/odbc/odbc_driver.php */ \ No newline at end of file +/* Location: ./system/database/drivers/odbc/odbc_driver.php */ diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index de2b0abeb..fea54e502 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -288,21 +288,6 @@ class CI_DB_pdo_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * Set client character set - * - * @access public - * @param string - * @param string - * @return resource - */ - function db_set_charset($charset, $collation) - { - return TRUE; - } - - // -------------------------------------------------------------------- - /** * Version number query string * @@ -950,4 +935,4 @@ class CI_DB_pdo_driver extends CI_DB { } /* End of file pdo_driver.php */ -/* Location: ./system/database/drivers/pdo/pdo_driver.php */ \ No newline at end of file +/* Location: ./system/database/drivers/pdo/pdo_driver.php */ diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 42329bded..89541e5fa 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -146,22 +146,6 @@ 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 * @@ -712,4 +696,4 @@ class CI_DB_postgre_driver extends CI_DB { /* End of file postgre_driver.php */ -/* Location: ./system/database/drivers/postgre/postgre_driver.php */ \ No newline at end of file +/* Location: ./system/database/drivers/postgre/postgre_driver.php */ diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 28c3caecd..718501b20 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -140,22 +140,6 @@ 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 * @@ -667,4 +651,4 @@ class CI_DB_sqlite_driver extends CI_DB { /* End of file sqlite_driver.php */ -/* Location: ./system/database/drivers/sqlite/sqlite_driver.php */ \ No newline at end of file +/* Location: ./system/database/drivers/sqlite/sqlite_driver.php */ diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index 9c50209ec..ba886f1fe 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -143,22 +143,6 @@ class CI_DB_sqlsrv_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 * -- cgit v1.2.3-24-g4f1b From 56784f67c35c75b706c5f9fc2950e58356e7ecec Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Wed, 29 Feb 2012 11:58:20 -0500 Subject: Finally figured out limit statement --- .../drivers/interbase/interbase_driver.php | 26 +++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php index b49d1fa74..e55a476bb 100644 --- a/system/database/drivers/interbase/interbase_driver.php +++ b/system/database/drivers/interbase/interbase_driver.php @@ -601,7 +601,31 @@ SQL; */ protected function _limit($sql, $limit, $offset) { - //There doesn't seem to be a limit clause? + // Keep the current sql string safe for a moment + $orig_sql = $sql; + + // Limit clause depends on if Interbase or Firebird + if (stripos($this->_version(), 'firebird') !== FALSE) + { + $sql = 'FIRST '. (int) $limit; + + if ($offset > 0) + { + $sql .= ' SKIP'. (int) $offset; + } + } + else + { + $sql = 'ROWS ' . (int) $limit; + + if ($offset > 0) + { + $sql = 'ROWS '. (int) $offset . ' TO ' . ($limit + $offset); + } + } + + $sql = preg_replace("`SELECT`i", "SELECT {$sql}", $orig_sql); + return $sql; } -- cgit v1.2.3-24-g4f1b From db0c06247949a4def38bcb0c0cf1239312140a81 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 29 Feb 2012 19:02:46 +0200 Subject: Change end() usage due to E_STRICT messages --- 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 424735157..eaae23f30 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -236,7 +236,8 @@ class CI_DB_active_record extends CI_DB_driver { { if (strpos($item, '.') !== FALSE) { - return end(explode('.', $item)); + $item = explode('.', $item); + return end($item); } return $item; -- cgit v1.2.3-24-g4f1b From 9a96082726feadadd50aef1287b4e0df61414c0d Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Wed, 29 Feb 2012 22:53:35 -0500 Subject: Fix 'skip' section of limit clause --- system/database/drivers/interbase/interbase_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php index e55a476bb..4dca7c8a9 100644 --- a/system/database/drivers/interbase/interbase_driver.php +++ b/system/database/drivers/interbase/interbase_driver.php @@ -611,7 +611,7 @@ SQL; if ($offset > 0) { - $sql .= ' SKIP'. (int) $offset; + $sql .= ' SKIP '. (int) $offset; } } else -- cgit v1.2.3-24-g4f1b From c2905f5884a7d9cd9ae1f70cdc615a5d214652dd Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Mar 2012 14:39:26 +0200 Subject: Fix an Oracle escape_str() bug (#68, #414) --- system/database/drivers/oci8/oci8_driver.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index c6621901b..057095c23 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -398,10 +398,9 @@ class CI_DB_oci8_driver extends CI_DB { /** * Escape String * - * @access public - * @param string + * @param string * @param bool whether or not the string will be used in a LIKE condition - * @return string + * @return string */ public function escape_str($str, $like = FALSE) { @@ -415,15 +414,14 @@ class CI_DB_oci8_driver extends CI_DB { return $str; } - $str = remove_invisible_characters($str); - $str = str_replace("'", "''", $str); + $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_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 41e46a97a43b0d5080bb9ace1b9326266955ef21 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Mar 2012 14:58:17 +0200 Subject: Fix issue #81 (ODBC list_fields(), field_data()) --- system/database/drivers/odbc/odbc_result.php | 38 ++++++++++++++-------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index ba660856e..bfd6949eb 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -54,10 +54,9 @@ class CI_DB_odbc_result extends CI_DB_result { /** * Number of fields in the result set * - * @access public - * @return integer + * @return int */ - function num_fields() + public function num_fields() { return @odbc_num_fields($this->result_id); } @@ -69,15 +68,19 @@ class CI_DB_odbc_result extends CI_DB_result { * * Generates an array of column names * - * @access public * @return array */ - function list_fields() + public function list_fields() { $field_names = array(); - for ($i = 0; $i < $this->num_fields(); $i++) + $num_fields = $this->num_fields(); + + if ($num_fields > 0) { - $field_names[] = odbc_field_name($this->result_id, $i); + for ($i = 1; $i <= $num_fields; $i++) + { + $field_names[] = odbc_field_name($this->result_id, $i); + } } return $field_names; @@ -90,22 +93,19 @@ class CI_DB_odbc_result extends CI_DB_result { * * Generates an array of objects containing field meta-data * - * @access public * @return array */ - function field_data() + public function field_data() { $retval = array(); - for ($i = 0; $i < $this->num_fields(); $i++) + for ($i = 0, $odbc_index = 1, $c = $this->num_fields(); $i < $c; $i++, $odbc_index++) { - $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; + $retval[$i] = new stdClass(); + $retval[$i]->name = odbc_field_name($this->result_id, $odbc_index); + $retval[$i]->type = odbc_field_type($this->result_id, $odbc_index); + $retval[$i]->max_length = odbc_field_len($this->result_id, $odbc_index); + $retval[$i]->primary_key = 0; + $retval[$i]->default = ''; } return $retval; @@ -237,4 +237,4 @@ class CI_DB_odbc_result extends CI_DB_result { /* End of file odbc_result.php */ -/* Location: ./system/database/drivers/odbc/odbc_result.php */ \ No newline at end of file +/* Location: ./system/database/drivers/odbc/odbc_result.php */ -- cgit v1.2.3-24-g4f1b From ef795ac23320c4636152af03c8600f2115f1e6e3 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Mar 2012 15:15:31 +0200 Subject: Fix issue #129 (ODBC num_rows() returning -1 in some cases) --- system/database/drivers/odbc/odbc_result.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index bfd6949eb..572e110ca 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -38,15 +38,27 @@ */ class CI_DB_odbc_result extends CI_DB_result { + public $num_rows; + /** * Number of rows in the result set * - * @access public - * @return integer + * @return int */ - function num_rows() + public function num_rows() { - return @odbc_num_rows($this->result_id); + if (is_int($this->num_rows)) + { + return $this->num_rows; + } + + // Work-around for ODBC subdrivers that don't support num_rows() + if (($this->num_rows = @odbc_num_rows($this->result_id)) === -1) + { + $this->num_rows = count($this->result_array()); + } + + return $this->num_rows; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 850f601edef5de5680510c900c3e613bc346fe1b Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Mar 2012 15:58:25 +0200 Subject: Fix issue #611 (SQLSRV _error_message() and _error_number() warnings) --- system/database/drivers/sqlsrv/sqlsrv_driver.php | 35 ++++++++++++++++++------ 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index 9c50209ec..e4fd90240 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -424,13 +424,18 @@ class CI_DB_sqlsrv_driver extends CI_DB { /** * The error message string * - * @access private * @return string */ - function _error_message() + protected function _error_message() { - $error = array_shift(sqlsrv_errors()); - return !empty($error['message']) ? $error['message'] : null; + $error = sqlsrv_errors(); + if ( ! is_array($error)) + { + return ''; + } + + $error = array_shift($error); + return isset($error['message']) ? $error['message'] : ''; } // -------------------------------------------------------------------- @@ -438,13 +443,25 @@ class CI_DB_sqlsrv_driver extends CI_DB { /** * The error message number * - * @access private - * @return integer + * @return string */ - function _error_number() + protected function _error_number() { - $error = array_shift(sqlsrv_errors()); - return isset($error['SQLSTATE']) ? $error['SQLSTATE'] : null; + $error = sqlsrv_errors(); + if ( ! is_array($error)) + { + return ''; + } + elseif (isset($error['SQLSTATE'])) + { + return isset($error['code']) ? $error['SQLSTATE'].'/'.$error['code'] : $error['SQLSTATE']; + } + elseif (isset($error['code'])) + { + return $error['code']; + } + + return ''; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 67f71a415c4bd7a206fcfc1a6007d74af4590883 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Mar 2012 16:18:42 +0200 Subject: Fix issue #1036 (is_write_type() returned FALSE for RENAME, OPTIMIZE queries) --- system/database/DB_driver.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 6352c731e..8ab5415ea 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -645,17 +645,12 @@ class CI_DB_driver { /** * Determines if a query is a "write" type. * - * @access public * @param string An SQL query string - * @return boolean + * @return bool */ - function is_write_type($sql) + public 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)) - { - return FALSE; - } - return TRUE; + return (bool) preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD DATA|COPY|ALTER|RENAME|GRANT|REVOKE|LOCK|UNLOCK|OPTIMIZE)\s+/i', $sql); } // -------------------------------------------------------------------- @@ -1443,4 +1438,4 @@ class CI_DB_driver { } /* End of file DB_driver.php */ -/* Location: ./system/database/DB_driver.php */ \ No newline at end of file +/* Location: ./system/database/DB_driver.php */ -- cgit v1.2.3-24-g4f1b From ed7408282e9fded97ade222f98b43623a0f17d22 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Mar 2012 16:37:08 +0200 Subject: Fix PDO's _version() method where it used to return client version instead of the server one --- system/database/drivers/pdo/pdo_driver.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index de2b0abeb..44e93a042 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -306,12 +306,11 @@ class CI_DB_pdo_driver extends CI_DB { /** * Version number query string * - * @access public * @return string */ - function _version() + protected function _version() { - return $this->conn_id->getAttribute(PDO::ATTR_CLIENT_VERSION); + return $this->conn_id->getAttribute(PDO::ATTR_SERVER_VERSION); } // -------------------------------------------------------------------- @@ -950,4 +949,4 @@ class CI_DB_pdo_driver extends CI_DB { } /* End of file pdo_driver.php */ -/* Location: ./system/database/drivers/pdo/pdo_driver.php */ \ No newline at end of file +/* Location: ./system/database/drivers/pdo/pdo_driver.php */ -- cgit v1.2.3-24-g4f1b From a39d699f90feb359ab994b3d77d71006060afecc Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Mar 2012 19:11:39 +0200 Subject: Fix a bug in PDO's insert_id() (PostgreSQL-specific) --- system/database/drivers/pdo/pdo_driver.php | 32 +++++++++--------------------- 1 file changed, 9 insertions(+), 23 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 44e93a042..dd803aba1 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -509,33 +509,19 @@ class CI_DB_pdo_driver extends CI_DB { /** * Insert ID - * - * @access public - * @return integer + * + * @return int */ - function insert_id($name=NULL) + public function insert_id($name = NULL) { - if ($this->pdodriver == 'pgsql') - { - //Convenience method for postgres insertid - $v = $this->_version(); - - $table = func_num_args() > 0 ? func_get_arg(0) : NULL; - - if ($table == NULL && $v >= '8.1') - { - $sql='SELECT LASTVAL() as ins_id'; - } - - $query = $this->query($sql); - $row = $query->row(); - - return $row->ins_id; - } - else + if ($this->pdodriver === 'pgsql' && $name === NULL && $this->_version() >= '8.1') { - return $this->conn_id->lastInsertId($name); + $query = $this->query('SELECT LASTVAL() AS ins_id'); + $query = $query->row(); + return $query->ins_id; } + + return $this->conn_id->lastInsertId($name); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From ea3eec9f670ea861a65a3e251d8c518ff47e2506 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Mar 2012 19:16:23 +0200 Subject: Fixed a bug in CUBRID's affected_rows() --- system/database/drivers/cubrid/cubrid_driver.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php index cde719eae..8738a2e87 100644 --- a/system/database/drivers/cubrid/cubrid_driver.php +++ b/system/database/drivers/cubrid/cubrid_driver.php @@ -362,12 +362,11 @@ class CI_DB_cubrid_driver extends CI_DB { /** * Affected Rows * - * @access public - * @return integer + * @return int */ - function affected_rows() + public function affected_rows() { - return @cubrid_affected_rows($this->conn_id); + return @cubrid_affected_rows(); } // -------------------------------------------------------------------- @@ -801,4 +800,4 @@ class CI_DB_cubrid_driver extends CI_DB { /* End of file cubrid_driver.php */ -/* Location: ./system/database/drivers/cubrid/cubrid_driver.php */ \ No newline at end of file +/* Location: ./system/database/drivers/cubrid/cubrid_driver.php */ -- cgit v1.2.3-24-g4f1b From 601f8b209d93fe70786776d9170eed5e23201e58 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Mar 2012 20:11:15 +0200 Subject: Fix issue #413 (Oracle _error_message(), _error_number()) --- system/database/drivers/oci8/oci8_driver.php | 38 ++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 8 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index d9acaaea6..6da6dc724 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -529,13 +529,11 @@ class CI_DB_oci8_driver extends CI_DB { /** * The error message string * - * @access protected - * @return string + * @return string */ protected function _error_message() { - // If the error was during connection, no conn_id should be passed - $error = is_resource($this->conn_id) ? oci_error($this->conn_id) : oci_error(); + $error = $this->_oci8_error_data(); return $error['message']; } @@ -544,18 +542,42 @@ class CI_DB_oci8_driver extends CI_DB { /** * The error message number * - * @access protected - * @return integer + * @return string */ protected function _error_number() { - // Same as _error_message() - $error = is_resource($this->conn_id) ? oci_error($this->conn_id) : oci_error(); + $error = $this->_oci8_error_data(); return $error['code']; } // -------------------------------------------------------------------- + /** + * OCI8-specific method to get errors. + * Used by _error_message() and _error_code(). + * + * @return array + */ + protected function _oci8_error_data() + { + if (is_resource($this->curs_id)) + { + return oci_error($this->curs_id); + } + elseif (is_resource($this->stmt_id)) + { + return oci_error($this->stmt_id); + } + elseif (is_resource($this->conn_id)) + { + return oci_error($this->conn_id); + } + + return oci_error(); + } + + // -------------------------------------------------------------------- + /** * Escape the SQL Identifiers * -- cgit v1.2.3-24-g4f1b From ef7474c6ca9887283c964e17c450ca09559643c4 Mon Sep 17 00:00:00 2001 From: Ryan Dial Date: Thu, 1 Mar 2012 16:11:36 -0500 Subject: compile binds before caching the query, otherwise the cached query will never match the unbound query. updated changlog to mention bug fix. --- system/database/DB_driver.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 4dfb584f2..6161f149b 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -265,6 +265,12 @@ class CI_DB_driver { $sql = preg_replace("/(\W)".$this->swap_pre."(\S+?)/", "\\1".$this->dbprefix."\\2", $sql); } + // Compile binds if needed + if ($binds !== FALSE) + { + $sql = $this->compile_binds($sql, $binds); + } + // 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 @@ -280,12 +286,6 @@ class CI_DB_driver { } } - // Compile binds if needed - if ($binds !== FALSE) - { - $sql = $this->compile_binds($sql, $binds); - } - // Save the query for debugging if ($this->save_queries == TRUE) { -- cgit v1.2.3-24-g4f1b From effd0133b3fa805e21ec934196e8e7d75608ba00 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 2 Mar 2012 12:34:54 +0200 Subject: Fix issue #1101 (MySQL/MySQLi result field_data()) --- system/database/drivers/mysql/mysql_result.php | 18 +++++++----------- system/database/drivers/mysqli/mysqli_result.php | 19 ++++++++----------- 2 files changed, 15 insertions(+), 22 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index 8f04a936d..5a65d9c72 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -90,18 +90,14 @@ class CI_DB_mysql_result extends CI_DB_result { public function field_data() { $retval = array(); - while ($field = mysql_fetch_object($this->result_id)) + for ($i = 0, $c = $this->num_fields(); $i < $c; $i++) { - preg_match('/([a-zA-Z]+)(\(\d+\))?/', $field->Type, $matches); - - $F = new stdClass(); - $F->name = $field->Field; - $F->type = ( ! empty($matches[1])) ? $matches[1] : NULL; - $F->default = $field->Default; - $F->max_length = ( ! empty($matches[2])) ? preg_replace('/[^\d]/', '', $matches[2]) : NULL; - $F->primary_key = (int) ($field->Key === 'PRI'); - - $retval[] = $F; + $retval[$i] = new stdClass(); + $retval[$i]->name = mysql_field_name($this->result_id, $i); + $retval[$i]->type = mysql_field_type($this->result_id, $i); + $retval[$i]->max_length = mysql_field_len($this->result_id, $i); + $retval[$i]->primary_key = (strpos(mysql_field_flags($this->result_id, $i), 'primary_key') === FALSE) ? 0 : 1; + $retval[$i]->default = ''; } return $retval; diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index 0a50cccac..8b909cc56 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -90,18 +90,15 @@ class CI_DB_mysqli_result extends CI_DB_result { public function field_data() { $retval = array(); - while ($field = mysqli_fetch_object($this->result_id)) + $field_data = mysqli_fetch_fields($this->result_id); + for ($i = 0, $c = count($field_data); $i < $c; $i++) { - preg_match('/([a-zA-Z]+)(\(\d+\))?/', $field->Type, $matches); - - $F = new stdClass(); - $F->name = $field->Field; - $F->type = ( ! empty($matches[1])) ? $matches[1] : NULL; - $F->default = $field->Default; - $F->max_length = ( ! empty($matches[2])) ? preg_replace('/[^\d]/', '', $matches[2]) : NULL; - $F->primary_key = (int) ($field->Key === 'PRI'); - - $retval[] = $F; + $retval[$i] = new stdClass(); + $retval[$i]->name = $field_data[$i]->name; + $retval[$i]->type = $field_data[$i]->type; + $retval[$i]->max_length = $field_data[$i]->max_length; + $retval[$i]->primary_key = (int) ($field_data[$i]->flags & 2); + $retval[$i]->default = ''; } return $retval; -- cgit v1.2.3-24-g4f1b From 8f22057724dd8fe2b9d41ba98bfc4da282572c5e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 2 Mar 2012 13:05:45 +0200 Subject: Fix a bug in Oracle's DB forge _create_table() method (AUTO_INCREMENT is not supported) --- system/database/drivers/oci8/oci8_forge.php | 64 ++++++++--------------------- 1 file changed, 17 insertions(+), 47 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index b4a24cdca..0aa119907 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -67,15 +67,14 @@ class CI_DB_oci8_forge extends CI_DB_forge { /** * 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 + * @param bool should 'IF NOT EXISTS' be added to the SQL * @return bool */ - function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) + public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) { $sql = 'CREATE TABLE '; @@ -84,54 +83,27 @@ class CI_DB_oci8_forge extends CI_DB_forge { $sql .= 'IF NOT EXISTS '; } - $sql .= $this->db->_escape_identifiers($table)." ("; + $sql .= $this->db->_escape_identifiers($table).' ('; $current_field_count = 0; - foreach ($fields as $field=>$attributes) + 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"; + $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'; - } + $sql .= "\n\t".$this->db->protect_identifiers($field).' '.$attributes['TYPE'] + .((isset($attributes['UNSINGED']) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '') + .(isset($attributes['DEFAULT']) ? " DEFAULT '".$attributes['DEFAULT']."'" : '') + .((isset($attributes['NULL']) && $attributes['NULL'] === TRUE) ? '' : ' NOT NULL') + .(isset($attributes['CONSTRAINT']) ? ' CONSTRAINT '.$attributes['CONSTRAINT'] : ''); } // don't add a comma on the end of the last field @@ -143,8 +115,8 @@ class CI_DB_oci8_forge extends CI_DB_forge { if (count($primary_keys) > 0) { - $primary_keys = $this->db->_protect_identifiers($primary_keys); - $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; + $primary_keys = $this->db->protect_identifiers($primary_keys); + $sql .= ",\n\tCONSTRAINT ".$table.' PRIMARY KEY ('.implode(', ', $primary_keys).')'; } if (is_array($keys) && count($keys) > 0) @@ -153,20 +125,18 @@ 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)); + $key = array($this->db->protect_identifiers($key)); } - $sql .= ",\n\tUNIQUE COLUMNS (" . implode(', ', $key) . ")"; + $sql .= ",\n\tUNIQUE COLUMNS (".implode(', ', $key).")"; } } - $sql .= "\n)"; - - return $sql; + return $sql."\n)"; } // -------------------------------------------------------------------- @@ -257,4 +227,4 @@ class CI_DB_oci8_forge extends CI_DB_forge { } /* End of file oci8_forge.php */ -/* Location: ./system/database/drivers/oci8/oci8_forge.php */ \ No newline at end of file +/* Location: ./system/database/drivers/oci8/oci8_forge.php */ -- cgit v1.2.3-24-g4f1b From bcb3bbb97c8c046f80009a2bd8dffb96795ed239 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 2 Mar 2012 13:56:15 +0200 Subject: Added method visibility declarations to SQLite DB utility class --- system/database/drivers/sqlite/sqlite_utility.php | 41 +++++++++-------------- 1 file changed, 15 insertions(+), 26 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/sqlite/sqlite_utility.php b/system/database/drivers/sqlite/sqlite_utility.php index f00687e38..8fefcd9e2 100644 --- a/system/database/drivers/sqlite/sqlite_utility.php +++ b/system/database/drivers/sqlite/sqlite_utility.php @@ -1,13 +1,13 @@ -db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return array(); + return ($this->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE; } // -------------------------------------------------------------------- @@ -61,14 +54,12 @@ class CI_DB_sqlite_utility extends CI_DB_utility { /** * Optimize table query * - * Is optimization even supported in SQLite? - * - * @access private * @param string the table name - * @return object + * @return bool */ - function _optimize_table($table) + public function _optimize_table($table) { + // Not supported return FALSE; } @@ -77,14 +68,12 @@ class CI_DB_sqlite_utility extends CI_DB_utility { /** * Repair table query * - * Are table repairs even supported in SQLite? - * - * @access private * @param string the table name - * @return object + * @return bool */ - function _repair_table($table) + public function _repair_table($table) { + // Not supported return FALSE; } @@ -93,16 +82,16 @@ class CI_DB_sqlite_utility extends CI_DB_utility { /** * SQLite Export * - * @access private * @param array Preferences * @return mixed */ - function _backup($params = array()) + public function _backup($params = array()) { // Currently unsupported return $this->db->display_error('db_unsuported_feature'); } + } /* End of file sqlite_utility.php */ -/* Location: ./system/database/drivers/sqlite/sqlite_utility.php */ \ No newline at end of file +/* Location: ./system/database/drivers/sqlite/sqlite_utility.php */ -- cgit v1.2.3-24-g4f1b From 4be5de1d11eefd9f0b7cf0589a2942f067cefe35 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 2 Mar 2012 15:45:41 +0200 Subject: Replaced DB methods _error_message() and _error_number() with error() (issue #1097) --- system/database/DB_driver.php | 22 +++++----- system/database/drivers/cubrid/cubrid_driver.php | 25 +++--------- system/database/drivers/mssql/mssql_driver.php | 26 ++++-------- system/database/drivers/mysql/mysql_driver.php | 21 +++------- system/database/drivers/mysqli/mysqli_driver.php | 21 +++------- system/database/drivers/oci8/oci8_driver.php | 35 ++++------------ system/database/drivers/odbc/odbc_driver.php | 23 +++-------- system/database/drivers/pdo/pdo_driver.php | 35 ++++++++-------- system/database/drivers/postgre/postgre_driver.php | 23 +++-------- system/database/drivers/sqlite/sqlite_driver.php | 25 ++++-------- system/database/drivers/sqlsrv/sqlsrv_driver.php | 47 +++++++++------------- 11 files changed, 101 insertions(+), 202 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 5f435e363..03a222f9b 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -330,30 +330,28 @@ class CI_DB_driver { // This will trigger a rollback if transactions are being used $this->_trans_status = FALSE; - // 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(); + // Grab the error now, as we might run some additional queries before displaying the error + $error = $this->error(); // Log errors - log_message('error', 'Query error: '.$error_msg); + log_message('error', 'Query error: '.$error['message']); 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 + // 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(); // Display errors return $this->display_error( - array( - 'Error Number: '.$error_no, - $error_msg, - $sql - ) - ); + array( + 'Error Number: '.$error['code'], + $error['message'], + $sql + ) + ); } return FALSE; diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php index 42f08fbf6..cb33919a4 100644 --- a/system/database/drivers/cubrid/cubrid_driver.php +++ b/system/database/drivers/cubrid/cubrid_driver.php @@ -453,31 +453,18 @@ class CI_DB_cubrid_driver extends CI_DB { // -------------------------------------------------------------------- /** - * The error message string + * Error * - * @access private - * @return string - */ - function _error_message() - { - return cubrid_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number + * Returns an array containing code and message of the last + * database error that has occured. * - * @access private - * @return integer + * @return array */ - function _error_number() + public function error() { - return cubrid_errno($this->conn_id); + return array('code' => cubrid_errno($this->conn_id), 'message' => cubrid_error($this->conn_id)); } - // -------------------------------------------------------------------- - /** * Escape the SQL Identifiers * diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 2a4f2b575..188c91f9b 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -438,28 +438,18 @@ class CI_DB_mssql_driver extends CI_DB { // -------------------------------------------------------------------- /** - * The error message string + * Error * - * @access private - * @return string - */ - function _error_message() - { - return mssql_get_last_message(); - } - - // -------------------------------------------------------------------- - - /** - * The error message number + * Returns an array containing code and message of the last + * database error that has occured. * - * @access private - * @return integer + * @return array */ - function _error_number() + public function error() { - // Are error numbers supported? - return ''; + $query = $this->query('SELECT @@ERROR AS code'); + $query = $query->row(); + return array('code' => $query->code, 'message' => mssql_get_last_message()); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index c88a8a766..a7f08d1a8 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -417,25 +417,16 @@ class CI_DB_mysql_driver extends CI_DB { // -------------------------------------------------------------------- /** - * The error message string + * Error * - * @return string - */ - protected function _error_message() - { - return mysql_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number + * Returns an array containing code and message of the last + * database error that has occured. * - * @return int + * @return array */ - protected function _error_number() + public function error() { - return mysql_errno($this->conn_id); + return array('code' => mysql_errno($this->conn_id), 'message' => mysql_error($this->conn_id)); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index dbba12e15..031371345 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -418,25 +418,16 @@ class CI_DB_mysqli_driver extends CI_DB { // -------------------------------------------------------------------- /** - * The error message string + * Error * - * @return string - */ - protected function _error_message() - { - return mysqli_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number + * Returns an array containing code and message of the last + * database error that has occured. * - * @return int + * @return array */ - protected function _error_number() + public function error() { - return mysqli_errno($this->conn_id); + return array('code' => mysqli_errno($this->conn_id), 'message' => mysqli_error($this->conn_id)); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 6da6dc724..97efb4647 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -527,39 +527,18 @@ class CI_DB_oci8_driver extends CI_DB { // -------------------------------------------------------------------- /** - * The error message string + * Error * - * @return string - */ - protected function _error_message() - { - $error = $this->_oci8_error_data(); - return $error['message']; - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @return string - */ - protected function _error_number() - { - $error = $this->_oci8_error_data(); - return $error['code']; - } - - // -------------------------------------------------------------------- - - /** - * OCI8-specific method to get errors. - * Used by _error_message() and _error_code(). + * Returns an array containing code and message of the last + * database error that has occured. * * @return array */ - protected function _oci8_error_data() + public function error() { + /* oci_error() returns an array that already contains the + * 'code' and 'message' keys, so we can just return it. + */ if (is_resource($this->curs_id)) { return oci_error($this->curs_id); diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index abb660324..5a93f7cad 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -398,27 +398,16 @@ class CI_DB_odbc_driver extends CI_DB { // -------------------------------------------------------------------- /** - * The error message string + * Error * - * @access private - * @return string - */ - function _error_message() - { - return odbc_errormsg($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number + * Returns an array containing code and message of the last + * database error that has occured. * - * @access private - * @return integer + * @return array */ - function _error_number() + public function error() { - return odbc_error($this->conn_id); + return array('code' => odbc_error($this->conn_id), 'message' => odbc_errormsg($this->conn_id)); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 90f0fd791..de5e1f05e 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -609,29 +609,30 @@ class CI_DB_pdo_driver extends CI_DB { // -------------------------------------------------------------------- /** - * The error message string + * Error * - * @access private - * @return string + * Returns an array containing code and message of the last + * database error that has occured. + * + * @return array */ - function _error_message() + public function error() { - $error_array = $this->conn_id->errorInfo(); + $error = array('code' => '00000', 'message' => ''); + $pdo_error = $this->conn_id->errorInfo(); - return $error_array[2]; - } + if (empty($pdo_error[0])) + { + return $error; + } - // -------------------------------------------------------------------- + $error['code'] = isset($pdo_error[1]) ? $pdo_error[0].'/'.$pdo_error[1] : $pdo_error[0]; + if (isset($pdo_error[2])) + { + $error['message'] = $pdo_error[2]; + } - /** - * The error message number - * - * @access private - * @return integer - */ - function _error_number() - { - return $this->conn_id->errorCode(); + return $error; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 89541e5fa..0fcd954e9 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -443,27 +443,16 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- /** - * The error message string + * Error * - * @access private - * @return string - */ - function _error_message() - { - return pg_last_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number + * Returns an array containing code and message of the last + * database error that has occured. * - * @access private - * @return integer + * @return array */ - function _error_number() + public function error() { - return ''; + return array('code' => '', 'message' => pg_last_error($this->conn_id)); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 718501b20..3e4b37320 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -412,27 +412,18 @@ class CI_DB_sqlite_driver extends CI_DB { // -------------------------------------------------------------------- /** - * The error message string + * Error * - * @access private - * @return string - */ - function _error_message() - { - return sqlite_error_string(sqlite_last_error($this->conn_id)); - } - - // -------------------------------------------------------------------- - - /** - * The error message number + * Returns an array containing code and message of the last + * database error that has occured. * - * @access private - * @return integer + * @return array */ - function _error_number() + public function error() { - return sqlite_last_error($this->conn_id); + $error = array('code' => sqlite_last_error($this->conn_id)); + $error['message'] = sqlite_error_string($error['code']); + return $error; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index 9b9038189..03d7c7199 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -406,46 +406,39 @@ class CI_DB_sqlsrv_driver extends CI_DB { // -------------------------------------------------------------------- /** - * The error message string + * Error * - * @return string + * Returns an array containing code and message of the last + * database error that has occured. + * + * @return array */ - protected function _error_message() + public function error() { - $error = sqlsrv_errors(); - if ( ! is_array($error)) + $error = array('code' => '00000', 'message' => ''); + $sqlsrv_errors = sqlsrv_errors(SQLSRV_ERR_ERRORS); + + if ( ! is_array($sqlsrv_errors)) { - return ''; + return $error; } - $error = array_shift($error); - return isset($error['message']) ? $error['message'] : ''; - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @return string - */ - protected function _error_number() - { - $error = sqlsrv_errors(); - if ( ! is_array($error)) + $sqlsrv_error = array_shift($sqlsrv_errors); + if (isset($sqlsrv_error['SQLSTATE'])) { - return ''; + $error['code'] = isset($sqlsrv_error['code']) ? $sqlsrv_error['SQLSTATE'].'/'.$sqlsrv_error['code'] : $sqlsrv_error['SQLSTATE']; } - elseif (isset($error['SQLSTATE'])) + elseif (isset($sqlsrv_error['code'])) { - return isset($error['code']) ? $error['SQLSTATE'].'/'.$error['code'] : $error['SQLSTATE']; + $error['code'] = $sqlsrv_error['code']; } - elseif (isset($error['code'])) + + if (isset($sqlsrv_error['message'])) { - return $error['code']; + $error['message'] = $sqlsrv_error['message']; } - return ''; + return $error; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 00df2e3183dc1cbef82dafe6cc432d73fe659ae9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 2 Mar 2012 18:37:16 +0200 Subject: Replace Interbase _error_message(), _error_number() with the new error() method --- .../drivers/interbase/interbase_driver.php | 48 +++++++++------------- 1 file changed, 19 insertions(+), 29 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php index 4dca7c8a9..17fcffa65 100644 --- a/system/database/drivers/interbase/interbase_driver.php +++ b/system/database/drivers/interbase/interbase_driver.php @@ -58,7 +58,7 @@ class CI_DB_interbase_driver extends CI_DB { */ protected $_count_string = "SELECT COUNT(*) AS "; protected $_random_keyword = ' Random()'; // database specific random keyword - + // Keeps track of the resource for the current transaction protected $trans; @@ -139,12 +139,12 @@ class CI_DB_interbase_driver extends CI_DB { if (($service = ibase_service_attach($this->hostname, $this->username, $this->password))) { $version = ibase_server_info($service, IBASE_SVC_SERVER_VERSION); - + // Don't keep the service open ibase_service_detach($service); return $version; } - + return FALSE; } @@ -203,7 +203,7 @@ class CI_DB_interbase_driver extends CI_DB { $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; $this->trans = @ibase_trans($this->conn_id); - + return TRUE; } @@ -226,7 +226,7 @@ class CI_DB_interbase_driver extends CI_DB { { return TRUE; } - + return @ibase_commit($this->trans); } @@ -398,7 +398,7 @@ SQL; protected function _field_data($table) { // Need to find a more efficient way to do this - // but Interbase/Firebird seems to lack the + // but Interbase/Firebird seems to lack the // limit clause return "SELECT * FROM {$table}"; } @@ -406,25 +406,16 @@ SQL; // -------------------------------------------------------------------- /** - * The error message string + * Error * - * @return string - */ - protected function _error_message() - { - return ibase_errmsg(); - } - - // -------------------------------------------------------------------- - - /** - * The error message number + * Returns an array containing code and message of the last + * database error that has occured. * - * @return integer + * @return array */ - protected function _error_number() + public function error() { - return ibase_errcode(); + return array('code' => ibase_errcode(), 'message' => ibase_errmsg()); } // -------------------------------------------------------------------- @@ -603,12 +594,12 @@ SQL; { // Keep the current sql string safe for a moment $orig_sql = $sql; - + // Limit clause depends on if Interbase or Firebird if (stripos($this->_version(), 'firebird') !== FALSE) { $sql = 'FIRST '. (int) $limit; - + if ($offset > 0) { $sql .= ' SKIP '. (int) $offset; @@ -617,16 +608,14 @@ SQL; else { $sql = 'ROWS ' . (int) $limit; - + if ($offset > 0) { $sql = 'ROWS '. (int) $offset . ' TO ' . ($limit + $offset); } } - - $sql = preg_replace("`SELECT`i", "SELECT {$sql}", $orig_sql); - - return $sql; + + return preg_replace('`SELECT`i', "SELECT {$sql}", $orig_sql); } // -------------------------------------------------------------------- @@ -641,7 +630,8 @@ SQL; { @ibase_close($conn_id); } + } /* End of file interbase_driver.php */ -/* Location: ./system/database/drivers/interbase/interbase_driver.php */ \ No newline at end of file +/* Location: ./system/database/drivers/interbase/interbase_driver.php */ -- cgit v1.2.3-24-g4f1b From 78ca39bc8c4b7edf0468e4a0a7251f808f352414 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 2 Mar 2012 19:04:31 +0200 Subject: Removed db_set_charset() from Interbase driver (no longer needed) --- system/database/drivers/interbase/interbase_driver.php | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php index 17fcffa65..51e814e16 100644 --- a/system/database/drivers/interbase/interbase_driver.php +++ b/system/database/drivers/interbase/interbase_driver.php @@ -114,21 +114,6 @@ class CI_DB_interbase_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * Set client character set - * - * @param string - * @param string - * @return bool - */ - public function db_set_charset($charset, $collation) - { - // Must be determined at connection - return TRUE; - } - - // -------------------------------------------------------------------- - /** * Version number query string * -- cgit v1.2.3-24-g4f1b From 08856b8738ea4fc17b13986c9f2619383cb4a6e9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 3 Mar 2012 03:19:28 +0200 Subject: Improve DB version() implementation and add pg_version() support --- system/database/DB_driver.php | 46 ++++++++++++---------- system/database/drivers/cubrid/cubrid_driver.php | 14 +++---- .../drivers/interbase/interbase_driver.php | 15 ++++--- system/database/drivers/mssql/mssql_driver.php | 7 ++-- system/database/drivers/mysql/mysql_driver.php | 8 ++-- system/database/drivers/mysqli/mysqli_driver.php | 8 ++-- system/database/drivers/oci8/oci8_driver.php | 11 +++--- system/database/drivers/odbc/odbc_driver.php | 13 ------ system/database/drivers/pdo/pdo_driver.php | 10 +++-- system/database/drivers/postgre/postgre_driver.php | 27 ++++++++++--- system/database/drivers/sqlite/sqlite_driver.php | 9 +++-- system/database/drivers/sqlite/sqlite_forge.php | 4 +- system/database/drivers/sqlsrv/sqlsrv_driver.php | 24 +++++++---- 13 files changed, 109 insertions(+), 87 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 075cab2c9..b41a42051 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -222,36 +222,40 @@ class CI_DB_driver { // -------------------------------------------------------------------- /** - * Database Version Number. Returns a string containing the - * version of the database being used + * Database version number + * + * Returns a string containing the version of the database being used. + * Most drivers will override this method. * - * @access public * @return string */ - function version() + public function version() { - if (FALSE === ($sql = $this->_version())) + if (isset($this->data_cache['version'])) { - if ($this->db_debug) - { - return $this->display_error('db_unsupported_function'); - } - return FALSE; + return $this->data_cache['version']; } - // 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', 'cubrid', 'pdo', 'mysqli', 'interbase'); - - if (in_array($this->dbdriver, $driver_version_exceptions)) - { - return $sql; - } - else + if (FALSE === ($sql = $this->_version())) { - $query = $this->query($sql); - return $query->row('ver'); + return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE; } + + $query = $this->query($sql); + $query = $query->row(); + return $this->data_cache['version'] = $query->ver; + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @return string + */ + protected function _version() + { + return 'SELECT VERSION() AS ver'; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php index cb33919a4..afdaef351 100644 --- a/system/database/drivers/cubrid/cubrid_driver.php +++ b/system/database/drivers/cubrid/cubrid_driver.php @@ -156,19 +156,15 @@ class CI_DB_cubrid_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Version number query string + * Database version number * - * @access public * @return string */ - function _version() + public function version() { - // To obtain the CUBRID Server version, no need to run the SQL query. - // CUBRID PHP API provides a function to determin this value. - // This is why we also need to add 'cubrid' value to the list of - // $driver_version_exceptions array in DB_driver class in - // version() function. - return cubrid_get_server_info($this->conn_id); + return isset($this->data_cache['version']) + ? $this->data_cache['version'] + : $this->data_cache['version'] = cubrid_get_server_info($this->conn_id); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php index 51e814e16..f4bd9e271 100644 --- a/system/database/drivers/interbase/interbase_driver.php +++ b/system/database/drivers/interbase/interbase_driver.php @@ -115,19 +115,24 @@ class CI_DB_interbase_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Version number query string + * Database version number * * @return string */ - protected function _version() + public function version() { + if (isset($this->data_cache['version'])) + { + return $this->data_cache['version']; + } + if (($service = ibase_service_attach($this->hostname, $this->username, $this->password))) { - $version = ibase_server_info($service, IBASE_SVC_SERVER_VERSION); + $this->data_cache['version'] = ibase_server_info($service, IBASE_SVC_SERVER_VERSION); // Don't keep the service open ibase_service_detach($service); - return $version; + return $this->data_cache['version']; } return FALSE; @@ -581,7 +586,7 @@ SQL; $orig_sql = $sql; // Limit clause depends on if Interbase or Firebird - if (stripos($this->_version(), 'firebird') !== FALSE) + if (stripos($this->version(), 'firebird') !== FALSE) { $sql = 'FIRST '. (int) $limit; diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 188c91f9b..147c63483 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -339,12 +339,11 @@ class CI_DB_mssql_driver extends CI_DB { /** * Version number query string * - * @access public - * @return string + * @return string */ - function _version() + protected function _version() { - return "SELECT @@VERSION AS ver"; + return 'SELECT @@VERSION AS ver'; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index a7f08d1a8..7108a6db1 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -157,13 +157,15 @@ class CI_DB_mysql_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Version number query string + * Database version number * * @return string */ - protected function _version() + public function version() { - return 'SELECT version() AS ver'; + return isset($this->data_cache['version']) + ? $this->data_cache['version'] + : $this->data_cache['version'] = @mysql_get_server_info($this->conn_id); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 031371345..19353944d 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -157,13 +157,15 @@ class CI_DB_mysqli_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Version number query string + * Database version number * * @return string */ - protected function _version() + public function version() { - return @mysqli_get_server_info($this->conn_id); + return isset($this->data_cache['version']) + ? $this->data_cache['version'] + : $this->data_cache['version'] = @mysqli_get_server_info($this->conn_id); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 97efb4647..35cafff6c 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -139,14 +139,15 @@ class CI_DB_oci8_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Version number query string + * Database version number * - * @access protected - * @return string + * @return string */ - protected function _version() + public function version() { - return oci_server_version($this->conn_id); + return isset($this->data_cache['version']) + ? $this->data_cache['version'] + : $this->data_cache['version'] = oci_server_version($this->conn_id); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 5a93f7cad..779b0c62f 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -123,19 +123,6 @@ class CI_DB_odbc_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - /** * Execute the query * diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index de5e1f05e..8fdfd58fb 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -289,13 +289,15 @@ class CI_DB_pdo_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Version number query string + * Database version number * * @return string */ - protected function _version() + public function version() { - return $this->conn_id->getAttribute(PDO::ATTR_SERVER_VERSION); + return isset($this->data_cache['version']) + ? $this->data_cache['version'] + : $this->data_cache['version'] = $this->conn_id->getAttribute(PDO::ATTR_SERVER_VERSION); } // -------------------------------------------------------------------- @@ -499,7 +501,7 @@ class CI_DB_pdo_driver extends CI_DB { */ public function insert_id($name = NULL) { - if ($this->pdodriver === 'pgsql' && $name === NULL && $this->_version() >= '8.1') + if ($this->pdodriver === 'pgsql' && $name === NULL && $this->version() >= '8.1') { $query = $this->query('SELECT LASTVAL() AS ins_id'); $query = $query->row(); diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 0fcd954e9..d6681086a 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -147,14 +147,30 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Version number query string + * Database version number * - * @access public * @return string */ - function _version() + public function version() { - return "SELECT version() AS ver"; + if (isset($this->data_cache['version'])) + { + return $this->data_cache['version']; + } + + if (($pg_version = pg_version($this->conn_id)) === FALSE) + { + return FALSE; + } + + /* If PHP was compiled with PostgreSQL lib versions earlier + * than 7.4, pg_version() won't return the server version + * and so we'll have to fall back to running a query in + * order to get it. + */ + return isset($pg_version['server']) + ? $this->data_cache['version'] = $pg_version['server'] + : parent::version(); } // -------------------------------------------------------------------- @@ -323,8 +339,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function insert_id() { - $v = $this->_version(); - $v = $v['server']; + $v = $this->version(); $table = func_num_args() > 0 ? func_get_arg(0) : NULL; $column = func_num_args() > 1 ? func_get_arg(1) : NULL; diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 3e4b37320..3eaec949c 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -141,14 +141,15 @@ class CI_DB_sqlite_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Version number query string + * Database version number * - * @access public * @return string */ - function _version() + public function version() { - return sqlite_libversion(); + return isset($this->data_cache['version']) + ? $this->data_cache['version'] + : $this->data_cache['version'] = sqlite_libversion(); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlite/sqlite_forge.php b/system/database/drivers/sqlite/sqlite_forge.php index 2b723be0b..fd0f3eb98 100644 --- a/system/database/drivers/sqlite/sqlite_forge.php +++ b/system/database/drivers/sqlite/sqlite_forge.php @@ -89,7 +89,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->db->_version(), '3.3.0', '>=') === TRUE) + if ($if_not_exists === TRUE && version_compare($this->db->version(), '3.3.0', '>=') === TRUE) { $sql .= 'IF NOT EXISTS '; } @@ -274,4 +274,4 @@ class CI_DB_sqlite_forge extends CI_DB_forge { } /* End of file sqlite_forge.php */ -/* Location: ./system/database/drivers/sqlite/sqlite_forge.php */ \ No newline at end of file +/* Location: ./system/database/drivers/sqlite/sqlite_forge.php */ diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index 03d7c7199..5c90cb4f2 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -317,15 +317,23 @@ class CI_DB_sqlsrv_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Version number query string - * - * @access public - * @return string - */ - function _version() + * Database version number + * + * @return string + */ + public function version() { - $info = sqlsrv_server_info($this->conn_id); - return sprintf("select '%s' as ver", $info['SQLServerVersion']); + if (isset($this->data_cache['version'])) + { + return $this->data_cache['version']; + } + + if (($info = sqlsrv_server_info($this->conn_id)) === FALSE) + { + return FALSE; + } + + return $this->data_cache['version'] = $info['SQLServerVersion']; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 8e89df8f92444eb02dc73b6c3e66077a4fb3f710 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 3 Mar 2012 03:48:12 +0200 Subject: Add db_set_charset() support for PostgreSQL and change its implementation for 'mysql' --- system/database/drivers/mysql/mysql_driver.php | 2 +- system/database/drivers/postgre/postgre_driver.php | 13 +++++++++++++ 2 files changed, 14 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 7108a6db1..84f7791c7 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -147,7 +147,7 @@ class CI_DB_mysql_driver extends CI_DB { * @param string * @return bool */ - public function db_set_charset($charset, $collation) + protected function _db_set_charset($charset, $collation) { return function_exists('mysql_set_charset') ? @mysql_set_charset($charset, $this->conn_id) diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index d6681086a..8df90f6a4 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -146,6 +146,19 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Set client character set + * + * @param string + * @return bool + */ + protected function _db_set_charset($charset) + { + return (pg_set_client_encoding($this->conn_id, $charset) === 0); + } + + // -------------------------------------------------------------------- + /** * Database version number * -- cgit v1.2.3-24-g4f1b From 5fa729827d63774457ad34b57109a2f6ab20d20f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 3 Mar 2012 04:13:20 +0200 Subject: Added _optimize_table() support for PostgreSQL --- system/database/DB_driver.php | 2 +- .../database/drivers/postgre/postgre_utility.php | 35 ++++++++-------------- 2 files changed, 13 insertions(+), 24 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index b41a42051..15195b20a 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -651,7 +651,7 @@ class CI_DB_driver { */ public function is_write_type($sql) { - return (bool) preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD DATA|COPY|ALTER|RENAME|GRANT|REVOKE|LOCK|UNLOCK|OPTIMIZE)\s+/i', $sql); + return (bool) preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD DATA|COPY|ALTER|RENAME|GRANT|REVOKE|LOCK|UNLOCK|OPTIMIZE|REINDEX)\s+/i', $sql); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index dffd8c549..c426b363b 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -1,13 +1,13 @@ -db->protect_identifiers($table); } // -------------------------------------------------------------------- @@ -68,13 +62,10 @@ class CI_DB_postgre_utility extends CI_DB_utility { /** * Repair table query * - * Are table repairs supported in Postgre? - * - * @access private * @param string the table name - * @return object + * @return bool */ - function _repair_table($table) + public function _repair_table($table) { return FALSE; } @@ -84,7 +75,6 @@ class CI_DB_postgre_utility extends CI_DB_utility { /** * Postgre Export * - * @access private * @param array Preferences * @return mixed */ @@ -95,6 +85,5 @@ class CI_DB_postgre_utility extends CI_DB_utility { } } - /* End of file postgre_utility.php */ -/* Location: ./system/database/drivers/postgre/postgre_utility.php */ \ No newline at end of file +/* Location: ./system/database/drivers/postgre/postgre_utility.php */ -- cgit v1.2.3-24-g4f1b From a19beb0c580ac78c4b75548a046240a85f30cb29 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 3 Mar 2012 04:20:50 +0200 Subject: Replace usage of legacy alias pg_exec() in favor of pg_query() and improve PostgreSQL driver trans_*() methods --- system/database/drivers/postgre/postgre_driver.php | 38 ++++++---------------- 1 file changed, 10 insertions(+), 28 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 8df90f6a4..df0f50da5 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -222,18 +222,12 @@ class CI_DB_postgre_driver extends CI_DB { /** * Begin Transaction * - * @access public * @return bool */ - function trans_begin($test_mode = FALSE) + public 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) + if ( ! $this->trans_enabled OR $this->_trans_depth > 0) { return TRUE; } @@ -241,9 +235,9 @@ 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. - $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; + $this->_trans_failure = ($test_mode === TRUE); - return @pg_exec($this->conn_id, "begin"); + return @pg_query($this->conn_id, 'BEGIN'); } // -------------------------------------------------------------------- @@ -251,23 +245,17 @@ class CI_DB_postgre_driver extends CI_DB { /** * Commit Transaction * - * @access public * @return bool */ - function trans_commit() + public 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) + if ( ! $this->trans_enabled OR $this->_trans_depth > 0) { return TRUE; } - return @pg_exec($this->conn_id, "commit"); + return @pg_query($this->conn_id, 'COMMIT'); } // -------------------------------------------------------------------- @@ -275,23 +263,17 @@ class CI_DB_postgre_driver extends CI_DB { /** * Rollback Transaction * - * @access public * @return bool */ - function trans_rollback() + public 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) + if ( ! $this->trans_enabled OR $this->_trans_depth > 0) { return TRUE; } - return @pg_exec($this->conn_id, "rollback"); + return @pg_query($this->conn_id, 'ROLLBACK'); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 3722e50439fd88281f8730fd329b41812cd19963 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 3 Mar 2012 15:04:38 +0200 Subject: Fix MySQL/MySQLi field_data() --- system/database/drivers/mysql/mysql_driver.php | 31 +++++++++++++++++++----- system/database/drivers/mysqli/mysqli_driver.php | 31 +++++++++++++++++++----- 2 files changed, 50 insertions(+), 12 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 84f7791c7..7fd08a6ed 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -404,16 +404,35 @@ class CI_DB_mysql_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved + * Returns an object with field data * * @param string the table name - * @return string + * @return object */ - public function _field_data($table) + public function field_data($table = '') { - return 'DESCRIBE '.$table; + if ($table == '') + { + return ($this->db_debug) ? $this->display_error('db_field_param_missing') : FALSE; + } + + $query = $this->query('DESCRIBE '.$this->_protect_identifiers($table, TRUE, NULL, FALSE)); + $query = $query->result_object(); + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + preg_match('/([a-z]+)(\(\d+\))?/', $query[$i]->Type, $matches); + + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]->Field; + $retval[$i]->type = empty($matches[1]) ? NULL : $matches[1]; + $retval[$i]->default = $query[$i]->Default; + $retval[$i]->max_length = empty($matches[2]) ? NULL : preg_replace('/[^\d]/', '', $matches[2]); + $retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI'); + } + + return $retval; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 19353944d..25b6ceca1 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -405,16 +405,35 @@ class CI_DB_mysqli_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved + * Returns an object with field data * * @param string the table name - * @return string + * @return object */ - protected function _field_data($table) + public function field_data($table = '') { - return 'DESCRIBE '.$table; + if ($table == '') + { + return ($this->db_debug) ? $this->display_error('db_field_param_missing') : FALSE; + } + + $query = $this->query('DESCRIBE '.$this->_protect_identifiers($table, TRUE, NULL, FALSE)); + $query = $query->result_object(); + + $retval = array(); + for ($i = 0, $c = count($query); $i < $c; $i++) + { + preg_match('/([a-z]+)(\(\d+\))?/', $query[$i]->Type, $matches); + + $retval[$i] = new stdClass(); + $retval[$i]->name = $query[$i]->Field; + $retval[$i]->type = empty($matches[1]) ? NULL : $matches[1]; + $retval[$i]->default = $query[$i]->Default; + $retval[$i]->max_length = empty($matches[2]) ? NULL : preg_replace('/[^\d]/', '', $matches[2]); + $retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI'); + } + + return $retval; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b