Changeset 17843 for trunk/psLib/src/db
- Timestamp:
- May 28, 2008, 5:02:28 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/db/psDB.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/db/psDB.c
r17842 r17843 23 23 * 4.1.2 or newer is required. 24 24 * 25 * $Id: psDB.c,v 1.15 6 2008-05-29 02:53:20jhoblitt Exp $25 * $Id: psDB.c,v 1.157 2008-05-29 03:02:28 jhoblitt Exp $ 26 26 */ 27 27 … … 1644 1644 // Reset iterator to head of list 1645 1645 psListIteratorSet(cursor, 0); 1646 // look for UINDEXs before INDEXs 1647 while ((item = psListGetAndIncrement(cursor))) { 1648 // don't compile a regex unless we have too 1649 if (psStrcasestr(item->comment, "UINDEX") == NULL) { 1650 continue; 1651 } 1652 1653 regex_t myregex; 1654 regmatch_t mymatch[2]; // match + 1 sub strings 1655 int errbuf_size = 1024; 1656 char errbuf[errbuf_size]; 1657 char *pattern = "UINDEX[:space:]*[(]([^)]*)"; 1658 1659 int status = regcomp(&myregex, pattern, REG_EXTENDED|REG_ICASE); 1660 if (status != 0) { 1661 regerror(status, &myregex, errbuf, errbuf_size); 1662 psError(PS_ERR_UNKNOWN, true, "regcomp() failed: %s", errbuf); 1663 psFree(query); 1664 psFree(cursor); 1665 return NULL; 1666 } 1667 1668 psTrace("psLib.db", 10, "trying regex pattern: %s against string: %s", pattern, item->comment); 1669 status = regexec(&myregex, item->comment, 2, mymatch, 0); 1670 if (status != 0) { 1671 regerror(status, &myregex, errbuf, errbuf_size); 1672 psError(PS_ERR_UNKNOWN, true, "regexec() failed: %s", errbuf); 1673 psFree(query); 1674 psFree(cursor); 1675 return NULL; 1676 } 1677 1678 regfree(&myregex); 1679 1680 // sub string 1: uindex(.*) 1681 size_t matchStart = (size_t)mymatch[1].rm_so; 1682 size_t matchEnd = (size_t)mymatch[1].rm_eo; 1683 size_t matchLength = matchEnd - matchStart; 1684 1685 if (matchStart == -1) { 1686 psError(PS_ERR_UNKNOWN, true, "substring 1 failed to match"); 1687 psFree(query); 1688 psFree(cursor); 1689 return NULL; 1690 } 1691 1692 psString index = psStringNCopy(item->comment + matchStart, matchLength); 1693 psTrace("psLib.db", 10, "regex $1 matched: %s", index); 1694 psStringAppend(&query, ", UNIQUE KEY(%s)", index); 1695 psFree(index); 1696 } 1697 1698 // Reset iterator to head of list 1699 psListIteratorSet(cursor, 0); 1700 // look for INDEX values 1646 // look for indexes 1701 1647 while ((item = psListGetAndIncrement(cursor))) { 1702 1648 // don't compile a regex unless we have too … … 1705 1651 } 1706 1652 1707 regex_t myregex; 1708 regmatch_t mymatch[2]; // match + 1 sub strings 1709 int errbuf_size = 1024; 1710 char errbuf[errbuf_size]; 1711 // don't accidentally match uindex 1712 char *pattern = "[^U]INDEX[:space:]*[(]([^)]*)"; 1713 1714 int status = regcomp(&myregex, pattern, REG_EXTENDED|REG_ICASE); 1715 if (status != 0) { 1716 regerror(status, &myregex, errbuf, errbuf_size); 1717 psError(PS_ERR_UNKNOWN, true, "regcomp() failed: %s", errbuf); 1718 psFree(query); 1719 psFree(cursor); 1720 return NULL; 1721 } 1722 1723 psTrace("psLib.db", 10, "trying regex pattern: %s against string: %s", pattern, item->comment); 1724 status = regexec(&myregex, item->comment, 2, mymatch, 0); 1725 if (status != 0) { 1726 regerror(status, &myregex, errbuf, errbuf_size); 1727 psError(PS_ERR_UNKNOWN, true, "regexec() failed: %s", errbuf); 1728 psFree(query); 1729 psFree(cursor); 1730 return NULL; 1731 } 1732 1733 regfree(&myregex); 1734 1735 // sub string 1: index(.*) 1736 size_t matchStart = (size_t)mymatch[1].rm_so; 1737 size_t matchEnd = (size_t)mymatch[1].rm_eo; 1738 size_t matchLength = matchEnd - matchStart; 1739 1740 if (matchStart == -1) { 1741 psError(PS_ERR_UNKNOWN, true, "substring 1 failed to match"); 1742 psFree(query); 1743 psFree(cursor); 1744 return NULL; 1745 } 1746 1747 psString index = psStringNCopy(item->comment + matchStart, matchLength); 1748 psTrace("psLib.db", 10, "regex $1 matched: %s", index); 1749 psStringAppend(&query, ", INDEX(%s)", index); 1750 psFree(index); 1653 if (psStrcasestr(item->comment, "UINDEX")) { 1654 // look for UINDEXs before INDEXs 1655 regex_t myregex; 1656 regmatch_t mymatch[2]; // match + 1 sub strings 1657 int errbuf_size = 1024; 1658 char errbuf[errbuf_size]; 1659 char *pattern = "UINDEX[:space:]*[(]([^)]*)"; 1660 1661 int status = regcomp(&myregex, pattern, REG_EXTENDED|REG_ICASE); 1662 if (status != 0) { 1663 regerror(status, &myregex, errbuf, errbuf_size); 1664 psError(PS_ERR_UNKNOWN, true, "regcomp() failed: %s", errbuf); 1665 psFree(query); 1666 psFree(cursor); 1667 return NULL; 1668 } 1669 1670 psTrace("psLib.db", 10, "trying regex pattern: %s against string: %s", pattern, item->comment); 1671 status = regexec(&myregex, item->comment, 2, mymatch, 0); 1672 if (status != 0) { 1673 regerror(status, &myregex, errbuf, errbuf_size); 1674 psError(PS_ERR_UNKNOWN, true, "regexec() failed: %s", errbuf); 1675 psFree(query); 1676 psFree(cursor); 1677 return NULL; 1678 } 1679 1680 regfree(&myregex); 1681 1682 // sub string 1: uindex(.*) 1683 size_t matchStart = (size_t)mymatch[1].rm_so; 1684 size_t matchEnd = (size_t)mymatch[1].rm_eo; 1685 size_t matchLength = matchEnd - matchStart; 1686 1687 if (matchStart == -1) { 1688 psError(PS_ERR_UNKNOWN, true, "substring 1 failed to match"); 1689 psFree(query); 1690 psFree(cursor); 1691 return NULL; 1692 } 1693 1694 psString index = psStringNCopy(item->comment + matchStart, matchLength); 1695 psTrace("psLib.db", 10, "regex $1 matched: %s", index); 1696 psStringAppend(&query, ", UNIQUE KEY(%s)", index); 1697 psFree(index); 1698 } else { 1699 regex_t myregex; 1700 regmatch_t mymatch[2]; // match + 1 sub strings 1701 int errbuf_size = 1024; 1702 char errbuf[errbuf_size]; 1703 // don't accidentally match uindex 1704 char *pattern = "[^U]INDEX[:space:]*[(]([^)]*)"; 1705 1706 int status = regcomp(&myregex, pattern, REG_EXTENDED|REG_ICASE); 1707 if (status != 0) { 1708 regerror(status, &myregex, errbuf, errbuf_size); 1709 psError(PS_ERR_UNKNOWN, true, "regcomp() failed: %s", errbuf); 1710 psFree(query); 1711 psFree(cursor); 1712 return NULL; 1713 } 1714 1715 psTrace("psLib.db", 10, "trying regex pattern: %s against string: %s", pattern, item->comment); 1716 status = regexec(&myregex, item->comment, 2, mymatch, 0); 1717 if (status != 0) { 1718 regerror(status, &myregex, errbuf, errbuf_size); 1719 psError(PS_ERR_UNKNOWN, true, "regexec() failed: %s", errbuf); 1720 psFree(query); 1721 psFree(cursor); 1722 return NULL; 1723 } 1724 1725 regfree(&myregex); 1726 1727 // sub string 1: index(.*) 1728 size_t matchStart = (size_t)mymatch[1].rm_so; 1729 size_t matchEnd = (size_t)mymatch[1].rm_eo; 1730 size_t matchLength = matchEnd - matchStart; 1731 1732 if (matchStart == -1) { 1733 psError(PS_ERR_UNKNOWN, true, "substring 1 failed to match"); 1734 psFree(query); 1735 psFree(cursor); 1736 return NULL; 1737 } 1738 1739 psString index = psStringNCopy(item->comment + matchStart, matchLength); 1740 psTrace("psLib.db", 10, "regex $1 matched: %s", index); 1741 psStringAppend(&query, ", INDEX(%s)", index); 1742 psFree(index); 1743 } 1751 1744 } 1752 1745
Note:
See TracChangeset
for help on using the changeset viewer.
