blob: e3f8bc334e6735780ae8eec590020b5c2753a186 [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
Esen Sagynov2e087942011-08-09 23:35:01 -07002/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Esen Sagynov2e087942011-08-09 23:35:01 -07006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Andrey Andreev7f55d612012-01-26 13:44:28 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreev7f55d612012-01-26 13:44:28 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * 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 Sagynov2e087942011-08-09 23:35:01 -070019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
Greg Aker0defe5d2012-01-01 18:46:41 -060021 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Esen Sagynov2e087942011-08-09 23:35:01 -070023 * @link http://codeigniter.com
Andrey Andreevcf631202012-02-16 11:36:28 +020024 * @since Version 2.1
Esen Sagynov2e087942011-08-09 23:35:01 -070025 * @filesource
26 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020027defined('BASEPATH') OR exit('No direct script access allowed');
Esen Sagynov2e087942011-08-09 23:35:01 -070028
Esen Sagynov2e087942011-08-09 23:35:01 -070029/**
30 * CUBRID Forge Class
31 *
32 * @category Database
Esen Sagynov2ab2b1e2011-08-11 00:41:16 -070033 * @author Esen Sagynov
Esen Sagynov2e087942011-08-09 23:35:01 -070034 * @link http://codeigniter.com/user_guide/database/
35 */
36class CI_DB_cubrid_forge extends CI_DB_forge {
37
Andrey Andreevc98e93a2012-11-02 02:04:59 +020038 /**
39 * CREATE DATABASE statement
40 *
41 * @var string
42 */
Andrey Andreevd947eba2012-04-09 14:58:28 +030043 protected $_create_database = FALSE;
Andrey Andreevc98e93a2012-11-02 02:04:59 +020044
Andrey Andreevc98e93a2012-11-02 02:04:59 +020045 /**
46 * DROP DATABASE statement
47 *
48 * @var string
49 */
Andrey Andreevd947eba2012-04-09 14:58:28 +030050 protected $_drop_database = FALSE;
Esen Sagynov2e087942011-08-09 23:35:01 -070051
52 /**
Andrey Andreeva287a342012-11-05 23:19:59 +020053 * CREATE TABLE IF statement
Esen Sagynov2e087942011-08-09 23:35:01 -070054 *
Andrey Andreeva287a342012-11-05 23:19:59 +020055 * @var string
Esen Sagynov2e087942011-08-09 23:35:01 -070056 */
Andrey Andreeva287a342012-11-05 23:19:59 +020057 protected $_create_table_if = FALSE;
Esen Sagynov2e087942011-08-09 23:35:01 -070058
Andrey Andreeva287a342012-11-05 23:19:59 +020059 /**
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 Sagynov2e087942011-08-09 23:35:01 -070087 {
Andrey Andreeva287a342012-11-05 23:19:59 +020088 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 Sagynov2e087942011-08-09 23:35:01 -070096 {
Andrey Andreeva287a342012-11-05 23:19:59 +020097 $sqls[] = $sql.' CHANGE '.$field[$i]['_literal'];
Esen Sagynov2e087942011-08-09 23:35:01 -070098 }
99 else
100 {
Andrey Andreeva287a342012-11-05 23:19:59 +0200101 $sqls[] = $sql.' CHANGE '.$this->_process_column($field[$i]);
102 if ( ! empty($field[$i]['new_name']))
Esen Sagynov2e087942011-08-09 23:35:01 -0700103 {
Andrey Andreeva287a342012-11-05 23:19:59 +0200104 $sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
105 .' AS '.$this->db->escape_identifiers($field[$i]['name']);
Esen Sagynov2e087942011-08-09 23:35:01 -0700106 }
Esen Sagynov2e087942011-08-09 23:35:01 -0700107 }
108 }
109
Andrey Andreeva287a342012-11-05 23:19:59 +0200110 return $sqls;
Esen Sagynov2e087942011-08-09 23:35:01 -0700111 }
112
113 // --------------------------------------------------------------------
114
115 /**
Andrey Andreeva287a342012-11-05 23:19:59 +0200116 * Field attribute TYPE
Esen Sagynov2e087942011-08-09 23:35:01 -0700117 *
Andrey Andreeva287a342012-11-05 23:19:59 +0200118 * Performs a data type mapping between different databases.
119 *
120 * @param array &$attributes
121 * @return void
Esen Sagynov2e087942011-08-09 23:35:01 -0700122 */
Andrey Andreeva287a342012-11-05 23:19:59 +0200123 protected function _attr_type(&$attributes)
Esen Sagynov2e087942011-08-09 23:35:01 -0700124 {
Andrey Andreeva287a342012-11-05 23:19:59 +0200125 switch (strtoupper($attributes['TYPE']))
Esen Sagynov2e087942011-08-09 23:35:01 -0700126 {
Andrey Andreeva287a342012-11-05 23:19:59 +0200127 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 Sagynov2e087942011-08-09 23:35:01 -0700136 }
Esen Sagynov2e087942011-08-09 23:35:01 -0700137 }
138
139 // --------------------------------------------------------------------
140
141 /**
Andrey Andreeva287a342012-11-05 23:19:59 +0200142 * Process indexes
Esen Sagynov2e087942011-08-09 23:35:01 -0700143 *
Andrey Andreeva287a342012-11-05 23:19:59 +0200144 * @param string $table (ignored)
Andrey Andreev7f55d612012-01-26 13:44:28 +0200145 * @return string
Esen Sagynov2e087942011-08-09 23:35:01 -0700146 */
Andrey Andreeva287a342012-11-05 23:19:59 +0200147 protected function _process_indexes($table = NULL)
Esen Sagynov2e087942011-08-09 23:35:01 -0700148 {
Andrey Andreeva287a342012-11-05 23:19:59 +0200149 $sql = '';
Esen Sagynov2e087942011-08-09 23:35:01 -0700150
Andrey Andreeva287a342012-11-05 23:19:59 +0200151 for ($i = 0, $c = count($this->keys); $i < $c; $i++)
Esen Sagynov2e087942011-08-09 23:35:01 -0700152 {
Andrey Andreeva287a342012-11-05 23:19:59 +0200153 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 Sagynov2e087942011-08-09 23:35:01 -0700163 }
164
Andrey Andreeva287a342012-11-05 23:19:59 +0200165 $this->keys = array();
166
167 return $sql;
Esen Sagynov2e087942011-08-09 23:35:01 -0700168 }
169
Esen Sagynov2e087942011-08-09 23:35:01 -0700170}
171
172/* End of file cubrid_forge.php */
Andrey Andreevfead0552012-03-20 15:23:06 +0200173/* Location: ./system/database/drivers/cubrid/cubrid_forge.php */