From f013656b02830436ebcc6a0a6510bd5342ee3f6f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 23 Jul 2016 10:25:31 +0200 Subject: [PATCH] Better error management --- htdocs/core/db/mysql.class.php | 22 ++++++++++++++-------- htdocs/core/db/mysqli.class.php | 14 ++++++++++---- htdocs/core/db/pgsql.class.php | 11 +++++++---- htdocs/core/db/sqlite.class.php | 14 ++++++++++---- htdocs/core/db/sqlite3.class.php | 14 ++++++++++---- 5 files changed, 51 insertions(+), 24 deletions(-) diff --git a/htdocs/core/db/mysql.class.php b/htdocs/core/db/mysql.class.php index a92bb09e0b3..85b3ea13b13 100644 --- a/htdocs/core/db/mysql.class.php +++ b/htdocs/core/db/mysql.class.php @@ -606,10 +606,13 @@ class DoliDBMysql extends DoliDB $sql="SHOW TABLES FROM ".$database." ".$like.";"; //print $sql; $result = $this->query($sql); - while($row = $this->fetch_row($result)) - { - $listtables[] = $row[0]; - } + if ($result) + { + while($row = $this->fetch_row($result)) + { + $listtables[] = $row[0]; + } + } return $listtables; } @@ -627,10 +630,13 @@ class DoliDBMysql extends DoliDB dol_syslog($sql,LOG_DEBUG); $result = $this->query($sql); - while($row = $this->fetch_row($result)) - { - $infotables[] = $row; - } + if ($result) + { + while($row = $this->fetch_row($result)) + { + $infotables[] = $row; + } + } return $infotables; } diff --git a/htdocs/core/db/mysqli.class.php b/htdocs/core/db/mysqli.class.php index b83d42810a8..087abf709d9 100644 --- a/htdocs/core/db/mysqli.class.php +++ b/htdocs/core/db/mysqli.class.php @@ -589,9 +589,12 @@ class DoliDBMysqli extends DoliDB $sql="SHOW TABLES FROM ".$database." ".$like.";"; //print $sql; $result = $this->query($sql); - while($row = $this->fetch_row($result)) + if ($result) { - $listtables[] = $row[0]; + while($row = $this->fetch_row($result)) + { + $listtables[] = $row[0]; + } } return $listtables; } @@ -610,9 +613,12 @@ class DoliDBMysqli extends DoliDB dol_syslog($sql,LOG_DEBUG); $result = $this->query($sql); - while($row = $this->fetch_row($result)) + if ($result) { - $infotables[] = $row; + while($row = $this->fetch_row($result)) + { + $infotables[] = $row; + } } return $infotables; } diff --git a/htdocs/core/db/pgsql.class.php b/htdocs/core/db/pgsql.class.php index 5a9a446596f..3290e259dca 100644 --- a/htdocs/core/db/pgsql.class.php +++ b/htdocs/core/db/pgsql.class.php @@ -861,10 +861,13 @@ class DoliDBPgsql extends DoliDB $like = ''; if ($table) $like = " AND table_name LIKE '".$table."'"; $result = pg_query($this->db, "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'".$like." ORDER BY table_name"); - while($row = $this->fetch_row($result)) - { - $listtables[] = $row[0]; - } + if ($result) + { + while($row = $this->fetch_row($result)) + { + $listtables[] = $row[0]; + } + } return $listtables; } diff --git a/htdocs/core/db/sqlite.class.php b/htdocs/core/db/sqlite.class.php index 647cd3a6798..ef638b0e9fe 100644 --- a/htdocs/core/db/sqlite.class.php +++ b/htdocs/core/db/sqlite.class.php @@ -747,9 +747,12 @@ class DoliDBSqlite extends DoliDB $sql="SHOW TABLES FROM ".$database." ".$like.";"; //print $sql; $result = $this->query($sql); - while($row = $this->fetch_row($result)) + if ($result) { - $listtables[] = $row[0]; + while($row = $this->fetch_row($result)) + { + $listtables[] = $row[0]; + } } return $listtables; } @@ -769,9 +772,12 @@ class DoliDBSqlite extends DoliDB dol_syslog($sql,LOG_DEBUG); $result = $this->query($sql); - while($row = $this->fetch_row($result)) + if ($result) { - $infotables[] = $row; + while($row = $this->fetch_row($result)) + { + $infotables[] = $row; + } } return $infotables; } diff --git a/htdocs/core/db/sqlite3.class.php b/htdocs/core/db/sqlite3.class.php index 2b9f2dedf8a..97ba05a32ba 100644 --- a/htdocs/core/db/sqlite3.class.php +++ b/htdocs/core/db/sqlite3.class.php @@ -831,9 +831,12 @@ class DoliDBSqlite3 extends DoliDB $sql="SHOW TABLES FROM ".$database." ".$like.";"; //print $sql; $result = $this->query($sql); - while($row = $this->fetch_row($result)) + if ($result) { - $listtables[] = $row[0]; + while($row = $this->fetch_row($result)) + { + $listtables[] = $row[0]; + } } return $listtables; } @@ -853,9 +856,12 @@ class DoliDBSqlite3 extends DoliDB dol_syslog($sql,LOG_DEBUG); $result = $this->query($sql); - while($row = $this->fetch_row($result)) + if ($result) { - $infotables[] = $row; + while($row = $this->fetch_row($result)) + { + $infotables[] = $row; + } } return $infotables; }