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