diff --git a/src/main/java/org/mariadb/jdbc/ClientPreparedStatement.java b/src/main/java/org/mariadb/jdbc/ClientPreparedStatement.java index 21c45c2e9..64dcf039c 100644 --- a/src/main/java/org/mariadb/jdbc/ClientPreparedStatement.java +++ b/src/main/java/org/mariadb/jdbc/ClientPreparedStatement.java @@ -117,9 +117,9 @@ private void executeInternalPreparedBatch() throws SQLException { if (possibleLoadLocal) { String sqlUpper = sql.toUpperCase(Locale.ROOT); possibleLoadLocal = - sqlUpper.contains(" LOCAL ") - && sqlUpper.contains("LOAD") - && sqlUpper.contains(" INFILE"); + sqlUpper.contains(" LOCAL ") + && sqlUpper.contains("LOAD") + && sqlUpper.contains(" INFILE"); } if (possibleLoadLocal) { executeBatchStd(); diff --git a/src/main/java/org/mariadb/jdbc/ServerPreparedStatement.java b/src/main/java/org/mariadb/jdbc/ServerPreparedStatement.java index 6f83740e6..af214225d 100644 --- a/src/main/java/org/mariadb/jdbc/ServerPreparedStatement.java +++ b/src/main/java/org/mariadb/jdbc/ServerPreparedStatement.java @@ -11,7 +11,6 @@ import java.util.concurrent.locks.ReentrantLock; import java.util.regex.Pattern; import org.mariadb.jdbc.client.Completion; -import org.mariadb.jdbc.client.Context; import org.mariadb.jdbc.client.result.CompleteResult; import org.mariadb.jdbc.client.result.Result; import org.mariadb.jdbc.client.util.Parameters; diff --git a/src/main/java/org/mariadb/jdbc/Statement.java b/src/main/java/org/mariadb/jdbc/Statement.java index 4ea666035..be96ba42e 100644 --- a/src/main/java/org/mariadb/jdbc/Statement.java +++ b/src/main/java/org/mariadb/jdbc/Statement.java @@ -4,6 +4,8 @@ package org.mariadb.jdbc; +import static org.mariadb.jdbc.util.constants.Capabilities.LOCAL_FILES; + import java.sql.*; import java.util.ArrayList; import java.util.List; @@ -20,8 +22,6 @@ import org.mariadb.jdbc.util.NativeSql; import org.mariadb.jdbc.util.constants.ServerStatus; -import static org.mariadb.jdbc.util.constants.Capabilities.LOCAL_FILES; - /** Statement implementation */ public class Statement implements java.sql.Statement { @@ -709,9 +709,7 @@ public int[] executeBatch() throws SQLException { } List res = - possibleLoadLocal - ? executeInternalBatchStandard() - : executeInternalBatchPipeline(); + possibleLoadLocal ? executeInternalBatchStandard() : executeInternalBatchPipeline(); results = res; @@ -857,10 +855,10 @@ public ResultSet getGeneratedKeys() throws SQLException { OkPacket ok = ((OkPacket) currResult); if (ok.getLastInsertId() != 0) { List insertIds = new ArrayList<>(); - insertIds.add(new String[]{String.valueOf(ok.getLastInsertId())}); + insertIds.add(new String[] {String.valueOf(ok.getLastInsertId())}); for (Completion result : results) { if (result instanceof OkPacket) { - insertIds.add(new String[]{String.valueOf(((OkPacket) result).getLastInsertId())}); + insertIds.add(new String[] {String.valueOf(((OkPacket) result).getLastInsertId())}); } } String[][] ids = insertIds.toArray(new String[0][]); @@ -1460,9 +1458,7 @@ public long[] executeLargeBatch() throws SQLException { } List res = - possibleLoadLocal - ? executeInternalBatchStandard() - : executeInternalBatchPipeline(); + possibleLoadLocal ? executeInternalBatchStandard() : executeInternalBatchPipeline(); results = res; long[] updates = new long[res.size()]; diff --git a/src/main/java/org/mariadb/jdbc/message/server/ColumnDefinitionPacket.java b/src/main/java/org/mariadb/jdbc/message/server/ColumnDefinitionPacket.java index 6d54603df..7440c4c3d 100644 --- a/src/main/java/org/mariadb/jdbc/message/server/ColumnDefinitionPacket.java +++ b/src/main/java/org/mariadb/jdbc/message/server/ColumnDefinitionPacket.java @@ -509,7 +509,8 @@ public Codec getDefaultCodec(Configuration conf) { if (conf.yearIsDateType()) return DateCodec.INSTANCE; return ShortCodec.INSTANCE; case BIT: - return BitSetCodec.INSTANCE; + if (this.length == 1) return BooleanCodec.INSTANCE; + return ByteArrayCodec.INSTANCE; } throw new IllegalArgumentException(String.format("Unexpected datatype %s", dataType)); } diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/ByteArrayCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/ByteArrayCodec.java index 74f28b227..8e079e156 100644 --- a/src/main/java/org/mariadb/jdbc/plugin/codec/ByteArrayCodec.java +++ b/src/main/java/org/mariadb/jdbc/plugin/codec/ByteArrayCodec.java @@ -38,7 +38,7 @@ public class ByteArrayCodec implements Codec { DataType.STRING); public String className() { - return byte[].class.getName(); + return "byte[]"; } public boolean canDecode(Column column, Class type) { @@ -59,6 +59,7 @@ public byte[] decodeText(ReadableByteBuf buf, int length, Column column, Calenda private byte[] getBytes(ReadableByteBuf buf, int length, Column column) throws SQLDataException { switch (column.getType()) { + case BIT: case BLOB: case TINYBLOB: case MEDIUMBLOB: diff --git a/src/test/java/org/mariadb/jdbc/integration/StatementTest.java b/src/test/java/org/mariadb/jdbc/integration/StatementTest.java index 6b0aa02c7..ae4e31ea7 100644 --- a/src/test/java/org/mariadb/jdbc/integration/StatementTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/StatementTest.java @@ -53,12 +53,16 @@ public static void beforeAll2() throws SQLException { public void ensureGetGeneratedKeysReturnsEmptyResult() throws SQLException { Statement stmt = sharedConn.createStatement(); stmt.execute("CREATE TABLE IF NOT EXISTS key_test (id INT(11) NOT NULL)"); - try (PreparedStatement ps = sharedConn.prepareStatement("INSERT INTO key_test(id) VALUES(5)", Statement.RETURN_GENERATED_KEYS)) { + try (PreparedStatement ps = + sharedConn.prepareStatement( + "INSERT INTO key_test(id) VALUES(5)", Statement.RETURN_GENERATED_KEYS)) { ps.execute(); ResultSet rs = ps.getGeneratedKeys(); assertFalse(rs.next()); } - try (PreparedStatement ps = sharedConn.prepareStatement("UPDATE key_test set id=7 WHERE id=5", Statement.RETURN_GENERATED_KEYS)) { + try (PreparedStatement ps = + sharedConn.prepareStatement( + "UPDATE key_test set id=7 WHERE id=5", Statement.RETURN_GENERATED_KEYS)) { ps.execute(); ResultSet rs = ps.getGeneratedKeys(); assertFalse(rs.next()); @@ -913,7 +917,8 @@ public void ensureClassDefined() { Type it = codec.getClass().getGenericInterfaces()[0]; ParameterizedType parameterizedType = (ParameterizedType) it; Type typeParameter = parameterizedType.getActualTypeArguments()[0]; - assertEquals(((Class) typeParameter).getName(), codec.className()); + if (!"byte[]".equals(codec.className())) + assertEquals(((Class) typeParameter).getName(), codec.className()); } } diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/BitCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/BitCodecTest.java index 3fecb3344..a6ec6d78c 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/BitCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/BitCodecTest.java @@ -76,12 +76,12 @@ public void getObjectPrepare() throws SQLException { } public void getObject(ResultSet rs) throws SQLException { - assertEquals(BitSet.valueOf(new byte[] {(byte) 0}), rs.getObject(1)); + assertEquals(false, rs.getObject(1)); assertFalse(rs.wasNull()); - assertEquals(BitSet.valueOf(new byte[] {(byte) 1}), rs.getObject(2)); - assertEquals(BitSet.valueOf(new byte[] {(byte) 1}), rs.getObject("t2alias")); + assertArrayEquals(new byte[] {(byte) 1}, (byte[]) rs.getObject(2)); + assertArrayEquals(new byte[] {(byte) 1}, (byte[]) rs.getObject("t2alias")); assertFalse(rs.wasNull()); - assertEquals(BitSet.valueOf(new byte[] {(byte) 4, (byte) 15}), rs.getObject(3)); + assertArrayEquals(new byte[] {(byte) 15, (byte) 4}, (byte[]) rs.getObject(3)); assertFalse(rs.wasNull()); assertNull(rs.getObject(4)); assertTrue(rs.wasNull()); @@ -112,7 +112,7 @@ public void getObjectType(ResultSet rs) throws Exception { testErrObject(rs, Double.class); testErrObject(rs, Float.class); testObject(rs, Byte.class, (byte) 0); - testErrObject(rs, byte[].class); + testObject(rs, byte[].class, new byte[] {0}); testErrObject(rs, Date.class); testErrObject(rs, Time.class); testErrObject(rs, Timestamp.class); @@ -510,13 +510,16 @@ public void getBytesPrepare() throws SQLException { getBytes(getPrepare(sharedConnBinary)); } - public void getBytes(ResultSet rs) { - Common.assertThrowsContains( - SQLDataException.class, () -> rs.getBytes(1), "Data type BIT cannot be decoded as byte[]"); - Common.assertThrowsContains( - SQLDataException.class, - () -> rs.getBytes("t1alias"), - "Data type BIT cannot be decoded as byte[]"); + public void getBytes(ResultSet rs) throws SQLException { + assertArrayEquals(new byte[] {(byte) 0}, rs.getBytes(1)); + assertFalse(rs.wasNull()); + assertArrayEquals(new byte[] {(byte) 1}, rs.getBytes(2)); + assertArrayEquals(new byte[] {(byte) 1}, rs.getBytes("t2alias")); + assertFalse(rs.wasNull()); + assertArrayEquals(new byte[] {(byte) 15, (byte) 4}, rs.getBytes(3)); + assertFalse(rs.wasNull()); + assertNull(rs.getObject(4)); + assertTrue(rs.wasNull()); } @Test @@ -651,15 +654,26 @@ public void getMetaData() throws SQLException { ResultSetMetaData meta = rs.getMetaData(); assertEquals("BIT", meta.getColumnTypeName(1)); assertEquals(sharedConn.getCatalog(), meta.getCatalogName(1)); - assertEquals("java.util.BitSet", meta.getColumnClassName(1)); + assertEquals("java.lang.Boolean", meta.getColumnClassName(1)); assertEquals("t1alias", meta.getColumnLabel(1)); assertEquals("t1", meta.getColumnName(1)); - assertEquals(Types.BIT, meta.getColumnType(1)); + assertEquals(Types.BOOLEAN, meta.getColumnType(1)); assertEquals(4, meta.getColumnCount()); assertEquals(1, meta.getPrecision(1)); assertEquals(0, meta.getScale(1)); assertEquals("", meta.getSchemaName(1)); assertEquals(1, meta.getColumnDisplaySize(1)); + + assertEquals("BIT", meta.getColumnTypeName(2)); + assertEquals(sharedConn.getCatalog(), meta.getCatalogName(2)); + assertEquals("byte[]", meta.getColumnClassName(2)); + assertEquals("t2alias", meta.getColumnLabel(2)); + assertEquals("t2", meta.getColumnName(2)); + assertEquals(Types.VARBINARY, meta.getColumnType(2)); + assertEquals(4, meta.getPrecision(2)); + assertEquals(0, meta.getScale(2)); + assertEquals("", meta.getSchemaName(2)); + assertEquals(4, meta.getColumnDisplaySize(2)); } @Test diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/GeometryCollectionCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/GeometryCollectionCodecTest.java index 005453eca..bbc03ff6c 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/GeometryCollectionCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/GeometryCollectionCodecTest.java @@ -253,8 +253,7 @@ && minVersion(10, 5, 1) } assertEquals(sharedConn.getCatalog(), meta.getCatalogName(1)); assertEquals( - geoDefault ? GeometryCollection.class.getName() : byte[].class.getName(), - meta.getColumnClassName(1)); + geoDefault ? GeometryCollection.class.getName() : "byte[]", meta.getColumnClassName(1)); assertEquals("t1alias", meta.getColumnLabel(1)); assertEquals("t1", meta.getColumnName(1)); assertEquals(Types.VARBINARY, meta.getColumnType(1)); diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/LineStringCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/LineStringCodecTest.java index 656cbee97..11a98e5c2 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/LineStringCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/LineStringCodecTest.java @@ -269,7 +269,7 @@ && minVersion(10, 5, 1) && !"skysql-ha".equals(System.getenv("srv"))) ? LineString.class.getName() : GeometryCollection.class.getName()) - : byte[].class.getName(), + : "byte[]", meta.getColumnClassName(1)); assertEquals("t1alias", meta.getColumnLabel(1)); assertEquals("t1", meta.getColumnName(1)); diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/MultiLineStringCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/MultiLineStringCodecTest.java index e2938b5e9..2ce763ac5 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/MultiLineStringCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/MultiLineStringCodecTest.java @@ -339,7 +339,7 @@ && minVersion(10, 5, 1) && !"skysql-ha".equals(System.getenv("srv"))) ? MultiLineString.class.getName() : GeometryCollection.class.getName()) - : byte[].class.getName(), + : "byte[]", meta.getColumnClassName(1)); assertEquals("t1alias", meta.getColumnLabel(1)); assertEquals("t1", meta.getColumnName(1)); diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/MultiPointCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/MultiPointCodecTest.java index 122b5e094..1dae0bdfd 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/MultiPointCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/MultiPointCodecTest.java @@ -281,7 +281,7 @@ && minVersion(10, 5, 1) && !"skysql-ha".equals(System.getenv("srv"))) ? MultiPoint.class.getName() : GeometryCollection.class.getName()) - : byte[].class.getName(), + : "byte[]", meta.getColumnClassName(1)); assertEquals("t1alias", meta.getColumnLabel(1)); assertEquals("t1", meta.getColumnName(1)); diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/MultiPolygonCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/MultiPolygonCodecTest.java index 0a94ac6cf..8b191bfbb 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/MultiPolygonCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/MultiPolygonCodecTest.java @@ -288,7 +288,7 @@ && minVersion(10, 5, 1) && !"skysql-ha".equals(System.getenv("srv"))) ? MultiPolygon.class.getName() : GeometryCollection.class.getName()) - : byte[].class.getName(), + : "byte[]", meta.getColumnClassName(1)); assertEquals("t1alias", meta.getColumnLabel(1)); assertEquals("t1", meta.getColumnName(1)); diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/PointCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/PointCodecTest.java index 05c316250..7959eb20c 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/PointCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/PointCodecTest.java @@ -199,7 +199,7 @@ && minVersion(10, 5, 1) && !"skysql-ha".equals(System.getenv("srv"))) ? Point.class.getName() : GeometryCollection.class.getName()) - : byte[].class.getName(), + : "byte[]", meta.getColumnClassName(1)); assertEquals("t1alias", meta.getColumnLabel(1)); diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/PolygonCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/PolygonCodecTest.java index cfaf3ed92..359e7b27b 100644 --- a/src/test/java/org/mariadb/jdbc/integration/codec/PolygonCodecTest.java +++ b/src/test/java/org/mariadb/jdbc/integration/codec/PolygonCodecTest.java @@ -356,14 +356,13 @@ && minVersion(10, 5, 1) assertEquals(sharedConn.getCatalog(), meta.getCatalogName(1)); assertEquals( (geoDefault - ? ((isMariaDBServer() - && minVersion(10, 5, 1) - && !"maxscale".equals(System.getenv("srv")) - && !"skysql-ha".equals(System.getenv("srv"))) - ? Polygon.class - : GeometryCollection.class) - : byte[].class) - .getName(), + ? ((isMariaDBServer() + && minVersion(10, 5, 1) + && !"maxscale".equals(System.getenv("srv")) + && !"skysql-ha".equals(System.getenv("srv"))) + ? Polygon.class.getName() + : GeometryCollection.class.getName()) + : "byte[]"), meta.getColumnClassName(1)); assertEquals("t1alias", meta.getColumnLabel(1)); assertEquals("t1", meta.getColumnName(1));