Skip to content

Commit 354b711

Browse files
committed
[misc] coverage addition
1 parent 25b1717 commit 354b711

17 files changed

+266
-136
lines changed

src/main/java/org/mariadb/jdbc/BaseCallableStatement.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -510,9 +510,7 @@ public Object getObject(int parameterIndex, Map<String, Class<?>> map) throws SQ
510510
*/
511511
@Override
512512
public Ref getRef(int parameterIndex) throws SQLException {
513-
checkNotClosed();
514-
checkOutputResult();
515-
return outputResult.getRef(idxToOutIdx(parameterIndex));
513+
throw exceptionFactory().notSupported("Method ResultSet.getRef not supported");
516514
}
517515

518516
/**
@@ -569,7 +567,7 @@ public Clob getClob(int parameterIndex) throws SQLException {
569567
public Array getArray(int parameterIndex) throws SQLException {
570568
checkNotClosed();
571569
checkOutputResult();
572-
return outputResult.getArray(idxToOutIdx(parameterIndex));
570+
throw exceptionFactory().notSupported("Method ResultSet.getArray not supported");
573571
}
574572

575573
/**
@@ -714,7 +712,7 @@ public void registerOutParameter(String parameterName, int sqlType) throws SQLEx
714712
}
715713

716714
private int nameToIndex(String parameterName) throws SQLException {
717-
if (parameterName == null) throw exceptionFactory().create("parameterName cannot be null");
715+
if (parameterName == null) throw exceptionFactory().create("parameter name cannot be null");
718716
if (parameterMetaData == null) parameterMetaData = getParameterMetaData();
719717

720718
int count = parameterMetaData.getParameterCount();
@@ -724,7 +722,7 @@ private int nameToIndex(String parameterName) throws SQLException {
724722
return i;
725723
}
726724
}
727-
throw exceptionFactory().create(String.format("parameterName %s not found", parameterName));
725+
throw exceptionFactory().create(String.format("parameter name %s not found", parameterName));
728726
}
729727

730728
/**
@@ -1637,7 +1635,7 @@ public Object getObject(String parameterName, Map<String, Class<?>> map) throws
16371635
*/
16381636
@Override
16391637
public Ref getRef(String parameterName) throws SQLException {
1640-
return outputResult.getRef(idxToOutIdx(nameToIndex(parameterName)));
1638+
throw exceptionFactory().notSupported("Method ResultSet.getRef not supported");
16411639
}
16421640

16431641
/**
@@ -1688,7 +1686,7 @@ public Clob getClob(String parameterName) throws SQLException {
16881686
*/
16891687
@Override
16901688
public Array getArray(String parameterName) throws SQLException {
1691-
return outputResult.getArray(idxToOutIdx(nameToIndex(parameterName)));
1689+
throw exceptionFactory().notSupported("Method ResultSet.getArray not supported");
16921690
}
16931691

16941692
/**
@@ -2048,7 +2046,7 @@ public SQLXML getSQLXML(int parameterIndex) throws SQLException {
20482046
*/
20492047
@Override
20502048
public SQLXML getSQLXML(String parameterName) throws SQLException {
2051-
return getSQLXML(nameToIndex(parameterName));
2049+
throw exceptionFactory().notSupported("SQLXML are not supported");
20522050
}
20532051

20542052
/**

src/main/java/org/mariadb/jdbc/CallableParameterMetaData.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ public String getParameterName(int index) throws SQLException {
121121
@Override
122122
public int getParameterType(int index) throws SQLException {
123123
setIndex(index);
124-
String str = rs.getString("DATA_TYPE");
125-
switch (str.toUpperCase(Locale.ROOT)) {
124+
String str = rs.getString("DATA_TYPE").toUpperCase(Locale.ROOT);
125+
switch (str) {
126126
case "BIT":
127127
return Types.BIT;
128128
case "TINYINT":

src/main/java/org/mariadb/jdbc/ClientPreparedStatement.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,9 @@ public boolean execute() throws SQLException {
204204
@Override
205205
public ResultSet executeQuery() throws SQLException {
206206
executeInternal();
207-
if (!results.isEmpty()) {
208-
currResult = results.remove(0);
209-
if (currResult instanceof Result) return (Result) currResult;
207+
currResult = results.remove(0);
208+
if (currResult instanceof Result) {
209+
return (Result) currResult;
210210
}
211211
return new CompleteResult(new ColumnDefinitionPacket[0], new byte[0][], con.getContext());
212212
}

src/main/java/org/mariadb/jdbc/Connection.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public Statement createStatement() {
9898
lock,
9999
canUseServerTimeout,
100100
canUseServerMaxRows,
101-
Statement.NO_GENERATED_KEYS,
101+
Statement.RETURN_GENERATED_KEYS,
102102
ResultSet.TYPE_FORWARD_ONLY,
103103
ResultSet.CONCUR_READ_ONLY,
104104
defaultFetchSize);
@@ -406,7 +406,7 @@ public Statement createStatement(int resultSetType, int resultSetConcurrency)
406406
lock,
407407
canUseServerTimeout,
408408
canUseServerMaxRows,
409-
Statement.NO_GENERATED_KEYS,
409+
Statement.RETURN_GENERATED_KEYS,
410410
resultSetType,
411411
resultSetConcurrency,
412412
defaultFetchSize);
@@ -417,7 +417,7 @@ public PreparedStatement prepareStatement(String sql, int resultSetType, int res
417417
throws SQLException {
418418
return prepareInternal(
419419
sql,
420-
Statement.NO_GENERATED_KEYS,
420+
Statement.RETURN_GENERATED_KEYS,
421421
resultSetType,
422422
resultSetConcurrency,
423423
conf.useServerPrepStmts());

src/main/java/org/mariadb/jdbc/ServerPreparedStatement.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,6 @@ public ServerPreparedStatement(
6464
resultSetConcurrency,
6565
defaultFetchSize);
6666

67-
// MySQL server doesn't permit pipelining
68-
if (!con.getContext().getVersion().isMariaDBServer()) {
69-
prepareIfNotAlready(escapeTimeout(sql));
70-
}
7167
parameters = new ParameterList();
7268
}
7369

@@ -95,6 +91,8 @@ protected void executeInternal() throws SQLException {
9591
} else {
9692
executeStandard(cmd);
9793
}
94+
} catch (BatchUpdateException b) {
95+
throw (SQLException) b.getCause();
9896
} finally {
9997
parameters = new ParameterList();
10098
lock.unlock();

src/main/java/org/mariadb/jdbc/Statement.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,7 @@ public int[] executeBatch() throws SQLException {
687687
try {
688688
List<Completion> res = executeInternalBatch();
689689
results = res;
690+
690691
int[] updates = new int[res.size()];
691692
for (int i = 0; i < res.size(); i++) {
692693
updates[i] = (int) ((OkPacket) res.get(i)).getAffectedRows();
@@ -822,9 +823,16 @@ public ResultSet getGeneratedKeys() throws SQLException {
822823

823824
if (currResult instanceof OkPacket) {
824825
OkPacket ok = ((OkPacket) currResult);
825-
String lastInsertId = String.valueOf(ok.getLastInsertId());
826-
return CompleteResult.createResultSet(
827-
"insert_id", DataType.BIGINT, new String[] {lastInsertId}, con.getContext());
826+
List<String[]> insertIds = new ArrayList<>();
827+
insertIds.add(new String[] {String.valueOf(ok.getLastInsertId())});
828+
for (int i = 0; i < results.size(); i++) {
829+
if (results.get(i) instanceof OkPacket) {
830+
insertIds.add(
831+
new String[] {String.valueOf(((OkPacket) results.get(i)).getLastInsertId())});
832+
}
833+
}
834+
String[][] ids = insertIds.toArray(new String[0][]);
835+
return CompleteResult.createResultSet("insert_id", DataType.BIGINT, ids, con.getContext());
828836
}
829837

830838
return new CompleteResult(new ColumnDefinitionPacket[0], new byte[0][], con.getContext());

src/main/java/org/mariadb/jdbc/client/result/CompleteResult.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,8 @@ public CompleteResult(ColumnDefinitionPacket[] metadataList, byte[][] data, Cont
7474
}
7575

7676
public static ResultSet createResultSet(
77-
String columnName, DataType columnType, String[] data, Context context) {
78-
return createResultSet(
79-
new String[] {columnName}, new DataType[] {columnType}, new String[][] {data}, context);
77+
String columnName, DataType columnType, String[][] data, Context context) {
78+
return createResultSet(new String[] {columnName}, new DataType[] {columnType}, data, context);
8079
}
8180

8281
/**

src/main/java/org/mariadb/jdbc/client/result/Result.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,8 +849,11 @@ public void useAliasAsName() {
849849

850850
@Override
851851
public Object getObject(int columnIndex, Map<String, Class<?>> map) throws SQLException {
852+
if (map == null || map.isEmpty()) {
853+
return getObject(columnIndex);
854+
}
852855
throw exceptionFactory.notSupported(
853-
"Method ResultSet.getObject(int columnIndex, Map<String, Class<?>> map) not supported");
856+
"Method ResultSet.getObject(int columnIndex, Map<String, Class<?>> map) not supported for non empty map");
854857
}
855858

856859
@Override
@@ -875,6 +878,9 @@ public Array getArray(int columnIndex) throws SQLException {
875878

876879
@Override
877880
public Object getObject(String columnLabel, Map<String, Class<?>> map) throws SQLException {
881+
if (map == null || map.isEmpty()) {
882+
return getObject(columnLabel);
883+
}
878884
throw exceptionFactory.notSupported(
879885
"Method ResultSet.getObject(String columnLabel, Map<String, Class<?>> map) not supported");
880886
}

src/test/java/org/mariadb/jdbc/integration/BatchTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ public void largeBatch(Connection con) throws SQLException {
176176
@Test
177177
public void bulkPacketSplitMaxAllowedPacket() throws SQLException {
178178
int maxAllowedPacket = getMaxAllowedPacket();
179-
System.out.println("maxAllowedPacket:" + maxAllowedPacket);
180179
bulkPacketSplit(2, maxAllowedPacket - 40);
181180
}
182181

src/test/java/org/mariadb/jdbc/integration/ConfigurationTest.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,10 @@ public void testSessionVariable() throws SQLException {
6060

6161
assertTrue(rs.next());
6262
assertEquals(1, rs.getInt(1));
63-
assertFalse(rs.next());
64-
65-
stmt.getMoreResults();
66-
67-
rs = stmt.getGeneratedKeys();
6863
assertTrue(rs.next());
6964
assertEquals(5, rs.getInt(1));
7065
assertFalse(rs.next());
66+
assertFalse(stmt.getMoreResults());
7167
}
7268

7369
try (Connection connection =

0 commit comments

Comments
 (0)