tursodatabase/turso · error · SQLException
Cannot convert to ASCII stream: {type}
Error message
Cannot convert to ASCII stream: {type} What it means
getAsciiStream(int) returns a ByteArrayInputStream for exactly two runtime shapes: String columns (encoded US-ASCII) and byte[]/BLOB columns. Any other type (Long, Double, the 8-byte date blob, ...) throws with the class name — the driver performs no toString() coercion for streams.
Source
Thrown at bindings/java/src/main/java/tech/turso/jdbc4/JDBC4ResultSet.java:249
});
}
@Override
@SkipNullableCheck
public InputStream getAsciiStream(int columnIndex) throws SQLException {
final Object result = resultSet.get(columnIndex);
wasNull = result == null;
if (result == null) {
return null;
}
return wrapTypeConversion(
() -> {
if (result instanceof String) {
return new ByteArrayInputStream(((String) result).getBytes("US-ASCII"));
} else if (result instanceof byte[]) {
return new ByteArrayInputStream((byte[]) result);
}
throw new SQLException("Cannot convert to ASCII stream: " + result.getClass());
});
}
@Override
@SkipNullableCheck
public InputStream getUnicodeStream(int columnIndex) throws SQLException {
final Object result = resultSet.get(columnIndex);
wasNull = result == null;
if (result == null) {
return null;
}
return wrapTypeConversion(
() -> {
if (result instanceof String) {
return new ByteArrayInputStream(((String) result).getBytes("UTF-8"));
} else if (result instanceof byte[]) {
return new ByteArrayInputStream((byte[]) result);
}View on GitHub (pinned to bad083fafb)
Solutions
- Fall back to text yourself: new ByteArrayInputStream(rs.getString(i).getBytes(StandardCharsets.US_ASCII)) for non-text columns.
- CAST in SQL: SELECT CAST(col AS TEXT) ... so the value arrives as a String.
- Branch on ResultSetMetaData.getColumnType() and only call stream getters for CHAR/VARCHAR/TEXT/BINARY columns.
Example fix
// before
InputStream is = rs.getAsciiStream(1); // INTEGER column -> throws
// after
InputStream is = new ByteArrayInputStream(
rs.getString(1).getBytes(StandardCharsets.US_ASCII)); Defensive patterns
Strategy: type-guard
Validate before calling
Object v = rs.getObject(1);
InputStream is = (v instanceof String s)
? new ByteArrayInputStream(s.getBytes(StandardCharsets.US_ASCII))
: rs.getAsciiStream(1); // safe only for String/byte[] columns Type guard
static boolean isAsciiStreamable(Object v) {
return v instanceof String || v instanceof byte[];
} Try / catch
try {
return rs.getAsciiStream(i);
} catch (SQLException e) {
if (e.getMessage() != null && e.getMessage().contains("Cannot convert to ASCII stream")) {
return new ByteArrayInputStream(
rs.getString(i).getBytes(StandardCharsets.US_ASCII));
}
throw e;
} Prevention
- In exporters, branch on column type and only stream TEXT/BLOB columns.
- CAST numeric or computed columns to TEXT in the query when they must be streamed.
- Prefer getString + explicit encoding over stream getters in new code.
When it happens
Trigger: rs.getAsciiStream() on INTEGER/REAL columns; on expressions like COUNT(*); on the driver's 8-byte date/time blobs; generic exporters that stream every column of every row.
Common situations: Row-to-CSV export utilities; numeric aggregates expected to stream as text; schema drift turning a formerly TEXT column numeric via SQLite type affinity.
Related errors
- Cannot convert value to Date: {type}
- Cannot convert value to Timestamp: {type}
- Cannot convert to Unicode stream: {type}
- Cannot convert to binary stream: {type}
- Unsupported object type in setObject: {type}
AI-assisted analysis of tursodatabase/turso@bad083fafb (2026-08-16).
Data as JSON: /api/errors/b5fb1d6da03a6831.
Report an issue: GitHub.