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/cubrid/cubrid_forge.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/database/drivers/cubrid/cubrid_forge.php') diff --git a/system/database/drivers/cubrid/cubrid_forge.php b/system/database/drivers/cubrid/cubrid_forge.php index d328aa241..a7b4efd9a 100644 --- a/system/database/drivers/cubrid/cubrid_forge.php +++ b/system/database/drivers/cubrid/cubrid_forge.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/cubrid/cubrid_forge.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'system/database/drivers/cubrid/cubrid_forge.php') diff --git a/system/database/drivers/cubrid/cubrid_forge.php b/system/database/drivers/cubrid/cubrid_forge.php index a7b4efd9a..33d502137 100644 --- a/system/database/drivers/cubrid/cubrid_forge.php +++ b/system/database/drivers/cubrid/cubrid_forge.php @@ -35,13 +35,26 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ class CI_DB_cubrid_forge extends CI_DB_forge { + /** + * CREATE DATABASE statement + * + * @var string + */ protected $_create_database = FALSE; + + // -------------------------------------------------------------------- + + /** + * DROP DATABASE statement + * + * @var string + */ protected $_drop_database = FALSE; /** * Process Fields * - * @param mixed the fields + * @param mixed $fields * @return string */ protected function _process_fields($fields) -- 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/cubrid/cubrid_forge.php | 214 +++++++++--------------- 1 file changed, 78 insertions(+), 136 deletions(-) (limited to 'system/database/drivers/cubrid/cubrid_forge.php') diff --git a/system/database/drivers/cubrid/cubrid_forge.php b/system/database/drivers/cubrid/cubrid_forge.php index 33d502137..e3f8bc334 100644 --- a/system/database/drivers/cubrid/cubrid_forge.php +++ b/system/database/drivers/cubrid/cubrid_forge.php @@ -42,8 +42,6 @@ class CI_DB_cubrid_forge extends CI_DB_forge { */ protected $_create_database = FALSE; - // -------------------------------------------------------------------- - /** * DROP DATABASE statement * @@ -52,177 +50,121 @@ class CI_DB_cubrid_forge extends CI_DB_forge { protected $_drop_database = FALSE; /** - * Process Fields + * CREATE TABLE IF statement * - * @param mixed $fields - * @return string + * @var string + */ + protected $_create_table_if = FALSE; + + /** + * UNSIGNED support + * + * @var array */ - protected function _process_fields($fields) + protected $_unsigned = array( + 'SHORT' => 'INTEGER', + 'SMALLINT' => 'INTEGER', + 'INT' => 'BIGINT', + 'INTEGER' => 'BIGINT', + 'BIGINT' => 'NUMERIC', + 'FLOAT' => 'DOUBLE', + 'REAL' => 'DOUBLE' + ); + + // -------------------------------------------------------------------- + + /** + * 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) { - $current_field_count = 0; - $sql = ''; + if (in_array($alter_type, array('DROP', 'ADD'), TRUE)) + { + return parent::_alter_table($alter_type, $table, $field); + } - 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; + $sqls[] = $sql.' CHANGE '.$field[$i]['_literal']; } else { - $attributes = array_change_key_case($attributes, CASE_UPPER); - - $sql .= "\n\t".$this->db->escape_identifiers($field); - - empty($attributes['NAME']) OR $sql .= ' '.$this->db->escape_identifiers($attributes['NAME']).' '; - - if ( ! empty($attributes['TYPE'])) - { - $sql .= ' '.$attributes['TYPE']; - - if ( ! empty($attributes['CONSTRAINT'])) - { - switch (strtolower($attributes['TYPE'])) - { - case 'decimal': - case 'float': - case 'numeric': - $sql .= '('.implode(',', $attributes['CONSTRAINT']).')'; - break; - case 'enum': - // Will be supported in the future as part a part of - // MySQL compatibility features. - break; - case 'set': - $sql .= '("'.implode('","', $attributes['CONSTRAINT']).'")'; - break; - default: - $sql .= '('.$attributes['CONSTRAINT'].')'; - } - } - } - - /* As of version 8.4.1 CUBRID does not support UNSIGNED INTEGER data type. - * Will be supported in the next release as a part of MySQL Compatibility. - * - if (isset($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE) - { - $sql .= ' UNSIGNED'; - } - */ - - if (isset($attributes['DEFAULT'])) - { - $sql .= " DEFAULT '".$attributes['DEFAULT']."'"; - } - - $sql .= ( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE) - ? ' NULL' : ' NOT NULL'; - - if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) - { - $sql .= ' AUTO_INCREMENT'; - } - - if ( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE) + $sqls[] = $sql.' CHANGE '.$this->_process_column($field[$i]); + if ( ! empty($field[$i]['new_name'])) { - $sql .= ' UNIQUE'; + $sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' AS '.$this->db->escape_identifiers($field[$i]['name']); } } - - // don't add a comma on the end of the last field - if (++$current_field_count < count($fields)) - { - $sql .= ','; - } } - return $sql; + return $sqls; } // -------------------------------------------------------------------- /** - * Create Table + * Field attribute TYPE * - * @param string the table name - * @param mixed 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 '; - - /* As of version 8.4.1 CUBRID does not support this SQL syntax. - if ($if_not_exists === TRUE) + switch (strtoupper($attributes['TYPE'])) { - $sql .= 'IF NOT EXISTS '; + case 'TINYINT': + $attributes['TYPE'] = 'SMALLINT'; + $attributes['UNSIGNED'] = FALSE; + return; + case 'MEDIUMINT': + $attributes['TYPE'] = 'INTEGER'; + $attributes['UNSIGNED'] = FALSE; + return; + default: return; } - */ - - $sql .= $this->db->escape_identifiers($table).' ('.$this->_process_fields($fields); - - // If there is a PK defined - if (count($primary_keys) > 0) - { - $key_name = $this->db->escape_identifiers('pk_'.$table.'_'.implode('_', $primary_keys)); - $sql .= ",\n\tCONSTRAINT ".$key_name.' PRIMARY KEY('.implode(', ', $this->db->escape_identifiers($primary_keys)).')'; - } - - if (is_array($keys) && count($keys) > 0) - { - foreach ($keys as $key) - { - if (is_array($key)) - { - $key_name = $this->db->escape_identifiers('idx_'.$table.implode('_', $key)); - $key = $this->db->escape_identifiers($key); - } - else - { - $key_name = $this->db->escape_identifiers('idx_'.$table.$key); - $key = array($key_name); - } - - $sql .= ",\n\tKEY ".$key_name.' ('.implode(', ', $key).')'; - } - } - - return $sql."\n);"; } // -------------------------------------------------------------------- /** - * Alter table query - * - * Generates a platform-specific query so that a table can be altered - * Called by add_column(), drop_column(), and column_alter(), + * Process indexes * - * @param string the ALTER type (ADD, DROP, CHANGE) - * @param string the column name - * @param array fields - * @param string the field after which we should add the new field + * @param string $table (ignored) * @return string */ - protected function _alter_table($alter_type, $table, $fields, $after_field = '') + protected function _process_indexes($table = NULL) { - $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' '; + $sql = ''; - // DROP has everything it needs now. - if ($alter_type === 'DROP') + for ($i = 0, $c = count($this->keys); $i < $c; $i++) { - return $sql.$this->db->escape_identifiers($fields); + if ( ! isset($this->fields[$this->keys[$i]])) + { + unset($this->keys[$i]); + continue; + } + + is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]); + + $sql .= ",\n\tKEY ".$this->db->escape_identifiers(implode('_', $this->keys[$i])) + .' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).')'; } - return $sql.$this->_process_fields($fields) - .($after_field !== '' ? ' AFTER '.$this->db->escape_identifiers($after_field) : ''); + $this->keys = array(); + + return $sql; } } -- cgit v1.2.3-24-g4f1b From b0a97c100f5e7edc5e21ec7d07f768cd3b5618da Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 11 Nov 2012 13:58:53 +0200 Subject: Fix DBForge index creation on MySQL and CUBRID --- system/database/drivers/cubrid/cubrid_forge.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'system/database/drivers/cubrid/cubrid_forge.php') diff --git a/system/database/drivers/cubrid/cubrid_forge.php b/system/database/drivers/cubrid/cubrid_forge.php index e3f8bc334..86a41e57b 100644 --- a/system/database/drivers/cubrid/cubrid_forge.php +++ b/system/database/drivers/cubrid/cubrid_forge.php @@ -42,6 +42,16 @@ class CI_DB_cubrid_forge extends CI_DB_forge { */ protected $_create_database = FALSE; + /** + * CREATE TABLE keys flag + * + * Whether table keys are created from within the + * CREATE TABLE statement. + * + * @var bool + */ + protected $_create_table_keys = TRUE; + /** * DROP DATABASE statement * -- cgit v1.2.3-24-g4f1b From b67277b8063b0e6aab051ce269194255ef83e808 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 12 Nov 2012 12:51:14 +0200 Subject: Bring back the AFTER clause for DB Forge add_column() (it was temporarily removed due to multiple inconsistencies with other drivers) This commit also fixes issue #1988. Also added support for the FIRST clause (again, MySQL and CUBRID only). --- system/database/drivers/cubrid/cubrid_forge.php | 29 +++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'system/database/drivers/cubrid/cubrid_forge.php') diff --git a/system/database/drivers/cubrid/cubrid_forge.php b/system/database/drivers/cubrid/cubrid_forge.php index 86a41e57b..05762ba5a 100644 --- a/system/database/drivers/cubrid/cubrid_forge.php +++ b/system/database/drivers/cubrid/cubrid_forge.php @@ -122,6 +122,35 @@ class CI_DB_cubrid_forge extends CI_DB_forge { // -------------------------------------------------------------------- + /** + * Process column + * + * @param array $field + * @return string + */ + protected function _process_column($field) + { + $extra_clause = isset($field['after']) + ? ' AFTER '.$this->db->escape_identifiers($field['after']) : ''; + + if (empty($extra_clause) && isset($field['first']) && $field['first'] === TRUE) + { + $extra_clause = ' FIRST'; + } + + return $this->db->escape_identifiers($field['name']) + .(empty($field['new_name']) ? '' : $this->db->escape_identifiers($field['new_name'])) + .' '.$field['type'].$field['length'] + .$field['unsigned'] + .$field['null'] + .$field['default'] + .$field['auto_increment'] + .$field['unique'] + .$extra_clause; + } + + // -------------------------------------------------------------------- + /** * Field attribute TYPE * -- cgit v1.2.3-24-g4f1b