Permalink
Browse files

fix bug MDL_6419

  • Loading branch information...
1 parent 9aeeb39 commit e1af293f5f85f8db7c89cd1adbb3a7265f8450dd gbateson committed Sep 1, 2006
Showing with 18 additions and 21 deletions.
  1. +18 −21 mod/hotpot/db/update_to_v2.php
@@ -1239,10 +1239,7 @@ function hotpot_db_update_field_type($table, $oldfield, $field, $type, $size, $u
// get db version
$dbinfo = $db->ServerInfo();
$dbversion = substr($dbinfo['version'],0,3);
- // prevent conflicts with reserved words
- $tmpfield = "\"temporary_{$field}_".time()."\"";
- $oldfield = "\"$oldfield\"";
- $field = "\"$field\"";
+ $tmpfield = 'temporary_'.$field.'_'.time();
switch (strtoupper($type)) {
case "INTEGER":
if (!is_numeric($size)) {
@@ -1262,40 +1259,40 @@ function hotpot_db_update_field_type($table, $oldfield, $field, $type, $size, $u
$fieldtype = $type;
}
// start transaction
- execute_sql("BEGIN");
+ execute_sql('BEGIN');
// create temporary field
- execute_sql("ALTER TABLE $table ADD COLUMN $tmpfield $fieldtype");
+ execute_sql('ALTER TABLE '.$table.' ADD COLUMN "'.$tmpfield.'" '.$fieldtype);
// set default
if (isset($default)) {
- execute_sql("UPDATE $table SET $tmpfield = $default");
- execute_sql("ALTER TABLE $table ALTER COLUMN $tmpfield SET DEFAULT $default");
+ execute_sql('UPDATE '.$table.' SET "'.$tmpfield.'" = '.$default);
+ execute_sql('ALTER TABLE '.$table.' ALTER COLUMN "'.$tmpfield.'" SET DEFAULT '.$default);
} else {
- execute_sql("ALTER TABLE $table ALTER COLUMN $tmpfield DROP DEFAULT");
+ execute_sql('ALTER TABLE '.$table.' ALTER COLUMN "'.$tmpfield.'" DROP DEFAULT');
}
// set not null
- if ($dbversion >= "7.3") {
- $notnull = ($notnull ? "SET NOT NULL" : "DROP NOT NULL");
- execute_sql("ALTER TABLE $table ALTER COLUMN $tmpfield $notnull");
+ if ($dbversion=='' || $dbversion >= "7.3") {
+ $notnull = ($notnull ? 'SET NOT NULL' : 'DROP NOT NULL');
+ execute_sql('ALTER TABLE '.$table.' ALTER COLUMN "'.$tmpfield.'" '.$notnull);
} else {
execute_sql("
UPDATE pg_attribute SET attnotnull=".($notnull ? 'TRUE' : 'FALSE')."
- WHERE attname = $tmpfield
+ WHERE attname = '$tmpfield'
AND attrelid = (SELECT oid FROM pg_class WHERE relname = '$table')
");
}
// transfer $oldfield values, if necessary
- if ( $oldfield != '""' ) {
- execute_sql("UPDATE $table SET $tmpfield = CAST ($oldfield AS $fieldtype)");
- execute_sql("ALTER TABLE $table DROP COLUMN $oldfield");
+ if ( $oldfield != '' ) {
+ execute_sql('UPDATE '.$table.' SET "'.$tmpfield.'" = CAST ("'.$oldfield.'" AS '.$fieldtype.')');
+ execute_sql('ALTER TABLE '.$table.' DROP COLUMN "'.$oldfield.'"');
}
// rename $tmpfield to $field
- execute_sql("ALTER TABLE $table RENAME COLUMN $tmpfield TO $field");
+ execute_sql('ALTER TABLE '.$table.' RENAME COLUMN "'.$tmpfield.'" TO "'.$field.'"');
// do the transaction
- execute_sql("COMMIT");
+ execute_sql('COMMIT');
// reclaim disk space (must be done outside transaction)
- if ($oldfield != '""' && $dbversion >= "7.3") {
- execute_sql("UPDATE $table SET $field = $field");
- execute_sql("VACUUM FULL $table");
+ if ($oldfield != '' && $dbversion >= "7.3") {
+ execute_sql('UPDATE '.$table.' SET "'.$field.'" = "'.$field.'"');
+ execute_sql('VACUUM FULL '.$table);
}
break;
} // end switch $CGF->dbtype

0 comments on commit e1af293

Please sign in to comment.