Return-Path: X-Original-To: apmail-db-derby-user-archive@www.apache.org Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 06B0D108E4 for ; Thu, 1 Aug 2013 17:04:33 +0000 (UTC) Received: (qmail 6056 invoked by uid 500); 1 Aug 2013 17:04:32 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 5885 invoked by uid 500); 1 Aug 2013 17:04:29 -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 5855 invoked by uid 99); 1 Aug 2013 17:04:27 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Aug 2013 17:04:27 +0000 X-ASF-Spam-Status: No, hits=-1.3 required=5.0 tests=FSL_NEW_HELO_USER,RCVD_IN_DNSWL_MED,SPF_PASS,UNPARSEABLE_RELAY X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of rick.hillegas@oracle.com designates 156.151.31.81 as permitted sender) Received: from [156.151.31.81] (HELO userp1040.oracle.com) (156.151.31.81) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Aug 2013 17:04:17 +0000 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by userp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r71H3swt012987 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 1 Aug 2013 17:03:56 GMT Received: from aserz7021.oracle.com (aserz7021.oracle.com [141.146.126.230]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r71H3rR1003139 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 1 Aug 2013 17:03:54 GMT Received: from abhmt105.oracle.com (abhmt105.oracle.com [141.146.116.57]) by aserz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r71H3rN4003430; Thu, 1 Aug 2013 17:03:53 GMT Received: from dhcp-rmdc-twvpn-1-vpnpool-10-159-71-190.vpn.oracle.com (/10.159.71.190) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 01 Aug 2013 10:03:53 -0700 Message-ID: <51FA94F8.2050103@oracle.com> Date: Thu, 01 Aug 2013 10:03:52 -0700 From: Rick Hillegas User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.7; en-US; rv:1.9.2.18) Gecko/20110616 Thunderbird/3.1.11 MIME-Version: 1.0 To: Derby Discussion CC: Steve Ebersole Subject: Re: Java stored procedure performing insert/update/delete References: <51F9A579.5060204@hibernate.org> <51FA6A67.6030401@hibernate.org> <51FA6BEA.3080807@hibernate.org> <51FA7715.3080607@oracle.com> <51FA7E5A.60404@hibernate.org> In-Reply-To: <51FA7E5A.60404@hibernate.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Source-IP: acsinet22.oracle.com [141.146.126.238] X-Virus-Checked: Checked by ClamAV on apache.org On 8/1/13 8:27 AM, Steve Ebersole wrote: > As far as I could tell, the embedded driver was always returning > zero. That happens from both executeUpdate() and getUpdateCount(). > Now its very possible that I did not code the stored procedure > properly in terms of how Derby expects to "see" the update count. I > followed examples, but maybe I missed something. > > And the options of using a function nor an (IN)OUT parameter is not an > option unfortunately. > > I am trying to spin up unit tests here, so have only used in-process > dbs thus far for testing this. Specifically H2 and then Derby. > Neither returned what I expect based on JDBC. Thomas agrees H2 does > not do this properly. > > In terms of expectation, the execute() call should of course execute > the proc. Since this proc does not return results, execute() should > return false. Then getUpdateCount() ought to return the number of > rows "modified" by the call, or -1 if no modification was done. 0 and > -1 are distinctly different according to the spec. I hate "magic > values" as much as anyone, but the spec says what it says ;) Hi Steve, Can you point me at the sections of the JDBC spec which you feel support this interpretation? I am concerned that this part of the spec may be undefined and I am seeing a range of opinions, including: 1) Should return -1 because a procedure call is not an INSERT/UPDATE/DELETE statement. 2) Should return the update count of the last INSERT/UPDATE/DELETE statement executed by the procedure. 3) Should return the sum of the update counts of all INSERT/UPDATE/DELETE statements executed by the procedure. Thanks, -Rick > > > On Thu 01 Aug 2013 09:56:21 AM CDT, Rick Hillegas wrote: >> Hi Steve, >> >> I'm not sure that DERBY-211 addresses the functionality you want. That >> issue seems to me to be a discussion about whether 0 or -1 is the >> correct value for CallableStatement.getUpdateCount() when the stored >> procedure does NOT return any ResultSets. It sounds as though you want >> getUpdateCount() to return a positive number in that case, maybe the >> sum of the update counts for all INSERT, UPDATE, and DELETE statements >> executed inside the procedure. >> >> It also sounds as though you are experimenting with other databases >> for which CallableStatement.getUpdateCount() returns a positive >> number. Can you describe the behavior of the other databases? I would >> like to take your evidence to the JDBC expert group in order to >> determine what the correct behavior should be. As a result, we may >> need to open a new Derby issue. >> >> Note that the solution which I suggested ought to be portable across >> all JDBC databases. >> >> Thanks, >> -Rick >> >> On 8/1/13 7:08 AM, Steve Ebersole wrote: >>> Dag, Rick.. thanks for your replies. I am not subscribed to the >>> list, but saw them in archive. >>> >>> Unfortunately a workaround won't work. This is support for stored >>> procedures across all databases that I am adding in Hibernate. So >>> there has to be a certain level of consistency. I'll just add a note >>> that stored procedures doing manipulation will not work correctly >>> with Derby (in terms of getting the "affect rows" count) when used in >>> embedded mode and reference to DERBY-211. >>> >>> On Thu 01 Aug 2013 09:02:15 AM CDT, Steve Ebersole wrote: >>>> Looks like I am seeing https://issues.apache.org/jira/browse/DERBY-211 >>>> >>>> On Wed 31 Jul 2013 07:02:01 PM CDT, Steve Ebersole wrote: >>>>> I am trying to work out how to define a Java stored procedure using >>>>> Derby that performs a insert/update/delete and results in the proper >>>>> "update count" on the JDBC client. But I have so far been >>>>> unsuccessful. >>>>> >>>>> Here is what I have... >>>>> >>>>> First, through JDBC I execute: >>>>> >>>>> create procedure deleteAllUsers() >>>>> language java >>>>> external name 'TheClass.deleteAllUsers' >>>>> parameter style java >>>>> >>>>> TheClass.deleteAllUsers looks like: >>>>> >>>>> public static void deleteAllUsers() { >>>>> Connection conn = DriverManager.getConnection( >>>>> "jdbc:default:connection" ); >>>>> PreparedStatement ps = conn.prepareStatement( "delete from >>>>> t_user" ); >>>>> int count = ps.executeUpdate(); >>>>> System.out.println( "Count : " + count ); >>>>> ps.close(); >>>>> conn.close(); >>>>> } >>>>> >>>>> And on the JDBC client side: >>>>> >>>>> Connection conn = ...; >>>>> CallableStatement stmnt = conn.prepareCall( "{call >>>>> deleteAllUsers()}" ); >>>>> // yes I know this could be stmnt.executeUpdate()... >>>>> stmnt.execute(); >>>>> int count = stmnt.getUpdateCount(); >>>>> >>>>> >>>>> So the deleteAllUsers() prints the correct count. But on the client, >>>>> I always get zero (and not -1). >>>>> >>>>> Obviously I am doing something wrong. Any pointers? >>>>> >>>>> Thanks, >>>>> Steve >>> >> >