Skip to content

Commit ed4f635

Browse files
committed
Fix for Bug#30474158, CONNECTOR/J 8 DOES NOT HONOR THE REQUESTED RESULTSETTYPE SCROLL_INSENSITIVE ETC.
1 parent 07369e8 commit ed4f635

File tree

11 files changed

+176
-66
lines changed

11 files changed

+176
-66
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
Version 8.0.20
55

6+
- Fix for Bug#30474158, CONNECTOR/J 8 DOES NOT HONOR THE REQUESTED RESULTSETTYPE SCROLL_INSENSITIVE ETC.
7+
68
- Fix for Bug#98445 (30832513), Connection option clientInfoProvider=ClientInfoProviderSP causes NPE.
79

810
- WL#12248, DevAPI: Connection compression.

src/main/core-api/java/com/mysql/cj/protocol/Resultset.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program is free software; you can redistribute it and/or modify it under
55
* the terms of the GNU General Public License, version 2.0, as published by the
@@ -56,7 +56,7 @@ public enum Concurrency {
5656
private int value;
5757

5858
private Concurrency(int jdbcRsConcur) {
59-
value = jdbcRsConcur;
59+
this.value = jdbcRsConcur;
6060
}
6161

6262
public int getIntValue() {

src/main/resources/com/mysql/cj/LocalizedErrorMessages.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ ResultSet.Illegal_operation_on_empty_result_set=Illegal operation on empty resul
397397

398398
ResultSet.Query_generated_no_fields_for_ResultSet_57=Query generated no fields for ResultSet
399399
ResultSet.Illegal_value_for_fetch_direction_64=Illegal value for fetch direction
400+
ResultSet.Unacceptable_value_for_fetch_direction=Fetch direction {0} cannot be set on a ResultSet of type ResultSet.TYPE_FORWARD_ONLY
400401
ResultSet.Value_must_be_between_0_and_getMaxRows()_66=Value must be between 0 and getMaxRows()
401402
ResultSet.Query_generated_no_fields_for_ResultSet_99=Query generated no fields for ResultSet
402403
ResultSet.Operation_not_allowed_after_ResultSet_closed_144=Operation not allowed after ResultSet closed
@@ -501,7 +502,7 @@ ResultSet.16=Can not call updateNCharacterStream() when field''s character set i
501502
ResultSet.17=Can not call updateNClob() when field''s character set isn''t UTF-8
502503
ResultSet.18=Can not call updateNString() when field''s character set isn''t UTF-8
503504

504-
ResultSet.ForwardOnly=Operation is not allowed for the result set with TYPE_FORWARD_ONLY type.
505+
ResultSet.ForwardOnly=Operation not allowed for a result set of type ResultSet.TYPE_FORWARD_ONLY.
505506

506507
ResultSetScannerInterceptor.0=resultSetScannerRegex must be configured, and must be > 0 characters
507508
ResultSetScannerInterceptor.1=Can''t use configured regex due to underlying exception.

src/main/user-impl/java/com/mysql/cj/jdbc/DatabaseMetaData.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program is free software; you can redistribute it and/or modify it under
55
* the terms of the GNU General Public License, version 2.0, as published by the
@@ -4693,12 +4693,12 @@ public boolean supportsResultSetConcurrency(int type, int concurrency) throws SQ
46934693

46944694
@Override
46954695
public boolean supportsResultSetHoldability(int holdability) throws SQLException {
4696-
return (holdability == ResultSet.HOLD_CURSORS_OVER_COMMIT);
4696+
return holdability == ResultSet.HOLD_CURSORS_OVER_COMMIT;
46974697
}
46984698

46994699
@Override
47004700
public boolean supportsResultSetType(int type) throws SQLException {
4701-
return (type == ResultSet.TYPE_SCROLL_INSENSITIVE); // TODO other types?
4701+
return type == ResultSet.TYPE_FORWARD_ONLY || type == ResultSet.TYPE_SCROLL_INSENSITIVE;
47024702
}
47034703

47044704
@Override
@@ -4898,7 +4898,7 @@ public boolean supportsStoredFunctionsUsingCallSyntax() throws SQLException {
48984898
*/
48994899
protected java.sql.PreparedStatement prepareMetaDataSafeStatement(String sql) throws SQLException {
49004900
// Can't use server-side here as we coerce a lot of types to match the spec.
4901-
java.sql.PreparedStatement pStmt = this.conn.clientPrepareStatement(sql);
4901+
java.sql.PreparedStatement pStmt = this.conn.clientPrepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
49024902

49034903
if (pStmt.getMaxRows() != 0) {
49044904
pStmt.setMaxRows(0);

src/main/user-impl/java/com/mysql/cj/jdbc/StatementImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program is free software; you can redistribute it and/or modify it under
55
* the terms of the GNU General Public License, version 2.0, as published by the
@@ -1933,7 +1933,7 @@ void setResultSetType(Resultset.Type typeFlag) throws SQLException {
19331933
}
19341934

19351935
void setResultSetType(int typeFlag) throws SQLException {
1936-
Type.fromValue(typeFlag, Type.FORWARD_ONLY);
1936+
this.query.setResultType(Type.fromValue(typeFlag, Type.FORWARD_ONLY));
19371937
}
19381938

19391939
protected void getBatchedGeneratedKeys(java.sql.Statement batchedStatement) throws SQLException {

src/main/user-impl/java/com/mysql/cj/jdbc/result/ResultSetImpl.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.sql.Date;
4545
import java.sql.NClob;
4646
import java.sql.Ref;
47+
import java.sql.ResultSet;
4748
import java.sql.RowId;
4849
import java.sql.SQLException;
4950
import java.sql.SQLFeatureNotSupportedException;
@@ -348,6 +349,9 @@ public void initializeWithMetadata() throws SQLException {
348349
@Override
349350
public boolean absolute(int row) throws SQLException {
350351
synchronized (checkClosed().getConnectionMutex()) {
352+
if (getType() == ResultSet.TYPE_FORWARD_ONLY) {
353+
throw ExceptionFactory.createException(Messages.getString("ResultSet.ForwardOnly"));
354+
}
351355

352356
boolean b;
353357

@@ -393,6 +397,9 @@ public boolean absolute(int row) throws SQLException {
393397
@Override
394398
public void afterLast() throws SQLException {
395399
synchronized (checkClosed().getConnectionMutex()) {
400+
if (getType() == ResultSet.TYPE_FORWARD_ONLY) {
401+
throw ExceptionFactory.createException(Messages.getString("ResultSet.ForwardOnly"));
402+
}
396403

397404
if (this.rowData.size() != 0) {
398405
this.rowData.afterLast();
@@ -406,6 +413,9 @@ public void afterLast() throws SQLException {
406413
@Override
407414
public void beforeFirst() throws SQLException {
408415
synchronized (checkClosed().getConnectionMutex()) {
416+
if (getType() == ResultSet.TYPE_FORWARD_ONLY) {
417+
throw ExceptionFactory.createException(Messages.getString("ResultSet.ForwardOnly"));
418+
}
409419

410420
if (this.rowData.size() == 0) {
411421
return;
@@ -558,6 +568,9 @@ public int findColumn(String columnName) throws SQLException {
558568
@Override
559569
public boolean first() throws SQLException {
560570
synchronized (checkClosed().getConnectionMutex()) {
571+
if (getType() == ResultSet.TYPE_FORWARD_ONLY) {
572+
throw ExceptionFactory.createException(Messages.getString("ResultSet.ForwardOnly"));
573+
}
561574

562575
boolean b = true;
563576

@@ -1682,6 +1695,9 @@ public boolean isLast() throws SQLException {
16821695
@Override
16831696
public boolean last() throws SQLException {
16841697
synchronized (checkClosed().getConnectionMutex()) {
1698+
if (getType() == ResultSet.TYPE_FORWARD_ONLY) {
1699+
throw ExceptionFactory.createException(Messages.getString("ResultSet.ForwardOnly"));
1700+
}
16851701

16861702
boolean b = true;
16871703

@@ -1785,6 +1801,10 @@ public boolean prev() throws java.sql.SQLException {
17851801
@Override
17861802
public boolean previous() throws SQLException {
17871803
synchronized (checkClosed().getConnectionMutex()) {
1804+
if (getType() == ResultSet.TYPE_FORWARD_ONLY) {
1805+
throw ExceptionFactory.createException(Messages.getString("ResultSet.ForwardOnly"));
1806+
}
1807+
17881808
return prev();
17891809
}
17901810
}
@@ -1903,6 +1923,9 @@ public void refreshRow() throws SQLException {
19031923
@Override
19041924
public boolean relative(int rows) throws SQLException {
19051925
synchronized (checkClosed().getConnectionMutex()) {
1926+
if (getType() == ResultSet.TYPE_FORWARD_ONLY) {
1927+
throw ExceptionFactory.createException(Messages.getString("ResultSet.ForwardOnly"));
1928+
}
19061929

19071930
if (this.rowData.size() == 0) {
19081931
setRowPositionValidity();
@@ -1942,6 +1965,11 @@ public void setFetchDirection(int direction) throws SQLException {
19421965
MysqlErrorNumbers.SQL_STATE_ILLEGAL_ARGUMENT, getExceptionInterceptor());
19431966
}
19441967

1968+
if (getType() == ResultSet.TYPE_FORWARD_ONLY && direction != FETCH_FORWARD) {
1969+
String constName = direction == ResultSet.FETCH_REVERSE ? "ResultSet.FETCH_REVERSE" : "ResultSet.FETCH_UNKNOWN";
1970+
throw ExceptionFactory.createException(Messages.getString("ResultSet.Unacceptable_value_for_fetch_direction", new Object[] { constName }));
1971+
}
1972+
19451973
this.fetchDirection = direction;
19461974
}
19471975
}

src/main/user-impl/java/com/mysql/cj/jdbc/result/UpdatableResultSet.java

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program is free software; you can redistribute it and/or modify it under
55
* the terms of the GNU General Public License, version 2.0, as published by the
@@ -36,6 +36,7 @@
3636
import java.sql.Clob;
3737
import java.sql.JDBCType;
3838
import java.sql.NClob;
39+
import java.sql.ResultSet;
3940
import java.sql.SQLException;
4041
import java.sql.SQLType;
4142
import java.sql.SQLXML;
@@ -50,6 +51,7 @@
5051
import com.mysql.cj.conf.PropertyDefinitions.DatabaseTerm;
5152
import com.mysql.cj.conf.PropertyKey;
5253
import com.mysql.cj.exceptions.AssertionFailedException;
54+
import com.mysql.cj.exceptions.ExceptionFactory;
5355
import com.mysql.cj.exceptions.FeatureNotAvailableException;
5456
import com.mysql.cj.exceptions.MysqlErrorNumbers;
5557
import com.mysql.cj.jdbc.ClientPreparedStatement;
@@ -155,40 +157,36 @@ public UpdatableResultSet(ResultsetRows tuples, JdbcConnection conn, StatementIm
155157

156158
@Override
157159
public boolean absolute(int row) throws SQLException {
160+
boolean ret = super.absolute(row);
158161
if (this.onInsertRow) {
159162
this.onInsertRow = false;
160163
}
161-
162164
if (this.doingUpdates) {
163165
this.doingUpdates = false;
164166
}
165-
return super.absolute(row);
167+
return ret;
166168
}
167169

168170
@Override
169171
public void afterLast() throws SQLException {
172+
super.afterLast();
170173
if (this.onInsertRow) {
171174
this.onInsertRow = false;
172175
}
173-
174176
if (this.doingUpdates) {
175177
this.doingUpdates = false;
176178
}
177-
178-
super.afterLast();
179179
}
180180

181181
@Override
182182
public void beforeFirst() throws SQLException {
183+
super.beforeFirst();
183184
if (this.onInsertRow) {
184185
this.onInsertRow = false;
185186
}
186-
187187
if (this.doingUpdates) {
188188
this.doingUpdates = false;
189189
}
190-
191-
super.beforeFirst();
192190
}
193191

194192
@Override
@@ -429,7 +427,7 @@ public void deleteRow() throws SQLException {
429427
this.deleter.executeUpdate();
430428
this.rowData.remove();
431429

432-
previous(); // position on previous row - Bug#27431
430+
prev(); // position on previous row - Bug#27431
433431
}
434432
}
435433

@@ -541,15 +539,14 @@ private void extractDefaultValues() throws SQLException {
541539

542540
@Override
543541
public boolean first() throws SQLException {
542+
boolean ret = super.first();
544543
if (this.onInsertRow) {
545544
this.onInsertRow = false;
546545
}
547-
548546
if (this.doingUpdates) {
549547
this.doingUpdates = false;
550548
}
551-
552-
return super.first();
549+
return ret;
553550
}
554551

555552
/**
@@ -784,15 +781,14 @@ boolean isUpdatable() {
784781

785782
@Override
786783
public boolean last() throws SQLException {
784+
boolean ret = super.last();
787785
if (this.onInsertRow) {
788786
this.onInsertRow = false;
789787
}
790-
791788
if (this.doingUpdates) {
792789
this.doingUpdates = false;
793790
}
794-
795-
return super.last();
791+
return ret;
796792
}
797793

798794
@Override
@@ -885,33 +881,38 @@ public void moveToInsertRow() throws SQLException {
885881

886882
@Override
887883
public boolean next() throws SQLException {
884+
boolean ret = super.next();
888885
if (this.onInsertRow) {
889886
this.onInsertRow = false;
890887
}
891-
892888
if (this.doingUpdates) {
893889
this.doingUpdates = false;
894890
}
895-
896-
return super.next();
891+
return ret;
897892
}
898893

899894
@Override
900895
public boolean prev() throws SQLException {
901-
return super.prev();
896+
boolean ret = super.prev();
897+
if (this.onInsertRow) {
898+
this.onInsertRow = false;
899+
}
900+
if (this.doingUpdates) {
901+
this.doingUpdates = false;
902+
}
903+
return ret;
902904
}
903905

904906
@Override
905907
public boolean previous() throws SQLException {
908+
boolean ret = super.previous();
906909
if (this.onInsertRow) {
907910
this.onInsertRow = false;
908911
}
909-
910912
if (this.doingUpdates) {
911913
this.doingUpdates = false;
912914
}
913-
914-
return super.previous();
915+
return ret;
915916
}
916917

917918
@Override
@@ -973,6 +974,10 @@ public void realClose(boolean calledExplicitly) throws SQLException {
973974
@Override
974975
public void refreshRow() throws SQLException {
975976
synchronized (checkClosed().getConnectionMutex()) {
977+
if (getType() == ResultSet.TYPE_FORWARD_ONLY) {
978+
throw ExceptionFactory.createException(Messages.getString("ResultSet.ForwardOnly"));
979+
}
980+
976981
if (!this.isUpdatable) {
977982
throw new NotUpdatable(Messages.getString("NotUpdatable.0"));
978983
}
@@ -1073,7 +1078,14 @@ private void refreshRow(ClientPreparedStatement updateInsertStmt, Row rowToRefre
10731078

10741079
@Override
10751080
public boolean relative(int rows) throws SQLException {
1076-
return super.relative(rows);
1081+
boolean ret = super.relative(rows);
1082+
if (this.onInsertRow) {
1083+
this.onInsertRow = false;
1084+
}
1085+
if (this.doingUpdates) {
1086+
this.doingUpdates = false;
1087+
}
1088+
return ret;
10771089
}
10781090

10791091
private void resetInserter() throws SQLException {
@@ -1171,7 +1183,7 @@ public void updateRow() throws SQLException {
11711183

11721184
if (this.doingUpdates) {
11731185
this.updater.executeUpdate();
1174-
refreshRow();
1186+
refreshRow(this.updater, this.thisRow);
11751187
this.doingUpdates = false;
11761188
} else if (this.onInsertRow) {
11771189
throw SQLError.createSQLException(Messages.getString("UpdatableResultSet.44"), getExceptionInterceptor());

src/test/java/testsuite/BaseTestCase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program is free software; you can redistribute it and/or modify it under
55
* the terms of the GNU General Public License, version 2.0, as published by the
@@ -666,7 +666,7 @@ public void setUp() throws Exception {
666666

667667
this.serverVersion = ((JdbcConnection) this.conn).getServerVersion();
668668

669-
this.stmt = this.conn.createStatement();
669+
this.stmt = this.conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
670670

671671
try {
672672
if (dbUrl.indexOf("mysql") != -1) {

0 commit comments

Comments
 (0)