From 7eea4f8906c21c1061cc9f21100e5597aae648b9 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 18:13:17 +0000 Subject: --- system/database/drivers/postgre/postgre_driver.php | 484 +++++++++++++++++++++ 1 file changed, 484 insertions(+) create mode 100644 system/database/drivers/postgre/postgre_driver.php (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php new file mode 100644 index 000000000..92767c42b --- /dev/null +++ b/system/database/drivers/postgre/postgre_driver.php @@ -0,0 +1,484 @@ +port == '') ? '' : " port=".$this->port; + + return pg_connect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + $port = ($this->port == '') ? '' : " port=".$this->port; + + return pg_pconnect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + // Not needed for Postgre so we'll return TRUE + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + function _execute($sql) + { + $sql = $this->_prep_query($sql); + return @pg_query($this->conn_id, $sql); + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @access private called by execute() + * @param string an SQL query + * @return string + */ + function _prep_query($sql) + { + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @return bool + */ + function trans_begin($test_mode = FALSE) + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + // Reset the transaction failure flag. + // If the $test_mode flag is set to TRUE transactions will be rolled back + // even if the queries produce a successful result. + $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; + + return @pg_exec($this->conn_id, "begin"); + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @access public + * @return bool + */ + function trans_commit() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + return @pg_exec($this->conn_id, "commit"); + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @access public + * @return bool + */ + function trans_rollback() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + return @pg_exec($this->conn_id, "rollback"); + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + return pg_escape_string($str); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @pg_affected_rows($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + $v = pg_version($this->conn_id); + $v = $v['server']; + + $table = func_num_args() > 0 ? func_get_arg(0) : null; + $column = func_num_args() > 1 ? func_get_arg(1) : null; + + if ($table == null && $v >= '8.1') + { + $sql='SELECT LASTVAL() as ins_id'; + } + elseif ($table != null && $column != null && $v >= '8.0') + { + $sql = sprintf("SELECT pg_get_serial_sequence('%s','%s') as seq", $table, $column); + $query = $this->query($sql); + $row = $query->row(); + $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $row->seq); + } + elseif ($table != null) + { + // seq_name passed in table parameter + $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $table); + } + else + { + return pg_last_oid($this->result_id); + } + $query = $this->query($sql); + $row = $query->row(); + return $row->ins_id; + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + return '0'; + + $query = $this->query('SELECT COUNT(*) AS numrows FROM "'.$this->dbprefix.$table.'"'); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + return pg_last_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + return ''; + } + + // -------------------------------------------------------------------- + + /** + * Escape Table Name + * + * This function adds backticks if the table name has a period + * in it. Some DBs will get cranky unless periods are escaped. + * + * @access public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = '"'.preg_replace("/\./", '"."', $table).'"'; + } + + return $table; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @return string + */ + function _update($table, $values, $where) + { + foreach($values as $key => $val) + { + $valstr[] = $key." = ".$val; + } + + return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _show_columns($table = '') + { + return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->escape_table($table)."'"; + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + $sql .= "LIMIT ".$limit; + + if ($offset > 0) + { + $sql .= " OFFSET ".$offset; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + pg_close($conn_id); + } + +} + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From bb1d439a981023415569549d8b8c4987fa5b9b51 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 20:14:38 +0000 Subject: --- system/database/drivers/postgre/postgre_driver.php | 117 +++++++++++---------- 1 file changed, 59 insertions(+), 58 deletions(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 92767c42b..03817188f 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -279,10 +279,10 @@ class CI_DB_postgre_driver extends CI_DB { /** * The error message string * - * @access public + * @access private * @return string */ - function error_message() + function _error_message() { return pg_last_error($this->conn_id); } @@ -292,10 +292,10 @@ class CI_DB_postgre_driver extends CI_DB { /** * The error message number * - * @access public + * @access private * @return integer */ - function error_number() + function _error_number() { return ''; } @@ -308,11 +308,11 @@ class CI_DB_postgre_driver extends CI_DB { * This function adds backticks if the table name has a period * in it. Some DBs will get cranky unless periods are escaped. * - * @access public + * @access private * @param string the table name * @return string */ - function escape_table($table) + function _escape_table($table) { if (stristr($table, '.')) { @@ -324,24 +324,6 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; - $query = $this->query($sql); - return $query->field_data(); - } - - // -------------------------------------------------------------------- - /** * Insert statement * @@ -355,7 +337,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function _insert($table, $keys, $values) { - return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -378,7 +360,7 @@ class CI_DB_postgre_driver extends CI_DB { $valstr[] = $key." = ".$val; } - return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); } // -------------------------------------------------------------------- @@ -395,9 +377,48 @@ class CI_DB_postgre_driver extends CI_DB { */ function _delete($table, $where) { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + $sql .= "LIMIT ".$limit; + if ($offset > 0) + { + $sql .= " OFFSET ".$offset; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + pg_close($conn_id); + } + // -------------------------------------------------------------------- /** @@ -437,48 +458,28 @@ class CI_DB_postgre_driver extends CI_DB { */ function _show_columns($table = '') { - return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->escape_table($table)."'"; - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - $sql .= "LIMIT ".$limit; - - if ($offset > 0) - { - $sql .= " OFFSET ".$offset; - } - - return $sql; + return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->_escape_table($table)."'"; } // -------------------------------------------------------------------- /** - * Close DB Connection + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved * * @access public - * @param resource - * @return void + * @param string the table name + * @return object */ - function _close($conn_id) + function _field_data($table) { - pg_close($conn_id); + $sql = "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; + $query = $this->query($sql); + return $query->field_data(); } + } ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From a5e812c007b8dfbc4c117df379d63060f08b096a Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 25 Sep 2006 02:17:30 +0000 Subject: --- system/database/drivers/postgre/postgre_driver.php | 60 ---------------------- 1 file changed, 60 deletions(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 03817188f..9c8a18eb5 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -419,66 +419,6 @@ class CI_DB_postgre_driver extends CI_DB { pg_close($conn_id); } - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _show_columns($table = '') - { - return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->_escape_table($table)."'"; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - $sql = "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; - $query = $this->query($sql); - return $query->field_data(); - } - } -- cgit v1.2.3-24-g4f1b From 9cd4e8e639a1a09fd6ca426f1af94586f30d4a80 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 25 Sep 2006 23:26:25 +0000 Subject: --- system/database/drivers/postgre/postgre_driver.php | 47 +++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 9c8a18eb5..026284118 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -71,7 +71,20 @@ class CI_DB_postgre_driver extends CI_DB { // Not needed for Postgre so we'll return TRUE return TRUE; } - + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + // -------------------------------------------------------------------- /** @@ -276,6 +289,38 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Show columnn query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _list_columns($table = '') + { + return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->_escape_table($table)."'"; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + return "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; + } + + // -------------------------------------------------------------------- + /** * The error message string * -- cgit v1.2.3-24-g4f1b From 3dd978f680076be842bfcb5c9e2cbf35b926373b Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 30 Sep 2006 19:24:45 +0000 Subject: --- system/database/drivers/postgre/postgre_driver.php | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 026284118..f14395638 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -286,6 +286,34 @@ class CI_DB_postgre_driver extends CI_DB { $row = $query->row(); return $row->numrows; } + + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + return "SELECT datname FROM pg_database"; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; + } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From b2a9ceccdb85050cb494e6d0a98b0a49495d29bb Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 1 Oct 2006 03:38:04 +0000 Subject: --- system/database/drivers/postgre/postgre_driver.php | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index f14395638..340d65046 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -289,19 +289,6 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - return "SELECT datname FROM pg_database"; - } - - // -------------------------------------------------------------------- - /** * Show table query * -- cgit v1.2.3-24-g4f1b From fafe28bec4f414e48f63e01ed9105ae5c2c99802 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 21 Oct 2006 19:08:17 +0000 Subject: --- system/database/drivers/postgre/postgre_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 340d65046..f74e652d5 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -305,7 +305,7 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Show columnn query + * Show column query * * Generates a platform-specific query string so that the column names can be fetched * -- cgit v1.2.3-24-g4f1b From e334c472fb4be44feec3a73402fc4a2b062cbfc0 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 21 Oct 2006 19:44:22 +0000 Subject: --- system/database/drivers/postgre/postgre_driver.php | 28 +++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index f74e652d5..81aaafe14 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -111,18 +111,18 @@ class CI_DB_postgre_driver extends CI_DB { * @param string an SQL query * @return string */ - function _prep_query($sql) - { + function _prep_query($sql) + { return $sql; - } + } // -------------------------------------------------------------------- /** * Begin Transaction - * + * * @access public - * @return bool + * @return bool */ function trans_begin($test_mode = FALSE) { @@ -138,8 +138,8 @@ class CI_DB_postgre_driver extends CI_DB { } // Reset the transaction failure flag. - // If the $test_mode flag is set to TRUE transactions will be rolled back - // even if the queries produce a successful result. + // If the $test_mode flag is set to TRUE transactions will be rolled back + // even if the queries produce a successful result. $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; return @pg_exec($this->conn_id, "begin"); @@ -149,9 +149,9 @@ class CI_DB_postgre_driver extends CI_DB { /** * Commit Transaction - * + * * @access public - * @return bool + * @return bool */ function trans_commit() { @@ -173,9 +173,9 @@ class CI_DB_postgre_driver extends CI_DB { /** * Rollback Transaction - * + * * @access public - * @return bool + * @return bool */ function trans_rollback() { @@ -298,7 +298,7 @@ class CI_DB_postgre_driver extends CI_DB { * @return string */ function _list_tables() - { + { return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; } -- cgit v1.2.3-24-g4f1b From 7acd581d9441fb8ada4c46c58f4ec30a01507506 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 23 Oct 2006 21:37:22 +0000 Subject: --- system/database/drivers/postgre/postgre_driver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 81aaafe14..68fde01b1 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -40,7 +40,7 @@ class CI_DB_postgre_driver extends CI_DB { { $port = ($this->port == '') ? '' : " port=".$this->port; - return pg_connect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); + return @pg_connect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); } // -------------------------------------------------------------------- @@ -55,7 +55,7 @@ class CI_DB_postgre_driver extends CI_DB { { $port = ($this->port == '') ? '' : " port=".$this->port; - return pg_pconnect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); + return @pg_pconnect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From befd4c226950dfe7fae260961355787bb1bf29a9 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 26 Oct 2006 01:49:26 +0000 Subject: --- system/database/drivers/postgre/postgre_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 68fde01b1..a66fddbdf 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -476,7 +476,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function _close($conn_id) { - pg_close($conn_id); + @pg_close($conn_id); } -- cgit v1.2.3-24-g4f1b From ba0dd638336d2617066b67cf4f59667aaff8c531 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 7 Mar 2007 12:10:58 +0000 Subject: pg_version() doesn't exist. Changed reference to version() which does. --- system/database/drivers/postgre/postgre_driver.php | 968 ++++++++++----------- 1 file changed, 484 insertions(+), 484 deletions(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index a66fddbdf..58cc69a96 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -1,485 +1,485 @@ -port == '') ? '' : " port=".$this->port; - - return @pg_connect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - $port = ($this->port == '') ? '' : " port=".$this->port; - - return @pg_pconnect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - // Not needed for Postgre so we'll return TRUE - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return resource - */ - function _execute($sql) - { - $sql = $this->_prep_query($sql); - return @pg_query($this->conn_id, $sql); - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @access private called by execute() - * @param string an SQL query - * @return string - */ - function _prep_query($sql) - { - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @return bool - */ - function trans_begin($test_mode = FALSE) - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - // Reset the transaction failure flag. - // If the $test_mode flag is set to TRUE transactions will be rolled back - // even if the queries produce a successful result. - $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; - - return @pg_exec($this->conn_id, "begin"); - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - return @pg_exec($this->conn_id, "commit"); - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - return @pg_exec($this->conn_id, "rollback"); - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @return string - */ - function escape_str($str) - { - return pg_escape_string($str); - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @pg_affected_rows($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - $v = pg_version($this->conn_id); - $v = $v['server']; - - $table = func_num_args() > 0 ? func_get_arg(0) : null; - $column = func_num_args() > 1 ? func_get_arg(1) : null; - - if ($table == null && $v >= '8.1') - { - $sql='SELECT LASTVAL() as ins_id'; - } - elseif ($table != null && $column != null && $v >= '8.0') - { - $sql = sprintf("SELECT pg_get_serial_sequence('%s','%s') as seq", $table, $column); - $query = $this->query($sql); - $row = $query->row(); - $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $row->seq); - } - elseif ($table != null) - { - // seq_name passed in table parameter - $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $table); - } - else - { - return pg_last_oid($this->result_id); - } - $query = $this->query($sql); - $row = $query->row(); - return $row->ins_id; - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - return '0'; - - $query = $this->query('SELECT COUNT(*) AS numrows FROM "'.$this->dbprefix.$table.'"'); - - if ($query->num_rows() == 0) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; - } - - // -------------------------------------------------------------------- - - /** - * Show column query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _list_columns($table = '') - { - return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->_escape_table($table)."'"; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - return "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access private - * @return string - */ - function _error_message() - { - return pg_last_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access private - * @return integer - */ - function _error_number() - { - return ''; - } - - // -------------------------------------------------------------------- - - /** - * Escape Table Name - * - * This function adds backticks if the table name has a period - * in it. Some DBs will get cranky unless periods are escaped. - * - * @access private - * @param string the table name - * @return string - */ - function _escape_table($table) - { - if (stristr($table, '.')) - { - $table = '"'.preg_replace("/\./", '"."', $table).'"'; - } - - return $table; - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @return string - */ - function _update($table, $values, $where) - { - foreach($values as $key => $val) - { - $valstr[] = $key." = ".$val; - } - - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @return string - */ - function _delete($table, $where) - { - return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - $sql .= "LIMIT ".$limit; - - if ($offset > 0) - { - $sql .= " OFFSET ".$offset; - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - @pg_close($conn_id); - } - - -} - +port == '') ? '' : " port=".$this->port; + + return @pg_connect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + $port = ($this->port == '') ? '' : " port=".$this->port; + + return @pg_pconnect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + // Not needed for Postgre so we'll return TRUE + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + function _execute($sql) + { + $sql = $this->_prep_query($sql); + return @pg_query($this->conn_id, $sql); + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @access private called by execute() + * @param string an SQL query + * @return string + */ + function _prep_query($sql) + { + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @return bool + */ + function trans_begin($test_mode = FALSE) + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + // Reset the transaction failure flag. + // If the $test_mode flag is set to TRUE transactions will be rolled back + // even if the queries produce a successful result. + $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; + + return @pg_exec($this->conn_id, "begin"); + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @access public + * @return bool + */ + function trans_commit() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + return @pg_exec($this->conn_id, "commit"); + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @access public + * @return bool + */ + function trans_rollback() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + return @pg_exec($this->conn_id, "rollback"); + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + return pg_escape_string($str); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @pg_affected_rows($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + $v = version($this->conn_id); + $v = $v['server']; + + $table = func_num_args() > 0 ? func_get_arg(0) : null; + $column = func_num_args() > 1 ? func_get_arg(1) : null; + + if ($table == null && $v >= '8.1') + { + $sql='SELECT LASTVAL() as ins_id'; + } + elseif ($table != null && $column != null && $v >= '8.0') + { + $sql = sprintf("SELECT pg_get_serial_sequence('%s','%s') as seq", $table, $column); + $query = $this->query($sql); + $row = $query->row(); + $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $row->seq); + } + elseif ($table != null) + { + // seq_name passed in table parameter + $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $table); + } + else + { + return pg_last_oid($this->result_id); + } + $query = $this->query($sql); + $row = $query->row(); + return $row->ins_id; + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + return '0'; + + $query = $this->query('SELECT COUNT(*) AS numrows FROM "'.$this->dbprefix.$table.'"'); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _list_columns($table = '') + { + return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->_escape_table($table)."'"; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + return "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access private + * @return string + */ + function _error_message() + { + return pg_last_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access private + * @return integer + */ + function _error_number() + { + return ''; + } + + // -------------------------------------------------------------------- + + /** + * Escape Table Name + * + * This function adds backticks if the table name has a period + * in it. Some DBs will get cranky unless periods are escaped. + * + * @access private + * @param string the table name + * @return string + */ + function _escape_table($table) + { + if (stristr($table, '.')) + { + $table = '"'.preg_replace("/\./", '"."', $table).'"'; + } + + return $table; + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @return string + */ + function _update($table, $values, $where) + { + foreach($values as $key => $val) + { + $valstr[] = $key." = ".$val; + } + + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + $sql .= "LIMIT ".$limit; + + if ($offset > 0) + { + $sql .= " OFFSET ".$offset; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + @pg_close($conn_id); + } + + +} + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From d2df9bc7cc9d4b3e53818470c5d0977c9a36677c Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 15 Apr 2007 17:41:17 +0000 Subject: update pMachine to EllisLab update copyright year update Code Igniter to CodeIgniter --- system/database/drivers/postgre/postgre_driver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 58cc69a96..bfb212cfd 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -1,12 +1,12 @@ Date: Thu, 12 Jul 2007 13:56:21 +0000 Subject: fixed undefined function in insert_id() of PostgreSQL driver --- system/database/drivers/postgre/postgre_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index bfb212cfd..798905126 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -230,7 +230,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function insert_id() { - $v = version($this->conn_id); + $v = $this->_version(); $v = $v['server']; $table = func_num_args() > 0 ? func_get_arg(0) : null; -- cgit v1.2.3-24-g4f1b From 6838f00a708f53f834fb8a98af560177db1d1454 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 4 Oct 2007 19:29:59 +0000 Subject: Fixed a typo in the docblock comments that had CodeIgniter spelled CodeIgnitor. --- system/database/drivers/postgre/postgre_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 798905126..a8a6ca169 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource -- cgit v1.2.3-24-g4f1b From 694b5b8ee6a40b57c91be3c5448bc8f5540d32d8 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 18 Dec 2007 15:58:03 +0000 Subject: Added count_all_results() function to Active Record. --- system/database/drivers/postgre/postgre_driver.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index a8a6ca169..beaa7931c 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -30,6 +30,13 @@ */ class CI_DB_postgre_driver extends CI_DB { + /** + * The syntax to count rows is slightly different across different + * database engines, so this string appears in each driver and is + * used for the count_all() and count_all_results() functions. + */ + var $count_string = "SELECT COUNT(*) AS numrows "; + /** * Non-persistent database connection * @@ -277,9 +284,11 @@ class CI_DB_postgre_driver extends CI_DB { { if ($table == '') return '0'; - - $query = $this->query('SELECT COUNT(*) AS numrows FROM "'.$this->dbprefix.$table.'"'); - + + $query = $this->query($this->count_string .'FROM "'.$this->dbprefix.$table.'"'); +// original query before count_string was used. Kept for reference +// $query = $this->query('SELECT COUNT(*) AS numrows FROM "'.$this->dbprefix.$table.'"'); + if ($query->num_rows() == 0) return '0'; @@ -315,7 +324,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function _list_columns($table = '') { - return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->_escape_table($table)."'"; + return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->_escape_table($table)."'"; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 6ddb5a17ae1a0a75ca75f846dbb7d3a98f1902a3 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 18 Dec 2007 17:22:50 +0000 Subject: Added 'random' as an order_by() option in Active Record. --- system/database/drivers/postgre/postgre_driver.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index beaa7931c..e54f9cceb 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -35,7 +35,8 @@ class CI_DB_postgre_driver extends CI_DB { * database engines, so this string appears in each driver and is * used for the count_all() and count_all_results() functions. */ - var $count_string = "SELECT COUNT(*) AS numrows "; + var $_count_string = "SELECT COUNT(*) AS numrows "; + var $_random_keyword = ' RANDOM()'; // database specific random keyword /** * Non-persistent database connection @@ -285,8 +286,8 @@ class CI_DB_postgre_driver extends CI_DB { if ($table == '') return '0'; - $query = $this->query($this->count_string .'FROM "'.$this->dbprefix.$table.'"'); -// original query before count_string was used. Kept for reference + $query = $this->query($this->_count_string .'FROM "'.$this->dbprefix.$table.'"'); +// original query before _count_string was used. Kept for reference // $query = $this->query('SELECT COUNT(*) AS numrows FROM "'.$this->dbprefix.$table.'"'); if ($query->num_rows() == 0) -- cgit v1.2.3-24-g4f1b From da6d240d7b8615b5ae628496c42cb216658eb6e4 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 19 Dec 2007 14:49:29 +0000 Subject: Added support for limit() into update() statements in Active Record. --- system/database/drivers/postgre/postgre_driver.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index e54f9cceb..076d87a58 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -423,14 +423,16 @@ class CI_DB_postgre_driver extends CI_DB { * @param array the where clause * @return string */ - function _update($table, $values, $where) + function _update($table, $values, $where, $limit = FALSE) { foreach($values as $key => $val) { $valstr[] = $key." = ".$val; } + + $limit = (!$limit) ? '' : ' LIMIT '.$limit; - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$limit; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From e77d77c6b4c094483a3d85b23845436b77796d07 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 19 Dec 2007 15:01:55 +0000 Subject: Added support for limit() into update() and delete() statements in Active Record. --- system/database/drivers/postgre/postgre_driver.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 076d87a58..88f08b2d7 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -447,9 +447,11 @@ class CI_DB_postgre_driver extends CI_DB { * @param array the where clause * @return string */ - function _delete($table, $where) + function _delete($table, $where, $limit = FALSE) { - return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where); + $limit = (!$limit) ? '' : ' LIMIT '.$limit; + + return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where).$limit; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 39b622db9bda38282a32bb45623da63efe685729 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 16 Jan 2008 21:10:09 +0000 Subject: Many new Active Record functions, and another whack of stuff --- system/database/drivers/postgre/postgre_driver.php | 129 +++++++++++++++++++-- 1 file changed, 121 insertions(+), 8 deletions(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 88f08b2d7..63a72f5d3 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -35,7 +35,7 @@ class CI_DB_postgre_driver extends CI_DB { * database engines, so this string appears in each driver and is * used for the count_all() and count_all_results() functions. */ - var $_count_string = "SELECT COUNT(*) AS numrows "; + var $_count_string = "SELECT COUNT(*) AS "; var $_random_keyword = ' RANDOM()'; // database specific random keyword /** @@ -82,6 +82,22 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Set client character set + * + * @access public + * @param string + * @param string + * @return resource + */ + function db_set_charset($charset, $collation) + { + // TODO - add support if needed + return TRUE; + } + + // -------------------------------------------------------------------- + /** * Version number query string * @@ -305,11 +321,19 @@ class CI_DB_postgre_driver extends CI_DB { * Generates a platform-specific query string so that the table names can be fetched * * @access private + * @param boolean * @return string */ - function _list_tables() + function _list_tables($prefix_limit = FALSE) { - return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; + $sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; + + if ($prefix_limit !== FALSE AND $this->dbprefix != '') + { + $sql .= " AND table_name LIKE '".$this->dbprefix."%'"; + } + + return $sql; } // -------------------------------------------------------------------- @@ -394,6 +418,58 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Protect Identifiers + * + * This function adds backticks if appropriate based on db type + * + * @access private + * @param mixed the item to escape + * @param boolean only affect the first word + * @return mixed the item with backticks + */ + function _protect_identifiers($item, $first_word_only = FALSE) + { + if (is_array($item)) + { + $escaped_array = array(); + + foreach($item as $k=>$v) + { + $escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v, $first_word_only); + } + + return $escaped_array; + } + + // This function may get "item1 item2" as a string, and so + // we may need ""item1" "item2"" and not ""item1 item2"" + if (strpos($item, ' ') !== FALSE) + { + // This function may get "field >= 1", and need it to return ""field" >= 1" + if ($first_word_only === TRUE) + { + return '"'.preg_replace('/ /', '" ', $item, 1); + } + + $item = preg_replace('/(^|\s|\()([\w\d\-\_]+?)(\s|\)|$)/iS', '$1"$2"$3', $item); + } + + $exceptions = array('AS', '/', '-', '%', '+', '*'); + + foreach ($exceptions as $exception) + { + if (stristr($item, " "{$exception}" ") !== FALSE) + { + $item = preg_replace('/ "('.preg_quote($exception).')" /i', ' $1 ', $item); + } + } + + return $item; + } + + // -------------------------------------------------------------------- + /** * Insert statement * @@ -421,9 +497,11 @@ class CI_DB_postgre_driver extends CI_DB { * @param string the table name * @param array the update data * @param array the where clause + * @param array the orderby clause + * @param array the limit clause * @return string */ - function _update($table, $values, $where, $limit = FALSE) + function _update($table, $values, $where, $orderby = array(), $limit = FALSE) { foreach($values as $key => $val) { @@ -431,8 +509,29 @@ class CI_DB_postgre_driver extends CI_DB { } $limit = (!$limit) ? '' : ' LIMIT '.$limit; + + $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$limit; + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$orderby.$limit; + } + + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * If the database does not support the truncate() command + * This function maps to "DELETE FROM table" + * + * @access public + * @param string the table name + * @return string + */ + function _truncate($table) + { + return "TRUNCATE ".$this->_escape_table($table); } // -------------------------------------------------------------------- @@ -445,17 +544,31 @@ class CI_DB_postgre_driver extends CI_DB { * @access public * @param string the table name * @param array the where clause + * @param string the limit clause * @return string */ - function _delete($table, $where, $limit = FALSE) + function _delete($table, $where = array(), $like = array(), $limit = FALSE) { + $conditions = ''; + + if (count($where) > 0 || count($like) > 0) + { + $conditions = "\nWHERE "; + $conditions .= implode("\n", $this->ar_where); + + if (count($where) > 0 && count($like) > 0) + { + $conditions .= " AND "; + } + $conditions .= implode("\n", $like); + } + $limit = (!$limit) ? '' : ' LIMIT '.$limit; - return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where).$limit; + return "DELETE FROM ".$table.$conditions.$limit; } // -------------------------------------------------------------------- - /** * Limit string * -- cgit v1.2.3-24-g4f1b From 6157938ad5dd9d48607921593ca4ed7bff3e3a8b Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 16 Jan 2008 22:22:42 +0000 Subject: --- system/database/drivers/postgre/postgre_driver.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 63a72f5d3..fa27f03d5 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -444,27 +444,28 @@ class CI_DB_postgre_driver extends CI_DB { // This function may get "item1 item2" as a string, and so // we may need ""item1" "item2"" and not ""item1 item2"" - if (strpos($item, ' ') !== FALSE) + if (ctype_alnum($item) === FALSE) { // This function may get "field >= 1", and need it to return ""field" >= 1" - if ($first_word_only === TRUE) - { - return '"'.preg_replace('/ /', '" ', $item, 1); - } + $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; - $item = preg_replace('/(^|\s|\()([\w\d\-\_]+?)(\s|\)|$)/iS', '$1"$2"$3', $item); + $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1"$2"$3', $item); + } + else + { + return ""{$item}""; } $exceptions = array('AS', '/', '-', '%', '+', '*'); foreach ($exceptions as $exception) { + if (stristr($item, " "{$exception}" ") !== FALSE) { $item = preg_replace('/ "('.preg_quote($exception).')" /i', ' $1 ', $item); } } - return $item; } -- cgit v1.2.3-24-g4f1b From f6cd45ccb9f8825eb44dd2fa736c7aa0082ff98c Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 18 Jan 2008 14:31:51 +0000 Subject: fix for count_all --- system/database/drivers/postgre/postgre_driver.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index fa27f03d5..8ea76033c 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -302,9 +302,7 @@ class CI_DB_postgre_driver extends CI_DB { if ($table == '') return '0'; - $query = $this->query($this->_count_string .'FROM "'.$this->dbprefix.$table.'"'); -// original query before _count_string was used. Kept for reference -// $query = $this->query('SELECT COUNT(*) AS numrows FROM "'.$this->dbprefix.$table.'"'); + $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($this->dbprefix.$table)); if ($query->num_rows() == 0) return '0'; -- cgit v1.2.3-24-g4f1b From 3d879d529107c0c9d3f1e6b894d9ed17b6e6c54f Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 18 Jan 2008 19:41:32 +0000 Subject: ExpressionEngine Dev Team in credit --- system/database/drivers/postgre/postgre_driver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 8ea76033c..5bf87c597 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -25,7 +25,7 @@ * @package CodeIgniter * @subpackage Drivers * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_postgre_driver extends CI_DB { -- cgit v1.2.3-24-g4f1b From 7a9193afa6d890a91eb3528fa0e62df799b07ed6 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 21 Jan 2008 18:39:20 +0000 Subject: replaced www.codeigniter.com with codeigniter.com --- system/database/drivers/postgre/postgre_driver.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 5bf87c597..34d76de61 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -26,7 +26,7 @@ * @subpackage Drivers * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_postgre_driver extends CI_DB { -- cgit v1.2.3-24-g4f1b From 4acd792e54f58a5d86269057b5a827440fc2efcd Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sat, 26 Jan 2008 19:33:59 +0000 Subject: fix a postgre escape error --- system/database/drivers/postgre/postgre_driver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 34d76de61..96cf2dfe9 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -451,7 +451,7 @@ class CI_DB_postgre_driver extends CI_DB { } else { - return ""{$item}""; + return "\"{$item}\""; } $exceptions = array('AS', '/', '-', '%', '+', '*'); @@ -459,7 +459,7 @@ class CI_DB_postgre_driver extends CI_DB { foreach ($exceptions as $exception) { - if (stristr($item, " "{$exception}" ") !== FALSE) + if (stristr($item, " \"{$exception}\" ") !== FALSE) { $item = preg_replace('/ "('.preg_quote($exception).')" /i', ' $1 ', $item); } -- cgit v1.2.3-24-g4f1b From c6ad0237eb6957046343ca654ab1c7d26787d466 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 29 Jan 2008 18:44:54 +0000 Subject: Abstracted FROM table listing in Active Record for databases that do not support parenthetic grouping of tables to explicitly define operator precedence --- system/database/drivers/postgre/postgre_driver.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 96cf2dfe9..20f91650a 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -469,6 +469,28 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * From Tables + * + * This function implicitly groups FROM tables so there is no confusion + * about operator precedence in harmony with SQL standards + * + * @access public + * @param type + * @return type + */ + function _from_tables($tables) + { + if (! is_array($tables)) + { + $tables = array($tables); + } + + return '('.implode(', ', $tables).')'; + } + + // -------------------------------------------------------------------- + /** * Insert statement * -- cgit v1.2.3-24-g4f1b From 7b80700a88e3e3a9ad46fe484e1cbfc3bd353b91 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 31 Jan 2008 23:52:01 +0000 Subject: remove parenthesis from postrgre _from_tables --- system/database/drivers/postgre/postgre_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 20f91650a..e72981348 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -486,7 +486,7 @@ class CI_DB_postgre_driver extends CI_DB { $tables = array($tables); } - return '('.implode(', ', $tables).')'; + return implode(', ', $tables); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 9b3e7b5f2d4ec4feae793ef90454506addbb19e1 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 4 Feb 2008 23:20:34 +0000 Subject: Added and documented Active Record caching. Made AR fully database-prefix aware --- system/database/drivers/postgre/postgre_driver.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index e72981348..ae8bd86eb 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -444,6 +444,13 @@ class CI_DB_postgre_driver extends CI_DB { // we may need ""item1" "item2"" and not ""item1 item2"" if (ctype_alnum($item) === FALSE) { + if (strpos($item, '.') !== FALSE) + { + $aliased_tables = implode(".",$this->ar_aliased_tables).'.'; + $table_name = substr($item, 0, strpos($item, '.')+1); + $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item; + } + // This function may get "field >= 1", and need it to return ""field" >= 1" $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; @@ -486,7 +493,7 @@ class CI_DB_postgre_driver extends CI_DB { $tables = array($tables); } - return implode(', ', $tables); + return '('.implode(', ', $tables).')'; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 32cf7eb132ec688a3b0339f266efa3f064c58a60 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 5 Feb 2008 16:03:50 +0000 Subject: Changed the behaviour of Active Record's update() to make the WHERE clause optional (#3395) --- system/database/drivers/postgre/postgre_driver.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index ae8bd86eb..cac0ecb60 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -540,7 +540,11 @@ class CI_DB_postgre_driver extends CI_DB { $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$orderby.$limit; + $sql = "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr); + $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; + $sql .= $orderby.$limit; + + return $sql; } -- cgit v1.2.3-24-g4f1b From 156481371306db532d6b3880d0914e9237b93685 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 10 Feb 2008 21:46:18 +0000 Subject: changes for enhanced database compatibility --- system/database/drivers/postgre/postgre_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index cac0ecb60..a32c37ed8 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -493,7 +493,7 @@ class CI_DB_postgre_driver extends CI_DB { $tables = array($tables); } - return '('.implode(', ', $tables).')'; + return implode(', ', $tables); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 41d4b592b9b0962e444938fcf106cccbbd8fda59 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 10 Feb 2008 23:47:13 +0000 Subject: escape_table made consistent with mysql driver across all drivers --- system/database/drivers/postgre/postgre_driver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index a32c37ed8..2472c5e92 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -406,9 +406,9 @@ class CI_DB_postgre_driver extends CI_DB { */ function _escape_table($table) { - if (stristr($table, '.')) + if (strpos($table, '.') !== FALSE) { - $table = '"'.preg_replace("/\./", '"."', $table).'"'; + $table = str_replace('.', '`.`', $table); } return $table; -- cgit v1.2.3-24-g4f1b From 70529a739dd0a73fc72124720390313d8a8b0dca Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 11 Feb 2008 03:54:42 +0000 Subject: driver escape_table fixes --- system/database/drivers/postgre/postgre_driver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 2472c5e92..a32c37ed8 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -406,9 +406,9 @@ class CI_DB_postgre_driver extends CI_DB { */ function _escape_table($table) { - if (strpos($table, '.') !== FALSE) + if (stristr($table, '.')) { - $table = str_replace('.', '`.`', $table); + $table = '"'.preg_replace("/\./", '"."', $table).'"'; } return $table; -- cgit v1.2.3-24-g4f1b From c0743381b20910a3fc23b391e8b2009ac5771ae8 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 11 Feb 2008 05:54:44 +0000 Subject: database enhancements, compatibility additions and bugfixes --- system/database/drivers/postgre/postgre_driver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index a32c37ed8..ce8cb258a 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -406,9 +406,9 @@ class CI_DB_postgre_driver extends CI_DB { */ function _escape_table($table) { - if (stristr($table, '.')) + if (strpos($table, '.') !== FALSE) { - $table = '"'.preg_replace("/\./", '"."', $table).'"'; + $table = '"' . str_replace('.', '"."', $table) . '"'; } return $table; -- cgit v1.2.3-24-g4f1b From 9a4d1da5fa823b6bb58cdd1d210f782e95830e91 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 25 Feb 2008 14:18:38 +0000 Subject: Fixed an AR_caching error where it wasn't tracking table aliases (#3463) --- system/database/drivers/postgre/postgre_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index ce8cb258a..4eff97fcc 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -461,7 +461,7 @@ class CI_DB_postgre_driver extends CI_DB { return "\"{$item}\""; } - $exceptions = array('AS', '/', '-', '%', '+', '*'); + $exceptions = array('AS', '/', '-', '%', '+', '*', 'OR', 'IS'); foreach ($exceptions as $exception) { -- cgit v1.2.3-24-g4f1b From 7327499064ae165468c7440f8571c3e570b58a0b Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 5 May 2008 16:39:18 +0000 Subject: Added get_dir_file_info(), get_file_info(), and get_mime_by_extension() to the File Helper. Changed ( ! condition) into (! condition) within the code --- system/database/drivers/postgre/postgre_driver.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 4eff97fcc..46ba1d009 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -150,7 +150,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function trans_begin($test_mode = FALSE) { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } @@ -179,7 +179,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function trans_commit() { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } @@ -203,7 +203,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function trans_rollback() { - if ( ! $this->trans_enabled) + if (! $this->trans_enabled) { return TRUE; } -- cgit v1.2.3-24-g4f1b From 5583e1aae64ff7e902136c4ba610d438dc2015d4 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Sun, 11 May 2008 15:48:20 +0000 Subject: removed closing PHP tag from all framework files --- system/database/drivers/postgre/postgre_driver.php | 1 - 1 file changed, 1 deletion(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 46ba1d009..7c46e7a4b 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -641,4 +641,3 @@ class CI_DB_postgre_driver extends CI_DB { } -?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c7deac9f2f9e43cedb18202542e8a46061df046e Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Sun, 11 May 2008 16:27:41 +0000 Subject: Undoing change committed in r1115 --- system/database/drivers/postgre/postgre_driver.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 7c46e7a4b..46ba1d009 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -641,3 +641,4 @@ class CI_DB_postgre_driver extends CI_DB { } +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From a3ffbbb75ab9403941e4f810703313432b3993cc Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Sun, 11 May 2008 18:18:29 +0000 Subject: Removed closing PHP tags, replaced with a comment block identifying the end of the file --- system/database/drivers/postgre/postgre_driver.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 46ba1d009..4fd92f0c0 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -641,4 +641,6 @@ class CI_DB_postgre_driver extends CI_DB { } -?> \ No newline at end of file + +/* End of file postgre_driver.php */ +/* Location: ./system/database/drivers/postgre/postgre_driver.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 0b59f270a432f8c7b6128981f0a39b4a2e2fbd34 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 13 May 2008 04:22:33 +0000 Subject: Some sweeping syntax changes for consistency: (! foo) changed to ( ! foo) || changed to OR changed newline standardization code in various places from preg_replace to str_replace --- system/database/drivers/postgre/postgre_driver.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 4fd92f0c0..9a260a5ac 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -1,4 +1,4 @@ -trans_enabled) + if ( ! $this->trans_enabled) { return TRUE; } @@ -179,7 +179,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function trans_commit() { - if (! $this->trans_enabled) + if ( ! $this->trans_enabled) { return TRUE; } @@ -203,7 +203,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function trans_rollback() { - if (! $this->trans_enabled) + if ( ! $this->trans_enabled) { return TRUE; } @@ -488,7 +488,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function _from_tables($tables) { - if (! is_array($tables)) + if ( ! is_array($tables)) { $tables = array($tables); } @@ -536,7 +536,7 @@ class CI_DB_postgre_driver extends CI_DB { $valstr[] = $key." = ".$val; } - $limit = (!$limit) ? '' : ' LIMIT '.$limit; + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; @@ -583,7 +583,7 @@ class CI_DB_postgre_driver extends CI_DB { { $conditions = ''; - if (count($where) > 0 || count($like) > 0) + if (count($where) > 0 OR count($like) > 0) { $conditions = "\nWHERE "; $conditions .= implode("\n", $this->ar_where); @@ -595,7 +595,7 @@ class CI_DB_postgre_driver extends CI_DB { $conditions .= implode("\n", $like); } - $limit = (!$limit) ? '' : ' LIMIT '.$limit; + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; return "DELETE FROM ".$table.$conditions.$limit; } @@ -641,6 +641,6 @@ class CI_DB_postgre_driver extends CI_DB { } - -/* End of file postgre_driver.php */ + +/* End of file postgre_driver.php */ /* Location: ./system/database/drivers/postgre/postgre_driver.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 9ba2bf2e2094c12533887fe77c0ef5006e41c960 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Fri, 12 Sep 2008 23:34:39 +0000 Subject: updated copyright --- system/database/drivers/postgre/postgre_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 9a260a5ac..7574ded13 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b From 52dc8ca4372eb36e9186cef0e34bf0cafe5b1cd8 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 30 Sep 2008 19:53:52 +0000 Subject: Added backticks to column names when using insert_string and update_string. Relates to this bug report: http://codeigniter.com/bug_tracker/bug/4509/ --- system/database/drivers/postgre/postgre_driver.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 7574ded13..3d006d3d6 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -391,7 +391,23 @@ class CI_DB_postgre_driver extends CI_DB { { return ''; } - + // -------------------------------------------------------------------- + + /** + * Escape Column Name + * + * This function adds backticks around supplied column name + * + * @access private + * @param string the column name + * @return string + */ + function _escape_column($column) + { + // Probably not necessary with Postgres so we simply return the value + return $column; + } + // -------------------------------------------------------------------- /** -- cgit v1.2.3-24-g4f1b From ff73401cdef0136c15c6dab95d4d722123668e7a Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 30 Sep 2008 20:38:12 +0000 Subject: Did a little clean up. Nothing that affected functionality --- system/database/drivers/postgre/postgre_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 3d006d3d6..55f650280 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -92,7 +92,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function db_set_charset($charset, $collation) { - // TODO - add support if needed + // @todo - add support if needed return TRUE; } -- cgit v1.2.3-24-g4f1b From b6ba6a3a8ef3d594ff3f32f2d128a8211f1d2db3 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 7 Oct 2008 00:44:41 +0000 Subject: Added support for empty connection strings, based on bug # 3135 --- system/database/drivers/postgre/postgre_driver.php | 39 ++++++++++++++++++---- 1 file changed, 32 insertions(+), 7 deletions(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 55f650280..aada164d0 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -38,6 +38,35 @@ class CI_DB_postgre_driver extends CI_DB { var $_count_string = "SELECT COUNT(*) AS "; var $_random_keyword = ' RANDOM()'; // database specific random keyword + /** + * Connection String + * + * @access private + * @return string + */ + function _connect_string() + { + $components = array( + 'hostname' => 'host', + 'port' => 'port', + 'database' => 'dbname', + 'username' => 'user', + 'password' => 'password' + ); + + $connect_string = ""; + foreach ($components as $key => $val) + { + if (isset($this->$key) && $this->$key != '') + { + $connect_string .= " $val=".$this->$key; + } + } + return trim($connect_string); + } + + // -------------------------------------------------------------------- + /** * Non-persistent database connection * @@ -45,10 +74,8 @@ class CI_DB_postgre_driver extends CI_DB { * @return resource */ function db_connect() - { - $port = ($this->port == '') ? '' : " port=".$this->port; - - return @pg_connect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); + { + return @pg_connect($this->_connect_string()); } // -------------------------------------------------------------------- @@ -61,9 +88,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function db_pconnect() { - $port = ($this->port == '') ? '' : " port=".$this->port; - - return @pg_pconnect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); + return @pg_pconnect($this->_connect_string()); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 5aa8c60392a89140448691b838a90b7d1c644774 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 7 Oct 2008 01:24:07 +0000 Subject: Explicitly added driver name variable in each DB driver, based on this bug report: #4436 --- system/database/drivers/postgre/postgre_driver.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index aada164d0..c5c70a736 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -30,6 +30,8 @@ */ class CI_DB_postgre_driver extends CI_DB { + var $dbdriver = 'postgre'; + /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is -- cgit v1.2.3-24-g4f1b From 605a07a2ea479a8761588f7775b500a7e8d9e098 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Fri, 17 Oct 2008 04:07:54 +0000 Subject: Fixed a number of bug reports related to table/db names not being escaped or prefixed correctly. --- system/database/drivers/postgre/postgre_driver.php | 106 ++++----------------- 1 file changed, 21 insertions(+), 85 deletions(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index c5c70a736..d94cce149 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -31,6 +31,8 @@ class CI_DB_postgre_driver extends CI_DB { var $dbdriver = 'postgre'; + + var $_escape_char = '"'; /** * The syntax to count rows is slightly different across different @@ -329,7 +331,7 @@ class CI_DB_postgre_driver extends CI_DB { if ($table == '') return '0'; - $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($this->dbprefix.$table)); + $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); if ($query->num_rows() == 0) return '0'; @@ -374,7 +376,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function _list_columns($table = '') { - return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->_escape_table($table)."'"; + return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$table."'"; } // -------------------------------------------------------------------- @@ -390,7 +392,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function _field_data($table) { - return "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; + return "SELECT * FROM ".$table." LIMIT 1"; } // -------------------------------------------------------------------- @@ -418,103 +420,36 @@ class CI_DB_postgre_driver extends CI_DB { { return ''; } - // -------------------------------------------------------------------- - - /** - * Escape Column Name - * - * This function adds backticks around supplied column name - * - * @access private - * @param string the column name - * @return string - */ - function _escape_column($column) - { - // Probably not necessary with Postgres so we simply return the value - return $column; - } // -------------------------------------------------------------------- /** - * Escape Table Name + * Escape the SQL Identifiers * - * This function adds backticks if the table name has a period - * in it. Some DBs will get cranky unless periods are escaped. + * This function escapes column and table names * * @access private - * @param string the table name + * @param string * @return string */ - function _escape_table($table) + function _escape_identifiers($item) { - if (strpos($table, '.') !== FALSE) + if ($this->_escape_char == '') { - $table = '"' . str_replace('.', '"."', $table) . '"'; + return $item; } - - return $table; - } - // -------------------------------------------------------------------- - - /** - * Protect Identifiers - * - * This function adds backticks if appropriate based on db type - * - * @access private - * @param mixed the item to escape - * @param boolean only affect the first word - * @return mixed the item with backticks - */ - function _protect_identifiers($item, $first_word_only = FALSE) - { - if (is_array($item)) + if (strpos($item, '.') !== FALSE) { - $escaped_array = array(); - - foreach($item as $k=>$v) - { - $escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v, $first_word_only); - } - - return $escaped_array; - } - - // This function may get "item1 item2" as a string, and so - // we may need ""item1" "item2"" and not ""item1 item2"" - if (ctype_alnum($item) === FALSE) - { - if (strpos($item, '.') !== FALSE) - { - $aliased_tables = implode(".",$this->ar_aliased_tables).'.'; - $table_name = substr($item, 0, strpos($item, '.')+1); - $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item; - } - - // This function may get "field >= 1", and need it to return ""field" >= 1" - $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; - - $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1"$2"$3', $item); + $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; } else { - return "\"{$item}\""; + $str = $this->_escape_char.$item.$this->_escape_char; } - - $exceptions = array('AS', '/', '-', '%', '+', '*', 'OR', 'IS'); - foreach ($exceptions as $exception) - { - - if (stristr($item, " \"{$exception}\" ") !== FALSE) - { - $item = preg_replace('/ "('.preg_quote($exception).')" /i', ' $1 ', $item); - } - } - return $item; + // remove duplicates if the user already included the escape + return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); } // -------------------------------------------------------------------- @@ -554,7 +489,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function _insert($table, $keys, $values) { - return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -583,14 +518,15 @@ class CI_DB_postgre_driver extends CI_DB { $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - $sql = "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr); + $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); + $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; + $sql .= $orderby.$limit; return $sql; } - // -------------------------------------------------------------------- /** @@ -606,7 +542,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function _truncate($table) { - return "TRUNCATE ".$this->_escape_table($table); + return "TRUNCATE ".$table; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From a0e86293949ff7761cca573853e54146d76f9ba7 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Sun, 26 Oct 2008 22:46:55 +0000 Subject: Fixed a bug in which identifers were not being escaped properly when reserved characters were used --- system/database/drivers/postgre/postgre_driver.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index d94cce149..68622a22b 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -438,6 +438,17 @@ class CI_DB_postgre_driver extends CI_DB { { return $item; } + + foreach ($this->_reserved_identifiers as $id) + { + if (strpos($item, '.'.$id) !== FALSE) + { + $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); + + // remove duplicates if the user already included the escape + return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); + } + } if (strpos($item, '.') !== FALSE) { -- cgit v1.2.3-24-g4f1b From 2067d1a727e7eb5e5ffb40e967f3d1fc4c8a41b2 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 13 Nov 2008 22:59:24 +0000 Subject: Changing EOL style to LF --- system/database/drivers/postgre/postgre_driver.php | 1270 ++++++++++---------- 1 file changed, 635 insertions(+), 635 deletions(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 68622a22b..da0b0f23a 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -1,636 +1,636 @@ - 'host', - 'port' => 'port', - 'database' => 'dbname', - 'username' => 'user', - 'password' => 'password' - ); - - $connect_string = ""; - foreach ($components as $key => $val) - { - if (isset($this->$key) && $this->$key != '') - { - $connect_string .= " $val=".$this->$key; - } - } - return trim($connect_string); - } - - // -------------------------------------------------------------------- - - /** - * Non-persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_connect() - { - return @pg_connect($this->_connect_string()); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return @pg_pconnect($this->_connect_string()); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - // Not needed for Postgre so we'll return TRUE - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Set client character set - * - * @access public - * @param string - * @param string - * @return resource - */ - function db_set_charset($charset, $collation) - { - // @todo - add support if needed - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return resource - */ - function _execute($sql) - { - $sql = $this->_prep_query($sql); - return @pg_query($this->conn_id, $sql); - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @access private called by execute() - * @param string an SQL query - * @return string - */ - function _prep_query($sql) - { - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @return bool - */ - function trans_begin($test_mode = FALSE) - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - // Reset the transaction failure flag. - // If the $test_mode flag is set to TRUE transactions will be rolled back - // even if the queries produce a successful result. - $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; - - return @pg_exec($this->conn_id, "begin"); - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - return @pg_exec($this->conn_id, "commit"); - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - return @pg_exec($this->conn_id, "rollback"); - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @return string - */ - function escape_str($str) - { - return pg_escape_string($str); - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @pg_affected_rows($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - $v = $this->_version(); - $v = $v['server']; - - $table = func_num_args() > 0 ? func_get_arg(0) : null; - $column = func_num_args() > 1 ? func_get_arg(1) : null; - - if ($table == null && $v >= '8.1') - { - $sql='SELECT LASTVAL() as ins_id'; - } - elseif ($table != null && $column != null && $v >= '8.0') - { - $sql = sprintf("SELECT pg_get_serial_sequence('%s','%s') as seq", $table, $column); - $query = $this->query($sql); - $row = $query->row(); - $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $row->seq); - } - elseif ($table != null) - { - // seq_name passed in table parameter - $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $table); - } - else - { - return pg_last_oid($this->result_id); - } - $query = $this->query($sql); - $row = $query->row(); - return $row->ins_id; - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - return '0'; - - $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); - - if ($query->num_rows() == 0) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @param boolean - * @return string - */ - function _list_tables($prefix_limit = FALSE) - { - $sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; - - if ($prefix_limit !== FALSE AND $this->dbprefix != '') - { - $sql .= " AND table_name LIKE '".$this->dbprefix."%'"; - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Show column query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _list_columns($table = '') - { - return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$table."'"; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - return "SELECT * FROM ".$table." LIMIT 1"; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access private - * @return string - */ - function _error_message() - { - return pg_last_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access private - * @return integer - */ - function _error_number() - { - return ''; - } - - // -------------------------------------------------------------------- - - /** - * Escape the SQL Identifiers - * - * This function escapes column and table names - * - * @access private - * @param string - * @return string - */ - function _escape_identifiers($item) - { - if ($this->_escape_char == '') - { - return $item; - } - - foreach ($this->_reserved_identifiers as $id) - { - if (strpos($item, '.'.$id) !== FALSE) - { - $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } - } - - if (strpos($item, '.') !== FALSE) - { - $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; - } - else - { - $str = $this->_escape_char.$item.$this->_escape_char; - } - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } - - // -------------------------------------------------------------------- - - /** - * From Tables - * - * This function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @access public - * @param type - * @return type - */ - function _from_tables($tables) - { - if ( ! is_array($tables)) - { - $tables = array($tables); - } - - return implode(', ', $tables); - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @param array the orderby clause - * @param array the limit clause - * @return string - */ - function _update($table, $values, $where, $orderby = array(), $limit = FALSE) - { - foreach($values as $key => $val) - { - $valstr[] = $key." = ".$val; - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - - $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); - - $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; - - $sql .= $orderby.$limit; - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Truncate statement - * - * Generates a platform-specific truncate string from the supplied data - * If the database does not support the truncate() command - * This function maps to "DELETE FROM table" - * - * @access public - * @param string the table name - * @return string - */ - function _truncate($table) - { - return "TRUNCATE ".$table; - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @param string the limit clause - * @return string - */ - function _delete($table, $where = array(), $like = array(), $limit = FALSE) - { - $conditions = ''; - - if (count($where) > 0 OR count($like) > 0) - { - $conditions = "\nWHERE "; - $conditions .= implode("\n", $this->ar_where); - - if (count($where) > 0 && count($like) > 0) - { - $conditions .= " AND "; - } - $conditions .= implode("\n", $like); - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - return "DELETE FROM ".$table.$conditions.$limit; - } - - // -------------------------------------------------------------------- - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - $sql .= "LIMIT ".$limit; - - if ($offset > 0) - { - $sql .= " OFFSET ".$offset; - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - @pg_close($conn_id); - } - - -} - - -/* End of file postgre_driver.php */ + 'host', + 'port' => 'port', + 'database' => 'dbname', + 'username' => 'user', + 'password' => 'password' + ); + + $connect_string = ""; + foreach ($components as $key => $val) + { + if (isset($this->$key) && $this->$key != '') + { + $connect_string .= " $val=".$this->$key; + } + } + return trim($connect_string); + } + + // -------------------------------------------------------------------- + + /** + * Non-persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_connect() + { + return @pg_connect($this->_connect_string()); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return @pg_pconnect($this->_connect_string()); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + // Not needed for Postgre so we'll return TRUE + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Set client character set + * + * @access public + * @param string + * @param string + * @return resource + */ + function db_set_charset($charset, $collation) + { + // @todo - add support if needed + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + function _execute($sql) + { + $sql = $this->_prep_query($sql); + return @pg_query($this->conn_id, $sql); + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @access private called by execute() + * @param string an SQL query + * @return string + */ + function _prep_query($sql) + { + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @return bool + */ + function trans_begin($test_mode = FALSE) + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + // Reset the transaction failure flag. + // If the $test_mode flag is set to TRUE transactions will be rolled back + // even if the queries produce a successful result. + $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; + + return @pg_exec($this->conn_id, "begin"); + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @access public + * @return bool + */ + function trans_commit() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + return @pg_exec($this->conn_id, "commit"); + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @access public + * @return bool + */ + function trans_rollback() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + return @pg_exec($this->conn_id, "rollback"); + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + return pg_escape_string($str); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @pg_affected_rows($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + $v = $this->_version(); + $v = $v['server']; + + $table = func_num_args() > 0 ? func_get_arg(0) : null; + $column = func_num_args() > 1 ? func_get_arg(1) : null; + + if ($table == null && $v >= '8.1') + { + $sql='SELECT LASTVAL() as ins_id'; + } + elseif ($table != null && $column != null && $v >= '8.0') + { + $sql = sprintf("SELECT pg_get_serial_sequence('%s','%s') as seq", $table, $column); + $query = $this->query($sql); + $row = $query->row(); + $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $row->seq); + } + elseif ($table != null) + { + // seq_name passed in table parameter + $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $table); + } + else + { + return pg_last_oid($this->result_id); + } + $query = $this->query($sql); + $row = $query->row(); + return $row->ins_id; + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + return '0'; + + $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @param boolean + * @return string + */ + function _list_tables($prefix_limit = FALSE) + { + $sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; + + if ($prefix_limit !== FALSE AND $this->dbprefix != '') + { + $sql .= " AND table_name LIKE '".$this->dbprefix."%'"; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _list_columns($table = '') + { + return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$table."'"; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + return "SELECT * FROM ".$table." LIMIT 1"; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access private + * @return string + */ + function _error_message() + { + return pg_last_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access private + * @return integer + */ + function _error_number() + { + return ''; + } + + // -------------------------------------------------------------------- + + /** + * Escape the SQL Identifiers + * + * This function escapes column and table names + * + * @access private + * @param string + * @return string + */ + function _escape_identifiers($item) + { + if ($this->_escape_char == '') + { + return $item; + } + + foreach ($this->_reserved_identifiers as $id) + { + if (strpos($item, '.'.$id) !== FALSE) + { + $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); + + // remove duplicates if the user already included the escape + return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); + } + } + + if (strpos($item, '.') !== FALSE) + { + $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; + } + else + { + $str = $this->_escape_char.$item.$this->_escape_char; + } + + // remove duplicates if the user already included the escape + return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); + } + + // -------------------------------------------------------------------- + + /** + * From Tables + * + * This function implicitly groups FROM tables so there is no confusion + * about operator precedence in harmony with SQL standards + * + * @access public + * @param type + * @return type + */ + function _from_tables($tables) + { + if ( ! is_array($tables)) + { + $tables = array($tables); + } + + return implode(', ', $tables); + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @param array the orderby clause + * @param array the limit clause + * @return string + */ + function _update($table, $values, $where, $orderby = array(), $limit = FALSE) + { + foreach($values as $key => $val) + { + $valstr[] = $key." = ".$val; + } + + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; + + $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; + + $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); + + $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; + + $sql .= $orderby.$limit; + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * If the database does not support the truncate() command + * This function maps to "DELETE FROM table" + * + * @access public + * @param string the table name + * @return string + */ + function _truncate($table) + { + return "TRUNCATE ".$table; + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @param string the limit clause + * @return string + */ + function _delete($table, $where = array(), $like = array(), $limit = FALSE) + { + $conditions = ''; + + if (count($where) > 0 OR count($like) > 0) + { + $conditions = "\nWHERE "; + $conditions .= implode("\n", $this->ar_where); + + if (count($where) > 0 && count($like) > 0) + { + $conditions .= " AND "; + } + $conditions .= implode("\n", $like); + } + + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; + + return "DELETE FROM ".$table.$conditions.$limit; + } + + // -------------------------------------------------------------------- + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + $sql .= "LIMIT ".$limit; + + if ($offset > 0) + { + $sql .= " OFFSET ".$offset; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + @pg_close($conn_id); + } + + +} + + +/* End of file postgre_driver.php */ /* Location: ./system/database/drivers/postgre/postgre_driver.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From e37ab385f5c9ef8824d2ad4e31f544dbe6089095 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 3 Feb 2009 16:13:57 +0000 Subject: DB count_all() not returns an integer always Added some syntactical improvements within DB (braces) Fixed a bug when doing 'random' on order_by() (#5706). Fixed a bug where adding a primary key through Forge could fail (#5731). Fixed a bug when using DB cache on multiple databases (#5737). --- system/database/drivers/postgre/postgre_driver.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index da0b0f23a..9d53b1ef8 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -329,15 +329,19 @@ class CI_DB_postgre_driver extends CI_DB { function count_all($table = '') { if ($table == '') - return '0'; + { + return 0; + } + + $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); - $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); - if ($query->num_rows() == 0) - return '0'; + { + return 0; + } $row = $query->row(); - return $row->numrows; + return (int) $row->numrows; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From e4ed583067095144eb20aefc61d4499d8386532a Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 20 Feb 2009 21:44:59 +0000 Subject: added LIKE condition escaping to all drivers and Active Record updated all DB drivers to accept arrays in escape_str() --- system/database/drivers/postgre/postgre_driver.php | 31 +++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 9d53b1ef8..8d0d8901c 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -34,6 +34,10 @@ class CI_DB_postgre_driver extends CI_DB { var $_escape_char = '"'; + // clause and character used for LIKE escape sequences + var $_like_escape_str = " ESCAPE '%s' "; + var $_like_escape_chr = '!'; + /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is @@ -253,11 +257,32 @@ class CI_DB_postgre_driver extends CI_DB { * * @access public * @param string + * @param bool whether or not the string will be used in a LIKE condition * @return string */ - function escape_str($str) - { - return pg_escape_string($str); + function escape_str($str, $like = FALSE) + { + if (is_array($str)) + { + foreach($str as $key => $val) + { + $str[$key] = $this->escape_str($val, $like); + } + + return $str; + } + + $str = pg_escape_string($str); + + // escape LIKE condition wildcards + if ($like === TRUE) + { + $str = str_replace( array('%', '_', $this->_like_escape_chr), + array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr), + $str); + } + + return $str; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 3c11b6f5dee83ebe11dfdcec3022313c45a4a4e2 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 20 Feb 2009 22:36:27 +0000 Subject: updated _list_tables() in db drivers to escape the db prefix for LIKE wildcards --- system/database/drivers/postgre/postgre_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 8d0d8901c..4bc5b7d94 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -386,7 +386,7 @@ class CI_DB_postgre_driver extends CI_DB { if ($prefix_limit !== FALSE AND $this->dbprefix != '') { - $sql .= " AND table_name LIKE '".$this->dbprefix."%'"; + $sql .= " AND table_name LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_char); } return $sql; -- cgit v1.2.3-24-g4f1b From 87cbafce2d6803af78714baf8bba64309c01fc33 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 27 Feb 2009 16:29:59 +0000 Subject: added reconnect() method to db drivers --- system/database/drivers/postgre/postgre_driver.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 4bc5b7d94..db3a3f29d 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -101,6 +101,25 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Reconnect + * + * Keep / reestablish the db connection if no queries have been + * sent for a length of time exceeding the server's idle timeout + * + * @access public + * @return void + */ + function reconnect() + { + if (pg_ping($this->conn_id) === FALSE) + { + $this->conn_id = FALSE; + } + } + + // -------------------------------------------------------------------- + /** * Select the database * -- cgit v1.2.3-24-g4f1b From fc395a1046441cb584cbcfe42651dacece7eca3e Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 22 Apr 2009 14:15:09 +0000 Subject: updated copyrights to 2009 --- system/database/drivers/postgre/postgre_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index db3a3f29d..9258da684 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b From 7f3719faf120dc15f3d7b45e132ab3192f60ad62 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 5 Jan 2010 13:35:37 +0000 Subject: updated copyrights --- system/database/drivers/postgre/postgre_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 9258da684..bac179d40 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b From 0d42489234e0fdfecd11f46b1d3573e60db3918c Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Tue, 26 Jan 2010 02:14:44 +0000 Subject: Misspelled class property in db class. _like_escape_chr, not _like_escape_char http://codeigniter.com/bug_tracker/bug/9518/ --- system/database/drivers/postgre/postgre_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index bac179d40..9f991e4a0 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -405,7 +405,7 @@ class CI_DB_postgre_driver extends CI_DB { if ($prefix_limit !== FALSE AND $this->dbprefix != '') { - $sql .= " AND table_name LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_char); + $sql .= " AND table_name LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); } return $sql; -- cgit v1.2.3-24-g4f1b From dd6719738936be31cdaa1758ca86d5eb14dcab3d Mon Sep 17 00:00:00 2001 From: Barry Mieny Date: Mon, 4 Oct 2010 16:33:58 +0200 Subject: Cleanup of stray spaces and tabs --- system/database/drivers/postgre/postgre_driver.php | 116 ++++++++++----------- 1 file changed, 58 insertions(+), 58 deletions(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 9f991e4a0..cf865432b 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -31,7 +31,7 @@ class CI_DB_postgre_driver extends CI_DB { var $dbdriver = 'postgre'; - + var $_escape_char = '"'; // clause and character used for LIKE escape sequences @@ -51,7 +51,7 @@ class CI_DB_postgre_driver extends CI_DB { * * @access private * @return string - */ + */ function _connect_string() { $components = array( @@ -61,7 +61,7 @@ class CI_DB_postgre_driver extends CI_DB { 'username' => 'user', 'password' => 'password' ); - + $connect_string = ""; foreach ($components as $key => $val) { @@ -80,9 +80,9 @@ class CI_DB_postgre_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_connect() - { + { return @pg_connect($this->_connect_string()); } @@ -93,12 +93,12 @@ class CI_DB_postgre_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_pconnect() { return @pg_pconnect($this->_connect_string()); } - + // -------------------------------------------------------------------- /** @@ -125,7 +125,7 @@ class CI_DB_postgre_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_select() { // Not needed for Postgre so we'll return TRUE @@ -149,7 +149,7 @@ class CI_DB_postgre_driver extends CI_DB { } // -------------------------------------------------------------------- - + /** * Version number query string * @@ -169,13 +169,13 @@ class CI_DB_postgre_driver extends CI_DB { * @access private called by the base class * @param string an SQL query * @return resource - */ + */ function _execute($sql) { $sql = $this->_prep_query($sql); return @pg_query($this->conn_id, $sql); } - + // -------------------------------------------------------------------- /** @@ -186,7 +186,7 @@ class CI_DB_postgre_driver extends CI_DB { * @access private called by execute() * @param string an SQL query * @return string - */ + */ function _prep_query($sql) { return $sql; @@ -198,15 +198,15 @@ class CI_DB_postgre_driver extends CI_DB { * Begin Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_begin($test_mode = FALSE) { if ( ! $this->trans_enabled) { return TRUE; } - + // When transactions are nested we only begin/commit/rollback the outermost ones if ($this->_trans_depth > 0) { @@ -227,8 +227,8 @@ class CI_DB_postgre_driver extends CI_DB { * Commit Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_commit() { if ( ! $this->trans_enabled) @@ -251,8 +251,8 @@ class CI_DB_postgre_driver extends CI_DB { * Rollback Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_rollback() { if ( ! $this->trans_enabled) @@ -284,15 +284,15 @@ class CI_DB_postgre_driver extends CI_DB { if (is_array($str)) { foreach($str as $key => $val) - { + { $str[$key] = $this->escape_str($val, $like); - } - - return $str; - } + } + + return $str; + } $str = pg_escape_string($str); - + // escape LIKE condition wildcards if ($like === TRUE) { @@ -300,10 +300,10 @@ class CI_DB_postgre_driver extends CI_DB { array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr), $str); } - + return $str; } - + // -------------------------------------------------------------------- /** @@ -316,7 +316,7 @@ class CI_DB_postgre_driver extends CI_DB { { return @pg_affected_rows($this->result_id); } - + // -------------------------------------------------------------------- /** @@ -329,10 +329,10 @@ class CI_DB_postgre_driver extends CI_DB { { $v = $this->_version(); $v = $v['server']; - + $table = func_num_args() > 0 ? func_get_arg(0) : null; $column = func_num_args() > 1 ? func_get_arg(1) : null; - + if ($table == null && $v >= '8.1') { $sql='SELECT LASTVAL() as ins_id'; @@ -400,17 +400,17 @@ class CI_DB_postgre_driver extends CI_DB { * @return string */ function _list_tables($prefix_limit = FALSE) - { - $sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; - + { + $sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; + if ($prefix_limit !== FALSE AND $this->dbprefix != '') { $sql .= " AND table_name LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); } - + return $sql; } - + // -------------------------------------------------------------------- /** @@ -455,7 +455,7 @@ class CI_DB_postgre_driver extends CI_DB { { return pg_last_error($this->conn_id); } - + // -------------------------------------------------------------------- /** @@ -491,26 +491,26 @@ class CI_DB_postgre_driver extends CI_DB { { if (strpos($item, '.'.$id) !== FALSE) { - $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); - + $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); + // remove duplicates if the user already included the escape return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } + } } - + if (strpos($item, '.') !== FALSE) { - $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; + $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; } else { $str = $this->_escape_char.$item.$this->_escape_char; } - + // remove duplicates if the user already included the escape return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); } - + // -------------------------------------------------------------------- /** @@ -529,12 +529,12 @@ class CI_DB_postgre_driver extends CI_DB { { $tables = array($tables); } - + return implode(', ', $tables); } // -------------------------------------------------------------------- - + /** * Insert statement * @@ -547,10 +547,10 @@ class CI_DB_postgre_driver extends CI_DB { * @return string */ function _insert($table, $keys, $values) - { + { return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } - + // -------------------------------------------------------------------- /** @@ -572,17 +572,17 @@ class CI_DB_postgre_driver extends CI_DB { { $valstr[] = $key." = ".$val; } - + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - + $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - + $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; $sql .= $orderby.$limit; - + return $sql; } @@ -598,12 +598,12 @@ class CI_DB_postgre_driver extends CI_DB { * @access public * @param string the table name * @return string - */ + */ function _truncate($table) { return "TRUNCATE ".$table; } - + // -------------------------------------------------------------------- /** @@ -616,7 +616,7 @@ class CI_DB_postgre_driver extends CI_DB { * @param array the where clause * @param string the limit clause * @return string - */ + */ function _delete($table, $where = array(), $like = array(), $limit = FALSE) { $conditions = ''; @@ -634,7 +634,7 @@ class CI_DB_postgre_driver extends CI_DB { } $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - + return "DELETE FROM ".$table.$conditions.$limit; } @@ -651,14 +651,14 @@ class CI_DB_postgre_driver extends CI_DB { * @return string */ function _limit($sql, $limit, $offset) - { + { $sql .= "LIMIT ".$limit; - + if ($offset > 0) { $sql .= " OFFSET ".$offset; } - + return $sql; } -- cgit v1.2.3-24-g4f1b From 741de1c1319dd13de75348863cca591713dd46ce Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Wed, 10 Nov 2010 14:52:57 -0600 Subject: Updating PHP requirements in files 5.1.6 --- system/database/drivers/postgre/postgre_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index cf865432b..b61a9d75b 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team -- cgit v1.2.3-24-g4f1b From 0711dc87d98ce20d3a87f7ac43d78af8fba1dca7 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Wed, 5 Jan 2011 10:49:40 -0600 Subject: Hey look, it's 2011 --- system/database/drivers/postgre/postgre_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index b61a9d75b..0bb7974d8 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b From 8761ef56b465a190489ed555c6a0ab58470bfc73 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Mon, 14 Feb 2011 13:13:52 -0500 Subject: Uppercasing some stray lowercase keywords for code consistency --- system/database/drivers/postgre/postgre_driver.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 0bb7974d8..81ca6e051 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -330,21 +330,21 @@ class CI_DB_postgre_driver extends CI_DB { $v = $this->_version(); $v = $v['server']; - $table = func_num_args() > 0 ? func_get_arg(0) : null; - $column = func_num_args() > 1 ? func_get_arg(1) : null; + $table = func_num_args() > 0 ? func_get_arg(0) : NULL; + $column = func_num_args() > 1 ? func_get_arg(1) : NULL; - if ($table == null && $v >= '8.1') + if ($table == NULL && $v >= '8.1') { $sql='SELECT LASTVAL() as ins_id'; } - elseif ($table != null && $column != null && $v >= '8.0') + elseif ($table != NULL && $column != NULL && $v >= '8.0') { $sql = sprintf("SELECT pg_get_serial_sequence('%s','%s') as seq", $table, $column); $query = $this->query($sql); $row = $query->row(); $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $row->seq); } - elseif ($table != null) + elseif ($table != NULL) { // seq_name passed in table parameter $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $table); -- cgit v1.2.3-24-g4f1b From c3a4a8d973b9c0a7cc935d150b8b1c6898037c45 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Mon, 14 Feb 2011 13:40:08 -0500 Subject: Whitespace cleanup in db classes --- system/database/drivers/postgre/postgre_driver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 81ca6e051..47ff36246 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -283,7 +283,7 @@ class CI_DB_postgre_driver extends CI_DB { { if (is_array($str)) { - foreach($str as $key => $val) + foreach ($str as $key => $val) { $str[$key] = $this->escape_str($val, $like); } @@ -568,7 +568,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function _update($table, $values, $where, $orderby = array(), $limit = FALSE) { - foreach($values as $key => $val) + foreach ($values as $key => $val) { $valstr[] = $key." = ".$val; } -- cgit v1.2.3-24-g4f1b From 114ab0988e20ac6be39ad363ff897a1a3b85e565 Mon Sep 17 00:00:00 2001 From: Razican Date: Mon, 25 Apr 2011 17:26:45 +0200 Subject: Fixed double-space typo. --- system/database/drivers/postgre/postgre_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 47ff36246..bf985de37 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -1,4 +1,4 @@ - Date: Wed, 27 Apr 2011 01:45:38 -0500 Subject: Added insert_batch() function to the PostgreSQL database driver. Thanks to epallerols for the patch. --- system/database/drivers/postgre/postgre_driver.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 47ff36246..140396885 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -553,6 +553,24 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Insert_batch statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert_batch($table, $keys, $values) + { + return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values); + } + + // -------------------------------------------------------------------- + /** * Update statement * -- cgit v1.2.3-24-g4f1b From 4b9c62980599228f070b401c7673dce8085b0c61 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 1 Jul 2011 17:40:48 -0500 Subject: backed out 648b42a75739, which was a NON-trivial whitespace commit. It broke the Typography class's string replacements, for instance --- system/database/drivers/postgre/postgre_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database/drivers/postgre/postgre_driver.php') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index bf985de37..47ff36246 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -1,4 +1,4 @@ -