oci8_result.php 4.4 KB

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