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