Hi Jochen,
Tthere's one on the phpmyadmin code that may help you.
http://phpmyadmin.svn.sourceforge.net/viewvc/phpmyadmin/trunk/phpMyAdmin/libraries/sqlparser.lib.php?view=markup
<http://phpmyadmin.svn.sourceforge.net/viewvc/phpmyadmin/trunk/phpMyAdmin/libraries/sqlparser.lib.php?view=markup>
http://phpmyadmin.svn.sourceforge.net/viewvc/phpmyadmin/trunk/phpMyAdmin/libraries/sqlparser.data.php?revision=11986&view=markup
<http://phpmyadmin.svn.sourceforge.net/viewvc/phpmyadmin/trunk/phpMyAdmin/libraries/sqlparser.data.php?revision=11986&view=markup>
- Mike
On 10/02/2009 09:46, Jochen Daum wrote:
> Hi,
>
> does anybody here know or has used a regular expression to tokenise a
> Mysql query? What I'm looking at is getting the parts of the query in
> an array of matches, i.e. the 'select ...' part, the 'from ...' part etc.
>
> I got this one for now, but it has some shortfalls:
>
> $found = preg_match
> ('/^(\s?(SELECT|select)(.*?)\s(FROM|from)\s([^\s]+)(\s+((AS|as)\s+)?([^\s]+))?(\s+?(JOIN|join|LEFT|left|NATURAL|natural|RIGHT|right|INNER|inner).*?)?)(\s+(WHERE|where)\s(.+?))?(\s+(GROUP
>
> BY|group by)\s.+?)?(\s+(ORDER BY|order
> by)\s(.+?))?(\s+(LIMIT|limit)\s.*)?$/sm', $sql, $matches);
>
> - would be great to have all joins in a separate array, this probably
> needs to be done in a second step
> - doesn't handle table names with spaces, ie. `table name`
>
>
> Any other issues anyone can see? Any regex or libraries that you've used?
>
> Kind Regards,
>
> Jochen
>
> >
--
Mike Cochrane
Web Team Leader
gardyneHOLT - design partners
18 Beresford Square Newton
PO Box 3340 Auckland New Zealand
p +64 9 300 3155 f +64 9 302 3349 m 021 545 565
skype gardyneholt_mikec
www.gardyneholt.co.nz
DISCLAIMER: This electronic message, together with any attachments, was
created solely for the use of the intended recipient(s), and may be
confidential. Views expressed may be those of the individual sender and are not
necessarily endorsed by gardyneHOLT. If you are not the intended recipient,
please advise us by return e-mail that you have received the message in error
and then delete it. Do not copy, disclose or use the contents in any way.
--~--~---------~--~----~------------~-------~--~----~
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[email protected]
-~----------~----~----~----~------~----~------~--~---