瀏覽代碼

Fix minor error management

Laurent Destailleur 9 年之前
父節點
當前提交
753c5c7fc4
共有 4 個文件被更改,包括 67 次插入43 次删除
  1. 14 9
      htdocs/core/db/mssql.class.php
  2. 6 2
      htdocs/core/db/mysql.class.php
  3. 6 2
      htdocs/core/db/mysqli.class.php
  4. 41 30
      htdocs/core/db/pgsql.class.php

+ 14 - 9
htdocs/core/db/mssql.class.php

@@ -192,8 +192,12 @@ class DoliDBMssql extends DoliDB
 	function getVersion()
 	{
 		$resql=$this->query("SELECT @@VERSION");
-		$version=$this->fetch_array($resql);
-		return $version['computed'];
+		if ($resql)
+		{
+            $version=$this->fetch_array($resql);
+            return $version['computed'];
+		}
+		else return '';
 	}
 
 	/**
@@ -203,10 +207,7 @@ class DoliDBMssql extends DoliDB
 	 */
 	function getDriverInfo()
 	{
-		// FIXME: Dummy method
-		// TODO: Implement
-
-		return '';
+		return 'php mssql driver';
 	}
 
     /**
@@ -648,7 +649,7 @@ class DoliDBMssql extends DoliDB
 	function last_insert_id($tab,$fieldid='rowid')
 	{
 		$res = $this->query("SELECT @@IDENTITY as id");
-		if ($data = $this->fetch_array($res))
+		if ($res && $data = $this->fetch_array($res))
 		{
 			return $data["id"];
 		}
@@ -709,8 +710,12 @@ class DoliDBMssql extends DoliDB
 	function DDLGetConnectId()
 	{
 		$resql=$this->query('SELECT CONNECTION_ID()');
-		$row=$this->fetch_row($resql);
-		return $row[0];
+		if ($resql)
+		{
+            $row=$this->fetch_row($resql);
+            return $row[0];
+		}
+		else return '?';
 	}
 
 	/**

+ 6 - 2
htdocs/core/db/mysql.class.php

@@ -549,8 +549,12 @@ class DoliDBMysql extends DoliDB
 	function DDLGetConnectId()
 	{
 		$resql=$this->query('SELECT CONNECTION_ID()');
-		$row=$this->fetch_row($resql);
-		return $row[0];
+		if ($resql)
+		{
+            $row=$this->fetch_row($resql);
+            return $row[0];
+		}
+		else return '?';
 	}
 
 

+ 6 - 2
htdocs/core/db/mysqli.class.php

@@ -532,8 +532,12 @@ class DoliDBMysqli extends DoliDB
     function DDLGetConnectId()
     {
         $resql=$this->query('SELECT CONNECTION_ID()');
-        $row=$this->fetch_row($resql);
-        return $row[0];
+        if ($resql)
+        {
+            $row=$this->fetch_row($resql);
+            return $row[0];
+        }
+        else return '?';
     }
 
     /**

+ 41 - 30
htdocs/core/db/pgsql.class.php

@@ -874,31 +874,34 @@ class DoliDBPgsql extends DoliDB
 	 */
 	function DDLInfoTable($table)
 	{
-		 $infotables=array();
-
-		 $sql="SELECT ";
-		 $sql.="	infcol.column_name as \"Column\",";
-		 $sql.="	CASE WHEN infcol.character_maximum_length IS NOT NULL THEN infcol.udt_name || '('||infcol.character_maximum_length||')'";
-		 $sql.="		ELSE infcol.udt_name";
-		 $sql.="	END as \"Type\",";
-		 $sql.="	infcol.collation_name as \"Collation\",";
-		 $sql.="	infcol.is_nullable as \"Null\",";
-		 $sql.="	'' as \"Key\",";
-		 $sql.="	infcol.column_default as \"Default\",";
-		 $sql.="	'' as \"Extra\",";
-		 $sql.="	'' as \"Privileges\"";
-		 $sql.="	FROM information_schema.columns infcol";
-		 $sql.="	WHERE table_schema='public' ";
-		 $sql.="	AND table_name='".$table."'";
-		 $sql.="	ORDER BY ordinal_position;";
-
-		 dol_syslog($sql,LOG_DEBUG);
-		 $result = $this->query($sql);
-		 while($row = $this->fetch_row($result))
-		 {
-			$infotables[] = $row;
-		 }
-		return $infotables;
+		$infotables=array();
+
+		$sql="SELECT ";
+		$sql.="	infcol.column_name as \"Column\",";
+		$sql.="	CASE WHEN infcol.character_maximum_length IS NOT NULL THEN infcol.udt_name || '('||infcol.character_maximum_length||')'";
+		$sql.="		ELSE infcol.udt_name";
+		$sql.="	END as \"Type\",";
+		$sql.="	infcol.collation_name as \"Collation\",";
+		$sql.="	infcol.is_nullable as \"Null\",";
+		$sql.="	'' as \"Key\",";
+		$sql.="	infcol.column_default as \"Default\",";
+		$sql.="	'' as \"Extra\",";
+		$sql.="	'' as \"Privileges\"";
+		$sql.="	FROM information_schema.columns infcol";
+		$sql.="	WHERE table_schema='public' ";
+		$sql.="	AND table_name='".$table."'";
+		$sql.="	ORDER BY ordinal_position;";
+
+		dol_syslog($sql,LOG_DEBUG);
+		$result = $this->query($sql);
+		if ($result)
+		{
+    		 while($row = $this->fetch_row($result))
+    		 {
+    			$infotables[] = $row;
+    		 }
+		}
+        return $infotables;
 	}
 
 
@@ -1111,8 +1114,12 @@ class DoliDBPgsql extends DoliDB
 	function getDefaultCharacterSetDatabase()
 	{
 		$resql=$this->query('SHOW SERVER_ENCODING');
-		$liste=$this->fetch_array($resql);
-		return $liste['server_encoding'];
+		if ($resql)
+		{
+            $liste=$this->fetch_array($resql);
+		    return $liste['server_encoding'];
+		}
+		else return '';
 	}
 
 	/**
@@ -1127,7 +1134,7 @@ class DoliDBPgsql extends DoliDB
 		if ($resql)
 		{
 			$i = 0;
-			while ($obj = $this->fetch_object($resql) )
+			while ($obj = $this->fetch_object($resql))
 			{
 				$liste[$i]['charset'] = $obj->server_encoding;
 				$liste[$i]['description'] = 'Default database charset';
@@ -1148,8 +1155,12 @@ class DoliDBPgsql extends DoliDB
 	function getDefaultCollationDatabase()
 	{
 		$resql=$this->query('SHOW LC_COLLATE');
-		$liste=$this->fetch_array($resql);
-		return $liste['lc_collate'];
+		if ($resql)
+		{
+		    $liste=$this->fetch_array($resql);
+			return $liste['lc_collate'];
+		}
+		else return '';
 	}
 
 	/**