/halogy/database/drivers/oci8/oci8_result.php

https://bitbucket.org/haloweb/halogy-1.0/ · PHP · 249 lines · 105 code · 37 blank · 107 comment · 10 complexity · 160af06bf11e49791312ed84ceed47bc MD5 · raw file

  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * CodeIgniter
  4. *
  5. * An open source application development framework for PHP 4.3.2 or newer
  6. *
  7. * @package CodeIgniter
  8. * @author ExpressionEngine Dev Team
  9. * @copyright Copyright (c) 2008 - 2009, 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. var $stmt_id;
  27. var $curs_id;
  28. var $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. *
  36. * @access public
  37. * @return integer
  38. */
  39. function num_rows()
  40. {
  41. $rowcount = count($this->result_array());
  42. @ociexecute($this->stmt_id);
  43. if ($this->curs_id)
  44. {
  45. @ociexecute($this->curs_id);
  46. }
  47. return $rowcount;
  48. }
  49. // --------------------------------------------------------------------
  50. /**
  51. * Number of fields in the result set
  52. *
  53. * @access public
  54. * @return integer
  55. */
  56. function num_fields()
  57. {
  58. $count = @ocinumcols($this->stmt_id);
  59. // if we used a limit we subtract it
  60. if ($this->limit_used)
  61. {
  62. $count = $count - 1;
  63. }
  64. return $count;
  65. }
  66. // --------------------------------------------------------------------
  67. /**
  68. * Fetch Field Names
  69. *
  70. * Generates an array of column names
  71. *
  72. * @access public
  73. * @return array
  74. */
  75. function list_fields()
  76. {
  77. $field_names = array();
  78. $fieldCount = $this->num_fields();
  79. for ($c = 1; $c <= $fieldCount; $c++)
  80. {
  81. $field_names[] = ocicolumnname($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. function field_data()
  95. {
  96. $retval = array();
  97. $fieldCount = $this->num_fields();
  98. for ($c = 1; $c <= $fieldCount; $c++)
  99. {
  100. $F = new stdClass();
  101. $F->name = ocicolumnname($this->stmt_id, $c);
  102. $F->type = ocicolumntype($this->stmt_id, $c);
  103. $F->max_length = ocicolumnsize($this->stmt_id, $c);
  104. $retval[] = $F;
  105. }
  106. return $retval;
  107. }
  108. // --------------------------------------------------------------------
  109. /**
  110. * Free the result
  111. *
  112. * @return null
  113. */
  114. function free_result()
  115. {
  116. if (is_resource($this->result_id))
  117. {
  118. ocifreestatement($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 private
  129. * @return array
  130. */
  131. function _fetch_assoc(&$row)
  132. {
  133. $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
  134. return ocifetchinto($id, $row, OCI_ASSOC + OCI_RETURN_NULLS);
  135. }
  136. // --------------------------------------------------------------------
  137. /**
  138. * Result - object
  139. *
  140. * Returns the result set as an object
  141. *
  142. * @access private
  143. * @return object
  144. */
  145. function _fetch_object()
  146. {
  147. $result = array();
  148. // If PHP 5 is being used we can fetch an result object
  149. if (function_exists('oci_fetch_object'))
  150. {
  151. $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
  152. return @oci_fetch_object($id);
  153. }
  154. // If PHP 4 is being used we have to build our own result
  155. foreach ($this->result_array() as $key => $val)
  156. {
  157. $obj = new stdClass();
  158. if (is_array($val))
  159. {
  160. foreach ($val as $k => $v)
  161. {
  162. $obj->$k = $v;
  163. }
  164. }
  165. else
  166. {
  167. $obj->$key = $val;
  168. }
  169. $result[] = $obj;
  170. }
  171. return $result;
  172. }
  173. // --------------------------------------------------------------------
  174. /**
  175. * Query result. "array" version.
  176. *
  177. * @access public
  178. * @return array
  179. */
  180. function result_array()
  181. {
  182. if (count($this->result_array) > 0)
  183. {
  184. return $this->result_array;
  185. }
  186. // oracle's fetch functions do not return arrays.
  187. // The information is returned in reference parameters
  188. $row = NULL;
  189. while ($this->_fetch_assoc($row))
  190. {
  191. $this->result_array[] = $row;
  192. }
  193. return $this->result_array;
  194. }
  195. // --------------------------------------------------------------------
  196. /**
  197. * Data Seek
  198. *
  199. * Moves the internal pointer to the desired offset. We call
  200. * this internally before fetching results to make sure the
  201. * result set starts at zero
  202. *
  203. * @access private
  204. * @return array
  205. */
  206. function _data_seek($n = 0)
  207. {
  208. return FALSE; // Not needed
  209. }
  210. }
  211. /* End of file oci8_result.php */
  212. /* Location: ./system/database/drivers/oci8/oci8_result.php */