From 00541ae101a2044c4223b7b48d97c6afefe94be4 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 9 Apr 2012 11:43:10 +0300 Subject: Extend fix for #798 to work across all DB drivers instead of just mysql --- system/database/drivers/postgre/postgre_driver.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 1e96452b4..c15417f65 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -485,22 +485,26 @@ class CI_DB_postgre_driver extends CI_DB { * @param string the table name * @param array the update data * @param array the where clause - * @param array the orderby clause - * @param array the limit clause + * @param array the orderby clause (ignored) + * @param array the limit clause (ignored) + * @param array the like clause * @return string */ - protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE) + protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array()) { foreach ($values as $key => $val) { - $valstr[] = $key." = ".$val; + $valstr[] = $key.' = '.$val; } - $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); + $where = empty($where) ? '' : ' WHERE '.implode(' ', $where); - $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; + if ( ! empty($like)) + { + $where .= ($where === '' ? ' WHERE ' : ' AND ').implode(' ', $like); + } - return $sql; + return 'UPDATE '.$table.' SET '.implode(', ', $valstr).$where; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From c01d31685ad365c6bf3e833c03d7f8a3402c0ec7 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 9 Apr 2012 12:55:11 +0300 Subject: Added a default _delete() method to CI_DB_active_record --- system/database/drivers/postgre/postgre_driver.php | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index c15417f65..b85049d04 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -516,26 +516,17 @@ class CI_DB_postgre_driver extends CI_DB { * * @param string the table name * @param array the where clause - * @param string the limit clause + * @param array the like clause * @return string */ - protected function _delete($table, $where = array(), $like = array(), $limit = FALSE) + protected function _delete($table, $where = array(), $like = array()) { - $conditions = ''; - - if (count($where) > 0 OR count($like) > 0) - { - $conditions = "\nWHERE "; - $conditions .= implode("\n", $this->ar_where); + $conditions = array(); - if (count($where) > 0 && count($like) > 0) - { - $conditions .= " AND "; - } - $conditions .= implode("\n", $like); - } + empty($where) OR $conditions[] = implode(' ', $where); + empty($like) OR $conditions[] = implode(' ', $like); - return "DELETE FROM ".$table.$conditions; + return 'DELETE FROM '.$table.(count($conditions) > 0 ? ' WHERE '.implode(' AND ', $conditions) : ''); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From a254836a611e8f555ea4bbc84e500c7040ebae4e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 9 Apr 2012 13:03:11 +0300 Subject: Add back limit parameter to Interbase and PostgreSQL _delete() due to CI_DB_active_record being abstract --- system/database/drivers/postgre/postgre_driver.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index b85049d04..14259be52 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -517,9 +517,10 @@ class CI_DB_postgre_driver extends CI_DB { * @param string the table name * @param array the where clause * @param array the like clause + * @param string the limit clause (ignored) * @return string */ - protected function _delete($table, $where = array(), $like = array()) + protected function _delete($table, $where = array(), $like = array(), $limit = FALSE) { $conditions = array(); -- cgit v1.2.3-24-g4f1b From d947eba0bdaf9d86401fdcba9e97706905cacf9d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 9 Apr 2012 14:58:28 +0300 Subject: Multiple DB Forge improvements - Replaced driver methods _create_database(), _drop_database(), _drop_table() and _rename_table() with properties - Added defaults for the above mentioned platform-specific queries, so that not all drivers need to define them - Improved support for the SQLite, ODBC and PDO drivers --- system/database/drivers/postgre/postgre_forge.php | 54 +---------------------- 1 file changed, 1 insertion(+), 53 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index f7d59284a..d86fb9656 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -34,31 +34,7 @@ */ class CI_DB_postgre_forge extends CI_DB_forge { - /** - * Create database - * - * @param string the database name - * @return bool - */ - public function _create_database($name) - { - return "CREATE DATABASE ".$name; - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @param string the database name - * @return bool - */ - public function _drop_database($name) - { - return "DROP DATABASE ".$name; - } - - // -------------------------------------------------------------------- + protected $_drop_table = 'DROP TABLE IF EXISTS %s CASCADE'; /** * Process Fields @@ -233,19 +209,6 @@ class CI_DB_postgre_forge extends CI_DB_forge { // -------------------------------------------------------------------- - /** - * Drop Table - * - * @param string table name - * @return string - */ - public function _drop_table($table) - { - return 'DROP TABLE IF EXISTS '.$this->db->escape_identifiers($table).' CASCADE'; - } - - // -------------------------------------------------------------------- - /** * Alter table query * @@ -281,21 +244,6 @@ class CI_DB_postgre_forge extends CI_DB_forge { return $sql; } - // -------------------------------------------------------------------- - - /** - * Rename a table - * - * Generates a platform-specific query so that a table can be renamed - * - * @param string the old table name - * @param string the new table name - * @return string - */ - public 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); - } } /* End of file postgre_forge.php */ -- cgit v1.2.3-24-g4f1b From a0d4e417ef994628f67a75b2acdb5bb62971e803 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 9 Apr 2012 15:06:40 +0300 Subject: Switched public driver methods in DB forge to protected --- system/database/drivers/postgre/postgre_forge.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index d86fb9656..8b214ebe6 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -156,7 +156,7 @@ class CI_DB_postgre_forge extends CI_DB_forge { * @param bool should 'IF NOT EXISTS' be added to the SQL * @return bool */ - 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 '; @@ -224,7 +224,7 @@ class CI_DB_postgre_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, $fields, $after_field = '') + protected function _alter_table($alter_type, $table, $fields, $after_field = '') { $sql = 'ALTER TABLE '.$this->db->protect_identifiers($table).' '.$alter_type.' '; -- cgit v1.2.3-24-g4f1b From b457a4001ce2380e97f36b0a983b477c3e31de69 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 9 Apr 2012 16:11:56 +0300 Subject: DB Utility improvements - Replaced driver methods _list_databases(), _optimize_table() and _repair_table() with properties - Added defaults for optimize_table() and repair_table() SQL strings (FALSE, as those are mostly MySQL-specific) - Added MSSQL/SQLSRV support for optimize_table() (actually rebuilds table indexes) - Switched public driver methods to protected - Improved CUBRID support for list_databases() as it used to only return the currently used database - Minor speed improvements --- .../database/drivers/postgre/postgre_utility.php | 41 ++-------------------- 1 file changed, 3 insertions(+), 38 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index cf29201ff..c95e6df0c 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -34,43 +34,8 @@ */ class CI_DB_postgre_utility extends CI_DB_utility { - /** - * List databases - * - * @return string - */ - public function _list_databases() - { - return 'SELECT datname FROM pg_database'; - } - - // -------------------------------------------------------------------- - - /** - * Optimize table query - * - * @param string the table name - * @return string - */ - public function _optimize_table($table) - { - return 'REINDEX TABLE '.$this->db->protect_identifiers($table); - } - - // -------------------------------------------------------------------- - - /** - * Repair table query - * - * @param string the table name - * @return bool - */ - public function _repair_table($table) - { - return FALSE; - } - - // -------------------------------------------------------------------- + protected $_list_databases = 'SELECT datname FROM pg_database'; + protected $_optimize_table = 'REINDEX TABLE %s'; /** * Postgre Export @@ -78,7 +43,7 @@ class CI_DB_postgre_utility extends CI_DB_utility { * @param array Preferences * @return mixed */ - public function _backup($params = array()) + protected function _backup($params = array()) { // Currently unsupported return $this->db->display_error('db_unsuported_feature'); -- cgit v1.2.3-24-g4f1b