From: Chris Hilton Date: Wed, 3 May 2006 21:25:07 +0000 (+0000) Subject: Parser changes to accomodate function-based indexes and optional size modifier for... X-Git-Tag: v0.11008~450 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7f6504d358470f5abdabb613938c691439bc3187;p=dbsrgits%2FSQL-Translator.git Parser changes to accomodate function-based indexes and optional size modifier for data type --- diff --git a/lib/SQL/Translator/Parser/Oracle.pm b/lib/SQL/Translator/Parser/Oracle.pm index 06911f1..3dbc6e5 100644 --- a/lib/SQL/Translator/Parser/Oracle.pm +++ b/lib/SQL/Translator/Parser/Oracle.pm @@ -1,7 +1,7 @@ package SQL::Translator::Parser::Oracle; # ------------------------------------------------------------------- -# $Id: Oracle.pm,v 1.21 2005-08-10 15:17:48 duality72 Exp $ +# $Id: Oracle.pm,v 1.22 2006-05-03 21:25:07 duality72 Exp $ # ------------------------------------------------------------------- # Copyright (C) 2002-4 SQLFairy Authors # @@ -97,7 +97,7 @@ was altered to better handle the syntax created by DDL::Oracle. 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.22 $ =~ /(\d+)\.(\d+)/; $DEBUG = 0 unless defined $DEBUG; use Data::Dumper; @@ -196,7 +196,7 @@ create : create_table table_name '(' create_definition(s /,/) ')' table_option(s 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] ) { @@ -215,6 +215,11 @@ create : create_index index_name /on/i table_name parens_word_list table_option( } } +index_expr: parens_word_list + { $item[1] } + | '(' WORD parens_word_list ')' + { $item[2].$item[3] } + # Create anything else (e.g., domain, function, etc.) create : ...!create_table ...!create_index /create/i WORD /[^;]+/ ';' { @table_comments = () } @@ -329,13 +334,19 @@ field : comment(s?) field_name data_type field_meta(s?) comment(s?) 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?) { diff --git a/t/15oracle-parser.t b/t/15oracle-parser.t index a5098e4..aeccec1 100644 --- a/t/15oracle-parser.t +++ b/t/15oracle-parser.t @@ -29,8 +29,8 @@ my $sql = q[ ( qtl_trait_id NUMBER(11) NOT NULL CONSTRAINT pk_qtl_trait PRIMARY KEY, - trait_symbol VARCHAR2(100) NOT NULL, - trait_name VARCHAR2(200) NOT NULL, + trait_symbol VARCHAR2(100 BYTE) NOT NULL, + trait_name VARCHAR2(200 CHAR) NOT NULL, qtl_trait_category_id NUMBER(11) NOT NULL, UNIQUE ( trait_symbol ), UNIQUE ( trait_name ), @@ -54,6 +54,7 @@ my $sql = q[ ); CREATE UNIQUE INDEX qtl_accession ON qtl ( qtl_accession_id ); + CREATE UNIQUE INDEX qtl_accession_upper ON qtl ( UPPER(qtl_accession_id) ); CREATE TABLE qtl_trait_synonym ( @@ -206,7 +207,7 @@ my @t3_fields = $t3->get_fields; is( scalar @t3_fields, 8, '8 fields in table' ); my @t3_constraints = $t3->get_constraints; -is( scalar @t3_constraints, 3, '3 constraints on table' ); +is( scalar @t3_constraints, 4, '4 constraints on table' ); is( $t3->comments, 'qtl table comment', 'Comment "qtl table comment" exists' );