pdo_oci_forge.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 - 2019, 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 - 2019, British Columbia Institute of Technology (https://bcit.ca/)
  33. * @license https://opensource.org/licenses/MIT MIT License
  34. * @link https://codeigniter.com
  35. * @since Version 3.0.0
  36. * @filesource
  37. */
  38. defined('BASEPATH') OR exit('No direct script access allowed');
  39. /**
  40. * PDO 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_pdo_oci_forge extends CI_DB_pdo_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. * UNSIGNED support
  67. *
  68. * @var bool|array
  69. */
  70. protected $_unsigned = FALSE;
  71. /**
  72. * NULL value representation in CREATE/ALTER TABLE statements
  73. *
  74. * @var string
  75. */
  76. protected $_null = 'NULL';
  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. }
  119. }
  120. $sql .= ' '.$alter_type.' ';
  121. $sql .= (count($field) === 1)
  122. ? $field[0]
  123. : '('.implode(',', $field).')';
  124. // RENAME COLUMN must be executed after MODIFY
  125. array_unshift($sqls, $sql);
  126. return $sql;
  127. }
  128. // --------------------------------------------------------------------
  129. /**
  130. * Field attribute AUTO_INCREMENT
  131. *
  132. * @param array &$attributes
  133. * @param array &$field
  134. * @return void
  135. */
  136. protected function _attr_auto_increment(&$attributes, &$field)
  137. {
  138. // Not supported - sequences and triggers must be used instead
  139. }
  140. /**
  141. * Field attribute TYPE
  142. *
  143. * Performs a data type mapping between different databases.
  144. *
  145. * @param array &$attributes
  146. * @return void
  147. */
  148. protected function _attr_type(&$attributes)
  149. {
  150. switch (strtoupper($attributes['TYPE']))
  151. {
  152. case 'TINYINT':
  153. $attributes['TYPE'] = 'NUMBER';
  154. return;
  155. case 'MEDIUMINT':
  156. $attributes['TYPE'] = 'NUMBER';
  157. return;
  158. case 'INT':
  159. $attributes['TYPE'] = 'NUMBER';
  160. return;
  161. case 'BIGINT':
  162. $attributes['TYPE'] = 'NUMBER';
  163. return;
  164. default: return;
  165. }
  166. }
  167. }