IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 4279


Ignore:
Timestamp:
Jun 15, 2005, 3:48:18 PM (21 years ago)
Author:
evanalst
Message:

Update function psDBSelectColumn to handle invalid parameters.

Location:
trunk/psLib/src
Files:
4 edited

Legend:

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

    r4271 r4279  
    1212 *  @author Joshua Hoblitt
    1313 *
    14  *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2005-06-15 19:52:21 $
     14 *  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2005-06-16 01:48:18 $
    1616 *
    1717 *  Copyright 2005 Joshua Hoblitt, University of Hawaii
     
    255255    psPtr           data;               // copy of result field
    256256
     257    // Generate SQL query string
    257258    query = psDBGenerateSelectRowSQL(tableName, col, NULL, limit);
    258259    if (!query) {
    259         psError(PS_ERR_UNEXPECTED_NULL, false, "Query generation failed.");
     260        psError(PS_ERR_UNEXPECTED_NULL, false, PS_ERRORTEXT_psDB_QUERY_GEN_FAIL);
    260261        return NULL;
    261262    }
    262263
     264    // Execut SQL query string
    263265    if (!p_psDBRunQuery(dbh, query)) {
    264         psError(PS_ERR_UNKNOWN, false, "Query execution failed.");
     266        psError(PS_ERR_UNKNOWN, false, PS_ERRORTEXT_psDB_SEL_COL_FAIL);
    265267        psFree(query);
    266268        return NULL;
    267269    }
    268 
    269270    psFree(query);
    270271
     272    // Obtain query result and check for no data condition
    271273    result = mysql_store_result(dbh->mysql);
     274
    272275    if (!result) {
    273276        // no result set
     
    277280        // then something bad has happened.
    278281        if (fieldCount != 0) {
    279             psError(PS_ERR_UNEXPECTED_NULL, true, "Query returned no data.  Error: %s", mysql_error(dbh->mysql));
     282            psError(PS_ERR_UNEXPECTED_NULL, true, PS_ERRORTEXT_psDB_QUERY_NO_DATA,
     283                    mysql_error(dbh->mysql));
    280284            return NULL;
    281285        }
    282286    }
    283287
     288    // Get number of rows returned in result
    284289    rowCount = mysql_num_rows(result);
    285290
     
    290295    column->n = 0;
    291296
     297    // Fetch each result
    292298    while ((row = mysql_fetch_row(result))) {
    293299        // get the first element of lengths array that is part of the
     
    309315    }
    310316
     317    // Clean up mysql memory
    311318    mysql_free_result(result);
    312319
  • trunk/psLib/src/dataIO/psFileUtilsErrors.dat

    r4271 r4279  
    6565psDB_SQL_QUERY_FAIL                    Failed to execute SQL query.  Error: %s
    6666psDB_TABLE_DROP_FAIL                   Failed to drop table.
     67psDB_SEL_COL_FAIL                      Failed to select column.
     68psDB_QUERY_NO_DATA                     Query returned no data.  Error: %s
    6769#
    6870
  • trunk/psLib/src/dataIO/psFileUtilsErrors.h

    r4271 r4279  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2005-06-15 19:52:21 $
     9 *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2005-06-16 01:48:18 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    8484#define PS_ERRORTEXT_psDB_SQL_QUERY_FAIL "Failed to execute SQL query.  Error: %s"
    8585#define PS_ERRORTEXT_psDB_TABLE_DROP_FAIL "Failed to drop table."
     86#define PS_ERRORTEXT_psDB_SEL_COL_FAIL "Failed to select column."
     87#define PS_ERRORTEXT_psDB_QUERY_NO_DATA "Query returned no data.  Error: %s"
    8688//~End
    8789
  • trunk/psLib/src/db/psDB.c

    r4271 r4279  
    1212 *  @author Joshua Hoblitt
    1313 *
    14  *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2005-06-15 19:52:21 $
     14 *  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2005-06-16 01:48:18 $
    1616 *
    1717 *  Copyright 2005 Joshua Hoblitt, University of Hawaii
     
    255255    psPtr           data;               // copy of result field
    256256
     257    // Generate SQL query string
    257258    query = psDBGenerateSelectRowSQL(tableName, col, NULL, limit);
    258259    if (!query) {
    259         psError(PS_ERR_UNEXPECTED_NULL, false, "Query generation failed.");
     260        psError(PS_ERR_UNEXPECTED_NULL, false, PS_ERRORTEXT_psDB_QUERY_GEN_FAIL);
    260261        return NULL;
    261262    }
    262263
     264    // Execut SQL query string
    263265    if (!p_psDBRunQuery(dbh, query)) {
    264         psError(PS_ERR_UNKNOWN, false, "Query execution failed.");
     266        psError(PS_ERR_UNKNOWN, false, PS_ERRORTEXT_psDB_SEL_COL_FAIL);
    265267        psFree(query);
    266268        return NULL;
    267269    }
    268 
    269270    psFree(query);
    270271
     272    // Obtain query result and check for no data condition
    271273    result = mysql_store_result(dbh->mysql);
     274
    272275    if (!result) {
    273276        // no result set
     
    277280        // then something bad has happened.
    278281        if (fieldCount != 0) {
    279             psError(PS_ERR_UNEXPECTED_NULL, true, "Query returned no data.  Error: %s", mysql_error(dbh->mysql));
     282            psError(PS_ERR_UNEXPECTED_NULL, true, PS_ERRORTEXT_psDB_QUERY_NO_DATA,
     283                    mysql_error(dbh->mysql));
    280284            return NULL;
    281285        }
    282286    }
    283287
     288    // Get number of rows returned in result
    284289    rowCount = mysql_num_rows(result);
    285290
     
    290295    column->n = 0;
    291296
     297    // Fetch each result
    292298    while ((row = mysql_fetch_row(result))) {
    293299        // get the first element of lengths array that is part of the
     
    309315    }
    310316
     317    // Clean up mysql memory
    311318    mysql_free_result(result);
    312319
Note: See TracChangeset for help on using the changeset viewer.