pdo_ibm_forge.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 IBM DB2 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_ibm_forge extends CI_DB_pdo_forge {
  47. /**
  48. * RENAME TABLE IF statement
  49. *
  50. * @var string
  51. */
  52. protected $_rename_table = 'RENAME TABLE %s TO %s';
  53. /**
  54. * UNSIGNED support
  55. *
  56. * @var array
  57. */
  58. protected $_unsigned = array(
  59. 'SMALLINT' => 'INTEGER',
  60. 'INT' => 'BIGINT',
  61. 'INTEGER' => 'BIGINT'
  62. );
  63. /**
  64. * DEFAULT value representation in CREATE/ALTER TABLE statements
  65. *
  66. * @var string
  67. */
  68. protected $_default = FALSE;
  69. // --------------------------------------------------------------------
  70. /**
  71. * ALTER TABLE
  72. *
  73. * @param string $alter_type ALTER type
  74. * @param string $table Table name
  75. * @param mixed $field Column definition
  76. * @return string|string[]
  77. */
  78. protected function _alter_table($alter_type, $table, $field)
  79. {
  80. if ($alter_type === 'CHANGE')
  81. {
  82. $alter_type = 'MODIFY';
  83. }
  84. return parent::_alter_table($alter_type, $table, $field);
  85. }
  86. // --------------------------------------------------------------------
  87. /**
  88. * Field attribute TYPE
  89. *
  90. * Performs a data type mapping between different databases.
  91. *
  92. * @param array &$attributes
  93. * @return void
  94. */
  95. protected function _attr_type(&$attributes)
  96. {
  97. switch (strtoupper($attributes['TYPE']))
  98. {
  99. case 'TINYINT':
  100. $attributes['TYPE'] = 'SMALLINT';
  101. $attributes['UNSIGNED'] = FALSE;
  102. return;
  103. case 'MEDIUMINT':
  104. $attributes['TYPE'] = 'INTEGER';
  105. $attributes['UNSIGNED'] = FALSE;
  106. return;
  107. default: return;
  108. }
  109. }
  110. // --------------------------------------------------------------------
  111. /**
  112. * Field attribute UNIQUE
  113. *
  114. * @param array &$attributes
  115. * @param array &$field
  116. * @return void
  117. */
  118. protected function _attr_unique(&$attributes, &$field)
  119. {
  120. if ( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE)
  121. {
  122. $field['unique'] = ' UNIQUE';
  123. // UNIQUE must be used with NOT NULL
  124. $field['null'] = ' NOT NULL';
  125. }
  126. }
  127. // --------------------------------------------------------------------
  128. /**
  129. * Field attribute AUTO_INCREMENT
  130. *
  131. * @param array &$attributes
  132. * @param array &$field
  133. * @return void
  134. */
  135. protected function _attr_auto_increment(&$attributes, &$field)
  136. {
  137. // Not supported
  138. }
  139. }