cubrid_result.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 2.0.2
  14. * @filesource
  15. */
  16. // --------------------------------------------------------------------
  17. /**
  18. * CUBRID Result Class
  19. *
  20. * This class extends the parent result class: CI_DB_result
  21. *
  22. * @category Database
  23. * @author Esen Sagynov
  24. * @link http://codeigniter.com/user_guide/database/
  25. */
  26. class CI_DB_cubrid_result extends CI_DB_result {
  27. /**
  28. * Number of rows in the result set
  29. *
  30. * @access public
  31. * @return integer
  32. */
  33. function num_rows()
  34. {
  35. return @cubrid_num_rows($this->result_id);
  36. }
  37. // --------------------------------------------------------------------
  38. /**
  39. * Number of fields in the result set
  40. *
  41. * @access public
  42. * @return integer
  43. */
  44. function num_fields()
  45. {
  46. return @cubrid_num_fields($this->result_id);
  47. }
  48. // --------------------------------------------------------------------
  49. /**
  50. * Fetch Field Names
  51. *
  52. * Generates an array of column names
  53. *
  54. * @access public
  55. * @return array
  56. */
  57. function list_fields()
  58. {
  59. return cubrid_column_names($this->result_id);
  60. }
  61. // --------------------------------------------------------------------
  62. /**
  63. * Field data
  64. *
  65. * Generates an array of objects containing field meta-data
  66. *
  67. * @access public
  68. * @return array
  69. */
  70. function field_data()
  71. {
  72. $retval = array();
  73. $tablePrimaryKeys = array();
  74. while ($field = cubrid_fetch_field($this->result_id))
  75. {
  76. $F = new stdClass();
  77. $F->name = $field->name;
  78. $F->type = $field->type;
  79. $F->default = $field->def;
  80. $F->max_length = $field->max_length;
  81. // At this moment primary_key property is not returned when
  82. // cubrid_fetch_field is called. The following code will
  83. // provide a patch for it. primary_key property will be added
  84. // in the next release.
  85. // TODO: later version of CUBRID will provide primary_key
  86. // property.
  87. // When PK is defined in CUBRID, an index is automatically
  88. // created in the db_index system table in the form of
  89. // pk_tblname_fieldname. So the following will count how many
  90. // columns are there which satisfy this format.
  91. // The query will search for exact single columns, thus
  92. // compound PK is not supported.
  93. $res = cubrid_query($this->conn_id,
  94. "SELECT COUNT(*) FROM db_index WHERE class_name = '" . $field->table .
  95. "' AND is_primary_key = 'YES' AND index_name = 'pk_" .
  96. $field->table . "_" . $field->name . "'"
  97. );
  98. if ($res)
  99. {
  100. $row = cubrid_fetch_array($res, CUBRID_NUM);
  101. $F->primary_key = ($row[0] > 0 ? 1 : null);
  102. }
  103. else
  104. {
  105. $F->primary_key = null;
  106. }
  107. if (is_resource($res))
  108. {
  109. cubrid_close_request($res);
  110. $this->result_id = FALSE;
  111. }
  112. $retval[] = $F;
  113. }
  114. return $retval;
  115. }
  116. // --------------------------------------------------------------------
  117. /**
  118. * Free the result
  119. *
  120. * @return null
  121. */
  122. function free_result()
  123. {
  124. if(is_resource($this->result_id) ||
  125. get_resource_type($this->result_id) == "Unknown" &&
  126. preg_match('/Resource id #/', strval($this->result_id)))
  127. {
  128. cubrid_close_request($this->result_id);
  129. $this->result_id = FALSE;
  130. }
  131. }
  132. // --------------------------------------------------------------------
  133. /**
  134. * Data Seek
  135. *
  136. * Moves the internal pointer to the desired offset. We call
  137. * this internally before fetching results to make sure the
  138. * result set starts at zero
  139. *
  140. * @access private
  141. * @return array
  142. */
  143. function _data_seek($n = 0)
  144. {
  145. return cubrid_data_seek($this->result_id, $n);
  146. }
  147. // --------------------------------------------------------------------
  148. /**
  149. * Result - associative array
  150. *
  151. * Returns the result set as an array
  152. *
  153. * @access private
  154. * @return array
  155. */
  156. function _fetch_assoc()
  157. {
  158. return cubrid_fetch_assoc($this->result_id);
  159. }
  160. // --------------------------------------------------------------------
  161. /**
  162. * Result - object
  163. *
  164. * Returns the result set as an object
  165. *
  166. * @access private
  167. * @return object
  168. */
  169. function _fetch_object()
  170. {
  171. return cubrid_fetch_object($this->result_id);
  172. }
  173. }
  174. /* End of file cubrid_result.php */
  175. /* Location: ./system/database/drivers/cubrid/cubrid_result.php */