Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 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 |
Derek Jones | 7f3719f | 2010-01-05 13:35:37 +0000 | [diff] [blame] | 9 | * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 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 | |
| 18 | /** |
| 19 | * SQLite Result Class |
| 20 | * |
| 21 | * This class extends the parent result class: CI_DB_result |
| 22 | * |
| 23 | * @category Database |
| 24 | * @author ExpressionEngine Dev Team |
| 25 | * @link http://codeigniter.com/user_guide/database/ |
| 26 | */ |
| 27 | class CI_DB_sqlite_result extends CI_DB_result { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame^] | 28 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 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 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame^] | 39 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 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 | { |
| 68 | $field_names[] = sqlite_field_name($this->result_id, $i); |
| 69 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame^] | 70 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 71 | return $field_names; |
| 72 | } |
| 73 | |
| 74 | // -------------------------------------------------------------------- |
| 75 | |
| 76 | /** |
| 77 | * Field data |
| 78 | * |
| 79 | * Generates an array of objects containing field meta-data |
| 80 | * |
| 81 | * @access public |
| 82 | * @return array |
| 83 | */ |
| 84 | function field_data() |
| 85 | { |
| 86 | $retval = array(); |
| 87 | for ($i = 0; $i < $this->num_fields(); $i++) |
| 88 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame^] | 89 | $F = new stdClass(); |
| 90 | $F->name = sqlite_field_name($this->result_id, $i); |
| 91 | $F->type = 'varchar'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 92 | $F->max_length = 0; |
| 93 | $F->primary_key = 0; |
| 94 | $F->default = ''; |
| 95 | |
| 96 | $retval[] = $F; |
| 97 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame^] | 98 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 99 | return $retval; |
| 100 | } |
| 101 | |
| 102 | // -------------------------------------------------------------------- |
| 103 | |
| 104 | /** |
| 105 | * Free the result |
| 106 | * |
| 107 | * @return null |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame^] | 108 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 109 | function free_result() |
| 110 | { |
| 111 | // Not implemented in SQLite |
| 112 | } |
| 113 | |
| 114 | // -------------------------------------------------------------------- |
| 115 | |
| 116 | /** |
| 117 | * Data Seek |
| 118 | * |
| 119 | * Moves the internal pointer to the desired offset. We call |
| 120 | * this internally before fetching results to make sure the |
| 121 | * result set starts at zero |
| 122 | * |
| 123 | * @access private |
| 124 | * @return array |
| 125 | */ |
| 126 | function _data_seek($n = 0) |
| 127 | { |
| 128 | return sqlite_seek($this->result_id, $n); |
| 129 | } |
| 130 | |
| 131 | // -------------------------------------------------------------------- |
| 132 | |
| 133 | /** |
| 134 | * Result - associative array |
| 135 | * |
| 136 | * Returns the result set as an array |
| 137 | * |
| 138 | * @access private |
| 139 | * @return array |
| 140 | */ |
| 141 | function _fetch_assoc() |
| 142 | { |
| 143 | return sqlite_fetch_array($this->result_id); |
| 144 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame^] | 145 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 146 | // -------------------------------------------------------------------- |
| 147 | |
| 148 | /** |
| 149 | * Result - object |
| 150 | * |
| 151 | * Returns the result set as an object |
| 152 | * |
| 153 | * @access private |
| 154 | * @return object |
| 155 | */ |
| 156 | function _fetch_object() |
| 157 | { |
| 158 | if (function_exists('sqlite_fetch_object')) |
| 159 | { |
| 160 | return sqlite_fetch_object($this->result_id); |
| 161 | } |
| 162 | else |
| 163 | { |
| 164 | $arr = sqlite_fetch_array($this->result_id, SQLITE_ASSOC); |
| 165 | if (is_array($arr)) |
| 166 | { |
| 167 | $obj = (object) $arr; |
| 168 | return $obj; |
| 169 | } else { |
| 170 | return NULL; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame^] | 171 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 172 | } |
| 173 | } |
| 174 | |
| 175 | } |
| 176 | |
| 177 | |
| 178 | /* End of file sqlite_result.php */ |
Derek Jones | a3ffbbb | 2008-05-11 18:18:29 +0000 | [diff] [blame] | 179 | /* Location: ./system/database/drivers/sqlite/sqlite_result.php */ |