IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 12351


Ignore:
Timestamp:
Mar 8, 2007, 3:32:21 PM (19 years ago)
Author:
jhoblitt
Message:

re-import the original psDB tests, currently broken

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/db/tap_psDB.c

    r12094 r12351  
    44 *
    55 *  @author Aaron Culliney, MHPCC
    6  *
    7  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2007-02-27 23:56:12 $
     6 *  @author Joshua Hoblitt, University of Hawaii
     7 *
     8 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2007-03-09 01:32:21 $
    910 *
    1011 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
    1112 *
    1213 */
     14
     15#include <string.h>
    1316
    1417#include "tap.h"
     
    1619
    1720#include "pslib.h"
    18 
    19 #define STR_1 "hello world!"
    20 #define STR_2 "foobar"
    21 #define S32_1 1974
    22 #define S32_2 -18
    23 #define F32_1 3.14159
    24 #define F32_2 3.33
    25 #define F64_1 2.7182818
    26 #define F64_2 1.23456789
    27 #define B_1 TRUE
    28 #define B_2 FALSE
    29 
    30 #define ERROR_TOL   0.001
    31 
    32 #define CONST_ROW_1_STR      "randrow1"
    33 #define CONST_ROW_1_S32      12345
    34 #define CONST_ROW_1_F32      9876.5
    35 #define CONST_ROW_1_F64      456.75
    36 #define CONST_ROW_1_BOOL     TRUE
    37 
    38 #define CONST_ROW_2_STR      "randrow2"
    39 #define CONST_ROW_2_S32      2345
    40 #define CONST_ROW_2_F32      876.5
    41 #define CONST_ROW_2_F64      56.75
    42 #define CONST_ROW_2_BOOL     FALSE
    43 
    44 #define TAB_COL_0_NAME      "key_string"
    45 #define TAB_COL_1_NAME      "key_s32"
    46 #define TAB_COL_2_NAME      "key_f32"
    47 #define TAB_COL_3_NAME      "key_f64"
    48 #define TAB_COL_4_NAME      "key_bool"
    49 #define TAB_COL_5_NAME      "key_s32_0"
    5021
    5122#define HOST    "localhost"
     
    5728int main(int argc, char* argv[])
    5829{
     30#if DEBUG
     31    psTraceSetLevel("psLib.db", 10);
     32    psTraceSetLevel("err", 10);
     33#endif
     34
    5935    plan_tests(2);
    6036
    61     // Initialize database connection with test database
    62     psDB *dbh = psDBInit(HOST, USER, PASSWD, DBNAME, PORT);
    63     ok(dbh, "open a database handle");
    64     if (!dbh) {
    65         done();
    66     }
     37    // see if we can open a db connection at all
     38    {
     39        psDB *dbh = psDBInit(HOST, USER, PASSWD, DBNAME, PORT);
     40        ok(dbh, "open a database handle");
     41        if (!dbh) {
     42            done();
     43        }
     44        psFree(dbh);
     45    }
     46
     47    // test new database creation
     48    // the next 3 tests will fail as the MySQL test account has insufficent
     49    // permissions
     50    {
     51        psDB *dbh = psDBInit(HOST, USER, PASSWD, DBNAME, PORT);
     52        ok(psDBCreate(dbh, "foobar"), "psDBCreate()");
     53        ok(psDBChange(dbh, "foobar"), "psDBChange()");
     54        ok(psDBDrop(dbh, "foobar"), "psDBDrop()");
     55        // change back to the test dbname
     56        ok(psDBChange(dbh, DBNAME), "psDBChange()");
     57        psFree(dbh);
     58    }
     59
     60    // psDBCreateTable() & psDBDropTable()
     61    {
     62        psDB *dbh = psDBInit(HOST, USER, PASSWD, DBNAME, PORT);
     63        psMetadata *md = psMetadataAlloc();
     64        psMetadataAdd(md, PS_LIST_TAIL, "foo", PS_DATA_S32, "Primary Key", 0);
     65        psMetadataAdd(md, PS_LIST_TAIL, "bar", PS_DATA_BOOL, "Key", false);
     66        psMetadataAdd(md, PS_LIST_TAIL, "baz", PS_DATA_F64,  NULL, 0.0);
     67        psMetadataAdd(md, PS_LIST_TAIL, "boing", PS_DATA_STRING, NULL, "60");
     68
     69        ok(psDBCreateTable(dbh, "bar", md), "psDBCreateTable() - create table");
     70        psFree(md);
     71
     72        ok(psDBDropTable(dbh, "bar"), "psDBDropTable() - drop table");
     73
     74        psFree(dbh);
     75    }
     76
     77    {
     78        psDB *dbh = psDBInit(HOST, USER, PASSWD, DBNAME, PORT);
     79        psMetadata *md = psMetadataAlloc();
     80        psMetadataAdd(md, PS_LIST_TAIL, "foo", PS_TYPE_S32, "Primary Key", 0);
     81        psDBCreateTable(dbh, "bar", md);
     82
     83        ok(!psDBCreateTable(dbh, "bar", md), "psDBCreateTable() - table already exists");
     84
     85        psFree(md);
     86
     87        psDBDropTable(dbh, "bar");
     88
     89        ok(!psDBDropTable(dbh, "fubar"), "psDBDropTable() - non-existant table");
     90        psFree(dbh);
     91    }
     92
     93    {
     94        psDB *dbh = psDBInit(HOST, USER, PASSWD, DBNAME, PORT);
     95
     96        // setup yak table for later tests
     97        {
     98            psMetadata *md = psMetadataAlloc();
     99            psMetadataAdd(md, PS_LIST_TAIL, "hair", PS_TYPE_F32, NULL, 0.0);
     100            psDBCreateTable(dbh, "yak", md);
     101            psFree(md);
     102        }
     103
     104        // setup horse table for later tests
     105        {
     106            psMetadata *md = psMetadataAlloc();
     107            psMetadataAdd(md, PS_LIST_TAIL, "color", PS_DATA_STRING, NULL, "100");
     108            psDBCreateTable(dbh, "horse", md);
     109            psFree(md);
     110        }
     111
     112        // psDBInsertOneRow()
     113        {
     114            psMetadata *md = psMetadataAlloc();
     115            psMetadataAdd(md, PS_LIST_TAIL, "hair", PS_TYPE_F32, NULL, 10e3);
     116
     117            ok(psDBInsertOneRow(dbh, "yak", md),"psDBInsertOneRow() - number");
     118
     119            psFree(md);
     120        }
     121
     122        {
     123            psMetadata *md = psMetadataAlloc();
     124            psMetadataAdd(md, PS_LIST_TAIL, "hair", PS_TYPE_F32, NULL, NAN);
     125            ok(psDBInsertOneRow(dbh, "yak", md),"psDBInsertOneRow() - nan");
     126
     127            psFree(md);
     128        }
     129
     130        // psDBInsertRows()
     131        {
     132            psArray *rowSet = psArrayAllocEmpty(3);
     133            psMetadata *row = psMetadataAlloc();
     134            psMetadataAdd(row, PS_LIST_TAIL, "color", PS_DATA_STRING, NULL, "brown");
     135            psArrayAdd(rowSet, 0, row);
     136            psFree(row);
     137
     138            row = psMetadataAlloc();
     139            psMetadataAdd(row, PS_LIST_TAIL, "color", PS_DATA_STRING, NULL, "");
     140            psArrayAdd(rowSet, 0, row);
     141            psFree(row);
     142
     143            row = psMetadataAlloc();
     144            psMetadataAdd(row, PS_LIST_TAIL, "color", PS_DATA_STRING, NULL, "pink");
     145            psArrayAdd(rowSet, 0, row);
     146            psFree(row);
     147
     148            ok(psDBInsertRows(dbh, "horse", rowSet), "psDBInsertRows() - multi-row insert");
     149
     150            psFree(rowSet);
     151        }
     152
     153        // psDBSelectColumn()
     154        {
     155            psArray *column = psDBSelectColumn(dbh, "horse", "color", 42);
     156            ok(column, "psDBSelectColumn() - select");
     157            ok(column->n == 3, "psDBSelectColumn() - number of elements");
     158
     159            for (long i = 0; i < column->n; i++) {
     160                printf("\thorse color is: %s\n", (char *)column->data[i]);
     161            }
     162
     163            psFree(column);
     164        }
     165
     166        // psDBSelectColumnNum()
     167        {
     168            psVector *column = psDBSelectColumnNum(dbh, "yak", "hair", PS_TYPE_F32, 42);
     169            ok(column, "psDBSelectColumnNum() - select");
     170            ok(column->n == 2, "psDBSelectColumnNum() - number of elements");
     171
     172            for (long i = 0; i < column->n; i++) {
     173                printf("\tyak hair count is: %f\n", column->data.F32[i]);
     174                if (isnan(column->data.F32[i])){
     175                    printf("\t\tNO yak hair!!! (it's a nan)\n");
     176                }
     177            }
     178
     179            psFree(column);
     180        }
     181
     182        // psDBSelectRows()
     183        {
     184            psMetadata *md = psMetadataAlloc();
     185            psMetadataAdd(md, PS_LIST_TAIL, "color", PS_DATA_STRING, NULL, "brown");
     186
     187            psArray *resultSet = psDBSelectRows(dbh, "horse", md, 0);
     188            ok(resultSet, "psDBSelectRows() - select");
     189            ok(resultSet->n == 1, "psDBSelectRows() - number of rows");
     190
     191            psFree(md);
     192            for (long i = 0; i < resultSet->n; i++) {
     193                md = (psMetadata *)resultSet->data[0];
     194
     195                psListIterator *cursor = psListIteratorAlloc(md->list, 0, NULL);
     196
     197                psMetadataItem *item;
     198                while ((item = psListGetAndIncrement(cursor))) {
     199                    printf("\tcolum name is: %s, value is: %s\n", item->name, (char *)item->data.V);
     200                }
     201
     202                psFree(cursor);
     203            }
     204            psFree(resultSet);
     205
     206        }
     207
     208        // psDBDumpRows()
     209        {
     210            psArray *resultSet = psDBDumpRows(dbh, "horse");
     211            ok(resultSet, "psDBDumpRows() - dump");
     212            ok(resultSet->n == 3, "psDBDumpRows() - number of rows");
     213            psFree(resultSet);
     214        }
     215
     216        // psDBDumpCols()
     217        {
     218            psMetadata *columns = psDBDumpCols(dbh, "horse");
     219            ok(columns, "psDBDumpCols() - dump");
     220            ok(psListLength(columns->list) == 1, "psDBDumpCols() - number of columns");
     221
     222            psListIterator *cursor = psListIteratorAlloc(columns->list, 0, NULL);
     223
     224            psMetadataItem  *item;
     225            while ((item = psListGetAndIncrement(cursor))) {
     226                printf("\tcolumn name is: %s\n", item->name);
     227            }
     228
     229            psFree(cursor);
     230            psFree(columns);
     231        }
     232
     233        // psDBUpdateRows()
     234        {
     235            psMetadata *where = psMetadataAlloc();
     236            psMetadataAdd(where, PS_LIST_TAIL, "color", PS_DATA_STRING, NULL, "pink");
     237
     238            psMetadata *value = psMetadataAlloc();
     239            psMetadataAdd(value, PS_LIST_TAIL, "color", PS_DATA_STRING, NULL, "HOT pink");
     240
     241            psU64 rowsAffected = psDBUpdateRows(dbh, "horse", where, value);
     242            psFree(where);
     243            psFree(value);
     244
     245            ok(rowsAffected, "psDBUpdateRows() - pink -> HOT pink");
     246
     247            psArray *resultSet = psDBSelectRows(dbh, "horse", value, 0);
     248
     249            for (long i = 0; i < resultSet->n; i++) {
     250                psMetadata *md = (psMetadata *)resultSet->data[0];
     251
     252                psListIterator  *cursor = psListIteratorAlloc(md->list, 0, NULL);
     253
     254                psMetadataItem  *item;
     255                while ((item = psListGetAndIncrement(cursor))) {
     256                    if (strcmp((char *)item->data.V, "HOT pink") == 0) {
     257                        ok(1, "psDBUpdateRows() - psDBSelectRows() found HOT pink");
     258                        printf("\thorse color is: %s\n", (char *)item->data.V);
     259                    }
     260                }
     261
     262                psFree(cursor);
     263            }
     264
     265            psFree(resultSet);
     266        }
     267
     268        // psDBDeleteRows()
     269        ok(psDBDeleteRows(dbh, "yak", NULL, 0), "psDBDeleteRows()");
     270
     271        // cleanup other tests
     272        psDBDropTable(dbh, "horse");
     273        psDBDropTable(dbh, "yak");
     274
     275        psFree(dbh);
     276    }
     277
    67278
    68279    done();
    69280}
    70 
    71 #if 0
    72 psMetadata *_get_CreateTableMetadata( void )
    73 {
    74     return _get_RowMetadata(
    75                TAB_COL_0_NAME, "comment-string",     "90000", // value used to determine size of field
    76                TAB_COL_1_NAME,    "Primary Key",        0,       // values unused here ...
    77                TAB_COL_2_NAME,    "Key",                0.0,
    78                TAB_COL_3_NAME,    "",                   0.0,
    79                TAB_COL_4_NAME,   "",                   FALSE,
    80                TAB_COL_5_NAME,  "Key,AUTO_INCREMENT", 0);
    81 }
    82 
    83 psMetadata *_get_RowMetadataValues(const char *val0, psS32 val1, psF32 val2, psF64 val3, psBool val4)
    84 {
    85     return _get_RowMetadata(
    86                TAB_COL_0_NAME, "comment-string", val0,
    87                TAB_COL_1_NAME,    "comment-s32",    val1,
    88                TAB_COL_2_NAME,    "comment-f32",    val2,
    89                TAB_COL_3_NAME,    "comment-f64",    val3,
    90                TAB_COL_4_NAME,   "comment-bool",   val4,
    91                NULL,         NULL,             0.0);
    92 }
    93 
    94 psMetadata *_get_RowMetadata(
    95     const char *key0, const char *comm0, const char *val0,
    96     const char *key1, const char *comm1, psS32  val1,
    97     const char *key2, const char *comm2, psF32  val2,
    98     const char *key3, const char *comm3, psF64  val3,
    99     const char *key4, const char *comm4, psBool val4,
    100     const char *key5, const char *comm5, psS32  val5)
    101 {
    102     psMetadata *md = NULL;
    103     psMetadataItem *str=NULL, *s32_0=NULL, *s32=NULL, *f32=NULL, *f64=NULL, *b;
    104 
    105     md = psMetadataAlloc();
    106     if (md == NULL) {
    107         psError(PS_ERR_UNKNOWN, true, "could not create psMetadata in %s!", __func__ );
    108         return NULL;
    109     }
    110     if (key0 != NULL) {
    111         str = psMetadataItemAllocStr(key0, comm0, val0);
    112     }
    113     if (key5 != NULL) {
    114         s32_0 = psMetadataItemAllocS32(key5, comm5, val5);
    115     }
    116     s32 = psMetadataItemAllocS32 (key1, comm1, val1);
    117     f32 = psMetadataItemAllocF32 (key2, comm2, val2);
    118     f64 = psMetadataItemAllocF64 (key3, comm3, val3);
    119     b   = psMetadataItemAllocBool(key4, comm4, val4);
    120 
    121     if ( ((key0 != NULL) && (str == NULL)) || (s32 == NULL) || (f32 == NULL) || (f64 == NULL) || (b == NULL) ||
    122             ((key5 != NULL) && (s32_0 == NULL)) ) {
    123         psError(PS_ERR_UNKNOWN, true, "could not create psMetadataItem(s) in %s!", __func__ );
    124         return NULL;
    125     }
    126     if ( ((key0 != NULL) && !psMetadataAddItem(md, str, 0, 0)) ||
    127             !psMetadataAddItem(md, s32, 0, 0) || !psMetadataAddItem(md, f32, 0, 0) ||
    128             !psMetadataAddItem(md, f64, 0, 0) || !psMetadataAddItem(md, b,   0, 0) ||
    129             ((key5 != NULL) && !psMetadataAddItem(md, s32_0, 0, 0))) {
    130         psError(PS_ERR_UNKNOWN, true, "could not add psMetadataItem(s) to psMetadata in %s!", __func__ );
    131         return NULL;
    132     }
    133 
    134     if (str != NULL) {
    135         psFree(str);
    136     }
    137     psFree(s32);
    138     psFree(f32);
    139     psFree(f64);
    140     psFree(b);
    141     if (s32_0 != NULL) {
    142         psFree(s32_0);
    143     }
    144 
    145     return md;
    146 }
    147 
    148 psMetadata *_get_const_row1( void )
    149 {
    150     char buf[32];
    151     snprintf(buf, 32, "%s", CONST_ROW_1_STR );
    152     return _get_RowMetadata(
    153                TAB_COL_0_NAME, "comment-string", buf,
    154                TAB_COL_1_NAME,    "comment-s32",    CONST_ROW_1_S32,
    155                TAB_COL_2_NAME,    "comment-f32",    CONST_ROW_1_F32,
    156                TAB_COL_3_NAME,    "comment-f64",    CONST_ROW_1_F64,
    157                TAB_COL_4_NAME,   "comment-bool",   CONST_ROW_1_BOOL,
    158                NULL,         NULL,             0.0);
    159 }
    160 
    161 psMetadata *_get_const_row2( void )
    162 {
    163     char buf[32];
    164     snprintf(buf, 32, "%s",CONST_ROW_2_STR);
    165     return _get_RowMetadata(
    166                TAB_COL_0_NAME, "comment-string", buf,
    167                TAB_COL_1_NAME,    "comment-s32",    CONST_ROW_2_S32,
    168                TAB_COL_2_NAME,    "comment-f32",    CONST_ROW_2_F32,
    169                TAB_COL_3_NAME,    "comment-f64",    CONST_ROW_2_F64,
    170                TAB_COL_4_NAME,   "comment-bool",   CONST_ROW_2_BOOL,
    171                NULL,         NULL,             0.0);
    172 }
    173 
    174 psMetadata *_get_row( void )
    175 {
    176     return _get_RowMetadata(
    177                TAB_COL_0_NAME, "comment-string", STR_1,
    178                TAB_COL_1_NAME,    "comment-s32",    S32_1,
    179                TAB_COL_2_NAME,    "comment-f32",    F32_1,
    180                TAB_COL_3_NAME,    "comment-f64",    F64_1,
    181                TAB_COL_4_NAME,   "comment-bool",   B_1,
    182                NULL,         NULL,             0.0);
    183 }
    184 
    185 psMetadata *_get_invalid_row( void )
    186 {
    187     return _get_RowMetadata(
    188                TAB_COL_0_NAME, "comment-string", STR_1,
    189                TAB_COL_1_NAME,    "comment-s32",    S32_1,
    190                "key_999",    "comment-f32",    F32_1,
    191                TAB_COL_3_NAME,    "comment-f64",    F64_1,
    192                TAB_COL_4_NAME,   "comment-bool",   B_1,
    193                NULL,         NULL,             0.0);
    194 }
    195 
    196 psMetadata *_get_where( void )
    197 {
    198     psMetadata *md = NULL;
    199     psMetadataItem *s32=NULL;
    200 
    201     md = psMetadataAlloc();
    202     if (md == NULL) {
    203         psError(PS_ERR_UNKNOWN, true, "could not create psMetadata in %s!", __func__ );
    204         return NULL;
    205     }
    206     s32 = psMetadataItemAllocS32(TAB_COL_1_NAME, "", S32_1);
    207     if (s32 == NULL) {
    208         psError(PS_ERR_UNKNOWN, true, "could not create psMetadataItem in %s!", __func__ );
    209         return NULL;
    210     }
    211     if (!psMetadataAddItem(md, s32, 0, 0)) {
    212         psError(PS_ERR_UNKNOWN, true, "could not add psMetadataItem(s) to psMetadata in %s!", __func__ );
    213         return NULL;
    214     }
    215 
    216     psFree(s32);
    217     return md;
    218 }
    219 
    220 psMetadata *_get_invalid_where( void )
    221 {
    222     psMetadata *md = NULL;
    223     psMetadataItem *s32=NULL;
    224 
    225     md = psMetadataAlloc();
    226     if (md == NULL) {
    227         psError(PS_ERR_UNKNOWN, true, "could not create psMetadata in %s!", __func__ );
    228         return NULL;
    229     }
    230     s32 = psMetadataItemAllocS32("col999", "", S32_1);
    231     if (s32 == NULL) {
    232         psError(PS_ERR_UNKNOWN, true, "could not create psMetadataItem in %s!", __func__ );
    233         return NULL;
    234     }
    235     if (!psMetadataAddItem(md, s32, 0, 0)) {
    236         psError(PS_ERR_UNKNOWN, true, "could not add psMetadataItem(s) to psMetadata in %s!", __func__ );
    237         return NULL;
    238     }
    239 
    240     psFree(s32);
    241     return md;
    242 }
    243 
    244 psMetadata *_get_where_bad_value( void )
    245 {
    246     psMetadata *md = NULL;
    247     psMetadataItem *s32=NULL;
    248 
    249     md = psMetadataAlloc();
    250     if (md == NULL) {
    251         psError(PS_ERR_UNKNOWN, true, "could not create psMetadata in %s!", __func__ );
    252         return NULL;
    253     }
    254     s32 = psMetadataItemAllocS32(TAB_COL_1_NAME, "", S32_1 + 1);
    255     if (s32 == NULL) {
    256         psError(PS_ERR_UNKNOWN, true, "could not create psMetadataItem in %s!", __func__ );
    257         return NULL;
    258     }
    259     if (!psMetadataAddItem(md, s32, 0, 0)) {
    260         psError(PS_ERR_UNKNOWN, true, "could not add psMetadataItem(s) to psMetadata in %s!", __func__ );
    261         return NULL;
    262     }
    263 
    264     psFree(s32);
    265     return md;
    266 }
    267 
    268 psMetadata *_get_update_values(const char *val0, psS32 val1, psF32 val2, psF64 val3, psBool val4)
    269 {
    270     return _get_RowMetadataValues(val0, val1, val2, val3, val4);
    271 }
    272 
    273 bool _check_row(psMetadata* row)
    274 {
    275     bool              returnValue = true;
    276     psMetadataItem*   item        = NULL;
    277 
    278     item = psMetadataLookup(row,TAB_COL_0_NAME);
    279     if((item==NULL) || (strcmp(item->data.V,STR_1)!=0)) {
    280         psError(PS_ERR_UNKNOWN,true,"Column key_string item %s not as expected %s",
    281                 item->data.V,STR_1);
    282         return false;
    283     }
    284 
    285     item = psMetadataLookup(row,TAB_COL_1_NAME);
    286     if((item==NULL) || (item->data.S32 != S32_1)) {
    287         psError(PS_ERR_UNKNOWN,true,"Column key_s32 item %d not as expected %d",
    288                 item->data.S32, S32_1);
    289         return false;
    290     }
    291 
    292     item = psMetadataLookup(row,TAB_COL_2_NAME);
    293     if((item==NULL) || (fabs(item->data.F32-F32_1)>ERROR_TOL)) {
    294         psError(PS_ERR_UNKNOWN,true,"Column key_f32 item %f not as expected %f",
    295                 item->data.F32, F32_1);
    296         return false;
    297     }
    298 
    299     item = psMetadataLookup(row,TAB_COL_3_NAME);
    300     if((item==NULL) || (fabs(item->data.F64-F64_1)>ERROR_TOL)) {
    301         psError(PS_ERR_UNKNOWN,true,"Column key_f64 item %lf not as expected %lf",
    302                 item->data.F64,F64_1);
    303         return false;
    304     }
    305 
    306     item = psMetadataLookup(row,TAB_COL_4_NAME);
    307     if((item==NULL) || (item->data.B != B_1)) {
    308         psError(PS_ERR_UNKNOWN,true,"Column key_bool item %d not as expected %d",
    309                 item->data.B, B_1);
    310         return false;
    311     }
    312 
    313     return returnValue;
    314 }
    315 
    316 bool _check_row_update(psMetadata* row)
    317 {
    318     bool              returnValue = true;
    319     psMetadataItem*   item        = NULL;
    320 
    321     item = psMetadataLookup(row,TAB_COL_0_NAME);
    322     if((item==NULL) || (strcmp(item->data.V,STR_2)!=0)) {
    323         psError(PS_ERR_UNKNOWN,true,"Column key_string item %s not as expected %s",
    324                 item->data.V,STR_2);
    325         return false;
    326     }
    327 
    328     item = psMetadataLookup(row,TAB_COL_1_NAME);
    329     if((item==NULL) || (item->data.S32 != S32_2)) {
    330         psError(PS_ERR_UNKNOWN,true,"Column key_s32 item %d not as expected %d",
    331                 item->data.S32, S32_2);
    332         return false;
    333     }
    334 
    335     item = psMetadataLookup(row,TAB_COL_2_NAME);
    336     if((item==NULL) || (fabs(item->data.F32-F32_2)>ERROR_TOL)) {
    337         psError(PS_ERR_UNKNOWN,true,"Column key_f32 item %f not as expected %f",
    338                 item->data.F32, F32_2);
    339         return false;
    340     }
    341 
    342     item = psMetadataLookup(row,TAB_COL_3_NAME);
    343     if((item==NULL) || (fabs(item->data.F64-F64_2)>ERROR_TOL)) {
    344         psError(PS_ERR_UNKNOWN,true,"Column key_f64 item %lf not as expected %lf",
    345                 item->data.F64,F64_2);
    346         return false;
    347     }
    348 
    349     item = psMetadataLookup(row,TAB_COL_4_NAME);
    350     if((item==NULL) || (item->data.B != B_2)) {
    351         psError(PS_ERR_UNKNOWN,true,"Column key_bool item %d not as expected %d",
    352                 item->data.B, B_2);
    353         return false;
    354     }
    355 
    356     return returnValue;
    357 }
    358 
    359 bool _check_const_row1(psMetadata* row)
    360 {
    361     bool              returnValue = true;
    362     psMetadataItem*   item        = NULL;
    363 
    364     item = psMetadataLookup(row,TAB_COL_0_NAME);
    365     if((item==NULL) || (strcmp(item->data.V,CONST_ROW_1_STR)!=0)) {
    366         psError(PS_ERR_UNKNOWN,true,"Column key_string item %s not as expected %s",
    367                 item->data.V,CONST_ROW_1_STR);
    368         return false;
    369     }
    370 
    371     item = psMetadataLookup(row,TAB_COL_1_NAME);
    372     if((item==NULL) || (item->data.S32 != CONST_ROW_1_S32)) {
    373         psError(PS_ERR_UNKNOWN,true,"Column key_s32 item %d not as expected %d",
    374                 item->data.S32, CONST_ROW_1_S32);
    375         return false;
    376     }
    377 
    378     item = psMetadataLookup(row,TAB_COL_2_NAME);
    379     if((item==NULL) || (fabs(item->data.F32-CONST_ROW_1_F32)>ERROR_TOL)) {
    380         psError(PS_ERR_UNKNOWN,true,"Column key_f32 item %f not as expected %f",
    381                 item->data.F32, CONST_ROW_1_F32);
    382         return false;
    383     }
    384 
    385     item = psMetadataLookup(row,TAB_COL_3_NAME);
    386     if((item==NULL) || (fabs(item->data.F64-CONST_ROW_1_F64)>ERROR_TOL)) {
    387         psError(PS_ERR_UNKNOWN,true,"Column key_f64 item %lf not as expected %lf",
    388                 item->data.F64,CONST_ROW_1_F64);
    389         return false;
    390     }
    391 
    392     item = psMetadataLookup(row,TAB_COL_4_NAME);
    393     if((item==NULL) || (item->data.B != CONST_ROW_1_BOOL)) {
    394         psError(PS_ERR_UNKNOWN,true,"Column key_bool item %d not as expected %d",
    395                 item->data.B, CONST_ROW_1_BOOL);
    396         return false;
    397     }
    398 
    399     return returnValue;
    400 }
    401 
    402 bool _check_const_row2(psMetadata* row)
    403 {
    404     bool              returnValue = true;
    405     psMetadataItem*   item        = NULL;
    406 
    407     item = psMetadataLookup(row,TAB_COL_0_NAME);
    408     if((item==NULL) || (strcmp(item->data.V,CONST_ROW_2_STR)!=0)) {
    409         psError(PS_ERR_UNKNOWN,true,"Column key_string item %s not as expected %s",
    410                 item->data.V,CONST_ROW_2_STR);
    411         return false;
    412     }
    413 
    414     item = psMetadataLookup(row,TAB_COL_1_NAME);
    415     if((item==NULL) || (item->data.S32 != CONST_ROW_2_S32)) {
    416         psError(PS_ERR_UNKNOWN,true,"Column key_s32 item %d not as expected %d",
    417                 item->data.S32, CONST_ROW_2_S32);
    418         return false;
    419     }
    420 
    421     item = psMetadataLookup(row,TAB_COL_2_NAME);
    422     if((item==NULL) || (fabs(item->data.F32-CONST_ROW_2_F32)>ERROR_TOL)) {
    423         psError(PS_ERR_UNKNOWN,true,"Column key_f32 item %f not as expected %f",
    424                 item->data.F32, CONST_ROW_2_F32);
    425         return false;
    426     }
    427 
    428     item = psMetadataLookup(row,TAB_COL_3_NAME);
    429     if((item==NULL) || (fabs(item->data.F64-CONST_ROW_2_F64)>ERROR_TOL)) {
    430         psError(PS_ERR_UNKNOWN,true,"Column key_f64 item %lf not as expected %lf",
    431                 item->data.F64,CONST_ROW_2_F64);
    432         return false;
    433     }
    434 
    435     item = psMetadataLookup(row,TAB_COL_4_NAME);
    436     if((item==NULL) || (item->data.B != CONST_ROW_2_BOOL)) {
    437         psError(PS_ERR_UNKNOWN,true,"Column key_bool item %d not as expected %d",
    438                 item->data.B, CONST_ROW_2_BOOL);
    439         return false;
    440     }
    441 
    442     return returnValue;
    443 }
    444 
    445 psS32 main(psS32 argc, char* argv[])
    446 {
    447     psLogSetLevel( PS_LOG_INFO );
    448 
    449     srand(time(NULL));
    450 
    451     return ( ! runTestSuite( stderr, "psDB", tests, argc, argv ) );
    452 }
    453 
    454 // Testpoint #841, initialize/break-down MySQL connection.
    455 psS32 TPDBInit( void )
    456 {
    457     psDB *dbh = NULL;
    458 
    459     // Initialize database with valid arguments
    460     dbh = _init_psDB();
    461     if (dbh == NULL) {
    462         psError(PS_ERR_UNKNOWN,true,"Did not expect NULL to be returned for valid arguments");
    463         return 1;
    464     }
    465 
    466     // Cleanup database/connection with valid psDB object
    467     psDBCleanup(dbh);
    468 
    469     // Attempt to initialize database with invalid arguments
    470     psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for invalid host");
    471     dbh = psDBInit("xxx",NULL,NULL,NULL);
    472     if(dbh != NULL) {
    473         psError(PS_ERR_UNKNOWN,true,"Did not expect non-NULL psDB with invalid arguments");
    474         return 2;
    475     }
    476 
    477     // Attempt cleanup database/connection with NULL psDB object
    478     psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for NULL database objec");
    479     psDBCleanup(NULL);
    480 
    481     return 0;
    482 }
    483 
    484 // Testpoint #842, psDBChange shall change databases.
    485 psS32 TPDBChange( void )
    486 {
    487     psDB *dbh = NULL;
    488 
    489     // Initialize database connection
    490     dbh = _init_psDB();
    491     if (dbh == NULL) {
    492         psError(PS_ERR_UNKNOWN,true,"Did not expect NULL for valid arguments");
    493         return 1;
    494     }
    495 
    496     // Attempt to change database with valid arguments
    497     if(!psDBChange(dbh, dbname)) {
    498         psError(PS_ERR_UNKNOWN,true,"Did not expect return false for valid arguments");
    499         return 2;
    500     }
    501 
    502     // Attemp to change database to invalid database name
    503     psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for invalid database");
    504     if(psDBChange(dbh,"abc")) {
    505         psError(PS_ERR_UNKNOWN,true,"Did not expect return true for unknown database name");
    506         return 3;
    507     }
    508 
    509     // Cleanup database connection
    510     psDBCleanup(dbh);
    511 
    512     // Attempt to change database with NULL database object
    513     psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for null database object");
    514     if(psDBChange(NULL,dbname)) {
    515         psError(PS_ERR_UNKNOWN,true,"Did not expect return true for NULL database object");
    516         return 4;
    517     }
    518 
    519     return 0;
    520 }
    521 
    522 // Testpoint #843, psDBCreateTable shall create tables in the test database ...
    523 psS32 TPDBCreateTable( void )
    524 {
    525     psDB *dbh = NULL;
    526     const char* table = "table1";
    527 
    528     // Create metadata for table definition
    529     psMetadata *md = _get_CreateTableMetadata();
    530 
    531     // Initialize database connection
    532     dbh = _init_psDB();
    533     if (dbh == NULL) {
    534         psError(PS_ERR_UNKNOWN,true,"Did not expect NULL for valid argument in database connection");
    535         return 1;
    536     }
    537 
    538     // Attempt to create database table with valid arguments
    539     if(!psDBCreateTable(dbh, table, md)) {
    540         psError(PS_ERR_UNKNOWN,true,"Did not expect return of false for valid arguments");
    541         return 2;
    542     } else {
    543         // Drop the table from the test database
    544         psDBDropTable(dbh, table);
    545     }
    546 
    547     // Free metadata definition of table
    548     psFree(md);
    549 
    550     // Attempt to create table with NULL table definition
    551     psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL parameter");
    552     if(psDBCreateTable(dbh,table,NULL)) {
    553         psError(PS_ERR_UNKNOWN,true,"Did not expect return of true for NULL metadata object");
    554         return 3;
    555     }
    556 
    557     // Attempt to create table with NULL connection
    558     psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL parameter");
    559     if(psDBCreateTable(NULL, table, md)) {
    560         psError(PS_ERR_UNKNOWN,true,"Did not expect return of true for NULL database object");
    561         return 4;
    562     }
    563 
    564     // Close/cleanup database connection
    565     psDBCleanup(dbh);
    566 
    567     return 0;
    568 }
    569 
    570 // Testpoint #844, psDBDropTable shall remove tables in the test database ...
    571 psS32 TPDBDropTable( void )
    572 {
    573     psDB *dbh = NULL;
    574     const char* table = "table2";
    575 
    576     // Create table definition metadata
    577     psMetadata *row=NULL, *md = _get_CreateTableMetadata();
    578 
    579     // Initialize database connection
    580     dbh = _init_psDB();
    581     if (dbh == NULL) {
    582         psError(PS_ERR_UNKNOWN,true,"Did not expect NULL return to initialize database");
    583         return 1;
    584     }
    585 
    586     // Create table in database
    587     if(psDBCreateTable(dbh, table, md)) {
    588 
    589         // Drop table with valid arguments
    590         if(!psDBDropTable(dbh, table)) {
    591             psError(PS_ERR_UNKNOWN,true,"Did not expect return false for valid arguments");
    592             return 2;
    593         }
    594 
    595         // insert should fail since the table has been drop from database
    596         psLogMsg( __func__, PS_LOG_INFO, "psDBDropTable: insert should fail here...\n" );
    597         row = _get_row();
    598         if (psDBInsertOneRow(dbh, table, row)) {
    599             psError(PS_ERR_UNKNOWN,true,"Did not expect to successfully insert row into dropped table");
    600             return 3;
    601         }
    602         psFree(row);
    603     } else {
    604         psError(PS_ERR_UNKNOWN,true,"Did not expect return false to create table");
    605         return 4;
    606     }
    607 
    608     // Attempt to drop table from NULL psDB object
    609     psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL database object");
    610     if(psDBDropTable(NULL,table)) {
    611         psError(PS_ERR_UNKNOWN,true,"Did not return false as expected for NULL database object");
    612         return 5;
    613     }
    614 
    615     // Attempt to drop table from valid psDB but invalid table
    616     psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid table");
    617     if(psDBDropTable(dbh,"table99")) {
    618         psError(PS_ERR_UNKNOWN,true,"Did not return false as expected for invalid table");
    619         return 6;
    620     }
    621 
    622     // Attempt to drop table from valid psDB but NULL table
    623     psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL table");
    624     if(psDBDropTable(dbh,NULL)) {
    625         psError(PS_ERR_UNKNOWN,true,"Did not return false as expected for NULL table");
    626         return 7;
    627     }
    628 
    629     psFree(md);
    630     psDBCleanup(dbh);
    631 
    632     return 0;
    633 }
    634 
    635 // Testpoint #845, TPDBSelectColumn shall write/select a column from a test table ...
    636 psS32 TPDBSelectColumn( void )
    637 {
    638     psDB *dbh = NULL;
    639     const char* table = "table3";
    640     psArray *ary = NULL;
    641     char *ptr=NULL;
    642 
    643     // Create table definition metadata
    644     psMetadata *row=NULL, *md = _get_CreateTableMetadata();
    645 
    646     // Initialize database connection
    647     dbh = _init_psDB();
    648     if (dbh == NULL) {
    649         psError(PS_ERR_UNKNOWN,true,"Did not expect return NULL to initialize database connection");
    650         return 1;
    651     }
    652 
    653     // Create database table
    654     if(!psDBCreateTable(dbh,table,md)) {
    655         psError(PS_ERR_UNKNOWN,true,"Unable to create database table for testing");
    656         psDBCleanup(dbh);
    657         return 2;
    658     }
    659 
    660     // Insert known constant row #1
    661     row = _get_const_row1();
    662     if(!psDBInsertOneRow(dbh, table, row)) {
    663         psError(PS_ERR_UNKNOWN,true,"Unable to add rows to test database");
    664         psDBDropTable(dbh, table);
    665         psDBCleanup(dbh);
    666         return 3;
    667     }
    668     psFree(row);
    669 
    670     // Insert known constant row #2
    671     row = _get_const_row2();
    672     if(!psDBInsertOneRow(dbh, table, row)) {
    673         psError(PS_ERR_UNKNOWN,true,"Unable to add rows to test database");
    674         psDBDropTable(dbh, table);
    675         psDBCleanup(dbh);
    676         return 4;
    677     }
    678     psFree(row);
    679 
    680     // Insert known row
    681     row = _get_row();
    682     if(!psDBInsertOneRow(dbh, table, row)) {
    683         psError(PS_ERR_UNKNOWN,true,"Unable to add rows to test database");
    684         psDBDropTable(dbh, table);
    685         psDBCleanup(dbh);
    686         return 5;
    687     }
    688     psFree(row);
    689 
    690     // Select all items in column key_string with valid arguments
    691     ary = psDBSelectColumn(dbh, table, TAB_COL_0_NAME, 0);
    692     if (ary == NULL) {
    693         psError(PS_ERR_UNKNOWN,true,"Did not expect return value of NULL");
    694         psDBDropTable(dbh, table);
    695         psDBCleanup(dbh);
    696         return 6;
    697     }
    698 
    699     // Verify array contents
    700     if(ary->n != 3) {
    701         psError(PS_ERR_UNKNOWN,true,"Array number of items %d not equal to expected %d",
    702                 ary->n, 3);
    703         psDBDropTable(dbh, table);
    704         psDBCleanup(dbh);
    705         return 60;
    706     }
    707     ptr = psArrayGet(ary, 2);
    708     if (strcmp(ptr, CONST_ROW_1_STR)) {
    709         psError(PS_ERR_UNKNOWN,true,"key_str column entry[%d] = %s not as expected %s",
    710                 2,CONST_ROW_1_STR,ptr);
    711         psDBDropTable(dbh, table);
    712         psDBCleanup(dbh);
    713         return 7;
    714     }
    715     //    psFree(ptr);
    716     ptr = psArrayGet(ary, 1);
    717     if (strcmp(ptr, CONST_ROW_2_STR)) {
    718         psError(PS_ERR_UNKNOWN,true,"key_str column entry[%d] = %s not as expected %s",
    719                 1,CONST_ROW_2_STR,ptr);
    720         psDBDropTable(dbh, table);
    721         psDBCleanup(dbh);
    722         return 8;
    723     }
    724     //    psFree(ptr);
    725     ptr = psArrayGet(ary, 0);
    726     if (strcmp(ptr, STR_1)) {
    727         psError(PS_ERR_UNKNOWN,true,"key_str column entry[%d] = %s not as expected %s",
    728                 0,STR_1,ptr);
    729         psDBDropTable(dbh, table);
    730         psDBCleanup(dbh);
    731         return 9;
    732     }
    733     //    psFree(ptr);
    734     psFree(ary);
    735 
    736     // Select items in column key_bool with limit 10 and valid arguments
    737     ary = psDBSelectColumn(dbh, table, TAB_COL_4_NAME, 10);
    738     if (ary == NULL) {
    739         psError(PS_ERR_UNKNOWN,true,"Did not expect return value of NULL");
    740         psDBDropTable(dbh, table);
    741         psDBCleanup(dbh);
    742         return 10;
    743     }
    744 
    745     // Verify array contents
    746     if(ary->n != 3) {
    747         psError(PS_ERR_UNKNOWN,true,"Array number of items %d not equal to expected %d",
    748                 ary->n, 3);
    749         psDBDropTable(dbh, table);
    750         psDBCleanup(dbh);
    751         return 100;
    752     }
    753     ptr = psArrayGet(ary, 2);
    754     if(atoi(ptr) != CONST_ROW_1_BOOL) {
    755         psError(PS_ERR_UNKNOWN,true,"key_bool column entry[%d] = %d not as expected %d",
    756                 2,CONST_ROW_1_BOOL,atoi(ptr));
    757         psDBDropTable(dbh, table);
    758         psDBCleanup(dbh);
    759         return 11;
    760     }
    761     //    psFree(ptr);
    762     ptr = psArrayGet(ary, 1);
    763     if(atoi(ptr) != CONST_ROW_2_BOOL) {
    764         psError(PS_ERR_UNKNOWN,true,"key_bool column entry[%d] = %d not as expected %d",
    765                 1,CONST_ROW_2_BOOL,atoi(ptr));
    766         psDBDropTable(dbh, table);
    767         psDBCleanup(dbh);
    768         return 12;
    769     }
    770     //    psFree(ptr);
    771     ptr = psArrayGet(ary, 0);
    772     if(atoi(ptr) != B_1) {
    773         psError(PS_ERR_UNKNOWN,true,"key_bool column entry[%d] = %d not as expected %d",
    774                 0,B_1,atoi(ptr));
    775         psDBDropTable(dbh, table);
    776         psDBCleanup(dbh);
    777         return 13;
    778     }
    779     //    psFree(ptr);
    780     psFree(ary);
    781 
    782     // Attempt to select columns from NULL database object
    783     psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for NULL database");
    784     if(psDBSelectColumn(NULL,table,"key_str",10) != NULL) {
    785         psError(PS_ERR_UNKNOWN,true,"Did not expect non-NULL return for selecting from NULL database");
    786         psDBDropTable(dbh, table);
    787         psDBCleanup(dbh);
    788         return 14;
    789     }
    790 
    791     // Attempt to select column from NULL table
    792     psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for NULL table");
    793     if(psDBSelectColumn(dbh,NULL,"key_str",10) != NULL) {
    794         psError(PS_ERR_UNKNOWN,true,"Did not expect non-NULL return for NULL table");
    795         psDBDropTable(dbh, table);
    796         psDBCleanup(dbh);
    797         return 15;
    798     }
    799 
    800     // Attempt to select column from invalid table
    801     psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for invalid table");
    802     if(psDBSelectColumn(dbh,"table99","key_str",10) != NULL) {
    803         psError(PS_ERR_UNKNOWN,true,"Did not expect non-NULL return for invalid table");
    804         psDBDropTable(dbh, table);
    805         psDBCleanup(dbh);
    806         return 16;
    807     }
    808 
    809     // Attempt to select invalid column from valid database object and valid table
    810     psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for invalid column");
    811     if(psDBSelectColumn(dbh,table,"key_null",10) != NULL) {
    812         psError(PS_ERR_UNKNOWN,true,"Did not expect non-NULL return for invalid column");
    813         psDBDropTable(dbh, table);
    814         psDBCleanup(dbh);
    815         return 17;
    816     }
    817 
    818     // Clean up table and memory
    819     psDBDropTable(dbh, table);
    820     psFree(md);
    821     psDBCleanup(dbh);
    822 
    823     return 0;
    824 }
    825 
    826 // Testpoint #846, TPDBSelectColumnNum shall write/select a column from a test table ...
    827 psS32 TPDBSelectColumnNum( void )
    828 {
    829     psDB *dbh = NULL;
    830     const char* table = "table4";
    831     psVector *vec = NULL;
    832 
    833     // Create table definition metadata
    834     psMetadata *row=NULL, *md = _get_CreateTableMetadata();
    835 
    836     // Initialize database connection
    837     dbh = _init_psDB();
    838     if (dbh == NULL) {
    839         psError(PS_ERR_UNKNOWN,true,"Did not expected NULL return to initialize database");
    840         return 1;
    841     }
    842 
    843     // Create database table for test
    844     if(!psDBCreateTable(dbh, table, md)) {
    845         psError(PS_ERR_UNKNOWN,true,"Did not expect return false for create table");
    846         return 2;
    847     }
    848 
    849     // Initialize database table with known rows
    850     row = _get_const_row1();
    851     psDBInsertOneRow(dbh, table, row);
    852     psFree(row);
    853 
    854     row = _get_const_row2();
    855     psDBInsertOneRow(dbh, table, row);
    856     psFree(row);
    857 
    858     row = _get_row();
    859     psDBInsertOneRow(dbh, table, row);
    860     psFree(row);
    861 
    862     // Use valid arguments to select column with numeric values to return vector
    863     vec = psDBSelectColumnNum(dbh, table, TAB_COL_1_NAME, PS_TYPE_S32, 0);
    864 
    865     // Verify vector returned
    866     if (vec == NULL) {
    867         psError(PS_ERR_UNKNOWN,true,"Did not expect NULL return with valid arguments");
    868         psDBDropTable(dbh,table);
    869         psDBCleanup(dbh);
    870         return 3;
    871     }
    872     // Verify vector values
    873     if(vec->n != 3) {
    874         psError(PS_ERR_UNKNOWN,true,"Did not expect return vector size not equal to 3");
    875         psDBDropTable(dbh,table);
    876         psDBCleanup(dbh);
    877         return 30;
    878     }
    879     if(vec->type.type != PS_TYPE_S32) {
    880         psError(PS_ERR_UNKNOWN,true,"Did not expect return vector type not equal to PS_TYPE_S32");
    881         psDBDropTable(dbh,table);
    882         psDBCleanup(dbh);
    883         return 31;
    884     }
    885     if ((vec->data.S32)[0] != S32_1) {
    886         psError(PS_ERR_UNKNOWN,true,"vector value[%d] = %d not as expected %d",
    887                 0,vec->data.S32[0], S32_1);
    888         psDBDropTable(dbh,table);
    889         psDBCleanup(dbh);
    890         return 4;
    891     }
    892     if ((vec->data.S32)[1] != CONST_ROW_2_S32) {
    893         psError(PS_ERR_UNKNOWN,true,"vector value[%d] = %d not as expected %d",
    894                 1,vec->data.S32[1], CONST_ROW_2_S32);
    895         psDBDropTable(dbh,table);
    896         psDBCleanup(dbh);
    897         return 5;
    898     }
    899     if ((vec->data.S32)[2] != CONST_ROW_1_S32) {
    900         psError(PS_ERR_UNKNOWN,true,"vector value[%d] = %d not as expected %d",
    901                 2,vec->data.S32[2], CONST_ROW_1_S32);
    902         psDBDropTable(dbh,table);
    903         psDBCleanup(dbh);
    904         return 6;
    905     }
    906     psFree(vec);
    907 
    908     // Use valid arguments to select column with numeric values to return vector
    909     vec = psDBSelectColumnNum(dbh, table, TAB_COL_4_NAME, PS_TYPE_BOOL, 0);
    910 
    911     // Verify vector returned
    912     if (vec == NULL) {
    913         psError(PS_ERR_UNKNOWN,true,"Did not expect NULL return with valid arguments");
    914         psDBDropTable(dbh,table);
    915         psDBCleanup(dbh);
    916         return 7;
    917     }
    918     // Verify vector values
    919     if(vec->n != 3) {
    920         psError(PS_ERR_UNKNOWN,true,"Did not expect return vector size not equal to 3");
    921         psDBDropTable(dbh,table);
    922         psDBCleanup(dbh);
    923         return 8;
    924     }
    925     if(vec->type.type != PS_TYPE_BOOL) {
    926         psError(PS_ERR_UNKNOWN,true,"Did not expect return vector type not equal to PS_TYPE_BOOL");
    927         psDBDropTable(dbh,table);
    928         psDBCleanup(dbh);
    929         return 9;
    930     }
    931     if ((vec->data.U8)[0] != B_1) {
    932         psError(PS_ERR_UNKNOWN,true,"vector value[%d] = %d not as expected %d",
    933                 0,vec->data.U8[0],B_1);
    934         psDBDropTable(dbh,table);
    935         psDBCleanup(dbh);
    936         return 10;
    937     }
    938     if ((vec->data.U8)[1] != CONST_ROW_2_BOOL) {
    939         psError(PS_ERR_UNKNOWN,true,"vector value[%d] = %d not as expected %d",
    940                 0,vec->data.U8[0],CONST_ROW_2_BOOL);
    941         psDBDropTable(dbh,table);
    942         psDBCleanup(dbh);
    943         return 11;
    944     }
    945     if ((vec->data.U8)[2] != CONST_ROW_1_BOOL) {
    946         psError(PS_ERR_UNKNOWN,true,"vector value[%d] = %d not as expected %d",
    947                 0,vec->data.U8[0],CONST_ROW_1_BOOL);
    948         psDBDropTable(dbh,table);
    949         psDBCleanup(dbh);
    950         return 12;
    951     }
    952     psFree(vec);
    953 
    954     // Attempt to select columns from NULL database
    955     psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error for NULL database object");
    956     if(psDBSelectColumnNum(NULL,table,TAB_COL_4_NAME,PS_TYPE_BOOL,10) != NULL) {
    957         psError(PS_ERR_UNKNOWN,true,"Did not expect non-NULL return with NULL database object");
    958         psDBDropTable(dbh,table);
    959         psDBCleanup(dbh);
    960         return 13;
    961     }
    962 
    963     // Attempt to select columns from NULL table
    964     psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error for NULL table");
    965     if(psDBSelectColumnNum(dbh,NULL,TAB_COL_4_NAME,PS_TYPE_BOOL,10) != NULL) {
    966         psError(PS_ERR_UNKNOWN,true,"Did not expect non-NULL return with NULL table");
    967         psDBDropTable(dbh,table);
    968         psDBCleanup(dbh);
    969         return 14;
    970     }
    971 
    972     // Attempt to select columns from invalid column
    973     psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error for invalid column");
    974     if(psDBSelectColumnNum(dbh,table,"key_999",PS_TYPE_BOOL,10) != NULL) {
    975         psError(PS_ERR_UNKNOWN,true,"Did not expect non-NULL return with NULL column");
    976         psDBDropTable(dbh,table);
    977         psDBCleanup(dbh);
    978         return 15;
    979     }
    980 
    981     // Attempt to select columns from invalid column
    982     psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error for invalid type");
    983     if(psDBSelectColumnNum(dbh,table,TAB_COL_0_NAME,0,10) != NULL) {
    984         psError(PS_ERR_UNKNOWN,true,"Did not expect non-NULL return with invalid type");
    985         psDBDropTable(dbh,table);
    986         psDBCleanup(dbh);
    987         return 16;
    988     }
    989 
    990     psDBDropTable(dbh, table);
    991     psFree(md);
    992     psDBCleanup(dbh);
    993 
    994     return 0;
    995 }
    996 
    997 // Testpoint #847, TPDBSelectRows shall write/select data from a test table ...
    998 psS32 TPDBSelectRows( void )
    999 {
    1000     int i;
    1001     psDB *dbh = NULL;
    1002     const char* table = "table5";
    1003     psArray *ary=NULL, *ary1=NULL, *ary2=NULL;
    1004     psMetadataItem *item = NULL;
    1005 
    1006     // Create database table definition
    1007     psMetadata *where=NULL, *row=NULL, *md = _get_CreateTableMetadata();
    1008 
    1009     // Initialize database connection
    1010     dbh = _init_psDB();
    1011     if (dbh == NULL) {
    1012         psError(PS_ERR_UNKNOWN,true,"Did not expected NULL return to initialize database");
    1013         return 1;
    1014     }
    1015 
    1016     psDBDropTable(dbh,table);
    1017     // Create database table for test
    1018     if(!psDBCreateTable(dbh, table, md)) {
    1019         psError(PS_ERR_UNKNOWN,true,"Did not expect return false for create table");
    1020         psDBCleanup(dbh);
    1021         return 2;
    1022     }
    1023 
    1024     // Initialize database table with known rows
    1025     row = _get_const_row1();
    1026     psDBInsertOneRow(dbh, table, row);
    1027     psFree(row);
    1028 
    1029     row = _get_const_row2();
    1030     psDBInsertOneRow(dbh, table, row);
    1031     psFree(row);
    1032 
    1033     row = _get_row();
    1034     psDBInsertOneRow(dbh, table, row);
    1035     psFree(row);
    1036 
    1037     // Generate valid where clause
    1038     where = _get_where();
    1039 
    1040     // Select rows with non limit
    1041     ary1 = psDBSelectRows(dbh, table, where, 0);
    1042 
    1043     // Select rows with a limit
    1044     ary2 = psDBSelectRows(dbh, table, where, 1);
    1045     psFree(where);
    1046 
    1047     // Cycle through both arrays to verify results
    1048     for (i=0; i<2; i++) {
    1049         ary = i ? ary2 : ary1;
    1050 
    1051         // Verify return array not NULL
    1052         if (ary == NULL) {
    1053             psError(PS_ERR_UNKNOWN,true,"Did not expect return NULL");
    1054             psDBDropTable(dbh,table);
    1055             psDBCleanup(dbh);
    1056             return 1;
    1057         }
    1058 
    1059         if(ary->n != 1) {
    1060             psError(PS_ERR_UNKNOWN,true,"Number of rows %d not as expected %d",
    1061                     ary->n, 1);
    1062             psDBDropTable(dbh,table);
    1063             psDBCleanup(dbh);
    1064             return 2;
    1065         }
    1066 
    1067         // Get metadata which contains row from array
    1068         row = (psMetadata*)psArrayGet(ary, 0);
    1069 
    1070         // Get key_s32 item from metadata
    1071         item = psMetadataLookup(row, TAB_COL_1_NAME);
    1072         if (item == NULL) {
    1073             psError(PS_ERR_UNKNOWN,true,"Could not find key_s32 item in row metadata");
    1074             psDBDropTable(dbh,table);
    1075             psDBCleanup(dbh);
    1076             return 2;
    1077         }
    1078         if (item->data.S32 != S32_1) {
    1079             psError(PS_ERR_UNKNOWN,true,"Row item %d not as expected %d",
    1080                     item->data.S32,S32_1);
    1081             psDBDropTable(dbh,table);
    1082             psDBCleanup(dbh);
    1083             return 3;
    1084         }
    1085 
    1086         // Get key_bool item from metadata
    1087         item = psMetadataLookup(row, TAB_COL_4_NAME);
    1088         if (item == NULL) {
    1089             psError(PS_ERR_UNKNOWN,true,"Could not find key_bool item in row metadata");
    1090             psDBDropTable(dbh,table);
    1091             psDBCleanup(dbh);
    1092             return 2;
    1093         }
    1094         if (item->data.B != B_1) {
    1095             psError(PS_ERR_UNKNOWN,true,"Row item %d not as expected %d",
    1096                     item->data.S32,S32_1);
    1097             psDBDropTable(dbh,table);
    1098             psDBCleanup(dbh);
    1099             return 4;
    1100         }
    1101         psFree(ary);
    1102         //        psFree(row);
    1103     }
    1104 
    1105     // Attempt to select rows with NULL database object
    1106     psLogMsg(__func__,PS_LOG_INFO,
    1107              "Following should generate an error message for NULL database object");
    1108     if(psDBSelectRows(NULL, table, where, 0) != NULL) {
    1109         psError(PS_ERR_UNKNOWN,true,"Did not expect non-NULL return for NULL database object");
    1110         psDBDropTable(dbh,table);
    1111         psDBCleanup(dbh);
    1112         return 5;
    1113     }
    1114 
    1115     // Attempt to select rows with invalid table
    1116     psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid table");
    1117     if(psDBSelectRows(dbh, NULL, where, 0) != NULL) {
    1118         psError(PS_ERR_UNKNOWN,true,"Did not expect non-NULL return for NULL database object");
    1119         psDBDropTable(dbh,table);
    1120         psDBCleanup(dbh);
    1121         return 5;
    1122     }
    1123 
    1124     // Select rows with no where specified
    1125     ary1 = psDBSelectRows(dbh, table, NULL, 0);
    1126     if(ary1 == NULL) {
    1127         psError(PS_ERR_UNKNOWN,true,"Did not expect NULL return using NULL where");
    1128         psDBDropTable(dbh,table);
    1129         psDBCleanup(dbh);
    1130         return 6;
    1131     }
    1132     if(ary1->n != 3) {
    1133         psError(PS_ERR_UNKNOWN,true,"Rows return %d not as expected %d",
    1134                 ary->n,3);
    1135         psDBDropTable(dbh,table);
    1136         psDBCleanup(dbh);
    1137         return 7;
    1138     }
    1139     psFree(ary1);
    1140 
    1141     psDBDropTable(dbh, table);
    1142     psFree(md);
    1143     psDBCleanup(dbh);
    1144 
    1145     return 0;
    1146 }
    1147 
    1148 // Testpoint #848, TPDBInsertOneRow shall write a row of data into a test table ...
    1149 psS32 TPDBInsertOneRow( void )
    1150 {
    1151     psDB *dbh = NULL;
    1152     const char* table = "table6";
    1153     psMetadata *invalidRow = NULL;
    1154     psArray*    ary = NULL;
    1155 
    1156     // Create table definition metadata
    1157     psMetadata *row=NULL, *md = _get_CreateTableMetadata();
    1158 
    1159     // Initialize database connection
    1160     dbh = _init_psDB();
    1161     if (dbh == NULL) {
    1162         psError(PS_ERR_UNKNOWN,true,"Did not expect return NULL for database initialization");
    1163         return 1;
    1164     }
    1165 
    1166     // Create database table
    1167     if(!psDBCreateTable(dbh, table, md)) {
    1168         psError(PS_ERR_UNKNOWN,true,"Did not expect return false for create database");
    1169         psDBCleanup(dbh);
    1170         return 2;
    1171     }
    1172 
    1173     // Insert a single row with valid arguments
    1174     row = _get_const_row1();
    1175     if(!psDBInsertOneRow(dbh, table, row)) {
    1176         psError(PS_ERR_UNKNOWN,true,"Did not expect return false for inserting row w/ valid arguments");
    1177         psDBDropTable(dbh,table);
    1178         psDBCleanup(dbh);
    1179         return 3;
    1180     }
    1181     // Verify row was added to table
    1182     ary = psDBSelectRows(dbh,table,NULL,0);
    1183     if(ary->n != 1) {
    1184         psError(PS_ERR_UNKNOWN,true,"Number of rows %d not as expected %d",
    1185                 ary->n,1);
    1186         psDBDropTable(dbh,table);
    1187         psDBCleanup(dbh);
    1188         return 30;
    1189     }
    1190     psFree(ary);
    1191 
    1192     // Insert a single row with NULL database
    1193     psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for NULL database");
    1194     if(psDBInsertOneRow(NULL,table,row)) {
    1195         psError(PS_ERR_UNKNOWN,true,"Did not expect return value true for NULL database");
    1196         psDBDropTable(dbh,table);
    1197         psDBCleanup(dbh);
    1198         return 4;
    1199     }
    1200 
    1201     // Insert a single row which has column which does not match table
    1202     invalidRow = _get_invalid_row();
    1203     psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for invalid column item");
    1204     if(psDBInsertOneRow(dbh,table,invalidRow)) {
    1205         psError(PS_ERR_UNKNOWN,true,"Did not expect return value true for invalid column item");
    1206         psDBDropTable(dbh,table);
    1207         psDBCleanup(dbh);
    1208         return 6;
    1209     }
    1210 
    1211     // Insert a single row with invalid table
    1212     psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for invalid table");
    1213     if(psDBInsertOneRow(dbh,"table999",row)) {
    1214         psError(PS_ERR_UNKNOWN,true,"Did not expect return value true for invalid table");
    1215         psDBDropTable(dbh,table);
    1216         psDBCleanup(dbh);
    1217         return 5;
    1218     }
    1219 
    1220     // Insert a single row with NULL row
    1221     psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for NULL row");
    1222     if(psDBInsertOneRow(dbh,table,NULL)) {
    1223         psError(PS_ERR_UNKNOWN,true,"Did not expect return value true for NULL row");
    1224         psDBDropTable(dbh,table);
    1225         psDBCleanup(dbh);
    1226         return 6;
    1227     }
    1228 
    1229     psFree(row);
    1230     psFree(invalidRow);
    1231     psDBDropTable(dbh, table);
    1232     psFree(md);
    1233     psDBCleanup(dbh);
    1234 
    1235     return 0;
    1236 }
    1237 
    1238 // Testpoint #849, TPDBInsertRows shall write rows of data into a test table ...
    1239 psS32 TPDBInsertRows( void )
    1240 {
    1241     psDB *dbh = NULL;
    1242     const char* table = "table7";
    1243     psArray *rowSet = NULL;
    1244     psArray* dumpRowSet = NULL;
    1245     psMetadataItem *item=NULL;
    1246     psArray* ary = NULL;
    1247     psMetadata* invalidRow = NULL;
    1248     psArray* invalidRowSet = NULL;
    1249 
    1250     //Create database table definition metadata
    1251     psMetadata *row=NULL, *md = _get_CreateTableMetadata();
    1252 
    1253     // Initialize database connection
    1254     dbh = _init_psDB();
    1255     if (dbh == NULL) {
    1256         psError(PS_ERR_UNKNOWN,true,"Did not expect NULL for initializing database connection");
    1257         return 1;
    1258     }
    1259 
    1260     // Create database table for testing
    1261     if(!psDBCreateTable(dbh, table, md)) {
    1262         psError(PS_ERR_UNKNOWN,true,"Did not expect return false for creating table");
    1263         psDBCleanup(dbh);
    1264         return 2;
    1265     }
    1266 
    1267     // Create array of row elements
    1268     rowSet = psArrayAlloc(3);
    1269     rowSet->n = 0;
    1270 
    1271     row = _get_const_row1();
    1272     psArrayAdd(rowSet, 0, row);
    1273     psFree(row);
    1274 
    1275     row = _get_const_row2();
    1276     psArrayAdd(rowSet, 0, row);
    1277     psFree(row);
    1278 
    1279     row = _get_row();
    1280     psArrayAdd(rowSet, 0, row);
    1281     psFree(row);
    1282 
    1283     // Insert rows with valid arguments
    1284     if(!psDBInsertRows(dbh, table, rowSet)) {
    1285         psError(PS_ERR_UNKNOWN,true,"Did not expect return false for inserting rows w/ valid args");
    1286         psDBDropTable(dbh,table);
    1287         psDBCleanup(dbh);
    1288         return 3;
    1289     }
    1290 
    1291     // Verify row was added to table
    1292     ary = psDBSelectRows(dbh,table,NULL,0);
    1293     if(ary->n != 3) {
    1294         psError(PS_ERR_UNKNOWN,true,"Number of rows %d not as expected %d",
    1295                 ary->n,3);
    1296         psDBDropTable(dbh,table);
    1297         psDBCleanup(dbh);
    1298         return 30;
    1299     }
    1300     psFree(ary);
    1301 
    1302     // extra checks ...
    1303     dumpRowSet = psDBDumpRows(dbh, table);
    1304     if (dumpRowSet == NULL) {
    1305         psError(PS_ERR_UNKNOWN,true,"Did not expect NULL from dump rows");
    1306         psDBDropTable(dbh,table);
    1307         psDBCleanup(dbh);
    1308         return 4;
    1309     }
    1310 
    1311     // Get first row from array
    1312     row = (psMetadata*)psArrayGet(dumpRowSet, 0);
    1313     // Verify contents for column key_s32
    1314     item = psMetadataLookup(row, TAB_COL_1_NAME);
    1315     if ((item == NULL) || (item->data.S32 != S32_1)) {
    1316         psError(PS_ERR_UNKNOWN,true,"Column value %d not as expected %d",
    1317                 item->data.S32, S32_1);
    1318         psDBDropTable(dbh,table);
    1319         psDBCleanup(dbh);
    1320         return 5;
    1321     }
    1322     // Verify contents for column key_bool
    1323     item = psMetadataLookup(row, TAB_COL_4_NAME);
    1324     if ((item == NULL) || (item->data.B != B_1)) {
    1325         psError(PS_ERR_UNKNOWN,true,"Column value %d not as expected %d",
    1326                 item->data.B, B_1);
    1327         psDBDropTable(dbh,table);
    1328         psDBCleanup(dbh);
    1329         return 6;
    1330     }
    1331     psFree(dumpRowSet);
    1332     //    psFree(row);
    1333 
    1334     // Insert rows with NULL database object
    1335     psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL database");
    1336     if(psDBInsertRows(NULL,table,rowSet)) {
    1337         psError(PS_ERR_UNKNOWN,true,"Did not expect return of false for NULL database");
    1338         psDBDropTable(dbh,table);
    1339         psDBCleanup(dbh);
    1340         return 7;
    1341     }
    1342 
    1343     // Insert rows with NULL table
    1344     psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL table");
    1345     if(psDBInsertRows(dbh,NULL,rowSet)) {
    1346         psError(PS_ERR_UNKNOWN,true,"Did not expect return of false for NULL table");
    1347         psDBDropTable(dbh,table);
    1348         psDBCleanup(dbh);
    1349         return 70;
    1350     }
    1351 
    1352     // Insert rows with invalid table
    1353     psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid table");
    1354     if(psDBInsertRows(dbh,"table999",rowSet)) {
    1355         psError(PS_ERR_UNKNOWN,true,"Did not expect return of false for invalid table");
    1356         psDBDropTable(dbh,table);
    1357         psDBCleanup(dbh);
    1358         return 8;
    1359     }
    1360 
    1361     // Insert rows with NULL array of rows to be inserted
    1362     psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL row array");
    1363     if(psDBInsertRows(dbh,table,NULL)) {
    1364         psError(PS_ERR_UNKNOWN,true,"Did not expect return of false for NULL row array");
    1365         psDBDropTable(dbh,table);
    1366         psDBCleanup(dbh);
    1367         return 9;
    1368     }
    1369 
    1370     // Insert a single row which has column which does not match table
    1371     invalidRow = _get_invalid_row();
    1372     // Create array of invalid row element
    1373     invalidRowSet = psArrayAlloc(1);
    1374     invalidRowSet->n = 0;
    1375     psArrayAdd(invalidRowSet, 0, invalidRow);
    1376     psFree(invalidRow);
    1377 
    1378     psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for invalid column item");
    1379     if(psDBInsertRows(dbh,table,invalidRowSet)) {
    1380         psError(PS_ERR_UNKNOWN,true,"Did not expect return value true for invalid column item");
    1381         psDBDropTable(dbh,table);
    1382         psDBCleanup(dbh);
    1383         return 10;
    1384     }
    1385     psFree(invalidRowSet);
    1386 
    1387     psFree(rowSet);
    1388     psDBDropTable(dbh, table);
    1389     psFree(md);
    1390     psDBCleanup(dbh);
    1391 
    1392     return 0;
    1393 }
    1394 
    1395 // Testpoint #850, TPDBDumpRows shall dump all rows from a test table ...
    1396 psS32 TPDBDumpRows( void )
    1397 {
    1398     psDB *dbh = NULL;
    1399     const char* table = "table8";
    1400     psArray *ary = NULL;
    1401 
    1402     // Create table definition metadata
    1403     psMetadata *row=NULL, *md = _get_CreateTableMetadata();
    1404 
    1405     // Initialize database connection
    1406     dbh = _init_psDB();
    1407     if (dbh == NULL) {
    1408         psError(PS_ERR_UNKNOWN,true,"Did not expect return NULL from initializing database");
    1409         return 1;
    1410     }
    1411 
    1412     // Create table for testing
    1413     if(!psDBCreateTable(dbh, table, md)) {
    1414         psError(PS_ERR_UNKNOWN,true,"Did not expect return false from creating table");
    1415         psDBCleanup(dbh);
    1416         return 2;
    1417     }
    1418 
    1419     // Insert known data rows into table
    1420     row = _get_const_row1();
    1421     psDBInsertOneRow(dbh, table, row);
    1422     psFree(row);
    1423 
    1424     row = _get_const_row2();
    1425     psDBInsertOneRow(dbh, table, row);
    1426     psFree(row);
    1427 
    1428     row = _get_row();
    1429     psDBInsertOneRow(dbh, table, row);
    1430     psFree(row);
    1431 
    1432     // Dump row with valid parameters
    1433     ary = psDBDumpRows(dbh, table);
    1434     if (ary == NULL) {
    1435         psError(PS_ERR_UNKNOWN,true,"Did not expect return NULL for dump rows");
    1436         psDBDropTable(dbh,table);
    1437         psDBCleanup(dbh);
    1438         return 3;
    1439     }
    1440     if(ary->n != 3) {
    1441         psError(PS_ERR_UNKNOWN,true,"Rows dumped %d not as expected %d",
    1442                 ary->n, 3);
    1443         psDBDropTable(dbh,table);
    1444         psDBCleanup(dbh);
    1445         return 4;
    1446     }
    1447 
    1448     row = (psMetadata*)psArrayGet(ary, 0);
    1449     if(!_check_row(row)) {
    1450         psDBDropTable(dbh,table);
    1451         psDBCleanup(dbh);
    1452         return 5;
    1453     }
    1454     //    psFree(row);
    1455     row = (psMetadata*)psArrayGet(ary, 1);
    1456     if(!_check_const_row2(row)) {
    1457         psDBDropTable(dbh,table);
    1458         psDBCleanup(dbh);
    1459         return 6;
    1460     }
    1461     //    psFree(row);
    1462     row = (psMetadata*)psArrayGet(ary, 2);
    1463     if(!_check_const_row1(row)) {
    1464         psDBDropTable(dbh,table);
    1465         psDBCleanup(dbh);
    1466         return 7;
    1467     }
    1468     //    psFree(row);
    1469     psFree(ary);
    1470 
    1471     // Attempt to dump row with database NULL
    1472     psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for NULL database");
    1473     if(psDBDumpRows(NULL,table)!=NULL) {
    1474         psError(PS_ERR_UNKNOWN,true,"Did not expect return non-NULL for NULL database specified");
    1475         psDBDropTable(dbh,table);
    1476         psDBCleanup(dbh);
    1477         return 8;
    1478     }
    1479 
    1480     // Attempt to dump row with table NULL
    1481     psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for NULL table");
    1482     if(psDBDumpRows(dbh,NULL)!=NULL) {
    1483         psError(PS_ERR_UNKNOWN,true,"Did not expect return non-NULL for NULL table specified");
    1484         psDBDropTable(dbh,table);
    1485         psDBCleanup(dbh);
    1486         return 9;
    1487     }
    1488 
    1489     psDBDropTable(dbh, table);
    1490 
    1491     psFree(md);
    1492     psDBCleanup(dbh);
    1493 
    1494     return 0;
    1495 }
    1496 
    1497 // Testpoint #851, TPDBDumpCols shall dump all cols from a test table ...
    1498 psS32 TPDBDumpCols( void )
    1499 {
    1500     psDB*                dbh     = NULL;
    1501     const char*          table   = "table9";
    1502     psMetadata*          row     = NULL;
    1503     psMetadata*          meta    = NULL;
    1504     psMetadata*          md      = NULL;
    1505     psMetadataIterator*  mdIter  = NULL;
    1506     psMetadataItem*      mdItem  = NULL;
    1507     int                  itemNum = 0;
    1508 
    1509     // Create database table definition
    1510     md = _get_CreateTableMetadata();
    1511 
    1512     // Initialize database connection
    1513     dbh = _init_psDB();
    1514     if (dbh == NULL) {
    1515         psError(PS_ERR_UNKNOWN,true,"Did not expect NULL return to initialize database");
    1516         return 1;
    1517     }
    1518 
    1519     // Create database table for testing
    1520     if(!psDBCreateTable(dbh, table, md)) {
    1521         psError(PS_ERR_UNKNOWN,true,"Did not expect return of false to create test table");
    1522         psDBCleanup(dbh);
    1523         return 2;
    1524     }
    1525 
    1526     // Add row with known data values
    1527     row = _get_const_row1();
    1528     psDBInsertOneRow(dbh, table, row);
    1529     psFree(row);
    1530 
    1531     row = _get_const_row2();
    1532     psDBInsertOneRow(dbh, table, row);
    1533     psFree(row);
    1534 
    1535     row = _get_row();
    1536     psDBInsertOneRow(dbh, table, row);
    1537     psFree(row);
    1538 
    1539     // Dump columns with valid arguments
    1540     meta = psDBDumpCols(dbh, table);
    1541     mdIter = psMetadataIteratorAlloc(meta,PS_LIST_HEAD,NULL);
    1542 
    1543     // Verify contents of metadata returned
    1544     if (meta == NULL) {
    1545         psError(PS_ERR_UNKNOWN,true,"Did not expect return value NULL for dumpCols with valid args");
    1546         psDBDropTable(dbh,table);
    1547         psDBCleanup(dbh);
    1548         return 3;
    1549     }
    1550     if(meta->list->n != 6) {
    1551         psError(PS_ERR_UNKNOWN,true,"Number of cols = %d not as expected %d",
    1552                 meta->list->n,6);
    1553         psDBDropTable(dbh,table);
    1554         psDBCleanup(dbh);
    1555         return 4;
    1556     }
    1557     // Verify the metadata items
    1558     itemNum = 0;
    1559     while ((mdItem = psMetadataGetAndIncrement(mdIter)) != NULL) {
    1560         switch(itemNum) {
    1561         case 0:
    1562             if(mdItem->type != PS_DATA_VECTOR) {
    1563                 psError(PS_ERR_UNKNOWN,true,"Column #%d type %d not as expected %d",
    1564                         itemNum,mdItem->type,PS_DATA_VECTOR);
    1565                 psDBDropTable(dbh,table);
    1566                 psDBCleanup(dbh);
    1567                 return 5*(itemNum+1);
    1568             }
    1569             if(((psVector*)mdItem->data.V)->type.type != PS_TYPE_S32) {
    1570                 psError(PS_ERR_UNKNOWN,true,"Column #%d vector type %d not as expected %d",
    1571                         itemNum,((psVector*)mdItem->data.V)->type.type, PS_TYPE_S32);
    1572                 psDBDropTable(dbh,table);
    1573                 psDBCleanup(dbh);
    1574                 return 6*(itemNum+1);
    1575             }
    1576             if(((psVector*)mdItem->data.V)->n != 3) {
    1577                 psError(PS_ERR_UNKNOWN,true,"Column #%d vector size %d not as expected %d",
    1578                         itemNum,((psVector*)mdItem->data.V)->n,3);
    1579                 psDBDropTable(dbh,table);
    1580                 psDBCleanup(dbh);
    1581                 return 7*(itemNum+1);
    1582             }
    1583             if(strcmp(mdItem->name,TAB_COL_5_NAME) != 0) {
    1584                 psError(PS_ERR_UNKNOWN,true,"Column #%d name %s not as expected %s",
    1585                         itemNum,mdItem->name,TAB_COL_5_NAME);
    1586                 psDBDropTable(dbh,table);
    1587                 psDBCleanup(dbh);
    1588                 return 8*(itemNum+1);
    1589             }
    1590             break;
    1591         case 1:
    1592             if(mdItem->type != PS_DATA_VECTOR) {
    1593                 psError(PS_ERR_UNKNOWN,true,"Column #%d type %d not as expected %d",
    1594                         itemNum,mdItem->type,PS_DATA_VECTOR);
    1595                 psDBDropTable(dbh,table);
    1596                 psDBCleanup(dbh);
    1597                 return 5*(itemNum+1);
    1598             }
    1599             if(((psVector*)mdItem->data.V)->type.type != PS_TYPE_BOOL) {
    1600                 psError(PS_ERR_UNKNOWN,true,"Column #%d vector type %d not as expected %d",
    1601                         itemNum,((psVector*)mdItem->data.V)->type.type, PS_TYPE_BOOL);
    1602                 psDBDropTable(dbh,table);
    1603                 psDBCleanup(dbh);
    1604                 return 6*(itemNum+1);
    1605             }
    1606             if(((psVector*)mdItem->data.V)->n != 3) {
    1607                 psError(PS_ERR_UNKNOWN,true,"Column #%d vector size %d not as expected %d",
    1608                         itemNum,((psVector*)mdItem->data.V)->n,3);
    1609                 psDBDropTable(dbh,table);
    1610                 psDBCleanup(dbh);
    1611                 return 7*(itemNum+1);
    1612             }
    1613             if(strcmp(mdItem->name,TAB_COL_4_NAME) != 0) {
    1614                 psError(PS_ERR_UNKNOWN,true,"Column #%d name %s not as expected %s",
    1615                         itemNum,mdItem->name,TAB_COL_4_NAME);
    1616                 psDBDropTable(dbh,table);
    1617                 psDBCleanup(dbh);
    1618                 return 8*(itemNum+1);
    1619             }
    1620             break;
    1621         case 2:
    1622             if(mdItem->type != PS_DATA_VECTOR) {
    1623                 psError(PS_ERR_UNKNOWN,true,"Column #%d type %d not as expected %d",
    1624                         itemNum,mdItem->type,PS_DATA_VECTOR);
    1625                 psDBDropTable(dbh,table);
    1626                 psDBCleanup(dbh);
    1627                 return 5*(itemNum+1);
    1628             }
    1629             if(((psVector*)mdItem->data.V)->type.type != PS_TYPE_F64) {
    1630                 psError(PS_ERR_UNKNOWN,true,"Column #%d vector type %d not as expected %d",
    1631                         itemNum,((psVector*)mdItem->data.V)->type.type, PS_TYPE_F64);
    1632                 psDBDropTable(dbh,table);
    1633                 psDBCleanup(dbh);
    1634                 return 6*(itemNum+1);
    1635             }
    1636             if(((psVector*)mdItem->data.V)->n != 3) {
    1637                 psError(PS_ERR_UNKNOWN,true,"Column #%d vector size %d not as expected %d",
    1638                         itemNum,((psVector*)mdItem->data.V)->n,3);
    1639                 psDBDropTable(dbh,table);
    1640                 psDBCleanup(dbh);
    1641                 return 7*(itemNum+1);
    1642             }
    1643             if(strcmp(mdItem->name,TAB_COL_3_NAME) != 0) {
    1644                 psError(PS_ERR_UNKNOWN,true,"Column #%d name %s not as expected %s",
    1645                         itemNum,mdItem->name,TAB_COL_3_NAME);
    1646                 psDBDropTable(dbh,table);
    1647                 psDBCleanup(dbh);
    1648                 return 8*(itemNum+1);
    1649             }
    1650             break;
    1651         case 3:
    1652             if(mdItem->type != PS_DATA_VECTOR) {
    1653                 psError(PS_ERR_UNKNOWN,true,"Column #%d type %d not as expected %d",
    1654                         itemNum,mdItem->type,PS_DATA_VECTOR);
    1655                 psDBDropTable(dbh,table);
    1656                 psDBCleanup(dbh);
    1657                 return 5*(itemNum+1);
    1658             }
    1659             if(((psVector*)mdItem->data.V)->type.type != PS_TYPE_F32) {
    1660                 psError(PS_ERR_UNKNOWN,true,"Column #%d vector type %d not as expected %d",
    1661                         itemNum,((psVector*)mdItem->data.V)->type.type, PS_TYPE_F32);
    1662                 psDBDropTable(dbh,table);
    1663                 psDBCleanup(dbh);
    1664                 return 6*(itemNum+1);
    1665             }
    1666             if(((psVector*)mdItem->data.V)->n != 3) {
    1667                 psError(PS_ERR_UNKNOWN,true,"Column #%d vector size %d not as expected %d",
    1668                         itemNum,((psVector*)mdItem->data.V)->n,3);
    1669                 psDBDropTable(dbh,table);
    1670                 psDBCleanup(dbh);
    1671                 return 7*(itemNum+1);
    1672             }
    1673             if(strcmp(mdItem->name,TAB_COL_2_NAME) != 0) {
    1674                 psError(PS_ERR_UNKNOWN,true,"Column #%d name %s not as expected %s",
    1675                         itemNum,mdItem->name,TAB_COL_2_NAME);
    1676                 psDBDropTable(dbh,table);
    1677                 psDBCleanup(dbh);
    1678                 return 8*(itemNum+1);
    1679             }
    1680             break;
    1681         case 4:
    1682             if(mdItem->type != PS_DATA_VECTOR) {
    1683                 psError(PS_ERR_UNKNOWN,true,"Column #%d type %d not as expected %d",
    1684                         itemNum,mdItem->type,PS_DATA_VECTOR);
    1685                 psDBDropTable(dbh,table);
    1686                 psDBCleanup(dbh);
    1687                 return 5*(itemNum+1);
    1688             }
    1689             if(((psVector*)mdItem->data.V)->type.type != PS_TYPE_S32) {
    1690                 psError(PS_ERR_UNKNOWN,true,"Column #%d vector type %d not as expected %d",
    1691                         itemNum,((psVector*)mdItem->data.V)->type.type, PS_TYPE_S32);
    1692                 psDBDropTable(dbh,table);
    1693                 psDBCleanup(dbh);
    1694                 return 6*(itemNum+1);
    1695             }
    1696             if(((psVector*)mdItem->data.V)->n != 3) {
    1697                 psError(PS_ERR_UNKNOWN,true,"Column #%d vector size %d not as expected %d",
    1698                         itemNum,((psVector*)mdItem->data.V)->n,3);
    1699                 psDBDropTable(dbh,table);
    1700                 psDBCleanup(dbh);
    1701                 return 7*(itemNum+1);
    1702             }
    1703             if(strcmp(mdItem->name,TAB_COL_1_NAME) != 0) {
    1704                 psError(PS_ERR_UNKNOWN,true,"Column #%d name %s not as expected %s",
    1705                         itemNum,mdItem->name,TAB_COL_1_NAME);
    1706                 psDBDropTable(dbh,table);
    1707                 psDBCleanup(dbh);
    1708                 return 8*(itemNum+1);
    1709             }
    1710             break;
    1711         case 5:
    1712             if(mdItem->type != PS_DATA_ARRAY) {
    1713                 psError(PS_ERR_UNKNOWN,true,"Column #%d type %d not as expected %d",
    1714                         itemNum,mdItem->type,PS_DATA_ARRAY);
    1715                 psDBDropTable(dbh,table);
    1716                 psDBCleanup(dbh);
    1717                 return 5*(itemNum+1);
    1718             }
    1719             if(((psArray*)mdItem->data.V)->n != 3) {
    1720                 psError(PS_ERR_UNKNOWN,true,"Column #%d vector size %d not as expected %d",
    1721                         itemNum,((psArray*)mdItem->data.V)->n,3);
    1722                 psDBDropTable(dbh,table);
    1723                 psDBCleanup(dbh);
    1724                 return 7*(itemNum+1);
    1725             }
    1726             if(strcmp(mdItem->name,TAB_COL_0_NAME) != 0) {
    1727                 psError(PS_ERR_UNKNOWN,true,"Column #%d name %s not as expected %s",
    1728                         itemNum,mdItem->name,TAB_COL_0_NAME);
    1729                 psDBDropTable(dbh,table);
    1730                 psDBCleanup(dbh);
    1731                 return 8*(itemNum+1);
    1732             }
    1733             break;
    1734 
    1735         default:
    1736             break;
    1737         }
    1738         itemNum++;
    1739     }
    1740     psFree(mdIter);
    1741     psFree(meta);
    1742 
    1743     // Attempt to dump columns from NULL database object
    1744     psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL database");
    1745     if(psDBDumpCols(NULL,table) != NULL) {
    1746         psError(PS_ERR_UNKNOWN,true,"Did not expect non-NULL when dumping columns from NULL database");
    1747         psDBDropTable(dbh,table);
    1748         psDBCleanup(dbh);
    1749         return 10;
    1750     }
    1751 
    1752     // Attempt to dump columns for NULL table
    1753     psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL table");
    1754     if(psDBDumpCols(dbh,NULL) != NULL) {
    1755         psError(PS_ERR_UNKNOWN,true,"Did not expect non-NULL when dumping columns from NULL table");
    1756         psDBDropTable(dbh,table);
    1757         psDBCleanup(dbh);
    1758         return 11;
    1759     }
    1760 
    1761 
    1762     psDBDropTable(dbh, table);
    1763 
    1764     psFree(md);
    1765 
    1766     psDBCleanup(dbh);
    1767 
    1768     return 0;
    1769 }
    1770 
    1771 // Testpoint #852, TPDBUpdateRows shall update rows in a test table ...
    1772 psS32 TPDBUpdateRows( void )
    1773 {
    1774     psDB*            dbh       = NULL;
    1775     const char*      table     = "table10";
    1776     psArray*         ary       = NULL;
    1777     psArray*         rowSet    = NULL;
    1778     psMetadata*      row       = NULL;
    1779     psMetadata*      where     = NULL;
    1780     psMetadata*      updates   = NULL;
    1781     psMetadata*      md        = NULL;
    1782     int              chgRows   = 0;
    1783 
    1784     // Create database table definition
    1785     md = _get_CreateTableMetadata();
    1786 
    1787     // Initialize database connection
    1788     dbh = _init_psDB();
    1789     if (dbh == NULL) {
    1790         psError(PS_ERR_UNKNOWN,true,"Did not expect return NULL when initializing database");
    1791         return 1;
    1792     }
    1793 
    1794     // Create test table
    1795     if(!psDBCreateTable(dbh, table, md)) {
    1796         psError(PS_ERR_UNKNOWN,true,"Did not expect return false to create test table");
    1797         psDBCleanup(dbh);
    1798         return 2;
    1799     }
    1800 
    1801     // Create array to hold rows to be added to test table
    1802     rowSet = psArrayAlloc(3);
    1803     rowSet->n = 0;
    1804 
    1805     row = _get_const_row1();
    1806     psArrayAdd(rowSet, 0, row);
    1807     psFree(row);
    1808 
    1809     row = _get_const_row2();
    1810     psArrayAdd(rowSet, 0, row);
    1811     psFree(row);
    1812 
    1813     row = _get_row();
    1814     psArrayAdd(rowSet, 0, row);
    1815     psFree(row);
    1816 
    1817     // Insert rows into test table
    1818     if(!psDBInsertRows(dbh, table, rowSet)) {
    1819         psError(PS_ERR_UNKNOWN,true,"Did not expect return false for inserting rows");
    1820         psDBDropTable(dbh,table);
    1821         psDBCleanup(dbh);
    1822         return 3;
    1823     }
    1824 
    1825     // Create where metadata to specify update - only one row
    1826     where = _get_where();
    1827 
    1828     // Create update metadata to specify values
    1829     updates = _get_update_values(STR_2, S32_2, F32_2, F64_2, B_2);
    1830 
    1831     // Perform database update with valid parameters
    1832     chgRows = psDBUpdateRows(dbh,table,where,updates);
    1833     if(chgRows != 1) {
    1834         psError(PS_ERR_UNKNOWN,true,"Did not expect return other than 1 for valid arguments");
    1835         psDBDropTable(dbh,table);
    1836         psDBCleanup(dbh);
    1837         return 4;
    1838     }
    1839     // Verify row contents after update
    1840     ary = psDBDumpRows(dbh, table);
    1841     if (ary == NULL) {
    1842         psError(PS_ERR_UNKNOWN,true,"Did not expect NULL return from dump rows");
    1843         psDBDropTable(dbh,table);
    1844         psDBCleanup(dbh);
    1845         return 5;
    1846     }
    1847     row = (psMetadata*)psArrayGet(ary, 0);
    1848     if(!_check_row_update(row)) {
    1849         psError(PS_ERR_UNKNOWN,true,"Update row not verified");
    1850         psDBDropTable(dbh,table);
    1851         psDBCleanup(dbh);
    1852         return 6;
    1853     }
    1854     //    psFree(row);
    1855     psFree(ary);
    1856 
    1857     // Attempt to update rows with NULL database
    1858     psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL database");
    1859     chgRows = psDBUpdateRows(NULL,table,where,updates);
    1860     if(chgRows != -1) {
    1861         psError(PS_ERR_UNKNOWN,true,"Updated rows %ld not as expected %ld",
    1862                 chgRows,-1);
    1863         psDBDropTable(dbh,table);
    1864         psDBCleanup(dbh);
    1865         return 7;
    1866     }
    1867 
    1868     // Attempt to update rows with invalid table
    1869     psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid table");
    1870     chgRows = psDBUpdateRows(dbh,"table999",where,updates);
    1871     if(chgRows != -1) {
    1872         psError(PS_ERR_UNKNOWN,true,"Updated rows %ld not as expected %ld",
    1873                 chgRows,-1);
    1874         psDBDropTable(dbh,table);
    1875         psDBCleanup(dbh);
    1876         return 8;
    1877     }
    1878 
    1879     // Attempt to update rows with NULL updates
    1880     psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL updates");
    1881     chgRows = psDBUpdateRows(dbh,table,where,NULL);
    1882     if(chgRows != -1) {
    1883         psError(PS_ERR_UNKNOWN,true,"Updated rows %ld not as expected %ld",
    1884                 chgRows,-1);
    1885         psDBDropTable(dbh,table);
    1886         psDBCleanup(dbh);
    1887         return 8;
    1888     }
    1889 
    1890     // Attempt to update rows with invalid where specifying non-existent column
    1891     psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid where");
    1892     psFree(where);
    1893     where = _get_invalid_where();
    1894     chgRows = psDBUpdateRows(dbh,table,where,updates);
    1895     if(chgRows != -1) {
    1896         psError(PS_ERR_UNKNOWN,true,"Updated rows %ld not as expected %ld",
    1897                 chgRows,-1);
    1898         psDBDropTable(dbh,table);
    1899         psDBCleanup(dbh);
    1900         return 9;
    1901     }
    1902 
    1903     // Attempt to update rows with bad value in where statement
    1904     psFree(where);
    1905     where = _get_where_bad_value();
    1906     chgRows = psDBUpdateRows(dbh,table,where,updates);
    1907     if(chgRows != 0) {
    1908         psError(PS_ERR_UNKNOWN,true,"Updated rows %ld not as expected %ld",
    1909                 chgRows,0);
    1910         psDBDropTable(dbh,table);
    1911         psDBCleanup(dbh);
    1912         return 10;
    1913     }
    1914     // Verify row contents after update - no change
    1915     ary = psDBDumpRows(dbh, table);
    1916     if (ary == NULL) {
    1917         psError(PS_ERR_UNKNOWN,true,"Did not expect NULL return from dump rows");
    1918         psDBDropTable(dbh,table);
    1919         psDBCleanup(dbh);
    1920         return 11;
    1921     }
    1922     row = (psMetadata*)psArrayGet(ary, 0);
    1923     if(!_check_row_update(row)) {
    1924         psError(PS_ERR_UNKNOWN,true,"Update row not verified");
    1925         psDBDropTable(dbh,table);
    1926         psDBCleanup(dbh);
    1927         return 12;
    1928     }
    1929     //    psFree(row);
    1930     psFree(ary);
    1931 
    1932     psFree(updates);
    1933     psFree(where);
    1934     psFree(rowSet);
    1935     psDBDropTable(dbh, table);
    1936 
    1937     psFree(md);
    1938     psDBCleanup(dbh);
    1939 
    1940     return 0;
    1941 }
    1942 
    1943 // Testpoint #853, TPDBDeleteRows shall update rows in a test table ...
    1944 psS32 TPDBDeleteRows( void )
    1945 {
    1946     psDB*         dbh       = NULL;
    1947     const char*   table     = "table11";
    1948     psArray*      ary       = NULL;
    1949     psArray*      rowSet    = NULL;
    1950     psMetadata*   where     = NULL;
    1951     psMetadata*   row       = NULL;
    1952     psMetadata*   md        = NULL;
    1953     int           chgRows   = 0;
    1954 
    1955     // Create database table definition
    1956     md = _get_CreateTableMetadata();
    1957 
    1958     // Initialize database connection
    1959     dbh = _init_psDB();
    1960     if (dbh == NULL) {
    1961         psError(PS_ERR_UNKNOWN,true,"Did not expect return NULL for initialize database");
    1962         return 1;
    1963     }
    1964 
    1965     // Create test table
    1966     if(!psDBCreateTable(dbh, table, md)) {
    1967         psError(PS_ERR_UNKNOWN,true,"Did not expect return false for creating test table");
    1968         psDBCleanup(dbh);
    1969         return 2;
    1970     }
    1971 
    1972     // Create known data rows to put into test table
    1973     rowSet = psArrayAlloc(3);
    1974     rowSet->n = 0;
    1975     row = _get_const_row1();
    1976     psArrayAdd(rowSet, 0, row);
    1977     psFree(row);
    1978     row = _get_const_row2();
    1979     psArrayAdd(rowSet, 0, row);
    1980     psFree(row);
    1981     row = _get_row();
    1982     psArrayAdd(rowSet, 0, row);
    1983     psFree(row);
    1984     if(!psDBInsertRows(dbh, table, rowSet)) {
    1985         psError(PS_ERR_UNKNOWN,true,"Did not expect return false for inserting data into table");
    1986         psDBDropTable(dbh,table);
    1987         psDBCleanup(dbh);
    1988         return 3;
    1989     }
    1990 
    1991     // Create where clause to specify the row to remove
    1992     where = _get_where();
    1993 
    1994     // Delete row with valid arguments
    1995     chgRows = psDBDeleteRows(dbh,table,where,10);
    1996     if(chgRows != 1) {
    1997         psError(PS_ERR_UNKNOWN,true,"Deleted rows %ld not as expected %ld",
    1998                 chgRows,1);
    1999         psDBDropTable(dbh,table);
    2000         psDBCleanup(dbh);
    2001         return 4;
    2002     }
    2003     // Verify table contents
    2004     ary = psDBDumpRows(dbh, table);
    2005     if (ary == NULL) {
    2006         psError(PS_ERR_UNKNOWN,true,"Did not expect return NULL for dump rows");
    2007         psDBDropTable(dbh,table);
    2008         psDBCleanup(dbh);
    2009         return 5;
    2010     }
    2011     if (ary->n != 2) {
    2012         psError(PS_ERR_UNKNOWN,true,"Remaining rows %d not as expected %d",
    2013                 ary->n,2);
    2014         psDBDropTable(dbh,table);
    2015         psDBCleanup(dbh);
    2016         return 6;
    2017     }
    2018     psFree(ary);
    2019 
    2020     // Attempt to delete row just deleted again
    2021     chgRows = psDBDeleteRows(dbh,table,where,10);
    2022     if(chgRows != 0) {
    2023         psError(PS_ERR_UNKNOWN,true,"Deleted rows %ld not as expected %ld",
    2024                 chgRows,0);
    2025         psDBDropTable(dbh,table);
    2026         psDBCleanup(dbh);
    2027         return 7;
    2028     }
    2029     // Verify table contents
    2030     ary = psDBDumpRows(dbh, table);
    2031     if (ary == NULL) {
    2032         psError(PS_ERR_UNKNOWN,true,"Did not expect return NULL for dump rows");
    2033         psDBDropTable(dbh,table);
    2034         psDBCleanup(dbh);
    2035         return 8;
    2036     }
    2037     if (ary->n != 2) {
    2038         psError(PS_ERR_UNKNOWN,true,"Remaining rows %d not as expected %d",
    2039                 ary->n,2);
    2040         psDBDropTable(dbh,table);
    2041         psDBCleanup(dbh);
    2042         return 9;
    2043     }
    2044     psFree(ary);
    2045 
    2046     // Attempt to delete row with NULL database
    2047     psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for NULL database");
    2048     chgRows = psDBDeleteRows(NULL,table,where,10);
    2049     if(chgRows > 0) {
    2050         psError(PS_ERR_UNKNOWN,true,"Deleted rows %ld not as expected %ld",
    2051                 chgRows, -1);
    2052         psDBDropTable(dbh,table);
    2053         psDBCleanup(dbh);
    2054         return 10;
    2055     }
    2056 
    2057     // Attempt to delete row with invalid table
    2058     psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for invalid table");
    2059     chgRows = psDBDeleteRows(dbh,"table999",where,10);
    2060     if(chgRows > 0) {
    2061         psError(PS_ERR_UNKNOWN,true,"Deleted rows %ld not as expected %ld",
    2062                 chgRows, -1);
    2063         psDBDropTable(dbh,table);
    2064         psDBCleanup(dbh);
    2065         return 11;
    2066     }
    2067 
    2068     // Attempt to delete row with NULL where - deletes all rows
    2069     chgRows = psDBDeleteRows(dbh,table,NULL,10);
    2070     if(chgRows != 2) {
    2071         psError(PS_ERR_UNKNOWN,true,"Deleted rows %ld not as expected %ld",
    2072                 chgRows, 2);
    2073         psDBDropTable(dbh,table);
    2074         psDBCleanup(dbh);
    2075         return 12;
    2076     }
    2077     // Verify table contents
    2078     ary = psDBDumpRows(dbh, table);
    2079     if (ary != NULL && ary->n != 0) {
    2080         psError(PS_ERR_UNKNOWN,true,"Remaining rows %d not as expected %d",
    2081                 ary->n,0);
    2082         psDBDropTable(dbh,table);
    2083         psDBCleanup(dbh);
    2084         return 14;
    2085     }
    2086     psFree(ary);
    2087 
    2088     // Attempt to delete row with NULL where - deletes all rows from an empty table
    2089     chgRows = psDBDeleteRows(dbh,table,NULL,10);
    2090     if(chgRows != 0) {
    2091         psError(PS_ERR_UNKNOWN,true,"Deleted rows %ld not as expected %d",
    2092                 chgRows, 0);
    2093         psDBDropTable(dbh,table);
    2094         psDBCleanup(dbh);
    2095         return 15;
    2096     }
    2097 
    2098     psFree(where);
    2099     psFree(rowSet);
    2100     psDBDropTable(dbh, table);
    2101 
    2102     psFree(md);
    2103     psDBCleanup(dbh);
    2104 
    2105     return 0;
    2106 }
    2107 
    2108 //
    2109 // Tests for psDBCreate and psDBDrop can only be executed if the user
    2110 // has system admin privileges for the SQL server so the tests have been
    2111 // commented out.
    2112 //
    2113 // Testpoint #XXX, psDBCreate shall create a new test database.
    2114 //psS32 TPDBCreate( void )
    2115 //{
    2116 //    const char *test_db = "ps_test_db";
    2117 //    psS32 failed = 0;
    2118 //    psDB *dbh = NULL;
    2119 //
    2120 //    dbh = _init_psDB();
    2121 //    if (dbh == NULL) {
    2122 //        return 1;
    2123 //    }
    2124 //
    2125 //    psLogMsg( __func__, PS_LOG_INFO, "psDBCreate shall create new new test database.\n" );
    2126 //
    2127 //    failed = ! psDBCreate(dbh, test_db);
    2128 //    if (!failed) {
    2129 //        psDBDrop(dbh, test_db);
    2130 //    }
    2131 //
    2132 //    psDBCleanup(dbh);
    2133 //
    2134 //    return failed;
    2135 //}
    2136 
    2137 // Testpoint #XXX, psDBDrop shall create a new test database.
    2138 //psS32 TPDBDrop( void )
    2139 //{
    2140 //    const char *test_db = "ps_test_db";
    2141 //    psS32 failed = 0;
    2142 //    psDB *dbh = NULL;
    2143 //
    2144 //    dbh = _init_psDB();
    2145 //    if (dbh == NULL) {
    2146 //        return 1;
    2147 //    }
    2148 //
    2149 //    psLogMsg( __func__, PS_LOG_INFO, "psDBDrop shall create/drop a new new test database.\n" );
    2150 //
    2151 //    failed = psDBCreate(dbh, test_db);
    2152 //    if (!failed) {
    2153 //        failed = ! psDBDrop(dbh, test_db);
    2154 //    }
    2155 //
    2156 //    psDBCleanup(dbh);
    2157 //
    2158 //    return failed;
    2159 //}
    2160 
    2161 #endif
Note: See TracChangeset for help on using the changeset viewer.