Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 2 | /**
|
| 3 | * CodeIgniter
|
| 4 | *
|
| 5 | * An open source application development framework for PHP 4.3.2 or newer
|
| 6 | *
|
| 7 | * @package CodeIgniter
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 8 | * @author ExpressionEngine Dev Team
|
Rick Ellis | 37b3ecf | 2008-09-12 23:34:18 +0000 | [diff] [blame^] | 9 | * @copyright Copyright (c) 2008, EllisLab, Inc.
|
Derek Jones | 7a9193a | 2008-01-21 18:39:20 +0000 | [diff] [blame] | 10 | * @license http://codeigniter.com/user_guide/license.html
|
| 11 | * @link http://codeigniter.com
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 12 | * @since Version 1.0
|
| 13 | * @filesource
|
| 14 | */
|
| 15 |
|
| 16 | // ------------------------------------------------------------------------
|
| 17 |
|
| 18 | /**
|
| 19 | * SQLite Result Class
|
| 20 | *
|
| 21 | * This class extends the parent result class: CI_DB_result
|
| 22 | *
|
| 23 | * @category Database
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 24 | * @author ExpressionEngine Dev Team
|
Derek Jones | 7a9193a | 2008-01-21 18:39:20 +0000 | [diff] [blame] | 25 | * @link http://codeigniter.com/user_guide/database/
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 26 | */
|
| 27 | class CI_DB_sqlite_result extends CI_DB_result {
|
| 28 |
|
| 29 | /**
|
| 30 | * Number of rows in the result set
|
| 31 | *
|
| 32 | * @access public
|
| 33 | * @return integer
|
| 34 | */
|
| 35 | function num_rows()
|
| 36 | {
|
| 37 | return @sqlite_num_rows($this->result_id);
|
| 38 | }
|
| 39 |
|
| 40 | // --------------------------------------------------------------------
|
| 41 |
|
| 42 | /**
|
| 43 | * Number of fields in the result set
|
| 44 | *
|
| 45 | * @access public
|
| 46 | * @return integer
|
| 47 | */
|
| 48 | function num_fields()
|
| 49 | {
|
| 50 | return @sqlite_num_fields($this->result_id);
|
| 51 | }
|
| 52 |
|
| 53 | // --------------------------------------------------------------------
|
| 54 |
|
| 55 | /**
|
| 56 | * Fetch Field Names
|
| 57 | *
|
| 58 | * Generates an array of column names
|
| 59 | *
|
| 60 | * @access public
|
| 61 | * @return array
|
| 62 | */
|
| 63 | function list_fields()
|
| 64 | {
|
| 65 | $field_names = array();
|
| 66 | for ($i = 0; $i < $this->num_fields(); $i++)
|
| 67 | {
|
Derek Allard | aa7f769 | 2007-12-20 14:38:56 +0000 | [diff] [blame] | 68 | $field_names[] = sqlite_field_name($this->result_id, $i);
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 69 | }
|
| 70 |
|
| 71 | return $field_names;
|
| 72 | }
|
| 73 |
|
| 74 | // Deprecated
|
| 75 | function field_names()
|
| 76 | {
|
| 77 | return $this->list_fields();
|
| 78 | }
|
| 79 |
|
| 80 | // --------------------------------------------------------------------
|
| 81 |
|
| 82 | /**
|
| 83 | * Field data
|
| 84 | *
|
| 85 | * Generates an array of objects containing field meta-data
|
| 86 | *
|
| 87 | * @access public
|
| 88 | * @return array
|
| 89 | */
|
| 90 | function field_data()
|
| 91 | {
|
| 92 | $retval = array();
|
| 93 | for ($i = 0; $i < $this->num_fields(); $i++)
|
| 94 | {
|
| 95 | $F = new stdClass();
|
| 96 | $F->name = sqlite_field_name($this->result_id, $i);
|
| 97 | $F->type = 'varchar';
|
| 98 | $F->max_length = 0;
|
| 99 | $F->primary_key = 0;
|
| 100 | $F->default = '';
|
| 101 |
|
| 102 | $retval[] = $F;
|
| 103 | }
|
| 104 |
|
| 105 | return $retval;
|
| 106 | }
|
| 107 |
|
| 108 | // --------------------------------------------------------------------
|
| 109 |
|
| 110 | /**
|
| 111 | * Free the result
|
| 112 | *
|
| 113 | * @return null
|
| 114 | */
|
| 115 | function free_result()
|
| 116 | {
|
| 117 | // Not implemented in SQLite
|
| 118 | }
|
| 119 |
|
| 120 | // --------------------------------------------------------------------
|
| 121 |
|
| 122 | /**
|
| 123 | * Data Seek
|
| 124 | *
|
| 125 | * Moves the internal pointer to the desired offset. We call
|
| 126 | * this internally before fetching results to make sure the
|
| 127 | * result set starts at zero
|
| 128 | *
|
| 129 | * @access private
|
| 130 | * @return array
|
| 131 | */
|
| 132 | function _data_seek($n = 0)
|
| 133 | {
|
| 134 | return sqlite_seek($this->result_id, $n);
|
| 135 | }
|
| 136 |
|
| 137 | // --------------------------------------------------------------------
|
| 138 |
|
| 139 | /**
|
| 140 | * Result - associative array
|
| 141 | *
|
| 142 | * Returns the result set as an array
|
| 143 | *
|
| 144 | * @access private
|
| 145 | * @return array
|
| 146 | */
|
| 147 | function _fetch_assoc()
|
| 148 | {
|
| 149 | return sqlite_fetch_array($this->result_id);
|
| 150 | }
|
| 151 |
|
| 152 | // --------------------------------------------------------------------
|
| 153 |
|
| 154 | /**
|
| 155 | * Result - object
|
| 156 | *
|
| 157 | * Returns the result set as an object
|
| 158 | *
|
| 159 | * @access private
|
| 160 | * @return object
|
| 161 | */
|
| 162 | function _fetch_object()
|
| 163 | {
|
| 164 | if (function_exists('sqlite_fetch_object'))
|
| 165 | {
|
| 166 | return sqlite_fetch_object($this->result_id);
|
| 167 | }
|
| 168 | else
|
| 169 | {
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 170 | $arr = sqlite_fetch_array($this->result_id, SQLITE_ASSOC);
|
| 171 | if (is_array($arr))
|
| 172 | {
|
| 173 | $obj = (object) $arr;
|
| 174 | return $obj;
|
| 175 | } else {
|
| 176 | return NULL;
|
| 177 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 178 | }
|
| 179 | }
|
| 180 |
|
| 181 | }
|
| 182 |
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 183 |
|
| 184 | /* End of file sqlite_result.php */
|
Derek Jones | a3ffbbb | 2008-05-11 18:18:29 +0000 | [diff] [blame] | 185 | /* Location: ./system/database/drivers/sqlite/sqlite_result.php */ |