From: | "Joel Hock" <joel(at)enspire(dot)com> |
---|---|
To: | <pgsql-jdbc(at)postgresql(dot)org> |
Subject: | more insertRow() bugs and fixes |
Date: | 2003-02-04 23:17:20 |
Message-ID: | BNEGKPDJEODNGBJKPJBPEENOCBAA.joel@enspire.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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(AbstractJdbc2Re
sultSet.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 Ive
skipped putting any code in it).
Ive included a patch to address these issues, but Im still new to the
codebase (and my directory isnt set up to compile), so itll need a good
looking-over.
Thanks again,
Joel
Attachment | Content-Type | Size |
---|---|---|
patch | application/octet-stream | 1.1 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Barry Lind | 2003-02-05 01:22:44 | Re: 7.3 compability, select * from myfunc(); |
Previous Message | Patric Bechtel | 2003-02-04 22:15:11 | Re: java.lang.OutOfMemoryError [Viruschecked] |