From: Johannes Plunien Date: Tue, 4 Nov 2008 09:22:56 +0000 (+0000) Subject: added notes about changed behaviour when calling oracle producer in array/scalar... X-Git-Tag: v0.11008~278 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2c5e662675e0f2eda79de9cbda282883e1783fe4;p=dbsrgits%2FSQL-Translator.git added notes about changed behaviour when calling oracle producer in array/scalar context --- diff --git a/Changes b/Changes index 98bba95..a734fda 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,7 @@ # ---------------------------------------------------------- # # ---------------------------------------------------------- +* Changed behaviour of ::Producer::Oracle when returning an array of statements to make it compatible to DBI->do() * Fixed a few bugs in ::Producer::Oracle * Applied patch from jgoulah to support mysql's MERGE option * Applied patch from rbo to add support of multiple database events on a trigger diff --git a/lib/SQL/Translator/Producer/Oracle.pm b/lib/SQL/Translator/Producer/Oracle.pm index dd08bfa..9625f49 100644 --- a/lib/SQL/Translator/Producer/Oracle.pm +++ b/lib/SQL/Translator/Producer/Oracle.pm @@ -46,6 +46,56 @@ CREATE TABLE statement and adds ALTER TABLEs at the end with it. =back +=head1 NOTES + +=head2 Autoincremental primary keys + +This producer uses sequences and triggers to autoincrement primary key +columns, if necessary. SQLPlus and DBI expect a slightly different syntax +of CREATE TRIGGER statement. You might have noticed that this +producer returns a scalar containing all statements concatenated by +newlines or an array of single statements depending on the context +(scalar, array) it has been called in. + +SQLPlus expects following trigger syntax: + + CREATE OR REPLACE TRIGGER ai_person_id + BEFORE INSERT ON person + FOR EACH ROW WHEN ( + new.id IS NULL OR new.id = 0 + ) + BEGIN + SELECT sq_person_id.nextval + INTO :new.id + FROM dual; + END; + / + +Whereas if you want to create the same trigger using L, you need +to omit the last slash: + + my $dbh = DBI->connect('dbi:Oracle:mysid', 'scott', 'tiger'); + $dbh->do(" + CREATE OR REPLACE TRIGGER ai_person_id + BEFORE INSERT ON person + FOR EACH ROW WHEN ( + new.id IS NULL OR new.id = 0 + ) + BEGIN + SELECT sq_person_id.nextval + INTO :new.id + FROM dual; + END; + "); + +If you call this producer in array context, we expect you want to process +the returned array of statements using L like +L does. + +To get this working we removed the slash in those statements in version +0.09002 of L when called in array context. In scalar +context the slash will be still there to ensure compatibility with SQLPlus. + =cut use strict;