blob: 4af80abf706d49b57e7ec9948234e086174fe823 [file] [log] [blame]
Andrey Andreevf4ebb0e2012-03-20 16:52:56 +02001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Andrey Andreevf4ebb0e2012-03-20 16:52:56 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreevf4ebb0e2012-03-20 16:52:56 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * 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
Greg Aker0defe5d2012-01-01 18:46:41 -060021 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @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
Derek Allard2067d1a2008-11-13 22:59:24 +000028/**
29 * SQLite Result Class
30 *
31 * This class extends the parent result class: CI_DB_result
32 *
33 * @category Database
Derek Jonesf4a4bd82011-10-20 12:18:42 -050034 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000035 * @link http://codeigniter.com/user_guide/database/
36 */
37class CI_DB_sqlite_result extends CI_DB_result {
Barry Mienydd671972010-10-04 16:33:58 +020038
Derek Allard2067d1a2008-11-13 22:59:24 +000039 /**
40 * Number of rows in the result set
41 *
Andrey Andreevf4ebb0e2012-03-20 16:52:56 +020042 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +000043 */
Andrey Andreevf4ebb0e2012-03-20 16:52:56 +020044 public function num_rows()
Derek Allard2067d1a2008-11-13 22:59:24 +000045 {
46 return @sqlite_num_rows($this->result_id);
47 }
Barry Mienydd671972010-10-04 16:33:58 +020048
Derek Allard2067d1a2008-11-13 22:59:24 +000049 // --------------------------------------------------------------------
50
51 /**
52 * Number of fields in the result set
53 *
Andrey Andreevf4ebb0e2012-03-20 16:52:56 +020054 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +000055 */
Andrey Andreevf4ebb0e2012-03-20 16:52:56 +020056 public function num_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +000057 {
58 return @sqlite_num_fields($this->result_id);
59 }
60
61 // --------------------------------------------------------------------
62
63 /**
64 * Fetch Field Names
65 *
66 * Generates an array of column names
67 *
Derek Allard2067d1a2008-11-13 22:59:24 +000068 * @return array
69 */
Andrey Andreevf4ebb0e2012-03-20 16:52:56 +020070 public function list_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +000071 {
72 $field_names = array();
Andrey Andreev22b9e5f2012-03-29 11:30:33 +030073 for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +000074 {
Andrey Andreev22b9e5f2012-03-29 11:30:33 +030075 $field_names[$i] = sqlite_field_name($this->result_id, $i);
Derek Allard2067d1a2008-11-13 22:59:24 +000076 }
Barry Mienydd671972010-10-04 16:33:58 +020077
Derek Allard2067d1a2008-11-13 22:59:24 +000078 return $field_names;
79 }
80
81 // --------------------------------------------------------------------
82
83 /**
84 * Field data
85 *
86 * Generates an array of objects containing field meta-data
87 *
Derek Allard2067d1a2008-11-13 22:59:24 +000088 * @return array
89 */
Andrey Andreevf4ebb0e2012-03-20 16:52:56 +020090 public function field_data()
Derek Allard2067d1a2008-11-13 22:59:24 +000091 {
92 $retval = array();
Andrey Andreev22b9e5f2012-03-29 11:30:33 +030093 for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +000094 {
Andrey Andreev22b9e5f2012-03-29 11:30:33 +030095 $retval[$i] = new stdClass();
96 $retval[$i]->name = sqlite_field_name($this->result_id, $i);
97 $retval[$i]->type = 'varchar';
98 $retval[$i]->max_length = 0;
99 $retval[$i]->primary_key = 0;
100 $retval[$i]->default = '';
Derek Allard2067d1a2008-11-13 22:59:24 +0000101 }
Barry Mienydd671972010-10-04 16:33:58 +0200102
Derek Allard2067d1a2008-11-13 22:59:24 +0000103 return $retval;
104 }
105
106 // --------------------------------------------------------------------
107
108 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000109 * Data Seek
110 *
Andrey Andreevf4ebb0e2012-03-20 16:52:56 +0200111 * Moves the internal pointer to the desired offset. We call
Derek Allard2067d1a2008-11-13 22:59:24 +0000112 * this internally before fetching results to make sure the
113 * result set starts at zero
114 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000115 * @return array
116 */
Andrey Andreevf4ebb0e2012-03-20 16:52:56 +0200117 protected function _data_seek($n = 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000118 {
119 return sqlite_seek($this->result_id, $n);
120 }
121
122 // --------------------------------------------------------------------
123
124 /**
125 * Result - associative array
126 *
127 * Returns the result set as an array
128 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000129 * @return array
130 */
Andrey Andreevf4ebb0e2012-03-20 16:52:56 +0200131 protected function _fetch_assoc()
Derek Allard2067d1a2008-11-13 22:59:24 +0000132 {
133 return sqlite_fetch_array($this->result_id);
134 }
Barry Mienydd671972010-10-04 16:33:58 +0200135
Derek Allard2067d1a2008-11-13 22:59:24 +0000136 // --------------------------------------------------------------------
137
138 /**
139 * Result - object
140 *
141 * Returns the result set as an object
142 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000143 * @return object
144 */
Andrey Andreevf4ebb0e2012-03-20 16:52:56 +0200145 protected function _fetch_object()
Derek Allard2067d1a2008-11-13 22:59:24 +0000146 {
147 if (function_exists('sqlite_fetch_object'))
148 {
149 return sqlite_fetch_object($this->result_id);
150 }
Andrey Andreev22b9e5f2012-03-29 11:30:33 +0300151
152 $arr = sqlite_fetch_array($this->result_id, SQLITE_ASSOC);
153 return is_array($arr) ? (object) $arr : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000154 }
155
156}
157
Derek Allard2067d1a2008-11-13 22:59:24 +0000158/* End of file sqlite_result.php */
Derek Jonesa3ffbbb2008-05-11 18:18:29 +0000159/* Location: ./system/database/drivers/sqlite/sqlite_result.php */