-1

Warning database has been locked for 0:00:10.000000. Make sure you always use the transaction object for database operations during a transaction.

I received this error while showing data in screen. And it takes too long so I have to reduce time.

In Futurebuilder I called method like this :

future: Provider.of<AllMethodCallProvider>(context,listen: false).sendAllOfflineData(context, accessToken).
then((value) {Provider.of<StowDetailProvider>(context, listen: false).searchPOItem(accessToken:accessToken,po_id: widget.po_id!,selectedSiteId: widget.siteId!,poNumber:widget.searchPOText!,   searchVendorPartNumber:widget.vendorPartName!,vendorName:widget.vendorName!,itemStatus:widget.item_status!,
          context: context).then((value) {
        Provider.of<StowDetailProvider>(context,listen: false).isSubmitted = false;
      });
    }),

I used for -loop to add API data in list. I tried await batch.commit(); but am not getting expected output.

user4157124
  • 2,809
  • 13
  • 27
  • 42

1 Answers1

0

Its deadlock occurred in the database required. You need to check if any require are atomic. Use transaction to make sure your requires are atomic.

await database.transaction((txn) async {
  // Ok
  await txn.execute('CREATE TABLE Test1 (id INTEGER PRIMARY KEY)');
  
  // DON'T  use the database object in a transaction
  // this will deadlock!
  await database.execute('CREATE TABLE Test2 (id INTEGER PRIMARY KEY)');
});

And not only deadlock occurs in the required syntax. maybe our of you use of the database requirements is not suitable and could occur a deadlock. Check all of your requirements are not at the same time, if necessary use transactions to make sure are atomic.