The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

DBIx::MyParse - Perl API for MySQL's SQL Parser

SYNOPSIS

        use DBIx::MyParse;
        my $parser = DBIx::MyParse->new();
        my $query = $parser->parse("SELECT field FROM table");
        print $query->getCommand();

DESCRIPTION

This module provides access to MySQL's SQL parser, which is a full-featured lexx/yacc-based SQL parser, complete with subqueries and various MySQL extensions.

Please check the documentation for DBIx::MyParse::Query to see how you can access the parse tree produced by parse(). The parse tree itself consists of DBIx::MyParse::Item objects.

FEATURES

The following esoteric SQL constructs are supported:

        * Multiple row INSERT
        * INSERT ... SELECT
        * INSERT ... ON DUPLICATE KEY UPDATE
        * Multiple-table DELETE
        * JOINS of any complexity
        * INSERT INTO table SET column = value
        * ?-style placeholders

The following SQL constructs are not currently supported:

        * Subqueries (they are on the top of the ToDo list)
        * LOAD DATA INFILE
        * SELECT INTO OUTFILE

The following MySQL oddities are not supported yet:

        * FORCE INDEX
        * NATURAL RIGHT [OUTER] JOIN
        * MySQL variables
        * DATE_ADD/DATE_SUB and the like
        * expr LIKE pat ESCAPE 'escape-char'

ADVANTAGES AND DISADVANTAGES

ADVANTAGES

This is a full-featured SQL parser, not a set of regular expressions that parsing just the most common queries. It makes use of a complete parsing grammar taken from a real-life database, by virtue of the fact that it uses the MySQL parsing engine to do the dirty work.

This module will accept any input that is a valid MySQL command and will reject any input that is not a valid MySQL command. Accepting an imput is one thing, producing a complete and meaningful parse tree is a different thing, however the module currently produces parse trees of considerable complexity for many common SQL constructs.

MySQL is unlikely to crash on SQL expressions of any complexity, and so is this parser API. In particular, weird functions, complex nested expressions and operator precedence are all handled correctly by definition.

Errors are returned as both error numbers, error codes in English and language-specific long MySQL error messages, rather than as die() or carp().

The module's objects are completely hash-free, which should be considerably faster than a comparable hash-based implementation.

DISADVANTAGES

This module is hooked directly to MySQL's internals. Non-MySQL SQL features are not supported and can not be supported without changing the MySQL source code. Extending MySQL to support new functionality is far more complicated and rewarding than simply adding a few regexps to your home-grown SQL parser.

Some of MySQL's code is not friendly towards being (ab)used in the manner employed by this module. There are object methods declared Private for no obvious reasons.

MySQL is GPL, so this module is GPL, please see the COPYRIGHT section below for more information.

SEE ALSO

Please see the following sources for further information:

MySQL Internals Manual: http://dev.mysql.com/doc/internals/en/index.html

Doxygen documentation for MySQL 4.1 source: http://www.distlab.dk/mysql-4.1/html/

Doxygen documentation for MySQL 5 source: "/leithal.cool-tools.co.uk/sourcedoc/mysql509/html/index.html" in http::

DBIx::MyParse has a page at SourceForge: http://sourceforge.net/projects/myparse/

AUTHOR

Philip Stoev <philip@stoev.org>

COPYRIGHT AND LICENSE

Copyright (C) 2005 by Philip Stoev

This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public Licence

Please note that this module links to libmysqld which is distributed under GPL as well. If you intend to use this module in a commercial product, you are strongly advised to contact MySQL directly to obtain a commercial licence for the MySQL embedded server.

Please see the file named LICENCE for the full text of the GNU General Public Licence