Changeset 14127
- Timestamp:
- Jul 10, 2007, 4:03:30 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/db/psDB.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/db/psDB.c
r12885 r14127 12 12 * @author Joshua Hoblitt 13 13 * 14 * @version $Revision: 1.14 2$ $Name: not supported by cvs2svn $15 * @date $Date: 2007-0 4-18 19:37:31$14 * @version $Revision: 1.143 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2007-07-11 02:03:30 $ 16 16 * 17 17 * Copyright (C) 2005-2006 Joshua Hoblitt, University of Hawaii … … 1587 1587 // Reset iterator to head of list 1588 1588 psListIteratorSet(cursor, 0); 1589 // look for INDEX values 1590 while ((item = psListGetAndIncrement(cursor))) { 1591 // don't compile a regex unless we have too 1592 if (psStrcasestr(item->comment, "INDEX") == NULL) { 1593 continue; 1594 } 1595 1596 regex_t myregex; 1597 regmatch_t mymatch[2]; // match + 1 sub strings 1598 int errbuf_size = 1024; 1599 char errbuf[errbuf_size]; 1600 char *pattern = "INDEX[:space:]*[(]([^)]*)"; 1601 1602 int status = regcomp(&myregex, pattern, REG_EXTENDED|REG_ICASE); 1603 if (status != 0) { 1604 regerror(status, &myregex, errbuf, errbuf_size); 1605 psError(PS_ERR_UNKNOWN, true, "regcomp() failed: %s", errbuf); 1606 psFree(query); 1607 psFree(cursor); 1608 return NULL; 1609 } 1610 1611 psTrace("psLib.db", 10, "trying regex pattern: %s against string: %s", pattern, item->comment); 1612 status = regexec(&myregex, item->comment, 2, mymatch, 0); 1613 if (status != 0) { 1614 regerror(status, &myregex, errbuf, errbuf_size); 1615 psError(PS_ERR_UNKNOWN, true, "regexec() failed: %s", errbuf); 1616 psFree(query); 1617 psFree(cursor); 1618 return NULL; 1619 } 1620 1621 regfree(&myregex); 1622 1623 // sub string 1: index(.*) 1624 size_t matchStart = (size_t)mymatch[1].rm_so; 1625 size_t matchEnd = (size_t)mymatch[1].rm_eo; 1626 size_t matchLength = matchEnd - matchStart; 1627 1628 if (matchStart == -1) { 1629 psError(PS_ERR_UNKNOWN, true, "substring 1 failed to match"); 1630 psFree(query); 1631 psFree(cursor); 1632 return NULL; 1633 } 1634 1635 psString index = psStringNCopy(item->comment + matchStart, matchLength); 1636 psTrace("psLib.db", 10, "regex $1 matched: %s", index); 1637 psStringAppend(&query, ", INDEX(%s)", index); 1638 psFree(index); 1639 } 1640 1641 // Reset iterator to head of list 1642 psListIteratorSet(cursor, 0); 1589 1643 // look for foreign keys after all other key types 1590 1644 while ((item = psListGetAndIncrement(cursor))) {
Note:
See TracChangeset
for help on using the changeset viewer.
