blob: 153e3480a2583197e3e11540753d94d82c3477c3 [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 /**
Andrey Andreev8ae24c52012-01-16 13:05:23 +020042 * Number of fields in the result set
43 *
44 * @return int
45 */
46 public function num_fields()
47 {
Andrey Andreev8463b912012-11-02 02:16:28 +020048 return $this->result_id->numColumns();
Andrey Andreev8ae24c52012-01-16 13:05:23 +020049 }
50
51 // --------------------------------------------------------------------
52
53 /**
54 * Fetch Field Names
55 *
56 * Generates an array of column names
57 *
58 * @return array
59 */
60 public function list_fields()
61 {
62 $field_names = array();
Andrey Andreev53921ca2012-01-16 14:35:22 +020063 for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
Andrey Andreev8ae24c52012-01-16 13:05:23 +020064 {
65 $field_names[] = $this->result_id->columnName($i);
66 }
67
68 return $field_names;
69 }
70
71 // --------------------------------------------------------------------
72
73 /**
74 * Field data
75 *
76 * Generates an array of objects containing field meta-data
77 *
78 * @return array
79 */
80 public function field_data()
81 {
82 $retval = array();
83 for ($i = 0, $c = $this->num_fields(); $i < $this->num_fields(); $i++)
84 {
85 $retval[$i] = new stdClass();
86 $retval[$i]->name = $this->result_id->columnName($i);
87 $retval[$i]->type = 'varchar';
88 $retval[$i]->max_length = 0;
89 $retval[$i]->primary_key = 0;
90 $retval[$i]->default = '';
91 }
92
93 return $retval;
94 }
95
96 // --------------------------------------------------------------------
97
98 /**
99 * Free the result
100 *
101 * @return void
102 */
103 public function free_result()
104 {
105 if (is_object($this->result_id))
106 {
107 $this->result_id->finalize();
108 $this->result_id = NULL;
109 }
110 }
111
112 // --------------------------------------------------------------------
113
114 /**
115 * Result - associative array
116 *
117 * Returns the result set as an array
118 *
119 * @return array
120 */
121 protected function _fetch_assoc()
122 {
123 return $this->result_id->fetchArray(SQLITE3_ASSOC);
124 }
125
126 // --------------------------------------------------------------------
127
128 /**
129 * Result - object
130 *
131 * Returns the result set as an object
132 *
Andrey Andreev8463b912012-11-02 02:16:28 +0200133 * @param string $class_name
Andrey Andreev8ae24c52012-01-16 13:05:23 +0200134 * @return object
135 */
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300136 protected function _fetch_object($class_name = 'stdClass')
Andrey Andreev8ae24c52012-01-16 13:05:23 +0200137 {
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300138 // No native support for fetching rows as objects
139 if (($row = $this->result_id->fetchArray(SQLITE3_ASSOC)) === FALSE)
140 {
141 return FALSE;
142 }
143 elseif ($class_name === 'stdClass')
144 {
145 return (object) $row;
146 }
147
148 $class_name = new $class_name();
149 foreach (array_keys($row) as $key)
150 {
151 $class_name->$key = $row[$key];
152 }
153
154 return $class_name;
Andrey Andreev8ae24c52012-01-16 13:05:23 +0200155 }
156
157 // --------------------------------------------------------------------
158
159 /**
Andrey Andreev8ae24c52012-01-16 13:05:23 +0200160 * Data Seek
161 *
162 * Moves the internal pointer to the desired offset. We call
163 * this internally before fetching results to make sure the
Andrey Andreev8463b912012-11-02 02:16:28 +0200164 * result set starts at zero.
Andrey Andreev8ae24c52012-01-16 13:05:23 +0200165 *
Andrey Andreev8463b912012-11-02 02:16:28 +0200166 * @param int $n (ignored)
Andrey Andreev8ae24c52012-01-16 13:05:23 +0200167 * @return array
168 */
Andrey Andreevf944d3b2012-03-20 22:12:55 +0200169 protected function _data_seek($n = 0)
Andrey Andreev8ae24c52012-01-16 13:05:23 +0200170 {
171 // Only resetting to the start of the result set is supported
172 return $this->result_id->reset();
173 }
174
175}
176
177/* End of file sqlite3_result.php */
Andrey Andreevf944d3b2012-03-20 22:12:55 +0200178/* Location: ./system/database/drivers/sqlite3/sqlite3_result.php */