? term_lower.patch
Index: modules/taxonomy/taxonomy.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.install,v
retrieving revision 1.7
diff -u -p -r1.7 taxonomy.install
--- modules/taxonomy/taxonomy.install	8 Jan 2008 07:46:41 -0000	1.7
+++ modules/taxonomy/taxonomy.install	1 Jul 2008 15:43:23 -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('Lowercase version of the term name for indexing.'),
+      ),
       'description' => array(
         'type' => 'text',
         'not null' => FALSE,
@@ -45,7 +52,7 @@ function taxonomy_schema() {
     'primary key' => array('tid'),
     'indexes' => array(
       'taxonomy_tree' => array('vid', 'weight', 'name'),
-      'vid_name' => array('vid', 'name'),
+      'vid_name_lower' => array('vid', 'name_lower'),
     ),
   );
 
@@ -284,3 +291,18 @@ function taxonomy_schema() {
   return $schema;
 }
 
+/**
+ * @defgroup updates-6.x-to-7.x Taxonomy updates from 6.x to 7.x
+ * @{
+ */
+ 
+function taxonomy_update_7000() {
+  $ret = array();
+  // Add name_lower column and populate it with existing terms.
+  db_add_field($ret, 'term_data', 'name_lower', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
+  db_drop_index($ret, 'term_data', 'vid_name');
+  db_add_index($ret, 'term_data', 'vid_name_lower', array('vid', 'name_lower'));
+  $ret[] = update_sql("UPDATE {term_data} SET name_lower = LOWER(name)");
+
+  return $ret;
+}
\ No newline at end of file
Index: modules/taxonomy/taxonomy.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.module,v
retrieving revision 1.423
diff -u -p -r1.423 taxonomy.module
--- modules/taxonomy/taxonomy.module	28 Jun 2008 19:51:02 -0000	1.423
+++ modules/taxonomy/taxonomy.module	1 Jul 2008 15:43:23 -0000
@@ -300,6 +300,9 @@ function taxonomy_save_term(&$form_value
     'description' => '',
     'weight' => 0
   );
+  // Add a lowercase version of 'name' to the $form_values array.
+  // Must use mb_strtolower() to be multi-byte safe.
+  $form_values['name_lower'] = mb_strtolower($form_values['name'], 'UTF-8');
 
   if (!empty($form_values['tid']) && $form_values['name']) {
     drupal_write_record('term_data', $form_values, 'tid');
@@ -953,7 +956,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) = 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 = LOWER('%s')", '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.11
diff -u -p -r1.11 taxonomy.pages.inc
--- modules/taxonomy/taxonomy.pages.inc	14 Apr 2008 17:48:42 -0000	1.11
+++ modules/taxonomy/taxonomy.pages.inc	1 Jul 2008 15:43:23 -0000
@@ -119,7 +119,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 LOWER('%%%s%%')", 't', 'tid'), $vid, $last_string, 0, 10);
 
     $prefix = count($array) ? implode(', ', $array) . ', ' : '';
 
