Skip to content

Commit 7129230

Browse files
committed
- Fixed critical bug in the javaxt.sql.Recordset class retrieving records from a PostgreSQL database with the setFetchSize() method.
- Added new javaxt.sql.Value.toDate() method to make it easier to retrieve arrays. - Updated logic in the Value.toDate() to improve performance. git-svn-id: svn://192.168.0.80/JavaXT/javaxt-core@680 2c7b0aa6-e0b2-3c4e-bb4a-8b65b6c465ff
1 parent 0a77390 commit 7129230

File tree

3 files changed

+63
-27
lines changed

3 files changed

+63
-27
lines changed

src/javaxt/sql/Recordset.java

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -385,24 +385,22 @@ else if (driver.equals("DB2")){
385385
/** Closes the Recordset freeing up database and jdbc resources. */
386386

387387
public void close(){
388+
388389
if (State==1){
389390
try{
390391
executeBatch();
391392
rs.close();
392393
stmt.close();
393394
State = 0;
395+
Conn.setAutoCommit(autoCommit);
394396
}
395397
catch(java.sql.SQLException e){
396398
e.printStackTrace();
397399
}
398400
}
399401

400402

401-
//Restore autoCommit setting
402-
try{
403-
Conn.setAutoCommit(autoCommit);
404-
}
405-
catch(Exception e){}
403+
406404

407405

408406
rs = null;
@@ -892,8 +890,10 @@ private int executeBatch() throws java.sql.SQLException{
892890

893891
int[] rowsUpdated = stmt.executeBatch();
894892
if (rowsUpdated.length>0) ttl+=rowsUpdated.length;
895-
896-
Conn.commit();
893+
894+
if (Conn.getAutoCommit()==false){
895+
Conn.commit();
896+
}
897897
}
898898
batchedStatements.clear();
899899
numBatches = 0;
@@ -1155,10 +1155,12 @@ public boolean moveNext(){
11551155
}
11561156
}
11571157
catch(Exception e){
1158+
EOF = true;
1159+
return false;
11581160
//System.out.println("ERROR MoveNext: " + e.toString());
11591161
}
11601162
}
1161-
return false;
1163+
//return false;
11621164
}
11631165

11641166

@@ -1372,14 +1374,14 @@ public int getRecordCount(){
13721374
}
13731375

13741376

1375-
//**************************************************************************
1376-
//** Finalize
1377-
//**************************************************************************
1378-
/** Method *should* be called by Java garbage collector once this class is
1379-
* disposed.
1380-
*/
1381-
protected void finalize() throws Throwable {
1382-
close();
1383-
super.finalize();
1384-
}
1377+
// //**************************************************************************
1378+
// //** Finalize
1379+
// //**************************************************************************
1380+
// /** Method *should* be called by Java garbage collector once this class is
1381+
// * disposed.
1382+
// */
1383+
// protected void finalize() throws Throwable {
1384+
// close();
1385+
// super.finalize();
1386+
// }
13851387
}

src/javaxt/sql/Value.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,29 @@ protected Value(Object value){
2222
}
2323

2424
public java.sql.Timestamp toTimeStamp(){
25-
javaxt.utils.Date date = toDate();
26-
if (date==null) return null;
27-
else return new java.sql.Timestamp(date.getDate().getTime());
25+
Object obj = super.toObject();
26+
if (obj!=null){
27+
if (obj instanceof java.sql.Timestamp){
28+
return (java.sql.Timestamp) obj;
29+
}
30+
else{
31+
javaxt.utils.Date date = toDate();
32+
return new java.sql.Timestamp(date.getDate().getTime());
33+
}
34+
}
35+
return null;
36+
}
37+
38+
public Object toArray(){
39+
Object obj = super.toObject();
40+
if (obj!=null){
41+
try{
42+
return ((java.sql.Array) obj).getArray();
43+
}
44+
catch(Exception e){
45+
}
46+
}
47+
48+
return null;
2849
}
2950
}

src/javaxt/utils/Value.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,26 @@ public Float toFloat(){
137137
* converting the value to a Date or if the value is null.
138138
*/
139139
public javaxt.utils.Date toDate(){
140-
if (value==null) return null;
141-
try{
142-
return new javaxt.utils.Date(value.toString());
143-
}
144-
catch(Exception e){
145-
return null;
140+
if (value!=null){
141+
if (value instanceof java.sql.Timestamp){
142+
java.sql.Timestamp ts = (java.sql.Timestamp) value;
143+
return new javaxt.utils.Date(ts.getTime());
144+
}
145+
else if (value instanceof java.util.Date){
146+
return new javaxt.utils.Date((java.util.Date) value);
147+
}
148+
else if (value instanceof java.util.Calendar){
149+
return new javaxt.utils.Date((java.util.Calendar) value);
150+
}
151+
else{
152+
try{
153+
return new javaxt.utils.Date(value.toString());
154+
}
155+
catch(Exception e){
156+
}
157+
}
146158
}
159+
return null;
147160
}
148161

149162

0 commit comments

Comments
 (0)