IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 4256 for trunk/psLib/src/db


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

Update function psDBInit and psDBCleanup to handle error conditions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.