1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-10-31 14:10:08 +00:00

Adding For Update to query

This commit is contained in:
Tim Düsterhus 2012-03-03 21:40:43 +01:00
parent d7548e19e3
commit b103dff5f9

View File

@ -34,15 +34,16 @@ public function create() {
$room = parent::create(); $room = parent::create();
WCF::getDB()->beginTransaction(); WCF::getDB()->beginTransaction();
$sql = "SELECT max(position) as max $sql = "SELECT max(position) as max
FROM wcf".WCF_N."_chat_room"; FROM wcf".WCF_N."_chat_room
FOR UPDATE";
$stmt = WCF::getDB()->prepareStatement($sql); $stmt = WCF::getDB()->prepareStatement($sql);
$stmt->execute(); $stmt->execute();
$row = $stmt->fetchArray(); $row = $stmt->fetchArray();
$sql = "UPDATE wcf".WCF_N."_chat_room $sql = "UPDATE wcf".WCF_N."_chat_room
SET position = ".($row['max'] + 1)." SET position = ".($row['max'] + 1)."
WHERE roomID = ?"; WHERE roomID = ?";
$stmt = WCF::getDB()->prepareStatement($sql); $stmt = WCF::getDB()->prepareStatement($sql);
$stmt->execute(array($room->roomID)); $stmt->execute(array($room->roomID));
WCF::getDB()->commitTransaction(); WCF::getDB()->commitTransaction();