Index: trunk/psLib/src/db/psDB.c
===================================================================
--- trunk/psLib/src/db/psDB.c	(revision 16696)
+++ trunk/psLib/src/db/psDB.c	(revision 17775)
@@ -23,5 +23,5 @@
  * 4.1.2 or newer is required.
  *
- * $Id: psDB.c,v 1.151 2008-02-28 02:13:03 jhoblitt Exp $
+ * $Id: psDB.c,v 1.152 2008-05-22 21:16:55 jhoblitt Exp $
  */
 
@@ -1643,4 +1643,5 @@
     // Reset iterator to head of list
     psListIteratorSet(cursor, 0);
+
     // look for INDEX values
     while ((item = psListGetAndIncrement(cursor))) {
@@ -1692,4 +1693,58 @@
         psTrace("psLib.db", 10, "regex $1 matched: %s", index);
         psStringAppend(&query, ", INDEX(%s)", index);
+        psFree(index);
+    }
+
+    // Reset iterator to head of list
+    psListIteratorSet(cursor, 0);
+    // look for UNIQUE INDEXES
+    while ((item = psListGetAndIncrement(cursor))) {
+        // don't compile a regex unless we have too
+        if (psStrcasestr(item->comment, "UNIQUE") == NULL) {
+            continue;
+        }
+
+        regex_t         myregex;
+        regmatch_t      mymatch[2];     // match + 1 sub strings
+        int             errbuf_size = 1024;
+        char            errbuf[errbuf_size];
+        char            *pattern = "UNIQUE[: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: unique(.*)
+        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 UNIQUE(%s)", index);
         psFree(index);
     }
