more insertRow() bugs and fixes - Mailing list pgsql-jdbc

From Joel Hock
Subject more insertRow() bugs and fixes
Date
Msg-id BNEGKPDJEODNGBJKPJBPEENOCBAA.joel@enspire.com
Whole thread Raw
Responses cannot build current cvs
Re: more insertRow() bugs and fixes
List pgsql-jdbc

First, a big thanks to Dave Cramer for working with me on the last insertRow() issue I had--the patch works wonderfully!

 

Now, on to the next few things.

 

1.  When you insert a row into a resultset that has no rows and then call moveToCurrentRow(), you get a null pointer exception.  Example code:

 

Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);

ResultSet uprs = stmt.executeQuery("SELECT oid,* FROM school WHERE 1=0");

uprs.moveToInsertRow();

uprs.updateString("name", name);

uprs.insertRow();

uprs.moveToCurrentRow();

 

java.lang.ArrayIndexOutOfBoundsException: -1 < 0

        at java.util.Vector.elementAt(Vector.java:437)

        at org.postgresql.jdbc2.AbstractJdbc2ResultSet.moveToCurrentRow(AbstractJdbc2ResultSet.java:667)

 

The cause of this is pretty straightforward.  The offending line 667 in AbstractJdbc2ResultSet.java is:

 

this_row = (byte[][]) rows.elementAt(current_row);

 

current_row is -1 because the current position is before any rows.

 

2.  After moving onto the insert row, only a few of the resultset cursor-moving functions clear the internal “onInsertRow” variable.  According to http://java.sun.com/docs/books/tutorial/jdbc/jdbc2dot0/inserting.html :

“After you have called the method insertRow , you can start building another row to be inserted, or you can move the cursor back to a result set row. You can, for instance, invoke any of the methods that put the cursor on a specific row, such as first , last , beforeFirst , afterLast , and absolute . You can also use the methods previous , relative , and moveToCurrentRow.”

 

However, in the current driver, only first() and moveToCurrentRow() clear the onInsertRow flag.  This causes problems when you later try to update a row in the same resultset.  The functions that need to be modified that come to mind are: last(), beforeFirst(), afterLast(), absolute(), previous(), next(), and relative() (relative() uses absolute() internally, so I’ve skipped putting any code in it).

 

I’ve included a patch to address these issues, but I’m still new to the codebase (and my directory isn’t set up to compile), so it’ll need a good looking-over.

 

Thanks again,

Joel

Attachment

pgsql-jdbc by date:

Previous
From: "Patric Bechtel"
Date:
Subject: Re: java.lang.OutOfMemoryError [Viruschecked]
Next
From: Michael Adler
Date:
Subject: cannot build current cvs