diff --git includes/actions.inc includes/actions.inc
index 129f38d..cd1da63 100644
--- includes/actions.inc
+++ includes/actions.inc
@@ -117,7 +117,7 @@ function actions_do($action_ids, $object = NULL, $context = NULL, $a1 = NULL, $a
   else {
     // If it's a configurable action, retrieve stored parameters.
     if (is_numeric($action_ids)) {
-      $action = db_query("SELECT callback, parameters FROM {actions} WHERE aid = :aid", array(':aid' => $action_ids))->fetchObject();
+      $action = db_static_query("SELECT callback, parameters FROM {actions} WHERE aid = :aid", array(':aid' => $action_ids))->fetchObject();
       $function = $action->callback;
       if (function_exists($function)) {
         $context = array_merge($context, unserialize($action->parameters));
@@ -187,7 +187,7 @@ function actions_list($reset = FALSE) {
  *   array with keys 'callback', 'label', 'type' and 'configurable'.
  */
 function actions_get_all_actions() {
-  $actions = db_query("SELECT aid, type, callback, parameters, label FROM {actions}")->fetchAllAssoc('aid', PDO::FETCH_ASSOC);
+  $actions = db_static_query("SELECT aid, type, callback, parameters, label FROM {actions}")->fetchAllAssoc('aid', PDO::FETCH_ASSOC);
   foreach ($actions as &$action) {
     $action['configurable'] = (bool) $action['parameters'];
     unset($action['parameters']);
@@ -245,7 +245,7 @@ function actions_function_lookup($hash) {
   }
   $aid = FALSE;
   // Must be a configurable action; check database.
-  $result = db_query("SELECT aid FROM {actions} WHERE parameters <> ''")->fetchAll(PDO::FETCH_ASSOC);
+  $result = db_static_query("SELECT aid FROM {actions} WHERE parameters <> ''")->fetchAll(PDO::FETCH_ASSOC);
   foreach ($result as $row) {
     if (drupal_hash_base64($row['aid']) == $hash) {
       $aid = $row['aid'];
@@ -270,7 +270,7 @@ function actions_function_lookup($hash) {
  */
 function actions_synchronize($delete_orphans = FALSE) {
   $actions_in_code = actions_list(TRUE);
-  $actions_in_db = db_query("SELECT aid, callback, label FROM {actions} WHERE parameters = ''")->fetchAllAssoc('callback', PDO::FETCH_ASSOC);
+  $actions_in_db = db_static_query("SELECT aid, callback, label FROM {actions} WHERE parameters = ''")->fetchAllAssoc('callback', PDO::FETCH_ASSOC);
 
   // Go through all the actions provided by modules.
   foreach ($actions_in_code as $callback => $array) {
@@ -302,7 +302,7 @@ function actions_synchronize($delete_orphans = FALSE) {
     $orphaned = array_keys($actions_in_db);
 
     if ($delete_orphans) {
-      $actions = db_query('SELECT aid, label FROM {actions} WHERE callback IN (:orphaned)', array(':orphaned' => $orphaned))->fetchAll();
+      $actions = db_static_query('SELECT aid, label FROM {actions} WHERE callback IN (:orphaned)', array(':orphaned' => $orphaned))->fetchAll();
       foreach ($actions as $action) {
         actions_delete($action->aid);
         watchdog('actions', "Removed orphaned action '%action' from database.", array('%action' => filter_xss_admin($action->label)));
@@ -366,7 +366,7 @@ function actions_save($function, $type, $params, $label, $aid = NULL) {
  *   The appropriate action row from the database as an object.
  */
 function actions_load($aid) {
-  return db_query("SELECT aid, type, callback, parameters, label FROM {actions} WHERE aid = :aid", array(':aid' => $aid))->fetchObject();
+  return db_static_query("SELECT aid, type, callback, parameters, label FROM {actions} WHERE aid = :aid", array(':aid' => $aid))->fetchObject();
 }
 
 /**
diff --git includes/batch.inc includes/batch.inc
index 7fcc915..1505e36 100644
--- includes/batch.inc
+++ includes/batch.inc
@@ -26,7 +26,7 @@
  *   An array representing the batch, or FALSE if no batch was found.
  */
 function batch_load($id) {
-  $batch = db_query("SELECT batch FROM {batch} WHERE bid = :bid AND token = :token", array(
+  $batch = db_static_query("SELECT batch FROM {batch} WHERE bid = :bid AND token = :token", array(
     ':bid' => $id,
     ':token' => drupal_get_token($id),
   ))->fetchField();
diff --git includes/batch.queue.inc includes/batch.queue.inc
index 8193280..1c160ad 100644
--- includes/batch.queue.inc
+++ includes/batch.queue.inc
@@ -21,7 +21,7 @@
 class BatchQueue extends SystemQueue {
 
   public function claimItem($lease_time = 0) {
-    $item = db_query('SELECT data, item_id FROM {queue} q WHERE name = :name ORDER BY item_id ASC', array(':name' => $this->name))->fetchObject();
+    $item = db_static_query('SELECT data, item_id FROM {queue} q WHERE name = :name ORDER BY item_id ASC', array(':name' => $this->name))->fetchObject();
     if ($item) {
       $item->data = unserialize($item->data);
       return $item;
@@ -36,7 +36,7 @@ class BatchQueue extends SystemQueue {
    */
   public function getAllItems() {
     $result = array();
-    $items = db_query('SELECT data FROM {queue} q WHERE name = :name ORDER BY item_id ASC', array(':name' => $this->name))->fetchAll();
+    $items = db_static_query('SELECT data FROM {queue} q WHERE name = :name ORDER BY item_id ASC', array(':name' => $this->name))->fetchAll();
     foreach ($items as $item) {
       $result[] = unserialize($item->data);
     }
diff --git includes/bootstrap.inc includes/bootstrap.inc
index 8fc1e07..3e09a12 100644
--- includes/bootstrap.inc
+++ includes/bootstrap.inc
@@ -688,8 +688,8 @@ function drupal_get_filename($type, $name, $filename = NULL) {
   // when a database connection fails.
   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();
+      if (function_exists('db_static_query')) {
+        $file = db_static_query("SELECT filename FROM {system} WHERE name = :name AND type = :type", array(':name' => $name, ':type' => $type))->fetchField();
         if (file_exists($file)) {
           $files[$type][$name] = $file;
         }
@@ -748,7 +748,7 @@ function variable_initialize($conf = array()) {
     $variables = $cached->data;
   }
   else {
-    $variables = array_map('unserialize', db_query('SELECT name, value FROM {variable}')->fetchAllKeyed());
+    $variables = array_map('unserialize', db_static_query('SELECT name, value FROM {variable}')->fetchAllKeyed());
     cache_set('variables', $variables, 'cache_bootstrap');
   }
 
@@ -1734,7 +1734,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_static_query("SELECT 1 FROM {blocked_ips} WHERE ip = :ip", array(':ip' => $ip))->fetchField();
   }
   return $denied;
 }
@@ -2292,7 +2292,7 @@ function language_list($field = 'language') {
   // Init language list
   if (!isset($languages)) {
     if (drupal_multilingual() || module_exists('locale')) {
-      $languages['language'] = db_query('SELECT * FROM {languages} ORDER BY weight ASC, name ASC')->fetchAllAssoc('language');
+      $languages['language'] = db_static_query('SELECT * FROM {languages} ORDER BY weight ASC, name ASC')->fetchAllAssoc('language');
     }
     else {
       // No locale module, so use the default language only.
diff --git includes/cache.inc includes/cache.inc
index 2a729ef..c73b871 100644
--- includes/cache.inc
+++ includes/cache.inc
@@ -308,7 +308,7 @@ class DrupalDatabaseCache implements DrupalCacheInterface {
     try {
       // Garbage collection necessary when enforcing a minimum cache lifetime.
       $this->garbageCollection($this->bin);
-      $cache = db_query("SELECT data, created, expire, serialized FROM {" . $this->bin . "} WHERE cid = :cid", array(':cid' => $cid))->fetchObject();
+      $cache = db_static_query("SELECT data, created, expire, serialized FROM {" . $this->bin . "} WHERE cid = :cid", array(':cid' => $cid))->fetchObject();
       return $this->prepareItem($cache);
     }
     catch (Exception $e) {
diff --git includes/common.inc includes/common.inc
index ed635e6..ad60962 100644
--- includes/common.inc
+++ includes/common.inc
@@ -1184,7 +1184,7 @@ function flood_is_allowed($name, $threshold, $window = 3600, $identifier = NULL)
   if (!isset($identifier)) {
     $identifier = ip_address();
   }
-  $number = db_query("SELECT COUNT(*) FROM {flood} WHERE event = :event AND identifier = :identifier AND timestamp > :timestamp", array(
+  $number = db_static_query("SELECT COUNT(*) FROM {flood} WHERE event = :event AND identifier = :identifier AND timestamp > :timestamp", array(
     ':event' => $name,
     ':identifier' => $identifier,
     ':timestamp' => REQUEST_TIME - $window))
diff --git includes/database/database.inc includes/database/database.inc
index 2989833..1964f63 100644
--- includes/database/database.inc
+++ includes/database/database.inc
@@ -26,7 +26,7 @@
  * The system is built atop PHP's PDO (PHP Data Objects) database API and
  * inherits much of its syntax and semantics.
  *
- * Most Drupal database SELECT queries are performed by a call to db_query() or
+ * Most Drupal database SELECT queries are performed by a call to db_static_query() or
  * db_query_range(). Module authors should also consider using the PagerDefault
  * Extender for queries that return results that need to be presented on
  * multiple pages, and the Tablesort Extender for generating appropriate queries
@@ -47,7 +47,7 @@
  * @endcode
  * Curly braces are used around "node" to provide table prefixing via
  * DatabaseConnection::prefixTables(). The explicit use of a user ID is pulled
- * out into an argument passed to db_query() so that SQL injection attacks
+ * out into an argument passed to db_static_query() so that SQL injection attacks
  * from user input can be caught and nullified. The LIMIT syntax varies between
  * database servers, so that is abstracted into db_query_range() arguments.
  * Finally, note the PDO-based ability to foreach() over the result set.
@@ -806,7 +806,7 @@ abstract class DatabaseConnection extends PDO {
    * For example, the following does a case-insensitive query for all rows whose
    * name starts with $prefix:
    * @code
-   * $result = db_query(
+   * $result = db_static_query(
    *   'SELECT * FROM person WHERE name LIKE :pattern',
    *   array(':pattern' => db_like($prefix) . '%')
    * );
@@ -2206,15 +2206,15 @@ function db_autoload($class) {
 /**
  * Executes an arbitrary query string against the active database.
  *
- * Do not use this function for INSERT, UPDATE, or DELETE queries. Those should
- * be handled via the appropriate query builder factory. Use this function for
- * SELECT queries that do not require a query builder.
+ * Do no use this query for dynamic queries that take arguments or use clauses.
+ * Those should be handled via the appropriate query builder factory. Use this
+ * function for SELECT queries that do not require a query builder.
  *
  * @param $query
  *   The prepared statement query to run. Although it will accept both named and
  *   unnamed placeholders, named placeholders are strongly preferred as they are
  *   more self-documenting.
- * @param $args
+ * @param $args (deprecated)
  *   An array of values to substitute into the query. If the query uses named
  *   placeholders, this is an associative array in any order. If the query uses
  *   unnamed placeholders (?), this is an indexed array and the order must match
@@ -2227,7 +2227,7 @@ function db_autoload($class) {
  *
  * @see DatabaseConnection::defaultOptions()
  */
-function db_query($query, array $args = array(), array $options = array()) {
+function db_static_query($query, array $args = array(), array $options = array()) {
   if (empty($options['target'])) {
     $options['target'] = 'default';
   }
@@ -2480,7 +2480,7 @@ function db_escape_field($field) {
  * For example, the following does a case-insensitive query for all rows whose
  * name starts with $prefix:
  * @code
- * $result = db_query(
+ * $result = db_static_query(
  *   'SELECT * FROM person WHERE name LIKE :pattern',
  *   array(':pattern' => db_like($prefix) . '%')
  * );
diff --git includes/database/pgsql/install.inc includes/database/pgsql/install.inc
index 7f63f6c..b613167 100644
--- includes/database/pgsql/install.inc
+++ includes/database/pgsql/install.inc
@@ -32,7 +32,7 @@ class DatabaseTasks_pgsql extends DatabaseTasks {
    */
   protected function checkEncoding() {
     try {
-      if (db_query('SHOW server_encoding')->fetchField() == 'UTF8') {
+      if (db_static_query('SHOW server_encoding')->fetchField() == 'UTF8') {
         $this->pass(st('Database is encoded in UTF-8'));
       }
       else {
@@ -61,31 +61,31 @@ class DatabaseTasks_pgsql extends DatabaseTasks {
 
     try {
       // Create functions.
-      db_query('CREATE OR REPLACE FUNCTION "greatest"(numeric, numeric) RETURNS numeric AS
+      db_static_query('CREATE OR REPLACE FUNCTION "greatest"(numeric, numeric) RETURNS numeric AS
         \'SELECT CASE WHEN (($1 > $2) OR ($2 IS NULL)) THEN $1 ELSE $2 END;\'
         LANGUAGE \'sql\''
       );
-      db_query('CREATE OR REPLACE FUNCTION "greatest"(numeric, numeric, numeric) RETURNS numeric AS
+      db_static_query('CREATE OR REPLACE FUNCTION "greatest"(numeric, numeric, numeric) RETURNS numeric AS
         \'SELECT greatest($1, greatest($2, $3));\'
         LANGUAGE \'sql\''
       );
       // Don't use {} around pg_proc table.
-      if (!db_query("SELECT COUNT(*) FROM pg_proc WHERE proname = 'rand'")->fetchField()) {
-        db_query('CREATE OR REPLACE FUNCTION "rand"() RETURNS float AS
+      if (!db_static_query("SELECT COUNT(*) FROM pg_proc WHERE proname = 'rand'")->fetchField()) {
+        db_static_query('CREATE OR REPLACE FUNCTION "rand"() RETURNS float AS
           \'SELECT random();\'
           LANGUAGE \'sql\''
         );
       }
 
       // Don't use {} around pg_proc table.
-      if (!db_query("SELECT COUNT(*) FROM pg_proc WHERE proname = 'concat'")->fetchField()) {
-        db_query('CREATE OR REPLACE FUNCTION "concat"(text, text) RETURNS text AS
+      if (!db_static_query("SELECT COUNT(*) FROM pg_proc WHERE proname = 'concat'")->fetchField()) {
+        db_static_query('CREATE OR REPLACE FUNCTION "concat"(text, text) RETURNS text AS
           \'SELECT $1 || $2;\'
           LANGUAGE \'sql\''
         );
       }
 
-      db_query('CREATE OR REPLACE FUNCTION "substring_index"(text, text, integer) RETURNS text AS
+      db_static_query('CREATE OR REPLACE FUNCTION "substring_index"(text, text, integer) RETURNS text AS
         \'SELECT array_to_string((string_to_array($1, $2)) [1:$3], $2);\'
         LANGUAGE \'sql\''
       );
diff --git includes/database/sqlite/schema.inc includes/database/sqlite/schema.inc
index ade0219..63c569c 100644
--- includes/database/sqlite/schema.inc
+++ includes/database/sqlite/schema.inc
@@ -536,7 +536,7 @@ class DatabaseSchema_sqlite extends DatabaseSchema {
 
   public function findTables($table_expression) {
     // Don't use {} around sqlite_master table.
-    $result = db_query("SELECT name FROM sqlite_master WHERE name LIKE :table_name", array(
+    $result = db_static_query("SELECT name FROM sqlite_master WHERE name LIKE :table_name", array(
       ':table_name' => $table_expression,
     ));
     return $result->fetchAllKeyed(0, 0);
diff --git includes/form.inc includes/form.inc
index 68f24f6..bf27cd2 100644
--- includes/form.inc
+++ includes/form.inc
@@ -3247,7 +3247,7 @@ function _form_set_class(&$element, $class = array()) {
  *   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_static_query('SELECT COUNT(DISTINCT nid) FROM {node}')->fetchField();
  *   }
  *   $limit = 5;
  *   $result = db_select('node')
diff --git includes/install.core.inc includes/install.core.inc
index dd376ae..25a2d53 100644
--- includes/install.core.inc
+++ includes/install.core.inc
@@ -780,7 +780,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'))) {
+    if ($result = db_static_query("SELECT value FROM {variable} WHERE name = :name", array('name' => 'install_task'))) {
       $task = unserialize($result->fetchField());
     }
   }
diff --git includes/install.inc includes/install.inc
index c5083eb..57d5069 100644
--- includes/install.inc
+++ includes/install.inc
@@ -148,7 +148,7 @@ function drupal_get_installed_schema_version($module, $reset = FALSE, $array = F
 
   if (!$versions) {
     $versions = array();
-    $result = db_query("SELECT name, schema_version FROM {system} WHERE type = :type", array(':type' => 'module'));
+    $result = db_static_query("SELECT name, schema_version FROM {system} WHERE type = :type", array(':type' => 'module'));
     foreach ($result as $row) {
       $versions[$row->name] = $row->schema_version;
     }
@@ -395,7 +395,7 @@ abstract class DatabaseTasks {
    */
   protected function runTestQuery($query, $pass, $fail, $fatal = FALSE) {
     try {
-      db_query($query);
+      db_static_query($query);
       $this->pass(st($pass));
     }
     catch (Exception $e) {
diff --git includes/locale.inc includes/locale.inc
index 39908ce..2ffd0c4 100644
--- includes/locale.inc
+++ includes/locale.inc
@@ -415,7 +415,7 @@ function _locale_import_po($file, $langcode, $mode, $group = NULL) {
   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_static_query("SELECT COUNT(language) FROM {languages} WHERE language = :language", array(':language' => $langcode))->fetchField()) {
     drupal_set_message(t('The language selected for import is not supported.'), 'error');
     return FALSE;
   }
@@ -770,7 +770,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, $textgroup, $location, $mode, $plid = 0, $plural = 0) {
-  $lid = db_query("SELECT lid FROM {locales_source} WHERE source = :source AND context = :context AND textgroup = :textgroup", array(':source' => $source, ':context' => $context, ':textgroup' => $textgroup))->fetchField();
+  $lid = db_static_query("SELECT lid FROM {locales_source} WHERE source = :source AND context = :context AND textgroup = :textgroup", array(':source' => $source, ':context' => $context, ':textgroup' => $textgroup))->fetchField();
 
   if (!empty($translation)) {
     // Skip this string unless it passes a check for dangerous code.
@@ -789,7 +789,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_static_query("SELECT COUNT(lid) FROM {locales_target} WHERE lid = :lid AND language = :language", array(':lid' => $lid, ':language' => $langcode))->fetchField();
 
       if (!$exists) {
         // No translation in this language.
@@ -1194,7 +1194,7 @@ function _locale_parse_js_file($filepath) {
       // Remove the quotes and string concatenations from the string.
       $string = implode('', preg_split('~(?<!\\\\)[\'"]\s*\+\s*[\'"]~s', substr($string, 1, -1)));
 
-      $source = db_query("SELECT lid, location FROM {locales_source} WHERE source = :source AND textgroup = 'default'", array(':source' => $string))->fetchObject();
+      $source = db_static_query("SELECT lid, location FROM {locales_source} WHERE source = :source AND textgroup = 'default'", array(':source' => $string))->fetchObject();
       if ($source) {
         // We already have this source string and now have to add the location
         // to the location column, if this file is not yet present in there.
@@ -1246,10 +1246,10 @@ function _locale_parse_js_file($filepath) {
  */
 function _locale_export_get_strings($language = NULL, $group = 'default') {
   if (isset($language)) {
-    $result = db_query("SELECT s.lid, s.source, s.context, s.location, t.translation, t.plid, t.plural FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.textgroup = :textgroup ORDER BY t.plid, t.plural", array(':language' => $language->language, ':textgroup' => $group));
+    $result = db_static_query("SELECT s.lid, s.source, s.context, s.location, t.translation, t.plid, t.plural FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.textgroup = :textgroup ORDER BY t.plid, t.plural", array(':language' => $language->language, ':textgroup' => $group));
   }
   else {
-    $result = db_query("SELECT s.lid, s.source, s.context, s.location, t.plid, t.plural FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid WHERE s.textgroup = :textgroup ORDER BY t.plid, t.plural", array(':textgroup' => $group));
+    $result = db_static_query("SELECT s.lid, s.source, s.context, s.location, t.plid, t.plural FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid WHERE s.textgroup = :textgroup ORDER BY t.plid, t.plural", array(':textgroup' => $group));
   }
   $strings = array();
   foreach ($result as $child) {
@@ -1638,7 +1638,7 @@ function _locale_rebuild_js($langcode = NULL) {
 
   // Construct the array for JavaScript translations.
   // We sort on plural so that we have all plural forms before singular forms.
-  $result = db_query("SELECT s.lid, s.source, t.plid, t.plural, t.translation FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.location LIKE '%.js%' AND s.textgroup = :textgroup ORDER BY t.plural DESC", array(':language' => $language->language, ':textgroup' => 'default'));
+  $result = db_static_query("SELECT s.lid, s.source, t.plid, t.plural, t.translation FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.location LIKE '%.js%' AND s.textgroup = :textgroup ORDER BY t.plural DESC", array(':language' => $language->language, ':textgroup' => 'default'));
 
   $translations = $plurals = array();
   foreach ($result as $data) {
@@ -1743,7 +1743,7 @@ function _locale_rebuild_js($langcode = NULL) {
     // version of the language and to prevent checking against an outdated hash.
     $default_langcode = language_default('language');
     if ($default_langcode == $language->language) {
-      $default = db_query("SELECT * FROM {languages} WHERE language = :language", array(':language' => $default_langcode))->fetchObject();
+      $default = db_static_query("SELECT * FROM {languages} WHERE language = :language", array(':language' => $default_langcode))->fetchObject();
       variable_set('language_default', $default);
     }
   }
@@ -1888,7 +1888,7 @@ function locale_batch_by_component($components, $finished = '_locale_batch_syste
   if (count($languages[1])) {
     $language_list = join('|', array_keys($languages[1]));
     // Collect all files to import for all $components.
-    $result = db_query("SELECT name, filename FROM {system} WHERE status = 1");
+    $result = db_static_query("SELECT name, filename FROM {system} WHERE status = 1");
     foreach ($result as $component) {
       if (in_array($component->name, $components)) {
         // Collect all files for this component in all enabled languages, named
diff --git includes/lock.inc includes/lock.inc
index 3239b7f..faeea25 100644
--- includes/lock.inc
+++ includes/lock.inc
@@ -158,7 +158,7 @@ function lock_acquire($name, $timeout = 30.0) {
  *   TRUE if there is no lock or it was removed, FALSE otherwise.
  */
 function lock_may_be_available($name) {
-  $lock = db_query('SELECT expire, value FROM {semaphore} WHERE name = :name', array(':name' => $name))->fetchAssoc();
+  $lock = db_static_query('SELECT expire, value FROM {semaphore} WHERE name = :name', array(':name' => $name))->fetchAssoc();
   if (!$lock) {
     return TRUE;
   }
diff --git includes/menu.inc includes/menu.inc
index cbd2b59..a91f163 100644
--- includes/menu.inc
+++ includes/menu.inc
@@ -2565,10 +2565,10 @@ function menu_delete_links($menu_name) {
  */
 function menu_link_delete($mlid, $path = NULL) {
   if (isset($mlid)) {
-    _menu_delete_item(db_query("SELECT * FROM {menu_links} WHERE mlid = :mlid", array(':mlid' => $mlid))->fetchAssoc());
+    _menu_delete_item(db_static_query("SELECT * FROM {menu_links} WHERE mlid = :mlid", array(':mlid' => $mlid))->fetchAssoc());
   }
   else {
-    $result = db_query("SELECT * FROM {menu_links} WHERE link_path = :link_path", array(':link_path' => $path));
+    $result = db_static_query("SELECT * FROM {menu_links} WHERE link_path = :link_path", array(':link_path' => $path));
     foreach ($result as $link) {
       _menu_delete_item($link);
     }
@@ -2588,7 +2588,7 @@ function _menu_delete_item($item, $force = FALSE) {
   if ($item && ($item['module'] != 'system' || $item['updated'] || $force)) {
     // Children get re-attached to the item's parent.
     if ($item['has_children']) {
-      $result = db_query("SELECT mlid FROM {menu_links} WHERE plid = :plid", array(':plid' => $item['mlid']));
+      $result = db_static_query("SELECT mlid FROM {menu_links} WHERE plid = :plid", array(':plid' => $item['mlid']));
       foreach ($result as $m) {
         $child = menu_link_load($m->mlid);
         $child['plid'] = $item['plid'];
@@ -2646,7 +2646,7 @@ function menu_link_save(&$item) {
   );
   $existing_item = FALSE;
   if (isset($item['mlid'])) {
-    if ($existing_item = db_query("SELECT * FROM {menu_links} WHERE mlid = :mlid", array(':mlid' => $item['mlid']))->fetchAssoc()) {
+    if ($existing_item = db_static_query("SELECT * FROM {menu_links} WHERE mlid = :mlid", array(':mlid' => $item['mlid']))->fetchAssoc()) {
       $existing_item['options'] = unserialize($existing_item['options']);
     }
   }
@@ -2654,7 +2654,7 @@ function menu_link_save(&$item) {
   // If we have a parent link ID, we use it to inherit 'menu_name' and 'depth'.
   if (isset($item['plid'])) {
     if ($item['plid']) {
-      $parent = db_query("SELECT * FROM {menu_links} WHERE mlid = :mlid", array(':mlid' => $item['plid']))->fetchAssoc();
+      $parent = db_static_query("SELECT * FROM {menu_links} WHERE mlid = :mlid", array(':mlid' => $item['plid']))->fetchAssoc();
     }
     // If the parent link ID is zero, then this link lives at the top-level.
     else {
@@ -2833,7 +2833,7 @@ function _menu_clear_page_cache() {
  * Helper function to update a list of menus with expanded items
  */
 function _menu_set_expanded_menus() {
-  $names = db_query("SELECT menu_name FROM {menu_links} WHERE expanded <> 0 GROUP BY menu_name")->fetchCol();
+  $names = db_static_query("SELECT menu_name FROM {menu_links} WHERE expanded <> 0 GROUP BY menu_name")->fetchCol();
   variable_set('menu_expanded', $names);
 }
 
@@ -2905,7 +2905,7 @@ function menu_link_maintain($module, $op, $link_path, $link_title) {
       return menu_link_save($menu_link);
       break;
     case 'update':
-      $result = db_query("SELECT * FROM {menu_links} WHERE link_path = :link_path AND module = :module AND customized = 0", array(':link_path' => $link_path, ':module' => $module))->fetchAll(PDO::FETCH_ASSOC);
+      $result = db_static_query("SELECT * FROM {menu_links} WHERE link_path = :link_path AND module = :module AND customized = 0", array(':link_path' => $link_path, ':module' => $module))->fetchAll(PDO::FETCH_ASSOC);
       foreach ($result as $link) {
         $link['link_title'] = $link_title;
         $link['options'] = unserialize($link['options']);
@@ -3145,7 +3145,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_static_query("SELECT menu_name FROM {menu_links} WHERE router_path = :router_path AND module = 'system'", array(':router_path' => $parent_path))->fetchField();
             if ($menu_name) {
               $parent['menu_name'] = $menu_name;
             }
diff --git includes/module.inc includes/module.inc
index c9d2f4d..13ececb 100644
--- includes/module.inc
+++ includes/module.inc
@@ -112,7 +112,7 @@ function system_list($type) {
       $bootstrap_list = $cached->data;
     }
     else {
-      $bootstrap_list = db_query("SELECT name, filename FROM {system} WHERE status = 1 AND bootstrap = 1 AND type = 'module' ORDER BY weight ASC, name ASC")->fetchAllAssoc('name');
+      $bootstrap_list = db_static_query("SELECT name, filename FROM {system} WHERE status = 1 AND bootstrap = 1 AND type = 'module' ORDER BY weight ASC, name ASC")->fetchAllAssoc('name');
       cache_set('bootstrap_modules', $bootstrap_list, 'cache_bootstrap');
     }
     // To avoid a separate database lookup for the filepath, prime the
@@ -141,7 +141,7 @@ function system_list($type) {
       // Drupal installations, which might have modules installed in different
       // locations in the file system. The ordering here must also be
       // consistent with the one used in module_implements().
-      $result = db_query("SELECT * FROM {system} ORDER BY weight ASC, name ASC");
+      $result = db_static_query("SELECT * FROM {system} ORDER BY weight ASC, name ASC");
       foreach ($result as $record) {
         if ($record->type == 'module' && $record->status) {
           // Build a list of all enabled modules.
@@ -342,7 +342,7 @@ function module_enable($module_list, $enable_dependencies = TRUE) {
   $modules_enabled = array();
   foreach ($module_list as $module) {
     // Only process modules that are not already enabled.
-    $existing = db_query("SELECT status FROM {system} WHERE type = :type AND name = :name", array(
+    $existing = db_static_query("SELECT status FROM {system} WHERE type = :type AND name = :name", array(
       ':type' => 'module',
       ':name' => $module))
       ->fetchObject();
diff --git includes/path.inc includes/path.inc
index daaca11..9644628 100644
--- includes/path.inc
+++ includes/path.inc
@@ -92,7 +92,7 @@ function drupal_lookup_path($action, $path = '', $path_language = NULL) {
           // Now fetch the aliases corresponding to these system paths.
           // We order by ASC and overwrite array keys to ensure the correct
           // alias is used when there are multiple aliases per path.
-          $cache['map'][$path_language] = db_query("SELECT source, alias FROM {url_alias} WHERE source IN (:system) AND language IN (:language, :language_none) ORDER BY language ASC, pid ASC", array(
+          $cache['map'][$path_language] = db_static_query("SELECT source, alias FROM {url_alias} WHERE source IN (:system) AND language IN (:language, :language_none) ORDER BY language ASC, pid ASC", array(
             ':system' => $cache['system_paths'],
             ':language' => $path_language,
             ':language_none' => LANGUAGE_NONE,
@@ -114,7 +114,7 @@ function drupal_lookup_path($action, $path = '', $path_language = NULL) {
       // For system paths which were not cached, query aliases individually.
       else if (!isset($cache['no_aliases'][$path_language][$path])) {
         // Get the most fitting result falling back with alias without language
-        $alias = db_query("SELECT alias FROM {url_alias} WHERE source = :source AND language IN (:language, :language_none) ORDER BY language DESC, pid DESC", array(
+        $alias = db_static_query("SELECT alias FROM {url_alias} WHERE source = :source AND language IN (:language, :language_none) ORDER BY language DESC, pid DESC", array(
           ':source' => $path,
           ':language' => $path_language,
           ':language_none' => LANGUAGE_NONE,
@@ -130,7 +130,7 @@ function drupal_lookup_path($action, $path = '', $path_language = NULL) {
       $source = '';
       if (!isset($cache['map'][$path_language]) || !($source = array_search($path, $cache['map'][$path_language]))) {
         // Get the most fitting result falling back with alias without language
-        if ($source = db_query("SELECT source FROM {url_alias} WHERE alias = :alias AND language IN (:language, :language_none) ORDER BY language DESC, pid DESC", array(
+        if ($source = db_static_query("SELECT source FROM {url_alias} WHERE alias = :alias AND language IN (:language, :language_none) ORDER BY language DESC, pid DESC", array(
                      ':alias' => $path,
                      ':language' => $path_language,
                      ':language_none' => LANGUAGE_NONE))
@@ -336,7 +336,7 @@ function drupal_path_alias_whitelist_rebuild($source = NULL) {
   // path it corresponds to. This is the portion of the path before the first
   // '/', if present, otherwise the whole path itself.
   $whitelist = array();
-  $result = db_query("SELECT SUBSTRING_INDEX(source, '/', 1) AS path FROM {url_alias} GROUP BY path");
+  $result = db_static_query("SELECT SUBSTRING_INDEX(source, '/', 1) AS path FROM {url_alias} GROUP BY path");
   foreach ($result as $row) {
     $whitelist[$row->path] = TRUE;
   }
@@ -511,7 +511,7 @@ function drupal_valid_path($path, $dynamic_allowed = FALSE) {
   }
   elseif ($dynamic_allowed && preg_match('/\/\%/', $path)) {
     // Path is dynamic (ie 'user/%'), so check directly against menu_router table.
-    if ($item = db_query("SELECT * FROM {menu_router} where path = :path", array(':path' => $path))->fetchAssoc()) {
+    if ($item = db_static_query("SELECT * FROM {menu_router} where path = :path", array(':path' => $path))->fetchAssoc()) {
       $item['link_path']  = $form_item['link_path'];
       $item['link_title'] = $form_item['link_title'];
       $item['external']   = FALSE;
diff --git includes/registry.inc includes/registry.inc
index 13b653f..e33c01a 100644
--- includes/registry.inc
+++ includes/registry.inc
@@ -35,7 +35,7 @@ function _registry_update() {
   require_once DRUPAL_ROOT . '/includes/database/' . $driver . '/query.inc';
 
   // Get current list of modules and their files.
-  $modules = db_query("SELECT * FROM {system} WHERE type = 'module'")->fetchAll();
+  $modules = db_static_query("SELECT * FROM {system} WHERE type = 'module'")->fetchAll();
   // Get the list of files we are going to parse.
   $files = array();
   foreach ($modules as &$module) {
@@ -110,7 +110,7 @@ function _registry_update() {
 function registry_get_parsed_files() {
   $files = array();
   // We want the result as a keyed array.
-  $files = db_query("SELECT * FROM {registry_file}")->fetchAllAssoc('filename', PDO::FETCH_ASSOC);
+  $files = db_static_query("SELECT * FROM {registry_file}")->fetchAllAssoc('filename', PDO::FETCH_ASSOC);
   return $files;
 }
 
diff --git includes/session.inc includes/session.inc
index 67c52e6..16e658b 100644
--- includes/session.inc
+++ includes/session.inc
@@ -87,17 +87,17 @@ function _drupal_session_read($sid) {
   // a HTTPS session or we are about to log in so we check the sessions table
   // for an anonymous session with the non-HTTPS-only cookie.
   if ($is_https) {
-    $user = db_query("SELECT u.*, s.* FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.ssid = :ssid", array(':ssid' => $sid))->fetchObject();
+    $user = db_static_query("SELECT u.*, s.* FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.ssid = :ssid", array(':ssid' => $sid))->fetchObject();
     if (!$user) {
       if (isset($_COOKIE[$insecure_session_name])) {
-        $user = db_query("SELECT u.*, s.* FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.sid = :sid AND s.uid = 0", array(
+        $user = db_static_query("SELECT u.*, s.* FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.sid = :sid AND s.uid = 0", array(
         ':sid' => $_COOKIE[$insecure_session_name]))
         ->fetchObject();
       }
     }
   }
   else {
-    $user = db_query("SELECT u.*, s.* FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.sid = :sid", array(':sid' => $sid))->fetchObject();
+    $user = db_static_query("SELECT u.*, s.* FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.sid = :sid", array(':sid' => $sid))->fetchObject();
   }
 
   // We found the client's session record and they are an authenticated,
@@ -109,7 +109,7 @@ function _drupal_session_read($sid) {
     // Add roles element to $user.
     $user->roles = array();
     $user->roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user';
-    $user->roles += db_query("SELECT r.rid, r.name FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid = :uid", array(':uid' => $user->uid))->fetchAllKeyed(0, 1);
+    $user->roles += db_static_query("SELECT r.rid, r.name FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid = :uid", array(':uid' => $user->uid))->fetchAllKeyed(0, 1);
   }
   // We didn't find the client's record (session has expired), or they are
   // blocked, or they are an anonymous user.
diff --git includes/update.inc includes/update.inc
index ff641a9..936021e 100644
--- includes/update.inc
+++ includes/update.inc
@@ -14,7 +14,7 @@
  */
 function update_fix_compatibility() {
   $incompatible = array();
-  $result = db_query("SELECT name, type, status FROM {system} WHERE status = 1 AND type IN ('module','theme')");
+  $result = db_static_query("SELECT name, type, status FROM {system} WHERE status = 1 AND type IN ('module','theme')");
   foreach ($result as $row) {
     if (update_check_incompatibility($row->name, $row->type)) {
       $incompatible[] = $row->name;
@@ -235,7 +235,7 @@ function update_fix_d7_block_deltas(&$sandbox, $renamed_deltas) {
       foreach ($renamed_deltas as $module => $deltas) {
         foreach ($deltas as $old_delta => $new_delta) {
           // Only do the update if the old block actually exists.
-          $block_exists = db_query("SELECT COUNT(*) FROM {" . $table . "} WHERE module = :module AND delta = :delta", array(
+          $block_exists = db_static_query("SELECT COUNT(*) FROM {" . $table . "} WHERE module = :module AND delta = :delta", array(
             ':module' => $module,
             ':delta' => $old_delta,
           ))
@@ -254,7 +254,7 @@ function update_fix_d7_block_deltas(&$sandbox, $renamed_deltas) {
     // Initialize batch update information.
     $sandbox['progress'] = 0;
     $sandbox['last_user_processed'] = -1;
-    $sandbox['max'] = db_query("SELECT COUNT(*) FROM {users} WHERE data IS NOT NULL")->fetchField();
+    $sandbox['max'] = db_static_query("SELECT COUNT(*) FROM {users} WHERE data IS NOT NULL")->fetchField();
   }
   // Now do the batch update of the user-specific block visibility settings.
   $limit = 100;
@@ -553,9 +553,9 @@ function update_fix_d7_requirements() {
     db_create_table('sequences', $schema['sequences']);
     // Initialize the table with the maximum current increment of the tables
     // that will rely on it for their ids.
-    $max_aid = db_query('SELECT MAX(aid) FROM {actions_aid}')->fetchField();
-    $max_uid = db_query('SELECT MAX(uid) FROM {users}')->fetchField();
-    $max_batch_id = db_query('SELECT MAX(bid) FROM {batch}')->fetchField();
+    $max_aid = db_static_query('SELECT MAX(aid) FROM {actions_aid}')->fetchField();
+    $max_uid = db_static_query('SELECT MAX(uid) FROM {users}')->fetchField();
+    $max_batch_id = db_static_query('SELECT MAX(bid) FROM {batch}')->fetchField();
     db_insert('sequences')->fields(array('value' => max($max_aid, $max_uid, $max_batch_id)))->execute();
 
     // Add column for locale context.
@@ -1188,7 +1188,7 @@ function update_retrieve_dependencies() {
   $return = array();
   // Get a list of installed modules, arranged so that we invoke their hooks in
   // the same order that module_invoke_all() does.
-  $modules = db_query("SELECT name FROM {system} WHERE type = 'module' AND schema_version != :schema ORDER BY weight ASC, name ASC", array(':schema' => SCHEMA_UNINSTALLED))->fetchCol();
+  $modules = db_static_query("SELECT name FROM {system} WHERE type = 'module' AND schema_version != :schema ORDER BY weight ASC, name ASC", array(':schema' => SCHEMA_UNINSTALLED))->fetchCol();
   foreach ($modules as $module) {
     $function = $module . '_update_dependencies';
     if (function_exists($function)) {
diff --git modules/aggregator/aggregator.admin.inc modules/aggregator/aggregator.admin.inc
index 4deaf60..5d2d229 100644
--- modules/aggregator/aggregator.admin.inc
+++ modules/aggregator/aggregator.admin.inc
@@ -20,7 +20,7 @@ function aggregator_admin_overview() {
  *   The page HTML.
  */
 function aggregator_view() {
-  $result = db_query('SELECT f.fid, f.title, f.url, f.refresh, f.checked, f.link, f.description, f.hash, f.etag, f.modified, f.image, f.block, COUNT(i.iid) AS items FROM {aggregator_feed} f LEFT JOIN {aggregator_item} i ON f.fid = i.fid GROUP BY f.fid, f.title, f.url, f.refresh, f.checked, f.link, f.description, f.hash, f.etag, f.modified, f.image, f.block ORDER BY f.title');
+  $result = db_static_query('SELECT f.fid, f.title, f.url, f.refresh, f.checked, f.link, f.description, f.hash, f.etag, f.modified, f.image, f.block, COUNT(i.iid) AS items FROM {aggregator_feed} f LEFT JOIN {aggregator_item} i ON f.fid = i.fid GROUP BY f.fid, f.title, f.url, f.refresh, f.checked, f.link, f.description, f.hash, f.etag, f.modified, f.image, f.block ORDER BY f.title');
 
   $output = '<h3>' . t('Feed overview') . '</h3>';
 
@@ -39,7 +39,7 @@ function aggregator_view() {
   }
   $output .= theme('table', array('header' => $header, 'rows' => $rows, 'empty' => t('No feeds available. <a href="@link">Add feed</a>.', array('@link' => url('admin/config/services/aggregator/add/feed')))));
 
-  $result = db_query('SELECT c.cid, c.title, COUNT(ci.iid) as items FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid GROUP BY c.cid, c.title ORDER BY title');
+  $result = db_static_query('SELECT c.cid, c.title, COUNT(ci.iid) as items FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid GROUP BY c.cid, c.title ORDER BY title');
 
   $output .= '<h3>' . t('Category overview') . '</h3>';
 
@@ -94,7 +94,7 @@ function aggregator_form_feed($form, &$form_state, stdClass $feed = NULL) {
   // Handling of categories.
   $options = array();
   $values = array();
-  $categories = db_query('SELECT c.cid, c.title, f.fid FROM {aggregator_category} c LEFT JOIN {aggregator_category_feed} f ON c.cid = f.cid AND f.fid = :fid ORDER BY title', array(':fid' => isset($feed->fid) ? $feed->fid : NULL));
+  $categories = db_static_query('SELECT c.cid, c.title, f.fid FROM {aggregator_category} c LEFT JOIN {aggregator_category_feed} f ON c.cid = f.cid AND f.fid = :fid ORDER BY title', array(':fid' => isset($feed->fid) ? $feed->fid : NULL));
   foreach ($categories as $category) {
     $options[$category->cid] = check_plain($category->title);
     if ($category->fid) $values[] = $category->cid;
@@ -140,10 +140,10 @@ function aggregator_form_feed_validate($form, &$form_state) {
     }
     // Check for duplicate titles.
     if (isset($form_state['values']['fid'])) {
-      $result = db_query("SELECT title, url FROM {aggregator_feed} WHERE (title = :title OR url = :url) AND fid <> :fid", array(':title' => $form_state['values']['title'], ':url' => $form_state['values']['url'], ':fid' => $form_state['values']['fid']));
+      $result = db_static_query("SELECT title, url FROM {aggregator_feed} WHERE (title = :title OR url = :url) AND fid <> :fid", array(':title' => $form_state['values']['title'], ':url' => $form_state['values']['url'], ':fid' => $form_state['values']['fid']));
     }
     else {
-      $result = db_query("SELECT title, url FROM {aggregator_feed} WHERE title = :title OR url = :url", array(':title' => $form_state['values']['title'], ':url' => $form_state['values']['url']));
+      $result = db_static_query("SELECT title, url FROM {aggregator_feed} WHERE title = :title OR url = :url", array(':title' => $form_state['values']['title'], ':url' => $form_state['values']['url']));
     }
     foreach ($result as $feed) {
       if (strcasecmp($feed->title, $form_state['values']['title']) == 0) {
@@ -262,7 +262,7 @@ function aggregator_form_opml($form, &$form_state) {
   );
 
   // Handling of categories.
-  $options = array_map('check_plain', db_query("SELECT cid, title FROM {aggregator_category} ORDER BY title")->fetchAllKeyed());
+  $options = array_map('check_plain', db_static_query("SELECT cid, title FROM {aggregator_category} ORDER BY title")->fetchAllKeyed());
   if ($options) {
     $form['category'] = array(
       '#type' => 'checkboxes',
@@ -326,7 +326,7 @@ function aggregator_form_opml_submit($form, &$form_state) {
     }
 
     // Check for duplicate titles or URLs.
-    $result = db_query("SELECT title, url FROM {aggregator_feed} WHERE title = :title OR url = :url", array(':title' => $feed['title'], ':url' => $feed['url']));
+    $result = db_static_query("SELECT title, url FROM {aggregator_feed} WHERE title = :title OR url = :url", array(':title' => $feed['title'], ':url' => $feed['url']));
     foreach ($result as $old) {
       if (strcasecmp($old->title, $feed['title']) == 0) {
         drupal_set_message(t('A feed named %title already exists.', array('%title' => $old->title)), 'warning');
@@ -541,10 +541,10 @@ function aggregator_form_category_validate($form, &$form_state) {
   if ($form_state['values']['op'] == t('Save')) {
     // Check for duplicate titles
     if (isset($form_state['values']['cid'])) {
-      $category = db_query("SELECT cid FROM {aggregator_category} WHERE title = :title AND cid <> :cid", array(':title' => $form_state['values']['title'], ':cid' => $form_state['values']['cid']))->fetchObject();
+      $category = db_static_query("SELECT cid FROM {aggregator_category} WHERE title = :title AND cid <> :cid", array(':title' => $form_state['values']['title'], ':cid' => $form_state['values']['cid']))->fetchObject();
     }
     else {
-      $category = db_query("SELECT cid FROM {aggregator_category} WHERE title = :title", array(':title' => $form_state['values']['title']))->fetchObject();
+      $category = db_static_query("SELECT cid FROM {aggregator_category} WHERE title = :title", array(':title' => $form_state['values']['title']))->fetchObject();
     }
     if ($category) {
       form_set_error('title', t('A category named %category already exists. Enter a unique title.', array('%category' => $form_state['values']['title'])));
diff --git modules/aggregator/aggregator.module modules/aggregator/aggregator.module
index 172361a..c9b105b 100644
--- modules/aggregator/aggregator.module
+++ modules/aggregator/aggregator.module
@@ -296,7 +296,7 @@ function aggregator_init() {
  *   TRUE if there is at least one category and the user has access to them, FALSE otherwise.
  */
 function _aggregator_has_categories() {
-  return user_access('access news feeds') && db_query('SELECT COUNT(*) FROM {aggregator_category}')->fetchField();
+  return user_access('access news feeds') && db_static_query('SELECT COUNT(*) FROM {aggregator_category}')->fetchField();
 }
 
 /**
@@ -319,7 +319,7 @@ function aggregator_permission() {
  * Queues news feeds for updates once their refresh interval has elapsed.
  */
 function aggregator_cron() {
-  $result = db_query('SELECT * FROM {aggregator_feed} WHERE queued = 0 AND checked + refresh < :time AND refresh != :never', array(
+  $result = db_static_query('SELECT * FROM {aggregator_feed} WHERE queued = 0 AND checked + refresh < :time AND refresh != :never', array(
     ':time' => REQUEST_TIME,
     ':never' => AGGREGATOR_CLEAR_NEVER
   ));
@@ -357,11 +357,11 @@ function aggregator_cron_queue_info() {
  */
 function aggregator_block_info() {
   $block = array();
-  $result = db_query('SELECT cid, title FROM {aggregator_category} ORDER BY title');
+  $result = db_static_query('SELECT cid, title FROM {aggregator_category} ORDER BY title');
   foreach ($result as $category) {
     $block['category-' . $category->cid]['info'] = t('!title category latest items', array('!title' => $category->title));
   }
-  $result = db_query('SELECT fid, title FROM {aggregator_feed} WHERE block <> 0 ORDER BY fid');
+  $result = db_static_query('SELECT fid, title FROM {aggregator_feed} WHERE block <> 0 ORDER BY fid');
   foreach ($result as $feed) {
     $block['feed-' . $feed->fid]['info'] = t('!title feed latest items', array('!title' => $feed->title));
   }
@@ -374,7 +374,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_static_query('SELECT block FROM {aggregator_category} WHERE cid = :cid', array(':cid' => $id))->fetchField();
     $form['block'] = array(
       '#type' => 'select',
       '#title' => t('Number of news items in block'),
@@ -409,7 +409,7 @@ function aggregator_block_view($delta = '') {
     list($type, $id) = explode('-', $delta);
     switch ($type) {
       case 'feed':
-        if ($feed = db_query('SELECT fid, title, block FROM {aggregator_feed} WHERE block <> 0 AND fid = :fid', array(':fid' => $id))->fetchObject()) {
+        if ($feed = db_static_query('SELECT fid, title, block FROM {aggregator_feed} WHERE block <> 0 AND fid = :fid', array(':fid' => $id))->fetchObject()) {
           $block['subject'] = check_plain($feed->title);
           $result = db_query_range("SELECT * FROM {aggregator_item} WHERE fid = :fid ORDER BY timestamp DESC, iid DESC", 0, $feed->block, array(':fid' => $id));
           $read_more = theme('more_link', array('url' => url('aggregator/sources/' . $feed->fid), 'title' => t("View this feed's recent news.")));
@@ -417,7 +417,7 @@ function aggregator_block_view($delta = '') {
         break;
 
       case 'category':
-        if ($category = db_query('SELECT cid, title, block FROM {aggregator_category} WHERE cid = :cid', array(':cid' => $id))->fetchObject()) {
+        if ($category = db_static_query('SELECT cid, title, block FROM {aggregator_category} WHERE cid = :cid', array(':cid' => $id))->fetchObject()) {
           $block['subject'] = check_plain($category->title);
           $result = db_query_range('SELECT i.* FROM {aggregator_category_item} ci LEFT JOIN {aggregator_item} i ON ci.iid = i.iid WHERE ci.cid = :cid ORDER BY i.timestamp DESC, i.iid DESC', 0, $category->block, array(':cid' => $category->cid));
           $read_more = theme('more_link', array('url' => url('aggregator/categories/' . $category->cid), 'title' => t("View this category's recent news.")));
@@ -511,7 +511,7 @@ function aggregator_save_feed($edit) {
       ->execute();
   }
   elseif (!empty($edit['fid'])) {
-    $iids = db_query('SELECT iid FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $edit['fid']))->fetchCol();
+    $iids = db_static_query('SELECT iid FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $edit['fid']))->fetchCol();
     if ($iids) {
       db_delete('aggregator_category_item')
         ->condition('iid', $iids, 'IN')
@@ -679,7 +679,7 @@ function aggregator_refresh($feed) {
 function aggregator_feed_load($fid) {
   $feeds = &drupal_static(__FUNCTION__);
   if (!isset($feeds[$fid])) {
-    $feeds[$fid] = db_query('SELECT * FROM {aggregator_feed} WHERE fid = :fid', array(':fid' => $fid))->fetchObject();
+    $feeds[$fid] = db_static_query('SELECT * FROM {aggregator_feed} WHERE fid = :fid', array(':fid' => $fid))->fetchObject();
   }
 
   return $feeds[$fid];
@@ -696,7 +696,7 @@ function aggregator_feed_load($fid) {
 function aggregator_category_load($cid) {
   $categories = &drupal_static(__FUNCTION__);
   if (!isset($categories[$cid])) {
-    $categories[$cid] = db_query('SELECT * FROM {aggregator_category} WHERE cid = :cid', array(':cid' => $cid))->fetchAssoc();
+    $categories[$cid] = db_static_query('SELECT * FROM {aggregator_category} WHERE cid = :cid', array(':cid' => $cid))->fetchAssoc();
   }
 
   return $categories[$cid];
diff --git modules/aggregator/aggregator.pages.inc modules/aggregator/aggregator.pages.inc
index be4dcd1..fd933e2 100644
--- modules/aggregator/aggregator.pages.inc
+++ modules/aggregator/aggregator.pages.inc
@@ -115,7 +115,7 @@ function aggregator_feed_items_load($type, $data = NULL) {
   }
 
   foreach ($result as $item) {
-    $item->categories = db_query('SELECT c.title, c.cid FROM {aggregator_category_item} ci LEFT JOIN {aggregator_category} c ON ci.cid = c.cid WHERE ci.iid = :iid ORDER BY c.title', array(':iid' => $item->iid))->fetchAll();
+    $item->categories = db_static_query('SELECT c.title, c.cid FROM {aggregator_category_item} ci LEFT JOIN {aggregator_category} c ON ci.cid = c.cid WHERE ci.iid = :iid ORDER BY c.title', array(':iid' => $item->iid))->fetchAll();
     $items[] = $item;
   }
 
@@ -180,7 +180,7 @@ function aggregator_categorize_items($items, $feed_source = '') {
   foreach ($items as $item) {
     $form['items'][$item->iid] = array('#markup' => theme('aggregator_item', array('item' => $item)));
     $form['categories'][$item->iid] = array();
-    $categories_result = db_query('SELECT c.cid, c.title, ci.iid FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid AND ci.iid = :iid', array(':iid' => $item->iid));
+    $categories_result = db_static_query('SELECT c.cid, c.title, ci.iid FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid AND ci.iid = :iid', array(':iid' => $item->iid));
     $selected = array();
     foreach ($categories_result as $category) {
       if (!$done) {
@@ -306,7 +306,7 @@ function template_preprocess_aggregator_item(&$variables) {
  * Menu callback; displays all the feeds used by the aggregator.
  */
 function aggregator_page_sources() {
-  $result = db_query('SELECT f.fid, f.title, f.description, f.image, MAX(i.timestamp) AS last FROM {aggregator_feed} f LEFT JOIN {aggregator_item} i ON f.fid = i.fid GROUP BY f.fid, f.title, f.description, f.image ORDER BY last DESC, f.title');
+  $result = db_static_query('SELECT f.fid, f.title, f.description, f.image, MAX(i.timestamp) AS last FROM {aggregator_feed} f LEFT JOIN {aggregator_item} i ON f.fid = i.fid GROUP BY f.fid, f.title, f.description, f.image ORDER BY last DESC, f.title');
 
   $output = '';
   foreach ($result as $feed) {
@@ -330,7 +330,7 @@ function aggregator_page_sources() {
  * Menu callback; displays all the categories used by the aggregator.
  */
 function aggregator_page_categories() {
-  $result = db_query('SELECT c.cid, c.title, c.description FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid LEFT JOIN {aggregator_item} i ON ci.iid = i.iid GROUP BY c.cid, c.title, c.description');
+  $result = db_static_query('SELECT c.cid, c.title, c.description FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid LEFT JOIN {aggregator_item} i ON ci.iid = i.iid GROUP BY c.cid, c.title, c.description');
 
   $output = '';
   foreach ($result as $category) {
@@ -355,7 +355,7 @@ function aggregator_page_rss() {
   $result = NULL;
   // arg(2) is the passed cid, only select for that category.
   if (arg(2)) {
-    $category = db_query('SELECT cid, title FROM {aggregator_category} WHERE cid = :cid', array(':cid' => arg(2)))->fetchObject();
+    $category = db_static_query('SELECT cid, title FROM {aggregator_category} WHERE cid = :cid', array(':cid' => arg(2)))->fetchObject();
     $result = db_query_range('SELECT i.*, f.title AS ftitle, f.link AS flink FROM {aggregator_category_item} c LEFT JOIN {aggregator_item} i ON c.iid = i.iid LEFT JOIN {aggregator_feed} f ON i.fid = f.fid WHERE cid = :cid ORDER BY timestamp DESC, i.iid DESC', 0, variable_get('feed_default_items', 10), array(':cid' => $category->cid));
   }
   // Or, get the default aggregator items.
@@ -426,10 +426,10 @@ function theme_aggregator_page_rss($variables) {
  */
 function aggregator_page_opml($cid = NULL) {
   if ($cid) {
-    $result = db_query('SELECT f.title, f.url FROM {aggregator_feed} f LEFT JOIN {aggregator_category_feed} c on f.fid = c.fid WHERE c.cid = :cid ORDER BY title', array(':cid' => $cid));
+    $result = db_static_query('SELECT f.title, f.url FROM {aggregator_feed} f LEFT JOIN {aggregator_category_feed} c on f.fid = c.fid WHERE c.cid = :cid ORDER BY title', array(':cid' => $cid));
   }
   else {
-    $result = db_query('SELECT * FROM {aggregator_feed} ORDER BY title');
+    $result = db_static_query('SELECT * FROM {aggregator_feed} ORDER BY title');
   }
 
   $feeds = $result->fetchAll();
diff --git modules/aggregator/aggregator.processor.inc modules/aggregator/aggregator.processor.inc
index 2888e2f..28d0664 100644
--- modules/aggregator/aggregator.processor.inc
+++ modules/aggregator/aggregator.processor.inc
@@ -27,13 +27,13 @@ function aggregator_aggregator_process($feed) {
         // we find a duplicate entry, we resolve it and pass along its ID is such
         // that we can update it if needed.
         if (!empty($item['guid'])) {
-          $entry = db_query("SELECT iid, timestamp FROM {aggregator_item} WHERE fid = :fid AND guid = :guid", array(':fid' => $feed->fid, ':guid' => $item['guid']))->fetchObject();
+          $entry = db_static_query("SELECT iid, timestamp FROM {aggregator_item} WHERE fid = :fid AND guid = :guid", array(':fid' => $feed->fid, ':guid' => $item['guid']))->fetchObject();
         }
         elseif ($item['link'] && $item['link'] != $feed->link && $item['link'] != $feed->url) {
-          $entry = db_query("SELECT iid, timestamp FROM {aggregator_item} WHERE fid = :fid AND link = :link", array(':fid' => $feed->fid, ':link' => $item['link']))->fetchObject();
+          $entry = db_static_query("SELECT iid, timestamp FROM {aggregator_item} WHERE fid = :fid AND link = :link", array(':fid' => $feed->fid, ':link' => $item['link']))->fetchObject();
         }
         else {
-          $entry = db_query("SELECT iid, timestamp FROM {aggregator_item} WHERE fid = :fid AND title = :title", array(':fid' => $feed->fid, ':title' => $item['title']))->fetchObject();
+          $entry = db_static_query("SELECT iid, timestamp FROM {aggregator_item} WHERE fid = :fid AND title = :title", array(':fid' => $feed->fid, ':title' => $item['title']))->fetchObject();
         }
         if (!$item['timestamp']) {
           $item['timestamp'] = isset($entry->timestamp) ? $entry->timestamp : REQUEST_TIME;
@@ -48,7 +48,7 @@ function aggregator_aggregator_process($feed) {
  * Implements hook_aggregator_remove().
  */
 function aggregator_aggregator_remove($feed) {
-  $iids = db_query('SELECT iid FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchCol();
+  $iids = db_static_query('SELECT iid FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchCol();
   if ($iids) {
     db_delete('aggregator_category_item')
       ->condition('iid', $iids, 'IN')
@@ -159,7 +159,7 @@ function aggregator_save_item($edit) {
   }
   elseif ($edit['title'] && $edit['link']) {
     // file the items in the categories indicated by the feed
-    $result = db_query('SELECT cid FROM {aggregator_category_feed} WHERE fid = :fid', array(':fid' => $edit['fid']));
+    $result = db_static_query('SELECT cid FROM {aggregator_category_feed} WHERE fid = :fid', array(':fid' => $edit['fid']));
     foreach ($result as $category) {
       db_merge('aggregator_category_item')
         ->key(array('iid' => $edit['iid']))
@@ -183,7 +183,7 @@ function aggregator_expire($feed) {
   if ($aggregator_clear != AGGREGATOR_CLEAR_NEVER) {
     // Remove all items that are older than flush item timer.
     $age = REQUEST_TIME - $aggregator_clear;
-    $iids = db_query('SELECT iid FROM {aggregator_item} WHERE fid = :fid AND timestamp < :timestamp', array(
+    $iids = db_static_query('SELECT iid FROM {aggregator_item} WHERE fid = :fid AND timestamp < :timestamp', array(
       ':fid' => $feed->fid,
       ':timestamp' => $age,
     ))
diff --git modules/aggregator/aggregator.test modules/aggregator/aggregator.test
index 93e77f9..884e167 100644
--- modules/aggregator/aggregator.test
+++ modules/aggregator/aggregator.test
@@ -28,7 +28,7 @@ class AggregatorTestCase extends DrupalWebTestCase {
     $this->drupalPost('admin/config/services/aggregator/add/feed', $edit, t('Save'));
     $this->assertRaw(t('The feed %name has been added.', array('%name' => $edit['title'])), t('The feed !name has been added.', array('!name' => $edit['title'])));
 
-    $feed = db_query("SELECT *  FROM {aggregator_feed} WHERE title = :title AND url = :url", array(':title' => $edit['title'], ':url' => $edit['url']))->fetch();
+    $feed = db_static_query("SELECT *  FROM {aggregator_feed} WHERE title = :title AND url = :url", array(':title' => $edit['title'], ':url' => $edit['url']))->fetch();
     $this->assertTrue(!empty($feed), t('The feed found in database.'));
     return $feed;
   }
@@ -97,7 +97,7 @@ class AggregatorTestCase extends DrupalWebTestCase {
     $this->drupalGet('admin/config/services/aggregator/update/' . $feed->fid);
 
     // Ensure we have the right number of items.
-    $result = db_query('SELECT iid FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid));
+    $result = db_static_query('SELECT iid FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid));
     $items = array();
     $feed->items = array();
     foreach ($result as $item) {
@@ -128,10 +128,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_static_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchField();
     $this->assertTrue($count);
     $this->removeFeedItems($feed);
-    $count = db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchField();
+    $count = db_static_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchField();
     $this->assertTrue($count == 0);
   }
 
@@ -143,7 +143,7 @@ class AggregatorTestCase extends DrupalWebTestCase {
    */
   function getFeedCategories($feed) {
     // add the categories to the feed so we can use them
-    $result = db_query('SELECT cid FROM {aggregator_category_feed} WHERE fid = :fid', array(':fid' => $feed->fid));
+    $result = db_static_query('SELECT cid FROM {aggregator_category_feed} WHERE fid = :fid', array(':fid' => $feed->fid));
     foreach ($result as $category) {
       $feed->categories[] = $category->cid;
     }
@@ -160,7 +160,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_static_query("SELECT COUNT(*) FROM {aggregator_feed} WHERE title = :title AND url = :url", array(':title' => $feed_name, ':url' => $feed_url))->fetchField();
     return (1 == $result);
   }
 
@@ -356,7 +356,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_static_query("SELECT COUNT(*) FROM {aggregator_feed} WHERE title = :title AND url = :url", array(':title' => $feed->title, ':url' => $feed->url))->fetchField();
     $this->assertFalse($result, t('Feed not found in database'));
   }
 }
@@ -398,10 +398,10 @@ class UpdateFeedItemTestCase extends AggregatorTestCase {
     $this->drupalPost('admin/config/services/aggregator/add/feed', $edit, t('Save'));
     $this->assertRaw(t('The feed %name has been added.', array('%name' => $edit['title'])), t('The feed !name has been added.', array('!name' => $edit['title'])));
 
-    $feed = db_query("SELECT * FROM {aggregator_feed} WHERE url = :url", array(':url' => $edit['url']))->fetchObject();
+    $feed = db_static_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_static_query('SELECT timestamp FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchField();
 
     // Sleep for 3 second.
     sleep(3);
@@ -416,7 +416,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_static_query('SELECT timestamp FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchField();
 
     $this->assertTrue($before === $after, t('Publish timestamp of feed item was not updated (!before === !after)', array('!before' => $before, '!after' => $after)));
   }
@@ -481,11 +481,11 @@ class CategorizeFeedItemTestCase extends AggregatorTestCase {
     $this->drupalPost('admin/config/services/aggregator/add/category', $edit, t('Save'));
     $this->assertRaw(t('The category %title has been added.', array('%title' => $edit['title'])), t('The category %title has been added.', array('%title' => $edit['title'])));
 
-    $category = db_query("SELECT * FROM {aggregator_category} WHERE title = :title", array(':title' => $edit['title']))->fetch();
+    $category = db_static_query("SELECT * FROM {aggregator_category} WHERE title = :title", array(':title' => $edit['title']))->fetch();
     $this->assertTrue(!empty($category), t('The category found in database.'));
 
     $link_path = 'aggregator/categories/' . $category->cid;
-    $menu_link = db_query("SELECT * FROM {menu_links} WHERE link_path = :link_path", array(':link_path' => $link_path))->fetch();
+    $menu_link = db_static_query("SELECT * FROM {menu_links} WHERE link_path = :link_path", array(':link_path' => $link_path))->fetch();
     $this->assertTrue(!empty($menu_link), t('The menu link associated with the category found in database.'));
 
     $feed = $this->createFeed();
@@ -552,7 +552,7 @@ class ImportOPMLTestCase extends AggregatorTestCase {
    * Submit form filled with invalid fields.
    */
   function validateImportFormFields() {
-    $before = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField();
+    $before = db_static_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField();
 
     $edit = array();
     $this->drupalPost('admin/config/services/aggregator/add/opml', $edit, t('Import'));
@@ -570,7 +570,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_static_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField();
     $this->assertEqual($before, $after, t('No feeds were added during the three last form submissions.'));
   }
 
@@ -578,7 +578,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_static_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField();
 
     $form['files[upload]'] = $this->getInvalidOpml();
     $this->drupalPost('admin/config/services/aggregator/add/opml', $form, t('Import'));
@@ -588,7 +588,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_static_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField();
     $this->assertEqual($before, $after, t('No feeds were added during the two last form submissions.'));
 
     db_delete('aggregator_feed')->execute();
@@ -616,10 +616,10 @@ 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_static_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField();
     $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");
+    $feeds_from_db = db_static_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");
     $refresh = $category = TRUE;
     foreach ($feeds_from_db as $feed) {
       $title[$feed->url] = $feed->title;
@@ -660,11 +660,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_static_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchField(), '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_static_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchField(), '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_static_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchField(), 'Expected number of items in database.');
 
     // Test feed locking when queued for update.
     $this->removeFeedItems($feed);
@@ -675,7 +675,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_static_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchField(), 'Expected number of items in database.');
     db_update('aggregator_feed')
       ->condition('fid', $feed->fid)
       ->fields(array(
@@ -683,6 +683,6 @@ 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_static_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchField(), 'Expected number of items in database.');
   }
 }
diff --git modules/block/block.admin.inc modules/block/block.admin.inc
index 131b214..5820f56 100644
--- modules/block/block.admin.inc
+++ modules/block/block.admin.inc
@@ -230,7 +230,7 @@ function block_admin_configure($form, &$form_state, $module, $delta) {
   foreach (list_themes() as $key => $theme) {
     // Only display enabled themes
     if ($theme->status) {
-      $region = db_query("SELECT region FROM {block} WHERE module = :module AND delta = :delta AND theme = :theme", array(
+      $region = db_static_query("SELECT region FROM {block} WHERE module = :module AND delta = :delta AND theme = :theme", array(
         ':module' => $block->module,
         ':delta' => $block->delta,
         ':theme' => $key,
@@ -310,7 +310,7 @@ function block_admin_configure($form, &$form_state, $module, $delta) {
   }
 
   // Per-role visibility.
-  $default_role_options = db_query("SELECT rid FROM {block_role} WHERE module = :module AND delta = :delta", array(
+  $default_role_options = db_static_query("SELECT rid FROM {block_role} WHERE module = :module AND delta = :delta", array(
     ':module' => $block->module,
     ':delta' => $block->delta,
   ))->fetchCol();
diff --git modules/block/block.api.php modules/block/block.api.php
index cec9922..2a25728 100644
--- modules/block/block.api.php
+++ modules/block/block.api.php
@@ -258,7 +258,7 @@ function hook_block_view_MODULE_DELTA_alter(&$data, $block) {
 function hook_block_list_alter(&$blocks) {
   global $language, $theme_key;
 
-  $result = db_query('SELECT module, delta, language FROM {my_table}');
+  $result = db_static_query('SELECT module, delta, language FROM {my_table}');
   $block_languages = array();
   foreach ($result as $record) {
     $block_languages[$record->module][$record->delta][$record->language] = TRUE;
diff --git modules/block/block.install modules/block/block.install
index 8f6863a..4b2f30f 100644
--- modules/block/block.install
+++ modules/block/block.install
@@ -235,7 +235,7 @@ function block_update_7003() {
 function block_update_7004() {
   // Collect a list of themes with blocks.
   $themes_with_blocks = array();
-  $result = db_query("SELECT s.name FROM {system} s INNER JOIN {block} b ON s.name = b.theme WHERE s.type = 'theme' GROUP by s.name");
+  $result = db_static_query("SELECT s.name FROM {system} s INNER JOIN {block} b ON s.name = b.theme WHERE s.type = 'theme' GROUP by s.name");
 
   $insert = db_insert('block')->fields(array('module', 'delta', 'theme', 'status', 'weight', 'region', 'pages', 'cache'));
   foreach ($result as $theme) {
diff --git modules/block/block.module modules/block/block.module
index 3770bb2..7731a64 100644
--- modules/block/block.module
+++ modules/block/block.module
@@ -181,7 +181,7 @@ function _block_custom_theme($theme = NULL) {
 function block_block_info() {
   $blocks = array();
 
-  $result = db_query('SELECT bid, info FROM {block_custom} ORDER BY info');
+  $result = db_static_query('SELECT bid, info FROM {block_custom} ORDER BY info');
   foreach ($result as $block) {
     $blocks[$block->bid]['info'] = $block->info;
     // Not worth caching.
@@ -214,7 +214,7 @@ function block_block_save($delta = 0, $edit = array()) {
  * Generates the administrator-defined blocks for display.
  */
 function block_block_view($delta = 0, $edit = array()) {
-  $block = db_query('SELECT body, format FROM {block_custom} WHERE bid = :bid', array(':bid' => $delta))->fetchObject();
+  $block = db_static_query('SELECT body, format FROM {block_custom} WHERE bid = :bid', array(':bid' => $delta))->fetchObject();
   $data['content'] = check_markup($block->body, $block->format, '', TRUE);
   return $data;
 }
@@ -428,7 +428,7 @@ function _block_rehash($theme = NULL) {
  *   - format: Filter ID of the filter format for the body.
  */
 function block_custom_block_get($bid) {
-  return db_query("SELECT * FROM {block_custom} WHERE bid = :bid", array(':bid' => $bid))->fetchAssoc();
+  return db_static_query("SELECT * FROM {block_custom} WHERE bid = :bid", array(':bid' => $bid))->fetchAssoc();
 }
 
 /**
@@ -496,7 +496,7 @@ function block_form_user_profile_form_alter(&$form, &$form_state) {
   if ($form['#user_category'] == 'account') {
     $account = $form['#user'];
     $rids = array_keys($account->roles);
-    $result = db_query("SELECT DISTINCT b.* FROM {block} b LEFT JOIN {block_role} r ON b.module = r.module AND b.delta = r.delta WHERE b.status = 1 AND b.custom <> 0 AND (r.rid IN (:rids) OR r.rid IS NULL) ORDER BY b.weight, b.module", array(':rids' => $rids));
+    $result = db_static_query("SELECT DISTINCT b.* FROM {block} b LEFT JOIN {block_role} r ON b.module = r.module AND b.delta = r.delta WHERE b.status = 1 AND b.custom <> 0 AND (r.rid IN (:rids) OR r.rid IS NULL) ORDER BY b.weight, b.module", array(':rids' => $rids));
 
     $blocks = array();
     foreach ($result as $block) {
@@ -550,7 +550,7 @@ function block_theme_initialize($theme) {
   if (!$has_blocks) {
     $default_theme = variable_get('theme_default', 'garland');
     $regions = system_region_list($theme);
-    $result = db_query("SELECT * FROM {block} WHERE theme = :theme", array(':theme' => $default_theme), array('fetch' => PDO::FETCH_ASSOC));
+    $result = db_static_query("SELECT * FROM {block} WHERE theme = :theme", array(':theme' => $default_theme), array('fetch' => PDO::FETCH_ASSOC));
     foreach ($result as $block) {
       // If the region isn't supported by the theme, assign the block to the theme's default region.
       if (!array_key_exists($block['region'], $regions)) {
@@ -611,7 +611,7 @@ function block_list($region) {
  */
 function block_load($module, $delta) {
   if (isset($delta)) {
-    $block = db_query('SELECT * FROM {block} WHERE module = :module AND delta = :delta', array(':module' => $module, ':delta' => $delta))->fetchObject();
+    $block = db_static_query('SELECT * FROM {block} WHERE module = :module AND delta = :delta', array(':module' => $module, ':delta' => $delta))->fetchObject();
   }
 
   // If the block does not exist in the database yet return a stub block
@@ -665,7 +665,7 @@ function block_block_list_alter(&$blocks) {
 
   // Build an array of roles for each block.
   $block_roles = array();
-  $result = db_query('SELECT module, delta, rid FROM {block_role}');
+  $result = db_static_query('SELECT module, delta, rid FROM {block_role}');
   foreach ($result as $record) {
     $block_roles[$record->module][$record->delta][] = $record->rid;
   }
diff --git modules/block/block.test modules/block/block.test
index 0f9eaaf..0b90fbf 100644
--- modules/block/block.test
+++ modules/block/block.test
@@ -73,7 +73,7 @@ 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_static_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchField();
 
     // 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'));
@@ -100,7 +100,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_static_query("SELECT 1 FROM {block_role} WHERE module = :module AND delta = :delta", array(':module' => $custom_block['module'], ':delta' => $custom_block['delta']))->fetchField();
     $this->assertFalse($count, t('Table block_role being cleaned.'));
   }
 
@@ -118,7 +118,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_static_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchField();
     $edit = array();
     $edit['block_' . $bid . '[region]'] = $this->regions[1]['name'];
     $this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
@@ -157,7 +157,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_static_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchField();
     $block['module'] = 'block';
     $block['delta'] = $bid;
     $block['title'] = $title;
@@ -200,7 +200,7 @@ class BlockTestCase extends DrupalWebTestCase {
     // Set block title to confirm that interface works and override any custom titles.
     $this->drupalPost('admin/structure/block/manage/' . $block['module'] . '/' . $block['delta'] . '/configure', array('title' => $block['title']), t('Save block'));
     $this->assertText(t('The block configuration has been saved.'), t('Block title set.'));
-    $bid = db_query("SELECT bid FROM {block} WHERE module = :module AND delta = :delta", array(
+    $bid = db_static_query("SELECT bid FROM {block} WHERE module = :module AND delta = :delta", array(
       ':module' => $block['module'],
       ':delta' => $block['delta'],
     ))->fetchField();
@@ -309,7 +309,7 @@ class NewDefaultThemeBlocks extends DrupalWebTestCase {
 
     // Populate list of all blocks for matching against new theme.
     $blocks = array();
-    $result = db_query("SELECT * FROM {block} WHERE theme = 'garland'");
+    $result = db_static_query("SELECT * FROM {block} WHERE theme = 'garland'");
     foreach ($result as $block) {
       // $block->theme and $block->bid will not match, so remove them.
       unset($block->theme, $block->bid);
@@ -320,7 +320,7 @@ class NewDefaultThemeBlocks extends DrupalWebTestCase {
     // that Garland did.
     theme_enable(array('stark'));
     variable_set('theme_default', 'stark');
-    $result = db_query("SELECT * FROM {block} WHERE theme='stark'");
+    $result = db_static_query("SELECT * FROM {block} WHERE theme='stark'");
     foreach ($result as $block) {
       unset($block->theme, $block->bid);
       $this->assertEqual($blocks[$block->module][$block->delta], $block, t('Block %name matched', array('%name' => $block->module . '-' . $block->delta)));
@@ -543,7 +543,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_static_query("SELECT cache FROM {block} WHERE module = 'block_test'")->fetchField();
     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 modules/book/book.install modules/book/book.install
index bf932bb..aa9327c 100644
--- modules/book/book.install
+++ modules/book/book.install
@@ -19,7 +19,7 @@ function book_install() {
  */
 function book_uninstall() {
   // Delete menu links.
-  db_query("DELETE FROM {menu_links} WHERE module = 'book'");
+  db_static_query("DELETE FROM {menu_links} WHERE module = 'book'");
   menu_cache_clear_all();
 }
 
diff --git modules/book/book.module modules/book/book.module
index bea4a07..d872993 100644
--- modules/book/book.module
+++ modules/book/book.module
@@ -366,7 +366,7 @@ function book_get_books() {
 
   if (!isset($all_books)) {
     $all_books = array();
-    $nids = db_query("SELECT DISTINCT(bid) FROM {book}")->fetchCol();
+    $nids = db_static_query("SELECT DISTINCT(bid) FROM {book}")->fetchCol();
 
     if ($nids) {
       $query = db_select('book', 'b', array('fetch' => PDO::FETCH_ASSOC));
@@ -577,12 +577,12 @@ function _book_update_outline($node) {
   else {
     // Check in case the parent is not is this book; the book takes precedence.
     if (!empty($node->book['plid'])) {
-      $parent = db_query("SELECT * FROM {book} WHERE mlid = :mlid", array(
+      $parent = db_static_query("SELECT * FROM {book} WHERE mlid = :mlid", array(
         ':mlid' => $node->book['plid'],
       ))->fetchAssoc();
     }
     if (empty($node->book['plid']) || !$parent || $parent['bid'] != $node->book['bid']) {
-      $node->book['plid'] = db_query("SELECT mlid FROM {book} WHERE nid = :nid", array(
+      $node->book['plid'] = db_static_query("SELECT mlid FROM {book} WHERE nid = :nid", array(
         ':nid' => $node->book['bid'],
       ))->fetchField();
       $node->book['parent_mismatch'] = TRUE; // Likely when JS is disabled.
@@ -601,7 +601,7 @@ function _book_update_outline($node) {
         ->execute();
     }
     else {
-      if ($node->book['bid'] != db_query("SELECT bid FROM {book} WHERE nid = :nid", array(
+      if ($node->book['bid'] != db_static_query("SELECT bid FROM {book} WHERE nid = :nid", array(
           ':nid' => $node->nid,
         ))->fetchField()) {
         // Update the bid for this page and all children.
@@ -768,7 +768,7 @@ function book_menu_name($bid) {
  * Implements hook_node_load().
  */
 function book_node_load($nodes, $types) {
-  $result = db_query("SELECT * FROM {book} b INNER JOIN {menu_links} ml ON b.mlid = ml.mlid WHERE b.nid IN (:nids)", array(':nids' =>  array_keys($nodes)), array('fetch' => PDO::FETCH_ASSOC));
+  $result = db_static_query("SELECT * FROM {book} b INNER JOIN {menu_links} ml ON b.mlid = ml.mlid WHERE b.nid IN (:nids)", array(':nids' =>  array_keys($nodes)), array('fetch' => PDO::FETCH_ASSOC));
   foreach ($result as $record) {
     $nodes[$record['nid']]->book = $record;
     $nodes[$record['nid']]->book['href'] = $record['link_path'];
@@ -864,7 +864,7 @@ function book_node_delete($node) {
   if (!empty($node->book['bid'])) {
     if ($node->nid == $node->book['bid']) {
       // Handle deletion of a top-level post.
-      $result = db_query("SELECT b.nid FROM {menu_links} ml INNER JOIN {book} b on b.mlid = ml.mlid WHERE ml.plid = :plid", array(
+      $result = db_static_query("SELECT b.nid FROM {menu_links} ml INNER JOIN {book} b on b.mlid = ml.mlid WHERE ml.plid = :plid", array(
         ':plid' => $node->book['mlid']
       ));
       foreach ($result as $child) {
@@ -1211,7 +1211,7 @@ function book_node_type_update($type) {
  * Do not call when loading a node, since this function may call node_load().
  */
 function book_link_load($mlid) {
-  if ($item = db_query("SELECT * FROM {menu_links} ml INNER JOIN {book} b ON b.mlid = ml.mlid LEFT JOIN {menu_router} m ON m.path = ml.router_path WHERE ml.mlid = :mlid", array(
+  if ($item = db_static_query("SELECT * FROM {menu_links} ml INNER JOIN {book} b ON b.mlid = ml.mlid LEFT JOIN {menu_router} m ON m.path = ml.router_path WHERE ml.mlid = :mlid", array(
       ':mlid' => $mlid,
     ))->fetchAssoc()) {
     _menu_link_translate($item);
diff --git modules/comment/comment.admin.inc modules/comment/comment.admin.inc
index ddbdc8b..56c3081 100644
--- modules/comment/comment.admin.inc
+++ 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_static_query('SELECT subject FROM {comment} WHERE cid = :cid', array(':cid' => $cid))->fetchField();
       $form['comments'][$cid] = array('#type' => 'hidden', '#value' => $cid, '#prefix' => '<li>', '#suffix' => check_plain($subject) . '</li>');
       $comment_counter++;
     }
diff --git modules/comment/comment.api.php modules/comment/comment.api.php
index c7d2f6a..46082fb 100644
--- modules/comment/comment.api.php
+++ modules/comment/comment.api.php
@@ -53,7 +53,7 @@ function hook_comment_update($comment) {
  *  An array of comment objects indexed by cid.
  */
 function hook_comment_load($comments) {
-  $result = db_query('SELECT cid, foo FROM {mytable} WHERE cid IN (:cids)', array(':cids' => array_keys($comments)));
+  $result = db_static_query('SELECT cid, foo FROM {mytable} WHERE cid IN (:cids)', array(':cids' => array_keys($comments)));
   foreach ($result as $record) {
     $comments[$record->cid]->foo = $record->foo;
   }
diff --git modules/comment/comment.install modules/comment/comment.install
index b7a2490..0142bc7 100644
--- modules/comment/comment.install
+++ modules/comment/comment.install
@@ -196,7 +196,7 @@ function comment_update_7007() {
 
   // Migrate the data.
   // @todo db_update() should support this.
-  db_query('UPDATE {comment} SET created = changed');
+  db_static_query('UPDATE {comment} SET created = changed');
 
   // Recreate the indexes.
   // The 'comment_num_new' index is optimized for comment_num_new()
diff --git modules/comment/comment.module modules/comment/comment.module
index 66ccef6..5090729 100644
--- modules/comment/comment.module
+++ modules/comment/comment.module
@@ -308,7 +308,7 @@ function comment_menu_alter(&$items) {
  * Returns a menu title which includes the number of unapproved comments.
  */
 function comment_count_unpublished() {
-  $count = db_query('SELECT COUNT(cid) FROM {comment} WHERE status = :status', array(
+  $count = db_static_query('SELECT COUNT(cid) FROM {comment} WHERE status = :status', array(
     ':status' => COMMENT_NOT_PUBLISHED,
   ))->fetchField();
   return t('Unapproved comments (@count)', array('@count' => $count));
@@ -555,7 +555,7 @@ function comment_new_page_count($num_comments, $new_replies, $node) {
     $first_thread = substr($first_thread, 0, -1);
 
     // Find the number of the first comment of the first unread thread.
-    $count = db_query('SELECT COUNT(*) FROM {comment} WHERE nid = :nid AND status = :status AND SUBSTRING(thread, 1, (LENGTH(thread) - 1)) < :thread', array(
+    $count = db_static_query('SELECT COUNT(*) FROM {comment} WHERE nid = :nid AND status = :status AND SUBSTRING(thread, 1, (LENGTH(thread) - 1)) < :thread', array(
       ':status' => COMMENT_PUBLISHED,
       ':nid' => $node->nid,
       ':thread' => $first_thread,
@@ -1155,7 +1155,7 @@ function comment_form_alter(&$form, $form_state, $form_id) {
        ),
       '#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_static_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = :nid', array(':nid' => $node->nid))->fetchField() : 0;
     $comment_settings = ($node->comment == COMMENT_NODE_HIDDEN && empty($comment_count)) ? COMMENT_NODE_CLOSED : $node->comment;
     $form['comment_settings']['comment'] = array(
       '#type' => 'radios',
@@ -1227,7 +1227,7 @@ function comment_node_load($nodes, $types) {
 
   // For nodes with comments enabled, fetch information from the database.
   if (!empty($comments_enabled)) {
-    $result = db_query('SELECT nid, cid, last_comment_timestamp, last_comment_name, comment_count FROM {node_comment_statistics} WHERE nid IN (:comments_enabled)', array(':comments_enabled' => $comments_enabled));
+    $result = db_static_query('SELECT nid, cid, last_comment_timestamp, last_comment_name, comment_count FROM {node_comment_statistics} WHERE nid IN (:comments_enabled)', array(':comments_enabled' => $comments_enabled));
     foreach ($result as $record) {
       $nodes[$record->nid]->cid = $record->cid;
       $nodes[$record->nid]->last_comment_timestamp = $record->last_comment_timestamp;
@@ -1270,7 +1270,7 @@ function comment_node_insert($node) {
  * Implements hook_node_delete().
  */
 function comment_node_delete($node) {
-  $cids = db_query('SELECT cid FROM {comment} WHERE nid = :nid', array(':nid' => $node->nid))->fetchCol();
+  $cids = db_static_query('SELECT cid FROM {comment} WHERE nid = :nid', array(':nid' => $node->nid))->fetchCol();
   comment_delete_multiple($cids);
   db_delete('node_comment_statistics')
     ->condition('nid', $node->nid)
@@ -1296,7 +1296,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_static_query('SELECT MAX(comment_count) FROM {node_comment_statistics}')->fetchField()));
 }
 
 /**
@@ -1308,7 +1308,7 @@ function comment_update_index() {
 function comment_node_search_result($node) {
   // Do not make a string if comments are hidden. 
   if ($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_static_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = :nid', array('nid' => $node->nid))->fetchField();
     // Do not make a string if comments are closed and there are currently
     // zero comments.
     if ($node->comment != COMMENT_NODE_CLOSED || $comments > 0) {
@@ -1350,7 +1350,7 @@ function comment_user_cancel($edit, $account, $method) {
  * Implements hook_user_delete().
  */
 function comment_user_delete($account) {
-  $cids = db_query('SELECT c.cid FROM {comment} c WHERE uid = :uid', array(':uid' => $account->uid))->fetchCol();
+  $cids = db_static_query('SELECT c.cid FROM {comment} c WHERE uid = :uid', array(':uid' => $account->uid))->fetchCol();
   comment_delete_multiple($cids);
 }
 
@@ -1445,7 +1445,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_static_query('SELECT MAX(thread) FROM {comment} WHERE nid = :nid', array(':nid' => $comment->nid))->fetchField();
         // Strip the "/" from the end of the thread.
         $max = rtrim($max, '/');
         // Finally, build the thread field for this new comment.
@@ -1460,7 +1460,7 @@ function comment_save($comment) {
         // Strip the "/" from the end of the parent thread.
         $parent->thread = (string) rtrim((string) $parent->thread, '/');
         // Get the max value in *this* thread.
-        $max = db_query("SELECT MAX(thread) FROM {comment} WHERE thread LIKE :thread AND nid = :nid", array(
+        $max = db_static_query("SELECT MAX(thread) FROM {comment} WHERE thread LIKE :thread AND nid = :nid", array(
           ':thread' => $parent->thread . '.%',
           ':nid' => $comment->nid,
         ))->fetchField();
@@ -1564,7 +1564,7 @@ function comment_delete_multiple($cids) {
       module_invoke_all('comment_delete', $comment);
 
       // Delete the comment's replies.
-      $child_cids = db_query('SELECT cid FROM {comment} WHERE pid = :cid', array(':cid' => $comment->cid))->fetchCol();
+      $child_cids = db_static_query('SELECT cid FROM {comment} WHERE pid = :cid', array(':cid' => $comment->cid))->fetchCol();
       comment_delete_multiple($child_cids);
       _comment_update_node_statistics($comment->nid);
     }
@@ -1651,7 +1651,7 @@ function comment_num_new($nid, $timestamp = 0) {
     $timestamp = ($timestamp > NODE_NEW_LIMIT ? $timestamp : NODE_NEW_LIMIT);
 
     // Use the timestamp to retrieve the number of new comments.
-    return db_query('SELECT COUNT(cid) FROM {comment} WHERE nid = :nid  AND created > :timestamp AND status = :status', array(
+    return db_static_query('SELECT COUNT(cid) FROM {comment} WHERE nid = :nid  AND created > :timestamp AND status = :status', array(
       ':nid' => $nid,
       ':timestamp' => $timestamp,
       ':status' => COMMENT_PUBLISHED,
@@ -2318,7 +2318,7 @@ function _comment_update_node_statistics($nid) {
     return;
   }
 
-  $count = db_query('SELECT COUNT(cid) FROM {comment} WHERE nid = :nid AND status = :status', array(
+  $count = db_static_query('SELECT COUNT(cid) FROM {comment} WHERE nid = :nid AND status = :status', array(
     ':nid' => $nid,
     ':status' => COMMENT_PUBLISHED,
   ))->fetchField();
@@ -2342,7 +2342,7 @@ function _comment_update_node_statistics($nid) {
   }
   else {
     // Comments do not exist.
-    $node = db_query('SELECT uid, created FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchObject();
+    $node = db_static_query('SELECT uid, created FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchObject();
     db_update('node_comment_statistics')
       ->fields(array(
         'cid' => 0,
@@ -2436,7 +2436,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_static_query('SELECT subject FROM {comment} WHERE cid = :cid', array(':cid', $cid))->fetchField();
     db_update('comment')
       ->fields(array('status' => COMMENT_PUBLISHED))
       ->condition('cid', $cid)
@@ -2463,7 +2463,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_static_query('SELECT subject FROM {comment} WHERE cid = :cid', array(':cid', $cid))->fetchField();
     db_update('comment')
       ->fields(array('status' => COMMENT_NOT_PUBLISHED))
       ->condition('cid', $cid)
diff --git modules/comment/comment.pages.inc modules/comment/comment.pages.inc
index 089825f..ca5555a 100644
--- modules/comment/comment.pages.inc
+++ modules/comment/comment.pages.inc
@@ -48,7 +48,7 @@ function comment_reply($node, $pid = NULL) {
       // $pid indicates that this is a reply to a comment.
       if ($pid) {
         // Load the comment whose cid = $pid
-        $comment = db_query('SELECT c.*, u.uid, u.name AS registered_name, u.signature, u.picture, u.data FROM {comment} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = :cid AND c.status = :status', array(
+        $comment = db_static_query('SELECT c.*, u.uid, u.name AS registered_name, u.signature, u.picture, u.data FROM {comment} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = :cid AND c.status = :status', array(
           ':cid' => $pid,
           ':status' => COMMENT_PUBLISHED,
         ))->fetchObject();
diff --git modules/contact/contact.pages.inc modules/contact/contact.pages.inc
index fa7e1bc..acfb4e6 100644
--- modules/contact/contact.pages.inc
+++ modules/contact/contact.pages.inc
@@ -32,7 +32,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_static_query("SELECT cid FROM {contact} WHERE selected = 1")->fetchField();
 
   // If there are no categories, do not display the form.
   if (!$categories) {
diff --git modules/contact/contact.test modules/contact/contact.test
index 80a157b..be12e73 100644
--- modules/contact/contact.test
+++ modules/contact/contact.test
@@ -72,7 +72,7 @@ class ContactSitewideTestCase extends DrupalWebTestCase {
     // Test update contact form category.
     $categories = $this->getCategories();
     $category_id = $this->updateCategory($categories, $category = $this->randomName(16), $recipients_str = implode(',', array($recipients[0], $recipients[1])), $reply = $this->randomName(30), FALSE);
-    $category_array = db_query("SELECT category, recipients, reply, selected FROM {contact} WHERE cid = :cid", array(':cid' => $category_id))->fetchAssoc();
+    $category_array = db_static_query("SELECT category, recipients, reply, selected FROM {contact} WHERE cid = :cid", array(':cid' => $category_id))->fetchAssoc();
     $this->assertEqual($category_array['category'], $category);
     $this->assertEqual($category_array['recipients'], $recipients_str);
     $this->assertEqual($category_array['reply'], $reply);
@@ -101,7 +101,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_static_query("SELECT COUNT(*) FROM {flood}")->fetchField();
     $this->assertIdentical($num_records_after, '0', t('Flood table emptied.'));
     $this->drupalLogout();
 
@@ -259,7 +259,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_static_query("SELECT category FROM {contact} WHERE cid = :cid", array(':cid' => $category))->fetchField();
       $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.'));
     }
@@ -271,7 +271,7 @@ class ContactSitewideTestCase extends DrupalWebTestCase {
    * @return array Category ids.
    */
   function getCategories() {
-    $categories = db_query('SELECT cid FROM {contact}')->fetchCol();
+    $categories = db_static_query('SELECT cid FROM {contact}')->fetchCol();
     return $categories;
   }
 }
@@ -376,7 +376,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_static_query("SELECT COUNT(*) FROM {flood}")->fetchField();
     $this->assertIdentical($num_records_flood, '0', 'Flood table emptied.');
 
     $this->drupalLogin($this->web_user);
diff --git modules/dashboard/dashboard.module modules/dashboard/dashboard.module
index 76a7e2d..ae44996 100644
--- modules/dashboard/dashboard.module
+++ modules/dashboard/dashboard.module
@@ -310,7 +310,7 @@ function dashboard_show_block_content($module, $delta) {
   global $theme_key;
 
   $blocks = array();
-  $block_object = db_query("SELECT * FROM {block} WHERE theme = :theme AND module = :module AND delta = :delta", array(
+  $block_object = db_static_query("SELECT * FROM {block} WHERE theme = :theme AND module = :module AND delta = :delta", array(
     ":theme" => $theme_key,
     ":module" => $module,
     ":delta" => $delta,
diff --git modules/dblog/dblog.admin.inc modules/dblog/dblog.admin.inc
index bc09b5f..a719d59 100644
--- modules/dblog/dblog.admin.inc
+++ modules/dblog/dblog.admin.inc
@@ -140,7 +140,7 @@ function dblog_top($type) {
  */
 function dblog_event($id) {
   $severity = watchdog_severity_levels();
-  $result = db_query('SELECT w.*, u.name, u.uid FROM {watchdog} w INNER JOIN {users} u ON w.uid = u.uid WHERE w.wid = :id', array(':id' => $id))->fetchObject();
+  $result = db_static_query('SELECT w.*, u.name, u.uid FROM {watchdog} w INNER JOIN {users} u ON w.uid = u.uid WHERE w.wid = :id', array(':id' => $id))->fetchObject();
   if ($dblog = $result) {
     $rows = array(
       array(
diff --git modules/dblog/dblog.module modules/dblog/dblog.module
index d27507d..29a5434 100644
--- modules/dblog/dblog.module
+++ modules/dblog/dblog.module
@@ -101,7 +101,7 @@ function dblog_cron() {
 function _dblog_get_message_types() {
   $types = array();
 
-  $result = db_query('SELECT DISTINCT(type) FROM {watchdog} ORDER BY type');
+  $result = db_static_query('SELECT DISTINCT(type) FROM {watchdog} ORDER BY type');
   foreach ($result as $object) {
     $types[] = $object->type;
   }
diff --git modules/dblog/dblog.test modules/dblog/dblog.test
index 92f0dd4..dc74063 100644
--- modules/dblog/dblog.test
+++ modules/dblog/dblog.test
@@ -57,7 +57,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_static_query("SELECT value FROM {variable} WHERE name = :dblog_limit", array(':dblog_limit' => 'dblog_row_limit'))->fetchField());
     $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)));
   }
 
@@ -70,13 +70,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_static_query('SELECT COUNT(wid) FROM {watchdog}')->fetchField();
     $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_static_query('SELECT COUNT(wid) FROM {watchdog}')->fetchField();
     $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)));
   }
 
@@ -199,7 +199,7 @@ class DBLogTestCase extends DrupalWebTestCase {
     // Logout user.
     $this->drupalLogout();
     // Fetch row ids in watchdog that relate to the user.
-    $result = db_query('SELECT wid FROM {watchdog} WHERE uid = :uid', array(':uid' => $user->uid));
+    $result = db_static_query('SELECT wid FROM {watchdog} WHERE uid = :uid', array(':uid' => $user->uid));
     foreach ($result as $row) {
       $ids[] = $row->wid;
     }
@@ -375,7 +375,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_static_query('SELECT COUNT(*) FROM {watchdog}')->fetchField();
     $log = array(
       'type'        => 'custom',
       'message'     => 'Log entry added to test the doClearTest clear down.',
@@ -391,13 +391,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_static_query('SELECT COUNT(*) FROM {watchdog}')->fetchField(), 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_static_query('SELECT COUNT(*) FROM {watchdog}')->fetchField();
     $this->assertEqual($count, 0, t('DBLog contains :count records after a clear.', array(':count' => $count)));
   }
 
diff --git modules/field/modules/field_sql_storage/field_sql_storage.test modules/field/modules/field_sql_storage/field_sql_storage.test
index 6af10a0..d60c6a3 100644
--- modules/field/modules/field_sql_storage/field_sql_storage.test
+++ modules/field/modules/field_sql_storage/field_sql_storage.test
@@ -44,8 +44,8 @@ class FieldSqlStorageTestCase extends DrupalWebTestCase {
     $this->assertEqual($t1+1, $t2, 'Entity type ids are sequential');
     $this->assertIdentical(variable_get('field_sql_storage_t1_etid', NULL), $t1, 'First entity type variable is correct');
     $this->assertIdentical(variable_get('field_sql_storage_t2_etid', NULL), $t2, 'Second entity type variable is correct');
-    $this->assertEqual(db_query("SELECT etid FROM {field_config_entity_type} WHERE type='t1'")->fetchField(), $t1, 'First entity type in database is correct');
-    $this->assertEqual(db_query("SELECT etid FROM {field_config_entity_type} WHERE type='t2'")->fetchField(), $t2, 'Second entity type in database is correct');
+    $this->assertEqual(db_static_query("SELECT etid FROM {field_config_entity_type} WHERE type='t1'")->fetchField(), $t1, 'First entity type in database is correct');
+    $this->assertEqual(db_static_query("SELECT etid FROM {field_config_entity_type} WHERE type='t2'")->fetchField(), $t2, 'Second entity type in database is correct');
     $this->assertEqual($t1, _field_sql_storage_etid('t1'), '_field_sql_storage_etid returns the same value for the first entity type');
     $this->assertEqual($t2, _field_sql_storage_etid('t2'), '_field_sql_storage_etid returns the same value for the second entity type');
   }
diff --git modules/field/modules/text/text.test modules/field/modules/text/text.test
index 52f757e..7cf0ea7 100644
--- modules/field/modules/text/text.test
+++ modules/field/modules/text/text.test
@@ -202,7 +202,7 @@ class TextFieldTestCase extends DrupalWebTestCase {
     $this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration'));
     filter_formats_reset();
     $this->checkPermissions(array(), TRUE);
-    $format_id = db_query("SELECT format FROM {filter_format} WHERE name = :name", array(':name' => $edit['name']))->fetchField();
+    $format_id = db_static_query("SELECT format FROM {filter_format} WHERE name = :name", array(':name' => $edit['name']))->fetchField();
     $permission = filter_permission_name(filter_format_load($format_id));
     $rid = max(array_keys($this->web_user->roles));
     user_role_grant_permissions($rid, array($permission));
diff --git modules/field/tests/field.test modules/field/tests/field.test
index fa24ada..188f85c 100644
--- modules/field/tests/field.test
+++ modules/field/tests/field.test
@@ -1290,7 +1290,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_static_query('SELECT data FROM {field_config} WHERE field_name = :field_name', array(':field_name' => $field_definition['field_name']))->fetchField();
     $data = unserialize($data);
     $data['settings'] = array();
     db_update('field_config')
@@ -1327,7 +1327,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_static_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 = unserialize($data);
     $data['settings'] = array();
     $data['widget']['settings'] = 'unavailable_widget';
@@ -1986,7 +1986,7 @@ class FieldCrudTestCase extends FieldTestCase {
     $this->assertIdentical($mem['field_test_field_create_field'][0][0], $field_definition, 'hook_field_create_field() called with correct arguments.');
 
     // Read the raw record from the {field_config_instance} table.
-    $result = db_query('SELECT * FROM {field_config} WHERE field_name = :field_name', array(':field_name' => $field_definition['field_name']));
+    $result = db_static_query('SELECT * FROM {field_config} WHERE field_name = :field_name', array(':field_name' => $field_definition['field_name']));
     $record = $result->fetchAssoc();
     $record['data'] = unserialize($record['data']);
 
@@ -2437,7 +2437,7 @@ class FieldInstanceCrudTestCase extends FieldTestCase {
     field_create_instance($this->instance_definition);
 
     // Read the raw record from the {field_config_instance} table.
-    $result = db_query('SELECT * FROM {field_config_instance} WHERE field_name = :field_name AND bundle = :bundle', array(':field_name' => $this->instance_definition['field_name'], ':bundle' => $this->instance_definition['bundle']));
+    $result = db_static_query('SELECT * FROM {field_config_instance} WHERE field_name = :field_name AND bundle = :bundle', array(':field_name' => $this->instance_definition['field_name'], ':bundle' => $this->instance_definition['bundle']));
     $record = $result->fetchAssoc();
     $record['data'] = unserialize($record['data']);
 
diff --git modules/filter/filter.admin.inc modules/filter/filter.admin.inc
index d19fe7e..49664a4 100644
--- modules/filter/filter.admin.inc
+++ modules/filter/filter.admin.inc
@@ -274,7 +274,7 @@ function filter_admin_format_form_validate($form, &$form_state) {
   if (!isset($form_state['values']['format'])) {
     $format_name = trim($form_state['values']['name']);
     form_set_value($form['name'], $format_name, $form_state);
-    $result = db_query("SELECT format FROM {filter_format} WHERE name = :name", array(':name' => $format_name))->fetchField();
+    $result = db_static_query("SELECT format FROM {filter_format} WHERE name = :name", array(':name' => $format_name))->fetchField();
     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 modules/filter/filter.install modules/filter/filter.install
index 41108ea..1ef5c8b 100644
--- modules/filter/filter.install
+++ modules/filter/filter.install
@@ -189,7 +189,7 @@ function filter_update_7000() {
  * Break out "escape HTML filter" option to its own filter.
  */
 function filter_update_7001() {
-  $result = db_query("SELECT format FROM {filter_formats}")->fetchCol();
+  $result = db_static_query("SELECT format FROM {filter_formats}")->fetchCol();
   $insert = db_insert('filters')->fields(array('format', 'module', 'delta', 'weight'));
 
   foreach ($result as $format_id) {
@@ -278,7 +278,7 @@ function filter_update_7004() {
     ->execute();
 
   // Move filter settings from system variables into {filter}.settings.
-  $filters = db_query("SELECT * FROM {filter} WHERE module = :name", array(':name' => 'filter'));
+  $filters = db_static_query("SELECT * FROM {filter} WHERE module = :name", array(':name' => 'filter'));
   foreach ($filters as $filter) {
     $settings = array();
     if ($filter->name == 'filter_html') {
@@ -324,7 +324,7 @@ function filter_update_7005() {
   // Move role data from the filter system to the user permission system.
   $all_roles = array_keys(user_roles());
   $default_format = variable_get('filter_default_format', 1);
-  $result = db_query("SELECT * FROM {filter_format}");
+  $result = db_static_query("SELECT * FROM {filter_format}");
   foreach ($result as $format) {
     // We need to assign the default format to all roles (regardless of what
     // was stored in the database) to preserve the behavior of the site at the
@@ -345,7 +345,7 @@ function filter_update_7005() {
   // "Plain text".
   $start_name = 'Plain text';
   $format_name = $start_name;
-  while ($format = db_query('SELECT format FROM {filter_format} WHERE name = :name', array(':name' => $format_name))->fetchField()) {
+  while ($format = db_static_query('SELECT format FROM {filter_format} WHERE name = :name', array(':name' => $format_name))->fetchField()) {
     $id = empty($id) ? 2 : $id + 1;
     $format_name = $start_name . ' ' . $id;
   }
diff --git modules/filter/filter.module modules/filter/filter.module
index 21cc0fe..cdeea41 100644
--- modules/filter/filter.module
+++ modules/filter/filter.module
@@ -623,7 +623,7 @@ function filter_list_format($format_id) {
   $filter_info = filter_get_filters();
 
   if (!isset($filters['all'])) {
-    $result = db_query('SELECT * FROM {filter} ORDER BY weight, module, name');
+    $result = db_static_query('SELECT * FROM {filter} ORDER BY weight, module, name');
     foreach ($result as $record) {
       $filters['all'][$record->format][$record->name] = $record;
     }
diff --git modules/filter/filter.test modules/filter/filter.test
index fcc026d..f04d8ef 100644
--- modules/filter/filter.test
+++ modules/filter/filter.test
@@ -59,9 +59,9 @@ class FilterCRUDTestCase extends DrupalWebTestCase {
 
     // Delete the text format.
     filter_format_delete($format);
-    $db_format = db_query("SELECT * FROM {filter_format} WHERE format = :format", array(':format' => $format->format))->fetchObject();
+    $db_format = db_static_query("SELECT * FROM {filter_format} WHERE format = :format", array(':format' => $format->format))->fetchObject();
     $this->assertFalse($db_format, t('Database: Deleted text format no longer exists.'));
-    $db_filters = db_query("SELECT * FROM {filter} WHERE format = :format", array(':format' => $format->format))->fetchObject();
+    $db_filters = db_static_query("SELECT * FROM {filter} WHERE format = :format", array(':format' => $format->format))->fetchObject();
     $this->assertFalse($db_filters, t('Database: Filters for deleted text format no longer exist.'));
     $formats = filter_formats();
     $this->assertTrue(!isset($formats[$format->format]), t('filter_formats: Deleted text format no longer exists.'));
@@ -110,7 +110,7 @@ class FilterCRUDTestCase extends DrupalWebTestCase {
    */
   function verifyFilters($format) {
     // Verify filter database records.
-    $filters = db_query("SELECT * FROM {filter} WHERE format = :format", array(':format' => $format->format))->fetchAllAssoc('name');
+    $filters = db_static_query("SELECT * FROM {filter} WHERE format = :format", array(':format' => $format->format))->fetchAllAssoc('name');
     $format_filters = $format->filters;
     foreach ($filters as $name => $filter) {
       $t_args = array('%format' => $format->name, '%filter' => $name);
@@ -235,7 +235,7 @@ class FilterAdminTestCase extends DrupalWebTestCase {
     $this->drupalPost('admin/config/content/formats/' . $filtered, $edit, t('Save configuration'));
     $this->assertFieldByName('filters[filter_html][settings][allowed_html]', $edit['filters[filter_html][settings][allowed_html]'], t('Allowed HTML tag added.'));
 
-    $result = db_query('SELECT * FROM {cache_filter}')->fetchObject();
+    $result = db_static_query('SELECT * FROM {cache_filter}')->fetchObject();
     $this->assertFalse($result, t('Cache cleared.'));
 
     $elements = $this->xpath('//select[@name=:first]/following::select[@name=:second]', array(
@@ -258,7 +258,7 @@ class FilterAdminTestCase extends DrupalWebTestCase {
     ));
     $this->assertTrue(!empty($elements), t('Reorder confirmed in admin interface.'));
 
-    $result = db_query('SELECT * FROM {filter} WHERE format = :format ORDER BY weight ASC', array(':format' => $filtered));
+    $result = db_static_query('SELECT * FROM {filter} WHERE format = :format ORDER BY weight ASC', array(':format' => $filtered));
     $filters = array();
     foreach ($result as $filter) {
       if ($filter->name == $second_filter || $filter->name == $first_filter) {
@@ -362,7 +362,7 @@ class FilterAdminTestCase extends DrupalWebTestCase {
    *   An array containing filtered, full, and plain text format ids.
    */
   function checkFilterFormats() {
-    $result = db_query('SELECT format, name FROM {filter_format}');
+    $result = db_static_query('SELECT format, name FROM {filter_format}');
 
     $filtered = -1;
     $full = -1;
@@ -391,7 +391,7 @@ class FilterAdminTestCase extends DrupalWebTestCase {
    *   A text format object.
    */
   function getFormat($name) {
-    return db_query("SELECT * FROM {filter_format} WHERE name = :name", array(':name' => $name))->fetchObject();
+    return db_static_query("SELECT * FROM {filter_format} WHERE name = :name", array(':name' => $name))->fetchObject();
   }
 }
 
@@ -427,7 +427,7 @@ class FilterFormatAccessTestCase extends DrupalWebTestCase {
       $edit = array('name' => $this->randomName());
       $this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration'));
       $this->resetFilterCaches();
-      $format_id = db_query("SELECT format FROM {filter_format} WHERE name = :name", array(':name' => $edit['name']))->fetchField();
+      $format_id = db_static_query("SELECT format FROM {filter_format} WHERE name = :name", array(':name' => $edit['name']))->fetchField();
       $formats[] = filter_format_load($format_id);
     }
     list($this->allowed_format, $this->disallowed_format) = $formats;
@@ -580,7 +580,7 @@ class FilterDefaultFormatTestCase extends DrupalWebTestCase {
       $edit = array('name' => $this->randomName());
       $this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration'));
       $this->resetFilterCaches();
-      $format_id = db_query("SELECT format FROM {filter_format} WHERE name = :name", array(':name' => $edit['name']))->fetchField();
+      $format_id = db_static_query("SELECT format FROM {filter_format} WHERE name = :name", array(':name' => $edit['name']))->fetchField();
       $formats[] = filter_format_load($format_id);
     }
     list($first_format, $second_format) = $formats;
@@ -589,7 +589,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_static_query("SELECT MIN(weight) FROM {filter_format}")->fetchField();
     $edit = array();
     $edit['formats[' . $first_format->format . '][weight]'] = $minimum_weight - 2;
     $edit['formats[' . $second_format->format . '][weight]'] = $minimum_weight - 1;
@@ -1281,7 +1281,7 @@ class FilterHooksTestCase extends DrupalWebTestCase {
     $this->assertRaw(t('Added text format %format.', array('%format' => $name)), t('New format created.'));
     $this->assertText('hook_filter_format_insert invoked.', t('hook_filter_format_insert was invoked.'));
 
-    $format_id = db_query("SELECT format FROM {filter_format} WHERE name = :name", array(':name' => $name))->fetchField();
+    $format_id = db_static_query("SELECT format FROM {filter_format} WHERE name = :name", array(':name' => $name))->fetchField();
 
     // Update text format.
     $edit = array();
@@ -1301,7 +1301,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_static_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchField();
     $this->assertNotNull($bid, t('New block found in database'));
 
     // Delete the text format.
diff --git modules/forum/forum.install modules/forum/forum.install
index 1a48832..e4be7a3 100644
--- modules/forum/forum.install
+++ modules/forum/forum.install
@@ -291,5 +291,5 @@ function forum_update_7001() {
   );
   db_create_table('forum_index', $forum_index);
 
-  db_query('INSERT INTO {forum_index} (SELECT n.nid, n.title, f.tid, n.sticky, n.created, ncs.last_comment_timestamp, ncs.comment_count FROM {node} n INNER JOIN {forum} f on n.vid = f.vid INNER JOIN {node_comment_statistics} ncs ON n.nid = ncs.nid)');
+  db_static_query('INSERT INTO {forum_index} (SELECT n.nid, n.title, f.tid, n.sticky, n.created, ncs.last_comment_timestamp, ncs.comment_count FROM {node} n INNER JOIN {forum} f on n.vid = f.vid INNER JOIN {node_comment_statistics} ncs ON n.nid = ncs.nid)');
 }
diff --git modules/forum/forum.module modules/forum/forum.module
index ea7f77f..76809b1 100644
--- modules/forum/forum.module
+++ modules/forum/forum.module
@@ -356,7 +356,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_static_query('SELECT tid FROM {forum} WHERE nid=:nid', array(':nid' => $node->nid))->fetchField()) {
       if (!empty($node->forum_tid)) {
         db_update('forum')
           ->fields(array('tid' => $node->forum_tid))
@@ -902,7 +902,7 @@ function forum_get_topics($tid, $sortby, $forum_per_page) {
     $nids[] = $record->nid;
   }
   if ($nids) {
-    $result = db_query("SELECT n.title, n.nid, n.type, n.sticky, n.created, n.uid, n.comment AS comment_mode, ncs.*, f.tid AS forum_tid, u.name, IF (ncs.last_comment_uid != 0, u2.name, ncs.last_comment_name) AS last_comment_name FROM {node} n INNER JOIN {node_comment_statistics} ncs ON n.nid = ncs.nid INNER JOIN {forum} f ON n.vid = f.vid INNER JOIN {users} u ON n.uid = u.uid INNER JOIN {users} u2 ON ncs.last_comment_uid = u2.uid WHERE n.nid IN (:nids)", array(':nids' => $nids));
+    $result = db_static_query("SELECT n.title, n.nid, n.type, n.sticky, n.created, n.uid, n.comment AS comment_mode, ncs.*, f.tid AS forum_tid, u.name, IF (ncs.last_comment_uid != 0, u2.name, ncs.last_comment_name) AS last_comment_name FROM {node} n INNER JOIN {node_comment_statistics} ncs ON n.nid = ncs.nid INNER JOIN {forum} f ON n.vid = f.vid INNER JOIN {users} u ON n.uid = u.uid INNER JOIN {users} u2 ON ncs.last_comment_uid = u2.uid WHERE n.nid IN (:nids)", array(':nids' => $nids));
   }
   else {
     $result = array();
@@ -1177,7 +1177,7 @@ function _forum_user_last_visit($nid) {
   $history = &drupal_static(__FUNCTION__, array());
 
   if (empty($history)) {
-    $result = db_query('SELECT nid, timestamp FROM {history} WHERE uid = :uid', array(':uid' => $user->uid));
+    $result = db_static_query('SELECT nid, timestamp FROM {history} WHERE uid = :uid', array(':uid' => $user->uid));
     foreach ($result as $t) {
       $history[$t->nid] = $t->timestamp > NODE_NEW_LIMIT ? $t->timestamp : NODE_NEW_LIMIT;
     }
@@ -1209,7 +1209,7 @@ function _forum_get_topic_order($sortby) {
  *   The ID of the node to update.
  */
 function _forum_update_forum_index($nid) {
-  $count = db_query('SELECT COUNT(cid) FROM {comment} WHERE nid = :nid AND status = :status', array(
+  $count = db_static_query('SELECT COUNT(cid) FROM {comment} WHERE nid = :nid AND status = :status', array(
     ':nid' => $nid,
     ':status' => COMMENT_PUBLISHED,
   ))->fetchField();
@@ -1230,7 +1230,7 @@ function _forum_update_forum_index($nid) {
   }
   else {
     // Comments do not exist.
-    $node = db_query('SELECT uid, created FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchObject();
+    $node = db_static_query('SELECT uid, created FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchObject();
     db_update('forum_index')
       ->fields( array(
         'comment_count' => 0,
diff --git modules/forum/forum.test modules/forum/forum.test
index 2d8d8f9..daa6d5d 100644
--- modules/forum/forum.test
+++ modules/forum/forum.test
@@ -110,7 +110,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_static_query('SELECT COUNT(nid) FROM {node}')->fetchField();
     $this->assertEqual(0, $nid_count, t('A forum node was not created when missing a forum vocabulary.'));
 
     // Reset the defaults for future tests.
@@ -244,12 +244,12 @@ class ForumTestCase extends DrupalWebTestCase {
     $this->assertRaw(t('Created new @type %term.', array('%term' => $name, '@type' => t($type))), t(ucfirst($type) . ' was created'));
 
     // Verify forum.
-    $term = db_query("SELECT * FROM {taxonomy_term_data} t WHERE t.vid = :vid AND t.name = :name AND t.description = :desc", array(':vid' => variable_get('forum_nav_vocabulary', ''), ':name' => $name, ':desc' => $description))->fetchAssoc();
+    $term = db_static_query("SELECT * FROM {taxonomy_term_data} t WHERE t.vid = :vid AND t.name = :name AND t.description = :desc", array(':vid' => variable_get('forum_nav_vocabulary', ''), ':name' => $name, ':desc' => $description))->fetchAssoc();
     $this->assertTrue(!empty($term), 'The ' . $type . ' exists in the database');
 
     // 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_static_query("SELECT t.parent FROM {taxonomy_term_hierarchy} t WHERE t.tid = :tid", array(':tid' => $tid))->fetchField();
     $this->assertTrue($parent == $parent_tid, 'The ' . $type . ' is linked to its container');
 
     return $term;
@@ -404,7 +404,7 @@ class ForumTestCase extends DrupalWebTestCase {
       $this->assertRaw(t('Forum topic %title has been updated.', array('%title' => $edit["title"])), t('Forum node was edited'));
 
       // Verify topic was moved to a different forum.
-      $forum_tid = db_query("SELECT tid FROM {forum} WHERE nid = :nid AND vid = :vid", array(
+      $forum_tid = db_static_query("SELECT tid FROM {forum} WHERE nid = :nid AND vid = :vid", array(
         ':nid' => $node->nid,
         ':vid' => $node->vid,
       ))->fetchField();
diff --git modules/help/help.test modules/help/help.test
index db739f3..9f35c61 100644
--- modules/help/help.test
+++ modules/help/help.test
@@ -79,7 +79,7 @@ class HelpTestCase extends DrupalWebTestCase {
    */
   protected function getModuleList() {
     $this->modules = array();
-    $result = db_query("SELECT name, filename, info FROM {system} WHERE type = 'module' AND status = 1 ORDER BY weight ASC, filename ASC");
+    $result = db_static_query("SELECT name, filename, info FROM {system} WHERE type = 'module' AND status = 1 ORDER BY weight ASC, filename ASC");
     foreach ($result as $module) {
       if (file_exists($module->filename) && function_exists($module->name . '_help')) {
         $fullname = unserialize($module->info);
diff --git modules/locale/locale.admin.inc modules/locale/locale.admin.inc
index da4dcc3..f2023fd 100644
--- modules/locale/locale.admin.inc
+++ modules/locale/locale.admin.inc
@@ -201,7 +201,7 @@ function locale_languages_custom_form($form) {
  *   Language code of the language to edit.
  */
 function locale_languages_edit_form($form, &$form_state, $langcode) {
-  if ($language = db_query("SELECT * FROM {languages} WHERE language = :language", array(':language' => $langcode))->fetchObject()) {
+  if ($language = db_static_query("SELECT * FROM {languages} WHERE language = :language", array(':language' => $langcode))->fetchObject()) {
     _locale_languages_common_controls($form, $language);
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array(
@@ -294,7 +294,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_static_query("SELECT COUNT(*) FROM {languages} WHERE language = :language", array(':language' => $langcode))->fetchField()) != 0) {
     form_set_error('langcode', t('The language %language (%code) already exists.', array('%language' => $form_state['values']['name'], '%code' => $langcode)));
   }
 
@@ -357,13 +357,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_static_query("SELECT language FROM {languages} WHERE domain = :domain AND language <> :language", array(':domain' => $form_state['values']['domain'], ':language' => $form_state['values']['langcode']))->fetchField()) {
     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_static_query("SELECT language FROM {languages} WHERE prefix = :prefix AND language <> :language", array(':prefix' => $form_state['values']['prefix'], ':language' => $form_state['values']['langcode']))->fetchField()) {
     form_set_error('prefix', t('The prefix (%prefix) is already tied to a language (%language).', array('%prefix' => $form_state['values']['prefix'], '%language' => $duplicate->language)));
   }
 }
@@ -754,7 +754,7 @@ function locale_translate_overview_screen() {
   $headers = array_merge(array(t('Language')), array_values($groups));
 
   // Collect summaries of all source strings in all groups.
-  $sums = db_query("SELECT COUNT(*) AS strings, textgroup FROM {locales_source} GROUP BY textgroup");
+  $sums = db_static_query("SELECT COUNT(*) AS strings, textgroup FROM {locales_source} GROUP BY textgroup");
   $groupsums = array();
   foreach ($sums as $group) {
     $groupsums[$group->textgroup] = $group->strings;
@@ -770,7 +770,7 @@ function locale_translate_overview_screen() {
   }
 
   // Languages with at least one record in the locale table.
-  $translations = db_query("SELECT COUNT(*) AS translation, t.language, s.textgroup FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid GROUP BY textgroup, language");
+  $translations = db_static_query("SELECT COUNT(*) AS translation, t.language, s.textgroup FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid GROUP BY textgroup, language");
   foreach ($translations as $data) {
     $ratio = (!empty($groupsums[$data->textgroup]) && $data->translation > 0) ? round(($data->translation/$groupsums[$data->textgroup]) * 100.0, 2) : 0;
     $rows[$data->language][$data->textgroup] = $data->translation . '/' . $groupsums[$data->textgroup] . " ($ratio%)";
@@ -1118,7 +1118,7 @@ function locale_translate_export_po_form_submit($form, &$form_state) {
  */
 function locale_translate_edit_form($form, &$form_state, $lid) {
   // Fetch source string, if possible.
-  $source = db_query('SELECT source, context, textgroup, location FROM {locales_source} WHERE lid = :lid', array(':lid' => $lid))->fetchObject();
+  $source = db_static_query('SELECT source, context, textgroup, location FROM {locales_source} WHERE lid = :lid', array(':lid' => $lid))->fetchObject();
   if (!$source) {
     drupal_set_message(t('String not found.'), 'error');
     drupal_goto('admin/config/regional/translate/translate');
@@ -1170,7 +1170,7 @@ function locale_translate_edit_form($form, &$form_state, $lid) {
   }
 
   // Fetch translations and fill in default values in the form.
-  $result = db_query("SELECT DISTINCT translation, language FROM {locales_target} WHERE lid = :lid AND language <> :omit", array(':lid' => $lid, ':omit' => $omit));
+  $result = db_static_query("SELECT DISTINCT translation, language FROM {locales_target} WHERE lid = :lid AND language <> :omit", array(':lid' => $lid, ':omit' => $omit));
   foreach ($result as $translation) {
     $form['translations'][$translation->language]['#default_value'] = $translation->translation;
   }
@@ -1202,7 +1202,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_static_query("SELECT translation FROM {locales_target} WHERE lid = :lid AND language = :language", array(':lid' => $lid, ':language' => $key))->fetchField();
     if (!empty($value)) {
       // Only update or insert if we have a value to use.
       if (!empty($translation)) {
@@ -1258,7 +1258,7 @@ function locale_translate_edit_form_submit($form, &$form_state) {
  * String deletion confirmation page.
  */
 function locale_translate_delete_page($lid) {
-  if ($source = db_query('SELECT lid, source FROM {locales_source} WHERE lid = :lid', array(':lid' => $lid))->fetchObject()) {
+  if ($source = db_static_query('SELECT lid, source FROM {locales_source} WHERE lid = :lid', array(':lid' => $lid))->fetchObject()) {
     return drupal_get_form('locale_translate_delete_form', $source);
   }
   else {
diff --git modules/locale/locale.install modules/locale/locale.install
index 1bc877c..d890d2f 100644
--- modules/locale/locale.install
+++ modules/locale/locale.install
@@ -98,7 +98,7 @@ function locale_update_7002() {
 function locale_uninstall() {
   // Delete all JavaScript translation files.
   $locale_js_directory = 'public://' . variable_get('locale_js_directory', 'languages');
-  $files = db_query('SELECT language, javascript FROM {languages}');
+  $files = db_static_query('SELECT language, javascript FROM {languages}');
   foreach ($files as $file) {
     if (!empty($file->javascript)) {
       file_unmanaged_delete($locale_js_directory . '/' . $file->language . '_' . $file->javascript . '.js');
diff --git modules/locale/locale.module modules/locale/locale.module
index e122b9f..029afeb 100644
--- modules/locale/locale.module
+++ modules/locale/locale.module
@@ -650,7 +650,7 @@ function locale($string = NULL, $context = NULL, $langcode = NULL) {
         // Refresh database stored cache of translations for given language.
         // We only store short strings used in current version, to improve
         // performance and consume less memory.
-        $result = db_query("SELECT s.source, s.context, t.translation, t.language FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.textgroup = 'default' AND s.version = :version AND LENGTH(s.source) < 75", array(':language' => $langcode, ':version' => VERSION));
+        $result = db_static_query("SELECT s.source, s.context, t.translation, t.language FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.textgroup = 'default' AND s.version = :version AND LENGTH(s.source) < 75", array(':language' => $langcode, ':version' => VERSION));
         foreach ($result as $data) {
           $locale_t[$langcode][$data->context][$data->source] = (empty($data->translation) ? TRUE : $data->translation);
         }
@@ -664,7 +664,7 @@ function locale($string = NULL, $context = NULL, $langcode = NULL) {
   if (!isset($locale_t[$langcode][$context][$string])) {
 
     // We do not have this translation cached, so get it from the DB.
-    $translation = db_query("SELECT s.lid, t.translation, s.version FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.source = :source AND s.context = :context AND s.textgroup = 'default'", array(
+    $translation = db_static_query("SELECT s.lid, t.translation, s.version FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.source = :source AND s.context = :context AND s.textgroup = 'default'", array(
       ':language' => $langcode,
       ':source' => $string,
       ':context' => (string) $context,
diff --git modules/locale/locale.test modules/locale/locale.test
index ee73054..b2706f9 100644
--- modules/locale/locale.test
+++ modules/locale/locale.test
@@ -614,7 +614,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' => 7, '%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_static_query("SELECT plurals FROM {languages} WHERE language = 'fr'")->fetchField() == 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.'));
@@ -672,7 +672,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_static_query("SELECT plurals FROM {languages} WHERE language = 'fr'")->fetchField() == 2, t('Plural numbers untouched.'));
 
     // Try importing a .po file with overriding strings, and ensure existing
     // strings are overwritten.
@@ -693,7 +693,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_static_query("SELECT plurals FROM {languages} WHERE language = 'fr'")->fetchField() == 3, t('Plural numbers changed.'));
   }
 
   /**
@@ -1033,14 +1033,14 @@ class LocaleUninstallFunctionalTest extends DrupalWebTestCase {
     $user = $this->drupalCreateUser(array('translate interface', 'access administration pages'));
     $this->drupalLogin($user);
     $this->drupalGet('admin/config/regional/translate/translate');
-    $string = db_query('SELECT min(lid) AS lid FROM {locales_source} WHERE location LIKE :location AND textgroup = :textgroup', array(
+    $string = db_static_query('SELECT min(lid) AS lid FROM {locales_source} WHERE location LIKE :location AND textgroup = :textgroup', array(
       ':location' => '%.js%',
       ':textgroup' => 'default',
     ))->fetchObject();
     $edit = array('translations[fr]' => 'french translation');
     $this->drupalPost('admin/config/regional/translate/edit/' . $string->lid, $edit, t('Save translations'));
     _locale_rebuild_js('fr');
-    $file = db_query('SELECT javascript FROM {languages} WHERE language = :language', array(':language' => 'fr'))->fetchObject();
+    $file = db_static_query('SELECT javascript FROM {languages} WHERE language = :language', array(':language' => 'fr'))->fetchObject();
     $js_file = 'public://' . variable_get('locale_js_directory', 'languages') . '/fr_' . $file->javascript . '.js';
     $this->assertTrue($result = file_exists($js_file), t('JavaScript file created: %file', array('%file' => $result ? $js_file : t('none'))));
 
diff --git modules/menu/menu.admin.inc modules/menu/menu.admin.inc
index c0f6c14..170d7b6 100644
--- modules/menu/menu.admin.inc
+++ modules/menu/menu.admin.inc
@@ -10,7 +10,7 @@
  * Menu callback which shows an overview page of all the custom menus and their descriptions.
  */
 function menu_overview_page() {
-  $result = db_query("SELECT * FROM {menu_custom} ORDER BY title", array(), array('fetch' => PDO::FETCH_ASSOC));
+  $result = db_static_query("SELECT * FROM {menu_custom} ORDER BY title", array(), array('fetch' => PDO::FETCH_ASSOC));
   $header = array(t('Title'), array('data' => t('Operations'), 'colspan' => '3'));
   $rows = array();
   foreach ($result as $menu) {
@@ -55,7 +55,7 @@ function menu_overview_form($form, &$form_state, $menu) {
     FROM {menu_links} ml LEFT JOIN {menu_router} m ON m.path = ml.router_path
     WHERE ml.menu_name = :menu
     ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC, p6 ASC, p7 ASC, p8 ASC, p9 ASC";
-  $result = db_query($sql, array(':menu' => $menu['menu_name']), array('fetch' => PDO::FETCH_ASSOC));
+  $result = db_static_query($sql, array(':menu' => $menu['menu_name']), array('fetch' => PDO::FETCH_ASSOC));
   $links = array();
   foreach ($result as $item) {
     $links[] = $item;
@@ -514,7 +514,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_static_query("SELECT COUNT(*) FROM {menu_links} WHERE menu_name = :menu", array(':menu' => $menu['menu_name']))->fetchField();
   if ($num_links) {
     $caption .= '<p>' . format_plural($num_links, '<strong>Warning:</strong> There is currently 1 menu link in %title. It will be deleted (system-defined items will be reset).', '<strong>Warning:</strong> There are currently @count menu links in %title. They will be deleted (system-defined links will be reset).', array('%title' => $menu['title'])) . '</p>';
   }
@@ -531,18 +531,18 @@ 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_static_query("SELECT 1 FROM {menu_custom} WHERE menu_name = :menu", array(':menu' => $menu['menu_name']))->fetchField())) {
     return;
   }
 
   // Reset all the menu links defined by the system via hook_menu().
-  $result = db_query("SELECT * FROM {menu_links} ml INNER JOIN {menu_router} m ON ml.router_path = m.path WHERE ml.menu_name = :menu AND ml.module = 'system' ORDER BY m.number_parts ASC", array(':menu' => $menu['menu_name']), array('fetch' => PDO::FETCH_ASSOC));
+  $result = db_static_query("SELECT * FROM {menu_links} ml INNER JOIN {menu_router} m ON ml.router_path = m.path WHERE ml.menu_name = :menu AND ml.module = 'system' ORDER BY m.number_parts ASC", array(':menu' => $menu['menu_name']), array('fetch' => PDO::FETCH_ASSOC));
   foreach ($result as $link) {
     menu_reset_item($link);
   }
 
   // Delete all links to the overview page for this menu.
-  $result = db_query("SELECT mlid FROM {menu_links} ml WHERE ml.link_path = :link", array(':link' => 'admin/structure/menu/manage/' . $menu['menu_name']), array('fetch' => PDO::FETCH_ASSOC));
+  $result = db_static_query("SELECT mlid FROM {menu_links} ml WHERE ml.link_path = :link", array(':link' => 'admin/structure/menu/manage/' . $menu['menu_name']), array('fetch' => PDO::FETCH_ASSOC));
   foreach ($result as $link) {
     menu_link_delete($link['mlid']);
   }
@@ -591,7 +591,7 @@ function menu_edit_menu_submit($form, &$form_state) {
     $link['link_path'] = $path . $menu['menu_name'];
     $link['router_path'] = $path . '%';
     $link['module'] = 'menu';
-    $link['plid'] = db_query("SELECT mlid FROM {menu_links} WHERE link_path = :link AND module = :module", array(
+    $link['plid'] = db_static_query("SELECT mlid FROM {menu_links} WHERE link_path = :link AND module = :module", array(
       ':link' => 'admin/structure/menu',
       ':module' => 'system'
     ))
@@ -602,7 +602,7 @@ function menu_edit_menu_submit($form, &$form_state) {
   }
   else {
     menu_save($menu);
-    $result = db_query("SELECT mlid FROM {menu_links} WHERE link_path = :path", array(':path' => $path . $menu['menu_name']), array('fetch' => PDO::FETCH_ASSOC));
+    $result = db_static_query("SELECT mlid FROM {menu_links} WHERE link_path = :path", array(':path' => $path . $menu['menu_name']), array('fetch' => PDO::FETCH_ASSOC));
     foreach ($result as $m) {
       $link = menu_link_load($m['mlid']);
       $link['link_title'] = $menu['title'];
diff --git modules/menu/menu.module modules/menu/menu.module
index 1238154..803a9e6 100644
--- modules/menu/menu.module
+++ modules/menu/menu.module
@@ -179,17 +179,17 @@ function menu_theme() {
  */
 function menu_enable() {
   menu_rebuild();
-  $base_link = db_query("SELECT mlid AS plid, menu_name FROM {menu_links} WHERE link_path = 'admin/structure/menu' AND module = 'system'")->fetchAssoc();
+  $base_link = db_static_query("SELECT mlid AS plid, menu_name FROM {menu_links} WHERE link_path = 'admin/structure/menu' AND module = 'system'")->fetchAssoc();
   $base_link['router_path'] = 'admin/structure/menu/manage/%';
   $base_link['module'] = 'menu';
-  $result = db_query("SELECT * FROM {menu_custom}", array(), array('fetch' => PDO::FETCH_ASSOC));
+  $result = db_static_query("SELECT * FROM {menu_custom}", array(), array('fetch' => PDO::FETCH_ASSOC));
   foreach ($result as $menu) {
     // $link is passed by reference to menu_link_save(), so we make a copy of $base_link.
     $link = $base_link;
     $link['mlid'] = 0;
     $link['link_title'] = $menu['title'];
     $link['link_path'] = 'admin/structure/menu/manage/' . $menu['menu_name'];
-    $menu_link = db_query("SELECT mlid FROM {menu_links} WHERE link_path = :path AND plid = :plid", array(
+    $menu_link = db_static_query("SELECT mlid FROM {menu_links} WHERE link_path = :path AND plid = :plid", array(
       ':path' => $link['link_path'],
       ':plid' => $link['plid']
     ))
@@ -234,7 +234,7 @@ function menu_load_all() {
       $custom_menus = $cached->data;
     }
     else {
-      $custom_menus = db_query('SELECT * FROM {menu_custom}')->fetchAllAssoc('menu_name', PDO::FETCH_ASSOC);
+      $custom_menus = db_static_query('SELECT * FROM {menu_custom}')->fetchAllAssoc('menu_name', PDO::FETCH_ASSOC);
       cache_set('menu_custom', $custom_menus, 'cache_menu');
     }
   }
@@ -524,7 +524,7 @@ function menu_node_save($node) {
  */
 function menu_node_delete($node) {
   // Delete all menu module links that point to this node.
-  $result = db_query("SELECT mlid FROM {menu_links} WHERE link_path = :path AND module = 'menu'", array(':path' => 'node/' . $node->nid), array('fetch' => PDO::FETCH_ASSOC));
+  $result = db_static_query("SELECT mlid FROM {menu_links} WHERE link_path = :path AND module = 'menu'", array(':path' => 'node/' . $node->nid), array('fetch' => PDO::FETCH_ASSOC));
   foreach ($result as $m) {
     menu_link_delete($m['mlid']);
   }
diff --git modules/menu/menu.test modules/menu/menu.test
index d1b8226..d5d353a 100644
--- modules/menu/menu.test
+++ modules/menu/menu.test
@@ -180,7 +180,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_static_query("SELECT menu_name FROM {menu_links} WHERE menu_name = :menu_name", array(':menu_name' => $menu_name))->fetchField();
     $this->assertFalse($result, t('All menu links associated to the custom menu were deleted.'));
   }
 
@@ -219,7 +219,7 @@ class MenuTestCase extends DrupalWebTestCase {
     $this->drupalPost('admin/structure/menu/manage/' . $item1['menu_name'], $edit, t('Save configuration'));
 
     // Verify in the database.
-    $hidden = db_query("SELECT hidden FROM {menu_links} WHERE mlid = :mlid", array(':mlid' => $item1['mlid']))->fetchField();
+    $hidden = db_static_query("SELECT hidden FROM {menu_links} WHERE mlid = :mlid", array(':mlid' => $item1['mlid']))->fetchField();
     $this->assertEqual($hidden, 0, t('Link is not hidden in the database table when enabled via the overview form'));
 
     // Save menu links for later tests.
@@ -278,7 +278,7 @@ class MenuTestCase extends DrupalWebTestCase {
     $this->assertText($title, 'Menu link was added');
 
     // Retrieve menu link.
-    $item = db_query("SELECT * FROM {menu_links} WHERE link_title = :title", array(':title' => $title))->fetchAssoc();
+    $item = db_static_query("SELECT * FROM {menu_links} WHERE link_title = :title", array(':title' => $title))->fetchAssoc();
 
     // Check the structure in the DB of the two menu links.
     // In general, if $n = $item['depth'] then $item['p'. $n] == $item['mlid'] and $item['p' . ($n - 1)] == $item['plid'] (unless depth == 0).
@@ -453,7 +453,7 @@ class MenuTestCase extends DrupalWebTestCase {
 
     // Unlike most other modules, there is no confirmation message displayed.
     // Verify in the database.
-    $hidden = db_query("SELECT hidden FROM {menu_links} WHERE mlid = :mlid", array(':mlid' => $mlid))->fetchField();
+    $hidden = db_static_query("SELECT hidden FROM {menu_links} WHERE mlid = :mlid", array(':mlid' => $mlid))->fetchField();
     $this->assertEqual($hidden, 1, t('Link is hidden in the database table'));
   }
 
@@ -469,7 +469,7 @@ class MenuTestCase extends DrupalWebTestCase {
     $this->drupalPost("admin/structure/menu/item/$mlid/edit", $edit, t('Save'));
 
     // Verify in the database.
-    $hidden = db_query("SELECT hidden FROM {menu_links} WHERE mlid = :mlid", array(':mlid' => $mlid))->fetchField();
+    $hidden = db_static_query("SELECT hidden FROM {menu_links} WHERE mlid = :mlid", array(':mlid' => $mlid))->fetchField();
     $this->assertEqual($hidden, 0, t('Link is not hidden in the database table'));
   }
 
@@ -478,7 +478,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_static_query("SELECT mlid FROM {menu_links} WHERE module = 'system' AND router_path = 'user/logout'")->fetchField();
     $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 modules/node/content_types.inc modules/node/content_types.inc
index 812d680..fe299a6 100644
--- modules/node/content_types.inc
+++ modules/node/content_types.inc
@@ -435,7 +435,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_static_query("SELECT COUNT(*) FROM {node} WHERE type = :type", array(':type' => $type->type))->fetchField();
   if ($num_nodes) {
     $caption .= '<p>' . 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)) . '</p>';
   }
diff --git modules/node/node.admin.inc modules/node/node.admin.inc
index 15c0593..bf9db15 100644
--- modules/node/node.admin.inc
+++ modules/node/node.admin.inc
@@ -417,7 +417,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("SELECT COUNT(*) FROM {node} WHERE language <> :language", array(':language' => LANGUAGE_NONE))->fetchField());
+  $multilanguage = (module_exists('translation') || db_static_query("SELECT COUNT(*) FROM {node} WHERE language <> :language", array(':language' => LANGUAGE_NONE))->fetchField());
 
   // Build the sortable table header.
   $header = array(
@@ -439,7 +439,7 @@ function node_admin_nodes() {
     // If the user is able to view their own unpublished nodes, allow them
     // to see these in addition to published nodes. Check that they actually
     // have some unpublished nodes to view before adding the condition.
-    if (user_access('view own unpublished content') && $own_unpublished = db_query('SELECT nid FROM {node} WHERE uid = :uid AND status = :status', array(':uid' => $GLOBALS['user']->uid, ':status' => 0))->fetchCol()) {
+    if (user_access('view own unpublished content') && $own_unpublished = db_static_query('SELECT nid FROM {node} WHERE uid = :uid AND status = :status', array(':uid' => $GLOBALS['user']->uid, ':status' => 0))->fetchCol()) {
       $query->condition(db_or()
         ->condition('n.status', 1)
         ->condition('n.nid', $own_unpublished, 'IN')
@@ -593,7 +593,7 @@ function node_multiple_delete_confirm($form, &$form_state, $nodes) {
   $form['nodes'] = array('#prefix' => '<ul>', '#suffix' => '</ul>', '#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_static_query('SELECT title FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchField();
     $form['nodes'][$nid] = array(
       '#type' => 'hidden',
       '#value' => $nid,
diff --git modules/node/node.api.php modules/node/node.api.php
index 4bf6780..1111c3f 100644
--- modules/node/node.api.php
+++ modules/node/node.api.php
@@ -469,7 +469,7 @@ function hook_node_insert($node) {
  * @ingroup node_api_hooks
  */
 function hook_node_load($nodes, $types) {
-  $result = db_query('SELECT nid, foo FROM {mytable} WHERE nid IN(:nids)', array(':nids' => array_keys($nodes)));
+  $result = db_static_query('SELECT nid, foo FROM {mytable} WHERE nid IN(:nids)', array(':nids' => array_keys($nodes)));
   foreach ($result as $record) {
     $nodes[$record->nid]->foo = $record->foo;
   }
@@ -584,7 +584,7 @@ function hook_node_prepare_translation($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_static_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = :nid', array('nid' => $node->nid))->fetchField();
   return format_plural($comments, '1 comment', '@count comments');
 }
 
@@ -643,7 +643,7 @@ function hook_node_update($node) {
  */
 function hook_node_update_index($node) {
   $text = '';
-  $comments = db_query('SELECT subject, comment, format FROM {comment} WHERE nid = :nid AND status = :status', array(':nid' => $node->nid, ':status' => COMMENT_PUBLISHED));
+  $comments = db_static_query('SELECT subject, comment, format FROM {comment} WHERE nid = :nid AND status = :status', array(':nid' => $node->nid, ':status' => COMMENT_PUBLISHED));
   foreach ($comments as $comment) {
     $text .= '<h2>' . check_plain($comment->subject) . '</h2>' . check_markup($comment->comment, $comment->format, '', TRUE);
   }
@@ -1055,7 +1055,7 @@ function hook_insert($node) {
  * @ingroup node_api_hooks
  */
 function hook_load($nodes) {
-  $result = db_query('SELECT nid, foo FROM {mytable} WHERE nid IN (:nids)', array(':nids' => array_keys($nodes)));
+  $result = db_static_query('SELECT nid, foo FROM {mytable} WHERE nid IN (:nids)', array(':nids' => array_keys($nodes)));
   foreach ($result as $record) {
     $nodes[$record->nid]->foo = $record->foo;
   }
diff --git modules/node/node.module modules/node/node.module
index bc59ea9..b1bad71 100644
--- modules/node/node.module
+++ modules/node/node.module
@@ -324,7 +324,7 @@ function node_last_viewed($nid) {
   $history = &drupal_static(__FUNCTION__, array());
 
   if (!isset($history[$nid])) {
-    $history[$nid] = db_query("SELECT timestamp FROM {history} WHERE uid = :uid AND nid = :nid", array(':uid' => $user->uid, ':nid' => $nid))->fetchObject();
+    $history[$nid] = db_static_query("SELECT timestamp FROM {history} WHERE uid = :uid AND nid = :nid", array(':uid' => $user->uid, ':nid' => $nid))->fetchObject();
   }
 
   return (isset($history[$nid]->timestamp) ? $history[$nid]->timestamp : 0);
@@ -1499,8 +1499,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_static_query('SELECT COUNT(*) FROM {node}')->fetchField();
+  $remaining = db_static_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();
   return array('remaining' => $remaining, 'total' => $total);
 }
 
@@ -1676,7 +1676,7 @@ function node_user_delete($account) {
     ->fetchCol();
   node_delete_multiple($nodes);
   // Delete old revisions.
-  $revisions = db_query('SELECT vid FROM {node_revision} WHERE uid = :uid', array(':uid' => $account->uid))->fetchCol();
+  $revisions = db_static_query('SELECT vid FROM {node_revision} WHERE uid = :uid', array(':uid' => $account->uid))->fetchCol();
   foreach ($revisions as $revision) {
     node_revision_delete($revision);
   }
@@ -1733,7 +1733,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_static_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid', array(':nid' => $node->nid))->fetchField() == 1 || $op == 'update' || $op == 'delete')) {
       $access[$node->vid] = FALSE;
     }
     elseif (user_access('administer nodes')) {
@@ -2001,7 +2001,7 @@ function node_init() {
 }
 
 function node_last_changed($nid) {
-  return db_query('SELECT changed FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetch()->changed;
+  return db_static_query('SELECT changed FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetch()->changed;
 }
 
 /**
@@ -2009,7 +2009,7 @@ function node_last_changed($nid) {
  */
 function node_revision_list($node) {
   $revisions = array();
-  $result = db_query('SELECT r.vid, r.title, r.log, r.uid, n.vid AS current_vid, r.timestamp, u.name FROM {node_revision} r LEFT JOIN {node} n ON n.vid = r.vid INNER JOIN {users} u ON u.uid = r.uid WHERE r.nid = :nid ORDER BY r.vid DESC', array(':nid' => $node->nid));
+  $result = db_static_query('SELECT r.vid, r.title, r.log, r.uid, n.vid AS current_vid, r.timestamp, u.name FROM {node_revision} r LEFT JOIN {node} n ON n.vid = r.vid INNER JOIN {users} u ON u.uid = r.uid WHERE r.nid = :nid ORDER BY r.vid DESC', array(':nid' => $node->nid));
   foreach ($result as $revision) {
     $revisions[$revision->vid] = $revision;
   }
@@ -2100,7 +2100,7 @@ function node_get_recent($number = 10) {
     // If the user is able to view their own unpublished nodes, allow them
     // to see these in addition to published nodes. Check that they actually
     // have some unpublished nodes to view before adding the condition.
-    if (user_access('view own unpublished content') && $own_unpublished = db_query('SELECT nid FROM {node} WHERE uid = :uid AND status = :status', array(':uid' => $GLOBALS['user']->uid, ':status' => NODE_NOT_PUBLISHED))->fetchCol()) {
+    if (user_access('view own unpublished content') && $own_unpublished = db_static_query('SELECT nid FROM {node} WHERE uid = :uid AND status = :status', array(':uid' => $GLOBALS['user']->uid, ':status' => NODE_NOT_PUBLISHED))->fetchCol()) {
       $query->condition(db_or()
         ->condition('n.status', NODE_PUBLISHED)
         ->condition('n.nid', $own_unpublished, 'IN')
@@ -2206,7 +2206,7 @@ function node_form_block_add_block_form_alter(&$form, &$form_state) {
  * @see block_admin_configure()
  */
 function node_form_block_admin_configure_alter(&$form, &$form_state) {
-  $default_type_options = db_query("SELECT type FROM {block_node_type} WHERE module = :module AND delta = :delta", array(
+  $default_type_options = db_static_query("SELECT type FROM {block_node_type} WHERE module = :module AND delta = :delta", array(
     ':module' => $form['module']['#value'],
     ':delta' => $form['delta']['#value'],
   ))->fetchCol();
@@ -2294,7 +2294,7 @@ function node_block_list_alter(&$blocks) {
 
   // Build an array of node types for each block.
   $block_node_types = array();
-  $result = db_query('SELECT module, delta, type FROM {block_node_type}');
+  $result = db_static_query('SELECT module, delta, type FROM {block_node_type}');
   foreach ($result as $record) {
     $block_node_types[$record->module][$record->delta][$record->type] = TRUE;
   }
@@ -3208,7 +3208,7 @@ function node_access_rebuild($batch_mode = FALSE) {
       // Try to allocate enough time to rebuild node grants
       drupal_set_time_limit(240);
 
-      $nids = db_query("SELECT nid FROM {node}")->fetchCol();
+      $nids = db_static_query("SELECT nid FROM {node}")->fetchCol();
       foreach ($nids as $nid) {
         $node = node_load($nid, NULL, TRUE);
         // To preserve database integrity, only acquire grants if the node
@@ -3252,7 +3252,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_static_query('SELECT COUNT(DISTINCT nid) FROM {node}')->fetchField();
   }
 
   // Process the next 20 nodes.
@@ -3492,7 +3492,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_static_query("SELECT name FROM {users} WHERE uid = :uid", array(':uid' => $context['owner_uid']))->fetchField();
   watchdog('action', 'Changed owner of @type %title to uid %name.', array('@type' =>  node_type_get_type($node), '%title' => $node->title, '%name' => $owner_name));
 }
 
@@ -3501,16 +3501,16 @@ 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_static_query("SELECT COUNT(*) FROM {users}")->fetchField();
   $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_static_query("SELECT name FROM {users} WHERE uid = :uid", array(':uid' => $context['owner_uid']))->fetchField();
   }
 
   // Use dropdown for fewer than 200 users; textbox for more than that.
   if (intval($count) < 200) {
     $options = array();
-    $result = db_query("SELECT uid, name FROM {users} WHERE uid > 0 ORDER BY name");
+    $result = db_static_query("SELECT uid, name FROM {users} WHERE uid > 0 ORDER BY name");
     foreach ($result as $data) {
       $options[$data->name] = $data->name;
     }
@@ -3551,7 +3551,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_static_query('SELECT uid from {users} WHERE name = :name', array(':name' => $form_state['values']['owner_name']))->fetchField();
   return array('owner_uid' => $uid);
 }
 
@@ -3608,7 +3608,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_static_query('SELECT COUNT(*) FROM {node_access}')->fetchField();
   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 modules/node/node.pages.inc modules/node/node.pages.inc
index 6b9544f..97b281c 100644
--- modules/node/node.pages.inc
+++ modules/node/node.pages.inc
@@ -542,7 +542,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_static_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid', array(':nid' => $node_revision->nid))->fetchField() > 1) {
     $form_state['redirect'] .= '/revisions';
   }
 }
diff --git modules/node/node.test modules/node/node.test
index db004f6..4ec8268 100644
--- modules/node/node.test
+++ modules/node/node.test
@@ -162,7 +162,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_static_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.'));
   }
 
   /**
@@ -485,12 +485,12 @@ class NodeCreationTestCase extends DrupalWebTestCase {
       $this->assertTrue($node, t('Transactions not supported, and node found in database.'));
 
       // Check that the failed rollback was logged.
-      $records = db_query("SELECT wid FROM {watchdog} WHERE message LIKE 'Explicit rollback failed%'")->fetchAll();
+      $records = db_static_query("SELECT wid FROM {watchdog} WHERE message LIKE 'Explicit rollback failed%'")->fetchAll();
       $this->assertTrue(count($records) > 0, t('Transactions not supported, and rollback error logged to watchdog.'));
     }
 
     // Check that the rollback error was logged.
-    $records = db_query("SELECT wid FROM {watchdog} WHERE message LIKE 'Test exception for rollback.'")->fetchAll();
+    $records = db_static_query("SELECT wid FROM {watchdog} WHERE message LIKE 'Test exception for rollback.'")->fetchAll();
     $this->assertTrue(count($records) > 0, t('Rollback explanatory error logged to watchdog.'));
   }
 }
@@ -862,7 +862,7 @@ class NodeAccessRecordsUnitTest extends DrupalWebTestCase {
     $this->assertTrue(node_load($node1->nid), t('Article node created.'));
 
     // Check to see if grants added by node_test_node_access_records made it in.
-    $records = db_query('SELECT realm, gid FROM {node_access} WHERE nid = :nid', array(':nid' => $node1->nid))->fetchAll();
+    $records = db_static_query('SELECT realm, gid FROM {node_access} WHERE nid = :nid', array(':nid' => $node1->nid))->fetchAll();
     $this->assertEqual(count($records), 1, t('Returned the correct number of rows.'));
     $this->assertEqual($records[0]->realm, 'test_article_realm', t('Grant with article_realm acquired for node without alteration.'));
     $this->assertEqual($records[0]->gid, 1, t('Grant with gid = 1 acquired for node without alteration.'));
@@ -872,7 +872,7 @@ class NodeAccessRecordsUnitTest extends DrupalWebTestCase {
     $this->assertTrue(node_load($node1->nid), t('Unpromoted basic page node created.'));
 
     // Check to see if grants added by node_test_node_access_records made it in.
-    $records = db_query('SELECT realm, gid FROM {node_access} WHERE nid = :nid', array(':nid' => $node2->nid))->fetchAll();
+    $records = db_static_query('SELECT realm, gid FROM {node_access} WHERE nid = :nid', array(':nid' => $node2->nid))->fetchAll();
     $this->assertEqual(count($records), 1, t('Returned the correct number of rows.'));
     $this->assertEqual($records[0]->realm, 'test_page_realm', t('Grant with page_realm acquired for node without alteration.'));
     $this->assertEqual($records[0]->gid, 1, t('Grant with gid = 1 acquired for node without alteration.'));
@@ -882,7 +882,7 @@ class NodeAccessRecordsUnitTest extends DrupalWebTestCase {
     $this->assertTrue(node_load($node3->nid), t('Unpromoted, unpublished basic page node created.'));
 
     // Check to see if grants added by node_test_node_access_records made it in.
-    $records = db_query('SELECT realm, gid FROM {node_access} WHERE nid = :nid', array(':nid' => $node3->nid))->fetchAll();
+    $records = db_static_query('SELECT realm, gid FROM {node_access} WHERE nid = :nid', array(':nid' => $node3->nid))->fetchAll();
     $this->assertEqual(count($records), 1, t('Returned the correct number of rows.'));
     $this->assertEqual($records[0]->realm, 'test_page_realm', t('Grant with page_realm acquired for node without alteration.'));
     $this->assertEqual($records[0]->gid, 1, t('Grant with gid = 1 acquired for node without alteration.'));
@@ -893,7 +893,7 @@ class NodeAccessRecordsUnitTest extends DrupalWebTestCase {
 
     // Check to see if grant added by node_test_node_access_records was altered
     // by node_test_node_access_records_alter.
-    $records = db_query('SELECT realm, gid FROM {node_access} WHERE nid = :nid', array(':nid' => $node4->nid))->fetchAll();
+    $records = db_static_query('SELECT realm, gid FROM {node_access} WHERE nid = :nid', array(':nid' => $node4->nid))->fetchAll();
     $this->assertEqual(count($records), 1, t('Returned the correct number of rows.'));
     $this->assertEqual($records[0]->realm, 'test_alter_realm', t('Altered grant with alter_realm acquired for node.'));
     $this->assertEqual($records[0]->gid, 2, t('Altered grant with gid = 2 acquired for node.'));
@@ -941,7 +941,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_static_query('SELECT MAX(nid) FROM {node}')->fetchField();
     $test_nid = $max_nid + mt_rand(1000, 1000000);
     $title = $this->randomName(8);
     $node = array(
@@ -1061,7 +1061,7 @@ class NodeTypeTestCase extends DrupalWebTestCase {
   function testNodeTypeCreation() {
     $type = $this->drupalCreateContentType();
 
-    $type_exists = db_query('SELECT 1 FROM {node_type} WHERE type = :type', array(':type' => $type->type))->fetchField();
+    $type_exists = db_static_query('SELECT 1 FROM {node_type} WHERE type = :type', array(':type' => $type->type))->fetchField();
     $this->assertTrue($type_exists, 'The new content type has been created in the database.');
 
     // Login a test user.
@@ -1456,7 +1456,7 @@ class NodeBlockFunctionalTest extends DrupalWebTestCase {
     $custom_block['regions[seven]'] = 'content';
     $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_static_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchField();
     $this->assertTrue($bid, t('Custom block with visibility rule was created.'));
 
     // Verify visibility rules.
@@ -1469,7 +1469,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_static_query("SELECT 1 FROM {block_node_type} WHERE module = 'block' AND delta = :delta", array(':delta' => $bid))->fetchField();
     $this->assertFalse($bid, t('Custom block was deleted.'));
   }
 }
diff --git modules/openid/openid.module modules/openid/openid.module
index d5c8689..c2f2c92 100644
--- modules/openid/openid.module
+++ modules/openid/openid.module
@@ -516,7 +516,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_static_query("SELECT assoc_handle FROM {openid_association} WHERE idp_endpoint_uri = :endpoint", array(':endpoint' => $op_endpoint))->fetchField();
   if (empty($assoc_handle)) {
     $mod = OPENID_DH_DEFAULT_MOD;
     $gen = OPENID_DH_DEFAULT_GEN;
@@ -722,7 +722,7 @@ function openid_verify_assertion($op_endpoint, $response) {
   // direct verification: ignore the openid.assoc_handle, even if present.
   // See http://openid.net/specs/openid-authentication-2_0.html#rfc.section.11.4.1
   if (!empty($response['openid.assoc_handle']) && empty($response['openid.invalidate_handle'])) {
-    $association = db_query("SELECT * FROM {openid_association} WHERE assoc_handle = :assoc_handle", array(':assoc_handle' => $response['openid.assoc_handle']))->fetchObject();
+    $association = db_static_query("SELECT * FROM {openid_association} WHERE assoc_handle = :assoc_handle", array(':assoc_handle' => $response['openid.assoc_handle']))->fetchObject();
   }
 
   if ($association && isset($association->session_type)) {
diff --git modules/openid/openid.pages.inc modules/openid/openid.pages.inc
index db41e3b..516cd55 100644
--- modules/openid/openid.pages.inc
+++ modules/openid/openid.pages.inc
@@ -48,7 +48,7 @@ function openid_user_identities($account) {
   $header = array(t('OpenID'), t('Operations'));
   $rows = array();
 
-  $result = db_query("SELECT * FROM {authmap} WHERE module='openid' AND uid=:uid", array(':uid' => $account->uid));
+  $result = db_static_query("SELECT * FROM {authmap} WHERE module='openid' AND uid=:uid", array(':uid' => $account->uid));
   foreach ($result as $identity) {
     $rows[] = array(check_plain($identity->authname), l(t('Delete'), 'user/' . $account->uid . '/openid/delete/' . $identity->aid));
   }
@@ -81,7 +81,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_static_query("SELECT authname FROM {authmap} WHERE authname = :authname", (array(':authname' => $claimed_id)))->fetchField()) {
     form_set_error('openid_identifier', t('That OpenID is already in use on this site.'));
   }
 }
@@ -95,7 +95,7 @@ function openid_user_add_submit($form, &$form_state) {
  * Menu callback; Delete the specified OpenID identity from the system.
  */
 function openid_user_delete_form($form, $form_state, $account, $aid = 0) {
-  $authname = db_query("SELECT authname FROM {authmap} WHERE uid = :uid AND aid = :aid AND module = 'openid'", array(
+  $authname = db_static_query("SELECT authname FROM {authmap} WHERE uid = :uid AND aid = :aid AND module = 'openid'", array(
     ':uid' => $account->uid,
     ':aid' => $aid,
   ))
diff --git modules/path/path.admin.inc modules/path/path.admin.inc
index 6c3e361..93773d8 100644
--- modules/path/path.admin.inc
+++ modules/path/path.admin.inc
@@ -180,7 +180,7 @@ function path_admin_form_validate($form, &$form_state) {
   // Language is only set if locale module is enabled, otherwise save for all languages.
   $language = isset($form_state['values']['language']) ? $form_state['values']['language'] : LANGUAGE_NONE;
 
-  $has_alias = db_query("SELECT COUNT(alias) FROM {url_alias} WHERE pid <> :pid AND alias = :alias AND language = :language", array(
+  $has_alias = db_static_query("SELECT COUNT(alias) FROM {url_alias} WHERE pid <> :pid AND alias = :alias AND language = :language", array(
       ':pid' => $pid,
       ':alias' => $alias,
       ':language' => $language,
diff --git modules/path/path.test modules/path/path.test
index 77df4a4..dfc4458 100644
--- modules/path/path.test
+++ modules/path/path.test
@@ -161,7 +161,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_static_query("SELECT pid FROM {url_alias} WHERE alias = :alias", array(':alias' => $alias))->fetchField();
   }
 }
 
@@ -203,7 +203,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_static_query("SELECT tid FROM {taxonomy_term_data} WHERE name = :name", array(':name' => $edit['name']))->fetchField();
     $edit2 = array();
     $edit2['path[alias]'] = $this->randomName();
     $this->drupalPost('taxonomy/term/' . $tid . '/edit', $edit2, t('Save'));
diff --git modules/poll/poll.module modules/poll/poll.module
index 7a8c333..4d08731 100644
--- modules/poll/poll.module
+++ modules/poll/poll.module
@@ -179,7 +179,7 @@ function poll_block_view($delta = '') {
  * Closes polls that have exceeded their allowed runtime.
  */
 function poll_cron() {
-  $nids = db_query('SELECT p.nid FROM {poll} p INNER JOIN {node} n ON p.nid = n.nid WHERE (n.created + p.runtime) < :request_time AND p.active = :active AND p.runtime <> :runtime', array(':request_time' => REQUEST_TIME, ':active' => 1, ':runtime' => 0))->fetchCol();
+  $nids = db_static_query('SELECT p.nid FROM {poll} p INNER JOIN {node} n ON p.nid = n.nid WHERE (n.created + p.runtime) < :request_time AND p.active = :active AND p.runtime <> :runtime', array(':request_time' => REQUEST_TIME, ':active' => 1, ':runtime' => 0))->fetchCol();
   if (!empty($nids)) {
     db_update('poll')
       ->fields(array('active' => 0))
@@ -475,7 +475,7 @@ function poll_node_prepare_translation($node) {
 function poll_load($nodes) {
   global $user;
   foreach ($nodes as $node) {
-    $poll = db_query("SELECT runtime, active FROM {poll} WHERE nid = :nid", array(':nid' => $node->nid))->fetchObject();
+    $poll = db_static_query("SELECT runtime, active FROM {poll} WHERE nid = :nid", array(':nid' => $node->nid))->fetchObject();
 
     // Load the appropriate choices into the $poll object.
     $poll->choice = db_select('poll_choice', 'c')
@@ -489,7 +489,7 @@ function poll_load($nodes) {
     $poll->allowvotes = FALSE;
     if (user_access('vote on polls') && $poll->active) {
       if ($user->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_static_query('SELECT chid FROM {poll_vote} WHERE nid = :nid AND uid = :uid', array(':nid' => $node->nid, ':uid' => $user->uid))->fetchField();
         if (empty($poll->vote)) {
           $poll->vote = -1;
           $poll->allowvotes = TRUE;
@@ -499,7 +499,7 @@ function poll_load($nodes) {
         $poll->vote = $_SESSION['poll_vote'][$node->nid];
       }
       else {
-        $poll->allowvotes = !db_query("SELECT 1 FROM {poll_vote} WHERE nid = :nid AND hostname = :hostname", array(':nid' => $node->nid, ':hostname' => ip_address()))->fetchField();
+        $poll->allowvotes = !db_static_query("SELECT 1 FROM {poll_vote} WHERE nid = :nid AND hostname = :hostname", array(':nid' => $node->nid, ':hostname' => ip_address()))->fetchField();
       }
     }
     foreach ($poll as $key => $value) {
diff --git modules/profile/profile.admin.inc modules/profile/profile.admin.inc
index 0bb1327..922cefd 100644
--- modules/profile/profile.admin.inc
+++ modules/profile/profile.admin.inc
@@ -13,7 +13,7 @@
  * @see profile_admin_overview_submit()
  */
 function profile_admin_overview($form) {
-  $result = db_query('SELECT title, name, type, category, fid, weight FROM {profile_field} ORDER BY category, weight');
+  $result = db_static_query('SELECT title, name, type, category, fid, weight FROM {profile_field} ORDER BY category, weight');
 
   $categories = array();
   foreach ($result as $field) {
@@ -179,7 +179,7 @@ function profile_field_form($form, &$form_state, $arg = NULL) {
     if (is_numeric($arg)) {
       $fid = $arg;
 
-      $edit = db_query('SELECT * FROM {profile_field} WHERE fid = :fid', array('fid' => $fid))->fetchAssoc();
+      $edit = db_static_query('SELECT * FROM {profile_field} WHERE fid = :fid', array('fid' => $fid))->fetchAssoc();
 
       if (!$edit) {
         drupal_not_found();
@@ -384,7 +384,7 @@ function profile_field_form_submit($form, &$form_state) {
  * Menu callback; deletes a field from all user profiles.
  */
 function profile_field_delete($form, &$form_state, $fid) {
-  $field = db_query("SELECT title FROM {profile_field} WHERE fid = :fid", array(':fid' => $fid))->fetchObject();
+  $field = db_static_query("SELECT title FROM {profile_field} WHERE fid = :fid", array(':fid' => $fid))->fetchObject();
   if (!$field) {
     drupal_not_found();
     return;
diff --git modules/profile/profile.module modules/profile/profile.module
index 5aabb3d..ff98429 100644
--- modules/profile/profile.module
+++ modules/profile/profile.module
@@ -149,7 +149,7 @@ function profile_menu() {
 function profile_block_configure($delta = '') {
   // Compile a list of fields to show
   $fields = array();
-  $result = db_query('SELECT name, title, weight, visibility FROM {profile_field} WHERE visibility IN (:visibility) ORDER BY weight', array(':visibility' => array(PROFILE_PUBLIC, PROFILE_PUBLIC_LISTINGS)));
+  $result = db_static_query('SELECT name, title, weight, visibility FROM {profile_field} WHERE visibility IN (:visibility) ORDER BY weight', array(':visibility' => array(PROFILE_PUBLIC, PROFILE_PUBLIC_LISTINGS)));
   foreach ($result as $record) {
     $fields[$record->name] = check_plain($record->title);
   }
@@ -184,7 +184,7 @@ function profile_block_view($delta = '') {
       if ($use_fields = variable_get('profile_block_author_fields', array())) {
         // Compile a list of fields to show.
         $fields = array();
-        $result = db_query('SELECT name, title, weight, visibility FROM {profile_field} WHERE visibility IN (:visibility) ORDER BY weight', array(':visibility' => array(PROFILE_PUBLIC, PROFILE_PUBLIC_LISTINGS)));
+        $result = db_static_query('SELECT name, title, weight, visibility FROM {profile_field} WHERE visibility IN (:visibility) ORDER BY weight', array(':visibility' => array(PROFILE_PUBLIC, PROFILE_PUBLIC_LISTINGS)));
         foreach ($result as $record) {
           // Ensure that field is displayed only if it is among the defined block fields and, if it is private, the user has appropriate permissions.
           if (isset($use_fields[$record->name]) && $use_fields[$record->name]) {
@@ -252,7 +252,7 @@ function profile_user_delete($account) {
  * Implements hook_user_load().
  */
 function profile_user_load($users) {
-  $result = db_query('SELECT f.name, f.type, v.uid, v.value FROM {profile_field} f INNER JOIN {profile_value} v ON f.fid = v.fid WHERE uid IN (:uids)', array(':uids' => array_keys($users)));
+  $result = db_static_query('SELECT f.name, f.type, v.uid, v.value FROM {profile_field} f INNER JOIN {profile_value} v ON f.fid = v.fid WHERE uid IN (:uids)', array(':uids' => array_keys($users)));
   foreach ($result as $record) {
     if (empty($users[$record->uid]->{$record->name})) {
       $users[$record->uid]->{$record->name} = _profile_field_serialize($record->type) ? unserialize($record->value) : $record->value;
@@ -329,10 +329,10 @@ function profile_view_field($account, $field) {
 function profile_user_view($account) {
   // Show private fields to administrators and people viewing their own account.
   if (user_access('administer users') || $GLOBALS['user']->uid == $account->uid) {
-    $result = db_query('SELECT * FROM {profile_field} WHERE visibility <> :hidden ORDER BY category, weight', array(':hidden' => PROFILE_HIDDEN));
+    $result = db_static_query('SELECT * FROM {profile_field} WHERE visibility <> :hidden ORDER BY category, weight', array(':hidden' => PROFILE_HIDDEN));
   }
   else {
-    $result = db_query('SELECT * FROM {profile_field} WHERE visibility <> :private AND visibility <> :hidden ORDER BY category, weight', array(':private' => PROFILE_PRIVATE, ':hidden' => PROFILE_HIDDEN));
+    $result = db_static_query('SELECT * FROM {profile_field} WHERE visibility <> :private AND visibility <> :hidden ORDER BY category, weight', array(':private' => PROFILE_PRIVATE, ':hidden' => PROFILE_HIDDEN));
   }
 
   $fields = array();
@@ -499,7 +499,7 @@ function profile_user_form_validate($form, &$form_state) {
  * Implements hook_user_categories().
  */
 function profile_user_categories() {
-  $result = db_query("SELECT DISTINCT(category) FROM {profile_field}");
+  $result = db_static_query("SELECT DISTINCT(category) FROM {profile_field}");
   $data = array();
   foreach ($result as $category) {
     $data[] = array(
diff --git modules/profile/profile.pages.inc modules/profile/profile.pages.inc
index 023b235..1ac067c 100644
--- modules/profile/profile.pages.inc
+++ modules/profile/profile.pages.inc
@@ -13,7 +13,7 @@ function profile_browse() {
   // Ensure that the path is converted to 3 levels always.
   list(, $name, $value) = array_pad(explode('/', $_GET['q'], 3), 3, '');
 
-  $field = db_query("SELECT DISTINCT(fid), type, title, page, visibility FROM {profile_field} WHERE name = :name", array(':name' => $name))->fetchObject();
+  $field = db_static_query("SELECT DISTINCT(fid), type, title, page, visibility FROM {profile_field} WHERE name = :name", array(':name' => $name))->fetchObject();
 
   if ($name && $field->fid) {
     // Only allow browsing of fields that have a page title set.
@@ -28,7 +28,7 @@ function profile_browse() {
     }
 
     // Compile a list of fields to show.
-    $fields = db_query('SELECT name, title, type, weight, page FROM {profile_field} WHERE fid <> :fid AND visibility = :visibility ORDER BY weight', array(
+    $fields = db_static_query('SELECT name, title, type, weight, page FROM {profile_field} WHERE fid <> :fid AND visibility = :visibility ORDER BY weight', array(
       ':fid' => $field->fid,
       ':visibility' => PROFILE_PUBLIC_LISTINGS,
     ))->fetchAll();
@@ -91,7 +91,7 @@ function profile_browse() {
   }
   else {
     // Compile a list of fields to show.
-    $fields = db_query('SELECT name, title, type, weight, page, visibility FROM {profile_field} WHERE visibility = :visibility ORDER BY category, weight', array(':visibility' => PROFILE_PUBLIC_LISTINGS))->fetchAll();
+    $fields = db_static_query('SELECT name, title, type, weight, page, visibility FROM {profile_field} WHERE visibility = :visibility ORDER BY category, weight', array(':visibility' => PROFILE_PUBLIC_LISTINGS))->fetchAll();
 
     // Extract the affected users:
     $query = db_select('users', 'u')->extend('PagerDefault');
diff --git modules/profile/profile.test modules/profile/profile.test
index 61709d3..226c622 100644
--- modules/profile/profile.test
+++ modules/profile/profile.test
@@ -37,7 +37,7 @@ class ProfileTestCase extends DrupalWebTestCase {
     $edit['explanation'] = $this->randomName(50);
 
     $this->drupalPost('admin/config/people/profile/add/' . $type, $edit, t('Save field'));
-    $fid = db_query("SELECT fid FROM {profile_field} WHERE title = :title", array(':title' => $title))->fetchField();
+    $fid = db_static_query("SELECT fid FROM {profile_field} WHERE title = :title", array(':title' => $title))->fetchField();
     $this->assertTrue($fid, t('New Profile field has been entered in the database'));
 
     // Check that the new field is appearing on the user edit form.
diff --git modules/rdf/rdf.test modules/rdf/rdf.test
index d77f896..d69df7a 100644
--- modules/rdf/rdf.test
+++ modules/rdf/rdf.test
@@ -229,7 +229,7 @@ class RdfCrudTestCase extends DrupalWebTestCase {
     $this->assertTrue(rdf_mapping_save($mapping) === SAVED_NEW, t('Mapping was saved.'));
 
     // Read the raw record from the {rdf_mapping} table.
-    $result = db_query('SELECT * FROM {rdf_mapping} WHERE type = :type AND bundle = :bundle', array(':type' => $mapping['type'], ':bundle' => $mapping['bundle']));
+    $result = db_static_query('SELECT * FROM {rdf_mapping} WHERE type = :type AND bundle = :bundle', array(':type' => $mapping['type'], ':bundle' => $mapping['bundle']));
     $stored_mapping = $result->fetchAssoc();
     $stored_mapping['mapping'] = unserialize($stored_mapping['mapping']);
     $this->assertEqual($mapping, $stored_mapping, t('Mapping was stored properly in the {rdf_mapping} table.'));
@@ -244,7 +244,7 @@ class RdfCrudTestCase extends DrupalWebTestCase {
     $this->assertTrue(rdf_mapping_save($mapping) === SAVED_UPDATED, t('Mapping was updated.'));
 
     // Read the raw record from the {rdf_mapping} table.
-    $result = db_query('SELECT * FROM {rdf_mapping} WHERE type = :type AND bundle = :bundle', array(':type' => $mapping['type'], ':bundle' => $mapping['bundle']));
+    $result = db_static_query('SELECT * FROM {rdf_mapping} WHERE type = :type AND bundle = :bundle', array(':type' => $mapping['type'], ':bundle' => $mapping['bundle']));
     $stored_mapping = $result->fetchAssoc();
     $stored_mapping['mapping'] = unserialize($stored_mapping['mapping']);
     $this->assertEqual($mapping, $stored_mapping, t('Updated mapping was stored properly in the {rdf_mapping} table.'));
@@ -528,7 +528,7 @@ class RdfTrackerAttributesTestCase extends DrupalWebTestCase {
 
     // Need to query database directly to obtain last_activity_date because
     // it cannot be accessed via node_load().
-    $result = db_query('SELECT t.changed FROM {tracker_node} t WHERE t.nid = (:nid)', array(':nid' => $node->nid));
+    $result = db_static_query('SELECT t.changed FROM {tracker_node} t WHERE t.nid = (:nid)', array(':nid' => $node->nid));
     foreach ($result as $node) {
       $expected_last_activity_date = $node->changed;
     }
diff --git modules/search/search.api.php modules/search/search.api.php
index 21f4174..62d68d7 100644
--- modules/search/search.api.php
+++ modules/search/search.api.php
@@ -81,8 +81,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_static_query('SELECT COUNT(*) FROM {node} WHERE status = 1')->fetchField();
+  $remaining = db_static_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();
   return array('remaining' => $remaining, 'total' => $total);
 }
 
diff --git modules/search/search.module modules/search/search.module
index 4eeb670..9259a25 100644
--- modules/search/search.module
+++ modules/search/search.module
@@ -397,7 +397,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_static_query("SELECT SUM(score) FROM {search_index} WHERE word = :word", array(':word' => $word), array('target' => 'slave'))->fetchField();
     // Apply Zipf's law to equalize the probability distribution.
     $total = log10(1 + 1/(max(1, $total)));
     db_merge('search_total')
@@ -408,7 +408,7 @@ function search_update_totals() {
   // Find words that were deleted from search_index, but are still in
   // search_total. We use a LEFT JOIN between the two tables and keep only the
   // rows which fail to join.
-  $result = db_query("SELECT t.word AS realword, i.word FROM {search_total} t LEFT JOIN {search_index} i ON t.word = i.word WHERE i.word IS NULL", array(), array('target' => 'slave'));
+  $result = db_static_query("SELECT t.word AS realword, i.word FROM {search_total} t LEFT JOIN {search_index} i ON t.word = i.word WHERE i.word IS NULL", array(), array('target' => 'slave'));
   $or = db_or();
   foreach ($result as $word) {
     $or->condition('word', $word->realword);
@@ -641,7 +641,7 @@ function search_index($sid, $type, $text) {
             if (preg_match('!(?:node|book)/(?:view/)?([0-9]+)!i', $path, $match)) {
               $linknid = $match[1];
               if ($linknid > 0) {
-                $node = db_query('SELECT title, nid, vid FROM {node} WHERE nid = :nid', array(':nid' => $linknid), array('target' => 'slave'))->fetchObject();
+                $node = db_static_query('SELECT title, nid, vid FROM {node} WHERE nid = :nid', array(':nid' => $linknid), array('target' => 'slave'))->fetchObject();
                 $link = TRUE;
                 $linktitle = $node->title;
               }
@@ -735,7 +735,7 @@ function search_index($sid, $type, $text) {
   unset($results[0]);
 
   // Get all previous links from this item.
-  $result = db_query("SELECT nid, caption FROM {search_node_links} WHERE sid = :sid AND type = :type", array(
+  $result = db_static_query("SELECT nid, caption FROM {search_node_links} WHERE sid = :sid AND type = :type", array(
     ':sid' => $sid,
     ':type' => $type
   ), array('target' => 'slave'));
@@ -805,7 +805,7 @@ function search_touch_node($nid) {
  */
 function search_node_update_index($node) {
   // Transplant links to a node into the target node.
-  $result = db_query("SELECT caption FROM {search_node_links} WHERE nid = :nid", array(':nid' => $node->nid), array('target' => 'slave'));
+  $result = db_static_query("SELECT caption FROM {search_node_links} WHERE nid = :nid", array(':nid' => $node->nid), array('target' => 'slave'));
   $output = array();
   foreach ($result as $link) {
     $output[] = $link->caption;
diff --git modules/shortcut/shortcut.admin.inc modules/shortcut/shortcut.admin.inc
index e86d8f5..76b79df 100644
--- modules/shortcut/shortcut.admin.inc
+++ modules/shortcut/shortcut.admin.inc
@@ -608,7 +608,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_static_query('SELECT COUNT(*) FROM {shortcut_set_users} WHERE set_name = :name', array(':name' => $shortcut_set->set_name))->fetchField();
   $info = '';
   if ($number) {
     $info .= '<p>' . format_plural($number,
diff --git modules/shortcut/shortcut.module modules/shortcut/shortcut.module
index 7144dae..661e594 100644
--- modules/shortcut/shortcut.module
+++ modules/shortcut/shortcut.module
@@ -543,7 +543,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_static_query("SELECT COUNT(*) FROM {shortcut_set}")->fetchField() + 1;
   do {
     $name = shortcut_set_name($number);
     $number++;
diff --git modules/simpletest/drupal_web_test_case.php modules/simpletest/drupal_web_test_case.php
index 1a92b17..f3220ae 100644
--- modules/simpletest/drupal_web_test_case.php
+++ modules/simpletest/drupal_web_test_case.php
@@ -988,7 +988,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_static_query('SELECT COUNT(*) FROM {role_permission} WHERE rid = :rid', array(':rid' => $role->rid))->fetchField();
       $this->assertTrue($count == count($permissions), t('Created permissions: @perms', array('@perms' => implode(', ', $permissions))), t('Role'));
       return $role->rid;
     }
@@ -1230,8 +1230,8 @@ class DrupalWebTestCase extends DrupalTestCase {
    * setup a clean environment for the current test run.
    */
   protected function preloadRegistry() {
-    db_query('INSERT INTO {registry} SELECT * FROM ' . $this->originalPrefix . 'registry');
-    db_query('INSERT INTO {registry_file} SELECT * FROM ' . $this->originalPrefix . 'registry_file');
+    db_static_query('INSERT INTO {registry} SELECT * FROM ' . $this->originalPrefix . 'registry');
+    db_static_query('INSERT INTO {registry_file} SELECT * FROM ' . $this->originalPrefix . 'registry_file');
   }
 
   /**
diff --git modules/simpletest/simpletest.module modules/simpletest/simpletest.module
index fc5a683..c9efa42 100644
--- modules/simpletest/simpletest.module
+++ modules/simpletest/simpletest.module
@@ -333,7 +333,7 @@ function simpletest_test_get_all() {
     }
     else {
       // Select all clases in files ending with .test.
-      $classes = db_query("SELECT name FROM {registry} WHERE type = :type AND filename LIKE :name", array(':type' => 'class', ':name' => '%.test'));
+      $classes = db_static_query("SELECT name FROM {registry} WHERE type = :type AND filename LIKE :name", array(':type' => 'class', ':name' => '%.test'));
 
       // Check that each class has a getInfo() method and store the information
       // in an array keyed with the group specified in the test information.
@@ -499,7 +499,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_static_query('SELECT COUNT(test_id) FROM {simpletest_test_id} WHERE test_id = :test_id', array(':test_id' => $test_id))->fetchField();
 
       db_delete('simpletest')
         ->condition('test_id', $test_id)
@@ -509,7 +509,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_static_query('SELECT COUNT(test_id) FROM {simpletest_test_id}')->fetchField();
 
       // Clear test results.
       db_delete('simpletest')->execute();
diff --git modules/simpletest/tests/actions.test modules/simpletest/tests/actions.test
index e88021f..61605ef 100644
--- modules/simpletest/tests/actions.test
+++ modules/simpletest/tests/actions.test
@@ -59,7 +59,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_static_query('SELECT aid FROM {actions} WHERE callback = :callback', array(':callback' => 'drupal_goto_action'))->fetchField();
     $this->assertFalse($exists, t('Make sure the action is gone from the database after being deleted.'));
   }
 }
@@ -116,7 +116,7 @@ class ActionLoopTestCase extends DrupalWebTestCase {
     }
     $expected[] = 'Stack overflow: too many calls to actions_do(). Aborting to prevent infinite recursion.';
 
-    $result = db_query("SELECT * FROM {watchdog} WHERE type = 'actions_loop_test' OR type = 'actions' ORDER BY timestamp");
+    $result = db_static_query("SELECT * FROM {watchdog} WHERE type = 'actions_loop_test' OR type = 'actions' ORDER BY timestamp");
     $loop_started = FALSE;
     foreach ($result as $row) {
 
diff --git modules/simpletest/tests/bootstrap.test modules/simpletest/tests/bootstrap.test
index 043cc4a..58f92e8 100644
--- modules/simpletest/tests/bootstrap.test
+++ modules/simpletest/tests/bootstrap.test
@@ -283,29 +283,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_static_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_static_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.'));
 
     // 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_static_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_static_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.'));
 
     // Boot and exit should not fire since the page is cached.
     variable_set('page_cache_invoke_hooks', FALSE);
     $this->assertTrue(cache_get(url('', array('absolute' => TRUE)), 'cache_page'), 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_static_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_static_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.'));
 
     // 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_static_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_static_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.'));
   }
 }
 
diff --git modules/simpletest/tests/common.test modules/simpletest/tests/common.test
index 7728b8d..1efde87 100644
--- modules/simpletest/tests/common.test
+++ modules/simpletest/tests/common.test
@@ -1552,7 +1552,7 @@ class DrupalDataApiTest extends DrupalWebTestCase {
     $this->assertIdentical($person->job, 'Undefined', t('Job field set to default value.'));
 
     // Verify that the record was inserted.
-    $result = db_query("SELECT * FROM {test} WHERE id = :id", array(':id' => $person->id))->fetchObject();
+    $result = db_static_query("SELECT * FROM {test} WHERE id = :id", array(':id' => $person->id))->fetchObject();
     $this->assertIdentical($result->name, 'John', t('Name field set.'));
     $this->assertIdentical($result->age, '0', t('Age field set to default value.'));
     $this->assertIdentical($result->job, 'Undefined', t('Job field set to default value.'));
@@ -1566,7 +1566,7 @@ class DrupalDataApiTest extends DrupalWebTestCase {
     $this->assertTrue($update_result == SAVED_UPDATED, t('Correct value returned when a record updated with drupal_write_record() for table with single-field primary key.'));
 
     // Verify that the record was updated.
-    $result = db_query("SELECT * FROM {test} WHERE id = :id", array(':id' => $person->id))->fetchObject();
+    $result = db_static_query("SELECT * FROM {test} WHERE id = :id", array(':id' => $person->id))->fetchObject();
     $this->assertIdentical($result->name, 'Peter', t('Name field set.'));
     $this->assertIdentical($result->age, '27', t('Age field set.'));
     $this->assertIdentical($result->job, '', t('Job field set and cast to string.'));
@@ -1578,7 +1578,7 @@ class DrupalDataApiTest extends DrupalWebTestCase {
     $person->job = NULL;
     $insert_result = drupal_write_record('test', $person);
     $this->assertTrue(isset($person->id), t('Primary key is set on record created with drupal_write_record().'));
-    $result = db_query("SELECT * FROM {test} WHERE id = :id", array(':id' => $person->id))->fetchObject();
+    $result = db_static_query("SELECT * FROM {test} WHERE id = :id", array(':id' => $person->id))->fetchObject();
     $this->assertIdentical($result->name, 'Ringo', t('Name field set.'));
     $this->assertIdentical($result->age, '0', t('Age field set.'));
     $this->assertIdentical($result->job, '', t('Job field set.'));
@@ -1589,7 +1589,7 @@ class DrupalDataApiTest extends DrupalWebTestCase {
     $person->age = NULL;
     $insert_result = drupal_write_record('test_null', $person);
     $this->assertTrue(isset($person->id), t('Primary key is set on record created with drupal_write_record().'));
-    $result = db_query("SELECT * FROM {test_null} WHERE id = :id", array(':id' => $person->id))->fetchObject();
+    $result = db_static_query("SELECT * FROM {test_null} WHERE id = :id", array(':id' => $person->id))->fetchObject();
     $this->assertIdentical($result->name, 'Paul', t('Name field set.'));
     $this->assertIdentical($result->age, NULL, t('Age field set.'));
 
@@ -1599,7 +1599,7 @@ class DrupalDataApiTest extends DrupalWebTestCase {
     $insert_result = drupal_write_record('test_null', $person);
     $this->assertTrue(isset($person->id), t('Primary key is set on record created with drupal_write_record().'));
     $this->assertIdentical($person->age, 0, t('Age field set to default value.'));
-    $result = db_query("SELECT * FROM {test_null} WHERE id = :id", array(':id' => $person->id))->fetchObject();
+    $result = db_static_query("SELECT * FROM {test_null} WHERE id = :id", array(':id' => $person->id))->fetchObject();
     $this->assertIdentical($result->name, 'Meredith', t('Name field set.'));
     $this->assertIdentical($result->age, '0', t('Age field set to default value.'));
 
@@ -1607,7 +1607,7 @@ class DrupalDataApiTest extends DrupalWebTestCase {
     $person->name = 'Mary';
     $person->age = NULL;
     $update_result = drupal_write_record('test_null', $person, array('id'));
-    $result = db_query("SELECT * FROM {test_null} WHERE id = :id", array(':id' => $person->id))->fetchObject();
+    $result = db_static_query("SELECT * FROM {test_null} WHERE id = :id", array(':id' => $person->id))->fetchObject();
     $this->assertIdentical($result->name, 'Mary', t('Name field set.'));
     $this->assertIdentical($result->age, NULL, t('Age field set.'));
 
@@ -1615,20 +1615,20 @@ class DrupalDataApiTest extends DrupalWebTestCase {
     $person = new stdClass();
     $person->name = 'Dave';
     $update_result = drupal_write_record('test_serialized', $person);
-    $result = db_query("SELECT * FROM {test_serialized} WHERE id = :id", array(':id' => $person->id))->fetchObject();
+    $result = db_static_query("SELECT * FROM {test_serialized} WHERE id = :id", array(':id' => $person->id))->fetchObject();
     $this->assertIdentical($result->name, 'Dave', t('Name field set.'));
     $this->assertIdentical($result->info, NULL, t('Info field set.'));
 
     $person->info = array();
     $update_result = drupal_write_record('test_serialized', $person, array('id'));
-    $result = db_query("SELECT * FROM {test_serialized} WHERE id = :id", array(':id' => $person->id))->fetchObject();
+    $result = db_static_query("SELECT * FROM {test_serialized} WHERE id = :id", array(':id' => $person->id))->fetchObject();
     $this->assertIdentical(unserialize($result->info), array(), t('Info field updated.'));
 
     // Update the serialized record.
     $data = array('foo' => 'bar', 1 => 2, 'empty' => '', 'null' => NULL);
     $person->info = $data;
     $update_result = drupal_write_record('test_serialized', $person, array('id'));
-    $result = db_query("SELECT * FROM {test_serialized} WHERE id = :id", array(':id' => $person->id))->fetchObject();
+    $result = db_static_query("SELECT * FROM {test_serialized} WHERE id = :id", array(':id' => $person->id))->fetchObject();
     $this->assertIdentical(unserialize($result->info), $data, t('Info field updated.'));
 
     // Run an update query where no field values are changed. The database
diff --git modules/simpletest/tests/database.test modules/simpletest/tests/database.test
index 83bb3a1..a5901e1 100644
--- modules/simpletest/tests/database.test
+++ modules/simpletest/tests/database.test
@@ -54,19 +54,19 @@ class DatabaseSecurityTestCase extends DrupalWebTestCase {
     db_create_table($ret, 'test_numeric', $schema);
     $insert_query = 'INSERT INTO {test_numeric} (n) VALUES (' . db_type_placeholder('numeric') . ')';
     foreach ($valid as $insert => $select) {
-      db_query('DELETE FROM {test_numeric}');
-      db_query($insert_query, $insert);
-      $count = db_result(db_query('SELECT COUNT(*) FROM {test_numeric}'));
+      db_static_query('DELETE FROM {test_numeric}');
+      db_static_query($insert_query, $insert);
+      $count = db_result(db_static_query('SELECT COUNT(*) FROM {test_numeric}'));
       $this->assertEqual(1, $count, "[numeric] One row ($count) after inserting $insert");
-      $test = db_result(db_query('SELECT n FROM {test_numeric}'));
+      $test = db_result(db_static_query('SELECT n FROM {test_numeric}'));
       $this->assertEqual($select, $test, "[numeric] Got $select ($test) after inserting valid value $insert");
     }
     foreach ($not_valid as $insert => $select) {
-      db_query('DELETE FROM {test_numeric}');
-      db_query($insert_query, $insert);
-      $count = db_result(db_query('SELECT COUNT(*) FROM {test_numeric}'));
+      db_static_query('DELETE FROM {test_numeric}');
+      db_static_query($insert_query, $insert);
+      $count = db_result(db_static_query('SELECT COUNT(*) FROM {test_numeric}'));
       $this->assertEqual(1, $count, "[numeric] One row ($count) after inserting $insert");
-      $test = db_result(db_query('SELECT n FROM {test_numeric}'));
+      $test = db_result(db_static_query('SELECT n FROM {test_numeric}'));
       $this->assertEqual(0, $test, "[numeric] Got $select ($test) after inserting invalid value $insert");
     }
 
@@ -108,19 +108,19 @@ class DatabaseSecurityTestCase extends DrupalWebTestCase {
     db_create_table($ret, 'test_int', $schema);
     $insert_query = 'INSERT INTO {test_int} (n) VALUES (' . db_type_placeholder('int') . ')';
     foreach ($valid as $insert => $select) {
-      db_query('DELETE FROM {test_int}');
-      db_query($insert_query, $insert);
-      $count = db_result(db_query('SELECT COUNT(*) FROM {test_int}'));
+      db_static_query('DELETE FROM {test_int}');
+      db_static_query($insert_query, $insert);
+      $count = db_result(db_static_query('SELECT COUNT(*) FROM {test_int}'));
       $this->assertEqual(1, $count, "[int] One row ($count) after inserting $insert");
-      $test = db_result(db_query('SELECT n FROM {test_int}'));
+      $test = db_result(db_static_query('SELECT n FROM {test_int}'));
       $this->assertEqual($select, $test, "[int] Got $select ($test) after inserting valid value $insert");
     }
     foreach ($not_valid as $insert => $select) {
-      db_query('DELETE FROM {test_int}');
-      db_query($insert_query, $insert);
-      $count = db_result(db_query('SELECT COUNT(*) FROM {test_int}'));
+      db_static_query('DELETE FROM {test_int}');
+      db_static_query($insert_query, $insert);
+      $count = db_result(db_static_query('SELECT COUNT(*) FROM {test_int}'));
       $this->assertEqual(1, $count, "[int] One row ($count) after inserting $insert");
-      $test = db_result(db_query('SELECT n FROM {test_int}'));
+      $test = db_result(db_static_query('SELECT n FROM {test_int}'));
       $this->assertEqual($select, $test, "[int] Got $select ($test) after inserting invalid value $insert");
     }
 
@@ -162,19 +162,19 @@ class DatabaseSecurityTestCase extends DrupalWebTestCase {
     db_create_table($ret, 'test_float', $schema);
     $insert_query = 'INSERT INTO {test_float} (n) VALUES (' . db_type_placeholder('float') . ')';
     foreach ($valid as $insert => $select) {
-      db_query('DELETE FROM {test_float}');
-      db_query($insert_query, $insert);
-      $count = db_result(db_query('SELECT COUNT(*) FROM {test_float}'));
+      db_static_query('DELETE FROM {test_float}');
+      db_static_query($insert_query, $insert);
+      $count = db_result(db_static_query('SELECT COUNT(*) FROM {test_float}'));
       $this->assertEqual(1, $count, "[float] One row ($count) after inserting $insert");
-      $test = db_result(db_query('SELECT n FROM {test_float}'));
+      $test = db_result(db_static_query('SELECT n FROM {test_float}'));
       $this->assertEqual($select, $test, "[float] Got $select ($test) after inserting valid value $insert");
     }
     foreach ($not_valid as $insert => $select) {
-      db_query('DELETE FROM {test_float}');
-      db_query($insert_query, $insert);
-      $count = db_result(db_query('SELECT COUNT(*) FROM {test_float}'));
+      db_static_query('DELETE FROM {test_float}');
+      db_static_query($insert_query, $insert);
+      $count = db_result(db_static_query('SELECT COUNT(*) FROM {test_float}'));
       $this->assertEqual(1, $count, "[float] One row ($count) after inserting $insert");
-      $test = db_result(db_query('SELECT n FROM {test_float}'));
+      $test = db_result(db_static_query('SELECT n FROM {test_float}'));
       $this->assertEqual($select, $test, "[float] Got $select ($test) after inserting invalid value $insert");
     }
 
diff --git modules/simpletest/tests/database_test.test modules/simpletest/tests/database_test.test
index b64b5bd..b04ff69 100644
--- modules/simpletest/tests/database_test.test
+++ modules/simpletest/tests/database_test.test
@@ -79,7 +79,7 @@ class DatabaseTestCase extends DrupalWebTestCase {
   /**
    * Setup our sample data.
    *
-   * These are added using db_query(), since we're not trying to test the
+   * These are added using db_static_query(), since we're not trying to test the
    * INSERT operations here, just populate.
    */
   function addSampleData() {
@@ -301,7 +301,7 @@ class DatabaseFetchTestCase extends DatabaseTestCase {
    */
   function testQueryFetchDefault() {
     $records = array();
-    $result = db_query('SELECT name FROM {test} WHERE age = :age', array(':age' => 25));
+    $result = db_static_query('SELECT name FROM {test} WHERE age = :age', array(':age' => 25));
     $this->assertTrue($result instanceof DatabaseStatementInterface, t('Result set is a Drupal statement object.'));
     foreach ($result as $record) {
       $records[] = $record;
@@ -317,7 +317,7 @@ class DatabaseFetchTestCase extends DatabaseTestCase {
    */
   function testQueryFetchObject() {
     $records = array();
-    $result = db_query('SELECT name FROM {test} WHERE age = :age', array(':age' => 25), array('fetch' => PDO::FETCH_OBJ));
+    $result = db_static_query('SELECT name FROM {test} WHERE age = :age', array(':age' => 25), array('fetch' => PDO::FETCH_OBJ));
     foreach ($result as $record) {
       $records[] = $record;
       $this->assertTrue(is_object($record), t('Record is an object.'));
@@ -332,7 +332,7 @@ class DatabaseFetchTestCase extends DatabaseTestCase {
    */
   function testQueryFetchArray() {
     $records = array();
-    $result = db_query('SELECT name FROM {test} WHERE age = :age', array(':age' => 25), array('fetch' => PDO::FETCH_ASSOC));
+    $result = db_static_query('SELECT name FROM {test} WHERE age = :age', array(':age' => 25), array('fetch' => PDO::FETCH_ASSOC));
     foreach ($result as $record) {
       $records[] = $record;
       if ($this->assertTrue(is_array($record), t('Record is an array.'))) {
@@ -350,7 +350,7 @@ class DatabaseFetchTestCase extends DatabaseTestCase {
    */
   function testQueryFetchClass() {
     $records = array();
-    $result = db_query('SELECT name FROM {test} WHERE age = :age', array(':age' => 25), array('fetch' => 'FakeRecord'));
+    $result = db_static_query('SELECT name FROM {test} WHERE age = :age', array(':age' => 25), array('fetch' => 'FakeRecord'));
     foreach ($result as $record) {
       $records[] = $record;
       if ($this->assertTrue($record instanceof FakeRecord, t('Record is an object of class FakeRecord.'))) {
@@ -384,7 +384,7 @@ class DatabaseFetch2TestCase extends DatabaseTestCase {
   // Confirm that we can fetch a record into an indexed array explicitly.
   function testQueryFetchNum() {
     $records = array();
-    $result = db_query('SELECT name FROM {test} WHERE age = :age', array(':age' => 25), array('fetch' => PDO::FETCH_NUM));
+    $result = db_static_query('SELECT name FROM {test} WHERE age = :age', array(':age' => 25), array('fetch' => PDO::FETCH_NUM));
     foreach ($result as $record) {
       $records[] = $record;
       if ($this->assertTrue(is_array($record), t('Record is an array.'))) {
@@ -400,7 +400,7 @@ class DatabaseFetch2TestCase extends DatabaseTestCase {
    */
   function testQueryFetchBoth() {
     $records = array();
-    $result = db_query('SELECT name FROM {test} WHERE age = :age', array(':age' => 25), array('fetch' => PDO::FETCH_BOTH));
+    $result = db_static_query('SELECT name FROM {test} WHERE age = :age', array(':age' => 25), array('fetch' => PDO::FETCH_BOTH));
     foreach ($result as $record) {
       $records[] = $record;
       if ($this->assertTrue(is_array($record), t('Record is an array.'))) {
@@ -417,11 +417,11 @@ class DatabaseFetch2TestCase extends DatabaseTestCase {
    */
   function testQueryFetchCol() {
     $records = array();
-    $result = db_query('SELECT name FROM {test} WHERE age > :age', array(':age' => 25));
+    $result = db_static_query('SELECT name FROM {test} WHERE age > :age', array(':age' => 25));
     $column = $result->fetchCol();
     $this->assertIdentical(count($column), 3, t('fetchCol() returns the right number of records.'));
 
-    $result = db_query('SELECT name FROM {test} WHERE age > :age', array(':age' => 25));
+    $result = db_static_query('SELECT name FROM {test} WHERE age > :age', array(':age' => 25));
     $i = 0;
     foreach ($result as $record) {
       $this->assertIdentical($record->name, $column[$i++], t('Column matches direct accesss.'));
@@ -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_static_query('SELECT COUNT(*) FROM {test}')->fetchField();
 
     $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_static_query('SELECT COUNT(*) FROM {test}')->fetchField();
     $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_static_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Yoko'))->fetchField();
     $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_static_query('SELECT COUNT(*) FROM {test}')->fetchField();
 
     $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_static_query('SELECT COUNT(*) FROM {test}')->fetchField();
     $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_static_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Larry'))->fetchField();
     $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_static_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Curly'))->fetchField();
     $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_static_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Moe'))->fetchField();
     $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_static_query('SELECT COUNT(*) FROM {test}')->fetchField();
 
     $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_static_query('SELECT COUNT(*) FROM {test}')->fetchField();
     $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_static_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Larry'))->fetchField();
     $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_static_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Curly'))->fetchField();
     $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_static_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Moe'))->fetchField();
     $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_static_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Larry'))->fetchField();
     $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_static_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Curly'))->fetchField();
     $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_static_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Moe'))->fetchField();
     $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_static_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Meredith'))->fetchField();
     $this->assertIdentical($saved_age, '30', t('Can retrieve after inserting.'));
   }
 }
@@ -612,7 +612,7 @@ class DatabaseInsertLOBTestCase extends DatabaseTestCase {
     $id = db_insert('test_one_blob')
       ->fields(array('blob1' => $data))
       ->execute();
-    $r = db_query('SELECT * FROM {test_one_blob} WHERE id = :id', array(':id' => $id))->fetchAssoc();
+    $r = db_static_query('SELECT * FROM {test_one_blob} WHERE id = :id', array(':id' => $id))->fetchAssoc();
     $this->assertTrue($r['blob1'] === $data, t('Can insert a blob: id @id, @data.', array('@id' => $id, '@data' => serialize($r))));
   }
 
@@ -626,7 +626,7 @@ class DatabaseInsertLOBTestCase extends DatabaseTestCase {
         'blob2' => 'a test',
       ))
       ->execute();
-    $r = db_query('SELECT * FROM {test_two_blobs} WHERE id = :id', array(':id' => $id))->fetchAssoc();
+    $r = db_static_query('SELECT * FROM {test_two_blobs} WHERE id = :id', array(':id' => $id))->fetchAssoc();
     $this->assertTrue($r['blob1'] === 'This is' && $r['blob2'] === 'a test', t('Can insert multiple blobs per row.'));
   }
 }
@@ -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_static_query('SELECT job FROM {test} WHERE id = :id', array(':id' => $id))->fetchField();
     $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_static_query('SELECT COUNT(*) FROM {test}')->fetchField();
 
     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_static_query('SELECT COUNT(*) FROM {test}')->fetchField();
     $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_static_query('SELECT job FROM {test} WHERE id = :id', array(':id' => $id))->fetchField();
     $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_static_query('SELECT name FROM {test} WHERE id = :id', array(':id' => 1))->fetchField();
     $this->assertIdentical($saved_name, 'Tiffany', t('Updated name successfully.'));
   }
 
@@ -728,7 +728,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_static_query('SELECT COUNT(*) FROM {test} WHERE job = :job', array(':job' => 'Musician'))->fetchField();
     $this->assertIdentical($num_matches, '2', t('Updated fields successfully.'));
   }
 
@@ -742,7 +742,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_static_query('SELECT COUNT(*) FROM {test} WHERE job = :job', array(':job' => 'Musician'))->fetchField();
     $this->assertIdentical($num_matches, '2', t('Updated fields successfully.'));
   }
 
@@ -756,7 +756,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_static_query('SELECT COUNT(*) FROM {test} WHERE job = :job', array(':job' => 'Musician'))->fetchField();
     $this->assertIdentical($num_matches, '2', t('Updated fields successfully.'));
   }
 
@@ -771,7 +771,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_static_query('SELECT COUNT(*) FROM {test} WHERE job = :job', array(':job' => 'Musician'))->fetchField();
     $this->assertIdentical($num_matches, '1', t('Updated fields successfully.'));
   }
 
@@ -803,7 +803,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_static_query('SELECT COUNT(*) FROM {test} WHERE job = :job', array(':job' => 'Musician'))->fetchField();
     $this->assertIdentical($num_matches, '2', t('Updated fields successfully.'));
   }
 
@@ -817,7 +817,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_static_query('SELECT COUNT(*) FROM {test} WHERE job = :job', array(':job' => 'Musician'))->fetchField();
     $this->assertIdentical($num_matches, '2', t('Updated fields successfully.'));
   }
 
@@ -833,7 +833,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_static_query('SELECT COUNT(*) FROM {test} WHERE job = :job', array(':job' => 'Musician'))->fetchField();
     $this->assertIdentical($num_matches, '1', t('Updated fields successfully.'));
   }
 
@@ -847,7 +847,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_static_query('SELECT COUNT(*) FROM {test} WHERE job = :job', array(':job' => 'Musician'))->fetchField();
     $this->assertIdentical($num_matches, '2', t('Updated fields successfully.'));
   }
 
@@ -861,7 +861,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_static_query('SELECT COUNT(*) FROM {test} WHERE job = :job', array(':job' => 'Musician'))->fetchField();
     $this->assertIdentical($num_matches, '1', t('Updated fields successfully.'));
   }
 
@@ -869,7 +869,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_static_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Ringo'))->fetchField();
     $GLOBALS['larry_test'] = 1;
     $num_updated = db_update('test')
       ->condition('name', 'Ringo')
@@ -878,10 +878,10 @@ 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_static_query('SELECT COUNT(*) FROM {test} WHERE job = :job', array(':job' => 'Musician'))->fetchField();
     $this->assertIdentical($num_matches, '1', t('Updated fields successfully.'));
 
-    $person = db_query('SELECT * FROM {test} WHERE name = :name', array(':name' => 'Ringo'))->fetch();
+    $person = db_static_query('SELECT * FROM {test} WHERE name = :name', array(':name' => 'Ringo'))->fetch();
     $this->assertEqual($person->name, 'Ringo', t('Name set correctly.'));
     $this->assertEqual($person->age, $before_age + 4, t('Age set correctly.'));
     $this->assertEqual($person->job, 'Musician', t('Job set correctly.'));
@@ -892,14 +892,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_static_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Ringo'))->fetchField();
     $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_static_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Ringo'))->fetchField();
     $this->assertEqual($before_age + 4, $after_age, t('Age updated correctly'));
   }
 }
@@ -933,7 +933,7 @@ class DatabaseUpdateLOBTestCase extends DatabaseTestCase {
       ->fields(array('blob1' => $data))
       ->execute();
 
-    $r = db_query('SELECT * FROM {test_one_blob} WHERE id = :id', array(':id' => $id))->fetchAssoc();
+    $r = db_static_query('SELECT * FROM {test_one_blob} WHERE id = :id', array(':id' => $id))->fetchAssoc();
     $this->assertTrue($r['blob1'] === $data, t('Can update a blob: id @id, @data.', array('@id' => $id, '@data' => serialize($r))));
   }
 
@@ -953,7 +953,7 @@ class DatabaseUpdateLOBTestCase extends DatabaseTestCase {
       ->fields(array('blob1' => 'and so', 'blob2' => 'is this'))
       ->execute();
 
-    $r = db_query('SELECT * FROM {test_two_blobs} WHERE id = :id', array(':id' => $id))->fetchAssoc();
+    $r = db_static_query('SELECT * FROM {test_two_blobs} WHERE id = :id', array(':id' => $id))->fetchAssoc();
     $this->assertTrue($r['blob1'] === 'and so' && $r['blob2'] === 'is this', t('Can update multiple blobs per row.'));
   }
 }
@@ -983,8 +983,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_static_query('SELECT COUNT(*) FROM {test_task}')->fetchField();
+    $pid_to_delete = db_static_query("SELECT * FROM {test_task} WHERE task = 'sleep'")->fetchField();
 
     $subquery = db_select('test', 't')
       ->fields('t', array('id'))
@@ -996,7 +996,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_static_query('SELECT COUNT(*) FROM {test_task}')->fetchField();
     $this->assertEqual($num_records_before, $num_records_after + $num_deleted, t('Deletion adds up.'));
   }
 
@@ -1004,14 +1004,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_static_query('SELECT COUNT(*) FROM {test}')->fetchField();
 
     $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_static_query('SELECT COUNT(*) FROM {test}')->fetchField();
     $this->assertEqual($num_records_before, $num_records_after + $num_deleted, t('Deletion adds up.'));
   }
 
@@ -1019,11 +1019,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_static_query("SELECT COUNT(*) FROM {test}")->fetchField();
 
     db_truncate('test')->execute();
 
-    $num_records_after = db_query("SELECT COUNT(*) FROM {test}")->fetchField();
+    $num_records_after = db_static_query("SELECT COUNT(*) FROM {test}")->fetchField();
     $this->assertEqual(0, $num_records_after, t('Truncate really deletes everything.'));
   }
 }
@@ -1045,7 +1045,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_static_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
 
     $result = db_merge('test_people')
       ->key(array('job' => 'Presenter'))
@@ -1057,10 +1057,10 @@ 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_static_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
     $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();
+    $person = db_static_query('SELECT * FROM {test_people} WHERE job = :job', array(':job' => 'Presenter'))->fetch();
     $this->assertEqual($person->name, 'Tiffany', t('Name set correctly.'));
     $this->assertEqual($person->age, 31, t('Age set correctly.'));
     $this->assertEqual($person->job, 'Presenter', t('Job set correctly.'));
@@ -1070,7 +1070,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_static_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
 
     $result = db_merge('test_people')
       ->key(array('job' => 'Speaker'))
@@ -1082,10 +1082,10 @@ 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_static_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
     $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();
+    $person = db_static_query('SELECT * FROM {test_people} WHERE job = :job', array(':job' => 'Speaker'))->fetch();
     $this->assertEqual($person->name, 'Tiffany', t('Name set correctly.'));
     $this->assertEqual($person->age, 31, t('Age set correctly.'));
     $this->assertEqual($person->job, 'Speaker', t('Job set correctly.'));
@@ -1095,7 +1095,7 @@ class DatabaseMergeTestCase extends DatabaseTestCase {
    * Confirm that we can merge-update a record successfully, with exclusion.
    */
   function testMergeUpdateExcept() {
-    $num_records_before = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
+    $num_records_before = db_static_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
 
     db_merge('test_people')
       ->key(array('job' => 'Speaker'))
@@ -1106,10 +1106,10 @@ class DatabaseMergeTestCase extends DatabaseTestCase {
       ->updateExcept('age')
       ->execute();
 
-    $num_records_after = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
+    $num_records_after = db_static_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
     $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();
+    $person = db_static_query('SELECT * FROM {test_people} WHERE job = :job', array(':job' => 'Speaker'))->fetch();
     $this->assertEqual($person->name, 'Tiffany', t('Name set correctly.'));
     $this->assertEqual($person->age, 30, t('Age skipped correctly.'));
     $this->assertEqual($person->job, 'Speaker', t('Job set correctly.'));
@@ -1119,7 +1119,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_static_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
 
     db_merge('test_people')
       ->key(array('job' => 'Speaker'))
@@ -1130,10 +1130,10 @@ class DatabaseMergeTestCase extends DatabaseTestCase {
       ->update(array('name' => 'Joe'))
       ->execute();
 
-    $num_records_after = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
+    $num_records_after = db_static_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
     $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();
+    $person = db_static_query('SELECT * FROM {test_people} WHERE job = :job', array(':job' => 'Speaker'))->fetch();
     $this->assertEqual($person->name, 'Joe', t('Name set correctly.'));
     $this->assertEqual($person->age, 30, t('Age skipped correctly.'));
     $this->assertEqual($person->job, 'Speaker', t('Job set correctly.'));
@@ -1143,9 +1143,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_static_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
 
-    $age_before = db_query('SELECT age FROM {test_people} WHERE job = :job', array(':job' => 'Speaker'))->fetchField();
+    $age_before = db_static_query('SELECT age FROM {test_people} WHERE job = :job', array(':job' => 'Speaker'))->fetchField();
 
     // 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.
@@ -1161,10 +1161,10 @@ 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_static_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
     $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();
+    $person = db_static_query('SELECT * FROM {test_people} WHERE job = :job', array(':job' => 'Speaker'))->fetch();
     $this->assertEqual($person->name, 'Tiffany', t('Name set correctly.'));
     $this->assertEqual($person->age, $age_before + 4, t('Age updated correctly.'));
     $this->assertEqual($person->job, 'Speaker', t('Job set correctly.'));
@@ -1174,16 +1174,16 @@ 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_static_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
 
     db_merge('test_people')
       ->key(array('job' => 'Presenter'))
       ->execute();
 
-    $num_records_after = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
+    $num_records_after = db_static_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
     $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();
+    $person = db_static_query('SELECT * FROM {test_people} WHERE job = :job', array(':job' => 'Presenter'))->fetch();
     $this->assertEqual($person->name, '', t('Name set correctly.'));
     $this->assertEqual($person->age, 0, t('Age set correctly.'));
     $this->assertEqual($person->job, 'Presenter', t('Job set correctly.'));
@@ -1193,16 +1193,16 @@ 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_static_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
 
     db_merge('test_people')
       ->key(array('job' => 'Speaker'))
       ->execute();
 
-    $num_records_after = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
+    $num_records_after = db_static_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
     $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();
+    $person = db_static_query('SELECT * FROM {test_people} WHERE job = :job', array(':job' => 'Speaker'))->fetch();
     $this->assertEqual($person->name, 'Meredith', t('Name skipped correctly.'));
     $this->assertEqual($person->age, 30, t('Age skipped correctly.'));
     $this->assertEqual($person->job, 'Speaker', t('Job skipped correctly.'));
@@ -1213,10 +1213,10 @@ class DatabaseMergeTestCase extends DatabaseTestCase {
       ->updateExcept(array('age'))
       ->execute();
 
-    $num_records_after = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
+    $num_records_after = db_static_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
     $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();
+    $person = db_static_query('SELECT * FROM {test_people} WHERE job = :job', array(':job' => 'Speaker'))->fetch();
     $this->assertEqual($person->name, 'Meredith', t('Name skipped correctly.'));
     $this->assertEqual($person->age, 30, t('Age skipped correctly.'));
     $this->assertEqual($person->job, 'Speaker', t('Job skipped correctly.'));
@@ -1502,7 +1502,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_static_query("SELECT MAX(id) FROM {test}")->fetchField() < $number_of_items) {
       db_insert('test')->fields(array('name' => $this->randomName()))->execute();
     }
 
@@ -2030,7 +2030,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_static_query('SELECT COUNT(*) FROM {test}')->fetchField();
 
     $correct_number = $limit;
     $num_pages = floor($count / $limit);
@@ -2064,7 +2064,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_static_query('SELECT COUNT(*) FROM {test_task}')->fetchField();
 
     $correct_number = $limit;
     $num_pages = floor($count / $limit);
@@ -2464,7 +2464,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_static_query('SELECT name FROM {test} WHERE name = :name', array(':name' => $name))->fetchField();
     $this->assertIdentical($name, $from_database, t("The database handles UTF-8 characters cleanly."));
   }
 
@@ -2512,8 +2512,8 @@ class DatabaseLoggingTestCase extends DatabaseTestCase {
   function testEnableLogging() {
     Database::startLog('testing');
 
-    db_query('SELECT name FROM {test} WHERE age > :age', array(':age' => 25))->fetchCol();
-    db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Ringo'))->fetchCol();
+    db_static_query('SELECT name FROM {test} WHERE age > :age', array(':age' => 25))->fetchCol();
+    db_static_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Ringo'))->fetchCol();
 
     $queries = Database::getLog('testing', 'default');
 
@@ -2530,11 +2530,11 @@ class DatabaseLoggingTestCase extends DatabaseTestCase {
   function testEnableMultiLogging() {
     Database::startLog('testing1');
 
-    db_query('SELECT name FROM {test} WHERE age > :age', array(':age' => 25))->fetchCol();
+    db_static_query('SELECT name FROM {test} WHERE age > :age', array(':age' => 25))->fetchCol();
 
     Database::startLog('testing2');
 
-    db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Ringo'))->fetchCol();
+    db_static_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Ringo'))->fetchCol();
 
     $queries1 = Database::getLog('testing1');
     $queries2 = Database::getLog('testing2');
@@ -2554,9 +2554,9 @@ class DatabaseLoggingTestCase extends DatabaseTestCase {
 
     Database::startLog('testing1');
 
-    db_query('SELECT name FROM {test} WHERE age > :age', array(':age' => 25))->fetchCol();
+    db_static_query('SELECT name FROM {test} WHERE age > :age', array(':age' => 25))->fetchCol();
 
-    db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Ringo'), array('target' => 'slave'));//->fetchCol();
+    db_static_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Ringo'), array('target' => 'slave'));//->fetchCol();
 
     $queries1 = Database::getLog('testing1');
 
@@ -2575,14 +2575,14 @@ class DatabaseLoggingTestCase extends DatabaseTestCase {
   function testEnableTargetLoggingNoTarget() {
     Database::startLog('testing1');
 
-    db_query('SELECT name FROM {test} WHERE age > :age', array(':age' => 25))->fetchCol();
+    db_static_query('SELECT name FROM {test} WHERE age > :age', array(':age' => 25))->fetchCol();
 
     // We use "fake" here as a target because any non-existent target will do.
     // However, because all of the tests in this class share a single page
     // request there is likely to be a target of "slave" from one of the other
     // unit tests, so we use a target here that we know with absolute certainty
     // does not exist.
-    db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Ringo'), array('target' => 'fake'))->fetchCol();
+    db_static_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Ringo'), array('target' => 'fake'))->fetchCol();
 
     $queries1 = Database::getLog('testing1');
 
@@ -2603,11 +2603,11 @@ class DatabaseLoggingTestCase extends DatabaseTestCase {
     Database::startLog('testing1');
     Database::startLog('testing1', 'test2');
 
-    db_query('SELECT name FROM {test} WHERE age > :age', array(':age' => 25))->fetchCol();
+    db_static_query('SELECT name FROM {test} WHERE age > :age', array(':age' => 25))->fetchCol();
 
     $old_key = db_set_active('test2');
 
-    db_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Ringo'), array('target' => 'slave'))->fetchCol();
+    db_static_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Ringo'), array('target' => 'slave'))->fetchCol();
 
     db_set_active($old_key);
 
@@ -2644,7 +2644,7 @@ class DatabaseRangeQueryTestCase extends DrupalWebTestCase {
     $this->assertEqual(count($range_rows), 3, t('Range query work and return correct number of rows.'));
 
     // Test if return target data.
-    $raw_rows = db_query('SELECT name FROM {system} ORDER BY name')->fetchAll();
+    $raw_rows = db_static_query('SELECT name FROM {system} ORDER BY name')->fetchAll();
     $raw_rows = array_slice($raw_rows, 2, 3);
     $this->assertEqual($range_rows, $raw_rows, t('Range query work and return target data.'));
   }
@@ -2720,7 +2720,7 @@ class DatabaseAnsiSyntaxTestCase extends DatabaseTestCase {
    * Test for ANSI string concatenation.
    */
   function testBasicConcat() {
-    $result = db_query('SELECT :a1 || :a2 || :a3 || :a4 || :a5', array(
+    $result = db_static_query('SELECT :a1 || :a2 || :a3 || :a4 || :a5', array(
       ':a1' => 'This',
       ':a2' => ' ',
       ':a3' => 'is',
@@ -2734,7 +2734,7 @@ class DatabaseAnsiSyntaxTestCase extends DatabaseTestCase {
    * Test for ANSI string concatenation with field values.
    */
   function testFieldConcat() {
-    $result = db_query('SELECT :a1 || name || :a2 || age || :a3 FROM {test} WHERE age = :age', array(
+    $result = db_static_query('SELECT :a1 || name || :a2 || age || :a3 FROM {test} WHERE age = :age', array(
       ':a1' => 'The age of ',
       ':a2' => ' is ',
       ':a3' => '.',
@@ -2844,7 +2844,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_static_query('SELECT name FROM {test} WHERE age = :age', array(':age' => 63))->fetchField();
 
       if ($name == 'Elvis') {
         if (!Database::getConnection()->supportsTransactions()) {
@@ -2894,7 +2894,7 @@ class DatabaseQueryTestCase extends DatabaseTestCase {
    * Test that we can specify an array of values in the query by simply passing in an array.
    */
   function testArraySubstitution() {
-    $names = db_query('SELECT name FROM {test} WHERE age IN (:ages) ORDER BY age', array(':ages' => array(25, 26, 27)))->fetchAll();
+    $names = db_static_query('SELECT name FROM {test} WHERE age IN (:ages) ORDER BY age', array(':ages' => array(25, 26, 27)))->fetchAll();
 
     $this->assertEqual(count($names), 3, t('Correct number of names returned'));
   }
@@ -3036,9 +3036,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_static_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DavidB'))->fetchField();
       $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_static_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DanielB'))->fetchField();
       $this->assertNotIdentical($saved_age, '19', t('Cannot retrieve DanielB row after commit.'));
     }
     catch (Exception $e) {
@@ -3062,9 +3062,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_static_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DavidB'))->fetchField();
       $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_static_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DanielB'))->fetchField();
       $this->assertIdentical($saved_age, '19', t('DanielB not rolled back, since transactions are not supported.'));
     }
     catch (Exception $e) {
@@ -3084,9 +3084,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_static_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DavidA'))->fetchField();
       $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_static_query('SELECT age FROM {test} WHERE name = :name', array(':name' => 'DanielA'))->fetchField();
       $this->assertIdentical($saved_age, '19', t('Can retrieve DanielA row after commit.'));
     }
     catch (Exception $e) {
@@ -3133,9 +3133,9 @@ class DatabaseExtraTypesTestCase extends DrupalWebTestCase {
          ->values(array('date_field' => '2100-06-30'))
          ->execute();
 
-       $num_records = (int) db_query('SELECT COUNT(*) FROM {date_table}')->fetchField();
+       $num_records = (int) db_static_query('SELECT COUNT(*) FROM {date_table}')->fetchField();
        $this->assertEqual($num_records, 3, t('Inserted 3 records, and counted 3 records'));
-       $res = db_query('SELECT date_field from {date_table} ORDER BY date_field');
+       $res = db_static_query('SELECT date_field from {date_table} ORDER BY date_field');
 
        $date = $res->fetch()->date_field;
        $this->assertEqual($date, '1856-12-31', t('Date retrieved in order @date', array('@date' => $date)));
@@ -3177,9 +3177,9 @@ class DatabaseExtraTypesTestCase extends DrupalWebTestCase {
          ->values(array('time_field' => '23:17:00'))
          ->execute();
 
-       $num_records = (int) db_query('SELECT COUNT(*) FROM {time_table}')->fetchField();
+       $num_records = (int) db_static_query('SELECT COUNT(*) FROM {time_table}')->fetchField();
        $this->assertEqual($num_records, 3, t('Inserted 3 records, and counted 3 records'));
-       $res = db_query('SELECT time_field from {time_table} ORDER BY time_field');
+       $res = db_static_query('SELECT time_field from {time_table} ORDER BY time_field');
 
        $time = $res->fetch()->time_field;
        $this->assertEqual($time, '00:01:00', t('Time retrieved in order @time', array('@time' => $time)));
diff --git modules/simpletest/tests/error_test.module modules/simpletest/tests/error_test.module
index 1e08304..111ae83 100644
--- modules/simpletest/tests/error_test.module
+++ modules/simpletest/tests/error_test.module
@@ -62,5 +62,5 @@ function error_test_trigger_exception() {
  */
 function error_test_trigger_pdo_exception() {
   define('SIMPLETEST_COLLECT_ERRORS', FALSE);
-  db_query('SELECT * FROM bananas_are_awesome');
+  db_static_query('SELECT * FROM bananas_are_awesome');
 }
diff --git modules/simpletest/tests/file.test modules/simpletest/tests/file.test
index b8afcd1..b643ece 100644
--- modules/simpletest/tests/file.test
+++ modules/simpletest/tests/file.test
@@ -560,7 +560,7 @@ class FileSaveUploadTest extends FileHookTestCase {
     $this->image = current($this->drupalGetTestFiles('image'));
     $this->assertTrue(is_file($this->image->uri), t("The file we're going to upload exists."));
 
-    $this->maxFidBefore = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField();
+    $this->maxFidBefore = db_static_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField();
 
     // Upload with replace to gurantee there's something there.
     $edit = array(
@@ -581,7 +581,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_static_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField();
     $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.'));
@@ -592,13 +592,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_static_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField();
     $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_static_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField();
 
     // Check that the correct hooks were called.
     $this->assertFileHooksCalled(array('validate', 'insert'));
@@ -1680,7 +1680,7 @@ class FileSaveTest extends FileHookTestCase {
 
     $this->assertNotNull($saved_file, t("Saving the file should give us back a file object."), 'File');
     $this->assertTrue($saved_file->fid > 0, t("A new file ID is set when saving a new file to the database."), 'File');
-    $loaded_file = db_query('SELECT * FROM {file_managed} f WHERE f.fid = :fid', array(':fid' => $saved_file->fid))->fetch(PDO::FETCH_OBJ);
+    $loaded_file = db_static_query('SELECT * FROM {file_managed} f WHERE f.fid = :fid', array(':fid' => $saved_file->fid))->fetch(PDO::FETCH_OBJ);
     $this->assertNotNull($loaded_file, t("Record exists in the database."));
     $this->assertEqual($loaded_file->status, $file->status, t("Status was saved correctly."));
     $this->assertEqual($saved_file->filesize, filesize($file->uri), t("File size was set correctly."), 'File');
@@ -1697,7 +1697,7 @@ class FileSaveTest extends FileHookTestCase {
 
     $this->assertEqual($resaved_file->fid, $saved_file->fid, t("The file ID of an existing file is not changed when updating the database."), 'File');
     $this->assertTrue($resaved_file->timestamp >= $saved_file->timestamp, t("Timestamp didn't go backwards."), 'File');
-    $loaded_file = db_query('SELECT * FROM {file_managed} f WHERE f.fid = :fid', array(':fid' => $saved_file->fid))->fetch(PDO::FETCH_OBJ);
+    $loaded_file = db_static_query('SELECT * FROM {file_managed} f WHERE f.fid = :fid', array(':fid' => $saved_file->fid))->fetch(PDO::FETCH_OBJ);
     $this->assertNotNull($loaded_file, t("Record still exists in the database."), 'File');
     $this->assertEqual($loaded_file->status, $saved_file->status, t("Status was saved correctly."));
   }
diff --git modules/simpletest/tests/menu.test modules/simpletest/tests/menu.test
index 0e6da76..0ca27c0 100644
--- modules/simpletest/tests/menu.test
+++ modules/simpletest/tests/menu.test
@@ -226,7 +226,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_static_query($sql)->fetchField();
     $this->assertEqual($name, 'original', t('Menu name is "original".'));
 
     // Change the menu_name parameter in menu_test.module, then force a menu
@@ -235,7 +235,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_static_query($sql)->fetchField();
     $this->assertEqual($name, 'changed', t('Menu name was successfully changed after rebuild.'));
   }
 
@@ -243,9 +243,9 @@ class MenuRouterTestCase extends DrupalWebTestCase {
    * Tests for menu hierarchy.
    */
   function testMenuHierarchy() {
-    $parent_link = db_query('SELECT * FROM {menu_links} WHERE link_path = :link_path', array(':link_path' => 'menu-test/hierarchy/parent'))->fetchAssoc();
-    $child_link = db_query('SELECT * FROM {menu_links} WHERE link_path = :link_path', array(':link_path' => 'menu-test/hierarchy/parent/child'))->fetchAssoc();
-    $unattached_child_link = db_query('SELECT * FROM {menu_links} WHERE link_path = :link_path', array(':link_path' => 'menu-test/hierarchy/parent/child2/child'))->fetchAssoc();
+    $parent_link = db_static_query('SELECT * FROM {menu_links} WHERE link_path = :link_path', array(':link_path' => 'menu-test/hierarchy/parent'))->fetchAssoc();
+    $child_link = db_static_query('SELECT * FROM {menu_links} WHERE link_path = :link_path', array(':link_path' => 'menu-test/hierarchy/parent/child'))->fetchAssoc();
+    $unattached_child_link = db_static_query('SELECT * FROM {menu_links} WHERE link_path = :link_path', array(':link_path' => 'menu-test/hierarchy/parent/child2/child'))->fetchAssoc();
 
     $this->assertEqual($child_link['plid'], $parent_link['mlid'], t('The parent of a directly attached child is correct.'));
     $this->assertEqual($unattached_child_link['plid'], $parent_link['mlid'], t('The parent of a non-directly attached child is correct.'));
@@ -416,14 +416,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_static_query('SELECT path from {menu_router} WHERE path = :path', array(':path' => 'admin'))->fetchField();
     $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_static_query('SELECT path from {menu_router} WHERE path = :path', array(':path' => 'admin'))->fetchField();
     $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()
@@ -431,7 +431,7 @@ class MenuRebuildTestCase extends DrupalWebTestCase {
     variable_set('menu_rebuild_needed', TRUE);
     // menu_execute_active_handler() should trigger the rebuild.
     $this->drupalGet('<front>');
-    $admin_exists = db_query('SELECT path from {menu_router} WHERE path = :path', array(':path' => 'admin'))->fetchField();
+    $admin_exists = db_static_query('SELECT path from {menu_router} WHERE path = :path', array(':path' => 'admin'))->fetchField();
     $this->assertEqual($admin_exists, 'admin', t("The menu has been rebuilt, the path 'admin' now exists again."));
   }
 
diff --git modules/simpletest/tests/module.test modules/simpletest/tests/module.test
index 9246c14..2256cd5 100644
--- modules/simpletest/tests/module.test
+++ modules/simpletest/tests/module.test
@@ -167,7 +167,7 @@ class ModuleInstallTestCase extends DrupalWebTestCase {
   function testDrupalWriteRecord() {
     // Check for data that was inserted using drupal_write_record() while the
     // 'module_test' module was being installed and enabled.
-    $data = db_query("SELECT data FROM {module_test}")->fetchCol();
+    $data = db_static_query("SELECT data FROM {module_test}")->fetchCol();
     $this->assertTrue(in_array('Data inserted in hook_install()', $data), t('Data inserted using drupal_write_record() in hook_install() is correctly saved.'));
     $this->assertTrue(in_array('Data inserted in hook_enable()', $data), t('Data inserted using drupal_write_record() in hook_enable() is correctly saved.'));
   }
@@ -199,7 +199,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_static_query("SELECT COUNT(rid) FROM {role_permission} WHERE permission = :perm", array(':perm' => 'module_test perm'))->fetchField();
     $this->assertEqual(0, $count, t('Permissions were all removed.'));
   }
 }
diff --git modules/simpletest/tests/path.test modules/simpletest/tests/path.test
index f995856..e85272a 100644
--- modules/simpletest/tests/path.test
+++ modules/simpletest/tests/path.test
@@ -181,7 +181,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_static_query("SELECT vid FROM {taxonomy_vocabulary} WHERE module = 'forum'")->fetchField();
     $tid = db_insert('taxonomy_term_data')
       ->fields(array(
         'name' => $this->randomName(),
diff --git modules/simpletest/tests/registry.test modules/simpletest/tests/registry.test
index 81bcfd8..637bcb4 100644
--- modules/simpletest/tests/registry.test
+++ modules/simpletest/tests/registry.test
@@ -24,7 +24,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_static_query('SELECT name FROM {registry} WHERE name = :name', array(':name' => $this->$resource))->fetchField();
       $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_static_query('SELECT name FROM {registry} WHERE name = :name', array(':name' => $this->$fileType->$resource))->fetchField();
         $this->assertTrue($this->$fileType->$resource == $foundName, t('Resource "@resource" found.', array('@resource' => $this->$fileType->$resource)));
       }
       // Test that we have the right file creation and modification dates.
-      $dates = db_query('SELECT filectime, filemtime FROM {registry_file} WHERE filename = :filename', array(':filename' => $this->$fileType->fileName))->fetchObject();
+      $dates = db_static_query('SELECT filectime, filemtime FROM {registry_file} WHERE filename = :filename', array(':filename' => $this->$fileType->fileName))->fetchObject();
       $this->assertEqual($dates->filectime, filectime($this->$fileType->fileName), t('File creation date matches for %filename.', array('%filename' => $this->$fileType->fileName)));
       $this->assertEqual($dates->filemtime, filemtime($this->$fileType->fileName), t('File modification date matches for %filename.', array('%filename' => $this->$fileType->fileName)));
     }
diff --git modules/simpletest/tests/schema.test modules/simpletest/tests/schema.test
index 53e8ea7..d4193f5 100644
--- modules/simpletest/tests/schema.test
+++ modules/simpletest/tests/schema.test
@@ -83,7 +83,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_static_query('SELECT COUNT(*) FROM {test_table2}')->fetchField();
     $this->assertEqual($count, 2, t('Two fields were successfully inserted.'));
 
     // Try to drop the table.
@@ -105,12 +105,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_static_query('SELECT MAX(test_serial) FROM {test_table}')->fetchField();
     $this->assertTrue($this->tryInsert(), t('Insert with a serial succeeded.'));
-    $max2 = db_query('SELECT MAX(test_serial) FROM {test_table}')->fetchField();
+    $max2 = db_static_query('SELECT MAX(test_serial) FROM {test_table}')->fetchField();
     $this->assertTrue($max2 > $max1, t('The serial is monotone.'));
 
-    $count = db_query('SELECT COUNT(*) FROM {test_table}')->fetchField();
+    $count = db_static_query('SELECT COUNT(*) FROM {test_table}')->fetchField();
     $this->assertEqual($count, 2, t('There were two rows.'));
   }
 
diff --git modules/simpletest/tests/session.test modules/simpletest/tests/session.test
index 1b74405..ce19268 100644
--- modules/simpletest/tests/session.test
+++ modules/simpletest/tests/session.test
@@ -375,7 +375,7 @@ class SessionHttpsTestCase extends DrupalWebTestCase {
       ':sid' => $sid,
       ':ssid' => $ssid,
     );
-    return $this->assertTrue(db_query('SELECT sid FROM {sessions} WHERE sid = :sid AND ssid = :ssid', $args)->fetchField(), $assertion_text);
+    return $this->assertTrue(db_static_query('SELECT sid FROM {sessions} WHERE sid = :sid AND ssid = :ssid', $args)->fetchField(), $assertion_text);
   }
 
   protected function httpsUrl($url) {
diff --git modules/statistics/statistics.admin.inc modules/statistics/statistics.admin.inc
index b9e986b..3f341b5 100644
--- modules/statistics/statistics.admin.inc
+++ modules/statistics/statistics.admin.inc
@@ -193,7 +193,7 @@ function statistics_top_referrers() {
  * Menu callback; Displays recent page accesses.
  */
 function statistics_access_log($aid) {
-  $access = db_query('SELECT a.*, u.name FROM {accesslog} a LEFT JOIN {users} u ON a.uid = u.uid WHERE aid = :aid', array(':aid' => $aid))->fetch();
+  $access = db_static_query('SELECT a.*, u.name FROM {accesslog} a LEFT JOIN {users} u ON a.uid = u.uid WHERE aid = :aid', array(':aid' => $aid))->fetch();
   if ($access) {
     $rows[] = array(
       array('data' => t('URL'), 'header' => TRUE),
diff --git modules/statistics/statistics.module modules/statistics/statistics.module
index 983dba4..019e384 100644
--- modules/statistics/statistics.module
+++ modules/statistics/statistics.module
@@ -302,7 +302,7 @@ function statistics_get($nid) {
 
   if ($nid > 0) {
     // Retrieve an array with both totalcount and daycount.
-    return db_query('SELECT totalcount, daycount, timestamp FROM {node_counter} WHERE nid = :nid', array(':nid' => $nid), array('target' => 'slave'))->fetchAssoc();
+    return db_static_query('SELECT totalcount, daycount, timestamp FROM {node_counter} WHERE nid = :nid', array(':nid' => $nid), array('target' => 'slave'))->fetchAssoc();
   }
 }
 
@@ -424,5 +424,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_static_query('SELECT MAX(totalcount) FROM {node_counter}')->fetchField()));
 }
diff --git modules/statistics/statistics.test modules/statistics/statistics.test
index 8922144..33778af 100644
--- modules/statistics/statistics.test
+++ modules/statistics/statistics.test
@@ -79,7 +79,7 @@ class StatisticsLoggingTestCase extends DrupalWebTestCase {
     // Verify logging of an uncached page.
     $this->drupalGet($path);
     $this->assertIdentical($this->drupalGetHeader('X-Drupal-Cache'), 'MISS', t('Testing an uncached page.'));
-    $log = db_query('SELECT * FROM {accesslog}')->fetchAll(PDO::FETCH_ASSOC);
+    $log = db_static_query('SELECT * FROM {accesslog}')->fetchAll(PDO::FETCH_ASSOC);
     $this->assertTrue(is_array($log) && count($log) == 1, t('Page request was logged.'));
     $this->assertEqual(array_intersect_key($log[0], $expected), $expected);
     $node_counter = statistics_get($this->node->nid);
@@ -88,7 +88,7 @@ class StatisticsLoggingTestCase extends DrupalWebTestCase {
     // Verify logging of a cached page.
     $this->drupalGet($path);
     $this->assertIdentical($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', t('Testing a cached page.'));
-    $log = db_query('SELECT * FROM {accesslog}')->fetchAll(PDO::FETCH_ASSOC);
+    $log = db_static_query('SELECT * FROM {accesslog}')->fetchAll(PDO::FETCH_ASSOC);
     $this->assertTrue(is_array($log) && count($log) == 2, t('Page request was logged.'));
     $this->assertEqual(array_intersect_key($log[1], $expected), $expected);
     $node_counter = statistics_get($this->node->nid);
@@ -218,7 +218,7 @@ class StatisticsBlockVisitorsTestCase extends StatisticsTestCase {
     $edit = array();
     $edit['ip'] = $test_ip_address;
     $this->drupalPost('admin/config/people/ip-blocking', $edit, t('Save'));
-    $ip = db_query("SELECT iid from {blocked_ips} WHERE ip = :ip", array(':ip' => $edit['ip']))->fetchField();
+    $ip = db_static_query("SELECT iid from {blocked_ips} WHERE ip = :ip", array(':ip' => $edit['ip']))->fetchField();
     $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.'));
 
diff --git modules/system/system.admin.inc modules/system/system.admin.inc
index 618e2b8..a7c8876 100644
--- modules/system/system.admin.inc
+++ modules/system/system.admin.inc
@@ -23,8 +23,8 @@ function system_main_admin_page($arg = NULL) {
     drupal_set_message(t('One or more problems were detected with your Drupal installation. Check the <a href="@status">status report</a> for more information.', array('@status' => url('admin/reports/status'))), 'error');
   }
   $blocks = array();
-  if ($admin = db_query("SELECT menu_name, mlid FROM {menu_links} WHERE link_path = 'admin' AND module = 'system'")->fetchAssoc()) {
-    $result = db_query("
+  if ($admin = db_static_query("SELECT menu_name, mlid FROM {menu_links} WHERE link_path = 'admin' AND module = 'system'")->fetchAssoc()) {
+    $result = db_static_query("
       SELECT m.*, ml.*
       FROM {menu_links} ml
       INNER JOIN {menu_router} m ON ml.router_path = m.path
@@ -79,8 +79,8 @@ function system_admin_config_page() {
     drupal_set_message(t('One or more problems were detected with your Drupal installation. Check the <a href="@status">status report</a> for more information.', array('@status' => url('admin/reports/status'))), 'error');
   }
   $blocks = array();
-  if ($admin = db_query("SELECT menu_name, mlid FROM {menu_links} WHERE link_path = 'admin/config' AND module = 'system'")->fetchAssoc()) {
-    $result = db_query("
+  if ($admin = db_static_query("SELECT menu_name, mlid FROM {menu_links} WHERE link_path = 'admin/config' AND module = 'system'")->fetchAssoc()) {
+    $result = db_static_query("
       SELECT m.*, ml.*
       FROM {menu_links} ml
       INNER JOIN {menu_router} m ON ml.router_path = m.path
@@ -1281,7 +1281,7 @@ function system_modules_uninstall($form, $form_state = NULL) {
   }
 
   // Pull all disabled modules from the system table.
-  $disabled_modules = db_query("SELECT name, filename, info FROM {system} WHERE type = 'module' AND status = 0 AND schema_version > :schema ORDER BY name", array(':schema' => SCHEMA_UNINSTALLED));
+  $disabled_modules = db_static_query("SELECT name, filename, info FROM {system} WHERE type = 'module' AND status = 0 AND schema_version > :schema ORDER BY name", array(':schema' => SCHEMA_UNINSTALLED));
   foreach ($disabled_modules as $module) {
     // Grab the module info
     $info = unserialize($module->info);
@@ -1399,7 +1399,7 @@ function system_ip_blocking($default_ip = '') {
   $output = '';
   $rows = array();
   $header = array(t('IP address'), t('Operations'));
-  $result = db_query('SELECT * FROM {blocked_ips}');
+  $result = db_static_query('SELECT * FROM {blocked_ips}');
   foreach ($result as $ip) {
     $rows[] = array(
       $ip->ip,
@@ -1446,7 +1446,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_static_query("SELECT * FROM {blocked_ips} WHERE ip = :ip", array(':ip' => $ip))->fetchField()) {
     form_set_error('ip', t('This IP address is already blocked.'));
   }
   elseif ($ip == ip_address()) {
@@ -2850,7 +2850,7 @@ function system_actions_manage() {
   }
 
   $row = array();
-  $instances_present = db_query("SELECT aid FROM {actions} WHERE parameters <> ''")->fetchField();
+  $instances_present = db_static_query("SELECT aid FROM {actions} WHERE parameters <> ''")->fetchField();
   $header = array(
     array('data' => t('Action type'), 'field' => 'type'),
     array('data' => t('Label'), 'field' => 'label'),
@@ -2962,7 +2962,7 @@ function system_actions_configure($form, &$form_state, $action = NULL) {
   if (is_numeric($action)) {
     $aid = $action;
     // Load stored parameter values from database.
-    $data = db_query("SELECT * FROM {actions} WHERE aid = :aid", array(':aid' => $aid))->fetch();
+    $data = db_static_query("SELECT * FROM {actions} WHERE aid = :aid", array(':aid' => $aid))->fetch();
     $edit['actions_label'] = $data->label;
     $edit['actions_type'] = $data->type;
     $function = $data->callback;
diff --git modules/system/system.api.php modules/system/system.api.php
index 32c55cf..fae025e 100644
--- modules/system/system.api.php
+++ modules/system/system.api.php
@@ -390,7 +390,7 @@ function hook_cron() {
 
   // Long-running operation example, leveraging a queue:
   // Fetch feeds from other sites.
-  $result = db_query('SELECT * FROM {aggregator_feed} WHERE checked + refresh < :time AND refresh != :never', array(
+  $result = db_static_query('SELECT * FROM {aggregator_feed} WHERE checked + refresh < :time AND refresh != :never', array(
     ':time' => REQUEST_TIME,
     ':never' => AGGREGATOR_CLEAR_NEVER,
   ));
@@ -819,7 +819,7 @@ function hook_page_build(&$page) {
  * load and return an "abc" object with internal id 123:
  * @code
  *   function mymodule_abc_load($abc_id) {
- *     return db_query("SELECT * FROM {mymodule_abc} WHERE abc_id = :abc_id", array(':abc_id' => $abc_id))->fetchObject();
+ *     return db_static_query("SELECT * FROM {mymodule_abc} WHERE abc_id = :abc_id", array(':abc_id' => $abc_id))->fetchObject();
  *   }
  * @endcode
  * This 'abc' object will then be passed into the page callback function
@@ -1074,7 +1074,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_result(db_query("SELECT mlid, menu_name, status FROM {menu_example} WHERE mlid = :mlid", array(':mlid' => $link['mlid'])));
+  $menu_name = db_result(db_static_query("SELECT mlid, menu_name, status FROM {menu_example} WHERE mlid = :mlid", array(':mlid' => $link['mlid'])));
   if ($menu_name != $link['menu_name']) {
     db_update('menu_example')
       ->fields(array('menu_name' => $link['menu_name']))
@@ -2187,7 +2187,7 @@ function hook_stream_wrappers_alter(&$wrappers) {
  */
 function hook_file_load($files) {
   // Add the upload specific data into the file object.
-  $result = db_query('SELECT * FROM {upload} u WHERE u.fid IN (:fids)', array(':fids' => array_keys($files)))->fetchAll(PDO::FETCH_ASSOC);
+  $result = db_static_query('SELECT * FROM {upload} u WHERE u.fid IN (:fids)', array(':fids' => array_keys($files)))->fetchAll(PDO::FETCH_ASSOC);
   foreach ($result as $record) {
     foreach ($record as $key => $value) {
       $files[$record['fid']]->$key = $value;
@@ -2342,7 +2342,7 @@ function hook_file_download($uri) {
   if (!file_prepare_directory($uri)) {
     $uri = FALSE;
   }
-  $result = db_query("SELECT f.* FROM {file_managed} f INNER JOIN {upload} u ON f.fid = u.fid WHERE uri = :uri", array('uri' => $uri));
+  $result = db_static_query("SELECT f.* FROM {file_managed} f INNER JOIN {upload} u ON f.fid = u.fid WHERE uri = :uri", array('uri' => $uri));
   foreach ($result as $file) {
     if (!user_access('view uploaded files')) {
       return -1;
@@ -2783,7 +2783,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_static_query('SELECT COUNT(DISTINCT uid) FROM {users}')->fetchField() - 1;
   }
   db_select('users', 'u')
     ->fields('u', array('uid', 'name'))
diff --git modules/system/system.install modules/system/system.install
index 38eec36..63b9eda 100644
--- modules/system/system.install
+++ modules/system/system.install
@@ -1581,7 +1581,7 @@ function system_update_last_removed() {
  * Rename blog and forum permissions to be consistent with other content types.
  */
 function system_update_7000() {
-  $result = db_query("SELECT rid, perm FROM {permission} ORDER BY rid");
+  $result = db_static_query("SELECT rid, perm FROM {permission} ORDER BY rid");
   foreach ($result as $role) {
     $renamed_permission = preg_replace('/(?<=^|,\ )create\ blog\ entries(?=,|$)/', 'create blog content', $role->perm);
     $renamed_permission = preg_replace('/(?<=^|,\ )edit\ own\ blog\ entries(?=,|$)/', 'edit own blog content', $role->perm);
@@ -1647,7 +1647,7 @@ function system_update_7002() {
 function system_update_7003() {
   $messages = array();
   $type = 'host';
-  $result = db_query("SELECT mask FROM {access} WHERE status = :status AND type = :type", array(
+  $result = db_static_query("SELECT mask FROM {access} WHERE status = :status AND type = :type", array(
     ':status' => 0,
     ':type' => $type,
   ));
@@ -1667,7 +1667,7 @@ function system_update_7003() {
   }
   // Make sure not to block any IP addresses that were specifically allowed by access rules.
   if (!empty($result)) {
-    $result = db_query("SELECT mask FROM {access} WHERE status = :status AND type = :type", array(
+    $result = db_static_query("SELECT mask FROM {access} WHERE status = :status AND type = :type", array(
       ':status' => 1,
       ':type' => $type,
     ));
@@ -1759,7 +1759,7 @@ function system_update_7006() {
 function system_update_7007() {
   // Copy the permissions from the old {permission} table to the new {role_permission} table.
   $messages = array();
-  $result = db_query("SELECT rid, perm FROM {permission} ORDER BY rid ASC");
+  $result = db_static_query("SELECT rid, perm FROM {permission} ORDER BY rid ASC");
   $query = db_insert('role_permission')->fields(array('rid', 'permission'));
   foreach ($result as $role) {
     foreach (explode(', ', $role->perm) as $perm) {
@@ -1785,7 +1785,7 @@ function system_update_7008() {
     // Add chid column and convert existing votes.
     db_add_field('poll_votes', 'chid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
     db_add_index('poll_votes', 'chid', array('chid'));
-    db_query("UPDATE {poll_votes} SET chid = (SELECT chid FROM {poll_choices} c WHERE {poll_votes}.chorder = c.chorder AND {poll_votes}.nid = c.nid)");
+    db_static_query("UPDATE {poll_votes} SET chid = (SELECT chid FROM {poll_choices} c WHERE {poll_votes}.chorder = c.chorder AND {poll_votes}.nid = c.nid)");
     // Remove old chorder column.
     db_drop_field('poll_votes', 'chorder');
   }
@@ -1819,7 +1819,7 @@ function system_update_7010() {
 function system_update_7011() {
   // Get existing roles that can 'administer nodes'.
   $rids = array();
-  $rids = db_query("SELECT rid FROM {role_permission} WHERE permission = :perm", array(':perm' => 'administer nodes'))->fetchCol();
+  $rids = db_static_query("SELECT rid FROM {role_permission} WHERE permission = :perm", array(':perm' => 'administer nodes'))->fetchCol();
   // None found.
   if (empty($rids)) {
     return;
@@ -1851,7 +1851,7 @@ function system_update_7013() {
   // the time zone name and use it as the default time zone.
   if (!$timezone && ($timezone_id = variable_get('date_default_timezone_id', 0))) {
     try {
-      $timezone_name = db_query('SELECT name FROM {event_timezones} WHERE timezone = :timezone_id', array(':timezone_id' => $timezone_id))->fetchField();
+      $timezone_name = db_static_query('SELECT name FROM {event_timezones} WHERE timezone = :timezone_id', array(':timezone_id' => $timezone_id))->fetchField();
       if (($timezone_name = str_replace(' ', '_', $timezone_name)) && isset($timezones[$timezone_name])) {
         $timezone = $timezone_name;
       }
@@ -1902,7 +1902,7 @@ function system_update_7015() {
 function system_update_7016() {
   // Only run these queries if the driver used is pgsql.
   if (db_driver() == 'pgsql') {
-    $result = db_query("SELECT c.relname AS table, a.attname AS field,
+    $result = db_static_query("SELECT c.relname AS table, a.attname AS field,
                         pg_catalog.format_type(a.atttypid, a.atttypmod) AS type
                         FROM pg_catalog.pg_attribute a
                         LEFT JOIN pg_class c ON (c.oid =  a.attrelid)
@@ -1919,12 +1919,12 @@ function system_update_7016() {
           $datatype = 'bigint';
           break;
       }
-      db_query('ALTER TABLE ' . $row->table . ' ALTER COLUMN ' . $row->field . ' TYPE ' . $datatype);
-      db_query('ALTER TABLE ' . $row->table . ' ADD CHECK (' . $row->field . ' >= 0)');
+      db_static_query('ALTER TABLE ' . $row->table . ' ALTER COLUMN ' . $row->field . ' TYPE ' . $datatype);
+      db_static_query('ALTER TABLE ' . $row->table . ' ADD CHECK (' . $row->field . ' >= 0)');
     }
-    db_query('DROP DOMAIN smallint_unsigned');
-    db_query('DROP DOMAIN int_unsigned');
-    db_query('DROP DOMAIN bigint_unsigned');
+    db_static_query('DROP DOMAIN smallint_unsigned');
+    db_static_query('DROP DOMAIN int_unsigned');
+    db_static_query('DROP DOMAIN bigint_unsigned');
   }
 }
 
@@ -1988,7 +1988,7 @@ function system_update_7021() {
  */
 function system_update_7024() {
   if (db_driver() == 'pgsql') {
-    db_query('CREATE OR REPLACE FUNCTION "substring_index"(text, text, integer) RETURNS text AS
+    db_static_query('CREATE OR REPLACE FUNCTION "substring_index"(text, text, integer) RETURNS text AS
       \'SELECT array_to_string((string_to_array($1, $2)) [1:$3], $2);\'
       LANGUAGE \'sql\''
     );
@@ -2152,7 +2152,7 @@ function system_update_7035() {
 
   // The old {files} tables still exists.  We migrate core data from upload
   // module, but any contrib module using it will need to do its own update.
-  $result = db_query('SELECT f.fid, uid, filename, filepath AS uri, filemime, filesize, status, timestamp FROM {files} f INNER JOIN {upload} u ON u.fid = f.fid', array(), array('fetch' => PDO::FETCH_ASSOC));
+  $result = db_static_query('SELECT f.fid, uid, filename, filepath AS uri, filemime, filesize, status, timestamp FROM {files} f INNER JOIN {upload} u ON u.fid = f.fid', array(), array('fetch' => PDO::FETCH_ASSOC));
 
   // We will convert filepaths to uri using the default schmeme
   // and stripping off the existing file directory path.
@@ -2174,7 +2174,7 @@ function system_update_7035() {
  */
 function system_update_7036() {
   // Get existing roles that can 'administer site configuration'.
-  $rids = db_query("SELECT rid FROM {role_permission} WHERE permission = :perm", array(':perm' => 'administer site configuration'))->fetchCol();
+  $rids = db_static_query("SELECT rid FROM {role_permission} WHERE permission = :perm", array(':perm' => 'administer site configuration'))->fetchCol();
   // None found.
   if (empty($rids)) {
     return;
diff --git modules/system/system.module modules/system/system.module
index f2970a9..cceb4c0 100644
--- modules/system/system.module
+++ modules/system/system.module
@@ -1553,7 +1553,7 @@ function system_stream_wrappers() {
  *   The blocked IP address from the database as an array.
  */
 function blocked_ip_load($iid) {
-  return db_query("SELECT * FROM {blocked_ips} WHERE iid = :iid", array(':iid' => $iid))->fetchAssoc();
+  return db_static_query("SELECT * FROM {blocked_ips} WHERE iid = :iid", array(':iid' => $iid))->fetchAssoc();
 }
 
 /**
@@ -1982,7 +1982,7 @@ function system_block_view($delta = '') {
 function system_admin_menu_block($item) {
   $cache = &drupal_static(__FUNCTION__, array());
   if (!isset($item['mlid'])) {
-    $item += db_query("SELECT mlid, menu_name FROM {menu_links} ml WHERE ml.router_path = :path AND module = 'system'", array(':path' => $item['path']))->fetchAssoc();
+    $item += db_static_query("SELECT mlid, menu_name FROM {menu_links} ml WHERE ml.router_path = :path AND module = 'system'", array(':path' => $item['path']))->fetchAssoc();
   }
 
   if (isset($cache[$item['mlid']])) {
@@ -1992,7 +1992,7 @@ function system_admin_menu_block($item) {
   $content = array();
   $default_task = NULL;
   $has_subitems = FALSE;
-  $result = db_query("
+  $result = db_static_query("
     SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.delivery_callback, m.title, m.title_callback, m.title_arguments, m.theme_callback, m.theme_arguments, m.type, m.description, m.path, m.weight as router_weight, ml.*
     FROM {menu_router} m
     LEFT JOIN {menu_links} ml ON m.path = ml.router_path
@@ -2091,7 +2091,7 @@ function system_check_directory($form_element) {
  */
 function system_get_files_database(&$files, $type) {
   // Extract current files from database.
-  $result = db_query("SELECT filename, name, type, status, schema_version, weight FROM {system} WHERE type = :type", array(':type' => $type));
+  $result = db_static_query("SELECT filename, name, type, status, schema_version, weight FROM {system} WHERE type = :type", array(':type' => $type));
   foreach ($result as $file) {
     if (isset($files[$file->name]) && is_object($files[$file->name])) {
       $file->uri = $file->filename;
@@ -2113,7 +2113,7 @@ function system_get_files_database(&$files, $type) {
  *   The type of the files.
  */
 function system_update_files_database(&$files, $type) {
-  $result = db_query("SELECT * FROM {system} WHERE type = :type", array(':type' => $type));
+  $result = db_static_query("SELECT * FROM {system} WHERE type = :type", array(':type' => $type));
 
   // Add all files that need to be deleted to a DatabaseCondition.
   $delete = db_or();
@@ -2206,7 +2206,7 @@ function system_update_files_database(&$files, $type) {
  */
 function system_get_info($type) {
   $info = array();
-  $result = db_query('SELECT name, info FROM {system} WHERE type = :type AND status = 1', array(':type' => $type));
+  $result = db_static_query('SELECT name, info FROM {system} WHERE type = :type AND status = 1', array(':type' => $type));
   foreach ($result as $item) {
     $info[$item->name] = unserialize($item->info);
   }
@@ -2759,7 +2759,7 @@ function system_get_module_admin_tasks($module) {
   $items = &drupal_static(__FUNCTION__, array());
 
   if (empty($items)) {
-    $result = db_query("
+    $result = db_static_query("
        SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.delivery_callback, m.title, m.title_callback, m.title_arguments, m.theme_callback, m.theme_arguments, m.type, ml.*
        FROM {menu_links} ml INNER JOIN {menu_router} m ON ml.router_path = m.path WHERE ml.link_path LIKE 'admin/%' AND hidden >= 0 AND module = 'system' AND m.number_parts > 2", array(), array('fetch' => PDO::FETCH_ASSOC));
     foreach ($result as $item) {
@@ -2804,7 +2804,7 @@ function system_cron() {
   // Remove temporary files that are older than DRUPAL_MAXIMUM_TEMP_FILE_AGE.
   // Use separate placeholders for the status to avoid a bug in some versions
   // of PHP. See http://drupal.org/node/352956.
-  $result = db_query('SELECT fid FROM {file_managed} WHERE status & :permanent1 <> :permanent2 AND timestamp < :timestamp', array(
+  $result = db_static_query('SELECT fid FROM {file_managed} WHERE status & :permanent1 <> :permanent2 AND timestamp < :timestamp', array(
     ':permanent1' => FILE_STATUS_PERMANENT,
     ':permanent2' => FILE_STATUS_PERMANENT,
     ':timestamp' => REQUEST_TIME - DRUPAL_MAXIMUM_TEMP_FILE_AGE
@@ -3353,7 +3353,7 @@ function system_get_date_formats($type = NULL) {
  *   Array of date format details.
  */
 function system_get_date_format($dfid) {
-  return db_query('SELECT df.dfid, df.format, df.type, df.locked FROM {date_formats} df WHERE df.dfid = :dfid', array(':dfid' => $dfid))->fetch();
+  return db_static_query('SELECT df.dfid, df.format, df.type, df.locked FROM {date_formats} df WHERE df.dfid = :dfid', array(':dfid' => $dfid))->fetch();
 }
 
 /**
@@ -3392,7 +3392,7 @@ function system_date_format_locale($langcode = NULL, $type = NULL) {
 
   if (empty($formats)) {
     $formats = array();
-    $result = db_query("SELECT format, type, language FROM {date_format_locale}");
+    $result = db_static_query("SELECT format, type, language FROM {date_format_locale}");
     foreach ($result as $record) {
       if (!isset($formats[$record->language])) {
         $formats[$record->language] = array();
@@ -3437,7 +3437,7 @@ function _system_date_format_types_build() {
   }
 
   // Get custom formats added to the database by the end user.
-  $result = db_query('SELECT dft.type, dft.title, dft.locked FROM {date_format_type} dft ORDER BY dft.title');
+  $result = db_static_query('SELECT dft.type, dft.title, dft.locked FROM {date_format_type} dft ORDER BY dft.title');
   foreach ($result as $record) {
     if (!in_array($record->type, $types)) {
       $type = array();
@@ -3504,7 +3504,7 @@ function _system_date_formats_build() {
   }
 
   // Get custom formats added to the database by the end user.
-  $result = db_query('SELECT df.dfid, df.format, df.type, df.locked, dfl.language FROM {date_formats} df LEFT JOIN {date_format_type} dft ON df.type = dft.type LEFT JOIN {date_format_locale} dfl ON df.format = dfl.format AND df.type = dfl.type ORDER BY df.type, df.format');
+  $result = db_static_query('SELECT df.dfid, df.format, df.type, df.locked, dfl.language FROM {date_formats} df LEFT JOIN {date_format_type} dft ON df.type = dft.type LEFT JOIN {date_format_locale} dfl ON df.format = dfl.format AND df.type = dfl.type ORDER BY df.type, df.format');
   foreach ($result as $record) {
     // If this date type isn't set, initialise the array.
     if (!isset($date_formats[$record->type])) {
diff --git modules/system/system.queue.inc modules/system/system.queue.inc
index 2698996..9e38c51 100644
--- modules/system/system.queue.inc
+++ modules/system/system.queue.inc
@@ -196,7 +196,7 @@ class SystemQueue implements DrupalQueueInterface {
   }
 
   public function numberOfItems() {
-    return db_query('SELECT COUNT(item_id) FROM {queue} WHERE name = :name', array(':name' => $this->name))->fetchField();
+    return db_static_query('SELECT COUNT(item_id) FROM {queue} WHERE name = :name', array(':name' => $this->name))->fetchField();
   }
 
   public function claimItem($lease_time = 30) {
diff --git modules/system/system.test modules/system/system.test
index d94f114..13272ef 100644
--- modules/system/system.test
+++ modules/system/system.test
@@ -355,7 +355,7 @@ class IPAddressBlockingTestCase extends DrupalWebTestCase {
     $edit = array();
     $edit['ip'] = '192.168.1.1';
     $this->drupalPost('admin/config/people/ip-blocking', $edit, t('Save'));
-    $ip = db_query("SELECT iid from {blocked_ips} WHERE ip = :ip", array(':ip' => $edit['ip']))->fetchField();
+    $ip = db_static_query("SELECT iid from {blocked_ips} WHERE ip = :ip", array(':ip' => $edit['ip']))->fetchField();
     $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.'));
 
@@ -386,7 +386,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('Save'));
-    $ip = db_query("SELECT iid from {blocked_ips} WHERE ip = :ip", array(':ip' => $submit_ip))->fetchField();
+    $ip = db_static_query("SELECT iid from {blocked_ips} WHERE ip = :ip", array(':ip' => $submit_ip))->fetchField();
     $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.'));
 
@@ -1680,7 +1680,7 @@ class UpdateScriptFunctionalTest extends DrupalWebTestCase {
     $user1->pass_raw = user_password();
     require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
     $user1->pass = user_hash_password(trim($user1->pass_raw));
-    db_query("UPDATE {users} SET pass = :pass WHERE uid = :uid", array(':pass' => $user1->pass, ':uid' => $user1->uid));
+    db_static_query("UPDATE {users} SET pass = :pass WHERE uid = :uid", array(':pass' => $user1->pass, ':uid' => $user1->uid));
     $this->drupalLogin($user1);
     $this->drupalGet($this->update_url, array('external' => TRUE));
     $this->assertResponse(200);
@@ -1693,10 +1693,10 @@ class UpdateScriptFunctionalTest extends DrupalWebTestCase {
     // Since visiting update.php triggers a rebuild of the theme system from an
     // unusual maintenance mode environment, we check that this rebuild did not
     // put any incorrect information about the themes into the database.
-    $original_theme_data = db_query("SELECT * FROM {system} WHERE type = 'theme' ORDER BY name")->fetchAll();
+    $original_theme_data = db_static_query("SELECT * FROM {system} WHERE type = 'theme' ORDER BY name")->fetchAll();
     $this->drupalLogin($this->update_user);
     $this->drupalGet($this->update_url, array('external' => TRUE));
-    $final_theme_data = db_query("SELECT * FROM {system} WHERE type = 'theme' ORDER BY name")->fetchAll();
+    $final_theme_data = db_static_query("SELECT * FROM {system} WHERE type = 'theme' ORDER BY name")->fetchAll();
     $this->assertEqual($original_theme_data, $final_theme_data, t('Visiting update.php does not alter the information about themes stored in the database.'));
   }
 }
diff --git modules/taxonomy/taxonomy.api.php modules/taxonomy/taxonomy.api.php
index c66ccdf..82b0754 100644
--- modules/taxonomy/taxonomy.api.php
+++ modules/taxonomy/taxonomy.api.php
@@ -88,7 +88,7 @@ function hook_taxonomy_vocabulary_delete($vocabulary) {
  *   An array of term objects, indexed by tid.
  */
 function hook_taxonomy_term_load($terms) {
-  $result = db_query('SELECT tid, foo FROM {mytable} WHERE tid IN (:tids)', array(':tids' => array_keys($terms)));
+  $result = db_static_query('SELECT tid, foo FROM {mytable} WHERE tid IN (:tids)', array(':tids' => array_keys($terms)));
   foreach ($result as $record) {
     $terms[$record->tid]->foo = $record->foo;
   }
diff --git modules/taxonomy/taxonomy.install modules/taxonomy/taxonomy.install
index 35fbca2..8a328d3 100644
--- modules/taxonomy/taxonomy.install
+++ modules/taxonomy/taxonomy.install
@@ -262,7 +262,7 @@ function taxonomy_update_7002() {
 
   // Do a direct query here, rather than calling taxonomy_get_vocabularies(),
   // in case Taxonomy module is disabled.
-  $vids = db_query('SELECT vid FROM {taxonomy_vocabulary}')->fetchCol();
+  $vids = db_static_query('SELECT vid FROM {taxonomy_vocabulary}')->fetchCol();
   foreach ($vids as $vid) {
     $machine_name = 'vocabulary_' . $vid;
     db_update('taxonomy_vocabulary')
@@ -336,7 +336,7 @@ function taxonomy_update_7004() {
 
   // Use an inline version of Drupal 6 taxonomy_get_vocabularies() here since
   // we can no longer rely on $vocabulary->nodes from the API function.
-  $result = db_query('SELECT v.*, n.type FROM {taxonomy_vocabulary} v LEFT JOIN {taxonomy_vocabulary_node_type} n ON v.vid = n.vid ORDER BY v.weight, v.name');
+  $result = db_static_query('SELECT v.*, n.type FROM {taxonomy_vocabulary} v LEFT JOIN {taxonomy_vocabulary_node_type} n ON v.vid = n.vid ORDER BY v.weight, v.name');
   $vocabularies = array();
   foreach ($result as $record) {
     // If no node types are associated with a vocabulary, the LEFT JOIN will
@@ -449,7 +449,7 @@ function taxonomy_update_7005(&$sandbox) {
     }
 
     // Query and save data for all revisions.
-    $result = db_query('SELECT td.tid, tn.nid, td.weight, tn.vid, n.type FROM {taxonomy_term_data} td INNER JOIN {taxonomy_term_node} tn ON td.tid = tn.tid AND td.vid = :vocabulary_id INNER JOIN {node} n ON tn.nid = n.nid ORDER BY td.weight ASC', array(':vocabulary_id' => $vocabulary->vid), $sandbox['last'][$batch]);
+    $result = db_static_query('SELECT td.tid, tn.nid, td.weight, tn.vid, n.type FROM {taxonomy_term_data} td INNER JOIN {taxonomy_term_node} tn ON td.tid = tn.tid AND td.vid = :vocabulary_id INNER JOIN {node} n ON tn.nid = n.nid ORDER BY td.weight ASC', array(':vocabulary_id' => $vocabulary->vid), $sandbox['last'][$batch]);
     $deltas = array();
     foreach ($result as $record) {
       $found = TRUE;
diff --git modules/taxonomy/taxonomy.module modules/taxonomy/taxonomy.module
index 6dd9b36..881f398 100644
--- modules/taxonomy/taxonomy.module
+++ modules/taxonomy/taxonomy.module
@@ -407,7 +407,7 @@ function taxonomy_vocabulary_delete($vid) {
   db_delete('taxonomy_vocabulary')
     ->condition('vid', $vid)
     ->execute();
-  $result = db_query('SELECT tid FROM {taxonomy_term_data} WHERE vid = :vid', array(':vid' => $vid))->fetchCol();
+  $result = db_static_query('SELECT tid FROM {taxonomy_term_data} WHERE vid = :vid', array(':vid' => $vid))->fetchCol();
   foreach ($result as $tid) {
     taxonomy_term_delete($tid);
   }
@@ -687,7 +687,7 @@ function taxonomy_get_vocabularies() {
  *   An array of vocabulary ids, names, machine names, keyed by machine name.
  */
 function taxonomy_vocabulary_get_names() {
-  $names = db_query('SELECT name, machine_name, vid FROM {taxonomy_vocabulary}')->fetchAllAssoc('machine_name');
+  $names = db_static_query('SELECT name, machine_name, vid FROM {taxonomy_vocabulary}')->fetchAllAssoc('machine_name');
   return $names;
 }
 
diff --git modules/taxonomy/taxonomy.test modules/taxonomy/taxonomy.test
index d60f1e6..757af06 100644
--- modules/taxonomy/taxonomy.test
+++ modules/taxonomy/taxonomy.test
@@ -733,7 +733,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_static_query('SELECT tid FROM {taxonomy_term_antonym} WHERE tid = :tid', array(':tid' => $term->tid))->fetchField();
     $this->assertFalse($antonym, t('The antonym were deleted from the database.'));
   }
 }
diff --git modules/toolbar/toolbar.module modules/toolbar/toolbar.module
index 396c50f..147c14c 100644
--- modules/toolbar/toolbar.module
+++ modules/toolbar/toolbar.module
@@ -269,7 +269,7 @@ function toolbar_view() {
  */
 function toolbar_get_menu_tree() {
   $tree = array();
-  $admin_link = db_query("SELECT * FROM {menu_links} WHERE menu_name = 'management' AND module = 'system' AND link_path = 'admin'")->fetchAssoc();
+  $admin_link = db_static_query("SELECT * FROM {menu_links} WHERE menu_name = 'management' AND module = 'system' AND link_path = 'admin'")->fetchAssoc();
   if ($admin_link) {
     // @todo Use a function like book_menu_subtree_data().
     $tree = menu_tree_all_data('management', $admin_link, $admin_link['depth'] + 1);
diff --git modules/tracker/tracker.install modules/tracker/tracker.install
index f377ff0..bee1638 100644
--- modules/tracker/tracker.install
+++ modules/tracker/tracker.install
@@ -13,7 +13,7 @@ function tracker_uninstall() {
  * Implements hook_enable().
  */
 function tracker_enable() {
-  $max_nid = db_query('SELECT MAX(nid) FROM {node}')->fetchField();
+  $max_nid = db_static_query('SELECT MAX(nid) FROM {node}')->fetchField();
   if ($max_nid != 0) {
     variable_set('tracker_index_nid', $max_nid);
     // To avoid timing out while attempting to do a complete indexing, we
@@ -192,7 +192,7 @@ function tracker_update_7000() {
     db_create_table($name, $table);
   }
 
-  $max_nid = db_query('SELECT MAX(nid) FROM {node}')->fetchField();
+  $max_nid = db_static_query('SELECT MAX(nid) FROM {node}')->fetchField();
   if ($max_nid != 0) {
     variable_set('tracker_index_nid', $max_nid);
   }
diff --git modules/tracker/tracker.module modules/tracker/tracker.module
index 5aebccc..b22943e 100644
--- modules/tracker/tracker.module
+++ modules/tracker/tracker.module
@@ -233,7 +233,7 @@ function tracker_comment_delete($comment) {
  *   The node updated timestamp or comment timestamp.
  */
 function _tracker_add($nid, $uid, $changed) {
-  $node = db_query('SELECT nid, status, uid, changed FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchObject();
+  $node = db_static_query('SELECT nid, status, uid, changed FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchObject();
 
   // Adding a comment can only increase the changed timestamp, so our
   // calculation here is simple.
@@ -272,7 +272,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_static_query('SELECT changed FROM {node} WHERE nid = :nid', array(':nid' => $nid), array('target' => 'slave'))->fetchField();
   $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,
@@ -294,7 +294,7 @@ function _tracker_calculate_changed($nid) {
  *   The last changed timestamp of the node.
  */
 function _tracker_remove($nid, $uid = NULL, $changed = NULL) {
-  $node = db_query('SELECT nid, status, uid, changed FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchObject();
+  $node = db_static_query('SELECT nid, status, uid, changed FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchObject();
 
   // The user only keeps his or her subscription if both of the following are true:
   // (1) The node exists.
@@ -328,7 +328,7 @@ function _tracker_remove($nid, $uid = NULL, $changed = NULL) {
 
     // We only need to do this if the removed item has a timestamp that equals
     // or exceeds the listed changed timestamp for the node
-    $tracker_node = db_query('SELECT nid, changed FROM {tracker_node} WHERE nid = :nid', array(':nid' => $nid))->fetchObject();
+    $tracker_node = db_static_query('SELECT nid, changed FROM {tracker_node} WHERE nid = :nid', array(':nid' => $nid))->fetchObject();
     if ($tracker_node && $changed >= $tracker_node->changed) {
       // If we're here, the item being removed is *possibly* the item that
       // established the node's changed timestamp.
diff --git modules/tracker/tracker.pages.inc modules/tracker/tracker.pages.inc
index 0a5a596..ef5ab9e 100644
--- modules/tracker/tracker.pages.inc
+++ modules/tracker/tracker.pages.inc
@@ -40,7 +40,7 @@ function tracker_page($account = NULL, $set_title = FALSE) {
   $rows = array();
   if (!empty($nodes)) {
     // Now, get the data and put into the placeholder array
-    $result = db_query('SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, l.comment_count FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid INNER JOIN {users} u ON n.uid = u.uid WHERE n.nid IN (:nids)', array(':nids' => array_keys($nodes)), array('target' => 'slave'));
+    $result = db_static_query('SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, l.comment_count FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid INNER JOIN {users} u ON n.uid = u.uid WHERE n.nid IN (:nids)', array(':nids' => array_keys($nodes)), array('target' => 'slave'));
     foreach ($result as $node) {
       $node->last_activity = $nodes[$node->nid]->changed;
       $nodes[$node->nid] = $node;
diff --git modules/translation/translation.module modules/translation/translation.module
index c79f752..03ac1d6 100644
--- modules/translation/translation.module
+++ modules/translation/translation.module
@@ -347,7 +347,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_static_query('SELECT COUNT(*) FROM {node} WHERE tnid = :tnid', array(':tnid' => $node->tnid))->fetchField() == 1) {
       // There is only one node left in the set: remove the set altogether.
       $query
         ->condition('tnid', $node->tnid)
@@ -361,7 +361,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_static_query('SELECT nid FROM {node} WHERE tnid = :tnid ORDER BY translate ASC, nid ASC', array(':tnid' => $node->tnid))->fetchField();
         db_update('node')
           ->fields(array('tnid' => $new_tnid))
           ->condition('tnid', $node->tnid)
diff --git modules/trigger/trigger.admin.inc modules/trigger/trigger.admin.inc
index d0e1266..e2e2d99 100644
--- modules/trigger/trigger.admin.inc
+++ modules/trigger/trigger.admin.inc
@@ -204,7 +204,7 @@ function trigger_assign_form_validate($form, $form_state) {
   $form_values = $form_state['values'];
   if (!empty($form_values['aid'])) {
     $aid = actions_function_lookup($form_values['aid']);
-    $aid_exists = db_query("SELECT aid FROM {trigger_assignments} WHERE hook = :hook AND aid = :aid", array(
+    $aid_exists = db_static_query("SELECT aid FROM {trigger_assignments} WHERE hook = :hook AND aid = :aid", array(
       ':hook' => $form_values['hook'],
       ':aid' => $aid,
     ))->fetchField();
@@ -220,7 +220,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_static_query("SELECT MAX(weight) FROM {trigger_assignments} WHERE hook = :hook", array(':hook' => $form_state['values']['hook']))->fetchField();
 
     // Insert the new action.
     db_insert('trigger_assignments')
@@ -244,7 +244,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_static_query("SELECT aid FROM {trigger_assignments} WHERE hook = :hook AND aid = :aid", array(':hook' => $form_state['values']['hook'], ':aid' => $save_action))->fetchField();
 
       if ($save_action_assigned) {
         db_delete('trigger_assignments')
diff --git modules/trigger/trigger.install modules/trigger/trigger.install
index e34c66c..e909fbb 100644
--- modules/trigger/trigger.install
+++ modules/trigger/trigger.install
@@ -54,7 +54,7 @@ function trigger_install() {
  * Adds operation names to the hook names and drops the "op" field.
  */
 function trigger_update_7000() {
-  $result = db_query("SELECT hook, op, aid FROM {trigger_assignments} WHERE op <> ''");
+  $result = db_static_query("SELECT hook, op, aid FROM {trigger_assignments} WHERE op <> ''");
 
   foreach ($result as $record) {
     db_update('trigger_assignments')
diff --git modules/trigger/trigger.module modules/trigger/trigger.module
index 93ed248..ed5dd26 100644
--- modules/trigger/trigger.module
+++ modules/trigger/trigger.module
@@ -181,7 +181,7 @@ function trigger_trigger_info() {
  *   label.
  */
 function trigger_get_assigned_actions($hook) {
-  return db_query("SELECT ta.aid, a.type, a.label FROM {trigger_assignments} ta LEFT JOIN {actions} a ON ta.aid = a.aid WHERE ta.hook = :hook ORDER BY ta.weight", array(
+  return db_static_query("SELECT ta.aid, a.type, a.label FROM {trigger_assignments} ta LEFT JOIN {actions} a ON ta.aid = a.aid WHERE ta.hook = :hook ORDER BY ta.weight", array(
     ':hook' => $hook,
   ))->fetchAllAssoc( 'aid', PDO::FETCH_ASSOC);
 }
diff --git modules/trigger/trigger.test modules/trigger/trigger.test
index fd4e2be..8412980 100644
--- modules/trigger/trigger.test
+++ modules/trigger/trigger.test
@@ -24,7 +24,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_static_query('SELECT aid FROM {actions} WHERE callback = :callback AND label = :label', array(':callback' => $action, ':label' => $edit['actions_label']))->fetchField();
   }
 
 }
@@ -92,7 +92,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_static_query("SELECT COUNT(*) FROM {trigger_assignments} WHERE aid IN (:keys)", array(':keys' => $content_actions))->fetchField();
       $this->assertFalse($assigned, t('Check to make sure unassign worked properly at the database level.'));
     }
   }
diff --git modules/update/update.module modules/update/update.module
index 1704fdf..555ec7f 100644
--- modules/update/update.module
+++ modules/update/update.module
@@ -692,7 +692,7 @@ function _update_cache_set($cid, $data, $expire) {
  *   The data for the given cache ID, or NULL if the ID was not found.
  */
 function _update_cache_get($cid) {
-  $cache = db_query("SELECT data, created, expire, serialized FROM {cache_update} WHERE cid = :cid", array(':cid' => $cid))->fetchObject();
+  $cache = db_static_query("SELECT data, created, expire, serialized FROM {cache_update} WHERE cid = :cid", array(':cid' => $cid))->fetchObject();
   if (isset($cache->data)) {
     if ($cache->serialized) {
       $cache->data = unserialize($cache->data);
diff --git modules/user/user.admin.inc modules/user/user.admin.inc
index 043ee97..0a312e4 100644
--- modules/user/user.admin.inc
+++ modules/user/user.admin.inc
@@ -192,7 +192,7 @@ function user_admin_account() {
   $accounts = array();
   foreach ($result as $account) {
     $users_roles = array();
-    $roles_result = db_query('SELECT rid FROM {users_roles} WHERE uid = :uid', array(':uid' => $account->uid));
+    $roles_result = db_static_query('SELECT rid FROM {users_roles} WHERE uid = :uid', array(':uid' => $account->uid));
     foreach ($roles_result as $user_role) {
       $users_roles[] = $roles[$user_role->rid];
     }
diff --git modules/user/user.api.php modules/user/user.api.php
index 21a10bf..d64f2f8 100644
--- modules/user/user.api.php
+++ modules/user/user.api.php
@@ -25,7 +25,7 @@
  * @see profile_user_load()
  */
 function hook_user_load($users) {
-  $result = db_query('SELECT * FROM {my_table} WHERE uid IN (:uids)', array(':uids' => array_keys($users)));
+  $result = db_static_query('SELECT * FROM {my_table} WHERE uid IN (:uids)', array(':uids' => array_keys($users)));
   foreach ($result as $record) {
     $users[$record->uid]->foo = $result->foo;
   }
diff --git modules/user/user.install modules/user/user.install
index aef0f9f..c6f89e4 100644
--- modules/user/user.install
+++ modules/user/user.install
@@ -332,7 +332,7 @@ function user_update_7000(&$sandbox) {
   if (!isset($sandbox['user_from'])) {
     db_change_field('users', 'pass', 'pass', array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''));
     $sandbox['user_from'] = 0;
-    $sandbox['user_count'] = db_query("SELECT COUNT(uid) FROM {users}")->fetchField();
+    $sandbox['user_count'] = db_static_query("SELECT COUNT(uid) FROM {users}")->fetchField();
   }
   else {
     require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
@@ -384,7 +384,7 @@ function user_update_7002(&$sandbox) {
   if (!isset($sandbox['user_from'])) {
     db_change_field('users', 'timezone', 'timezone', array('type' => 'varchar', 'length' => 32, 'not null' => FALSE));
     $sandbox['user_from'] = 0;
-    $sandbox['user_count'] = db_query("SELECT COUNT(uid) FROM {users}")->fetchField();
+    $sandbox['user_count'] = db_static_query("SELECT COUNT(uid) FROM {users}")->fetchField();
     $sandbox['user_not_migrated'] = 0;
   }
   else {
@@ -400,7 +400,7 @@ function user_update_7002(&$sandbox) {
       // If the contributed Date module has created a users.timezone_name
       // column, use this data to set each user's time zone.
       if ($contributed_date_module) {
-        $date_timezone = db_query("SELECT timezone_name FROM {users} WHERE uid = :uid", array(':uid' => $account->uid))->fetchField();
+        $date_timezone = db_static_query("SELECT timezone_name FROM {users} WHERE uid = :uid", array(':uid' => $account->uid))->fetchField();
         if (isset($timezones[$date_timezone])) {
           $timezone = $date_timezone;
         }
@@ -409,7 +409,7 @@ function user_update_7002(&$sandbox) {
       // use that information to update the user accounts.
       if (!$timezone && $contributed_event_module) {
         try {
-          $event_timezone = db_query("SELECT t.name FROM {users} u LEFT JOIN {event_timezones} t ON u.timezone_id = t.timezone WHERE u.uid = :uid", array(':uid' => $account->uid))->fetchField();
+          $event_timezone = db_static_query("SELECT t.name FROM {users} u LEFT JOIN {event_timezones} t ON u.timezone_id = t.timezone WHERE u.uid = :uid", array(':uid' => $account->uid))->fetchField();
           $event_timezone = str_replace(' ', '_', $event_timezone);
           if (isset($timezones[$event_timezone])) {
             $timezone = $event_timezone;
@@ -497,7 +497,7 @@ function user_update_7004(&$sandbox) {
     // Initialize batch update information.
     $sandbox['progress'] = 0;
     $sandbox['last_user_processed'] = -1;
-    $sandbox['max'] = db_query("SELECT COUNT(*) FROM {users} WHERE picture <> ''")->fetchField();
+    $sandbox['max'] = db_static_query("SELECT COUNT(*) FROM {users} WHERE picture <> ''")->fetchField();
   }
 
   // As a batch operation move the photos into the {file_managed} table and
diff --git modules/user/user.module modules/user/user.module
index 0256040..6c39fb4 100644
--- modules/user/user.module
+++ modules/user/user.module
@@ -202,7 +202,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_static_query("SELECT uid FROM {authmap} WHERE authname = :authname", array(':authname' => $authname))->fetchField();
 
   if ($uid) {
     return user_load($uid);
@@ -263,7 +263,7 @@ class UserController extends DrupalDefaultEntityController {
     }
 
     // Add any additional roles from the database.
-    $result = db_query('SELECT r.rid, r.name, ur.uid FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid IN (:uids)', array(':uids' => array_keys($queried_users)));
+    $result = db_static_query('SELECT r.rid, r.name, ur.uid FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid IN (:uids)', array(':uids' => array_keys($queried_users)));
     foreach ($result as $record) {
       $queried_users[$record->uid]->roles[$record->rid] = $record->name;
     }
@@ -501,7 +501,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($edit['uid'])) {
-        $edit['uid'] = db_next_id(db_query('SELECT MAX(uid) FROM {users}')->fetchField());
+        $edit['uid'] = db_next_id(db_static_query('SELECT MAX(uid) FROM {users}')->fetchField());
       }
       // Allow 'created' to be set by the caller.
       if (!isset($edit['created'])) {
@@ -693,7 +693,7 @@ function user_role_permissions($roles = array()) {
     if ($fetch) {
       // Get from the database permissions that were not in the static variable.
       // Only role IDs with at least one permission assigned will return rows.
-      $result = db_query("SELECT rid, permission FROM {role_permission} WHERE rid IN (:fetch)", array(':fetch' => $fetch));
+      $result = db_static_query("SELECT rid, permission FROM {role_permission} WHERE rid IN (:fetch)", array(':fetch' => $fetch));
 
       foreach ($result as $row) {
         $cache[$row->rid][$row->permission] = TRUE;
@@ -1333,7 +1333,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_static_query("SELECT COUNT(DISTINCT s.uid) FROM {sessions} s WHERE s.timestamp >= :timestamp AND s.uid > 0", array(':timestamp' => $interval))->fetchField();
 
         $output = '<p>' . format_plural($authenticated_count, 'There is currently 1 user online.', 'There are currently @count users online.') . '</p>';
 
@@ -1824,7 +1824,7 @@ function user_page_title($uid) {
  *   An associative array with module as key and username as value.
  */
 function user_get_authmaps($authname = NULL) {
-  $authmaps = db_query("SELECT authname, module FROM {authmap} WHERE authname = :authname", array(':authname' => $authname))->fetchAllKeyed();
+  $authmaps = db_static_query("SELECT authname, module FROM {authmap} WHERE authname = :authname", array(':authname' => $authname))->fetchAllKeyed();
   return count($authmaps) ? $authmaps : 0;
 }
 
@@ -1944,7 +1944,7 @@ function user_login_authenticate_validate($form, &$form_state) {
       $form_state['flood_control_triggered'] = 'ip';
       return;
     }
-    $account = db_query("SELECT * FROM {users} WHERE name = :name AND status = 1", array(':name' => $form_state['values']['name']))->fetchObject();
+    $account = db_static_query("SELECT * FROM {users} WHERE name = :name AND status = 1", array(':name' => $form_state['values']['name']))->fetchObject();
     if ($account) {
       if (variable_get('user_failed_login_identifier_uid_only', FALSE)) {
         // Register flood events based on the uid only, so they apply for any
@@ -2022,7 +2022,7 @@ function user_login_final_validate($form, &$form_state) {
 function user_authenticate($name, $password) {
   $uid = FALSE;
   if (!empty($name) && !empty($password)) {
-    $account = db_query("SELECT * FROM {users} WHERE name = :name AND status = 1", array(':name' => $name))->fetchObject();
+    $account = db_static_query("SELECT * FROM {users} WHERE name = :name AND status = 1", array(':name' => $name))->fetchObject();
     if ($account) {
       // Allow alternate password hashing schemes.
       require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
@@ -2928,7 +2928,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_static_query('SELECT name FROM {role} WHERE rid = :rid', array(':rid' => $rid))->fetchField();
 
   switch ($operation) {
     case 'add_role':
@@ -3315,7 +3315,7 @@ function user_node_load($nodes, $types) {
   }
 
   // Fetch name, picture, and data for these users.
-  $user_fields = db_query("SELECT uid, name, picture, data FROM {users} WHERE uid IN (:uids)", array(':uids' => $uids))->fetchAllAssoc('uid');
+  $user_fields = db_static_query("SELECT uid, name, picture, data FROM {users} WHERE uid IN (:uids)", array(':uids' => $uids))->fetchAllAssoc('uid');
 
   // Add these values back into the node objects.
   foreach ($uids as $nid => $uid) {
diff --git modules/user/user.test modules/user/user.test
index 732782d..86a12d7 100644
--- modules/user/user.test
+++ modules/user/user.test
@@ -1225,12 +1225,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_static_query("SELECT COUNT(*) FROM {sessions}")->fetchField(), 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_static_query("SELECT COUNT(*) FROM {sessions} WHERE uid = :uid", array(':uid' => $user1->uid))->fetchField(), 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));
@@ -1265,7 +1265,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_static_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.'));
   }
 }
 
@@ -1287,7 +1287,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_static_query('SELECT MAX(uid) FROM {users}')->fetchField();
     $test_uid = $max_uid + mt_rand(1000, 1000000);
     $test_name = $this->randomName();
 
diff --git scripts/run-tests.sh scripts/run-tests.sh
index 482163a..e70b944 100755
--- scripts/run-tests.sh
+++ scripts/run-tests.sh
@@ -502,7 +502,7 @@ function simpletest_script_reporter_display_results() {
       'exception' => 'Exception'
     );
 
-    $results = db_query("SELECT * FROM {simpletest} WHERE test_id = :test_id ORDER BY test_class, message_id", array(':test_id' => $test_id));
+    $results = db_static_query("SELECT * FROM {simpletest} WHERE test_id = :test_id ORDER BY test_class, message_id", array(':test_id' => $test_id));
     $test_class = '';
     foreach ($results as $result) {
       if (isset($results_map[$result->status])) {
