Index: trunk/psLib/src/db/psDB.c
===================================================================
--- trunk/psLib/src/db/psDB.c	(revision 17842)
+++ trunk/psLib/src/db/psDB.c	(revision 17843)
@@ -23,5 +23,5 @@
  * 4.1.2 or newer is required.
  *
- * $Id: psDB.c,v 1.156 2008-05-29 02:53:20 jhoblitt Exp $
+ * $Id: psDB.c,v 1.157 2008-05-29 03:02:28 jhoblitt Exp $
  */
 
@@ -1644,59 +1644,5 @@
     // Reset iterator to head of list
     psListIteratorSet(cursor, 0);
-    // look for UINDEXs before INDEXs
-    while ((item = psListGetAndIncrement(cursor))) {
-        // don't compile a regex unless we have too
-        if (psStrcasestr(item->comment, "UINDEX") == NULL) {
-            continue;
-        }
-
-        regex_t         myregex;
-        regmatch_t      mymatch[2];     // match + 1 sub strings
-        int             errbuf_size = 1024;
-        char            errbuf[errbuf_size];
-        char            *pattern = "UINDEX[:space:]*[(]([^)]*)";
-
-        int status = regcomp(&myregex, pattern, REG_EXTENDED|REG_ICASE);
-        if (status != 0) {
-            regerror(status, &myregex, errbuf, errbuf_size);
-            psError(PS_ERR_UNKNOWN, true, "regcomp() failed: %s", errbuf);
-            psFree(query);
-            psFree(cursor);
-            return NULL;
-        }
-
-        psTrace("psLib.db", 10, "trying regex pattern: %s against string: %s", pattern, item->comment);
-        status = regexec(&myregex, item->comment, 2, mymatch, 0);
-        if (status != 0) {
-            regerror(status, &myregex, errbuf, errbuf_size);
-            psError(PS_ERR_UNKNOWN, true, "regexec() failed: %s", errbuf);
-            psFree(query);
-            psFree(cursor);
-            return NULL;
-        }
-
-        regfree(&myregex);
-
-        // sub string 1: uindex(.*)
-        size_t matchStart = (size_t)mymatch[1].rm_so;
-        size_t matchEnd   = (size_t)mymatch[1].rm_eo;
-        size_t matchLength = matchEnd - matchStart;
-
-        if (matchStart == -1) {
-            psError(PS_ERR_UNKNOWN, true, "substring 1 failed to match");
-            psFree(query);
-            psFree(cursor);
-            return NULL;
-        }
-
-        psString index = psStringNCopy(item->comment + matchStart, matchLength);
-        psTrace("psLib.db", 10, "regex $1 matched: %s", index);
-        psStringAppend(&query, ", UNIQUE KEY(%s)", index);
-        psFree(index);
-    }
-
-    // Reset iterator to head of list
-    psListIteratorSet(cursor, 0);
-    // look for INDEX values
+    // look for indexes
     while ((item = psListGetAndIncrement(cursor))) {
         // don't compile a regex unless we have too
@@ -1705,48 +1651,95 @@
         }
 
-        regex_t         myregex;
-        regmatch_t      mymatch[2];     // match + 1 sub strings
-        int             errbuf_size = 1024;
-        char            errbuf[errbuf_size];
-        // don't accidentally match uindex
-        char            *pattern = "[^U]INDEX[:space:]*[(]([^)]*)";
-
-        int status = regcomp(&myregex, pattern, REG_EXTENDED|REG_ICASE);
-        if (status != 0) {
-            regerror(status, &myregex, errbuf, errbuf_size);
-            psError(PS_ERR_UNKNOWN, true, "regcomp() failed: %s", errbuf);
-            psFree(query);
-            psFree(cursor);
-            return NULL;
-        }
-
-        psTrace("psLib.db", 10, "trying regex pattern: %s against string: %s", pattern, item->comment);
-        status = regexec(&myregex, item->comment, 2, mymatch, 0);
-        if (status != 0) {
-            regerror(status, &myregex, errbuf, errbuf_size);
-            psError(PS_ERR_UNKNOWN, true, "regexec() failed: %s", errbuf);
-            psFree(query);
-            psFree(cursor);
-            return NULL;
-        }
-
-        regfree(&myregex);
-
-        // sub string 1: index(.*)
-        size_t matchStart = (size_t)mymatch[1].rm_so;
-        size_t matchEnd   = (size_t)mymatch[1].rm_eo;
-        size_t matchLength = matchEnd - matchStart;
-
-        if (matchStart == -1) {
-            psError(PS_ERR_UNKNOWN, true, "substring 1 failed to match");
-            psFree(query);
-            psFree(cursor);
-            return NULL;
-        }
-
-        psString index = psStringNCopy(item->comment + matchStart, matchLength);
-        psTrace("psLib.db", 10, "regex $1 matched: %s", index);
-        psStringAppend(&query, ", INDEX(%s)", index);
-        psFree(index);
+        if (psStrcasestr(item->comment, "UINDEX")) {
+            // look for UINDEXs before INDEXs
+            regex_t         myregex;
+            regmatch_t      mymatch[2];     // match + 1 sub strings
+            int             errbuf_size = 1024;
+            char            errbuf[errbuf_size];
+            char            *pattern = "UINDEX[:space:]*[(]([^)]*)";
+
+            int status = regcomp(&myregex, pattern, REG_EXTENDED|REG_ICASE);
+            if (status != 0) {
+                regerror(status, &myregex, errbuf, errbuf_size);
+                psError(PS_ERR_UNKNOWN, true, "regcomp() failed: %s", errbuf);
+                psFree(query);
+                psFree(cursor);
+                return NULL;
+            }
+
+            psTrace("psLib.db", 10, "trying regex pattern: %s against string: %s", pattern, item->comment);
+            status = regexec(&myregex, item->comment, 2, mymatch, 0);
+            if (status != 0) {
+                regerror(status, &myregex, errbuf, errbuf_size);
+                psError(PS_ERR_UNKNOWN, true, "regexec() failed: %s", errbuf);
+                psFree(query);
+                psFree(cursor);
+                return NULL;
+            }
+
+            regfree(&myregex);
+
+            // sub string 1: uindex(.*)
+            size_t matchStart = (size_t)mymatch[1].rm_so;
+            size_t matchEnd   = (size_t)mymatch[1].rm_eo;
+            size_t matchLength = matchEnd - matchStart;
+
+            if (matchStart == -1) {
+                psError(PS_ERR_UNKNOWN, true, "substring 1 failed to match");
+                psFree(query);
+                psFree(cursor);
+                return NULL;
+            }
+
+            psString index = psStringNCopy(item->comment + matchStart, matchLength);
+            psTrace("psLib.db", 10, "regex $1 matched: %s", index);
+            psStringAppend(&query, ", UNIQUE KEY(%s)", index);
+            psFree(index);
+        } else {
+            regex_t         myregex;
+            regmatch_t      mymatch[2];     // match + 1 sub strings
+            int             errbuf_size = 1024;
+            char            errbuf[errbuf_size];
+            // don't accidentally match uindex
+            char            *pattern = "[^U]INDEX[:space:]*[(]([^)]*)";
+
+            int status = regcomp(&myregex, pattern, REG_EXTENDED|REG_ICASE);
+            if (status != 0) {
+                regerror(status, &myregex, errbuf, errbuf_size);
+                psError(PS_ERR_UNKNOWN, true, "regcomp() failed: %s", errbuf);
+                psFree(query);
+                psFree(cursor);
+                return NULL;
+            }
+
+            psTrace("psLib.db", 10, "trying regex pattern: %s against string: %s", pattern, item->comment);
+            status = regexec(&myregex, item->comment, 2, mymatch, 0);
+            if (status != 0) {
+                regerror(status, &myregex, errbuf, errbuf_size);
+                psError(PS_ERR_UNKNOWN, true, "regexec() failed: %s", errbuf);
+                psFree(query);
+                psFree(cursor);
+                return NULL;
+            }
+
+            regfree(&myregex);
+
+            // sub string 1: index(.*)
+            size_t matchStart = (size_t)mymatch[1].rm_so;
+            size_t matchEnd   = (size_t)mymatch[1].rm_eo;
+            size_t matchLength = matchEnd - matchStart;
+
+            if (matchStart == -1) {
+                psError(PS_ERR_UNKNOWN, true, "substring 1 failed to match");
+                psFree(query);
+                psFree(cursor);
+                return NULL;
+            }
+
+            psString index = psStringNCopy(item->comment + matchStart, matchLength);
+            psTrace("psLib.db", 10, "regex $1 matched: %s", index);
+            psStringAppend(&query, ", INDEX(%s)", index);
+            psFree(index);
+        }
     }
 
