blob: 24f02a8b4395b021e4d62c71bd815a76489fe3cd [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
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 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020027defined('BASEPATH') OR exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +000028
Derek Allard2067d1a2008-11-13 22:59:24 +000029/**
30 * SQLite Result Class
31 *
32 * This class extends the parent result class: CI_DB_result
33 *
34 * @category Database
Derek Jonesf4a4bd82011-10-20 12:18:42 -050035 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000036 * @link http://codeigniter.com/user_guide/database/
Andrey Andreevc7db6bb2012-07-05 15:11:20 +030037 * @since 1.3
Derek Allard2067d1a2008-11-13 22:59:24 +000038 */
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 *
Andrey Andreevf4ebb0e2012-03-20 16:52:56 +020044 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +000045 */
Andrey Andreevf4ebb0e2012-03-20 16:52:56 +020046 public function num_rows()
Derek Allard2067d1a2008-11-13 22:59:24 +000047 {
Andrey Andreevc7db6bb2012-07-05 15:11:20 +030048 return is_int($this->num_rows)
49 ? $this->num_rows
50 : $this->num_rows = @sqlite_num_rows($this->result_id);
Derek Allard2067d1a2008-11-13 22:59:24 +000051 }
Barry Mienydd671972010-10-04 16:33:58 +020052
Derek Allard2067d1a2008-11-13 22:59:24 +000053 // --------------------------------------------------------------------
54
55 /**
56 * Number of fields in the result set
57 *
Andrey Andreevf4ebb0e2012-03-20 16:52:56 +020058 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +000059 */
Andrey Andreevf4ebb0e2012-03-20 16:52:56 +020060 public function num_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +000061 {
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 *
Derek Allard2067d1a2008-11-13 22:59:24 +000072 * @return array
73 */
Andrey Andreevf4ebb0e2012-03-20 16:52:56 +020074 public function list_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +000075 {
76 $field_names = array();
Andrey Andreev22b9e5f2012-03-29 11:30:33 +030077 for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +000078 {
Andrey Andreev22b9e5f2012-03-29 11:30:33 +030079 $field_names[$i] = sqlite_field_name($this->result_id, $i);
Derek Allard2067d1a2008-11-13 22:59:24 +000080 }
Barry Mienydd671972010-10-04 16:33:58 +020081
Derek Allard2067d1a2008-11-13 22:59:24 +000082 return $field_names;
83 }
84
85 // --------------------------------------------------------------------
86
87 /**
88 * Field data
89 *
90 * Generates an array of objects containing field meta-data
91 *
Derek Allard2067d1a2008-11-13 22:59:24 +000092 * @return array
93 */
Andrey Andreevf4ebb0e2012-03-20 16:52:56 +020094 public function field_data()
Derek Allard2067d1a2008-11-13 22:59:24 +000095 {
96 $retval = array();
Andrey Andreev22b9e5f2012-03-29 11:30:33 +030097 for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +000098 {
Andrey Andreev22b9e5f2012-03-29 11:30:33 +030099 $retval[$i] = new stdClass();
100 $retval[$i]->name = sqlite_field_name($this->result_id, $i);
Andrey Andreev822e74e2012-11-16 02:33:30 +0200101 $retval[$i]->type = NULL;
102 $retval[$i]->max_length = NULL;
Derek Allard2067d1a2008-11-13 22:59:24 +0000103 }
Barry Mienydd671972010-10-04 16:33:58 +0200104
Derek Allard2067d1a2008-11-13 22:59:24 +0000105 return $retval;
106 }
107
108 // --------------------------------------------------------------------
109
110 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000111 * Data Seek
112 *
Andrey Andreevf4ebb0e2012-03-20 16:52:56 +0200113 * Moves the internal pointer to the desired offset. We call
Derek Allard2067d1a2008-11-13 22:59:24 +0000114 * this internally before fetching results to make sure the
Andrey Andreev8463b912012-11-02 02:16:28 +0200115 * result set starts at zero.
Derek Allard2067d1a2008-11-13 22:59:24 +0000116 *
Andrey Andreev8463b912012-11-02 02:16:28 +0200117 * @param int $n
Andrey Andreev8f3566f2012-04-12 14:30:05 +0300118 * @return bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000119 */
Andrey Andreevf4ebb0e2012-03-20 16:52:56 +0200120 protected function _data_seek($n = 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000121 {
122 return sqlite_seek($this->result_id, $n);
123 }
124
125 // --------------------------------------------------------------------
126
127 /**
128 * Result - associative array
129 *
130 * Returns the result set as an array
131 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000132 * @return array
133 */
Andrey Andreevf4ebb0e2012-03-20 16:52:56 +0200134 protected function _fetch_assoc()
Derek Allard2067d1a2008-11-13 22:59:24 +0000135 {
136 return sqlite_fetch_array($this->result_id);
137 }
Barry Mienydd671972010-10-04 16:33:58 +0200138
Derek Allard2067d1a2008-11-13 22:59:24 +0000139 // --------------------------------------------------------------------
140
141 /**
142 * Result - object
143 *
144 * Returns the result set as an object
145 *
Andrey Andreev8463b912012-11-02 02:16:28 +0200146 * @param string $class_name
Derek Allard2067d1a2008-11-13 22:59:24 +0000147 * @return object
148 */
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300149 protected function _fetch_object($class_name = 'stdClass')
Derek Allard2067d1a2008-11-13 22:59:24 +0000150 {
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300151 return sqlite_fetch_object($this->result_id, $class_name);
Derek Allard2067d1a2008-11-13 22:59:24 +0000152 }
153
154}
155
Derek Allard2067d1a2008-11-13 22:59:24 +0000156/* End of file sqlite_result.php */
Derek Jonesa3ffbbb2008-05-11 18:18:29 +0000157/* Location: ./system/database/drivers/sqlite/sqlite_result.php */