Verzeichnisstruktur phpBB-3.1.0
- Veröffentlicht
- 27.10.2014
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
sqlite.php
001 <?php
002 /**
003 *
004 * This file is part of the phpBB Forum Software package.
005 *
006 * @copyright (c) phpBB Limited <https://www.phpbb.com>
007 * @license GNU General Public License, version 2 (GPL-2.0)
008 *
009 * For full copyright and license information, please see
010 * the docs/CREDITS.txt file.
011 *
012 */
013
014 namespace phpbb\db\driver;
015
016 /**
017 * Sqlite Database Abstraction Layer
018 * Minimum Requirement: 2.8.2+
019 */
020 class sqlite extends \phpbb\db\driver\driver
021 {
022 var $connect_error = '';
023
024 /**
025 * {@inheritDoc}
026 */
027 function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false)
028 {
029 $this->persistency = $persistency;
030 $this->user = $sqluser;
031 $this->server = $sqlserver . (($port) ? ':' . $port : '');
032 $this->dbname = $database;
033
034 $error = '';
035 if ($this->persistency)
036 {
037 if (!function_exists('sqlite_popen'))
038 {
039 $this->connect_error = 'sqlite_popen function does not exist, is sqlite extension installed?';
040 return $this->sql_error('');
041 }
042 $this->db_connect_id = @sqlite_popen($this->server, 0666, $error);
043 }
044 else
045 {
046 if (!function_exists('sqlite_open'))
047 {
048 $this->connect_error = 'sqlite_open function does not exist, is sqlite extension installed?';
049 return $this->sql_error('');
050 }
051 $this->db_connect_id = @sqlite_open($this->server, 0666, $error);
052 }
053
054 if ($this->db_connect_id)
055 {
056 @sqlite_query('PRAGMA short_column_names = 1', $this->db_connect_id);
057 // @sqlite_query('PRAGMA encoding = "UTF-8"', $this->db_connect_id);
058 }
059
060 return ($this->db_connect_id) ? true : array('message' => $error);
061 }
062
063 /**
064 * {@inheritDoc}
065 */
066 function sql_server_info($raw = false, $use_cache = true)
067 {
068 global $cache;
069
070 if (!$use_cache || empty($cache) || ($this->sql_server_version = $cache->get('sqlite_version')) === false)
071 {
072 $result = @sqlite_query('SELECT sqlite_version() AS version', $this->db_connect_id);
073 $row = @sqlite_fetch_array($result, SQLITE_ASSOC);
074
075 $this->sql_server_version = (!empty($row['version'])) ? $row['version'] : 0;
076
077 if (!empty($cache) && $use_cache)
078 {
079 $cache->put('sqlite_version', $this->sql_server_version);
080 }
081 }
082
083 return ($raw) ? $this->sql_server_version : 'SQLite ' . $this->sql_server_version;
084 }
085
086 /**
087 * SQL Transaction
088 * @access private
089 */
090 function _sql_transaction($status = 'begin')
091 {
092 switch ($status)
093 {
094 case 'begin':
095 return @sqlite_query('BEGIN', $this->db_connect_id);
096 break;
097
098 case 'commit':
099 return @sqlite_query('COMMIT', $this->db_connect_id);
100 break;
101
102 case 'rollback':
103 return @sqlite_query('ROLLBACK', $this->db_connect_id);
104 break;
105 }
106
107 return true;
108 }
109
110 /**
111 * {@inheritDoc}
112 */
113 function sql_query($query = '', $cache_ttl = 0)
114 {
115 if ($query != '')
116 {
117 global $cache;
118
119 // EXPLAIN only in extra debug mode
120 if (defined('DEBUG'))
121 {
122 $this->sql_report('start', $query);
123 }
124 else if (defined('PHPBB_DISPLAY_LOAD_TIME'))
125 {
126 $this->curtime = microtime(true);
127 }
128
129 $this->query_result = ($cache && $cache_ttl) ? $cache->sql_load($query) : false;
130 $this->sql_add_num_queries($this->query_result);
131
132 if ($this->query_result === false)
133 {
134 if (($this->query_result = @sqlite_query($query, $this->db_connect_id)) === false)
135 {
136 $this->sql_error($query);
137 }
138
139 if (defined('DEBUG'))
140 {
141 $this->sql_report('stop', $query);
142 }
143 else if (defined('PHPBB_DISPLAY_LOAD_TIME'))
144 {
145 $this->sql_time += microtime(true) - $this->curtime;
146 }
147
148 if ($cache && $cache_ttl)
149 {
150 $this->open_queries[(int) $this->query_result] = $this->query_result;
151 $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
152 }
153 else if (strpos($query, 'SELECT') === 0 && $this->query_result)
154 {
155 $this->open_queries[(int) $this->query_result] = $this->query_result;
156 }
157 }
158 else if (defined('DEBUG'))
159 {
160 $this->sql_report('fromcache', $query);
161 }
162 }
163 else
164 {
165 return false;
166 }
167
168 return $this->query_result;
169 }
170
171 /**
172 * Build LIMIT query
173 */
174 function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
175 {
176 $this->query_result = false;
177
178 // if $total is set to 0 we do not want to limit the number of rows
179 if ($total == 0)
180 {
181 $total = -1;
182 }
183
184 $query .= "\n LIMIT " . ((!empty($offset)) ? $offset . ', ' . $total : $total);
185
186 return $this->sql_query($query, $cache_ttl);
187 }
188
189 /**
190 * {@inheritDoc}
191 */
192 function sql_affectedrows()
193 {
194 return ($this->db_connect_id) ? @sqlite_changes($this->db_connect_id) : false;
195 }
196
197 /**
198 * {@inheritDoc}
199 */
200 function sql_fetchrow($query_id = false)
201 {
202 global $cache;
203
204 if ($query_id === false)
205 {
206 $query_id = $this->query_result;
207 }
208
209 if ($cache && $cache->sql_exists($query_id))
210 {
211 return $cache->sql_fetchrow($query_id);
212 }
213
214 return ($query_id !== false) ? @sqlite_fetch_array($query_id, SQLITE_ASSOC) : false;
215 }
216
217 /**
218 * {@inheritDoc}
219 */
220 function sql_rowseek($rownum, &$query_id)
221 {
222 global $cache;
223
224 if ($query_id === false)
225 {
226 $query_id = $this->query_result;
227 }
228
229 if ($cache && $cache->sql_exists($query_id))
230 {
231 return $cache->sql_rowseek($rownum, $query_id);
232 }
233
234 return ($query_id !== false) ? @sqlite_seek($query_id, $rownum) : false;
235 }
236
237 /**
238 * {@inheritDoc}
239 */
240 function sql_nextid()
241 {
242 return ($this->db_connect_id) ? @sqlite_last_insert_rowid($this->db_connect_id) : false;
243 }
244
245 /**
246 * {@inheritDoc}
247 */
248 function sql_freeresult($query_id = false)
249 {
250 global $cache;
251
252 if ($query_id === false)
253 {
254 $query_id = $this->query_result;
255 }
256
257 if ($cache && !is_object($query_id) && $cache->sql_exists($query_id))
258 {
259 return $cache->sql_freeresult($query_id);
260 }
261
262 return true;
263 }
264
265 /**
266 * {@inheritDoc}
267 */
268 function sql_escape($msg)
269 {
270 return @sqlite_escape_string($msg);
271 }
272
273 /**
274 * {@inheritDoc}
275 *
276 * For SQLite an underscore is a not-known character... this may change with SQLite3
277 */
278 function sql_like_expression($expression)
279 {
280 // Unlike LIKE, GLOB is unfortunately case sensitive.
281 // We only catch * and ? here, not the character map possible on file globbing.
282 $expression = str_replace(array(chr(0) . '_', chr(0) . '%'), array(chr(0) . '?', chr(0) . '*'), $expression);
283
284 $expression = str_replace(array('?', '*'), array("\?", "\*"), $expression);
285 $expression = str_replace(array(chr(0) . "\?", chr(0) . "\*"), array('?', '*'), $expression);
286
287 return 'GLOB \'' . $this->sql_escape($expression) . '\'';
288 }
289
290 /**
291 * {@inheritDoc}
292 *
293 * For SQLite an underscore is a not-known character...
294 */
295 function sql_not_like_expression($expression)
296 {
297 // Unlike NOT LIKE, NOT GLOB is unfortunately case sensitive.
298 // We only catch * and ? here, not the character map possible on file globbing.
299 $expression = str_replace(array(chr(0) . '_', chr(0) . '%'), array(chr(0) . '?', chr(0) . '*'), $expression);
300
301 $expression = str_replace(array('?', '*'), array("\?", "\*"), $expression);
302 $expression = str_replace(array(chr(0) . "\?", chr(0) . "\*"), array('?', '*'), $expression);
303
304 return 'NOT GLOB \'' . $this->sql_escape($expression) . '\'';
305 }
306
307 /**
308 * return sql error array
309 * @access private
310 */
311 function _sql_error()
312 {
313 if (function_exists('sqlite_error_string'))
314 {
315 $error = array(
316 'message' => @sqlite_error_string(@sqlite_last_error($this->db_connect_id)),
317 'code' => @sqlite_last_error($this->db_connect_id),
318 );
319 }
320 else
321 {
322 $error = array(
323 'message' => $this->connect_error,
324 'code' => '',
325 );
326 }
327
328 return $error;
329 }
330
331 /**
332 * Build db-specific query data
333 * @access private
334 */
335 function _sql_custom_build($stage, $data)
336 {
337 return $data;
338 }
339
340 /**
341 * Close sql connection
342 * @access private
343 */
344 function _sql_close()
345 {
346 return @sqlite_close($this->db_connect_id);
347 }
348
349 /**
350 * Build db-specific report
351 * @access private
352 */
353 function _sql_report($mode, $query = '')
354 {
355 switch ($mode)
356 {
357 case 'start':
358 break;
359
360 case 'fromcache':
361 $endtime = explode(' ', microtime());
362 $endtime = $endtime[0] + $endtime[1];
363
364 $result = @sqlite_query($query, $this->db_connect_id);
365 while ($void = @sqlite_fetch_array($result, SQLITE_ASSOC))
366 {
367 // Take the time spent on parsing rows into account
368 }
369
370 $splittime = explode(' ', microtime());
371 $splittime = $splittime[0] + $splittime[1];
372
373 $this->sql_report('record_fromcache', $query, $endtime, $splittime);
374
375 break;
376 }
377 }
378 }
379