Index: /trunk/psLib/src/db/psDB.c
===================================================================
--- /trunk/psLib/src/db/psDB.c	(revision 7142)
+++ /trunk/psLib/src/db/psDB.c	(revision 7143)
@@ -12,6 +12,6 @@
  *  @author Joshua Hoblitt
  *
- *  @version $Revision: 1.51 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-05-05 23:56:51 $
+ *  @version $Revision: 1.52 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-05-18 20:08:33 $
  *
  *  Copyright 2005 Joshua Hoblitt, University of Hawaii
@@ -1134,14 +1134,34 @@
     }
 
+
+    // find database indexes
+    // check for Primary Keys first as they have to be part of the same Primary
+    // Key stmt
     // Reset iterator to head of list
     psListIteratorSet(cursor, 0);
-
-    // find database indexes
+    psArray *pKeys = psArrayAlloc(1);
     while ((item = psListGetAndIncrement(cursor))) {
-        // XXX NOTE: check for "Primary Key" first before "Key".  Yes we're
-        // playing fast and loose here, but I think it's fine...
         if (strstr(item->comment, "Primary Key")) {
-            psStringAppend(&query, ", PRIMARY KEY(%s)", item->name);
-        } else if (strstr(item->comment, "Key")) {
+            psArrayAdd(pKeys, 0, item->name);
+        }
+    }
+    if (psArrayLength(pKeys)) {
+        psStringAppend(&query, ", PRIMARY KEY(");
+        for (int i = 0; i < psArrayLength(pKeys); i++) {
+            if (i < 1) {
+                psStringAppend(&query, "%s", pKeys->data[i]);
+            } else {
+                psStringAppend(&query, ", %s", pKeys->data[i]);
+            }
+        }
+        psStringAppend(&query, ")");
+    }
+    psFree(pKeys);
+
+    // Reset iterator to head of list
+    psListIteratorSet(cursor, 0);
+    // look for regular keys
+    while ((item = psListGetAndIncrement(cursor))) {
+        if (strstr(item->comment, "Key")) {
             psStringAppend(&query, ", KEY(%s)", item->name);
         } else if (strstr(item->comment, "AUTO_INCREMENT")) {
