1 package SQL::Translator::Parser::Sybase;
3 # -------------------------------------------------------------------
4 # $Id: Sybase.pm,v 1.4 2003-01-27 17:04:46 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 # -------------------------------------------------------------------
27 SQL::Translator::Parser::Sybase - parser for Sybase
31 use SQL::Translator::Parser::Sybase;
35 Parses the output of "dbschema.pl," a Perl script freely available from
44 file : statement(s) { \%tables }
45 # { print "statements: ", join("\n", @{$item[1]}), "\n" }
51 # print "statement: ", join("\n", @{$item[1]}), "\n";
52 # $return = @{$item[1]};
53 # print "statement: '", $item[1], "'\n";
71 # { print "GO: ", $item[1], "\n" }
74 # { print "USE: ", $item[2], "\n" }
76 setuser : /setuser/i /.*/
77 # { print "SETUSER: ", $item[2], "\n" }
80 # { print "IF: ", $item[2], "\n" }
82 print : /\s*/ /print/i /.*/
83 # { print "PRINT: ", $item[3], "\n" }
86 # { print "ELSE: ", $item[2], "\n" }
95 # { print "GRANT: ", $item[2], "\n" }
98 # { print "EXEC: ", $item[2], "\n" }
100 comment : /^\s*\/\*.*\*\//m
101 # { print "COMMENT: ", $item[-1], "\n" }
103 create : create_table table_name '(' field(s /,/) ')' lock(?)
105 # print "TABLE $item[2]: ",
106 # join(', ', map{$_->{'name'}}@{$item[4]}), "\n";
108 for my $line ( @{ $item[4] } ) {
109 if ( $line->{'type'} eq 'field' ) {
110 my $field_name = $line->{'name'};
111 $tables{ $item{'table_name'} }
112 {'fields'}{$field_name} =
113 { %$line, order => $i };
116 if ( $line->{'is_primary_key'} ) {
118 @{ $tables{ $item{'table_name'} }{'indices'} },
120 type => 'primary_key',
121 fields => [ $field_name ],
126 push @{ $tables{ $item{'table_name'} }{'indices'} },
129 $tables{ $item{'table_name'} }{'type'} =
130 $item{'table_type'}[0];
137 field : field_name data_type null(?)
141 name => $item{'field_name'},
142 data_type => $item{'data_type'}{'type'},
143 size => $item{'data_type'}{'size'},
144 null => $item{'null'}[0],
145 # default => $item{'default_val'}[0],
146 # is_auto_inc => $item{'auto_inc'}[0],
147 # is_primary_key => $item{'primary_key'}[0],
152 index : primary_key_index
156 table_name : WORD '.' WORD
157 { $return = $item[3] }
163 data_type : WORD field_size(?)
171 lock : /lock/i /datarows/i
175 field_size : '(' num_range ')' { $item{'num_range'} }
177 num_range : DIGITS ',' DIGITS
178 { $return = $item[1].','.$item[3] }
180 { $return = $item[1] }
183 create_table : /create/i /table/i
185 null : /not/i /null/i
190 default_val : /default/i /(?:')?[\w\d.-]*(?:')?/ { $item[2]=~s/'//g; $return=$item[2] }
192 auto_inc : /auto_increment/i { 1 }
194 primary_key : /primary/i /key/i { 1 }
196 primary_key_index : primary_key index_name(?) '(' field_name(s /,/) ')'
199 name => $item{'index_name'}[0],
200 type => 'primary_key',
205 normal_index : key index_name(?) '(' field_name(s /,/) ')'
208 name => $item{'index_name'}[0],
214 unique_index : /unique/i key index_name(?) '(' field_name(s /,/) ')'
217 name => $item{'index_name'}[0],
226 table_type : /TYPE=/i /\w+/ { $item[2] }
238 #-----------------------------------------------------
239 # Every hero becomes a bore at last.
240 # Ralph Waldo Emerson
241 #-----------------------------------------------------
247 Ken Y. Clark E<lt>kclark@cpan.orgE<gt>