IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 4297 for trunk/psLib/src/db


Ignore:
Timestamp:
Jun 17, 2005, 11:33:46 AM (21 years ago)
Author:
evanalst
Message:

Update psDBInsertOneRow for invalid arguments.

File:
1 edited

Legend:

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

    r4279 r4297  
    1212 *  @author Joshua Hoblitt
    1313 *
    14  *  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2005-06-16 01:48:18 $
     14 *  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2005-06-17 21:33:46 $
    1616 *
    1717 *  Copyright 2005 Joshua Hoblitt, University of Hawaii
     
    513513    psArray         *rowSet;            // psArray of row to insert
    514514
     515    // Check for null row
     516    if(row == NULL) {
     517        psError(PS_ERR_UNKNOWN,true,PS_ERRORTEXT_psDB_INSERT_ROW_FAIL);
     518        return false;
     519    }
     520
     521    // Create array to store single row
    515522    rowSet = psArrayAlloc(1);
    516523    rowSet->n = 0;
    517524    psArrayAdd(rowSet, 0, row);
    518525
     526    // Execute function to insert rows
    519527    if (!psDBInsertRows(dbh, tableName, rowSet)) {
    520         psError(PS_ERR_UNKNOWN, false, "Insert failed.");
    521 
     528        psError(PS_ERR_UNKNOWN, false, PS_ERRORTEXT_psDB_INSERT_ROW_FAIL);
    522529        psFree(rowSet);
    523 
    524530        return false;
    525531    }
     
    539545    psU64           j;                  // row index
    540546
     547    // Verify database connections is set up
     548    if(dbh == NULL) {
     549        psError(PS_ERR_UNEXPECTED_NULL,true,PS_ERRORTEXT_psDB_INVALID_PSDB);
     550        return false;
     551    }
     552
    541553    // we are assuming that all rows in the set have an identical with reguard
    542554    // to field count and type
    543555    row = rowSet->data[0];
    544556
     557    // Generate SQL query string
    545558    query = psDBGenerateInsertRowSQL(tableName, row);
    546559    if (!query) {
    547         psError(PS_ERR_UNEXPECTED_NULL, false, "Query generation failed.");
    548 
    549         return NULL;
    550     }
    551 
     560        psError(PS_ERR_UNEXPECTED_NULL, false, PS_ERRORTEXT_psDB_QUERY_GEN_FAIL);
     561        return false;
     562    }
     563
     564    // Prepare SQL statement
    552565    stmt = mysql_stmt_init(dbh->mysql);
    553566    if (!stmt) {
    554567        psAbort(__func__, "mysql_stmt_init(), out of memory.");
    555568    }
    556 
    557569    if (mysql_stmt_prepare(stmt, query, (unsigned long)strlen(query))) {
    558570        psError(PS_ERR_UNKNOWN, true, "Failed to prepare query.  Error: %s", mysql_stmt_error(stmt));
    559 
    560571        mysql_stmt_close(stmt);
    561572        psFree(query);
    562 
    563573        return false;
    564574    }
Note: See TracChangeset for help on using the changeset viewer.