blob: a406a935cc23ac1ab171ec221cfb3a195b4950a2 [file] [log] [blame]
admin7b613c72006-09-24 18:05:17 +00001<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * Code Igniter
4 *
5 * An open source application development framework for PHP 4.3.2 or newer
6 *
7 * @package CodeIgniter
8 * @author Rick Ellis
9 * @copyright Copyright (c) 2006, pMachine, Inc.
admine334c472006-10-21 19:44:22 +000010 * @license http://www.codeignitor.com/user_guide/license.html
admin7b613c72006-09-24 18:05:17 +000011 * @link http://www.codeigniter.com
12 * @since Version 1.0
13 * @filesource
14 */
admine334c472006-10-21 19:44:22 +000015
admin7b613c72006-09-24 18:05:17 +000016// ------------------------------------------------------------------------
17
18/**
19 * SQLite Result Class
20 *
21 * This class extends the parent result class: CI_DB_result
admine334c472006-10-21 19:44:22 +000022 *
admin7b613c72006-09-24 18:05:17 +000023 * @category Database
24 * @author Rick Ellis
25 * @link http://www.codeigniter.com/user_guide/database/
26 */
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 }
adminab4f61b2006-09-25 22:12:32 +000052
53 // --------------------------------------------------------------------
54
55 /**
56 * Fetch Field Names
57 *
58 * Generates an array of column names
59 *
60 * @access public
61 * @return array
62 */
admin606f99c2006-10-11 23:48:41 +000063 function list_fields()
adminab4f61b2006-09-25 22:12:32 +000064 {
65 $field_names = array();
66 for ($i = 0; $i < $this->num_fields(); $i++)
67 {
68 $Ffield_names[] = sqlite_field_name($this->result_id, $i);
69 }
70
71 return $field_names;
72 }
73
admin606f99c2006-10-11 23:48:41 +000074 // Deprecated
75 function field_names()
76 {
77 return $this->list_fields();
78 }
79
admin7b613c72006-09-24 18:05:17 +000080 // --------------------------------------------------------------------
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 /**
admind2dd0312006-10-05 04:34:38 +0000123 * 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 {
admin1716cb82006-10-25 05:12:34 +0000134 return sqlite_seek($this->result_id, $n);
admind2dd0312006-10-05 04:34:38 +0000135 }
136
137 // --------------------------------------------------------------------
138
139 /**
admin7b613c72006-09-24 18:05:17 +0000140 * 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 {
170 return $this->_fetch_assoc();
171 }
172 }
173
174}
175
176?>