Use `->prepare()` in favor of `->prepareStatement()`

This commit is contained in:
Tim Düsterhus 2022-03-04 17:52:33 +01:00
parent f1fdf31ccd
commit 27213e507f
Signed by: TimWolla
GPG Key ID: 8FF75566094168AF
16 changed files with 74 additions and 74 deletions

View File

@ -5,7 +5,7 @@
* Use of this software is governed by the Business Source License
* included in the LICENSE file.
*
* Change Date: 2025-03-05
* Change Date: 2026-03-04
*
* On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2
@ -42,9 +42,9 @@ class Command extends \wcf\data\ProcessibleDatabaseObject {
}
$sql = "SELECT COUNT(*)
FROM chat".WCF_N."_command_trigger
FROM chat1_command_trigger
WHERE commandID = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement = WCF::getDB()->prepare($sql);
$statement->execute([ $this->commandID ]);
return $statement->fetchSingleColumn() > 0;
}

View File

@ -5,7 +5,7 @@
* Use of this software is governed by the Business Source License
* included in the LICENSE file.
*
* Change Date: 2025-03-05
* Change Date: 2026-03-04
*
* On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2
@ -42,9 +42,9 @@ class CommandTrigger extends \wcf\data\DatabaseObject implements \wcf\system\req
*/
public static function getTriggerByName($name) {
$sql = "SELECT *
FROM chat".WCF_N."_command_trigger
FROM chat1_command_trigger
WHERE commandTrigger = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement = WCF::getDB()->prepare($sql);
$statement->execute([ $name ]);
$row = $statement->fetchArray();
if (!$row) $row = [];

View File

@ -5,7 +5,7 @@
* Use of this software is governed by the Business Source License
* included in the LICENSE file.
*
* Change Date: 2025-03-05
* Change Date: 2026-03-04
*
* On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2
@ -34,8 +34,8 @@ class MessageAction extends \wcf\data\AbstractDatabaseObjectAction {
$message = parent::create();
if (isset($this->parameters['updateTimestamp']) && $this->parameters['updateTimestamp']) {
$sql = "UPDATE chat".WCF_N."_room_to_user SET lastPush = ? WHERE roomID = ? AND userID = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$sql = "UPDATE chat1_room_to_user SET lastPush = ? WHERE roomID = ? AND userID = ?";
$statement = WCF::getDB()->prepare($sql);
$statement->execute([ TIME_NOW, $message->roomID, $message->userID ]);
}
if (isset($this->parameters['grantPoints']) && $this->parameters['grantPoints']) {
@ -128,9 +128,9 @@ class MessageAction extends \wcf\data\AbstractDatabaseObjectAction {
if (!CHAT_LOG_ARCHIVETIME) return;
$sql = "SELECT messageID
FROM chat".WCF_N."_message
FROM chat1_message
WHERE time < ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement = WCF::getDB()->prepare($sql);
$statement->execute([ TIME_NOW - CHAT_LOG_ARCHIVETIME * 86400 ]);
$messageIDs = $statement->fetchAll(\PDO::FETCH_COLUMN);
@ -179,22 +179,22 @@ class MessageAction extends \wcf\data\AbstractDatabaseObjectAction {
WCF::getDB()->beginTransaction();
// update timestamp
$sql = "UPDATE chat".WCF_N."_room_to_user
$sql = "UPDATE chat1_room_to_user
SET lastPull = ?
WHERE roomID = ?
AND userID = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement = WCF::getDB()->prepare($sql);
$statement->execute([ TIME_NOW
, $room->roomID
, WCF::getUser()->userID
]);
$sql = "UPDATE chat".WCF_N."_session
$sql = "UPDATE chat1_session
SET lastRequest = ?
WHERE roomID = ?
AND userID = ?
AND sessionID = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement = WCF::getDB()->prepare($sql);
$statement->execute([ TIME_NOW
, $room->roomID
, WCF::getUser()->userID
@ -226,10 +226,10 @@ class MessageAction extends \wcf\data\AbstractDatabaseObjectAction {
}
$sql = "SELECT messageID
FROM chat".WCF_N."_message
FROM chat1_message
".$condition."
ORDER BY messageID ".$sortOrder;
$statement = WCF::getDB()->prepareStatement($sql, 20);
$statement = WCF::getDB()->prepare($sql, 20);
$statement->execute($condition->getParameters());
$messageIDs = $statement->fetchAll(\PDO::FETCH_COLUMN);

View File

@ -5,7 +5,7 @@
* Use of this software is governed by the Business Source License
* included in the LICENSE file.
*
* Change Date: 2025-03-05
* Change Date: 2026-03-04
*
* On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2
@ -212,12 +212,12 @@ final class Room extends \wcf\data\DatabaseObject implements \wcf\system\request
public function getUsers() {
if (self::$userToRoom === null) {
$sql = "SELECT r2u.userID, r2u.roomID
FROM chat".WCF_N."_room_to_user r2u
INNER JOIN wcf".WCF_N."_user u
FROM chat1_room_to_user r2u
INNER JOIN wcf1_user u
ON r2u.userID = u.userID
WHERE r2u.active = ?
ORDER BY u.username ASC";
$statement = WCF::getDB()->prepareStatement($sql);
$statement = WCF::getDB()->prepare($sql);
$statement->execute([ 1 ]);
self::$userToRoom = $statement->fetchMap('roomID', 'userID', false);

View File

@ -5,7 +5,7 @@
* Use of this software is governed by the Business Source License
* included in the LICENSE file.
*
* Change Date: 2025-03-05
* Change Date: 2026-03-04
*
* On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2
@ -73,8 +73,8 @@ class RoomAction extends \wcf\data\AbstractDatabaseObjectAction implements \wcf\
try {
// Create room_to_user mapping.
$sql = "INSERT INTO chat".WCF_N."_room_to_user (active, roomID, userID) VALUES (?, ?, ?)";
$statement = WCF::getDB()->prepareStatement($sql);
$sql = "INSERT INTO chat1_room_to_user (active, roomID, userID) VALUES (?, ?, ?)";
$statement = WCF::getDB()->prepare($sql);
$statement->execute([ 0, $room->roomID, $user->userID ]);
}
catch (\wcf\system\database\exception\DatabaseException $e) {
@ -83,8 +83,8 @@ class RoomAction extends \wcf\data\AbstractDatabaseObjectAction implements \wcf\
}
try {
$sql = "INSERT INTO chat".WCF_N."_session (roomID, userID, sessionID, lastRequest) VALUES (?, ?, ?, ?)";
$statement = WCF::getDB()->prepareStatement($sql);
$sql = "INSERT INTO chat1_session (roomID, userID, sessionID, lastRequest) VALUES (?, ?, ?, ?)";
$statement = WCF::getDB()->prepare($sql);
$statement->execute([ $room->roomID, $user->userID, $sessionID, TIME_NOW ]);
}
catch (\wcf\system\database\exception\DatabaseException $e) {
@ -106,8 +106,8 @@ class RoomAction extends \wcf\data\AbstractDatabaseObjectAction implements \wcf\
}
// Attempt to mark the user as active in the room.
$sql = "UPDATE chat".WCF_N."_room_to_user SET active = ? WHERE roomID = ? AND userID = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$sql = "UPDATE chat1_room_to_user SET active = ? WHERE roomID = ? AND userID = ?";
$statement = WCF::getDB()->prepare($sql);
$statement->execute([ 1, $room->roomID, $user->userID ]);
if ($statement->getAffectedRows() === 0) {
// The User already is inside the room: Nothing to do here.
@ -115,8 +115,8 @@ class RoomAction extends \wcf\data\AbstractDatabaseObjectAction implements \wcf\
}
// Update lastPull. This must not be merged into the above query, because of the 'getAffectedRows' check.
$sql = "UPDATE chat".WCF_N."_room_to_user SET lastPull = ? WHERE roomID = ? AND userID = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$sql = "UPDATE chat1_room_to_user SET lastPull = ? WHERE roomID = ? AND userID = ?";
$statement = WCF::getDB()->prepare($sql);
$statement->execute([ TIME_NOW, $room->roomID, $user->userID ]);
(new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID
@ -179,9 +179,9 @@ class RoomAction extends \wcf\data\AbstractDatabaseObjectAction implements \wcf\
if ($sessionID !== null) {
$condition->add('sessionID = ?', [ $sessionID ]);
}
$sql = "DELETE FROM chat".WCF_N."_session
$sql = "DELETE FROM chat1_session
".$condition;
$statement = WCF::getDB()->prepareStatement($sql);
$statement = WCF::getDB()->prepare($sql);
$statement->execute($condition->getParameters());
if ($statement->getAffectedRows() === 0) {
throw new UserInputException('sessionID');
@ -193,18 +193,18 @@ class RoomAction extends \wcf\data\AbstractDatabaseObjectAction implements \wcf\
// Check whether we deleted the last session.
$sql = "SELECT COUNT(*)
FROM chat".WCF_N."_session
FROM chat1_session
WHERE roomID = ?
AND userID = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement = WCF::getDB()->prepare($sql);
$statement->execute([ $room->roomID, $user->userID ]);
// We did not: Nothing to do here.
if ($statement->fetchColumn()) return;
// Mark the user as inactive.
$sql = "UPDATE chat".WCF_N."_room_to_user SET active = ? WHERE roomID = ? AND userID = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$sql = "UPDATE chat1_room_to_user SET active = ? WHERE roomID = ? AND userID = ?";
$statement = WCF::getDB()->prepare($sql);
$statement->execute([ 0, $room->roomID, $user->userID ]);
if ($statement->getAffectedRows() === 0) throw new \LogicException('Unreachable');

View File

@ -5,7 +5,7 @@
* Use of this software is governed by the Business Source License
* included in the LICENSE file.
*
* Change Date: 2025-03-05
* Change Date: 2026-03-04
*
* On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2
@ -40,9 +40,9 @@ class User extends \wcf\data\DatabaseObjectDecorator implements \JsonSerializabl
public function getRoomAssociations($skipCache = false) {
if ($this->roomToUser === null || $skipCache) {
$sql = "SELECT *
FROM chat".WCF_N."_room_to_user
FROM chat1_room_to_user
WHERE userID = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement = WCF::getDB()->prepare($sql);
$statement->execute([ $this->userID ]);
$this->roomToUser = [ ];
while (($row = $statement->fetchArray())) {
@ -86,9 +86,9 @@ class User extends \wcf\data\DatabaseObjectDecorator implements \JsonSerializabl
*/
public static function getDeadSessions() {
$sql = "SELECT userID, roomID, sessionID
FROM chat".WCF_N."_session
FROM chat1_session
WHERE lastRequest < ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement = WCF::getDB()->prepare($sql);
$statement->execute([ TIME_NOW - 60 * 3 ]);
return $statement->fetchAll(\PDO::FETCH_ASSOC);

View File

@ -5,7 +5,7 @@
* Use of this software is governed by the Business Source License
* included in the LICENSE file.
*
* Change Date: 2025-03-05
* Change Date: 2026-03-04
*
* On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2
@ -113,10 +113,10 @@ class LogPage extends \wcf\page\AbstractPage {
}
$sql = "SELECT messageID
FROM chat".WCF_N."_message
FROM chat1_message
".$condition."
ORDER BY messageID ASC";
$statement = WCF::getDB()->prepareStatement($sql, 20);
$statement = WCF::getDB()->prepare($sql, 20);
$statement->execute($condition->getParameters());
$messageIDs = $statement->fetchAll(\PDO::FETCH_COLUMN);

View File

@ -5,7 +5,7 @@
* Use of this software is governed by the Business Source License
* included in the LICENSE file.
*
* Change Date: 2025-03-05
* Change Date: 2026-03-04
*
* On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2
@ -75,8 +75,8 @@ class RoomPage extends \wcf\page\AbstractPage {
$package = \wcf\data\package\PackageCache::getInstance()->getPackageByIdentifier('be.bastelstu.chat');
if (stripos($package->packageVersion, 'Alpha') !== false) {
$sql = "SELECT COUNT(*) FROM wcf".WCF_N."_user";
$statement = WCF::getDB()->prepareStatement($sql);
$sql = "SELECT COUNT(*) FROM wcf1_user";
$statement = WCF::getDB()->prepare($sql);
$statement->execute();
$userCount = $statement->fetchSingleColumn();
if ((($userCount > 5 && !OFFLINE) || ($userCount > 30 && OFFLINE)) && sha1(WCF_UUID) !== '643a6b3af2a6ea3d393c4d8371e75d7d1b66e0d0') {
@ -90,7 +90,7 @@ class RoomPage extends \wcf\page\AbstractPage {
*/
public function readData() {
$sql = "SELECT 1";
$statement = WCF::getDB()->prepareStatement($sql);
$statement = WCF::getDB()->prepare($sql);
$statement->execute();
if ($statement->fetchSingleColumn() !== 1) {
throw new NamedUserException('PHP must be configured to use the MySQLnd driver, instead of libmysqlclient.');

View File

@ -5,7 +5,7 @@
* Use of this software is governed by the Business Source License
* included in the LICENSE file.
*
* Change Date: 2025-03-05
* Change Date: 2026-03-04
*
* On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2
@ -41,8 +41,8 @@ class CommandCacheBuilder extends \wcf\system\cache\builder\AbstractCacheBuilder
}
$sql = "SELECT *
FROM chat".WCF_N."_command_trigger";
$statement = WCF::getDB()->prepareStatement($sql);
FROM chat1_command_trigger";
$statement = WCF::getDB()->prepare($sql);
$statement->execute();
$data['triggers'] = $statement->fetchMap('commandTrigger', 'commandID');

View File

@ -40,11 +40,11 @@ class PermissionCacheBuilder extends \wcf\system\cache\builder\AbstractCacheBuil
$sql = "SELECT option_to_group.objectID AS roomID,
option_to_group.optionValue,
acl_option.optionName AS permission
FROM wcf".WCF_N."_acl_option acl_option
INNER JOIN wcf".WCF_N."_acl_option_to_group option_to_group
FROM wcf1_acl_option acl_option
INNER JOIN wcf1_acl_option_to_group option_to_group
ON option_to_group.optionID = acl_option.optionID
".$conditionBuilder;
$statement = WCF::getDB()->prepareStatement($sql);
$statement = WCF::getDB()->prepare($sql);
$statement->execute($conditionBuilder->getParameters());
while (($row = $statement->fetchArray())) {
if (!isset($data[$row['roomID']][$row['permission']])) {

View File

@ -5,7 +5,7 @@
* Use of this software is governed by the Business Source License
* included in the LICENSE file.
*
* Change Date: 2025-03-05
* Change Date: 2026-03-04
*
* On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2
@ -96,10 +96,10 @@ class TemproomCommand extends AbstractCommand implements ICommand {
$recipient = $this->getUser($this->assertParameter($parameters, 'username'));
WCF::getDB()->beginTransaction();
try {
$sql = "INSERT INTO chat".WCF_N."_room_temporary_invite
$sql = "INSERT INTO chat1_room_temporary_invite
(userID, roomID)
VALUES (?, ?)";
$statement = WCF::getDB()->prepareStatement($sql);
$statement = WCF::getDB()->prepare($sql);
$statement->execute([ $recipient->userID, $room->roomID ]);
}
catch (\wcf\system\database\DatabaseException $e) {

View File

@ -5,7 +5,7 @@
* Use of this software is governed by the Business Source License
* included in the LICENSE file.
*
* Change Date: 2025-03-05
* Change Date: 2026-03-04
*
* On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2
@ -27,11 +27,11 @@ class HourlyCleanUpCronjobExecuteChatCleanUpListener implements \wcf\system\even
(new \chat\data\message\MessageAction([ ], 'prune'))->executeAction();
(new \chat\data\user\UserAction([], 'clearDeadSessions'))->executeAction();
$sql = "UPDATE chat".WCF_N."_room_to_user
$sql = "UPDATE chat1_room_to_user
SET active = ?
WHERE (roomID, userID) NOT IN (SELECT roomID, userID FROM chat".WCF_N."_session)
WHERE (roomID, userID) NOT IN (SELECT roomID, userID FROM chat1_session)
AND active = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement = WCF::getDB()->prepare($sql);
$statement->execute([ 0, 1 ]);
if ($statement->getAffectedRows()) {
\wcf\functions\exception\logThrowable(new \Exception('Unreachable'));

View File

@ -5,7 +5,7 @@
* Use of this software is governed by the Business Source License
* included in the LICENSE file.
*
* Change Date: 2025-03-05
* Change Date: 2026-03-04
*
* On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 3
@ -32,10 +32,10 @@ class RoomCanSeeTemproomListener implements \wcf\system\event\listener\IParamete
if ($eventObj->ownerID === $user->userID) return;
$sql = "SELECT COUNT(*)
FROM chat".WCF_N."_room_temporary_invite
FROM chat1_room_temporary_invite
WHERE userID = ?
AND roomID = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement = WCF::getDB()->prepare($sql);
$statement->execute([ $user->userID, $eventObj->roomID ]);
if ($statement->fetchSingleColumn() > 0) return;

View File

@ -5,7 +5,7 @@
* Use of this software is governed by the Business Source License
* included in the LICENSE file.
*
* Change Date: 2025-03-05
* Change Date: 2026-03-04
*
* On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2
@ -37,17 +37,17 @@ trait TRoomPageHandler {
*/
public function lookup($searchString) {
$sql = "(SELECT ('chat.room.room' || roomID || '.title') AS languageItem
FROM chat".WCF_N."_room
FROM chat1_room
WHERE title LIKE ?
)
UNION
(SELECT languageItem
FROM wcf".WCF_N."_language_item
FROM wcf1_language_item
WHERE languageItemValue LIKE ?
AND languageItem LIKE ?
AND languageID = ?
)";
$statement = WCF::getDB()->prepareStatement($sql);
$statement = WCF::getDB()->prepare($sql);
$statement->execute([ '%'.$searchString.'%'
, '%'.$searchString.'%'
, 'chat.room.room%.title'

View File

@ -69,11 +69,11 @@ class PermissionHandler {
$sql = "SELECT option_to_user.objectID AS roomID,
option_to_user.optionValue,
acl_option.optionName AS permission
FROM wcf".WCF_N."_acl_option acl_option
INNER JOIN wcf".WCF_N."_acl_option_to_user option_to_user
FROM wcf1_acl_option acl_option
INNER JOIN wcf1_acl_option_to_user option_to_user
ON option_to_user.optionID = acl_option.optionID
".$conditionBuilder;
$statement = WCF::getDB()->prepareStatement($sql);
$statement = WCF::getDB()->prepare($sql);
$statement->execute($conditionBuilder->getParameters());
while (($row = $statement->fetchArray())) {
$userPermissions[$row['roomID']][$row['permission']] = $row['optionValue'];

View File

@ -5,7 +5,7 @@
* Use of this software is governed by the Business Source License
* included in the LICENSE file.
*
* Change Date: 2025-03-05
* Change Date: 2026-03-04
*
* On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2
@ -46,7 +46,7 @@ class ChatCommandPackageInstallationPlugin extends AbstractXMLPackageInstallatio
$sql = "DELETE FROM ".$this->application.WCF_N."_".$this->tableName."
WHERE packageID = ?
AND identifier = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement = WCF::getDB()->prepare($sql);
WCF::getDB()->beginTransaction();
foreach ($items as $item) {
@ -134,7 +134,7 @@ class ChatCommandPackageInstallationPlugin extends AbstractXMLPackageInstallatio
// import initial triggers
$sql = "INSERT INTO ".$this->application.WCF_N."_command_trigger (commandTrigger, commandID)
VALUES (?, ?)";
$statement = WCF::getDB()->prepareStatement($sql);
$statement = WCF::getDB()->prepare($sql);
try {
WCF::getDB()->beginTransaction();