From 7b613c7000a496fe0e4f9152ee8937d06eba2301 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 18:05:17 +0000 Subject: Adding database folder --- system/database/drivers/postgre/postgre.php | 484 +++++++++++++++++++++ system/database/drivers/postgre/postgre_result.php | 129 ++++++ .../database/drivers/postgre/postgre_utility.php | 41 ++ 3 files changed, 654 insertions(+) create mode 100644 system/database/drivers/postgre/postgre.php create mode 100644 system/database/drivers/postgre/postgre_result.php create mode 100644 system/database/drivers/postgre/postgre_utility.php (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre.php b/system/database/drivers/postgre/postgre.php new file mode 100644 index 000000000..317df37d1 --- /dev/null +++ b/system/database/drivers/postgre/postgre.php @@ -0,0 +1,484 @@ +port == '') ? '' : " port=".$this->port; + + return pg_connect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + $port = ($this->port == '') ? '' : " port=".$this->port; + + return pg_pconnect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + // Not needed for Postgre so we'll return TRUE + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + function _execute($sql) + { + $sql = $this->_prep_query($sql); + return @pg_query($this->conn_id, $sql); + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @access private called by execute() + * @param string an SQL query + * @return string + */ + function _prep_query($sql) + { + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @return bool + */ + function trans_begin($test_mode = FALSE) + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + // Reset the transaction failure flag. + // If the $test_mode flag is set to TRUE transactions will be rolled back + // even if the queries produce a successful result. + $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; + + return @pg_exec($this->conn_id, "begin"); + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @access public + * @return bool + */ + function trans_commit() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + return @pg_exec($this->conn_id, "commit"); + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @access public + * @return bool + */ + function trans_rollback() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + return @pg_exec($this->conn_id, "rollback"); + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + return pg_escape_string($str); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @pg_affected_rows($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + $v = pg_version($this->conn_id); + $v = $v['server']; + + $table = func_num_args() > 0 ? func_get_arg(0) : null; + $column = func_num_args() > 1 ? func_get_arg(1) : null; + + if ($table == null && $v >= '8.1') + { + $sql='SELECT LASTVAL() as ins_id'; + } + elseif ($table != null && $column != null && $v >= '8.0') + { + $sql = sprintf("SELECT pg_get_serial_sequence('%s','%s') as seq", $table, $column); + $query = $this->query($sql); + $row = $query->row(); + $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $row->seq); + } + elseif ($table != null) + { + // seq_name passed in table parameter + $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $table); + } + else + { + return pg_last_oid($this->result_id); + } + $query = $this->query($sql); + $row = $query->row(); + return $row->ins_id; + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + return '0'; + + $query = $this->query('SELECT COUNT(*) AS numrows FROM "'.$this->dbprefix.$table.'"'); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access public + * @return string + */ + function error_message() + { + return pg_last_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access public + * @return integer + */ + function error_number() + { + return ''; + } + + // -------------------------------------------------------------------- + + /** + * Escape Table Name + * + * This function adds backticks if the table name has a period + * in it. Some DBs will get cranky unless periods are escaped. + * + * @access public + * @param string the table name + * @return string + */ + function escape_table($table) + { + if (stristr($table, '.')) + { + $table = '"'.preg_replace("/\./", '"."', $table).'"'; + } + + return $table; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; + $query = $this->query($sql); + return $query->field_data(); + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @return string + */ + function _update($table, $values, $where) + { + foreach($values as $key => $val) + { + $valstr[] = $key." = ".$val; + } + + return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @return string + */ + function _delete($table, $where) + { + return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; + } + + // -------------------------------------------------------------------- + + /** + * Show columnn query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _show_columns($table = '') + { + return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->escape_table($table)."'"; + } + + // -------------------------------------------------------------------- + + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + $sql .= "LIMIT ".$limit; + + if ($offset > 0) + { + $sql .= " OFFSET ".$offset; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + pg_close($conn_id); + } + +} + +?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php new file mode 100644 index 000000000..6af7f94f2 --- /dev/null +++ b/system/database/drivers/postgre/postgre_result.php @@ -0,0 +1,129 @@ +result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @pg_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + for ($i = 0; $i < $this->num_fields(); $i++) + { + $F = new stdClass(); + $F->name = pg_field_name($this->result_id, $i); + $F->type = pg_field_type($this->result_id, $i); + $F->max_length = pg_field_size($this->result_id, $i); + $F->primary_key = $i == 0; + $F->default = ''; + + $retval[] = $F; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return null + */ + function free_result() + { + if (is_resource($this->result_id)) + { + pg_free_result($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @access private + * @return array + */ + function _fetch_assoc() + { + return pg_fetch_assoc($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + function _fetch_object() + { + return pg_fetch_object($this->result_id); + } + +} + +?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php new file mode 100644 index 000000000..760be81a0 --- /dev/null +++ b/system/database/drivers/postgre/postgre_utility.php @@ -0,0 +1,41 @@ + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 7eea4f8906c21c1061cc9f21100e5597aae648b9 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 18:13:17 +0000 Subject: --- system/database/drivers/postgre/postgre_driver.php | 484 +++++++++++++++++++++ 1 file changed, 484 insertions(+) create mode 100644 system/database/drivers/postgre/postgre_driver.php (limited to 'system/database/drivers/postgre') 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 46563d570944d6c5af8b4f46ba1eeca111eabaa4 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 Sep 2006 18:14:22 +0000 Subject: --- system/database/drivers/postgre/postgre.php | 484 ---------------------------- 1 file changed, 484 deletions(-) delete mode 100644 system/database/drivers/postgre/postgre.php (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre.php b/system/database/drivers/postgre/postgre.php deleted file mode 100644 index 317df37d1..000000000 --- a/system/database/drivers/postgre/postgre.php +++ /dev/null @@ -1,484 +0,0 @@ -port == '') ? '' : " port=".$this->port; - - return pg_connect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - $port = ($this->port == '') ? '' : " port=".$this->port; - - return pg_pconnect("host=".$this->hostname.$port." dbname=".$this->database." user=".$this->username." password=".$this->password); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - // Not needed for Postgre so we'll return TRUE - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return resource - */ - function _execute($sql) - { - $sql = $this->_prep_query($sql); - return @pg_query($this->conn_id, $sql); - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @access private called by execute() - * @param string an SQL query - * @return string - */ - function _prep_query($sql) - { - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @return bool - */ - function trans_begin($test_mode = FALSE) - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - // Reset the transaction failure flag. - // If the $test_mode flag is set to TRUE transactions will be rolled back - // even if the queries produce a successful result. - $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; - - return @pg_exec($this->conn_id, "begin"); - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - return @pg_exec($this->conn_id, "commit"); - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - return @pg_exec($this->conn_id, "rollback"); - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @return string - */ - function escape_str($str) - { - return pg_escape_string($str); - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @pg_affected_rows($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - $v = pg_version($this->conn_id); - $v = $v['server']; - - $table = func_num_args() > 0 ? func_get_arg(0) : null; - $column = func_num_args() > 1 ? func_get_arg(1) : null; - - if ($table == null && $v >= '8.1') - { - $sql='SELECT LASTVAL() as ins_id'; - } - elseif ($table != null && $column != null && $v >= '8.0') - { - $sql = sprintf("SELECT pg_get_serial_sequence('%s','%s') as seq", $table, $column); - $query = $this->query($sql); - $row = $query->row(); - $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $row->seq); - } - elseif ($table != null) - { - // seq_name passed in table parameter - $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $table); - } - else - { - return pg_last_oid($this->result_id); - } - $query = $this->query($sql); - $row = $query->row(); - return $row->ins_id; - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - return '0'; - - $query = $this->query('SELECT COUNT(*) AS numrows FROM "'.$this->dbprefix.$table.'"'); - - if ($query->num_rows() == 0) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access public - * @return string - */ - function error_message() - { - return pg_last_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access public - * @return integer - */ - function error_number() - { - return ''; - } - - // -------------------------------------------------------------------- - - /** - * Escape Table Name - * - * This function adds backticks if the table name has a period - * in it. Some DBs will get cranky unless periods are escaped. - * - * @access public - * @param string the table name - * @return string - */ - function escape_table($table) - { - if (stristr($table, '.')) - { - $table = '"'.preg_replace("/\./", '"."', $table).'"'; - } - - return $table; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - $sql = "SELECT * FROM ".$this->escape_table($table)." LIMIT 1"; - $query = $this->query($sql); - return $query->field_data(); - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$this->escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @return string - */ - function _update($table, $values, $where) - { - foreach($values as $key => $val) - { - $valstr[] = $key." = ".$val; - } - - return "UPDATE ".$this->escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @return string - */ - function _delete($table, $where) - { - return "DELETE FROM ".$this->escape_table($table)." WHERE ".implode(" ", $where); - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _show_columns($table = '') - { - return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->escape_table($table)."'"; - } - - // -------------------------------------------------------------------- - - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - $sql .= "LIMIT ".$limit; - - if ($offset > 0) - { - $sql .= " OFFSET ".$offset; - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - pg_close($conn_id); - } - -} - -?> \ No newline at end of file -- 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') 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 ---------------------- .../database/drivers/postgre/postgre_utility.php | 58 +++++++++++++++++++-- 2 files changed, 54 insertions(+), 64 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 03817188f..9c8a18eb5 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -419,66 +419,6 @@ class CI_DB_postgre_driver extends CI_DB { pg_close($conn_id); } - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access public - * @return string - */ - function _show_tables() - { - return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; - } - - // -------------------------------------------------------------------- - - /** - * Show columnn query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _show_columns($table = '') - { - return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->_escape_table($table)."'"; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - $sql = "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; - $query = $this->query($sql); - return $query->field_data(); - } - } diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 760be81a0..cfc475f6b 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -22,20 +22,70 @@ * @author Rick Ellis * @link http://www.codeigniter.com/user_guide/database/ */ -class CI_DB_postgre_utility { +class CI_DB_postgre_utility extends CI_DB_utility { + /** - * Some function + * Version number query string * * @access public - * @return integer + * @return string */ - function something() + function _version() { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access public + * @return string + */ + function _show_tables() + { + return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; } // -------------------------------------------------------------------- + /** + * Show columnn query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _show_columns($table = '') + { + return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->db->_escape_table($table)."'"; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + $sql = "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; + $query = $this->db->query($sql); + return $query->field_data(); + } + + } ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 6ca6f9471ba31f7cba9054d075b4f90382b2d410 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 25 Sep 2006 02:51:08 +0000 Subject: --- .../database/drivers/postgre/postgre_utility.php | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index cfc475f6b..c38cf6e69 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -25,6 +25,34 @@ class CI_DB_postgre_utility extends CI_DB_utility { + /** + * Create database + * + * @access public + * @param string the database name + * @return bool + */ + function create_database($name) + { + return $this->db->query("CREATE DATABASE ".$this->db->_escape_table($name)); + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access public + * @param string the database name + * @return bool + */ + function drop_database($name) + { + return $this->db->query("DROP DATABASE ".$this->db->_escape_table($name)); + } + + // -------------------------------------------------------------------- + /** * Version number query string * -- cgit v1.2.3-24-g4f1b From 72496373008b263e098cf6082cdce1d47d01d3f1 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 25 Sep 2006 03:44:04 +0000 Subject: --- .../database/drivers/postgre/postgre_utility.php | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index c38cf6e69..103f8d553 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -53,6 +53,29 @@ class CI_DB_postgre_utility extends CI_DB_utility { // -------------------------------------------------------------------- + /** + * List databases + * + * @access public + * @return bool + */ + function list_databases() + { + $query = $this->db->query("SELECT datname FROM pg_database"); + $dbs = array(); + if ($query->num_rows() > 0) + { + foreach ($query->result_array() as $row) + { + $dbs[] = current($row); + } + } + + return $dbs; + } + + // -------------------------------------------------------------------- + /** * Version number query string * -- cgit v1.2.3-24-g4f1b From 4ceac2d4efa5a16486b6e97911bb32e261b9d648 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 25 Sep 2006 06:40:16 +0000 Subject: --- system/database/drivers/postgre/postgre_utility.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 103f8d553..7bb210ab7 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -34,7 +34,7 @@ class CI_DB_postgre_utility extends CI_DB_utility { */ function create_database($name) { - return $this->db->query("CREATE DATABASE ".$this->db->_escape_table($name)); + return $this->db->query("CREATE DATABASE ".$name); } // -------------------------------------------------------------------- @@ -48,7 +48,7 @@ class CI_DB_postgre_utility extends CI_DB_utility { */ function drop_database($name) { - return $this->db->query("DROP DATABASE ".$this->db->_escape_table($name)); + return $this->db->query("DROP DATABASE ".$name); } // -------------------------------------------------------------------- @@ -73,6 +73,19 @@ class CI_DB_postgre_utility extends CI_DB_utility { return $dbs; } + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * @access public + * @return bool + */ + function drop_table($table) + { + "DROP TABLE ".$this->db->_escape_table($name)." CASCADE"; + } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 6cec6a58d993fb0b1beb5fac7ea0d1cb9769c0a4 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 25 Sep 2006 06:56:49 +0000 Subject: --- system/database/drivers/postgre/postgre_utility.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 7bb210ab7..8e51623be 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -28,13 +28,13 @@ class CI_DB_postgre_utility extends CI_DB_utility { /** * Create database * - * @access public + * @access private * @param string the database name * @return bool */ - function create_database($name) + function _create_database($name) { - return $this->db->query("CREATE DATABASE ".$name); + return "CREATE DATABASE ".$name; } // -------------------------------------------------------------------- @@ -84,7 +84,7 @@ class CI_DB_postgre_utility extends CI_DB_utility { */ function drop_table($table) { - "DROP TABLE ".$this->db->_escape_table($name)." CASCADE"; + return $this->db->query("DROP TABLE ".$this->db->_escape_table($name)." CASCADE"); } // -------------------------------------------------------------------- @@ -144,9 +144,7 @@ class CI_DB_postgre_utility extends CI_DB_utility { */ function _field_data($table) { - $sql = "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; - $query = $this->db->query($sql); - return $query->field_data(); + return "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; } -- cgit v1.2.3-24-g4f1b From 83b05a860a5f208d15942b517385848cfe4887bb Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 25 Sep 2006 21:06:46 +0000 Subject: --- .../database/drivers/postgre/postgre_utility.php | 28 +++++++--------------- 1 file changed, 9 insertions(+), 19 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 8e51623be..b31609aea 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -42,13 +42,13 @@ class CI_DB_postgre_utility extends CI_DB_utility { /** * Drop database * - * @access public + * @access private * @param string the database name * @return bool */ - function drop_database($name) + function _drop_database($name) { - return $this->db->query("DROP DATABASE ".$name); + return "DROP DATABASE ".$name; } // -------------------------------------------------------------------- @@ -56,22 +56,12 @@ class CI_DB_postgre_utility extends CI_DB_utility { /** * List databases * - * @access public + * @access private * @return bool */ - function list_databases() + function _list_databases() { - $query = $this->db->query("SELECT datname FROM pg_database"); - $dbs = array(); - if ($query->num_rows() > 0) - { - foreach ($query->result_array() as $row) - { - $dbs[] = current($row); - } - } - - return $dbs; + return "SELECT datname FROM pg_database"; } // -------------------------------------------------------------------- @@ -79,12 +69,12 @@ class CI_DB_postgre_utility extends CI_DB_utility { /** * Drop Table * - * @access public + * @access private * @return bool */ - function drop_table($table) + function _drop_table($table) { - return $this->db->query("DROP TABLE ".$this->db->_escape_table($name)." CASCADE"); + return "DROP TABLE ".$this->db->_escape_table($name)." CASCADE"; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From ab4f61bacfa022c0c7238e9661ad9cb2ac440d95 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 25 Sep 2006 22:12:32 +0000 Subject: --- system/database/drivers/postgre/postgre_result.php | 23 +++++++++++++++- .../database/drivers/postgre/postgre_utility.php | 32 ++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index 6af7f94f2..ee838b450 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -49,7 +49,28 @@ class CI_DB_postgre_result extends CI_DB_result { { return @pg_num_fields($this->result_id); } - + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function field_names() + { + $field_names = array(); + for ($i = 0; $i < $this->num_fields(); $i++) + { + $Ffield_names[] = pg_field_name($this->result_id, $i); + } + + return $field_names; + } + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index b31609aea..b2fdd5fd4 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -137,6 +137,38 @@ class CI_DB_postgre_utility extends CI_DB_utility { return "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; } + // -------------------------------------------------------------------- + + /** + * Optimize table query + * + * Generates a platform-specific query so that a table can be optimized + * + * @access private + * @param string the table name + * @return object + */ + function _optimize_table($table) + { + return FALSE; // Is this supported in Postgre? + } + + // -------------------------------------------------------------------- + + /** + * Repair table query + * + * Generates a platform-specific query so that a table can be repaired + * + * @access private + * @param string the table name + * @return object + */ + function _repair_table($table) + { + return return FALSE; // Is this supported in Postgre? + } + } -- 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 ++++++++++++++++- .../database/drivers/postgre/postgre_utility.php | 59 +++------------------- 2 files changed, 53 insertions(+), 53 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 9c8a18eb5..026284118 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -71,7 +71,20 @@ class CI_DB_postgre_driver extends CI_DB { // Not needed for Postgre so we'll return TRUE return TRUE; } - + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + // -------------------------------------------------------------------- /** @@ -276,6 +289,38 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Show columnn query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _list_columns($table = '') + { + return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->_escape_table($table)."'"; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + return "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; + } + + // -------------------------------------------------------------------- + /** * The error message string * diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index b2fdd5fd4..0ee448f9e 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -63,32 +63,6 @@ class CI_DB_postgre_utility extends CI_DB_utility { { return "SELECT datname FROM pg_database"; } - - // -------------------------------------------------------------------- - - /** - * Drop Table - * - * @access private - * @return bool - */ - function _drop_table($table) - { - return "DROP TABLE ".$this->db->_escape_table($name)." CASCADE"; - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } // -------------------------------------------------------------------- @@ -97,44 +71,25 @@ class CI_DB_postgre_utility extends CI_DB_utility { * * Generates a platform-specific query string so that the table names can be fetched * - * @access public + * @access private * @return string */ - function _show_tables() + function _list_tables() { return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; } - - // -------------------------------------------------------------------- - - /** - * Show columnn query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _show_columns($table = '') - { - return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->db->_escape_table($table)."'"; - } // -------------------------------------------------------------------- /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved + * Drop Table * - * @access public - * @param string the table name - * @return object + * @access private + * @return bool */ - function _field_data($table) + function _drop_table($table) { - return "SELECT * FROM ".$this->db->_escape_table($table)." LIMIT 1"; + return "DROP TABLE ".$this->db->_escape_table($name)." CASCADE"; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 4a2ed69c3af500ca51bddcc9b6c54bebb2bfeae8 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 29 Sep 2006 01:14:52 +0000 Subject: --- system/database/drivers/postgre/postgre_utility.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 0ee448f9e..7b51c3fe7 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -97,7 +97,7 @@ class CI_DB_postgre_utility extends CI_DB_utility { /** * Optimize table query * - * Generates a platform-specific query so that a table can be optimized + * Is table optimization supported in Postgre? * * @access private * @param string the table name @@ -105,7 +105,7 @@ class CI_DB_postgre_utility extends CI_DB_utility { */ function _optimize_table($table) { - return FALSE; // Is this supported in Postgre? + return FALSE; } // -------------------------------------------------------------------- @@ -113,7 +113,7 @@ class CI_DB_postgre_utility extends CI_DB_utility { /** * Repair table query * - * Generates a platform-specific query so that a table can be repaired + * Are table repairs supported in Postgre? * * @access private * @param string the table name @@ -121,7 +121,7 @@ class CI_DB_postgre_utility extends CI_DB_utility { */ function _repair_table($table) { - return return FALSE; // Is this supported in Postgre? + return return FALSE; } -- 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 ++++++++++++++++++++++ .../database/drivers/postgre/postgre_utility.php | 28 ---------------------- 2 files changed, 28 insertions(+), 28 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 026284118..f14395638 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -286,6 +286,34 @@ class CI_DB_postgre_driver extends CI_DB { $row = $query->row(); return $row->numrows; } + + // -------------------------------------------------------------------- + + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + return "SELECT datname FROM pg_database"; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @return string + */ + function _list_tables() + { + return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 7b51c3fe7..46c98cc7d 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -53,34 +53,6 @@ class CI_DB_postgre_utility extends CI_DB_utility { // -------------------------------------------------------------------- - /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - return "SELECT datname FROM pg_database"; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @return string - */ - function _list_tables() - { - return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; - } - - // -------------------------------------------------------------------- - /** * Drop Table * -- 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 ------------- system/database/drivers/postgre/postgre_utility.php | 13 +++++++++++++ 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index f14395638..340d65046 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -289,19 +289,6 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * List databases - * - * @access private - * @return bool - */ - function _list_databases() - { - return "SELECT datname FROM pg_database"; - } - - // -------------------------------------------------------------------- - /** * Show table query * diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 46c98cc7d..038aa26cd 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -53,6 +53,19 @@ class CI_DB_postgre_utility extends CI_DB_utility { // -------------------------------------------------------------------- + /** + * List databases + * + * @access private + * @return bool + */ + function _list_databases() + { + return "SELECT datname FROM pg_database"; + } + + // -------------------------------------------------------------------- + /** * Drop Table * -- cgit v1.2.3-24-g4f1b From 3cad41e56fe4edc057cf6a84952a343686376429 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 2 Oct 2006 03:21:46 +0000 Subject: --- system/database/drivers/postgre/postgre_utility.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 038aa26cd..0c265de16 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -109,6 +109,20 @@ class CI_DB_postgre_utility extends CI_DB_utility { return return FALSE; } + // -------------------------------------------------------------------- + + /** + * Postgre Export + * + * @access private + * @param array Preferences + * @return mixed + */ + function _backup($params = array()) + { + // Currently unsupported + return $this->db->display_error('db_unsuported_feature'); + } } -- cgit v1.2.3-24-g4f1b From d2dd03143d9e47a36a2f8561160e278a358fa031 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 5 Oct 2006 04:34:38 +0000 Subject: --- system/database/drivers/postgre/postgre_result.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index ee838b450..8c25c5d4c 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -117,6 +117,23 @@ class CI_DB_postgre_result extends CI_DB_result { // -------------------------------------------------------------------- + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero + * + * @access private + * @return array + */ + function _data_seek($n = 0) + { + pg_result_seek($this->result_id, $n); + } + + // -------------------------------------------------------------------- + /** * Result - associative array * -- cgit v1.2.3-24-g4f1b From 7099a589d1719311427d7552523ec962ebc3b650 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 10 Oct 2006 17:47:59 +0000 Subject: --- system/database/drivers/postgre/postgre_utility.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 0c265de16..b08b879d7 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -106,7 +106,7 @@ class CI_DB_postgre_utility extends CI_DB_utility { */ function _repair_table($table) { - return return FALSE; + return FALSE; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 606f99c043272f96f21911d89c21cd36c2ef59e4 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 11 Oct 2006 23:48:41 +0000 Subject: --- system/database/drivers/postgre/postgre_result.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index 8c25c5d4c..e792544ae 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -60,7 +60,7 @@ class CI_DB_postgre_result extends CI_DB_result { * @access public * @return array */ - function field_names() + function list_fields() { $field_names = array(); for ($i = 0; $i < $this->num_fields(); $i++) @@ -71,6 +71,12 @@ class CI_DB_postgre_result extends CI_DB_result { return $field_names; } + // Deprecated + function field_names() + { + return $this->list_fields(); + } + // -------------------------------------------------------------------- /** -- 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') 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 +++++++++++----------- system/database/drivers/postgre/postgre_result.php | 8 +++---- .../database/drivers/postgre/postgre_utility.php | 6 ++--- 3 files changed, 21 insertions(+), 21 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index f74e652d5..81aaafe14 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -111,18 +111,18 @@ class CI_DB_postgre_driver extends CI_DB { * @param string an SQL query * @return string */ - function _prep_query($sql) - { + function _prep_query($sql) + { return $sql; - } + } // -------------------------------------------------------------------- /** * Begin Transaction - * + * * @access public - * @return bool + * @return bool */ function trans_begin($test_mode = FALSE) { @@ -138,8 +138,8 @@ class CI_DB_postgre_driver extends CI_DB { } // Reset the transaction failure flag. - // If the $test_mode flag is set to TRUE transactions will be rolled back - // even if the queries produce a successful result. + // If the $test_mode flag is set to TRUE transactions will be rolled back + // even if the queries produce a successful result. $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; return @pg_exec($this->conn_id, "begin"); @@ -149,9 +149,9 @@ class CI_DB_postgre_driver extends CI_DB { /** * Commit Transaction - * + * * @access public - * @return bool + * @return bool */ function trans_commit() { @@ -173,9 +173,9 @@ class CI_DB_postgre_driver extends CI_DB { /** * Rollback Transaction - * + * * @access public - * @return bool + * @return bool */ function trans_rollback() { @@ -298,7 +298,7 @@ class CI_DB_postgre_driver extends CI_DB { * @return string */ function _list_tables() - { + { return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; } diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index e792544ae..76bd60187 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -116,8 +116,8 @@ class CI_DB_postgre_result extends CI_DB_result { { if (is_resource($this->result_id)) { - pg_free_result($this->result_id); - $this->result_id = FALSE; + pg_free_result($this->result_id); + $this->result_id = FALSE; } } diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index b08b879d7..478e74276 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -90,7 +90,7 @@ class CI_DB_postgre_utility extends CI_DB_utility { */ function _optimize_table($table) { - return FALSE; + return FALSE; } // -------------------------------------------------------------------- -- 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') 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 1716cb80344dcb09dd263293b7901cd5b669e302 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 25 Oct 2006 05:12:34 +0000 Subject: --- system/database/drivers/postgre/postgre_result.php | 2 +- system/database/drivers/postgre/postgre_utility.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index 76bd60187..f065e54fb 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -135,7 +135,7 @@ class CI_DB_postgre_result extends CI_DB_result { */ function _data_seek($n = 0) { - pg_result_seek($this->result_id, $n); + return pg_result_seek($this->result_id, $n); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 478e74276..bebe09415 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -74,7 +74,7 @@ class CI_DB_postgre_utility extends CI_DB_utility { */ function _drop_table($table) { - return "DROP TABLE ".$this->db->_escape_table($name)." CASCADE"; + return "DROP TABLE ".$this->db->_escape_table($table)." CASCADE"; } // -------------------------------------------------------------------- -- 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') 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 1a726a6a21d2ef2b6402d9027aab29544655760d Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 1 Nov 2006 05:27:15 +0000 Subject: --- system/database/drivers/postgre/index.html | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 system/database/drivers/postgre/index.html (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/index.html b/system/database/drivers/postgre/index.html new file mode 100644 index 000000000..5a1f5d6ae --- /dev/null +++ b/system/database/drivers/postgre/index.html @@ -0,0 +1,15 @@ + + + + +403 Forbidden + + + + + +

Directory access is forbidden.

+ + + + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 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') 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 +- system/database/drivers/postgre/postgre_result.php | 344 ++++++++++----------- .../database/drivers/postgre/postgre_utility.php | 256 +++++++-------- 3 files changed, 302 insertions(+), 302 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 58cc69a96..bfb212cfd 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -1,12 +1,12 @@ result_id); - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - return @pg_num_fields($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Fetch Field Names - * - * Generates an array of column names - * - * @access public - * @return array - */ - function list_fields() - { - $field_names = array(); - for ($i = 0; $i < $this->num_fields(); $i++) - { - $Ffield_names[] = pg_field_name($this->result_id, $i); - } - - return $field_names; - } - - // Deprecated - function field_names() - { - return $this->list_fields(); - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - function field_data() - { - $retval = array(); - for ($i = 0; $i < $this->num_fields(); $i++) - { - $F = new stdClass(); - $F->name = pg_field_name($this->result_id, $i); - $F->type = pg_field_type($this->result_id, $i); - $F->max_length = pg_field_size($this->result_id, $i); - $F->primary_key = $i == 0; - $F->default = ''; - - $retval[] = $F; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Free the result - * - * @return null - */ - function free_result() - { - if (is_resource($this->result_id)) - { - pg_free_result($this->result_id); - $this->result_id = FALSE; - } - } - - // -------------------------------------------------------------------- - - /** - * Data Seek - * - * Moves the internal pointer to the desired offset. We call - * this internally before fetching results to make sure the - * result set starts at zero - * - * @access private - * @return array - */ - function _data_seek($n = 0) - { - return pg_result_seek($this->result_id, $n); - } - - // -------------------------------------------------------------------- - - /** - * Result - associative array - * - * Returns the result set as an array - * - * @access private - * @return array - */ - function _fetch_assoc() - { - return pg_fetch_assoc($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Result - object - * - * Returns the result set as an object - * - * @access private - * @return object - */ - function _fetch_object() - { - return pg_fetch_object($this->result_id); - } - -} - +result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @pg_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function list_fields() + { + $field_names = array(); + for ($i = 0; $i < $this->num_fields(); $i++) + { + $Ffield_names[] = pg_field_name($this->result_id, $i); + } + + return $field_names; + } + + // Deprecated + function field_names() + { + return $this->list_fields(); + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + for ($i = 0; $i < $this->num_fields(); $i++) + { + $F = new stdClass(); + $F->name = pg_field_name($this->result_id, $i); + $F->type = pg_field_type($this->result_id, $i); + $F->max_length = pg_field_size($this->result_id, $i); + $F->primary_key = $i == 0; + $F->default = ''; + + $retval[] = $F; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return null + */ + function free_result() + { + if (is_resource($this->result_id)) + { + pg_free_result($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero + * + * @access private + * @return array + */ + function _data_seek($n = 0) + { + return pg_result_seek($this->result_id, $n); + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @access private + * @return array + */ + function _fetch_assoc() + { + return pg_fetch_assoc($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + function _fetch_object() + { + return pg_fetch_object($this->result_id); + } + +} + ?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index bebe09415..9d56af363 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -1,129 +1,129 @@ -db->_escape_table($table)." CASCADE"; - } - - // -------------------------------------------------------------------- - - /** - * Optimize table query - * - * Is table optimization supported in Postgre? - * - * @access private - * @param string the table name - * @return object - */ - function _optimize_table($table) - { - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Repair table query - * - * Are table repairs supported in Postgre? - * - * @access private - * @param string the table name - * @return object - */ - function _repair_table($table) - { - return FALSE; - } - - // -------------------------------------------------------------------- - - /** - * Postgre Export - * - * @access private - * @param array Preferences - * @return mixed - */ - function _backup($params = array()) - { - // Currently unsupported - return $this->db->display_error('db_unsuported_feature'); - } - -} - +db->_escape_table($table)." CASCADE"; + } + + // -------------------------------------------------------------------- + + /** + * Optimize table query + * + * Is table optimization supported in Postgre? + * + * @access private + * @param string the table name + * @return object + */ + function _optimize_table($table) + { + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Repair table query + * + * Are table repairs supported in Postgre? + * + * @access private + * @param string the table name + * @return object + */ + function _repair_table($table) + { + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Postgre Export + * + * @access private + * @param array Preferences + * @return mixed + */ + function _backup($params = array()) + { + // Currently unsupported + return $this->db->display_error('db_unsuported_feature'); + } + +} + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From f9a4e9e04589df8dcf808519c95703f16c318384 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 12 Jul 2007 13:56:21 +0000 Subject: fixed undefined function in insert_id() of PostgreSQL driver --- system/database/drivers/postgre/postgre_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database/drivers/postgre') 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 +- system/database/drivers/postgre/postgre_result.php | 2 +- system/database/drivers/postgre/postgre_utility.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 798905126..a8a6ca169 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index 5b955ad12..9938d4069 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 9d56af363..fa5960e58 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource -- 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') 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') 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') 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') 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 aa7f769c1e6f46171f2fbc15f43428207c02abcb Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 20 Dec 2007 14:38:56 +0000 Subject: fixed typo: $field_names[] vs $Ffield_names[] --- system/database/drivers/postgre/postgre_result.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index 9938d4069..9fd2a7e93 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -65,7 +65,7 @@ class CI_DB_postgre_result extends CI_DB_result { $field_names = array(); for ($i = 0; $i < $this->num_fields(); $i++) { - $Ffield_names[] = pg_field_name($this->result_id, $i); + $field_names[] = pg_field_name($this->result_id, $i); } return $field_names; -- 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 +++++++++++- system/database/drivers/postgre/postgre_forge.php | 219 +++++++++++++++++++++ .../database/drivers/postgre/postgre_utility.php | 77 ++++---- 3 files changed, 375 insertions(+), 50 deletions(-) create mode 100644 system/database/drivers/postgre/postgre_forge.php (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 88f08b2d7..63a72f5d3 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -35,7 +35,7 @@ class CI_DB_postgre_driver extends CI_DB { * database engines, so this string appears in each driver and is * used for the count_all() and count_all_results() functions. */ - var $_count_string = "SELECT COUNT(*) AS numrows "; + var $_count_string = "SELECT COUNT(*) AS "; var $_random_keyword = ' RANDOM()'; // database specific random keyword /** @@ -82,6 +82,22 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Set client character set + * + * @access public + * @param string + * @param string + * @return resource + */ + function db_set_charset($charset, $collation) + { + // TODO - add support if needed + return TRUE; + } + + // -------------------------------------------------------------------- + /** * Version number query string * @@ -305,11 +321,19 @@ class CI_DB_postgre_driver extends CI_DB { * Generates a platform-specific query string so that the table names can be fetched * * @access private + * @param boolean * @return string */ - function _list_tables() + function _list_tables($prefix_limit = FALSE) { - return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; + $sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; + + if ($prefix_limit !== FALSE AND $this->dbprefix != '') + { + $sql .= " AND table_name LIKE '".$this->dbprefix."%'"; + } + + return $sql; } // -------------------------------------------------------------------- @@ -394,6 +418,58 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Protect Identifiers + * + * This function adds backticks if appropriate based on db type + * + * @access private + * @param mixed the item to escape + * @param boolean only affect the first word + * @return mixed the item with backticks + */ + function _protect_identifiers($item, $first_word_only = FALSE) + { + if (is_array($item)) + { + $escaped_array = array(); + + foreach($item as $k=>$v) + { + $escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v, $first_word_only); + } + + return $escaped_array; + } + + // This function may get "item1 item2" as a string, and so + // we may need ""item1" "item2"" and not ""item1 item2"" + if (strpos($item, ' ') !== FALSE) + { + // This function may get "field >= 1", and need it to return ""field" >= 1" + if ($first_word_only === TRUE) + { + return '"'.preg_replace('/ /', '" ', $item, 1); + } + + $item = preg_replace('/(^|\s|\()([\w\d\-\_]+?)(\s|\)|$)/iS', '$1"$2"$3', $item); + } + + $exceptions = array('AS', '/', '-', '%', '+', '*'); + + foreach ($exceptions as $exception) + { + if (stristr($item, " "{$exception}" ") !== FALSE) + { + $item = preg_replace('/ "('.preg_quote($exception).')" /i', ' $1 ', $item); + } + } + + return $item; + } + + // -------------------------------------------------------------------- + /** * Insert statement * @@ -421,9 +497,11 @@ class CI_DB_postgre_driver extends CI_DB { * @param string the table name * @param array the update data * @param array the where clause + * @param array the orderby clause + * @param array the limit clause * @return string */ - function _update($table, $values, $where, $limit = FALSE) + function _update($table, $values, $where, $orderby = array(), $limit = FALSE) { foreach($values as $key => $val) { @@ -431,8 +509,29 @@ class CI_DB_postgre_driver extends CI_DB { } $limit = (!$limit) ? '' : ' LIMIT '.$limit; + + $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$limit; + return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where).$orderby.$limit; + } + + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * If the database does not support the truncate() command + * This function maps to "DELETE FROM table" + * + * @access public + * @param string the table name + * @return string + */ + function _truncate($table) + { + return "TRUNCATE ".$this->_escape_table($table); } // -------------------------------------------------------------------- @@ -445,17 +544,31 @@ class CI_DB_postgre_driver extends CI_DB { * @access public * @param string the table name * @param array the where clause + * @param string the limit clause * @return string */ - function _delete($table, $where, $limit = FALSE) + function _delete($table, $where = array(), $like = array(), $limit = FALSE) { + $conditions = ''; + + if (count($where) > 0 || count($like) > 0) + { + $conditions = "\nWHERE "; + $conditions .= implode("\n", $this->ar_where); + + if (count($where) > 0 && count($like) > 0) + { + $conditions .= " AND "; + } + $conditions .= implode("\n", $like); + } + $limit = (!$limit) ? '' : ' LIMIT '.$limit; - return "DELETE FROM ".$this->_escape_table($table)." WHERE ".implode(" ", $where).$limit; + return "DELETE FROM ".$table.$conditions.$limit; } // -------------------------------------------------------------------- - /** * Limit string * diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php new file mode 100644 index 000000000..34bbe88b6 --- /dev/null +++ b/system/database/drivers/postgre/postgre_forge.php @@ -0,0 +1,219 @@ +db->_escape_table($table)." ("; + $current_field_count = 0; + + foreach ($fields as $field=>$attributes) + { + // Numeric field names aren't allowed in databases, so if the key is + // numeric, we know it was assigned by PHP and the developer manually + // entered the field information, so we'll simply add it to the list + if (is_numeric($field)) + { + $sql .= "\n\t$attributes"; + } + else + { + $attributes = array_change_key_case($attributes, CASE_UPPER); + + $sql .= "\n\t".$this->db->_protect_identifiers($field); + + $sql .= ' '.$attributes['TYPE']; + + if (array_key_exists('CONSTRAINT', $attributes)) + { + $sql .= '('.$attributes['CONSTRAINT'].')'; + } + + if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) + { + $sql .= ' UNSIGNED'; + } + + if (array_key_exists('DEFAULT', $attributes)) + { + $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; + } + + if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) + { + $sql .= ' NULL'; + } + else + { + $sql .= ' NOT NULL'; + } + + if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) + { + $sql .= ' AUTO_INCREMENT'; + } + } + + // don't add a comma on the end of the last field + if (++$current_field_count < count($fields)) + { + $sql .= ','; + } + } + + if (count($primary_keys) > 0) + { + $primary_keys = $this->db->_protect_identifiers($primary_keys); + $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; + } + + if (is_array($keys) && count($keys) > 0) + { + $keys = $this->db->_protect_identifiers($keys); + foreach ($keys as $key) + { + $sql .= ",\n\tFOREIGN KEY ($key)"; + } + } + + $sql .= "\n);"; + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * @access private + * @return bool + */ + function _drop_table($table) + { + return "DROP TABLE ".$this->db->_escape_table($table)." CASCADE"; + } + + // -------------------------------------------------------------------- + + /** + * Alter table query + * + * Generates a platform-specific query so that a table can be altered + * Called by add_column(), drop_column(), and column_alter(), + * + * @access private + * @param string the ALTER type (ADD, DROP, CHANGE) + * @param string the column name + * @param string the table name + * @param string the column definition + * @param string the default value + * @param boolean should 'NOT NULL' be added + * @param string the field after which we should add the new field + * @return object + */ + function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') + { + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name); + + // DROP has everything it needs now. + if ($alter_type == 'DROP') + { + return $sql; + } + + $sql .= " $column_definition"; + + if ($default_value != '') + { + $sql .= " DEFAULT \"$default_value\""; + } + + if ($null === NULL) + { + $sql .= ' NULL'; + } + else + { + $sql .= ' NOT NULL'; + } + + if ($after_field != '') + { + $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); + } + + return $sql; + + } + +} +?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index fa5960e58..a706d9505 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -24,35 +24,6 @@ */ class CI_DB_postgre_utility extends CI_DB_utility { - - /** - * Create database - * - * @access private - * @param string the database name - * @return bool - */ - function _create_database($name) - { - return "CREATE DATABASE ".$name; - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access private - * @param string the database name - * @return bool - */ - function _drop_database($name) - { - return "DROP DATABASE ".$name; - } - - // -------------------------------------------------------------------- - /** * List databases * @@ -66,19 +37,6 @@ class CI_DB_postgre_utility extends CI_DB_utility { // -------------------------------------------------------------------- - /** - * Drop Table - * - * @access private - * @return bool - */ - function _drop_table($table) - { - return "DROP TABLE ".$this->db->_escape_table($table)." CASCADE"; - } - - // -------------------------------------------------------------------- - /** * Optimize table query * @@ -124,6 +82,41 @@ class CI_DB_postgre_utility extends CI_DB_utility { return $this->db->display_error('db_unsuported_feature'); } + /** + * + * The functions below have been deprecated as of 1.6, and are only here for backwards + * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation + * is STRONGLY discouraged in favour if using dbforge. + * + */ + + /** + * Create database + * + * @access private + * @param string the database name + * @return bool + */ + function _create_database($name) + { + return "CREATE DATABASE ".$name; + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access private + * @param string the database name + * @return bool + */ + function _drop_database($name) + { + return "DROP DATABASE ".$name; + } + + } ?> \ No newline at end of file -- 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') 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') 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 ++-- system/database/drivers/postgre/postgre_forge.php | 4 ++-- system/database/drivers/postgre/postgre_result.php | 4 ++-- system/database/drivers/postgre/postgre_utility.php | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 8ea76033c..5bf87c597 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -25,7 +25,7 @@ * @package CodeIgniter * @subpackage Drivers * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_postgre_driver extends CI_DB { diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index 34bbe88b6..e3d6a8f70 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -19,7 +19,7 @@ * Postgre Forge Class * * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_postgre_forge extends CI_DB_forge { diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index 9fd2a7e93..d09e5730b 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -21,7 +21,7 @@ * This class extends the parent result class: CI_DB_result * * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_postgre_result extends CI_DB_result { diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index a706d9505..240e1b7df 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com @@ -19,7 +19,7 @@ * Postgre Utility Class * * @category Database - * @author Rick Ellis + * @author ExpressionEngine Dev Team * @link http://www.codeigniter.com/user_guide/database/ */ class CI_DB_postgre_utility extends CI_DB_utility { -- 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 +++--- system/database/drivers/postgre/postgre_forge.php | 6 +++--- system/database/drivers/postgre/postgre_result.php | 6 +++--- system/database/drivers/postgre/postgre_utility.php | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 5bf87c597..34d76de61 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -26,7 +26,7 @@ * @subpackage Drivers * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_postgre_driver extends CI_DB { diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index e3d6a8f70..81ac8e92b 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -20,7 +20,7 @@ * * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_postgre_forge extends CI_DB_forge { diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index d09e5730b..fdce01aac 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -22,7 +22,7 @@ * * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_postgre_result extends CI_DB_result { diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 240e1b7df..573654f68 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -7,8 +7,8 @@ * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeigniter.com/user_guide/license.html - * @link http://www.codeigniter.com + * @license http://codeigniter.com/user_guide/license.html + * @link http://codeigniter.com * @since Version 1.0 * @filesource */ @@ -20,7 +20,7 @@ * * @category Database * @author ExpressionEngine Dev Team - * @link http://www.codeigniter.com/user_guide/database/ + * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_postgre_utility extends CI_DB_utility { -- 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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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 2385d30422b865052bbc6f333e6a189f46215a61 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 7 Apr 2008 14:01:01 +0000 Subject: Added rename_table() into DBForge. --- system/database/drivers/postgre/postgre_forge.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index 81ac8e92b..72a61748d 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -215,5 +215,24 @@ class CI_DB_postgre_forge extends CI_DB_forge { } + // -------------------------------------------------------------------- + + /** + * Rename a table + * + * Generates a platform-specific query so that a table can be renamed + * + * @access private + * @param string the old table name + * @param string the new table name + * @return string + */ + function _rename_table($table_name, $new_table_name) + { + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); + return $sql; + } + + } ?> \ No newline at end of file -- 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') 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 - system/database/drivers/postgre/postgre_forge.php | 1 - system/database/drivers/postgre/postgre_result.php | 1 - system/database/drivers/postgre/postgre_utility.php | 1 - 4 files changed, 4 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 46ba1d009..7c46e7a4b 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -641,4 +641,3 @@ class CI_DB_postgre_driver extends CI_DB { } -?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index 72a61748d..ad4c5cdae 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -235,4 +235,3 @@ class CI_DB_postgre_forge extends CI_DB_forge { } -?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index fdce01aac..f3fb89951 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -170,4 +170,3 @@ class CI_DB_postgre_result extends CI_DB_result { } -?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 573654f68..25f44f06c 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -119,4 +119,3 @@ class CI_DB_postgre_utility extends CI_DB_utility { } -?> \ No newline at end of file -- 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 + system/database/drivers/postgre/postgre_forge.php | 1 + system/database/drivers/postgre/postgre_result.php | 1 + system/database/drivers/postgre/postgre_utility.php | 1 + 4 files changed, 4 insertions(+) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 7c46e7a4b..46ba1d009 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -641,3 +641,4 @@ class CI_DB_postgre_driver extends CI_DB { } +?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index ad4c5cdae..72a61748d 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -235,3 +235,4 @@ class CI_DB_postgre_forge extends CI_DB_forge { } +?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index f3fb89951..fdce01aac 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -170,3 +170,4 @@ class CI_DB_postgre_result extends CI_DB_result { } +?> \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 25f44f06c..573654f68 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -119,3 +119,4 @@ class CI_DB_postgre_utility extends CI_DB_utility { } +?> \ No newline at end of file -- 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 +++- system/database/drivers/postgre/postgre_forge.php | 4 +++- system/database/drivers/postgre/postgre_result.php | 4 +++- system/database/drivers/postgre/postgre_utility.php | 4 +++- 4 files changed, 12 insertions(+), 4 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 46ba1d009..4fd92f0c0 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -641,4 +641,6 @@ class CI_DB_postgre_driver extends CI_DB { } -?> \ No newline at end of file + +/* End of file postgre_driver.php */ +/* Location: ./system/database/drivers/postgre/postgre_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index 72a61748d..fb4fcf128 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -235,4 +235,6 @@ class CI_DB_postgre_forge extends CI_DB_forge { } -?> \ No newline at end of file + +/* End of file postgre_forge.php */ +/* Location: ./system/database/drivers/postgre/postgre_forge.php */ \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index fdce01aac..25360b3f3 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -170,4 +170,6 @@ class CI_DB_postgre_result extends CI_DB_result { } -?> \ No newline at end of file + +/* End of file postgre_result.php */ +/* Location: ./system/database/drivers/postgre/postgre_result.php */ \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 573654f68..17df599b6 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -119,4 +119,6 @@ class CI_DB_postgre_utility extends CI_DB_utility { } -?> \ No newline at end of file + +/* End of file postgre_utility.php */ +/* Location: ./system/database/drivers/postgre/postgre_utility.php */ \ No newline at end of file -- 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 ++++++++++---------- system/database/drivers/postgre/postgre_forge.php | 6 +++--- system/database/drivers/postgre/postgre_result.php | 6 +++--- system/database/drivers/postgre/postgre_utility.php | 6 +++--- 4 files changed, 19 insertions(+), 19 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 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 diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index fb4fcf128..f8dfca8a1 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -1,4 +1,4 @@ - Date: Thu, 29 May 2008 17:52:11 +0000 Subject: made MySQL/MySQLi forge use explicitly named KEYs, added ability to specify multi-column non-primary keys in table creation --- system/database/drivers/postgre/postgre_forge.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index f8dfca8a1..ef5783451 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -134,13 +134,21 @@ class CI_DB_postgre_forge extends CI_DB_forge { $primary_keys = $this->db->_protect_identifiers($primary_keys); $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; } - + if (is_array($keys) && count($keys) > 0) { - $keys = $this->db->_protect_identifiers($keys); foreach ($keys as $key) { - $sql .= ",\n\tFOREIGN KEY ($key)"; + if (is_array($key)) + { + $key = $this->db->_protect_identifiers($key); + } + else + { + $key = array($this->db->_protect_identifiers($key)); + } + + $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")"; } } -- cgit v1.2.3-24-g4f1b From fd7943aaac8f35956e30874291e211d2a3c48453 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 27 Jun 2008 07:44:45 +0000 Subject: Fixed a double opening <p> tag in the index pages of each system directory. --- system/database/drivers/postgre/index.html | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/index.html b/system/database/drivers/postgre/index.html index 5a1f5d6ae..065d2da5e 100644 --- a/system/database/drivers/postgre/index.html +++ b/system/database/drivers/postgre/index.html @@ -1,15 +1,10 @@ - - -403 Forbidden - + 403 Forbidden + - - -

Directory access is forbidden.

+

Directory access is forbidden.

- \ No newline at end of file -- 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 +- system/database/drivers/postgre/postgre_forge.php | 2 +- system/database/drivers/postgre/postgre_result.php | 2 +- system/database/drivers/postgre/postgre_utility.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 9a260a5ac..7574ded13 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index ef5783451..b9e1cd9bb 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index 1613da9b8..d018a9b2b 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 261050b2d..f9b0f22e0 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2006, EllisLab, Inc. + * @copyright Copyright (c) 2008, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b From 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') 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') 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') 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') 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 ++++----------------- system/database/drivers/postgre/postgre_forge.php | 4 +- system/database/drivers/postgre/postgre_result.php | 6 -- 3 files changed, 23 insertions(+), 93 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index c5c70a736..d94cce149 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -31,6 +31,8 @@ class CI_DB_postgre_driver extends CI_DB { var $dbdriver = 'postgre'; + + var $_escape_char = '"'; /** * The syntax to count rows is slightly different across different @@ -329,7 +331,7 @@ class CI_DB_postgre_driver extends CI_DB { if ($table == '') return '0'; - $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($this->dbprefix.$table)); + $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); if ($query->num_rows() == 0) return '0'; @@ -374,7 +376,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function _list_columns($table = '') { - return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$this->_escape_table($table)."'"; + return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$table."'"; } // -------------------------------------------------------------------- @@ -390,7 +392,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function _field_data($table) { - return "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1"; + return "SELECT * FROM ".$table." LIMIT 1"; } // -------------------------------------------------------------------- @@ -418,103 +420,36 @@ class CI_DB_postgre_driver extends CI_DB { { return ''; } - // -------------------------------------------------------------------- - - /** - * Escape Column Name - * - * This function adds backticks around supplied column name - * - * @access private - * @param string the column name - * @return string - */ - function _escape_column($column) - { - // Probably not necessary with Postgres so we simply return the value - return $column; - } // -------------------------------------------------------------------- /** - * Escape Table Name + * Escape the SQL Identifiers * - * This function adds backticks if the table name has a period - * in it. Some DBs will get cranky unless periods are escaped. + * This function escapes column and table names * * @access private - * @param string the table name + * @param string * @return string */ - function _escape_table($table) + function _escape_identifiers($item) { - if (strpos($table, '.') !== FALSE) + if ($this->_escape_char == '') { - $table = '"' . str_replace('.', '"."', $table) . '"'; + return $item; } - - return $table; - } - // -------------------------------------------------------------------- - - /** - * Protect Identifiers - * - * This function adds backticks if appropriate based on db type - * - * @access private - * @param mixed the item to escape - * @param boolean only affect the first word - * @return mixed the item with backticks - */ - function _protect_identifiers($item, $first_word_only = FALSE) - { - if (is_array($item)) + if (strpos($item, '.') !== FALSE) { - $escaped_array = array(); - - foreach($item as $k=>$v) - { - $escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v, $first_word_only); - } - - return $escaped_array; - } - - // This function may get "item1 item2" as a string, and so - // we may need ""item1" "item2"" and not ""item1 item2"" - if (ctype_alnum($item) === FALSE) - { - if (strpos($item, '.') !== FALSE) - { - $aliased_tables = implode(".",$this->ar_aliased_tables).'.'; - $table_name = substr($item, 0, strpos($item, '.')+1); - $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item; - } - - // This function may get "field >= 1", and need it to return ""field" >= 1" - $lbound = ($first_word_only === TRUE) ? '' : '|\s|\('; - - $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1"$2"$3', $item); + $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; } else { - return "\"{$item}\""; + $str = $this->_escape_char.$item.$this->_escape_char; } - - $exceptions = array('AS', '/', '-', '%', '+', '*', 'OR', 'IS'); - foreach ($exceptions as $exception) - { - - if (stristr($item, " \"{$exception}\" ") !== FALSE) - { - $item = preg_replace('/ "('.preg_quote($exception).')" /i', ' $1 ', $item); - } - } - return $item; + // remove duplicates if the user already included the escape + return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); } // -------------------------------------------------------------------- @@ -554,7 +489,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function _insert($table, $keys, $values) { - return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -583,14 +518,15 @@ class CI_DB_postgre_driver extends CI_DB { $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - $sql = "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr); + $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); + $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; + $sql .= $orderby.$limit; return $sql; } - // -------------------------------------------------------------------- /** @@ -606,7 +542,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function _truncate($table) { - return "TRUNCATE ".$this->_escape_table($table); + return "TRUNCATE ".$table; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index b9e1cd9bb..5b4bcc295 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -72,7 +72,7 @@ class CI_DB_postgre_forge extends CI_DB_forge { $sql .= 'IF NOT EXISTS '; } - $sql .= $this->db->_escape_table($table)." ("; + $sql .= $this->db->_escape_identifiers($table)." ("; $current_field_count = 0; foreach ($fields as $field=>$attributes) @@ -167,7 +167,7 @@ class CI_DB_postgre_forge extends CI_DB_forge { */ function _drop_table($table) { - return "DROP TABLE ".$this->db->_escape_table($table)." CASCADE"; + return "DROP TABLE ".$this->db->_escape_identifiers($table)." CASCADE"; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index d018a9b2b..2e1e00330 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -71,12 +71,6 @@ class CI_DB_postgre_result extends CI_DB_result { return $field_names; } - // Deprecated - function field_names() - { - return $this->list_fields(); - } - // -------------------------------------------------------------------- /** -- cgit v1.2.3-24-g4f1b From b5a9acabee5472637f962b776e3c01c1f3d7e205 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Sat, 18 Oct 2008 02:25:45 +0000 Subject: Set primary key to zero, since there isn't a good way to retrieve it. Bug report: 5172 --- system/database/drivers/postgre/postgre_result.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index 2e1e00330..78b9a6040 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -90,7 +90,7 @@ class CI_DB_postgre_result extends CI_DB_result { $F->name = pg_field_name($this->result_id, $i); $F->type = pg_field_type($this->result_id, $i); $F->max_length = pg_field_size($this->result_id, $i); - $F->primary_key = $i == 0; + $F->primary_key = 0; $F->default = ''; $retval[] = $F; -- cgit v1.2.3-24-g4f1b From 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') 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/index.html | 18 +- system/database/drivers/postgre/postgre_driver.php | 1270 ++++++++++---------- system/database/drivers/postgre/postgre_forge.php | 494 ++++---- system/database/drivers/postgre/postgre_result.php | 336 +++--- .../database/drivers/postgre/postgre_utility.php | 246 ++-- 5 files changed, 1182 insertions(+), 1182 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/index.html b/system/database/drivers/postgre/index.html index 065d2da5e..c942a79ce 100644 --- a/system/database/drivers/postgre/index.html +++ b/system/database/drivers/postgre/index.html @@ -1,10 +1,10 @@ - - - 403 Forbidden - - - -

Directory access is forbidden.

- - + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 68622a22b..da0b0f23a 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -1,636 +1,636 @@ - 'host', - 'port' => 'port', - 'database' => 'dbname', - 'username' => 'user', - 'password' => 'password' - ); - - $connect_string = ""; - foreach ($components as $key => $val) - { - if (isset($this->$key) && $this->$key != '') - { - $connect_string .= " $val=".$this->$key; - } - } - return trim($connect_string); - } - - // -------------------------------------------------------------------- - - /** - * Non-persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_connect() - { - return @pg_connect($this->_connect_string()); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @access private called by the base class - * @return resource - */ - function db_pconnect() - { - return @pg_pconnect($this->_connect_string()); - } - - // -------------------------------------------------------------------- - - /** - * Select the database - * - * @access private called by the base class - * @return resource - */ - function db_select() - { - // Not needed for Postgre so we'll return TRUE - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Set client character set - * - * @access public - * @param string - * @param string - * @return resource - */ - function db_set_charset($charset, $collation) - { - // @todo - add support if needed - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Version number query string - * - * @access public - * @return string - */ - function _version() - { - return "SELECT version() AS ver"; - } - - // -------------------------------------------------------------------- - - /** - * Execute the query - * - * @access private called by the base class - * @param string an SQL query - * @return resource - */ - function _execute($sql) - { - $sql = $this->_prep_query($sql); - return @pg_query($this->conn_id, $sql); - } - - // -------------------------------------------------------------------- - - /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @access private called by execute() - * @param string an SQL query - * @return string - */ - function _prep_query($sql) - { - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Begin Transaction - * - * @access public - * @return bool - */ - function trans_begin($test_mode = FALSE) - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - // Reset the transaction failure flag. - // If the $test_mode flag is set to TRUE transactions will be rolled back - // even if the queries produce a successful result. - $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; - - return @pg_exec($this->conn_id, "begin"); - } - - // -------------------------------------------------------------------- - - /** - * Commit Transaction - * - * @access public - * @return bool - */ - function trans_commit() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - return @pg_exec($this->conn_id, "commit"); - } - - // -------------------------------------------------------------------- - - /** - * Rollback Transaction - * - * @access public - * @return bool - */ - function trans_rollback() - { - if ( ! $this->trans_enabled) - { - return TRUE; - } - - // When transactions are nested we only begin/commit/rollback the outermost ones - if ($this->_trans_depth > 0) - { - return TRUE; - } - - return @pg_exec($this->conn_id, "rollback"); - } - - // -------------------------------------------------------------------- - - /** - * Escape String - * - * @access public - * @param string - * @return string - */ - function escape_str($str) - { - return pg_escape_string($str); - } - - // -------------------------------------------------------------------- - - /** - * Affected Rows - * - * @access public - * @return integer - */ - function affected_rows() - { - return @pg_affected_rows($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Insert ID - * - * @access public - * @return integer - */ - function insert_id() - { - $v = $this->_version(); - $v = $v['server']; - - $table = func_num_args() > 0 ? func_get_arg(0) : null; - $column = func_num_args() > 1 ? func_get_arg(1) : null; - - if ($table == null && $v >= '8.1') - { - $sql='SELECT LASTVAL() as ins_id'; - } - elseif ($table != null && $column != null && $v >= '8.0') - { - $sql = sprintf("SELECT pg_get_serial_sequence('%s','%s') as seq", $table, $column); - $query = $this->query($sql); - $row = $query->row(); - $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $row->seq); - } - elseif ($table != null) - { - // seq_name passed in table parameter - $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $table); - } - else - { - return pg_last_oid($this->result_id); - } - $query = $this->query($sql); - $row = $query->row(); - return $row->ins_id; - } - - // -------------------------------------------------------------------- - - /** - * "Count All" query - * - * Generates a platform-specific query string that counts all records in - * the specified database - * - * @access public - * @param string - * @return string - */ - function count_all($table = '') - { - if ($table == '') - return '0'; - - $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); - - if ($query->num_rows() == 0) - return '0'; - - $row = $query->row(); - return $row->numrows; - } - - // -------------------------------------------------------------------- - - /** - * Show table query - * - * Generates a platform-specific query string so that the table names can be fetched - * - * @access private - * @param boolean - * @return string - */ - function _list_tables($prefix_limit = FALSE) - { - $sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; - - if ($prefix_limit !== FALSE AND $this->dbprefix != '') - { - $sql .= " AND table_name LIKE '".$this->dbprefix."%'"; - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Show column query - * - * Generates a platform-specific query string so that the column names can be fetched - * - * @access public - * @param string the table name - * @return string - */ - function _list_columns($table = '') - { - return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$table."'"; - } - - // -------------------------------------------------------------------- - - /** - * Field data query - * - * Generates a platform-specific query so that the column data can be retrieved - * - * @access public - * @param string the table name - * @return object - */ - function _field_data($table) - { - return "SELECT * FROM ".$table." LIMIT 1"; - } - - // -------------------------------------------------------------------- - - /** - * The error message string - * - * @access private - * @return string - */ - function _error_message() - { - return pg_last_error($this->conn_id); - } - - // -------------------------------------------------------------------- - - /** - * The error message number - * - * @access private - * @return integer - */ - function _error_number() - { - return ''; - } - - // -------------------------------------------------------------------- - - /** - * Escape the SQL Identifiers - * - * This function escapes column and table names - * - * @access private - * @param string - * @return string - */ - function _escape_identifiers($item) - { - if ($this->_escape_char == '') - { - return $item; - } - - foreach ($this->_reserved_identifiers as $id) - { - if (strpos($item, '.'.$id) !== FALSE) - { - $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } - } - - if (strpos($item, '.') !== FALSE) - { - $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; - } - else - { - $str = $this->_escape_char.$item.$this->_escape_char; - } - - // remove duplicates if the user already included the escape - return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } - - // -------------------------------------------------------------------- - - /** - * From Tables - * - * This function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @access public - * @param type - * @return type - */ - function _from_tables($tables) - { - if ( ! is_array($tables)) - { - $tables = array($tables); - } - - return implode(', ', $tables); - } - - // -------------------------------------------------------------------- - - /** - * Insert statement - * - * Generates a platform-specific insert string from the supplied data - * - * @access public - * @param string the table name - * @param array the insert keys - * @param array the insert values - * @return string - */ - function _insert($table, $keys, $values) - { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; - } - - // -------------------------------------------------------------------- - - /** - * Update statement - * - * Generates a platform-specific update string from the supplied data - * - * @access public - * @param string the table name - * @param array the update data - * @param array the where clause - * @param array the orderby clause - * @param array the limit clause - * @return string - */ - function _update($table, $values, $where, $orderby = array(), $limit = FALSE) - { - foreach($values as $key => $val) - { - $valstr[] = $key." = ".$val; - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - - $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); - - $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; - - $sql .= $orderby.$limit; - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Truncate statement - * - * Generates a platform-specific truncate string from the supplied data - * If the database does not support the truncate() command - * This function maps to "DELETE FROM table" - * - * @access public - * @param string the table name - * @return string - */ - function _truncate($table) - { - return "TRUNCATE ".$table; - } - - // -------------------------------------------------------------------- - - /** - * Delete statement - * - * Generates a platform-specific delete string from the supplied data - * - * @access public - * @param string the table name - * @param array the where clause - * @param string the limit clause - * @return string - */ - function _delete($table, $where = array(), $like = array(), $limit = FALSE) - { - $conditions = ''; - - if (count($where) > 0 OR count($like) > 0) - { - $conditions = "\nWHERE "; - $conditions .= implode("\n", $this->ar_where); - - if (count($where) > 0 && count($like) > 0) - { - $conditions .= " AND "; - } - $conditions .= implode("\n", $like); - } - - $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - - return "DELETE FROM ".$table.$conditions.$limit; - } - - // -------------------------------------------------------------------- - /** - * Limit string - * - * Generates a platform-specific LIMIT clause - * - * @access public - * @param string the sql query string - * @param integer the number of rows to limit the query to - * @param integer the offset value - * @return string - */ - function _limit($sql, $limit, $offset) - { - $sql .= "LIMIT ".$limit; - - if ($offset > 0) - { - $sql .= " OFFSET ".$offset; - } - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Close DB Connection - * - * @access public - * @param resource - * @return void - */ - function _close($conn_id) - { - @pg_close($conn_id); - } - - -} - - -/* End of file postgre_driver.php */ + 'host', + 'port' => 'port', + 'database' => 'dbname', + 'username' => 'user', + 'password' => 'password' + ); + + $connect_string = ""; + foreach ($components as $key => $val) + { + if (isset($this->$key) && $this->$key != '') + { + $connect_string .= " $val=".$this->$key; + } + } + return trim($connect_string); + } + + // -------------------------------------------------------------------- + + /** + * Non-persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_connect() + { + return @pg_connect($this->_connect_string()); + } + + // -------------------------------------------------------------------- + + /** + * Persistent database connection + * + * @access private called by the base class + * @return resource + */ + function db_pconnect() + { + return @pg_pconnect($this->_connect_string()); + } + + // -------------------------------------------------------------------- + + /** + * Select the database + * + * @access private called by the base class + * @return resource + */ + function db_select() + { + // Not needed for Postgre so we'll return TRUE + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Set client character set + * + * @access public + * @param string + * @param string + * @return resource + */ + function db_set_charset($charset, $collation) + { + // @todo - add support if needed + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Version number query string + * + * @access public + * @return string + */ + function _version() + { + return "SELECT version() AS ver"; + } + + // -------------------------------------------------------------------- + + /** + * Execute the query + * + * @access private called by the base class + * @param string an SQL query + * @return resource + */ + function _execute($sql) + { + $sql = $this->_prep_query($sql); + return @pg_query($this->conn_id, $sql); + } + + // -------------------------------------------------------------------- + + /** + * Prep the query + * + * If needed, each database adapter can prep the query string + * + * @access private called by execute() + * @param string an SQL query + * @return string + */ + function _prep_query($sql) + { + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Begin Transaction + * + * @access public + * @return bool + */ + function trans_begin($test_mode = FALSE) + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + // Reset the transaction failure flag. + // If the $test_mode flag is set to TRUE transactions will be rolled back + // even if the queries produce a successful result. + $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; + + return @pg_exec($this->conn_id, "begin"); + } + + // -------------------------------------------------------------------- + + /** + * Commit Transaction + * + * @access public + * @return bool + */ + function trans_commit() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + return @pg_exec($this->conn_id, "commit"); + } + + // -------------------------------------------------------------------- + + /** + * Rollback Transaction + * + * @access public + * @return bool + */ + function trans_rollback() + { + if ( ! $this->trans_enabled) + { + return TRUE; + } + + // When transactions are nested we only begin/commit/rollback the outermost ones + if ($this->_trans_depth > 0) + { + return TRUE; + } + + return @pg_exec($this->conn_id, "rollback"); + } + + // -------------------------------------------------------------------- + + /** + * Escape String + * + * @access public + * @param string + * @return string + */ + function escape_str($str) + { + return pg_escape_string($str); + } + + // -------------------------------------------------------------------- + + /** + * Affected Rows + * + * @access public + * @return integer + */ + function affected_rows() + { + return @pg_affected_rows($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Insert ID + * + * @access public + * @return integer + */ + function insert_id() + { + $v = $this->_version(); + $v = $v['server']; + + $table = func_num_args() > 0 ? func_get_arg(0) : null; + $column = func_num_args() > 1 ? func_get_arg(1) : null; + + if ($table == null && $v >= '8.1') + { + $sql='SELECT LASTVAL() as ins_id'; + } + elseif ($table != null && $column != null && $v >= '8.0') + { + $sql = sprintf("SELECT pg_get_serial_sequence('%s','%s') as seq", $table, $column); + $query = $this->query($sql); + $row = $query->row(); + $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $row->seq); + } + elseif ($table != null) + { + // seq_name passed in table parameter + $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $table); + } + else + { + return pg_last_oid($this->result_id); + } + $query = $this->query($sql); + $row = $query->row(); + return $row->ins_id; + } + + // -------------------------------------------------------------------- + + /** + * "Count All" query + * + * Generates a platform-specific query string that counts all records in + * the specified database + * + * @access public + * @param string + * @return string + */ + function count_all($table = '') + { + if ($table == '') + return '0'; + + $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); + + if ($query->num_rows() == 0) + return '0'; + + $row = $query->row(); + return $row->numrows; + } + + // -------------------------------------------------------------------- + + /** + * Show table query + * + * Generates a platform-specific query string so that the table names can be fetched + * + * @access private + * @param boolean + * @return string + */ + function _list_tables($prefix_limit = FALSE) + { + $sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; + + if ($prefix_limit !== FALSE AND $this->dbprefix != '') + { + $sql .= " AND table_name LIKE '".$this->dbprefix."%'"; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Show column query + * + * Generates a platform-specific query string so that the column names can be fetched + * + * @access public + * @param string the table name + * @return string + */ + function _list_columns($table = '') + { + return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$table."'"; + } + + // -------------------------------------------------------------------- + + /** + * Field data query + * + * Generates a platform-specific query so that the column data can be retrieved + * + * @access public + * @param string the table name + * @return object + */ + function _field_data($table) + { + return "SELECT * FROM ".$table." LIMIT 1"; + } + + // -------------------------------------------------------------------- + + /** + * The error message string + * + * @access private + * @return string + */ + function _error_message() + { + return pg_last_error($this->conn_id); + } + + // -------------------------------------------------------------------- + + /** + * The error message number + * + * @access private + * @return integer + */ + function _error_number() + { + return ''; + } + + // -------------------------------------------------------------------- + + /** + * Escape the SQL Identifiers + * + * This function escapes column and table names + * + * @access private + * @param string + * @return string + */ + function _escape_identifiers($item) + { + if ($this->_escape_char == '') + { + return $item; + } + + foreach ($this->_reserved_identifiers as $id) + { + if (strpos($item, '.'.$id) !== FALSE) + { + $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); + + // remove duplicates if the user already included the escape + return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); + } + } + + if (strpos($item, '.') !== FALSE) + { + $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; + } + else + { + $str = $this->_escape_char.$item.$this->_escape_char; + } + + // remove duplicates if the user already included the escape + return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); + } + + // -------------------------------------------------------------------- + + /** + * From Tables + * + * This function implicitly groups FROM tables so there is no confusion + * about operator precedence in harmony with SQL standards + * + * @access public + * @param type + * @return type + */ + function _from_tables($tables) + { + if ( ! is_array($tables)) + { + $tables = array($tables); + } + + return implode(', ', $tables); + } + + // -------------------------------------------------------------------- + + /** + * Insert statement + * + * Generates a platform-specific insert string from the supplied data + * + * @access public + * @param string the table name + * @param array the insert keys + * @param array the insert values + * @return string + */ + function _insert($table, $keys, $values) + { + return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + } + + // -------------------------------------------------------------------- + + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @access public + * @param string the table name + * @param array the update data + * @param array the where clause + * @param array the orderby clause + * @param array the limit clause + * @return string + */ + function _update($table, $values, $where, $orderby = array(), $limit = FALSE) + { + foreach($values as $key => $val) + { + $valstr[] = $key." = ".$val; + } + + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; + + $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; + + $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); + + $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; + + $sql .= $orderby.$limit; + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Truncate statement + * + * Generates a platform-specific truncate string from the supplied data + * If the database does not support the truncate() command + * This function maps to "DELETE FROM table" + * + * @access public + * @param string the table name + * @return string + */ + function _truncate($table) + { + return "TRUNCATE ".$table; + } + + // -------------------------------------------------------------------- + + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @access public + * @param string the table name + * @param array the where clause + * @param string the limit clause + * @return string + */ + function _delete($table, $where = array(), $like = array(), $limit = FALSE) + { + $conditions = ''; + + if (count($where) > 0 OR count($like) > 0) + { + $conditions = "\nWHERE "; + $conditions .= implode("\n", $this->ar_where); + + if (count($where) > 0 && count($like) > 0) + { + $conditions .= " AND "; + } + $conditions .= implode("\n", $like); + } + + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; + + return "DELETE FROM ".$table.$conditions.$limit; + } + + // -------------------------------------------------------------------- + /** + * Limit string + * + * Generates a platform-specific LIMIT clause + * + * @access public + * @param string the sql query string + * @param integer the number of rows to limit the query to + * @param integer the offset value + * @return string + */ + function _limit($sql, $limit, $offset) + { + $sql .= "LIMIT ".$limit; + + if ($offset > 0) + { + $sql .= " OFFSET ".$offset; + } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Close DB Connection + * + * @access public + * @param resource + * @return void + */ + function _close($conn_id) + { + @pg_close($conn_id); + } + + +} + + +/* End of file postgre_driver.php */ /* Location: ./system/database/drivers/postgre/postgre_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index 5b4bcc295..72c2dd797 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -1,248 +1,248 @@ -db->_escape_identifiers($table)." ("; - $current_field_count = 0; - - foreach ($fields as $field=>$attributes) - { - // Numeric field names aren't allowed in databases, so if the key is - // numeric, we know it was assigned by PHP and the developer manually - // entered the field information, so we'll simply add it to the list - if (is_numeric($field)) - { - $sql .= "\n\t$attributes"; - } - else - { - $attributes = array_change_key_case($attributes, CASE_UPPER); - - $sql .= "\n\t".$this->db->_protect_identifiers($field); - - $sql .= ' '.$attributes['TYPE']; - - if (array_key_exists('CONSTRAINT', $attributes)) - { - $sql .= '('.$attributes['CONSTRAINT'].')'; - } - - if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) - { - $sql .= ' UNSIGNED'; - } - - if (array_key_exists('DEFAULT', $attributes)) - { - $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; - } - - if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } - - if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) - { - $sql .= ' AUTO_INCREMENT'; - } - } - - // don't add a comma on the end of the last field - if (++$current_field_count < count($fields)) - { - $sql .= ','; - } - } - - if (count($primary_keys) > 0) - { - $primary_keys = $this->db->_protect_identifiers($primary_keys); - $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; - } - - if (is_array($keys) && count($keys) > 0) - { - foreach ($keys as $key) - { - if (is_array($key)) - { - $key = $this->db->_protect_identifiers($key); - } - else - { - $key = array($this->db->_protect_identifiers($key)); - } - - $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")"; - } - } - - $sql .= "\n);"; - - return $sql; - } - - // -------------------------------------------------------------------- - - /** - * Drop Table - * - * @access private - * @return bool - */ - function _drop_table($table) - { - return "DROP TABLE ".$this->db->_escape_identifiers($table)." CASCADE"; - } - - // -------------------------------------------------------------------- - - /** - * Alter table query - * - * Generates a platform-specific query so that a table can be altered - * Called by add_column(), drop_column(), and column_alter(), - * - * @access private - * @param string the ALTER type (ADD, DROP, CHANGE) - * @param string the column name - * @param string the table name - * @param string the column definition - * @param string the default value - * @param boolean should 'NOT NULL' be added - * @param string the field after which we should add the new field - * @return object - */ - function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') - { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name); - - // DROP has everything it needs now. - if ($alter_type == 'DROP') - { - return $sql; - } - - $sql .= " $column_definition"; - - if ($default_value != '') - { - $sql .= " DEFAULT \"$default_value\""; - } - - if ($null === NULL) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } - - if ($after_field != '') - { - $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); - } - - return $sql; - - } - - // -------------------------------------------------------------------- - - /** - * Rename a table - * - * Generates a platform-specific query so that a table can be renamed - * - * @access private - * @param string the old table name - * @param string the new table name - * @return string - */ - function _rename_table($table_name, $new_table_name) - { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); - return $sql; - } - - -} - -/* End of file postgre_forge.php */ +db->_escape_identifiers($table)." ("; + $current_field_count = 0; + + foreach ($fields as $field=>$attributes) + { + // Numeric field names aren't allowed in databases, so if the key is + // numeric, we know it was assigned by PHP and the developer manually + // entered the field information, so we'll simply add it to the list + if (is_numeric($field)) + { + $sql .= "\n\t$attributes"; + } + else + { + $attributes = array_change_key_case($attributes, CASE_UPPER); + + $sql .= "\n\t".$this->db->_protect_identifiers($field); + + $sql .= ' '.$attributes['TYPE']; + + if (array_key_exists('CONSTRAINT', $attributes)) + { + $sql .= '('.$attributes['CONSTRAINT'].')'; + } + + if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) + { + $sql .= ' UNSIGNED'; + } + + if (array_key_exists('DEFAULT', $attributes)) + { + $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; + } + + if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) + { + $sql .= ' NULL'; + } + else + { + $sql .= ' NOT NULL'; + } + + if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) + { + $sql .= ' AUTO_INCREMENT'; + } + } + + // don't add a comma on the end of the last field + if (++$current_field_count < count($fields)) + { + $sql .= ','; + } + } + + if (count($primary_keys) > 0) + { + $primary_keys = $this->db->_protect_identifiers($primary_keys); + $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; + } + + if (is_array($keys) && count($keys) > 0) + { + foreach ($keys as $key) + { + if (is_array($key)) + { + $key = $this->db->_protect_identifiers($key); + } + else + { + $key = array($this->db->_protect_identifiers($key)); + } + + $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")"; + } + } + + $sql .= "\n);"; + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Drop Table + * + * @access private + * @return bool + */ + function _drop_table($table) + { + return "DROP TABLE ".$this->db->_escape_identifiers($table)." CASCADE"; + } + + // -------------------------------------------------------------------- + + /** + * Alter table query + * + * Generates a platform-specific query so that a table can be altered + * Called by add_column(), drop_column(), and column_alter(), + * + * @access private + * @param string the ALTER type (ADD, DROP, CHANGE) + * @param string the column name + * @param string the table name + * @param string the column definition + * @param string the default value + * @param boolean should 'NOT NULL' be added + * @param string the field after which we should add the new field + * @return object + */ + function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') + { + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name); + + // DROP has everything it needs now. + if ($alter_type == 'DROP') + { + return $sql; + } + + $sql .= " $column_definition"; + + if ($default_value != '') + { + $sql .= " DEFAULT \"$default_value\""; + } + + if ($null === NULL) + { + $sql .= ' NULL'; + } + else + { + $sql .= ' NOT NULL'; + } + + if ($after_field != '') + { + $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); + } + + return $sql; + + } + + // -------------------------------------------------------------------- + + /** + * Rename a table + * + * Generates a platform-specific query so that a table can be renamed + * + * @access private + * @param string the old table name + * @param string the new table name + * @return string + */ + function _rename_table($table_name, $new_table_name) + { + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); + return $sql; + } + + +} + +/* End of file postgre_forge.php */ /* Location: ./system/database/drivers/postgre/postgre_forge.php */ \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index 78b9a6040..3206c1330 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -1,169 +1,169 @@ -result_id); - } - - // -------------------------------------------------------------------- - - /** - * Number of fields in the result set - * - * @access public - * @return integer - */ - function num_fields() - { - return @pg_num_fields($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Fetch Field Names - * - * Generates an array of column names - * - * @access public - * @return array - */ - function list_fields() - { - $field_names = array(); - for ($i = 0; $i < $this->num_fields(); $i++) - { - $field_names[] = pg_field_name($this->result_id, $i); - } - - return $field_names; - } - - // -------------------------------------------------------------------- - - /** - * Field data - * - * Generates an array of objects containing field meta-data - * - * @access public - * @return array - */ - function field_data() - { - $retval = array(); - for ($i = 0; $i < $this->num_fields(); $i++) - { - $F = new stdClass(); - $F->name = pg_field_name($this->result_id, $i); - $F->type = pg_field_type($this->result_id, $i); - $F->max_length = pg_field_size($this->result_id, $i); - $F->primary_key = 0; - $F->default = ''; - - $retval[] = $F; - } - - return $retval; - } - - // -------------------------------------------------------------------- - - /** - * Free the result - * - * @return null - */ - function free_result() - { - if (is_resource($this->result_id)) - { - pg_free_result($this->result_id); - $this->result_id = FALSE; - } - } - - // -------------------------------------------------------------------- - - /** - * Data Seek - * - * Moves the internal pointer to the desired offset. We call - * this internally before fetching results to make sure the - * result set starts at zero - * - * @access private - * @return array - */ - function _data_seek($n = 0) - { - return pg_result_seek($this->result_id, $n); - } - - // -------------------------------------------------------------------- - - /** - * Result - associative array - * - * Returns the result set as an array - * - * @access private - * @return array - */ - function _fetch_assoc() - { - return pg_fetch_assoc($this->result_id); - } - - // -------------------------------------------------------------------- - - /** - * Result - object - * - * Returns the result set as an object - * - * @access private - * @return object - */ - function _fetch_object() - { - return pg_fetch_object($this->result_id); - } - -} - - -/* End of file postgre_result.php */ +result_id); + } + + // -------------------------------------------------------------------- + + /** + * Number of fields in the result set + * + * @access public + * @return integer + */ + function num_fields() + { + return @pg_num_fields($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Fetch Field Names + * + * Generates an array of column names + * + * @access public + * @return array + */ + function list_fields() + { + $field_names = array(); + for ($i = 0; $i < $this->num_fields(); $i++) + { + $field_names[] = pg_field_name($this->result_id, $i); + } + + return $field_names; + } + + // -------------------------------------------------------------------- + + /** + * Field data + * + * Generates an array of objects containing field meta-data + * + * @access public + * @return array + */ + function field_data() + { + $retval = array(); + for ($i = 0; $i < $this->num_fields(); $i++) + { + $F = new stdClass(); + $F->name = pg_field_name($this->result_id, $i); + $F->type = pg_field_type($this->result_id, $i); + $F->max_length = pg_field_size($this->result_id, $i); + $F->primary_key = 0; + $F->default = ''; + + $retval[] = $F; + } + + return $retval; + } + + // -------------------------------------------------------------------- + + /** + * Free the result + * + * @return null + */ + function free_result() + { + if (is_resource($this->result_id)) + { + pg_free_result($this->result_id); + $this->result_id = FALSE; + } + } + + // -------------------------------------------------------------------- + + /** + * Data Seek + * + * Moves the internal pointer to the desired offset. We call + * this internally before fetching results to make sure the + * result set starts at zero + * + * @access private + * @return array + */ + function _data_seek($n = 0) + { + return pg_result_seek($this->result_id, $n); + } + + // -------------------------------------------------------------------- + + /** + * Result - associative array + * + * Returns the result set as an array + * + * @access private + * @return array + */ + function _fetch_assoc() + { + return pg_fetch_assoc($this->result_id); + } + + // -------------------------------------------------------------------- + + /** + * Result - object + * + * Returns the result set as an object + * + * @access private + * @return object + */ + function _fetch_object() + { + return pg_fetch_object($this->result_id); + } + +} + + +/* End of file postgre_result.php */ /* Location: ./system/database/drivers/postgre/postgre_result.php */ \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index f9b0f22e0..06292f22a 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -1,124 +1,124 @@ -db->display_error('db_unsuported_feature'); - } - - /** - * - * The functions below have been deprecated as of 1.6, and are only here for backwards - * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation - * is STRONGLY discouraged in favour if using dbforge. - * - */ - - /** - * Create database - * - * @access private - * @param string the database name - * @return bool - */ - function _create_database($name) - { - return "CREATE DATABASE ".$name; - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access private - * @param string the database name - * @return bool - */ - function _drop_database($name) - { - return "DROP DATABASE ".$name; - } - - -} - - -/* End of file postgre_utility.php */ +db->display_error('db_unsuported_feature'); + } + + /** + * + * The functions below have been deprecated as of 1.6, and are only here for backwards + * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation + * is STRONGLY discouraged in favour if using dbforge. + * + */ + + /** + * Create database + * + * @access private + * @param string the database name + * @return bool + */ + function _create_database($name) + { + return "CREATE DATABASE ".$name; + } + + // -------------------------------------------------------------------- + + /** + * Drop database + * + * @access private + * @param string the database name + * @return bool + */ + function _drop_database($name) + { + return "DROP DATABASE ".$name; + } + + +} + + +/* End of file postgre_utility.php */ /* Location: ./system/database/drivers/postgre/postgre_utility.php */ \ No newline at end of file -- 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') 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') 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') 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') 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 +- system/database/drivers/postgre/postgre_forge.php | 2 +- system/database/drivers/postgre/postgre_result.php | 2 +- system/database/drivers/postgre/postgre_utility.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index db3a3f29d..9258da684 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index 72c2dd797..471dd80c9 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index 3206c1330..8e45eb1cf 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 06292f22a..235954fa6 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 -- 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 +- system/database/drivers/postgre/postgre_forge.php | 2 +- system/database/drivers/postgre/postgre_result.php | 2 +- system/database/drivers/postgre/postgre_utility.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 9258da684..bac179d40 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index 471dd80c9..c98ef425d 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index 8e45eb1cf..545f413e8 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 235954fa6..dda22ddb0 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 -- 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') 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 c5b044b739234c1e1635d4a4647b3440c44f4fa3 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Fri, 6 Aug 2010 13:06:32 -0500 Subject: Removed deprecated _drop_database() and _create_database() functions from db utility drivers. --- .../database/drivers/postgre/postgre_utility.php | 36 ---------------------- 1 file changed, 36 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index dda22ddb0..84b089af0 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -81,42 +81,6 @@ class CI_DB_postgre_utility extends CI_DB_utility { // Currently unsupported return $this->db->display_error('db_unsuported_feature'); } - - /** - * - * The functions below have been deprecated as of 1.6, and are only here for backwards - * compatibility. They now reside in dbforge(). The use of dbutils for database manipulation - * is STRONGLY discouraged in favour if using dbforge. - * - */ - - /** - * Create database - * - * @access private - * @param string the database name - * @return bool - */ - function _create_database($name) - { - return "CREATE DATABASE ".$name; - } - - // -------------------------------------------------------------------- - - /** - * Drop database - * - * @access private - * @param string the database name - * @return bool - */ - function _drop_database($name) - { - return "DROP DATABASE ".$name; - } - - } -- 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 ++++++++++----------- system/database/drivers/postgre/postgre_forge.php | 32 +++--- system/database/drivers/postgre/postgre_result.php | 18 ++-- 3 files changed, 83 insertions(+), 83 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 9f991e4a0..cf865432b 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -31,7 +31,7 @@ class CI_DB_postgre_driver extends CI_DB { var $dbdriver = 'postgre'; - + var $_escape_char = '"'; // clause and character used for LIKE escape sequences @@ -51,7 +51,7 @@ class CI_DB_postgre_driver extends CI_DB { * * @access private * @return string - */ + */ function _connect_string() { $components = array( @@ -61,7 +61,7 @@ class CI_DB_postgre_driver extends CI_DB { 'username' => 'user', 'password' => 'password' ); - + $connect_string = ""; foreach ($components as $key => $val) { @@ -80,9 +80,9 @@ class CI_DB_postgre_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_connect() - { + { return @pg_connect($this->_connect_string()); } @@ -93,12 +93,12 @@ class CI_DB_postgre_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_pconnect() { return @pg_pconnect($this->_connect_string()); } - + // -------------------------------------------------------------------- /** @@ -125,7 +125,7 @@ class CI_DB_postgre_driver extends CI_DB { * * @access private called by the base class * @return resource - */ + */ function db_select() { // Not needed for Postgre so we'll return TRUE @@ -149,7 +149,7 @@ class CI_DB_postgre_driver extends CI_DB { } // -------------------------------------------------------------------- - + /** * Version number query string * @@ -169,13 +169,13 @@ class CI_DB_postgre_driver extends CI_DB { * @access private called by the base class * @param string an SQL query * @return resource - */ + */ function _execute($sql) { $sql = $this->_prep_query($sql); return @pg_query($this->conn_id, $sql); } - + // -------------------------------------------------------------------- /** @@ -186,7 +186,7 @@ class CI_DB_postgre_driver extends CI_DB { * @access private called by execute() * @param string an SQL query * @return string - */ + */ function _prep_query($sql) { return $sql; @@ -198,15 +198,15 @@ class CI_DB_postgre_driver extends CI_DB { * Begin Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_begin($test_mode = FALSE) { if ( ! $this->trans_enabled) { return TRUE; } - + // When transactions are nested we only begin/commit/rollback the outermost ones if ($this->_trans_depth > 0) { @@ -227,8 +227,8 @@ class CI_DB_postgre_driver extends CI_DB { * Commit Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_commit() { if ( ! $this->trans_enabled) @@ -251,8 +251,8 @@ class CI_DB_postgre_driver extends CI_DB { * Rollback Transaction * * @access public - * @return bool - */ + * @return bool + */ function trans_rollback() { if ( ! $this->trans_enabled) @@ -284,15 +284,15 @@ class CI_DB_postgre_driver extends CI_DB { if (is_array($str)) { foreach($str as $key => $val) - { + { $str[$key] = $this->escape_str($val, $like); - } - - return $str; - } + } + + return $str; + } $str = pg_escape_string($str); - + // escape LIKE condition wildcards if ($like === TRUE) { @@ -300,10 +300,10 @@ class CI_DB_postgre_driver extends CI_DB { array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr), $str); } - + return $str; } - + // -------------------------------------------------------------------- /** @@ -316,7 +316,7 @@ class CI_DB_postgre_driver extends CI_DB { { return @pg_affected_rows($this->result_id); } - + // -------------------------------------------------------------------- /** @@ -329,10 +329,10 @@ class CI_DB_postgre_driver extends CI_DB { { $v = $this->_version(); $v = $v['server']; - + $table = func_num_args() > 0 ? func_get_arg(0) : null; $column = func_num_args() > 1 ? func_get_arg(1) : null; - + if ($table == null && $v >= '8.1') { $sql='SELECT LASTVAL() as ins_id'; @@ -400,17 +400,17 @@ class CI_DB_postgre_driver extends CI_DB { * @return string */ function _list_tables($prefix_limit = FALSE) - { - $sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; - + { + $sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"; + if ($prefix_limit !== FALSE AND $this->dbprefix != '') { $sql .= " AND table_name LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); } - + return $sql; } - + // -------------------------------------------------------------------- /** @@ -455,7 +455,7 @@ class CI_DB_postgre_driver extends CI_DB { { return pg_last_error($this->conn_id); } - + // -------------------------------------------------------------------- /** @@ -491,26 +491,26 @@ class CI_DB_postgre_driver extends CI_DB { { if (strpos($item, '.'.$id) !== FALSE) { - $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); - + $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item); + // remove duplicates if the user already included the escape return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); - } + } } - + if (strpos($item, '.') !== FALSE) { - $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; + $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char; } else { $str = $this->_escape_char.$item.$this->_escape_char; } - + // remove duplicates if the user already included the escape return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str); } - + // -------------------------------------------------------------------- /** @@ -529,12 +529,12 @@ class CI_DB_postgre_driver extends CI_DB { { $tables = array($tables); } - + return implode(', ', $tables); } // -------------------------------------------------------------------- - + /** * Insert statement * @@ -547,10 +547,10 @@ class CI_DB_postgre_driver extends CI_DB { * @return string */ function _insert($table, $keys, $values) - { + { return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } - + // -------------------------------------------------------------------- /** @@ -572,17 +572,17 @@ class CI_DB_postgre_driver extends CI_DB { { $valstr[] = $key." = ".$val; } - + $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - + $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):''; - + $sql = "UPDATE ".$table." SET ".implode(', ', $valstr); $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : ''; $sql .= $orderby.$limit; - + return $sql; } @@ -598,12 +598,12 @@ class CI_DB_postgre_driver extends CI_DB { * @access public * @param string the table name * @return string - */ + */ function _truncate($table) { return "TRUNCATE ".$table; } - + // -------------------------------------------------------------------- /** @@ -616,7 +616,7 @@ class CI_DB_postgre_driver extends CI_DB { * @param array the where clause * @param string the limit clause * @return string - */ + */ function _delete($table, $where = array(), $like = array(), $limit = FALSE) { $conditions = ''; @@ -634,7 +634,7 @@ class CI_DB_postgre_driver extends CI_DB { } $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; - + return "DELETE FROM ".$table.$conditions.$limit; } @@ -651,14 +651,14 @@ class CI_DB_postgre_driver extends CI_DB { * @return string */ function _limit($sql, $limit, $offset) - { + { $sql .= "LIMIT ".$limit; - + if ($offset > 0) { $sql .= " OFFSET ".$offset; } - + return $sql; } diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index c98ef425d..12eef2923 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -66,12 +66,12 @@ class CI_DB_postgre_forge extends CI_DB_forge { function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) { $sql = 'CREATE TABLE '; - + if ($if_not_exists === TRUE) { $sql .= 'IF NOT EXISTS '; } - + $sql .= $this->db->_escape_identifiers($table)." ("; $current_field_count = 0; @@ -87,41 +87,41 @@ class CI_DB_postgre_forge extends CI_DB_forge { else { $attributes = array_change_key_case($attributes, CASE_UPPER); - + $sql .= "\n\t".$this->db->_protect_identifiers($field); - + $sql .= ' '.$attributes['TYPE']; - + if (array_key_exists('CONSTRAINT', $attributes)) { $sql .= '('.$attributes['CONSTRAINT'].')'; } - + if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) { $sql .= ' UNSIGNED'; } - + if (array_key_exists('DEFAULT', $attributes)) { $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; } - + if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) { $sql .= ' NULL'; } else { - $sql .= ' NOT NULL'; + $sql .= ' NOT NULL'; } - + if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) { $sql .= ' AUTO_INCREMENT'; } } - + // don't add a comma on the end of the last field if (++$current_field_count < count($fields)) { @@ -134,20 +134,20 @@ class CI_DB_postgre_forge extends CI_DB_forge { $primary_keys = $this->db->_protect_identifiers($primary_keys); $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; } - + if (is_array($keys) && count($keys) > 0) { foreach ($keys as $key) { if (is_array($key)) { - $key = $this->db->_protect_identifiers($key); + $key = $this->db->_protect_identifiers($key); } else { $key = array($this->db->_protect_identifiers($key)); } - + $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")"; } } @@ -218,9 +218,9 @@ class CI_DB_postgre_forge extends CI_DB_forge { { $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); } - + return $sql; - + } // -------------------------------------------------------------------- diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index 545f413e8..b60ad7dd3 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -36,7 +36,7 @@ class CI_DB_postgre_result extends CI_DB_result { { return @pg_num_rows($this->result_id); } - + // -------------------------------------------------------------------- /** @@ -67,7 +67,7 @@ class CI_DB_postgre_result extends CI_DB_result { { $field_names[] = pg_field_name($this->result_id, $i); } - + return $field_names; } @@ -86,16 +86,16 @@ class CI_DB_postgre_result extends CI_DB_result { $retval = array(); for ($i = 0; $i < $this->num_fields(); $i++) { - $F = new stdClass(); - $F->name = pg_field_name($this->result_id, $i); - $F->type = pg_field_type($this->result_id, $i); + $F = new stdClass(); + $F->name = pg_field_name($this->result_id, $i); + $F->type = pg_field_type($this->result_id, $i); $F->max_length = pg_field_size($this->result_id, $i); $F->primary_key = 0; $F->default = ''; $retval[] = $F; } - + return $retval; } @@ -105,7 +105,7 @@ class CI_DB_postgre_result extends CI_DB_result { * Free the result * * @return null - */ + */ function free_result() { if (is_resource($this->result_id)) @@ -146,7 +146,7 @@ class CI_DB_postgre_result extends CI_DB_result { { return pg_fetch_assoc($this->result_id); } - + // -------------------------------------------------------------------- /** @@ -161,7 +161,7 @@ class CI_DB_postgre_result extends CI_DB_result { { return pg_fetch_object($this->result_id); } - + } -- 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 +- system/database/drivers/postgre/postgre_forge.php | 2 +- system/database/drivers/postgre/postgre_result.php | 2 +- system/database/drivers/postgre/postgre_utility.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index cf865432b..b61a9d75b 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index 12eef2923..41858f36e 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index b60ad7dd3..126631201 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 84b089af0..f04c7f083 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team -- cgit v1.2.3-24-g4f1b From 678256c2007b06452b581fb692d948b7c9c94a7b Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Tue, 21 Dec 2010 12:05:12 -0600 Subject: Fix #93 Updating postgres dbforge create table method. Thanks to James Gifford for the patch. http://codeigniter.com/forums/viewthread/73392/ --- system/database/drivers/postgre/postgre_forge.php | 81 ++++++++++++++++++----- 1 file changed, 66 insertions(+), 15 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index 41858f36e..16127ffd7 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -69,7 +69,10 @@ class CI_DB_postgre_forge extends CI_DB_forge { if ($if_not_exists === TRUE) { - $sql .= 'IF NOT EXISTS '; + if ($this->db->table_exists($table)) + { + return "SELECT * FROM $table"; // Needs to return innocous but valid SQL statement + } } $sql .= $this->db->_escape_identifiers($table)." ("; @@ -90,16 +93,55 @@ class CI_DB_postgre_forge extends CI_DB_forge { $sql .= "\n\t".$this->db->_protect_identifiers($field); - $sql .= ' '.$attributes['TYPE']; + $is_unsigned = (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE); - if (array_key_exists('CONSTRAINT', $attributes)) + // Convert datatypes to be PostgreSQL-compatible + switch (strtoupper($attributes['TYPE'])) { - $sql .= '('.$attributes['CONSTRAINT'].')'; + case 'TINYINT': + $attributes['TYPE'] = 'SMALLINT'; + break; + case 'SMALLINT': + $attributes['TYPE'] = ($is_unsigned) ? 'INTEGER' : 'SMALLINT'; + break; + case 'MEDIUMINT': + $attributes['TYPE'] = 'INTEGER'; + break; + case 'INT': + $attributes['TYPE'] = ($is_unsigned) ? 'BIGINT' : 'INTEGER'; + break; + case 'BIGINT': + $attributes['TYPE'] = ($is_unsigned) ? 'NUMERIC' : 'BIGINT'; + break; + case 'DOUBLE': + $attributes['TYPE'] = 'DOUBLE PRECISION'; + break; + case 'DATETIME': + $attributes['TYPE'] = 'TIMESTAMP'; + break; + case 'LONGTEXT': + $attributes['TYPE'] = 'TEXT'; + break; + case 'BLOB': + $attributes['TYPE'] = 'BYTEA'; + break; } - if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) + // If this is an auto-incrementing primary key, use the serial data type instead + if (in_array($field, $primary_keys) && array_key_exists('AUTO_INCREMENT', $attributes) + && $attributes['AUTO_INCREMENT'] === TRUE) + { + $sql .= ' SERIAL'; + } + else { - $sql .= ' UNSIGNED'; + $sql .= ' '.$attributes['TYPE']; + } + + // Modified to prevent constraints with integer data types + if (array_key_exists('CONSTRAINT', $attributes) && strpos($attributes['TYPE'], 'INT') === false) + { + $sql .= '('.$attributes['CONSTRAINT'].')'; } if (array_key_exists('DEFAULT', $attributes)) @@ -116,9 +158,10 @@ class CI_DB_postgre_forge extends CI_DB_forge { $sql .= ' NOT NULL'; } - if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) + // Added new attribute to create unqite fields. Also works with MySQL + if (array_key_exists('UNIQUE', $attributes) && $attributes['UNIQUE'] === TRUE) { - $sql .= ' AUTO_INCREMENT'; + $sql .= ' UNIQUE'; } } @@ -131,10 +174,17 @@ class CI_DB_postgre_forge extends CI_DB_forge { if (count($primary_keys) > 0) { - $primary_keys = $this->db->_protect_identifiers($primary_keys); + // Something seems to break when passing an array to _protect_identifiers() + foreach ($primary_keys as $index => $key) + { + $primary_keys[$index] = $this->db->_protect_identifiers($key); + } + $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; } + $sql .= "\n);"; + if (is_array($keys) && count($keys) > 0) { foreach ($keys as $key) @@ -148,12 +198,13 @@ class CI_DB_postgre_forge extends CI_DB_forge { $key = array($this->db->_protect_identifiers($key)); } - $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")"; + foreach ($key as $field) + { + $sql .= "CREATE INDEX " . $table . "_" . str_replace(array('"', "'"), '', $field) . "_index ON $table ($field); "; + } } } - $sql .= "\n);"; - return $sql; } @@ -162,12 +213,12 @@ class CI_DB_postgre_forge extends CI_DB_forge { /** * Drop Table * - * @access private - * @return bool + * @access private + * @return bool */ function _drop_table($table) { - return "DROP TABLE ".$this->db->_escape_identifiers($table)." CASCADE"; + return "DROP TABLE IF EXISTS ".$this->db->_escape_identifiers($table)." CASCADE"; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 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 +- system/database/drivers/postgre/postgre_forge.php | 2 +- system/database/drivers/postgre/postgre_result.php | 2 +- system/database/drivers/postgre/postgre_utility.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index b61a9d75b..0bb7974d8 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index 16127ffd7..91a1c6861 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index 126631201..e9a1d1607 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index f04c7f083..741c52ea8 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 -- 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') 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') 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 +- system/database/drivers/postgre/postgre_forge.php | 10 +++++----- system/database/drivers/postgre/postgre_result.php | 4 ++-- system/database/drivers/postgre/postgre_utility.php | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 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') 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 +- system/database/drivers/postgre/postgre_forge.php | 10 +++++----- system/database/drivers/postgre/postgre_result.php | 4 ++-- system/database/drivers/postgre/postgre_utility.php | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index bf985de37..47ff36246 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -1,4 +1,4 @@ -