=== modified file 'modules/comment/comment.module' --- modules/comment/comment.module 2007-10-25 10:28:05 +0000 +++ modules/comment/comment.module 2007-11-01 09:36:30 +0000 @@ -1446,7 +1446,7 @@ function comment_validate($edit) { $node = node_load($edit['nid']); 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 name_lower = '%s'", strtolower($edit['name']))); if ($taken != 0) { form_set_error('name', t('The name you used belongs to a registered user.')); === modified file 'modules/system/system.install' --- modules/system/system.install 2007-10-25 20:41:16 +0000 +++ modules/system/system.install 2007-11-01 09:51:45 +0000 @@ -4455,6 +4455,46 @@ function system_update_6034() { return $ret; } +function system_update_6035() { + $ret = array(); + if (db_table_exists('term_data')) { + db_add_field($ret, 'term_data', 'name_lower', array('name' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '')); + } + db_add_field($ret, 'users', 'name_lower', array('name' => 'varchar', 'length' => 60, 'not null' => TRUE, 'default' => '')); + return $ret; +} + +function _system_update_6035_strotolower($update_id, $table_name) { + // Multi-part update. This must be done in PHP to avoid UTF-8 issues. + $field_name = $table_name[0] .'id'; + if (!isset($_SESSION['system_update_'. $update_id])) { + $_SESSION['system_update_'. $update_id] = 0; + $_SESSION['system_update_'. $update_id .'_max'] = db_result(db_query("SELECT MAX($field_name) FROM {". $table_name .'}')); + } + $limit = 20; + $result = db_query_range('SELECT name FROM {'. $table_name ."} WHERE $field_name > %d ORDER BY $field_name ASC", $_SESSION['system_update_'. $update_id], 0, $limit); + while ($o = db_fetch_object($result)) { + db_query('UPDATE {'. $table_name ."} SET name_lower = '%s' WHERE name = '%s'", strtolower($o->name), $o->name); + } + + if ($_SESSION['system_update_'. $update_id] == $_SESSION['system_update_'. $update_id .'_max']) { + unset($_SESSION['system_update_'. $update_id]); + unset($_SESSION['system_update_'. $update_id .'_max']); + return array(); + } + return array('#finished' => $_SESSION['system_update_'. $update_id] / $_SESSION['system_update_'. $update_id .'_max']); +} + +function system_update_6036() { + return _system_update_6035_strotolower(6036, 'term_data'); +} + +function system_update_6037() { + if (db_table_exists('term_data')) { + return _system_update_6035_strotolower(6037, 'term_data'); + } +} + /** * @} End of "defgroup updates-5.x-to-6.x" * The next series of updates should start at 7000. === modified file 'modules/taxonomy/taxonomy.install' --- modules/taxonomy/taxonomy.install 2007-10-21 18:59:01 +0000 +++ modules/taxonomy/taxonomy.install 2007-11-01 09:38:00 +0000 @@ -28,6 +28,13 @@ function taxonomy_schema() { 'default' => '', 'description' => t('The term name.'), ), + 'name_lower' => array( + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => '', + 'description' => t('The term name in lowercase.'), + ), 'description' => array( 'type' => 'text', 'not null' => FALSE, === modified file 'modules/taxonomy/taxonomy.module' --- modules/taxonomy/taxonomy.module 2007-10-02 16:15:56 +0000 +++ modules/taxonomy/taxonomy.module 2007-11-01 09:35:46 +0000 @@ -233,6 +233,7 @@ function taxonomy_save_term(&$form_value 'weight' => 0 ); + $form_values['name_lower'] = strtolower($form_values['name']); if (!empty($form_values['tid']) && $form_values['name']) { drupal_write_record('term_data', $form_values, 'tid'); $hook = 'update'; @@ -830,7 +831,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 t.name_lower LIKE '%s'", 't', 'tid'), strtolower(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-10-25 08:24:42 +0000 +++ modules/taxonomy/taxonomy.pages.inc 2007-11-01 09:34:13 +0000 @@ -81,7 +81,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 t.name_lower LIKE '%%%s%%'", 't', 'tid'), $vid, strtolower($last_string), 0, 10); $prefix = count($array) ? implode(', ', $array) .', ' : ''; === modified file 'modules/user/user.install' --- modules/user/user.install 2007-10-10 11:39:32 +0000 +++ modules/user/user.install 2007-11-01 09:42:51 +0000 @@ -142,6 +142,13 @@ function user_schema() { 'default' => '', 'description' => t('Unique user name.'), ), + 'name_lower' => array( + 'type' => 'varchar', + 'length' => 60, + 'not null' => TRUE, + 'default' => '', + 'description' => t('User name in lowercase.'), + ), 'pass' => array( 'type' => 'varchar', 'length' => 32, @@ -281,4 +288,3 @@ function user_schema() { return $schema; } - === modified file 'modules/user/user.module' --- modules/user/user.module 2007-10-25 10:30:40 +0000 +++ modules/user/user.module 2007-11-01 09:54:14 +0000 @@ -144,17 +144,26 @@ function user_load($array = array()) { } foreach ($array as $key => $value) { - if ($key == 'uid' || $key == 'status') { - $query[] = "$key = %d"; - $params[] = $value; - } - else if ($key == 'pass') { - $query[] = "pass = '%s'"; - $params[] = md5($value); - } - else { - $query[]= "LOWER($key) = LOWER('%s')"; - $params[] = $value; + switch ($key) { + case 'uid': case 'status': + $query[] = "$key = %d"; + $params[] = $value; + break; + case 'pass': + $query[] = "pass = '%s'"; + $params[] = md5($value); + break; + // Loading by signature is rare enough that storing a lowercase version + // does not worth it. + case 'signature': + $query[] = "LOWER($key) = LOWER('%s')"; + $params[] = $value; + case 'name': + $key = 'name_lower'; + // fail over. + default: + $query[] = "$key = '%s'"; + $params[] = strtolower($value); } } $result = db_query('SELECT * FROM {users} u WHERE '. implode(' AND ', $query), $params); @@ -212,7 +221,18 @@ function user_save($account, $array = ar if (in_array($key, $user_fields)) { // Save standard fields $query .= "$key = '%s', "; - $v[] = $value; + switch ($key) { + case 'name': + $query .= "name_lower = '%s', "; + $v[] = $value; + $v[] = strtolower($value); + case 'signature': + $v[] = $value; + break; + default: + $v[] = strtolower($value); + break; + } } else if ($key != 'roles') { // Roles is a special case: it used below. @@ -471,9 +491,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)); - - return $deny; + return db_fetch_object(db_query("SELECT name FROM {users} WHERE status = 0 AND name_lower = '%s'", strtolower($name))); } function user_fields() { @@ -528,13 +546,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 name_lower LIKE '%%%s%%' OR mail LIKE '%%%s%%'", 15, 0, NULL, strtolower($keys), strtolower($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 name_lower LIKE '%%%s%%'", 15, 0, NULL, strtolower($keys)); while ($account = db_fetch_object($result)) { $find[] = array('title' => $account->name, 'link' => url('user/'. $account->uid, array('absolute' => TRUE))); } @@ -1361,7 +1379,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 name_lower = '%s'", $uid, strtolower($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 +1391,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 mail = '%s'", $uid, strtolower($edit['mail']))) > 0) { form_set_error('mail', t('The e-mail address %email is already registered. Have you forgotten your password?', array('%email' => $edit['mail'], '@password' => url('user/password')))); } else if (drupal_is_denied('mail', $edit['mail'])) {