IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 9990


Ignore:
Timestamp:
Nov 14, 2006, 3:34:42 PM (20 years ago)
Author:
jhoblitt
Message:

rename psDBInit() -> psDBAlloc() and set psDBFree() as the deallocator func
rename psDBCleanup() -> psDBFree() and make it private
add a macro/wrapper named psDBInit() around psDBAlloc()
add a macro/wrapper named psDBCleanup() around psFree()

Location:
trunk/psLib/src/db
Files:
2 edited

Legend:

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

    r9985 r9990  
    1212 *  @author Joshua Hoblitt
    1313 *
    14  *  @version $Revision: 1.110 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2006-11-15 00:54:22 $
     14 *  @version $Revision: 1.111 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2006-11-15 01:34:42 $
    1616 *
    1717 *  Copyright (C) 2005-2006  Joshua Hoblitt, University of Hawaii
     
    6868static psHash   *mysqlToSqlLookupTable = NULL;
    6969static psHash   *pTypeToMysqlLookupTable = NULL;
     70
     71// free func
     72static void psDBFree(psDB *dbh);
    7073
    7174// database utility functions
     
    120123/*****************************************************************************/
    121124
    122 psDB *psDBInit(const char *host,
    123                const char *user,
    124                const char *passwd,
    125                const char *dbname,
    126                unsigned int port)
     125psDB *psDBAlloc(const char *host,
     126                const char *user,
     127                const char *passwd,
     128                const char *dbname,
     129                unsigned int port)
    127130{
    128131    MYSQL           *mysql;
     
    180183    }
    181184
     185    // don't set the deallocator func until after we've setup the lookup tables
     186    // so an alloc error doesn't try to free potentionally uncreated tables
     187    psMemSetDeallocator(dbh, (psFreeFunc) psDBFree);
     188
    182189    psTrace("psLib.db", PS_LOG_INFO, "connected to database %s", dbname);
    183190
     
    185192}
    186193
    187 void psDBCleanup(psDB *dbh)
     194static void psDBFree(psDB *dbh)
    188195{
    189196    // quietly handle NULLs
     
    194201    // Attempt to close specified database connection
    195202    mysql_close(dbh->mysql);
    196     psFree(dbh);
    197203
    198204    // ASC WARNING NOTE: the psDBSQLToPTypeTableCleanup cleanup routine
  • trunk/psLib/src/db/psDB.h

    r9544 r9990  
    1010 *  @author Joshua Hoblitt
    1111 *
    12  *  @version $Revision: 1.29 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2006-10-13 22:26:14 $
     12 *  @version $Revision: 1.30 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2006-11-15 01:34:42 $
    1414 *
    1515 *  Copyright 2005 Joshua Hoblitt, University of Hawaii
     
    4040/** Opens a new database connection
    4141 *
    42  *  @return psDB*:      A new psDB object if the database connection is successful or NULL on
    43  *  failure.
    44  */
     42 *  @return psDB*:      A new psDB object if the database connection is
     43 *  successful or NULL on failure.
     44 */
     45psDB *psDBAlloc(
     46    const char *host,                  ///< Database server hostname
     47    const char *user,                  ///< Database username
     48    const char *passwd,                ///< Database password
     49    const char *dbname,                ///< Database namespace
     50    unsigned int port                  ///< Database port number
     51);
     52
     53/** Opens a new database connection
     54 *
     55 *  This function is deprecated favor of psDBAlloc()
     56 *
     57 *  @return psDB*:      A new psDB object if the database connection is
     58 *  successful or NULL on failure.
     59 */
     60#ifdef DOXYGEN
    4561psDB *psDBInit(
    4662    const char *host,                  ///< Database server hostname
     
    5066    unsigned int port                  ///< Database port number
    5167);
    52 
    53 /** Closes a database connection  */
     68#else // DOXYGEN
     69#define psDBInit(host, user, passwd, dbname, port) \
     70psDBAlloc(host, user, passwd, dbname, port)
     71#endif
     72
     73#ifdef DOXYGEN
     74/** Closes a database connection
     75 *
     76 *  This function is deprecated favor of psFree()
     77 */
    5478void psDBCleanup(
    5579    psDB *dbh                          ///< Database handle
    5680);
     81#else // DOXYGEN
     82#define psDBCleanup(dbh) \
     83psFree(dbh)
     84#endif
    5785
    5886/** Creates a new database namespace
Note: See TracChangeset for help on using the changeset viewer.