Index: includes/database.inc
===================================================================
--- includes/database.inc	(revision 10)
+++ includes/database.inc	(working copy)
@@ -194,7 +194,9 @@
  * @param $query
  *   Query to be rewritten.
  * @param $primary_table
- *   Name or alias of the table which has the primary key field for this query. Possible values are: comments, forum, node, menu, term_data, vocabulary.
+ *   Name or alias of the table which has the primary key field for this query.
+ *   Possible values are: blocks, comments, forum, node, menu, term_data,
+ *   vocabulary.
  * @param $primary_field
  *   Name of the primary field.
  * @param $args
Index: modules/block/block.module
===================================================================
--- modules/block/block.module	(revision 10)
+++ modules/block/block.module	(working copy)
@@ -683,7 +683,7 @@
   static $blocks = array();
 
   if (!count($blocks)) {
-    $result = db_query("SELECT DISTINCT b.* FROM {blocks} b LEFT JOIN {blocks_roles} r ON b.module = r.module AND b.delta = r.delta WHERE b.theme = '%s' AND b.status = 1 AND (r.rid IN (%s) OR r.rid IS NULL) ORDER BY b.region, b.weight, b.module", $theme_key, implode(',', array_keys($user->roles)));
+    $result = db_query(db_rewrite_sql("SELECT DISTINCT b.* FROM {blocks} b LEFT JOIN {blocks_roles} r ON b.module = r.module AND b.delta = r.delta WHERE b.theme = '%s' AND b.status = 1 AND (r.rid IN (%s) OR r.rid IS NULL) ORDER BY b.region, b.weight, b.module", 'b', 'bid'), $theme_key, implode(',', array_keys($user->roles)));
     while ($block = db_fetch_object($result)) {
       if (!isset($blocks[$block->region])) {
         $blocks[$block->region] = array();
