Index: /trunk/psLib/test/dataIO/tst_psDB.c
===================================================================
--- /trunk/psLib/test/dataIO/tst_psDB.c	(revision 4382)
+++ /trunk/psLib/test/dataIO/tst_psDB.c	(revision 4383)
@@ -9,6 +9,6 @@
  *  @author Aaron Culliney, MHPCC
  *
- *  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-24 02:11:59 $
+ *  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-06-24 21:31:13 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -72,7 +72,9 @@
 static psMetadata *_get_invalid_row( void );
 static psMetadata *_get_where( void );
+static psMetadata *_get_invalid_where( void );
+static psMetadata *_get_where_bad_value( void );
 static psMetadata *_get_update_values(const char *val0, psS32 val1, psF32 val2, psF64 val3, psBool val4);
-static void _print_row( psMetadata *row );
 static bool _check_row(psMetadata* row);
+static bool _check_row_update(psMetadata* row);
 static bool _check_const_row1(psMetadata* row);
 static bool _check_const_row2(psMetadata* row);
@@ -106,5 +108,5 @@
                               {TPDBDumpRows,       850,  "dbDumpRows",        0, false},
                               {TPDBDumpCols,       851,  "dbDumpCols",        0, false},
-                              {TPDBUpdateRows,      -12, "dbUpdateRows",      0, false},
+                              {TPDBUpdateRows,     852,  "dbUpdateRows",      0, false},
                               {TPDBDeleteRows,      -13, "dbDeleteRows",      0, false},
                               //{TPDBCreate,        -14, "dbCreate",          0, false},
@@ -280,4 +282,52 @@
 }
 
+psMetadata *_get_invalid_where( void )
+{
+    psMetadata *md = NULL;
+    psMetadataItem *s32=NULL;
+
+    md = psMetadataAlloc();
+    if (md == NULL) {
+        psError(PS_ERR_UNKNOWN, true, "could not create psMetadata in %s!", __func__ );
+        return NULL;
+    }
+    s32 = psMetadataItemAllocS32("col999", "", S32_1);
+    if (s32 == NULL) {
+        psError(PS_ERR_UNKNOWN, true, "could not create psMetadataItem in %s!", __func__ );
+        return NULL;
+    }
+    if (!psMetadataAddItem(md, s32, 0, 0)) {
+        psError(PS_ERR_UNKNOWN, true, "could not add psMetadataItem(s) to psMetadata in %s!", __func__ );
+        return NULL;
+    }
+
+    psFree(s32);
+    return md;
+}
+
+psMetadata *_get_where_bad_value( void )
+{
+    psMetadata *md = NULL;
+    psMetadataItem *s32=NULL;
+
+    md = psMetadataAlloc();
+    if (md == NULL) {
+        psError(PS_ERR_UNKNOWN, true, "could not create psMetadata in %s!", __func__ );
+        return NULL;
+    }
+    s32 = psMetadataItemAllocS32(TAB_COL_1_NAME, "", S32_1 + 1);
+    if (s32 == NULL) {
+        psError(PS_ERR_UNKNOWN, true, "could not create psMetadataItem in %s!", __func__ );
+        return NULL;
+    }
+    if (!psMetadataAddItem(md, s32, 0, 0)) {
+        psError(PS_ERR_UNKNOWN, true, "could not add psMetadataItem(s) to psMetadata in %s!", __func__ );
+        return NULL;
+    }
+
+    psFree(s32);
+    return md;
+}
+
 psMetadata *_get_update_values(const char *val0, psS32 val1, psF32 val2, psF64 val3, psBool val4)
 {
@@ -328,4 +378,47 @@
 }
 
+bool _check_row_update(psMetadata* row)
+{
+    bool              returnValue = true;
+    psMetadataItem*   item        = NULL;
+
+    item = psMetadataLookup(row,TAB_COL_0_NAME);
+    if((item==NULL) || (strcmp(item->data.V,STR_2)!=0)) {
+        psError(PS_ERR_UNKNOWN,true,"Column key_string item %s not as expected %s",
+                item->data.V,STR_2);
+        return false;
+    }
+
+    item = psMetadataLookup(row,TAB_COL_1_NAME);
+    if((item==NULL) || (item->data.S32 != S32_2)) {
+        psError(PS_ERR_UNKNOWN,true,"Column key_s32 item %d not as expected %d",
+                item->data.S32, S32_2);
+        return false;
+    }
+
+    item = psMetadataLookup(row,TAB_COL_2_NAME);
+    if((item==NULL) || (fabs(item->data.F32-F32_2)>ERROR_TOL)) {
+        psError(PS_ERR_UNKNOWN,true,"Column key_f32 item %f not as expected %f",
+                item->data.F32, F32_2);
+        return false;
+    }
+
+    item = psMetadataLookup(row,TAB_COL_3_NAME);
+    if((item==NULL) || (fabs(item->data.F64-F64_2)>ERROR_TOL)) {
+        psError(PS_ERR_UNKNOWN,true,"Column key_f64 item %lf not as expected %lf",
+                item->data.F64,F64_2);
+        return false;
+    }
+
+    item = psMetadataLookup(row,TAB_COL_4_NAME);
+    if((item==NULL) || (item->data.B != B_2)) {
+        psError(PS_ERR_UNKNOWN,true,"Column key_bool item %d not as expected %d",
+                item->data.B, B_2);
+        return false;
+    }
+
+    return returnValue;
+}
+
 bool _check_const_row1(psMetadata* row)
 {
@@ -412,27 +505,4 @@
 
     return returnValue;
-}
-
-void _print_row( psMetadata *row )
-{
-    psMetadataIterator *iter=NULL;
-    psMetadataItem *item=NULL;
-
-    iter = psMetadataIteratorAlloc(row, 0, NULL);
-    while ((item = psMetadataGetAndIncrement(iter)) != NULL) {
-        if (item->type == PS_META_STR) {
-            psLogMsg( __func__, PS_LOG_INFO, "[%s]=[%s]\n", item->name, item->data.V );
-        } else if (item->type == PS_META_S32) {
-            psLogMsg( __func__, PS_LOG_INFO, "[%s]=[%d]\n", item->name, item->data.S32 );
-        } else if (item->type == PS_META_F32) {
-            psLogMsg( __func__, PS_LOG_INFO, "[%s]=[%g]\n", item->name, item->data.F32 );
-        } else if (item->type == PS_META_F64) {
-            psLogMsg( __func__, PS_LOG_INFO, "[%s]=[%g]\n", item->name, item->data.F64 );
-        } else if (item->type == PS_META_BOOL) {
-            psLogMsg( __func__, PS_LOG_INFO, "[%s]=[%s]\n", item->name, item->data.B ? "Yay" : "Nay" );
-        }
-    }
-
-    psFree(iter);
 }
 
@@ -1752,82 +1822,172 @@
 }
 
-// Testpoint #XXX, TPDBUpdateRows shall update rows in a test table ...
+// Testpoint #852, TPDBUpdateRows shall update rows in a test table ...
 psS32 TPDBUpdateRows( void )
 {
-    psS32 failed = 0;
-    psDB *dbh = NULL;
-    const char* table = "table10";
-    psArray *ary=NULL, *rowSet=NULL;
-    psMetadata *row=NULL, *where=NULL, *updates=NULL, *md = _get_CreateTableMetadata();
-    psMetadataItem *item=NULL;
-
+    psDB*            dbh       = NULL;
+    const char*      table     = "table10";
+    psArray*         ary       = NULL;
+    psArray*         rowSet    = NULL;
+    psMetadata*      row       = NULL;
+    psMetadata*      where     = NULL;
+    psMetadata*      updates   = NULL;
+    psMetadata*      md        = NULL;
+    int              chgRows   = 0;
+
+    // Create database table definition
+    md = _get_CreateTableMetadata();
+
+    // Initialize database connection
     dbh = _init_psDB();
     if (dbh == NULL) {
+        psError(PS_ERR_UNKNOWN,true,"Did not expect return NULL when initializing database");
         return 1;
     }
 
-    psLogMsg( __func__, PS_LOG_INFO, "psDBUpdateRows shall update rows in a test table.\n" );
-
-    failed = ! psDBCreateTable(dbh, table, md);
-    if (!failed) {
-        rowSet = psArrayAlloc(3);
-        rowSet->n = 0;
-
-        row = _get_const_row1();
-        psArrayAdd(rowSet, 0, row);
-        psFree(row);
-
-        row = _get_const_row2();
-        psArrayAdd(rowSet, 0, row);
-        psFree(row);
-
-        row = _get_row();
-        psArrayAdd(rowSet, 0, row);
-        psFree(row);
-
-        failed = ! psDBInsertRows(dbh, table, rowSet);
-        if (!failed) {
-            where = _get_where();
-            updates = _get_update_values(STR_2, S32_2, F32_2, F64_2, B_2);
-            failed = (psDBUpdateRows(dbh, table, where, updates) < 0);
-
-            ary = psDBDumpRows(dbh, table);
-            if (ary == NULL) {
-                failed = 1;
-            } else {
-
-                row = (psMetadata*)psArrayGet(ary, 0);
-                _print_row(row);
-
-                item = psMetadataLookup(row, TAB_COL_1_NAME);
-                if ((item == NULL) || (item->data.S32 != S32_2)) {
-                    psLogMsg( __func__, PS_LOG_INFO, "oops, did not find expected output!\n" );
-                    failed = 1;
-                } else {
-                    psLogMsg( __func__, PS_LOG_INFO, "found expected output.\n" );
-                }
-
-                item = psMetadataLookup(row, TAB_COL_4_NAME);
-                if ((item == NULL) || (item->data.B != B_2)) {
-                    psLogMsg( __func__, PS_LOG_INFO, "oops, did not find expected output!\n" );
-                    failed = 1;
-                } else {
-                    psLogMsg( __func__, PS_LOG_INFO, "found expected output.\n" );
-                }
-
-                psFree(ary);
-            }
-
-            psFree(updates);
-            psFree(where);
-        }
-        psFree(rowSet);
-        psDBDropTable(dbh, table);
-    }
+    // Create test table
+    if(!psDBCreateTable(dbh, table, md)) {
+        psError(PS_ERR_UNKNOWN,true,"Did not expect return false to create test table");
+        psDBCleanup(dbh);
+        return 2;
+    }
+
+    // Create array to hold rows to be added to test table
+    rowSet = psArrayAlloc(3);
+    rowSet->n = 0;
+
+    row = _get_const_row1();
+    psArrayAdd(rowSet, 0, row);
+    psFree(row);
+
+    row = _get_const_row2();
+    psArrayAdd(rowSet, 0, row);
+    psFree(row);
+
+    row = _get_row();
+    psArrayAdd(rowSet, 0, row);
+    psFree(row);
+
+    // Insert rows into test table
+    if(!psDBInsertRows(dbh, table, rowSet)) {
+        psError(PS_ERR_UNKNOWN,true,"Did not expect return false for inserting rows");
+        psDBDropTable(dbh,table);
+        psDBCleanup(dbh);
+        return 3;
+    }
+
+    // Create where metadata to specify update - only one row
+    where = _get_where();
+
+    // Create update metadata to specify values
+    updates = _get_update_values(STR_2, S32_2, F32_2, F64_2, B_2);
+
+    // Perform database update with valid parameters
+    chgRows = psDBUpdateRows(dbh,table,where,updates);
+    if(chgRows != 1) {
+        psError(PS_ERR_UNKNOWN,true,"Did not expect return other than 1 for valid arguments");
+        psDBDropTable(dbh,table);
+        psDBCleanup(dbh);
+        return 4;
+    }
+    // Verify row contents after update
+    ary = psDBDumpRows(dbh, table);
+    if (ary == NULL) {
+        psError(PS_ERR_UNKNOWN,true,"Did not expect NULL return from dump rows");
+        psDBDropTable(dbh,table);
+        psDBCleanup(dbh);
+        return 5;
+    }
+    row = (psMetadata*)psArrayGet(ary, 0);
+    if(!_check_row_update(row)) {
+        psError(PS_ERR_UNKNOWN,true,"Update row not verified");
+        psDBDropTable(dbh,table);
+        psDBCleanup(dbh);
+        return 6;
+    }
+    psFree(ary);
+
+    // Attempt to update rows with NULL database
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL database");
+    chgRows = psDBUpdateRows(NULL,table,where,updates);
+    if(chgRows != -1) {
+        psError(PS_ERR_UNKNOWN,true,"Updated rows %ld not as expected %ld",
+                chgRows,-1);
+        psDBDropTable(dbh,table);
+        psDBCleanup(dbh);
+        return 7;
+    }
+
+    // Attempt to update rows with invalid table
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid table");
+    chgRows = psDBUpdateRows(dbh,"table999",where,updates);
+    if(chgRows != -1) {
+        psError(PS_ERR_UNKNOWN,true,"Updated rows %ld not as expected %ld",
+                chgRows,-1);
+        psDBDropTable(dbh,table);
+        psDBCleanup(dbh);
+        return 8;
+    }
+
+    // Attempt to update rows with NULL updates
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL updates");
+    chgRows = psDBUpdateRows(dbh,table,where,NULL);
+    if(chgRows != -1) {
+        psError(PS_ERR_UNKNOWN,true,"Updated rows %ld not as expected %ld",
+                chgRows,-1);
+        psDBDropTable(dbh,table);
+        psDBCleanup(dbh);
+        return 8;
+    }
+
+    // Attempt to update rows with invalid where specifying non-existent column
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid where");
+    psFree(where);
+    where = _get_invalid_where();
+    chgRows = psDBUpdateRows(dbh,table,where,updates);
+    if(chgRows != -1) {
+        psError(PS_ERR_UNKNOWN,true,"Updated rows %ld not as expected %ld",
+                chgRows,-1);
+        psDBDropTable(dbh,table);
+        psDBCleanup(dbh);
+        return 9;
+    }
+
+    // Attempt to update rows with bad value in where statement
+    psFree(where);
+    where = _get_where_bad_value();
+    chgRows = psDBUpdateRows(dbh,table,where,updates);
+    if(chgRows != 0) {
+        psError(PS_ERR_UNKNOWN,true,"Updated rows %ld not as expected %ld",
+                chgRows,0);
+        psDBDropTable(dbh,table);
+        psDBCleanup(dbh);
+        return 10;
+    }
+    // Verify row contents after update - no change
+    ary = psDBDumpRows(dbh, table);
+    if (ary == NULL) {
+        psError(PS_ERR_UNKNOWN,true,"Did not expect NULL return from dump rows");
+        psDBDropTable(dbh,table);
+        psDBCleanup(dbh);
+        return 11;
+    }
+    row = (psMetadata*)psArrayGet(ary, 0);
+    if(!_check_row_update(row)) {
+        psError(PS_ERR_UNKNOWN,true,"Update row not verified");
+        psDBDropTable(dbh,table);
+        psDBCleanup(dbh);
+        return 12;
+    }
+    psFree(ary);
+
+    psFree(updates);
+    psFree(where);
+    psFree(rowSet);
+    psDBDropTable(dbh, table);
 
     psFree(md);
     psDBCleanup(dbh);
 
-    return failed;
+    return 0;
 }
 
Index: /trunk/psLib/test/dataIO/verified/tst_psDB.stderr
===================================================================
--- /trunk/psLib/test/dataIO/verified/tst_psDB.stderr	(revision 4382)
+++ /trunk/psLib/test/dataIO/verified/tst_psDB.stderr	(revision 4383)
@@ -281,21 +281,21 @@
 
 <DATE><TIME>|<HOST>|I|TPDBUpdateRows
-    psDBUpdateRows shall update rows in a test table.
-<DATE><TIME>|<HOST>|I|_print_row
-    [key_string]=[foobar]
-<DATE><TIME>|<HOST>|I|_print_row
-    [key_s32]=[-18]
-<DATE><TIME>|<HOST>|I|_print_row
-    [key_f32]=[3.33]
-<DATE><TIME>|<HOST>|I|_print_row
-    [key_f64]=[1.23457]
-<DATE><TIME>|<HOST>|I|_print_row
-    [key_bool]=[Nay]
-<DATE><TIME>|<HOST>|I|_print_row
-    [key_s32_0]=[3]
+    Following should generate an error message for NULL database
+<DATE><TIME>|<HOST>|E|psDBUpdateRows (FILE:LINENO)
+    Invalid psDB has been specified.
 <DATE><TIME>|<HOST>|I|TPDBUpdateRows
-    found expected output.
+    Following should generate an error message for invalid table
+<DATE><TIME>|<HOST>|E|psDBUpdateRows (FILE:LINENO)
+    Failed to prepare query.  Error: Table 'test.table999' doesn't exist
 <DATE><TIME>|<HOST>|I|TPDBUpdateRows
-    found expected output.
+    Following should generate an error message for NULL updates
+<DATE><TIME>|<HOST>|E|psDBGenerateUpdateRowSQL (FILE:LINENO)
+    Update row SQL generate fail: values and where params may not be NULL.
+<DATE><TIME>|<HOST>|E|psDBUpdateRows (FILE:LINENO)
+    Query generation failed.
+<DATE><TIME>|<HOST>|I|TPDBUpdateRows
+    Following should generate an error message for invalid where
+<DATE><TIME>|<HOST>|E|psDBUpdateRows (FILE:LINENO)
+    Failed to prepare query.  Error: Unknown column 'col999' in 'where clause'
 
 ---> TESTPOINT PASSED (psDB{dbUpdateRows} | tst_psDB.c)
