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.

209 lines
5.4 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 3.0.0
  36. * @filesource
  37. */
  38. defined('BASEPATH') OR exit('No direct script access allowed');
  39. /**
  40. * PDO CUBRID Database Adapter Class
  41. *
  42. * Note: _DB is an extender class that the app controller
  43. * creates dynamically based on whether the query builder
  44. * class is being used or not.
  45. *
  46. * @package CodeIgniter
  47. * @subpackage Drivers
  48. * @category Database
  49. * @author EllisLab Dev Team
  50. * @link https://codeigniter.com/user_guide/database/
  51. */
  52. class CI_DB_pdo_cubrid_driver extends CI_DB_pdo_driver {
  53. /**
  54. * Sub-driver
  55. *
  56. * @var string
  57. */
  58. public $subdriver = 'cubrid';
  59. /**
  60. * Identifier escape character
  61. *
  62. * @var string
  63. */
  64. protected $_escape_char = '`';
  65. /**
  66. * ORDER BY random keyword
  67. *
  68. * @var array
  69. */
  70. protected $_random_keyword = array('RANDOM()', 'RANDOM(%d)');
  71. // --------------------------------------------------------------------
  72. /**
  73. * Class constructor
  74. *
  75. * Builds the DSN if not already set.
  76. *
  77. * @param array $params
  78. * @return void
  79. */
  80. public function __construct($params)
  81. {
  82. parent::__construct($params);
  83. if (empty($this->dsn))
  84. {
  85. $this->dsn = 'cubrid:host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname);
  86. empty($this->port) OR $this->dsn .= ';port='.$this->port;
  87. empty($this->database) OR $this->dsn .= ';dbname='.$this->database;
  88. empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set;
  89. }
  90. }
  91. // --------------------------------------------------------------------
  92. /**
  93. * Show table query
  94. *
  95. * Generates a platform-specific query string so that the table names can be fetched
  96. *
  97. * @param bool $prefix_limit
  98. * @return string
  99. */
  100. protected function _list_tables($prefix_limit = FALSE)
  101. {
  102. $sql = 'SHOW TABLES';
  103. if ($prefix_limit === TRUE && $this->dbprefix !== '')
  104. {
  105. return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'";
  106. }
  107. return $sql;
  108. }
  109. // --------------------------------------------------------------------
  110. /**
  111. * Show column query
  112. *
  113. * Generates a platform-specific query string so that the column names can be fetched
  114. *
  115. * @param string $table
  116. * @return string
  117. */
  118. protected function _list_columns($table = '')
  119. {
  120. return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE);
  121. }
  122. // --------------------------------------------------------------------
  123. /**
  124. * Returns an object with field data
  125. *
  126. * @param string $table
  127. * @return array
  128. */
  129. public function field_data($table)
  130. {
  131. if (($query = $this->query('SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE))) === FALSE)
  132. {
  133. return FALSE;
  134. }
  135. $query = $query->result_object();
  136. $retval = array();
  137. for ($i = 0, $c = count($query); $i < $c; $i++)
  138. {
  139. $retval[$i] = new stdClass();
  140. $retval[$i]->name = $query[$i]->Field;
  141. sscanf($query[$i]->Type, '%[a-z](%d)',
  142. $retval[$i]->type,
  143. $retval[$i]->max_length
  144. );
  145. $retval[$i]->default = $query[$i]->Default;
  146. $retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI');
  147. }
  148. return $retval;
  149. }
  150. // --------------------------------------------------------------------
  151. /**
  152. * Truncate statement
  153. *
  154. * Generates a platform-specific truncate string from the supplied data
  155. *
  156. * If the database does not support the TRUNCATE statement,
  157. * then this method maps to 'DELETE FROM table'
  158. *
  159. * @param string $table
  160. * @return string
  161. */
  162. protected function _truncate($table)
  163. {
  164. return 'TRUNCATE '.$table;
  165. }
  166. // --------------------------------------------------------------------
  167. /**
  168. * FROM tables
  169. *
  170. * Groups tables in FROM clauses if needed, so there is no confusion
  171. * about operator precedence.
  172. *
  173. * @return string
  174. */
  175. protected function _from_tables()
  176. {
  177. if ( ! empty($this->qb_join) && count($this->qb_from) > 1)
  178. {
  179. return '('.implode(', ', $this->qb_from).')';
  180. }
  181. return implode(', ', $this->qb_from);
  182. }
  183. }