Index: modules/locale/locale.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/locale/locale.install,v
retrieving revision 1.38
diff -u -p -r1.38 locale.install
--- modules/locale/locale.install	24 May 2009 17:39:32 -0000	1.38
+++ modules/locale/locale.install	26 May 2009 16:35:50 -0000
@@ -17,7 +17,17 @@ function locale_install() {
   // Create tables.
   drupal_install_schema('locale');
 
-  db_query("INSERT INTO {languages} (language, name, native, direction, enabled, weight, javascript) VALUES ('en', 'English', 'English', '0', '1', '0', '')");
+  db_insert('languages')
+    ->fields(array(
+      'language' => 'en',
+      'name' => 'English',
+      'native' => 'English',
+      'direction' => 0,
+      'enabled' => 1,
+      'weight' => 0,
+      'javascript' => '',
+    ))
+    ->execute();
 }
 
 /**
@@ -217,7 +227,7 @@ function locale_uninstall() {
   // Delete all JavaScript translation files.
   $locale_js_directory = file_create_path(variable_get('locale_js_directory', 'languages'));
   $files = db_query('SELECT language, javascript FROM {languages}');
-  while ($file = db_fetch_object($files)) {
+  foreach ($files as $file) {
     if (!empty($file->javascript)) {
       file_unmanaged_delete(file_create_path($locale_js_directory . '/' . $file->language . '_' . $file->javascript . '.js'));
     }
Index: modules/locale/locale.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/locale/locale.module,v
retrieving revision 1.238
diff -u -p -r1.238 locale.module
--- modules/locale/locale.module	31 Mar 2009 02:02:21 -0000	1.238
+++ modules/locale/locale.module	26 May 2009 16:35:50 -0000
@@ -376,8 +376,8 @@ function locale($string = NULL, $langcod
         // Refresh database stored cache of translations for given language.
         // We only store short strings used in current version, to improve
         // performance and consume less memory.
-        $result = db_query("SELECT s.source, t.translation, t.language FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = '%s' WHERE s.textgroup = 'default' AND s.version = '%s' AND LENGTH(s.source) < 75", $langcode, VERSION);
-        while ($data = db_fetch_object($result)) {
+        $result = db_query("SELECT s.source, t.translation, t.language FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.textgroup = 'default' AND s.version = :version AND LENGTH(s.source) < 75", array(':language' => $langcode, ':version' => VERSION));
+        foreach ($result as $data) {
           $locale_t[$langcode][$data->source] = (empty($data->translation) ? TRUE : $data->translation);
         }
         cache_set('locale:' . $langcode, $locale_t[$langcode]);
@@ -389,7 +389,10 @@ 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.source = :source AND s.textgroup = 'default'", array(
+      ':language' => $langcode,
+      ':source' => $string,
+    ))->fetchObject();
     if ($translation) {
       // We have the source string at least.
       // Cache translation string or TRUE if no translation exists.
@@ -399,13 +402,23 @@ function locale($string = NULL, $langcod
         // This is the first use of this string under current Drupal version. Save version
         // and clear cache, to include the string into caching next time. Saved version is
         // also a string-history information for later pruning of the tables.
-        db_query("UPDATE {locales_source} SET version = '%s' WHERE lid = %d", VERSION, $translation->lid);
+        db_update('locales_source')
+          ->fields(array('version' => VERSION))
+          ->condition('lid', $translation->lid)
+          ->execute();
         cache_clear_all('locale:', 'cache', TRUE);
       }
     }
     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,
+          '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);
Index: modules/locale/locale.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/locale/locale.test,v
retrieving revision 1.23
diff -u -p -r1.23 locale.test
--- modules/locale/locale.test	20 Apr 2009 02:23:16 -0000	1.23
+++ modules/locale/locale.test	26 May 2009 16:35:50 -0000
@@ -906,11 +906,14 @@ class LocaleUninstallFunctionalTest exte
     $user = $this->drupalCreateUser(array('translate interface', 'access administration pages'));
     $this->drupalLogin($user);
     $this->drupalGet('admin/international/translate/translate');
-    $string = db_fetch_object(db_query('SELECT min(lid) AS lid FROM {locales_source} WHERE location LIKE \'%.js%\' AND textgroup = \'default\''));
+    $string = db_query('SELECT min(lid) AS lid FROM {locales_source} WHERE location LIKE :location AND textgroup = :textgroup', array(
+      ':location' => '%.js%',
+      ':textgroup' => 'default',
+    ))->fetchObject();
     $edit = array('translations[fr]' => 'french translation');
     $this->drupalPost('admin/international/translate/edit/' . $string->lid, $edit, t('Save translations'));
     _locale_rebuild_js('fr');
-    $file = db_fetch_object(db_query('SELECT javascript FROM {languages} WHERE language = \'fr\''));
+    $file = db_query('SELECT javascript FROM {languages} WHERE language = :language', array(':language' => 'fr'))->fetchObject();
     $js_file = file_create_path(variable_get('locale_js_directory', 'languages')) . '/fr_' . $file->javascript . '.js';
     $this->assertTrue($result = file_exists($js_file), t('JavaScript file created: %file', array('%file' => $result ? $js_file : t('none'))));
 
