? profiles/simpletest
? sites/default/modules
? sites/default/settings.php
Index: includes/locale.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/locale.inc,v
retrieving revision 1.195
diff -u -p -r1.195 locale.inc
--- includes/locale.inc	16 Nov 2008 19:41:14 -0000	1.195
+++ includes/locale.inc	27 Nov 2008 04:37:51 -0000
@@ -844,10 +844,20 @@ function locale_translate_edit_form_subm
     if (!empty($value)) {
       // Only update or insert if we have a value to use.
       if (!empty($translation)) {
-        db_query("UPDATE {locales_target} SET translation = '%s' WHERE lid = %d AND language = '%s'", $value, $lid, $key);
+        db_update('locales_target')
+          ->fields(array('translation' => $value))
+          ->condition('lid', $lid)
+          ->condition('language', $key)
+          ->execute();
       }
       else {
-        db_query("INSERT INTO {locales_target} (lid, translation, language) VALUES (%d, '%s', '%s')", $lid, $value, $key);
+        db_insert('locales_target')
+          ->fields(array(
+            'lid' => $lid,
+            'translation' => $value,
+            'language' => $key,
+          ))
+          ->execute();
       }
     }
     elseif (!empty($translation)) {
@@ -1307,8 +1317,8 @@ function _locale_import_one_string($op, 
  * @return
  *   The string ID of the existing string modified or the new string added.
  */
-function _locale_import_one_string_db(&$report, $langcode, $source, $translation, $textgroup, $location, $mode, $plid = NULL, $plural = NULL) {
-  $lid = db_result(db_query("SELECT lid FROM {locales_source} WHERE source = '%s' AND textgroup = '%s'", $source, $textgroup));
+function _locale_import_one_string_db(&$report, $langcode, $source, $translation, $textgroup, $location, $mode, $plid = 0, $plural = 0) {
+  $lid = db_query("SELECT lid FROM {locales_source} WHERE hash = :hash AND textgroup = :textgroup", array(':hash' => md5($source), ':textgroup' => $textgroup))->fetchField();
 
   if (!empty($translation)) {
     if ($lid) {
@@ -1317,20 +1327,51 @@ function _locale_import_one_string_db(&$
       $exists = (bool) db_result(db_query("SELECT lid FROM {locales_target} WHERE lid = %d AND language = '%s'", $lid, $langcode));
       if (!$exists) {
         // No translation in this language.
-        db_query("INSERT INTO {locales_target} (lid, language, translation, plid, plural) VALUES (%d, '%s', '%s', %d, %d)", $lid, $langcode, $translation, $plid, $plural);
+        db_insert('locales_target')
+          ->fields(array(
+            'lid' => $lid,
+            'language' => $langcode,
+            'translation' => $translation,
+            'plid' => $plid,
+            'plural' => $plural,
+          ))
+          ->execute();
         $report[0]++;
       }
       elseif ($mode == LOCALE_IMPORT_OVERWRITE) {
         // Translation exists, only overwrite if instructed.
-        db_query("UPDATE {locales_target} SET translation = '%s', plid = %d, plural = %d WHERE language = '%s' AND lid = %d", $translation, $plid, $plural, $langcode, $lid);
+        db_update('locales_target')
+          ->fields(array(
+            'translation' => $translation,
+            'plid' => $plid,
+            'plural' => $plural,     
+          ))
+          ->condition('lid', $lid)
+          ->condition('language', $langcode)
+          ->execute();        
         $report[1]++;
       }
     }
     else {
       // No such source string in the database yet.
-      db_query("INSERT INTO {locales_source} (location, source, textgroup) VALUES ('%s', '%s', '%s')", $location, $source, $textgroup);
-      $lid = db_result(db_query("SELECT lid FROM {locales_source} WHERE source = '%s' AND textgroup = '%s'", $source, $textgroup));
-      db_query("INSERT INTO {locales_target} (lid, language, translation, plid, plural) VALUES (%d, '%s', '%s', %d, %d)", $lid, $langcode, $translation, $plid, $plural);
+      db_insert('locales_source')
+        ->fields(array(
+          'location' => $location,
+          'source' => $source,
+          'hash' => md5($source),
+          'textgroup' => $textgroup,
+        ))
+        ->execute();
+      $lid = db_query("SELECT lid FROM {locales_source} WHERE hash = :hash AND textgroup = :textgroup", array(':hash' => md5($source), ':textgroup' => $textgroup))->fetchField();
+      db_insert('locales_target')
+        ->fields(array(
+          'lid' => $lid,
+          'language' => $langcode,
+          'translation' => $translation,
+          'plid' => $plid,
+          'plural' => $plural,
+        ))
+        ->execute();
       $report[0]++;
     }
   }
@@ -1672,8 +1713,8 @@ function _locale_parse_js_file($filepath
       // Remove the quotes and string concatenations from the string.
       $string = implode('', preg_split('~(?<!\\\\)[\'"]\s*\+\s*[\'"]~s', substr($string, 1, -1)));
 
-      $result = db_query("SELECT lid, location FROM {locales_source} WHERE source = '%s' AND textgroup = 'default'", $string);
-      if ($source = db_fetch_object($result)) {
+      $result = db_query("SELECT lid, location FROM {locales_source} WHERE hash = :hash AND textgroup = :textgroup", array(':hash' => md5($string), ':textgroup' => 'default'));
+      if ($source = $result->fetchObject()) {
         // We already have this source string and now have to add the location
         // to the location column, if this file is not yet present in there.
         $locations = preg_split('~\s*;\s*~', $source->location);
@@ -1688,7 +1729,14 @@ function _locale_parse_js_file($filepath
       }
       else {
         // We don't have the source string yet, thus we insert it into the database.
-        db_query("INSERT INTO {locales_source} (location, source, textgroup) VALUES ('%s', '%s', 'default')", $filepath, $string);
+        db_insert('locales_source')
+          ->fields(array(
+            'location' => $filepath,
+            'source' => $string,
+            'hash' => md5($string),
+            'textgroup' => 'default',
+          ))
+          ->execute();
       }
     }
   }
Index: modules/locale/locale.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/locale/locale.install,v
retrieving revision 1.31
diff -u -p -r1.31 locale.install
--- modules/locale/locale.install	15 Nov 2008 13:01:07 -0000	1.31
+++ modules/locale/locale.install	27 Nov 2008 04:37:51 -0000
@@ -206,6 +206,30 @@ function locale_update_6005() {
  */
 
 /**
+ * @defgroup updates-6.x-to-7.x Locale updates from 6.x to 7.x
+ * @{
+ */
+
+/**
+ * Add hash column to locales_source table. Also revamp locales_source.source
+ * and locales_target.translation as BLOB.
+ */
+function locale_update_7000() {
+  $ret = array();
+  db_add_field($ret, 'locales_source', 'hash', array('type' => 'varchar', 'length' => 32, 'not null' => FALSE));
+  db_add_index($ret, 'locales_source', 'hash', array('hash'));
+  $ret[] = update_sql('UPDATE {locales_source} SET hash = MD5(source)');
+  db_change_field($ret, 'locales_source', 'source', 'source', array('type' => 'blob', 'not null' => FALSE));
+  db_change_field($ret, 'locales_target', 'translation', 'translation', array('type' => 'blob', 'not null' => FALSE));
+  return $ret;
+}
+
+/**
+ * @} End of "defgroup updates-6.x-to-7.x"
+ * The next series of updates should start at 8000.
+ */
+
+/**
  * Implementation of hook_uninstall().
  */
 function locale_uninstall() {
@@ -331,11 +355,16 @@ function locale_schema() {
         'description' => 'A module defined group of translations, see hook_locale().',
       ),
       'source' => array(
-        'type' => 'text',
-        'mysql_type' => 'blob',
-        'not null' => TRUE,
+        'type' => 'blob',
+        'not null' => FALSE,
         'description' => 'The original string in English.',
       ),
+      'hash' => array(
+        'type' => 'varchar',
+        'length' => 32,
+        'not null' => FALSE,
+        'description' => t('Calculated md5 hash of the original string, used for validation.'),
+      ),
       'version' => array(
         'type' => 'varchar',
         'length' => 20,
@@ -347,6 +376,7 @@ function locale_schema() {
     'primary key' => array('lid'),
     'indexes' => array(
       'source' => array(array('source', 30)),
+      'hash' => array('hash'),      
     ),
   );
 
@@ -360,9 +390,8 @@ function locale_schema() {
         'description' => 'Source string ID. References {locales_source}.lid.',
       ),
       'translation' => array(
-        'type' => 'text',
-        'mysql_type' => 'blob',
-        'not null' => TRUE,
+        'type' => 'blob',
+        'not null' => FALSE,
         'description' => 'Translation string value in this language.',
       ),
       'language' => array(
Index: modules/locale/locale.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/locale/locale.module,v
retrieving revision 1.232
diff -u -p -r1.232 locale.module
--- modules/locale/locale.module	23 Nov 2008 16:00:06 -0000	1.232
+++ modules/locale/locale.module	27 Nov 2008 04:37:51 -0000
@@ -390,7 +390,7 @@ function locale($string = NULL, $langcod
   if (!isset($locale_t[$langcode][$string])) {
 
     // We do not have this translation cached, so get it from the DB.
-    $translation = db_fetch_object(db_query("SELECT s.lid, t.translation, s.version FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = '%s' WHERE s.source = '%s' AND s.textgroup = 'default'", $langcode, $string));
+    $translation = db_query("SELECT s.lid, t.translation, s.version FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.hash = :hash AND s.textgroup = :textgroup", array(':language' => $langcode, ':hash' => md5($string), ':textgroup' => 'default'))->fetchObject();
     if ($translation) {
       // We have the source string at least.
       // Cache translation string or TRUE if no translation exists.
@@ -406,7 +406,15 @@ function locale($string = NULL, $langcod
     }
     else {
       // We don't have the source string, cache this as untranslated.
-      db_query("INSERT INTO {locales_source} (location, source, textgroup, version) VALUES ('%s', '%s', 'default', '%s')", request_uri(), $string, VERSION);
+      db_insert('locales_source')
+        ->fields(array(
+          'location' => request_uri(),
+          'source' => $string,
+          'hash' => md5($string),
+          'textgroup' => 'default',
+          'version' => VERSION,
+        ))
+        ->execute();
       $locale_t[$langcode][$string] = TRUE;
       // Clear locale cache so this string can be added in a later request.
       cache_clear_all('locale:', 'cache', TRUE);
