Philip Stoev > DBIx-MyParsePP-0.50 > DBIx::MyParsePP

Download:
DBIx-MyParsePP-0.50.tar.gz

Dependencies

Annotate this POD

Related Modules

Parse::RecDescent
SQL::Statement
more...
By perlmonks.org

CPAN RT

New  2
Open  0
View/Report Bugs
Module Version: 0.50   Source  

NAME ^

DBIx::MyParsePP - Pure-perl SQL parser based on MySQL grammar and lexer

SYNOPSIS ^

  use DBIx::MyParsePP;
  use Data::Dumper;

  my $parser = DBIx::MyParsePP->new();

  my $query = $parser->parse("SELECT 1");

  print Dumper $query;
  print $query->toString();

DESCRIPTION ^

DBIx::MyParsePP is a pure-perl SQL parser that implements the MySQL grammar and lexer. The grammar was automatically converted from the original sql_yacc.yy file by removing all the C code. The lexer comes from sql_lex.cc, completely translated in Perl almost verbatim.

The grammar is converted into Perl form using Parse::Yapp.

CONSTRUCTOR ^

charset, version, sql_mode, client_capabilities and stmt_prepare_mode can be passed as arguments to the constructor. Please use DBIx::MyParsePP::Lexer to bring in the required constants and see DBIx::MyParsePP::Lexer for information.

METHODS ^

DBIx::MyParsePP provides parse() which takes the string to be parsed. The result is a DBIx::MyParsePP::Query object which contains the result from the parsing.

Queries can be reconstructed back into SQL by calling the toString() method.

SPECIAL CONSIDERATIONS ^

The file containing the grammar lib/DBIx/MyParsePP/Parser.pm is about 5 megabytes in size and takes a while to load. Compex statements take a while to parse, e.g. the first Twins query from the MySQL manual can only be parsed at a speed of few queries per second per 1GHz of CPU. If you require a full-speed parsing solution, please take a look at DBIx::MyParse, which requires a GCC compiler and produces more concise parse trees.

The parse trees produced by DBIx::MyParsePP contain one leaf for every grammar rule that has been matched, even rules that serve no useful purpose. Therefore, parsing event simple statements such as SELECT 1 produce trees dozens of levels deep. Please exercise caution when walking those trees recursively. The DBIx::MyParsePP::Rule module contains the extract() and shrink() methods which are useful for dealing with the inherent complexity of the MySQL grammar.

USING GRAMMARS FROM OTHER MYSQL VERSIONS ^

The package by default parses strings using the grammar from MySQL version 5.0.45. If you wish to use the grammar from a different version, you can use the bin/myconvpp.pl script to prepare the grammar:

        $ perl bin/myconvpp.pl --

SEE ALSO ^

For Yacc grammars, please see the Bison manual at:

        http://www.gnu.org/software/bison

For generating Yacc parsers in Perl, please see:

        http://search.cpan.org/~fdesar

For a full-speed C++-based parser that generates nicer parse trees, please see DBIx::MyParse

AUTHOR ^

Philip Stoev, <philip@stoev.org>

COPYRIGHT AND LICENSE ^

Copyright (C) 2007 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 as specified in the README and LICENCE files.

Please note that this module contains code copyright by MySQL AB released under the GNU General Public Licence, and not the GNU Lesser General Public Licence. Using this code for commercial purposes may require purchasing a licence from MySQL AB.

The Parse::Yapp module and its related modules and shell scripts are copyright (c) 1998-2001 Francois Desarmenien, France. All rights reserved.

syntax highlighting: