package SQL::Translator::Parser::Oracle;
# -------------------------------------------------------------------
-# $Id: Oracle.pm,v 1.18 2004-04-22 19:56:28 kycl4rk Exp $
+# $Id: Oracle.pm,v 1.20 2005-06-28 16:39:41 mwz444 Exp $
# -------------------------------------------------------------------
# Copyright (C) 2002-4 SQLFairy Authors
#
tbl_defs:
column datatype [DEFAULT expr] [column_constraint(s)]
- table_constraint
table_ref_constraint
storage_options:
use strict;
use vars qw[ $DEBUG $VERSION $GRAMMAR @EXPORT_OK ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.18 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.20 $ =~ /(\d+)\.(\d+)/;
$DEBUG = 0 unless defined $DEBUG;
use Data::Dumper;
reference_table => $desc->{'reference_table'},
reference_fields => $desc->{'reference_fields'},
# match_type => $desc->{'match_type'},
-# on_update_do => $desc->{'on_update_do'},
+# on_update => $desc->{'on_update'},
}
}
constraint_name : /constraint/i NAME { $item[2] }
-column_constraint_type : /not null/i { $return = { type => 'not_null' } }
+column_constraint_type : /not\s+null/i { $return = { type => 'not_null' } }
| /null/
{ $return = { type => 'null' } }
| /unique/
{ $return = { type => 'unique' } }
- | /primary key/i
+ | /primary\s+key/i
{ $return = { type => 'primary_key' } }
| /check/i '(' /[^)]+/ ')'
- { $return = { type => 'check', expression => $item[2] } }
- | /references/i table_name parens_word_list(?) on_delete_do(?)
+ { $return = { type => 'check', expression => $item[3] } }
+ | /references/i table_name parens_word_list(?) on_delete(?)
{
$return = {
type => 'foreign_key',
reference_table => $item[2],
reference_fields => $item[3][0],
# match_type => $item[4][0],
- on_delete_do => $item[5][0],
+ on_delete => $item[5][0],
}
}
reference_table => $desc->{'reference_table'},
reference_fields => $desc->{'reference_fields'},
# match_type => $desc->{'match_type'}[0],
- on_delete_do => $desc->{'on_delete_do'},
- on_update_do => $desc->{'on_update_do'},
+ on_delete => $desc->{'on_delete'} || $desc->{'on_delete_do'},
+ on_update => $desc->{'on_update'} || $desc->{'on_update_do'},
comments => [ @comments ],
}
}
}
}
|
- /foreign key/i '(' NAME(s /,/) ')' /references/i table_name parens_word_list(?) on_delete_do(?)
+ /foreign key/i '(' NAME(s /,/) ')' /references/i table_name parens_word_list(?) on_delete(?)
{
$return = {
type => 'foreign_key',
reference_table => $item[6],
reference_fields => $item[7][0],
match_type => $item[8][0],
- on_delete_do => $item[9][0],
- on_update_do => $item[10][0],
+ on_delete => $item[9][0],
+ on_update => $item[10][0],
}
}
-on_delete_do : /on delete/i WORD(s)
+on_delete : /on delete/i WORD(s)
{ $item[2] }
UNIQUE : /unique/i { $return = 1 }
my $result = $parser->startrule( $data );
die "Parse failed.\n" unless defined $result;
- warn Dumper($result) if $DEBUG;
+ if ( $DEBUG ) {
+ warn "Parser results =\n", Dumper($result), "\n";
+ }
my $schema = $translator->schema;
my $indices = $result->{'indices'};
is_nullable => $fdata->{'null'},
comments => $fdata->{'comments'},
) or die $table->error;
-
- for my $cdata ( @{ $fdata->{'constraints'} } ) {
- next unless $cdata->{'type'} eq 'foreign_key';
- $cdata->{'fields'} ||= [ $field->name ];
- push @{ $tdata->{'constraints'} }, $cdata;
- }
}
push @{ $tdata->{'indices'} }, @{ $indices->{ $table_name } || [] };
reference_table => $cdata->{'reference_table'},
reference_fields => $cdata->{'reference_fields'},
match_type => $cdata->{'match_type'} || '',
- on_delete => $cdata->{'on_delete_do'},
- on_update => $cdata->{'on_update_do'},
+ on_delete => $cdata->{'on_delete'} || $cdata->{'on_delete_do'},
+ on_update => $cdata->{'on_update'} || $cdata->{'on_update_do'},
) or die $table->error;
}
}