Index: trunk/psLib/src/db/psDB.c
===================================================================
--- trunk/psLib/src/db/psDB.c	(revision 10999)
+++ trunk/psLib/src/db/psDB.c	(revision 11320)
@@ -12,6 +12,6 @@
  *  @author Joshua Hoblitt
  *
- *  @version $Revision: 1.131 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-01-09 22:38:52 $
+ *  @version $Revision: 1.132 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-01-26 22:24:37 $
  *
  *  Copyright (C) 2005-2006  Joshua Hoblitt, University of Hawaii
@@ -121,4 +121,5 @@
 static void     psDBAddToLookupTable(psHash *lookupTable, psU32 type, const char *string);
 static void     psDBAddVoidToLookupTable(psHash *lookupTable, psU32 type, psPtr value);
+static psErrorCode mysqlTopsErr(MYSQL *mysql);
 
 // pType utility functions
@@ -148,5 +149,5 @@
     // Connect to host and mySql server with specified database
     if (!mysql_real_connect(mysql, host, user, passwd, dbname, port, NULL, 0)) {
-        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
+        psError(mysqlTopsErr(dbh->mysql), true,
                 _("Failed to connect to database.  Error: %s"),mysql_error(mysql));
 
@@ -162,5 +163,5 @@
     // explicit transactions default to false
     if (!psDBExplicitTrans(dbh, false)) {
-        psError(PS_ERR_UNKNOWN, true,
+        psError(mysqlTopsErr(dbh->mysql), true,
                 "failed to set transaction type. Error: %s", mysql_error(mysql));
 
@@ -263,5 +264,5 @@
     // Attempt to select new database
     if (mysql_select_db(dbh->mysql, dbname) != 0) {
-        psError(PS_ERR_UNKNOWN, true, _("Failed to change database.  Error: %s"),
+        psError(mysqlTopsErr(dbh->mysql), true, _("Failed to change database.  Error: %s"),
                 mysql_error(dbh->mysql));
 
@@ -389,5 +390,5 @@
         // then something bad has happened.
         if (fieldCount != 0) {
-            psError(PS_ERR_UNEXPECTED_NULL, true, _("Query returned no data.  Error: %s"),
+            psError(mysqlTopsErr(dbh->mysql), true, _("Query returned no data.  Error: %s"),
                     mysql_error(dbh->mysql));
             return NULL;
@@ -823,13 +824,5 @@
 
     if (mysql_real_query(dbh->mysql, query, (unsigned long)strlen(query)) !=0) {
-        //The following if statement was added to standardize outputs between platforms for testing purposes.
-        char mysqlTemp[165];
-        strncpy(mysqlTemp,
-                "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'null) WHERE' at line 1", 165);
-        if ( !strncmp(mysql_error(dbh->mysql), mysqlTemp, 145) ) {
-            psError(PS_ERR_UNKNOWN, true, _("Failed to execute SQL query.  Error: %s"), mysqlTemp);
-        } else {
-            psError(PS_ERR_UNKNOWN, true, _("Failed to execute SQL query.  Error: %s"), mysql_error(dbh->mysql));
-        }
+        psError(mysqlTopsErr(dbh->mysql), true, _("Failed to execute SQL query.  Error: %s"), mysql_error(dbh->mysql));
         psFree(query);
         return false;
@@ -951,5 +944,5 @@
         // it's non-zero then something bad has happened.
         if (fieldCount != 0) {
-            psError(PS_ERR_UNEXPECTED_NULL, true, "Query returned no data.  Error: %s", mysql_error(dbh->mysql));
+            psError(mysqlTopsErr(dbh->mysql), true, "Query returned no data.  Error: %s", mysql_error(dbh->mysql));
 
             return NULL;
@@ -2414,4 +2407,16 @@
 }
 
+static psErrorCode mysqlTopsErr(MYSQL *mysql)
+{
+    unsigned int myerrno = mysql_errno(mysql);
+    if ((myerrno >= 1000) && (myerrno < 2000)) {
+        return PS_ERR_DB_SERVER;
+    } else if ((myerrno >= 2000) && (myerrno < 3000)) {
+        return PS_ERR_DB_CLIENT;
+    }
+
+    return PS_ERR_UNKNOWN;
+}
+
 
 // pType utility functions
