1 package SQL::Translator::Parser;
3 # ----------------------------------------------------------------------
4 # $Id: Parser.pm,v 1.5 2002-11-22 03:03:40 kycl4rk Exp $
5 # ----------------------------------------------------------------------
6 # Copyright (C) 2002 Ken Y. Clark <kclark@cpan.org>,
7 # darren chamberlain <darren@cpan.org>
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation; version 2.
13 # This program is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 # ----------------------------------------------------------------------
25 use vars qw( $VERSION );
26 $VERSION = sprintf "%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/;
32 # ----------------------------------------------------------------------
33 # Enough! or Too much.
35 # ----------------------------------------------------------------------
41 SQL::Translator::Parser - base object for parsers
45 Parser modules that get invoked by SQL::Translator need to implement a
46 single function: B<parse>. This function will be called by the
47 SQL::Translator instance as $class::parse($tr, $data_as_string), where
48 $tr is a SQL::Translator instance. Other than that, the classes are
49 free to define any helper functions, or use any design pattern
50 internally that make the most sense.
52 =head1 FORMAT OF THE DATA STRUCTURE
54 The data structure returned from the B<parse> function has a very
61 The data structure should be a reference to a hash, the keys of which
66 The values associated with each table should also be a reference to a
67 hash. This hash should have several keys, enumerated below.
75 This is the type of the table, if applicable, as a string, or undef if not (for
76 example, if the database does not have multiple options). For MySQL,
77 this value might include MyISAM, HEAP, or similar.
81 The indices keys is a reference to an array of hashrefs. Each hashref
82 defines one index, and has the keys 'name' (if defined, it will be a
83 string), 'type' (a string), and 'fields' (a reference to another
84 array). For example, a table in a MySQL database with two indexes,
89 KEY foo_bar_idx (foo, bar),
91 would be described in the indices element as:
95 'type' => 'primary_key',
114 'name' => 'foo_bar_idx',
120 The fields element is a refernce to a hash; the keys of this hash are
121 the row names from the table, and each value fills in this template:
125 order => 1, # the order in the original table
126 name => '', # same as the key
127 data_type => '', # in the db's jargon,
128 # i.e., MySQL => int, Oracale => INTEGER
130 null => 1 | 0, # boolean
132 is_auto_inc => 1 1 0, # boolean
133 is_primary_key => 1 | 0, # boolean
138 username CHAR(8) NOT NULL DEFAULT 'nobody',
139 KEY username_idx (username)
141 would be represented as:
152 is_auto_inc => undef,
153 is_primary_key => undef,
158 'name' => 'username_idx',
171 Ken Y. Clark, E<lt>kclark@cpan.org<gt>,
172 darren chamberlain E<lt>darren@cpan.orgE<gt>.