? db_stricmp-181625-19.patch ? sites/pgsql.drupal.cvs ? sites/all/modules ? sites/default/files ? sites/default/settings.php Index: includes/database.mysql-common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/database.mysql-common.inc,v retrieving revision 1.13 diff -u -p -r1.13 database.mysql-common.inc --- includes/database.mysql-common.inc 2 Oct 2007 16:15:56 -0000 1.13 +++ includes/database.mysql-common.inc 10 Oct 2007 21:05:25 -0000 @@ -530,3 +530,32 @@ function db_change_field(&$ret, $table, function db_last_insert_id($table, $field) { return db_result(db_query('SELECT LAST_INSERT_ID()')); } + +/** + * Prepare two strings for comparing case insensitively by the database. + * + * This function only works correctly if the collation used for the database + * is the same for every table (as is the default). Otherwise, you can + * overwrite the variable mysql_case_sensitive in settings.php or as a last + * resort for really exotic configurations you should hack this function. + * + * @param $str1 + * The first string. + * @param $operator + * Typically = or LIKE. + * @param $str2 + * The second string. + * @return + * Example: db_stricmp('foo', '=', "'%s'") returns foo = '%s' as mysql is + * case insensitive. + */ +function db_stricmp($str1, $operator = '=', $str2 = "'%s'") { + $mysql_case_sensitive = variable_get('mysql_case_sensitive', NULL); + if (!isset($mysql_case_sensitive)) { + $fields = db_fetch_array(db_query('SHOW FULL COLUMNS FROM {system}')); + $collation = $fields['Collation']; + $mysql_case_sensitive = $collation[strlen($collation) - 1] == 's'; + variable_set('mysql_case_sensitive', $mysql_case_sensitive); + } + return $mysql_case_sensitive ? "LOWER($str1) $operator LOWER($str2)" : "$str1 $operator $str2"; +} Index: includes/database.pgsql.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/database.pgsql.inc,v retrieving revision 1.62 diff -u -p -r1.62 database.pgsql.inc --- includes/database.pgsql.inc 2 Oct 2007 16:15:56 -0000 1.62 +++ includes/database.pgsql.inc 10 Oct 2007 21:05:26 -0000 @@ -424,6 +424,22 @@ function db_check_setup() { } /** + * Prepare two strings for comparing case insensitively by the database. + * + * @param $str1 + * The first string. + * @param $operator + * Typically = or LIKE. + * @param $str2 + * The second string. + * @return + * Example: db_stricmp('foo', '=', "'%s'") returns LOWER(foo) = LOWER('%s') + */ +function db_stricmp($str1, $operator = '=', $str2 = "'%s'") { + return $operator == 'LIKE' ? "$str1 ILIKE $str2" : "LOWER($str1) $operator LOWER($str2)"; +} + +/** * 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 Index: modules/comment/comment.module =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v retrieving revision 1.588 diff -u -p -r1.588 comment.module --- modules/comment/comment.module 8 Oct 2007 14:22:31 -0000 1.588 +++ modules/comment/comment.module 10 Oct 2007 21:05:29 -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_stricmp('name'), $edit['name'])); if ($taken != 0) { form_set_error('name', t('The name you used belongs to a registered user.')); Index: modules/profile/profile.module =================================================================== RCS file: /cvs/drupal/drupal/modules/profile/profile.module,v retrieving revision 1.220 diff -u -p -r1.220 profile.module --- modules/profile/profile.module 5 Oct 2007 13:26:53 -0000 1.220 +++ modules/profile/profile.module 10 Oct 2007 21:05:31 -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_stricmp('value', 'LIKE', "'%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_stricmp('category'); $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_stricmp('category', 'LIKE', "'%s%%'"), $string, 0, 10); while ($data = db_fetch_object($result)) { $matches[$data->category] = check_plain($data->category); } Index: modules/statistics/statistics.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/statistics/statistics.admin.inc,v retrieving revision 1.1 diff -u -p -r1.1 statistics.admin.inc --- modules/statistics/statistics.admin.inc 23 Aug 2007 16:34:44 -0000 1.1 +++ modules/statistics/statistics.admin.inc 10 Oct 2007 21:05:31 -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_stricmp('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_cnt = "SELECT COUNT(DISTINCT(CONCAT(uid, hostname))) FROM {accesslog}"; $result = pager_query($sql, 30, 0, $sql_cnt); Index: modules/taxonomy/taxonomy.module =================================================================== RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.module,v retrieving revision 1.384 diff -u -p -r1.384 taxonomy.module --- modules/taxonomy/taxonomy.module 2 Oct 2007 16:15:56 -0000 1.384 +++ modules/taxonomy/taxonomy.module 10 Oct 2007 21:05:33 -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_stricmp('t.name', 'LIKE'), 't', 'tid'), trim($name)); $result = array(); while ($term = db_fetch_object($db_result)) { $result[] = $term; Index: modules/taxonomy/taxonomy.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.pages.inc,v retrieving revision 1.2 diff -u -p -r1.2 taxonomy.pages.inc --- modules/taxonomy/taxonomy.pages.inc 27 Sep 2007 16:52:00 -0000 1.2 +++ modules/taxonomy/taxonomy.pages.inc 10 Oct 2007 21:05:33 -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_stricmp('t.name', 'LIKE', "'%%%s%%'"), 't', 'tid'), $vid, $last_string, 0, 10); $prefix = count($array) ? implode(', ', $array) .', ' : ''; Index: modules/user/user.module =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.module,v retrieving revision 1.852 diff -u -p -r1.852 user.module --- modules/user/user.module 7 Oct 2007 19:27:40 -0000 1.852 +++ modules/user/user.module 10 Oct 2007 21:05:36 -0000 @@ -153,7 +153,7 @@ function user_load($array = array()) { $params[] = md5($value); } else { - $query[]= "LOWER($key) = LOWER('%s')"; + $query[]= db_stricmp($key); $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_stricmp('name'), $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_stricmp('name', 'LIKE', "'%%%s%%'") .' OR '. db_stricmp('mail', 'LIKE', "'%%%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_stricmp('name', 'LIKE', "'%%%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_stricmp('name'), $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_stricmp('mail'), $uid, $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'])) { Index: modules/user/user.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.pages.inc,v retrieving revision 1.1 diff -u -p -r1.1 user.pages.inc --- modules/user/user.pages.inc 10 Sep 2007 13:14:38 -0000 1.1 +++ modules/user/user.pages.inc 10 Oct 2007 21:05:36 -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_stricmp('name', 'LIKE', "'%s%%'"), $string, 0, 10); while ($user = db_fetch_object($result)) { $matches[$user->name] = check_plain($user->name); }