Skip to content

Commit

Permalink
[ticket/11305] Check for $cache being null before using it in db driv…
Browse files Browse the repository at this point in the history
…ers.

There is no reason why db drivers must have a cache to work.
They query the database, that part works without caches.

PHPBB3-11305
  • Loading branch information
p committed Jan 2, 2013
1 parent bc317c4 commit c8c6eb4
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 41 deletions.
4 changes: 2 additions & 2 deletions phpBB/includes/db/driver/driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ function sql_rowseek($rownum, &$query_id)
$query_id = $this->query_result;
}

if ($cache->sql_exists($query_id))
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_rowseek($rownum, $query_id);
}
Expand Down Expand Up @@ -256,7 +256,7 @@ function sql_fetchfield($field, $rownum = false, $query_id = false)
$this->sql_rowseek($rownum, $query_id);
}

if (!is_object($query_id) && $cache->sql_exists($query_id))
if ($cache && !is_object($query_id) && $cache->sql_exists($query_id))
{
return $cache->sql_fetchfield($query_id, $field);
}
Expand Down
8 changes: 4 additions & 4 deletions phpBB/includes/db/driver/firebird.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ function sql_query($query = '', $cache_ttl = 0)
}

$this->last_query_text = $query;
$this->query_result = ($cache_ttl) ? $cache->sql_load($query) : false;
$this->query_result = ($cache && $cache_ttl) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);

if ($this->query_result === false)
Expand Down Expand Up @@ -267,7 +267,7 @@ function sql_query($query = '', $cache_ttl = 0)
}
}

if ($cache_ttl)
if ($cache && $cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
Expand Down Expand Up @@ -330,7 +330,7 @@ function sql_fetchrow($query_id = false)
$query_id = $this->query_result;
}

if ($cache->sql_exists($query_id))
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
Expand Down Expand Up @@ -396,7 +396,7 @@ function sql_freeresult($query_id = false)
$query_id = $this->query_result;
}

if ($cache->sql_exists($query_id))
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}
Expand Down
10 changes: 5 additions & 5 deletions phpBB/includes/db/driver/mssql.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function sql_query($query = '', $cache_ttl = 0)
$this->sql_report('start', $query);
}

$this->query_result = ($cache_ttl) ? $cache->sql_load($query) : false;
$this->query_result = ($cache && $cache_ttl) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);

if ($this->query_result === false)
Expand All @@ -165,7 +165,7 @@ function sql_query($query = '', $cache_ttl = 0)
$this->sql_report('stop', $query);
}

if ($cache_ttl)
if ($cache && $cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
Expand Down Expand Up @@ -240,7 +240,7 @@ function sql_fetchrow($query_id = false)
$query_id = $this->query_result;
}

if ($cache->sql_exists($query_id))
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
Expand Down Expand Up @@ -277,7 +277,7 @@ function sql_rowseek($rownum, &$query_id)
$query_id = $this->query_result;
}

if ($cache->sql_exists($query_id))
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_rowseek($rownum, $query_id);
}
Expand Down Expand Up @@ -316,7 +316,7 @@ function sql_freeresult($query_id = false)
$query_id = $this->query_result;
}

if ($cache->sql_exists($query_id))
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}
Expand Down
8 changes: 4 additions & 4 deletions phpBB/includes/db/driver/mssql_odbc.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function sql_query($query = '', $cache_ttl = 0)
}

$this->last_query_text = $query;
$this->query_result = ($cache_ttl) ? $cache->sql_load($query) : false;
$this->query_result = ($cache && $cache_ttl) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);

if ($this->query_result === false)
Expand All @@ -194,7 +194,7 @@ function sql_query($query = '', $cache_ttl = 0)
$this->sql_report('stop', $query);
}

if ($cache_ttl)
if ($cache && $cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
Expand Down Expand Up @@ -270,7 +270,7 @@ function sql_fetchrow($query_id = false, $debug = false)
$query_id = $this->query_result;
}

if ($cache->sql_exists($query_id))
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
Expand Down Expand Up @@ -311,7 +311,7 @@ function sql_freeresult($query_id = false)
$query_id = $this->query_result;
}

if ($cache->sql_exists($query_id))
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}
Expand Down
2 changes: 1 addition & 1 deletion phpBB/includes/db/driver/mssqlnative.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ function sql_query($query = '', $cache_ttl = 0)
}

$this->last_query_text = $query;
$this->query_result = ($cache_ttl) ? $cache->sql_load($query) : false;
$this->query_result = ($cache && $cache_ttl) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);

if ($this->query_result === false)
Expand Down
10 changes: 5 additions & 5 deletions phpBB/includes/db/driver/mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ function sql_query($query = '', $cache_ttl = 0)
$this->sql_report('start', $query);
}

$this->query_result = ($cache_ttl) ? $cache->sql_load($query) : false;
$this->query_result = ($cache && $cache_ttl) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);

if ($this->query_result === false)
Expand All @@ -203,7 +203,7 @@ function sql_query($query = '', $cache_ttl = 0)
$this->sql_report('stop', $query);
}

if ($cache_ttl)
if ($cache && $cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
Expand Down Expand Up @@ -265,7 +265,7 @@ function sql_fetchrow($query_id = false)
$query_id = $this->query_result;
}

if ($cache->sql_exists($query_id))
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
Expand All @@ -286,7 +286,7 @@ function sql_rowseek($rownum, &$query_id)
$query_id = $this->query_result;
}

if ($cache->sql_exists($query_id))
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_rowseek($rownum, $query_id);
}
Expand Down Expand Up @@ -314,7 +314,7 @@ function sql_freeresult($query_id = false)
$query_id = $this->query_result;
}

if ($cache->sql_exists($query_id))
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}
Expand Down
10 changes: 5 additions & 5 deletions phpBB/includes/db/driver/mysqli.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ function sql_query($query = '', $cache_ttl = 0)
$this->sql_report('start', $query);
}

$this->query_result = ($cache_ttl) ? $cache->sql_load($query) : false;
$this->query_result = ($cache && $cache_ttl) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);

if ($this->query_result === false)
Expand All @@ -199,7 +199,7 @@ function sql_query($query = '', $cache_ttl = 0)
$this->sql_report('stop', $query);
}

if ($cache_ttl)
if ($cache && $cache_ttl)
{
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
}
Expand Down Expand Up @@ -256,7 +256,7 @@ function sql_fetchrow($query_id = false)
$query_id = $this->query_result;
}

if (!is_object($query_id) && $cache->sql_exists($query_id))
if ($cache && !is_object($query_id) && $cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
Expand All @@ -283,7 +283,7 @@ function sql_rowseek($rownum, &$query_id)
$query_id = $this->query_result;
}

if (!is_object($query_id) && $cache->sql_exists($query_id))
if ($cache && !is_object($query_id) && $cache->sql_exists($query_id))
{
return $cache->sql_rowseek($rownum, $query_id);
}
Expand Down Expand Up @@ -311,7 +311,7 @@ function sql_freeresult($query_id = false)
$query_id = $this->query_result;
}

if (!is_object($query_id) && $cache->sql_exists($query_id))
if ($cache && !is_object($query_id) && $cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}
Expand Down
10 changes: 5 additions & 5 deletions phpBB/includes/db/driver/oracle.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ function sql_query($query = '', $cache_ttl = 0)
}

$this->last_query_text = $query;
$this->query_result = ($cache_ttl) ? $cache->sql_load($query) : false;
$this->query_result = ($cache && $cache_ttl) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);

if ($this->query_result === false)
Expand Down Expand Up @@ -443,7 +443,7 @@ function sql_query($query = '', $cache_ttl = 0)
$this->sql_report('stop', $query);
}

if ($cache_ttl)
if ($cache && $cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
Expand Down Expand Up @@ -498,7 +498,7 @@ function sql_fetchrow($query_id = false)
$query_id = $this->query_result;
}

if ($cache->sql_exists($query_id))
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
Expand Down Expand Up @@ -550,7 +550,7 @@ function sql_rowseek($rownum, &$query_id)
$query_id = $this->query_result;
}

if ($cache->sql_exists($query_id))
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_rowseek($rownum, $query_id);
}
Expand Down Expand Up @@ -619,7 +619,7 @@ function sql_freeresult($query_id = false)
$query_id = $this->query_result;
}

if ($cache->sql_exists($query_id))
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}
Expand Down
10 changes: 5 additions & 5 deletions phpBB/includes/db/driver/postgres.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ function sql_query($query = '', $cache_ttl = 0)
}

$this->last_query_text = $query;
$this->query_result = ($cache_ttl) ? $cache->sql_load($query) : false;
$this->query_result = ($cache && $cache_ttl) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);

if ($this->query_result === false)
Expand All @@ -208,7 +208,7 @@ function sql_query($query = '', $cache_ttl = 0)
$this->sql_report('stop', $query);
}

if ($cache_ttl)
if ($cache && $cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
Expand Down Expand Up @@ -278,7 +278,7 @@ function sql_fetchrow($query_id = false)
$query_id = $this->query_result;
}

if ($cache->sql_exists($query_id))
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
Expand All @@ -299,7 +299,7 @@ function sql_rowseek($rownum, &$query_id)
$query_id = $this->query_result;
}

if ($cache->sql_exists($query_id))
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_rowseek($rownum, $query_id);
}
Expand Down Expand Up @@ -348,7 +348,7 @@ function sql_freeresult($query_id = false)
$query_id = $this->query_result;
}

if ($cache->sql_exists($query_id))
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}
Expand Down
10 changes: 5 additions & 5 deletions phpBB/includes/db/driver/sqlite.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function sql_query($query = '', $cache_ttl = 0)
$this->sql_report('start', $query);
}

$this->query_result = ($cache_ttl) ? $cache->sql_load($query) : false;
$this->query_result = ($cache && $cache_ttl) ? $cache->sql_load($query) : false;
$this->sql_add_num_queries($this->query_result);

if ($this->query_result === false)
Expand All @@ -149,7 +149,7 @@ function sql_query($query = '', $cache_ttl = 0)
$this->sql_report('stop', $query);
}

if ($cache_ttl)
if ($cache && $cache_ttl)
{
$this->open_queries[(int) $this->query_result] = $this->query_result;
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
Expand Down Expand Up @@ -210,7 +210,7 @@ function sql_fetchrow($query_id = false)
$query_id = $this->query_result;
}

if ($cache->sql_exists($query_id))
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_fetchrow($query_id);
}
Expand All @@ -231,7 +231,7 @@ function sql_rowseek($rownum, &$query_id)
$query_id = $this->query_result;
}

if ($cache->sql_exists($query_id))
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_rowseek($rownum, $query_id);
}
Expand Down Expand Up @@ -259,7 +259,7 @@ function sql_freeresult($query_id = false)
$query_id = $this->query_result;
}

if ($cache->sql_exists($query_id))
if ($cache && $cache->sql_exists($query_id))
{
return $cache->sql_freeresult($query_id);
}
Expand Down

0 comments on commit c8c6eb4

Please sign in to comment.