summaryrefslogtreecommitdiffstats
path: root/system/database/drivers/postgre
diff options
context:
space:
mode:
Diffstat (limited to 'system/database/drivers/postgre')
-rw-r--r--system/database/drivers/postgre/index.html3
-rw-r--r--system/database/drivers/postgre/postgre_driver.php736
-rw-r--r--system/database/drivers/postgre/postgre_forge.php354
-rw-r--r--system/database/drivers/postgre/postgre_result.php113
-rw-r--r--system/database/drivers/postgre/postgre_utility.php102
5 files changed, 567 insertions, 741 deletions
diff --git a/system/database/drivers/postgre/index.html b/system/database/drivers/postgre/index.html
index c942a79ce..b702fbc39 100644
--- a/system/database/drivers/postgre/index.html
+++ b/system/database/drivers/postgre/index.html
@@ -1,3 +1,4 @@
+<!DOCTYPE html>
<html>
<head>
<title>403 Forbidden</title>
@@ -7,4 +8,4 @@
<p>Directory access is forbidden.</p>
</body>
-</html> \ No newline at end of file
+</html>
diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php
index c9365fdb1..bcdfc060a 100644
--- a/system/database/drivers/postgre/postgre_driver.php
+++ b/system/database/drivers/postgre/postgre_driver.php
@@ -1,102 +1,172 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP
*
- * @package CodeIgniter
- * @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc.
- * @license http://codeigniter.com/user_guide/license.html
- * @link http://codeigniter.com
- * @since Version 1.0
+ * This content is released under the MIT License (MIT)
+ *
+ * Copyright (c) 2014 - 2017, British Columbia Institute of Technology
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
+ * @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/)
+ * @license http://opensource.org/licenses/MIT MIT License
+ * @link https://codeigniter.com
+ * @since Version 1.3.0
* @filesource
*/
-
-// ------------------------------------------------------------------------
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Postgre Database Adapter Class
*
* Note: _DB is an extender class that the app controller
- * creates dynamically based on whether the active record
+ * creates dynamically based on whether the query builder
* class is being used or not.
*
* @package CodeIgniter
* @subpackage Drivers
* @category Database
- * @author ExpressionEngine Dev Team
- * @link http://codeigniter.com/user_guide/database/
+ * @author EllisLab Dev Team
+ * @link https://codeigniter.com/user_guide/database/
*/
class CI_DB_postgre_driver extends CI_DB {
- var $dbdriver = 'postgre';
+ /**
+ * Database driver
+ *
+ * @var string
+ */
+ public $dbdriver = 'postgre';
- var $_escape_char = '"';
+ /**
+ * Database schema
+ *
+ * @var string
+ */
+ public $schema = 'public';
- // 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
- * used for the count_all() and count_all_results() functions.
+ * ORDER BY random keyword
+ *
+ * @var array
*/
- var $_count_string = "SELECT COUNT(*) AS ";
- var $_random_keyword = ' RANDOM()'; // database specific random keyword
+ protected $_random_keyword = array('RANDOM()', 'RANDOM()');
+
+ // --------------------------------------------------------------------
/**
- * Connection String
+ * Class constructor
*
- * @access private
- * @return string
+ * Creates a DSN string to be used for db_connect() and db_pconnect()
+ *
+ * @param array $params
+ * @return void
*/
- function _connect_string()
+ public function __construct($params)
{
- $components = array(
- 'hostname' => 'host',
- 'port' => 'port',
- 'database' => 'dbname',
- 'username' => 'user',
- 'password' => 'password'
- );
-
- $connect_string = "";
- foreach ($components as $key => $val)
+ parent::__construct($params);
+
+ if ( ! empty($this->dsn))
+ {
+ return;
+ }
+
+ $this->dsn === '' OR $this->dsn = '';
+
+ if (strpos($this->hostname, '/') !== FALSE)
+ {
+ // If UNIX sockets are used, we shouldn't set a port
+ $this->port = '';
+ }
+
+ $this->hostname === '' OR $this->dsn = 'host='.$this->hostname.' ';
+
+ if ( ! empty($this->port) && ctype_digit($this->port))
+ {
+ $this->dsn .= 'port='.$this->port.' ';
+ }
+
+ if ($this->username !== '')
+ {
+ $this->dsn .= 'user='.$this->username.' ';
+
+ /* An empty password is valid!
+ *
+ * $db['password'] = NULL must be done in order to ignore it.
+ */
+ $this->password === NULL OR $this->dsn .= "password='".$this->password."' ";
+ }
+
+ $this->database === '' OR $this->dsn .= 'dbname='.$this->database.' ';
+
+ /* We don't have these options as elements in our standard configuration
+ * array, but they might be set by parse_url() if the configuration was
+ * provided via string. Example:
+ *
+ * postgre://username:password@localhost:5432/database?connect_timeout=5&sslmode=1
+ */
+ foreach (array('connect_timeout', 'options', 'sslmode', 'service') as $key)
{
- if (isset($this->$key) && $this->$key != '')
+ if (isset($this->$key) && is_string($this->$key) && $this->$key !== '')
{
- $connect_string .= " $val=".$this->$key;
+ $this->dsn .= $key."='".$this->$key."' ";
}
}
- return trim($connect_string);
+
+ $this->dsn = rtrim($this->dsn);
}
// --------------------------------------------------------------------
/**
- * Non-persistent database connection
+ * Database connection
*
- * @access private called by the base class
+ * @param bool $persistent
* @return resource
*/
- function db_connect()
+ public function db_connect($persistent = FALSE)
{
- return @pg_connect($this->_connect_string());
- }
+ $this->conn_id = ($persistent === TRUE)
+ ? pg_pconnect($this->dsn)
+ : pg_connect($this->dsn);
- // --------------------------------------------------------------------
+ if ($this->conn_id !== FALSE)
+ {
+ if ($persistent === TRUE
+ && pg_connection_status($this->conn_id) === PGSQL_CONNECTION_BAD
+ && pg_ping($this->conn_id) === FALSE
+ )
+ {
+ return FALSE;
+ }
- /**
- * Persistent database connection
- *
- * @access private called by the base class
- * @return resource
- */
- function db_pconnect()
- {
- return @pg_pconnect($this->_connect_string());
+ empty($this->schema) OR $this->simple_query('SET search_path TO '.$this->schema.',public');
+ }
+
+ return $this->conn_id;
}
// --------------------------------------------------------------------
@@ -107,10 +177,9 @@ class CI_DB_postgre_driver extends CI_DB {
* Keep / reestablish the db connection if no queries have been
* sent for a length of time exceeding the server's idle timeout
*
- * @access public
* @return void
*/
- function reconnect()
+ public function reconnect()
{
if (pg_ping($this->conn_id) === FALSE)
{
@@ -121,188 +190,147 @@ class CI_DB_postgre_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Select the database
+ * Set client character set
*
- * @access private called by the base class
- * @return resource
+ * @param string $charset
+ * @return bool
*/
- function db_select()
+ protected function _db_set_charset($charset)
{
- // Not needed for Postgre so we'll return TRUE
- return TRUE;
+ return (pg_set_client_encoding($this->conn_id, $charset) === 0);
}
// --------------------------------------------------------------------
/**
- * Set client character set
+ * Database version number
*
- * @access public
- * @param string
- * @param string
- * @return resource
+ * @return string
*/
- function db_set_charset($charset, $collation)
+ public function version()
{
- // @todo - add support if needed
- return TRUE;
+ if (isset($this->data_cache['version']))
+ {
+ return $this->data_cache['version'];
+ }
+
+ if ( ! $this->conn_id OR ($pg_version = pg_version($this->conn_id)) === FALSE)
+ {
+ return FALSE;
+ }
+
+ /* If PHP was compiled with PostgreSQL lib versions earlier
+ * than 7.4, pg_version() won't return the server version
+ * and so we'll have to fall back to running a query in
+ * order to get it.
+ */
+ return isset($pg_version['server'])
+ ? $this->data_cache['version'] = $pg_version['server']
+ : parent::version();
}
// --------------------------------------------------------------------
/**
- * Version number query string
+ * Execute the query
*
- * @access public
- * @return string
+ * @param string $sql an SQL query
+ * @return resource
*/
- function _version()
+ protected function _execute($sql)
{
- $pg_version = pg_version($this->conn_id);
- return $pg_version;
+ return pg_query($this->conn_id, $sql);
}
// --------------------------------------------------------------------
/**
- * Execute the query
+ * Begin Transaction
*
- * @access private called by the base class
- * @param string an SQL query
- * @return resource
+ * @return bool
*/
- function _execute($sql)
+ protected function _trans_begin()
{
- $sql = $this->_prep_query($sql);
- return @pg_query($this->conn_id, $sql);
+ return (bool) pg_query($this->conn_id, 'BEGIN');
}
// --------------------------------------------------------------------
/**
- * Prep the query
- *
- * If needed, each database adapter can prep the query string
+ * Commit Transaction
*
- * @access private called by execute()
- * @param string an SQL query
- * @return string
+ * @return bool
*/
- function _prep_query($sql)
+ protected function _trans_commit()
{
- return $sql;
+ return (bool) pg_query($this->conn_id, 'COMMIT');
}
// --------------------------------------------------------------------
/**
- * Begin Transaction
+ * Rollback Transaction
*
- * @access public
* @return bool
*/
- function trans_begin($test_mode = FALSE)
+ protected 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;
- }
-
- // 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");
+ return (bool) pg_query($this->conn_id, 'ROLLBACK');
}
// --------------------------------------------------------------------
/**
- * Commit Transaction
+ * Determines if a query is a "write" type.
*
- * @access public
+ * @param string An SQL query string
* @return bool
*/
- function trans_commit()
+ public function is_write_type($sql)
{
- if ( ! $this->trans_enabled)
+ if (preg_match('#^(INSERT|UPDATE).*RETURNING\s.+(\,\s?.+)*$#is', $sql))
{
- return TRUE;
+ return FALSE;
}
- // 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");
+ return parent::is_write_type($sql);
}
// --------------------------------------------------------------------
/**
- * Rollback Transaction
+ * Platform-dependent string escape
*
- * @access public
- * @return bool
+ * @param string
+ * @return string
*/
- function trans_rollback()
+ protected function _escape_str($str)
{
- 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");
+ return pg_escape_string($this->conn_id, $str);
}
// --------------------------------------------------------------------
/**
- * Escape String
+ * "Smart" Escape String
*
- * @access public
- * @param string
- * @param bool whether or not the string will be used in a LIKE condition
- * @return string
+ * Escapes data based on type
+ *
+ * @param string $str
+ * @return mixed
*/
- function escape_str($str, $like = FALSE)
+ public function escape($str)
{
- if (is_array($str))
+ if (is_php('5.4.4') && (is_string($str) OR (is_object($str) && method_exists($str, '__toString'))))
{
- foreach ($str as $key => $val)
- {
- $str[$key] = $this->escape_str($val, $like);
- }
-
- return $str;
+ return pg_escape_literal($this->conn_id, $str);
}
-
- $str = pg_escape_string($str);
-
- // escape LIKE condition wildcards
- if ($like === TRUE)
+ elseif (is_bool($str))
{
- $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) ? 'TRUE' : 'FALSE';
}
- return $str;
+ return parent::escape($str);
}
// --------------------------------------------------------------------
@@ -310,12 +338,11 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Affected Rows
*
- * @access public
- * @return integer
+ * @return int
*/
- function affected_rows()
+ public function affected_rows()
{
- return @pg_affected_rows($this->result_id);
+ return pg_affected_rows($this->result_id);
}
// --------------------------------------------------------------------
@@ -323,71 +350,45 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Insert ID
*
- * @access public
- * @return integer
+ * @return string
*/
- function insert_id()
+ public function insert_id()
{
- $v = $this->_version();
- $v = $v['server'];
+ $v = pg_version($this->conn_id);
+ $v = isset($v['server']) ? $v['server'] : 0; // 'server' key is only available since PosgreSQL 7.4
- $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';
+ $sql = 'SELECT LASTVAL() AS ins_id';
}
- elseif ($table != NULL && $column != NULL && $v >= '8.0')
+ elseif ($table !== NULL)
{
- $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);
+ if ($column !== NULL && $v >= '8.0')
+ {
+ $sql = 'SELECT pg_get_serial_sequence(\''.$table."', '".$column."') AS seq";
+ $query = $this->query($sql);
+ $query = $query->row();
+ $seq = $query->seq;
+ }
+ else
+ {
+ // seq_name passed in table parameter
+ $seq = $table;
+ }
+
+ $sql = 'SELECT CURRVAL(\''.$seq."') AS ins_id";
}
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();
- $this->_reset_select();
- return (int) $row->numrows;
+ $query = $this->query($sql);
+ $query = $query->row();
+ return (int) $query->ins_id;
}
// --------------------------------------------------------------------
@@ -397,17 +398,18 @@ 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
+ * @param bool $prefix_limit
* @return string
*/
- function _list_tables($prefix_limit = FALSE)
+ protected 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" = \''.$this->schema."'";
- if ($prefix_limit !== FALSE AND $this->dbprefix != '')
+ if ($prefix_limit !== FALSE && $this->dbprefix !== '')
{
- $sql .= " AND table_name LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
+ return $sql.' AND "table_name" LIKE \''
+ .$this->escape_like_str($this->dbprefix)."%' "
+ .sprintf($this->_like_escape_str, $this->_like_escape_chr);
}
return $sql;
@@ -416,212 +418,160 @@ class CI_DB_postgre_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Show column query
+ * List column query
*
* Generates a platform-specific query string so that the column names can be fetched
*
- * @access public
- * @param string the table name
+ * @param string $table
* @return string
*/
- function _list_columns($table = '')
+ protected function _list_columns($table = '')
{
- return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$table."'";
+ return 'SELECT "column_name"
+ FROM "information_schema"."columns"
+ WHERE LOWER("table_name") = '.$this->escape(strtolower($table));
}
// --------------------------------------------------------------------
/**
- * Field data query
- *
- * Generates a platform-specific query so that the column data can be retrieved
+ * Returns an object with field data
*
- * @access public
- * @param string the table name
- * @return object
+ * @param string $table
+ * @return array
*/
- function _field_data($table)
+ public function field_data($table)
{
- return "SELECT * FROM ".$table." LIMIT 1";
- }
+ $sql = 'SELECT "column_name", "data_type", "character_maximum_length", "numeric_precision", "column_default"
+ FROM "information_schema"."columns"
+ WHERE LOWER("table_name") = '.$this->escape(strtolower($table));
- // --------------------------------------------------------------------
+ if (($query = $this->query($sql)) === FALSE)
+ {
+ return FALSE;
+ }
+ $query = $query->result_object();
- /**
- * The error message string
- *
- * @access private
- * @return string
- */
- function _error_message()
- {
- return pg_last_error($this->conn_id);
+ $retval = array();
+ for ($i = 0, $c = count($query); $i < $c; $i++)
+ {
+ $retval[$i] = new stdClass();
+ $retval[$i]->name = $query[$i]->column_name;
+ $retval[$i]->type = $query[$i]->data_type;
+ $retval[$i]->max_length = ($query[$i]->character_maximum_length > 0) ? $query[$i]->character_maximum_length : $query[$i]->numeric_precision;
+ $retval[$i]->default = $query[$i]->column_default;
+ }
+
+ return $retval;
}
// --------------------------------------------------------------------
/**
- * The error message number
+ * Error
+ *
+ * Returns an array containing code and message of the last
+ * database error that has occurred.
*
- * @access private
- * @return integer
+ * @return array
*/
- function _error_number()
+ public function error()
{
- return '';
+ return array('code' => '', 'message' => pg_last_error($this->conn_id));
}
// --------------------------------------------------------------------
/**
- * Escape the SQL Identifiers
+ * ORDER BY
*
- * This function escapes column and table names
- *
- * @access private
- * @param string
- * @return string
+ * @param string $orderby
+ * @param string $direction ASC, DESC or RANDOM
+ * @param bool $escape
+ * @return object
*/
- function _escape_identifiers($item)
+ public function order_by($orderby, $direction = '', $escape = NULL)
{
- if ($this->_escape_char == '')
- {
- return $item;
- }
-
- foreach ($this->_reserved_identifiers as $id)
+ $direction = strtoupper(trim($direction));
+ if ($direction === 'RANDOM')
{
- if (strpos($item, '.'.$id) !== FALSE)
+ if ( ! is_float($orderby) && ctype_digit((string) $orderby))
{
- $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);
+ $orderby = ($orderby > 1)
+ ? (float) '0.'.$orderby
+ : (float) $orderby;
}
- }
-
- 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);
- }
-
- // --------------------------------------------------------------------
+ if (is_float($orderby))
+ {
+ $this->simple_query('SET SEED '.$orderby);
+ }
- /**
- * 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);
+ $orderby = $this->_random_keyword[0];
+ $direction = '';
+ $escape = FALSE;
}
- return implode(', ', $tables);
+ return parent::order_by($orderby, $direction, $escape);
}
// --------------------------------------------------------------------
/**
- * Insert statement
+ * Update statement
*
- * Generates a platform-specific insert string from the supplied data
+ * Generates a platform-specific update string from the supplied data
*
- * @access public
- * @param string the table name
- * @param array the insert keys
- * @param array the insert values
+ * @param string $table
+ * @param array $values
* @return string
*/
- function _insert($table, $keys, $values)
- {
- return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
- }
-
- // --------------------------------------------------------------------
-
- /**
- * 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)
+ protected function _update($table, $values)
{
- return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values);
+ $this->qb_limit = FALSE;
+ $this->qb_orderby = array();
+ return parent::_update($table, $values);
}
// --------------------------------------------------------------------
/**
- * Update statement
+ * Update_Batch statement
*
- * Generates a platform-specific update string from the supplied data
+ * Generates a platform-specific batch update string from the supplied data
*
- * @access public
- * @param string the table name
- * @param array the update data
- * @param array the where clause
- * @param array the orderby clause
- * @param array the limit clause
+ * @param string $table Table name
+ * @param array $values Update data
+ * @param string $index WHERE key
* @return string
*/
- function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
+ protected function _update_batch($table, $values, $index)
{
+ $ids = array();
foreach ($values as $key => $val)
{
- $valstr[] = $key." = ".$val;
- }
+ $ids[] = $val[$index]['value'];
- $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;
+ foreach (array_keys($val) as $field)
+ {
+ if ($field !== $index)
+ {
+ $final[$val[$field]['field']][] = 'WHEN '.$val[$index]['value'].' THEN '.$val[$field]['value'];
+ }
+ }
+ }
- return $sql;
- }
+ $cases = '';
+ foreach ($final as $k => $v)
+ {
+ $cases .= $k.' = (CASE '.$val[$index]['field']."\n"
+ .implode("\n", $v)."\n"
+ .'ELSE '.$k.' END), ';
+ }
- // --------------------------------------------------------------------
+ $this->where($val[$index]['field'].' IN('.implode(',', $ids).')', NULL, FALSE);
- /**
- * 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;
+ return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_wh('qb_where');
}
// --------------------------------------------------------------------
@@ -631,55 +581,28 @@ class CI_DB_postgre_driver extends CI_DB {
*
* Generates a platform-specific delete string from the supplied data
*
- * @access public
- * @param string the table name
- * @param array the where clause
- * @param string the limit clause
+ * @param string $table
* @return string
*/
- function _delete($table, $where = array(), $like = array(), $limit = FALSE)
+ protected function _delete($table)
{
- $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;
+ $this->qb_limit = FALSE;
+ return parent::_delete($table);
}
// --------------------------------------------------------------------
+
/**
- * Limit string
+ * LIMIT
*
* Generates a platform-specific LIMIT clause
*
- * @access public
- * @param string the sql query string
- * @param integer the number of rows to limit the query to
- * @param integer the offset value
+ * @param string $sql SQL Query
* @return string
*/
- function _limit($sql, $limit, $offset)
+ protected function _limit($sql)
{
- $sql .= "LIMIT ".$limit;
-
- if ($offset > 0)
- {
- $sql .= " OFFSET ".$offset;
- }
-
- return $sql;
+ return $sql.' LIMIT '.$this->qb_limit.($this->qb_offset ? ' OFFSET '.$this->qb_offset : '');
}
// --------------------------------------------------------------------
@@ -687,18 +610,11 @@ class CI_DB_postgre_driver extends CI_DB {
/**
* Close DB Connection
*
- * @access public
- * @param resource
* @return void
*/
- function _close($conn_id)
+ protected function _close()
{
- @pg_close($conn_id);
+ pg_close($this->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 d9997a433..cdbff4c4b 100644
--- a/system/database/drivers/postgre/postgre_forge.php
+++ b/system/database/drivers/postgre/postgre_forge.php
@@ -1,299 +1,205 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP
*
- * @package CodeIgniter
- * @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc.
- * @license http://codeigniter.com/user_guide/license.html
- * @link http://codeigniter.com
- * @since Version 1.0
+ * This content is released under the MIT License (MIT)
+ *
+ * Copyright (c) 2014 - 2017, British Columbia Institute of Technology
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
+ * @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/)
+ * @license http://opensource.org/licenses/MIT MIT License
+ * @link https://codeigniter.com
+ * @since Version 1.3.0
* @filesource
*/
-
-// ------------------------------------------------------------------------
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Postgre Forge Class
*
+ * @package CodeIgniter
+ * @subpackage Drivers
* @category Database
- * @author ExpressionEngine Dev Team
- * @link http://codeigniter.com/user_guide/database/
+ * @author EllisLab Dev Team
+ * @link https://codeigniter.com/user_guide/database/
*/
class CI_DB_postgre_forge extends CI_DB_forge {
/**
- * Create database
+ * UNSIGNED support
*
- * @access private
- * @param string the database name
- * @return bool
+ * @var array
*/
- function _create_database($name)
- {
- return "CREATE DATABASE ".$name;
- }
+ protected $_unsigned = array(
+ 'INT2' => 'INTEGER',
+ 'SMALLINT' => 'INTEGER',
+ 'INT' => 'BIGINT',
+ 'INT4' => 'BIGINT',
+ 'INTEGER' => 'BIGINT',
+ 'INT8' => 'NUMERIC',
+ 'BIGINT' => 'NUMERIC',
+ 'REAL' => 'DOUBLE PRECISION',
+ 'FLOAT' => 'DOUBLE PRECISION'
+ );
+
+ /**
+ * NULL value representation in CREATE/ALTER TABLE statements
+ *
+ * @var string
+ */
+ protected $_null = 'NULL';
// --------------------------------------------------------------------
/**
- * Drop database
+ * Class constructor
*
- * @access private
- * @param string the database name
- * @return bool
+ * @param object &$db Database object
+ * @return void
*/
- function _drop_database($name)
+ public function __construct(&$db)
{
- return "DROP DATABASE ".$name;
+ parent::__construct($db);
+
+ if (version_compare($this->db->version(), '9.0', '>'))
+ {
+ $this->create_table_if = 'CREATE TABLE IF NOT EXISTS';
+ }
}
// --------------------------------------------------------------------
/**
- * Create Table
+ * ALTER TABLE
*
- * @access private
- * @param string the table name
- * @param array the fields
- * @param mixed primary key(s)
- * @param mixed key(s)
- * @param boolean should 'IF NOT EXISTS' be added to the SQL
- * @return bool
+ * @param string $alter_type ALTER type
+ * @param string $table Table name
+ * @param mixed $field Column definition
+ * @return string|string[]
*/
- function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
- {
- $sql = 'CREATE TABLE ';
-
- if ($if_not_exists === TRUE)
+ protected function _alter_table($alter_type, $table, $field)
+ {
+ if (in_array($alter_type, array('DROP', 'ADD'), TRUE))
{
- if ($this->db->table_exists($table))
- {
- return "SELECT * FROM $table"; // Needs to return innocous but valid SQL statement
- }
+ return parent::_alter_table($alter_type, $table, $field);
}
- $sql .= $this->db->_escape_identifiers($table)." (";
- $current_field_count = 0;
-
- foreach ($fields as $field=>$attributes)
+ $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
+ $sqls = array();
+ for ($i = 0, $c = count($field); $i < $c; $i++)
{
- // 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))
+ if ($field[$i]['_literal'] !== FALSE)
{
- $sql .= "\n\t$attributes";
+ return FALSE;
}
- else
- {
- $attributes = array_change_key_case($attributes, CASE_UPPER);
-
- $sql .= "\n\t".$this->db->_protect_identifiers($field);
-
- $is_unsigned = (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE);
- // Convert datatypes to be PostgreSQL-compatible
- switch (strtoupper($attributes['TYPE']))
- {
- 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 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 .= ' '.$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))
- {
- $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
- }
-
- if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)
- {
- $sql .= ' NULL';
- }
- else
- {
- $sql .= ' NOT NULL';
- }
-
- // Added new attribute to create unqite fields. Also works with MySQL
- if (array_key_exists('UNIQUE', $attributes) && $attributes['UNIQUE'] === TRUE)
- {
- $sql .= ' UNIQUE';
- }
+ if (version_compare($this->db->version(), '8', '>=') && isset($field[$i]['type']))
+ {
+ $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
+ .' TYPE '.$field[$i]['type'].$field[$i]['length'];
}
- // don't add a comma on the end of the last field
- if (++$current_field_count < count($fields))
+ if ( ! empty($field[$i]['default']))
{
- $sql .= ',';
+ $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
+ .' SET DEFAULT '.$field[$i]['default'];
}
- }
- if (count($primary_keys) > 0)
- {
- // Something seems to break when passing an array to _protect_identifiers()
- foreach ($primary_keys as $index => $key)
+ if (isset($field[$i]['null']))
{
- $primary_keys[$index] = $this->db->_protect_identifiers($key);
+ $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
+ .($field[$i]['null'] === TRUE ? ' DROP NOT NULL' : ' SET NOT NULL');
}
- $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";
- }
-
- $sql .= "\n);";
-
- if (is_array($keys) && count($keys) > 0)
- {
- foreach ($keys as $key)
+ if ( ! empty($field[$i]['new_name']))
{
- if (is_array($key))
- {
- $key = $this->db->_protect_identifiers($key);
- }
- else
- {
- $key = array($this->db->_protect_identifiers($key));
- }
+ $sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
+ .' TO '.$this->db->escape_identifiers($field[$i]['new_name']);
+ }
- foreach ($key as $field)
- {
- $sql .= "CREATE INDEX " . $table . "_" . str_replace(array('"', "'"), '', $field) . "_index ON $table ($field); ";
- }
+ if ( ! empty($field[$i]['comment']))
+ {
+ $sqls[] = 'COMMENT ON COLUMN '
+ .$this->db->escape_identifiers($table).'.'.$this->db->escape_identifiers($field[$i]['name'])
+ .' IS '.$field[$i]['comment'];
}
}
- return $sql;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Drop Table
- *
- * @access private
- * @return bool
- */
- function _drop_table($table)
- {
- return "DROP TABLE IF EXISTS ".$this->db->_escape_identifiers($table)." CASCADE";
- }
+ return $sqls;
+ }
// --------------------------------------------------------------------
/**
- * Alter table query
+ * Field attribute TYPE
*
- * Generates a platform-specific query so that a table can be altered
- * Called by add_column(), drop_column(), and column_alter(),
+ * Performs a data type mapping between different databases.
*
- * @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
+ * @param array &$attributes
+ * @return void
*/
- function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
+ protected function _attr_type(&$attributes)
{
- $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')
+ // Reset field lengths for data types that don't support it
+ if (isset($attributes['CONSTRAINT']) && stripos($attributes['TYPE'], 'int') !== FALSE)
{
- return $sql;
+ $attributes['CONSTRAINT'] = NULL;
}
- $sql .= " $column_definition";
-
- if ($default_value != '')
- {
- $sql .= " DEFAULT \"$default_value\"";
- }
-
- if ($null === NULL)
- {
- $sql .= ' NULL';
- }
- else
- {
- $sql .= ' NOT NULL';
- }
-
- if ($after_field != '')
+ switch (strtoupper($attributes['TYPE']))
{
- $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
+ case 'TINYINT':
+ $attributes['TYPE'] = 'SMALLINT';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ case 'MEDIUMINT':
+ $attributes['TYPE'] = 'INTEGER';
+ $attributes['UNSIGNED'] = FALSE;
+ return;
+ default: return;
}
-
- return $sql;
-
}
// --------------------------------------------------------------------
/**
- * Rename a table
- *
- * Generates a platform-specific query so that a table can be renamed
+ * Field attribute AUTO_INCREMENT
*
- * @access private
- * @param string the old table name
- * @param string the new table name
- * @return string
+ * @param array &$attributes
+ * @param array &$field
+ * @return void
*/
- function _rename_table($table_name, $new_table_name)
+ protected function _attr_auto_increment(&$attributes, &$field)
{
- $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name);
- return $sql;
+ if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
+ {
+ $field['type'] = ($field['type'] === 'NUMERIC')
+ ? 'BIGSERIAL'
+ : 'SERIAL';
+ }
}
-
}
-
-/* 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 8655f7aee..57864a7f3 100644
--- a/system/database/drivers/postgre/postgre_result.php
+++ b/system/database/drivers/postgre/postgre_result.php
@@ -1,40 +1,65 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP
*
- * @package CodeIgniter
- * @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc.
- * @license http://codeigniter.com/user_guide/license.html
- * @link http://codeigniter.com
- * @since Version 1.0
+ * This content is released under the MIT License (MIT)
+ *
+ * Copyright (c) 2014 - 2017, British Columbia Institute of Technology
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
+ * @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/)
+ * @license http://opensource.org/licenses/MIT MIT License
+ * @link https://codeigniter.com
+ * @since Version 1.3.0
* @filesource
*/
-
-// ------------------------------------------------------------------------
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Postgres Result Class
*
* This class extends the parent result class: CI_DB_result
*
+ * @package CodeIgniter
+ * @subpackage Drivers
* @category Database
- * @author ExpressionEngine Dev Team
- * @link http://codeigniter.com/user_guide/database/
+ * @author EllisLab Dev Team
+ * @link https://codeigniter.com/user_guide/database/
*/
class CI_DB_postgre_result extends CI_DB_result {
/**
* Number of rows in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
- function num_rows()
+ public function num_rows()
{
- return @pg_num_rows($this->result_id);
+ return is_int($this->num_rows)
+ ? $this->num_rows
+ : $this->num_rows = pg_num_rows($this->result_id);
}
// --------------------------------------------------------------------
@@ -42,12 +67,11 @@ class CI_DB_postgre_result extends CI_DB_result {
/**
* Number of fields in the result set
*
- * @access public
- * @return integer
+ * @return int
*/
- function num_fields()
+ public function num_fields()
{
- return @pg_num_fields($this->result_id);
+ return pg_num_fields($this->result_id);
}
// --------------------------------------------------------------------
@@ -57,13 +81,12 @@ class CI_DB_postgre_result extends CI_DB_result {
*
* Generates an array of column names
*
- * @access public
* @return array
*/
- function list_fields()
+ public function list_fields()
{
$field_names = array();
- for ($i = 0; $i < $this->num_fields(); $i++)
+ for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
{
$field_names[] = pg_field_name($this->result_id, $i);
}
@@ -78,22 +101,17 @@ class CI_DB_postgre_result extends CI_DB_result {
*
* Generates an array of objects containing field meta-data
*
- * @access public
* @return array
*/
- function field_data()
+ public function field_data()
{
$retval = array();
- for ($i = 0; $i < $this->num_fields(); $i++)
+ for ($i = 0, $c = $this->num_fields(); $i < $c; $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;
+ $retval[$i] = new stdClass();
+ $retval[$i]->name = pg_field_name($this->result_id, $i);
+ $retval[$i]->type = pg_field_type($this->result_id, $i);
+ $retval[$i]->max_length = pg_field_size($this->result_id, $i);
}
return $retval;
@@ -104,9 +122,9 @@ class CI_DB_postgre_result extends CI_DB_result {
/**
* Free the result
*
- * @return null
+ * @return void
*/
- function free_result()
+ public function free_result()
{
if (is_resource($this->result_id))
{
@@ -120,14 +138,14 @@ class CI_DB_postgre_result extends CI_DB_result {
/**
* Data Seek
*
- * Moves the internal pointer to the desired offset. We call
+ * Moves the internal pointer to the desired offset. We call
* this internally before fetching results to make sure the
- * result set starts at zero
+ * result set starts at zero.
*
- * @access private
- * @return array
+ * @param int $n
+ * @return bool
*/
- function _data_seek($n = 0)
+ public function data_seek($n = 0)
{
return pg_result_seek($this->result_id, $n);
}
@@ -139,10 +157,9 @@ class CI_DB_postgre_result extends CI_DB_result {
*
* Returns the result set as an array
*
- * @access private
* @return array
*/
- function _fetch_assoc()
+ protected function _fetch_assoc()
{
return pg_fetch_assoc($this->result_id);
}
@@ -154,16 +171,12 @@ class CI_DB_postgre_result extends CI_DB_result {
*
* Returns the result set as an object
*
- * @access private
+ * @param string $class_name
* @return object
*/
- function _fetch_object()
+ protected function _fetch_object($class_name = 'stdClass')
{
- return pg_fetch_object($this->result_id);
+ return pg_fetch_object($this->result_id, NULL, $class_name);
}
}
-
-
-/* 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 d7af1a7ef..5ca358da5 100644
--- a/system/database/drivers/postgre/postgre_utility.php
+++ b/system/database/drivers/postgre/postgre_utility.php
@@ -1,88 +1,78 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP
*
- * @package CodeIgniter
- * @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc.
- * @license http://codeigniter.com/user_guide/license.html
- * @link http://codeigniter.com
- * @since Version 1.0
+ * This content is released under the MIT License (MIT)
+ *
+ * Copyright (c) 2014 - 2017, British Columbia Institute of Technology
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
+ * @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/)
+ * @license http://opensource.org/licenses/MIT MIT License
+ * @link https://codeigniter.com
+ * @since Version 1.3.0
* @filesource
*/
-
-// ------------------------------------------------------------------------
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Postgre Utility Class
*
+ * @package CodeIgniter
+ * @subpackage Drivers
* @category Database
- * @author ExpressionEngine Dev Team
- * @link http://codeigniter.com/user_guide/database/
+ * @author EllisLab Dev Team
+ * @link https://codeigniter.com/user_guide/database/
*/
class CI_DB_postgre_utility extends CI_DB_utility {
/**
- * List databases
- *
- * @access private
- * @return bool
- */
- function _list_databases()
- {
- return "SELECT datname FROM pg_database";
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Optimize table query
- *
- * Is table optimization supported in Postgre?
+ * List databases statement
*
- * @access private
- * @param string the table name
- * @return object
+ * @var string
*/
- function _optimize_table($table)
- {
- return FALSE;
- }
-
- // --------------------------------------------------------------------
+ protected $_list_databases = 'SELECT datname FROM pg_database';
/**
- * Repair table query
- *
- * Are table repairs supported in Postgre?
+ * OPTIMIZE TABLE statement
*
- * @access private
- * @param string the table name
- * @return object
+ * @var string
*/
- function _repair_table($table)
- {
- return FALSE;
- }
+ protected $_optimize_table = 'REINDEX TABLE %s';
// --------------------------------------------------------------------
/**
- * Postgre Export
+ * Export
*
- * @access private
- * @param array Preferences
+ * @param array $params Preferences
* @return mixed
*/
- function _backup($params = array())
+ protected function _backup($params = array())
{
// Currently unsupported
- return $this->db->display_error('db_unsuported_feature');
+ return $this->db->display_error('db_unsupported_feature');
}
}
-
-
-/* End of file postgre_utility.php */
-/* Location: ./system/database/drivers/postgre/postgre_utility.php */ \ No newline at end of file