summaryrefslogtreecommitdiffstats
path: root/system/database/drivers/cubrid/cubrid_forge.php
diff options
context:
space:
mode:
Diffstat (limited to 'system/database/drivers/cubrid/cubrid_forge.php')
-rw-r--r--system/database/drivers/cubrid/cubrid_forge.php110
1 files changed, 39 insertions, 71 deletions
diff --git a/system/database/drivers/cubrid/cubrid_forge.php b/system/database/drivers/cubrid/cubrid_forge.php
index bbda484c4..f0d9804cc 100644
--- a/system/database/drivers/cubrid/cubrid_forge.php
+++ b/system/database/drivers/cubrid/cubrid_forge.php
@@ -21,7 +21,7 @@
* @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
- * @since Version 1.0
+ * @since Version 2.1
* @filesource
*/
@@ -42,8 +42,8 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
*/
public function _create_database($name)
{
- // CUBRID does not allow to create a database in SQL. The GUI tools
- // have to be used for this purpose.
+ // CUBRID does not allow to create a database in SQL. GUI or
+ // command line tools have to be used for this purpose.
return FALSE;
}
@@ -57,8 +57,8 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
*/
public function _drop_database($name)
{
- // CUBRID does not allow to drop a database in SQL. The GUI tools
- // have to be used for this purpose.
+ // CUBRID does not allow to drop a database in SQL. GUI or
+ // command line tools have to be used for this purpose.
return FALSE;
}
@@ -82,24 +82,19 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
// entered the field information, so we'll simply add it to the list
if (is_numeric($field))
{
- $sql .= "\n\t$attributes";
+ $sql .= "\n\t".$attributes;
}
else
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
+ $sql .= "\n\t".$this->db->protect_identifiers($field)
+ .( ! empty($attributes['NAME']) ? ' '.$this->db->protect_identifiers($attributes['NAME']).' ' : '');
- $sql .= "\n\t\"".$this->db->protect_identifiers($field).'"';
-
- if (array_key_exists('NAME', $attributes))
- {
- $sql .= ' '.$this->db->protect_identifiers($attributes['NAME']).' ';
- }
-
- if (array_key_exists('TYPE', $attributes))
+ if ( ! empty($attributes['TYPE']))
{
$sql .= ' '.$attributes['TYPE'];
- if (array_key_exists('CONSTRAINT', $attributes))
+ if ( ! empty($attributes['CONSTRAINT']))
{
switch ($attributes['TYPE'])
{
@@ -108,9 +103,10 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
case 'numeric':
$sql .= '('.implode(',', $attributes['CONSTRAINT']).')';
break;
- case 'enum': // As of version 8.4.0 CUBRID does not support
- // enum data type.
- 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;
@@ -120,36 +116,19 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
}
}
- if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
- {
- //$sql .= ' UNSIGNED';
- // As of version 8.4.0 CUBRID does not support UNSIGNED INTEGER data type.
- // Will be supported in the next release as a part of MySQL Compatibility.
- }
-
- 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)
+ /* 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 .= ' AUTO_INCREMENT';
+ $sql .= ' UNSIGNED';
}
+ */
- if (array_key_exists('UNIQUE', $attributes) && $attributes['UNIQUE'] === TRUE)
- {
- $sql .= ' UNIQUE';
- }
+ $sql .= (isset($attributes['DEFAULT']) ? " DEFAULT '".$attributes['DEFAULT']."'" : '')
+ .(( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL')
+ .(( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : '')
+ .(( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE) ? ' UNIQUE' : '');
}
// don't add a comma on the end of the last field
@@ -178,23 +157,20 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
{
$sql = 'CREATE TABLE ';
+ /* As of version 8.4.1 CUBRID does not support this SQL syntax.
if ($if_not_exists === TRUE)
{
- //$sql .= 'IF NOT EXISTS ';
- // As of version 8.4.0 CUBRID does not support this SQL syntax.
+ $sql .= 'IF NOT EXISTS ';
}
+ */
- $sql .= $this->db->_escape_identifiers($table)." (";
-
- $sql .= $this->_process_fields($fields);
+ $sql .= $this->db->protect_identifiers($table).' ('.$this->_process_fields($fields);
// If there is a PK defined
if (count($primary_keys) > 0)
{
- $key_name = 'pk_'.$table.'_'.$this->db->protect_identifiers(implode('_', $primary_keys));
-
- $primary_keys = $this->db->protect_identifiers($primary_keys);
- $sql .= ",\n\tCONSTRAINT " . $key_name . " PRIMARY KEY(" . implode(', ', $primary_keys) . ")";
+ $key_name = $this->db->protect_identifiers('pk_'.$table.'_'.implode('_', $primary_keys));
+ $sql .= ",\n\tCONSTRAINT ".$key_name.' PRIMARY KEY('.implode(', ', $this->db->protect_identifiers($primary_keys)).')';
}
if (is_array($keys) && count($keys) > 0)
@@ -203,22 +179,20 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
{
if (is_array($key))
{
- $key_name = $this->db->protect_identifiers(implode('_', $key));
+ $key_name = $this->db->protect_identifiers('idx_'.$table.implode('_', $key));
$key = $this->db->protect_identifiers($key);
}
else
{
- $key_name = $this->db->protect_identifiers($key);
+ $key_name = $this->db->protect_identifiers('idx_'.$table.$key);
$key = array($key_name);
}
- $sql .= ",\n\tKEY \"{$key_name}\" (" . implode(', ', $key) . ")";
+ $sql .= ",\n\tKEY ".$key_name.' ('.implode(', ', $key).')';
}
}
- $sql .= "\n);";
-
- return $sql;
+ return $sql."\n);";
}
// --------------------------------------------------------------------
@@ -230,7 +204,7 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
*/
public function _drop_table($table)
{
- return "DROP TABLE IF EXISTS ".$this->db->_escape_identifiers($table);
+ return 'DROP TABLE IF EXISTS '.$this->db->protect_identifiers($table);
}
// --------------------------------------------------------------------
@@ -252,19 +226,13 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
$sql = 'ALTER TABLE '.$this->db->protect_identifiers($table).' '.$alter_type.' ';
// DROP has everything it needs now.
- if ($alter_type == 'DROP')
+ if ($alter_type === 'DROP')
{
return $sql.$this->db->protect_identifiers($fields);
}
- $sql .= $this->_process_fields($fields);
-
- if ($after_field != '')
- {
- return $sql.' AFTER '.$this->db->protect_identifiers($after_field);
- }
-
- return $sql;
+ return $sql.$this->_process_fields($fields)
+ .($after_field != '' ? ' AFTER '.$this->db->protect_identifiers($after_field) : '');
}
// --------------------------------------------------------------------
@@ -286,4 +254,4 @@ class CI_DB_cubrid_forge extends CI_DB_forge {
}
/* End of file cubrid_forge.php */
-/* Location: ./system/database/drivers/cubrid/cubrid_forge.php */ \ No newline at end of file
+/* Location: ./system/database/drivers/cubrid/cubrid_forge.php */