Use PreparedStatement::fetchSingleColumn()
authorMatthias Schmidt <gravatronics@live.com>
Mon, 28 Mar 2016 12:34:37 +0000 (14:34 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Mon, 28 Mar 2016 12:34:37 +0000 (14:34 +0200)
33 files changed:
wcfsetup/install/files/lib/acp/form/DataImportForm.class.php
wcfsetup/install/files/lib/acp/form/TemplateAddForm.class.php
wcfsetup/install/files/lib/acp/form/TemplateGroupAddForm.class.php
wcfsetup/install/files/lib/acp/form/UserEmailAddressExportForm.class.php
wcfsetup/install/files/lib/acp/page/IndexPage.class.php
wcfsetup/install/files/lib/acp/page/UserListPage.class.php
wcfsetup/install/files/lib/data/DatabaseObjectList.class.php
wcfsetup/install/files/lib/data/like/LikeAction.class.php
wcfsetup/install/files/lib/data/package/Package.class.php
wcfsetup/install/files/lib/data/poll/PollEditor.class.php
wcfsetup/install/files/lib/data/session/virtual/SessionVirtual.class.php
wcfsetup/install/files/lib/data/style/StyleEditor.class.php
wcfsetup/install/files/lib/data/user/TeamList.class.php
wcfsetup/install/files/lib/data/user/authentication/failure/UserAuthenticationFailure.class.php
wcfsetup/install/files/lib/data/user/follow/UserFollowAction.class.php
wcfsetup/install/files/lib/data/user/follow/UserFollowingAction.class.php
wcfsetup/install/files/lib/data/user/profile/visitor/UserProfileVisitorAction.class.php
wcfsetup/install/files/lib/system/WCFSetup.class.php
wcfsetup/install/files/lib/system/clipboard/ClipboardHandler.class.php
wcfsetup/install/files/lib/system/moderation/queue/ModerationQueueManager.class.php
wcfsetup/install/files/lib/system/moderation/queue/ModerationQueueReportManager.class.php
wcfsetup/install/files/lib/system/package/PackageArchive.class.php
wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php
wcfsetup/install/files/lib/system/package/PackageInstallationFormManager.class.php
wcfsetup/install/files/lib/system/package/plugin/ACLOptionPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/package/plugin/AbstractMenuPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/package/plugin/AbstractOptionPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/package/plugin/AbstractPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/search/mysql/MysqlSearchIndexManager.class.php
wcfsetup/install/files/lib/system/stat/AbstractStatDailyHandler.class.php
wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php
wcfsetup/install/files/lib/system/worker/MailWorker.class.php
wcfsetup/install/files/lib/util/UserUtil.class.php

index 9f20400428fde65df8c6a773a5431395ba4fde7a..7c0450b27f0890a008340f51bf2e494c41567aa7 100644 (file)
@@ -272,13 +272,12 @@ class DataImportForm extends AbstractForm {
                
                if (empty($_POST)) {
                        if (!$this->exporterName) {
-                               $sql = "SELECT  COUNT(*) AS count
+                               $sql = "SELECT  COUNT(*)
                                        FROM    wcf".WCF_N."_import_mapping";
                                $statement = WCF::getDB()->prepareStatement($sql);
                                $statement->execute();
-                               $row = $statement->fetchArray();
                                
-                               if ($row['count']) {
+                               if ($statement->fetchSingleColumn()) {
                                        $this->showMappingNotice = true;
                                }
                        }
index ead4b3cdb696def4add262338c2e15c4b7b9eabc..da113ae9cb094568600dad8e1ff524becccaa000 100644 (file)
@@ -157,13 +157,13 @@ class TemplateAddForm extends AbstractForm {
                        $conditionBuilder->add('packageID = ?', array($this->packageID));
                }
                
-               $sql = "SELECT  COUNT(*) AS count
+               $sql = "SELECT  COUNT(*)
                        FROM    wcf".WCF_N."_template
                        ".$conditionBuilder;
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute($conditionBuilder->getParameters());
-               $row = $statement->fetchArray();
-               if ($row['count']) {
+               
+               if ($statement->fetchSingleColumn()) {
                        throw new UserInputException('tplName', 'notUnique');
                }
        }
index 937a9aaaf4671a198a7c5b3fd0e1adc37e126058..769bf8fba20e0a3d999404266a85a8c19189ec24 100644 (file)
@@ -89,13 +89,13 @@ class TemplateGroupAddForm extends AbstractForm {
                        throw new UserInputException('templateGroupName');
                }
                
-               $sql = "SELECT  COUNT(*) AS count
+               $sql = "SELECT  COUNT(*)
                        FROM    wcf".WCF_N."_template_group
                        WHERE   templateGroupName = ?";
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute(array($this->templateGroupName));
-               $row = $statement->fetchArray();
-               if ($row['count']) {
+               
+               if ($statement->fetchSingleColumn()) {
                        throw new UserInputException('templateGroupName', 'notUnique');
                }
        }
@@ -112,13 +112,13 @@ class TemplateGroupAddForm extends AbstractForm {
                        throw new UserInputException('templateGroupFolderName', 'notValid');
                }
                
-               $sql = "SELECT  COUNT(*) AS count
+               $sql = "SELECT  COUNT(*)
                        FROM    wcf".WCF_N."_template_group
                        WHERE   templateGroupFolderName = ?";
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute(array($this->templateGroupFolderName));
-               $row = $statement->fetchArray();
-               if ($row['count']) {
+               
+               if ($statement->fetchSingleColumn()) {
                        throw new UserInputException('templateGroupFolderName', 'notUnique');
                }
        }
index b6e4b13243364019c855fd9bd0a9080dba8cbda9..265bd5319a213b04d7f62bc42b4cf6d99d63d1a2 100755 (executable)
@@ -117,12 +117,12 @@ class UserEmailAddressExportForm extends AbstractForm {
                $conditions->add("userID IN (?)", array($this->userIDs));
                
                // count users
-               $sql = "SELECT  COUNT(*) AS count
+               $sql = "SELECT  COUNT(*)
                        FROM    wcf".WCF_N."_user
                        ".$conditions;
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute($conditions->getParameters());
-               $count = $statement->fetchArray();
+               $count = $statement->fetchSingleColumn();
                
                // get users
                $sql = "SELECT          email
@@ -138,7 +138,7 @@ class UserEmailAddressExportForm extends AbstractForm {
                                echo "<address><![CDATA[".StringUtil::escapeCDATA($row['email'])."]]></address>\n";
                        }
                        else {
-                               echo $this->textSeparator . $row['email'] . $this->textSeparator . ($i < $count['count'] ? $this->separator : '');
+                               echo $this->textSeparator . $row['email'] . $this->textSeparator . ($i < $count ? $this->separator : '');
                        }
                        $i++;
                }
index 5ef133d475e445cb9c1117c4df573aaa0045af32..c94897bd7732b3838f77ac25fa5b0e4b925104ed 100755 (executable)
@@ -51,13 +51,12 @@ class IndexPage extends AbstractPage {
                
                $usersAwaitingApproval = 0;
                if (REGISTER_ACTIVATION_METHOD == 2) {
-                       $sql = "SELECT  COUNT(*) AS count
+                       $sql = "SELECT  COUNT(*)
                                FROM    wcf".WCF_N."_user
                                WHERE   activationCode <> 0";
                        $statement = WCF::getDB()->prepareStatement($sql);
                        $statement->execute();
-                       $row = $statement->fetchArray();
-                       $usersAwaitingApproval = $row['count'];
+                       $usersAwaitingApproval = $statement->fetchSingleColumn();
                }
                
                WCF::getTPL()->assign([
index d0dc3c12b925822f20aee05fee13199d11db968e..ff52bf4830489c06ea3cb4e367ba28906013a4ff 100755 (executable)
@@ -219,13 +219,13 @@ class UserListPage extends SortablePage {
                // call countItems event
                EventHandler::getInstance()->fireAction($this, 'countItems');
                
-               $sql = "SELECT  COUNT(*) AS count
+               $sql = "SELECT  COUNT(*)
                        FROM    wcf".WCF_N."_user user_table
                        ".$this->conditions;
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute($this->conditions->getParameters());
-               $row = $statement->fetchArray();
-               return $row['count'];
+               
+               return $statement->fetchColumn();
        }
        
        /**
index 52094685d3bfbf995999bd2b223f031af39bd8be..f59a281c0b65157732a389e2628bb0330dade63e 100644 (file)
@@ -143,14 +143,14 @@ abstract class DatabaseObjectList implements \Countable, ITraversableObject {
         * @return      integer
         */
        public function countObjects() {
-               $sql = "SELECT  COUNT(*) AS count
+               $sql = "SELECT  COUNT(*)
                        FROM    ".$this->getDatabaseTableName()." ".$this->getDatabaseTableAlias()."
                        ".$this->sqlConditionJoins."
                        ".$this->getConditionBuilder();
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute($this->getConditionBuilder()->getParameters());
-               $row = $statement->fetchArray();
-               return $row['count'];
+               
+               return $statement->fetchSingleColumn();
        }
        
        /**
index 3a45946375b227c420c4653123c173cf5d62f539..790aa9ba8470e836311532f448a84b78622d8299 100644 (file)
@@ -373,7 +373,7 @@ class LikeAction extends AbstractDatabaseObjectAction implements IGroupedUserLis
                //
                
                if ($newLikeObject->objectUserID) {
-                       $sql = "SELECT  COUNT(*) AS count
+                       $sql = "SELECT  COUNT(*)
                                FROM    wcf".WCF_N."_like
                                WHERE   objectTypeID = ?
                                        AND objectID = ?
@@ -384,17 +384,17 @@ class LikeAction extends AbstractDatabaseObjectAction implements IGroupedUserLis
                                $this->parameters['targetObjectID'],
                                Like::LIKE
                        ));
-                       $row = $statement->fetchArray();
+                       $count = $statement->fetchSingleColumn();
                        
-                       if ($row['count']) {
+                       if ($count) {
                                // update received likes
                                $userEditor = new UserEditor(new User($newLikeObject->objectUserID));
                                $userEditor->updateCounters(array(
-                                       'likesReceived' => $row['count']
+                                       'likesReceived' => $count
                                ));
                                
                                // add activity points
-                               UserActivityPointHandler::getInstance()->fireEvents('com.woltlab.wcf.like.activityPointEvent.receivedLikes', array($newLikeObject->objectUserID => $row['count']));
+                               UserActivityPointHandler::getInstance()->fireEvents('com.woltlab.wcf.like.activityPointEvent.receivedLikes', array($newLikeObject->objectUserID => $count));
                        }
                }
        }
index e89d25b322318386dacd9f7ac1e48c0068d9b5e3..9fa893d461b91b41703e5ff8855d75448026e6bf 100644 (file)
@@ -236,14 +236,13 @@ class Package extends DatabaseObject {
         * @return      boolean
         */
        public static function isAlreadyInstalled($package) {
-               $sql = "SELECT  COUNT(*) AS count
+               $sql = "SELECT  COUNT(*)
                        FROM    wcf".WCF_N."_package
                        WHERE   package = ?";
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute(array($package));
-               $row = $statement->fetchArray();
                
-               return ($row['count'] ? true : false);
+               return $statement->fetchSingleColumn() > 0;
        }
        
        /**
index 82452e167816cada0f3e3828e322f5c30193639c..febb71d6ced0ff4ac98ea1037a55f42a953f1cb3 100644 (file)
@@ -26,7 +26,7 @@ class PollEditor extends DatabaseObjectEditor {
                // update option votes
                $sql = "UPDATE  wcf".WCF_N."_poll_option poll_option
                        SET     poll_option.votes = (
-                                       SELECT  COUNT(*) AS count
+                                       SELECT  COUNT(*)
                                        FROM    wcf".WCF_N."_poll_option_vote
                                        WHERE   optionID = poll_option.optionID
                                )
@@ -37,9 +37,9 @@ class PollEditor extends DatabaseObjectEditor {
                // update total count
                $sql = "UPDATE  wcf".WCF_N."_poll poll
                        SET     poll.votes = (
-                                       SELECT          COUNT(DISTINCT userID) AS count
-                                       FROM            wcf".WCF_N."_poll_option_vote
-                                       WHERE           pollID = poll.pollID
+                                       SELECT  COUNT(DISTINCT userID)
+                                       FROM    wcf".WCF_N."_poll_option_vote
+                                       WHERE   pollID = poll.pollID
                                )
                        WHERE   poll.pollID = ?";
                $statement = WCF::getDB()->prepareStatement($sql);
index 8fe7420a2109bfcbda5923a531ddeeb3605ba088..cd8c0343a67f828b500b5af662285feb00b7f3f7 100644 (file)
@@ -66,13 +66,12 @@ class SessionVirtual extends DatabaseObject {
         * @return      integer
         */
        public static function countVirtualSessions($sessionID) {
-               $sql = "SELECT  COUNT(*) AS count
+               $sql = "SELECT  COUNT(*)
                        FROM    ".static::getDatabaseTableName()."
                        WHERE   sessionID = ?";
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute(array($sessionID));
-               $row = $statement->fetchArray();
                
-               return $row['count'];
+               return $statement->fetchSingleColumn();
        }
 }
index 5c3c98c51d3b20b9ed2460d4196d863567d277d8..04e9d20b4bb57d8c460b5148ed44967e36c991c4 100644 (file)
@@ -351,37 +351,35 @@ class StyleEditor extends DatabaseObjectEditor implements IEditableCachedObject
                                $templateGroupFolderName = preg_replace('/[^a-z0-9_-]/i', '', $templateGroupName);
                                if (empty($templateGroupFolderName)) $templateGroupFolderName = 'generic'.mb_substr(StringUtil::getRandomID(), 0, 8);
                                $originalTemplateGroupFolderName = $templateGroupFolderName;
-                                       
+                               
                                // get unique template group name
                                $i = 1;
                                while (true) {
-                                       $sql = "SELECT  COUNT(*) AS count
+                                       $sql = "SELECT  COUNT(*)
                                                FROM    wcf".WCF_N."_template_group
                                                WHERE   templateGroupName = ?";
                                        $statement = WCF::getDB()->prepareStatement($sql);
                                        $statement->execute([$templateGroupName]);
-                                       $row = $statement->fetchArray();
-                                       if (!$row['count']) break;
+                                       if (!$statement->fetchSingleColumn()) break;
                                        $templateGroupName = $originalTemplateGroupName . '_' . $i;
                                        $i++;
                                }
-                                       
+                               
                                // get unique folder name
                                $i = 1;
                                while (true) {
-                                       $sql = "SELECT  COUNT(*) AS count
+                                       $sql = "SELECT  COUNT(*)
                                                FROM    wcf".WCF_N."_template_group
                                                WHERE   templateGroupFolderName = ?";
                                        $statement = WCF::getDB()->prepareStatement($sql);
                                        $statement->execute([
                                                FileUtil::addTrailingSlash($templateGroupFolderName)
                                        ]);
-                                       $row = $statement->fetchArray();
-                                       if (!$row['count']) break;
+                                       if (!$statement->fetchSingleColumn()) break;
                                        $templateGroupFolderName = $originalTemplateGroupFolderName . '_' . $i;
                                        $i++;
                                }
-                                       
+                               
                                $templateGroupAction = new TemplateGroupAction([], 'create', [
                                        'data' => [
                                                'templateGroupName' => $templateGroupName,
index 626524412db12db833f6740cec08296ea2dd4b8c..e08129b4848e69b44d9031a3b57c25bcbd01c0b4 100644 (file)
@@ -25,15 +25,15 @@ class TeamList extends UserProfileList {
         * @see \wcf\data\DatabaseObjectList::countObjects()
         */
        public function countObjects() {
-               $sql = "SELECT  COUNT(*) AS count
+               $sql = "SELECT  COUNT(*)
                        FROM    wcf".WCF_N."_user_group user_group,
                                wcf".WCF_N."_user_to_group user_to_group
                        WHERE   user_to_group.groupID = user_group.groupID
                                AND user_group.showOnTeamPage = 1";
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute();
-               $row = $statement->fetchArray();
-               return $row['count'];
+               
+               return $statement->fetchSingleColumn();
        }
        
        /**
index 80d7c0ecff7adc625469e07c3c199be6f2959eca..8e152880e5bb0128019c45c787afddeffe799906 100644 (file)
@@ -49,12 +49,13 @@ class UserAuthenticationFailure extends DatabaseObject {
         * @return      boolean
         */
        public static function countIPFailures($ipAddress) {
-               $sql = "SELECT  COUNT(*) AS count
+               $sql = "SELECT  COUNT(*)
                        FROM    wcf".WCF_N."_user_authentication_failure
                        WHERE   ipAddress = ?
                                AND time > ?";
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute(array($ipAddress, TIME_NOW - USER_AUTHENTICATION_FAILURE_TIMEOUT));
+               
                return $statement->fetchColumn();
        }
        
@@ -65,12 +66,13 @@ class UserAuthenticationFailure extends DatabaseObject {
         * @return      boolean
         */
        public static function countUserFailures($userID) {
-               $sql = "SELECT  COUNT(*) AS count
+               $sql = "SELECT  COUNT(*)
                        FROM    wcf".WCF_N."_user_authentication_failure
                        WHERE   userID = ?
                                AND time > ?";
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute(array($userID, TIME_NOW - USER_AUTHENTICATION_FAILURE_TIMEOUT));
+               
                return $statement->fetchColumn();
        }
 }
index 1b48377a2c2db65d7332815ced02c7759a15f5a3..1a6cc07dcf6f5967c52503ed2a975cc5a9305277 100644 (file)
@@ -169,13 +169,12 @@ class UserFollowAction extends AbstractDatabaseObjectAction implements IGroupedU
         */
        public function getGroupedUserList() {
                // resolve page count
-               $sql = "SELECT  COUNT(*) AS count
+               $sql = "SELECT  COUNT(*)
                        FROM    wcf".WCF_N."_user_follow
                        WHERE   followUserID = ?";
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute(array($this->parameters['userID']));
-               $row = $statement->fetchArray();
-               $pageCount = ceil($row['count'] / 20);
+               $pageCount = ceil($statement->fetchSingleColumn() / 20);
                
                // get user ids
                $sql = "SELECT  userID
index b6845f7dd826b7267e318167fde55751ae07fe7b..768caa88970ce8fdcc088cff21c6fffa7fef3b18 100644 (file)
@@ -39,13 +39,12 @@ class UserFollowingAction extends UserFollowAction {
         */
        public function getGroupedUserList() {
                // resolve page count
-               $sql = "SELECT  COUNT(*) AS count
+               $sql = "SELECT  COUNT(*)
                        FROM    wcf".WCF_N."_user_follow
                        WHERE   userID = ?";
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute(array($this->parameters['userID']));
-               $row = $statement->fetchArray();
-               $pageCount = ceil($row['count'] / 20);
+               $pageCount = ceil($statement->fetchSingleColumn() / 20);
                
                // get user ids
                $sql = "SELECT  followUserID
index f4e0037e41f46c264f4bfcc3de5a8a8ee89d17fe..811062be02a50f7ed7f99b8eb83a08b8cc2e514b 100644 (file)
@@ -47,13 +47,12 @@ class UserProfileVisitorAction extends AbstractDatabaseObjectAction implements I
         */
        public function getGroupedUserList() {
                // resolve page count
-               $sql = "SELECT  COUNT(*) AS count
+               $sql = "SELECT  COUNT(*)
                        FROM    wcf".WCF_N."_user_profile_visitor
                        WHERE   ownerID = ?";
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute(array($this->parameters['userID']));
-               $row = $statement->fetchArray();
-               $pageCount = ceil($row['count'] / 20);
+               $pageCount = ceil($statement->fetchSingleColumn() / 20);
                
                // get user ids
                $sql = "SELECT          userID
index 73c5b8d4744d4187b9a76e77fca4078f00eef35a..eb2bed913dbdfee6586e2593ed3f81a38605b462 100644 (file)
@@ -1146,8 +1146,7 @@ class WCFSetup extends WCF {
                        WHERE   package = 'com.woltlab.wcf'";
                $statement = self::getDB()->prepareStatement($sql);
                $statement->execute();
-               $row = $statement->fetchArray();
-               if (!$row['count']) {
+               if (!$statement->fetchSingleColumn()) {
                        if (empty($wcfPackageFile)) {
                                throw new SystemException('the essential package com.woltlab.wcf is missing.');
                        }
index 50cb81706165e234f890a80b79e15a8bda461888..77f6bf9ccd117039264983d3791db993b5183309 100644 (file)
@@ -390,18 +390,13 @@ class ClipboardHandler extends SingletonFactory {
                        $conditionBuilder->add("objectTypeID = ?", array($objectTypeID));
                }
                
-               $sql = "SELECT  COUNT(*) AS count
+               $sql = "SELECT  COUNT(*)
                        FROM    wcf".WCF_N."_clipboard_item
                        ".$conditionBuilder;
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute($conditionBuilder->getParameters());
-               $count = $statement->fetchArray();
                
-               if ($count['count']) {
-                       return 1;
-               }
-               
-               return 0;
+               return $statement->fetchSingleColumn() ? 1 : 0;
        }
        
        /**
index 8517afe8e44683036298bdecf1270207956587d6..5467e9482a661025b48fef34ecbf15e17794d3c8 100644 (file)
@@ -223,15 +223,14 @@ class ModerationQueueManager extends SingletonFactory {
                        $conditions->add("moderation_queue_to_user.isAffected = ?", array(1));
                        $conditions->add("moderation_queue.status IN (?)", array(array(ModerationQueue::STATUS_OUTSTANDING, ModerationQueue::STATUS_PROCESSING)));
                        
-                       $sql = "SELECT          COUNT(*) AS count
+                       $sql = "SELECT          COUNT(*)
                                FROM            wcf".WCF_N."_moderation_queue_to_user moderation_queue_to_user
                                LEFT JOIN       wcf".WCF_N."_moderation_queue moderation_queue
                                ON              (moderation_queue.queueID = moderation_queue_to_user.queueID)
                                ".$conditions;
                        $statement = WCF::getDB()->prepareStatement($sql);
                        $statement->execute($conditions->getParameters());
-                       $row = $statement->fetchArray();
-                       $count = $row['count'];
+                       $count = $statement->fetchSingleColumn();
                        
                        // update storage data
                        UserStorageHandler::getInstance()->update(WCF::getUser()->userID, 'outstandingModerationCount', $count);
@@ -263,7 +262,7 @@ class ModerationQueueManager extends SingletonFactory {
                        $conditions->add("moderation_queue.time > ?", array(VisitTracker::getInstance()->getVisitTime('com.woltlab.wcf.moderation.queue')));
                        $conditions->add("(moderation_queue.time > tracked_visit.visitTime OR tracked_visit.visitTime IS NULL)");
                        
-                       $sql = "SELECT          COUNT(*) AS count
+                       $sql = "SELECT          COUNT(*)
                                FROM            wcf".WCF_N."_moderation_queue_to_user moderation_queue_to_user
                                LEFT JOIN       wcf".WCF_N."_moderation_queue moderation_queue
                                ON              (moderation_queue.queueID = moderation_queue_to_user.queueID)
@@ -272,9 +271,8 @@ class ModerationQueueManager extends SingletonFactory {
                                ".$conditions;
                        $statement = WCF::getDB()->prepareStatement($sql);
                        $statement->execute($conditions->getParameters());
-                       $row = $statement->fetchArray();
-                       $count = $row['count'];
-                               
+                       $count = $statement->fetchSingleColumn();
+                       
                        // update storage data
                        UserStorageHandler::getInstance()->update(WCF::getUser()->userID, 'unreadModerationCount', $count);
                }
index 6c28d06737f59e6d0a137368e0313ca2518d02b0..5d8418cbb0139aaa28839b539c4e1f435cc257a8 100644 (file)
@@ -33,7 +33,7 @@ class ModerationQueueReportManager extends AbstractModerationQueueManager {
        public function isAlreadyReported($objectType, $objectID) {
                $objectTypeID = $this->getObjectTypeID($objectType);
                
-               $sql = "SELECT  COUNT(*) AS count
+               $sql = "SELECT  COUNT(*)
                        FROM    wcf".WCF_N."_moderation_queue
                        WHERE   objectTypeID = ?
                                AND objectID = ?";
@@ -42,9 +42,8 @@ class ModerationQueueReportManager extends AbstractModerationQueueManager {
                        $objectTypeID,
                        $objectID
                ));
-               $row = $statement->fetchArray();
                
-               return ($row['count'] == 0 ? false : true);
+               return $statement->fetchSingleColumn() > 0;
        }
        
        /**
index 774359e6cd9f1ef25aa5331f4e601eabc128ab7f..91d824a0956a381635ea92684c3138e6b224697f 100644 (file)
@@ -463,14 +463,13 @@ class PackageArchive {
         * @return      boolean
         */
        public function isAlreadyInstalled() {
-               $sql = "SELECT  COUNT(*) AS count
+               $sql = "SELECT  COUNT(*)
                        FROM    wcf".WCF_N."_package
                        WHERE   package = ?";
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute(array($this->packageInfo['name']));
-               $row = $statement->fetchArray();
                
-               return ($row['count'] > 0) ? true : false;
+               return $statement->fetchSingleColumn() > 0;
        }
        
        /**
@@ -493,7 +492,7 @@ class PackageArchive {
                        '%.'.Package::getAbbreviation($this->packageInfo['name'])
                ));
                
-               return $statement->fetchColumn();
+               return $statement->fetchSingleColumn() > 0;
        }
        
        /**
index fbce7a40e9e5948906452db7bfffe24c2881afb9..e8181f7baafc6e867cd06a5e9bab80257138c436 100644 (file)
@@ -699,13 +699,12 @@ class PackageInstallationDispatcher {
                        
                        $defaultPath = FileUtil::addTrailingSlash(FileUtil::unifyDirSeparator(dirname(WCF_DIR)));
                        // check if there is already an application
-                       $sql = "SELECT  COUNT(*) AS count
+                       $sql = "SELECT  COUNT(*)
                                FROM    wcf".WCF_N."_package
                                WHERE   packageDir = ?";
                        $statement = WCF::getDB()->prepareStatement($sql);
                        $statement->execute(array('../'));
-                       $row = $statement->fetchArray();
-                       if ($row['count']) {
+                       if ($statement->fetchSingleColumn()) {
                                // use abbreviation
                                $defaultPath .= strtolower(Package::getAbbreviation($this->getPackage()->package)) . '/';
                        }
index 5bbd07ec687a391814190cff6ff4edb46906a254..d3e10c658e390e2f4ab55e69f2bcf92d4f54a9c0 100644 (file)
@@ -57,7 +57,7 @@ abstract class PackageInstallationFormManager {
         * @return      boolean
         */
        public static function findForm(PackageInstallationQueue $queue, $formName) {
-               $sql = "SELECT  COUNT(*) AS count
+               $sql = "SELECT  COUNT(*)
                        FROM    wcf".WCF_N."_package_installation_form
                        WHERE   queueID = ?
                                AND formName = ?";
@@ -66,9 +66,8 @@ abstract class PackageInstallationFormManager {
                        $queue->queueID,
                        $formName
                ));
-               $row = $statement->fetchArray();
                
-               return (bool)$row['count'];
+               return $statement->fetchSingleColumn() > 0;
        }
        
        /**
index 2e4c01992ef337f7c87018883f79bfa5a3631493..62a91ce43bc95bd18601bac8574b10b1226d738e 100644 (file)
@@ -104,7 +104,7 @@ class ACLOptionPackageInstallationPlugin extends AbstractOptionPackageInstallati
                        
                        // validate category name
                        if (isset($data['categoryname'])) {
-                               $sql = "SELECT  COUNT(categoryID) AS count
+                               $sql = "SELECT  COUNT(categoryID)
                                        FROM    wcf".WCF_N."_".$this->tableName."_category
                                        WHERE   categoryName = ?
                                                AND objectTypeID = ?";
@@ -113,8 +113,8 @@ class ACLOptionPackageInstallationPlugin extends AbstractOptionPackageInstallati
                                        $data['categoryname'],
                                        $objectTypeID
                                ));
-                               $row = $statement->fetchArray();
-                               if (!$row) {
+                               
+                               if (!$statement->fetchSingleColumn()) {
                                        throw new SystemException("unknown category '".$data['categoryname']."' for acl object type '".$data['objecttype']."' given");
                                }
                        }
index f8c0c1984e98134a26f03fd5ac30c6f535e0af76..9ad13b0cd7474c261745a2c20e2fe07e218678e5 100644 (file)
@@ -59,14 +59,13 @@ abstract class AbstractMenuPackageInstallationPlugin extends AbstractXMLPackageI
                        return;
                }
                
-               $sql = "SELECT  COUNT(menuItemID) AS count
+               $sql = "SELECT  COUNT(menuItemID)
                        FROM    ".$this->application.WCF_N."_".$this->tableName."
                        WHERE   menuItem = ?";
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute(array($data['parentMenuItem']));
-               $row = $statement->fetchArray();
                
-               if (!$row['count']) {
+               if (!$statement->fetchSingleColumn()) {
                        throw new SystemException("Unable to find parent 'menu item' with name '".$data['parentMenuItem']."' for 'menu item' with name '".$data['menuItem']."'.");
                }
        }
index e7bcddbd4dbe4bed0bc5e9aca970fe66612e326a..3c94d1de2a59ffc695451925311703d996adc8d6 100644 (file)
@@ -127,14 +127,13 @@ abstract class AbstractOptionPackageInstallationPlugin extends AbstractXMLPackag
                        
                        // validate parent
                        if (!empty($data['parentCategoryName'])) {
-                               $sql = "SELECT  COUNT(categoryID) AS count
+                               $sql = "SELECT  COUNT(categoryID)
                                        FROM    ".$this->application.WCF_N."_".$this->tableName."_category
                                        WHERE   categoryName = ?";
                                $statement = WCF::getDB()->prepareStatement($sql);
                                $statement->execute(array($data['parentCategoryName']));
-                               $row = $statement->fetchArray();
                                
-                               if (!$row['count']) {
+                               if (!$statement->fetchSingleColumn()) {
                                        throw new SystemException("Unable to find parent 'option category' with name '".$data['parentCategoryName']."' for category with name '".$data['categoryName']."'.");
                                }
                        }
@@ -175,13 +174,13 @@ abstract class AbstractOptionPackageInstallationPlugin extends AbstractXMLPackag
         */
        public function hasUninstall() {
                $hasUninstallOptions = parent::hasUninstall();
-               $sql = "SELECT  COUNT(categoryID) AS count
+               $sql = "SELECT  COUNT(categoryID)
                        FROM    ".$this->application.WCF_N."_".$this->tableName."_category
                        WHERE   packageID = ?";
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute(array($this->installation->getPackageID()));
-               $categoryCount = $statement->fetchArray();
-               return ($hasUninstallOptions || $categoryCount['count'] > 0);
+               
+               return ($hasUninstallOptions || $statement->fetchSingleColumn() > 0);
        }
        
        /**
index 39c8d53ce49e089eb1169079722080f934808ee3..d6fc74dc30b75e5c42840f519f21029d34c13fa6 100644 (file)
@@ -79,13 +79,13 @@ abstract class AbstractPackageInstallationPlugin implements IPackageInstallation
                // call 'hasUninstall' event
                EventHandler::getInstance()->fireAction($this, 'hasUninstall');
                
-               $sql = "SELECT  COUNT(*) AS count
+               $sql = "SELECT  COUNT(*)
                        FROM    ".$this->application.WCF_N."_".$this->tableName."
                        WHERE   packageID = ?";
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute(array($this->installation->getPackageID()));
-               $installationCount = $statement->fetchArray();
-               return $installationCount['count'];
+               
+               return $statement->fetchSingleColumn() > 0;
        }
        
        /**
index 5fad06d250d2961164d61a761ee352cacc4e8e3c..0b9ed2440abb1ee4fa6afe1c96443801e2d7e6ef 100644 (file)
@@ -71,13 +71,13 @@ class MysqlSearchIndexManager extends AbstractSearchIndexManager {
                $tableName = SearchIndexManager::getTableName($objectType);
                
                // check if table already exists
-               $sql = "SELECT  COUNT(*) AS count
+               $sql = "SELECT  COUNT(*)
                        FROM    wcf".WCF_N."_package_installation_sql_log
                        WHERE   sqlTable = ?";
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute(array($tableName));
-               $row = $statement->fetchArray();
-               if ($row['count']) {
+               
+               if ($statement->fetchSingleColumn()) {
                        // table already exists
                        return false;
                }
index 202010a3c4ba0c3504869be5c014abfadb91d475..d390db36e94751f252f57b360df63e3acaca4513 100644 (file)
@@ -22,7 +22,7 @@ abstract class AbstractStatDailyHandler implements IStatDailyHandler {
         * @return      integer
         */
        protected function getCounter($date, $tableName, $dateColumnName) {
-               $sql = "SELECT  COUNT(*) AS count
+               $sql = "SELECT  COUNT(*)
                        FROM    " . $tableName . "
                        WHERE   " . $dateColumnName . " BETWEEN ? AND ?";
                $statement = WCF::getDB()->prepareStatement($sql);
@@ -39,7 +39,7 @@ abstract class AbstractStatDailyHandler implements IStatDailyHandler {
         * @return      integer
         */
        protected function getTotal($date, $tableName, $dateColumnName) {
-               $sql = "SELECT  COUNT(*) AS count
+               $sql = "SELECT  COUNT(*)
                        FROM    " . $tableName . "
                        WHERE   " . $dateColumnName . " < ?";
                $statement = WCF::getDB()->prepareStatement($sql);
index 3fd262f31283b84d18fa1678f743800fa1707430..b9aa49bd6a67f925aeada0cbdffbfb2a15312cc2 100644 (file)
@@ -257,7 +257,7 @@ class UserNotificationHandler extends SingletonFactory {
                                
                                // cache does not exist or is outdated
                                if ($data === null || $skipCache) {
-                                       $sql = "SELECT  COUNT(*) AS count
+                                       $sql = "SELECT  COUNT(*)
                                                FROM    wcf".WCF_N."_user_notification
                                                WHERE   userID = ?
                                                        AND confirmTime = ?";
@@ -267,8 +267,7 @@ class UserNotificationHandler extends SingletonFactory {
                                                0
                                        ));
                                        
-                                       $row = $statement->fetchArray();
-                                       $this->notificationCount = $row['count'];
+                                       $this->notificationCount = $statement->fetchSingleColumn();
                                        
                                        // update storage data
                                        UserStorageHandler::getInstance()->update(WCF::getUser()->userID, 'userNotificationCount', serialize($this->notificationCount));
@@ -288,14 +287,13 @@ class UserNotificationHandler extends SingletonFactory {
         * @return      integer
         */
        public function countAllNotifications() {
-               $sql = "SELECT  COUNT(*) AS count
+               $sql = "SELECT  COUNT(*)
                        FROM    wcf".WCF_N."_user_notification
                        WHERE   userID = ?";
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute(array(WCF::getUser()->userID));
-               $row = $statement->fetchArray();
                
-               return $row['count'];
+               return $statement->fetchSingleColumn();
        }
        
        /**
index d304d4c69707aa1f5772feb8dad029f0a9f0c310..6bf09369d5bf0bb17367e73c243e395cfb217971 100644 (file)
@@ -71,14 +71,13 @@ class MailWorker extends AbstractWorker {
                        }
                }
                
-               $sql = "SELECT  COUNT(*) AS count
+               $sql = "SELECT  COUNT(*)
                        FROM    wcf".WCF_N."_user user
                        ".$this->conditions;
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute($this->conditions->getParameters());
-               $row = $statement->fetchArray();
                
-               $this->count = $row['count'];
+               $this->count = $statement->fetchSingleColumn();
        }
        
        /**
index b272c8ccabc8b49e8694590b25e9eca817afed4a..2709f68f239046164ba36de536661b2dcd2c9a44 100644 (file)
@@ -51,13 +51,13 @@ final class UserUtil {
         * @return      boolean
         */
        public static function isAvailableUsername($name) {
-               $sql = "SELECT  COUNT(username) AS count
+               $sql = "SELECT  COUNT(username)
                        FROM    wcf".WCF_N."_user
                        WHERE   username = ?";
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute(array($name));
-               $row = $statement->fetchArray();
-               return $row['count'] == 0;
+               
+               return $statement->fetchSingleColumn() == 0;
        }
        
        /**
@@ -90,13 +90,13 @@ final class UserUtil {
         * @return      boolean
         */
        public static function isAvailableEmail($email) {
-               $sql = "SELECT  COUNT(email) AS count
+               $sql = "SELECT  COUNT(email)
                        FROM    wcf".WCF_N."_user
                        WHERE   email = ?";
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute(array($email));
-               $row = $statement->fetchArray();
-               return $row['count'] == 0;
+               
+               return $statement->fetchSingleColumn() == 0;
        }
        
        /**