Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 1 | <?php |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Phil Sturgeon | 07c1ac8 | 2012-03-09 17:03:37 +0000 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.2.4 or newer |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 8 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 9 | * Licensed under the Open Software License version 3.0 |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 10 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 11 | * This source file is subject to the Open Software License (OSL 3.0) that is |
| 12 | * bundled with this package in the files license.txt / license.rst. It is |
| 13 | * also available through the world wide web at this URL: |
| 14 | * http://opensource.org/licenses/OSL-3.0 |
| 15 | * If you did not receive a copy of the license and are unable to obtain it |
| 16 | * through the world wide web, please send an email to |
| 17 | * licensing@ellislab.com so we can send you a copy immediately. |
| 18 | * |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 20 | * @author EllisLab Dev Team |
Greg Aker | 0defe5d | 2012-01-01 18:46:41 -0600 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 23 | * @link http://codeigniter.com |
Andrey Andreev | cf63120 | 2012-02-16 11:36:28 +0200 | [diff] [blame] | 24 | * @since Version 2.1 |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 25 | * @filesource |
| 26 | */ |
Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 27 | defined('BASEPATH') OR exit('No direct script access allowed'); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 28 | |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 29 | /** |
| 30 | * CUBRID Forge Class |
| 31 | * |
| 32 | * @category Database |
Esen Sagynov | 2ab2b1e | 2011-08-11 00:41:16 -0700 | [diff] [blame] | 33 | * @author Esen Sagynov |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 34 | * @link http://codeigniter.com/user_guide/database/ |
| 35 | */ |
| 36 | class CI_DB_cubrid_forge extends CI_DB_forge { |
| 37 | |
Andrey Andreev | c98e93a | 2012-11-02 02:04:59 +0200 | [diff] [blame] | 38 | /** |
| 39 | * CREATE DATABASE statement |
| 40 | * |
| 41 | * @var string |
| 42 | */ |
Andrey Andreev | d947eba | 2012-04-09 14:58:28 +0300 | [diff] [blame] | 43 | protected $_create_database = FALSE; |
Andrey Andreev | c98e93a | 2012-11-02 02:04:59 +0200 | [diff] [blame] | 44 | |
Andrey Andreev | c98e93a | 2012-11-02 02:04:59 +0200 | [diff] [blame] | 45 | /** |
| 46 | * DROP DATABASE statement |
| 47 | * |
| 48 | * @var string |
| 49 | */ |
Andrey Andreev | d947eba | 2012-04-09 14:58:28 +0300 | [diff] [blame] | 50 | protected $_drop_database = FALSE; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 51 | |
| 52 | /** |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame^] | 53 | * CREATE TABLE IF statement |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 54 | * |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame^] | 55 | * @var string |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 56 | */ |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame^] | 57 | protected $_create_table_if = FALSE; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 58 | |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame^] | 59 | /** |
| 60 | * UNSIGNED support |
| 61 | * |
| 62 | * @var array |
| 63 | */ |
| 64 | protected $_unsigned = array( |
| 65 | 'SHORT' => 'INTEGER', |
| 66 | 'SMALLINT' => 'INTEGER', |
| 67 | 'INT' => 'BIGINT', |
| 68 | 'INTEGER' => 'BIGINT', |
| 69 | 'BIGINT' => 'NUMERIC', |
| 70 | 'FLOAT' => 'DOUBLE', |
| 71 | 'REAL' => 'DOUBLE' |
| 72 | ); |
| 73 | |
| 74 | // -------------------------------------------------------------------- |
| 75 | |
| 76 | /** |
| 77 | * ALTER TABLE |
| 78 | * |
| 79 | * @param string $alter_type ALTER type |
| 80 | * @param string $table Table name |
| 81 | * @param mixed $field Column definition |
| 82 | * @return string|string[] |
| 83 | */ |
| 84 | protected function _alter_table($alter_type, $table, $field) |
| 85 | { |
| 86 | if (in_array($alter_type, array('DROP', 'ADD'), TRUE)) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 87 | { |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame^] | 88 | return parent::_alter_table($alter_type, $table, $field); |
| 89 | } |
| 90 | |
| 91 | $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table); |
| 92 | $sqls = array(); |
| 93 | for ($i = 0, $c = count($field); $i < $c; $i++) |
| 94 | { |
| 95 | if ($field[$i]['_literal'] !== FALSE) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 96 | { |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame^] | 97 | $sqls[] = $sql.' CHANGE '.$field[$i]['_literal']; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 98 | } |
| 99 | else |
| 100 | { |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame^] | 101 | $sqls[] = $sql.' CHANGE '.$this->_process_column($field[$i]); |
| 102 | if ( ! empty($field[$i]['new_name'])) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 103 | { |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame^] | 104 | $sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name']) |
| 105 | .' AS '.$this->db->escape_identifiers($field[$i]['name']); |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 106 | } |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 107 | } |
| 108 | } |
| 109 | |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame^] | 110 | return $sqls; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | // -------------------------------------------------------------------- |
| 114 | |
| 115 | /** |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame^] | 116 | * Field attribute TYPE |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 117 | * |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame^] | 118 | * Performs a data type mapping between different databases. |
| 119 | * |
| 120 | * @param array &$attributes |
| 121 | * @return void |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 122 | */ |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame^] | 123 | protected function _attr_type(&$attributes) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 124 | { |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame^] | 125 | switch (strtoupper($attributes['TYPE'])) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 126 | { |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame^] | 127 | case 'TINYINT': |
| 128 | $attributes['TYPE'] = 'SMALLINT'; |
| 129 | $attributes['UNSIGNED'] = FALSE; |
| 130 | return; |
| 131 | case 'MEDIUMINT': |
| 132 | $attributes['TYPE'] = 'INTEGER'; |
| 133 | $attributes['UNSIGNED'] = FALSE; |
| 134 | return; |
| 135 | default: return; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 136 | } |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | // -------------------------------------------------------------------- |
| 140 | |
| 141 | /** |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame^] | 142 | * Process indexes |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 143 | * |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame^] | 144 | * @param string $table (ignored) |
Andrey Andreev | 7f55d61 | 2012-01-26 13:44:28 +0200 | [diff] [blame] | 145 | * @return string |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 146 | */ |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame^] | 147 | protected function _process_indexes($table = NULL) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 148 | { |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame^] | 149 | $sql = ''; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 150 | |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame^] | 151 | for ($i = 0, $c = count($this->keys); $i < $c; $i++) |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 152 | { |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame^] | 153 | if ( ! isset($this->fields[$this->keys[$i]])) |
| 154 | { |
| 155 | unset($this->keys[$i]); |
| 156 | continue; |
| 157 | } |
| 158 | |
| 159 | is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]); |
| 160 | |
| 161 | $sql .= ",\n\tKEY ".$this->db->escape_identifiers(implode('_', $this->keys[$i])) |
| 162 | .' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).')'; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 163 | } |
| 164 | |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame^] | 165 | $this->keys = array(); |
| 166 | |
| 167 | return $sql; |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Esen Sagynov | 2e08794 | 2011-08-09 23:35:01 -0700 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | /* End of file cubrid_forge.php */ |
Andrey Andreev | fead055 | 2012-03-20 15:23:06 +0200 | [diff] [blame] | 173 | /* Location: ./system/database/drivers/cubrid/cubrid_forge.php */ |