Skip to content

Commit fba5ec3

Browse files
author
diego Dupin
committed
[misc] permit getString on a binary object
1 parent 2f29c3a commit fba5ec3

File tree

2 files changed

+11
-47
lines changed

2 files changed

+11
-47
lines changed

src/main/java/org/mariadb/jdbc/plugin/codec/StringCodec.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,6 @@ public String decodeText(
8787
sb.append("'");
8888
return sb.toString();
8989

90-
case BLOB:
91-
case TINYBLOB:
92-
case MEDIUMBLOB:
93-
case LONGBLOB:
94-
if (column.isBinary()) {
95-
buf.skip(length);
96-
throw new SQLDataException(
97-
String.format("Data type %s cannot be decoded as String", column.getType()));
98-
}
99-
return buf.readString(length);
100-
10190
default:
10291
return buf.readString(length);
10392
}
@@ -253,17 +242,6 @@ public String decodeBinary(
253242
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss" + microSecPattern);
254243
return dateTime.toLocalDate().toString() + ' ' + dateTime.toLocalTime().format(formatter);
255244

256-
case BLOB:
257-
case TINYBLOB:
258-
case MEDIUMBLOB:
259-
case LONGBLOB:
260-
if (column.isBinary()) {
261-
buf.skip(length);
262-
throw new SQLDataException(
263-
String.format("Data type %s cannot be decoded as String", column.getType()));
264-
}
265-
return buf.readString(length);
266-
267245
default:
268246
return buf.readString(length);
269247
}

src/test/java/org/mariadb/jdbc/integration/codec/BlobCodecTest.java

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public void getObjectTypePrepare() throws Exception {
112112

113113
public void getObjectType(ResultSet rs) throws Exception {
114114
testErrObject(rs, Integer.class);
115-
testErrObject(rs, String.class);
115+
testObject(rs, String.class, "0");
116116
testErrObject(rs, Long.class);
117117
testErrObject(rs, Short.class);
118118
testErrObject(rs, BigDecimal.class);
@@ -151,19 +151,12 @@ public void getStringPrepare() throws SQLException {
151151
}
152152

153153
public void getString(ResultSet rs) throws SQLException {
154-
Common.assertThrowsContains(
155-
SQLDataException.class,
156-
() -> rs.getNString(1),
157-
"Data type BLOB cannot be decoded as String");
154+
assertEquals("0", rs.getString(1));
158155
assertFalse(rs.wasNull());
159-
Common.assertThrowsContains(
160-
SQLDataException.class,
161-
() -> rs.getNString(2),
162-
"Data type BLOB cannot be decoded as String");
163-
Common.assertThrowsContains(
164-
SQLDataException.class,
165-
() -> rs.getNString("t2alias"),
166-
"Data type BLOB cannot be decoded as String");
156+
assertEquals("1", rs.getString(2));
157+
assertEquals("1", rs.getString("t2alias"));
158+
assertFalse(rs.wasNull());
159+
assertEquals("some🌟", rs.getString(3));
167160
assertFalse(rs.wasNull());
168161
assertNull(rs.getNString(4));
169162
assertTrue(rs.wasNull());
@@ -181,19 +174,12 @@ public void getNStringPrepare() throws SQLException {
181174
}
182175

183176
public void getNString(ResultSet rs) throws SQLException {
184-
Common.assertThrowsContains(
185-
SQLDataException.class,
186-
() -> rs.getNString(1),
187-
"Data type BLOB cannot be decoded as String");
177+
assertEquals("0", rs.getString(1));
188178
assertFalse(rs.wasNull());
189-
Common.assertThrowsContains(
190-
SQLDataException.class,
191-
() -> rs.getNString(2),
192-
"Data type BLOB cannot be decoded as String");
193-
Common.assertThrowsContains(
194-
SQLDataException.class,
195-
() -> rs.getNString("t2alias"),
196-
"Data type BLOB cannot be decoded as String");
179+
assertEquals("1", rs.getString(2));
180+
assertEquals("1", rs.getString("t2alias"));
181+
assertFalse(rs.wasNull());
182+
assertEquals("some🌟", rs.getString(3));
197183
assertFalse(rs.wasNull());
198184
assertNull(rs.getNString(4));
199185
assertTrue(rs.wasNull());

0 commit comments

Comments
 (0)