如果有人能帮助我回答我的问题,我将非常感谢 可以说我的Flutter应用程序有一个表Account(使用Sqfite扩展名),在Account表中我有Balance列,以下是更新Balance的功能:
Future<bool> updateAccountBalance(double amount) async {
// Read current balance
double currentBalance = await database.execute(....); // execute a query to get the balance
double newBalance = currentBalance + amount;
// Update newBalance to DB
await database.execute(...);
return true;
}
因为在我的应用程序中有许多事件调用该方法,所以我认为这可能导致更新错误的值。 我的问题是,updateAccountBalance是原子的吗?有没有机会将错误的号码更新为数据库?如果有可能,我该怎么做才能保证余额始终能正确更新?