break my regexp?

by "Michael Gerholdt" <gerholdt(at)fredonia.edu>

 Date:  Wed, 1 May 2002 23:29:11 -0400
 To:  "hwg-techniques" <hwg-techniques(at)hwg.org>
  todo: View Thread, Original
Howdy,

I'm trying to create some regexp to do syntax checking on fairly simple SQL
statements.

I believe I've got the first two clauses working, but would appreciate a
more practiced eye or two.

The rules I'm trying to enforce:

alpha characters and underscores only allowed in column and table names (no
spaces etc)

I'm writing this for use in VBScript/ASP where it seems to be testing well
for me.

^Select\s([a-zA-Z_]*(,\s))*[a-zA-Z_]*\sFrom

From\s([a-zA-Z_]*(,\s))*[a-zA-Z_]*\sWhere

The Where clause is going to be a bit more of a pickle. I'm not nearly there
yet  -  have to allow for existence or not of parens, make sure they are
paired properly, booleans, logicals ... Has anyone already done this? Know
where it has been done?

Here's my bare start which doesn't do it by any means. Not all booleans are
there but it's simple addition. I'm more worried about how to ensure that
parens are correct and that it doesn't end in a boolean or logical operator
etc -

Where\s([a-zA-Z_]*\s?((=)|(<>)|(<)|(>)){1}\s?'?[a-zA-Z_]*'?(\s((and)|(or)))?
\s?)*

Thanks for any suggestions
Mike

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA