Rosetta::Utility::SQLParser - Parse ANSI/ISO SQL:2003 and other SQL variants


Rosetta-Utility-SQLParser documentation Contained in the Rosetta-Utility-SQLParser distribution.

Index


Code Index:

NAME

Top

Rosetta::Utility::SQLParser - Parse ANSI/ISO SQL:2003 and other SQL variants

VERSION

Top

This document describes Rosetta::Utility::SQLParser version 0.3.0.

SYNOPSIS

Top

This documentation section will be written later.

DESCRIPTION

Top

This module is a reference implementation of fundamental Rosetta::Model features.

The Rosetta::Utility::SQLParser Perl 5 module is a functional but quickly built Rosetta::Model utility class that converts one or more SQL strings into a set of related Rosetta::Model Nodes that are functionally equivalent, and can be used for a variety of tasks that SQL would normally be used with, but saving the users from having to parse the string SQL themselves. This class will parse multiple string SQL variants; usually it can determine the intent of a SQL string based soley from examining the string itself, but in cases where the string is ambiguous as to what SQL variant it is, this class takes arguments that let you give it hints to resolve the ambiguity; by default it will resolve ambiguities by whatever decision results in something closer to the ANSI/ISO SQL:2003 (or 1999 or 1992) standard.

Rosetta::Utility::SQLParser is designed to implement common functionality for multiple Rosetta Engine classes (such as Rosetta::Engine::Generic) allowing them to focus more on the non-SQL specific aspects of their work. A Rosetta Engine would typically invoke this class when reverse-engineering a database schema where the database returns the schema object descriptors as SQL strings ('create' statements usually) rather than the information being in an "information schema". This class can also be used by code on the application-side of a Rosetta::Interface tree (such as Rosetta::Emulator::DBI); for example, a module that emulates an older database interface which wants to accept database commands as SQL strings can use this module to parse those. (For your reference, see also the Rosetta::Utility::SQLBuilder module, which implements the inverse functionality to SQLParser, and is used in both of the same places.)

CAVEAT: SIGNIFICANT PORTIONS OF THIS MODULE ARE NOT WRITTEN YET.

CONSTRUCTOR FUNCTIONS

Top

This function is stateless and can be invoked off of either this module's name or an existing module object, with the same result.

new()

    my $parser = Rosetta::Utility::SQLParser->new();
    my $parser2 = $parser->new();

This "getter" function/method will create and return a single Rosetta::Utility::SQLParser (or subclass) object. All of this object's properties are set to default values that should cause the object to resolve SQL parsing ambiguities in a manner leaning towards the SQL:2003 standard.

DEPENDENCIES

Top

This module requires any version of Perl 5.x.y that is at least 5.8.1.

It also requires the Perl modules version and only, which would conceptually be built-in to Perl, but aren't, so they are on CPAN instead.

It also requires these modules that are on CPAN: Locale::KeyedText '1.6.0-' (for error messages), Rosetta::Model '0.71.0-'.

INCOMPATIBILITIES

Top

None reported.

SEE ALSO

Top

perl(1), Rosetta::Utility::SQLParser::L::en, Locale::KeyedText, Rosetta::Model, Rosetta::Utility::SQLBuilder, Rosetta::Engine::Generic, Rosetta::Emulator::DBI, DBIx::MyParse.

BUGS AND LIMITATIONS

Top

This module is currently in pre-alpha development status, meaning that some parts of it will be changed in the near future, perhaps in incompatible ways.

AUTHOR

Top

Darren R. Duncan (perl@DarrenDuncan.net)

LICENCE AND COPYRIGHT

Top


Rosetta-Utility-SQLParser documentation Contained in the Rosetta-Utility-SQLParser distribution.

#!perl
use 5.008001; use utf8; use strict; use warnings;

use only 'Locale::KeyedText' => '1.6.0-';
use only 'Rosetta::Model' => '0.71.0-';

package Rosetta::Utility::SQLParser;
use version; our $VERSION = qv('0.3.0');

######################################################################
######################################################################

# These are constant values used by this module.
my $EMPTY_STR = q{};

######################################################################

sub new {
    my ($class) = @_;
    my $parser = bless {}, ref $class || $class;



    return $parser;
}

######################################################################
# This is a 'protected' method; only sub-classes should invoke it.

sub _throw_error_message {
    my ($parser, $msg_key, $msg_vars) = @_;
    # Throws an exception consisting of an object.
    ref $msg_vars eq 'HASH' or $msg_vars = {};
    for my $var_key (keys %{$msg_vars}) {
        if (ref $msg_vars->{$var_key} eq 'ARRAY') {
            $msg_vars->{$var_key} = 'PERL_ARRAY:[' . (join q{,},map {$_||$EMPTY_STR} @{$msg_vars->{$var_key}}) . ']';
        }
    }
    die Locale::KeyedText->new_message( $msg_key, $msg_vars );
}

sub _assert_arg_node_type {
    my ($parser, $meth_name, $arg_name, $exp_node_types, $arg_value) = @_;
    $parser->_throw_error_message( 'ROS_U_SP_METH_ARG_UNDEF',
        { 'METH' => $meth_name, 'ARGNM' => $arg_name } )
        if !defined $arg_value;
    $parser->_throw_error_message( 'ROS_U_SP_METH_ARG_NO_NODE',
        { 'METH' => $meth_name, 'ARGNM' => $arg_name, 'ARGVL' => $arg_value } )
        if !ref $arg_value or !UNIVERSAL::isa( $arg_value, 'Rosetta::Model::Node' );
    return
        if @{$exp_node_types} == 0; # any Node type is acceptable
    my $given_node_type = $arg_value->get_node_type();
    $parser->_throw_error_message( 'ROS_U_SP_METH_ARG_WRONG_NODE_TYPE',
        { 'METH' => $meth_name, 'ARGNM' => $arg_name,
        'EXPNTYPE' => $exp_node_types, 'ARGNTYPE' => $given_node_type } )
        if !grep { $given_node_type eq $_ } @{$exp_node_types};
    # If we get here, $arg_value is acceptable to the method.
}

######################################################################
######################################################################

1;
__END__