During installation, if the database isn't UTF and it is empty,

then try and set it to UTF automatically.

I did MySQL only, can someone tackle this for PostgreSQL?
This commit is contained in:
moodler 2006-04-14 11:57:11 +00:00
parent b5a5d9f668
commit b1e64385dc

View file

@ -294,13 +294,29 @@ if ($INSTALL['stage'] == DATABASE) {
if ($rs && $rs->RecordCount() > 0) { if ($rs && $rs->RecordCount() > 0) {
$records = $rs->GetAssoc(true); $records = $rs->GetAssoc(true);
$encoding = $records['character_set_database']['Value']; $encoding = $records['character_set_database']['Value'];
if (strtoupper($encoding) != 'UTF8') { if (strtoupper($encoding) == 'UTF8') {
$errormsg = get_string('dbwrongencoding', 'install', $encoding);
$nextstage = DATABASE;
$INSTALL['showskipdbencodingtest'] = true;
$INSTALL['dbencodingtestresults'] = false;
} else {
$INSTALL['dbencodingtestresults'] = true; $INSTALL['dbencodingtestresults'] = true;
} else {
// Try to set the encoding now!
if (! $db->Metatables()) { // We have no tables so go ahead
$db->Execute("ALTER DATABASE `".$INSTALL['dbname']."` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci");
$rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'"); // this works
$records = $rs->GetAssoc(true);
$encoding = $records['character_set_database']['Value'];
if (strtoupper($encoding) == 'UTF8') {
$INSTALL['dbencodingtestresults'] = true;
} else {
$errormsg = get_string('dbwrongencoding', 'install', $encoding);
$nextstage = DATABASE;
$INSTALL['showskipdbencodingtest'] = true;
$INSTALL['dbencodingtestresults'] = false;
}
} else {
$INSTALL['showskipdbencodingtest'] = true;
$INSTALL['dbencodingtestresults'] = false;
}
} }
} }
break; break;