From: | PG Bug reporting form <noreply(at)postgresql(dot)org> |
---|---|
To: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
Cc: | linuxhippy(at)gmail(dot)com |
Subject: | BUG #16230: Boolean column stick to "false" after calling updateRow() on updateable ResultSet |
Date: | 2020-01-25 19:05:22 |
Message-ID: | 16230-a2e15977e9f64e47@postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs pgsql-jdbc |
The following bug has been logged on the website:
Bug reference: 16230
Logged by: Clemens Eisserer
Email address: linuxhippy(at)gmail(dot)com
PostgreSQL version: 12.1
Operating system: linux / platform independent
Description:
Boolean columns always seem to stick to "false" after updateRow() is called
on updateable ResultSets (this is a regression and worked with
PostgreSQL-8.4.21 & postgresql-8.4-701.jdbc3.jar ).
The value stored however is correct, and calling refreshRow() right after
updateRow() seems to restore the "old" behaviour and restores the value set
a few lines aboce.
In PgResultSet.getBoolean() there is manual type conversion from byte[] to
boolean going on:
int col = columnIndex - 1;
if (Oid.BOOL == fields[col].getOID()) {
final byte[] v = thisRow[col];
return (1 == v.length) && (116 == v[0]); // 116 = 't'
}
... so in case the value of thisRow[col] is a single character with the
letter 't' the check succeeds.
This is the case when the value was sent from the server (right after the
select or after calling refreshRow()).
However after updateRow(), fields[col]. contains the string "true", because
of length != 1, the check fails.
Code to trigger the problem:
//DDL
CREATE TABLE sometable (id integer NOT NULL, someprop boolean DEFAULT
false);
//JDBC access
Statement st =
connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs = st.executeQuery("SELECT * FROM sometable WHERE
id=...");
rs.next();
System.out.println(rs.getBoolean("someprop")); // value stored in
DB
rs.updateBoolean("vereinsFlugzeug", true);
System.out.println(rs.getBoolean("someprop")); //Matches the
value set above (true)
rs.updateRow();
// rs.refreshRow(); //fetches the value stored
System.out.println(rs.getBoolean("someprop")); // always returns
false.
From | Date | Subject | |
---|---|---|---|
Next Message | Eduardo Lúcio Amorim Costa | 2020-01-26 00:31:44 | Re: SQL/PostgreSQL - Error observed in the QUERY not caught by the “EXCEPTION” block in the stored procedure |
Previous Message | PG Bug reporting form | 2020-01-25 15:56:08 | BUG #16229: PgAdmin 4.17 show message error |
From | Date | Subject | |
---|---|---|---|
Next Message | Clemens Eisserer | 2020-01-25 19:07:53 | Re: Boolean column stick to "false" after calling updateRow() on updateable ResultSet |
Previous Message | Clemens Eisserer | 2020-01-25 16:43:02 | Boolean column stick to "false" after calling updateRow() on updateable ResultSet |