question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`VALUES ?` fails to make use of custom adapters

See original GitHub issue

SQLDelight Version

2.0.0-alpha02

Operating System

Mac

Gradle Version

7.4.2

Kotlin Version

1.6.21

Dialect

sqlite

AGP Version

7.2.0

Describe the Bug

The following sql fails:

import kotlin.Int;

CREATE TABLE myTable (
  id TEXT PRIMARY KEY,
  foo INTEGER AS Int
);

upsert:
INSERT OR REPLACE INTO myTable
VALUES ?
;

When generating the code for the upsert there’s no jamesJourneySessionEntryAdapter passed. Although it’s referenced:

public class MyTableQueries(
  private val driver: SqlDriver,
) : TransacterImpl(driver) {
  public fun upsert(myTable: MyTable): Unit {
    driver.execute(-1698177346, """
        |INSERT OR REPLACE INTO myTable
        |VALUES (?, ?)
        """.trimMargin(), 2) {
          bindString(1, myTable.id)
          bindLong(2, myTableAdapter.fooAdapter.encode(myTable.foo))
        }
    notifyQueries(-1698177346) { emit ->
      emit("myTable")
    }
  }
}

I can workaround it by using:

-VALUES ?
+VALUES (?, ?)

Here’s also a repro: https://github.com/vanniktech/playground/pull/3

Stacktrace

e: /Users/niklas/dev/GitHub/playground-android/app/build/generated/sqldelight/code/QueryWrapper/debug/com/vanniktech/playground/MyTableQueries.kt: (16, 23): Unresolved reference: myTableAdapter

Gradle Build Script

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
hfhbdcommented, Jun 15, 2022

Another workaround: Use select in your query file

// does not work:
create:
INSERT INTO foo VALUES ?;
// works
create:
INSERT INTO foo VALUES ?;

select:
SELECT * FROM foo;

This is the real reason, why the tests don’t fail… Removing select results into a test failure too.

0reactions
hfhbdcommented, Jun 13, 2022

I analyzed it a little bit, but was unable to find the real cause:

The database and constructor uses the function forAdapter, which should find the needed binding expressions by calling requiredAdapters, argumentType and SqlExpr.inferredType(): IntermediateType. The resulting IntermediateType.column is null, so IntermediateType.parentAdapter(): PropertySpec? returns null => no adapter found.

But I don’t know, why IntermediateType.column is null.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom Adapter ListView Error - java - Stack Overflow
I am trying to list some user detail in a Listview , in each row show 4 String. The String is got from...
Read more >
Getting Adapter values during login failure
During a user login failure with HTML Form Adapter, is it possible to get the failed user name and error detail from Ping...
Read more >
Custom adapter program - IBM
The custom adapter program is a user-written program that transmits a business event to one or more event consumers. The custom adapter program...
Read more >
Known Issues for the WCF Adapters - BizTalk Server
If the adapter fails to read the SOAP envelope and body while creating the BizTalk message, the message is not suspended because the...
Read more >
Examples of custom action adapters - BMC Documentation
If you do not specify a value for an optional runtime parameter in a custom action, the property does not exist for the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found