After upgrading to SQLDelight 1.4.0 last_insert_rowid() stopped working on iOS.
See original GitHub issueRuntime Environment SQLDelight version: 1.4.0 Application OS: iOS 13.5.1 Kotlin version 1.3.72
Describe the bug
I use following table
CREATE TABLE IF NOT EXISTS connection (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
start INTEGER,
end INTEGER,
has_error INTEGER AS Boolean DEFAULT 0,
error INTEGER AS Int DEFAULT -1,
message TEXT);
I insert rows like this
insertConnection:
INSERT INTO connection(start, end, has_error, error, message) VALUES (?, ?, ?, ?, ?);
With SQLDelight 1.3.0 I could query the last row like this:
getLastInsertedConnectionId:
SELECT last_insert_rowid();
Since SQLDelight 1.4.0 the query always returns 0. If I use the query on Android it still works. So I guess the issue is in “com.squareup.sqldelight:native-driver:1.4.0”
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:13 (6 by maintainers)
Top Results From Across the Web
Could not resolve com.squareup.sqldelight:runtime:1.1.3
I was solved this problem. First: Apply sqldelight plugin right to all project: apply plugin: 'com.squareup.sqldelight' sqldelight ...
Read more >Changelog - SQLDelight
New: Update to Kotlin 1.0 final. Fix: Report 'sqldelight' folder structure problems in a non-failing way. Fix: Forbid columns named table_name . Their...
Read more >SQLCipher and Kotlin Multiplatform Mobile - Touchlab
How we implemented Kotlin Multiplatform Mobile encryption with SQDelight and SQLCipher for Kotlin 1.4.0 and made the iOS side work.
Read more >Create a multiplatform app using Ktor and SQLDelight – tutorial
This tutorial demonstrates how to use Android Studio to create a mobile application for iOS and Android using Kotlin Multiplatform Mobile with ...
Read more >Kotlin Multiplatform In-Memory SQLDelight Database for ...
So, calling setUpKoinForTesting() in the setUp function will not work. The iOS testing framework allows sending so-called launch arguments: app.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Aha!
transactionWithResult
was the missing piece of the puzzle.Thank you, @benasher44!
last_insert_rowid()
only works on the connection where the write happened. There was a previous bug (in the native driver) where writes that weren’t explicitly inside of a transaction would be run on the connection used for queries, but writes wrapped in an explicit transaction would be run on the connection used for writes (all writes should go to the same connection). In practice, this can cause spurious SQLITE_LOCKED-type errors that are hard to diagnose. This was fixed in 1.4.0, but as a result it means that if you want yourlast_insert_rowid()
query to work properly, you will need to wrap it inside of a transaction to force it onto the writer connection.