[ticket/11305] Check for $cache being null before using it in db drivers.

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

PHPBB3-11305
This commit is contained in:
Oleg Pudeyev 2013-01-02 14:36:14 -05:00
parent bc317c49a7
commit c8c6eb46ec
10 changed files with 41 additions and 41 deletions

View file

@ -206,7 +206,7 @@ class phpbb_db_driver
$query_id = $this->query_result; $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); return $cache->sql_rowseek($rownum, $query_id);
} }
@ -256,7 +256,7 @@ class phpbb_db_driver
$this->sql_rowseek($rownum, $query_id); $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); return $cache->sql_fetchfield($query_id, $field);
} }

View file

@ -154,7 +154,7 @@ class phpbb_db_driver_firebird extends phpbb_db_driver
} }
$this->last_query_text = $query; $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); $this->sql_add_num_queries($this->query_result);
if ($this->query_result === false) if ($this->query_result === false)
@ -267,7 +267,7 @@ class phpbb_db_driver_firebird extends phpbb_db_driver
} }
} }
if ($cache_ttl) if ($cache && $cache_ttl)
{ {
$this->open_queries[(int) $this->query_result] = $this->query_result; $this->open_queries[(int) $this->query_result] = $this->query_result;
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl); $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
@ -330,7 +330,7 @@ class phpbb_db_driver_firebird extends phpbb_db_driver
$query_id = $this->query_result; $query_id = $this->query_result;
} }
if ($cache->sql_exists($query_id)) if ($cache && $cache->sql_exists($query_id))
{ {
return $cache->sql_fetchrow($query_id); return $cache->sql_fetchrow($query_id);
} }
@ -396,7 +396,7 @@ class phpbb_db_driver_firebird extends phpbb_db_driver
$query_id = $this->query_result; $query_id = $this->query_result;
} }
if ($cache->sql_exists($query_id)) if ($cache && $cache->sql_exists($query_id))
{ {
return $cache->sql_freeresult($query_id); return $cache->sql_freeresult($query_id);
} }

View file

@ -150,7 +150,7 @@ class phpbb_db_driver_mssql extends phpbb_db_driver
$this->sql_report('start', $query); $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); $this->sql_add_num_queries($this->query_result);
if ($this->query_result === false) if ($this->query_result === false)
@ -165,7 +165,7 @@ class phpbb_db_driver_mssql extends phpbb_db_driver
$this->sql_report('stop', $query); $this->sql_report('stop', $query);
} }
if ($cache_ttl) if ($cache && $cache_ttl)
{ {
$this->open_queries[(int) $this->query_result] = $this->query_result; $this->open_queries[(int) $this->query_result] = $this->query_result;
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl); $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
@ -240,7 +240,7 @@ class phpbb_db_driver_mssql extends phpbb_db_driver
$query_id = $this->query_result; $query_id = $this->query_result;
} }
if ($cache->sql_exists($query_id)) if ($cache && $cache->sql_exists($query_id))
{ {
return $cache->sql_fetchrow($query_id); return $cache->sql_fetchrow($query_id);
} }
@ -277,7 +277,7 @@ class phpbb_db_driver_mssql extends phpbb_db_driver
$query_id = $this->query_result; $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); return $cache->sql_rowseek($rownum, $query_id);
} }
@ -316,7 +316,7 @@ class phpbb_db_driver_mssql extends phpbb_db_driver
$query_id = $this->query_result; $query_id = $this->query_result;
} }
if ($cache->sql_exists($query_id)) if ($cache && $cache->sql_exists($query_id))
{ {
return $cache->sql_freeresult($query_id); return $cache->sql_freeresult($query_id);
} }

View file

@ -179,7 +179,7 @@ class phpbb_db_driver_mssql_odbc extends phpbb_db_driver
} }
$this->last_query_text = $query; $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); $this->sql_add_num_queries($this->query_result);
if ($this->query_result === false) if ($this->query_result === false)
@ -194,7 +194,7 @@ class phpbb_db_driver_mssql_odbc extends phpbb_db_driver
$this->sql_report('stop', $query); $this->sql_report('stop', $query);
} }
if ($cache_ttl) if ($cache && $cache_ttl)
{ {
$this->open_queries[(int) $this->query_result] = $this->query_result; $this->open_queries[(int) $this->query_result] = $this->query_result;
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl); $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
@ -270,7 +270,7 @@ class phpbb_db_driver_mssql_odbc extends phpbb_db_driver
$query_id = $this->query_result; $query_id = $this->query_result;
} }
if ($cache->sql_exists($query_id)) if ($cache && $cache->sql_exists($query_id))
{ {
return $cache->sql_fetchrow($query_id); return $cache->sql_fetchrow($query_id);
} }
@ -311,7 +311,7 @@ class phpbb_db_driver_mssql_odbc extends phpbb_db_driver
$query_id = $this->query_result; $query_id = $this->query_result;
} }
if ($cache->sql_exists($query_id)) if ($cache && $cache->sql_exists($query_id))
{ {
return $cache->sql_freeresult($query_id); return $cache->sql_freeresult($query_id);
} }

View file

@ -317,7 +317,7 @@ class phpbb_db_driver_mssqlnative extends phpbb_db_driver
} }
$this->last_query_text = $query; $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); $this->sql_add_num_queries($this->query_result);
if ($this->query_result === false) if ($this->query_result === false)

View file

@ -188,7 +188,7 @@ class phpbb_db_driver_mysql extends phpbb_db_driver
$this->sql_report('start', $query); $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); $this->sql_add_num_queries($this->query_result);
if ($this->query_result === false) if ($this->query_result === false)
@ -203,7 +203,7 @@ class phpbb_db_driver_mysql extends phpbb_db_driver
$this->sql_report('stop', $query); $this->sql_report('stop', $query);
} }
if ($cache_ttl) if ($cache && $cache_ttl)
{ {
$this->open_queries[(int) $this->query_result] = $this->query_result; $this->open_queries[(int) $this->query_result] = $this->query_result;
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl); $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
@ -265,7 +265,7 @@ class phpbb_db_driver_mysql extends phpbb_db_driver
$query_id = $this->query_result; $query_id = $this->query_result;
} }
if ($cache->sql_exists($query_id)) if ($cache && $cache->sql_exists($query_id))
{ {
return $cache->sql_fetchrow($query_id); return $cache->sql_fetchrow($query_id);
} }
@ -286,7 +286,7 @@ class phpbb_db_driver_mysql extends phpbb_db_driver
$query_id = $this->query_result; $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); return $cache->sql_rowseek($rownum, $query_id);
} }
@ -314,7 +314,7 @@ class phpbb_db_driver_mysql extends phpbb_db_driver
$query_id = $this->query_result; $query_id = $this->query_result;
} }
if ($cache->sql_exists($query_id)) if ($cache && $cache->sql_exists($query_id))
{ {
return $cache->sql_freeresult($query_id); return $cache->sql_freeresult($query_id);
} }

View file

@ -184,7 +184,7 @@ class phpbb_db_driver_mysqli extends phpbb_db_driver
$this->sql_report('start', $query); $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); $this->sql_add_num_queries($this->query_result);
if ($this->query_result === false) if ($this->query_result === false)
@ -199,7 +199,7 @@ class phpbb_db_driver_mysqli extends phpbb_db_driver
$this->sql_report('stop', $query); $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); $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
} }
@ -256,7 +256,7 @@ class phpbb_db_driver_mysqli extends phpbb_db_driver
$query_id = $this->query_result; $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); return $cache->sql_fetchrow($query_id);
} }
@ -283,7 +283,7 @@ class phpbb_db_driver_mysqli extends phpbb_db_driver
$query_id = $this->query_result; $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); return $cache->sql_rowseek($rownum, $query_id);
} }
@ -311,7 +311,7 @@ class phpbb_db_driver_mysqli extends phpbb_db_driver
$query_id = $this->query_result; $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); return $cache->sql_freeresult($query_id);
} }

View file

@ -267,7 +267,7 @@ class phpbb_db_driver_oracle extends phpbb_db_driver
} }
$this->last_query_text = $query; $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); $this->sql_add_num_queries($this->query_result);
if ($this->query_result === false) if ($this->query_result === false)
@ -443,7 +443,7 @@ class phpbb_db_driver_oracle extends phpbb_db_driver
$this->sql_report('stop', $query); $this->sql_report('stop', $query);
} }
if ($cache_ttl) if ($cache && $cache_ttl)
{ {
$this->open_queries[(int) $this->query_result] = $this->query_result; $this->open_queries[(int) $this->query_result] = $this->query_result;
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl); $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
@ -498,7 +498,7 @@ class phpbb_db_driver_oracle extends phpbb_db_driver
$query_id = $this->query_result; $query_id = $this->query_result;
} }
if ($cache->sql_exists($query_id)) if ($cache && $cache->sql_exists($query_id))
{ {
return $cache->sql_fetchrow($query_id); return $cache->sql_fetchrow($query_id);
} }
@ -550,7 +550,7 @@ class phpbb_db_driver_oracle extends phpbb_db_driver
$query_id = $this->query_result; $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); return $cache->sql_rowseek($rownum, $query_id);
} }
@ -619,7 +619,7 @@ class phpbb_db_driver_oracle extends phpbb_db_driver
$query_id = $this->query_result; $query_id = $this->query_result;
} }
if ($cache->sql_exists($query_id)) if ($cache && $cache->sql_exists($query_id))
{ {
return $cache->sql_freeresult($query_id); return $cache->sql_freeresult($query_id);
} }

View file

@ -193,7 +193,7 @@ class phpbb_db_driver_postgres extends phpbb_db_driver
} }
$this->last_query_text = $query; $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); $this->sql_add_num_queries($this->query_result);
if ($this->query_result === false) if ($this->query_result === false)
@ -208,7 +208,7 @@ class phpbb_db_driver_postgres extends phpbb_db_driver
$this->sql_report('stop', $query); $this->sql_report('stop', $query);
} }
if ($cache_ttl) if ($cache && $cache_ttl)
{ {
$this->open_queries[(int) $this->query_result] = $this->query_result; $this->open_queries[(int) $this->query_result] = $this->query_result;
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl); $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
@ -278,7 +278,7 @@ class phpbb_db_driver_postgres extends phpbb_db_driver
$query_id = $this->query_result; $query_id = $this->query_result;
} }
if ($cache->sql_exists($query_id)) if ($cache && $cache->sql_exists($query_id))
{ {
return $cache->sql_fetchrow($query_id); return $cache->sql_fetchrow($query_id);
} }
@ -299,7 +299,7 @@ class phpbb_db_driver_postgres extends phpbb_db_driver
$query_id = $this->query_result; $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); return $cache->sql_rowseek($rownum, $query_id);
} }
@ -348,7 +348,7 @@ class phpbb_db_driver_postgres extends phpbb_db_driver
$query_id = $this->query_result; $query_id = $this->query_result;
} }
if ($cache->sql_exists($query_id)) if ($cache && $cache->sql_exists($query_id))
{ {
return $cache->sql_freeresult($query_id); return $cache->sql_freeresult($query_id);
} }

View file

@ -134,7 +134,7 @@ class phpbb_db_driver_sqlite extends phpbb_db_driver
$this->sql_report('start', $query); $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); $this->sql_add_num_queries($this->query_result);
if ($this->query_result === false) if ($this->query_result === false)
@ -149,7 +149,7 @@ class phpbb_db_driver_sqlite extends phpbb_db_driver
$this->sql_report('stop', $query); $this->sql_report('stop', $query);
} }
if ($cache_ttl) if ($cache && $cache_ttl)
{ {
$this->open_queries[(int) $this->query_result] = $this->query_result; $this->open_queries[(int) $this->query_result] = $this->query_result;
$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl); $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
@ -210,7 +210,7 @@ class phpbb_db_driver_sqlite extends phpbb_db_driver
$query_id = $this->query_result; $query_id = $this->query_result;
} }
if ($cache->sql_exists($query_id)) if ($cache && $cache->sql_exists($query_id))
{ {
return $cache->sql_fetchrow($query_id); return $cache->sql_fetchrow($query_id);
} }
@ -231,7 +231,7 @@ class phpbb_db_driver_sqlite extends phpbb_db_driver
$query_id = $this->query_result; $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); return $cache->sql_rowseek($rownum, $query_id);
} }
@ -259,7 +259,7 @@ class phpbb_db_driver_sqlite extends phpbb_db_driver
$query_id = $this->query_result; $query_id = $this->query_result;
} }
if ($cache->sql_exists($query_id)) if ($cache && $cache->sql_exists($query_id))
{ {
return $cache->sql_freeresult($query_id); return $cache->sql_freeresult($query_id);
} }