Verzeichnisstruktur phpBB-3.0.0


Veröffentlicht
12.12.2007

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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

sqlite.php

Zuletzt modifiziert: 09.10.2024, 12:51 - Dateigröße: 6.68 KiB


001  <?php
002  /**
003  *
004  * @package dbal
005  * @version $Id$
006  * @copyright (c) 2005 phpBB Group
007  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
008  *
009  */
010   
011  /**
012  * @ignore
013  */
014  if (!defined('IN_PHPBB'))
015  {
016      exit;
017  }
018   
019  include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
020   
021  /**
022  * Sqlite Database Abstraction Layer
023  * Minimum Requirement: 2.8.2+
024  * @package dbal
025  */
026  class dbal_sqlite extends dbal
027  {
028      /**
029      * Connect to server
030      */
031      function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false)
032      {
033          $this->persistency = $persistency;
034          $this->user = $sqluser;
035          $this->server = $sqlserver . (($port) ? ':' . $port : '');
036          $this->dbname = $database;
037   
038          $error = '';
039          $this->db_connect_id = ($this->persistency) ? @sqlite_popen($this->server, 0666, $error) : @sqlite_open($this->server, 0666, $error);
040   
041          if ($this->db_connect_id)
042          {
043              @sqlite_query('PRAGMA short_column_names = 1', $this->db_connect_id);
044          }
045   
046          
047          return ($this->db_connect_id) ? true : array('message' => $error);
048      }
049   
050      /**
051      * Version information about used database
052      */
053      function sql_server_info()
054      {
055          return 'SQLite ' . @sqlite_libversion();
056      }
057   
058      /**
059      * SQL Transaction
060      * @access private
061      */
062      function _sql_transaction($status = 'begin')
063      {
064          switch ($status)
065          {
066              case 'begin':
067                  return @sqlite_query('BEGIN', $this->db_connect_id);
068              break;
069   
070              case 'commit':
071                  return @sqlite_query('COMMIT', $this->db_connect_id);
072              break;
073   
074              case 'rollback':
075                  return @sqlite_query('ROLLBACK', $this->db_connect_id);
076              break;
077          }
078   
079          return true;
080      }
081   
082      /**
083      * Base query method
084      *
085      * @param    string    $query        Contains the SQL query which shall be executed
086      * @param    int        $cache_ttl    Either 0 to avoid caching or the time in seconds which the result shall be kept in cache
087      * @return    mixed                When casted to bool the returned value returns true on success and false on failure
088      *
089      * @access    public
090      */
091      function sql_query($query = '', $cache_ttl = 0)
092      {
093          if ($query != '')
094          {
095              global $cache;
096   
097              // EXPLAIN only in extra debug mode
098              if (defined('DEBUG_EXTRA'))
099              {
100                  $this->sql_report('start', $query);
101              }
102   
103              $this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
104              $this->sql_add_num_queries($this->query_result);
105   
106              if ($this->query_result === false)
107              {
108                  if (($this->query_result = @sqlite_query($query, $this->db_connect_id)) === false)
109                  {
110                      $this->sql_error($query);
111                  }
112   
113                  if (defined('DEBUG_EXTRA'))
114                  {
115                      $this->sql_report('stop', $query);
116                  }
117   
118                  if ($cache_ttl && method_exists($cache, 'sql_save'))
119                  {
120                      $this->open_queries[(int) $this->query_result] = $this->query_result;
121                      $cache->sql_save($query, $this->query_result, $cache_ttl);
122                  }
123                  else if (strpos($query, 'SELECT') === 0 && $this->query_result)
124                  {
125                      $this->open_queries[(int) $this->query_result] = $this->query_result;
126                  }
127              }
128              else if (defined('DEBUG_EXTRA'))
129              {
130                  $this->sql_report('fromcache', $query);
131              }
132          }
133          else
134          {
135              return false;
136          }
137   
138          return ($this->query_result) ? $this->query_result : false;
139      }
140   
141      /**
142      * Build LIMIT query
143      */
144      function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
145      {
146          $this->query_result = false;
147   
148          // if $total is set to 0 we do not want to limit the number of rows
149          if ($total == 0)
150          {
151              $total = -1;
152          }
153   
154          $query .= "\n LIMIT " . ((!empty($offset)) ? $offset . ', ' . $total : $total);
155   
156          return $this->sql_query($query, $cache_ttl);
157      }
158   
159      /**
160      * Return number of affected rows
161      */
162      function sql_affectedrows()
163      {
164          return ($this->db_connect_id) ? @sqlite_changes($this->db_connect_id) : false;
165      }
166   
167      /**
168      * Fetch current row
169      */
170      function sql_fetchrow($query_id = false)
171      {
172          global $cache;
173   
174          if ($query_id === false)
175          {
176              $query_id = $this->query_result;
177          }
178   
179          if (isset($cache->sql_rowset[$query_id]))
180          {
181              return $cache->sql_fetchrow($query_id);
182          }
183   
184          return ($query_id !== false) ? @sqlite_fetch_array($query_id, SQLITE_ASSOC) : false;
185      }
186   
187      /**
188      * Seek to given row number
189      * rownum is zero-based
190      */
191      function sql_rowseek($rownum, &$query_id)
192      {
193          global $cache;
194   
195          if ($query_id === false)
196          {
197              $query_id = $this->query_result;
198          }
199   
200          if (isset($cache->sql_rowset[$query_id]))
201          {
202              return $cache->sql_rowseek($rownum, $query_id);
203          }
204   
205          return ($query_id !== false) ? @sqlite_seek($query_id, $rownum) : false;
206      }
207   
208      /**
209      * Get last inserted id after insert statement
210      */
211      function sql_nextid()
212      {
213          return ($this->db_connect_id) ? @sqlite_last_insert_rowid($this->db_connect_id) : false;
214      }
215   
216      /**
217      * Free sql result
218      */
219      function sql_freeresult($query_id = false)
220      {
221          global $cache;
222   
223          if ($query_id === false)
224          {
225              $query_id = $this->query_result;
226          }
227   
228          if (isset($cache->sql_rowset[$query_id]))
229          {
230              return $cache->sql_freeresult($query_id);
231          }
232   
233          return true;
234      }
235   
236      /**
237      * Escape string used in sql query
238      */
239      function sql_escape($msg)
240      {
241          return @sqlite_escape_string($msg);
242      }
243   
244      /**
245      * Correctly adjust LIKE expression for special characters
246      * For SQLite an underscore is a not-known character... this may change with SQLite3
247      */
248      function sql_like_expression($expression)
249      {
250          // Unlike LIKE, GLOB is case sensitive (unfortunatly). SQLite users need to live with it!
251          // We only catch * and ? here, not the character map possible on file globbing.
252          $expression = str_replace(array(chr(0) . '_', chr(0) . '%'), array(chr(0) . '?', chr(0) . '*'), $expression);
253   
254          $expression = str_replace(array('?', '*'), array("\?", "\*"), $expression);
255          $expression = str_replace(array(chr(0) . "\?", chr(0) . "\*"), array('?', '*'), $expression);
256   
257          return 'GLOB \'' . $this->sql_escape($expression) . '\'';
258      }
259   
260      /**
261      * return sql error array
262      * @access private
263      */
264      function _sql_error()
265      {
266          return array(
267              'message'    => @sqlite_error_string(@sqlite_last_error($this->db_connect_id)),
268              'code'        => @sqlite_last_error($this->db_connect_id)
269          );
270      }
271   
272      /**
273      * Build db-specific query data
274      * @access private
275      */
276      function _sql_custom_build($stage, $data)
277      {
278          return $data;
279      }
280   
281      /**
282      * Close sql connection
283      * @access private
284      */
285      function _sql_close()
286      {
287          return @sqlite_close($this->db_connect_id);
288      }
289   
290      /**
291      * Build db-specific report
292      * @access private
293      */
294      function _sql_report($mode, $query = '')
295      {
296          switch ($mode)
297          {
298              case 'start':
299              break;
300   
301              case 'fromcache':
302                  $endtime = explode(' ', microtime());
303                  $endtime = $endtime[0] + $endtime[1];
304   
305                  $result = @sqlite_query($query, $this->db_connect_id);
306                  while ($void = @sqlite_fetch_array($result, SQLITE_ASSOC))
307                  {
308                      // Take the time spent on parsing rows into account
309                  }
310   
311                  $splittime = explode(' ', microtime());
312                  $splittime = $splittime[0] + $splittime[1];
313   
314                  $this->sql_report('record_fromcache', $query, $endtime, $splittime);
315   
316              break;
317          }
318      }
319  }
320   
321  ?>