IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 4269


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

Update psDBCreateTable to handle invalid arguments.

Location:
trunk/psLib/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/dataIO/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
  • trunk/psLib/src/dataIO/psFileUtilsErrors.dat

    r4262 r4269  
    6060psDB_FAILED_TO_CONNECT                 Failed to connect to database.  Error: %s
    6161psDB_FAILED_TO_CHANGE                  Failed to change database.  Error: %s
     62psDB_TABLE_PARAM_NULL                  Create table parameters may not be NULL.
     63psDB_QUERY_GEN_FAIL                    Query generation failed.
     64psDB_TABLE_CREATE_FAIL                 Failed to create table.
     65psDB_SQL_QUERY_FAIL                    Failed to execute SQL query.  Error: %s
    6266#
    6367
  • trunk/psLib/src/dataIO/psFileUtilsErrors.h

    r4262 r4269  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2005-06-15 01:47:30 $
     9 *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2005-06-15 03:20:04 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    7979#define PS_ERRORTEXT_psDB_FAILED_TO_CONNECT "Failed to connect to database.  Error: %s"
    8080#define PS_ERRORTEXT_psDB_FAILED_TO_CHANGE "Failed to change database.  Error: %s"
     81#define PS_ERRORTEXT_psDB_TABLE_PARAM_NULL "Create table parameters may not be NULL."
     82#define PS_ERRORTEXT_psDB_QUERY_GEN_FAIL "Query generation failed."
     83#define PS_ERRORTEXT_psDB_TABLE_CREATE_FAIL "Failed to create table."
     84#define PS_ERRORTEXT_psDB_SQL_QUERY_FAIL "Failed to execute SQL query.  Error: %s"
    8185//~End
    8286
  • 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.