You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

187 lines
4.8 KiB

7 years ago
  1. <?php
  2. /**
  3. * CodeIgniter
  4. *
  5. * An open source application development framework for PHP
  6. *
  7. * This content is released under the MIT License (MIT)
  8. *
  9. * Copyright (c) 2014 - 2017, British Columbia Institute of Technology
  10. *
  11. * Permission is hereby granted, free of charge, to any person obtaining a copy
  12. * of this software and associated documentation files (the "Software"), to deal
  13. * in the Software without restriction, including without limitation the rights
  14. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  15. * copies of the Software, and to permit persons to whom the Software is
  16. * furnished to do so, subject to the following conditions:
  17. *
  18. * The above copyright notice and this permission notice shall be included in
  19. * all copies or substantial portions of the Software.
  20. *
  21. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  22. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  24. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  25. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  26. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  27. * THE SOFTWARE.
  28. *
  29. * @package CodeIgniter
  30. * @author EllisLab Dev Team
  31. * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
  32. * @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/)
  33. * @license http://opensource.org/licenses/MIT MIT License
  34. * @link https://codeigniter.com
  35. * @since Version 1.4.1
  36. * @filesource
  37. */
  38. defined('BASEPATH') OR exit('No direct script access allowed');
  39. /**
  40. * Oracle Forge Class
  41. *
  42. * @category Database
  43. * @author EllisLab Dev Team
  44. * @link https://codeigniter.com/user_guide/database/
  45. */
  46. class CI_DB_oci8_forge extends CI_DB_forge {
  47. /**
  48. * CREATE DATABASE statement
  49. *
  50. * @var string
  51. */
  52. protected $_create_database = FALSE;
  53. /**
  54. * CREATE TABLE IF statement
  55. *
  56. * @var string
  57. */
  58. protected $_create_table_if = FALSE;
  59. /**
  60. * DROP DATABASE statement
  61. *
  62. * @var string
  63. */
  64. protected $_drop_database = FALSE;
  65. /**
  66. * DROP TABLE IF statement
  67. *
  68. * @var string
  69. */
  70. protected $_drop_table_if = FALSE;
  71. /**
  72. * UNSIGNED support
  73. *
  74. * @var bool|array
  75. */
  76. protected $_unsigned = FALSE;
  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 ($alter_type === 'DROP')
  89. {
  90. return parent::_alter_table($alter_type, $table, $field);
  91. }
  92. elseif ($alter_type === 'CHANGE')
  93. {
  94. $alter_type = 'MODIFY';
  95. }
  96. $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
  97. $sqls = array();
  98. for ($i = 0, $c = count($field); $i < $c; $i++)
  99. {
  100. if ($field[$i]['_literal'] !== FALSE)
  101. {
  102. $field[$i] = "\n\t".$field[$i]['_literal'];
  103. }
  104. else
  105. {
  106. $field[$i]['_literal'] = "\n\t".$this->_process_column($field[$i]);
  107. if ( ! empty($field[$i]['comment']))
  108. {
  109. $sqls[] = 'COMMENT ON COLUMN '
  110. .$this->db->escape_identifiers($table).'.'.$this->db->escape_identifiers($field[$i]['name'])
  111. .' IS '.$field[$i]['comment'];
  112. }
  113. if ($alter_type === 'MODIFY' && ! empty($field[$i]['new_name']))
  114. {
  115. $sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
  116. .' TO '.$this->db->escape_identifiers($field[$i]['new_name']);
  117. }
  118. $field[$i] = "\n\t".$field[$i]['_literal'];
  119. }
  120. }
  121. $sql .= ' '.$alter_type.' ';
  122. $sql .= (count($field) === 1)
  123. ? $field[0]
  124. : '('.implode(',', $field).')';
  125. // RENAME COLUMN must be executed after MODIFY
  126. array_unshift($sqls, $sql);
  127. return $sqls;
  128. }
  129. // --------------------------------------------------------------------
  130. /**
  131. * Field attribute AUTO_INCREMENT
  132. *
  133. * @param array &$attributes
  134. * @param array &$field
  135. * @return void
  136. */
  137. protected function _attr_auto_increment(&$attributes, &$field)
  138. {
  139. // Not supported - sequences and triggers must be used instead
  140. }
  141. // --------------------------------------------------------------------
  142. /**
  143. * Field attribute TYPE
  144. *
  145. * Performs a data type mapping between different databases.
  146. *
  147. * @param array &$attributes
  148. * @return void
  149. */
  150. protected function _attr_type(&$attributes)
  151. {
  152. switch (strtoupper($attributes['TYPE']))
  153. {
  154. case 'TINYINT':
  155. $attributes['TYPE'] = 'NUMBER';
  156. return;
  157. case 'MEDIUMINT':
  158. $attributes['TYPE'] = 'NUMBER';
  159. return;
  160. case 'INT':
  161. $attributes['TYPE'] = 'NUMBER';
  162. return;
  163. case 'BIGINT':
  164. $attributes['TYPE'] = 'NUMBER';
  165. return;
  166. default: return;
  167. }
  168. }
  169. }