1
我正在尝试编写SQL SELECT ... FOR UPDATE在Play中使用Anorm,以便我可以让多个线程与同一个数据库进行交互,但是会引发问题。选择...更新使用Anorm
的代码是:
db.withConnection { implicit connection: Connection =>
SQL"""
start transaction;
select * from push_messages where vendorId=$vendorId for update;
UPDATE push_messages set stageOne=$first, stageTwo=$second, stageThree=$third,
stageFour=$fourth, stageFive=$fifth, highestStage=$highestStage, iOSTotal=$iOSTotal,
androidTotal=$androidTotal, iOSRunningCount=$iOSRunningCount, androidRunningCount=$androidRunningCount,
problem=$newProblem, iOSComplete=$iOSCompleted, androidComplete=$newAndroidComplete,
totalStageThrees=$totalStageThrees, totalStageFours=$totalStageFours, expectedTotals=$expectedTotals,
startTime=$startTime, date=$date, topics=$topics, androidFailures=$androidFailures, iOSFailures=$iOSFailures where vendorId=$vendorId;
commit;
""".execute
}
但是,它似乎并不喜欢在select
语句中使用.execute
。是否有一种很好的方法可以打破select...for update
以便我可以使用或executeUpdate
?
任何和所有的帮助将不胜感激。谢谢。
我不明白你是如何使用“SQL SELECT ... FOR UPDATE”实现更好的多线程... – cchantep