X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FParser.pm;h=7dc3d37e9aa57c52d2def87c8319f7c49d182f49;hb=935800450f88b0500c4fa7c3b174cd22b5f9eb56;hp=66bdb17ad7756ddf9645cedc89bbac061ce473ff;hpb=9a7841ddb10b27d35ad58eecb5f413e8bdaa907f;p=dbsrgits%2FSQL-Translator.git diff --git a/lib/SQL/Translator/Parser.pm b/lib/SQL/Translator/Parser.pm index 66bdb17..7dc3d37 100644 --- a/lib/SQL/Translator/Parser.pm +++ b/lib/SQL/Translator/Parser.pm @@ -1,43 +1,23 @@ package SQL::Translator::Parser; -# ---------------------------------------------------------------------- -# $Id: Parser.pm,v 1.2 2002-03-21 18:50:53 dlc Exp $ -# ---------------------------------------------------------------------- -# Copyright (C) 2002 Ken Y. Clark , -# darren chamberlain -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; version 2. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -# 02111-1307 USA -# ---------------------------------------------------------------------- - use strict; use vars qw( $VERSION ); -$VERSION = sprintf "%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/; +$VERSION = '1.60'; sub parse { "" } 1; -#----------------------------------------------------- +# ---------------------------------------------------------------------- # Enough! or Too much. # William Blake -#----------------------------------------------------- -__END__ +# ---------------------------------------------------------------------- + +=pod =head1 NAME -SQL::Translator::Parser - base object for parsers +SQL::Translator::Parser - describes how to write a parser =head1 DESCRIPTION @@ -48,127 +28,25 @@ $tr is a SQL::Translator instance. Other than that, the classes are free to define any helper functions, or use any design pattern internally that make the most sense. -=head1 FORMAT OF THE DATA STRUCTURE - -The data structure returned from the B function has a very -particular format. - -=over 4 - -=item o - -The data structure should be a reference to a hash, the keys of which -are table names. - -=item o - -The values associated with each table should also be a reference to a -hash. This hash should have several keys, enumerated below. - -=back - -=over 15 - -=item B - -This is the type of the table, if applicable, as a string, or undef if not (for -example, if the database does not have multiple options). For MySQL, -this value might include MyISAM, HEAP, or similar. - -=item B - -The indeces keys is a reference to an array of hashrefs. Each hashref -defines one index, and has the keys 'name' (if defined, it will be a -string), 'type' (a string), and 'fields' (a reference to another -array). For example, a table in a MySQL database with two indexes, -created as: - - PRIMARY KEY (id), - KEY foo_idx (foo), - KEY foo_bar_idx (foo, bar), - -would be described in the indeces element as: - - [ - { - 'type' => 'primary_key', - 'fields' => [ - 'id' - ], - 'name' => undef, - }, - { - 'type' => 'normal', - 'fields' => [ - 'foo' - ], - 'name' => 'foo_idx', - }, - { - 'type' => 'normal', - 'fields' => [ - 'foo', - 'bar', - ], - 'name' => 'foo_bar_idx', - }, - ] - -=item B - -The fields element is a refernce to a hash; the keys of this hash are -the row names from the table, and each value fills in this template: - - { - type => 'field', - name => '', # same as the key - data_type => '', # in the db's jargon, - # i.e., MySQL => int, Oracale => INTEGER - size => '', # int - null => 1 | 0, # boolean - default => '', - is_auto_inc => 1 1 0, # boolean - is_primary_key => 1 | 0, # boolean - } - -So a row defined as: - - username CHAR(8) NOT NULL DEFAULT 'nobody', - KEY username_idx (username) - -would be represented as: - - 'fields => { - 'username' => { - type => 'field', - name => 'username', - data_type => 'char', - size => '8', - null => undef, - default => 'nobody', - is_auto_inc => undef, - is_primary_key => undef, - }, - }, - 'indeces' => [ - { - 'name' => 'username_idx', - 'fields' => [ - 'username' - ], - 'type' => 'normal', - }, - ], - -=back +When the parser has determined what exists, it will communicate the +structure to the producer through the SQL::Translator::Schema object. +This object can be retrieved from the translator (the first argument +pass to B) by calling the B method: + + my $schema = $tr->schema; +The Schema object has methods for adding tables, fields, indices, etc. +For more information, consult the docs for SQL::Translator::Schema and +its related modules. For examples of how this works, examine the +source code for existing SQL::Translator::Parser::* modules. =head1 AUTHORS -Ken Y. Clark, Ekclark@logsoft.comE, darren chamberlain Edarren@cpan.orgE +Ken Youens-Clark, Ekclark@cpan.org, +darren chamberlain Edarren@cpan.orgE. =head1 SEE ALSO -perl(1). +perl(1), SQL::Translator, SQL::Translator::Schema. =cut