oci8_result.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * CodeIgniter
  4. *
  5. * An open source application development framework for PHP 5.1.6 or newer
  6. *
  7. * @package CodeIgniter
  8. * @author EllisLab Dev Team
  9. * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc.
  10. * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/)
  11. * @license http://codeigniter.com/user_guide/license.html
  12. * @link http://codeigniter.com
  13. * @since Version 1.0
  14. * @filesource
  15. */
  16. // ------------------------------------------------------------------------
  17. /**
  18. * oci8 Result Class
  19. *
  20. * This class extends the parent result class: CI_DB_result
  21. *
  22. * @category Database
  23. * @author EllisLab Dev Team
  24. * @link http://codeigniter.com/user_guide/database/
  25. */
  26. class CI_DB_oci8_result extends CI_DB_result {
  27. public $stmt_id;
  28. public $curs_id;
  29. public $limit_used;
  30. /**
  31. * Number of rows in the result set.
  32. *
  33. * Oracle doesn't have a graceful way to retun the number of rows
  34. * so we have to use what amounts to a hack.
  35. *
  36. * @return integer
  37. */
  38. public function num_rows()
  39. {
  40. if ($this->num_rows === 0 && count($this->result_array()) > 0)
  41. {
  42. $this->num_rows = count($this->result_array());
  43. @oci_execute($this->stmt_id, OCI_DEFAULT);
  44. if ($this->curs_id)
  45. {
  46. @oci_execute($this->curs_id, OCI_DEFAULT);
  47. }
  48. }
  49. return $this->num_rows;
  50. }
  51. // --------------------------------------------------------------------
  52. /**
  53. * Number of fields in the result set
  54. *
  55. * @access public
  56. * @return integer
  57. */
  58. public function num_fields()
  59. {
  60. $count = @oci_num_fields($this->stmt_id);
  61. // if we used a limit we subtract it
  62. if ($this->limit_used)
  63. {
  64. $count = $count - 1;
  65. }
  66. return $count;
  67. }
  68. // --------------------------------------------------------------------
  69. /**
  70. * Fetch Field Names
  71. *
  72. * Generates an array of column names
  73. *
  74. * @access public
  75. * @return array
  76. */
  77. public function list_fields()
  78. {
  79. $field_names = array();
  80. for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++)
  81. {
  82. $field_names[] = oci_field_name($this->stmt_id, $c);
  83. }
  84. return $field_names;
  85. }
  86. // --------------------------------------------------------------------
  87. /**
  88. * Field data
  89. *
  90. * Generates an array of objects containing field meta-data
  91. *
  92. * @access public
  93. * @return array
  94. */
  95. public function field_data()
  96. {
  97. $retval = array();
  98. for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++)
  99. {
  100. $F = new stdClass();
  101. $F->name = oci_field_name($this->stmt_id, $c);
  102. $F->type = oci_field_type($this->stmt_id, $c);
  103. $F->max_length = oci_field_size($this->stmt_id, $c);
  104. $retval[] = $F;
  105. }
  106. return $retval;
  107. }
  108. // --------------------------------------------------------------------
  109. /**
  110. * Free the result
  111. *
  112. * @return null
  113. */
  114. public function free_result()
  115. {
  116. if (is_resource($this->result_id))
  117. {
  118. oci_free_statement($this->result_id);
  119. $this->result_id = FALSE;
  120. }
  121. }
  122. // --------------------------------------------------------------------
  123. /**
  124. * Result - associative array
  125. *
  126. * Returns the result set as an array
  127. *
  128. * @access protected
  129. * @return array
  130. */
  131. protected function _fetch_assoc()
  132. {
  133. $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
  134. return oci_fetch_assoc($id);
  135. }
  136. // --------------------------------------------------------------------
  137. /**
  138. * Result - object
  139. *
  140. * Returns the result set as an object
  141. *
  142. * @access protected
  143. * @return object
  144. */
  145. protected function _fetch_object()
  146. {
  147. $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
  148. return @oci_fetch_object($id);
  149. }
  150. // --------------------------------------------------------------------
  151. /**
  152. * Query result. "array" version.
  153. *
  154. * @access public
  155. * @return array
  156. */
  157. public function result_array()
  158. {
  159. if (count($this->result_array) > 0)
  160. {
  161. return $this->result_array;
  162. }
  163. $row = NULL;
  164. while ($row = $this->_fetch_assoc())
  165. {
  166. $this->result_array[] = $row;
  167. }
  168. return $this->result_array;
  169. }
  170. // --------------------------------------------------------------------
  171. /**
  172. * Data Seek
  173. *
  174. * Moves the internal pointer to the desired offset. We call
  175. * this internally before fetching results to make sure the
  176. * result set starts at zero
  177. *
  178. * @access protected
  179. * @return array
  180. */
  181. protected function _data_seek($n = 0)
  182. {
  183. return FALSE; // Not needed
  184. }
  185. }
  186. /* End of file oci8_result.php */
  187. /* Location: ./system/database/drivers/oci8/oci8_result.php */