Index: /trunk/psLib/test/astronomy/Makefile.am
===================================================================
--- /trunk/psLib/test/astronomy/Makefile.am	(revision 3530)
+++ /trunk/psLib/test/astronomy/Makefile.am	(revision 3531)
@@ -19,4 +19,5 @@
          tst_psTime_03 \
          tst_psTime_04 \
+         tst_psDB \
          tst_psMetadataIO  \
          tst_psMetadata_01 \
@@ -53,4 +54,5 @@
 tst_psTime_03_SOURCES = tst_psTime_03.c
 tst_psTime_04_SOURCES = tst_psTime_04.c
+tst_psDB_SOURCES = tst_psDB.c
 tst_psMetadataIO_SOURCES = tst_psMetadataIO.c
 tst_psMetadata_01_SOURCES = tst_psMetadata_01.c
Index: /trunk/psLib/test/astronomy/tst_psDB.c
===================================================================
--- /trunk/psLib/test/astronomy/tst_psDB.c	(revision 3531)
+++ /trunk/psLib/test/astronomy/tst_psDB.c	(revision 3531)
@@ -0,0 +1,605 @@
+/** @file  tst_psDB.c
+*
+* -*- mode: C; c-basic-indent: 4; tab-width: 8; indent-tabs-mode: nil -*-
+* vim: set cindent ts=8 sw=4 expandtab:
+*
+*  @brief Contains the tests for psDB.[ch]
+*
+*
+*  @author Aaron Culliney, MHPCC
+*
+*  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-03-28 22:52:32 $
+*
+*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
+*
+*/
+
+#define PS_ALLOW_MALLOC // for MySQL internals ...
+
+#include <unistd.h>
+#include <sys/wait.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <limits.h>
+#include <stdlib.h>
+
+#include "psDB.h"
+#include "psTest.h"
+#include "pslib.h"
+
+static psDB *_init_psDB( void );
+static void  _cleanup_psDB(psDB *dbh);
+static psMetadata *_get_CreateTableMetadata( void );
+static psMetadata *_get_RowMetadataValues(const char *val0, psS32 val1, psF32 val2, psF64 val3);
+static psMetadata *_get_RowMetadata(
+    const char *key0, const char *comm0, const char *val0,
+    const char *key1, const char *comm1, psS32 val1,
+    const char *key2, const char *comm2, psF32 val2,
+    const char *key3, const char *comm3, psF64 val3);
+static psMetadata *_get_row( void );
+static psMetadata *_get_where( void );
+static psMetadata *_get_update_values(const char *val0, psS32 val1, psF32 val2, psF64 val3);
+
+//static psS32 TPDBCreate( void );
+//static psS32 TPDBDrop( void );
+static psS32 TPDBInit( void );
+static psS32 TPDBChange( void );
+static psS32 TPDBCreateTable( void );
+static psS32 TPDBDropTable( void );
+static psS32 TPDBSelectColumn( void );
+static psS32 TPDBSelectColumnNum( void );
+static psS32 TPDBSelectRows( void );
+static psS32 TPDBInsertOneRow( void );
+static psS32 TPDBInsertRows( void );
+static psS32 TPDBDumpRows( void );
+static psS32 TPDBDumpCols( void );
+static psS32 TPDBUpdateRows( void );
+static psS32 TPDBDeleteRows( void );
+
+testDescription tests[] = {
+                              {TPDBInit,            -1,  "dbInit",            0, false},
+                              {TPDBCreateTable,     -1,  "dbCreateTable",     0, false},
+                              {TPDBDropTable,       -2,  "dbDropTable",       0, true},
+                              {TPDBSelectColumn,    -3,  "dbSelectColumn",    0, true},
+                              {TPDBSelectColumnNum, -4,  "dbSelectColumnNum", 0, true},
+                              {TPDBSelectRows,      -5,  "dbSelectRows",      0, true},
+                              {TPDBInsertOneRow,    -6,  "dbInsertOneRow",    0, true},
+                              {TPDBInsertRows,      -7,  "dbInsertRows",      0, true},
+                              {TPDBDumpRows,        -8,  "dbDumpRows",        0, true},
+                              {TPDBDumpCols,        -9,  "dbDumpCols",        0, true},
+                              {TPDBUpdateRows,      -10, "dbUpdateRows",      0, true},
+                              {TPDBDeleteRows,      -11, "dbDeleteRows",      0, true},
+                              {TPDBChange,          -12, "dbChange",          0, true},
+                              //{TPDBCreate,        -15, "dbCreate",          0, false},
+                              //{TPDBDrop,          -16, "dbDrop",            0, false},
+                              {NULL}
+                          };
+
+static const char *host    = "localhost";
+static const char *user    = "test";
+static const char *passwd  = "";
+static const char *dbname  = "test";
+
+// internal method to initialize DB
+psDB *_init_psDB( void )
+{
+    psDB *dbh = NULL;
+
+    psLogMsg( __func__, PS_LOG_INFO, "initialize database connection...\n" );
+
+    dbh = psDBInit(host, user, passwd, dbname);
+    if (dbh == NULL) {
+        psError(PS_ERR_UNKNOWN, true, "could not initialize DB connection in %s!", __func__ );
+    }
+
+    return dbh;
+}
+
+// internal method to handle DB cleanup
+void _cleanup_psDB(psDB *dbh)
+{
+    psDBCleanup(dbh);
+}
+
+psMetadata *_get_CreateTableMetadata( void )
+{
+    return _get_RowMetadata(
+               "key_string", "comment-string", "90000",  // XXX value used to determine size of field ...
+               "key_s32",    "comment-s32",     0,       // NOTE: values unused here
+               "key_f32",    "comment-f32",     0.0,
+               "key_f64",    "comment-f64",     0.0);
+}
+
+psMetadata *_get_RowMetadataValues(const char *val0, psS32 val1, psF32 val2, psF64 val3)
+{
+    return _get_RowMetadata(
+               "key_string", "comment-string", val0,
+               "key_s32",    "comment-s32",    val1,
+               "key_f32",    "comment-f32",    val2,
+               "key_f64",    "comment-f64",    val3);
+}
+
+psMetadata *_get_RowMetadata(
+    const char *key0, const char *comm0, const char *val0,
+    const char *key1, const char *comm1, psS32 val1,
+    const char *key2, const char *comm2, psF32 val2,
+    const char *key3, const char *comm3, psF64 val3)
+{
+    psMetadata *md = NULL;
+    psMetadataItem *str=NULL, *s32=NULL, *f32=NULL, *f64=NULL;
+
+    md = psMetadataAlloc();
+    if (md == NULL) {
+        psError(PS_ERR_UNKNOWN, true, "could not create psMetadata in %s!", __func__ );
+        return NULL;
+    }
+    str = psMetadataItemAllocStr(key0, comm0, val0);
+    //psLogMsg( __func__, PS_LOG_INFO, "MetaDataItemType (%d).\n", str->type );
+    s32 = psMetadataItemAllocS32(key1, comm1, val1);
+    //psLogMsg( __func__, PS_LOG_INFO, "MetaDataItemType (%d).\n", s32->type );
+    f32 = psMetadataItemAllocF32(key2, comm2, val2);
+    //psLogMsg( __func__, PS_LOG_INFO, "MetaDataItemType (%d).\n", f32->type );
+    f64 = psMetadataItemAllocF64(key3, comm3, val3);
+    //psLogMsg( __func__, PS_LOG_INFO, "MetaDataItemType (%d).\n", f64->type );
+    if ((str == NULL) || (s32 == NULL) || (f32 == NULL) || (f64 == NULL)) {
+        psError(PS_ERR_UNKNOWN, true, "could not create psMetadataItem(s) in %s!", __func__ );
+        return NULL;
+    }
+    if ( !psMetadataAddItem(md, str, 0, 0) || !psMetadataAddItem(md, s32, 0, 0) ||
+            !psMetadataAddItem(md, f32, 0, 0) || !psMetadataAddItem(md, f64, 0, 0)) {
+        psError(PS_ERR_UNKNOWN, true, "could not add psMetadataItem(s) to psMetadata in %s!", __func__ );
+        return NULL;
+    }
+
+    return md;
+}
+
+void _cleanup_Metadata (psMetadata *md)
+{
+    psMetadataItem* item = NULL;
+    psMetadataIterator* mdi = psMetadataIteratorAlloc(md, 0, NULL);
+    while ((item = psMetadataGetAndIncrement(mdi)) != NULL) {
+        psFree(item);
+    }
+    psFree(mdi);
+    psFree(md);
+}
+
+psMetadata *_get_row( void )
+{
+    return _get_RowMetadata(
+               "key_string", "comment-string", "hello world!",
+               "key_s32",    "comment-s32",     1974,
+               "key_f32",    "comment-f32",     3.14159,
+               "key_f64",    "comment-f64",     2.71828);
+}
+
+psMetadata *_get_where( void )
+{
+    return _get_row();
+}
+
+psMetadata *_get_update_values(const char *val0, psS32 val1, psF32 val2, psF64 val3)
+{
+    return _get_RowMetadataValues(val0, val1, val2, val3);
+}
+
+psS32 main(psS32 argc, char* argv[])
+{
+    psLogSetLevel( PS_LOG_INFO );
+
+    return ( ! runTestSuite( stderr, "psDB", tests, argc, argv ) );
+}
+
+// Testpoint #XXX, initialize/break-down MySQL connection.
+psS32 TPDBInit( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBInit/psDBCleanup shall initialize/cleanup database connection.\n" );
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, psDBCreate shall create a new test database.
+psS32 TPDBCreate( void )
+{
+    const char *test_db = "ps_test_db";
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBCreate shall create new new test database.\n" );
+
+    failed = ! psDBCreate(dbh, test_db);
+    if (!failed) {
+        psDBDrop(dbh, test_db);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, psDBDrop shall create a new test database.
+psS32 TPDBDrop( void )
+{
+    const char *test_db = "ps_test_db";
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBDrop shall create/drop a new new test database.\n" );
+
+    failed = psDBCreate(dbh, test_db);
+    if (!failed) {
+        failed = ! psDBDrop(dbh, test_db);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, psDBChange shall change databases.
+psS32 TPDBChange( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBChange shall change to a new new test database.\n" );
+
+    failed = ! psDBChange(dbh, dbname);
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, psDBCreateTable shall create tables in the test database ...
+psS32 TPDBCreateTable( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+    const char* table = "table1";
+    psMetadata *md = _get_CreateTableMetadata();
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBCreateTable shall create a new table in the new test database.\n" );
+
+    failed = ! psDBCreateTable(dbh, table, md);
+    if (!failed) {
+        psDBDropTable(dbh, table);
+    }
+
+    _cleanup_Metadata(md);
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, psDBDropTable shall create tables in the test database ...
+psS32 TPDBDropTable( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+    const char* table = "table2";
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBDropTable shall create/drop a new table in the new test database.\n" );
+
+    failed = ! psDBCreateTable(dbh, table, _get_CreateTableMetadata());
+    if (!failed) {
+        failed = ! psDBDropTable(dbh, table);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, TPDBSelectColumn shall write/select a column from a test table ...
+psS32 TPDBSelectColumn( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+    const char* table = "table3";
+    psArray *ary = NULL;
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBSelectColumn shall select data from a test table.\n" );
+
+    failed = ! psDBCreateTable(dbh, table, _get_CreateTableMetadata());
+    if (!failed) {
+        ary = psDBSelectColumn(dbh, table, "", 1);
+        failed = (ary == NULL);
+        psDBDropTable(dbh, table);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, TPDBSelectColumnNum shall write/select a column from a test table ...
+psS32 TPDBSelectColumnNum( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+    const char* table = "table4";
+    psVector *vec = NULL;
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBSelectColumnNum shall select data from a test table.\n" );
+
+    failed = ! psDBCreateTable(dbh, table, _get_CreateTableMetadata());
+    if (!failed) {
+        vec = psDBSelectColumnNum(dbh, table, "key-string", PS_TYPE_PTR, 1);
+        failed = (vec == NULL);
+        psDBDropTable(dbh, table);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, TPDBSelectRows shall write/select data from a test table ...
+psS32 TPDBSelectRows( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+    const char* table = "table5";
+    psArray *ary = NULL;
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBSelectRows shall select data from a test table.\n" );
+
+    failed = ! psDBCreateTable(dbh, table, _get_CreateTableMetadata());
+    if (!failed) {
+        psDBInsertOneRow(dbh, table, _get_row());             // 3X rows for general case
+        psDBInsertOneRow(dbh, table, _get_row());
+        failed = ! psDBInsertOneRow(dbh, table, _get_row());
+        if (!failed) {
+            ary = psDBSelectRows(dbh, table, _get_where(), 0);
+            failed = (ary == NULL);
+        }
+        psDBDropTable(dbh, table);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, TPDBInsertOneRow shall write a row of data into a test table ...
+psS32 TPDBInsertOneRow( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+    const char* table = "table6";
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBInsertOneRow shall insert a row into a test table.\n" );
+
+    failed = ! psDBCreateTable(dbh, table, _get_CreateTableMetadata());
+    if (!failed) {
+        failed = ! psDBInsertOneRow(dbh, table, _get_row());
+        psDBDropTable(dbh, table);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, TPDBInsertRows shall write rows of data into a test table ...
+psS32 TPDBInsertRows( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+    const char* table = "table7";
+    psArray *rowSet = NULL;
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBInsertRows shall insert rows into a test table.\n" );
+
+    failed = ! psDBCreateTable(dbh, table, _get_CreateTableMetadata());
+    if (!failed) {
+        rowSet = psArrayAlloc(1);
+        rowSet->n = 0;
+        psArrayAdd(rowSet, 0, _get_row());
+        psArrayAdd(rowSet, 0, _get_row());
+        psArrayAdd(rowSet, 0, _get_row());
+        failed = ! psDBInsertRows(dbh, table, rowSet);
+        psDBDropTable(dbh, table);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, TPDBDumpRows shall dump all rows from a test table ...
+psS32 TPDBDumpRows( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+    const char* table = "table8";
+    psArray *rowSet = NULL;
+    psArray *ary = NULL;
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBDumpRows shall dump all rows from a test table.\n" );
+
+    failed = ! psDBCreateTable(dbh, table, _get_CreateTableMetadata());
+    if (!failed) {
+        rowSet = psArrayAlloc(1);
+        rowSet->n = 0;
+        psArrayAdd(rowSet, 0, _get_row());
+        psArrayAdd(rowSet, 0, _get_row());
+        psArrayAdd(rowSet, 0, _get_row());
+        failed = ! psDBInsertRows(dbh, table, rowSet);
+        if (!failed) {
+            ary = psDBDumpRows(dbh, table);
+            failed = (ary == NULL);
+        }
+        psDBDropTable(dbh, table);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, TPDBDumpCols shall dump all cols from a test table ...
+psS32 TPDBDumpCols( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+    const char* table = "table9";
+    psMetadata *meta = NULL;
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBDumpCols shall dump all cols from a test table.\n" );
+
+    failed = ! psDBCreateTable(dbh, table, _get_CreateTableMetadata());
+    if (!failed) {
+        meta = psDBDumpCols(dbh, table);
+        failed = (meta == NULL);
+        psDBDropTable(dbh, table);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, TPDBUpdateRows shall update rows in a test table ...
+psS32 TPDBUpdateRows( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+    const char* table = "table10";
+    psArray *rowSet = NULL;
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBUpdateRows shall dump all rows from a test table.\n" );
+
+    failed = ! psDBCreateTable(dbh, table, _get_CreateTableMetadata());
+    if (!failed) {
+        rowSet = psArrayAlloc(1);
+        rowSet->n = 0;
+        psArrayAdd(rowSet, 0, _get_row());
+        psArrayAdd(rowSet, 0, _get_row());
+        psArrayAdd(rowSet, 0, _get_row());
+        failed = ! psDBInsertRows(dbh, table, rowSet);
+        if (!failed) {
+            failed = (psDBUpdateRows(dbh, table, _get_where(), _get_update_values(
+                                         "foobar", -1, 3.3333, 1234.5)) < 0);
+        }
+        psDBDropTable(dbh, table);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, TPDBDeleteRows shall update rows in a test table ...
+psS32 TPDBDeleteRows( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+    const char* table = "table10";
+    psArray *rowSet = NULL;
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBDeleteRows shall delete rows from a test table.\n" );
+
+    failed = ! psDBCreateTable(dbh, table, _get_CreateTableMetadata());
+    if (!failed) {
+        rowSet = psArrayAlloc(1);
+        rowSet->n = 0;
+        psArrayAdd(rowSet, 0, _get_row());
+        psArrayAdd(rowSet, 0, _get_row());
+        psArrayAdd(rowSet, 0, _get_row());
+        failed = ! psDBInsertRows(dbh, table, rowSet);
+        if (!failed) {
+            failed = (psDBDeleteRows(dbh, table, _get_where()) < 0);
+        }
+        psDBDropTable(dbh, table);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
Index: /trunk/psLib/test/dataIO/tst_psDB.c
===================================================================
--- /trunk/psLib/test/dataIO/tst_psDB.c	(revision 3531)
+++ /trunk/psLib/test/dataIO/tst_psDB.c	(revision 3531)
@@ -0,0 +1,605 @@
+/** @file  tst_psDB.c
+*
+* -*- mode: C; c-basic-indent: 4; tab-width: 8; indent-tabs-mode: nil -*-
+* vim: set cindent ts=8 sw=4 expandtab:
+*
+*  @brief Contains the tests for psDB.[ch]
+*
+*
+*  @author Aaron Culliney, MHPCC
+*
+*  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-03-28 22:52:32 $
+*
+*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
+*
+*/
+
+#define PS_ALLOW_MALLOC // for MySQL internals ...
+
+#include <unistd.h>
+#include <sys/wait.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <limits.h>
+#include <stdlib.h>
+
+#include "psDB.h"
+#include "psTest.h"
+#include "pslib.h"
+
+static psDB *_init_psDB( void );
+static void  _cleanup_psDB(psDB *dbh);
+static psMetadata *_get_CreateTableMetadata( void );
+static psMetadata *_get_RowMetadataValues(const char *val0, psS32 val1, psF32 val2, psF64 val3);
+static psMetadata *_get_RowMetadata(
+    const char *key0, const char *comm0, const char *val0,
+    const char *key1, const char *comm1, psS32 val1,
+    const char *key2, const char *comm2, psF32 val2,
+    const char *key3, const char *comm3, psF64 val3);
+static psMetadata *_get_row( void );
+static psMetadata *_get_where( void );
+static psMetadata *_get_update_values(const char *val0, psS32 val1, psF32 val2, psF64 val3);
+
+//static psS32 TPDBCreate( void );
+//static psS32 TPDBDrop( void );
+static psS32 TPDBInit( void );
+static psS32 TPDBChange( void );
+static psS32 TPDBCreateTable( void );
+static psS32 TPDBDropTable( void );
+static psS32 TPDBSelectColumn( void );
+static psS32 TPDBSelectColumnNum( void );
+static psS32 TPDBSelectRows( void );
+static psS32 TPDBInsertOneRow( void );
+static psS32 TPDBInsertRows( void );
+static psS32 TPDBDumpRows( void );
+static psS32 TPDBDumpCols( void );
+static psS32 TPDBUpdateRows( void );
+static psS32 TPDBDeleteRows( void );
+
+testDescription tests[] = {
+                              {TPDBInit,            -1,  "dbInit",            0, false},
+                              {TPDBCreateTable,     -1,  "dbCreateTable",     0, false},
+                              {TPDBDropTable,       -2,  "dbDropTable",       0, true},
+                              {TPDBSelectColumn,    -3,  "dbSelectColumn",    0, true},
+                              {TPDBSelectColumnNum, -4,  "dbSelectColumnNum", 0, true},
+                              {TPDBSelectRows,      -5,  "dbSelectRows",      0, true},
+                              {TPDBInsertOneRow,    -6,  "dbInsertOneRow",    0, true},
+                              {TPDBInsertRows,      -7,  "dbInsertRows",      0, true},
+                              {TPDBDumpRows,        -8,  "dbDumpRows",        0, true},
+                              {TPDBDumpCols,        -9,  "dbDumpCols",        0, true},
+                              {TPDBUpdateRows,      -10, "dbUpdateRows",      0, true},
+                              {TPDBDeleteRows,      -11, "dbDeleteRows",      0, true},
+                              {TPDBChange,          -12, "dbChange",          0, true},
+                              //{TPDBCreate,        -15, "dbCreate",          0, false},
+                              //{TPDBDrop,          -16, "dbDrop",            0, false},
+                              {NULL}
+                          };
+
+static const char *host    = "localhost";
+static const char *user    = "test";
+static const char *passwd  = "";
+static const char *dbname  = "test";
+
+// internal method to initialize DB
+psDB *_init_psDB( void )
+{
+    psDB *dbh = NULL;
+
+    psLogMsg( __func__, PS_LOG_INFO, "initialize database connection...\n" );
+
+    dbh = psDBInit(host, user, passwd, dbname);
+    if (dbh == NULL) {
+        psError(PS_ERR_UNKNOWN, true, "could not initialize DB connection in %s!", __func__ );
+    }
+
+    return dbh;
+}
+
+// internal method to handle DB cleanup
+void _cleanup_psDB(psDB *dbh)
+{
+    psDBCleanup(dbh);
+}
+
+psMetadata *_get_CreateTableMetadata( void )
+{
+    return _get_RowMetadata(
+               "key_string", "comment-string", "90000",  // XXX value used to determine size of field ...
+               "key_s32",    "comment-s32",     0,       // NOTE: values unused here
+               "key_f32",    "comment-f32",     0.0,
+               "key_f64",    "comment-f64",     0.0);
+}
+
+psMetadata *_get_RowMetadataValues(const char *val0, psS32 val1, psF32 val2, psF64 val3)
+{
+    return _get_RowMetadata(
+               "key_string", "comment-string", val0,
+               "key_s32",    "comment-s32",    val1,
+               "key_f32",    "comment-f32",    val2,
+               "key_f64",    "comment-f64",    val3);
+}
+
+psMetadata *_get_RowMetadata(
+    const char *key0, const char *comm0, const char *val0,
+    const char *key1, const char *comm1, psS32 val1,
+    const char *key2, const char *comm2, psF32 val2,
+    const char *key3, const char *comm3, psF64 val3)
+{
+    psMetadata *md = NULL;
+    psMetadataItem *str=NULL, *s32=NULL, *f32=NULL, *f64=NULL;
+
+    md = psMetadataAlloc();
+    if (md == NULL) {
+        psError(PS_ERR_UNKNOWN, true, "could not create psMetadata in %s!", __func__ );
+        return NULL;
+    }
+    str = psMetadataItemAllocStr(key0, comm0, val0);
+    //psLogMsg( __func__, PS_LOG_INFO, "MetaDataItemType (%d).\n", str->type );
+    s32 = psMetadataItemAllocS32(key1, comm1, val1);
+    //psLogMsg( __func__, PS_LOG_INFO, "MetaDataItemType (%d).\n", s32->type );
+    f32 = psMetadataItemAllocF32(key2, comm2, val2);
+    //psLogMsg( __func__, PS_LOG_INFO, "MetaDataItemType (%d).\n", f32->type );
+    f64 = psMetadataItemAllocF64(key3, comm3, val3);
+    //psLogMsg( __func__, PS_LOG_INFO, "MetaDataItemType (%d).\n", f64->type );
+    if ((str == NULL) || (s32 == NULL) || (f32 == NULL) || (f64 == NULL)) {
+        psError(PS_ERR_UNKNOWN, true, "could not create psMetadataItem(s) in %s!", __func__ );
+        return NULL;
+    }
+    if ( !psMetadataAddItem(md, str, 0, 0) || !psMetadataAddItem(md, s32, 0, 0) ||
+            !psMetadataAddItem(md, f32, 0, 0) || !psMetadataAddItem(md, f64, 0, 0)) {
+        psError(PS_ERR_UNKNOWN, true, "could not add psMetadataItem(s) to psMetadata in %s!", __func__ );
+        return NULL;
+    }
+
+    return md;
+}
+
+void _cleanup_Metadata (psMetadata *md)
+{
+    psMetadataItem* item = NULL;
+    psMetadataIterator* mdi = psMetadataIteratorAlloc(md, 0, NULL);
+    while ((item = psMetadataGetAndIncrement(mdi)) != NULL) {
+        psFree(item);
+    }
+    psFree(mdi);
+    psFree(md);
+}
+
+psMetadata *_get_row( void )
+{
+    return _get_RowMetadata(
+               "key_string", "comment-string", "hello world!",
+               "key_s32",    "comment-s32",     1974,
+               "key_f32",    "comment-f32",     3.14159,
+               "key_f64",    "comment-f64",     2.71828);
+}
+
+psMetadata *_get_where( void )
+{
+    return _get_row();
+}
+
+psMetadata *_get_update_values(const char *val0, psS32 val1, psF32 val2, psF64 val3)
+{
+    return _get_RowMetadataValues(val0, val1, val2, val3);
+}
+
+psS32 main(psS32 argc, char* argv[])
+{
+    psLogSetLevel( PS_LOG_INFO );
+
+    return ( ! runTestSuite( stderr, "psDB", tests, argc, argv ) );
+}
+
+// Testpoint #XXX, initialize/break-down MySQL connection.
+psS32 TPDBInit( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBInit/psDBCleanup shall initialize/cleanup database connection.\n" );
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, psDBCreate shall create a new test database.
+psS32 TPDBCreate( void )
+{
+    const char *test_db = "ps_test_db";
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBCreate shall create new new test database.\n" );
+
+    failed = ! psDBCreate(dbh, test_db);
+    if (!failed) {
+        psDBDrop(dbh, test_db);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, psDBDrop shall create a new test database.
+psS32 TPDBDrop( void )
+{
+    const char *test_db = "ps_test_db";
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBDrop shall create/drop a new new test database.\n" );
+
+    failed = psDBCreate(dbh, test_db);
+    if (!failed) {
+        failed = ! psDBDrop(dbh, test_db);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, psDBChange shall change databases.
+psS32 TPDBChange( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBChange shall change to a new new test database.\n" );
+
+    failed = ! psDBChange(dbh, dbname);
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, psDBCreateTable shall create tables in the test database ...
+psS32 TPDBCreateTable( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+    const char* table = "table1";
+    psMetadata *md = _get_CreateTableMetadata();
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBCreateTable shall create a new table in the new test database.\n" );
+
+    failed = ! psDBCreateTable(dbh, table, md);
+    if (!failed) {
+        psDBDropTable(dbh, table);
+    }
+
+    _cleanup_Metadata(md);
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, psDBDropTable shall create tables in the test database ...
+psS32 TPDBDropTable( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+    const char* table = "table2";
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBDropTable shall create/drop a new table in the new test database.\n" );
+
+    failed = ! psDBCreateTable(dbh, table, _get_CreateTableMetadata());
+    if (!failed) {
+        failed = ! psDBDropTable(dbh, table);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, TPDBSelectColumn shall write/select a column from a test table ...
+psS32 TPDBSelectColumn( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+    const char* table = "table3";
+    psArray *ary = NULL;
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBSelectColumn shall select data from a test table.\n" );
+
+    failed = ! psDBCreateTable(dbh, table, _get_CreateTableMetadata());
+    if (!failed) {
+        ary = psDBSelectColumn(dbh, table, "", 1);
+        failed = (ary == NULL);
+        psDBDropTable(dbh, table);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, TPDBSelectColumnNum shall write/select a column from a test table ...
+psS32 TPDBSelectColumnNum( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+    const char* table = "table4";
+    psVector *vec = NULL;
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBSelectColumnNum shall select data from a test table.\n" );
+
+    failed = ! psDBCreateTable(dbh, table, _get_CreateTableMetadata());
+    if (!failed) {
+        vec = psDBSelectColumnNum(dbh, table, "key-string", PS_TYPE_PTR, 1);
+        failed = (vec == NULL);
+        psDBDropTable(dbh, table);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, TPDBSelectRows shall write/select data from a test table ...
+psS32 TPDBSelectRows( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+    const char* table = "table5";
+    psArray *ary = NULL;
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBSelectRows shall select data from a test table.\n" );
+
+    failed = ! psDBCreateTable(dbh, table, _get_CreateTableMetadata());
+    if (!failed) {
+        psDBInsertOneRow(dbh, table, _get_row());             // 3X rows for general case
+        psDBInsertOneRow(dbh, table, _get_row());
+        failed = ! psDBInsertOneRow(dbh, table, _get_row());
+        if (!failed) {
+            ary = psDBSelectRows(dbh, table, _get_where(), 0);
+            failed = (ary == NULL);
+        }
+        psDBDropTable(dbh, table);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, TPDBInsertOneRow shall write a row of data into a test table ...
+psS32 TPDBInsertOneRow( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+    const char* table = "table6";
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBInsertOneRow shall insert a row into a test table.\n" );
+
+    failed = ! psDBCreateTable(dbh, table, _get_CreateTableMetadata());
+    if (!failed) {
+        failed = ! psDBInsertOneRow(dbh, table, _get_row());
+        psDBDropTable(dbh, table);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, TPDBInsertRows shall write rows of data into a test table ...
+psS32 TPDBInsertRows( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+    const char* table = "table7";
+    psArray *rowSet = NULL;
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBInsertRows shall insert rows into a test table.\n" );
+
+    failed = ! psDBCreateTable(dbh, table, _get_CreateTableMetadata());
+    if (!failed) {
+        rowSet = psArrayAlloc(1);
+        rowSet->n = 0;
+        psArrayAdd(rowSet, 0, _get_row());
+        psArrayAdd(rowSet, 0, _get_row());
+        psArrayAdd(rowSet, 0, _get_row());
+        failed = ! psDBInsertRows(dbh, table, rowSet);
+        psDBDropTable(dbh, table);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, TPDBDumpRows shall dump all rows from a test table ...
+psS32 TPDBDumpRows( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+    const char* table = "table8";
+    psArray *rowSet = NULL;
+    psArray *ary = NULL;
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBDumpRows shall dump all rows from a test table.\n" );
+
+    failed = ! psDBCreateTable(dbh, table, _get_CreateTableMetadata());
+    if (!failed) {
+        rowSet = psArrayAlloc(1);
+        rowSet->n = 0;
+        psArrayAdd(rowSet, 0, _get_row());
+        psArrayAdd(rowSet, 0, _get_row());
+        psArrayAdd(rowSet, 0, _get_row());
+        failed = ! psDBInsertRows(dbh, table, rowSet);
+        if (!failed) {
+            ary = psDBDumpRows(dbh, table);
+            failed = (ary == NULL);
+        }
+        psDBDropTable(dbh, table);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, TPDBDumpCols shall dump all cols from a test table ...
+psS32 TPDBDumpCols( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+    const char* table = "table9";
+    psMetadata *meta = NULL;
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBDumpCols shall dump all cols from a test table.\n" );
+
+    failed = ! psDBCreateTable(dbh, table, _get_CreateTableMetadata());
+    if (!failed) {
+        meta = psDBDumpCols(dbh, table);
+        failed = (meta == NULL);
+        psDBDropTable(dbh, table);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, TPDBUpdateRows shall update rows in a test table ...
+psS32 TPDBUpdateRows( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+    const char* table = "table10";
+    psArray *rowSet = NULL;
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBUpdateRows shall dump all rows from a test table.\n" );
+
+    failed = ! psDBCreateTable(dbh, table, _get_CreateTableMetadata());
+    if (!failed) {
+        rowSet = psArrayAlloc(1);
+        rowSet->n = 0;
+        psArrayAdd(rowSet, 0, _get_row());
+        psArrayAdd(rowSet, 0, _get_row());
+        psArrayAdd(rowSet, 0, _get_row());
+        failed = ! psDBInsertRows(dbh, table, rowSet);
+        if (!failed) {
+            failed = (psDBUpdateRows(dbh, table, _get_where(), _get_update_values(
+                                         "foobar", -1, 3.3333, 1234.5)) < 0);
+        }
+        psDBDropTable(dbh, table);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, TPDBDeleteRows shall update rows in a test table ...
+psS32 TPDBDeleteRows( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+    const char* table = "table10";
+    psArray *rowSet = NULL;
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBDeleteRows shall delete rows from a test table.\n" );
+
+    failed = ! psDBCreateTable(dbh, table, _get_CreateTableMetadata());
+    if (!failed) {
+        rowSet = psArrayAlloc(1);
+        rowSet->n = 0;
+        psArrayAdd(rowSet, 0, _get_row());
+        psArrayAdd(rowSet, 0, _get_row());
+        psArrayAdd(rowSet, 0, _get_row());
+        failed = ! psDBInsertRows(dbh, table, rowSet);
+        if (!failed) {
+            failed = (psDBDeleteRows(dbh, table, _get_where()) < 0);
+        }
+        psDBDropTable(dbh, table);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
Index: /trunk/psLib/test/fileUtils/tst_psDB.c
===================================================================
--- /trunk/psLib/test/fileUtils/tst_psDB.c	(revision 3531)
+++ /trunk/psLib/test/fileUtils/tst_psDB.c	(revision 3531)
@@ -0,0 +1,605 @@
+/** @file  tst_psDB.c
+*
+* -*- mode: C; c-basic-indent: 4; tab-width: 8; indent-tabs-mode: nil -*-
+* vim: set cindent ts=8 sw=4 expandtab:
+*
+*  @brief Contains the tests for psDB.[ch]
+*
+*
+*  @author Aaron Culliney, MHPCC
+*
+*  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-03-28 22:52:32 $
+*
+*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
+*
+*/
+
+#define PS_ALLOW_MALLOC // for MySQL internals ...
+
+#include <unistd.h>
+#include <sys/wait.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <limits.h>
+#include <stdlib.h>
+
+#include "psDB.h"
+#include "psTest.h"
+#include "pslib.h"
+
+static psDB *_init_psDB( void );
+static void  _cleanup_psDB(psDB *dbh);
+static psMetadata *_get_CreateTableMetadata( void );
+static psMetadata *_get_RowMetadataValues(const char *val0, psS32 val1, psF32 val2, psF64 val3);
+static psMetadata *_get_RowMetadata(
+    const char *key0, const char *comm0, const char *val0,
+    const char *key1, const char *comm1, psS32 val1,
+    const char *key2, const char *comm2, psF32 val2,
+    const char *key3, const char *comm3, psF64 val3);
+static psMetadata *_get_row( void );
+static psMetadata *_get_where( void );
+static psMetadata *_get_update_values(const char *val0, psS32 val1, psF32 val2, psF64 val3);
+
+//static psS32 TPDBCreate( void );
+//static psS32 TPDBDrop( void );
+static psS32 TPDBInit( void );
+static psS32 TPDBChange( void );
+static psS32 TPDBCreateTable( void );
+static psS32 TPDBDropTable( void );
+static psS32 TPDBSelectColumn( void );
+static psS32 TPDBSelectColumnNum( void );
+static psS32 TPDBSelectRows( void );
+static psS32 TPDBInsertOneRow( void );
+static psS32 TPDBInsertRows( void );
+static psS32 TPDBDumpRows( void );
+static psS32 TPDBDumpCols( void );
+static psS32 TPDBUpdateRows( void );
+static psS32 TPDBDeleteRows( void );
+
+testDescription tests[] = {
+                              {TPDBInit,            -1,  "dbInit",            0, false},
+                              {TPDBCreateTable,     -1,  "dbCreateTable",     0, false},
+                              {TPDBDropTable,       -2,  "dbDropTable",       0, true},
+                              {TPDBSelectColumn,    -3,  "dbSelectColumn",    0, true},
+                              {TPDBSelectColumnNum, -4,  "dbSelectColumnNum", 0, true},
+                              {TPDBSelectRows,      -5,  "dbSelectRows",      0, true},
+                              {TPDBInsertOneRow,    -6,  "dbInsertOneRow",    0, true},
+                              {TPDBInsertRows,      -7,  "dbInsertRows",      0, true},
+                              {TPDBDumpRows,        -8,  "dbDumpRows",        0, true},
+                              {TPDBDumpCols,        -9,  "dbDumpCols",        0, true},
+                              {TPDBUpdateRows,      -10, "dbUpdateRows",      0, true},
+                              {TPDBDeleteRows,      -11, "dbDeleteRows",      0, true},
+                              {TPDBChange,          -12, "dbChange",          0, true},
+                              //{TPDBCreate,        -15, "dbCreate",          0, false},
+                              //{TPDBDrop,          -16, "dbDrop",            0, false},
+                              {NULL}
+                          };
+
+static const char *host    = "localhost";
+static const char *user    = "test";
+static const char *passwd  = "";
+static const char *dbname  = "test";
+
+// internal method to initialize DB
+psDB *_init_psDB( void )
+{
+    psDB *dbh = NULL;
+
+    psLogMsg( __func__, PS_LOG_INFO, "initialize database connection...\n" );
+
+    dbh = psDBInit(host, user, passwd, dbname);
+    if (dbh == NULL) {
+        psError(PS_ERR_UNKNOWN, true, "could not initialize DB connection in %s!", __func__ );
+    }
+
+    return dbh;
+}
+
+// internal method to handle DB cleanup
+void _cleanup_psDB(psDB *dbh)
+{
+    psDBCleanup(dbh);
+}
+
+psMetadata *_get_CreateTableMetadata( void )
+{
+    return _get_RowMetadata(
+               "key_string", "comment-string", "90000",  // XXX value used to determine size of field ...
+               "key_s32",    "comment-s32",     0,       // NOTE: values unused here
+               "key_f32",    "comment-f32",     0.0,
+               "key_f64",    "comment-f64",     0.0);
+}
+
+psMetadata *_get_RowMetadataValues(const char *val0, psS32 val1, psF32 val2, psF64 val3)
+{
+    return _get_RowMetadata(
+               "key_string", "comment-string", val0,
+               "key_s32",    "comment-s32",    val1,
+               "key_f32",    "comment-f32",    val2,
+               "key_f64",    "comment-f64",    val3);
+}
+
+psMetadata *_get_RowMetadata(
+    const char *key0, const char *comm0, const char *val0,
+    const char *key1, const char *comm1, psS32 val1,
+    const char *key2, const char *comm2, psF32 val2,
+    const char *key3, const char *comm3, psF64 val3)
+{
+    psMetadata *md = NULL;
+    psMetadataItem *str=NULL, *s32=NULL, *f32=NULL, *f64=NULL;
+
+    md = psMetadataAlloc();
+    if (md == NULL) {
+        psError(PS_ERR_UNKNOWN, true, "could not create psMetadata in %s!", __func__ );
+        return NULL;
+    }
+    str = psMetadataItemAllocStr(key0, comm0, val0);
+    //psLogMsg( __func__, PS_LOG_INFO, "MetaDataItemType (%d).\n", str->type );
+    s32 = psMetadataItemAllocS32(key1, comm1, val1);
+    //psLogMsg( __func__, PS_LOG_INFO, "MetaDataItemType (%d).\n", s32->type );
+    f32 = psMetadataItemAllocF32(key2, comm2, val2);
+    //psLogMsg( __func__, PS_LOG_INFO, "MetaDataItemType (%d).\n", f32->type );
+    f64 = psMetadataItemAllocF64(key3, comm3, val3);
+    //psLogMsg( __func__, PS_LOG_INFO, "MetaDataItemType (%d).\n", f64->type );
+    if ((str == NULL) || (s32 == NULL) || (f32 == NULL) || (f64 == NULL)) {
+        psError(PS_ERR_UNKNOWN, true, "could not create psMetadataItem(s) in %s!", __func__ );
+        return NULL;
+    }
+    if ( !psMetadataAddItem(md, str, 0, 0) || !psMetadataAddItem(md, s32, 0, 0) ||
+            !psMetadataAddItem(md, f32, 0, 0) || !psMetadataAddItem(md, f64, 0, 0)) {
+        psError(PS_ERR_UNKNOWN, true, "could not add psMetadataItem(s) to psMetadata in %s!", __func__ );
+        return NULL;
+    }
+
+    return md;
+}
+
+void _cleanup_Metadata (psMetadata *md)
+{
+    psMetadataItem* item = NULL;
+    psMetadataIterator* mdi = psMetadataIteratorAlloc(md, 0, NULL);
+    while ((item = psMetadataGetAndIncrement(mdi)) != NULL) {
+        psFree(item);
+    }
+    psFree(mdi);
+    psFree(md);
+}
+
+psMetadata *_get_row( void )
+{
+    return _get_RowMetadata(
+               "key_string", "comment-string", "hello world!",
+               "key_s32",    "comment-s32",     1974,
+               "key_f32",    "comment-f32",     3.14159,
+               "key_f64",    "comment-f64",     2.71828);
+}
+
+psMetadata *_get_where( void )
+{
+    return _get_row();
+}
+
+psMetadata *_get_update_values(const char *val0, psS32 val1, psF32 val2, psF64 val3)
+{
+    return _get_RowMetadataValues(val0, val1, val2, val3);
+}
+
+psS32 main(psS32 argc, char* argv[])
+{
+    psLogSetLevel( PS_LOG_INFO );
+
+    return ( ! runTestSuite( stderr, "psDB", tests, argc, argv ) );
+}
+
+// Testpoint #XXX, initialize/break-down MySQL connection.
+psS32 TPDBInit( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBInit/psDBCleanup shall initialize/cleanup database connection.\n" );
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, psDBCreate shall create a new test database.
+psS32 TPDBCreate( void )
+{
+    const char *test_db = "ps_test_db";
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBCreate shall create new new test database.\n" );
+
+    failed = ! psDBCreate(dbh, test_db);
+    if (!failed) {
+        psDBDrop(dbh, test_db);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, psDBDrop shall create a new test database.
+psS32 TPDBDrop( void )
+{
+    const char *test_db = "ps_test_db";
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBDrop shall create/drop a new new test database.\n" );
+
+    failed = psDBCreate(dbh, test_db);
+    if (!failed) {
+        failed = ! psDBDrop(dbh, test_db);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, psDBChange shall change databases.
+psS32 TPDBChange( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBChange shall change to a new new test database.\n" );
+
+    failed = ! psDBChange(dbh, dbname);
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, psDBCreateTable shall create tables in the test database ...
+psS32 TPDBCreateTable( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+    const char* table = "table1";
+    psMetadata *md = _get_CreateTableMetadata();
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBCreateTable shall create a new table in the new test database.\n" );
+
+    failed = ! psDBCreateTable(dbh, table, md);
+    if (!failed) {
+        psDBDropTable(dbh, table);
+    }
+
+    _cleanup_Metadata(md);
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, psDBDropTable shall create tables in the test database ...
+psS32 TPDBDropTable( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+    const char* table = "table2";
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBDropTable shall create/drop a new table in the new test database.\n" );
+
+    failed = ! psDBCreateTable(dbh, table, _get_CreateTableMetadata());
+    if (!failed) {
+        failed = ! psDBDropTable(dbh, table);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, TPDBSelectColumn shall write/select a column from a test table ...
+psS32 TPDBSelectColumn( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+    const char* table = "table3";
+    psArray *ary = NULL;
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBSelectColumn shall select data from a test table.\n" );
+
+    failed = ! psDBCreateTable(dbh, table, _get_CreateTableMetadata());
+    if (!failed) {
+        ary = psDBSelectColumn(dbh, table, "", 1);
+        failed = (ary == NULL);
+        psDBDropTable(dbh, table);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, TPDBSelectColumnNum shall write/select a column from a test table ...
+psS32 TPDBSelectColumnNum( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+    const char* table = "table4";
+    psVector *vec = NULL;
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBSelectColumnNum shall select data from a test table.\n" );
+
+    failed = ! psDBCreateTable(dbh, table, _get_CreateTableMetadata());
+    if (!failed) {
+        vec = psDBSelectColumnNum(dbh, table, "key-string", PS_TYPE_PTR, 1);
+        failed = (vec == NULL);
+        psDBDropTable(dbh, table);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, TPDBSelectRows shall write/select data from a test table ...
+psS32 TPDBSelectRows( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+    const char* table = "table5";
+    psArray *ary = NULL;
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBSelectRows shall select data from a test table.\n" );
+
+    failed = ! psDBCreateTable(dbh, table, _get_CreateTableMetadata());
+    if (!failed) {
+        psDBInsertOneRow(dbh, table, _get_row());             // 3X rows for general case
+        psDBInsertOneRow(dbh, table, _get_row());
+        failed = ! psDBInsertOneRow(dbh, table, _get_row());
+        if (!failed) {
+            ary = psDBSelectRows(dbh, table, _get_where(), 0);
+            failed = (ary == NULL);
+        }
+        psDBDropTable(dbh, table);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, TPDBInsertOneRow shall write a row of data into a test table ...
+psS32 TPDBInsertOneRow( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+    const char* table = "table6";
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBInsertOneRow shall insert a row into a test table.\n" );
+
+    failed = ! psDBCreateTable(dbh, table, _get_CreateTableMetadata());
+    if (!failed) {
+        failed = ! psDBInsertOneRow(dbh, table, _get_row());
+        psDBDropTable(dbh, table);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, TPDBInsertRows shall write rows of data into a test table ...
+psS32 TPDBInsertRows( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+    const char* table = "table7";
+    psArray *rowSet = NULL;
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBInsertRows shall insert rows into a test table.\n" );
+
+    failed = ! psDBCreateTable(dbh, table, _get_CreateTableMetadata());
+    if (!failed) {
+        rowSet = psArrayAlloc(1);
+        rowSet->n = 0;
+        psArrayAdd(rowSet, 0, _get_row());
+        psArrayAdd(rowSet, 0, _get_row());
+        psArrayAdd(rowSet, 0, _get_row());
+        failed = ! psDBInsertRows(dbh, table, rowSet);
+        psDBDropTable(dbh, table);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, TPDBDumpRows shall dump all rows from a test table ...
+psS32 TPDBDumpRows( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+    const char* table = "table8";
+    psArray *rowSet = NULL;
+    psArray *ary = NULL;
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBDumpRows shall dump all rows from a test table.\n" );
+
+    failed = ! psDBCreateTable(dbh, table, _get_CreateTableMetadata());
+    if (!failed) {
+        rowSet = psArrayAlloc(1);
+        rowSet->n = 0;
+        psArrayAdd(rowSet, 0, _get_row());
+        psArrayAdd(rowSet, 0, _get_row());
+        psArrayAdd(rowSet, 0, _get_row());
+        failed = ! psDBInsertRows(dbh, table, rowSet);
+        if (!failed) {
+            ary = psDBDumpRows(dbh, table);
+            failed = (ary == NULL);
+        }
+        psDBDropTable(dbh, table);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, TPDBDumpCols shall dump all cols from a test table ...
+psS32 TPDBDumpCols( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+    const char* table = "table9";
+    psMetadata *meta = NULL;
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBDumpCols shall dump all cols from a test table.\n" );
+
+    failed = ! psDBCreateTable(dbh, table, _get_CreateTableMetadata());
+    if (!failed) {
+        meta = psDBDumpCols(dbh, table);
+        failed = (meta == NULL);
+        psDBDropTable(dbh, table);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, TPDBUpdateRows shall update rows in a test table ...
+psS32 TPDBUpdateRows( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+    const char* table = "table10";
+    psArray *rowSet = NULL;
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBUpdateRows shall dump all rows from a test table.\n" );
+
+    failed = ! psDBCreateTable(dbh, table, _get_CreateTableMetadata());
+    if (!failed) {
+        rowSet = psArrayAlloc(1);
+        rowSet->n = 0;
+        psArrayAdd(rowSet, 0, _get_row());
+        psArrayAdd(rowSet, 0, _get_row());
+        psArrayAdd(rowSet, 0, _get_row());
+        failed = ! psDBInsertRows(dbh, table, rowSet);
+        if (!failed) {
+            failed = (psDBUpdateRows(dbh, table, _get_where(), _get_update_values(
+                                         "foobar", -1, 3.3333, 1234.5)) < 0);
+        }
+        psDBDropTable(dbh, table);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
+// Testpoint #XXX, TPDBDeleteRows shall update rows in a test table ...
+psS32 TPDBDeleteRows( void )
+{
+    psS32 failed = 0;
+    psDB *dbh = NULL;
+    const char* table = "table10";
+    psArray *rowSet = NULL;
+
+    dbh = _init_psDB();
+    if (dbh == NULL) {
+        return 1;
+    }
+
+    psLogMsg( __func__, PS_LOG_INFO, "psDBDeleteRows shall delete rows from a test table.\n" );
+
+    failed = ! psDBCreateTable(dbh, table, _get_CreateTableMetadata());
+    if (!failed) {
+        rowSet = psArrayAlloc(1);
+        rowSet->n = 0;
+        psArrayAdd(rowSet, 0, _get_row());
+        psArrayAdd(rowSet, 0, _get_row());
+        psArrayAdd(rowSet, 0, _get_row());
+        failed = ! psDBInsertRows(dbh, table, rowSet);
+        if (!failed) {
+            failed = (psDBDeleteRows(dbh, table, _get_where()) < 0);
+        }
+        psDBDropTable(dbh, table);
+    }
+
+    _cleanup_psDB(dbh);
+
+    return failed;
+}
+
