From 2276c1c0f246a39dee8d0e979c89e8de0ee7a5de Mon Sep 17 00:00:00 2001
From: Tristan Darricau <github@nicofuma.fr>
Date: Sun, 22 Jun 2014 18:08:38 +0200
Subject: [ticket/12387] Cleanup *_free_result call and remove @ on that call

PHPBB3-12387
---
 phpBB/phpbb/db/driver/postgres.php | 43 ++++++++++++++++++++++++--------------
 1 file changed, 27 insertions(+), 16 deletions(-)

(limited to 'phpBB/phpbb/db/driver/postgres.php')

diff --git a/phpBB/phpbb/db/driver/postgres.php b/phpBB/phpbb/db/driver/postgres.php
index a4aa9497ed..3fade46bdd 100644
--- a/phpBB/phpbb/db/driver/postgres.php
+++ b/phpBB/phpbb/db/driver/postgres.php
@@ -127,14 +127,17 @@ class postgres extends \phpbb\db\driver\driver
 		if (!$use_cache || empty($cache) || ($this->sql_server_version = $cache->get('pgsql_version')) === false)
 		{
 			$query_id = @pg_query($this->db_connect_id, 'SELECT VERSION() AS version');
-			$row = @pg_fetch_assoc($query_id, null);
-			@pg_free_result($query_id);
+			if ($query_id)
+			{
+				$row = pg_fetch_assoc($query_id, null);
+				pg_free_result($query_id);
 
-			$this->sql_server_version = (!empty($row['version'])) ? trim(substr($row['version'], 10)) : 0;
+				$this->sql_server_version = (!empty($row['version'])) ? trim(substr($row['version'], 10)) : 0;
 
-			if (!empty($cache) && $use_cache)
-			{
-				$cache->put('pgsql_version', $this->sql_server_version);
+				if (!empty($cache) && $use_cache)
+				{
+					$cache->put('pgsql_version', $this->sql_server_version);
+				}
 			}
 		}
 
@@ -196,6 +199,11 @@ class postgres extends \phpbb\db\driver\driver
 					$this->sql_report('stop', $query);
 				}
 
+				if (!$this->query_result)
+				{
+					return false;
+				}
+
 				if ($cache && $cache_ttl)
 				{
 					$this->open_queries[(int) $this->query_result] = $this->query_result;
@@ -271,7 +279,7 @@ class postgres extends \phpbb\db\driver\driver
 			return $cache->sql_fetchrow($query_id);
 		}
 
-		return ($query_id !== false) ? @pg_fetch_assoc($query_id, null) : false;
+		return ($query_id) ? pg_fetch_assoc($query_id, null) : false;
 	}
 
 	/**
@@ -291,7 +299,7 @@ class postgres extends \phpbb\db\driver\driver
 			return $cache->sql_rowseek($rownum, $query_id);
 		}
 
-		return ($query_id !== false) ? @pg_result_seek($query_id, $rownum) : false;
+		return ($query_id) ? @pg_result_seek($query_id, $rownum) : false;
 	}
 
 	/**
@@ -313,8 +321,8 @@ class postgres extends \phpbb\db\driver\driver
 					return false;
 				}
 
-				$temp_result = @pg_fetch_assoc($temp_q_id, null);
-				@pg_free_result($query_id);
+				$temp_result = pg_fetch_assoc($temp_q_id, null);
+				pg_free_result($query_id);
 
 				return ($temp_result) ? $temp_result['last_value'] : false;
 			}
@@ -343,7 +351,7 @@ class postgres extends \phpbb\db\driver\driver
 		if (isset($this->open_queries[(int) $query_id]))
 		{
 			unset($this->open_queries[(int) $query_id]);
-			return @pg_free_result($query_id);
+			return pg_free_result($query_id);
 		}
 
 		return false;
@@ -440,12 +448,12 @@ class postgres extends \phpbb\db\driver\driver
 
 					if ($result = @pg_query($this->db_connect_id, "EXPLAIN $explain_query"))
 					{
-						while ($row = @pg_fetch_assoc($result, null))
+						while ($row = pg_fetch_assoc($result, null))
 						{
 							$html_table = $this->sql_report('add_select_row', $query, $html_table, $row);
 						}
+						pg_free_result($result);
 					}
-					@pg_free_result($result);
 
 					if ($html_table)
 					{
@@ -460,11 +468,14 @@ class postgres extends \phpbb\db\driver\driver
 				$endtime = $endtime[0] + $endtime[1];
 
 				$result = @pg_query($this->db_connect_id, $query);
-				while ($void = @pg_fetch_assoc($result, null))
+				if ($result)
 				{
-					// Take the time spent on parsing rows into account
+					while ($void = pg_fetch_assoc($result, null))
+					{
+						// Take the time spent on parsing rows into account
+					}
+					pg_free_result($result);
 				}
-				@pg_free_result($result);
 
 				$splittime = explode(' ', microtime());
 				$splittime = $splittime[0] + $splittime[1];
-- 
cgit v1.2.1


From 50f4bea6101f64c513b3918ade58a712b00f3df7 Mon Sep 17 00:00:00 2001
From: Tristan Darricau <github@nicofuma.fr>
Date: Sun, 22 Jun 2014 19:35:07 +0200
Subject: [ticket/12387] Remove unnecessary checks

PHPBB3-12387
---
 phpBB/phpbb/db/driver/postgres.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'phpBB/phpbb/db/driver/postgres.php')

diff --git a/phpBB/phpbb/db/driver/postgres.php b/phpBB/phpbb/db/driver/postgres.php
index 3fade46bdd..78825de73c 100644
--- a/phpBB/phpbb/db/driver/postgres.php
+++ b/phpBB/phpbb/db/driver/postgres.php
@@ -209,7 +209,7 @@ class postgres extends \phpbb\db\driver\driver
 					$this->open_queries[(int) $this->query_result] = $this->query_result;
 					$this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
 				}
-				else if (strpos($query, 'SELECT') === 0 && $this->query_result)
+				else if (strpos($query, 'SELECT') === 0)
 				{
 					$this->open_queries[(int) $this->query_result] = $this->query_result;
 				}
-- 
cgit v1.2.1