more insertRow() bugs and fixes

Поиск
Список
Период
Сортировка
Искать
От
Joel Hock
Тема
more insertRow() bugs and fixes
Дата
Msg-id
BNEGKPDJEODNGBJKPJBPEENOCBAA.joel@enspire.com
Список
Дерево обсуждения
more insertRow() bugs and fixes "Joel Hock" <joel@enspire.com>
Re: more insertRow() bugs and fixes Dave Cramer <Dave@micro-automation.net>
Re: more insertRow() bugs and fixes "Joel Hock" <joel@enspire.com>
cannot build current cvs Michael Adler <adler@glimpser.org>
Re: cannot build current cvs Dave Cramer <Dave@micro-automation.net>
Re: cannot build current cvs Kris Jurka <books@ejurka.com>
Re: cannot build current cvs Dave Cramer <Dave@micro-automation.net>
Re: cannot build current cvs Kris Jurka <books@ejurka.com>
Re: cannot build current cvs Dave Cramer <Dave@micro-automation.net>
Re: cannot build current cvs Michael Adler <adler@glimpser.org>

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

В списке pgsql-jdbc по дате отправления
От: Patric Bechtel
Дата:
От: Michael Adler
Дата:
Сообщение: cannot build current cvs
FAQ