IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 11320


Ignore:
Timestamp:
Jan 26, 2007, 12:24:37 PM (19 years ago)
Author:
jhoblitt
Message:

remove ridiculous use of error handling from p_psDBRunQuery()
add mysqlTopsErr() function

Location:
trunk/psLib/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/db/psDB.c

    r10999 r11320  
    1212 *  @author Joshua Hoblitt
    1313 *
    14  *  @version $Revision: 1.131 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2007-01-09 22:38:52 $
     14 *  @version $Revision: 1.132 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2007-01-26 22:24:37 $
    1616 *
    1717 *  Copyright (C) 2005-2006  Joshua Hoblitt, University of Hawaii
     
    121121static void     psDBAddToLookupTable(psHash *lookupTable, psU32 type, const char *string);
    122122static void     psDBAddVoidToLookupTable(psHash *lookupTable, psU32 type, psPtr value);
     123static psErrorCode mysqlTopsErr(MYSQL *mysql);
    123124
    124125// pType utility functions
     
    148149    // Connect to host and mySql server with specified database
    149150    if (!mysql_real_connect(mysql, host, user, passwd, dbname, port, NULL, 0)) {
    150         psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     151        psError(mysqlTopsErr(dbh->mysql), true,
    151152                _("Failed to connect to database.  Error: %s"),mysql_error(mysql));
    152153
     
    162163    // explicit transactions default to false
    163164    if (!psDBExplicitTrans(dbh, false)) {
    164         psError(PS_ERR_UNKNOWN, true,
     165        psError(mysqlTopsErr(dbh->mysql), true,
    165166                "failed to set transaction type. Error: %s", mysql_error(mysql));
    166167
     
    263264    // Attempt to select new database
    264265    if (mysql_select_db(dbh->mysql, dbname) != 0) {
    265         psError(PS_ERR_UNKNOWN, true, _("Failed to change database.  Error: %s"),
     266        psError(mysqlTopsErr(dbh->mysql), true, _("Failed to change database.  Error: %s"),
    266267                mysql_error(dbh->mysql));
    267268
     
    389390        // then something bad has happened.
    390391        if (fieldCount != 0) {
    391             psError(PS_ERR_UNEXPECTED_NULL, true, _("Query returned no data.  Error: %s"),
     392            psError(mysqlTopsErr(dbh->mysql), true, _("Query returned no data.  Error: %s"),
    392393                    mysql_error(dbh->mysql));
    393394            return NULL;
     
    823824
    824825    if (mysql_real_query(dbh->mysql, query, (unsigned long)strlen(query)) !=0) {
    825         //The following if statement was added to standardize outputs between platforms for testing purposes.
    826         char mysqlTemp[165];
    827         strncpy(mysqlTemp,
    828                 "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);
    829         if ( !strncmp(mysql_error(dbh->mysql), mysqlTemp, 145) ) {
    830             psError(PS_ERR_UNKNOWN, true, _("Failed to execute SQL query.  Error: %s"), mysqlTemp);
    831         } else {
    832             psError(PS_ERR_UNKNOWN, true, _("Failed to execute SQL query.  Error: %s"), mysql_error(dbh->mysql));
    833         }
     826        psError(mysqlTopsErr(dbh->mysql), true, _("Failed to execute SQL query.  Error: %s"), mysql_error(dbh->mysql));
    834827        psFree(query);
    835828        return false;
     
    951944        // it's non-zero then something bad has happened.
    952945        if (fieldCount != 0) {
    953             psError(PS_ERR_UNEXPECTED_NULL, true, "Query returned no data.  Error: %s", mysql_error(dbh->mysql));
     946            psError(mysqlTopsErr(dbh->mysql), true, "Query returned no data.  Error: %s", mysql_error(dbh->mysql));
    954947
    955948            return NULL;
     
    24142407}
    24152408
     2409static psErrorCode mysqlTopsErr(MYSQL *mysql)
     2410{
     2411    unsigned int myerrno = mysql_errno(mysql);
     2412    if ((myerrno >= 1000) && (myerrno < 2000)) {
     2413        return PS_ERR_DB_SERVER;
     2414    } else if ((myerrno >= 2000) && (myerrno < 3000)) {
     2415        return PS_ERR_DB_CLIENT;
     2416    }
     2417
     2418    return PS_ERR_UNKNOWN;
     2419}
     2420
    24162421
    24172422// pType utility functions
  • trunk/psLib/src/psErrorCodes_en.dat

    r10376 r11320  
    2020BAD_FITS                       file doesn't obey FITS standard
    2121IEEE                           a NaN or Inf was detected
     22DB_CLIENT                       Database error originated in the client library
     23DB_SERVER                       Database error generated by the server
Note: See TracChangeset for help on using the changeset viewer.