Skip to content

Recursive Lock Not Allowed in Transaction #2

Closed
@cliftonlabrum

Description

@cliftonlabrum

I have a function that iterates over a List of objects, converts them to queries, and saves them to the database. I've omitted how I actually generate the query, but suffice it to say the end result is a proper SQLite query.

final db = SqliteDatabase(path: Paths.database);

await db.writeTransaction((tx) async { //<-- Exception: Recursive lock is not allowed
  for (var object in objects) {
    //Get the table name...

    //Assemble column names from object keys...

    //Make a comma-separated list of ? using the column list length...

    await db.execute('''
    INSERT OR REPLACE INTO $table (${columns.join(',')})
    VALUES ($questionMarks)
    ''', values);
  }
});

await db.close();

But I keep getting an exception on the line with the db.writeTransaction that says:

Recursive lock is not allowed

Any idea why can't I execute multiple INSERT queries at once inside the transaction? I call this code for a variety of different chunks of data, so it's possible a prior transaction is already in progress.

How I make sure the database isn't locked and that my queries don't collide?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions