Changeset 3543 for trunk/psLib/src/fileUtils/psDB.c
- Timestamp:
- Mar 29, 2005, 12:13:28 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/fileUtils/psDB.c (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/fileUtils/psDB.c
r3532 r3543 1 1 /** @file psDB.c 2 * 3 * -*- mode: C; c-basic-indent: 4; tab-width: 8; indent-tabs-mode: nil -*- 4 * vim: set cindent ts=8 sw=4 expandtab: 2 5 * 3 6 * @brief database functions … … 8 11 * @author Joshua Hoblitt 9 12 * 10 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $11 * @date $Date: 2005-03-2 8 22:54:19$13 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2005-03-29 22:13:28 $ 12 15 * 13 16 * Copyright 2005 Joshua Hoblitt, University of Hawaii … … 430 433 431 434 // copy field data and convert NULLs to the appropriate NaN value 432 if (pType == PS_TYPE_PTR) { 435 if ((pType == PS_TYPE_PTR) || (pType == PS_META_STR)) { 436 pType = PS_META_STR; 433 437 data = fieldLength[i] ? psStringNCopy(row[i], fieldLength[i]) 434 438 : psDBGetPTypeNaN(pType); … … 443 447 444 448 // add new field to row 445 psMetadataAdd(md, i, field[i].name, pType, "no comment", data);449 psMetadataAdd(md, 0, field[i].name, pType, "no comment", data); 446 450 447 451 psFree(data); … … 450 454 // add row to result set 451 455 psArrayAdd(resultSet, 0, md); 456 psFree(md); 452 457 } 453 458 … … 460 465 { 461 466 psArray *rowSet; // psArray of row to insert 462 463 // this is to prevent row from being free'd when rowSet is free'd. this464 // will have to be removed when psArrayAdd is modified to do this for you.465 psMemIncrRefCounter(row);466 467 467 468 rowSet = psArrayAlloc(1); … … 603 604 // find ptype of column 604 605 pType = psDBMySQLToPType(field[i].type, field[i].flags); 606 //psLogMsg( __func__, PS_LOG_INFO, "pType=[%ld]\n", pType ); 605 607 606 608 // if the ptype is PS_TYPE_PTR assume that it's a string and fetch the 607 609 // column as an psArray of strings; otherwise fetch the column as a 608 610 // psVector. 609 if ( pType == PS_TYPE_PTR) {611 if ((pType == PS_TYPE_PTR) || (pType == PS_META_STR)) { 610 612 // PS_META_UNKNOWN -> PS_META_ARRAY ? 611 613 column = psDBSelectColumn(dbh, tableName, field[i].name, 0); 612 psMetadataAdd(table, 0, field[i].name, PS_TYPE_PTR, "psArray", column); 613 // FIXME 614 //psFree(column); 614 psMetadataAdd(table, 0, field[i].name, PS_META_STR, "no comment", column); 615 psFree(column); 615 616 } else { 616 617 column = psDBSelectColumnNum(dbh, tableName, field[i].name, pType, 0); 617 psMetadataAdd(table, 0, field[i].name, PS_TYPE_PTR, "psVector", column); 618 // FIXME 619 //psFree(column); 618 psMetadataAdd(table, 0, field[i].name, pType, "no comment", column); 619 psFree(column); 620 620 } 621 621 } … … 799 799 // convert NaNs to NULL and set the buffer_length for strings 800 800 //} else if ((item->type == PS_META_STR) && (item->pType == PS_TYPE_PTR)) { 801 } else if (item->type == PS_TYPE_PTR) { 801 } else if ((item->type == PS_META_STR) || (item->type == PS_META_VEC) || 802 (item->type == PS_META_IMG) || (item->type == PS_META_HASH) || 803 (item->type == PS_META_LOOKUPTABLE) || (item->type == PS_META_JPEG) || 804 (item->type == PS_META_PNG) || (item->type == PS_META_ASTROM) || 805 (item->type == PS_META_UNKNOWN) || (item->type == PS_TYPE_PTR)) { 806 802 807 bind[i].buffer_length = (unsigned long)strlen((char *)item->data.V); 803 808 bind[i].length = &bind[i].buffer_length; … … 848 853 // find column name and type 849 854 while ((item = psListGetAndIncrement(cursor))) { 850 if ((item->type == PS_META_S32) || (item->type == PS_META_F32) || (item->type == PS_META_F64)) { 855 if ((item->type == PS_META_S32) || (item->type == PS_META_F32) || (item->type == PS_META_F64) || 856 (item->type == PS_TYPE_S32) || (item->type == PS_TYPE_F32) || (item->type == PS_TYPE_F64)) { 851 857 // + column name + _ + column type 852 858 colType = psDBPTypeToSQL(item->type); … … 857 863 (item->type == PS_META_LOOKUPTABLE) || (item->type == PS_META_JPEG) || 858 864 (item->type == PS_META_PNG) || (item->type == PS_META_ASTROM) || 859 (item->type == PS_META_UNKNOWN) ) {865 (item->type == PS_META_UNKNOWN) || (item->type == PS_TYPE_PTR)) { 860 866 // + column name + _ + varchar( + length + ) 861 867 psStringAppend(&query, "%s VARCHAR(%s)", item->name, item->data.V); … … 1029 1035 1030 1036 psStringAppend(&query, "DELETE FROM %s %s", tableName, whereSQL); 1037 psFree(whereSQL); 1031 1038 1032 1039 return query; … … 1052 1059 while ((item = psListGetAndIncrement(cursor))) { 1053 1060 // item->data must be a string 1054 if (item->type == PS_META_STR) { 1061 if ((item->type == PS_META_S32) || (item->type == PS_TYPE_S32)) { 1062 psStringAppend(&query, "%s=%d", item->name, (int)(item->data.S32)); 1063 } else if ((item->type == PS_META_F32) || (item->type == PS_TYPE_F32)) { 1064 psStringAppend(&query, "%s=%g", item->name, (double)(item->data.F32)); 1065 } else if ((item->type == PS_META_F64) || (item->type == PS_TYPE_F64)) { 1066 psStringAppend(&query, "%s=%g", item->name, (double)(item->data.F64)); 1067 } else if (item->type == PS_META_STR) { 1055 1068 // + column name + _ + like + _ + ' + value + ' 1056 1069 if (*(char *)item->data.V == '\0') { 1057 1070 psStringAppend(&query, "%s IS NULL", item->name); 1058 1071 } else { 1072 // XXX ASC NOTE: we should have a better match for 1073 // char & varchar columns than this. LIKE is OK for 1074 // very large TEXT columns that really shouldn't be 1075 // used in a where clause... 1059 1076 psStringAppend(&query, "%s LIKE '%s'", item->name, item->data.V); 1060 1077 } 1061 1078 } else { 1062 psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Only a type of PS_META_STR is supported."); 1079 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 1080 "Only types PS_META_S32, PS_META_F32, PS_META_F64, PS_META_STR is supported"); 1063 1081 1064 1082 psFree(cursor); … … 1128 1146 1129 1147 mysqlToSQLTable = psDBGetMySQLToSQLTable(); 1130 sqlToPSTable = psDBGetSQLToPTypeTable();1131 1148 1132 1149 // lookup MySQL column type … … 1138 1155 if (!sqlType) { 1139 1156 psError(PS_ERR_UNEXPECTED_NULL, true, "type lookup failed."); 1140 1141 psFree(sqlToPSTable);1142 1143 1157 return -1; 1144 1158 } … … 1152 1166 } 1153 1167 1168 psLogMsg( __func__, PS_LOG_INFO, "sqlType=[%s]\n", sqlType ); 1169 1154 1170 // convert MySQL type to PS type 1171 sqlToPSTable = psDBGetSQLToPTypeTable(); 1155 1172 value = psHashLookup(sqlToPSTable, sqlType); 1156 1173 psFree(sqlToPSTable); … … 1236 1253 psDBAddToLookupTable(lookupTable, PS_TYPE_C64, "PS_TYPE_C64 is not supported"); 1237 1254 psDBAddToLookupTable(lookupTable, PS_TYPE_BOOL,"BOOLEAN"); 1238 psDBAddToLookupTable(lookupTable, PS_TYPE_PTR, "VARCHAR"); 1255 psDBAddToLookupTable(lookupTable, PS_TYPE_PTR, "BLOB"); 1256 psDBAddToLookupTable(lookupTable, PS_META_STR, "BLOB"); 1239 1257 } 1240 1258 … … 1274 1292 while ((key = psListGetAndIncrement(cursor))) { 1275 1293 value = psHashLookup(psToSQLTable, key); 1294 if (!strcmp(value, "BLOB")) { 1295 continue; // ignore reverse BLOB mapping, fill in below 1296 } 1276 1297 // switch key and value 1277 1298 psHashAdd(lookupTable, value, key); 1278 1299 } 1300 1301 value = psDBIntToString((psU64)PS_META_STR); 1302 psHashAdd(lookupTable, "VARCHAR", value); 1303 psHashAdd(lookupTable, "BLOB", value); 1304 psHashAdd(lookupTable, "TEXT", value); 1305 psFree(value); 1279 1306 1280 1307 // DECIMAL does not exist in the pType to SQL table … … 1372 1399 psDBAddVoidToLookupTable(lookupTable, PS_TYPE_BOOL, psDBMySQLTypeAlloc(MYSQL_TYPE_TINY, true)); 1373 1400 psDBAddVoidToLookupTable(lookupTable, PS_TYPE_PTR, psDBMySQLTypeAlloc(MYSQL_TYPE_VAR_STRING, false)); 1401 1402 psDBAddVoidToLookupTable(lookupTable, PS_META_STR, psDBMySQLTypeAlloc(MYSQL_TYPE_VAR_STRING, false)); 1403 psDBAddVoidToLookupTable(lookupTable, PS_META_VEC, psDBMySQLTypeAlloc(MYSQL_TYPE_VAR_STRING, false)); 1404 psDBAddVoidToLookupTable(lookupTable, PS_META_IMG, psDBMySQLTypeAlloc(MYSQL_TYPE_VAR_STRING, false)); 1405 psDBAddVoidToLookupTable(lookupTable, PS_META_HASH, psDBMySQLTypeAlloc(MYSQL_TYPE_VAR_STRING, false)); 1406 psDBAddVoidToLookupTable(lookupTable, PS_META_LOOKUPTABLE, 1407 psDBMySQLTypeAlloc(MYSQL_TYPE_VAR_STRING, false)); 1408 psDBAddVoidToLookupTable(lookupTable, PS_META_JPEG, psDBMySQLTypeAlloc(MYSQL_TYPE_VAR_STRING, false)); 1409 psDBAddVoidToLookupTable(lookupTable, PS_META_PNG, psDBMySQLTypeAlloc(MYSQL_TYPE_VAR_STRING, false)); 1410 psDBAddVoidToLookupTable(lookupTable, PS_META_ASTROM, psDBMySQLTypeAlloc(MYSQL_TYPE_VAR_STRING, false)); 1411 psDBAddVoidToLookupTable(lookupTable, PS_META_UNKNOWN,psDBMySQLTypeAlloc(MYSQL_TYPE_VAR_STRING, false)); 1374 1412 } 1375 1413
Note:
See TracChangeset
for help on using the changeset viewer.
