commit 37d24b37a9b3c1683fcadb1a976b08030a1fccb2 Author: Damien Tournoud Date: Sun Sep 11 19:24:31 2011 +0200 Issue #1266694: remove DatabaseStatementInterface::fetchField() which duplicates PDOStatement::fetchColumn(). diff --git a/includes/batch.inc b/includes/batch.inc index 513a8f9..2bab776 100644 --- a/includes/batch.inc +++ b/includes/batch.inc @@ -28,7 +28,7 @@ function batch_load($id) { $batch = db_query("SELECT batch FROM {batch} WHERE bid = :bid AND token = :token", array( ':bid' => $id, ':token' => drupal_get_token($id), - ))->fetchField(); + ))->fetchColumn(); if ($batch) { return unserialize($batch); } diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc index 2856529..77ca8a7 100644 --- a/includes/bootstrap.inc +++ b/includes/bootstrap.inc @@ -843,7 +843,7 @@ function drupal_get_filename($type, $name, $filename = NULL) { else { try { if (function_exists('db_query')) { - $file = db_query("SELECT filename FROM {system} WHERE name = :name AND type = :type", array(':name' => $name, ':type' => $type))->fetchField(); + $file = db_query("SELECT filename FROM {system} WHERE name = :name AND type = :type", array(':name' => $name, ':type' => $type))->fetchColumn(); if (file_exists(DRUPAL_ROOT . '/' . $file)) { $files[$type][$name] = $file; } @@ -1838,7 +1838,7 @@ function drupal_is_denied($ip) { // database and also in this case it's quite likely that the user relies // on higher performance solutions like a firewall. elseif (class_exists('Database', FALSE)) { - $denied = (bool)db_query("SELECT 1 FROM {blocked_ips} WHERE ip = :ip", array(':ip' => $ip))->fetchField(); + $denied = (bool)db_query("SELECT 1 FROM {blocked_ips} WHERE ip = :ip", array(':ip' => $ip))->fetchColumn(); } return $denied; } @@ -2953,7 +2953,7 @@ function _registry_check_code($type, $name = NULL) { ':name' => $name, ':type' => $type, )) - ->fetchField(); + ->fetchColumn(); // Flag that we've run a lookup query and need to update the cache. $cache_update_needed = TRUE; diff --git a/includes/cache.inc b/includes/cache.inc index 9b60a7e..c4ad5f2 100644 --- a/includes/cache.inc +++ b/includes/cache.inc @@ -568,7 +568,7 @@ class DrupalDatabaseCache implements DrupalCacheInterface { $query->addExpression('1'); $result = $query->range(0, 1) ->execute() - ->fetchField(); + ->fetchColumn(); return empty($result); } } diff --git a/includes/common.inc b/includes/common.inc index bb4d8e7..76463c0 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -1201,7 +1201,7 @@ function flood_is_allowed($name, $threshold, $window = 3600, $identifier = NULL) ':event' => $name, ':identifier' => $identifier, ':timestamp' => REQUEST_TIME - $window)) - ->fetchField(); + ->fetchColumn(); return ($number < $threshold); } diff --git a/includes/database/database.inc b/includes/database/database.inc index 6108614..ee3f2d0 100644 --- a/includes/database/database.inc +++ b/includes/database/database.inc @@ -1991,17 +1991,6 @@ interface DatabaseStatementInterface extends Traversable { // public function fetch($mode = NULL, $cursor_orientation = NULL, $cursor_offset = NULL); /** - * Returns a single field from the next record of a result set. - * - * @param $index - * The numeric index of the field to return. Defaults to the first field. - * - * @return - * A single field from the next record. - */ - public function fetchField($index = 0); - - /** * Fetches the next row and returns it as an object. * * The object will be of the class specified by DatabaseStatementInterface::setFetchMode() @@ -2180,11 +2169,6 @@ class DatabaseStatementBase extends PDOStatement implements DatabaseStatementInt return $return; } - public function fetchField($index = 0) { - // Call PDOStatement::fetchColumn to fetch the field. - return $this->fetchColumn($index); - } - public function fetchAssoc() { // Call PDOStatement::fetch to fetch the row. return $this->fetch(PDO::FETCH_ASSOC); @@ -2224,10 +2208,6 @@ class DatabaseStatementEmpty implements Iterator, DatabaseStatementInterface { return NULL; } - public function fetchField($index = 0) { - return NULL; - } - public function fetchObject() { return NULL; } diff --git a/includes/database/mysql/database.inc b/includes/database/mysql/database.inc index 7d5d859..e156bf9 100644 --- a/includes/database/mysql/database.inc +++ b/includes/database/mysql/database.inc @@ -122,7 +122,7 @@ class DatabaseConnection_mysql extends DatabaseConnection { // be a problem in this case. Also, TRUNCATE resets the auto increment // counter. try { - $max_id = $this->query('SELECT MAX(value) FROM {sequences}')->fetchField(); + $max_id = $this->query('SELECT MAX(value) FROM {sequences}')->fetchColumn(); // We know we are using MySQL here, no need for the slower db_delete(). $this->query('DELETE FROM {sequences} WHERE value < :value', array(':value' => $max_id)); } diff --git a/includes/database/mysql/schema.inc b/includes/database/mysql/schema.inc index 4e88fa1..0d64e58 100644 --- a/includes/database/mysql/schema.inc +++ b/includes/database/mysql/schema.inc @@ -481,11 +481,11 @@ class DatabaseSchema_mysql extends DatabaseSchema { $condition->condition('column_name', $column); $condition->compile($this->connection, $this); // Don't use {} around information_schema.columns table. - return $this->connection->query("SELECT column_comment FROM information_schema.columns WHERE " . (string) $condition, $condition->arguments())->fetchField(); + return $this->connection->query("SELECT column_comment FROM information_schema.columns WHERE " . (string) $condition, $condition->arguments())->fetchColumn(); } $condition->compile($this->connection, $this); // Don't use {} around information_schema.tables table. - $comment = $this->connection->query("SELECT table_comment FROM information_schema.tables WHERE " . (string) $condition, $condition->arguments())->fetchField(); + $comment = $this->connection->query("SELECT table_comment FROM information_schema.tables WHERE " . (string) $condition, $condition->arguments())->fetchColumn(); // Work-around for MySQL 5.0 bug http://bugs.mysql.com/bug.php?id=11379 return preg_replace('/; InnoDB free:.*$/', '', $comment); } diff --git a/includes/database/pgsql/database.inc b/includes/database/pgsql/database.inc index 39b4e9b..32dbcee 100644 --- a/includes/database/pgsql/database.inc +++ b/includes/database/pgsql/database.inc @@ -168,7 +168,7 @@ class DatabaseConnection_pgsql extends DatabaseConnection { // When PostgreSQL gets a value too small then it will lock the table, // retry the INSERT and if it's still too small then alter the sequence. - $id = $this->query("SELECT nextval('" . $sequence_name . "')")->fetchField(); + $id = $this->query("SELECT nextval('" . $sequence_name . "')")->fetchColumn(); if ($id > $existing) { return $id; } @@ -180,7 +180,7 @@ class DatabaseConnection_pgsql extends DatabaseConnection { // While waiting to obtain the lock, the sequence may have been altered // so lets try again to obtain an adequate value. - $id = $this->query("SELECT nextval('" . $sequence_name . "')")->fetchField(); + $id = $this->query("SELECT nextval('" . $sequence_name . "')")->fetchColumn(); if ($id > $existing) { $this->query("SELECT pg_advisory_unlock(" . POSTGRESQL_NEXTID_LOCK . ")"); return $id; @@ -190,7 +190,7 @@ class DatabaseConnection_pgsql extends DatabaseConnection { $this->query("ALTER SEQUENCE " . $sequence_name . " RESTART WITH " . ($existing + 1)); // Retrive the next id. We know this will be as high as we want it. - $id = $this->query("SELECT nextval('" . $sequence_name . "')")->fetchField(); + $id = $this->query("SELECT nextval('" . $sequence_name . "')")->fetchColumn(); $this->query("SELECT pg_advisory_unlock(" . POSTGRESQL_NEXTID_LOCK . ")"); diff --git a/includes/database/pgsql/install.inc b/includes/database/pgsql/install.inc index c350634..49a0a8d 100644 --- a/includes/database/pgsql/install.inc +++ b/includes/database/pgsql/install.inc @@ -39,7 +39,7 @@ class DatabaseTasks_pgsql extends DatabaseTasks { */ protected function checkEncoding() { try { - if (db_query('SHOW server_encoding')->fetchField() == 'UTF8') { + if (db_query('SHOW server_encoding')->fetchColumn() == 'UTF8') { $this->pass(st('Database is encoded in UTF-8')); } else { @@ -108,7 +108,7 @@ class DatabaseTasks_pgsql extends DatabaseTasks { * Verify that a binary data roundtrip returns the original string. */ protected function checkBinaryOutputSuccess() { - $bytea_output = db_query("SELECT 'encoding'::bytea AS output")->fetchField(); + $bytea_output = db_query("SELECT 'encoding'::bytea AS output")->fetchColumn(); return ($bytea_output == 'encoding'); } @@ -132,7 +132,7 @@ class DatabaseTasks_pgsql extends DatabaseTasks { LANGUAGE \'sql\'' ); // Don't use {} around pg_proc table. - if (!db_query("SELECT COUNT(*) FROM pg_proc WHERE proname = 'rand'")->fetchField()) { + if (!db_query("SELECT COUNT(*) FROM pg_proc WHERE proname = 'rand'")->fetchColumn()) { db_query('CREATE OR REPLACE FUNCTION "rand"() RETURNS float AS \'SELECT random();\' LANGUAGE \'sql\'' diff --git a/includes/database/pgsql/schema.inc b/includes/database/pgsql/schema.inc index 9ed8a26..32f2b2c 100644 --- a/includes/database/pgsql/schema.inc +++ b/includes/database/pgsql/schema.inc @@ -417,7 +417,7 @@ class DatabaseSchema_pgsql extends DatabaseSchema { public function indexExists($table, $name) { // Details http://www.postgresql.org/docs/8.3/interactive/view-pg-indexes.html $index_name = '{' . $table . '}_' . $name . '_idx'; - return (bool) $this->connection->query("SELECT 1 FROM pg_indexes WHERE indexname = '$index_name'")->fetchField(); + return (bool) $this->connection->query("SELECT 1 FROM pg_indexes WHERE indexname = '$index_name'")->fetchColumn(); } /** @@ -430,7 +430,7 @@ class DatabaseSchema_pgsql extends DatabaseSchema { */ protected function constraintExists($table, $name) { $constraint_name = '{' . $table . '}_' . $name; - return (bool) $this->connection->query("SELECT 1 FROM pg_constraint WHERE conname = '$constraint_name'")->fetchField(); + return (bool) $this->connection->query("SELECT 1 FROM pg_constraint WHERE conname = '$constraint_name'")->fetchColumn(); } public function addPrimaryKey($table, $fields) { @@ -608,10 +608,10 @@ class DatabaseSchema_pgsql extends DatabaseSchema { $info = $this->getPrefixInfo($table); // Don't use {} around pg_class, pg_attribute tables. if (isset($column)) { - return $this->connection->query('SELECT col_description(oid, attnum) FROM pg_class, pg_attribute WHERE attrelid = oid AND relname = ? AND attname = ?', array($info['table'], $column))->fetchField(); + return $this->connection->query('SELECT col_description(oid, attnum) FROM pg_class, pg_attribute WHERE attrelid = oid AND relname = ? AND attname = ?', array($info['table'], $column))->fetchColumn(); } else { - return $this->connection->query('SELECT obj_description(oid, ?) FROM pg_class WHERE relname = ?', array('pg_class', $info['table']))->fetchField(); + return $this->connection->query('SELECT obj_description(oid, ?) FROM pg_class WHERE relname = ?', array('pg_class', $info['table']))->fetchColumn(); } } } diff --git a/includes/database/prefetch.inc b/includes/database/prefetch.inc index 4f2b19d..07737fd 100644 --- a/includes/database/prefetch.inc +++ b/includes/database/prefetch.inc @@ -382,10 +382,6 @@ class DatabaseStatementPrefetch implements Iterator, DatabaseStatementInterface } } - public function fetchField($index = 0) { - return $this->fetchColumn($index); - } - public function fetchObject($class_name = NULL, $constructor_args = array()) { if (isset($this->currentRow)) { if (!isset($class_name)) { diff --git a/includes/database/query.inc b/includes/database/query.inc index c7363f2..96426f5 100644 --- a/includes/database/query.inc +++ b/includes/database/query.inc @@ -1599,7 +1599,7 @@ class MergeQuery extends Query implements QueryConditionInterface { ->condition($this->condition) ->forUpdate(); $select->addExpression('1'); - if (!$select->execute()->fetchField()) { + if (!$select->execute()->fetchColumn()) { try { $insert = $this->connection->insert($this->table)->fields($this->insertFields); if ($this->defaultFields) { @@ -1613,7 +1613,7 @@ class MergeQuery extends Query implements QueryConditionInterface { // beat us in inserting the same row. Retry the select query, if it // returns a row, ignore the error and continue with the update // query below. - if (!$select->execute()->fetchField()) { + if (!$select->execute()->fetchColumn()) { throw $e; } } diff --git a/includes/database/schema.inc b/includes/database/schema.inc index 41c6802..2b0e7f0 100644 --- a/includes/database/schema.inc +++ b/includes/database/schema.inc @@ -310,7 +310,7 @@ abstract class DatabaseSchema implements QueryPlaceholderInterface { // couldn't use db_select() here because it would prefix // information_schema.tables and the query would fail. // Don't use {} around information_schema.tables table. - return (bool) $this->connection->query("SELECT 1 FROM information_schema.tables WHERE " . (string) $condition, $condition->arguments())->fetchField(); + return (bool) $this->connection->query("SELECT 1 FROM information_schema.tables WHERE " . (string) $condition, $condition->arguments())->fetchColumn(); } /** @@ -355,7 +355,7 @@ abstract class DatabaseSchema implements QueryPlaceholderInterface { // couldn't use db_select() here because it would prefix // information_schema.tables and the query would fail. // Don't use {} around information_schema.columns table. - return (bool) $this->connection->query("SELECT 1 FROM information_schema.columns WHERE " . (string) $condition, $condition->arguments())->fetchField(); + return (bool) $this->connection->query("SELECT 1 FROM information_schema.columns WHERE " . (string) $condition, $condition->arguments())->fetchColumn(); } /** diff --git a/includes/database/sqlite/database.inc b/includes/database/sqlite/database.inc index 0fc0b55..208008a 100644 --- a/includes/database/sqlite/database.inc +++ b/includes/database/sqlite/database.inc @@ -90,7 +90,7 @@ class DatabaseConnection_sqlite extends DatabaseConnection { $this->setPrefix($prefixes); // Detect support for SAVEPOINT. - $version = $this->query('SELECT sqlite_version()')->fetchField(); + $version = $this->query('SELECT sqlite_version()')->fetchColumn(); $this->savepointSupport = (version_compare($version, '3.6.8') >= 0); // Create functions needed by SQLite. @@ -117,7 +117,7 @@ class DatabaseConnection_sqlite extends DatabaseConnection { foreach ($this->attachedDatabases as $prefix) { // Check if the database is now empty, ignore the internal SQLite tables. try { - $count = $this->query('SELECT COUNT(*) FROM ' . $prefix . '.sqlite_master WHERE type = :type AND name NOT LIKE :pattern', array(':type' => 'table', ':pattern' => 'sqlite_%'))->fetchField(); + $count = $this->query('SELECT COUNT(*) FROM ' . $prefix . '.sqlite_master WHERE type = :type AND name NOT LIKE :pattern', array(':type' => 'table', ':pattern' => 'sqlite_%'))->fetchColumn(); // We can prune the database file if it doens't have any tables. if ($count == 0) { @@ -285,7 +285,7 @@ class DatabaseConnection_sqlite extends DatabaseConnection { } // The transaction gets committed when the transaction object gets destroyed // because it gets out of scope. - return $this->query('SELECT value FROM {sequences}')->fetchField(); + return $this->query('SELECT value FROM {sequences}')->fetchColumn(); } public function rollback($savepoint_name = 'drupal_transaction') { diff --git a/includes/database/sqlite/query.inc b/includes/database/sqlite/query.inc index 6b8a72f..c297c04 100644 --- a/includes/database/sqlite/query.inc +++ b/includes/database/sqlite/query.inc @@ -130,7 +130,7 @@ class UpdateQuery_sqlite extends UpdateQuery { class DeleteQuery_sqlite extends DeleteQuery { public function execute() { if (!count($this->condition)) { - $total_rows = $this->connection->query('SELECT COUNT(*) FROM {' . $this->connection->escapeTable($this->table) . '}')->fetchField(); + $total_rows = $this->connection->query('SELECT COUNT(*) FROM {' . $this->connection->escapeTable($this->table) . '}')->fetchColumn(); parent::execute(); return $total_rows; } diff --git a/includes/database/sqlite/schema.inc b/includes/database/sqlite/schema.inc index 3c8cd3f..71e08ea 100644 --- a/includes/database/sqlite/schema.inc +++ b/includes/database/sqlite/schema.inc @@ -22,7 +22,7 @@ class DatabaseSchema_sqlite extends DatabaseSchema { $info = $this->getPrefixInfo($table); // Don't use {} around sqlite_master table. - return (bool) $this->connection->query('SELECT 1 FROM ' . $info['schema'] . '.sqlite_master WHERE type = :type AND name = :name', array(':type' => 'table', ':name' => $info['table']))->fetchField(); + return (bool) $this->connection->query('SELECT 1 FROM ' . $info['schema'] . '.sqlite_master WHERE type = :type AND name = :name', array(':type' => 'table', ':name' => $info['table']))->fetchColumn(); } public function fieldExists($table, $column) { @@ -386,8 +386,8 @@ class DatabaseSchema_sqlite extends DatabaseSchema { ->from($select) ->execute(); - $old_count = $this->connection->query('SELECT COUNT(*) FROM {' . $table . '}')->fetchField(); - $new_count = $this->connection->query('SELECT COUNT(*) FROM {' . $new_table . '}')->fetchField(); + $old_count = $this->connection->query('SELECT COUNT(*) FROM {' . $table . '}')->fetchColumn(); + $new_count = $this->connection->query('SELECT COUNT(*) FROM {' . $new_table . '}')->fetchColumn(); if ($old_count == $new_count) { $this->dropTable($table); $this->renameTable($new_table, $table); @@ -575,7 +575,7 @@ class DatabaseSchema_sqlite extends DatabaseSchema { public function indexExists($table, $name) { $info = $this->getPrefixInfo($table); - return $this->connection->query('PRAGMA ' . $info['schema'] . '.index_info(' . $info['table'] . '_' . $name . ')')->fetchField() != ''; + return $this->connection->query('PRAGMA ' . $info['schema'] . '.index_info(' . $info['table'] . '_' . $name . ')')->fetchColumn() != ''; } public function dropIndex($table, $name) { diff --git a/includes/entity.inc b/includes/entity.inc index 99baf49..2a01b03 100644 --- a/includes/entity.inc +++ b/includes/entity.inc @@ -1286,7 +1286,7 @@ class EntityFieldQuery { $select_query->range($this->range['start'], $this->range['length']); } if ($this->count) { - return $select_query->countQuery()->execute()->fetchField(); + return $select_query->countQuery()->execute()->fetchColumn(); } $return = array(); foreach ($select_query->execute() as $partial_entity) { diff --git a/includes/file.inc b/includes/file.inc index 6e2e5cb..89e39c6 100644 --- a/includes/file.inc +++ b/includes/file.inc @@ -1355,7 +1355,7 @@ function file_space_used($uid = NULL, $status = FILE_STATUS_PERMANENT) { if (isset($uid)) { $query->condition('f.uid', $uid); } - return $query->execute()->fetchField(); + return $query->execute()->fetchColumn(); } /** diff --git a/includes/form.inc b/includes/form.inc index cfbea38..466dbd4 100644 --- a/includes/form.inc +++ b/includes/form.inc @@ -4115,7 +4115,7 @@ function element_validate_number($element, &$form_state) { * if (empty($context['sandbox'])) { * $context['sandbox']['progress'] = 0; * $context['sandbox']['current_node'] = 0; - * $context['sandbox']['max'] = db_query('SELECT COUNT(DISTINCT nid) FROM {node}')->fetchField(); + * $context['sandbox']['max'] = db_query('SELECT COUNT(DISTINCT nid) FROM {node}')->fetchColumn(); * } * $limit = 5; * $result = db_select('node') diff --git a/includes/gettext.inc b/includes/gettext.inc index fa9952b..d388330 100644 --- a/includes/gettext.inc +++ b/includes/gettext.inc @@ -32,7 +32,7 @@ function _locale_import_po($file, $langcode, $mode) { drupal_set_time_limit(240); // Check if we have the language already in the database. - if (!db_query("SELECT COUNT(language) FROM {languages} WHERE language = :language", array(':language' => $langcode))->fetchField()) { + if (!db_query("SELECT COUNT(language) FROM {languages} WHERE language = :language", array(':language' => $langcode))->fetchColumn()) { drupal_set_message(t('The language selected for import is not supported.'), 'error'); return FALSE; } @@ -476,7 +476,7 @@ function _locale_import_one_string($op, $value = NULL, $mode = NULL, $lang = NUL * The string ID of the existing string modified or the new string added. */ function _locale_import_one_string_db(&$report, $langcode, $context, $source, $translation, $location, $mode, $plid = 0, $plural = 0) { - $lid = db_query("SELECT lid FROM {locales_source} WHERE source = :source AND context = :context", array(':source' => $source, ':context' => $context))->fetchField(); + $lid = db_query("SELECT lid FROM {locales_source} WHERE source = :source AND context = :context", array(':source' => $source, ':context' => $context))->fetchColumn(); if (!empty($translation)) { // Skip this string unless it passes a check for dangerous code. @@ -493,7 +493,7 @@ function _locale_import_one_string_db(&$report, $langcode, $context, $source, $t ->condition('lid', $lid) ->execute(); - $exists = db_query("SELECT COUNT(lid) FROM {locales_target} WHERE lid = :lid AND language = :language", array(':lid' => $lid, ':language' => $langcode))->fetchField(); + $exists = db_query("SELECT COUNT(lid) FROM {locales_target} WHERE lid = :lid AND language = :language", array(':lid' => $lid, ':language' => $langcode))->fetchColumn(); if (!$exists) { // No translation in this language. diff --git a/includes/install.core.inc b/includes/install.core.inc index 1040bf3..67506d1 100644 --- a/includes/install.core.inc +++ b/includes/install.core.inc @@ -779,7 +779,7 @@ function install_system_module(&$install_state) { function install_verify_completed_task() { try { if ($result = db_query("SELECT value FROM {variable} WHERE name = :name", array('name' => 'install_task'))) { - $task = unserialize($result->fetchField()); + $task = unserialize($result->fetchColumn()); } } // Do not trigger an error if the database query fails, since the database diff --git a/includes/locale.inc b/includes/locale.inc index 199edd1..c10b3cf 100644 --- a/includes/locale.inc +++ b/includes/locale.inc @@ -806,7 +806,7 @@ function locale_date_format_save($langcode, $type, $format) { $locale_format['type'] = $type; $locale_format['format'] = $format; - $is_existing = (bool) db_query_range('SELECT 1 FROM {date_format_locale} WHERE language = :langcode AND type = :type', 0, 1, array(':langcode' => $langcode, ':type' => $type))->fetchField(); + $is_existing = (bool) db_query_range('SELECT 1 FROM {date_format_locale} WHERE language = :langcode AND type = :type', 0, 1, array(':langcode' => $langcode, ':type' => $type))->fetchColumn(); if ($is_existing) { $keys = array('type', 'language'); drupal_write_record('date_format_locale', $locale_format, $keys); diff --git a/includes/menu.inc b/includes/menu.inc index 0e3f5b6..6a0df86 100644 --- a/includes/menu.inc +++ b/includes/menu.inc @@ -3137,7 +3137,7 @@ function _menu_link_find_parent($menu_link, $parent_candidates = array()) { $new_query = clone $query; $new_query->condition('link_path', $parent_path); // Only valid if we get a unique result. - if ($new_query->countQuery()->execute()->fetchField() == 1) { + if ($new_query->countQuery()->execute()->fetchColumn() == 1) { $parent = $new_query->fields('menu_links')->execute()->fetchAssoc(); } } while ($parent === FALSE && $parent_path); @@ -3201,7 +3201,7 @@ function _menu_find_router_path($link_path) { ->condition('path', $ancestors, 'IN') ->orderBy('fit', 'DESC') ->range(0, 1) - ->execute()->fetchField(); + ->execute()->fetchColumn(); } elseif (!isset($menu[$router_path])) { // Add an empty router path as a fallback. @@ -3285,7 +3285,7 @@ function menu_link_children_relative_depth($item) { $p = 'p' . ++$i; } - $max_depth = $query->execute()->fetchField(); + $max_depth = $query->execute()->fetchColumn(); return ($max_depth > $item['depth']) ? $max_depth - $item['depth'] : 0; } @@ -3355,7 +3355,7 @@ function _menu_update_parental_status($item, $exclude = FALSE) { if ($exclude) { $query->condition('mlid', $item['mlid'], '<>'); } - $parent_has_children = ((bool) $query->execute()->fetchField()) ? 1 : 0; + $parent_has_children = ((bool) $query->execute()->fetchColumn()) ? 1 : 0; db_update('menu_links') ->fields(array('has_children' => $parent_has_children)) ->condition('mlid', $item['plid']) @@ -3491,7 +3491,7 @@ function _menu_router_build($callbacks) { // previous iteration assigned one already), try to find the menu name // of the parent item in the currently stored menu links. if (!isset($parent['menu_name'])) { - $menu_name = db_query("SELECT menu_name FROM {menu_links} WHERE router_path = :router_path AND module = 'system'", array(':router_path' => $parent_path))->fetchField(); + $menu_name = db_query("SELECT menu_name FROM {menu_links} WHERE router_path = :router_path AND module = 'system'", array(':router_path' => $parent_path))->fetchColumn(); if ($menu_name) { $parent['menu_name'] = $menu_name; } diff --git a/includes/pager.inc b/includes/pager.inc index 7a3a7be..d3ae00e 100644 --- a/includes/pager.inc +++ b/includes/pager.inc @@ -71,7 +71,7 @@ class PagerDefault extends SelectQueryExtender { } $this->ensureElement(); - $total_items = $this->getCountQuery()->execute()->fetchField(); + $total_items = $this->getCountQuery()->execute()->fetchColumn(); $current_page = pager_default_initialize($total_items, $this->limit, $this->element); $this->range($current_page * $this->limit, $this->limit); diff --git a/includes/path.inc b/includes/path.inc index 630b34c..b9641bc 100644 --- a/includes/path.inc +++ b/includes/path.inc @@ -103,7 +103,7 @@ function drupal_lookup_path($action, $path = '', $path_language = NULL) { // ASC, while 'xx-lolspeak' is more than 'und' so the order needs to // be DESC. We also order by pid ASC so that fetchAllKeyed() returns // the most recently created alias for each source. Subsequent queries - // using fetchField() must use pid DESC to have the same effect. + // using fetchColumn() must use pid DESC to have the same effect. // For performance reasons, the query builder is not used here. if ($path_language == LANGUAGE_NONE) { // Prevent PDO from complaining about a token the query doesn't use. @@ -141,13 +141,13 @@ function drupal_lookup_path($action, $path = '', $path_language = NULL) { // See the queries above. if ($path_language == LANGUAGE_NONE) { unset($args[':language']); - $alias = db_query("SELECT alias FROM {url_alias} WHERE source = :source AND language = :language_none ORDER BY pid DESC", $args)->fetchField(); + $alias = db_query("SELECT alias FROM {url_alias} WHERE source = :source AND language = :language_none ORDER BY pid DESC", $args)->fetchColumn(); } elseif ($path_language > LANGUAGE_NONE) { - $alias = db_query("SELECT alias FROM {url_alias} WHERE source = :source AND language IN (:language, :language_none) ORDER BY language DESC, pid DESC", $args)->fetchField(); + $alias = db_query("SELECT alias FROM {url_alias} WHERE source = :source AND language IN (:language, :language_none) ORDER BY language DESC, pid DESC", $args)->fetchColumn(); } else { - $alias = db_query("SELECT alias FROM {url_alias} WHERE source = :source AND language IN (:language, :language_none) ORDER BY language ASC, pid DESC", $args)->fetchField(); + $alias = db_query("SELECT alias FROM {url_alias} WHERE source = :source AND language IN (:language, :language_none) ORDER BY language ASC, pid DESC", $args)->fetchColumn(); } $cache['map'][$path_language][$path] = $alias; return $alias; @@ -175,7 +175,7 @@ function drupal_lookup_path($action, $path = '', $path_language = NULL) { else { $result = db_query("SELECT source FROM {url_alias} WHERE alias = :alias AND language IN (:language, :language_none) ORDER BY language ASC, pid DESC", $args); } - if ($source = $result->fetchField()) { + if ($source = $result->fetchColumn()) { $cache['map'][$path_language][$source] = $path; } else { diff --git a/modules/aggregator/aggregator.module b/modules/aggregator/aggregator.module index f247d26..934138b 100644 --- a/modules/aggregator/aggregator.module +++ b/modules/aggregator/aggregator.module @@ -283,7 +283,7 @@ function _aggregator_category_title($category) { * otherwise. */ function _aggregator_has_categories() { - return user_access('access news feeds') && (bool) db_query_range('SELECT 1 FROM {aggregator_category}', 0, 1)->fetchField(); + return user_access('access news feeds') && (bool) db_query_range('SELECT 1 FROM {aggregator_category}', 0, 1)->fetchColumn(); } /** @@ -361,7 +361,7 @@ function aggregator_block_info() { function aggregator_block_configure($delta = '') { list($type, $id) = explode('-', $delta); if ($type == 'category') { - $value = db_query('SELECT block FROM {aggregator_category} WHERE cid = :cid', array(':cid' => $id))->fetchField(); + $value = db_query('SELECT block FROM {aggregator_category} WHERE cid = :cid', array(':cid' => $id))->fetchColumn(); $form['block'] = array( '#type' => 'select', '#title' => t('Number of news items in block'), diff --git a/modules/aggregator/aggregator.test b/modules/aggregator/aggregator.test index 1ab12dc..c52813a 100644 --- a/modules/aggregator/aggregator.test +++ b/modules/aggregator/aggregator.test @@ -75,7 +75,7 @@ class AggregatorTestCase extends DrupalWebTestCase { */ function getDefaultFeedItemCount() { // Our tests are based off of rss.xml, so let's find out how many elements should be related. - $feed_count = db_query_range('SELECT COUNT(*) FROM {node} n WHERE n.promote = 1 AND n.status = 1', 0, variable_get('feed_default_items', 10))->fetchField(); + $feed_count = db_query_range('SELECT COUNT(*) FROM {node} n WHERE n.promote = 1 AND n.status = 1', 0, variable_get('feed_default_items', 10))->fetchColumn(); return $feed_count > 10 ? 10 : $feed_count; } @@ -127,10 +127,10 @@ class AggregatorTestCase extends DrupalWebTestCase { */ function updateAndRemove($feed, $expected_count) { $this->updateFeedItems($feed, $expected_count); - $count = db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchField(); + $count = db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchColumn(); $this->assertTrue($count); $this->removeFeedItems($feed); - $count = db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchField(); + $count = db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchColumn(); $this->assertTrue($count == 0); } @@ -172,7 +172,7 @@ class AggregatorTestCase extends DrupalWebTestCase { * TRUE if feed is unique. */ function uniqueFeed($feed_name, $feed_url) { - $result = db_query("SELECT COUNT(*) FROM {aggregator_feed} WHERE title = :title AND url = :url", array(':title' => $feed_name, ':url' => $feed_url))->fetchField(); + $result = db_query("SELECT COUNT(*) FROM {aggregator_feed} WHERE title = :title AND url = :url", array(':title' => $feed_name, ':url' => $feed_url))->fetchColumn(); return (1 == $result); } @@ -417,7 +417,7 @@ class RemoveFeedTestCase extends AggregatorTestCase { $this->assertResponse(404, t('Deleted feed source does not exists.')); // Check database for feed. - $result = db_query("SELECT COUNT(*) FROM {aggregator_feed} WHERE title = :title AND url = :url", array(':title' => $feed->title, ':url' => $feed->url))->fetchField(); + $result = db_query("SELECT COUNT(*) FROM {aggregator_feed} WHERE title = :title AND url = :url", array(':title' => $feed->title, ':url' => $feed->url))->fetchColumn(); $this->assertFalse($result, t('Feed not found in database')); } } @@ -462,7 +462,7 @@ class UpdateFeedItemTestCase extends AggregatorTestCase { $feed = db_query("SELECT * FROM {aggregator_feed} WHERE url = :url", array(':url' => $edit['url']))->fetchObject(); $this->drupalGet('admin/config/services/aggregator/update/' . $feed->fid); - $before = db_query('SELECT timestamp FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchField(); + $before = db_query('SELECT timestamp FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchColumn(); // Sleep for 3 second. sleep(3); @@ -477,7 +477,7 @@ class UpdateFeedItemTestCase extends AggregatorTestCase { ->execute(); $this->drupalGet('admin/config/services/aggregator/update/' . $feed->fid); - $after = db_query('SELECT timestamp FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchField(); + $after = db_query('SELECT timestamp FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchColumn(); $this->assertTrue($before === $after, t('Publish timestamp of feed item was not updated (!before === !after)', array('!before' => $before, '!after' => $after))); } @@ -567,7 +567,7 @@ class CategorizeFeedItemTestCase extends AggregatorTestCase { ->condition('iid', $feed->items, 'IN') ->countQuery() ->execute() - ->fetchField(); + ->fetchColumn(); $this->assertEqual($feed->item_count, $categorized_count, t('Total items in feed equal to the total categorized feed items in database')); } @@ -613,7 +613,7 @@ class ImportOPMLTestCase extends AggregatorTestCase { * Submit form filled with invalid fields. */ function validateImportFormFields() { - $before = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField(); + $before = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchColumn(); $edit = array(); $this->drupalPost('admin/config/services/aggregator/add/opml', $edit, t('Import')); @@ -631,7 +631,7 @@ class ImportOPMLTestCase extends AggregatorTestCase { $this->drupalPost('admin/config/services/aggregator/add/opml', $edit, t('Import')); $this->assertText(t('This URL is not valid.'), t('Error if the URL is invalid.')); - $after = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField(); + $after = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchColumn(); $this->assertEqual($before, $after, t('No feeds were added during the three last form submissions.')); } @@ -639,7 +639,7 @@ class ImportOPMLTestCase extends AggregatorTestCase { * Submit form with invalid, empty and valid OPML files. */ function submitImportForm() { - $before = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField(); + $before = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchColumn(); $form['files[upload]'] = $this->getInvalidOpml(); $this->drupalPost('admin/config/services/aggregator/add/opml', $form, t('Import')); @@ -649,7 +649,7 @@ class ImportOPMLTestCase extends AggregatorTestCase { $this->drupalPost('admin/config/services/aggregator/add/opml', $edit, t('Import')); $this->assertText(t('No new feed has been added.'), t('Attempting to load empty OPML from remote URL.')); - $after = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField(); + $after = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchColumn(); $this->assertEqual($before, $after, t('No feeds were added during the two last form submissions.')); db_delete('aggregator_feed')->execute(); @@ -677,7 +677,7 @@ class ImportOPMLTestCase extends AggregatorTestCase { $this->assertRaw(t('A feed with the URL %url already exists.', array('%url' => $feeds[0]['url'])), t('Verifying that a duplicate URL was identified')); $this->assertRaw(t('A feed named %title already exists.', array('%title' => $feeds[1]['title'])), t('Verifying that a duplicate title was identified')); - $after = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField(); + $after = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchColumn(); $this->assertEqual($after, 2, t('Verifying that two distinct feeds were added.')); $feeds_from_db = db_query("SELECT f.title, f.url, f.refresh, cf.cid FROM {aggregator_feed} f LEFT JOIN {aggregator_category_feed} cf ON f.fid = cf.fid"); @@ -721,11 +721,11 @@ class AggregatorCronTestCase extends AggregatorTestCase { $this->createSampleNodes(); $feed = $this->createFeed(); $this->drupalGet($base_url . '/cron.php', array('external' => TRUE, 'query' => array('cron_key' => $key))); - $this->assertEqual(5, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchField(), 'Expected number of items in database.'); + $this->assertEqual(5, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchColumn(), 'Expected number of items in database.'); $this->removeFeedItems($feed); - $this->assertEqual(0, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchField(), 'Expected number of items in database.'); + $this->assertEqual(0, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchColumn(), 'Expected number of items in database.'); $this->drupalGet($base_url . '/cron.php', array('external' => TRUE, 'query' => array('cron_key' => $key))); - $this->assertEqual(5, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchField(), 'Expected number of items in database.'); + $this->assertEqual(5, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchColumn(), 'Expected number of items in database.'); // Test feed locking when queued for update. $this->removeFeedItems($feed); @@ -736,7 +736,7 @@ class AggregatorCronTestCase extends AggregatorTestCase { )) ->execute(); $this->drupalGet($base_url . '/cron.php', array('external' => TRUE, 'query' => array('cron_key' => $key))); - $this->assertEqual(0, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchField(), 'Expected number of items in database.'); + $this->assertEqual(0, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchColumn(), 'Expected number of items in database.'); db_update('aggregator_feed') ->condition('fid', $feed->fid) ->fields(array( @@ -744,7 +744,7 @@ class AggregatorCronTestCase extends AggregatorTestCase { )) ->execute(); $this->drupalGet($base_url . '/cron.php', array('external' => TRUE, 'query' => array('cron_key' => $key))); - $this->assertEqual(5, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchField(), 'Expected number of items in database.'); + $this->assertEqual(5, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchColumn(), 'Expected number of items in database.'); } } @@ -853,7 +853,7 @@ class FeedParserTestCase extends AggregatorTestCase { $this->assertText('Atom-Powered Robots Run Amok'); $this->assertLinkByHref('http://example.org/2003/12/13/atom03'); $this->assertText('Some text.'); - $this->assertEqual('urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a', db_query('SELECT guid FROM {aggregator_item} WHERE link = :link', array(':link' => 'http://example.org/2003/12/13/atom03'))->fetchField(), 'Atom entry id element is parsed correctly.'); + $this->assertEqual('urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a', db_query('SELECT guid FROM {aggregator_item} WHERE link = :link', array(':link' => 'http://example.org/2003/12/13/atom03'))->fetchColumn(), 'Atom entry id element is parsed correctly.'); } } diff --git a/modules/block/block.admin.inc b/modules/block/block.admin.inc index ba31b9c..ee13827 100644 --- a/modules/block/block.admin.inc +++ b/modules/block/block.admin.inc @@ -304,7 +304,7 @@ function block_admin_configure($form, &$form_state, $module, $delta) { ':module' => $block->module, ':delta' => $block->delta, ':theme' => $key, - ))->fetchField(); + ))->fetchColumn(); // Use a meaningful title for the main site theme and administrative // theme. @@ -451,7 +451,7 @@ function block_admin_configure_validate($form, &$form_state) { $custom_block_exists = (bool) db_query_range('SELECT 1 FROM {block_custom} WHERE bid <> :bid AND info = :info', 0, 1, array( ':bid' => $form_state['values']['delta'], ':info' => $form_state['values']['info'], - ))->fetchField(); + ))->fetchColumn(); if (empty($form_state['values']['info']) || $custom_block_exists) { form_set_error('info', t('Ensure that each block description is unique.')); } @@ -536,7 +536,7 @@ function block_add_block_form($form, &$form_state) { * @see block_add_block_form_submit() */ function block_add_block_form_validate($form, &$form_state) { - $custom_block_exists = (bool) db_query_range('SELECT 1 FROM {block_custom} WHERE info = :info', 0, 1, array(':info' => $form_state['values']['info']))->fetchField(); + $custom_block_exists = (bool) db_query_range('SELECT 1 FROM {block_custom} WHERE info = :info', 0, 1, array(':info' => $form_state['values']['info']))->fetchColumn(); if (empty($form_state['values']['info']) || $custom_block_exists) { form_set_error('info', t('Ensure that each block description is unique.')); diff --git a/modules/block/block.module b/modules/block/block.module index 93c34ae..cd08786 100644 --- a/modules/block/block.module +++ b/modules/block/block.module @@ -609,7 +609,7 @@ function block_themes_enabled($theme_list) { */ function block_theme_initialize($theme) { // Initialize theme's blocks if none already registered. - $has_blocks = (bool) db_query_range('SELECT 1 FROM {block} WHERE theme = :theme', 0, 1, array(':theme' => $theme))->fetchField(); + $has_blocks = (bool) db_query_range('SELECT 1 FROM {block} WHERE theme = :theme', 0, 1, array(':theme' => $theme))->fetchColumn(); if (!$has_blocks) { $default_theme = variable_get('theme_default', 'bartik'); // Apply only to new theme's visible regions. diff --git a/modules/block/block.test b/modules/block/block.test index 2166687..5cddca9 100644 --- a/modules/block/block.test +++ b/modules/block/block.test @@ -72,14 +72,14 @@ class BlockTestCase extends DrupalWebTestCase { // Confirm that the custom block has been created, and then query the created bid. $this->assertText(t('The block has been created.'), t('Custom block successfully created.')); - $bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchField(); + $bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchColumn(); // Check to see if the custom block was created by checking that it's in the database. $this->assertNotNull($bid, t('Custom block found in database')); // Check that block_block_view() returns the correct title and content. $data = block_block_view($bid); - $format = db_query("SELECT format FROM {block_custom} WHERE bid = :bid", array(':bid' => $bid))->fetchField(); + $format = db_query("SELECT format FROM {block_custom} WHERE bid = :bid", array(':bid' => $bid))->fetchColumn(); $this->assertTrue(array_key_exists('subject', $data) && empty($data['subject']), t('block_block_view() provides an empty block subject, since custom blocks do not have default titles.')); $this->assertEqual(check_markup($custom_block['body[value]'], $format), $data['content'], t('block_block_view() provides correct block content.')); @@ -105,7 +105,7 @@ class BlockTestCase extends DrupalWebTestCase { $this->drupalPost('admin/structure/block/manage/block/' . $bid . '/delete', array(), t('Delete')); $this->assertRaw(t('The block %title has been removed.', array('%title' => $custom_block['info'])), t('Custom block successfully deleted.')); $this->assertNoText(t($custom_block['title']), t('Custom block no longer appears on page.')); - $count = db_query("SELECT 1 FROM {block_role} WHERE module = :module AND delta = :delta", array(':module' => $custom_block['module'], ':delta' => $custom_block['delta']))->fetchField(); + $count = db_query("SELECT 1 FROM {block_role} WHERE module = :module AND delta = :delta", array(':module' => $custom_block['module'], ':delta' => $custom_block['delta']))->fetchColumn(); $this->assertFalse($count, t('Table block_role being cleaned.')); } @@ -123,7 +123,7 @@ class BlockTestCase extends DrupalWebTestCase { $this->drupalPost('admin/structure/block/add', $custom_block, t('Save block')); // Set the created custom block to a specific region. - $bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchField(); + $bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchColumn(); $edit = array(); $edit['blocks[block_' . $bid . '][region]'] = $this->regions[1]; $this->drupalPost('admin/structure/block', $edit, t('Save blocks')); @@ -162,7 +162,7 @@ class BlockTestCase extends DrupalWebTestCase { $custom_block['body[value]'] = $this->randomName(32); $this->drupalPost('admin/structure/block/add', $custom_block, t('Save block')); - $bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchField(); + $bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchColumn(); $block['module'] = 'block'; $block['delta'] = $bid; $block['title'] = $title; @@ -209,7 +209,7 @@ class BlockTestCase extends DrupalWebTestCase { $custom_block['body[value]'] = $this->randomName(32); $this->drupalPost('admin/structure/block/add', $custom_block, t('Save block')); - $bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchField(); + $bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchColumn(); $block['module'] = 'block'; $block['delta'] = $bid; $block['title'] = $title; @@ -251,7 +251,7 @@ class BlockTestCase extends DrupalWebTestCase { $custom_block['body[value]'] = $this->randomName(32); $this->drupalPost('admin/structure/block/add', $custom_block, t('Save block')); - $bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchField(); + $bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchColumn(); $block['module'] = 'block'; $block['delta'] = $bid; $block['title'] = $title; @@ -302,7 +302,7 @@ class BlockTestCase extends DrupalWebTestCase { $bid = db_query("SELECT bid FROM {block} WHERE module = :module AND delta = :delta", array( ':module' => $block['module'], ':delta' => $block['delta'], - ))->fetchField(); + ))->fetchColumn(); // Check to see if the block was created by checking that it's in the database. $this->assertNotNull($bid, t('Block found in database')); @@ -367,7 +367,7 @@ class BlockTestCase extends DrupalWebTestCase { // block management page. $this->drupalGet('admin/structure/block'); // Our test block's caching should default to DRUPAL_CACHE_PER_ROLE. - $current_caching = db_query("SELECT cache FROM {block} WHERE module = 'block_test' AND delta = 'test_cache'")->fetchField(); + $current_caching = db_query("SELECT cache FROM {block} WHERE module = 'block_test' AND delta = 'test_cache'")->fetchColumn(); $this->assertEqual($current_caching, DRUPAL_CACHE_PER_ROLE, t('Test block cache mode defaults to DRUPAL_CACHE_PER_ROLE.')); // Disable caching for this block. @@ -375,7 +375,7 @@ class BlockTestCase extends DrupalWebTestCase { // Flushing all caches should call _block_rehash(). drupal_flush_all_caches(); // Verify that the database is updated with the new caching mode. - $current_caching = db_query("SELECT cache FROM {block} WHERE module = 'block_test' AND delta = 'test_cache'")->fetchField(); + $current_caching = db_query("SELECT cache FROM {block} WHERE module = 'block_test' AND delta = 'test_cache'")->fetchColumn(); $this->assertEqual($current_caching, DRUPAL_NO_CACHE, t("Test block's database entry updated to DRUPAL_NO_CACHE.")); } } @@ -426,7 +426,7 @@ class NewDefaultThemeBlocks extends DrupalWebTestCase { if ($admin_theme = variable_get('admin_theme')) { $themes['admin'] = $admin_theme; } - $count = db_query_range('SELECT 1 FROM {block} WHERE theme NOT IN (:themes)', 0, 1, array(':themes' => $themes))->fetchField(); + $count = db_query_range('SELECT 1 FROM {block} WHERE theme NOT IN (:themes)', 0, 1, array(':themes' => $themes))->fetchColumn(); $this->assertFalse($count, t('Only the default theme and the admin theme have blocks.')); // Populate list of all blocks for matching against new theme. @@ -665,7 +665,7 @@ class BlockCacheTestCase extends DrupalWebTestCase { ->condition('module', 'block_test') ->execute(); - $current_mode = db_query("SELECT cache FROM {block} WHERE module = 'block_test'")->fetchField(); + $current_mode = db_query("SELECT cache FROM {block} WHERE module = 'block_test'")->fetchColumn(); if ($current_mode != $cache_mode) { $this->fail(t('Unable to set cache mode to %mode. Current mode: %current_mode', array('%mode' => $cache_mode, '%current_mode' => $current_mode))); } diff --git a/modules/book/book.module b/modules/book/book.module index 6e74d32..f66924e 100644 --- a/modules/book/book.module +++ b/modules/book/book.module @@ -283,7 +283,7 @@ function book_block_view($delta = '') { ->fields('n', array('title')) ->condition('nid', $node->book['bid']) ->addTag('node_access'); - $title = $select->execute()->fetchField(); + $title = $select->execute()->fetchColumn(); // Only show the block if the user has view access for the top-level node. if ($title) { $tree = menu_tree_all_data($node->book['menu_name'], $node->book); @@ -602,7 +602,7 @@ function _book_update_outline($node) { if (empty($node->book['plid']) || !$parent || $parent['bid'] != $node->book['bid']) { $node->book['plid'] = db_query("SELECT mlid FROM {book} WHERE nid = :nid", array( ':nid' => $node->book['bid'], - ))->fetchField(); + ))->fetchColumn(); $node->book['parent_mismatch'] = TRUE; // Likely when JS is disabled. } } @@ -623,7 +623,7 @@ function _book_update_outline($node) { else { if ($node->book['bid'] != db_query("SELECT bid FROM {book} WHERE nid = :nid", array( ':nid' => $node->nid, - ))->fetchField()) { + ))->fetchColumn()) { // Update the bid for this page and all children. book_update_bid($node->book); // Reset the cache of stored books. diff --git a/modules/comment/comment.admin.inc b/modules/comment/comment.admin.inc index 4f3d350..63dabc9 100644 --- a/modules/comment/comment.admin.inc +++ b/modules/comment/comment.admin.inc @@ -204,7 +204,7 @@ function comment_multiple_delete_confirm($form, &$form_state) { foreach (array_filter($edit['comments']) as $cid => $value) { $comment = comment_load($cid); if (is_object($comment) && is_numeric($comment->cid)) { - $subject = db_query('SELECT subject FROM {comment} WHERE cid = :cid', array(':cid' => $cid))->fetchField(); + $subject = db_query('SELECT subject FROM {comment} WHERE cid = :cid', array(':cid' => $cid))->fetchColumn(); $form['comments'][$cid] = array('#type' => 'hidden', '#value' => $cid, '#prefix' => '
  • ', '#suffix' => check_plain($subject) . '
  • '); $comment_counter++; } diff --git a/modules/comment/comment.module b/modules/comment/comment.module index 37a208f..5d51d41 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -307,7 +307,7 @@ function comment_menu_alter(&$items) { function comment_count_unpublished() { $count = db_query('SELECT COUNT(cid) FROM {comment} WHERE status = :status', array( ':status' => COMMENT_NOT_PUBLISHED, - ))->fetchField(); + ))->fetchColumn(); return t('Unapproved comments (@count)', array('@count' => $count)); } @@ -563,7 +563,7 @@ function comment_new_page_count($num_comments, $new_replies, $node) { ->orderBy('SUBSTRING(thread, 1, (LENGTH(thread) - 1))') ->range(0, 1) ->execute() - ->fetchField(); + ->fetchColumn(); // Remove the final '/'. $first_thread = substr($first_thread, 0, -1); @@ -573,7 +573,7 @@ function comment_new_page_count($num_comments, $new_replies, $node) { ':status' => COMMENT_PUBLISHED, ':nid' => $node->nid, ':thread' => $first_thread, - ))->fetchField(); + ))->fetchColumn(); $pageno = $count / $comments_per_page; } @@ -1203,7 +1203,7 @@ function comment_form_node_form_alter(&$form, $form_state) { ), '#weight' => 30, ); - $comment_count = isset($node->nid) ? db_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = :nid', array(':nid' => $node->nid))->fetchField() : 0; + $comment_count = isset($node->nid) ? db_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = :nid', array(':nid' => $node->nid))->fetchColumn() : 0; $comment_settings = ($node->comment == COMMENT_NODE_HIDDEN && empty($comment_count)) ? COMMENT_NODE_CLOSED : $node->comment; $form['comment_settings']['comment'] = array( '#type' => 'radios', @@ -1353,7 +1353,7 @@ function comment_node_update_index($node) { */ function comment_update_index() { // Store the maximum possible comments per thread (used for ranking by reply count) - variable_set('node_cron_comments_scale', 1.0 / max(1, db_query('SELECT MAX(comment_count) FROM {node_comment_statistics}')->fetchField())); + variable_set('node_cron_comments_scale', 1.0 / max(1, db_query('SELECT MAX(comment_count) FROM {node_comment_statistics}')->fetchColumn())); } /** @@ -1365,7 +1365,7 @@ function comment_update_index() { function comment_node_search_result($node) { // Do not make a string if comments are hidden. if (user_access('access comments') && $node->comment != COMMENT_NODE_HIDDEN) { - $comments = db_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = :nid', array('nid' => $node->nid))->fetchField(); + $comments = db_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = :nid', array('nid' => $node->nid))->fetchColumn(); // Do not make a string if comments are closed and there are currently // zero comments. if ($node->comment != COMMENT_NODE_CLOSED || $comments > 0) { @@ -1493,7 +1493,7 @@ function comment_save($comment) { elseif ($comment->pid == 0) { // This is a comment with no parent comment (depth 0): we start // by retrieving the maximum thread level. - $max = db_query('SELECT MAX(thread) FROM {comment} WHERE nid = :nid', array(':nid' => $comment->nid))->fetchField(); + $max = db_query('SELECT MAX(thread) FROM {comment} WHERE nid = :nid', array(':nid' => $comment->nid))->fetchColumn(); // Strip the "/" from the end of the thread. $max = rtrim($max, '/'); // Finally, build the thread field for this new comment. @@ -1511,7 +1511,7 @@ function comment_save($comment) { $max = db_query("SELECT MAX(thread) FROM {comment} WHERE thread LIKE :thread AND nid = :nid", array( ':thread' => $parent->thread . '.%', ':nid' => $comment->nid, - ))->fetchField(); + ))->fetchColumn(); if ($max == '') { // First child of this parent. @@ -1715,7 +1715,7 @@ function comment_num_new($nid, $timestamp = 0) { ':nid' => $nid, ':timestamp' => $timestamp, ':status' => COMMENT_PUBLISHED, - ))->fetchField(); + ))->fetchColumn(); } else { return FALSE; @@ -1762,7 +1762,7 @@ function comment_get_display_ordinal($cid, $node_type) { $query->where('SUBSTRING(c1.thread, 1, (LENGTH(c1.thread) -1)) < SUBSTRING(c2.thread, 1, (LENGTH(c2.thread) -1))'); } - return $query->execute()->fetchField(); + return $query->execute()->fetchColumn(); } /** @@ -2114,7 +2114,7 @@ function comment_form_validate($form, &$form_state) { ->condition('name', db_like($form_state['values']['name']), 'LIKE') ->countQuery() ->execute() - ->fetchField(); + ->fetchColumn(); if ($taken) { form_set_error('name', t('The name you used belongs to a registered user.')); } @@ -2407,7 +2407,7 @@ function _comment_update_node_statistics($nid) { $count = db_query('SELECT COUNT(cid) FROM {comment} WHERE nid = :nid AND status = :status', array( ':nid' => $nid, ':status' => COMMENT_PUBLISHED, - ))->fetchField(); + ))->fetchColumn(); if ($count > 0) { // Comments exist. @@ -2522,7 +2522,7 @@ function comment_publish_action($comment, $context = array()) { } else { $cid = $context['cid']; - $subject = db_query('SELECT subject FROM {comment} WHERE cid = :cid', array(':cid' => $cid))->fetchField(); + $subject = db_query('SELECT subject FROM {comment} WHERE cid = :cid', array(':cid' => $cid))->fetchColumn(); db_update('comment') ->fields(array('status' => COMMENT_PUBLISHED)) ->condition('cid', $cid) @@ -2549,7 +2549,7 @@ function comment_unpublish_action($comment, $context = array()) { } else { $cid = $context['cid']; - $subject = db_query('SELECT subject FROM {comment} WHERE cid = :cid', array(':cid' => $cid))->fetchField(); + $subject = db_query('SELECT subject FROM {comment} WHERE cid = :cid', array(':cid' => $cid))->fetchColumn(); db_update('comment') ->fields(array('status' => COMMENT_NOT_PUBLISHED)) ->condition('cid', $cid) diff --git a/modules/comment/comment.test b/modules/comment/comment.test index e5cae5e..57b5aa9 100644 --- a/modules/comment/comment.test +++ b/modules/comment/comment.test @@ -1859,7 +1859,7 @@ class CommentActionsTestCase extends CommentHelperCase { * The assertion message. */ function assertWatchdogMessage($watchdog_message, $variables, $message) { - $status = (bool) db_query_range("SELECT 1 FROM {watchdog} WHERE message = :message AND variables = :variables", 0, 1, array(':message' => $watchdog_message, ':variables' => serialize($variables)))->fetchField(); + $status = (bool) db_query_range("SELECT 1 FROM {watchdog} WHERE message = :message AND variables = :variables", 0, 1, array(':message' => $watchdog_message, ':variables' => serialize($variables)))->fetchColumn(); return $this->assert($status, $message); } diff --git a/modules/contact/contact.admin.inc b/modules/contact/contact.admin.inc index 9fde037..0a53a94 100644 --- a/modules/contact/contact.admin.inc +++ b/modules/contact/contact.admin.inc @@ -130,7 +130,7 @@ function contact_category_edit_form_validate($form, &$form_state) { if (!empty($form_state['values']['cid'])) { $query->condition('c.cid', $form_state['values']['cid'], '<>'); } - if ($query->countQuery()->execute()->fetchField()) { + if ($query->countQuery()->execute()->fetchColumn()) { form_set_error('category', t('A contact form with category %category already exists.', array('%category' => $category))); } diff --git a/modules/contact/contact.pages.inc b/modules/contact/contact.pages.inc index 30b2825..842920e 100644 --- a/modules/contact/contact.pages.inc +++ b/modules/contact/contact.pages.inc @@ -31,7 +31,7 @@ function contact_site_form($form, &$form_state) { ->orderBy('category') ->execute() ->fetchAllKeyed(); - $default_category = db_query("SELECT cid FROM {contact} WHERE selected = 1")->fetchField(); + $default_category = db_query("SELECT cid FROM {contact} WHERE selected = 1")->fetchColumn(); // If there are no categories, do not display the form. if (!$categories) { diff --git a/modules/contact/contact.test b/modules/contact/contact.test index bc44f5a..6106a23 100644 --- a/modules/contact/contact.test +++ b/modules/contact/contact.test @@ -102,7 +102,7 @@ class ContactSitewideTestCase extends DrupalWebTestCase { // Clear flood table in preparation for flood test and allow other checks to complete. db_delete('flood')->execute(); - $num_records_after = db_query("SELECT COUNT(*) FROM {flood}")->fetchField(); + $num_records_after = db_query("SELECT COUNT(*) FROM {flood}")->fetchColumn(); $this->assertIdentical($num_records_after, '0', t('Flood table emptied.')); $this->drupalLogout(); @@ -260,7 +260,7 @@ class ContactSitewideTestCase extends DrupalWebTestCase { function deleteCategories() { $categories = $this->getCategories(); foreach ($categories as $category) { - $category_name = db_query("SELECT category FROM {contact} WHERE cid = :cid", array(':cid' => $category))->fetchField(); + $category_name = db_query("SELECT category FROM {contact} WHERE cid = :cid", array(':cid' => $category))->fetchColumn(); $this->drupalPost('admin/structure/contact/delete/' . $category, array(), t('Delete')); $this->assertRaw(t('Category %category has been deleted.', array('%category' => $category_name)), t('Category deleted sucessfully.')); } @@ -377,7 +377,7 @@ class ContactPersonalTestCase extends DrupalWebTestCase { // Clear flood table in preparation for flood test and allow other checks to complete. db_delete('flood')->execute(); - $num_records_flood = db_query("SELECT COUNT(*) FROM {flood}")->fetchField(); + $num_records_flood = db_query("SELECT COUNT(*) FROM {flood}")->fetchColumn(); $this->assertIdentical($num_records_flood, '0', 'Flood table emptied.'); $this->drupalLogin($this->web_user); diff --git a/modules/dblog/dblog.module b/modules/dblog/dblog.module index 496a043..7c0834c 100644 --- a/modules/dblog/dblog.module +++ b/modules/dblog/dblog.module @@ -110,7 +110,7 @@ function dblog_cron() { ->fields('w', array('wid')) ->orderBy('wid', 'DESC') ->range($row_limit - 1, 1) - ->execute()->fetchField(); + ->execute()->fetchColumn(); // Delete all table entries older than the nth row, if nth row was found. if ($min_row) { diff --git a/modules/dblog/dblog.test b/modules/dblog/dblog.test index ffd3e8a..cc62f17 100644 --- a/modules/dblog/dblog.test +++ b/modules/dblog/dblog.test @@ -61,7 +61,7 @@ class DBLogTestCase extends DrupalWebTestCase { $current_limit = variable_get('dblog_row_limit', 1000); $this->assertTrue($current_limit == $row_limit, t('[Cache] Row limit variable of @count equals row limit of @limit', array('@count' => $current_limit, '@limit' => $row_limit))); // Verify dblog row limit equals specified row limit. - $current_limit = unserialize(db_query("SELECT value FROM {variable} WHERE name = :dblog_limit", array(':dblog_limit' => 'dblog_row_limit'))->fetchField()); + $current_limit = unserialize(db_query("SELECT value FROM {variable} WHERE name = :dblog_limit", array(':dblog_limit' => 'dblog_row_limit'))->fetchColumn()); $this->assertTrue($current_limit == $row_limit, t('[Variable table] Row limit variable of @count equals row limit of @limit', array('@count' => $current_limit, '@limit' => $row_limit))); } @@ -74,13 +74,13 @@ class DBLogTestCase extends DrupalWebTestCase { // Generate additional log entries. $this->generateLogEntries($row_limit + 10); // Verify dblog row count exceeds row limit. - $count = db_query('SELECT COUNT(wid) FROM {watchdog}')->fetchField(); + $count = db_query('SELECT COUNT(wid) FROM {watchdog}')->fetchColumn(); $this->assertTrue($count > $row_limit, t('Dblog row count of @count exceeds row limit of @limit', array('@count' => $count, '@limit' => $row_limit))); // Run cron job. $this->cronRun(); // Verify dblog row count equals row limit plus one because cron adds a record after it runs. - $count = db_query('SELECT COUNT(wid) FROM {watchdog}')->fetchField(); + $count = db_query('SELECT COUNT(wid) FROM {watchdog}')->fetchColumn(); $this->assertTrue($count == $row_limit + 1, t('Dblog row count of @count equals row limit of @limit plus one', array('@count' => $count, '@limit' => $row_limit))); } @@ -378,7 +378,7 @@ class DBLogTestCase extends DrupalWebTestCase { protected function testDBLogAddAndClear() { global $base_root; // Get a count of how many watchdog entries there are. - $count = db_query('SELECT COUNT(*) FROM {watchdog}')->fetchField(); + $count = db_query('SELECT COUNT(*) FROM {watchdog}')->fetchColumn(); $log = array( 'type' => 'custom', 'message' => 'Log entry added to test the doClearTest clear down.', @@ -394,13 +394,13 @@ class DBLogTestCase extends DrupalWebTestCase { // Add a watchdog entry. dblog_watchdog($log); // Make sure the table count has actually incremented. - $this->assertEqual($count + 1, db_query('SELECT COUNT(*) FROM {watchdog}')->fetchField(), t('dblog_watchdog() added an entry to the dblog :count', array(':count' => $count))); + $this->assertEqual($count + 1, db_query('SELECT COUNT(*) FROM {watchdog}')->fetchColumn(), t('dblog_watchdog() added an entry to the dblog :count', array(':count' => $count))); // Login the admin user. $this->drupalLogin($this->big_user); // Now post to clear the db table. $this->drupalPost('admin/reports/dblog', array(), t('Clear log messages')); // Count rows in watchdog that previously related to the deleted user. - $count = db_query('SELECT COUNT(*) FROM {watchdog}')->fetchField(); + $count = db_query('SELECT COUNT(*) FROM {watchdog}')->fetchColumn(); $this->assertEqual($count, 0, t('DBLog contains :count records after a clear.', array(':count' => $count))); } diff --git a/modules/field/field.install b/modules/field/field.install index 16b09e1..15a5055 100644 --- a/modules/field/field.install +++ b/modules/field/field.install @@ -252,7 +252,7 @@ function _update_7000_field_create_field(&$field) { */ function _update_7000_field_delete_field($field_name) { $table_name = 'field_data_' . $field_name; - if (db_select($table_name)->range(0, 1)->countQuery()->execute()->fetchField()) { + if (db_select($table_name)->range(0, 1)->countQuery()->execute()->fetchColumn()) { $t = get_t(); throw new Exception($t('This function can only be used to delete fields without data')); } diff --git a/modules/field/modules/field_sql_storage/field_sql_storage.test b/modules/field/modules/field_sql_storage/field_sql_storage.test index f94344f..096c1ab 100644 --- a/modules/field/modules/field_sql_storage/field_sql_storage.test +++ b/modules/field/modules/field_sql_storage/field_sql_storage.test @@ -199,7 +199,7 @@ class FieldSqlStorageTestCase extends DrupalWebTestCase { $count = db_select($this->table) ->countQuery() ->execute() - ->fetchField(); + ->fetchColumn(); $this->assertEqual($count, 0, 'Missing field results in no inserts'); // Insert: Field is NULL @@ -208,7 +208,7 @@ class FieldSqlStorageTestCase extends DrupalWebTestCase { $count = db_select($this->table) ->countQuery() ->execute() - ->fetchField(); + ->fetchColumn(); $this->assertEqual($count, 0, 'NULL field results in no inserts'); // Add some real data @@ -217,7 +217,7 @@ class FieldSqlStorageTestCase extends DrupalWebTestCase { $count = db_select($this->table) ->countQuery() ->execute() - ->fetchField(); + ->fetchColumn(); $this->assertEqual($count, 1, 'Field data saved'); // Update: Field is missing. Data should survive. @@ -226,7 +226,7 @@ class FieldSqlStorageTestCase extends DrupalWebTestCase { $count = db_select($this->table) ->countQuery() ->execute() - ->fetchField(); + ->fetchColumn(); $this->assertEqual($count, 1, 'Missing field leaves data in table'); // Update: Field is NULL. Data should be wiped. @@ -235,7 +235,7 @@ class FieldSqlStorageTestCase extends DrupalWebTestCase { $count = db_select($this->table) ->countQuery() ->execute() - ->fetchField(); + ->fetchColumn(); $this->assertEqual($count, 0, 'NULL field leaves no data in table'); // Add a translation in an unavailable language. @@ -247,7 +247,7 @@ class FieldSqlStorageTestCase extends DrupalWebTestCase { $count = db_select($this->table) ->countQuery() ->execute() - ->fetchField(); + ->fetchColumn(); $this->assertEqual($count, 1, 'Field translation in an unavailable language saved.'); // Again add some real data. @@ -256,7 +256,7 @@ class FieldSqlStorageTestCase extends DrupalWebTestCase { $count = db_select($this->table) ->countQuery() ->execute() - ->fetchField(); + ->fetchColumn(); $this->assertEqual($count, 2, 'Field data saved.'); // Update: Field translation is missing but field is not empty. Translation @@ -267,7 +267,7 @@ class FieldSqlStorageTestCase extends DrupalWebTestCase { $count = db_select($this->table) ->countQuery() ->execute() - ->fetchField(); + ->fetchColumn(); $this->assertEqual($count, 2, 'Missing field translation leaves data in table.'); // Update: Field translation is NULL but field is not empty. Translation @@ -277,7 +277,7 @@ class FieldSqlStorageTestCase extends DrupalWebTestCase { $count = db_select($this->table) ->countQuery() ->execute() - ->fetchField(); + ->fetchColumn(); $this->assertEqual($count, 1, 'NULL field translation is wiped.'); } diff --git a/modules/field/tests/field.test b/modules/field/tests/field.test index b361637..758f950 100644 --- a/modules/field/tests/field.test +++ b/modules/field/tests/field.test @@ -1133,7 +1133,7 @@ class FieldInfoTestCase extends FieldTestCase { // Simulate a stored field definition missing a field setting (e.g. a // third-party module adding a new field setting has been enabled, and // existing fields do not know the setting yet). - $data = db_query('SELECT data FROM {field_config} WHERE field_name = :field_name', array(':field_name' => $field_definition['field_name']))->fetchField(); + $data = db_query('SELECT data FROM {field_config} WHERE field_name = :field_name', array(':field_name' => $field_definition['field_name']))->fetchColumn(); $data = unserialize($data); $data['settings'] = array(); db_update('field_config') @@ -1170,7 +1170,7 @@ class FieldInfoTestCase extends FieldTestCase { // Simulate a stored instance definition missing various settings (e.g. a // third-party module adding instance, widget or display settings has been // enabled, but existing instances do not know the new settings). - $data = db_query('SELECT data FROM {field_config_instance} WHERE field_name = :field_name AND bundle = :bundle', array(':field_name' => $instance_definition['field_name'], ':bundle' => $instance_definition['bundle']))->fetchField(); + $data = db_query('SELECT data FROM {field_config_instance} WHERE field_name = :field_name AND bundle = :bundle', array(':field_name' => $instance_definition['field_name'], ':bundle' => $instance_definition['bundle']))->fetchColumn(); $data = unserialize($data); $data['settings'] = array(); $data['widget']['settings'] = 'unavailable_widget'; @@ -2063,7 +2063,7 @@ class FieldCrudTestCase extends FieldTestCase { $query = db_select('field_config')->condition('field_name', $field_name)->countQuery(); // The field does not appear in field_config. - $count = $query->execute()->fetchField(); + $count = $query->execute()->fetchColumn(); $this->assertEqual($count, 0, 'A field_config row for the field does not exist.'); // Try to create the field. @@ -2076,7 +2076,7 @@ class FieldCrudTestCase extends FieldTestCase { } // The field does not appear in field_config. - $count = $query->execute()->fetchField(); + $count = $query->execute()->fetchColumn(); $this->assertEqual($count, 0, 'A field_config row for the field does not exist.'); } diff --git a/modules/file/tests/file.test b/modules/file/tests/file.test index 32de9dc..c757a5b 100644 --- a/modules/file/tests/file.test +++ b/modules/file/tests/file.test @@ -43,7 +43,7 @@ class FileFieldTestCase extends DrupalWebTestCase { * Get the fid of the last inserted file. */ function getLastFileId() { - return (int) db_query('SELECT MAX(fid) FROM {file_managed}')->fetchField(); + return (int) db_query('SELECT MAX(fid) FROM {file_managed}')->fetchColumn(); } /** diff --git a/modules/filter/filter.admin.inc b/modules/filter/filter.admin.inc index 5a21e6e..b3c7848 100644 --- a/modules/filter/filter.admin.inc +++ b/modules/filter/filter.admin.inc @@ -297,7 +297,7 @@ function filter_admin_format_form_validate($form, &$form_state) { form_set_value($form['format'], $format_format, $form_state); form_set_value($form['name'], $format_name, $form_state); - $result = db_query("SELECT format FROM {filter_format} WHERE name = :name AND format <> :format", array(':name' => $format_name, ':format' => $format_format))->fetchField(); + $result = db_query("SELECT format FROM {filter_format} WHERE name = :name AND format <> :format", array(':name' => $format_name, ':format' => $format_format))->fetchColumn(); if ($result) { form_set_error('name', t('Text format names must be unique. A format named %name already exists.', array('%name' => $format_name))); } diff --git a/modules/filter/filter.module b/modules/filter/filter.module index a3f787e..dda7de7 100644 --- a/modules/filter/filter.module +++ b/modules/filter/filter.module @@ -307,7 +307,7 @@ function filter_format_disable($format) { * @see filter_format_load() */ function filter_format_exists($format_id) { - return (bool) db_query_range('SELECT 1 FROM {filter_format} WHERE format = :format', 0, 1, array(':format' => $format_id))->fetchField(); + return (bool) db_query_range('SELECT 1 FROM {filter_format} WHERE format = :format', 0, 1, array(':format' => $format_id))->fetchColumn(); } /** diff --git a/modules/filter/filter.test b/modules/filter/filter.test index 67d0833..b6d778f 100644 --- a/modules/filter/filter.test +++ b/modules/filter/filter.test @@ -676,7 +676,7 @@ class FilterDefaultFormatTestCase extends DrupalWebTestCase { // Adjust the weights so that the first and second formats (in that order) // are the two lowest weighted formats available to any user. - $minimum_weight = db_query("SELECT MIN(weight) FROM {filter_format}")->fetchField(); + $minimum_weight = db_query("SELECT MIN(weight) FROM {filter_format}")->fetchColumn(); $edit = array(); $edit['formats[' . $first_format->format . '][weight]'] = $minimum_weight - 2; $edit['formats[' . $second_format->format . '][weight]'] = $minimum_weight - 1; @@ -1740,7 +1740,7 @@ class FilterHooksTestCase extends DrupalWebTestCase { $this->assertText(t('The block has been created.'), t('New block successfully created.')); // Verify the new block is in the database. - $bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchField(); + $bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchColumn(); $this->assertNotNull($bid, t('New block found in database')); // Disable the text format. diff --git a/modules/forum/forum.module b/modules/forum/forum.module index 5bb4392..fe6e641 100644 --- a/modules/forum/forum.module +++ b/modules/forum/forum.module @@ -307,7 +307,7 @@ function forum_node_validate($node, $form) { $used = db_query_range('SELECT 1 FROM {taxonomy_term_data} WHERE tid = :tid AND vid = :vid',0 , 1, array( ':tid' => $term->tid, ':vid' => $term->vid, - ))->fetchField(); + ))->fetchColumn(); if ($used && in_array($term->tid, $containers)) { form_set_error('taxonomy_forums', t('The item %forum is a forum container, not a forum. Select one of the forums below instead.', array('%forum' => $term->name))); } @@ -329,7 +329,7 @@ function forum_node_presave($node) { $langcode = key($node->taxonomy_forums); if (!empty($node->taxonomy_forums[$langcode])) { $node->forum_tid = $node->taxonomy_forums[$langcode][0]['tid']; - $old_tid = db_query_range("SELECT f.tid FROM {forum} f INNER JOIN {node} n ON f.vid = n.vid WHERE n.nid = :nid ORDER BY f.vid DESC", 0, 1, array(':nid' => $node->nid))->fetchField(); + $old_tid = db_query_range("SELECT f.tid FROM {forum} f INNER JOIN {node} n ON f.vid = n.vid WHERE n.nid = :nid ORDER BY f.vid DESC", 0, 1, array(':nid' => $node->nid))->fetchColumn(); if ($old_tid && isset($node->forum_tid) && ($node->forum_tid != $old_tid) && !empty($node->shadow)) { // A shadow copy needs to be created. Retain new term and add old term. $node->taxonomy_forums[$langcode][] = array('tid' => $old_tid); @@ -343,7 +343,7 @@ function forum_node_presave($node) { */ function forum_node_update($node) { if (_forum_node_check_node_type($node)) { - if (empty($node->revision) && db_query('SELECT tid FROM {forum} WHERE nid=:nid', array(':nid' => $node->nid))->fetchField()) { + if (empty($node->revision) && db_query('SELECT tid FROM {forum} WHERE nid=:nid', array(':nid' => $node->nid))->fetchColumn()) { if (!empty($node->forum_tid)) { db_update('forum') ->fields(array('tid' => $node->forum_tid)) @@ -849,7 +849,7 @@ function _forum_topics_unread($term, $uid) { ->isNull('h.nid') ->addTag('node_access') ->execute() - ->fetchField(); + ->fetchColumn(); } function forum_get_topics($tid, $sortby, $forum_per_page) { @@ -1239,7 +1239,7 @@ function _forum_update_forum_index($nid) { $count = db_query('SELECT COUNT(cid) FROM {comment} WHERE nid = :nid AND status = :status', array( ':nid' => $nid, ':status' => COMMENT_PUBLISHED, - ))->fetchField(); + ))->fetchColumn(); if ($count > 0) { // Comments exist. diff --git a/modules/forum/forum.test b/modules/forum/forum.test index c7c3d9c..0741554 100644 --- a/modules/forum/forum.test +++ b/modules/forum/forum.test @@ -182,7 +182,7 @@ class ForumTestCase extends DrupalWebTestCase { $this->drupalLogin($this->admin_user); $this->drupalPost('node/add/forum', array('title' => $this->randomName(10), 'body[' . LANGUAGE_NONE .'][0][value]' => $this->randomName(120)), t('Save')); - $nid_count = db_query('SELECT COUNT(nid) FROM {node}')->fetchField(); + $nid_count = db_query('SELECT COUNT(nid) FROM {node}')->fetchColumn(); $this->assertEqual(0, $nid_count, t('A forum node was not created when missing a forum vocabulary.')); // Reset the defaults for future tests. @@ -213,7 +213,7 @@ class ForumTestCase extends DrupalWebTestCase { $this->assertText(t('The block settings have been updated.'), t('[New forum topics] Forum block was enabled')); // Retrieve forum menu id. - $mlid = db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = 'forum' AND menu_name = 'navigation' AND module = 'system' ORDER BY mlid ASC", 0, 1)->fetchField(); + $mlid = db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = 'forum' AND menu_name = 'navigation' AND module = 'system' ORDER BY mlid ASC", 0, 1)->fetchColumn(); // Add forum to navigation menu. $edit = array(); @@ -321,7 +321,7 @@ class ForumTestCase extends DrupalWebTestCase { // Verify forum hierarchy. $tid = $term['tid']; - $parent_tid = db_query("SELECT t.parent FROM {taxonomy_term_hierarchy} t WHERE t.tid = :tid", array(':tid' => $tid))->fetchField(); + $parent_tid = db_query("SELECT t.parent FROM {taxonomy_term_hierarchy} t WHERE t.tid = :tid", array(':tid' => $tid))->fetchColumn(); $this->assertTrue($parent == $parent_tid, 'The ' . $type . ' is linked to its container'); return $term; @@ -482,7 +482,7 @@ class ForumTestCase extends DrupalWebTestCase { $forum_tid = db_query("SELECT tid FROM {forum} WHERE nid = :nid AND vid = :vid", array( ':nid' => $node->nid, ':vid' => $node->vid, - ))->fetchField(); + ))->fetchColumn(); $this->assertTrue($forum_tid == $this->root_forum['tid'], 'The forum topic is linked to a different forum'); // Delete forum node. diff --git a/modules/locale/locale.admin.inc b/modules/locale/locale.admin.inc index cd2edf5..406875e 100644 --- a/modules/locale/locale.admin.inc +++ b/modules/locale/locale.admin.inc @@ -325,7 +325,7 @@ function _locale_languages_common_controls(&$form, $language = NULL) { function locale_languages_predefined_form_validate($form, &$form_state) { $langcode = $form_state['values']['langcode']; - if (($duplicate = db_query("SELECT COUNT(*) FROM {languages} WHERE language = :language", array(':language' => $langcode))->fetchField()) != 0) { + if (($duplicate = db_query("SELECT COUNT(*) FROM {languages} WHERE language = :language", array(':language' => $langcode))->fetchColumn()) != 0) { form_set_error('langcode', t('The language %language (%code) already exists.', array('%language' => $form_state['values']['name'], '%code' => $langcode))); } @@ -389,13 +389,13 @@ function locale_languages_edit_form_validate($form, &$form_state) { if (!empty($form_state['values']['domain']) && !empty($form_state['values']['prefix'])) { form_set_error('prefix', t('Domain and path prefix values should not be set at the same time.')); } - if (!empty($form_state['values']['domain']) && $duplicate = db_query("SELECT language FROM {languages} WHERE domain = :domain AND language <> :language", array(':domain' => $form_state['values']['domain'], ':language' => $form_state['values']['langcode']))->fetchField()) { + if (!empty($form_state['values']['domain']) && $duplicate = db_query("SELECT language FROM {languages} WHERE domain = :domain AND language <> :language", array(':domain' => $form_state['values']['domain'], ':language' => $form_state['values']['langcode']))->fetchColumn()) { form_set_error('domain', t('The domain (%domain) is already tied to a language (%language).', array('%domain' => $form_state['values']['domain'], '%language' => $duplicate->language))); } if (empty($form_state['values']['prefix']) && language_default()->language != $form_state['values']['langcode'] && empty($form_state['values']['domain'])) { form_set_error('prefix', t('Only the default language can have both the domain and prefix empty.')); } - if (!empty($form_state['values']['prefix']) && $duplicate = db_query("SELECT language FROM {languages} WHERE prefix = :prefix AND language <> :language", array(':prefix' => $form_state['values']['prefix'], ':language' => $form_state['values']['langcode']))->fetchField()) { + if (!empty($form_state['values']['prefix']) && $duplicate = db_query("SELECT language FROM {languages} WHERE prefix = :prefix AND language <> :language", array(':prefix' => $form_state['values']['prefix'], ':language' => $form_state['values']['langcode']))->fetchColumn()) { form_set_error('prefix', t('The prefix (%prefix) is already tied to a language (%language).', array('%prefix' => $form_state['values']['prefix'], '%language' => $duplicate->language))); } } diff --git a/modules/locale/locale.pages.inc b/modules/locale/locale.pages.inc index 3e6590e..731f3ae 100644 --- a/modules/locale/locale.pages.inc +++ b/modules/locale/locale.pages.inc @@ -12,7 +12,7 @@ function locale_translate_overview_screen() { drupal_static_reset('language_list'); $languages = language_list('language'); $headers = array(t('Language'), t('Interface translation status')); - $num_strings = db_query("SELECT COUNT(*) FROM {locales_source}")->fetchField(); + $num_strings = db_query("SELECT COUNT(*) FROM {locales_source}")->fetchColumn(); // Set up overview table with default values, ensuring common order for values. $rows = array(); @@ -372,7 +372,7 @@ function locale_translate_edit_form_validate($form, &$form_state) { function locale_translate_edit_form_submit($form, &$form_state) { $lid = $form_state['values']['lid']; foreach ($form_state['values']['translations'] as $key => $value) { - $translation = db_query("SELECT translation FROM {locales_target} WHERE lid = :lid AND language = :language", array(':lid' => $lid, ':language' => $key))->fetchField(); + $translation = db_query("SELECT translation FROM {locales_target} WHERE lid = :lid AND language = :language", array(':lid' => $lid, ':language' => $key))->fetchColumn(); if (!empty($value)) { // Only update or insert if we have a value to use. if (!empty($translation)) { diff --git a/modules/locale/locale.test b/modules/locale/locale.test index 425f68c..cafa796 100644 --- a/modules/locale/locale.test +++ b/modules/locale/locale.test @@ -631,7 +631,7 @@ class LocaleImportFunctionalTest extends DrupalWebTestCase { $this->assertRaw(t('The translation was successfully imported. There are %number newly created translated strings, %update strings were updated and %delete strings were removed.', array('%number' => 9, '%update' => 0, '%delete' => 0)), t('The translation file was successfully imported.')); // This import should have saved plural forms to have 2 variants. - $this->assert(db_query("SELECT plurals FROM {languages} WHERE language = 'fr'")->fetchField() == 2, t('Plural number initialized.')); + $this->assert(db_query("SELECT plurals FROM {languages} WHERE language = 'fr'")->fetchColumn() == 2, t('Plural number initialized.')); // Ensure we were redirected correctly. $this->assertEqual($this->getUrl(), url('admin/config/regional/translate', array('absolute' => TRUE)), t('Correct page redirection.')); @@ -677,7 +677,7 @@ class LocaleImportFunctionalTest extends DrupalWebTestCase { $this->assertText(t('No strings available.'), t('String not overwritten by imported string.')); // This import should not have changed number of plural forms. - $this->assert(db_query("SELECT plurals FROM {languages} WHERE language = 'fr'")->fetchField() == 2, t('Plural numbers untouched.')); + $this->assert(db_query("SELECT plurals FROM {languages} WHERE language = 'fr'")->fetchColumn() == 2, t('Plural numbers untouched.')); // Try importing a .po file with overriding strings, and ensure existing // strings are overwritten. @@ -697,7 +697,7 @@ class LocaleImportFunctionalTest extends DrupalWebTestCase { $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter')); $this->assertNoText(t('No strings available.'), t('String overwritten by imported string.')); // This import should have changed number of plural forms. - $this->assert(db_query("SELECT plurals FROM {languages} WHERE language = 'fr'")->fetchField() == 3, t('Plural numbers changed.')); + $this->assert(db_query("SELECT plurals FROM {languages} WHERE language = 'fr'")->fetchColumn() == 3, t('Plural numbers changed.')); } /** diff --git a/modules/menu/menu.admin.inc b/modules/menu/menu.admin.inc index cb33cbb..89ffdef 100644 --- a/modules/menu/menu.admin.inc +++ b/modules/menu/menu.admin.inc @@ -507,7 +507,7 @@ function menu_delete_menu_page($menu) { function menu_delete_menu_confirm($form, &$form_state, $menu) { $form['#menu'] = $menu; $caption = ''; - $num_links = db_query("SELECT COUNT(*) FROM {menu_links} WHERE menu_name = :menu", array(':menu' => $menu['menu_name']))->fetchField(); + $num_links = db_query("SELECT COUNT(*) FROM {menu_links} WHERE menu_name = :menu", array(':menu' => $menu['menu_name']))->fetchColumn(); if ($num_links) { $caption .= '

    ' . format_plural($num_links, 'Warning: There is currently 1 menu link in %title. It will be deleted (system-defined items will be reset).', 'Warning: There are currently @count menu links in %title. They will be deleted (system-defined links will be reset).', array('%title' => $menu['title'])) . '

    '; } @@ -524,7 +524,7 @@ function menu_delete_menu_confirm_submit($form, &$form_state) { // System-defined menus may not be deleted - only menus defined by this module. $system_menus = menu_list_system_menus(); - if (isset($system_menus[$menu['menu_name']]) || !(db_query("SELECT 1 FROM {menu_custom} WHERE menu_name = :menu", array(':menu' => $menu['menu_name']))->fetchField())) { + if (isset($system_menus[$menu['menu_name']]) || !(db_query("SELECT 1 FROM {menu_custom} WHERE menu_name = :menu", array(':menu' => $menu['menu_name']))->fetchColumn())) { return; } @@ -557,8 +557,8 @@ function menu_delete_menu_confirm_submit($form, &$form_state) { function menu_edit_menu_name_exists($value) { // 'menu-' is added to the menu name to avoid name-space conflicts. $value = 'menu-' . $value; - $custom_exists = db_query_range('SELECT 1 FROM {menu_custom} WHERE menu_name = :menu', 0, 1, array(':menu' => $value))->fetchField(); - $link_exists = db_query_range("SELECT 1 FROM {menu_links} WHERE menu_name = :menu", 0, 1, array(':menu' => $value))->fetchField(); + $custom_exists = db_query_range('SELECT 1 FROM {menu_custom} WHERE menu_name = :menu', 0, 1, array(':menu' => $value))->fetchColumn(); + $link_exists = db_query_range("SELECT 1 FROM {menu_links} WHERE menu_name = :menu", 0, 1, array(':menu' => $value))->fetchColumn(); return $custom_exists || $link_exists; } @@ -580,7 +580,7 @@ function menu_edit_menu_submit($form, &$form_state) { ':link' => 'admin/structure/menu', ':module' => 'system' )) - ->fetchField(); + ->fetchColumn(); menu_link_save($link); menu_save($menu); diff --git a/modules/menu/menu.module b/modules/menu/menu.module index fa58373..43bb529 100644 --- a/modules/menu/menu.module +++ b/modules/menu/menu.module @@ -193,7 +193,7 @@ function menu_enable() { ':path' => $link['link_path'], ':plid' => $link['plid'] )) - ->fetchField(); + ->fetchColumn(); if (!$menu_link) { menu_link_save($link); } @@ -551,14 +551,14 @@ function menu_node_prepare($node) { $mlid = db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = :path AND menu_name = :menu_name AND module = 'menu' ORDER BY mlid ASC", 0, 1, array( ':path' => 'node/' . $node->nid, ':menu_name' => $menu_name, - ))->fetchField(); + ))->fetchColumn(); } // Check all allowed menus if a link does not exist in the default menu. if (!$mlid && !empty($type_menus)) { $mlid = db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = :path AND module = 'menu' AND menu_name IN (:type_menus) ORDER BY mlid ASC", 0, 1, array( ':path' => 'node/' . $node->nid, ':type_menus' => array_values($type_menus), - ))->fetchField(); + ))->fetchColumn(); } if ($mlid) { $item = menu_link_load($mlid); diff --git a/modules/menu/menu.test b/modules/menu/menu.test index d1f16f6..a4ef79d 100644 --- a/modules/menu/menu.test +++ b/modules/menu/menu.test @@ -187,7 +187,7 @@ class MenuTestCase extends DrupalWebTestCase { $this->assertRaw(t('The custom menu %title has been deleted.', array('%title' => $title)), t('Custom menu was deleted')); $this->assertFalse(menu_load($menu_name), 'Custom menu was deleted'); // Test if all menu links associated to the menu were removed from database. - $result = db_query("SELECT menu_name FROM {menu_links} WHERE menu_name = :menu_name", array(':menu_name' => $menu_name))->fetchField(); + $result = db_query("SELECT menu_name FROM {menu_links} WHERE menu_name = :menu_name", array(':menu_name' => $menu_name))->fetchColumn(); $this->assertFalse($result, t('All menu links associated to the custom menu were deleted.')); } @@ -518,7 +518,7 @@ class MenuTestCase extends DrupalWebTestCase { */ private function getStandardMenuLink() { // Retrieve menu link id of the Log out menu link, which will always be on the front page. - $mlid = db_query("SELECT mlid FROM {menu_links} WHERE module = 'system' AND router_path = 'user/logout'")->fetchField(); + $mlid = db_query("SELECT mlid FROM {menu_links} WHERE module = 'system' AND router_path = 'user/logout'")->fetchColumn(); $this->assertTrue($mlid > 0, 'Standard menu link id was found'); // Load menu link. // Use api function so that link is translated for rendering. diff --git a/modules/node/content_types.inc b/modules/node/content_types.inc index d58bc31..cbf6063 100644 --- a/modules/node/content_types.inc +++ b/modules/node/content_types.inc @@ -418,7 +418,7 @@ function node_type_delete_confirm($form, &$form_state, $type) { $message = t('Are you sure you want to delete the content type %type?', array('%type' => $type->name)); $caption = ''; - $num_nodes = db_query("SELECT COUNT(*) FROM {node} WHERE type = :type", array(':type' => $type->type))->fetchField(); + $num_nodes = db_query("SELECT COUNT(*) FROM {node} WHERE type = :type", array(':type' => $type->type))->fetchColumn(); if ($num_nodes) { $caption .= '

    ' . format_plural($num_nodes, '%type is used by 1 piece of content on your site. If you remove this content type, you will not be able to edit the %type content and it may not display correctly.', '%type is used by @count pieces of content on your site. If you remove %type, you will not be able to edit the %type content and it may not display correctly.', array('%type' => $type->name)) . '

    '; } diff --git a/modules/node/node.admin.inc b/modules/node/node.admin.inc index 43e0ecd..8245743 100644 --- a/modules/node/node.admin.inc +++ b/modules/node/node.admin.inc @@ -389,7 +389,7 @@ function node_admin_nodes() { // Enable language column if translation module is enabled or if we have any // node with language. - $multilanguage = (module_exists('translation') || db_query_range("SELECT 1 FROM {node} WHERE language <> :language", 0, 1, array(':language' => LANGUAGE_NONE))->fetchField()); + $multilanguage = (module_exists('translation') || db_query_range("SELECT 1 FROM {node} WHERE language <> :language", 0, 1, array(':language' => LANGUAGE_NONE))->fetchColumn()); // Build the sortable table header. $header = array( @@ -570,7 +570,7 @@ function node_multiple_delete_confirm($form, &$form_state, $nodes) { $form['nodes'] = array('#prefix' => '', '#tree' => TRUE); // array_filter returns only elements with TRUE values foreach ($nodes as $nid => $value) { - $title = db_query('SELECT title FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchField(); + $title = db_query('SELECT title FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchColumn(); $form['nodes'][$nid] = array( '#type' => 'hidden', '#value' => $nid, diff --git a/modules/node/node.api.php b/modules/node/node.api.php index 7ac62f8..8cb6178 100644 --- a/modules/node/node.api.php +++ b/modules/node/node.api.php @@ -654,7 +654,7 @@ function hook_node_prepare($node) { * @ingroup node_api_hooks */ function hook_node_search_result($node) { - $comments = db_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = :nid', array('nid' => $node->nid))->fetchField(); + $comments = db_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = :nid', array('nid' => $node->nid))->fetchColumn(); return array('comment' => format_plural($comments, '1 comment', '@count comments')); } diff --git a/modules/node/node.module b/modules/node/node.module index 92c6795..9590c76 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -490,7 +490,7 @@ function node_type_load($name) { */ function node_type_save($info) { $existing_type = !empty($info->old_type) ? $info->old_type : $info->type; - $is_existing = (bool) db_query_range('SELECT 1 FROM {node_type} WHERE type = :type', 0, 1, array(':type' => $existing_type))->fetchField(); + $is_existing = (bool) db_query_range('SELECT 1 FROM {node_type} WHERE type = :type', 0, 1, array(':type' => $existing_type))->fetchColumn(); $type = node_type_set_defaults($info); $fields = array( @@ -1598,8 +1598,8 @@ function node_search_reset() { * Implements hook_search_status(). */ function node_search_status() { - $total = db_query('SELECT COUNT(*) FROM {node}')->fetchField(); - $remaining = db_query("SELECT COUNT(*) FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE d.sid IS NULL OR d.reindex <> 0")->fetchField(); + $total = db_query('SELECT COUNT(*) FROM {node}')->fetchColumn(); + $remaining = db_query("SELECT COUNT(*) FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE d.sid IS NULL OR d.reindex <> 0")->fetchColumn(); return array('remaining' => $remaining, 'total' => $total); } @@ -1833,7 +1833,7 @@ function _node_revision_access($node, $op = 'view') { // different revisions so there is no need for a separate database check. // Also, if you try to revert to or delete the current revision, that's // not good. - if ($is_current_revision && (db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid', array(':nid' => $node->nid))->fetchField() == 1 || $op == 'update' || $op == 'delete')) { + if ($is_current_revision && (db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid', array(':nid' => $node->nid))->fetchColumn() == 1 || $op == 'update' || $op == 'delete')) { $access[$node->vid] = FALSE; } elseif (user_access('administer nodes')) { @@ -2916,7 +2916,7 @@ function node_access($op, $node, $account = NULL) { } $result = (bool) $query ->execute() - ->fetchField(); + ->fetchColumn(); $rights[$account->uid][$cid][$op] = $result; return $result; } @@ -3112,7 +3112,7 @@ function node_access_view_all_nodes($account = NULL) { } $access[$account->uid] = $query ->execute() - ->fetchField(); + ->fetchColumn(); } return $access[$account->uid]; @@ -3513,7 +3513,7 @@ function _node_access_rebuild_batch_operation(&$context) { // Initiate multistep processing. $context['sandbox']['progress'] = 0; $context['sandbox']['current_node'] = 0; - $context['sandbox']['max'] = db_query('SELECT COUNT(DISTINCT nid) FROM {node}')->fetchField(); + $context['sandbox']['max'] = db_query('SELECT COUNT(DISTINCT nid) FROM {node}')->fetchColumn(); } // Process the next 20 nodes. @@ -3754,7 +3754,7 @@ function node_save_action($node) { */ function node_assign_owner_action($node, $context) { $node->uid = $context['owner_uid']; - $owner_name = db_query("SELECT name FROM {users} WHERE uid = :uid", array(':uid' => $context['owner_uid']))->fetchField(); + $owner_name = db_query("SELECT name FROM {users} WHERE uid = :uid", array(':uid' => $context['owner_uid']))->fetchColumn(); watchdog('action', 'Changed owner of @type %title to uid %name.', array('@type' => node_type_get_name($node), '%title' => $node->title, '%name' => $owner_name)); } @@ -3763,10 +3763,10 @@ function node_assign_owner_action($node, $context) { */ function node_assign_owner_action_form($context) { $description = t('The username of the user to which you would like to assign ownership.'); - $count = db_query("SELECT COUNT(*) FROM {users}")->fetchField(); + $count = db_query("SELECT COUNT(*) FROM {users}")->fetchColumn(); $owner_name = ''; if (isset($context['owner_uid'])) { - $owner_name = db_query("SELECT name FROM {users} WHERE uid = :uid", array(':uid' => $context['owner_uid']))->fetchField(); + $owner_name = db_query("SELECT name FROM {users} WHERE uid = :uid", array(':uid' => $context['owner_uid']))->fetchColumn(); } // Use dropdown for fewer than 200 users; textbox for more than that. @@ -3802,7 +3802,7 @@ function node_assign_owner_action_form($context) { * Validates settings form for node_assign_owner_action(). */ function node_assign_owner_action_validate($form, $form_state) { - $exists = (bool) db_query_range('SELECT 1 FROM {users} WHERE name = :name', 0, 1, array(':name' => $form_state['values']['owner_name']))->fetchField(); + $exists = (bool) db_query_range('SELECT 1 FROM {users} WHERE name = :name', 0, 1, array(':name' => $form_state['values']['owner_name']))->fetchColumn(); if (!$exists) { form_set_error('owner_name', t('Enter a valid username.')); } @@ -3813,7 +3813,7 @@ function node_assign_owner_action_validate($form, $form_state) { */ function node_assign_owner_action_submit($form, $form_state) { // Username can change, so we need to store the ID, not the username. - $uid = db_query('SELECT uid from {users} WHERE name = :name', array(':name' => $form_state['values']['owner_name']))->fetchField(); + $uid = db_query('SELECT uid from {users} WHERE name = :name', array(':name' => $form_state['values']['owner_name']))->fetchColumn(); return array('owner_uid' => $uid); } @@ -3870,7 +3870,7 @@ function node_requirements($phase) { // Only show rebuild button if there are either 0, or 2 or more, rows // in the {node_access} table, or if there are modules that // implement hook_node_grants(). - $grant_count = db_query('SELECT COUNT(*) FROM {node_access}')->fetchField(); + $grant_count = db_query('SELECT COUNT(*) FROM {node_access}')->fetchColumn(); if ($grant_count != 1 || count(module_implements('node_grants')) > 0) { $value = format_plural($grant_count, 'One permission in use', '@count permissions in use', array('@count' => $grant_count)); } else { diff --git a/modules/node/node.pages.inc b/modules/node/node.pages.inc index d92e8b7..413d939 100644 --- a/modules/node/node.pages.inc +++ b/modules/node/node.pages.inc @@ -577,7 +577,7 @@ function node_revision_delete_confirm_submit($form, &$form_state) { watchdog('content', '@type: deleted %title revision %revision.', array('@type' => $node_revision->type, '%title' => $node_revision->title, '%revision' => $node_revision->vid)); drupal_set_message(t('Revision from %revision-date of @type %title has been deleted.', array('%revision-date' => format_date($node_revision->revision_timestamp), '@type' => node_type_get_name($node_revision), '%title' => $node_revision->title))); $form_state['redirect'] = 'node/' . $node_revision->nid; - if (db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid', array(':nid' => $node_revision->nid))->fetchField() > 1) { + if (db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid', array(':nid' => $node_revision->nid))->fetchColumn() > 1) { $form_state['redirect'] .= '/revisions'; } } diff --git a/modules/node/node.test b/modules/node/node.test index d004684..dfadf10 100644 --- a/modules/node/node.test +++ b/modules/node/node.test @@ -210,7 +210,7 @@ class NodeRevisionsTestCase extends DrupalWebTestCase { $this->assertRaw(t('Revision from %revision-date of @type %title has been deleted.', array('%revision-date' => format_date($nodes[1]->revision_timestamp), '@type' => 'Basic page', '%title' => $nodes[1]->title)), t('Revision deleted.')); - $this->assertTrue(db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid and vid = :vid', array(':nid' => $node->nid, ':vid' => $nodes[1]->vid))->fetchField() == 0, t('Revision not found.')); + $this->assertTrue(db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid and vid = :vid', array(':nid' => $node->nid, ':vid' => $nodes[1]->vid))->fetchColumn() == 0, t('Revision not found.')); } /** @@ -1032,8 +1032,8 @@ class NodeAccessBaseTableTestCase extends DrupalWebTestCase { } $this->drupalPost('node/add/article', $edit, t('Save')); - $nid = db_query('SELECT nid FROM {node} WHERE title = :title', array(':title' => $edit['title']))->fetchField(); - $private_status = db_query('SELECT private FROM {node_access_test} where nid = :nid', array(':nid' => $nid))->fetchField(); + $nid = db_query('SELECT nid FROM {node} WHERE title = :title', array(':title' => $edit['title']))->fetchColumn(); + $private_status = db_query('SELECT private FROM {node_access_test} where nid = :nid', array(':nid' => $nid))->fetchColumn(); $this->assertTrue($is_private == $private_status, t('The private status of the node was properly set in the node_access_test table.')); if ($is_private) { $private_nodes[] = $nid; @@ -1042,8 +1042,8 @@ class NodeAccessBaseTableTestCase extends DrupalWebTestCase { $this->nodesByUser[$this->webUser->uid][$nid] = $is_private; } } - $this->publicTid = db_query('SELECT tid FROM {taxonomy_term_data} WHERE name = :name', array(':name' => 'public'))->fetchField(); - $this->privateTid = db_query('SELECT tid FROM {taxonomy_term_data} WHERE name = :name', array(':name' => 'private'))->fetchField(); + $this->publicTid = db_query('SELECT tid FROM {taxonomy_term_data} WHERE name = :name', array(':name' => 'public'))->fetchColumn(); + $this->privateTid = db_query('SELECT tid FROM {taxonomy_term_data} WHERE name = :name', array(':name' => 'private'))->fetchColumn(); $this->assertTrue($this->publicTid, t('Public tid was found')); $this->assertTrue($this->privateTid, t('Private tid was found')); foreach ($simple_users as $this->webUser) { @@ -1148,7 +1148,7 @@ class NodeSaveTestCase extends DrupalWebTestCase { */ function testImport() { // Node ID must be a number that is not in the database. - $max_nid = db_query('SELECT MAX(nid) FROM {node}')->fetchField(); + $max_nid = db_query('SELECT MAX(nid) FROM {node}')->fetchColumn(); $test_nid = $max_nid + mt_rand(1000, 1000000); $title = $this->randomName(8); $node = array( @@ -1299,7 +1299,7 @@ class NodeTypeTestCase extends DrupalWebTestCase { // Create a content type programmaticaly. $type = $this->drupalCreateContentType(); - $type_exists = db_query('SELECT 1 FROM {node_type} WHERE type = :type', array(':type' => $type->type))->fetchField(); + $type_exists = db_query('SELECT 1 FROM {node_type} WHERE type = :type', array(':type' => $type->type))->fetchColumn(); $this->assertTrue($type_exists, 'The new content type has been created in the database.'); // Login a test user. @@ -1318,7 +1318,7 @@ class NodeTypeTestCase extends DrupalWebTestCase { 'type' => 'foo', ); $this->drupalPost('admin/structure/types/add', $edit, t('Save content type')); - $type_exists = db_query('SELECT 1 FROM {node_type} WHERE type = :type', array(':type' => 'foo'))->fetchField(); + $type_exists = db_query('SELECT 1 FROM {node_type} WHERE type = :type', array(':type' => 'foo'))->fetchColumn(); $this->assertTrue($type_exists, 'The new content type has been created in the database.'); } @@ -1440,7 +1440,7 @@ class NodeTypePersistenceTestCase extends DrupalWebTestCase { // Enable poll and verify that the node type is in the DB and is not // disabled. $this->drupalPost('admin/modules', $poll_enable, t('Save configuration')); - $disabled = db_query('SELECT disabled FROM {node_type} WHERE type = :type', array(':type' => 'poll'))->fetchField(); + $disabled = db_query('SELECT disabled FROM {node_type} WHERE type = :type', array(':type' => 'poll'))->fetchColumn(); $this->assertNotIdentical($disabled, FALSE, t('Poll node type found in the database')); $this->assertEqual($disabled, 0, t('Poll node type is not disabled')); @@ -1459,7 +1459,7 @@ class NodeTypePersistenceTestCase extends DrupalWebTestCase { // Disable poll and check that the node type gets disabled. $this->drupalPost('admin/modules', $poll_disable, t('Save configuration')); - $disabled = db_query('SELECT disabled FROM {node_type} WHERE type = :type', array(':type' => 'poll'))->fetchField(); + $disabled = db_query('SELECT disabled FROM {node_type} WHERE type = :type', array(':type' => 'poll'))->fetchColumn(); $this->assertEqual($disabled, 1, t('Poll node type is disabled')); $this->drupalGet('node/add'); $this->assertNoText('poll', t('poll type is not found on node/add')); @@ -1467,7 +1467,7 @@ class NodeTypePersistenceTestCase extends DrupalWebTestCase { // Reenable poll and check that the customization survived the module // disable. $this->drupalPost('admin/modules', $poll_enable, t('Save configuration')); - $disabled = db_query('SELECT disabled FROM {node_type} WHERE type = :type', array(':type' => 'poll'))->fetchField(); + $disabled = db_query('SELECT disabled FROM {node_type} WHERE type = :type', array(':type' => 'poll'))->fetchColumn(); $this->assertNotIdentical($disabled, FALSE, t('Poll node type found in the database')); $this->assertEqual($disabled, 0, t('Poll node type is not disabled')); $this->drupalGet('node/add'); @@ -1478,7 +1478,7 @@ class NodeTypePersistenceTestCase extends DrupalWebTestCase { $edit = array('uninstall[poll]' => 'poll'); $this->drupalPost('admin/modules/uninstall', $edit, t('Uninstall')); $this->drupalPost(NULL, array(), t('Uninstall')); - $disabled = db_query('SELECT disabled FROM {node_type} WHERE type = :type', array(':type' => 'poll'))->fetchField(); + $disabled = db_query('SELECT disabled FROM {node_type} WHERE type = :type', array(':type' => 'poll'))->fetchColumn(); $this->assertTrue($disabled, t('Poll node type is in the database and is disabled')); $this->drupalGet('node/add'); $this->assertNoText('poll', t('poll type is no longer found on node/add')); @@ -1875,7 +1875,7 @@ class NodeBlockFunctionalTest extends DrupalWebTestCase { } $this->drupalPost('admin/structure/block/add', $custom_block, t('Save block')); - $bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchField(); + $bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchColumn(); $this->assertTrue($bid, t('Custom block with visibility rule was created.')); // Verify visibility rules. @@ -1888,7 +1888,7 @@ class NodeBlockFunctionalTest extends DrupalWebTestCase { // Delete the created custom block & verify that it's been deleted. $this->drupalPost('admin/structure/block/manage/block/' . $bid . '/delete', array(), t('Delete')); - $bid = db_query("SELECT 1 FROM {block_node_type} WHERE module = 'block' AND delta = :delta", array(':delta' => $bid))->fetchField(); + $bid = db_query("SELECT 1 FROM {block_node_type} WHERE module = 'block' AND delta = :delta", array(':delta' => $bid))->fetchColumn(); $this->assertFalse($bid, t('Custom block was deleted.')); } } diff --git a/modules/openid/openid.module b/modules/openid/openid.module index bb6ad71..f87952a 100644 --- a/modules/openid/openid.module +++ b/modules/openid/openid.module @@ -591,7 +591,7 @@ function openid_association($op_endpoint) { ->execute(); // Check to see if we have an association for this IdP already - $assoc_handle = db_query("SELECT assoc_handle FROM {openid_association} WHERE idp_endpoint_uri = :endpoint", array(':endpoint' => $op_endpoint))->fetchField(); + $assoc_handle = db_query("SELECT assoc_handle FROM {openid_association} WHERE idp_endpoint_uri = :endpoint", array(':endpoint' => $op_endpoint))->fetchColumn(); if (empty($assoc_handle)) { $mod = OPENID_DH_DEFAULT_MOD; $gen = OPENID_DH_DEFAULT_GEN; @@ -945,7 +945,7 @@ function openid_verify_assertion_nonce($service, $response) { $count_used = db_query("SELECT COUNT(*) FROM {openid_nonce} WHERE nonce = :nonce AND idp_endpoint_uri = :idp_endpoint_uri", array( ':nonce' => $response['openid.response_nonce'], ':idp_endpoint_uri' => $service['uri'], - ))->fetchField(); + ))->fetchColumn(); if ($count_used == 1) { return TRUE; diff --git a/modules/openid/openid.pages.inc b/modules/openid/openid.pages.inc index 6e3f096..442739c 100644 --- a/modules/openid/openid.pages.inc +++ b/modules/openid/openid.pages.inc @@ -80,7 +80,7 @@ function openid_user_add() { function openid_user_add_validate($form, &$form_state) { // Check for existing entries. $claimed_id = openid_normalize($form_state['values']['openid_identifier']); - if (db_query("SELECT authname FROM {authmap} WHERE authname = :authname", (array(':authname' => $claimed_id)))->fetchField()) { + if (db_query("SELECT authname FROM {authmap} WHERE authname = :authname", (array(':authname' => $claimed_id)))->fetchColumn()) { form_set_error('openid_identifier', t('That OpenID is already in use on this site.')); } } @@ -98,7 +98,7 @@ function openid_user_delete_form($form, $form_state, $account, $aid = 0) { ':uid' => $account->uid, ':aid' => $aid, )) - ->fetchField(); + ->fetchColumn(); return confirm_form(array(), t('Are you sure you want to delete the OpenID %authname for %user?', array('%authname' => $authname, '%user' => $account->name)), 'user/' . $account->uid . '/openid'); } diff --git a/modules/path/path.admin.inc b/modules/path/path.admin.inc index f10142b..e83a679 100644 --- a/modules/path/path.admin.inc +++ b/modules/path/path.admin.inc @@ -15,7 +15,7 @@ function path_admin_overview($keys = NULL) { // Add the filter form above the overview table. $build['path_admin_filter_form'] = drupal_get_form('path_admin_filter_form', $keys); // Enable language column if locale is enabled or if we have any alias with language - $alias_exists = (bool) db_query_range('SELECT 1 FROM {url_alias} WHERE language <> :language', 0, 1, array(':language' => LANGUAGE_NONE))->fetchField(); + $alias_exists = (bool) db_query_range('SELECT 1 FROM {url_alias} WHERE language <> :language', 0, 1, array(':language' => LANGUAGE_NONE))->fetchColumn(); $multilanguage = (module_exists('locale') || $alias_exists); $header = array(); @@ -184,7 +184,7 @@ function path_admin_form_validate($form, &$form_state) { ':alias' => $alias, ':language' => $language, )) - ->fetchField(); + ->fetchColumn(); if ($has_alias) { form_set_error('alias', t('The alias %alias is already in use in this language.', array('%alias' => $alias))); diff --git a/modules/path/path.module b/modules/path/path.module index 332287d..bf4e6dc 100644 --- a/modules/path/path.module +++ b/modules/path/path.module @@ -172,7 +172,7 @@ function path_form_element_validate($element, &$form_state, $complete_form) { } $query->addExpression('1'); $query->range(0, 1); - if ($query->execute()->fetchField()) { + if ($query->execute()->fetchColumn()) { form_set_error('alias', t('The alias is already in use.')); } } diff --git a/modules/path/path.test b/modules/path/path.test index 241f532..1eccecf 100644 --- a/modules/path/path.test +++ b/modules/path/path.test @@ -160,7 +160,7 @@ class PathTestCase extends DrupalWebTestCase { } function getPID($alias) { - return db_query("SELECT pid FROM {url_alias} WHERE alias = :alias", array(':alias' => $alias))->fetchField(); + return db_query("SELECT pid FROM {url_alias} WHERE alias = :alias", array(':alias' => $alias))->fetchColumn(); } } @@ -202,7 +202,7 @@ class PathTaxonomyTermTestCase extends DrupalWebTestCase { $this->assertText($description, 'Term can be accessed on URL alias.'); // Change the term's URL alias. - $tid = db_query("SELECT tid FROM {taxonomy_term_data} WHERE name = :name", array(':name' => $edit['name']))->fetchField(); + $tid = db_query("SELECT tid FROM {taxonomy_term_data} WHERE name = :name", array(':name' => $edit['name']))->fetchColumn(); $edit2 = array(); $edit2['path[alias]'] = $this->randomName(); $this->drupalPost('taxonomy/term/' . $tid . '/edit', $edit2, t('Save')); diff --git a/modules/php/php.install b/modules/php/php.install index 12944dd..d56b2df 100644 --- a/modules/php/php.install +++ b/modules/php/php.install @@ -9,7 +9,7 @@ * Implements hook_enable(). */ function php_enable() { - $format_exists = (bool) db_query_range('SELECT 1 FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'PHP code'))->fetchField(); + $format_exists = (bool) db_query_range('SELECT 1 FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'PHP code'))->fetchColumn(); // Add a PHP code text format, if it does not exist. Do this only for the // first install (or if the format has been manually deleted) as there is no // reliable method to identify the format in an uninstall hook or in diff --git a/modules/poll/poll.module b/modules/poll/poll.module index 2737c2b..4530f90 100644 --- a/modules/poll/poll.module +++ b/modules/poll/poll.module @@ -502,7 +502,7 @@ function poll_load($nodes) { if (user_access('vote on polls') && $poll->active) { if ($user->uid) { // If authenticated, find existing vote based on uid. - $poll->vote = db_query('SELECT chid FROM {poll_vote} WHERE nid = :nid AND uid = :uid', array(':nid' => $node->nid, ':uid' => $user->uid))->fetchField(); + $poll->vote = db_query('SELECT chid FROM {poll_vote} WHERE nid = :nid AND uid = :uid', array(':nid' => $node->nid, ':uid' => $user->uid))->fetchColumn(); if (empty($poll->vote)) { $poll->vote = -1; $poll->allowvotes = TRUE; @@ -516,7 +516,7 @@ function poll_load($nodes) { else { // Finally, query the database for an existing vote based on anonymous // user's hostname. - $poll->allowvotes = !db_query("SELECT 1 FROM {poll_vote} WHERE nid = :nid AND hostname = :hostname AND uid = 0", array(':nid' => $node->nid, ':hostname' => ip_address()))->fetchField(); + $poll->allowvotes = !db_query("SELECT 1 FROM {poll_vote} WHERE nid = :nid AND hostname = :hostname AND uid = 0", array(':nid' => $node->nid, ':hostname' => ip_address()))->fetchColumn(); } } foreach ($poll as $key => $value) { diff --git a/modules/poll/poll.test b/modules/poll/poll.test index d7648a6..5d95230 100644 --- a/modules/poll/poll.test +++ b/modules/poll/poll.test @@ -733,7 +733,7 @@ class PollExpirationTestCase extends PollTestCase { // Test expiration. Since REQUEST_TIME is a constant and we don't // want to keep SimpleTest waiting until the moment of expiration arrives, // we forcibly change the expiration date in the database. - $created = db_query('SELECT created FROM {node} WHERE nid = :nid', array(':nid' => $poll_nid))->fetchField(); + $created = db_query('SELECT created FROM {node} WHERE nid = :nid', array(':nid' => $poll_nid))->fetchColumn(); db_update('node') ->fields(array('created' => $created - ($poll_expiration * 1.01))) ->condition('nid', $poll_nid) diff --git a/modules/rdf/rdf.module b/modules/rdf/rdf.module index ebecd42..d0fe833 100644 --- a/modules/rdf/rdf.module +++ b/modules/rdf/rdf.module @@ -195,7 +195,7 @@ function _rdf_mapping_load($type, $bundle) { ->condition('type', $type) ->condition('bundle', $bundle) ->execute() - ->fetchField(); + ->fetchColumn(); if (!$mapping) { return array(); diff --git a/modules/search/search.api.php b/modules/search/search.api.php index 8d6e239..bde84a3 100644 --- a/modules/search/search.api.php +++ b/modules/search/search.api.php @@ -119,8 +119,8 @@ function hook_search_reset() { * @ingroup search */ function hook_search_status() { - $total = db_query('SELECT COUNT(*) FROM {node} WHERE status = 1')->fetchField(); - $remaining = db_query("SELECT COUNT(*) FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE n.status = 1 AND d.sid IS NULL OR d.reindex <> 0")->fetchField(); + $total = db_query('SELECT COUNT(*) FROM {node} WHERE status = 1')->fetchColumn(); + $remaining = db_query("SELECT COUNT(*) FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE n.status = 1 AND d.sid IS NULL OR d.reindex <> 0")->fetchColumn(); return array('remaining' => $remaining, 'total' => $total); } diff --git a/modules/search/search.extender.inc b/modules/search/search.extender.inc index b7af4d0..6d182ab 100644 --- a/modules/search/search.extender.inc +++ b/modules/search/search.extender.inc @@ -355,7 +355,7 @@ class SearchQuery extends SelectQueryExtender { ->range(0, 1) ->orderBy('calculated_score', 'DESC') ->execute() - ->fetchField(); + ->fetchColumn(); if ($this->normalize) { return TRUE; diff --git a/modules/search/search.module b/modules/search/search.module index 518272a..fd94dd7 100644 --- a/modules/search/search.module +++ b/modules/search/search.module @@ -374,7 +374,7 @@ function search_update_totals() { // Update word IDF (Inverse Document Frequency) counts for new/changed words. foreach (search_dirty() as $word => $dummy) { // Get total count - $total = db_query("SELECT SUM(score) FROM {search_index} WHERE word = :word", array(':word' => $word), array('target' => 'slave'))->fetchField(); + $total = db_query("SELECT SUM(score) FROM {search_index} WHERE word = :word", array(':word' => $word), array('target' => 'slave'))->fetchColumn(); // Apply Zipf's law to equalize the probability distribution. $total = log10(1 + 1/(max(1, $total))); db_merge('search_total') diff --git a/modules/shortcut/shortcut.admin.inc b/modules/shortcut/shortcut.admin.inc index 4c8bf53..3340caf 100644 --- a/modules/shortcut/shortcut.admin.inc +++ b/modules/shortcut/shortcut.admin.inc @@ -670,7 +670,7 @@ function shortcut_set_delete_form($form, &$form_state, $shortcut_set) { // Find out how many users are directly assigned to this shortcut set, and // make a message. - $number = db_query('SELECT COUNT(*) FROM {shortcut_set_users} WHERE set_name = :name', array(':name' => $shortcut_set->set_name))->fetchField(); + $number = db_query('SELECT COUNT(*) FROM {shortcut_set_users} WHERE set_name = :name', array(':name' => $shortcut_set->set_name))->fetchColumn(); $info = ''; if ($number) { $info .= '

    ' . format_plural($number, diff --git a/modules/shortcut/shortcut.module b/modules/shortcut/shortcut.module index 8642d9d..a0cad69 100644 --- a/modules/shortcut/shortcut.module +++ b/modules/shortcut/shortcut.module @@ -494,7 +494,7 @@ function shortcut_current_displayed_set($account = NULL) { $query->addField('s', 'set_name'); $query->join('shortcut_set_users', 'u', 's.set_name = u.set_name'); $query->condition('u.uid', $account->uid); - $shortcut_set_name = $query->execute()->fetchField(); + $shortcut_set_name = $query->execute()->fetchColumn(); if ($shortcut_set_name) { $shortcut_set = shortcut_set_load($shortcut_set_name); } @@ -548,7 +548,7 @@ function shortcut_set_get_unique_name() { // equal to one more than the current number of shortcut sets, so that if // no shortcut sets have been deleted from the database, this will // automatically give us the correct one. - $number = db_query("SELECT COUNT(*) FROM {shortcut_set}")->fetchField() + 1; + $number = db_query("SELECT COUNT(*) FROM {shortcut_set}")->fetchColumn() + 1; do { $name = shortcut_set_name($number); $number++; @@ -597,7 +597,7 @@ function shortcut_sets() { * TRUE if a shortcut set with that title exists; FALSE otherwise. */ function shortcut_set_title_exists($title) { - return (bool) db_query_range('SELECT 1 FROM {shortcut_set} WHERE title = :title', 0, 1, array(':title' => $title))->fetchField(); + return (bool) db_query_range('SELECT 1 FROM {shortcut_set} WHERE title = :title', 0, 1, array(':title' => $title))->fetchColumn(); } /** diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php index 3ce06d5..05cd338 100644 --- a/modules/simpletest/drupal_web_test_case.php +++ b/modules/simpletest/drupal_web_test_case.php @@ -1109,7 +1109,7 @@ class DrupalWebTestCase extends DrupalTestCase { $this->assertTrue(isset($role->rid), t('Created role of name: @name, id: @rid', array('@name' => $name, '@rid' => (isset($role->rid) ? $role->rid : t('-n/a-')))), t('Role')); if ($role && !empty($role->rid)) { - $count = db_query('SELECT COUNT(*) FROM {role_permission} WHERE rid = :rid', array(':rid' => $role->rid))->fetchField(); + $count = db_query('SELECT COUNT(*) FROM {role_permission} WHERE rid = :rid', array(':rid' => $role->rid))->fetchColumn(); $this->assertTrue($count == count($permissions), t('Created permissions: @perms', array('@perms' => implode(', ', $permissions))), t('Role')); return $role->rid; } @@ -1327,7 +1327,7 @@ class DrupalWebTestCase extends DrupalTestCase { // Run the profile tasks. $install_profile_module_exists = db_query("SELECT 1 FROM {system} WHERE type = 'module' AND name = :name", array( ':name' => $this->profile, - ))->fetchField(); + ))->fetchColumn(); if ($install_profile_module_exists) { module_enable(array($this->profile), FALSE); } diff --git a/modules/simpletest/simpletest.module b/modules/simpletest/simpletest.module index 80a6bc5..4857368 100644 --- a/modules/simpletest/simpletest.module +++ b/modules/simpletest/simpletest.module @@ -234,8 +234,8 @@ function _simpletest_batch_finished($success, $results, $operations, $elapsed) { * that ran. */ function simpletest_last_test_get($test_id) { - $last_prefix = db_query_range('SELECT last_prefix FROM {simpletest_test_id} WHERE test_id = :test_id', 0, 1, array(':test_id' => $test_id))->fetchField(); - $last_test_class = db_query_range('SELECT test_class FROM {simpletest} WHERE test_id = :test_id ORDER BY message_id DESC', 0, 1, array(':test_id' => $test_id))->fetchField(); + $last_prefix = db_query_range('SELECT last_prefix FROM {simpletest_test_id} WHERE test_id = :test_id', 0, 1, array(':test_id' => $test_id))->fetchColumn(); + $last_test_class = db_query_range('SELECT test_class FROM {simpletest} WHERE test_id = :test_id ORDER BY message_id DESC', 0, 1, array(':test_id' => $test_id))->fetchColumn(); return array($last_prefix, $last_test_class); } @@ -483,7 +483,7 @@ function simpletest_clean_temporary_directories() { function simpletest_clean_results_table($test_id = NULL) { if (variable_get('simpletest_clear_results', TRUE)) { if ($test_id) { - $count = db_query('SELECT COUNT(test_id) FROM {simpletest_test_id} WHERE test_id = :test_id', array(':test_id' => $test_id))->fetchField(); + $count = db_query('SELECT COUNT(test_id) FROM {simpletest_test_id} WHERE test_id = :test_id', array(':test_id' => $test_id))->fetchColumn(); db_delete('simpletest') ->condition('test_id', $test_id) @@ -493,7 +493,7 @@ function simpletest_clean_results_table($test_id = NULL) { ->execute(); } else { - $count = db_query('SELECT COUNT(test_id) FROM {simpletest_test_id}')->fetchField(); + $count = db_query('SELECT COUNT(test_id) FROM {simpletest_test_id}')->fetchColumn(); // Clear test results. db_delete('simpletest')->execute(); diff --git a/modules/simpletest/tests/actions.test b/modules/simpletest/tests/actions.test index 23587f0..dd77e58 100644 --- a/modules/simpletest/tests/actions.test +++ b/modules/simpletest/tests/actions.test @@ -58,7 +58,7 @@ class ActionsConfigurationTestCase extends DrupalWebTestCase { $this->assertRaw(t('Action %action was deleted', array('%action' => $new_action_label)), t('Make sure that we get a delete confirmation message.')); $this->drupalGet('admin/config/system/actions/manage'); $this->assertNoText($new_action_label, t("Make sure the action label does not appear on the overview page after we've deleted the action.")); - $exists = db_query('SELECT aid FROM {actions} WHERE callback = :callback', array(':callback' => 'drupal_goto_action'))->fetchField(); + $exists = db_query('SELECT aid FROM {actions} WHERE callback = :callback', array(':callback' => 'drupal_goto_action'))->fetchColumn(); $this->assertFalse($exists, t('Make sure the action is gone from the database after being deleted.')); } } diff --git a/modules/simpletest/tests/bootstrap.test b/modules/simpletest/tests/bootstrap.test index d1e9662..fccd3f2 100644 --- a/modules/simpletest/tests/bootstrap.test +++ b/modules/simpletest/tests/bootstrap.test @@ -294,29 +294,29 @@ class HookBootExitTestCase extends DrupalWebTestCase { variable_set('cache', 0); $this->drupalGet(''); $calls = 1; - $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_boot'))->fetchField(), $calls, t('hook_boot called with disabled cache.')); - $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_exit'))->fetchField(), $calls, t('hook_exit called with disabled cache.')); + $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_boot'))->fetchColumn(), $calls, t('hook_boot called with disabled cache.')); + $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_exit'))->fetchColumn(), $calls, t('hook_exit called with disabled cache.')); // Test with normal cache. Boot and exit should be called. variable_set('cache', 1); $this->drupalGet(''); $calls++; - $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_boot'))->fetchField(), $calls, t('hook_boot called with normal cache.')); - $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_exit'))->fetchField(), $calls, t('hook_exit called with normal cache.')); + $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_boot'))->fetchColumn(), $calls, t('hook_boot called with normal cache.')); + $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_exit'))->fetchColumn(), $calls, t('hook_exit called with normal cache.')); // Boot and exit should not fire since the page is cached. variable_set('page_cache_invoke_hooks', FALSE); $this->assertTrue(cache('page')->get(url('', array('absolute' => TRUE))), t('Page has been cached.')); $this->drupalGet(''); - $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_boot'))->fetchField(), $calls, t('hook_boot not called with agressive cache and a cached page.')); - $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_exit'))->fetchField(), $calls, t('hook_exit not called with agressive cache and a cached page.')); + $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_boot'))->fetchColumn(), $calls, t('hook_boot not called with agressive cache and a cached page.')); + $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_exit'))->fetchColumn(), $calls, t('hook_exit not called with agressive cache and a cached page.')); // Test with page cache cleared, boot and exit should be called. $this->assertTrue(db_delete('cache_page')->execute(), t('Page cache cleared.')); $this->drupalGet(''); $calls++; - $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_boot'))->fetchField(), $calls, t('hook_boot called with agressive cache and no cached page.')); - $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_exit'))->fetchField(), $calls, t('hook_exit called with agressive cache and no cached page.')); + $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_boot'))->fetchColumn(), $calls, t('hook_boot called with agressive cache and no cached page.')); + $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_exit'))->fetchColumn(), $calls, t('hook_exit called with agressive cache and no cached page.')); } } diff --git a/modules/simpletest/tests/database_test.module b/modules/simpletest/tests/database_test.module index 6fac319..c284722 100644 --- a/modules/simpletest/tests/database_test.module +++ b/modules/simpletest/tests/database_test.module @@ -84,7 +84,7 @@ function database_test_db_query_temporary() { $table_name = db_query_temporary('SELECT status FROM {system}', array()); drupal_json_output(array( 'table_name' => $table_name, - 'row_count' => db_select($table_name)->countQuery()->execute()->fetchField(), + 'row_count' => db_select($table_name)->countQuery()->execute()->fetchColumn(), )); exit; } diff --git a/modules/simpletest/tests/database_test.test b/modules/simpletest/tests/database_test.test index 76ca103..500fd1b 100644 --- a/modules/simpletest/tests/database_test.test +++ b/modules/simpletest/tests/database_test.test @@ -446,7 +446,7 @@ class DatabaseInsertTestCase extends DatabaseTestCase { * Test the very basic insert functionality. */ function testSimpleInsert() { - $num_records_before = db_query('SELECT COUNT(*) FROM {test}')->fetchField(); + $num_records_before = db_query('SELECT COUNT(*) FROM {test}')->fetchColumn(); $query = db_insert('test'); $query->fields(array( @@ -455,9 +455,9 @@ class DatabaseInsertTestCase extends DatabaseTestCase { )); $query->execute(); - $num_records_after = db_query('SELECT COUNT(*) FROM {test}')->fetchField(); + $num_records_after = db_query('SELECT COUNT(*) FROM {test}')->fetchColumn(); $this->assertIdentical($num_records_before + 1, (int) $num_records_after, t('Record inserts correctly.')); - $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Yoko'))->fetchField(); + $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Yoko'))->fetchColumn(); $this->assertIdentical($saved_age, '29', t('Can retrieve after inserting.')); } @@ -465,7 +465,7 @@ class DatabaseInsertTestCase extends DatabaseTestCase { * Test that we can insert multiple records in one query object. */ function testMultiInsert() { - $num_records_before = (int) db_query('SELECT COUNT(*) FROM {test}')->fetchField(); + $num_records_before = (int) db_query('SELECT COUNT(*) FROM {test}')->fetchColumn(); $query = db_insert('test'); $query->fields(array( @@ -484,13 +484,13 @@ class DatabaseInsertTestCase extends DatabaseTestCase { $query->values(array('Moe', '32')); $query->execute(); - $num_records_after = (int) db_query('SELECT COUNT(*) FROM {test}')->fetchField(); + $num_records_after = (int) db_query('SELECT COUNT(*) FROM {test}')->fetchColumn(); $this->assertIdentical($num_records_before + 3, $num_records_after, t('Record inserts correctly.')); - $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Larry'))->fetchField(); + $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Larry'))->fetchColumn(); $this->assertIdentical($saved_age, '30', t('Can retrieve after inserting.')); - $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Curly'))->fetchField(); + $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Curly'))->fetchColumn(); $this->assertIdentical($saved_age, '31', t('Can retrieve after inserting.')); - $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Moe'))->fetchField(); + $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Moe'))->fetchColumn(); $this->assertIdentical($saved_age, '32', t('Can retrieve after inserting.')); } @@ -498,7 +498,7 @@ class DatabaseInsertTestCase extends DatabaseTestCase { * Test that an insert object can be reused with new data after it executes. */ function testRepeatedInsert() { - $num_records_before = db_query('SELECT COUNT(*) FROM {test}')->fetchField(); + $num_records_before = db_query('SELECT COUNT(*) FROM {test}')->fetchColumn(); $query = db_insert('test'); @@ -519,13 +519,13 @@ class DatabaseInsertTestCase extends DatabaseTestCase { $query->values(array('Moe', '32')); $query->execute(); - $num_records_after = db_query('SELECT COUNT(*) FROM {test}')->fetchField(); + $num_records_after = db_query('SELECT COUNT(*) FROM {test}')->fetchColumn(); $this->assertIdentical((int) $num_records_before + 3, (int) $num_records_after, t('Record inserts correctly.')); - $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Larry'))->fetchField(); + $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Larry'))->fetchColumn(); $this->assertIdentical($saved_age, '30', t('Can retrieve after inserting.')); - $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Curly'))->fetchField(); + $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Curly'))->fetchColumn(); $this->assertIdentical($saved_age, '31', t('Can retrieve after inserting.')); - $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Moe'))->fetchField(); + $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Moe'))->fetchColumn(); $this->assertIdentical($saved_age, '32', t('Can retrieve after inserting.')); } @@ -541,11 +541,11 @@ class DatabaseInsertTestCase extends DatabaseTestCase { ->values(array('Curly', '31')) ->values(array('Moe', '32')) ->execute(); - $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Larry'))->fetchField(); + $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Larry'))->fetchColumn(); $this->assertIdentical($saved_age, '30', t('Can retrieve after inserting.')); - $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Curly'))->fetchField(); + $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Curly'))->fetchColumn(); $this->assertIdentical($saved_age, '31', t('Can retrieve after inserting.')); - $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Moe'))->fetchField(); + $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Moe'))->fetchColumn(); $this->assertIdentical($saved_age, '32', t('Can retrieve after inserting.')); } @@ -585,7 +585,7 @@ class DatabaseInsertTestCase extends DatabaseTestCase { ->from($query) ->execute(); - $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Meredith'))->fetchField(); + $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Meredith'))->fetchColumn(); $this->assertIdentical($saved_age, '30', t('Can retrieve after inserting.')); } } @@ -653,7 +653,7 @@ class DatabaseInsertDefaultsTestCase extends DatabaseTestCase { $schema = drupal_get_schema('test'); - $job = db_query('SELECT job FROM {test} WHERE id = :id', array(':id' => $id))->fetchField(); + $job = db_query('SELECT job FROM {test} WHERE id = :id', array(':id' => $id))->fetchColumn(); $this->assertEqual($job, $schema['fields']['job']['default'], t('Default field value is set.')); } @@ -661,7 +661,7 @@ class DatabaseInsertDefaultsTestCase extends DatabaseTestCase { * Test that no action will be preformed if no fields are specified. */ function testDefaultEmptyInsert() { - $num_records_before = (int) db_query('SELECT COUNT(*) FROM {test}')->fetchField(); + $num_records_before = (int) db_query('SELECT COUNT(*) FROM {test}')->fetchColumn(); try { $result = db_insert('test')->execute(); @@ -671,7 +671,7 @@ class DatabaseInsertDefaultsTestCase extends DatabaseTestCase { $this->pass(t('Expected exception NoFieldsException has been thrown.')); } - $num_records_after = (int) db_query('SELECT COUNT(*) FROM {test}')->fetchField(); + $num_records_after = (int) db_query('SELECT COUNT(*) FROM {test}')->fetchColumn(); $this->assertIdentical($num_records_before, $num_records_after, t('Do nothing as no fields are specified.')); } @@ -686,7 +686,7 @@ class DatabaseInsertDefaultsTestCase extends DatabaseTestCase { $schema = drupal_get_schema('test'); - $job = db_query('SELECT job FROM {test} WHERE id = :id', array(':id' => $id))->fetchField(); + $job = db_query('SELECT job FROM {test} WHERE id = :id', array(':id' => $id))->fetchColumn(); $this->assertEqual($job, $schema['fields']['job']['default'], t('Default field value is set.')); } } @@ -714,7 +714,7 @@ class DatabaseUpdateTestCase extends DatabaseTestCase { ->execute(); $this->assertIdentical($num_updated, 1, t('Updated 1 record.')); - $saved_name = db_query('SELECT name FROM {test} WHERE id = :id', array(':id' => 1))->fetchField(); + $saved_name = db_query('SELECT name FROM {test} WHERE id = :id', array(':id' => 1))->fetchColumn(); $this->assertIdentical($saved_name, 'Tiffany', t('Updated name successfully.')); } @@ -729,7 +729,7 @@ class DatabaseUpdateTestCase extends DatabaseTestCase { ->execute(); $this->assertIdentical($num_updated, 1, t('Updated 1 record.')); - $saved_age = db_query('SELECT age FROM {test_null} WHERE name = :name', array(':name' => 'Kermit'))->fetchField(); + $saved_age = db_query('SELECT age FROM {test_null} WHERE name = :name', array(':name' => 'Kermit'))->fetchColumn(); $this->assertNull($saved_age, t('Updated name successfully.')); } @@ -743,7 +743,7 @@ class DatabaseUpdateTestCase extends DatabaseTestCase { ->execute(); $this->assertIdentical($num_updated, 2, t('Updated 2 records.')); - $num_matches = db_query('SELECT COUNT(*) FROM {test} WHERE job = :job', array(':job' => 'Musician'))->fetchField(); + $num_matches = db_query('SELECT COUNT(*) FROM {test} WHERE job = :job', array(':job' => 'Musician'))->fetchColumn(); $this->assertIdentical($num_matches, '2', t('Updated fields successfully.')); } @@ -757,7 +757,7 @@ class DatabaseUpdateTestCase extends DatabaseTestCase { ->execute(); $this->assertIdentical($num_updated, 2, t('Updated 2 records.')); - $num_matches = db_query('SELECT COUNT(*) FROM {test} WHERE job = :job', array(':job' => 'Musician'))->fetchField(); + $num_matches = db_query('SELECT COUNT(*) FROM {test} WHERE job = :job', array(':job' => 'Musician'))->fetchColumn(); $this->assertIdentical($num_matches, '2', t('Updated fields successfully.')); } @@ -771,7 +771,7 @@ class DatabaseUpdateTestCase extends DatabaseTestCase { ->execute(); $this->assertIdentical($num_updated, 2, t('Updated 2 records.')); - $num_matches = db_query('SELECT COUNT(*) FROM {test} WHERE job = :job', array(':job' => 'Musician'))->fetchField(); + $num_matches = db_query('SELECT COUNT(*) FROM {test} WHERE job = :job', array(':job' => 'Musician'))->fetchColumn(); $this->assertIdentical($num_matches, '2', t('Updated fields successfully.')); } @@ -786,7 +786,7 @@ class DatabaseUpdateTestCase extends DatabaseTestCase { $num_updated = $update->execute(); $this->assertIdentical($num_updated, 1, t('Updated 1 record.')); - $num_matches = db_query('SELECT COUNT(*) FROM {test} WHERE job = :job', array(':job' => 'Musician'))->fetchField(); + $num_matches = db_query('SELECT COUNT(*) FROM {test} WHERE job = :job', array(':job' => 'Musician'))->fetchColumn(); $this->assertIdentical($num_matches, '1', t('Updated fields successfully.')); } @@ -837,7 +837,7 @@ class DatabaseUpdateComplexTestCase extends DatabaseTestCase { $num_updated = $update->execute(); $this->assertIdentical($num_updated, 2, t('Updated 2 records.')); - $num_matches = db_query('SELECT COUNT(*) FROM {test} WHERE job = :job', array(':job' => 'Musician'))->fetchField(); + $num_matches = db_query('SELECT COUNT(*) FROM {test} WHERE job = :job', array(':job' => 'Musician'))->fetchColumn(); $this->assertIdentical($num_matches, '2', t('Updated fields successfully.')); } @@ -851,7 +851,7 @@ class DatabaseUpdateComplexTestCase extends DatabaseTestCase { ->execute(); $this->assertIdentical($num_updated, 2, t('Updated 2 records.')); - $num_matches = db_query('SELECT COUNT(*) FROM {test} WHERE job = :job', array(':job' => 'Musician'))->fetchField(); + $num_matches = db_query('SELECT COUNT(*) FROM {test} WHERE job = :job', array(':job' => 'Musician'))->fetchColumn(); $this->assertIdentical($num_matches, '2', t('Updated fields successfully.')); } @@ -867,7 +867,7 @@ class DatabaseUpdateComplexTestCase extends DatabaseTestCase { ->execute(); $this->assertIdentical($num_updated, 1, t('Updated 1 record.')); - $num_matches = db_query('SELECT COUNT(*) FROM {test} WHERE job = :job', array(':job' => 'Musician'))->fetchField(); + $num_matches = db_query('SELECT COUNT(*) FROM {test} WHERE job = :job', array(':job' => 'Musician'))->fetchColumn(); $this->assertIdentical($num_matches, '1', t('Updated fields successfully.')); } @@ -881,7 +881,7 @@ class DatabaseUpdateComplexTestCase extends DatabaseTestCase { ->execute(); $this->assertIdentical($num_updated, 2, t('Updated 2 records.')); - $num_matches = db_query('SELECT COUNT(*) FROM {test} WHERE job = :job', array(':job' => 'Musician'))->fetchField(); + $num_matches = db_query('SELECT COUNT(*) FROM {test} WHERE job = :job', array(':job' => 'Musician'))->fetchColumn(); $this->assertIdentical($num_matches, '2', t('Updated fields successfully.')); } @@ -895,7 +895,7 @@ class DatabaseUpdateComplexTestCase extends DatabaseTestCase { ->execute(); $this->assertIdentical($num_updated, 1, t('Updated 1 record.')); - $num_matches = db_query('SELECT COUNT(*) FROM {test} WHERE job = :job', array(':job' => 'Musician'))->fetchField(); + $num_matches = db_query('SELECT COUNT(*) FROM {test} WHERE job = :job', array(':job' => 'Musician'))->fetchColumn(); $this->assertIdentical($num_matches, '1', t('Updated fields successfully.')); } @@ -903,7 +903,7 @@ class DatabaseUpdateComplexTestCase extends DatabaseTestCase { * Test update with expression values. */ function testUpdateExpression() { - $before_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Ringo'))->fetchField(); + $before_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Ringo'))->fetchColumn(); $GLOBALS['larry_test'] = 1; $num_updated = db_update('test') ->condition('name', 'Ringo') @@ -912,7 +912,7 @@ class DatabaseUpdateComplexTestCase extends DatabaseTestCase { ->execute(); $this->assertIdentical($num_updated, 1, t('Updated 1 record.')); - $num_matches = db_query('SELECT COUNT(*) FROM {test} WHERE job = :job', array(':job' => 'Musician'))->fetchField(); + $num_matches = db_query('SELECT COUNT(*) FROM {test} WHERE job = :job', array(':job' => 'Musician'))->fetchColumn(); $this->assertIdentical($num_matches, '1', t('Updated fields successfully.')); $person = db_query('SELECT * FROM {test} WHERE name = :name', array(':name' => 'Ringo'))->fetch(); @@ -926,14 +926,14 @@ class DatabaseUpdateComplexTestCase extends DatabaseTestCase { * Test update with only expression values. */ function testUpdateOnlyExpression() { - $before_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Ringo'))->fetchField(); + $before_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Ringo'))->fetchColumn(); $num_updated = db_update('test') ->condition('name', 'Ringo') ->expression('age', 'age + :age', array(':age' => 4)) ->execute(); $this->assertIdentical($num_updated, 1, t('Updated 1 record.')); - $after_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Ringo'))->fetchField(); + $after_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Ringo'))->fetchColumn(); $this->assertEqual($before_age + 4, $after_age, t('Age updated correctly')); } } @@ -1017,8 +1017,8 @@ class DatabaseDeleteTruncateTestCase extends DatabaseTestCase { * Confirm that we can use a subselect in a delete successfully. */ function testSubselectDelete() { - $num_records_before = db_query('SELECT COUNT(*) FROM {test_task}')->fetchField(); - $pid_to_delete = db_query("SELECT * FROM {test_task} WHERE task = 'sleep'")->fetchField(); + $num_records_before = db_query('SELECT COUNT(*) FROM {test_task}')->fetchColumn(); + $pid_to_delete = db_query("SELECT * FROM {test_task} WHERE task = 'sleep'")->fetchColumn(); $subquery = db_select('test', 't') ->fields('t', array('id')) @@ -1030,7 +1030,7 @@ class DatabaseDeleteTruncateTestCase extends DatabaseTestCase { $num_deleted = $delete->execute(); $this->assertEqual($num_deleted, 1, t("Deleted 1 record.")); - $num_records_after = db_query('SELECT COUNT(*) FROM {test_task}')->fetchField(); + $num_records_after = db_query('SELECT COUNT(*) FROM {test_task}')->fetchColumn(); $this->assertEqual($num_records_before, $num_records_after + $num_deleted, t('Deletion adds up.')); } @@ -1038,14 +1038,14 @@ class DatabaseDeleteTruncateTestCase extends DatabaseTestCase { * Confirm that we can delete a single record successfully. */ function testSimpleDelete() { - $num_records_before = db_query('SELECT COUNT(*) FROM {test}')->fetchField(); + $num_records_before = db_query('SELECT COUNT(*) FROM {test}')->fetchColumn(); $num_deleted = db_delete('test') ->condition('id', 1) ->execute(); $this->assertIdentical($num_deleted, 1, t('Deleted 1 record.')); - $num_records_after = db_query('SELECT COUNT(*) FROM {test}')->fetchField(); + $num_records_after = db_query('SELECT COUNT(*) FROM {test}')->fetchColumn(); $this->assertEqual($num_records_before, $num_records_after + $num_deleted, t('Deletion adds up.')); } @@ -1053,11 +1053,11 @@ class DatabaseDeleteTruncateTestCase extends DatabaseTestCase { * Confirm that we can truncate a whole table successfully. */ function testTruncate() { - $num_records_before = db_query("SELECT COUNT(*) FROM {test}")->fetchField(); + $num_records_before = db_query("SELECT COUNT(*) FROM {test}")->fetchColumn(); db_truncate('test')->execute(); - $num_records_after = db_query("SELECT COUNT(*) FROM {test}")->fetchField(); + $num_records_after = db_query("SELECT COUNT(*) FROM {test}")->fetchColumn(); $this->assertEqual(0, $num_records_after, t('Truncate really deletes everything.')); } } @@ -1079,7 +1079,7 @@ class DatabaseMergeTestCase extends DatabaseTestCase { * Confirm that we can merge-insert a record successfully. */ function testMergeInsert() { - $num_records_before = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField(); + $num_records_before = db_query('SELECT COUNT(*) FROM {test_people}')->fetchColumn(); $result = db_merge('test_people') ->key(array('job' => 'Presenter')) @@ -1091,7 +1091,7 @@ class DatabaseMergeTestCase extends DatabaseTestCase { $this->assertEqual($result, MergeQuery::STATUS_INSERT, t('Insert status returned.')); - $num_records_after = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField(); + $num_records_after = db_query('SELECT COUNT(*) FROM {test_people}')->fetchColumn(); $this->assertEqual($num_records_before + 1, $num_records_after, t('Merge inserted properly.')); $person = db_query('SELECT * FROM {test_people} WHERE job = :job', array(':job' => 'Presenter'))->fetch(); @@ -1104,7 +1104,7 @@ class DatabaseMergeTestCase extends DatabaseTestCase { * Confirm that we can merge-update a record successfully. */ function testMergeUpdate() { - $num_records_before = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField(); + $num_records_before = db_query('SELECT COUNT(*) FROM {test_people}')->fetchColumn(); $result = db_merge('test_people') ->key(array('job' => 'Speaker')) @@ -1116,7 +1116,7 @@ class DatabaseMergeTestCase extends DatabaseTestCase { $this->assertEqual($result, MergeQuery::STATUS_UPDATE, t('Update status returned.')); - $num_records_after = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField(); + $num_records_after = db_query('SELECT COUNT(*) FROM {test_people}')->fetchColumn(); $this->assertEqual($num_records_before, $num_records_after, t('Merge updated properly.')); $person = db_query('SELECT * FROM {test_people} WHERE job = :job', array(':job' => 'Speaker'))->fetch(); @@ -1129,7 +1129,7 @@ class DatabaseMergeTestCase extends DatabaseTestCase { * Confirm that we can merge-update a record successfully, with different insert and update. */ function testMergeUpdateExcept() { - $num_records_before = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField(); + $num_records_before = db_query('SELECT COUNT(*) FROM {test_people}')->fetchColumn(); db_merge('test_people') ->key(array('job' => 'Speaker')) @@ -1137,7 +1137,7 @@ class DatabaseMergeTestCase extends DatabaseTestCase { ->updateFields(array('name' => 'Tiffany')) ->execute(); - $num_records_after = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField(); + $num_records_after = db_query('SELECT COUNT(*) FROM {test_people}')->fetchColumn(); $this->assertEqual($num_records_before, $num_records_after, t('Merge updated properly.')); $person = db_query('SELECT * FROM {test_people} WHERE job = :job', array(':job' => 'Speaker'))->fetch(); @@ -1150,7 +1150,7 @@ class DatabaseMergeTestCase extends DatabaseTestCase { * Confirm that we can merge-update a record successfully, with alternate replacement. */ function testMergeUpdateExplicit() { - $num_records_before = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField(); + $num_records_before = db_query('SELECT COUNT(*) FROM {test_people}')->fetchColumn(); db_merge('test_people') ->key(array('job' => 'Speaker')) @@ -1163,7 +1163,7 @@ class DatabaseMergeTestCase extends DatabaseTestCase { )) ->execute(); - $num_records_after = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField(); + $num_records_after = db_query('SELECT COUNT(*) FROM {test_people}')->fetchColumn(); $this->assertEqual($num_records_before, $num_records_after, t('Merge updated properly.')); $person = db_query('SELECT * FROM {test_people} WHERE job = :job', array(':job' => 'Speaker'))->fetch(); @@ -1176,9 +1176,9 @@ class DatabaseMergeTestCase extends DatabaseTestCase { * Confirm that we can merge-update a record successfully, with expressions. */ function testMergeUpdateExpression() { - $num_records_before = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField(); + $num_records_before = db_query('SELECT COUNT(*) FROM {test_people}')->fetchColumn(); - $age_before = db_query('SELECT age FROM {test_people} WHERE job = :job', array(':job' => 'Speaker'))->fetchField(); + $age_before = db_query('SELECT age FROM {test_people} WHERE job = :job', array(':job' => 'Speaker'))->fetchColumn(); // This is a very contrived example, as I have no idea why you'd want to // change age this way, but that's beside the point. @@ -1192,7 +1192,7 @@ class DatabaseMergeTestCase extends DatabaseTestCase { ->expression('age', 'age + :age', array(':age' => 4)) ->execute(); - $num_records_after = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField(); + $num_records_after = db_query('SELECT COUNT(*) FROM {test_people}')->fetchColumn(); $this->assertEqual($num_records_before, $num_records_after, t('Merge updated properly.')); $person = db_query('SELECT * FROM {test_people} WHERE job = :job', array(':job' => 'Speaker'))->fetch(); @@ -1205,13 +1205,13 @@ class DatabaseMergeTestCase extends DatabaseTestCase { * Test that we can merge-insert without any update fields. */ function testMergeInsertWithoutUpdate() { - $num_records_before = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField(); + $num_records_before = db_query('SELECT COUNT(*) FROM {test_people}')->fetchColumn(); db_merge('test_people') ->key(array('job' => 'Presenter')) ->execute(); - $num_records_after = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField(); + $num_records_after = db_query('SELECT COUNT(*) FROM {test_people}')->fetchColumn(); $this->assertEqual($num_records_before + 1, $num_records_after, t('Merge inserted properly.')); $person = db_query('SELECT * FROM {test_people} WHERE job = :job', array(':job' => 'Presenter'))->fetch(); @@ -1224,13 +1224,13 @@ class DatabaseMergeTestCase extends DatabaseTestCase { * Confirm that we can merge-update without any update fields. */ function testMergeUpdateWithoutUpdate() { - $num_records_before = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField(); + $num_records_before = db_query('SELECT COUNT(*) FROM {test_people}')->fetchColumn(); db_merge('test_people') ->key(array('job' => 'Speaker')) ->execute(); - $num_records_after = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField(); + $num_records_after = db_query('SELECT COUNT(*) FROM {test_people}')->fetchColumn(); $this->assertEqual($num_records_before, $num_records_after, t('Merge skipped properly.')); $person = db_query('SELECT * FROM {test_people} WHERE job = :job', array(':job' => 'Speaker'))->fetch(); @@ -1243,7 +1243,7 @@ class DatabaseMergeTestCase extends DatabaseTestCase { ->insertFields(array('age' => 31)) ->execute(); - $num_records_after = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField(); + $num_records_after = db_query('SELECT COUNT(*) FROM {test_people}')->fetchColumn(); $this->assertEqual($num_records_before, $num_records_after, t('Merge skipped properly.')); $person = db_query('SELECT * FROM {test_people} WHERE job = :job', array(':job' => 'Speaker'))->fetch(); @@ -1553,7 +1553,7 @@ class DatabaseSelectTestCase extends DatabaseTestCase { // same as the chance that a deck of cards will come out in the same order // after shuffling it (in other words, nearly impossible). $number_of_items = 52; - while (db_query("SELECT MAX(id) FROM {test}")->fetchField() < $number_of_items) { + while (db_query("SELECT MAX(id) FROM {test}")->fetchColumn() < $number_of_items) { db_insert('test')->fields(array('name' => $this->randomName()))->execute(); } @@ -2051,7 +2051,7 @@ class DatabaseSelectComplexTestCase extends DatabaseTestCase { $age_field = $query->addField('test', 'age', 'age'); $query->orderBy('name'); - $count = $query->countQuery()->execute()->fetchField(); + $count = $query->countQuery()->execute()->fetchColumn(); $this->assertEqual($count, 4, t('Counted the correct number of records.')); @@ -2085,7 +2085,7 @@ class DatabaseSelectComplexTestCase extends DatabaseTestCase { $this->assertFalse(isset($orderby['name']), t('Count query correctly unsets ordering caluse.')); // Make sure that the count query works. - $count = $count->execute()->fetchField(); + $count = $count->execute()->fetchColumn(); $this->assertEqual($count, 4, t('Counted the correct number of records.')); } @@ -2102,11 +2102,11 @@ class DatabaseSelectComplexTestCase extends DatabaseTestCase { // records in the {test} table). $query = db_select('test'); $query->fields('test', array('fail')); - $this->assertEqual(4, $query->countQuery()->execute()->fetchField(), t('Count Query removed fields')); + $this->assertEqual(4, $query->countQuery()->execute()->fetchColumn(), t('Count Query removed fields')); $query = db_select('test'); $query->addExpression('fail'); - $this->assertEqual(4, $query->countQuery()->execute()->fetchField(), t('Count Query removed expressions')); + $this->assertEqual(4, $query->countQuery()->execute()->fetchColumn(), t('Count Query removed expressions')); } /** @@ -2117,7 +2117,7 @@ class DatabaseSelectComplexTestCase extends DatabaseTestCase { $task_field = $query->addField('test_task', 'task'); $query->distinct(); - $count = $query->countQuery()->execute()->fetchField(); + $count = $query->countQuery()->execute()->fetchColumn(); $this->assertEqual($count, 6, t('Counted the correct number of records.')); } @@ -2130,7 +2130,7 @@ class DatabaseSelectComplexTestCase extends DatabaseTestCase { $pid_field = $query->addField('test_task', 'pid'); $query->groupBy('pid'); - $count = $query->countQuery()->execute()->fetchField(); + $count = $query->countQuery()->execute()->fetchColumn(); $this->assertEqual($count, 3, t('Counted the correct number of records.')); @@ -2142,7 +2142,7 @@ class DatabaseSelectComplexTestCase extends DatabaseTestCase { $query->groupBy('pid_alias'); $query->orderBy('pid_alias', 'asc'); - $count = $query->countQuery()->execute()->fetchField(); + $count = $query->countQuery()->execute()->fetchColumn(); $this->assertEqual($count, 3, t('Counted the correct number of records.')); } @@ -2160,7 +2160,7 @@ class DatabaseSelectComplexTestCase extends DatabaseTestCase { $query->condition('name', 'Paul'); $query->condition(db_or()->condition('age', 26)->condition('age', 27)); - $job = $query->execute()->fetchField(); + $job = $query->execute()->fetchColumn(); $this->assertEqual($job, 'Songwriter', t('Correct data retrieved.')); } @@ -2266,7 +2266,7 @@ class DatabaseSelectPagerDefaultTestCase extends DatabaseTestCase { // information forward to the actual query on the other side of the // HTTP request. $limit = 2; - $count = db_query('SELECT COUNT(*) FROM {test}')->fetchField(); + $count = db_query('SELECT COUNT(*) FROM {test}')->fetchColumn(); $correct_number = $limit; $num_pages = floor($count / $limit); @@ -2300,7 +2300,7 @@ class DatabaseSelectPagerDefaultTestCase extends DatabaseTestCase { // information forward to the actual query on the other side of the // HTTP request. $limit = 2; - $count = db_query('SELECT COUNT(*) FROM {test_task}')->fetchField(); + $count = db_query('SELECT COUNT(*) FROM {test_task}')->fetchColumn(); $correct_number = $limit; $num_pages = floor($count / $limit); @@ -2375,7 +2375,7 @@ class DatabaseSelectPagerDefaultTestCase extends DatabaseTestCase { ->orderBy('age') ->limit(1) ->execute() - ->fetchField(); + ->fetchColumn(); $this->assertEqual($name, 'Paul', t('Pager query #1 with a specified element ID returned the correct results.')); // Setting an element smaller than the previous one @@ -2386,7 +2386,7 @@ class DatabaseSelectPagerDefaultTestCase extends DatabaseTestCase { ->orderBy('age') ->limit(1) ->execute() - ->fetchField(); + ->fetchColumn(); $this->assertEqual($name, 'George', t('Pager query #2 with a specified element ID returned the correct results.')); $name = db_select('test', 't')->extend('PagerDefault') @@ -2394,7 +2394,7 @@ class DatabaseSelectPagerDefaultTestCase extends DatabaseTestCase { ->orderBy('age') ->limit(1) ->execute() - ->fetchField(); + ->fetchColumn(); $this->assertEqual($name, 'John', t('Pager query #3 with a generated element ID returned the correct results.')); unset($_GET['page']); @@ -2746,7 +2746,7 @@ class DatabaseRegressionTestCase extends DatabaseTestCase { 'job' => 'Dancer', ))->execute(); - $from_database = db_query('SELECT name FROM {test} WHERE name = :name', array(':name' => $name))->fetchField(); + $from_database = db_query('SELECT name FROM {test} WHERE name = :name', array(':name' => $name))->fetchColumn(); $this->assertIdentical($name, $from_database, t("The database handles UTF-8 characters cleanly.")); } @@ -2979,7 +2979,7 @@ class DatabaseTemporaryQueryTestCase extends DrupalWebTestCase { * Return the number of rows of a table. */ function countTableRows($table_name) { - return db_select($table_name)->countQuery()->execute()->fetchField(); + return db_select($table_name)->countQuery()->execute()->fetchColumn(); } /** @@ -3036,7 +3036,7 @@ class DatabaseBasicSyntaxTestCase extends DatabaseTestCase { ':a4' => ' a ', ':a5' => 'test.', )); - $this->assertIdentical($result->fetchField(), 'This is a test.', t('Basic CONCAT works.')); + $this->assertIdentical($result->fetchColumn(), 'This is a test.', t('Basic CONCAT works.')); } /** @@ -3049,7 +3049,7 @@ class DatabaseBasicSyntaxTestCase extends DatabaseTestCase { ':a3' => '.', ':age' => 25, )); - $this->assertIdentical($result->fetchField(), 'The age of John is 25.', t('Field CONCAT works.')); + $this->assertIdentical($result->fetchColumn(), 'The age of John is 25.', t('Field CONCAT works.')); } /** @@ -3067,14 +3067,14 @@ class DatabaseBasicSyntaxTestCase extends DatabaseTestCase { ->condition('name', 'Ring_', 'LIKE') ->countQuery() ->execute() - ->fetchField(); + ->fetchColumn(); $this->assertIdentical($num_matches, '2', t('Found 2 records.')); // Match only "Ring_" using a LIKE expression with no wildcards. $num_matches = db_select('test', 't') ->condition('name', db_like('Ring_'), 'LIKE') ->countQuery() ->execute() - ->fetchField(); + ->fetchColumn(); $this->assertIdentical($num_matches, '1', t('Found 1 record.')); } @@ -3098,14 +3098,14 @@ class DatabaseBasicSyntaxTestCase extends DatabaseTestCase { ->condition('name', 'abc%\\\\_', 'LIKE') ->countQuery() ->execute() - ->fetchField(); + ->fetchColumn(); $this->assertIdentical($num_matches, '2', t('Found 2 records.')); // Match only the former using a LIKE expression with no wildcards. $num_matches = db_select('test', 't') ->condition('name', db_like('abc%\_'), 'LIKE') ->countQuery() ->execute() - ->fetchField(); + ->fetchColumn(); $this->assertIdentical($num_matches, '1', t('Found 1 record.')); } } @@ -3153,7 +3153,7 @@ class DatabaseInvalidDataTestCase extends DatabaseTestCase { } catch (Exception $e) { // Check if the first record was inserted. - $name = db_query('SELECT name FROM {test} WHERE age = :age', array(':age' => 63))->fetchField(); + $name = db_query('SELECT name FROM {test} WHERE age = :age', array(':age' => 63))->fetchColumn(); if ($name == 'Elvis') { if (!Database::getConnection()->supportsTransactions()) { @@ -3363,9 +3363,9 @@ class DatabaseTransactionTestCase extends DatabaseTestCase { // Neither of the rows we inserted in the two transaction layers // should be present in the tables post-rollback. - $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DavidB'))->fetchField(); + $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DavidB'))->fetchColumn(); $this->assertNotIdentical($saved_age, '24', t('Cannot retrieve DavidB row after commit.')); - $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DanielB'))->fetchField(); + $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DanielB'))->fetchColumn(); $this->assertNotIdentical($saved_age, '19', t('Cannot retrieve DanielB row after commit.')); } catch (Exception $e) { @@ -3389,9 +3389,9 @@ class DatabaseTransactionTestCase extends DatabaseTestCase { // Because our current database claims to not support transactions, // the inserted rows should be present despite the attempt to roll back. - $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DavidB'))->fetchField(); + $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DavidB'))->fetchColumn(); $this->assertIdentical($saved_age, '24', t('DavidB not rolled back, since transactions are not supported.')); - $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DanielB'))->fetchField(); + $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DanielB'))->fetchColumn(); $this->assertIdentical($saved_age, '19', t('DanielB not rolled back, since transactions are not supported.')); } catch (Exception $e) { @@ -3411,9 +3411,9 @@ class DatabaseTransactionTestCase extends DatabaseTestCase { $this->transactionOuterLayer('A'); // Because we committed, both of the inserted rows should be present. - $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DavidA'))->fetchField(); + $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DavidA'))->fetchColumn(); $this->assertIdentical($saved_age, '24', t('Can retrieve DavidA row after commit.')); - $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DanielA'))->fetchField(); + $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DanielA'))->fetchColumn(); $this->assertIdentical($saved_age, '19', t('Can retrieve DanielA row after commit.')); } catch (Exception $e) { @@ -3430,12 +3430,12 @@ class DatabaseTransactionTestCase extends DatabaseTestCase { $this->transactionOuterLayer('D', FALSE, TRUE); // Because we committed, the inserted rows should both be present. - $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DavidD'))->fetchField(); + $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DavidD'))->fetchColumn(); $this->assertIdentical($saved_age, '24', t('Can retrieve DavidD row after commit.')); - $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DanielD'))->fetchField(); + $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DanielD'))->fetchColumn(); $this->assertIdentical($saved_age, '19', t('Can retrieve DanielD row after commit.')); // The created table should also exist. - $count = db_query('SELECT COUNT(id) FROM {database_test_1}')->fetchField(); + $count = db_query('SELECT COUNT(id) FROM {database_test_1}')->fetchColumn(); $this->assertIdentical($count, '0', t('Table was successfully created inside a transaction.')); } catch (Exception $e) { @@ -3447,9 +3447,9 @@ class DatabaseTransactionTestCase extends DatabaseTestCase { $this->transactionOuterLayer('E', TRUE, TRUE); // Because we rolled back, the inserted rows shouldn't be present. - $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DavidE'))->fetchField(); + $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DavidE'))->fetchColumn(); $this->assertNotIdentical($saved_age, '24', t('Cannot retrieve DavidE row after rollback.')); - $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DanielE'))->fetchField(); + $saved_age = db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DanielE'))->fetchColumn(); $this->assertNotIdentical($saved_age, '19', t('Cannot retrieve DanielE row after rollback.')); } catch (Exception $e) { @@ -3489,7 +3489,7 @@ class DatabaseTransactionTestCase extends DatabaseTestCase { if (!isset($message)) { $message = t('Row %name is present.', array('%name' => $name)); } - $present = (boolean) db_query('SELECT 1 FROM {test} WHERE name = :name', array(':name' => $name))->fetchField(); + $present = (boolean) db_query('SELECT 1 FROM {test} WHERE name = :name', array(':name' => $name))->fetchColumn(); return $this->assertTrue($present, $message); } @@ -3505,7 +3505,7 @@ class DatabaseTransactionTestCase extends DatabaseTestCase { if (!isset($message)) { $message = t('Row %name is absent.', array('%name' => $name)); } - $present = (boolean) db_query('SELECT 1 FROM {test} WHERE name = :name', array(':name' => $name))->fetchField(); + $present = (boolean) db_query('SELECT 1 FROM {test} WHERE name = :name', array(':name' => $name))->fetchColumn(); return $this->assertFalse($present, $message); } diff --git a/modules/simpletest/tests/file.test b/modules/simpletest/tests/file.test index 3633bae..f8d41bb 100644 --- a/modules/simpletest/tests/file.test +++ b/modules/simpletest/tests/file.test @@ -602,7 +602,7 @@ class FileSaveUploadTest extends FileHookTestCase { $this->phpfile = current($this->drupalGetTestFiles('php')); $this->assertTrue(is_file($this->phpfile->uri), t("The PHP file we're going to upload exists.")); - $this->maxFidBefore = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField(); + $this->maxFidBefore = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchColumn(); // Upload with replace to guarantee there's something there. $edit = array( @@ -623,7 +623,7 @@ class FileSaveUploadTest extends FileHookTestCase { * Test the file_save_upload() function. */ function testNormal() { - $max_fid_after = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField(); + $max_fid_after = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchColumn(); $this->assertTrue($max_fid_after > $this->maxFidBefore, t('A new file was created.')); $file1 = file_load($max_fid_after); $this->assertTrue($file1, t('Loaded the file.')); @@ -634,13 +634,13 @@ class FileSaveUploadTest extends FileHookTestCase { file_test_reset(); // Upload a second file. - $max_fid_before = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField(); + $max_fid_before = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchColumn(); $image2 = current($this->drupalGetTestFiles('image')); $edit = array('files[file_test_upload]' => drupal_realpath($image2->uri)); $this->drupalPost('file-test/upload', $edit, t('Submit')); $this->assertResponse(200, t('Received a 200 response for posted test file.')); $this->assertRaw(t('You WIN!')); - $max_fid_after = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField(); + $max_fid_after = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchColumn(); // Check that the correct hooks were called. $this->assertFileHooksCalled(array('validate', 'insert')); @@ -2118,7 +2118,7 @@ class FileUsageTest extends FileTestCase { ->fields('f', array('count')) ->condition('f.fid', $file->fid) ->execute() - ->fetchField(); + ->fetchColumn(); $this->assertEqual(2, $count, t('The count was decremented correctly.')); // Multiple decrement and removal. @@ -2127,7 +2127,7 @@ class FileUsageTest extends FileTestCase { ->fields('f', array('count')) ->condition('f.fid', $file->fid) ->execute() - ->fetchField(); + ->fetchColumn(); $this->assertIdentical(FALSE, $count, t('The count was removed entirely when empty.')); // Non-existent decrement. @@ -2136,7 +2136,7 @@ class FileUsageTest extends FileTestCase { ->fields('f', array('count')) ->condition('f.fid', $file->fid) ->execute() - ->fetchField(); + ->fetchColumn(); $this->assertIdentical(FALSE, $count, t('Decrementing non-exist record complete.')); } } diff --git a/modules/simpletest/tests/menu.test b/modules/simpletest/tests/menu.test index 3c0952b..168e485 100644 --- a/modules/simpletest/tests/menu.test +++ b/modules/simpletest/tests/menu.test @@ -255,7 +255,7 @@ class MenuRouterTestCase extends DrupalWebTestCase { $this->drupalLogin($admin_user); $sql = "SELECT menu_name FROM {menu_links} WHERE router_path = 'menu_name_test'"; - $name = db_query($sql)->fetchField(); + $name = db_query($sql)->fetchColumn(); $this->assertEqual($name, 'original', t('Menu name is "original".')); // Change the menu_name parameter in menu_test.module, then force a menu @@ -264,7 +264,7 @@ class MenuRouterTestCase extends DrupalWebTestCase { menu_rebuild(); $sql = "SELECT menu_name FROM {menu_links} WHERE router_path = 'menu_name_test'"; - $name = db_query($sql)->fetchField(); + $name = db_query($sql)->fetchColumn(); $this->assertEqual($name, 'changed', t('Menu name was successfully changed after rebuild.')); } @@ -763,14 +763,14 @@ class MenuRebuildTestCase extends DrupalWebTestCase { */ function testMenuRebuildByVariable() { // Check if 'admin' path exists. - $admin_exists = db_query('SELECT path from {menu_router} WHERE path = :path', array(':path' => 'admin'))->fetchField(); + $admin_exists = db_query('SELECT path from {menu_router} WHERE path = :path', array(':path' => 'admin'))->fetchColumn(); $this->assertEqual($admin_exists, 'admin', t("The path 'admin/' exists prior to deleting.")); // Delete the path item 'admin', and test that the path doesn't exist in the database. $delete = db_delete('menu_router') ->condition('path', 'admin') ->execute(); - $admin_exists = db_query('SELECT path from {menu_router} WHERE path = :path', array(':path' => 'admin'))->fetchField(); + $admin_exists = db_query('SELECT path from {menu_router} WHERE path = :path', array(':path' => 'admin'))->fetchColumn(); $this->assertFalse($admin_exists, t("The path 'admin/' has been deleted and doesn't exist in the database.")); // Now we enable the rebuild variable and trigger menu_execute_active_handler() @@ -778,7 +778,7 @@ class MenuRebuildTestCase extends DrupalWebTestCase { variable_set('menu_rebuild_needed', TRUE); // menu_execute_active_handler() should trigger the rebuild. $this->drupalGet(''); - $admin_exists = db_query('SELECT path from {menu_router} WHERE path = :path', array(':path' => 'admin'))->fetchField(); + $admin_exists = db_query('SELECT path from {menu_router} WHERE path = :path', array(':path' => 'admin'))->fetchColumn(); $this->assertEqual($admin_exists, 'admin', t("The menu has been rebuilt, the path 'admin' now exists again.")); } diff --git a/modules/simpletest/tests/module.test b/modules/simpletest/tests/module.test index c9601c9..16ab45b 100644 --- a/modules/simpletest/tests/module.test +++ b/modules/simpletest/tests/module.test @@ -298,7 +298,7 @@ class ModuleUninstallTestCase extends DrupalWebTestCase { drupal_uninstall_modules(array('module_test')); // Are the perms defined by module_test removed from {role_permission}. - $count = db_query("SELECT COUNT(rid) FROM {role_permission} WHERE permission = :perm", array(':perm' => 'module_test perm'))->fetchField(); + $count = db_query("SELECT COUNT(rid) FROM {role_permission} WHERE permission = :perm", array(':perm' => 'module_test perm'))->fetchColumn(); $this->assertEqual(0, $count, t('Permissions were all removed.')); } } diff --git a/modules/simpletest/tests/path.test b/modules/simpletest/tests/path.test index 4701b56..52cf458 100644 --- a/modules/simpletest/tests/path.test +++ b/modules/simpletest/tests/path.test @@ -180,7 +180,7 @@ class UrlAlterFunctionalTest extends DrupalWebTestCase { // level and for a specific existing forum. $this->assertUrlInboundAlter('community', 'forum'); $this->assertUrlOutboundAlter('forum', 'community'); - $forum_vid = db_query("SELECT vid FROM {taxonomy_vocabulary} WHERE module = 'forum'")->fetchField(); + $forum_vid = db_query("SELECT vid FROM {taxonomy_vocabulary} WHERE module = 'forum'")->fetchColumn(); $tid = db_insert('taxonomy_term_data') ->fields(array( 'name' => $this->randomName(), diff --git a/modules/simpletest/tests/registry.test b/modules/simpletest/tests/registry.test index bcd8d4e..8d9b76b 100644 --- a/modules/simpletest/tests/registry.test +++ b/modules/simpletest/tests/registry.test @@ -23,7 +23,7 @@ class RegistryParseFileTestCase extends DrupalWebTestCase { function testRegistryParseFile() { _registry_parse_file($this->fileName, $this->getFileContents()); foreach (array('className', 'interfaceName') as $resource) { - $foundName = db_query('SELECT name FROM {registry} WHERE name = :name', array(':name' => $this->$resource))->fetchField(); + $foundName = db_query('SELECT name FROM {registry} WHERE name = :name', array(':name' => $this->$resource))->fetchColumn(); $this->assertTrue($this->$resource == $foundName, t('Resource "@resource" found.', array('@resource' => $this->$resource))); } } @@ -101,11 +101,11 @@ class RegistryParseFilesTestCase extends DrupalWebTestCase { foreach ($this->fileTypes as $fileType) { // Test that we have all the right resources. foreach (array('className', 'interfaceName') as $resource) { - $foundName = db_query('SELECT name FROM {registry} WHERE name = :name', array(':name' => $this->$fileType->$resource))->fetchField(); + $foundName = db_query('SELECT name FROM {registry} WHERE name = :name', array(':name' => $this->$fileType->$resource))->fetchColumn(); $this->assertTrue($this->$fileType->$resource == $foundName, t('Resource "@resource" found.', array('@resource' => $this->$fileType->$resource))); } // Test that we have the right hash. - $hash = db_query('SELECT hash FROM {registry_file} WHERE filename = :filename', array(':filename' => $this->$fileType->fileName))->fetchField(); + $hash = db_query('SELECT hash FROM {registry_file} WHERE filename = :filename', array(':filename' => $this->$fileType->fileName))->fetchColumn(); $this->assertTrue(hash('sha256', $this->$fileType->contents) == $hash, t('sha-256 for "@filename" matched.' . $fileType . $hash, array('@filename' => $this->$fileType->fileName))); } } diff --git a/modules/simpletest/tests/schema.test b/modules/simpletest/tests/schema.test index 8945117..9a4be28 100644 --- a/modules/simpletest/tests/schema.test +++ b/modules/simpletest/tests/schema.test @@ -87,7 +87,7 @@ class SchemaTestCase extends DrupalWebTestCase { $this->assertTrue($this->tryInsert('test_table2'), t('Insert into the new table succeeded.')); // We should have successfully inserted exactly two rows. - $count = db_query('SELECT COUNT(*) FROM {test_table2}')->fetchField(); + $count = db_query('SELECT COUNT(*) FROM {test_table2}')->fetchColumn(); $this->assertEqual($count, 2, t('Two fields were successfully inserted.')); // Try to drop the table. @@ -109,12 +109,12 @@ class SchemaTestCase extends DrupalWebTestCase { $this->checkSchemaComment('Changed column description.', 'test_table', 'test_serial'); $this->assertTrue($this->tryInsert(), t('Insert with a serial succeeded.')); - $max1 = db_query('SELECT MAX(test_serial) FROM {test_table}')->fetchField(); + $max1 = db_query('SELECT MAX(test_serial) FROM {test_table}')->fetchColumn(); $this->assertTrue($this->tryInsert(), t('Insert with a serial succeeded.')); - $max2 = db_query('SELECT MAX(test_serial) FROM {test_table}')->fetchField(); + $max2 = db_query('SELECT MAX(test_serial) FROM {test_table}')->fetchColumn(); $this->assertTrue($max2 > $max1, t('The serial is monotone.')); - $count = db_query('SELECT COUNT(*) FROM {test_table}')->fetchField(); + $count = db_query('SELECT COUNT(*) FROM {test_table}')->fetchColumn(); $this->assertEqual($count, 2, t('There were two rows.')); // Use database specific data type and ensure that table is created. @@ -361,7 +361,7 @@ class SchemaTestCase extends DrupalWebTestCase { ->condition($field_name, $field_spec['initial'], '<>') ->countQuery() ->execute() - ->fetchField(); + ->fetchColumn(); $this->assertEqual($count, 0, t('Initial values filled out.')); } @@ -375,7 +375,7 @@ class SchemaTestCase extends DrupalWebTestCase { ->fields($table_name, array($field_name)) ->condition('serial_column', $id) ->execute() - ->fetchField(); + ->fetchColumn(); $this->assertEqual($field_value, $field_spec['default'], t('Default value registered.')); } diff --git a/modules/simpletest/tests/session.test b/modules/simpletest/tests/session.test index bc72e5c..4c7df39 100644 --- a/modules/simpletest/tests/session.test +++ b/modules/simpletest/tests/session.test @@ -502,7 +502,7 @@ class SessionHttpsTestCase extends DrupalWebTestCase { ':sid' => $sid, ':ssid' => $ssid, ); - return $this->assertTrue(db_query('SELECT timestamp FROM {sessions} WHERE sid = :sid AND ssid = :ssid', $args)->fetchField(), $assertion_text); + return $this->assertTrue(db_query('SELECT timestamp FROM {sessions} WHERE sid = :sid AND ssid = :ssid', $args)->fetchColumn(), $assertion_text); } /** diff --git a/modules/simpletest/tests/taxonomy_test.module b/modules/simpletest/tests/taxonomy_test.module index aae13a2..fda5bd7 100644 --- a/modules/simpletest/tests/taxonomy_test.module +++ b/modules/simpletest/tests/taxonomy_test.module @@ -77,5 +77,5 @@ function taxonomy_test_get_antonym($tid) { ->fields('ta', array('name')) ->condition('tid', $tid) ->execute() - ->fetchField(); + ->fetchColumn(); } diff --git a/modules/statistics/statistics.module b/modules/statistics/statistics.module index 69e06f3..24bd62a 100644 --- a/modules/statistics/statistics.module +++ b/modules/statistics/statistics.module @@ -423,5 +423,5 @@ function statistics_ranking() { * Implements hook_update_index(). */ function statistics_update_index() { - variable_set('node_cron_views_scale', 1.0 / max(1, db_query('SELECT MAX(totalcount) FROM {node_counter}')->fetchField())); + variable_set('node_cron_views_scale', 1.0 / max(1, db_query('SELECT MAX(totalcount) FROM {node_counter}')->fetchColumn())); } diff --git a/modules/statistics/statistics.test b/modules/statistics/statistics.test index 126828f..d11b136 100644 --- a/modules/statistics/statistics.test +++ b/modules/statistics/statistics.test @@ -241,7 +241,7 @@ class StatisticsBlockVisitorsTestCase extends StatisticsTestCase { $edit = array(); $edit['ip'] = $test_ip_address; $this->drupalPost('admin/config/people/ip-blocking', $edit, t('Add')); - $ip = db_query("SELECT iid from {blocked_ips} WHERE ip = :ip", array(':ip' => $edit['ip']))->fetchField(); + $ip = db_query("SELECT iid from {blocked_ips} WHERE ip = :ip", array(':ip' => $edit['ip']))->fetchColumn(); $this->assertNotEqual($ip, FALSE, t('IP address found in database')); $this->assertRaw(t('The IP address %ip has been blocked.', array('%ip' => $edit['ip'])), t('IP address was blocked.')); @@ -394,7 +394,7 @@ class StatisticsAdminTestCase extends DrupalWebTestCase { ->fields('nc', array('daycount')) ->condition('nid', $this->test_node->nid, '=') ->execute() - ->fetchField(); + ->fetchColumn(); $this->assertFalse($result, t('Daycounter is zero.')); } } diff --git a/modules/system/system.admin.inc b/modules/system/system.admin.inc index 6824f19..821b0ad 100644 --- a/modules/system/system.admin.inc +++ b/modules/system/system.admin.inc @@ -1394,7 +1394,7 @@ function system_ip_blocking_form($form, $form_state, $default_ip) { function system_ip_blocking_form_validate($form, &$form_state) { $ip = trim($form_state['values']['ip']); - if (db_query("SELECT * FROM {blocked_ips} WHERE ip = :ip", array(':ip' => $ip))->fetchField()) { + if (db_query("SELECT * FROM {blocked_ips} WHERE ip = :ip", array(':ip' => $ip))->fetchColumn()) { form_set_error('ip', t('This IP address is already blocked.')); } elseif ($ip == ip_address()) { @@ -2920,7 +2920,7 @@ function system_actions_manage() { } $row = array(); - $instances_present = db_query("SELECT aid FROM {actions} WHERE parameters <> ''")->fetchField(); + $instances_present = db_query("SELECT aid FROM {actions} WHERE parameters <> ''")->fetchColumn(); $header = array( array('data' => t('Action type'), 'field' => 'type'), array('data' => t('Label'), 'field' => 'label'), diff --git a/modules/system/system.api.php b/modules/system/system.api.php index fc7b737..28ba8ea 100644 --- a/modules/system/system.api.php +++ b/modules/system/system.api.php @@ -1326,7 +1326,7 @@ function hook_menu_link_insert($link) { */ function hook_menu_link_update($link) { // If the parent menu has changed, update our record. - $menu_name = db_query("SELECT menu_name FROM {menu_example} WHERE mlid = :mlid", array(':mlid' => $link['mlid']))->fetchField(); + $menu_name = db_query("SELECT menu_name FROM {menu_example} WHERE mlid = :mlid", array(':mlid' => $link['mlid']))->fetchColumn(); if ($menu_name != $link['menu_name']) { db_update('menu_example') ->fields(array('menu_name' => $link['menu_name'])) @@ -3182,7 +3182,7 @@ function hook_update_N(&$sandbox) { $sandbox['progress'] = 0; $sandbox['current_uid'] = 0; // We'll -1 to disregard the uid 0... - $sandbox['max'] = db_query('SELECT COUNT(DISTINCT uid) FROM {users}')->fetchField() - 1; + $sandbox['max'] = db_query('SELECT COUNT(DISTINCT uid) FROM {users}')->fetchColumn() - 1; } $users = db_select('users', 'u') diff --git a/modules/system/system.module b/modules/system/system.module index cfab0a9..de1d978 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -3872,7 +3872,7 @@ function system_date_format_save($date_format, $dfid = 0) { foreach ($date_format['locales'] as $langcode) { // Only proceed if language is enabled. if (isset($languages[$langcode])) { - $is_existing = (bool) db_query_range('SELECT 1 FROM {date_format_locale} WHERE type = :type AND language = :language', 0, 1, array(':type' => $date_format['type'], ':language' => $langcode))->fetchField(); + $is_existing = (bool) db_query_range('SELECT 1 FROM {date_format_locale} WHERE type = :type AND language = :language', 0, 1, array(':type' => $date_format['type'], ':language' => $langcode))->fetchColumn(); if (!$is_existing) { $locale_format['language'] = $langcode; drupal_write_record('date_format_locale', $locale_format); diff --git a/modules/system/system.queue.inc b/modules/system/system.queue.inc index 00d3940..6dac012 100644 --- a/modules/system/system.queue.inc +++ b/modules/system/system.queue.inc @@ -229,7 +229,7 @@ class SystemQueue implements DrupalReliableQueueInterface { } public function numberOfItems() { - return db_query('SELECT COUNT(item_id) FROM {queue} WHERE name = :name', array(':name' => $this->name))->fetchField(); + return db_query('SELECT COUNT(item_id) FROM {queue} WHERE name = :name', array(':name' => $this->name))->fetchColumn(); } public function claimItem($lease_time = 30) { diff --git a/modules/system/system.test b/modules/system/system.test index 846653b..620e4a8 100644 --- a/modules/system/system.test +++ b/modules/system/system.test @@ -121,7 +121,7 @@ class ModuleTestCase extends DrupalWebTestCase { ->condition('link', $link) ->countQuery() ->execute() - ->fetchField(); + ->fetchColumn(); $this->assertTrue($count > 0, t('watchdog table contains @count rows for @message', array('@count' => $count, '@message' => $message))); } } @@ -639,7 +639,7 @@ class IPAddressBlockingTestCase extends DrupalWebTestCase { $edit = array(); $edit['ip'] = '192.168.1.1'; $this->drupalPost('admin/config/people/ip-blocking', $edit, t('Add')); - $ip = db_query("SELECT iid from {blocked_ips} WHERE ip = :ip", array(':ip' => $edit['ip']))->fetchField(); + $ip = db_query("SELECT iid from {blocked_ips} WHERE ip = :ip", array(':ip' => $edit['ip']))->fetchColumn(); $this->assertTrue($ip, t('IP address found in database.')); $this->assertRaw(t('The IP address %ip has been blocked.', array('%ip' => $edit['ip'])), t('IP address was blocked.')); @@ -670,7 +670,7 @@ class IPAddressBlockingTestCase extends DrupalWebTestCase { // Pass an IP address as a URL parameter and submit it. $submit_ip = '1.2.3.4'; $this->drupalPost('admin/config/people/ip-blocking/' . $submit_ip, NULL, t('Add')); - $ip = db_query("SELECT iid from {blocked_ips} WHERE ip = :ip", array(':ip' => $submit_ip))->fetchField(); + $ip = db_query("SELECT iid from {blocked_ips} WHERE ip = :ip", array(':ip' => $submit_ip))->fetchColumn(); $this->assertTrue($ip, t('IP address found in database')); $this->assertRaw(t('The IP address %ip has been blocked.', array('%ip' => $submit_ip)), t('IP address was blocked.')); @@ -1202,7 +1202,7 @@ class DateTimeFunctionalTest extends DrupalWebTestCase { ->condition('type', 'short') ->condition('format', 'dmYHis') ->execute() - ->fetchField(); + ->fetchColumn(); $this->verbose($format); $this->assertEqual('dmYHis', $format, 'Unlocalized date format resides in general table.'); @@ -1211,7 +1211,7 @@ class DateTimeFunctionalTest extends DrupalWebTestCase { ->condition('type', 'short') ->condition('format', 'dmYHis') ->execute() - ->fetchField(); + ->fetchColumn(); $this->assertFalse($format, 'Unlocalized date format resides not in localized table.'); // Enable German language @@ -1232,7 +1232,7 @@ class DateTimeFunctionalTest extends DrupalWebTestCase { ->condition('format', 'YMDHis') ->condition('language', 'de') ->execute() - ->fetchField(); + ->fetchColumn(); $this->assertEqual('YMDHis', $format, 'Localized date format resides in localized table.'); $format = db_select('date_formats', 'df') @@ -1240,7 +1240,7 @@ class DateTimeFunctionalTest extends DrupalWebTestCase { ->condition('type', 'short') ->condition('format', 'YMDHis') ->execute() - ->fetchField(); + ->fetchColumn(); $this->assertEqual('YMDHis', $format, 'Localized date format resides in general table too.'); $format = db_select('date_format_locale', 'dfl') @@ -2065,7 +2065,7 @@ class SystemInfoAlterTestCase extends DrupalWebTestCase { * Array of info, or FALSE if the record is not found. */ function getSystemInfo($name, $type) { - $raw_info = db_query("SELECT info FROM {system} WHERE name = :name AND type = :type", array(':name' => $name, ':type' => $type))->fetchField(); + $raw_info = db_query("SELECT info FROM {system} WHERE name = :name AND type = :type", array(':name' => $name, ':type' => $type))->fetchColumn(); return $raw_info ? unserialize($raw_info) : FALSE; } } diff --git a/modules/taxonomy/taxonomy.test b/modules/taxonomy/taxonomy.test index 9a89b9c..e59760d 100644 --- a/modules/taxonomy/taxonomy.test +++ b/modules/taxonomy/taxonomy.test @@ -34,7 +34,7 @@ class TaxonomyWebTestCase extends DrupalWebTestCase { $term->name = $this->randomName(); $term->description = $this->randomName(); // Use the first available text format. - $term->format = db_query_range('SELECT format FROM {filter_format}', 0, 1)->fetchField(); + $term->format = db_query_range('SELECT format FROM {filter_format}', 0, 1)->fetchColumn(); $term->vid = $vocabulary->vid; taxonomy_term_save($term); return $term; @@ -228,7 +228,7 @@ class TaxonomyVocabularyUnitTest extends TaxonomyWebTestCase { } // Assert that there are no terms left. - $this->assertEqual(0, db_query('SELECT COUNT(*) FROM {taxonomy_term_data}')->fetchField()); + $this->assertEqual(0, db_query('SELECT COUNT(*) FROM {taxonomy_term_data}')->fetchColumn()); // Create a new vocabulary and add a few terms to it. $vocabulary = $this->createVocabulary(); @@ -244,12 +244,12 @@ class TaxonomyVocabularyUnitTest extends TaxonomyWebTestCase { taxonomy_term_save($terms[4]); // Assert that there are now 5 terms. - $this->assertEqual(5, db_query('SELECT COUNT(*) FROM {taxonomy_term_data}')->fetchField()); + $this->assertEqual(5, db_query('SELECT COUNT(*) FROM {taxonomy_term_data}')->fetchColumn()); taxonomy_vocabulary_delete($vocabulary->vid); // Assert that there are no terms left. - $this->assertEqual(0, db_query('SELECT COUNT(*) FROM {taxonomy_term_data}')->fetchField()); + $this->assertEqual(0, db_query('SELECT COUNT(*) FROM {taxonomy_term_data}')->fetchColumn()); } /** @@ -941,7 +941,7 @@ class TaxonomyHooksTestCase extends TaxonomyWebTestCase { // Delete the term. taxonomy_term_delete($term->tid); - $antonym = db_query('SELECT tid FROM {taxonomy_term_antonym} WHERE tid = :tid', array(':tid' => $term->tid))->fetchField(); + $antonym = db_query('SELECT tid FROM {taxonomy_term_antonym} WHERE tid = :tid', array(':tid' => $term->tid))->fetchColumn(); $this->assertFalse($antonym, t('The antonym were deleted from the database.')); } } diff --git a/modules/taxonomy/taxonomy.tokens.inc b/modules/taxonomy/taxonomy.tokens.inc index f8ae457..3f2d986 100644 --- a/modules/taxonomy/taxonomy.tokens.inc +++ b/modules/taxonomy/taxonomy.tokens.inc @@ -118,7 +118,7 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options = $query = db_select('taxonomy_index'); $query->condition('tid', $term->tid); $query->addTag('term_node_count'); - $count = $query->countQuery()->execute()->fetchField(); + $count = $query->countQuery()->execute()->fetchColumn(); $replacements[$original] = $count; break; @@ -168,7 +168,7 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options = $query = db_select('taxonomy_term_data'); $query->condition('vid', $vocabulary->vid); $query->addTag('vocabulary_term_count'); - $count = $query->countQuery()->execute()->fetchField(); + $count = $query->countQuery()->execute()->fetchColumn(); $replacements[$original] = $count; break; @@ -178,7 +178,7 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options = $query->leftJoin('taxonomy_term_data', 'td', 'ti.tid = td.tid'); $query->condition('td.vid', $vocabulary->vid); $query->addTag('vocabulary_node_count'); - $count = $query->execute()->fetchField(); + $count = $query->execute()->fetchColumn(); $replacements[$original] = $count; break; } diff --git a/modules/tracker/tracker.install b/modules/tracker/tracker.install index cfe8dc7..1f69ffb 100644 --- a/modules/tracker/tracker.install +++ b/modules/tracker/tracker.install @@ -12,7 +12,7 @@ function tracker_uninstall() { * Implements hook_enable(). */ function tracker_enable() { - $max_nid = db_query('SELECT MAX(nid) FROM {node}')->fetchField(); + $max_nid = db_query('SELECT MAX(nid) FROM {node}')->fetchColumn(); if ($max_nid != 0) { variable_set('tracker_index_nid', $max_nid); // To avoid timing out while attempting to do a complete indexing, we diff --git a/modules/tracker/tracker.module b/modules/tracker/tracker.module index 227cf72..0403d46 100644 --- a/modules/tracker/tracker.module +++ b/modules/tracker/tracker.module @@ -276,7 +276,7 @@ function _tracker_add($nid, $uid, $changed) { * is the greatest. */ function _tracker_calculate_changed($nid) { - $changed = db_query('SELECT changed FROM {node} WHERE nid = :nid', array(':nid' => $nid), array('target' => 'slave'))->fetchField(); + $changed = db_query('SELECT changed FROM {node} WHERE nid = :nid', array(':nid' => $nid), array('target' => 'slave'))->fetchColumn(); $latest_comment = db_query_range('SELECT cid, changed FROM {comment} WHERE nid = :nid AND status = :status ORDER BY changed DESC', 0, 1, array( ':nid' => $nid, ':status' => COMMENT_PUBLISHED, @@ -316,7 +316,7 @@ function _tracker_remove($nid, $uid = NULL, $changed = NULL) { ':nid' => $nid, ':uid' => $uid, ':status' => COMMENT_PUBLISHED, - ))->fetchField(); + ))->fetchColumn(); } // If we haven't found a reason to keep the user's subscription, delete it. diff --git a/modules/translation/translation.module b/modules/translation/translation.module index 697929f..b8ff044 100644 --- a/modules/translation/translation.module +++ b/modules/translation/translation.module @@ -407,7 +407,7 @@ function translation_remove_from_set($node) { 'tnid' => 0, 'translate' => 0, )); - if (db_query('SELECT COUNT(*) FROM {node} WHERE tnid = :tnid', array(':tnid' => $node->tnid))->fetchField() == 1) { + if (db_query('SELECT COUNT(*) FROM {node} WHERE tnid = :tnid', array(':tnid' => $node->tnid))->fetchColumn() == 1) { // There is only one node left in the set: remove the set altogether. $query ->condition('tnid', $node->tnid) @@ -421,7 +421,7 @@ function translation_remove_from_set($node) { // If the node being removed was the source of the translation set, // we pick a new source - preferably one that is up to date. if ($node->tnid == $node->nid) { - $new_tnid = db_query('SELECT nid FROM {node} WHERE tnid = :tnid ORDER BY translate ASC, nid ASC', array(':tnid' => $node->tnid))->fetchField(); + $new_tnid = db_query('SELECT nid FROM {node} WHERE tnid = :tnid ORDER BY translate ASC, nid ASC', array(':tnid' => $node->tnid))->fetchColumn(); db_update('node') ->fields(array('tnid' => $new_tnid)) ->condition('tnid', $node->tnid) diff --git a/modules/trigger/trigger.admin.inc b/modules/trigger/trigger.admin.inc index 7509eb3..06905ba 100644 --- a/modules/trigger/trigger.admin.inc +++ b/modules/trigger/trigger.admin.inc @@ -208,7 +208,7 @@ function trigger_assign_form_validate($form, $form_state) { $aid_exists = db_query("SELECT aid FROM {trigger_assignments} WHERE hook = :hook AND aid = :aid", array( ':hook' => $form_values['hook'], ':aid' => $aid, - ))->fetchField(); + ))->fetchColumn(); if ($aid_exists) { form_set_error($form_values['hook'], t('The action you chose is already assigned to that trigger.')); } @@ -221,7 +221,7 @@ function trigger_assign_form_validate($form, $form_state) { function trigger_assign_form_submit($form, &$form_state) { if (!empty($form_state['values']['aid'])) { $aid = actions_function_lookup($form_state['values']['aid']); - $weight = db_query("SELECT MAX(weight) FROM {trigger_assignments} WHERE hook = :hook", array(':hook' => $form_state['values']['hook']))->fetchField(); + $weight = db_query("SELECT MAX(weight) FROM {trigger_assignments} WHERE hook = :hook", array(':hook' => $form_state['values']['hook']))->fetchColumn(); // Insert the new action. db_insert('trigger_assignments') @@ -245,7 +245,7 @@ function trigger_assign_form_submit($form, &$form_state) { } // Delete previous save action if it exists, and re-add it using a higher // weight. - $save_action_assigned = db_query("SELECT aid FROM {trigger_assignments} WHERE hook = :hook AND aid = :aid", array(':hook' => $form_state['values']['hook'], ':aid' => $save_action))->fetchField(); + $save_action_assigned = db_query("SELECT aid FROM {trigger_assignments} WHERE hook = :hook AND aid = :aid", array(':hook' => $form_state['values']['hook'], ':aid' => $save_action))->fetchColumn(); if ($save_action_assigned) { db_delete('trigger_assignments') diff --git a/modules/trigger/trigger.test b/modules/trigger/trigger.test index 9a9a4ba..fd7a995 100644 --- a/modules/trigger/trigger.test +++ b/modules/trigger/trigger.test @@ -29,7 +29,7 @@ class TriggerWebTestCase extends DrupalWebTestCase { $this->assertText(t('The action has been successfully saved.')); // Now we have to find out the action ID of what we created. - return db_query('SELECT aid FROM {actions} WHERE callback = :callback AND label = :label', array(':callback' => $action, ':label' => $edit['actions_label']))->fetchField(); + return db_query('SELECT aid FROM {actions} WHERE callback = :callback AND label = :label', array(':callback' => $action, ':label' => $edit['actions_label']))->fetchColumn(); } } @@ -99,7 +99,7 @@ class TriggerContentTestCase extends TriggerWebTestCase { // The action should be able to be unassigned from a trigger. $this->drupalPost('admin/structure/trigger/unassign/node/node_presave/' . $hash, array(), t('Unassign')); $this->assertRaw(t('Action %action has been unassigned.', array('%action' => ucfirst($info['name']))), t('Check to make sure the @action action can be unassigned from the trigger.', array('@action' => $info['name']))); - $assigned = db_query("SELECT COUNT(*) FROM {trigger_assignments} WHERE aid IN (:keys)", array(':keys' => $content_actions))->fetchField(); + $assigned = db_query("SELECT COUNT(*) FROM {trigger_assignments} WHERE aid IN (:keys)", array(':keys' => $content_actions))->fetchColumn(); $this->assertFalse($assigned, t('Check to make sure unassign worked properly at the database level.')); } } diff --git a/modules/user/user.module b/modules/user/user.module index 1355159..0a2df58 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -243,7 +243,7 @@ function user_field_extra_fields() { * A fully-loaded user object if the user is found or FALSE if not found. */ function user_external_load($authname) { - $uid = db_query("SELECT uid FROM {authmap} WHERE authname = :authname", array(':authname' => $authname))->fetchField(); + $uid = db_query("SELECT uid FROM {authmap} WHERE authname = :authname", array(':authname' => $authname))->fetchColumn(); if ($uid) { return user_load($uid); @@ -560,7 +560,7 @@ function user_save($account, $edit = array(), $category = 'account') { // Allow 'uid' to be set by the caller. There is no danger of writing an // existing user as drupal_write_record will do an INSERT. if (empty($account->uid)) { - $account->uid = db_next_id(db_query('SELECT MAX(uid) FROM {users}')->fetchField()); + $account->uid = db_next_id(db_query('SELECT MAX(uid) FROM {users}')->fetchColumn()); } // Allow 'created' to be set by the caller. if (!isset($account->created)) { @@ -1203,7 +1203,7 @@ function user_account_form_validate($form, &$form_state) { if ($error = user_validate_name($form_state['values']['name'])) { form_set_error('name', $error); } - elseif ((bool) db_select('users')->fields('users', array('uid'))->condition('uid', $account->uid, '<>')->condition('name', db_like($form_state['values']['name']), 'LIKE')->range(0, 1)->execute()->fetchField()) { + elseif ((bool) db_select('users')->fields('users', array('uid'))->condition('uid', $account->uid, '<>')->condition('name', db_like($form_state['values']['name']), 'LIKE')->range(0, 1)->execute()->fetchColumn()) { form_set_error('name', t('The name %name is already taken.', array('%name' => $form_state['values']['name']))); } } @@ -1217,7 +1217,7 @@ function user_account_form_validate($form, &$form_state) { if ($error = user_validate_mail($form_state['values']['mail'])) { form_set_error('mail', $error); } - elseif ((bool) db_select('users')->fields('users', array('uid'))->condition('uid', $account->uid, '<>')->condition('mail', db_like($form_state['values']['mail']), 'LIKE')->range(0, 1)->execute()->fetchField()) { + elseif ((bool) db_select('users')->fields('users', array('uid'))->condition('uid', $account->uid, '<>')->condition('mail', db_like($form_state['values']['mail']), 'LIKE')->range(0, 1)->execute()->fetchColumn()) { // Format error message dependent on whether the user is logged in or not. if ($GLOBALS['user']->uid) { form_set_error('mail', t('The e-mail address %email is already taken.', array('%email' => $form_state['values']['mail']))); @@ -1409,7 +1409,7 @@ function user_block_view($delta = '') { // Perform database queries to gather online user lists. We use s.timestamp // rather than u.access because it is much faster. - $authenticated_count = db_query("SELECT COUNT(DISTINCT s.uid) FROM {sessions} s WHERE s.timestamp >= :timestamp AND s.uid > 0", array(':timestamp' => $interval))->fetchField(); + $authenticated_count = db_query("SELECT COUNT(DISTINCT s.uid) FROM {sessions} s WHERE s.timestamp >= :timestamp AND s.uid > 0", array(':timestamp' => $interval))->fetchColumn(); $output = '

    ' . format_plural($authenticated_count, 'There is currently 1 user online.', 'There are currently @count users online.') . '

    '; @@ -2878,7 +2878,7 @@ function user_role_save($role) { // Set a role weight to make this new role last. $query = db_select('role'); $query->addExpression('MAX(weight)'); - $role->weight = $query->execute()->fetchField() + 1; + $role->weight = $query->execute()->fetchColumn() + 1; } // Let modules modify the user role before it is saved to the database. @@ -3161,7 +3161,7 @@ function user_user_operations_block($accounts) { function user_multiple_role_edit($accounts, $operation, $rid) { // The role name is not necessary as user_save() will reload the user // object, but some modules' hook_user() may look at this first. - $role_name = db_query('SELECT name FROM {role} WHERE rid = :rid', array(':rid' => $rid))->fetchField(); + $role_name = db_query('SELECT name FROM {role} WHERE rid = :rid', array(':rid' => $rid))->fetchColumn(); switch ($operation) { case 'add_role': diff --git a/modules/user/user.test b/modules/user/user.test index 6ecbfac..47bb32e 100644 --- a/modules/user/user.test +++ b/modules/user/user.test @@ -1465,12 +1465,12 @@ class UserBlocksUnitTests extends DrupalWebTestCase { $user1 = $this->drupalCreateUser(array()); $user2 = $this->drupalCreateUser(array()); $user3 = $this->drupalCreateUser(array()); - $this->assertEqual(db_query("SELECT COUNT(*) FROM {sessions}")->fetchField(), 0, t('Sessions table is empty.')); + $this->assertEqual(db_query("SELECT COUNT(*) FROM {sessions}")->fetchColumn(), 0, t('Sessions table is empty.')); // Insert a user with two sessions. $this->insertSession(array('uid' => $user1->uid)); $this->insertSession(array('uid' => $user1->uid)); - $this->assertEqual(db_query("SELECT COUNT(*) FROM {sessions} WHERE uid = :uid", array(':uid' => $user1->uid))->fetchField(), 2, t('Duplicate user session has been inserted.')); + $this->assertEqual(db_query("SELECT COUNT(*) FROM {sessions} WHERE uid = :uid", array(':uid' => $user1->uid))->fetchColumn(), 2, t('Duplicate user session has been inserted.')); // Insert a user with only one session. $this->insertSession(array('uid' => $user2->uid, 'timestamp' => REQUEST_TIME + 1)); @@ -1505,7 +1505,7 @@ class UserBlocksUnitTests extends DrupalWebTestCase { db_insert('sessions') ->fields($fields) ->execute(); - $this->assertEqual(db_query("SELECT COUNT(*) FROM {sessions} WHERE uid = :uid AND sid = :sid AND timestamp = :timestamp", array(':uid' => $fields['uid'], ':sid' => $fields['sid'], ':timestamp' => $fields['timestamp']))->fetchField(), 1, t('Session record inserted.')); + $this->assertEqual(db_query("SELECT COUNT(*) FROM {sessions} WHERE uid = :uid AND sid = :sid AND timestamp = :timestamp", array(':uid' => $fields['uid'], ':sid' => $fields['sid'], ':timestamp' => $fields['timestamp']))->fetchColumn(), 1, t('Session record inserted.')); } } @@ -1527,7 +1527,7 @@ class UserSaveTestCase extends DrupalWebTestCase { */ function testUserImport() { // User ID must be a number that is not in the database. - $max_uid = db_query('SELECT MAX(uid) FROM {users}')->fetchField(); + $max_uid = db_query('SELECT MAX(uid) FROM {users}')->fetchColumn(); $test_uid = $max_uid + mt_rand(1000, 1000000); $test_name = $this->randomName();