blob: 437adf28e40630fcf067232bac16374a27fe6d05 [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
Andrey Andreev8ae24c52012-01-16 13:05:23 +02002/**
3 * CodeIgniter
4 *
vlakofffe832492012-07-13 20:40:06 +02005 * An open source application development framework for PHP 5.2.4 or newer
Andrey Andreev8ae24c52012-01-16 13:05:23 +02006 *
7 * 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
Andrey Andreevf20fb982012-01-24 15:26:01 +020012 * bundled with this package in the files license.txt / license.rst. It is
Andrey Andreev8ae24c52012-01-16 13:05:23 +020013 * 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 *
Andrey Andreevd947eba2012-04-09 14:58:28 +030019 * @package CodeIgniter
20 * @author EllisLab Dev Team
Andrey Andreev8ae24c52012-01-16 13:05:23 +020021 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
Andrey Andreevd947eba2012-04-09 14:58:28 +030022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
23 * @link http://codeigniter.com
24 * @since Version 1.0
Andrey Andreev8ae24c52012-01-16 13:05:23 +020025 * @filesource
26 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020027defined('BASEPATH') OR exit('No direct script access allowed');
Andrey Andreev8ae24c52012-01-16 13:05:23 +020028
29/**
Andrey Andreev9a4f3562012-07-06 11:57:37 +030030 * SQLite3 Result Class
Andrey Andreev8ae24c52012-01-16 13:05:23 +020031 *
32 * This class extends the parent result class: CI_DB_result
33 *
34 * @category Database
Andrey Andreev9a4f3562012-07-06 11:57:37 +030035 * @author Andrey Andreev
36 * @link http://codeigniter.com/user_guide/database/
Andrey Andreev5ca05132012-07-05 12:06:34 +030037 * @since 3.0
Andrey Andreev8ae24c52012-01-16 13:05:23 +020038 */
39class CI_DB_sqlite3_result extends CI_DB_result {
40
Andrey Andreev8ae24c52012-01-16 13:05:23 +020041 // num_fields() might be called multiple times, so we'll use this one to cache it's result
42 protected $_num_fields;
43
44 /**
Andrey Andreev8ae24c52012-01-16 13:05:23 +020045 * Number of fields in the result set
46 *
47 * @return int
48 */
49 public function num_fields()
50 {
51 return ( ! is_int($this->_num_fields))
52 ? $this->_num_fields = $this->result_id->numColumns()
53 : $this->_num_fields;
54 }
55
56 // --------------------------------------------------------------------
57
58 /**
59 * Fetch Field Names
60 *
61 * Generates an array of column names
62 *
63 * @return array
64 */
65 public function list_fields()
66 {
67 $field_names = array();
Andrey Andreev53921ca2012-01-16 14:35:22 +020068 for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
Andrey Andreev8ae24c52012-01-16 13:05:23 +020069 {
70 $field_names[] = $this->result_id->columnName($i);
71 }
72
73 return $field_names;
74 }
75
76 // --------------------------------------------------------------------
77
78 /**
79 * Field data
80 *
81 * Generates an array of objects containing field meta-data
82 *
83 * @return array
84 */
85 public function field_data()
86 {
87 $retval = array();
88 for ($i = 0, $c = $this->num_fields(); $i < $this->num_fields(); $i++)
89 {
90 $retval[$i] = new stdClass();
91 $retval[$i]->name = $this->result_id->columnName($i);
92 $retval[$i]->type = 'varchar';
93 $retval[$i]->max_length = 0;
94 $retval[$i]->primary_key = 0;
95 $retval[$i]->default = '';
96 }
97
98 return $retval;
99 }
100
101 // --------------------------------------------------------------------
102
103 /**
104 * Free the result
105 *
106 * @return void
107 */
108 public function free_result()
109 {
110 if (is_object($this->result_id))
111 {
112 $this->result_id->finalize();
113 $this->result_id = NULL;
114 }
115 }
116
117 // --------------------------------------------------------------------
118
119 /**
120 * Result - associative array
121 *
122 * Returns the result set as an array
123 *
124 * @return array
125 */
126 protected function _fetch_assoc()
127 {
128 return $this->result_id->fetchArray(SQLITE3_ASSOC);
129 }
130
131 // --------------------------------------------------------------------
132
133 /**
134 * Result - object
135 *
136 * Returns the result set as an object
137 *
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300138 * @param string
Andrey Andreev8ae24c52012-01-16 13:05:23 +0200139 * @return object
140 */
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300141 protected function _fetch_object($class_name = 'stdClass')
Andrey Andreev8ae24c52012-01-16 13:05:23 +0200142 {
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300143 // No native support for fetching rows as objects
144 if (($row = $this->result_id->fetchArray(SQLITE3_ASSOC)) === FALSE)
145 {
146 return FALSE;
147 }
148 elseif ($class_name === 'stdClass')
149 {
150 return (object) $row;
151 }
152
153 $class_name = new $class_name();
154 foreach (array_keys($row) as $key)
155 {
156 $class_name->$key = $row[$key];
157 }
158
159 return $class_name;
Andrey Andreev8ae24c52012-01-16 13:05:23 +0200160 }
161
162 // --------------------------------------------------------------------
163
164 /**
Andrey Andreev8ae24c52012-01-16 13:05:23 +0200165 * Data Seek
166 *
167 * Moves the internal pointer to the desired offset. We call
168 * this internally before fetching results to make sure the
169 * result set starts at zero
170 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300171 * @param $n = 0 (ignored)
Andrey Andreev8ae24c52012-01-16 13:05:23 +0200172 * @return array
173 */
Andrey Andreevf944d3b2012-03-20 22:12:55 +0200174 protected function _data_seek($n = 0)
Andrey Andreev8ae24c52012-01-16 13:05:23 +0200175 {
176 // Only resetting to the start of the result set is supported
177 return $this->result_id->reset();
178 }
179
180}
181
182/* End of file sqlite3_result.php */
Andrey Andreevf944d3b2012-03-20 22:12:55 +0200183/* Location: ./system/database/drivers/sqlite3/sqlite3_result.php */