IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 14, 2005, 5:20:04 PM (21 years ago)
Author:
evanalst
Message:

Update psDBCreateTable to handle invalid arguments.

File:
1 edited

Legend:

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

    r4262 r4269  
    1212 *  @author Joshua Hoblitt
    1313 *
    14  *  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2005-06-15 01:47:30 $
     14 *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2005-06-15 03:20:04 $
    1616 *
    1717 *  Copyright 2005 Joshua Hoblitt, University of Hawaii
     
    200200    bool            status;
    201201
     202    // Verify the database object is not NULL
     203    if(dbh == NULL) {
     204        psError(PS_ERR_BAD_PARAMETER_NULL,true,PS_ERRORTEXT_psDB_INVALID_PSDB);
     205        return false;
     206    }
     207
     208    // Generate SQL query string
    202209    query = psDBGenerateCreateTableSQL(tableName, md);
    203210    if (!query) {
    204         psError(PS_ERR_UNEXPECTED_NULL, false, "Query generation failed.");
    205 
    206         return NULL;
    207     }
    208 
     211        psError(PS_ERR_UNEXPECTED_NULL, false, PS_ERRORTEXT_psDB_QUERY_GEN_FAIL);
     212        return false;
     213    }
     214
     215    // Run SQL query to create table
    209216    status = p_psDBRunQuery(dbh, query);
    210217    if (!status) {
    211         psError(PS_ERR_UNKNOWN, false, "Failed to create table.");
    212     }
    213 
     218        psError(PS_ERR_UNKNOWN, false, PS_ERRORTEXT_psDB_TABLE_CREATE_FAIL);
     219    }
     220
     221    // Free query string
    214222    psFree(query);
    215223
     
    775783bool p_psDBRunQuery(psDB *dbh, const char *query)
    776784{
     785    // Verify database object is not NULL
     786    if(dbh == NULL) {
     787        psError(PS_ERR_BAD_PARAMETER_NULL,true,PS_ERRORTEXT_psDB_INVALID_PSDB);
     788        return false;
     789    }
     790
     791    // Run query
    777792    if (mysql_real_query(dbh->mysql, query, (unsigned long)strlen(query)) !=0) {
    778         psError(PS_ERR_UNKNOWN, true, "Failed to execute query.  Error: %s\n", mysql_error(dbh->mysql));
    779 
     793        psError(PS_ERR_UNKNOWN, true, PS_ERRORTEXT_psDB_SQL_QUERY_FAIL, mysql_error(dbh->mysql));
    780794        return false;
    781795    }
     
    880894    char            *colType;           // type lookup table
    881895
    882     if (!table) {
    883         psError(PS_ERR_BAD_PARAMETER_NULL, true, "table param may not be null.");
    884 
     896    // Verify input parameters are not null
     897    if ( (tableName==NULL) || (table==NULL) ) {
     898        psError(PS_ERR_BAD_PARAMETER_NULL, true, PS_ERRORTEXT_psDB_TABLE_PARAM_NULL);
    885899        return NULL;
    886900    }
    887901
     902    // Begin to create SQL string to create table
    888903    psStringAppend(&query, "CREATE TABLE %s (", tableName);
    889904
     905    // Set list iterator at head of list
    890906    cursor = psListIteratorAlloc(table->list, 0, false);
    891907
     
    922938    }
    923939
     940    // Reset iterator to head of list
    924941    psListIteratorSet(cursor, 0);
    925942
Note: See TracChangeset for help on using the changeset viewer.