blob: b8f3dc5b7feb654408704ab840165e69204d9f73 [file] [log] [blame]
Derek Allardd2df9bc2007-04-15 17:41:17 +00001<?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
Derek Allard3d879d52008-01-18 19:41:32 +00008 * @author ExpressionEngine Dev Team
Derek Allardd2df9bc2007-04-15 17:41:17 +00009 * @copyright Copyright (c) 2006, EllisLab, Inc.
Derek Jones7a9193a2008-01-21 18:39:20 +000010 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
Derek Allardd2df9bc2007-04-15 17:41:17 +000012 * @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 Allard3d879d52008-01-18 19:41:32 +000024 * @author ExpressionEngine Dev Team
Derek Jones7a9193a2008-01-21 18:39:20 +000025 * @link http://codeigniter.com/user_guide/database/
Derek Allardd2df9bc2007-04-15 17:41:17 +000026 */
27class 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 Allardaa7f7692007-12-20 14:38:56 +000068 $field_names[] = sqlite_field_name($this->result_id, $i);
Derek Allardd2df9bc2007-04-15 17:41:17 +000069 }
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 Allard39b622d2008-01-16 21:10:09 +0000170 $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 Allardd2df9bc2007-04-15 17:41:17 +0000178 }
179 }
180
181}
182
admin7b613c72006-09-24 18:05:17 +0000183?>