Open 2001zhaozhao opened 1 year ago
I didn't manage to test it yet, but I believe the change below may fix the problem:
Index: drivers/r2dbc-driver/src/main/kotlin/app/cash/sqldelight/driver/r2dbc/R2dbcDriver.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/drivers/r2dbc-driver/src/main/kotlin/app/cash/sqldelight/driver/r2dbc/R2dbcDriver.kt b/drivers/r2dbc-driver/src/main/kotlin/app/cash/sqldelight/driver/r2dbc/R2dbcDriver.kt
--- a/drivers/r2dbc-driver/src/main/kotlin/app/cash/sqldelight/driver/r2dbc/R2dbcDriver.kt (revision fb48f4682c4f086d7d2f34e383b901ba4b91fd1a)
+++ b/drivers/r2dbc-driver/src/main/kotlin/app/cash/sqldelight/driver/r2dbc/R2dbcDriver.kt (date 1717396182529)
@@ -9,6 +9,7 @@
import io.r2dbc.spi.Connection
import io.r2dbc.spi.Statement
import java.math.BigDecimal
+import java.nio.ByteBuffer
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.CoroutineScope
@@ -320,7 +321,7 @@
override fun getLong(index: Int): Long? = get<Number>(index)?.toLong()
- override fun getBytes(index: Int): ByteArray? = get(index)
+ override fun getBytes(index: Int): ByteArray? = get<ByteBuffer>(index)?.array()
override fun getDouble(index: Int): Double? = get(index)
SQLDelight Version
2.0.0-rc02
SQLDelight Dialect
postgresql on R2DBC
Describe the Bug
On PostgreSQL with R2DBC, an exception is thrown whenever calling a query that returns a column value of the
BYTEA
(binary) type.The cause seems to be that
r2dbc-postgresql
seems to prefer translating theBYTEA
type to a ByteBuffer, rather than a byte array, as shown on their README: https://github.com/pgjdbc/r2dbc-postgresql/tree/mainHowever, SQLDelight's driver tries to cast it into a
ByteArray?
, causing the error: https://github.com/cashapp/sqldelight/blob/958dbf89850bfe780b9e91470ddf2afc6272f28a/drivers/r2dbc-driver/src/main/kotlin/app/cash/sqldelight/driver/r2dbc/R2dbcDriver.kt#L270I have tested that this happens with both
SELECT
queries andUPDATE ... RETURNING
queries.Stacktrace