package SQL::Translator::Parser::Oracle;
# -------------------------------------------------------------------
-# $Id: Oracle.pm,v 1.21 2005-08-10 15:17:48 duality72 Exp $
+# $Id: Oracle.pm,v 1.26 2006-06-29 19:24:14 kycl4rk Exp $
# -------------------------------------------------------------------
# Copyright (C) 2002-4 SQLFairy Authors
#
use strict;
use vars qw[ $DEBUG $VERSION $GRAMMAR @EXPORT_OK ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.21 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.26 $ =~ /(\d+)\.(\d+)/;
$DEBUG = 0 unless defined $DEBUG;
use Data::Dumper;
$::RD_WARN = 1; # Enable warnings. This will warn on unused rules &c.
$::RD_HINT = 1; # Give out hints to help fix problems.
-my $parser;
-
$GRAMMAR = q`
{ my ( %tables, %indices, %constraints, $table_order, @table_comments ) }
1;
}
-create : create_index index_name /on/i table_name parens_word_list table_option(?) ';'
+create : create_index index_name /on/i table_name index_expr table_option(?) ';'
{
my $table_name = $item[4];
if ( $item[1] ) {
}
}
+index_expr: parens_word_list
+ { $item[1] }
+ | '(' WORD parens_word_list ')'
+ {
+ my $arg_list = join(",", @{$item[3]});
+ $return = "$item[2]($arg_list)";
+ }
+
# Create anything else (e.g., domain, function, etc.)
create : ...!create_table ...!create_index /create/i WORD /[^;]+/ ';'
{ @table_comments = () }
field_name : NAME
-data_type : ora_data_type parens_value_list(?)
+data_type : ora_data_type data_size(?)
{
$return = {
type => $item[1],
size => $item[2][0] || '',
}
}
+
+data_size : '(' VALUE(s /,/) data_size_modifier(?) ')'
+ { $item[2] }
+
+data_size_modifier: /byte/i
+ | /char/i
column_constraint : constraint_name(?) column_constraint_type constraint_state(s?)
{
constraint_name : /constraint/i NAME { $item[2] }
column_constraint_type : /not\s+null/i { $return = { type => 'not_null' } }
- | /null/
- { $return = { type => 'null' } }
- | /unique/
+ | /unique/i
{ $return = { type => 'unique' } }
| /primary\s+key/i
{ $return = { type => 'primary_key' } }
value => $val,
}
}
+ | /null/i
+ {
+ $return = {
+ supertype => 'constraint',
+ type => 'default',
+ value => 'NULL',
+ }
+ }
create_table : /create/i global_temporary(?) /table/i
fields => $item[3],
reference_table => $item[6],
reference_fields => $item[7][0],
- match_type => $item[8][0],
- on_delete => $item[9][0],
- on_update => $item[10][0],
+# match_type => $item[8][0],
+ on_delete => $item[8][0],
+# on_update => $item[9][0],
}
}
on_delete : /on delete/i WORD(s)
- { $item[2] }
+ { join(' ', @{$item[2]}) }
UNIQUE : /unique/i { $return = 1 }
# -------------------------------------------------------------------
sub parse {
my ( $translator, $data ) = @_;
- $parser ||= Parse::RecDescent->new($GRAMMAR);
+ my $parser = Parse::RecDescent->new($GRAMMAR);
local $::RD_TRACE = $translator->trace ? 1 : undef;
local $DEBUG = $translator->debug;