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

From Dave Cramer
Subject Re: more insertRow() bugs and fixes
Date
Msg-id 1044443970.1792.74.camel@inspiron.cramers
Whole thread Raw
In response to more insertRow() bugs and fixes  ("Joel Hock" <joel@enspire.com>)
Responses Re: more insertRow() bugs and fixes  ("Joel Hock" <joel@enspire.com>)
List pgsql-jdbc
Joel,

Thanks for the code, I do have one request though, can you use the -c
switch on diff to produce a context diff, and resubmit please?

Dave
On Tue, 2003-02-04 at 18:17, Joel Hock wrote:
> 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
>
>
>
> ______________________________________________________________________
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
--
Dave Cramer <Dave@micro-automation.net>


pgsql-jdbc by date:

Previous
From: Dave Cramer
Date:
Subject: Re: cannot build current cvs
Next
From: Daniel Serodio
Date:
Subject: Re: DbVisualizer shows same tables for all DBs