Boost logo

Boost Users :

From: eydelber (eydelber_at_[hidden])
Date: 2002-12-04 14:09:56


This test is completely stripped down, should work for you on Win32,
and still reproduces the problem:

#include <iostream>
#include <string>
#include <boost/regex.hpp>

using namespace std;
using namespace boost;

const string re_ID = "[\\w\\-]+";
const string re_TYPES = "int|decimal|datetime|varchar";
const string re_BASIC_COLDEF = "(_ID_) (_TYPES_)( not null)?(
unique)?( default ((\\d+(\\.\\d+)?)|(\"[^\"]*\")))?( unique)?";
const string re_EXT_COLDEF = re_BASIC_COLDEF+"( first| after
(_ID_))?";

string replaceStr(string Source, const string& Find, const string&
Replacement) {
        string::size_type Length = Find.length();
        string::size_type ReplacementLength = Replacement.length();
        string::size_type Pos = 0;
        while((Pos = Source.find(Find,Pos)) != string::npos) {
                Source.replace(Pos,Length,Replacement);
                Pos += ReplacementLength;
        }
        return Source;
}

string replaceMacros(string reg) {
        return(replaceStr(replaceStr(replaceStr(replaceStr(replaceStr
(reg," ","\\s+"),"_COL_",re_BASIC_COLDEF),"_ECOL_",re_EXT_COLDEF),"_I
D_",re_ID),"_TYPES_",re_TYPES));
}

int main() {
        string sql = "insert into test
(vklajsfkljsdfkjsldfsdjkfdslklfsdjklfsjfsd) values (1)";
        string checks[] = {
                /* 0 */ "create table (_ID_) (\\(((\\s*,?
\\s*_COL_\\s*)+)\\))",
                /* 1 */ "show tables",
                /* 2 */ "drop table (_ID_)",
                /* 3 */ "show database",
                /* 4 */ "desc( table)? (_ID_)",
                /* 5 */ "alter table (_ID_) add( column)? (_ECOL_)",
                /* 6 */ "alter table (_ID_) drop( column)? (_ID_)",
                /* 7 */ "alter table (_ID_) add( column)?
\\(((\\s*,?\\s*_ECOL_\\s*)+)\\)",
                /* 8 */ "rename table (_ID_) (to|as) (_ID_)",
                /* 9 */ "alter table (_ID_) alter( column)? (_ID_)
(set default ((\\d+(\\.\\d+)?)|(\"[^\"]*\"))|drop default)",
                /* 10 */ "alter table (_ID_) modify( column)?
(_COL_)",
                /* 11 */ "alter table (_ID_) change( column)? (_ID_)
(_COL_)",
                /* 12 */ "alter table (_ID_) rename( to| as) (_ID_)",
                /* 13 */ "insert( into)? (_ID_)( \\(((\\s*,?\\s*
(_ID_)\\s*)+)\\))? values \\(((\\s*,?\\s*((\\d+(\\.\\d+)?)|(\"[^\"]
*\"))\\s*)+)\\)"
        };
        int checksLength = sizeof checks / sizeof *checks;
        int i;
        for(i=0;i<checksLength;i++) {
                checks[i] = "^(\\s*"+replaceMacros(checks[i])
+"\\s*;?)$";
        }
        RegEx sqlRegex;
        for(i=0;i<checksLength;i++) {
                sqlRegex.SetExpression(checks[i],true);
                if(sqlRegex.Match(sql)) {
                        break;
                }
        }
        cout << "Finished." << endl;
        return 0;
}

If you change the "sql" string to match any other of the 12 cases,
they work fine. Only with the last case does it not work.

Again, thanks a lot for your time,
Kevin

--- In Boost-Users_at_y..., "John Maddock" <john_maddock_at_c...> wrote:
> > Sorry, I didn't qualify my problem correctly. The problem comes
in
> > when the column list is too long, opposite of what you tested.
> > Also, I doubt the problem is duplicable in such certain
conditions,
> > so if you want to try the full program, it will take about 5
minutes
> > to download and test and then try the same test, except with the
> > gibberish in the first ()'s and not the second ()'s.
>
> I tried to look at your code, but can't compile because of:
>
> #include <xmlparse.h>
>
> whatever that is.
>
> If you want me to look at this, can you please try and boil it
down to a
> reproducable test case, or failing that mail me a .zip file
privately
> containing everything needed to build the app, plus a text file
containing
> the input that demonstrates the problem. Remember that I'm likely
to be
> building on Win32 not linux: I know next to nothing about
debugging gcc
> built apps, so there's no mileage to be gained by me trying to do
that
> rather than you.
>
> John Maddock
> http://ourworld.compuserve.com/homepages/john_maddock/index.htm


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net