From 76ddf1ca4143f38f3bf8fc6aabdb3fa302d6ed40 Mon Sep 17 00:00:00 2001
From: Patrick Webster <noxwizard@phpbb.com>
Date: Mon, 14 Oct 2013 16:37:23 -0500
Subject: [ticket/11918] Make sql_freeresult() consistent across all DB drivers

PHPBB3-11918
---
 phpBB/phpbb/db/driver/firebird.php    | 2 +-
 phpBB/phpbb/db/driver/mssql.php       | 6 +++---
 phpBB/phpbb/db/driver/mssql_odbc.php  | 2 +-
 phpBB/phpbb/db/driver/mssqlnative.php | 3 ++-
 phpBB/phpbb/db/driver/mysql.php       | 2 +-
 phpBB/phpbb/db/driver/oracle.php      | 2 +-
 phpBB/phpbb/db/driver/postgres.php    | 2 +-
 phpBB/phpbb/db/driver/sqlite.php      | 2 +-
 8 files changed, 11 insertions(+), 10 deletions(-)

(limited to 'phpBB/phpbb/db')

diff --git a/phpBB/phpbb/db/driver/firebird.php b/phpBB/phpbb/db/driver/firebird.php
index 2df5eaf369..aef75eab15 100644
--- a/phpBB/phpbb/db/driver/firebird.php
+++ b/phpBB/phpbb/db/driver/firebird.php
@@ -398,7 +398,7 @@ class firebird extends \phpbb\db\driver\driver
 			$query_id = $this->query_result;
 		}
 
-		if ($cache && $cache->sql_exists($query_id))
+		if ($cache && !is_object($query_id) && $cache->sql_exists($query_id))
 		{
 			return $cache->sql_freeresult($query_id);
 		}
diff --git a/phpBB/phpbb/db/driver/mssql.php b/phpBB/phpbb/db/driver/mssql.php
index 4d2cd287da..50096deded 100644
--- a/phpBB/phpbb/db/driver/mssql.php
+++ b/phpBB/phpbb/db/driver/mssql.php
@@ -318,14 +318,14 @@ class mssql extends \phpbb\db\driver\driver
 			$query_id = $this->query_result;
 		}
 
-		if ($cache && $cache->sql_exists($query_id))
+		if ($cache && !is_object($query_id) && $cache->sql_exists($query_id))
 		{
 			return $cache->sql_freeresult($query_id);
 		}
 
-		if (isset($this->open_queries[$query_id]))
+		if (isset($this->open_queries[(int) $query_id]))
 		{
-			unset($this->open_queries[$query_id]);
+			unset($this->open_queries[(int) $query_id]);
 			return @mssql_free_result($query_id);
 		}
 
diff --git a/phpBB/phpbb/db/driver/mssql_odbc.php b/phpBB/phpbb/db/driver/mssql_odbc.php
index 9db34a69fb..b9881035c0 100644
--- a/phpBB/phpbb/db/driver/mssql_odbc.php
+++ b/phpBB/phpbb/db/driver/mssql_odbc.php
@@ -305,7 +305,7 @@ class mssql_odbc extends \phpbb\db\driver\mssql_base
 			$query_id = $this->query_result;
 		}
 
-		if ($cache && $cache->sql_exists($query_id))
+		if ($cache && !is_object($query_id) && $cache->sql_exists($query_id))
 		{
 			return $cache->sql_freeresult($query_id);
 		}
diff --git a/phpBB/phpbb/db/driver/mssqlnative.php b/phpBB/phpbb/db/driver/mssqlnative.php
index e6002fe1a3..aade311bcb 100644
--- a/phpBB/phpbb/db/driver/mssqlnative.php
+++ b/phpBB/phpbb/db/driver/mssqlnative.php
@@ -471,7 +471,7 @@ class mssqlnative extends \phpbb\db\driver\mssql_base
 			$query_id = $this->query_result;
 		}
 
-		if ($cache->sql_exists($query_id))
+		if ($cache && !is_object($query_id) && $cache->sql_exists($query_id))
 		{
 			return $cache->sql_freeresult($query_id);
 		}
@@ -481,6 +481,7 @@ class mssqlnative extends \phpbb\db\driver\mssql_base
 			unset($this->open_queries[(int) $query_id]);
 			return @sqlsrv_free_stmt($query_id);
 		}
+
 		return false;
 	}
 
diff --git a/phpBB/phpbb/db/driver/mysql.php b/phpBB/phpbb/db/driver/mysql.php
index c76126763d..d215453ccb 100644
--- a/phpBB/phpbb/db/driver/mysql.php
+++ b/phpBB/phpbb/db/driver/mysql.php
@@ -289,7 +289,7 @@ class mysql extends \phpbb\db\driver\mysql_base
 			$query_id = $this->query_result;
 		}
 
-		if ($cache && $cache->sql_exists($query_id))
+		if ($cache && !is_object($query_id) && $cache->sql_exists($query_id))
 		{
 			return $cache->sql_freeresult($query_id);
 		}
diff --git a/phpBB/phpbb/db/driver/oracle.php b/phpBB/phpbb/db/driver/oracle.php
index 5dfab21455..4fba654d1e 100644
--- a/phpBB/phpbb/db/driver/oracle.php
+++ b/phpBB/phpbb/db/driver/oracle.php
@@ -621,7 +621,7 @@ class oracle extends \phpbb\db\driver\driver
 			$query_id = $this->query_result;
 		}
 
-		if ($cache && $cache->sql_exists($query_id))
+		if ($cache && !is_object($query_id) && $cache->sql_exists($query_id))
 		{
 			return $cache->sql_freeresult($query_id);
 		}
diff --git a/phpBB/phpbb/db/driver/postgres.php b/phpBB/phpbb/db/driver/postgres.php
index 7a98b90c73..9cbb1ecb07 100644
--- a/phpBB/phpbb/db/driver/postgres.php
+++ b/phpBB/phpbb/db/driver/postgres.php
@@ -350,7 +350,7 @@ class postgres extends \phpbb\db\driver\driver
 			$query_id = $this->query_result;
 		}
 
-		if ($cache && $cache->sql_exists($query_id))
+		if ($cache && !is_object($query_id) && $cache->sql_exists($query_id))
 		{
 			return $cache->sql_freeresult($query_id);
 		}
diff --git a/phpBB/phpbb/db/driver/sqlite.php b/phpBB/phpbb/db/driver/sqlite.php
index a548fd2618..55a33284f2 100644
--- a/phpBB/phpbb/db/driver/sqlite.php
+++ b/phpBB/phpbb/db/driver/sqlite.php
@@ -261,7 +261,7 @@ class sqlite extends \phpbb\db\driver\driver
 			$query_id = $this->query_result;
 		}
 
-		if ($cache && $cache->sql_exists($query_id))
+		if ($cache && !is_object($query_id) && $cache->sql_exists($query_id))
 		{
 			return $cache->sql_freeresult($query_id);
 		}
-- 
cgit v1.2.1