IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 26, 2005, 10:00:57 AM (21 years ago)
Author:
drobbin
Message:

changed p_psDBRunQuery to accept a variable argument list (as requested in rev 15)

File:
1 edited

Legend:

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

    r4589 r4612  
    1212 *  @author Joshua Hoblitt
    1313 *
    14  *  @version $Revision: 1.40 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2005-07-21 01:40:10 $
     14 *  @version $Revision: 1.41 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2005-07-26 20:00:57 $
    1616 *
    1717 *  Copyright 2005 Joshua Hoblitt, University of Hawaii
     
    853853
    854854bool p_psDBRunQuery(psDB *dbh,
    855                     const char *format)
    856 {
     855                    const char *format,
     856                    ...)
     857{
     858    va_list argPtr;
     859    char *dest = NULL;
     860
    857861    // Verify database object is not NULL
    858862    if(dbh == NULL) {
     
    862866
    863867    // Run query
    864     if (mysql_real_query(dbh->mysql, format, (unsigned long)strlen(format)) !=0) {
     868    va_start(argPtr, format);
     869    if(argPtr == NULL) {
     870        dest=psStringCopy(format);
     871    } else {
     872        int destSize = vsnprintf(dest, 0, format, argPtr);
     873        dest = psAlloc(destSize+1);
     874        vsnprintf(dest, destSize+1, format, argPtr);
     875    }
     876    va_end(argPtr);
     877    if (mysql_real_query(dbh->mysql, dest, (unsigned long)strlen(dest)) !=0) {
    865878        psError(PS_ERR_UNKNOWN, true, PS_ERRORTEXT_psDB_SQL_QUERY_FAIL, mysql_error(dbh->mysql));
     879        psFree(dest);
    866880        return false;
    867881    }
    868882
     883    psFree(dest);
    869884    return true;
    870885}
Note: See TracChangeset for help on using the changeset viewer.