From c5536aac5752054f7f76e448d58b86407d8f574e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Nov 2012 17:33:58 +0200 Subject: Manually apply PR #1594 (fixing phpdoc page-level generation/warnings) Also partially fixes issue #1295, fixes inconsistencies in some page-level docblocks and adds include checks in language files. --- system/database/drivers/postgre/postgre_driver.php | 3 ++- system/database/drivers/postgre/postgre_forge.php | 3 ++- system/database/drivers/postgre/postgre_result.php | 3 ++- system/database/drivers/postgre/postgre_utility.php | 3 ++- 4 files changed, 8 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 ca231f6f7..96ea5f4f9 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -1,4 +1,4 @@ - Date: Fri, 2 Nov 2012 02:04:59 +0200 Subject: [ci skip] DocBlocks for DB drivers' utility classes Partially fixes issue #1295. --- system/database/drivers/postgre/postgre_forge.php | 11 +++++++++-- system/database/drivers/postgre/postgre_utility.php | 17 +++++++++++++++-- 2 files changed, 24 insertions(+), 4 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 aac82c1e5..b08fa5177 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -35,13 +35,20 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ class CI_DB_postgre_forge extends CI_DB_forge { + /** + * DROP TABLE statement + * + * @var string + */ protected $_drop_table = 'DROP TABLE IF EXISTS %s CASCADE'; + // -------------------------------------------------------------------- + /** * Process Fields * * @param mixed $fields - * @param array $primary_keys = array() + * @param array $primary_keys * @return string */ protected function _process_fields($fields, $primary_keys = array()) @@ -195,7 +202,7 @@ class CI_DB_postgre_forge extends CI_DB_forge { * @param string $alter_type the ALTER type (ADD, DROP, CHANGE) * @param string $table the table name * @param string $fields the column definition - * @param string $after_field = '' + * @param string $after_field * @return string */ protected function _alter_table($alter_type, $table, $fields, $after_field = '') diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php index 96cd90e92..bae1c6704 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -35,13 +35,26 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ class CI_DB_postgre_utility extends CI_DB_utility { + /** + * List databases statement + * + * @var string + */ protected $_list_databases = 'SELECT datname FROM pg_database'; + + /** + * OPTIMIZE TABLE statement + * + * @var string + */ protected $_optimize_table = 'REINDEX TABLE %s'; + // -------------------------------------------------------------------- + /** - * Postgre Export + * Export * - * @param array Preferences + * @param array $params Preferences * @return mixed */ protected function _backup($params = array()) -- cgit v1.2.3-24-g4f1b From 8463b919e17d9bd7fa35821d547c4acc229520f7 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 2 Nov 2012 02:16:28 +0200 Subject: [ci skip] DocBlocks for DB drivers' result classes Partially fixes issue #1295. --- system/database/drivers/postgre/postgre_result.php | 6 +++--- 1 file changed, 3 insertions(+), 3 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 78a8a9c68..3f73f84c7 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -130,9 +130,9 @@ class CI_DB_postgre_result extends CI_DB_result { * * 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. * - * @param int $n = 0 + * @param int $n * @return bool */ protected function _data_seek($n = 0) @@ -161,7 +161,7 @@ class CI_DB_postgre_result extends CI_DB_result { * * Returns the result set as an object * - * @param string + * @param string $class_name * @return object */ protected function _fetch_object($class_name = 'stdClass') -- cgit v1.2.3-24-g4f1b From a24e52e1c0136db0c1949e73255b4e9bf114b437 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 2 Nov 2012 03:54:12 +0200 Subject: [ci skip] DocBlocks for DB drivers' driver classes Partially fixes issue #1295. --- system/database/drivers/postgre/postgre_driver.php | 56 +++++++++++++--------- 1 file changed, 34 insertions(+), 22 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 96ea5f4f9..028dc1996 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -41,12 +41,13 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ class CI_DB_postgre_driver extends CI_DB { + /** + * Database driver + * + * @var string + */ public $dbdriver = 'postgre'; - protected $_escape_char = '"'; - - protected $_random_keyword = ' RANDOM()'; // database specific random keyword - /** * Database schema * @@ -54,8 +55,19 @@ class CI_DB_postgre_driver extends CI_DB { */ public $schema = 'public'; + // -------------------------------------------------------------------- + /** - * Constructor + * ORDER BY random keyword + * + * @var string + */ + protected $_random_keyword = ' RANDOM()'; // database specific random keyword + + // -------------------------------------------------------------------- + + /** + * Class constructor * * Creates a DSN string to be used for db_connect() and db_pconnect() * @@ -171,7 +183,7 @@ class CI_DB_postgre_driver extends CI_DB { /** * Set client character set * - * @param string + * @param string $charset * @return bool */ protected function _db_set_charset($charset) @@ -213,7 +225,7 @@ class CI_DB_postgre_driver extends CI_DB { /** * Execute the query * - * @param string an SQL query + * @param string $sql an SQL query * @return resource */ protected function _execute($sql) @@ -226,7 +238,7 @@ class CI_DB_postgre_driver extends CI_DB { /** * Begin Transaction * - * @param bool + * @param bool $test_mode * @return bool */ public function trans_begin($test_mode = FALSE) @@ -286,8 +298,8 @@ class CI_DB_postgre_driver extends CI_DB { /** * Escape String * - * @param string - * @param bool whether or not the string will be used in a LIKE condition + * @param string $str + * @param bool $like Whether or not the string will be used in a LIKE condition * @return string */ public function escape_str($str, $like = FALSE) @@ -323,7 +335,7 @@ class CI_DB_postgre_driver extends CI_DB { * Escapes data based on type * Sets boolean and null types * - * @param string + * @param string $str * @return mixed */ public function escape($str) @@ -401,7 +413,7 @@ class CI_DB_postgre_driver extends CI_DB { * * Generates a platform-specific query string so that the table names can be fetched * - * @param bool $prefix_limit = FALSE + * @param bool $prefix_limit * @return string */ protected function _list_tables($prefix_limit = FALSE) @@ -425,7 +437,7 @@ class CI_DB_postgre_driver extends CI_DB { * * Generates a platform-specific query string so that the column names can be fetched * - * @param string the table name + * @param string $table * @return string */ protected function _list_columns($table = '') @@ -440,7 +452,7 @@ class CI_DB_postgre_driver extends CI_DB { * * Generates a platform-specific query so that the column data can be retrieved * - * @param string the table name + * @param string $table * @return string */ protected function _field_data($table) @@ -470,8 +482,8 @@ class CI_DB_postgre_driver extends CI_DB { * * Generates a platform-specific update string from the supplied data * - * @param string the table name - * @param array the update data + * @param string $table + * @param array $values * @return string */ protected function _update($table, $values) @@ -488,9 +500,9 @@ class CI_DB_postgre_driver extends CI_DB { * * Generates a platform-specific batch update string from the supplied data * - * @param string the table name - * @param array the update data - * @param string the where key + * @param string $table Table name + * @param array $values Update data + * @param string $index WHERE key * @return string */ protected function _update_batch($table, $values, $index) @@ -529,7 +541,7 @@ class CI_DB_postgre_driver extends CI_DB { * * Generates a platform-specific delete string from the supplied data * - * @param string the table name + * @param string $table * @return string */ protected function _delete($table) @@ -541,11 +553,11 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Limit string + * LIMIT * * Generates a platform-specific LIMIT clause * - * @param string the sql query string + * @param string $sql SQL Query * @return string */ protected function _limit($sql) -- cgit v1.2.3-24-g4f1b From 2b73037e450859e85fb468ad7499a26882a67292 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 5 Nov 2012 17:01:11 +0200 Subject: Fix DB drivers version() implementations that don't execute a query Fails if called prior to the DB connection initialization. --- 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 028dc1996..40f21b1e8 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -204,8 +204,12 @@ class CI_DB_postgre_driver extends CI_DB { { return $this->data_cache['version']; } + elseif ( ! $this->conn_id) + { + $this->initialize(); + } - if (($pg_version = pg_version($this->conn_id)) === FALSE) + if ( ! $this->conn_id OR ($pg_version = pg_version($this->conn_id)) === FALSE) { return FALSE; } -- cgit v1.2.3-24-g4f1b From a287a34c215903d3452023d74149eb5880125715 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 5 Nov 2012 23:19:59 +0200 Subject: Refactored DB Forge - PDO subdrivers are isolated from each other now. - Added compatibility for pretty much all of the features, for every DB platform. - Unified the way that stuff works in general. - Fixes issue #1005. --- system/database/drivers/postgre/postgre_forge.php | 245 +++++++++------------- 1 file changed, 103 insertions(+), 142 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 b08fa5177..ad26763a4 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -36,188 +36,149 @@ defined('BASEPATH') OR exit('No direct script access allowed'); class CI_DB_postgre_forge extends CI_DB_forge { /** - * DROP TABLE statement + * UNSIGNED support + * + * @var array + */ + 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 $_drop_table = 'DROP TABLE IF EXISTS %s CASCADE'; + protected $_null = 'NULL'; // -------------------------------------------------------------------- /** - * Process Fields + * Class constructor * - * @param mixed $fields - * @param array $primary_keys - * @return string + * @return void */ - protected function _process_fields($fields, $primary_keys = array()) + public function __construct() { - $sql = ''; - $current_field_count = 0; + parent::__construct(); - foreach ($fields as $field => $attributes) + if (version_compare($this->db->version(), '9.0', '>')) { - // 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)) + $this->create_table_if = 'CREATE TABLE IF NOT EXISTS'; + } + } + + // -------------------------------------------------------------------- + + /** + * ALTER TABLE + * + * @param string $alter_type ALTER type + * @param string $table Table name + * @param mixed $field Column definition + * @return string|string[] + */ + protected function _alter_table($alter_type, $table, $field) + { + if (in_array($alter_type, array('DROP', 'ADD'), TRUE)) + { + return parent::_alter_table($alter_type, $table, $field); + } + + $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table); + $sqls = array(); + for ($i = 0, $c = count($field), $sql .= $alter_type.' '; $i < $c; $i++) + { + if ($field[$i]['_literal'] !== FALSE) { - $sql .= "\n\t".$attributes; + return FALSE; } - else + + if (version_compare($this->db->version(), '8', '>=') && isset($field[$i]['type'])) { - $sql .= "\n\t".$this->db->escape_identifiers($field); - - $attributes = array_change_key_case($attributes, CASE_UPPER); - $is_unsigned = ( ! empty($attributes['UNSIGNED']) && $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; - default: - break; - } - - // If this is an auto-incrementing primary key, use the serial data type instead - $sql .= (in_array($field, $primary_keys) && ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) - ? ' SERIAL' : ' '.$attributes['TYPE']; - - // Modified to prevent constraints with integer data types - if ( ! empty($attributes['CONSTRAINT']) && strpos($attributes['TYPE'], 'INT') === FALSE) - { - $sql .= '('.$attributes['CONSTRAINT'].')'; - } - - if (isset($attributes['DEFAULT'])) - { - $sql .= " DEFAULT '".$attributes['DEFAULT']."'"; - } - - $sql .= ( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE) - ? ' NULL' : ' NOT NULL'; - - // Added new attribute to create unique fields. Also works with MySQL - if ( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE) - { - $sql .= ' UNIQUE'; - } + $sqls[] = $sql.' 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 '.$this->db->escape_identifiers($field[$i]['name']) + .' SET '.$field[$i]['default']; + } + + if (isset($field[$i]['null'])) + { + $sqls[] = $sql.' ALTER '.$this->db->escape_identifiers($field[$i]['name']) + .($field[$i]['null'] === TRUE ? ' DROP NOT NULL' : ' SET NOT NULL'); + } + + if ( ! empty($field[$i]['new_name'])) + { + $sqls[] = $sql.' RENAME '.$this->db->escape_identifiers($field[$i]['name']) + .' TO '.$this->db->escape_identifiers($field[$i]['new_name']); } } - return $sql; - } + return $sqls; + } // -------------------------------------------------------------------- /** - * Create Table + * Field attribute TYPE * - * @param string the table name - * @param array the fields - * @param mixed primary key(s) - * @param mixed key(s) - * @param bool should 'IF NOT EXISTS' be added to the SQL - * @return bool + * Performs a data type mapping between different databases. + * + * @param array &$attributes + * @return void */ - protected function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) + protected function _attr_type(&$attributes) { - $sql = 'CREATE TABLE '; - - // PostgreSQL doesn't support IF NOT EXISTS syntax so we check if table exists manually - if ($if_not_exists === TRUE && $this->db->table_exists($table)) + // Reset field lenghts for data types that don't support it + if (isset($attributes['CONSTRAINT']) && stripos($attributes['TYPE'], 'int') !== FALSE) { - return TRUE; + $attributes['CONSTRAINT'] = NULL; } - $sql .= $this->db->escape_identifiers($table).' ('.$this->_process_fields($fields, $primary_keys); - - if (count($primary_keys) > 0) + switch (strtoupper($attributes['TYPE'])) { - $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->db->escape_identifiers($primary_keys)).')'; - } - - $sql .= "\n);"; - - if (is_array($keys) && count($keys) > 0) - { - foreach ($keys as $key) - { - $key = is_array($key) - ? $this->db->escape_identifiers($key) - : array($this->db->escape_identifiers($key)); - - foreach ($key as $field) - { - $sql .= "\nCREATE INDEX ".$this->db->escape_identifiers($table.'_'.str_replace(array('"', "'"), '', $field).'_index') - .' ON '.$this->db->escape_identifiers($table).' ('.$this->db->escape_identifiers($field).');'; - } - } + case 'TINYINT': + $attributes['TYPE'] = 'SMALLINT'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'MEDIUMINT': + $attributes['TYPE'] = 'INTEGER'; + $attributes['UNSIGNED'] = FALSE; + return; + default: return; } - - return $sql; } // -------------------------------------------------------------------- /** - * Alter table query - * - * Generates a platform-specific query so that a table can be altered - * Called by add_column(), drop_column(), and column_alter(), + * Field attribute AUTO_INCREMENT * - * @param string $alter_type the ALTER type (ADD, DROP, CHANGE) - * @param string $table the table name - * @param string $fields the column definition - * @param string $after_field - * @return string + * @param array &$attributes + * @param array &$field + * @return void */ - protected function _alter_table($alter_type, $table, $fields, $after_field = '') - { - $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' '; - - // DROP has everything it needs now. - if ($alter_type === 'DROP') - { - return $sql.$this->db->escape_identifiers($fields); - } - - return $sql.$this->_process_fields($fields) - .($after_field !== '' ? ' AFTER '.$this->db->escape_identifiers($after_field) : ''); - } + protected function _attr_auto_increment(&$attributes, &$field) + { + if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) + { + $field['type'] = ($field['type'] === 'NUMERIC') + ? 'BIGSERIAL' + : 'SERIAL'; + } + } } -- cgit v1.2.3-24-g4f1b From eaa60c71082c1e49f8a48d633347c98b68a387c0 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 6 Nov 2012 01:11:22 +0200 Subject: Added possibility to pass custom database objects to DB Forge and DB Utilities Also, their property is no longer public and the utility class no longer extends CI_DB_forge. --- system/database/drivers/postgre/postgre_forge.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'system/database/drivers/postgre') diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index ad26763a4..425622fac 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -64,11 +64,12 @@ class CI_DB_postgre_forge extends CI_DB_forge { /** * Class constructor * + * @param object &$db Database object * @return void */ - public function __construct() + public function __construct(&$db) { - parent::__construct(); + parent::__construct($db); if (version_compare($this->db->version(), '9.0', '>')) { -- cgit v1.2.3-24-g4f1b From 8d3afde93f9ff7f461095d5b9147b662610c045b Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 6 Nov 2012 12:53:47 +0200 Subject: Fix a lang key typo --- 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 bae1c6704..d3b2b9cdc 100644 --- a/system/database/drivers/postgre/postgre_utility.php +++ b/system/database/drivers/postgre/postgre_utility.php @@ -60,7 +60,7 @@ class CI_DB_postgre_utility extends CI_DB_utility { protected function _backup($params = array()) { // Currently unsupported - return $this->db->display_error('db_unsuported_feature'); + return $this->db->display_error('db_unsupported_feature'); } } -- cgit v1.2.3-24-g4f1b