From 37e351f1c1bf76758685158630be723e2951c032 Mon Sep 17 00:00:00 2001 From: Kyle Farris Date: Wed, 7 Sep 2011 11:14:46 -0300 Subject: Fix for issue #406 --- system/database/drivers/sqlsrv/sqlsrv_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index 400fd31c6..1021db945 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -86,7 +86,7 @@ class CI_DB_sqlsrv_driver extends CI_DB { */ function db_pconnect() { - $this->db_connect(TRUE); + return $this->db_connect(TRUE); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 0372f1ade3029c8363f1ed13545590c45d45d82f Mon Sep 17 00:00:00 2001 From: a-krebs Date: Wed, 23 Nov 2011 00:04:34 -0700 Subject: fix to issue #696 - make oci_execute calls inside num_rows non-committing, since they are only there to reset which row is next in line for oci_fetch calls and thus don't need to be committed. --- system/database/drivers/oci8/oci8_result.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/oci8/oci8_result.php b/system/database/drivers/oci8/oci8_result.php index 3ec71a9d6..f32559289 100644 --- a/system/database/drivers/oci8/oci8_result.php +++ b/system/database/drivers/oci8/oci8_result.php @@ -57,11 +57,11 @@ class CI_DB_oci8_result extends CI_DB_result { if ($this->num_rows === 0 && count($this->result_array()) > 0) { $this->num_rows = count($this->result_array()); - @oci_execute($this->stmt_id); + @oci_execute($this->stmt_id, OCI_DEFAULT); if ($this->curs_id) { - @oci_execute($this->curs_id); + @oci_execute($this->curs_id, OCI_DEFAULT); } } -- cgit v1.2.3-24-g4f1b From 65134ce0b594c378679c92c40fb835cf9ab5cdd0 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 28 Nov 2011 08:45:03 -0500 Subject: Fixed sytax error in pdo driver --- system/database/drivers/pdo/pdo_driver.php | 4 ---- 1 file changed, 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 5f63a3771..18a508b15 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -255,11 +255,7 @@ class CI_DB_pdo_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. -<<<<<<< HEAD - $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; -======= $this->_trans_failure = (bool) ($test_mode === TRUE); ->>>>>>> master return $this->conn_id->beginTransaction(); } -- cgit v1.2.3-24-g4f1b From 5d581b6d664c6ef662bcb9572ca147ac17af52cb Mon Sep 17 00:00:00 2001 From: Felix Balfoort Date: Tue, 29 Nov 2011 15:53:01 +0100 Subject: The DB_driver can now use failover databases if specified The DB_driver can now use failover databases if specified. If the main connection shouldn't connect for some reason the DB_driver will now try to connect to specified connections in the failover config. Example config: $db['default']['hostname'] = 'localhost'; $db['default']['username'] = ''; $db['default']['password'] = ''; $db['default']['database'] = ''; $db['default']['dbdriver'] = 'mysql'; $db['default']['dbprefix'] = ''; $db['default']['pconnect'] = TRUE; $db['default']['db_debug'] = TRUE; $db['default']['cache_on'] = FALSE; $db['default']['cachedir'] = ''; $db['default']['char_set'] = 'utf8'; $db['default']['dbcollat'] = 'utf8_general_ci'; $db['default']['swap_pre'] = ''; $db['default']['autoinit'] = TRUE; $db['default']['stricton'] = FALSE; $db['default']['failover'] = array(); $db['default']['failover'][0]['hostname'] = 'localhost1'; $db['default']['failover'][0]['username'] = ''; $db['default']['failover'][0]['password'] = ''; $db['default']['failover'][0]['database'] = ''; $db['default']['failover'][0]['dbdriver'] = 'mysql'; $db['default']['failover'][0]['dbprefix'] = ''; $db['default']['failover'][0]['pconnect'] = TRUE; $db['default']['failover'][0]['db_debug'] = TRUE; $db['default']['failover'][0]['cache_on'] = FALSE; $db['default']['failover'][0]['cachedir'] = ''; $db['default']['failover'][0]['char_set'] = 'utf8'; $db['default']['failover'][0]['dbcollat'] = 'utf8_general_ci'; $db['default']['failover'][0]['swap_pre'] = ''; $db['default']['failover'][0]['autoinit'] = TRUE; $db['default']['failover'][0]['stricton'] = FALSE; $db['default']['failover'][0]['failover'] = array(); $db['default']['failover'][1]['hostname'] = 'localhost2'; $db['default']['failover'][1]['username'] = ''; $db['default']['failover'][1]['password'] = ''; $db['default']['failover'][1]['database'] = ''; $db['default']['failover'][1]['dbdriver'] = 'mysql'; $db['default']['failover'][1]['dbprefix'] = ''; $db['default']['failover'][1]['pconnect'] = TRUE; $db['default']['failover'][1]['db_debug'] = TRUE; $db['default']['failover'][1]['cache_on'] = FALSE; $db['default']['failover'][1]['cachedir'] = ''; $db['default']['failover'][1]['char_set'] = 'utf8'; $db['default']['failover'][1]['dbcollat'] = 'utf8_general_ci'; $db['default']['failover'][1]['swap_pre'] = ''; $db['default']['failover'][1]['autoinit'] = TRUE; $db['default']['failover'][1]['stricton'] = FALSE; $db['default']['failover'][1]['failover'] = array(); Signed-off-by: Felix Balfoort --- system/database/DB_driver.php | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index cc40ba48a..c2d57a833 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -126,16 +126,43 @@ 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? Throw an error + // No connection resource? Check if there is a failover else throw an error if ( ! $this->conn_id) { - log_message('error', 'Unable to connect to the database'); + // Check if there is a failover set + if ( ! empty($this->failover) && is_array($this->failover)) + { + // Go over all the failovers + foreach ($this->failover as $failover) + { + // Replace the current settings with those of the failover + foreach ($failover as $key => $val) + { + $this->$key = $val; + } - if ($this->db_debug) + // Try to connect + $this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect(); + + // If a connection is made break the foreach loop + if ($this->conn_id) + { + break; + } + } + } + + // We still don't have a connection? + if ( ! $this->conn_id) { - $this->display_error('db_unable_to_connect'); + log_message('error', 'Unable to connect to the database'); + + if ($this->db_debug) + { + $this->display_error('db_unable_to_connect'); + } + return FALSE; } - return FALSE; } // ---------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 71b78096d95fc8f5ab46686168acd702abb90dc9 Mon Sep 17 00:00:00 2001 From: Repox Date: Thu, 1 Dec 2011 09:19:43 +0100 Subject: This fixes issue #725 --- system/database/DB_driver.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index c2d57a833..9d92f2f87 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1064,7 +1064,14 @@ class CI_DB_driver { { $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 717253f5c77a11b1b997069ff53bd2d2ab2e538c Mon Sep 17 00:00:00 2001 From: Tomasz T Date: Fri, 2 Dec 2011 17:57:30 +0100 Subject: SELECT * FROM isn't that innocuous, changed to SELECT 1 --- system/database/drivers/postgre/postgre_forge.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index 166cc4e6a..ddbce6062 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -83,7 +83,7 @@ class CI_DB_postgre_forge extends CI_DB_forge { { if ($this->db->table_exists($table)) { - return "SELECT * FROM $table"; // Needs to return innocous but valid SQL statement + return "SELECT 1"; // Needs to return innocous but valid SQL statement } } -- cgit v1.2.3-24-g4f1b From b9ec402de2ad190df899426f4bbcebbcc759d01f Mon Sep 17 00:00:00 2001 From: Tomasz T Date: Mon, 5 Dec 2011 15:28:33 +0100 Subject: changed create_table method to check whether a value returned from driver's forge is sql or bool (acts exactly as create_database) --- system/database/DB_forge.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'system/database') diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index 1aa2334ea..78bf77a9f 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -205,6 +205,12 @@ class CI_DB_forge { $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); } -- cgit v1.2.3-24-g4f1b From c9fc88c09c1a0accdddd3710907fee2f5b42d7ad Mon Sep 17 00:00:00 2001 From: Tomasz T Date: Mon, 5 Dec 2011 15:30:05 +0100 Subject: changed _create_table to return true if table already exists --- system/database/drivers/postgre/postgre_forge.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index ddbce6062..df0338e73 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -81,9 +81,10 @@ class CI_DB_postgre_forge extends CI_DB_forge { 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 "SELECT 1"; // Needs to return innocous but valid SQL statement + return TRUE; } } -- cgit v1.2.3-24-g4f1b From 59dbcda901f45c5183e976a0a2da7c7459294d05 Mon Sep 17 00:00:00 2001 From: toopay Date: Thu, 8 Dec 2011 20:42:41 +0700 Subject: Exception for sqlite --- 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 18a508b15..457cf714a 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -90,7 +90,10 @@ class CI_DB_pdo_driver extends CI_DB { $this->_like_escape_chr = '!'; } - $this->hostname .= ";dbname=".$this->database; + if (strpos($this->hostname, 'sqlite') === FALSE) + { + $this->hostname .= ";dbname=".$this->database; + } $this->trans_enabled = FALSE; -- cgit v1.2.3-24-g4f1b From c4caf5a181344e48fc6740f1383dd302f5b604d2 Mon Sep 17 00:00:00 2001 From: Mancy Date: Tue, 20 Dec 2011 11:47:51 +0300 Subject: taking care of LIKE when used in UPDATE statement #798 --- system/database/DB_active_rec.php | 2 +- system/database/drivers/mysql/mysql_driver.php | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 43920772a..7a608c4f0 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1424,7 +1424,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->limit($limit); } - $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); + $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); diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 828ef006b..7952312ab 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -606,7 +606,7 @@ class CI_DB_mysql_driver extends CI_DB { * @param array the limit clause * @return string */ - function _update($table, $values, $where, $orderby = array(), $limit = FALSE) + function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array()) { foreach ($values as $key => $val) { @@ -620,6 +620,15 @@ class CI_DB_mysql_driver extends CI_DB { $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; + + if (count($like) > 0) { + $sql .= ($where == '' AND count($where) <1) ? " WHERE " : ' AND '; + foreach ($like as $st_like) { + + $sql .= " " . $st_like; + + } + } $sql .= $orderby.$limit; -- cgit v1.2.3-24-g4f1b From 205d02936cf76f9b430129d9b704c182933cfee4 Mon Sep 17 00:00:00 2001 From: Mancy Date: Tue, 20 Dec 2011 12:45:58 +0300 Subject: #798: following current codeigniter code standards --- system/database/drivers/mysql/mysql_driver.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 7952312ab..6ded6e531 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -621,12 +621,13 @@ class CI_DB_mysql_driver extends CI_DB { $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; - if (count($like) > 0) { + if (count($like) > 0) + { $sql .= ($where == '' AND count($where) <1) ? " WHERE " : ' AND '; - foreach ($like as $st_like) { - - $sql .= " " . $st_like; - + + foreach ($like as $st_like) + { + $sql .= " " . $st_like; } } -- cgit v1.2.3-24-g4f1b From 0d91fd2956812e07905d8047ef95a0e556edbb1a Mon Sep 17 00:00:00 2001 From: Mancy Date: Tue, 20 Dec 2011 13:13:14 +0300 Subject: #798: update changelog and typo fix --- 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 7a608c4f0..41950e7d8 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1424,7 +1424,7 @@ class CI_DB_active_record extends CI_DB_driver { $this->limit($limit); } - $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); + $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); -- cgit v1.2.3-24-g4f1b From 2c685fb03a4d4b5a96789b839147191ce8cffacc Mon Sep 17 00:00:00 2001 From: pporlan Date: Thu, 22 Dec 2011 12:15:25 +0100 Subject: Adding $escape parameter to the order_by function, this enables ordering by custom fields --- system/database/DB_active_rec.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 41950e7d8..412febfcc 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -830,9 +830,10 @@ class CI_DB_active_record extends CI_DB_driver { * * @param string * @param string direction: asc or desc + * @param bool enable field name escaping * @return object */ - public function order_by($orderby, $direction = '') + public function order_by($orderby, $direction = '', $escape = TRUE) { if (strtolower($direction) == 'random') { @@ -845,7 +846,7 @@ class CI_DB_active_record extends CI_DB_driver { } - if (strpos($orderby, ',') !== FALSE) + if ((strpos($orderby, ',') !== FALSE) && ($escape === TRUE)) { $temp = array(); foreach (explode(',', $orderby) as $part) @@ -863,7 +864,10 @@ class CI_DB_active_record extends CI_DB_driver { } else if ($direction != $this->_random_keyword) { - $orderby = $this->_protect_identifiers($orderby); + if ($escape === TRUE) + { + $orderby = $this->_protect_identifiers($orderby); + } } $orderby_statement = $orderby.$direction; -- cgit v1.2.3-24-g4f1b From 03abee3df4534028c795e3c3da91034a3d3ee0f4 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Sun, 25 Dec 2011 00:31:29 -0600 Subject: Fixing soft tabs in a few files. --- system/database/DB_active_rec.php | 2 +- system/database/drivers/oci8/oci8_driver.php | 9 ++++----- system/database/drivers/postgre/postgre_forge.php | 3 --- 3 files changed, 5 insertions(+), 9 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index 412febfcc..530b44e09 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -75,7 +75,7 @@ class CI_DB_active_record extends CI_DB_driver { protected $ar_cache_set = array(); protected $ar_no_escape = array(); - protected $ar_cache_no_escape = array(); + protected $ar_cache_no_escape = array(); // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 190b86bb2..9c38dcbd6 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -661,11 +661,10 @@ class CI_DB_oci8_driver extends CI_DB { * * Generates a platform-specific insert string from the supplied data * - * @access protected - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string */ protected function _insert_batch($table, $keys, $values) { diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index df0338e73..f86ba2dda 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -225,9 +225,6 @@ class CI_DB_postgre_forge extends CI_DB_forge { /** * Drop Table - * - * @access private - * @return bool */ function _drop_table($table) { -- cgit v1.2.3-24-g4f1b