pdo_oci_forge.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 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. /**
  73. * ALTER TABLE
  74. *
  75. * @param string $alter_type ALTER type
  76. * @param string $table Table name
  77. * @param mixed $field Column definition
  78. * @return string|string[]
  79. */
  80. protected function _alter_table($alter_type, $table, $field)
  81. {
  82. if ($alter_type === 'DROP')
  83. {
  84. return parent::_alter_table($alter_type, $table, $field);
  85. }
  86. elseif ($alter_type === 'CHANGE')
  87. {
  88. $alter_type = 'MODIFY';
  89. }
  90. $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
  91. $sqls = array();
  92. for ($i = 0, $c = count($field); $i < $c; $i++)
  93. {
  94. if ($field[$i]['_literal'] !== FALSE)
  95. {
  96. $field[$i] = "\n\t".$field[$i]['_literal'];
  97. }
  98. else
  99. {
  100. $field[$i]['_literal'] = "\n\t".$this->_process_column($field[$i]);
  101. if ( ! empty($field[$i]['comment']))
  102. {
  103. $sqls[] = 'COMMENT ON COLUMN '
  104. .$this->db->escape_identifiers($table).'.'.$this->db->escape_identifiers($field[$i]['name'])
  105. .' IS '.$field[$i]['comment'];
  106. }
  107. if ($alter_type === 'MODIFY' && ! empty($field[$i]['new_name']))
  108. {
  109. $sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
  110. .' TO '.$this->db->escape_identifiers($field[$i]['new_name']);
  111. }
  112. }
  113. }
  114. $sql .= ' '.$alter_type.' ';
  115. $sql .= (count($field) === 1)
  116. ? $field[0]
  117. : '('.implode(',', $field).')';
  118. // RENAME COLUMN must be executed after MODIFY
  119. array_unshift($sqls, $sql);
  120. return $sql;
  121. }
  122. // --------------------------------------------------------------------
  123. /**
  124. * Field attribute AUTO_INCREMENT
  125. *
  126. * @param array &$attributes
  127. * @param array &$field
  128. * @return void
  129. */
  130. protected function _attr_auto_increment(&$attributes, &$field)
  131. {
  132. // Not supported - sequences and triggers must be used instead
  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'] = 'NUMBER';
  148. return;
  149. case 'MEDIUMINT':
  150. $attributes['TYPE'] = 'NUMBER';
  151. return;
  152. case 'INT':
  153. $attributes['TYPE'] = 'NUMBER';
  154. return;
  155. case 'BIGINT':
  156. $attributes['TYPE'] = 'NUMBER';
  157. return;
  158. default: return;
  159. }
  160. }
  161. }