【发布时间】:2016-08-15 15:58:48
【问题描述】:
我正在尝试在 Play 中使用 Anorm 编写 SQL SELECT...FOR UPDATE,以便我可以让多个线程与同一个数据库进行交互,但这会引发问题。
代码是:
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,以便我可以使用execute() 或executeUpdate?
任何和所有的帮助将不胜感激。谢谢。
【问题讨论】:
-
我不明白您打算如何使用“SQL SELECT...FOR UPDATE”实现更好的多线程...