IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 4256


Ignore:
Timestamp:
Jun 14, 2005, 3:01:08 PM (21 years ago)
Author:
evanalst
Message:

Update function psDBInit and psDBCleanup to handle error conditions.

Location:
trunk/psLib/src
Files:
4 edited

Legend:

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

    r4128 r4256  
    1212 *  @author Joshua Hoblitt
    1313 *
    14  *  @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2005-06-07 02:29:44 $
     14 *  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2005-06-15 01:01:08 $
    1616 *
    1717 *  Copyright 2005 Joshua Hoblitt, University of Hawaii
     
    3535#include "psError.h"
    3636#include "psString.h"
    37 
     37#include "psFileUtilsErrors.h"
    3838
    3939typedef struct
     
    9999    }
    100100
     101    // Connect to host and mySql server with specified database
    101102    if (!mysql_real_connect(mysql, host, user, passwd, dbname, 0, NULL, 0)) {
    102         psError(PS_ERR_UNKNOWN, true, "Failed to connect to database.  Error: %s", mysql_error(mysql));
     103        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     104                PS_ERRORTEXT_psDB_FAILED_TO_CONNECT,mysql_error(mysql));
    103105
    104106        mysql_close(mysql);
     
    116118void psDBCleanup(psDB *dbh)
    117119{
    118     mysql_close(dbh->mysql);
    119     dbh->mysql = NULL;
    120     psFree(dbh);
    121 
    122     // ASC WARNING NOTE: the psDBSQLToPTypeTableCleanup cleanup routine
    123     // needs to be called first because it refers to
    124     // psDBGetPTypeToSQLTable ...
    125     psDBSQLToPTypeTableCleanup();
    126     psDBMySQLToSQLTableCleanup();
    127     psDBPTypeToSQLTableCleanup();
    128     psDBPTypeToMySQLTableCleanup();
     120    // Check if argument dbh is NULL
     121    if(dbh == NULL) {
     122        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     123                PS_ERRORTEXT_psDB_INVALID_PSDB);
     124    } else {
     125
     126        // Attempt to close specified database connection
     127        mysql_close(dbh->mysql);
     128        dbh->mysql = NULL;
     129        psFree(dbh);
     130
     131        // ASC WARNING NOTE: the psDBSQLToPTypeTableCleanup cleanup routine
     132        // needs to be called first because it refers to
     133        // psDBGetPTypeToSQLTable ...
     134        psDBSQLToPTypeTableCleanup();
     135        psDBMySQLToSQLTableCleanup();
     136        psDBPTypeToSQLTableCleanup();
     137        psDBPTypeToMySQLTableCleanup();
     138    }
    129139}
    130140
  • trunk/psLib/src/dataIO/psFileUtilsErrors.dat

    r3271 r4256  
    5757psFits_FITS_Z_SMALL                    Current FITS HDU has %d z-planes, but z-plane %d was specified.
    5858#
     59psDB_INVALID_PSDB                      Invalid psDB has been specified.
     60psDB_FAILED_TO_CONNECT                 Failed to connect to database.  Error: %s
     61#
     62
  • trunk/psLib/src/dataIO/psFileUtilsErrors.h

    r4162 r4256  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2005-06-08 23:40:45 $
     9 *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2005-06-15 01:01:08 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    7676#define PS_ERRORTEXT_psFits_IMAGE_UPDATE_TYPE_MISMATCH "Can not update a %s image given a %s image."
    7777#define PS_ERRORTEXT_psFits_FITS_Z_SMALL "Current FITS HDU has %d z-planes, but z-plane %d was specified."
     78#define PS_ERRORTEXT_psDB_INVALID_PSDB "Invalid psDB has been specified."
     79#define PS_ERRORTEXT_psDB_FAILED_TO_CONNECT "Failed to connect to database.  Error: %s"
    7880//~End
    7981
  • trunk/psLib/src/db/psDB.c

    r4128 r4256  
    1212 *  @author Joshua Hoblitt
    1313 *
    14  *  @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2005-06-07 02:29:44 $
     14 *  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2005-06-15 01:01:08 $
    1616 *
    1717 *  Copyright 2005 Joshua Hoblitt, University of Hawaii
     
    3535#include "psError.h"
    3636#include "psString.h"
    37 
     37#include "psFileUtilsErrors.h"
    3838
    3939typedef struct
     
    9999    }
    100100
     101    // Connect to host and mySql server with specified database
    101102    if (!mysql_real_connect(mysql, host, user, passwd, dbname, 0, NULL, 0)) {
    102         psError(PS_ERR_UNKNOWN, true, "Failed to connect to database.  Error: %s", mysql_error(mysql));
     103        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     104                PS_ERRORTEXT_psDB_FAILED_TO_CONNECT,mysql_error(mysql));
    103105
    104106        mysql_close(mysql);
     
    116118void psDBCleanup(psDB *dbh)
    117119{
    118     mysql_close(dbh->mysql);
    119     dbh->mysql = NULL;
    120     psFree(dbh);
    121 
    122     // ASC WARNING NOTE: the psDBSQLToPTypeTableCleanup cleanup routine
    123     // needs to be called first because it refers to
    124     // psDBGetPTypeToSQLTable ...
    125     psDBSQLToPTypeTableCleanup();
    126     psDBMySQLToSQLTableCleanup();
    127     psDBPTypeToSQLTableCleanup();
    128     psDBPTypeToMySQLTableCleanup();
     120    // Check if argument dbh is NULL
     121    if(dbh == NULL) {
     122        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     123                PS_ERRORTEXT_psDB_INVALID_PSDB);
     124    } else {
     125
     126        // Attempt to close specified database connection
     127        mysql_close(dbh->mysql);
     128        dbh->mysql = NULL;
     129        psFree(dbh);
     130
     131        // ASC WARNING NOTE: the psDBSQLToPTypeTableCleanup cleanup routine
     132        // needs to be called first because it refers to
     133        // psDBGetPTypeToSQLTable ...
     134        psDBSQLToPTypeTableCleanup();
     135        psDBMySQLToSQLTableCleanup();
     136        psDBPTypeToSQLTableCleanup();
     137        psDBPTypeToMySQLTableCleanup();
     138    }
    129139}
    130140
Note: See TracChangeset for help on using the changeset viewer.