blob: 86a41e57b962419cff32ff267194a73458a02c0b [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 /**
Andrey Andreevb0a97c12012-11-11 13:58:53 +020046 * CREATE TABLE keys flag
47 *
48 * Whether table keys are created from within the
49 * CREATE TABLE statement.
50 *
51 * @var bool
52 */
53 protected $_create_table_keys = TRUE;
54
55 /**
Andrey Andreevc98e93a2012-11-02 02:04:59 +020056 * DROP DATABASE statement
57 *
58 * @var string
59 */
Andrey Andreevd947eba2012-04-09 14:58:28 +030060 protected $_drop_database = FALSE;
Esen Sagynov2e087942011-08-09 23:35:01 -070061
62 /**
Andrey Andreeva287a342012-11-05 23:19:59 +020063 * CREATE TABLE IF statement
Esen Sagynov2e087942011-08-09 23:35:01 -070064 *
Andrey Andreeva287a342012-11-05 23:19:59 +020065 * @var string
Esen Sagynov2e087942011-08-09 23:35:01 -070066 */
Andrey Andreeva287a342012-11-05 23:19:59 +020067 protected $_create_table_if = FALSE;
Esen Sagynov2e087942011-08-09 23:35:01 -070068
Andrey Andreeva287a342012-11-05 23:19:59 +020069 /**
70 * UNSIGNED support
71 *
72 * @var array
73 */
74 protected $_unsigned = array(
75 'SHORT' => 'INTEGER',
76 'SMALLINT' => 'INTEGER',
77 'INT' => 'BIGINT',
78 'INTEGER' => 'BIGINT',
79 'BIGINT' => 'NUMERIC',
80 'FLOAT' => 'DOUBLE',
81 'REAL' => 'DOUBLE'
82 );
83
84 // --------------------------------------------------------------------
85
86 /**
87 * ALTER TABLE
88 *
89 * @param string $alter_type ALTER type
90 * @param string $table Table name
91 * @param mixed $field Column definition
92 * @return string|string[]
93 */
94 protected function _alter_table($alter_type, $table, $field)
95 {
96 if (in_array($alter_type, array('DROP', 'ADD'), TRUE))
Esen Sagynov2e087942011-08-09 23:35:01 -070097 {
Andrey Andreeva287a342012-11-05 23:19:59 +020098 return parent::_alter_table($alter_type, $table, $field);
99 }
100
101 $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
102 $sqls = array();
103 for ($i = 0, $c = count($field); $i < $c; $i++)
104 {
105 if ($field[$i]['_literal'] !== FALSE)
Esen Sagynov2e087942011-08-09 23:35:01 -0700106 {
Andrey Andreeva287a342012-11-05 23:19:59 +0200107 $sqls[] = $sql.' CHANGE '.$field[$i]['_literal'];
Esen Sagynov2e087942011-08-09 23:35:01 -0700108 }
109 else
110 {
Andrey Andreeva287a342012-11-05 23:19:59 +0200111 $sqls[] = $sql.' CHANGE '.$this->_process_column($field[$i]);
112 if ( ! empty($field[$i]['new_name']))
Esen Sagynov2e087942011-08-09 23:35:01 -0700113 {
Andrey Andreeva287a342012-11-05 23:19:59 +0200114 $sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
115 .' AS '.$this->db->escape_identifiers($field[$i]['name']);
Esen Sagynov2e087942011-08-09 23:35:01 -0700116 }
Esen Sagynov2e087942011-08-09 23:35:01 -0700117 }
118 }
119
Andrey Andreeva287a342012-11-05 23:19:59 +0200120 return $sqls;
Esen Sagynov2e087942011-08-09 23:35:01 -0700121 }
122
123 // --------------------------------------------------------------------
124
125 /**
Andrey Andreeva287a342012-11-05 23:19:59 +0200126 * Field attribute TYPE
Esen Sagynov2e087942011-08-09 23:35:01 -0700127 *
Andrey Andreeva287a342012-11-05 23:19:59 +0200128 * Performs a data type mapping between different databases.
129 *
130 * @param array &$attributes
131 * @return void
Esen Sagynov2e087942011-08-09 23:35:01 -0700132 */
Andrey Andreeva287a342012-11-05 23:19:59 +0200133 protected function _attr_type(&$attributes)
Esen Sagynov2e087942011-08-09 23:35:01 -0700134 {
Andrey Andreeva287a342012-11-05 23:19:59 +0200135 switch (strtoupper($attributes['TYPE']))
Esen Sagynov2e087942011-08-09 23:35:01 -0700136 {
Andrey Andreeva287a342012-11-05 23:19:59 +0200137 case 'TINYINT':
138 $attributes['TYPE'] = 'SMALLINT';
139 $attributes['UNSIGNED'] = FALSE;
140 return;
141 case 'MEDIUMINT':
142 $attributes['TYPE'] = 'INTEGER';
143 $attributes['UNSIGNED'] = FALSE;
144 return;
145 default: return;
Esen Sagynov2e087942011-08-09 23:35:01 -0700146 }
Esen Sagynov2e087942011-08-09 23:35:01 -0700147 }
148
149 // --------------------------------------------------------------------
150
151 /**
Andrey Andreeva287a342012-11-05 23:19:59 +0200152 * Process indexes
Esen Sagynov2e087942011-08-09 23:35:01 -0700153 *
Andrey Andreeva287a342012-11-05 23:19:59 +0200154 * @param string $table (ignored)
Andrey Andreev7f55d612012-01-26 13:44:28 +0200155 * @return string
Esen Sagynov2e087942011-08-09 23:35:01 -0700156 */
Andrey Andreeva287a342012-11-05 23:19:59 +0200157 protected function _process_indexes($table = NULL)
Esen Sagynov2e087942011-08-09 23:35:01 -0700158 {
Andrey Andreeva287a342012-11-05 23:19:59 +0200159 $sql = '';
Esen Sagynov2e087942011-08-09 23:35:01 -0700160
Andrey Andreeva287a342012-11-05 23:19:59 +0200161 for ($i = 0, $c = count($this->keys); $i < $c; $i++)
Esen Sagynov2e087942011-08-09 23:35:01 -0700162 {
Andrey Andreeva287a342012-11-05 23:19:59 +0200163 if ( ! isset($this->fields[$this->keys[$i]]))
164 {
165 unset($this->keys[$i]);
166 continue;
167 }
168
169 is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]);
170
171 $sql .= ",\n\tKEY ".$this->db->escape_identifiers(implode('_', $this->keys[$i]))
172 .' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).')';
Esen Sagynov2e087942011-08-09 23:35:01 -0700173 }
174
Andrey Andreeva287a342012-11-05 23:19:59 +0200175 $this->keys = array();
176
177 return $sql;
Esen Sagynov2e087942011-08-09 23:35:01 -0700178 }
179
Esen Sagynov2e087942011-08-09 23:35:01 -0700180}
181
182/* End of file cubrid_forge.php */
Andrey Andreevfead0552012-03-20 15:23:06 +0200183/* Location: ./system/database/drivers/cubrid/cubrid_forge.php */