? sites/default/modules ? sites/default/settings.php Index: includes/locale.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/locale.inc,v retrieving revision 1.189 diff -u -p -r1.189 locale.inc --- includes/locale.inc 12 Oct 2008 04:30:05 -0000 1.189 +++ includes/locale.inc 14 Oct 2008 17:23:47 -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)) { @@ -1308,7 +1318,7 @@ function _locale_import_one_string($op, * 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)); + $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('~(? md5($string), ':textgroup' => 'default'))->fetch(); + if ($source) { // 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.30 diff -u -p -r1.30 locale.install --- modules/locale/locale.install 14 Apr 2008 17:48:37 -0000 1.30 +++ modules/locale/locale.install 14 Oct 2008 17:23:47 -0000 @@ -206,6 +206,45 @@ 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. + */ +function locale_update_7000() { + $ret = array(); + db_add_field($ret, 'locales_source', 'hash', array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => '')); + db_add_index($ret, 'locales_source', 'hash', array('hash')); + $ret[] = update_sql('UPDATE {locales_source} SET hash = MD5(source)'); + return $ret; +} + +/** + * Update locales_source.source as BLOB. + */ +function locale_update_7001() { + $ret = array(); + db_change_field($ret, 'locales_source', 'source', 'source', array('type' => 'blob', 'not null' => TRUE)); + return $ret; +} + +/** + * Update locales_target.translation as BLOB. + */ +function locale_update_7002() { + $ret = array(); + db_change_field($ret, 'locales_target', 'translation', 'translation', array('type' => 'blob', 'not null' => TRUE)); + 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 +370,17 @@ function locale_schema() { 'description' => t('A module defined group of translations, see hook_locale().'), ), 'source' => array( - 'type' => 'text', - 'mysql_type' => 'blob', + 'type' => 'blob', 'not null' => TRUE, 'description' => t('The original string in English.'), ), + 'hash' => array( + 'type' => 'varchar', + 'length' => 32, + 'not null' => TRUE, + 'default' => '', + 'description' => t('Calculated md5 hash of the original string, used for validation.'), + ), 'version' => array( 'type' => 'varchar', 'length' => 20, @@ -347,6 +392,7 @@ function locale_schema() { 'primary key' => array('lid'), 'indexes' => array( 'source' => array(array('source', 30)), + 'hash' => array('hash'), ), ); @@ -360,8 +406,7 @@ function locale_schema() { 'description' => t('Source string ID. References {locales_source}.lid.'), ), 'translation' => array( - 'type' => 'text', - 'mysql_type' => 'blob', + 'type' => 'blob', 'not null' => TRUE, 'description' => t('Translation string value in this language.'), ), Index: modules/locale/locale.module =================================================================== RCS file: /cvs/drupal/drupal/modules/locale/locale.module,v retrieving revision 1.229 diff -u -p -r1.229 locale.module --- modules/locale/locale.module 12 Oct 2008 04:30:06 -0000 1.229 +++ modules/locale/locale.module 14 Oct 2008 17:23:47 -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'))->fetch(); 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);