[geeklog-cvs] geeklog: Fixed PostgreSQL error handling

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Sun Feb 20 04:07:50 EST 2011


changeset 8118:4fc8c3832df4
url:  http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/4fc8c3832df4
user: Dirk Haun <dirk at haun-online.de>
date: Sun Feb 20 09:24:33 2011 +0100
description:
Fixed PostgreSQL error handling

diffstat:

 system/databases/pgsql.class.php |  60 ++++++++++++++++++++++++---------------
 1 files changed, 37 insertions(+), 23 deletions(-)

diffs (91 lines):

diff -r 2b40427f0a57 -r 4fc8c3832df4 system/databases/pgsql.class.php
--- a/system/databases/pgsql.class.php	Sat Feb 19 19:38:50 2011 +0100
+++ b/system/databases/pgsql.class.php	Sun Feb 20 09:24:33 2011 +0100
@@ -2,13 +2,13 @@
 
 /* Reminder: always indent with 4 spaces (no tabs). */
 // +---------------------------------------------------------------------------+
-// | Geeklog 1.6                                                               |
+// | Geeklog 1.7                                                               |
 // +---------------------------------------------------------------------------+
 // | mysql.class.php                                                           |
 // |                                                                           |
 // | mysql database class                                                      |
 // +---------------------------------------------------------------------------+
-// | Copyright (C) 2000-2009 by the following authors:                         |
+// | Copyright (C) 2000-2011 by the following authors:                         |
 // |                                                                           |
 // | Authors: Stanislav Palatnik, spalatnikk AT gmail DoT com                  |
 // +---------------------------------------------------------------------------+
@@ -828,36 +828,50 @@
     {
         $this->_display_error = $flag;
     }
-    
-        /**
-    * Returns an database error message
+
+    /**
+    * Returns a database error message
     *
     * @param    string      $sql    SQL that may have caused the error
     * @return   string      Text for error message
+    *
     */
-    function dbError($sql='')
+    function dbError($sql = '')
     {
         $result = pg_get_result($this->_db);
-        if($this->_pgsql_version>=7.4)
-        {
-            if(pg_result_error_field($result,PGSQL_DIAG_SOURCE_LINE)) //this provides a much more detailed error report
-            {
-              $this->_errorlog('You have an error in your SQL query on line'.pg_result_error_field($result,PGSQL_DIAG_SOURCE_LINE)."<br/> SQL in question: $sql");
-             $error = 'Error:'.pg_result_error_field($result,PGSQL_DIAG_SQLSTATE).'<br/>Description:'.pg_result_error_field($result,PGSQL_DIAG_MESSAGE_DETAIL);
+        if ($this->_pgsql_version >= 7.4) {
+            // this provides a much more detailed error report
+            if (pg_result_error_field($result, PGSQL_DIAG_SOURCE_LINE)) {
+                $this->_errorlog('You have an error in your SQL query on line '
+                    . pg_result_error_field($result, PGSQL_DIAG_SOURCE_LINE)
+                    . "\nSQL in question: $sql");
+                $this->_errorlog('Error: '
+                    . pg_result_error_field($result, PGSQL_DIAG_SQLSTATE)
+                    . "\nDescription: "
+                    . pg_result_error_field($result, PGSQL_DIAG_MESSAGE_DETAIL));
+                if ($this->_display_error) {
+                    $error = "An SQL error has occurred in the following SQL: $sql";
+                } else {
+                    $error = 'An SQL error has occurred. Please see error.log for details.';
+                }
+                return $error;
             }
-            else {$error = "An SQL error has occurred in the following SQL : $sql.";}
+        } else {
+            if (pg_result_error($result)) {
+                $this->_errorlog(pg_result_error($result)
+                    . ". SQL in question: $sql");        
+                if ($this->_display_error) {
+                    $error = 'Error ' . pg_result_error($result);
+                } else {
+                    $error = 'An SQL error has occurred. Please see error.log for details.';
+                }
+                return $error;
+            }
         }
-         else
-         {
-            if (pg_result_error($result)) {
-                $this->_errorlog(pg_result_error($result) . ". SQL in question: $sql");        
-                if ($this->_display_error) {$error = 'Error'.pg_result_error($result);} 
-                else{$error = "An SQL error has occurred in the following SQL : $sql.";}
-            }
-        return $error;
-        }
+
+        return;
     }
-    
+
     /**
     * Checks to see if debug mode is on
     * Returns value of $_verbose



More information about the geeklog-cvs mailing list