IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 24, 2005, 3:16:50 PM (21 years ago)
Author:
evanalst
Message:

Update function psDBDeleteRows to handle invalid arguments.

File:
1 edited

Legend:

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

    r4382 r4389  
    1212 *  @author Joshua Hoblitt
    1313 *
    14  *  @version $Revision: 1.33 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2005-06-24 21:29:41 $
     14 *  @version $Revision: 1.34 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2005-06-25 01:16:50 $
    1616 *
    1717 *  Copyright 2005 Joshua Hoblitt, University of Hawaii
     
    783783{
    784784    char            *query;
    785 
     785    psS64           rows = 0;
     786
     787    // Verify database is not NULL
     788    if(dbh == NULL) {
     789        psError(PS_ERR_UNEXPECTED_NULL, true, PS_ERRORTEXT_psDB_INVALID_PSDB);
     790        return -1;
     791    }
     792
     793    // Create SQL statement string
    786794    query = psDBGenerateDeleteRowSQL(tableName, where);
    787795    if (!query) {
    788796        psError(PS_ERR_UNEXPECTED_NULL, false, "Query generation failed.");
    789 
    790797        return -1;
    791798    }
    792799
     800    // Run SQL query
    793801    if (!p_psDBRunQuery(dbh, query)) {
    794802        psError(PS_ERR_UNKNOWN, false, "Delete failed.");
    795 
    796803        mysql_rollback(dbh->mysql);
    797 
    798804        psFree(query);
    799 
    800805        return -1;
    801806    }
    802 
    803807    psFree(query);
    804808
    805     if (!where) {
    806         // we truncated the table so mysql_affected_rows() won't work
    807         return 1;
    808     }
     809    // Get the number of affected row for the delete command
     810    rows = (psS64)mysql_affected_rows(dbh->mysql);
    809811
    810812    // point of no return
    811813    mysql_commit(dbh->mysql);
    812814
    813     return (psS64)mysql_affected_rows(dbh->mysql);
     815    return rows;
    814816}
    815817
     
    11381140    if (!where) {
    11391141        psStringAppend(&query, "TRUNCATE TABLE %s", tableName);
    1140 
    11411142        return query;
    11421143    }
    11431144
     1145    // Generate where SQL substring
    11441146    whereSQL = psDBGenerateWhereSQL(where);
    11451147    if (!whereSQL) {
    1146         psError(PS_ERR_UNEXPECTED_NULL, false, "SQL substring generation failed.");
    1147 
    1148         return NULL;
    1149     }
    1150 
     1148        psError(PS_ERR_UNEXPECTED_NULL, false, PS_ERRORTEXT_psDB_SQL_SUBSTR_FAIL);
     1149        return NULL;
     1150    }
     1151
     1152    // Complete delete SQL command string
    11511153    psStringAppend(&query, "DELETE FROM %s %s", tableName, whereSQL);
    11521154    psFree(whereSQL);
     
    11631165    if (!where) {
    11641166        psError(PS_ERR_BAD_PARAMETER_NULL, true, "where param may not be NULL.");
    1165 
    11661167        return NULL;
    11671168    }
Note: See TracChangeset for help on using the changeset viewer.