Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/main/java/org/duckdb/DuckDBPreparedStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import org.duckdb.user.DuckDBUserArray;

public class DuckDBPreparedStatement implements PreparedStatement {
private DuckDBConnection conn;
Expand Down Expand Up @@ -1046,6 +1047,13 @@ public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQ
throw new SQLException("Can't convert value to timestamp " + x.getClass().toString());
}
break;
case Types.ARRAY:
if (x instanceof DuckDBUserArray) {
setArray(parameterIndex, (Array) x);
} else {
throw new SQLException("Can't convert value to array " + x.getClass().toString());
}
break;
default:
throw new SQLException("Unknown target type " + targetSqlType);
}
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/org/duckdb/TestPrepare.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.duckdb.test.Assertions.*;

import java.sql.*;
import org.duckdb.user.DuckDBUserArray;

public class TestPrepare {

Expand Down Expand Up @@ -346,4 +347,21 @@ public static void test_max_rows() throws Exception {
assertEquals(stmt.getLargeMaxRows(), 0L);
}
}

public static void test_prepared_statement_array_parameter() throws Exception {
try (Connection conn = DriverManager.getConnection(JDBC_URL);
PreparedStatement ps = conn.prepareStatement("SELECT ?::INT[]")) {
Array arrParam = conn.createArrayOf("INT", new Object[] {41, 42});
ps.setObject(1, arrParam, Types.ARRAY);
try (ResultSet rs = ps.executeQuery()) {
assertTrue(rs.next());
Array arrWrapper = rs.getArray(1);
Object[] arr = (Object[]) arrWrapper.getArray();
assertEquals(arr.length, 2);
assertEquals(arr[0], 41);
assertEquals(arr[1], 42);
assertFalse(rs.next());
}
}
}
}