dbTalk Databases Forums  

Re: [BUGS] Bug #886: jdbc "update row" can mess up other columns

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss Re: [BUGS] Bug #886: jdbc "update row" can mess up other columns in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Kris Jurka
 
Posts: n/a

Default Re: [BUGS] Bug #886: jdbc "update row" can mess up other columns - 11-03-2003 , 03:47 AM






This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
Send mail to mime (AT) docserver (DOT) cac.washington.edu for more info.

--1866420246-1934839611-1067852746=:29431
Content-Type: TEXT/PLAIN; charset=US-ASCII



Half of this bug was fixed at some point, but an exception is still thrown
when calling rs.afterLast() and then rs.previous(). Attached is a
regression test addition and the appropriate fix. Sorry for the extreme
delay in response and thanks for the thorough report.

Kris Jurka

On Fri, 24 Jan 2003 pgsql-bugs (AT) postgresql (DOT) org wrote:

Quote:
Andrew Fyfe (afyfe (AT) bigtribe (DOT) com) reports a bug with a severity of 3
The lower the number the more severe it is.

Short Description
jdbc "update row" can mess up other columns

Long Description
The attached program when run gives me the following output

DatabaseProductName: PostgreSQL
DatabaseProductVersion: 7.3.1
DriverName: PostgreSQL Native Driver
DriverVersion: PostgreSQL 7.3.1 JDBC3 jdbc driver build 106
--- Forward ---
1: Colombian 7.99
2: French_Roast 9.99
--- Backward ---
2: French_Roast 9.99
1: Colombian 7.99
--- Update Row 2 ---
--- Forward ---
1: Colombian 7.99
2: Colombian 10.99

Note that the update of the price in row 2 caused jdbc to misrepesent the name. If one does not run through the rows backward (give the arg "b" when running the code), then the output is correct:

--- Forward ---
1: Colombian 7.99
2: French_Roast 9.99
--- Update Row 2 ---
--- Forward ---
1: Colombian 7.99
2: French_Roast 10.99

Suppressing the first forward pass through the data (giving "f" or "fb" to suppress both) will cause an exception to be thrown.

Note that another forward pass after the backward makes the problem go away.

Sample Code
import java.util.*;
import java.sql.*;

class pgbug
{
static String url = "jdbcostgresql://localhost/cdb";
static String driver = "org.postgresql.Driver";
static String userName = "cdb";
static String password = "cdb";

public static void print(ResultSet rs) {
try {
String s = rs.getString("COF_NAME");
float n = rs.getFloat("PRICE");
int rowNum = rs.getRow();
System.out.println(rowNum + ":\t" + s + "\t" + n);
} catch (SQLException sqlEx) { /* ignore */
System.out.println("print ResultSet failed");
}
}

public static void forward(ResultSet rs) {
try {
System.out.println("--- Forward ---");
rs.beforeFirst();
while (rs.next()) {
print(rs);
}
} catch (SQLException sqlEx) { /* ignore */
System.out.println("print ResultSet failed");
}
}

public static void backward(ResultSet rs) {
try {
System.out.println("--- Backward ---");
rs.afterLast();
while (rs.previous()) {
print(rs);
}
} catch (SQLException sqlEx) { /* ignore */
System.out.println("print ResultSet failed");
}
}

public static void main(String args [])
throws Exception
{

Connection conn = null;
Statement stmt = null;

try {
// Load the mysql JDBC driver
Class.forName(driver).newInstance();

// Connect to the database
Properties props = new Properties();
props.put("user", userName);
props.put("password", password);
props.put("loglevel", "0");
conn = DriverManager.getConnection(url, props);

// Create a Statement
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSI TIVE,
ResultSet.CONCUR_UPDATABLE);

DatabaseMetaData meta = conn.getMetaData();
System.out.println("DatabaseProductName: " +
meta.getDatabaseProductName());
System.out.println("DatabaseProductVersion: " +
meta.getDatabaseProductVersion());
System.out.println("DriverName: " +
meta.getDriverName());
System.out.println("DriverVersion: " +
meta.getDriverVersion());

try {
stmt.executeUpdate("drop table coffees");
} catch (SQLException sqlEx) { /* ignore */
System.out.println("drop table failed");
}

// create the table
String createTableCoffees = "create table coffees " +
"(COF_NAME VARCHAR(32) primary key, PRICE FLOAT)";
try {
stmt.executeUpdate(createTableCoffees);
} catch (SQLException sqlEx) { /* ignore */
System.out.println("create table failed");
}

stmt.executeUpdate("insert into coffees " +
"VALUES ('Colombian', 7.99)");
stmt.executeUpdate("insert into coffees " +
"VALUES ('French_Roast', 9.99)");

// Select from the test table
String query = "select cof_name, price from coffees";
ResultSet rs = stmt.executeQuery(query);

if (args.length == 0 || args[0].indexOf('f') < 0) {
forward(rs);
}
if (args.length == 0 || args[0].indexOf('b') < 0) {
backward(rs);
}

if (rs.absolute(2)) {
System.out.println("--- Update Row 2 ---");
rs.updateFloat("PRICE", 10.99f);
rs.updateRow();
}

forward(rs);
} finally {
if (stmt != null) {
try {
stmt.close();
}
catch (SQLException sqlEx) {
System.out.println("closing statement failed");
}
}
if (conn != null) {
try {
conn.close();
}
catch (SQLException sqlEx) {
System.out.println("closing connection failed");
}
}
}

}
}


No file was uploaded with this report


---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

--1866420246-1934839611-1067852746=:29431
Content-Type: TEXT/PLAIN; charset=US-ASCII; name="previous_test.patch"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.LNX.4.33.0311030445460.29431 (AT) leary (DOT) csoft.net>
Content-Description:
Content-Disposition: attachment; filename="previous_test.patch"

SW5kZXg6IHNyYy9pbnRlcmZhY2VzL2pkYmMvb3JnL3Bvc3Rncm VzcWwvdGVz
dC9qZGJjMi9SZXN1bHRTZXRUZXN0LmphdmENCj09PT09PT09PT 09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT 09PT09PT09
PT09PT0NClJDUyBmaWxlOiAvcHJvamVjdHMvY3Zzcm9vdC9wZ3 NxbC1zZXJ2
ZXIvc3JjL2ludGVyZmFjZXMvamRiYy9vcmcvcG9zdGdyZXNxbC 90ZXN0L2pk
YmMyL1Jlc3VsdFNldFRlc3QuamF2YSx2DQpyZXRyaWV2aW5nIH JldmlzaW9u
IDEuMTENCmRpZmYgLWMgLXIxLjExIFJlc3VsdFNldFRlc3Quam F2YQ0KKioq
IHNyYy9pbnRlcmZhY2VzL2pkYmMvb3JnL3Bvc3RncmVzcWwvdG VzdC9qZGJj
Mi9SZXN1bHRTZXRUZXN0LmphdmEJMjMgU2VwIDIwMDMgMDY6MT E6MDYgLTAw
MDAJMS4xMQ0KLS0tIHNyYy9pbnRlcmZhY2VzL2pkYmMvb3JnL3 Bvc3RncmVz
cWwvdGVzdC9qZGJjMi9SZXN1bHRTZXRUZXN0LmphdmEJMyBOb3 YgMjAwMyAw
OTozOToyMSAtMDAwMA0KKioqKioqKioqKioqKioqDQoqKiogOD MsODggKioq
Kg0KLS0tIDgzLDk4IC0tLS0NCiAgCQlUZXN0VXRpbC5jbG9zZU RCKGNvbik7
DQogIAl9DQogIA0KKyAJcHVibGljIHZvaWQgdGVzdEJhY2t3YX JkKCkgdGhy
b3dzIEV4Y2VwdGlvbg0KKyAJew0KKyAJCVN0YXRlbWVudCBzdG 10ID0gY29u
LmNyZWF0ZVN0YXRlbWVudCgpOw0KKyAJCVJlc3VsdFNldCBycy A9IHN0bXQu
ZXhlY3V0ZVF1ZXJ5KCJTRUxFQ1QgKiBGUk9NIHRlc3RycyIpOw 0KKyAJCXJz
LmFmdGVyTGFzdCgpOw0KKyAJCWFzc2VydFRydWUocnMucHJldm lvdXMoKSk7
DQorIAkJcnMuY2xvc2UoKTsNCisgCQlzdG10LmNsb3NlKCk7DQ orIAl9DQor
IA0KICAJcHVibGljIHZvaWQgdGVzdEFic29sdXRlKCkgdGhyb3 dzIEV4Y2Vw
dGlvbg0KICAJew0KICAJCVN0YXRlbWVudCBzdG10ID0gY29uLm NyZWF0ZVN0
YXRlbWVudCgpOw0K

--1866420246-1934839611-1067852746=:29431
Content-Type: TEXT/PLAIN; charset=US-ASCII; name="previous_fix.patch"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.LNX.4.33.0311030445461.29431 (AT) leary (DOT) csoft.net>
Content-Description:
Content-Disposition: attachment; filename="previous_fix.patch"

SW5kZXg6IHNyYy9pbnRlcmZhY2VzL2pkYmMvb3JnL3Bvc3Rncm VzcWwvamRi
YzIvQWJzdHJhY3RKZGJjMlJlc3VsdFNldC5qYXZhDQo9PT09PT 09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT 09PT09PT09
PT09PT09PT09DQpSQ1MgZmlsZTogL3Byb2plY3RzL2N2c3Jvb3 QvcGdzcWwt
c2VydmVyL3NyYy9pbnRlcmZhY2VzL2pkYmMvb3JnL3Bvc3Rncm VzcWwvamRi
YzIvQWJzdHJhY3RKZGJjMlJlc3VsdFNldC5qYXZhLHYNCnJldH JpZXZpbmcg
cmV2aXNpb24gMS4yNQ0KZGlmZiAtYyAtcjEuMjUgQWJzdHJhY3 RKZGJjMlJl
c3VsdFNldC5qYXZhDQoqKiogc3JjL2ludGVyZmFjZXMvamRiYy 9vcmcvcG9z
dGdyZXNxbC9qZGJjMi9BYnN0cmFjdEpkYmMyUmVzdWx0U2V0Lm phdmEJMjkg
T2N0IDIwMDMgMDI6Mzk6MDkgLTAwMDAJMS4yNQ0KLS0tIHNyYy 9pbnRlcmZh
Y2VzL2pkYmMvb3JnL3Bvc3RncmVzcWwvamRiYzIvQWJzdHJhY3 RKZGJjMlJl
c3VsdFNldC5qYXZhCTMgTm92IDIwMDMgMDk6Mzg6NDUgLTAwMD ANCioqKioq
KioqKioqKioqKg0KKioqIDQ5Myw0OTggKioqKg0KLS0tIDQ5My w0OTkgLS0t
LQ0KICAJCWlmICgtLWN1cnJlbnRfcm93IDwgMCkNCiAgCQkJcm V0dXJuIGZh
bHNlOw0KICAJCXRoaXNfcm93ID0gKGJ5dGVbXVtdKSByb3dzLm VsZW1lbnRB
dChjdXJyZW50X3Jvdyk7DQorIAkJcm93QnVmZmVyID0gbmV3IG J5dGVbdGhp
c19yb3cubGVuZ3RoXVtdOw0KICAJCVN5c3RlbS5hcnJheWNvcH kodGhpc19y
b3csIDAsIHJvd0J1ZmZlciwgMCwgdGhpc19yb3cubGVuZ3RoKT sNCiAgCQly
ZXR1cm4gdHJ1ZTsNCiAgCX0NCg==

--1866420246-1934839611-1067852746=:29431
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
MIME-Version: 1.0


---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

--1866420246-1934839611-1067852746=:29431--


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.