Return-Path: Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: (qmail 46001 invoked from network); 15 Jun 2007 18:46:43 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 15 Jun 2007 18:46:43 -0000 Received: (qmail 15861 invoked by uid 500); 15 Jun 2007 18:46:45 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 15826 invoked by uid 500); 15 Jun 2007 18:46:45 -0000 Mailing-List: contact derby-user-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Reply-To: "Derby Discussion" Delivered-To: mailing list derby-user@db.apache.org Received: (qmail 15814 invoked by uid 99); 15 Jun 2007 18:46:45 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Jun 2007 11:46:45 -0700 X-ASF-Spam-Status: No, hits=1.4 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (herse.apache.org: 32.97.110.153 is neither permitted nor denied by domain of Stan.Bradbury@gmail.com) Received: from [32.97.110.153] (HELO e35.co.us.ibm.com) (32.97.110.153) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Jun 2007 11:46:41 -0700 Received: from d03relay04.boulder.ibm.com (d03relay04.boulder.ibm.com [9.17.195.106]) by e35.co.us.ibm.com (8.13.8/8.13.8) with ESMTP id l5FIkKbw019609 for ; Fri, 15 Jun 2007 14:46:20 -0400 Received: from d03av01.boulder.ibm.com (d03av01.boulder.ibm.com [9.17.195.167]) by d03relay04.boulder.ibm.com (8.13.8/8.13.8/NCO v8.3) with ESMTP id l5FIkKBx215466 for ; Fri, 15 Jun 2007 12:46:20 -0600 Received: from d03av01.boulder.ibm.com (loopback [127.0.0.1]) by d03av01.boulder.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id l5FIkKTi009661 for ; Fri, 15 Jun 2007 12:46:20 -0600 Received: from [127.0.0.1] (sig-9-48-109-187.mts.ibm.com [9.48.109.187]) by d03av01.boulder.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id l5FIkIA0009572 for ; Fri, 15 Jun 2007 12:46:19 -0600 Message-ID: <4672DE41.9010300@gmail.com> Date: Fri, 15 Jun 2007 11:45:21 -0700 From: Stanley Bradbury User-Agent: Thunderbird 1.5.0.12 (Windows/20070509) MIME-Version: 1.0 To: Derby Discussion Subject: Re: After Insert statement trigger bug References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Amir Bar-or wrote: > > Hello, > > > We are trying to use an After insert statement trigger that calls a > java function with the JDBC Batch API. Instead of getting a single > activation of the trigger for a whole statement , we get one for every > inserted row like a row trigger. We get the same bug when we use > ODBC array binding. It seems to be related only to the java function > , since a trigger that calls a sql statement seems to be working fine. > An example code is below. Is anyone aware of this? > > > // create table > String str = "Create table " + tableName + " (a integer, c > VARCHAR(32))"; > psCreate = /dbConnection/.prepareStatement(str); > psCreate.execute(); > > // create function > Statement stmt = /dbConnection/.createStatement(); > stmt.executeUpdate("CREATE FUNCTION notifyData (" > + ")" > + " RETURNS INTEGER" > + " LANGUAGE JAVA " > + " PARAMETER STYLE JAVA" > + " NO SQL" > + " EXTERNAL NAME > 'com.ibm.jStage.tests.testJDBCBatchFunctionality.catchTriggerEvent'"); > > stmt.close(); > > // create trigger > str = > "CREATE TRIGGER " + "\"trig" + tableName + "\" AFTER INSERT > ON " + tableName > + " REFERENCING NEW_TABLE as NEW" > + " FOR EACH STATEMENT MODE DB2SQL " > + " VALUES( notifyData() )"; > > stmt = /dbConnection/.createStatement(); > stmt.executeUpdate(str); > > // prepare insert statement > PreparedStatement ps = *null*; > ps = /dbConnection/.prepareStatement("insert into " + tableName > + " (a,c) values (?,?)"); > ps.setInt(1, 1); > ps.setString(2, "XXXX"); > ps.addBatch(); > > ps.setInt(1, 2); > ps.setString(2, "YYYY"); > ps.addBatch(); > > ps.setInt(1, 3); > ps.setString(2, "ZZZZZZZZ"); > ps.addBatch(); > > > // insert something > ps.executeBatch(); > > // catch event > > // count callbacks > > /dbConnection/.close(); > derbyServer.shutdown(); > > *if*(/count/ > 1) > Assert./fail/(); > } > *catch*(Exception e) > { > Assert./fail/(); > } > } > > *public* *static* *int* catchTriggerEvent() *throws* SQLException > { > System./out/.println("Trigger activated!"); > > /count/++; > > *return* 0; > } > > // We get 3 invocation of this catchTriggerEvent() rather than > 1. Seems like a a bug right? > > Regards, > Amir Bar-or > Hi - The example code you provides shows three statements in your Batch so I would expect the trigger to fire three times (once for each statement submitted). If you have only one statement in your batch the trigger should fire only once. Are you seeing something different?