0

I have this function in my DB layer :

suspend inline fun <T : Any> query(stmt: String, vararg params: Any?, crossinline transform: (Row) -> T): List<T>? = dbQuery {
        var result: List<T>? = null
        using(sessionOf(dataSource)) { session ->
            result = session.run(queryOf(stmt, params)
                .map { transform(it) }
                .asList
            )
        }
        result
    }

And then I simply call from my controller :

db.query<User>("SELECT * FROM users where name = ?, "John")

For some reason, the params here make the query crash, because :

org.postgresql.util.PSQLException: Cannot cast an instance of [Ljava.lang.Object; to type Types.ARRAY
    at org.postgresql.jdbc.PgPreparedStatement.setObject(PgPreparedStatement.java:1004)

When I call the code like this however :

result = session.run(queryOf(stmt, "John") it works perfectly. (i.e - When using hardcoded "John" instead passing params)

Only when I pass the varargs through a function it starts crashing.

BVtp
  • 2,308
  • 2
  • 29
  • 68
  • You're right, I looked for something similar but somehow didn't find this one. Sorry, and thank you again :) – BVtp Feb 10 '22 at 18:48
  • yep, it does , don't know how I missed it when I was looking for a similar question.. – BVtp Feb 10 '22 at 18:50

0 Answers0