Changeset 4044
- Timestamp:
- May 27, 2005, 3:02:08 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/dataIO/tst_psDB.c (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/dataIO/tst_psDB.c
r3963 r4044 9 9 * @author Aaron Culliney, MHPCC 10 10 * 11 * @version $Revision: 1. 9$ $Name: not supported by cvs2svn $12 * @date $Date: 2005-05- 18 23:41:06$11 * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2005-05-28 01:02:08 $ 13 13 * 14 14 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 35 35 #define F64_1 2.7182818 36 36 #define F64_2 1.23456789 37 #define B_1 TRUE 38 #define B_2 FALSE 37 39 38 40 static psDB *_init_psDB( void ); 39 41 static psMetadata *_get_CreateTableMetadata( void ); 40 static psMetadata *_get_RowMetadataValues(const char *val0, psS32 val1, psF32 val2, psF64 val3 );42 static psMetadata *_get_RowMetadataValues(const char *val0, psS32 val1, psF32 val2, psF64 val3, psBool val4); 41 43 static psMetadata *_get_RowMetadata( 42 44 const char *key0, const char *comm0, const char *val0, 43 const char *key1, const char *comm1, psS32 val1, 44 const char *key2, const char *comm2, psF32 val2, 45 const char *key3, const char *comm3, psF64 val3, 46 const char *key4, const char *comm4, psS32 val4); 45 const char *key1, const char *comm1, psS32 val1, 46 const char *key2, const char *comm2, psF32 val2, 47 const char *key3, const char *comm3, psF64 val3, 48 const char *key4, const char *comm4, psBool val4, 49 const char *key5, const char *comm5, psS32 val5); 47 50 static psMetadata *_get_row( void ); 48 51 static psMetadata *_get_where( void ); 49 static psMetadata *_get_update_values(const char *val0, psS32 val1, psF32 val2, psF64 val3 );52 static psMetadata *_get_update_values(const char *val0, psS32 val1, psF32 val2, psF64 val3, psBool val4); 50 53 static void _print_row( psMetadata *row ); 51 54 … … 112 115 "key_f32", "Key", 0.0, 113 116 "key_f64", "", 0.0, 117 "key_bool", "", FALSE, 114 118 "key_s32_0", "Key,AUTO_INCREMENT", 0); 115 119 } 116 120 117 psMetadata *_get_RowMetadataValues(const char *val0, psS32 val1, psF32 val2, psF64 val3 )121 psMetadata *_get_RowMetadataValues(const char *val0, psS32 val1, psF32 val2, psF64 val3, psBool val4) 118 122 { 119 123 return _get_RowMetadata( … … 122 126 "key_f32", "comment-f32", val2, 123 127 "key_f64", "comment-f64", val3, 128 "key_bool", "comment-bool", val4, 124 129 NULL, NULL, 0.0); 125 130 } … … 127 132 psMetadata *_get_RowMetadata( 128 133 const char *key0, const char *comm0, const char *val0, 129 const char *key1, const char *comm1, psS32 val1, 130 const char *key2, const char *comm2, psF32 val2, 131 const char *key3, const char *comm3, psF64 val3, 132 const char *key4, const char *comm4, psS32 val4) 134 const char *key1, const char *comm1, psS32 val1, 135 const char *key2, const char *comm2, psF32 val2, 136 const char *key3, const char *comm3, psF64 val3, 137 const char *key4, const char *comm4, psBool val4, 138 const char *key5, const char *comm5, psS32 val5) 133 139 { 134 140 psMetadata *md = NULL; 135 psMetadataItem *str=NULL, *s32_0=NULL, *s32=NULL, *f32=NULL, *f64=NULL ;141 psMetadataItem *str=NULL, *s32_0=NULL, *s32=NULL, *f32=NULL, *f64=NULL, *b; 136 142 137 143 md = psMetadataAlloc(); … … 143 149 str = psMetadataItemAllocStr(key0, comm0, val0); 144 150 } 145 if (key4 != NULL) { 146 s32_0 = psMetadataItemAllocS32(key4, comm4, val4); 147 } 148 s32 = psMetadataItemAllocS32(key1, comm1, val1); 149 f32 = psMetadataItemAllocF32(key2, comm2, val2); 150 f64 = psMetadataItemAllocF64(key3, comm3, val3); 151 152 if ( ((key0 != NULL) && (str == NULL)) || (s32 == NULL) || (f32 == NULL) || (f64 == NULL) || 153 ((key4 != NULL) && (s32_0 == NULL)) ) { 151 if (key5 != NULL) { 152 s32_0 = psMetadataItemAllocS32(key5, comm5, val5); 153 } 154 s32 = psMetadataItemAllocS32 (key1, comm1, val1); 155 f32 = psMetadataItemAllocF32 (key2, comm2, val2); 156 f64 = psMetadataItemAllocF64 (key3, comm3, val3); 157 b = psMetadataItemAllocBool(key4, comm4, val4); 158 159 if ( ((key0 != NULL) && (str == NULL)) || (s32 == NULL) || (f32 == NULL) || (f64 == NULL) || (b == NULL) || 160 ((key5 != NULL) && (s32_0 == NULL)) ) { 154 161 psError(PS_ERR_UNKNOWN, true, "could not create psMetadataItem(s) in %s!", __func__ ); 155 162 return NULL; 156 163 } 157 if ( ((key0 != NULL) && !psMetadataAddItem(md, str, 0, 0)) || !psMetadataAddItem(md, s32, 0, 0) || 158 !psMetadataAddItem(md, f32, 0, 0) || !psMetadataAddItem(md, f64, 0, 0) || 159 ((key4 != NULL) && !psMetadataAddItem(md, s32_0, 0, 0))) { 164 if ( ((key0 != NULL) && !psMetadataAddItem(md, str, 0, 0)) || 165 !psMetadataAddItem(md, s32, 0, 0) || !psMetadataAddItem(md, f32, 0, 0) || 166 !psMetadataAddItem(md, f64, 0, 0) || !psMetadataAddItem(md, b, 0, 0) || 167 ((key5 != NULL) && !psMetadataAddItem(md, s32_0, 0, 0))) { 160 168 psError(PS_ERR_UNKNOWN, true, "could not add psMetadataItem(s) to psMetadata in %s!", __func__ ); 161 169 return NULL; … … 168 176 psFree(f32); 169 177 psFree(f64); 178 psFree(b); 170 179 if (s32_0 != NULL) { 171 180 psFree(s32_0); … … 184 193 "key_f32", "comment-f32", (double)rand()/RAND_MAX, 185 194 "key_f64", "comment-f64", (double)rand()/RAND_MAX, 195 "key_bool", "comment-bool", round((double)rand()/RAND_MAX), 186 196 NULL, NULL, 0.0); 187 197 } … … 194 204 "key_f32", "comment-f32", F32_1, 195 205 "key_f64", "comment-f64", F64_1, 206 "key_bool", "comment-bool", B_1, 196 207 NULL, NULL, 0.0); 197 208 } … … 221 232 } 222 233 223 psMetadata *_get_update_values(const char *val0, psS32 val1, psF32 val2, psF64 val3 )224 { 225 return _get_RowMetadataValues(val0, val1, val2, val3 );234 psMetadata *_get_update_values(const char *val0, psS32 val1, psF32 val2, psF64 val3, psBool val4) 235 { 236 return _get_RowMetadataValues(val0, val1, val2, val3, val4); 226 237 } 227 238 … … 241 252 } else if (item->type == PS_META_F64) { 242 253 psLogMsg( __func__, PS_LOG_INFO, "[%s]=[%g]\n", item->name, item->data.F64 ); 254 } else if (item->type == PS_META_BOOL) { 255 psLogMsg( __func__, PS_LOG_INFO, "[%s]=[%s]\n", item->name, item->data.B ? "Yay" : "Nay" ); 243 256 } 244 257 } … … 409 422 psFree(ary); 410 423 } 424 425 ary = psDBSelectColumn(dbh, table, "key_bool", 0); 426 if (ary == NULL) { 427 failed = 1; 428 } else { 429 ptr = psArrayGet(ary, 2); 430 psLogMsg( __func__, PS_LOG_INFO, "psDBSelectColumn: [%s]\n", ptr ); 431 432 ptr = psArrayGet(ary, 1); 433 psLogMsg( __func__, PS_LOG_INFO, "psDBSelectColumn: [%s]\n", ptr ); 434 435 ptr = psArrayGet(ary, 0); 436 psLogMsg( __func__, PS_LOG_INFO, "psDBSelectColumn: [%s]\n", ptr ); 437 438 if (atoi(ptr) != B_1) { 439 psLogMsg( __func__, PS_LOG_INFO, "oops, did not find expected string output!\n" ); 440 failed = 1; 441 } else { 442 psLogMsg( __func__, PS_LOG_INFO, "found expected string output.\n" ); 443 } 444 445 psFree(ary); 446 } 447 411 448 psDBDropTable(dbh, table); 412 449 } … … 464 501 psFree(vec); 465 502 } 503 504 vec = psDBSelectColumnNum(dbh, table, "key_bool", PS_TYPE_BOOL, 0); 505 if (vec == NULL) { 506 failed = 1; 507 } else { 508 psLogMsg( __func__, PS_LOG_INFO, "bool=[%d]\n", (vec->data.U8)[2] ); 509 psLogMsg( __func__, PS_LOG_INFO, "bool=[%d]\n", (vec->data.U8)[1] ); 510 psLogMsg( __func__, PS_LOG_INFO, "bool=[%d]\n", (vec->data.U8)[0] ); 511 if ((vec->data.U8)[0] != B_1) { 512 psLogMsg( __func__, PS_LOG_INFO, "oops, did not find expected bool output!\n" ); 513 failed = 1; 514 } else { 515 psLogMsg( __func__, PS_LOG_INFO, "found expected bool output.\n" ); 516 } 517 psFree(vec); 518 } 519 466 520 psDBDropTable(dbh, table); 467 521 } … … 531 585 } 532 586 587 item = psMetadataLookup(row, "key_bool"); 588 if (item == NULL) { 589 psLogMsg( __func__, PS_LOG_INFO, "oops, key_bool not found!\n" ); 590 failed = 1; 591 } else if (item->data.B != B_1) { 592 psLogMsg( __func__, PS_LOG_INFO, "oops, did not find expected output (%d vs %d)!\n", 593 item->data.B,B_1); 594 failed = 1; 595 } else { 596 psLogMsg( __func__, PS_LOG_INFO, "found expected output.\n" ); 597 } 598 533 599 psFree(ary); 534 600 } … … 628 694 } 629 695 696 item = psMetadataLookup(row, "key_bool"); 697 if ((item == NULL) || (item->data.B != B_1)) { 698 psLogMsg( __func__, PS_LOG_INFO, "oops, did not find expected output!\n" ); 699 failed = 1; 700 } else { 701 psLogMsg( __func__, PS_LOG_INFO, "found expected output.\n" ); 702 } 703 630 704 psFree(rowSet); 631 705 } … … 691 765 } 692 766 767 item = psMetadataLookup(row, "key_bool"); 768 if ((item == NULL) || (item->data.B != B_1)) { 769 psLogMsg( __func__, PS_LOG_INFO, "oops, did not find expected output!\n" ); 770 failed = 1; 771 } else { 772 psLogMsg( __func__, PS_LOG_INFO, "found expected output.\n" ); 773 } 774 693 775 psFree(ary); 694 776 } … … 710 792 psDB *dbh = NULL; 711 793 const char* table = "table9"; 712 psMetadata * meta=NULL, *md = _get_CreateTableMetadata();794 psMetadata *row=NULL, *meta=NULL, *md = _get_CreateTableMetadata(); 713 795 714 796 dbh = _init_psDB(); … … 721 803 failed = ! psDBCreateTable(dbh, table, md); 722 804 if (!failed) { 805 806 row = _get_rand_row(); 807 psDBInsertOneRow(dbh, table, row); 808 psFree(row); 809 810 row = _get_rand_row(); 811 psDBInsertOneRow(dbh, table, row); 812 psFree(row); 813 814 row = _get_row(); 815 failed = ! psDBInsertOneRow(dbh, table, row); 816 psFree(row); 817 723 818 meta = psDBDumpCols(dbh, table); 724 819 if (meta == NULL) { … … 774 869 if (!failed) { 775 870 where = _get_where(); 776 updates = _get_update_values(STR_2, S32_2, F32_2, F64_2 );871 updates = _get_update_values(STR_2, S32_2, F32_2, F64_2, B_2); 777 872 failed = (psDBUpdateRows(dbh, table, where, updates) < 0); 778 873 … … 787 882 item = psMetadataLookup(row, "key_s32"); 788 883 if ((item == NULL) || (item->data.S32 != S32_2)) { 884 psLogMsg( __func__, PS_LOG_INFO, "oops, did not find expected output!\n" ); 885 failed = 1; 886 } else { 887 psLogMsg( __func__, PS_LOG_INFO, "found expected output.\n" ); 888 } 889 890 item = psMetadataLookup(row, "key_bool"); 891 if ((item == NULL) || (item->data.B != B_2)) { 789 892 psLogMsg( __func__, PS_LOG_INFO, "oops, did not find expected output!\n" ); 790 893 failed = 1;
Note:
See TracChangeset
for help on using the changeset viewer.
