1 package SQL::Translator::Parser;
3 # ----------------------------------------------------------------------
4 # $Id: Parser.pm,v 1.3 2002-03-25 14:25:58 dlc Exp $
5 # ----------------------------------------------------------------------
6 # Copyright (C) 2002 Ken Y. Clark <kycl4rk@users.sourceforge.net>,
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.3 $ =~ /(\d+)\.(\d+)/;
32 #-----------------------------------------------------
33 # Enough! or Too much.
35 #-----------------------------------------------------
40 SQL::Translator::Parser - base object for parsers
44 Parser modules that get invoked by SQL::Translator need to implement a
45 single function: B<parse>. This function will be called by the
46 SQL::Translator instance as $class::parse($tr, $data_as_string), where
47 $tr is a SQL::Translator instance. Other than that, the classes are
48 free to define any helper functions, or use any design pattern
49 internally that make the most sense.
51 =head1 FORMAT OF THE DATA STRUCTURE
53 The data structure returned from the B<parse> function has a very
60 The data structure should be a reference to a hash, the keys of which
65 The values associated with each table should also be a reference to a
66 hash. This hash should have several keys, enumerated below.
74 This is the type of the table, if applicable, as a string, or undef if not (for
75 example, if the database does not have multiple options). For MySQL,
76 this value might include MyISAM, HEAP, or similar.
80 The indeces keys is a reference to an array of hashrefs. Each hashref
81 defines one index, and has the keys 'name' (if defined, it will be a
82 string), 'type' (a string), and 'fields' (a reference to another
83 array). For example, a table in a MySQL database with two indexes,
88 KEY foo_bar_idx (foo, bar),
90 would be described in the indeces element as:
94 'type' => 'primary_key',
113 'name' => 'foo_bar_idx',
119 The fields element is a refernce to a hash; the keys of this hash are
120 the row names from the table, and each value fills in this template:
124 order => 1, # the order in the original table
125 name => '', # same as the key
126 data_type => '', # in the db's jargon,
127 # i.e., MySQL => int, Oracale => INTEGER
129 null => 1 | 0, # boolean
131 is_auto_inc => 1 1 0, # boolean
132 is_primary_key => 1 | 0, # boolean
137 username CHAR(8) NOT NULL DEFAULT 'nobody',
138 KEY username_idx (username)
140 would be represented as:
151 is_auto_inc => undef,
152 is_primary_key => undef,
157 'name' => 'username_idx',
170 Ken Y. Clark, E<lt>kclark@logsoft.comE<gt>, darren chamberlain E<lt>darren@cpan.orgE<gt>