Search code examples
androidormgreendao

How do get SQLiteDatabase in GreenDao 3


Since the update to greenDao 3, statements like those do not work anymore:

getDatabase().insert(TABLENAME, null, values);
getDatabase().delete(...);
getDatabase().update(...);

The getDatabase() is a greenDao interface which doesn't have insert, delete and update methods. Thus, it gives me compile time errors. Anybody solved the issue?


Solution

  • The class you are getting back is org.greenrobot.greendao.database.Database, which is a database abstraction meant only for greenDAO. You have two options:

    1. You hold the reference to the original SQLiteDatabase and pass it to greenDAO during initialization.

    2. The Database abstraction class has a method getRawDatabase, which returns the underlying SQLiteDatabase. If you are not using encryption, it will be always android.database.sqlite.SQLiteDatabase. You have to do a cast.