Index: trunk/archive/psdb/psDB.c
===================================================================
--- trunk/archive/psdb/psDB.c	(revision 3134)
+++ trunk/archive/psdb/psDB.c	(revision 3135)
@@ -8,6 +8,6 @@
  *  @author Joshua Hoblitt
  *
- *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-02-04 23:44:40 $
+ *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-02-05 00:49:51 $
  *
  *  Copyright 2005 Joshua Hoblitt, University of Hawaii
@@ -228,84 +228,76 @@
 }
 
+// a = assign too, b = source psArray, c = conversion function, d = type to cast to
+#define STRINGARRAYTOPTYPE(a, b, c, d)  for (i = 0; i < b->n; i++) { \
+                                            a = (d)(strlen(b->data[i]) \
+                                              ? atoi(b->data[i]) \
+                                              : *(d *)p_psDBGetPTypeNull(pType)); \
+                                        }
+
 psVector *psDBSelectColumnNum(psDB *dbh, const char *tableName, const char *col, psElemType pType, const psU64 limit)
 {
-    psArray         *oldColumn;
+    psArray         *stringColumn;
     psVector        *column;
     int             i;
 
-    oldColumn = psDBSelectColumn(dbh, tableName, col, limit);
-
-    if (oldColumn) {
-        column = psVectorAlloc(oldColumn->n, pType);
-
-        for (i = 0; i < oldColumn->n; i++) {
-            // long long is 64b and long is 32b on x86
-            switch (pType) {
-                case PS_TYPE_S8:
-                    column->data.S8[i] = (psS8)(strlen(oldColumn->data[i])
-                                       ? atoi(oldColumn->data[i]) 
-                                       : *(psS8 *)p_psDBGetPTypeNull(pType));
-                    break;
-                case PS_TYPE_S16:
-                    column->data.S16[i] = (psS16)(strlen(oldColumn->data[i])
-                                        ? atoi(oldColumn->data[i]) : PS_MAX_S16);
-                    break;
-                case PS_TYPE_S32:
-                    column->data.S32[i] = (psS32)(strlen(oldColumn->data[i])
-                                        ? atol(oldColumn->data[i]) : PS_MAX_S32);
-                    break;
-                case PS_TYPE_S64:
-                    column->data.S64[i] = (psS64)(strlen(oldColumn->data[i])
-                                        ? atoll(oldColumn->data[i]) : PS_MAX_S64);
-                    break;
-                case PS_TYPE_U8:
-                    // missing from psVector in SDRS
-                    column->data.U8[i]  = (psU8)(strlen(oldColumn->data[i])
-                                        ? atoi(oldColumn->data[i]) : PS_MAX_U8);
-                    break;
-                case PS_TYPE_U16:
-                    column->data.U16[i] = (psU16)(strlen(oldColumn->data[i])
-                                        ? atoi(oldColumn->data[i]) : PS_MAX_U16);
-                    break;
-                case PS_TYPE_U32:
-                    column->data.U32[i] = (psU32)(strlen(oldColumn->data[i])
-                                        ? atol(oldColumn->data[i]) : PS_MAX_U32);
-                    break;
-                case PS_TYPE_U64:
-                    column->data.U64[i] = (psU64)(strlen(oldColumn->data[i])
-                                        ? atoll(oldColumn->data[i]) : PS_MAX_U64);
-                    break;
-                case PS_TYPE_F32:
-                    column->data.F32[i] = (psF32)(strlen(oldColumn->data[i])
-                                        ? atof(oldColumn->data[i]) : NAN);
-                    break;
-                case PS_TYPE_F64:
-                    column->data.F64[i] = (psF64)(strlen(oldColumn->data[i])
-                                        ? atof(oldColumn->data[i]) : NAN);
-                    break;
-                case PS_TYPE_C32:
-                    // this is a bogus SQL type
-                    column->data.C32[i] = (psC32)(strlen(oldColumn->data[i])
-                                        ? atof(oldColumn->data[i]) : NAN);
-                    break;
-                case PS_TYPE_C64:
-                    // this is a bogus SQL type
-                    column->data.C64[i] = (psC64)(strlen(oldColumn->data[i])
-                                        ? atof(oldColumn->data[i]) : NAN);
-                    break;
-                case PS_TYPE_BOOL:
-                    // valid for psVector?
-                    break;
-                case PS_TYPE_PTR:
-                    // valid for psVector?
-                    break;
-            }
-        }
-
-        psFree(oldColumn);
+    stringColumn = psDBSelectColumn(dbh, tableName, col, limit);
+
+    if (stringColumn) {
+        column = psVectorAlloc(stringColumn->n, pType);
     } else {
         // psDBSelectColumn() returned NULL
-        column = NULL;
-    }
+        return NULL;
+    }
+
+    // long long is 64b and long is 32b on x86
+    switch (pType) {
+        case PS_TYPE_S8:
+            STRINGARRAYTOPTYPE(column->data.S8[i], stringColumn, atoi, psS8);
+            break;
+        case PS_TYPE_S16:
+            STRINGARRAYTOPTYPE(column->data.S16[i], stringColumn, atoi, psS16);
+            break;
+        case PS_TYPE_S32:
+            STRINGARRAYTOPTYPE(column->data.S32[i], stringColumn, atoi, psS32);
+            break;
+        case PS_TYPE_S64:
+            STRINGARRAYTOPTYPE(column->data.S64[i], stringColumn, atoll, psS64);
+            break;
+        case PS_TYPE_U8:
+            // missing from psVector in SDRS
+            STRINGARRAYTOPTYPE(column->data.U8[i], stringColumn, atoi, psU8);
+            break;
+        case PS_TYPE_U16:
+            STRINGARRAYTOPTYPE(column->data.U16[i], stringColumn, atoi, psU16);
+            break;
+        case PS_TYPE_U32:
+            STRINGARRAYTOPTYPE(column->data.U32[i], stringColumn, atoi, psU32);
+            break;
+        case PS_TYPE_U64:
+            STRINGARRAYTOPTYPE(column->data.U64[i], stringColumn, atoll, psU64);
+            break;
+        case PS_TYPE_F32:
+            STRINGARRAYTOPTYPE(column->data.F32[i], stringColumn, atof, psF32);
+            break;
+        case PS_TYPE_F64:
+            STRINGARRAYTOPTYPE(column->data.F64[i], stringColumn, atof, psF64);
+            break;
+        case PS_TYPE_C32:
+            // this is a bogus SQL type
+            STRINGARRAYTOPTYPE(column->data.C32[i], stringColumn, atof, psC32);
+            break;
+        case PS_TYPE_C64:
+            // this is a bogus SQL type
+            STRINGARRAYTOPTYPE(column->data.C64[i], stringColumn, atof, psC64);
+            break;
+        case PS_TYPE_BOOL:
+            // valid for psVector?
+            break;
+        case PS_TYPE_PTR:
+            // valid for psVector?
+            break;
+    }
+
+    psFree(stringColumn);
 
     return column;
