Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.UnsupportedOperationException: Binding parameters is not supported for the statement #3526

Closed
unlimitedcoder2 opened this issue Sep 22, 2022 · 4 comments · Fixed by #3375
Labels

Comments

@unlimitedcoder2
Copy link

SQLDelight Version

2.0.0-alpha03

Application Operating System

JVM

Describe the Bug

I'm getting this error when calling insert with the r2dbc driver on with postgres
postgres dialect version: app.cash.sqldelight:postgresql-dialect:2.0.0-alpha03
sqldelight r2dbc version: app.cash.sqldelight:r2dbc-driver:2.0.0-alpha03
r2dbc spi version: io.r2dbc:r2dbc-spi:1.0.0.RELEASE
r2dbc postgres version: io.r2dbc:r2dbc-postgresql:0.8.13.RELEASE

This is the insert statement from User.sq

insert:
INSERT INTO User (email, password) VALUES (?, ?) RETURNING *;
public fun <T : Any> insert(
    email: String,
    password: String,
    mapper: (
      id: UserId,
      email: String,
      password: String,
      createdAt: LocalDateTime,
      enabled: Boolean,
    ) -> T,
  ): ExecutableQuery<T> = InsertQuery(email, password) { cursor ->
    check(cursor is R2dbcCursor)
    mapper(
      UserAdapter.idAdapter.decode(cursor.getLong(0)!!.toInt()),
      cursor.getString(1)!!,
      cursor.getString(2)!!,
      cursor.getObject(3)!!,
      UserAdapter.enabledAdapter.decode(cursor.getLong(4)!!.toInt())
    )
  }

  public fun insert(email: String, password: String): ExecutableQuery<User> = insert(email,
      password) { id, email_, password_, createdAt, enabled ->
    User(
      id,
      email_,
      password_,
      createdAt,
      enabled
    )
  }

private inner class InsertQuery<out T : Any>(
    public val email: String,
    public val password: String,
    mapper: (SqlCursor) -> T,
  ) : ExecutableQuery<T>(mapper) {
    public override fun <R> execute(mapper: (SqlCursor) -> R): QueryResult<R> =
        driver.executeQuery(502905972,
        """INSERT INTO User (email, password) VALUES (?, ?) RETURNING *""", mapper, 2) {
      check(this is R2dbcPreparedStatement)
      bindString(0, email)
      bindString(1, password)
    }

    public override fun toString(): String = "User.sq:insert"
  }

Stacktrace

java.lang.UnsupportedOperationException: Binding parameters is not supported for the statement 'INSERT INTO User (email, password) VALUES (?, ?) RETURNING *'
	at io.r2dbc.postgresql.SimpleQueryPostgresqlStatement.bind(SimpleQueryPostgresqlStatement.java:77)
	at io.r2dbc.postgresql.SimpleQueryPostgresqlStatement.bind(SimpleQueryPostgresqlStatement.java:43)
	at app.cash.sqldelight.driver.r2dbc.R2dbcPreparedStatement.bindString(R2dbcDriver.kt:130)
	at club.rokkit.server.database.UserQueries$InsertQuery$execute$1.invoke(UserQueries.kt:148)
	at club.rokkit.server.database.UserQueries$InsertQuery$execute$1.invoke(UserQueries.kt:145)
	at app.cash.sqldelight.driver.r2dbc.R2dbcDriver.executeQuery(R2dbcDriver.kt:23)
	at club.rokkit.server.database.UserQueries$InsertQuery.execute(UserQueries.kt:145)
	at club.rokkit.server.util.DatabaseKt.await(database.kt:5)
	at club.rokkit.server.service.UserPersistenceKt$userPersistence$1.createUser(userPersistence.kt:28)
	at club.rokkit.server.routes.AuthKt$installAuthRoutes$1$2.invokeSuspend(auth.kt:41)
	at club.rokkit.server.routes.AuthKt$installAuthRoutes$1$2.invoke(auth.kt)
	at club.rokkit.server.routes.AuthKt$installAuthRoutes$1$2.invoke(auth.kt)
	at io.ktor.server.routing.Route$buildPipeline$1$1.invokeSuspend(Route.kt:116)
	at io.ktor.server.routing.Route$buildPipeline$1$1.invoke(Route.kt)
	at io.ktor.server.routing.Route$buildPipeline$1$1.invoke(Route.kt)
	at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:123)
	at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:81)
	at io.ktor.util.pipeline.SuspendFunctionGun.execute$ktor_utils(SuspendFunctionGun.kt:101)
	at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:77)
	at io.ktor.server.routing.Routing$executeResult$$inlined$execute$1.invokeSuspend(Pipeline.kt:478)
	at io.ktor.server.routing.Routing$executeResult$$inlined$execute$1.invoke(Pipeline.kt)
	at io.ktor.server.routing.Routing$executeResult$$inlined$execute$1.invoke(Pipeline.kt)
	at io.ktor.util.debug.ContextUtilsKt.initContextInDebugMode(ContextUtils.kt:17)
	at io.ktor.server.routing.Routing.executeResult(Routing.kt:174)
	at io.ktor.server.routing.Routing.interceptor(Routing.kt:49)
	at io.ktor.server.routing.Routing$Plugin$install$1.invokeSuspend(Routing.kt:124)
	at io.ktor.server.routing.Routing$Plugin$install$1.invoke(Routing.kt)
	at io.ktor.server.routing.Routing$Plugin$install$1.invoke(Routing.kt)
	at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:123)
	at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:81)
	at io.ktor.server.plugins.callloging.MDCHookKt$MDCHook$1$install$1$1.invoke(MDCHook.kt:19)
	at io.ktor.server.plugins.callloging.MDCHookKt$MDCHook$1$install$1$1.invoke(MDCHook.kt:19)
	at io.ktor.server.plugins.callloging.CallLoggingKt$logCallsWithMDC$2$invokeSuspend$$inlined$withMDC$1.invokeSuspend(MDCEntryUtils.kt:21)
	at io.ktor.server.plugins.callloging.CallLoggingKt$logCallsWithMDC$2$invokeSuspend$$inlined$withMDC$1.invoke(MDCEntryUtils.kt)
	at io.ktor.server.plugins.callloging.CallLoggingKt$logCallsWithMDC$2$invokeSuspend$$inlined$withMDC$1.invoke(MDCEntryUtils.kt)
	at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:89)
	at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:169)
	at kotlinx.coroutines.BuildersKt.withContext(Unknown Source)
	at io.ktor.server.plugins.callloging.CallLoggingKt$logCallsWithMDC$2.invokeSuspend(CallLogging.kt:97)
	at io.ktor.server.plugins.callloging.CallLoggingKt$logCallsWithMDC$2.invoke(CallLogging.kt)
	at io.ktor.server.plugins.callloging.CallLoggingKt$logCallsWithMDC$2.invoke(CallLogging.kt)
	at io.ktor.server.plugins.callloging.MDCHookKt$MDCHook$1$install$1.invokeSuspend(MDCHook.kt:19)
	at io.ktor.server.plugins.callloging.MDCHookKt$MDCHook$1$install$1.invoke(MDCHook.kt)
	at io.ktor.server.plugins.callloging.MDCHookKt$MDCHook$1$install$1.invoke(MDCHook.kt)
	at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:123)
	at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:81)
	at io.ktor.server.engine.BaseApplicationEngineKt$installDefaultTransformationChecker$1.invokeSuspend(BaseApplicationEngine.kt:122)
	at io.ktor.server.engine.BaseApplicationEngineKt$installDefaultTransformationChecker$1.invoke(BaseApplicationEngine.kt)
	at io.ktor.server.engine.BaseApplicationEngineKt$installDefaultTransformationChecker$1.invoke(BaseApplicationEngine.kt)
	at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:123)
	at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:81)
	at io.ktor.server.plugins.callloging.MDCHookKt$MDCHook$1$install$1$1.invoke(MDCHook.kt:19)
	at io.ktor.server.plugins.callloging.MDCHookKt$MDCHook$1$install$1$1.invoke(MDCHook.kt:19)
	at io.ktor.server.plugins.callloging.CallLoggingKt$logCallsWithMDC$1$invokeSuspend$$inlined$withMDC$1.invokeSuspend(MDCEntryUtils.kt:21)
	at io.ktor.server.plugins.callloging.CallLoggingKt$logCallsWithMDC$1$invokeSuspend$$inlined$withMDC$1.invoke(MDCEntryUtils.kt)
	at io.ktor.server.plugins.callloging.CallLoggingKt$logCallsWithMDC$1$invokeSuspend$$inlined$withMDC$1.invoke(MDCEntryUtils.kt)
	at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:89)
	at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:169)
	at kotlinx.coroutines.BuildersKt.withContext(Unknown Source)
	at io.ktor.server.plugins.callloging.CallLoggingKt$logCallsWithMDC$1.invokeSuspend(CallLogging.kt:97)
	at io.ktor.server.plugins.callloging.CallLoggingKt$logCallsWithMDC$1.invoke(CallLogging.kt)
	at io.ktor.server.plugins.callloging.CallLoggingKt$logCallsWithMDC$1.invoke(CallLogging.kt)
	at io.ktor.server.plugins.callloging.MDCHookKt$MDCHook$1$install$1.invokeSuspend(MDCHook.kt:19)
	at io.ktor.server.plugins.callloging.MDCHookKt$MDCHook$1$install$1.invoke(MDCHook.kt)
	at io.ktor.server.plugins.callloging.MDCHookKt$MDCHook$1$install$1.invoke(MDCHook.kt)
	at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:123)
	at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:81)
	at io.ktor.server.application.hooks.CallFailed$install$1$1.invokeSuspend(CommonHooks.kt:43)
	at io.ktor.server.application.hooks.CallFailed$install$1$1.invoke(CommonHooks.kt)
	at io.ktor.server.application.hooks.CallFailed$install$1$1.invoke(CommonHooks.kt)
	at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:89)
	at kotlinx.coroutines.CoroutineScopeKt.coroutineScope(CoroutineScope.kt:264)
	at io.ktor.server.application.hooks.CallFailed$install$1.invokeSuspend(CommonHooks.kt:42)
	at io.ktor.server.application.hooks.CallFailed$install$1.invoke(CommonHooks.kt)
	at io.ktor.server.application.hooks.CallFailed$install$1.invoke(CommonHooks.kt)
	at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:123)
	at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:81)
	at io.ktor.server.application.hooks.CallFailed$install$1$1.invokeSuspend(CommonHooks.kt:43)
	at io.ktor.server.application.hooks.CallFailed$install$1$1.invoke(CommonHooks.kt)
	at io.ktor.server.application.hooks.CallFailed$install$1$1.invoke(CommonHooks.kt)
	at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:89)
	at kotlinx.coroutines.CoroutineScopeKt.coroutineScope(CoroutineScope.kt:264)
	at io.ktor.server.application.hooks.CallFailed$install$1.invokeSuspend(CommonHooks.kt:42)
	at io.ktor.server.application.hooks.CallFailed$install$1.invoke(CommonHooks.kt)
	at io.ktor.server.application.hooks.CallFailed$install$1.invoke(CommonHooks.kt)
	at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:123)
	at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:81)
	at io.ktor.util.pipeline.SuspendFunctionGun.execute$ktor_utils(SuspendFunctionGun.kt:101)
	at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:77)
	at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$1$invokeSuspend$$inlined$execute$1.invokeSuspend(Pipeline.kt:478)
	at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$1$invokeSuspend$$inlined$execute$1.invoke(Pipeline.kt)
	at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$1$invokeSuspend$$inlined$execute$1.invoke(Pipeline.kt)
	at io.ktor.util.debug.ContextUtilsKt.initContextInDebugMode(ContextUtils.kt:17)
	at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$1.invokeSuspend(DefaultEnginePipeline.kt:118)
	at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$1.invoke(DefaultEnginePipeline.kt)
	at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$1.invoke(DefaultEnginePipeline.kt)
	at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:123)
	at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:81)
	at io.ktor.util.pipeline.SuspendFunctionGun.execute$ktor_utils(SuspendFunctionGun.kt:101)
	at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:77)
	at io.ktor.server.cio.CIOApplicationEngine$handleRequest$2$invokeSuspend$$inlined$execute$1.invokeSuspend(Pipeline.kt:478)
	at io.ktor.server.cio.CIOApplicationEngine$handleRequest$2$invokeSuspend$$inlined$execute$1.invoke(Pipeline.kt)
	at io.ktor.server.cio.CIOApplicationEngine$handleRequest$2$invokeSuspend$$inlined$execute$1.invoke(Pipeline.kt)
	at io.ktor.util.debug.ContextUtilsKt.initContextInDebugMode(ContextUtils.kt:17)
	at io.ktor.server.cio.CIOApplicationEngine$handleRequest$2.invokeSuspend(CIOApplicationEngine.kt:189)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
	at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
	at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
@dellisd
Copy link
Collaborator

dellisd commented Sep 22, 2022

The R2DBC postgres driver requires the placeholders in the SQL string to be in ($1, $2) format instead of (?, ?) form, but that's currently not supported in SQLDelight.

This PR (#3375) would enable a custom dialect to allow for the different placeholder format to be supported.

Out of curiosity, what's your use case for using R2DBC over the JDBC?

@hfhbd
Copy link
Collaborator

hfhbd commented Sep 23, 2022

How do you create the database without #3525? :D I did try R2DBC yesterday and got many errors, which should be fixed after #3375 is merged :)

@unlimitedcoder2
Copy link
Author

unlimitedcoder2 commented Sep 23, 2022

Out of curiosity, what's your use case for using R2DBC over the JDBC?

As far as I am aware it is the only async driver that sqldelight supports.

How do you create the database without #3525? :D I did try R2DBC yesterday and got many errors, which should be fixed now (after #3375 is merged) :)

The database/table already existed so I didn't need to create them. The insert one above was the first query I tried to run using sqldelight

@hfhbd
Copy link
Collaborator

hfhbd commented Oct 3, 2022

@AlecStrong If you want to publish a new alpha today, fixing r2dbc would be nice too, by merging #3375. Or should I split the PR?
Edit: Shipped in alpha04

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants