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.

`AndroidSqliteDriver.Callback` class is final

See original GitHub issue

SQLDelight Version

2.0.0-alpha04

Operating System

MacOS 12.6

Gradle Version

7.5

Kotlin Version

1.7.20

Dialect

app.cash.sqldelight:sqlite-3-18-dialect

AGP Version

7.3.0

Describe the Bug

Hello

On the version 2.0.0-alpha04 the class AndroidSqliteDriver.Callback is marked as final which make impossible to override the onCreate, onUpgrade, onConfigure, onOpen, etc…

For instance, this code doesn’t compile:

AndroidSqliteDriver(
        schema = Database.Schema,
        context = context,
        name = "my_db.db",
        callback = object : AndroidSqliteDriver.Callback(Database.Schema) {
            override fun onOpen(db: SupportSQLiteDatabase) {
                db.execSQL("PRAGMA foreign_keys=ON;")
            }
        }
    )

Regards

Stacktrace

No response

Gradle Build Script

plugins {
    id 'com.android.library'
    id 'org.jetbrains.kotlin.android'
    id 'org.jetbrains.kotlin.kapt'
    id 'app.cash.sqldelight'
}

dependencies {
    api "app.cash.sqldelight:android-driver:$sqlDelightVersion"
    api "app.cash.sqldelight:coroutines-extensions-jvm:$sqlDelightVersion"
    api "app.cash.sqldelight:primitive-adapters:$sqlDelightVersion"
}

sqldelight {
    Database {
        packageName = "com.masselis.tpmsadvanced.data.car"
        verifyMigrations = true
        schemaOutputDirectory = file("src/main/sqldelight")
        dialect("app.cash.sqldelight:sqlite-3-18-dialect:$sqlDelightVersion")
    }
}

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
svenjacobscommented, Oct 22, 2022

Facing the same issue in 2.0.0-alpha04 because I want to implement onConfigure to enable foreign keys like

override fun onConfigure(db: SupportSQLiteDatabase) {
    db.setForeignKeyConstraintsEnabled(true)
}

The solution above with a delegate works but this was much less boiler plate code in version 1.5 of SQLDelight.

0reactions
VincentMasseliscommented, Oct 5, 2022

Thanks, I didn’t thought that I could just do that, I’ve applied this fix on my code until the next release 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Migrations - SQLDelight - Cash App Code Blog
After the callback it will resume at 4.sqm and complete the remaining migrations, in this case 4.sqm and 5.sqm, meaning the final database...
Read more >
java - Firebase Callback Interface needs to be declared final?
In your code you receive getFullNameCallback as parameter in ... class ValueEventListener , so, getFullNameCallback must be final in order ...
Read more >
Create a multiplatform app using Ktor and SQLDelight – tutorial
You can find this state of the project on the final branch. ... On Android, the AndroidSqliteDriver class implements the SQLite driver.
Read more >
SupportSQLiteOpenHelper.Callback - Android Developers
Fields. public final int, version. Version number of the database (starting at 1); if the database is older, onUpgrade(SupportSQLiteDatabase ...
Read more >
Understanding Callback Methods with Examples - OneSpan
While the concept is known as Callbacks in the Java community, ... public class Worker { ActionListenerCallback callBack; public Worker() ...
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