Index: /trunk/archive/psdb/psDB.c
===================================================================
--- /trunk/archive/psdb/psDB.c	(revision 3196)
+++ /trunk/archive/psdb/psDB.c	(revision 3197)
@@ -8,6 +8,6 @@
  *  @author Joshua Hoblitt
  *
- *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-02-11 23:19:25 $
+ *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-02-11 23:35:23 $
  *
  *  Copyright 2005 Joshua Hoblitt, University of Hawaii
@@ -581,12 +581,5 @@
     MYSQL_BIND      *bind;              // field values to insert
     psU32           paramCount;         // number of placeholders in query
-    psHash          *mysqlFieldType;    // type lookup table
-    mysqlType       *mType;             // type tmp variable
-    char            *key;               // hash tmp variable
-    psMetadataItem  *item;              // field in row
-    psListIterator  *cursor;            // row iterator
-    psU32           i;                  // field index
     psU64           j;                  // row index
-    bool            isNull = true;      // used in a MYSQL_BIND to indicate NULL
 
     // we are assuming that all rows in the set have an identical with reguard
@@ -624,57 +617,19 @@
     bind = psAlloc(sizeof(MYSQL_BIND) * paramCount);
 
-    mysqlFieldType = psDBGetPSToMySQLTable();
-
     // loop over rows
     for (j = 0; j < rowSet->n; j++) {
-        // extract the psList, from the psMetadata, in the current psArray element
-        cursor = psListIteratorAlloc(((psMetadata *)rowSet->data[j])->list, 0);
+        row = rowSet->data[j];
 
         // reset bind for each row
         memset(bind, 0, sizeof(MYSQL_BIND) * paramCount);
 
-        // loop over fields
-        i = 0;
-        while ((item = psListGetNext(cursor))) {
-            // lookup pType -> mysql type
-            key = psDBIntToString((psU64)item->pType);
-            mType = psHashLookup(mysqlFieldType, key);
-            psFree(key);
-
-            // input data length is determined by the MYSQL_TYPE_* unless it's a string
-            bind[i].buffer  = (char *)item->data.V;
-            bind[i].buffer_type = mType->type;
-            bind[i].is_unsigned = mType->isUnsigned;
-
-            // convert NaNs to NULL
-            bind[i].is_null = psDBIsPTypeNaN(item->pType, item->data.V) 
-                            ? (my_bool *)&isNull
-                            : NULL;
-
-            if (item->pType == PS_TYPE_PTR) {
-                if (item->type == PS_META_STR) {
-                    if (*(char *)item->data.V == '\0') {
-                        bind[i].is_null = (my_bool *)&isNull;
-                    } else {
-                        bind[i].buffer_length = (unsigned long)strlen((char *)item->data.V);
-                        bind[i].is_null = NULL;
-                    }
-                } else {
-                    // error, not a pointer to a string
-                    mysql_rollback(dbh->mysql);
-
-                    psFree(cursor);
-                    psFree(bind);
-                    mysql_stmt_close(stmt);
-
-                    return false;
-                }
-            }
-
-            // increment field index
-            i++;
-        }
-
-        psFree(cursor);
+        if (!psDBPackRow(bind, row, paramCount)) {
+            fprintf(stderr, "Failed to pack params into bind structure.\n");
+
+            mysql_rollback(dbh->mysql);
+
+            psFree(bind);
+            mysql_stmt_close(stmt);
+        }
 
         if (mysql_stmt_bind_param(stmt, bind)) {
@@ -700,6 +655,4 @@
         }
     } // end loop over rows
-
-    psFree(mysqlFieldType);
 
     // point of no return
@@ -807,7 +760,8 @@
     psHash          *mysqlFieldType;    // type lookup table
     mysqlType       *mType;             // type tmp variable
-    bool            isNull = true;      // used in a MYSQL_BIND to indicate NULL
+    static bool     isNull = true;      // used in a MYSQL_BIND to indicate NULL,
+                                        // this will be used outside of this func
     char            *key;               // hash tmp variable
-    int             i;
+    psU32           i;                  // field index
 
     // check size of values == paramCount ?
@@ -846,4 +800,5 @@
                 // error, not a pointer to a string
                 psFree(cursor);
+                psFree(mysqlFieldType);
 
                 return false;
