blob: 2bbd1dbc0159cf1f0d17b1517cc748fc143bc62f [file] [log] [blame]
Derek Jones37f4b9c2011-07-01 17:56:50 -05001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Greg Aker741de1c2010-11-10 14:52:57 -06005 * An open source application development framework for PHP 5.1.6 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
8 *
9 * Licensed under the Open Software License version 3.0
10 *
11 * This source file is subject to the Open Software License (OSL 3.0) that is
12 * bundled with this package in the files license.txt / license.rst. It is
13 * also available through the world wide web at this URL:
14 * http://opensource.org/licenses/OSL-3.0
15 * If you did not receive a copy of the license and are unable to obtain it
16 * through the world wide web, please send an email to
17 * licensing@ellislab.com so we can send you a copy immediately.
18 *
Derek Allard2067d1a2008-11-13 22:59:24 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
21 * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
22 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
24 * @since Version 1.0
25 * @filesource
26 */
27
28// ------------------------------------------------------------------------
29
30/**
31 * SQLite Result Class
32 *
33 * This class extends the parent result class: CI_DB_result
34 *
35 * @category Database
Derek Jonesf4a4bd82011-10-20 12:18:42 -050036 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000037 * @link http://codeigniter.com/user_guide/database/
38 */
39class CI_DB_sqlite_result extends CI_DB_result {
Barry Mienydd671972010-10-04 16:33:58 +020040
Derek Allard2067d1a2008-11-13 22:59:24 +000041 /**
42 * Number of rows in the result set
43 *
44 * @access public
45 * @return integer
46 */
47 function num_rows()
48 {
49 return @sqlite_num_rows($this->result_id);
50 }
Barry Mienydd671972010-10-04 16:33:58 +020051
Derek Allard2067d1a2008-11-13 22:59:24 +000052 // --------------------------------------------------------------------
53
54 /**
55 * Number of fields in the result set
56 *
57 * @access public
58 * @return integer
59 */
60 function num_fields()
61 {
62 return @sqlite_num_fields($this->result_id);
63 }
64
65 // --------------------------------------------------------------------
66
67 /**
68 * Fetch Field Names
69 *
70 * Generates an array of column names
71 *
72 * @access public
73 * @return array
74 */
75 function list_fields()
76 {
77 $field_names = array();
78 for ($i = 0; $i < $this->num_fields(); $i++)
79 {
80 $field_names[] = sqlite_field_name($this->result_id, $i);
81 }
Barry Mienydd671972010-10-04 16:33:58 +020082
Derek Allard2067d1a2008-11-13 22:59:24 +000083 return $field_names;
84 }
85
86 // --------------------------------------------------------------------
87
88 /**
89 * Field data
90 *
91 * Generates an array of objects containing field meta-data
92 *
93 * @access public
94 * @return array
95 */
96 function field_data()
97 {
98 $retval = array();
99 for ($i = 0; $i < $this->num_fields(); $i++)
100 {
Barry Mienydd671972010-10-04 16:33:58 +0200101 $F = new stdClass();
102 $F->name = sqlite_field_name($this->result_id, $i);
103 $F->type = 'varchar';
Derek Allard2067d1a2008-11-13 22:59:24 +0000104 $F->max_length = 0;
105 $F->primary_key = 0;
106 $F->default = '';
107
108 $retval[] = $F;
109 }
Barry Mienydd671972010-10-04 16:33:58 +0200110
Derek Allard2067d1a2008-11-13 22:59:24 +0000111 return $retval;
112 }
113
114 // --------------------------------------------------------------------
115
116 /**
117 * Free the result
118 *
119 * @return null
Barry Mienydd671972010-10-04 16:33:58 +0200120 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000121 function free_result()
122 {
123 // Not implemented in SQLite
124 }
125
126 // --------------------------------------------------------------------
127
128 /**
129 * Data Seek
130 *
Derek Jones37f4b9c2011-07-01 17:56:50 -0500131 * Moves the internal pointer to the desired offset. We call
Derek Allard2067d1a2008-11-13 22:59:24 +0000132 * this internally before fetching results to make sure the
133 * result set starts at zero
134 *
135 * @access private
136 * @return array
137 */
138 function _data_seek($n = 0)
139 {
140 return sqlite_seek($this->result_id, $n);
141 }
142
143 // --------------------------------------------------------------------
144
145 /**
146 * Result - associative array
147 *
148 * Returns the result set as an array
149 *
150 * @access private
151 * @return array
152 */
153 function _fetch_assoc()
154 {
155 return sqlite_fetch_array($this->result_id);
156 }
Barry Mienydd671972010-10-04 16:33:58 +0200157
Derek Allard2067d1a2008-11-13 22:59:24 +0000158 // --------------------------------------------------------------------
159
160 /**
161 * Result - object
162 *
163 * Returns the result set as an object
164 *
165 * @access private
166 * @return object
167 */
168 function _fetch_object()
169 {
170 if (function_exists('sqlite_fetch_object'))
171 {
172 return sqlite_fetch_object($this->result_id);
173 }
174 else
175 {
176 $arr = sqlite_fetch_array($this->result_id, SQLITE_ASSOC);
177 if (is_array($arr))
178 {
179 $obj = (object) $arr;
180 return $obj;
181 } else {
182 return NULL;
Barry Mienydd671972010-10-04 16:33:58 +0200183 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000184 }
185 }
186
187}
188
189
190/* End of file sqlite_result.php */
Derek Jonesa3ffbbb2008-05-11 18:18:29 +0000191/* Location: ./system/database/drivers/sqlite/sqlite_result.php */