diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2008-04-20 23:25:05 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2008-04-20 23:25:05 +0000 |
commit | d642b02e2d03c920ce8fa77cff33f24e1f407021 (patch) | |
tree | 46c25e61bc47112d37ef425ecadac1c109f3cd2f | |
parent | 2801dae0767b84d0e6b842e55dbef5b656eb65f7 (diff) | |
download | ampache-d642b02e2d03c920ce8fa77cff33f24e1f407021.tar.gz ampache-d642b02e2d03c920ce8fa77cff33f24e1f407021.tar.bz2 ampache-d642b02e2d03c920ce8fa77cff33f24e1f407021.zip |
db update that corrects the charset, or at least tries to
-rw-r--r-- | lib/class/update.class.php | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/class/update.class.php b/lib/class/update.class.php index 31f9d7a1..e40c9336 100644 --- a/lib/class/update.class.php +++ b/lib/class/update.class.php @@ -269,6 +269,10 @@ class Update { $version[] = array('version' => '340016','description'=>$update_string); + $update_string = '- Attempt to correct the charset of all columns in the database.<br />'; + + $version[] = array('version' => '340017','description'=>$update_string); + return $version; } // populate_version @@ -1187,6 +1191,7 @@ class Update { /** * update_340017 * This finalizes the democratic table. + * and fixes the charset crap */ public static function update_340017() { @@ -1202,6 +1207,50 @@ class Update { $sql = "TRUNCATE `democratic`"; $db_results = Dba::query($sql); + // MySQL translte real charset names into fancy smancy MySQL land names + switch (strtoupper(Config::get('site_charset'))) { + case 'EUC-KR': + $target_charset = 'euckr'; + break; + case 'CP932': + $target_charset = 'sjis'; + break; + case 'KOI8-U': + $target_charset = 'koi8u'; + break; + case 'KOI8-R': + $target_charset = 'koi8r'; + break; + case 'ISO-8859': + $target_charset = 'latin2'; + break; + default; + case 'UTF-8': + $target_charset = 'utf8'; + break; + } // end mysql charset translation + + $sql = "SHOW TABLES"; + $db_results = Dba::query($sql); + + // Go through the tables! + while ($row = Dba::fetch_row($db_results)) { + $sql = "DESCRIBE `" . $row['0'] . "`"; + $describe_results = Dba::query($sql); + + // Itterate through the columns of the table + while ($table = Dba::fetch_assoc($describe_results)) { + if (strstr($table['Type'],'varchar')) { + $sql = "ALTER TABLE `" . $row['0'] . "` MODIFY `" . $table['Field'] . "` " . $table['Type'] . " CHARACTER SET " . $target_charset; + $charset_results = Dba::query($sql); + if (!$charset_results) { + debug_event('CHARSET','Unable to update the charset of ' . $table['Field'] . '.' . $table['Type'] . ' to ' . $target_charset,'3'); + } // if it fails + } // if its a varchar + } // end columns + + } // end tables + self::set_version('db_version','340017'); } // update_340017 |