sqlite_result.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. * SQLite 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_sqlite_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 @sqlite_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 @sqlite_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. $field_names = array();
  60. for ($i = 0; $i < $this->num_fields(); $i++)
  61. {
  62. $field_names[] = sqlite_field_name($this->result_id, $i);
  63. }
  64. return $field_names;
  65. }
  66. // --------------------------------------------------------------------
  67. /**
  68. * Field data
  69. *
  70. * Generates an array of objects containing field meta-data
  71. *
  72. * @access public
  73. * @return array
  74. */
  75. function field_data()
  76. {
  77. $retval = array();
  78. for ($i = 0; $i < $this->num_fields(); $i++)
  79. {
  80. $F = new stdClass();
  81. $F->name = sqlite_field_name($this->result_id, $i);
  82. $F->type = 'varchar';
  83. $F->max_length = 0;
  84. $F->primary_key = 0;
  85. $F->default = '';
  86. $retval[] = $F;
  87. }
  88. return $retval;
  89. }
  90. // --------------------------------------------------------------------
  91. /**
  92. * Free the result
  93. *
  94. * @return null
  95. */
  96. function free_result()
  97. {
  98. // Not implemented in SQLite
  99. }
  100. // --------------------------------------------------------------------
  101. /**
  102. * Data Seek
  103. *
  104. * Moves the internal pointer to the desired offset. We call
  105. * this internally before fetching results to make sure the
  106. * result set starts at zero
  107. *
  108. * @access private
  109. * @return array
  110. */
  111. function _data_seek($n = 0)
  112. {
  113. return sqlite_seek($this->result_id, $n);
  114. }
  115. // --------------------------------------------------------------------
  116. /**
  117. * Result - associative array
  118. *
  119. * Returns the result set as an array
  120. *
  121. * @access private
  122. * @return array
  123. */
  124. function _fetch_assoc()
  125. {
  126. return sqlite_fetch_array($this->result_id);
  127. }
  128. // --------------------------------------------------------------------
  129. /**
  130. * Result - object
  131. *
  132. * Returns the result set as an object
  133. *
  134. * @access private
  135. * @return object
  136. */
  137. function _fetch_object()
  138. {
  139. if (function_exists('sqlite_fetch_object'))
  140. {
  141. return sqlite_fetch_object($this->result_id);
  142. }
  143. else
  144. {
  145. $arr = sqlite_fetch_array($this->result_id, SQLITE_ASSOC);
  146. if (is_array($arr))
  147. {
  148. $obj = (object) $arr;
  149. return $obj;
  150. } else {
  151. return NULL;
  152. }
  153. }
  154. }
  155. }
  156. /* End of file sqlite_result.php */
  157. /* Location: ./system/database/drivers/sqlite/sqlite_result.php */