cubrid_result.php 4.4 KB

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