function weather_update_4 in Weather 5.6
Same name and namespace in other branches
- 6.5 weather.install \weather_update_4()
File
- ./
weather.install, line 293
Code
function weather_update_4() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
// expand the VARCHAR for units from 8 to 255
$sql = "ALTER TABLE {weather_config} CHANGE units units VARCHAR(255) NOT NULL DEFAULT '%s'";
// we cannot use update_sql() because of the brackets {} issue
$result = db_query($sql, 'a:4:{s:11:"temperature";s:7:"celsius";s:9:"windspeed";s:3:"kmh";s:8:"pressure";s:3:"hpa";s:10:"visibility";s:10:"kilometers";}');
$ret[] = array(
'success' => $result !== FALSE,
'query' => check_plain($sql),
);
// add another column for configuration
$sql = "ALTER TABLE {weather_config} ADD config VARCHAR(255) NOT NULL DEFAULT '%s' AFTER units";
// we cannot use update_sql() because of the brackets {} issue
$result = db_query($sql, 'a:1:{s:22:"show_unconverted_metar";i:0;}');
$ret[] = array(
'success' => $result !== FALSE,
'query' => check_plain($sql),
);
break;
case 'pgsql':
// expand the VARCHAR for units from 8 to 255
$ret[] = update_sql("ALTER TABLE {weather_config} RENAME units TO units_old");
$ret[] = update_sql("ALTER TABLE {weather_config} ADD units VARCHAR(255)");
$ret[] = update_sql("UPDATE {weather_config} SET units = units_old");
$ret[] = update_sql("ALTER TABLE {weather_config} ALTER units SET NOT NULL");
// we cannot use update_sql() because of the brackets {} issue
$sql = "ALTER TABLE {weather_config} ALTER units SET DEFAULT '%s'";
$result = db_query($sql, 'a:4:{s:11:"temperature";s:7:"celsius";s:9:"windspeed";s:3:"kmh";s:8:"pressure";s:3:"hpa";s:10:"visibility";s:10:"kilometers";}');
$ret[] = array(
'success' => $result !== FALSE,
'query' => check_plain($sql),
);
$ret[] = update_sql("ALTER TABLE {weather_config} DROP units_old");
// add another column for configuration
$ret[] = update_sql("ALTER TABLE {weather_config} ADD config VARCHAR(255)");
$ret[] = update_sql("ALTER TABLE {weather_config} ALTER config SET NOT NULL");
// we cannot use update_sql() because of the brackets {} issue
$sql = "ALTER TABLE {weather_config} ALTER config SET DEFAULT '%s'";
$result = db_query($sql, 'a:1:{s:22:"show_unconverted_metar";i:0;}');
$ret[] = array(
'success' => $result !== FALSE,
'query' => check_plain($sql),
);
// this is a null-op, but restores the original order of columns.
// yes, I'm a pedantic. ;-)
$ret[] = update_sql("ALTER TABLE {weather_config} RENAME weight TO weight_old");
$ret[] = update_sql("ALTER TABLE {weather_config} ADD weight INTEGER");
$ret[] = update_sql("UPDATE {weather_config} SET weight = weight_old");
$ret[] = update_sql("ALTER TABLE {weather_config} ALTER weight SET NOT NULL");
$ret[] = update_sql("ALTER TABLE {weather_config} ALTER weight SET DEFAULT 0");
$ret[] = update_sql("ALTER TABLE {weather_config} DROP weight_old");
break;
}
// convert the 'metric' and 'imperial' entries
// we cannot use update_sql() because of the brackets {} issue
$sql = "UPDATE {weather_config} SET units='%s' WHERE units='metric'";
$result = db_query($sql, 'a:4:{s:11:"temperature";s:7:"celsius";s:9:"windspeed";s:3:"kmh";s:8:"pressure";s:3:"hpa";s:10:"visibility";s:10:"kilometers";}');
$ret[] = array(
'success' => $result !== FALSE,
'query' => check_plain($sql),
);
$sql = "UPDATE {weather_config} SET units='%s' WHERE units='imperial'";
$result = db_query($sql, 'a:4:{s:11:"temperature";s:10:"fahrenheit";s:9:"windspeed";s:3:"mph";s:8:"pressure";s:4:"inhg";s:10:"visibility";s:5:"miles";}');
$ret[] = array(
'success' => $result !== FALSE,
'query' => check_plain($sql),
);
return $ret;
}