Commit | Line | Data |
16dc9970 |
1 | package SQL::Translator::Parser; |
2 | |
077ebf34 |
3 | # ---------------------------------------------------------------------- |
948190b3 |
4 | # $Id: Parser.pm,v 1.3 2002-03-25 14:25:58 dlc Exp $ |
077ebf34 |
5 | # ---------------------------------------------------------------------- |
6 | # Copyright (C) 2002 Ken Y. Clark <kycl4rk@users.sourceforge.net>, |
7 | # darren chamberlain <darren@cpan.org> |
16dc9970 |
8 | # |
077ebf34 |
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. |
12 | # |
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. |
17 | # |
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 |
21 | # 02111-1307 USA |
22 | # ---------------------------------------------------------------------- |
16dc9970 |
23 | |
24 | use strict; |
25 | use vars qw( $VERSION ); |
948190b3 |
26 | $VERSION = sprintf "%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/; |
16dc9970 |
27 | |
077ebf34 |
28 | sub parse { "" } |
16dc9970 |
29 | |
30 | 1; |
31 | |
32 | #----------------------------------------------------- |
33 | # Enough! or Too much. |
34 | # William Blake |
35 | #----------------------------------------------------- |
8295a8cc |
36 | __END__ |
16dc9970 |
37 | |
38 | =head1 NAME |
39 | |
40 | SQL::Translator::Parser - base object for parsers |
41 | |
16dc9970 |
42 | =head1 DESCRIPTION |
43 | |
8295a8cc |
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. |
16dc9970 |
50 | |
8295a8cc |
51 | =head1 FORMAT OF THE DATA STRUCTURE |
16dc9970 |
52 | |
8295a8cc |
53 | The data structure returned from the B<parse> function has a very |
54 | particular format. |
55 | |
56 | =over 4 |
57 | |
58 | =item o |
59 | |
60 | The data structure should be a reference to a hash, the keys of which |
61 | are table names. |
62 | |
63 | =item o |
64 | |
65 | The values associated with each table should also be a reference to a |
66 | hash. This hash should have several keys, enumerated below. |
67 | |
68 | =back |
69 | |
70 | =over 15 |
71 | |
72 | =item B<type> |
73 | |
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. |
77 | |
78 | =item B<indeces> |
79 | |
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, |
84 | created as: |
85 | |
86 | PRIMARY KEY (id), |
87 | KEY foo_idx (foo), |
88 | KEY foo_bar_idx (foo, bar), |
89 | |
90 | would be described in the indeces element as: |
91 | |
92 | [ |
93 | { |
94 | 'type' => 'primary_key', |
95 | 'fields' => [ |
96 | 'id' |
97 | ], |
98 | 'name' => undef, |
99 | }, |
100 | { |
101 | 'type' => 'normal', |
102 | 'fields' => [ |
103 | 'foo' |
104 | ], |
105 | 'name' => 'foo_idx', |
106 | }, |
107 | { |
108 | 'type' => 'normal', |
109 | 'fields' => [ |
110 | 'foo', |
111 | 'bar', |
112 | ], |
113 | 'name' => 'foo_bar_idx', |
114 | }, |
115 | ] |
116 | |
117 | =item B<fields> |
118 | |
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: |
121 | |
122 | { |
123 | type => 'field', |
948190b3 |
124 | order => 1, # the order in the original table |
8295a8cc |
125 | name => '', # same as the key |
126 | data_type => '', # in the db's jargon, |
127 | # i.e., MySQL => int, Oracale => INTEGER |
128 | size => '', # int |
129 | null => 1 | 0, # boolean |
130 | default => '', |
131 | is_auto_inc => 1 1 0, # boolean |
132 | is_primary_key => 1 | 0, # boolean |
133 | } |
134 | |
135 | So a row defined as: |
136 | |
137 | username CHAR(8) NOT NULL DEFAULT 'nobody', |
138 | KEY username_idx (username) |
139 | |
140 | would be represented as: |
141 | |
142 | 'fields => { |
143 | 'username' => { |
144 | type => 'field', |
948190b3 |
145 | order => 1, |
8295a8cc |
146 | name => 'username', |
147 | data_type => 'char', |
148 | size => '8', |
149 | null => undef, |
150 | default => 'nobody', |
151 | is_auto_inc => undef, |
152 | is_primary_key => undef, |
153 | }, |
154 | }, |
155 | 'indeces' => [ |
156 | { |
157 | 'name' => 'username_idx', |
158 | 'fields' => [ |
159 | 'username' |
160 | ], |
161 | 'type' => 'normal', |
162 | }, |
163 | ], |
164 | |
165 | =back |
166 | |
167 | |
168 | =head1 AUTHORS |
169 | |
170 | Ken Y. Clark, E<lt>kclark@logsoft.comE<gt>, darren chamberlain E<lt>darren@cpan.orgE<gt> |
16dc9970 |
171 | |
172 | =head1 SEE ALSO |
173 | |
174 | perl(1). |
175 | |
176 | =cut |