IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 14, 2005, 9:28:50 PM (21 years ago)
Author:
jhoblitt
Message:

add psDBDeleteRows()
add psDBGenerateDeleteRowSQL()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/archive/psdb/psDB.c

    r3222 r3223  
    88 *  @author Joshua Hoblitt
    99 *
    10  *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2005-02-15 07:27:02 $
     10 *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2005-02-15 07:28:50 $
    1212 *
    1313 *  Copyright 2005 Joshua Hoblitt, University of Hawaii
     
    3939static char    *psDBGenerateInsertRowSQL(const char *tableName, psMetadata *row);
    4040static char    *psDBGenerateUpdateRowSQL(const char *tableName, psMetadata *where, psMetadata *values);
     41static char    *psDBGenerateDeleteRowSQL(const char *tableName, psMetadata *where);
    4142static char    *psDBGenerateWhereSQL(psMetadata *where);
    4243static char    *psDBGenerateSetSQL(psMetadata *set);
     
    638639    psU32           paramCount;         // number of placeholders in query
    639640    MYSQL_BIND      *bind;              // field values to insert
    640     psU64           rowsAffected;
     641    psU64           rowsAffected;       // number of rows affected by query
    641642
    642643    query = psDBGenerateUpdateRowSQL(tableName, where, values);
     
    716717}
    717718
     719psS64 psDBDeleteRows(psDB *dbh, const char *tableName, psMetadata *where)
     720{
     721    char            *query;
     722
     723    query = psDBGenerateDeleteRowSQL(tableName, where);
     724    if (!query) {
     725        return -1;
     726    }
     727
     728    if (!psDBRunQuery(dbh, query)) {
     729        psFree(query);
     730
     731        return -1;
     732    }
     733
     734    psFree(query);
     735
     736    if (!where) {
     737        // we truncated the table so mysql_affected_rows() won't work
     738
     739        return 1;
     740    }
     741
     742    return (psS64)mysql_affected_rows(dbh->mysql);
     743}
    718744
    719745// database utility functions
     
    967993    psFree(setSQL);
    968994    psFree(whereSQL);
     995
     996    return query;
     997}
     998
     999static char *psDBGenerateDeleteRowSQL(const char *tableName, psMetadata *where)
     1000{
     1001    char            *query = NULL;
     1002    char            *whereSQL;
     1003
     1004    // delete all rows if where is NULL
     1005    if (!where) {
     1006        psStringAppend(&query, "TRUNCATE TABLE %s", tableName);
     1007
     1008        return query;
     1009    }
     1010   
     1011    whereSQL = psDBGenerateWhereSQL(where);
     1012    if (!whereSQL) {
     1013        return NULL;
     1014    }
     1015
     1016    psStringAppend(&query, "DELETE FROM %s %s", tableName, whereSQL);
    9691017
    9701018    return query;
Note: See TracChangeset for help on using the changeset viewer.