=== modified file 'includes/database.mysql-common.inc'
--- includes/database.mysql-common.inc	2007-10-02 16:15:56 +0000
+++ includes/database.mysql-common.inc	2007-10-08 07:22:13 +0000
@@ -530,3 +530,15 @@ function db_change_field(&$ret, $table, 
 function db_last_insert_id($table, $field) {
   return db_result(db_query('SELECT LAST_INSERT_ID()'));
 }
+
+/**
+ * Wrap a stirng in a function which makes the database compare case insensitive.
+ *
+ * @param $string
+ *   The string to be wrapped. Usually a field name or '%s'.
+ * @return
+ *   LOWER($string)
+ */
+function db_lower($string) {
+  return $string;
+}

=== modified file 'includes/database.pgsql.inc'
--- includes/database.pgsql.inc	2007-10-02 16:15:56 +0000
+++ includes/database.pgsql.inc	2007-10-08 07:21:58 +0000
@@ -424,6 +424,18 @@ function db_check_setup() {
 }
 
 /**
+ * Wrap a stirng in a function which makes the database compare case insensitive.
+ *
+ * @param $string
+ *   The string to be wrapped. Usually a field name or '%s'.
+ * @return
+ *   LOWER($string)
+ */
+function db_lower($string) {
+  return 'LOWER('. $string .')';
+}
+
+/**
  * Wraps the given table.field entry with a DISTINCT(). The wrapper is added to
  * the SELECT list entry of the given query and the resulting query is returned.
  * This function only applies the wrapper if a DISTINCT doesn't already exist in

=== modified file 'modules/comment/comment.module'
--- modules/comment/comment.module	2007-10-07 19:25:57 +0000
+++ modules/comment/comment.module	2007-10-08 07:04:21 +0000
@@ -1441,9 +1441,9 @@ function comment_validate($edit) {
   // Check validity of name, mail and homepage (if given)
   if (!$user->uid || isset($edit['is_anonymous'])) {
     $node = node_load($edit['nid']);
-    if (variable_get('comment_anonymous_'. $node->type, COMMENT_ANONYMOUS_MAYNOT_CONTACT) > COMMENT_ANONYMOUS_MAYNOT_CONTACT) {
+    if (variable_get('comment_anonymous_'. $node->type, COMMENT_ANONYMOUS_MAYNOT_CONTACT) != COMMENT_ANONYMOUS_MAYNOT_CONTACT) {
       if ($edit['name']) {
-        $taken = db_result(db_query("SELECT COUNT(uid) FROM {users} WHERE LOWER(name) = '%s'", $edit['name']));
+        $taken = db_result(db_query("SELECT COUNT(uid) FROM {users} WHERE ". db_lower('name') .' = '. db_lower("'%s'"), $edit['name']));
 
         if ($taken != 0) {
           form_set_error('name', t('The name you used belongs to a registered user.'));

=== modified file 'modules/profile/profile.module'
--- modules/profile/profile.module	2007-10-05 13:26:53 +0000
+++ modules/profile/profile.module	2007-10-08 06:54:59 +0000
@@ -765,7 +765,7 @@ function profile_form_profile($edit, $us
 function profile_autocomplete($field, $string) {
   $matches = array();
   if (db_result(db_query("SELECT COUNT(*) FROM {profile_fields} WHERE fid = %d AND autocomplete = 1", $field))) {
-    $result = db_query_range("SELECT value FROM {profile_values} WHERE fid = %d AND LOWER(value) LIKE LOWER('%s%%') GROUP BY value ORDER BY value ASC", $field, $string, 0, 10);
+    $result = db_query_range('SELECT value FROM {profile_values} WHERE fid = %d AND '. db_lower('value') .' LIKE '. db_lower("'%s%%'") .' GROUP BY value ORDER BY value ASC', $field, $string, 0, 10);
     while ($data = db_fetch_object($result)) {
       $matches[$data->value] = check_plain($data->value);
     }
@@ -901,7 +901,7 @@ function _profile_get_fields($category, 
   }
   else {
     // Use LOWER('%s') instead of PHP's strtolower() to avoid UTF-8 conversion issues.
-    $filters[] = "LOWER(category) = LOWER('%s')";
+    $filters[] = db_lower('category') .' = '. db_lower("'%s'");
     $args[] = $category;
   }
   if (!user_access('administer users')) {
@@ -918,7 +918,7 @@ function _profile_get_fields($category, 
  */
 function profile_admin_settings_autocomplete($string) {
   $matches = array();
-  $result = db_query_range("SELECT category FROM {profile_fields} WHERE LOWER(category) LIKE LOWER('%s%%')", $string, 0, 10);
+  $result = db_query_range('SELECT category FROM {profile_fields} WHERE '. db_lower('category') .' LIKE '. db_lower("'%s%%'"), $string, 0, 10);
   while ($data = db_fetch_object($result)) {
     $matches[$data->category] = check_plain($data->category);
   }

=== modified file 'modules/statistics/statistics.admin.inc'
--- modules/statistics/statistics.admin.inc	2007-08-23 16:34:44 +0000
+++ modules/statistics/statistics.admin.inc	2007-10-08 07:09:34 +0000
@@ -81,7 +81,7 @@ function statistics_top_visitors() {
     array('data' => t('Operations'))
   );
 
-  $sql = "SELECT COUNT(a.uid) AS hits, a.uid, u.name, a.hostname, SUM(a.timer) AS total, ac.aid FROM {accesslog} a LEFT JOIN {access} ac ON ac.type = 'host' AND LOWER(a.hostname) LIKE (ac.mask) LEFT JOIN {users} u ON a.uid = u.uid GROUP BY a.hostname, a.uid, u.name, ac.aid". tablesort_sql($header);
+  $sql = "SELECT COUNT(a.uid) AS hits, a.uid, u.name, a.hostname, SUM(a.timer) AS total, ac.aid FROM {accesslog} a LEFT JOIN {access} ac ON ac.type = 'host' AND ". db_lower('a.hostname') .' LIKE '. db_lower('ac.mask') .' LEFT JOIN {users} u ON a.uid = u.uid GROUP BY a.hostname, a.uid, u.name, ac.aid'. tablesort_sql($header);
   $sql_cnt = "SELECT COUNT(DISTINCT(CONCAT(uid, hostname))) FROM {accesslog}";
   $result = pager_query($sql, 30, 0, $sql_cnt);
 

=== modified file 'modules/taxonomy/taxonomy.module'
--- modules/taxonomy/taxonomy.module	2007-10-02 16:15:56 +0000
+++ modules/taxonomy/taxonomy.module	2007-10-08 07:10:39 +0000
@@ -830,7 +830,7 @@ function _taxonomy_term_children($tid) {
  *   An array of matching term objects.
  */
 function taxonomy_get_term_by_name($name) {
-  $db_result = db_query(db_rewrite_sql("SELECT t.tid, t.* FROM {term_data} t WHERE LOWER(t.name) LIKE LOWER('%s')", 't', 'tid'), trim($name));
+  $db_result = db_query(db_rewrite_sql('SELECT t.tid, t.* FROM {term_data} t WHERE '. db_lower('t.name') .' LIKE '. db_lower("'%s'"), 't', 'tid'), trim($name));
   $result = array();
   while ($term = db_fetch_object($db_result)) {
     $result[] = $term;

=== modified file 'modules/taxonomy/taxonomy.pages.inc'
--- modules/taxonomy/taxonomy.pages.inc	2007-09-27 16:52:00 +0000
+++ modules/taxonomy/taxonomy.pages.inc	2007-10-08 07:11:40 +0000
@@ -80,7 +80,7 @@ function taxonomy_autocomplete($vid, $st
   $last_string = trim(array_pop($array));
   $matches = array();
   if ($last_string != '') {
-    $result = db_query_range(db_rewrite_sql("SELECT t.tid, t.name FROM {term_data} t WHERE t.vid = %d AND LOWER(t.name) LIKE LOWER('%%%s%%')", 't', 'tid'), $vid, $last_string, 0, 10);
+    $result = db_query_range(db_rewrite_sql('SELECT t.tid, t.name FROM {term_data} t WHERE t.vid = %d AND '. db_lower('t.name') .' LIKE '. db_lower("'%%%s%%'"), 't', 'tid'), $vid, $last_string, 0, 10);
 
     $prefix = count($array) ? implode(', ', $array) .', ' : '';
 

=== modified file 'modules/user/user.module'
--- modules/user/user.module	2007-10-07 19:27:40 +0000
+++ modules/user/user.module	2007-10-08 07:16:38 +0000
@@ -153,7 +153,7 @@ function user_load($array = array()) {
       $params[] = md5($value);
     }
     else {
-      $query[]= "LOWER($key) = LOWER('%s')";
+      $query[]= db_lower($key) .' = '. db_lower("'%s'");
       $params[] = $value;
     }
   }
@@ -471,7 +471,7 @@ function user_access($string, $account =
  * @return boolean TRUE for blocked users, FALSE for active
  */
 function user_is_blocked($name) {
-  $deny  = db_fetch_object(db_query("SELECT name FROM {users} WHERE status = 0 AND name = LOWER('%s')", $name));
+  $deny  = db_fetch_object(db_query('SELECT name FROM {users} WHERE status = 0 AND '. db_lower('name') .' = '. db_lower("'%s'"), $name));
 
   return $deny;
 }
@@ -528,13 +528,13 @@ function user_search($op = 'search', $ke
         $keys = preg_replace('!\*+!', '%', $keys);
         if (user_access('administer users')) {
           // Administrators can also search in the otherwise private email field.
-          $result = pager_query("SELECT name, uid, mail FROM {users} WHERE LOWER(name) LIKE LOWER('%%%s%%') OR LOWER(mail) LIKE LOWER('%%%s%%')", 15, 0, NULL, $keys, $keys);
+          $result = pager_query('SELECT name, uid, mail FROM {users} WHERE '. db_lower('name') .' LIKE '. db_lower("'%%%s%%'") .' OR '. db_lower('mail') .' LIKE '. db_lower("'%%%s%%'"), 15, 0, NULL, $keys, $keys);
           while ($account = db_fetch_object($result)) {
             $find[] = array('title' => $account->name .' ('. $account->mail .')', 'link' => url('user/'. $account->uid, array('absolute' => TRUE)));
           }
         }
         else {
-          $result = pager_query("SELECT name, uid FROM {users} WHERE LOWER(name) LIKE LOWER('%%%s%%')", 15, 0, NULL, $keys);
+          $result = pager_query('SELECT name, uid FROM {users} WHERE '. db_lower('name') .' LIKE '. db_lower("'%%%s%%'"), 15, 0, NULL, $keys);
           while ($account = db_fetch_object($result)) {
             $find[] = array('title' => $account->name, 'link' => url('user/'. $account->uid, array('absolute' => TRUE)));
           }
@@ -1361,7 +1361,7 @@ function _user_edit_validate($uid, &$edi
     if ($error = user_validate_name($edit['name'])) {
       form_set_error('name', $error);
     }
-    else if (db_result(db_query("SELECT COUNT(*) FROM {users} WHERE uid != %d AND LOWER(name) = LOWER('%s')", $uid, $edit['name'])) > 0) {
+    else if (db_result(db_query('SELECT COUNT(*) FROM {users} WHERE uid != %d AND '. db_lower('name') .' = '. db_lower("'%s'"), $uid, $edit['name'])) > 0) {
       form_set_error('name', t('The name %name is already taken.', array('%name' => $edit['name'])));
     }
     else if (drupal_is_denied('user', $edit['name'])) {
@@ -1373,7 +1373,7 @@ function _user_edit_validate($uid, &$edi
   if ($error = user_validate_mail($edit['mail'])) {
     form_set_error('mail', $error);
   }
-  else if (db_result(db_query("SELECT COUNT(*) FROM {users} WHERE uid != %d AND LOWER(mail) = LOWER('%s')", $uid, $edit['mail'])) > 0) {
+  else if (db_result(db_query('SELECT COUNT(*) FROM {users} WHERE uid != %d AND '. db_lower('mail') .' = '. db_lower("'%s'"), $uid, $edit['mail'])) > 0) {
     form_set_error('mail', t('The e-mail address %email is already registered. <a href="@password">Have you forgotten your password?</a>', array('%email' => $edit['mail'], '@password' => url('user/password'))));
   }
   else if (drupal_is_denied('mail', $edit['mail'])) {

=== modified file 'modules/user/user.pages.inc'
--- modules/user/user.pages.inc	2007-09-10 13:14:38 +0000
+++ modules/user/user.pages.inc	2007-10-08 07:17:15 +0000
@@ -12,7 +12,7 @@
 function user_autocomplete($string = '') {
   $matches = array();
   if ($string) {
-    $result = db_query_range("SELECT name FROM {users} WHERE LOWER(name) LIKE LOWER('%s%%')", $string, 0, 10);
+    $result = db_query_range('SELECT name FROM {users} WHERE '. db_lower('name') .' LIKE '. db_lower("'%s%%'"), $string, 0, 10);
     while ($user = db_fetch_object($result)) {
       $matches[$user->name] = check_plain($user->name);
     }

