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.

200 lines
5.5 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 4D 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_4d_driver extends CI_DB_pdo_driver {
  53. /**
  54. * Sub-driver
  55. *
  56. * @var string
  57. */
  58. public $subdriver = '4d';
  59. /**
  60. * Identifier escape character
  61. *
  62. * @var string[]
  63. */
  64. protected $_escape_char = array('[', ']');
  65. // --------------------------------------------------------------------
  66. /**
  67. * Class constructor
  68. *
  69. * Builds the DSN if not already set.
  70. *
  71. * @param array $params
  72. * @return void
  73. */
  74. public function __construct($params)
  75. {
  76. parent::__construct($params);
  77. if (empty($this->dsn))
  78. {
  79. $this->dsn = '4D:host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname);
  80. empty($this->port) OR $this->dsn .= ';port='.$this->port;
  81. empty($this->database) OR $this->dsn .= ';dbname='.$this->database;
  82. empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set;
  83. }
  84. elseif ( ! empty($this->char_set) && strpos($this->dsn, 'charset=', 3) === FALSE)
  85. {
  86. $this->dsn .= ';charset='.$this->char_set;
  87. }
  88. }
  89. // --------------------------------------------------------------------
  90. /**
  91. * Show table query
  92. *
  93. * Generates a platform-specific query string so that the table names can be fetched
  94. *
  95. * @param bool $prefix_limit
  96. * @return string
  97. */
  98. protected function _list_tables($prefix_limit = FALSE)
  99. {
  100. $sql = 'SELECT '.$this->escape_identifiers('TABLE_NAME').' FROM '.$this->escape_identifiers('_USER_TABLES');
  101. if ($prefix_limit === TRUE && $this->dbprefix !== '')
  102. {
  103. $sql .= ' WHERE '.$this->escape_identifiers('TABLE_NAME')." LIKE '".$this->escape_like_str($this->dbprefix)."%' "
  104. .sprintf($this->_like_escape_str, $this->_like_escape_chr);
  105. }
  106. return $sql;
  107. }
  108. // --------------------------------------------------------------------
  109. /**
  110. * Show column query
  111. *
  112. * Generates a platform-specific query string so that the column names can be fetched
  113. *
  114. * @param string $table
  115. * @return string
  116. */
  117. protected function _list_columns($table = '')
  118. {
  119. return 'SELECT '.$this->escape_identifiers('COLUMN_NAME').' FROM '.$this->escape_identifiers('_USER_COLUMNS')
  120. .' WHERE '.$this->escape_identifiers('TABLE_NAME').' = '.$this->escape($table);
  121. }
  122. // --------------------------------------------------------------------
  123. /**
  124. * Field data query
  125. *
  126. * Generates a platform-specific query so that the column data can be retrieved
  127. *
  128. * @param string $table
  129. * @return string
  130. */
  131. protected function _field_data($table)
  132. {
  133. return 'SELECT * FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE).' LIMIT 1';
  134. }
  135. // --------------------------------------------------------------------
  136. /**
  137. * Update statement
  138. *
  139. * Generates a platform-specific update string from the supplied data
  140. *
  141. * @param string $table
  142. * @param array $values
  143. * @return string
  144. */
  145. protected function _update($table, $values)
  146. {
  147. $this->qb_limit = FALSE;
  148. $this->qb_orderby = array();
  149. return parent::_update($table, $values);
  150. }
  151. // --------------------------------------------------------------------
  152. /**
  153. * Delete statement
  154. *
  155. * Generates a platform-specific delete string from the supplied data
  156. *
  157. * @param string $table
  158. * @return string
  159. */
  160. protected function _delete($table)
  161. {
  162. $this->qb_limit = FALSE;
  163. return parent::_delete($table);
  164. }
  165. // --------------------------------------------------------------------
  166. /**
  167. * LIMIT
  168. *
  169. * Generates a platform-specific LIMIT clause
  170. *
  171. * @param string $sql SQL Query
  172. * @return string
  173. */
  174. protected function _limit($sql)
  175. {
  176. return $sql.' LIMIT '.$this->qb_limit.($this->qb_offset ? ' OFFSET '.$this->qb_offset : '');
  177. }
  178. }