1 package SQL::Translator::Parser::Sybase;
3 # -------------------------------------------------------------------
4 # $Id: Sybase.pm,v 1.3 2002-11-22 03:03:40 kycl4rk Exp $
5 # -------------------------------------------------------------------
6 # Copyright (C) 2002 Ken Y. Clark <kclark@cpan.org>,
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 # -------------------------------------------------------------------
26 SQL::Translator::Parser::Sybase - parser for Sybase
30 use SQL::Translator::Parser::Sybase;
34 Parses the output of "dbschema.pl," a Perl script freely available from
43 file : statement(s) { \%tables }
44 # { print "statements: ", join("\n", @{$item[1]}), "\n" }
50 # print "statement: ", join("\n", @{$item[1]}), "\n";
51 # $return = @{$item[1]};
52 # print "statement: '", $item[1], "'\n";
70 # { print "GO: ", $item[1], "\n" }
73 # { print "USE: ", $item[2], "\n" }
75 setuser : /setuser/i /.*/
76 # { print "SETUSER: ", $item[2], "\n" }
79 # { print "IF: ", $item[2], "\n" }
81 print : /\s*/ /print/i /.*/
82 # { print "PRINT: ", $item[3], "\n" }
85 # { print "ELSE: ", $item[2], "\n" }
94 # { print "GRANT: ", $item[2], "\n" }
97 # { print "EXEC: ", $item[2], "\n" }
99 comment : /^\s*\/\*.*\*\//m
100 # { print "COMMENT: ", $item[-1], "\n" }
102 create : create_table table_name '(' field(s /,/) ')' lock(?)
104 # print "TABLE $item[2]: ",
105 # join(', ', map{$_->{'name'}}@{$item[4]}), "\n";
107 for my $line ( @{ $item[4] } ) {
108 if ( $line->{'type'} eq 'field' ) {
109 my $field_name = $line->{'name'};
110 $tables{ $item{'table_name'} }
111 {'fields'}{$field_name} =
112 { %$line, order => $i };
115 if ( $line->{'is_primary_key'} ) {
117 @{ $tables{ $item{'table_name'} }{'indices'} },
119 type => 'primary_key',
120 fields => [ $field_name ],
125 push @{ $tables{ $item{'table_name'} }{'indices'} },
128 $tables{ $item{'table_name'} }{'type'} =
129 $item{'table_type'}[0];
136 field : field_name data_type null(?)
140 name => $item{'field_name'},
141 data_type => $item{'data_type'}{'type'},
142 size => $item{'data_type'}{'size'},
143 null => $item{'null'}[0],
144 # default => $item{'default_val'}[0],
145 # is_auto_inc => $item{'auto_inc'}[0],
146 # is_primary_key => $item{'primary_key'}[0],
151 index : primary_key_index
155 table_name : WORD '.' WORD
156 { $return = $item[3] }
162 data_type : WORD field_size(?)
170 lock : /lock/i /datarows/i
174 field_size : '(' num_range ')' { $item{'num_range'} }
176 num_range : DIGITS ',' DIGITS
177 { $return = $item[1].','.$item[3] }
179 { $return = $item[1] }
182 create_table : /create/i /table/i
184 null : /not/i /null/i
189 default_val : /default/i /(?:')?[\w\d.-]*(?:')?/ { $item[2]=~s/'//g; $return=$item[2] }
191 auto_inc : /auto_increment/i { 1 }
193 primary_key : /primary/i /key/i { 1 }
195 primary_key_index : primary_key index_name(?) '(' field_name(s /,/) ')'
198 name => $item{'index_name'}[0],
199 type => 'primary_key',
204 normal_index : key index_name(?) '(' field_name(s /,/) ')'
207 name => $item{'index_name'}[0],
213 unique_index : /unique/i key index_name(?) '(' field_name(s /,/) ')'
216 name => $item{'index_name'}[0],
225 table_type : /TYPE=/i /\w+/ { $item[2] }
237 #-----------------------------------------------------
238 # Every hero becomes a bore at last.
239 # Ralph Waldo Emerson
240 #-----------------------------------------------------
246 Ken Y. Clark E<lt>kclark@cpan.orgE<gt>