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.

IllegalStateException: getDatabase called recursively in Migration even when using databaseWrapper

See original GitHub issue

DBFlow Version: 4.1.2

Bug or Feature Request: Recursive Database call

Description: I’m using the Database wrapper to perform a select during a migration (in order to set the value of one column to the value of an associated column), and even though I’m using the Database wrapper provider in migrate() I am getting an IllegalStateException saying that the database is being accessed recursively.

Here’s what I’m doing (in Kotlin):

@Migration(version = 3, database = AppDatabase::class)
class Migration3 : BaseMigration() {
    override fun migrate(database: DatabaseWrapper) {

        val messages = SQLite.select().from(Message::class).queryList(database)

        messages.forEach {
            (update<Message>()
                    set Message_Table.folder_path.eq(it.folder?.path)
                    where Message_Table.messageId.eq(it.messageId))
                    .execute(database)
        }
    }
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
agrosnercommented, Nov 6, 2018

in 5.0.0-alpha1 this has been fixed. code gen now resembles as follows:

 @Override
  public final Artist_Song loadFromCursor(FlowCursor cursor, DatabaseWrapper wrapper) {
    Artist_Song model = new Artist_Song();
    model._id = cursor.getLongOrDefault("_id");
    int index_song_id_Song_Table = cursor.getColumnIndex("song_id");
    if (index_song_id_Song_Table != -1 && !cursor.isNull(index_song_id_Song_Table)) {
      model.song = SQLite.select().from(Song.class).where()
          .and(Song_Table.id.eq(cursor.getInt(index_song_id_Song_Table)))
          .querySingle(wrapper);
    } else {
      model.song = null;
    }
    int index_artist_id_Artist_Table = cursor.getColumnIndex("artist_id");
    if (index_artist_id_Artist_Table != -1 && !cursor.isNull(index_artist_id_Artist_Table)) {
      model.artist = SQLite.select().from(Artist.class).where()
          .and(Artist_Table.id.eq(cursor.getInt(index_artist_id_Artist_Table)))
          .querySingle(wrapper);
    } else {
      model.artist = null;
    }
    return model;
  }

we pass in db wrapper everywhere and is pretty much a requirement in every db method now.

0reactions
agrosnercommented, Nov 6, 2018

closing as its fixed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

IllegalStateException: getDatabase called recursively in Migration ...
IllegalStateException : getDatabase called recursively in Migration even when using databaseWrapper.
Read more >
getDatabase called recursively during database migration
Caused by: java.lang.IllegalStateException: getDatabase called recursively at android.database.sqlite.SQLiteOpenHelper.
Read more >
[Fixed]-Android sqlite getdatabase called recursively
I have got a problem with my database. When the app start it should create the database with the tables if they not...
Read more >
[Problem] Android SQLIte Database Development ...
... the app crashes with an 02-24 10:45:54.636: E/AndroidRuntime(10845): java.lang.IllegalStateException: getDatabase called recursively
Read more >
Patterns of Enterprise Application Architecture - Yes PDF
Even though this technology was new, we did have the benefit of ... ber that he came up with the name for Special...
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