aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/db/sqlite.php
diff options
context:
space:
mode:
authorMeik Sievertsen <acydburn@phpbb.com>2005-10-07 23:00:41 +0000
committerMeik Sievertsen <acydburn@phpbb.com>2005-10-07 23:00:41 +0000
commit913c38768a21901187d2ded9427b3e2e533206f4 (patch)
tree7480cbd098b54782134f2f166573f56a585b8074 /phpBB/includes/db/sqlite.php
parent8d72671cc1c983dcafac6948f07ac3cf7447c93c (diff)
downloadforums-913c38768a21901187d2ded9427b3e2e533206f4.tar
forums-913c38768a21901187d2ded9427b3e2e533206f4.tar.gz
forums-913c38768a21901187d2ded9427b3e2e533206f4.tar.bz2
forums-913c38768a21901187d2ded9427b3e2e533206f4.tar.xz
forums-913c38768a21901187d2ded9427b3e2e533206f4.zip
- another try to break things. :)
- adjusted the dbal a little bit - removed db2 support git-svn-id: file:///svn/phpbb/trunk@5263 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/db/sqlite.php')
-rw-r--r--phpBB/includes/db/sqlite.php145
1 files changed, 72 insertions, 73 deletions
diff --git a/phpBB/includes/db/sqlite.php b/phpBB/includes/db/sqlite.php
index 1b20822284..4c8edeb4d5 100644
--- a/phpBB/includes/db/sqlite.php
+++ b/phpBB/includes/db/sqlite.php
@@ -23,7 +23,9 @@ if (!defined('SQL_LAYER'))
*/
class dbal_sqlite extends dbal
{
-
+ /**
+ * Connect to server
+ */
function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false)
{
$this->persistency = $persistency;
@@ -42,19 +44,9 @@ class dbal_sqlite extends dbal
return ($this->db_connect_id) ? true : array('message' => $error);
}
- //
- // Other base methods
- //
- function sql_close()
- {
- if (!$this->db_connect_id)
- {
- return false;
- }
-
- return @sqlite_close($this->db_connect_id);
- }
-
+ /**
+ * sql transaction
+ */
function sql_transaction($status = 'begin')
{
switch ($status)
@@ -86,7 +78,9 @@ class dbal_sqlite extends dbal
return $result;
}
- // Base query method
+ /**
+ * Base query method
+ */
function sql_query($query = '', $cache_ttl = 0)
{
if ($query != '')
@@ -119,8 +113,13 @@ class dbal_sqlite extends dbal
if ($cache_ttl && method_exists($cache, 'sql_save'))
{
+ $this->open_queries[(int) $this->query_result] = $this->query_result;
$cache->sql_save($query, $this->query_result, $cache_ttl);
}
+ else if (strpos($query, 'SELECT') !== false && $this->query_result)
+ {
+ $this->open_queries[(int) $this->query_result] = $this->query_result;
+ }
}
else if (defined('DEBUG_EXTRA'))
{
@@ -135,6 +134,9 @@ class dbal_sqlite extends dbal
return ($this->query_result) ? $this->query_result : false;
}
+ /**
+ * Build LIMIT query
+ */
function sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
{
if ($query != '')
@@ -157,10 +159,10 @@ class dbal_sqlite extends dbal
}
}
- // Other query methods
- //
- // NOTE :: Want to remove _ALL_ reliance on sql_numrows from core code ...
- // don't want this here by a middle Milestone
+ /**
+ * Return number of rows
+ * Not used within core code
+ */
function sql_numrows($query_id = false)
{
if (!$query_id)
@@ -171,11 +173,17 @@ class dbal_sqlite extends dbal
return ($query_id) ? @sqlite_num_rows($query_id) : false;
}
+ /**
+ * Return number of affected rows
+ */
function sql_affectedrows()
{
return ($this->db_connect_id) ? @sqlite_changes($this->db_connect_id) : false;
}
+ /**
+ * Fetch current row
+ */
function sql_fetchrow($query_id = false)
{
global $cache;
@@ -193,30 +201,11 @@ class dbal_sqlite extends dbal
return ($query_id) ? @sqlite_fetch_array($query_id, SQLITE_ASSOC) : false;
}
- function sql_fetchrowset($query_id = false)
- {
- if (!$query_id)
- {
- $query_id = $this->query_result;
- }
-
- if ($query_id)
- {
- unset($this->rowset[$query_id]);
- unset($this->row[$query_id]);
-
- $result = array();
- while ($this->rowset[$query_id] = $this->sql_fetchrow($query_id))
- {
- $result[] = $this->rowset[$query_id];
- }
- return $result;
- }
-
- return false;
- }
-
- function sql_fetchfield($field, $rownum = -1, $query_id = false)
+ /**
+ * Fetch field
+ * if rownum is false, the current row is used, else it is pointing to the row (zero-based)
+ */
+ function sql_fetchfield($field, $rownum = false, $query_id = false)
{
if (!$query_id)
{
@@ -225,21 +214,24 @@ class dbal_sqlite extends dbal
if ($query_id)
{
- if ($rownum > -1)
+ if ($rownum === false)
{
- $result = (@sqlite_seek($query_id, $rownum)) ? @sqlite_column($query_id, $field) : false;
+ return @sqlite_column($query_id, $field);
}
else
{
- $result = @sqlite_column($query_id, $field);
+ @sqlite_seek($query_id, $rownum);
+ return @sqlite_column($query_id, $field);
}
-
- return $result;
}
return false;
}
+ /**
+ * Seek to given row number
+ * rownum is zero-based
+ */
function sql_rowseek($rownum, $query_id = false)
{
if (!$query_id)
@@ -250,22 +242,35 @@ class dbal_sqlite extends dbal
return ($query_id) ? @sqlite_seek($query_id, $rownum) : false;
}
+ /**
+ * Get last inserted id after insert statement
+ */
function sql_nextid()
{
return ($this->db_connect_id) ? @sqlite_last_insert_rowid($this->db_connect_id) : false;
}
+ /**
+ * Free sql result
+ */
function sql_freeresult($query_id = false)
{
return true;
}
+ /**
+ * Escape string used in sql query
+ */
function sql_escape($msg)
{
- return @sqlite_escape_string(stripslashes($msg));
+ return @sqlite_escape_string($msg);
}
- function db_sql_error()
+ /**
+ * return sql error array
+ * @private
+ */
+ function _sql_error()
{
return array(
'message' => @sqlite_error_string(@sqlite_last_error($this->db_connect_id)),
@@ -273,22 +278,25 @@ class dbal_sqlite extends dbal
);
}
- function _sql_report($mode, $query = '')
+ /**
+ * Close sql connection
+ * @private
+ */
+ function _sql_close()
{
- global $cache, $starttime, $phpbb_root_path;
- static $curtime, $query_hold, $html_hold;
- static $sql_report = '';
- static $cache_num_queries = 0;
+ return @sqlite_close($this->db_connect_id);
+ }
+ /**
+ * Build db-specific report
+ * @private
+ */
+ function _sql_report($mode, $query = '')
+ {
switch ($mode)
{
case 'start':
- $query_hold = $query;
- $html_hold = '';
-
- $curtime = explode(' ', microtime());
- $curtime = $curtime[0] + $curtime[1];
- break;
+ break;
case 'fromcache':
$endtime = explode(' ', microtime());
@@ -299,22 +307,13 @@ class dbal_sqlite extends dbal
{
// Take the time spent on parsing rows into account
}
+
$splittime = explode(' ', microtime());
$splittime = $splittime[0] + $splittime[1];
- $time_cache = $endtime - $curtime;
- $time_db = $splittime - $endtime;
- $color = ($time_db > $time_cache) ? 'green' : 'red';
-
- $sql_report .= '<hr width="100%"/><br /><table class="bg" width="100%" cellspacing="1" cellpadding="4" border="0"><tr><th>Query results obtained from the cache</th></tr><tr><td class="row1"><textarea style="font-family:\'Courier New\',monospace;width:100%" rows="5">' . preg_replace('/\t(AND|OR)(\W)/', "\$1\$2", htmlspecialchars(preg_replace('/[\s]*[\n\r\t]+[\n\r\s\t]*/', "\n", $query))) . '</textarea></td></tr></table><p align="center">';
-
- $sql_report .= 'Before: ' . sprintf('%.5f', $curtime - $starttime) . 's | After: ' . sprintf('%.5f', $endtime - $starttime) . 's | Elapsed [cache]: <b style="color: ' . $color . '">' . sprintf('%.5f', ($time_cache)) . 's</b> | Elapsed [db]: <b>' . sprintf('%.5f', $time_db) . 's</b></p>';
+ $this->sql_report('record_fromcache', $query, $endtime, $splittime);
- // Pad the start time to not interfere with page timing
- $starttime += $time_db;
-
- $cache_num_queries++;
- break;
+ break;
}
}