/halogy/database/drivers/oci8/oci8_forge.php

https://bitbucket.org/haloweb/halogy-1.0/ · PHP · 248 lines · 119 code · 39 blank · 90 comment · 23 complexity · 11138205807c452e0464027986530ca9 MD5 · raw file

  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * CodeIgniter
  4. *
  5. * An open source application development framework for PHP 4.3.2 or newer
  6. *
  7. * @package CodeIgniter
  8. * @author ExpressionEngine Dev Team
  9. * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc.
  10. * @license http://codeigniter.com/user_guide/license.html
  11. * @link http://codeigniter.com
  12. * @since Version 1.0
  13. * @filesource
  14. */
  15. // ------------------------------------------------------------------------
  16. /**
  17. * Oracle Forge Class
  18. *
  19. * @category Database
  20. * @author ExpressionEngine Dev Team
  21. * @link http://codeigniter.com/user_guide/database/
  22. */
  23. class CI_DB_oci8_forge extends CI_DB_forge {
  24. /**
  25. * Create database
  26. *
  27. * @access public
  28. * @param string the database name
  29. * @return bool
  30. */
  31. function _create_database($name)
  32. {
  33. return FALSE;
  34. }
  35. // --------------------------------------------------------------------
  36. /**
  37. * Drop database
  38. *
  39. * @access private
  40. * @param string the database name
  41. * @return bool
  42. */
  43. function _drop_database($name)
  44. {
  45. return FALSE;
  46. }
  47. // --------------------------------------------------------------------
  48. /**
  49. * Create Table
  50. *
  51. * @access private
  52. * @param string the table name
  53. * @param array the fields
  54. * @param mixed primary key(s)
  55. * @param mixed key(s)
  56. * @param boolean should 'IF NOT EXISTS' be added to the SQL
  57. * @return bool
  58. */
  59. function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
  60. {
  61. $sql = 'CREATE TABLE ';
  62. if ($if_not_exists === TRUE)
  63. {
  64. $sql .= 'IF NOT EXISTS ';
  65. }
  66. $sql .= $this->db->_escape_identifiers($table)." (";
  67. $current_field_count = 0;
  68. foreach ($fields as $field=>$attributes)
  69. {
  70. // Numeric field names aren't allowed in databases, so if the key is
  71. // numeric, we know it was assigned by PHP and the developer manually
  72. // entered the field information, so we'll simply add it to the list
  73. if (is_numeric($field))
  74. {
  75. $sql .= "\n\t$attributes";
  76. }
  77. else
  78. {
  79. $attributes = array_change_key_case($attributes, CASE_UPPER);
  80. $sql .= "\n\t".$this->db->_protect_identifiers($field);
  81. $sql .= ' '.$attributes['TYPE'];
  82. if (array_key_exists('CONSTRAINT', $attributes))
  83. {
  84. $sql .= '('.$attributes['CONSTRAINT'].')';
  85. }
  86. if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
  87. {
  88. $sql .= ' UNSIGNED';
  89. }
  90. if (array_key_exists('DEFAULT', $attributes))
  91. {
  92. $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
  93. }
  94. if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)
  95. {
  96. $sql .= ' NULL';
  97. }
  98. else
  99. {
  100. $sql .= ' NOT NULL';
  101. }
  102. if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)
  103. {
  104. $sql .= ' AUTO_INCREMENT';
  105. }
  106. }
  107. // don't add a comma on the end of the last field
  108. if (++$current_field_count < count($fields))
  109. {
  110. $sql .= ',';
  111. }
  112. }
  113. if (count($primary_keys) > 0)
  114. {
  115. $primary_keys = $this->db->_protect_identifiers($primary_keys);
  116. $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";
  117. }
  118. if (is_array($keys) && count($keys) > 0)
  119. {
  120. foreach ($keys as $key)
  121. {
  122. if (is_array($key))
  123. {
  124. $key = $this->db->_protect_identifiers($key);
  125. }
  126. else
  127. {
  128. $key = array($this->db->_protect_identifiers($key));
  129. }
  130. $sql .= ",\n\tUNIQUE COLUMNS (" . implode(', ', $key) . ")";
  131. }
  132. }
  133. $sql .= "\n)";
  134. return $sql;
  135. }
  136. // --------------------------------------------------------------------
  137. /**
  138. * Drop Table
  139. *
  140. * @access private
  141. * @return bool
  142. */
  143. function _drop_table($table)
  144. {
  145. return FALSE;
  146. }
  147. // --------------------------------------------------------------------
  148. /**
  149. * Alter table query
  150. *
  151. * Generates a platform-specific query so that a table can be altered
  152. * Called by add_column(), drop_column(), and column_alter(),
  153. *
  154. * @access private
  155. * @param string the ALTER type (ADD, DROP, CHANGE)
  156. * @param string the column name
  157. * @param string the table name
  158. * @param string the column definition
  159. * @param string the default value
  160. * @param boolean should 'NOT NULL' be added
  161. * @param string the field after which we should add the new field
  162. * @return object
  163. */
  164. function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
  165. {
  166. $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name);
  167. // DROP has everything it needs now.
  168. if ($alter_type == 'DROP')
  169. {
  170. return $sql;
  171. }
  172. $sql .= " $column_definition";
  173. if ($default_value != '')
  174. {
  175. $sql .= " DEFAULT \"$default_value\"";
  176. }
  177. if ($null === NULL)
  178. {
  179. $sql .= ' NULL';
  180. }
  181. else
  182. {
  183. $sql .= ' NOT NULL';
  184. }
  185. if ($after_field != '')
  186. {
  187. $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
  188. }
  189. return $sql;
  190. }
  191. // --------------------------------------------------------------------
  192. /**
  193. * Rename a table
  194. *
  195. * Generates a platform-specific query so that a table can be renamed
  196. *
  197. * @access private
  198. * @param string the old table name
  199. * @param string the new table name
  200. * @return string
  201. */
  202. function _rename_table($table_name, $new_table_name)
  203. {
  204. $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name);
  205. return $sql;
  206. }
  207. }
  208. /* End of file oci8_forge.php */
  209. /* Location: ./system/database/drivers/oci8/oci8_forge.php */