Merge pull request #6574 from rxu/ticket/17232-master

[ticket/17232] Improve SQL error messages handling - master version
This commit is contained in:
Marc Alexander 2023-12-31 10:43:19 +01:00
commit 9f099a75cd
No known key found for this signature in database
GPG key ID: 50E0D2423696F995
5 changed files with 63 additions and 17 deletions

View file

@ -161,7 +161,16 @@ class mssql_odbc extends \phpbb\db\driver\mssql_base
if ($this->query_result === false) if ($this->query_result === false)
{ {
if (($this->query_result = @odbc_exec($this->db_connect_id, $query)) === false) try
{
$this->query_result = @odbc_exec($this->db_connect_id, $query);
}
catch (\Error $e)
{
// Do nothing as SQL driver will report the error
}
if ($this->query_result === false)
{ {
$this->sql_error($query); $this->sql_error($query);
} }

View file

@ -136,12 +136,22 @@ class mssqlnative extends \phpbb\db\driver\mssql_base
if ($this->query_result === false) if ($this->query_result === false)
{ {
if (($this->query_result = @sqlsrv_query($this->db_connect_id, $query, array(), $this->query_options)) === false) try
{
$this->query_result = @sqlsrv_query($this->db_connect_id, $query, array(), $this->query_options);
}
catch (\Error $e)
{
// Do nothing as SQL driver will report the error
}
if ($this->query_result === false)
{ {
$this->sql_error($query); $this->sql_error($query);
} }
// reset options for next query
$this->query_options = array(); // Reset options for the next query
$this->query_options = [];
if ($this->debug_sql_explain) if ($this->debug_sql_explain)
{ {

View file

@ -193,7 +193,16 @@ class mysqli extends \phpbb\db\driver\mysql_base
if ($this->query_result === false) if ($this->query_result === false)
{ {
if (($this->query_result = @mysqli_query($this->db_connect_id, $query)) === false) try
{
$this->query_result = @mysqli_query($this->db_connect_id, $query);
}
catch (\Error $e)
{
// Do nothing as SQL driver will report the error
}
if ($this->query_result === false)
{ {
$this->sql_error($query); $this->sql_error($query);
} }
@ -332,24 +341,24 @@ class mysqli extends \phpbb\db\driver\mysql_base
{ {
if ($this->db_connect_id) if ($this->db_connect_id)
{ {
$error = array( $error = [
'message' => @mysqli_error($this->db_connect_id), 'message' => $this->db_connect_id->error,
'code' => @mysqli_errno($this->db_connect_id) 'code' => $this->db_connect_id->errno,
); ];
} }
else if (function_exists('mysqli_connect_error')) else if (function_exists('mysqli_connect_error'))
{ {
$error = array( $error = [
'message' => @mysqli_connect_error(), 'message' => $this->db_connect_id->connect_error,
'code' => @mysqli_connect_errno(), 'code' => $this->db_connect_id->connect_errno,
); ];
} }
else else
{ {
$error = array( $error = [
'message' => $this->connect_error, 'message' => $this->connect_error,
'code' => '', 'code' => '',
); ];
} }
return $error; return $error;

View file

@ -183,7 +183,16 @@ class postgres extends \phpbb\db\driver\driver
if ($this->query_result === false) if ($this->query_result === false)
{ {
if (($this->query_result = @pg_query($this->db_connect_id, $query)) === false) try
{
$this->query_result = @pg_query($this->db_connect_id, $query);
}
catch (\Error $e)
{
// Do nothing as SQL driver will report the error
}
if ($this->query_result === false)
{ {
$this->sql_error($query); $this->sql_error($query);
} }

View file

@ -131,7 +131,16 @@ class sqlite3 extends \phpbb\db\driver\driver
$query = preg_replace('/^INSERT INTO/', 'INSERT OR ROLLBACK INTO', $query); $query = preg_replace('/^INSERT INTO/', 'INSERT OR ROLLBACK INTO', $query);
} }
if (($this->query_result = @$this->dbo->query($query)) === false) try
{
$this->query_result = @$this->dbo->query($query);
}
catch (\Error $e)
{
// Do nothing as SQL driver will report the error
}
if ($this->query_result === false)
{ {
// Try to recover a lost database connection // Try to recover a lost database connection
if ($this->dbo && !@$this->dbo->lastErrorMsg()) if ($this->dbo && !@$this->dbo->lastErrorMsg())