From dbadmin@nqadmin.com Mon Oct 29 20:45:21 2007 Received: from localhost (unknown [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id AD69A9FBC5F for ; Mon, 29 Oct 2007 17:45:21 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 43169-02-2 for ; Mon, 29 Oct 2007 17:45:13 -0300 (ADT) X-Greylist: delayed 01:00:12.289965 by SQLgrey-1.7.5 Received: from mail.nqadmin.com (mail.liquidcore.com [70.151.60.104]) by postgresql.org (Postfix) with ESMTP id A6BB09FBD1D for ; Mon, 29 Oct 2007 17:45:12 -0300 (ADT) Received: (from root@localhost) by mail.nqadmin.com (8.14.1/8.14.1) id l9TJiplP020281 for pgsql-jdbc@postgresql.org; Mon, 29 Oct 2007 14:44:51 -0500 Received: from ppasalalinux.nqadmin.com (ppasalalinux.nqadmin.com [192.168.0.234]) by mail.nqadmin.com with SMTP; for pgsql-jdbc@postgresql.org; Mon, 29 Oct 2007 14:44:51 -0500 (CDT) (envelope-from dbadmin@nqadmin.com) Message-ID: <4726383A.8060909@nqadmin.com> Date: Mon, 29 Oct 2007 14:44:58 -0500 From: Prasanth Reddy Reply-To: dbadmin@nqadmin.com User-Agent: Thunderbird 2.0.0.5 (X11/20070727) MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: getXXX throws SQLException while on insert row Content-Type: multipart/alternative; boundary="------------010204000700050307030603" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.002 tagged_above=0 required=5 tests=BAYES_50=0.001, HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 200710/172 X-Sequence-Number: 17744 This is a multi-part message in MIME format. --------------010204000700050307030603 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Hi, Should the below code throw an SQLException? rs.moveToInsertRow(); rs.updateInt("account_id", 1023); rs.getInt("account_id"); - shouldn't this return 1023 rather than throwing SQLException? Below is the exception: org.postgresql.util.PSQLException: ResultSet not positioned properly, perhaps you need to call next. at org.postgresql.jdbc2.AbstractJdbc2ResultSet.checkResultSet(AbstractJdbc2ResultSet.java:2473) at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getString(AbstractJdbc2ResultSet.java:1903) at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getFixedString(AbstractJdbc2ResultSet.java:2404) at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getInt(AbstractJdbc2ResultSet.java:2012) at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getInt(AbstractJdbc2ResultSet.java:2226) Postgres Server version: 8.1 JDBC Driver version: 8.1-410 JDBC 3 Thanks, -Prasanth. --------------010204000700050307030603 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Hi,

Should the below code throw an SQLException?

rs.moveToInsertRow();
rs.updateInt("account_id", 1023);
rs.getInt("account_id");      - shouldn't this return 1023 rather than throwing SQLException?

Below is the exception:
org.postgresql.util.PSQLException: ResultSet not positioned properly, perhaps you need to call next.
    at org.postgresql.jdbc2.AbstractJdbc2ResultSet.checkResultSet(AbstractJdbc2ResultSet.java:2473)
    at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getString(AbstractJdbc2ResultSet.java:1903)
    at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getFixedString(AbstractJdbc2ResultSet.java:2404)
    at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getInt(AbstractJdbc2ResultSet.java:2012)
    at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getInt(AbstractJdbc2ResultSet.java:2226)



Postgres Server version: 8.1
JDBC Driver version: 8.1-410 JDBC 3

Thanks,
-Prasanth.
--------------010204000700050307030603-- From books@ejurka.com Sat Dec 1 09:42:46 2007 Received: from localhost (unknown [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 749992E00DC for ; Sat, 1 Dec 2007 05:42:46 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 31547-05 for ; Sat, 1 Dec 2007 05:42:38 -0400 (AST) Received: from mail63.csoft.net (leary.csoft.net [205.205.214.5]) by postgresql.org (Postfix) with SMTP id 90F0F2E0094 for ; Sat, 1 Dec 2007 05:42:41 -0400 (AST) Received: (qmail 24930 invoked by uid 1112); 1 Dec 2007 09:42:40 -0000 Date: Sat, 1 Dec 2007 04:42:40 -0500 (EST) From: Kris Jurka X-X-Sender: books@leary.csoft.net To: Prasanth Reddy cc: pgsql-jdbc@postgresql.org Subject: Re: getXXX throws SQLException while on insert row In-Reply-To: <4726383A.8060909@nqadmin.com> Message-ID: References: <4726383A.8060909@nqadmin.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200712/5 X-Sequence-Number: 17860 On Mon, 29 Oct 2007, Prasanth Reddy wrote: > Should the below code throw an SQLException? > > rs.moveToInsertRow(); > rs.updateInt("account_id", 1023); > rs.getInt("account_id"); - shouldn't this return 1023 rather than > throwing SQLException? > > Below is the exception: > org.postgresql.util.PSQLException: ResultSet not positioned properly, > perhaps you need to call next. It's not clear. Reading the JDBC spec it doesn't seem to say anything about fetching data from a partially updated ResultSet. Also note that this doesn't work as you might expect for an update of a regular ResultSet row. int i = rs.getInt(1); rs.updateInt(1, i+1); // here j will be == i, not i+1. int j = rs.getInt(1); We store the pending values in a separate area because it makes things like cancelRowUpdates or just navigating away from the updated row without issuing updateRow easy. While I can see the utility of being able to fetch the updated values, it would complicate the driver, so I'm not excited about it unless you can point to some documentation that says we should. Kris Jurka From freyer@online.de Sun Feb 10 23:52:02 2008 Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id D7C4E2E38E4 for ; Sun, 10 Feb 2008 19:52:02 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 56007-02-4 for ; Sun, 10 Feb 2008 19:51:59 -0400 (AST) Received: from kuber.nabble.com (kuber.nabble.com [216.139.236.158]) by postgresql.org (Postfix) with ESMTP id 3CDAF2E3795 for ; Sun, 10 Feb 2008 19:50:34 -0400 (AST) Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1JOLwO-0000HO-H0 for pgsql-jdbc@postgresql.org; Sun, 10 Feb 2008 15:50:32 -0800 Message-ID: <15403292.post@talk.nabble.com> Date: Sun, 10 Feb 2008 15:50:32 -0800 (PST) From: andreasfreyer To: pgsql-jdbc@postgresql.org Subject: Re: getXXX throws SQLException while on insert row In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: freyer@online.de References: <4726383A.8060909@nqadmin.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.03 tagged_above=0 required=5 tests=BAYES_00=-2.599, DNS_FROM_OPENWHOIS=1.13, WHOIS_MYPRIVREG=1.499 X-Spam-Level: X-Archive-Number: 200802/35 X-Sequence-Number: 18242 Hello, according to the Java Documentation form SUN ResultSet.moveToInsertRow is defined as: Moves the cursor to the insert row. The current cursor position is remembered while the cursor is positioned on the insert row. The insert row is a special row associated with an updatable result set. It is essentially a buffer where a new row may be constructed by calling the updater methods prior to inserting the row into the result set. Only the updater, getter, and insertRow methods may be called when the cursor is on the insert row. All of the columns in a result set must be given a value each time this method is called before calling insertRow. An updater method must be called before a getter method can be called on a column value. I would like to draw our attention to the the last sentence: "An updater method must be called before a getter method can be called on a column value." That means after setting a value [rs.updateXXX(abc)] it is possible to get it back [rs.getXXX()] without doing anything else in between [so without rs.insertRow() or rs.updateRow()]. best regards, Andreas Freyer PS: To my knowledge atleast the JDBC Drivers for the following Databases work like this: MySQLDB, HSQLDB, Derby Kris Jurka wrote: > > > > On Mon, 29 Oct 2007, Prasanth Reddy wrote: > >> Should the below code throw an SQLException? >> >> rs.moveToInsertRow(); >> rs.updateInt("account_id", 1023); >> rs.getInt("account_id"); - shouldn't this return 1023 rather than >> throwing SQLException? >> >> Below is the exception: >> org.postgresql.util.PSQLException: ResultSet not positioned properly, >> perhaps you need to call next. > > It's not clear. Reading the JDBC spec it doesn't seem to say anything > about fetching data from a partially updated ResultSet. Also note that > this doesn't work as you might expect for an update of a regular ResultSet > row. > > int i = rs.getInt(1); > rs.updateInt(1, i+1); > // here j will be == i, not i+1. > int j = rs.getInt(1); > > We store the pending values in a separate area because it makes things > like cancelRowUpdates or just navigating away from the updated row without > issuing updateRow easy. While I can see the utility of being able to > fetch the updated values, it would complicate the driver, so I'm not > excited about it unless you can point to some documentation that says we > should. > > Kris Jurka > > ---------------------------(end of broadcast)--------------------------- > TIP 6: explain analyze is your friend > > -- View this message in context: http://www.nabble.com/getXXX-throws-SQLException-while-on-insert-row-tp13476706p15403292.html Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com. From books@ejurka.com Mon Feb 11 05:50:46 2008 Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id E68222E332C for ; Mon, 11 Feb 2008 01:50:46 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 32230-01-5 for ; Mon, 11 Feb 2008 01:50:40 -0400 (AST) Received: from mail63.csoft.net (leary.csoft.net [205.205.214.5]) by postgresql.org (Postfix) with SMTP id 319532E39DA for ; Mon, 11 Feb 2008 01:39:15 -0400 (AST) Received: (qmail 27373 invoked by uid 1112); 11 Feb 2008 05:39:14 -0000 Date: Mon, 11 Feb 2008 00:39:14 -0500 (EST) From: Kris Jurka X-X-Sender: books@leary.csoft.net To: andreasfreyer cc: pgsql-jdbc@postgresql.org Subject: Re: getXXX throws SQLException while on insert row In-Reply-To: <15403292.post@talk.nabble.com> Message-ID: References: <4726383A.8060909@nqadmin.com> <15403292.post@talk.nabble.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200802/36 X-Sequence-Number: 18243 On Sun, 10 Feb 2008, andreasfreyer wrote: > I would like to draw our attention to the the last sentence: > "An updater method must be called before a getter method can be called on a > column value." > > That means after setting a value [rs.updateXXX(abc)] it is possible to get > it back [rs.getXXX()] without doing anything else in between [so without > rs.insertRow() or rs.updateRow()]. > OK, I read that the same way you do (the pg driver is currently wrong). I'll take a look to see how hard this will be to fix. Kris Jurka From freyer@online.de Mon Feb 11 08:07:44 2008 Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 35FB22E30AF for ; Mon, 11 Feb 2008 04:07:44 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 13301-06 for ; Mon, 11 Feb 2008 04:07:40 -0400 (AST) Received: from kuber.nabble.com (kuber.nabble.com [216.139.236.158]) by postgresql.org (Postfix) with ESMTP id BEF8D2E30AD for ; Mon, 11 Feb 2008 04:07:40 -0400 (AST) Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1JOThT-0006UI-2k for pgsql-jdbc@postgresql.org; Mon, 11 Feb 2008 00:07:39 -0800 Message-ID: <15407063.post@talk.nabble.com> Date: Mon, 11 Feb 2008 00:07:39 -0800 (PST) From: andreasfreyer To: pgsql-jdbc@postgresql.org Subject: Re: getXXX throws SQLException while on insert row In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: freyer@online.de References: <4726383A.8060909@nqadmin.com> <15403292.post@talk.nabble.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.03 tagged_above=0 required=5 tests=BAYES_00=-2.599, DNS_FROM_OPENWHOIS=1.13, WHOIS_MYPRIVREG=1.499 X-Spam-Level: X-Archive-Number: 200802/40 X-Sequence-Number: 18246 Hi Kris, maybe it is not so hard to fix because only if an updateXXX (or updateNull) has already been performed onto a certain column the getter method needs to return an other result as the current implementation of the pg-jbdc driver does. I think if you would have a list of the rows that have been recently updated a getter-method could check this list and if the column is in this list it returns the value of the insertRow .... I mean the separate area that you mentioned in an earlier post. Best regards, Andreas Freyer PS: Have Fun! :-) -- View this message in context: http://www.nabble.com/getXXX-throws-SQLException-while-on-insert-row-tp13476706p15407063.html Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com. From freyer@online.de Mon Feb 11 08:09:33 2008 Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 0A89B2E30CE for ; Mon, 11 Feb 2008 04:09:33 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 14756-01 for ; Mon, 11 Feb 2008 04:09:26 -0400 (AST) Received: from kuber.nabble.com (kuber.nabble.com [216.139.236.158]) by postgresql.org (Postfix) with ESMTP id 74C172E30B3 for ; Mon, 11 Feb 2008 04:09:26 -0400 (AST) Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1JOTjB-0006W8-Pb for pgsql-jdbc@postgresql.org; Mon, 11 Feb 2008 00:09:25 -0800 Message-ID: <15407079.post@talk.nabble.com> Date: Mon, 11 Feb 2008 00:09:25 -0800 (PST) From: andreasfreyer To: pgsql-jdbc@postgresql.org Subject: Re: getXXX throws SQLException while on insert row In-Reply-To: <15407063.post@talk.nabble.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: freyer@online.de References: <4726383A.8060909@nqadmin.com> <15403292.post@talk.nabble.com> <15407063.post@talk.nabble.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.03 tagged_above=0 required=5 tests=BAYES_00=-2.599, DNS_FROM_OPENWHOIS=1.13, WHOIS_MYPRIVREG=1.499 X-Spam-Level: X-Archive-Number: 200802/39 X-Sequence-Number: 18247 sorry...typo: The last sentence of my last post should start with... I think if you would have a list of the coulumns that have.... -- View this message in context: http://www.nabble.com/getXXX-throws-SQLException-while-on-insert-row-tp13476706p15407079.html Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.