Changeset 3135
- Timestamp:
- Feb 4, 2005, 2:49:51 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/archive/psdb/psDB.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/archive/psdb/psDB.c
r3134 r3135 8 8 * @author Joshua Hoblitt 9 9 * 10 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $11 * @date $Date: 2005-02-0 4 23:44:40$10 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2005-02-05 00:49:51 $ 12 12 * 13 13 * Copyright 2005 Joshua Hoblitt, University of Hawaii … … 228 228 } 229 229 230 // a = assign too, b = source psArray, c = conversion function, d = type to cast to 231 #define STRINGARRAYTOPTYPE(a, b, c, d) for (i = 0; i < b->n; i++) { \ 232 a = (d)(strlen(b->data[i]) \ 233 ? atoi(b->data[i]) \ 234 : *(d *)p_psDBGetPTypeNull(pType)); \ 235 } 236 230 237 psVector *psDBSelectColumnNum(psDB *dbh, const char *tableName, const char *col, psElemType pType, const psU64 limit) 231 238 { 232 psArray * oldColumn;239 psArray *stringColumn; 233 240 psVector *column; 234 241 int i; 235 242 236 oldColumn = psDBSelectColumn(dbh, tableName, col, limit); 237 238 if (oldColumn) { 239 column = psVectorAlloc(oldColumn->n, pType); 240 241 for (i = 0; i < oldColumn->n; i++) { 242 // long long is 64b and long is 32b on x86 243 switch (pType) { 244 case PS_TYPE_S8: 245 column->data.S8[i] = (psS8)(strlen(oldColumn->data[i]) 246 ? atoi(oldColumn->data[i]) 247 : *(psS8 *)p_psDBGetPTypeNull(pType)); 248 break; 249 case PS_TYPE_S16: 250 column->data.S16[i] = (psS16)(strlen(oldColumn->data[i]) 251 ? atoi(oldColumn->data[i]) : PS_MAX_S16); 252 break; 253 case PS_TYPE_S32: 254 column->data.S32[i] = (psS32)(strlen(oldColumn->data[i]) 255 ? atol(oldColumn->data[i]) : PS_MAX_S32); 256 break; 257 case PS_TYPE_S64: 258 column->data.S64[i] = (psS64)(strlen(oldColumn->data[i]) 259 ? atoll(oldColumn->data[i]) : PS_MAX_S64); 260 break; 261 case PS_TYPE_U8: 262 // missing from psVector in SDRS 263 column->data.U8[i] = (psU8)(strlen(oldColumn->data[i]) 264 ? atoi(oldColumn->data[i]) : PS_MAX_U8); 265 break; 266 case PS_TYPE_U16: 267 column->data.U16[i] = (psU16)(strlen(oldColumn->data[i]) 268 ? atoi(oldColumn->data[i]) : PS_MAX_U16); 269 break; 270 case PS_TYPE_U32: 271 column->data.U32[i] = (psU32)(strlen(oldColumn->data[i]) 272 ? atol(oldColumn->data[i]) : PS_MAX_U32); 273 break; 274 case PS_TYPE_U64: 275 column->data.U64[i] = (psU64)(strlen(oldColumn->data[i]) 276 ? atoll(oldColumn->data[i]) : PS_MAX_U64); 277 break; 278 case PS_TYPE_F32: 279 column->data.F32[i] = (psF32)(strlen(oldColumn->data[i]) 280 ? atof(oldColumn->data[i]) : NAN); 281 break; 282 case PS_TYPE_F64: 283 column->data.F64[i] = (psF64)(strlen(oldColumn->data[i]) 284 ? atof(oldColumn->data[i]) : NAN); 285 break; 286 case PS_TYPE_C32: 287 // this is a bogus SQL type 288 column->data.C32[i] = (psC32)(strlen(oldColumn->data[i]) 289 ? atof(oldColumn->data[i]) : NAN); 290 break; 291 case PS_TYPE_C64: 292 // this is a bogus SQL type 293 column->data.C64[i] = (psC64)(strlen(oldColumn->data[i]) 294 ? atof(oldColumn->data[i]) : NAN); 295 break; 296 case PS_TYPE_BOOL: 297 // valid for psVector? 298 break; 299 case PS_TYPE_PTR: 300 // valid for psVector? 301 break; 302 } 303 } 304 305 psFree(oldColumn); 243 stringColumn = psDBSelectColumn(dbh, tableName, col, limit); 244 245 if (stringColumn) { 246 column = psVectorAlloc(stringColumn->n, pType); 306 247 } else { 307 248 // psDBSelectColumn() returned NULL 308 column = NULL; 309 } 249 return NULL; 250 } 251 252 // long long is 64b and long is 32b on x86 253 switch (pType) { 254 case PS_TYPE_S8: 255 STRINGARRAYTOPTYPE(column->data.S8[i], stringColumn, atoi, psS8); 256 break; 257 case PS_TYPE_S16: 258 STRINGARRAYTOPTYPE(column->data.S16[i], stringColumn, atoi, psS16); 259 break; 260 case PS_TYPE_S32: 261 STRINGARRAYTOPTYPE(column->data.S32[i], stringColumn, atoi, psS32); 262 break; 263 case PS_TYPE_S64: 264 STRINGARRAYTOPTYPE(column->data.S64[i], stringColumn, atoll, psS64); 265 break; 266 case PS_TYPE_U8: 267 // missing from psVector in SDRS 268 STRINGARRAYTOPTYPE(column->data.U8[i], stringColumn, atoi, psU8); 269 break; 270 case PS_TYPE_U16: 271 STRINGARRAYTOPTYPE(column->data.U16[i], stringColumn, atoi, psU16); 272 break; 273 case PS_TYPE_U32: 274 STRINGARRAYTOPTYPE(column->data.U32[i], stringColumn, atoi, psU32); 275 break; 276 case PS_TYPE_U64: 277 STRINGARRAYTOPTYPE(column->data.U64[i], stringColumn, atoll, psU64); 278 break; 279 case PS_TYPE_F32: 280 STRINGARRAYTOPTYPE(column->data.F32[i], stringColumn, atof, psF32); 281 break; 282 case PS_TYPE_F64: 283 STRINGARRAYTOPTYPE(column->data.F64[i], stringColumn, atof, psF64); 284 break; 285 case PS_TYPE_C32: 286 // this is a bogus SQL type 287 STRINGARRAYTOPTYPE(column->data.C32[i], stringColumn, atof, psC32); 288 break; 289 case PS_TYPE_C64: 290 // this is a bogus SQL type 291 STRINGARRAYTOPTYPE(column->data.C64[i], stringColumn, atof, psC64); 292 break; 293 case PS_TYPE_BOOL: 294 // valid for psVector? 295 break; 296 case PS_TYPE_PTR: 297 // valid for psVector? 298 break; 299 } 300 301 psFree(stringColumn); 310 302 311 303 return column;
Note:
See TracChangeset
for help on using the changeset viewer.
