Subversion-Projekte lars-tiefland.ci

Revision

Revision 2257 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
68 lars 1
<?php
2
/**
3
 * CodeIgniter
4
 *
5
 * An open source application development framework for PHP
6
 *
7
 * This content is released under the MIT License (MIT)
8
 *
2414 lars 9
 * Copyright (c) 2014 - 2019, British Columbia Institute of Technology
68 lars 10
 *
11
 * Permission is hereby granted, free of charge, to any person obtaining a copy
12
 * of this software and associated documentation files (the "Software"), to deal
13
 * in the Software without restriction, including without limitation the rights
14
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
 * copies of the Software, and to permit persons to whom the Software is
16
 * furnished to do so, subject to the following conditions:
17
 *
18
 * The above copyright notice and this permission notice shall be included in
19
 * all copies or substantial portions of the Software.
20
 *
21
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27
 * THE SOFTWARE.
28
 *
29
 * @package	CodeIgniter
30
 * @author	EllisLab Dev Team
31
 * @copyright	Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
2414 lars 32
 * @copyright	Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/)
33
 * @license	https://opensource.org/licenses/MIT	MIT License
68 lars 34
 * @link	https://codeigniter.com
35
 * @since	Version 3.0.0
36
 * @filesource
37
 */
38
defined('BASEPATH') OR exit('No direct script access allowed');
39
 
40
/**
41
 * PDO SQLite Database Adapter Class
42
 *
43
 * Note: _DB is an extender class that the app controller
44
 * creates dynamically based on whether the query builder
45
 * class is being used or not.
46
 *
47
 * @package		CodeIgniter
48
 * @subpackage	Drivers
49
 * @category	Database
50
 * @author		EllisLab Dev Team
51
 * @link		https://codeigniter.com/user_guide/database/
52
 */
53
class CI_DB_pdo_sqlite_driver extends CI_DB_pdo_driver {
54
 
55
	/**
56
	 * Sub-driver
57
	 *
58
	 * @var	string
59
	 */
60
	public $subdriver = 'sqlite';
61
 
62
	// --------------------------------------------------------------------
63
 
64
	/**
65
	 * ORDER BY random keyword
66
	 *
67
	 * @var	array
68
	 */
2049 lars 69
	protected $_random_keyword = array('RANDOM()', 'RANDOM()');
68 lars 70
 
71
	// --------------------------------------------------------------------
72
 
73
	/**
74
	 * Class constructor
75
	 *
76
	 * Builds the DSN if not already set.
77
	 *
78
	 * @param	array	$params
79
	 * @return	void
80
	 */
81
	public function __construct($params)
82
	{
83
		parent::__construct($params);
84
 
85
		if (empty($this->dsn))
86
		{
87
			$this->dsn = 'sqlite:';
88
 
89
			if (empty($this->database) && empty($this->hostname))
90
			{
91
				$this->database = ':memory:';
92
			}
93
 
94
			$this->database = empty($this->database) ? $this->hostname : $this->database;
95
		}
96
	}
97
 
98
	// --------------------------------------------------------------------
99
 
100
	/**
101
	 * Show table query
102
	 *
103
	 * Generates a platform-specific query string so that the table names can be fetched
104
	 *
105
	 * @param	bool	$prefix_limit
106
	 * @return	string
107
	 */
108
	protected function _list_tables($prefix_limit = FALSE)
109
	{
110
		$sql = 'SELECT "NAME" FROM "SQLITE_MASTER" WHERE "TYPE" = \'table\'';
111
 
112
		if ($prefix_limit === TRUE && $this->dbprefix !== '')
113
		{
114
			return $sql.' AND "NAME" LIKE \''.$this->escape_like_str($this->dbprefix)."%' "
115
				.sprintf($this->_like_escape_str, $this->_like_escape_chr);
116
		}
117
 
118
		return $sql;
119
	}
120
 
121
	// --------------------------------------------------------------------
122
 
123
	/**
124
	 * Fetch Field Names
125
	 *
126
	 * @param	string	$table	Table name
127
	 * @return	array
128
	 */
129
	public function list_fields($table)
130
	{
131
		if (($result = $this->query('PRAGMA TABLE_INFO('.$this->protect_identifiers($table, TRUE, NULL, FALSE).')')) === FALSE)
132
		{
133
			return FALSE;
134
		}
135
 
2414 lars 136
		$fields = array();
68 lars 137
		foreach ($result->result_array() as $row)
138
		{
2414 lars 139
			$fields[] = $row['name'];
68 lars 140
		}
141
 
2414 lars 142
		return $fields;
68 lars 143
	}
144
 
145
	// --------------------------------------------------------------------
146
 
147
	/**
148
	 * Returns an object with field data
149
	 *
150
	 * @param	string	$table
151
	 * @return	array
152
	 */
153
	public function field_data($table)
154
	{
155
		if (($query = $this->query('PRAGMA TABLE_INFO('.$this->protect_identifiers($table, TRUE, NULL, FALSE).')')) === FALSE)
156
		{
157
			return FALSE;
158
		}
159
 
160
		$query = $query->result_array();
161
		if (empty($query))
162
		{
163
			return FALSE;
164
		}
165
 
166
		$retval = array();
167
		for ($i = 0, $c = count($query); $i < $c; $i++)
168
		{
169
			$retval[$i]			= new stdClass();
170
			$retval[$i]->name		= $query[$i]['name'];
171
			$retval[$i]->type		= $query[$i]['type'];
172
			$retval[$i]->max_length		= NULL;
173
			$retval[$i]->default		= $query[$i]['dflt_value'];
174
			$retval[$i]->primary_key	= isset($query[$i]['pk']) ? (int) $query[$i]['pk'] : 0;
175
		}
176
 
177
		return $retval;
178
	}
179
 
180
	// --------------------------------------------------------------------
181
 
182
	/**
183
	 * Replace statement
184
	 *
185
	 * @param	string	$table	Table name
186
	 * @param	array	$keys	INSERT keys
187
	 * @param	array	$values	INSERT values
188
	 * @return 	string
189
	 */
190
	protected function _replace($table, $keys, $values)
191
	{
192
		return 'INSERT OR '.parent::_replace($table, $keys, $values);
193
	}
194
 
195
	// --------------------------------------------------------------------
196
 
197
	/**
198
	 * Truncate statement
199
	 *
200
	 * Generates a platform-specific truncate string from the supplied data
201
	 *
202
	 * If the database does not support the TRUNCATE statement,
203
	 * then this method maps to 'DELETE FROM table'
204
	 *
205
	 * @param	string	$table
206
	 * @return	string
207
	 */
208
	protected function _truncate($table)
209
	{
210
		return 'DELETE FROM '.$table;
211
	}
212
 
213
}