PageRenderTime 56ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/system/codeigniter/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php

https://github.com/asalem/pyrocms
PHP | 219 lines | 100 code | 25 blank | 94 comment | 11 complexity | 9740a1f23907b14c7821f50ad0dc659f MD5 | raw file
Possible License(s): CC-BY-3.0, BSD-3-Clause, CC0-1.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, MIT
  1. <?php
  2. /**
  3. * CodeIgniter
  4. *
  5. * An open source application development framework for PHP 5.2.4 or newer
  6. *
  7. * NOTICE OF LICENSE
  8. *
  9. * Licensed under the Open Software License version 3.0
  10. *
  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. *
  19. * @package CodeIgniter
  20. * @author EllisLab Dev Team
  21. * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/)
  22. * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
  23. * @link http://codeigniter.com
  24. * @since Version 2.1.0
  25. * @filesource
  26. */
  27. defined('BASEPATH') OR exit('No direct script access allowed');
  28. /**
  29. * PDO CUBRID Forge Class
  30. *
  31. * @category Database
  32. * @author EllisLab Dev Team
  33. * @link http://codeigniter.com/user_guide/database/
  34. */
  35. class CI_DB_pdo_cubrid_forge extends CI_DB_pdo_forge {
  36. /**
  37. * CREATE DATABASE statement
  38. *
  39. * @var string
  40. */
  41. protected $_create_database = FALSE;
  42. /**
  43. * DROP DATABASE statement
  44. *
  45. * @var string
  46. */
  47. protected $_drop_database = FALSE;
  48. /**
  49. * CREATE TABLE keys flag
  50. *
  51. * Whether table keys are created from within the
  52. * CREATE TABLE statement.
  53. *
  54. * @var bool
  55. */
  56. protected $_create_table_keys = TRUE;
  57. /**
  58. * DROP TABLE IF statement
  59. *
  60. * @var string
  61. */
  62. protected $_drop_table_if = 'DROP TABLE IF EXISTS';
  63. /**
  64. * UNSIGNED support
  65. *
  66. * @var array
  67. */
  68. protected $_unsigned = array(
  69. 'SHORT' => 'INTEGER',
  70. 'SMALLINT' => 'INTEGER',
  71. 'INT' => 'BIGINT',
  72. 'INTEGER' => 'BIGINT',
  73. 'BIGINT' => 'NUMERIC',
  74. 'FLOAT' => 'DOUBLE',
  75. 'REAL' => 'DOUBLE'
  76. );
  77. // --------------------------------------------------------------------
  78. /**
  79. * ALTER TABLE
  80. *
  81. * @param string $alter_type ALTER type
  82. * @param string $table Table name
  83. * @param mixed $field Column definition
  84. * @return string|string[]
  85. */
  86. protected function _alter_table($alter_type, $table, $field)
  87. {
  88. if (in_array($alter_type, array('DROP', 'ADD'), TRUE))
  89. {
  90. return parent::_alter_table($alter_type, $table, $field);
  91. }
  92. $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
  93. $sqls = array();
  94. for ($i = 0, $c = count($field); $i < $c; $i++)
  95. {
  96. if ($field[$i]['_literal'] !== FALSE)
  97. {
  98. $sqls[] = $sql.' CHANGE '.$field[$i]['_literal'];
  99. }
  100. else
  101. {
  102. $alter_type = empty($field[$i]['new_name']) ? ' MODIFY ' : ' CHANGE ';
  103. $sqls[] = $sql.$alter_type.$this->_process_column($field[$i]);
  104. }
  105. }
  106. return $sqls;
  107. }
  108. // --------------------------------------------------------------------
  109. /**
  110. * Process column
  111. *
  112. * @param array $field
  113. * @return string
  114. */
  115. protected function _process_column($field)
  116. {
  117. $extra_clause = isset($field['after'])
  118. ? ' AFTER '.$this->db->escape_identifiers($field['after']) : '';
  119. if (empty($extra_clause) && isset($field['first']) && $field['first'] === TRUE)
  120. {
  121. $extra_clause = ' FIRST';
  122. }
  123. return $this->db->escape_identifiers($field['name'])
  124. .(empty($field['new_name']) ? '' : ' '.$this->db->escape_identifiers($field['new_name']))
  125. .' '.$field['type'].$field['length']
  126. .$field['unsigned']
  127. .$field['null']
  128. .$field['default']
  129. .$field['auto_increment']
  130. .$field['unique']
  131. .$extra_clause;
  132. }
  133. // --------------------------------------------------------------------
  134. /**
  135. * Field attribute TYPE
  136. *
  137. * Performs a data type mapping between different databases.
  138. *
  139. * @param array &$attributes
  140. * @return void
  141. */
  142. protected function _attr_type(&$attributes)
  143. {
  144. switch (strtoupper($attributes['TYPE']))
  145. {
  146. case 'TINYINT':
  147. $attributes['TYPE'] = 'SMALLINT';
  148. $attributes['UNSIGNED'] = FALSE;
  149. return;
  150. case 'MEDIUMINT':
  151. $attributes['TYPE'] = 'INTEGER';
  152. $attributes['UNSIGNED'] = FALSE;
  153. return;
  154. default: return;
  155. }
  156. }
  157. // --------------------------------------------------------------------
  158. /**
  159. * Process indexes
  160. *
  161. * @param string $table (ignored)
  162. * @return string
  163. */
  164. protected function _process_indexes($table)
  165. {
  166. $sql = '';
  167. for ($i = 0, $c = count($this->keys); $i < $c; $i++)
  168. {
  169. if (is_array($this->keys[$i]))
  170. {
  171. for ($i2 = 0, $c2 = count($this->keys[$i]); $i2 < $c2; $i2++)
  172. {
  173. if ( ! isset($this->fields[$this->keys[$i][$i2]]))
  174. {
  175. unset($this->keys[$i][$i2]);
  176. continue;
  177. }
  178. }
  179. }
  180. elseif ( ! isset($this->fields[$this->keys[$i]]))
  181. {
  182. unset($this->keys[$i]);
  183. continue;
  184. }
  185. is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]);
  186. $sql .= ",\n\tKEY ".$this->db->escape_identifiers(implode('_', $this->keys[$i]))
  187. .' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).')';
  188. }
  189. $this->keys = array();
  190. return $sql;
  191. }
  192. }
  193. /* End of file pdo_cubrid_forge.php */
  194. /* Location: ./system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php */