Adding it back and making it an alias to XML::SQLFairy.
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Parser.pm
CommitLineData
16dc9970 1package SQL::Translator::Parser;
2
077ebf34 3# ----------------------------------------------------------------------
abfa405a 4# $Id: Parser.pm,v 1.6 2003-01-27 17:04:44 dlc Exp $
077ebf34 5# ----------------------------------------------------------------------
abfa405a 6# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
7# darren chamberlain <darren@cpan.org>,
8# Chris Mungall <cjm@fruitfly.org>
16dc9970 9#
077ebf34 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.
13#
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.
18#
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
22# 02111-1307 USA
23# ----------------------------------------------------------------------
16dc9970 24
25use strict;
26use vars qw( $VERSION );
abfa405a 27$VERSION = sprintf "%d.%02d", q$Revision: 1.6 $ =~ /(\d+)\.(\d+)/;
16dc9970 28
077ebf34 29sub parse { "" }
16dc9970 30
311;
32
49e1eb70 33# ----------------------------------------------------------------------
16dc9970 34# Enough! or Too much.
35# William Blake
49e1eb70 36# ----------------------------------------------------------------------
37
38=pod
16dc9970 39
40=head1 NAME
41
42SQL::Translator::Parser - base object for parsers
43
16dc9970 44=head1 DESCRIPTION
45
8295a8cc 46Parser modules that get invoked by SQL::Translator need to implement a
47single function: B<parse>. This function will be called by the
48SQL::Translator instance as $class::parse($tr, $data_as_string), where
49$tr is a SQL::Translator instance. Other than that, the classes are
50free to define any helper functions, or use any design pattern
51internally that make the most sense.
16dc9970 52
8295a8cc 53=head1 FORMAT OF THE DATA STRUCTURE
16dc9970 54
8295a8cc 55The data structure returned from the B<parse> function has a very
56particular format.
57
58=over 4
59
60=item o
61
62The data structure should be a reference to a hash, the keys of which
63are table names.
64
65=item o
66
67The values associated with each table should also be a reference to a
68hash. This hash should have several keys, enumerated below.
69
70=back
71
72=over 15
73
74=item B<type>
75
76This is the type of the table, if applicable, as a string, or undef if not (for
77example, if the database does not have multiple options). For MySQL,
78this value might include MyISAM, HEAP, or similar.
79
49e1eb70 80=item B<indices>
8295a8cc 81
49e1eb70 82The indices keys is a reference to an array of hashrefs. Each hashref
8295a8cc 83defines one index, and has the keys 'name' (if defined, it will be a
84string), 'type' (a string), and 'fields' (a reference to another
85array). For example, a table in a MySQL database with two indexes,
86created as:
87
88 PRIMARY KEY (id),
89 KEY foo_idx (foo),
90 KEY foo_bar_idx (foo, bar),
91
49e1eb70 92would be described in the indices element as:
8295a8cc 93
94 [
95 {
96 'type' => 'primary_key',
97 'fields' => [
98 'id'
99 ],
100 'name' => undef,
101 },
102 {
103 'type' => 'normal',
104 'fields' => [
105 'foo'
106 ],
107 'name' => 'foo_idx',
108 },
109 {
110 'type' => 'normal',
111 'fields' => [
112 'foo',
113 'bar',
114 ],
115 'name' => 'foo_bar_idx',
116 },
117 ]
118
119=item B<fields>
120
121The fields element is a refernce to a hash; the keys of this hash are
122the row names from the table, and each value fills in this template:
123
124 {
125 type => 'field',
948190b3 126 order => 1, # the order in the original table
8295a8cc 127 name => '', # same as the key
128 data_type => '', # in the db's jargon,
129 # i.e., MySQL => int, Oracale => INTEGER
130 size => '', # int
131 null => 1 | 0, # boolean
132 default => '',
133 is_auto_inc => 1 1 0, # boolean
134 is_primary_key => 1 | 0, # boolean
135 }
136
137So a row defined as:
138
139 username CHAR(8) NOT NULL DEFAULT 'nobody',
140 KEY username_idx (username)
141
142would be represented as:
143
144 'fields => {
145 'username' => {
146 type => 'field',
948190b3 147 order => 1,
8295a8cc 148 name => 'username',
149 data_type => 'char',
150 size => '8',
151 null => undef,
152 default => 'nobody',
153 is_auto_inc => undef,
154 is_primary_key => undef,
155 },
156 },
49e1eb70 157 'indices' => [
8295a8cc 158 {
159 'name' => 'username_idx',
160 'fields' => [
161 'username'
162 ],
163 'type' => 'normal',
164 },
165 ],
166
167=back
168
169
170=head1 AUTHORS
171
d529894e 172Ken Y. Clark, E<lt>kclark@cpan.org<gt>,
49e1eb70 173darren chamberlain E<lt>darren@cpan.orgE<gt>.
16dc9970 174
175=head1 SEE ALSO
176
177perl(1).
178
179=cut