/halogy/database/drivers/sqlite/sqlite_result.php

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