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.

229 lines
5.2 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 1.4.1
  36. * @filesource
  37. */
  38. defined('BASEPATH') OR exit('No direct script access allowed');
  39. /**
  40. * oci8 Result Class
  41. *
  42. * This class extends the parent result class: CI_DB_result
  43. *
  44. * @category Database
  45. * @author EllisLab Dev Team
  46. * @link https://codeigniter.com/user_guide/database/
  47. */
  48. class CI_DB_oci8_result extends CI_DB_result {
  49. /**
  50. * Statement ID
  51. *
  52. * @var resource
  53. */
  54. public $stmt_id;
  55. /**
  56. * Cursor ID
  57. *
  58. * @var resource
  59. */
  60. public $curs_id;
  61. /**
  62. * Limit used flag
  63. *
  64. * @var bool
  65. */
  66. public $limit_used;
  67. /**
  68. * Commit mode flag
  69. *
  70. * @var int
  71. */
  72. public $commit_mode;
  73. // --------------------------------------------------------------------
  74. /**
  75. * Class constructor
  76. *
  77. * @param object &$driver_object
  78. * @return void
  79. */
  80. public function __construct(&$driver_object)
  81. {
  82. parent::__construct($driver_object);
  83. $this->stmt_id = $driver_object->stmt_id;
  84. $this->curs_id = $driver_object->curs_id;
  85. $this->limit_used = $driver_object->limit_used;
  86. $this->commit_mode =& $driver_object->commit_mode;
  87. $driver_object->stmt_id = FALSE;
  88. }
  89. // --------------------------------------------------------------------
  90. /**
  91. * Number of fields in the result set
  92. *
  93. * @return int
  94. */
  95. public function num_fields()
  96. {
  97. $count = oci_num_fields($this->stmt_id);
  98. // if we used a limit we subtract it
  99. return ($this->limit_used) ? $count - 1 : $count;
  100. }
  101. // --------------------------------------------------------------------
  102. /**
  103. * Fetch Field Names
  104. *
  105. * Generates an array of column names
  106. *
  107. * @return array
  108. */
  109. public function list_fields()
  110. {
  111. $field_names = array();
  112. for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++)
  113. {
  114. $field_names[] = oci_field_name($this->stmt_id, $c);
  115. }
  116. return $field_names;
  117. }
  118. // --------------------------------------------------------------------
  119. /**
  120. * Field data
  121. *
  122. * Generates an array of objects containing field meta-data
  123. *
  124. * @return array
  125. */
  126. public function field_data()
  127. {
  128. $retval = array();
  129. for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++)
  130. {
  131. $F = new stdClass();
  132. $F->name = oci_field_name($this->stmt_id, $c);
  133. $F->type = oci_field_type($this->stmt_id, $c);
  134. $F->max_length = oci_field_size($this->stmt_id, $c);
  135. $retval[] = $F;
  136. }
  137. return $retval;
  138. }
  139. // --------------------------------------------------------------------
  140. /**
  141. * Free the result
  142. *
  143. * @return void
  144. */
  145. public function free_result()
  146. {
  147. if (is_resource($this->result_id))
  148. {
  149. oci_free_statement($this->result_id);
  150. $this->result_id = FALSE;
  151. }
  152. if (is_resource($this->stmt_id))
  153. {
  154. oci_free_statement($this->stmt_id);
  155. }
  156. if (is_resource($this->curs_id))
  157. {
  158. oci_cancel($this->curs_id);
  159. $this->curs_id = NULL;
  160. }
  161. }
  162. // --------------------------------------------------------------------
  163. /**
  164. * Result - associative array
  165. *
  166. * Returns the result set as an array
  167. *
  168. * @return array
  169. */
  170. protected function _fetch_assoc()
  171. {
  172. $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
  173. return oci_fetch_assoc($id);
  174. }
  175. // --------------------------------------------------------------------
  176. /**
  177. * Result - object
  178. *
  179. * Returns the result set as an object
  180. *
  181. * @param string $class_name
  182. * @return object
  183. */
  184. protected function _fetch_object($class_name = 'stdClass')
  185. {
  186. $row = ($this->curs_id)
  187. ? oci_fetch_object($this->curs_id)
  188. : oci_fetch_object($this->stmt_id);
  189. if ($class_name === 'stdClass' OR ! $row)
  190. {
  191. return $row;
  192. }
  193. $class_name = new $class_name();
  194. foreach ($row as $key => $value)
  195. {
  196. $class_name->$key = $value;
  197. }
  198. return $class_name;
  199. }
  200. }