package SQL::Translator::Producer::Oracle;
-# -------------------------------------------------------------------
-# Copyright (C) 2002-2009 SQLFairy Authors
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; version 2.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-# 02111-1307 USA
-# -------------------------------------------------------------------
-
=head1 NAME
SQL::Translator::Producer::Oracle - Oracle SQL producer
=cut
use strict;
-use vars qw[ $VERSION $DEBUG $WARN ];
-$VERSION = '1.59';
+use warnings;
+our ( $DEBUG, $WARN );
+our $VERSION = '1.59';
$DEBUG = 0 unless defined $DEBUG;
use SQL::Translator::Schema::Constants;
# Quote used to escape table, field, sequence and trigger names
my $quote_char = '"';
-# -------------------------------------------------------------------
sub produce {
my $translator = shift;
$DEBUG = $translator->debug;
$create .= ";\n\n";
# If wantarray is not set we have to add "/" in this statement
# DBI->do() needs them omitted
- # triggers may NOT end with a semicolon
- $create .= join "/\n\n", @trigger_defs;
- # for last trigger
- $create .= "/\n\n";
+ # triggers may NOT end with a semicolon but a "/" instead
+ $create .= "$_/\n\n"
+ for @trigger_defs;
return $create;
}
}
"CREATE OR REPLACE TRIGGER $trig_name\n".
"BEFORE INSERT OR UPDATE ON $table_name_q\n".
"FOR EACH ROW WHEN (new.$field_name_q IS NULL)\n".
- "BEGIN \n".
+ "BEGIN\n".
" SELECT sysdate INTO :new.$field_name_q FROM dual;\n".
"END;\n";
return \@create;
}
-# -------------------------------------------------------------------
sub mk_name {
my $basename = shift || '';
my $type = shift || '';
1;
-# -------------------------------------------------------------------
sub quote {
my ($name, $q) = @_;
- $q && $name ? "$quote_char$name$quote_char" : $name;
+ return $name unless $q && $name;
+ $name =~ s/\Q$quote_char/$quote_char$quote_char/g;
+ return "$quote_char$name$quote_char";
}