From 21ff7c17c0e11f294d5874a7a42c940ef316be36 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Sun, 31 Aug 2008 14:15:48 +0000 Subject: [PATCH] upgrade.php: ensure we cope with config table with a prefix; thanks to AldoReset (IRC); see also https://sourceforge.net/tracker/index.php?func=detail&aid=2084937&group_id=191583&atid=937964 git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@452 a1433add-5e2c-0410-b055-b7f2511e0802 --- upgrade.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/upgrade.php b/upgrade.php index cbcfe6eb..1bbf93af 100644 --- a/upgrade.php +++ b/upgrade.php @@ -51,12 +51,13 @@ function _pgsql_field_exists($table, $field) { } +$table = table_by_key('config'); if($CONF['database_type'] == 'pgsql') { // check if table already exists, if so, don't recreate it - $r = db_query("SELECT relname FROM pg_class WHERE relname = 'config'"); + $r = db_query("SELECT relname FROM pg_class WHERE relname = '$table'"); if($r['rows'] == 0) { $pgsql = " - CREATE TABLE " . table_by_key ('config') . " ( + CREATE TABLE $table ( id SERIAL, name VARCHAR(20) NOT NULL UNIQUE, value VARCHAR(20) NOT NULL, @@ -67,7 +68,7 @@ if($CONF['database_type'] == 'pgsql') { } else { $mysql = " - CREATE TABLE {IF_NOT_EXISTS} " . table_by_key ('config') . "( + CREATE TABLE {IF_NOT_EXISTS} $table ( `id` {AUTOINCREMENT} {PRIMARY}, `name` VARCHAR(20) {LATIN1} NOT NULL DEFAULT '', `value` VARCHAR(20) {LATIN1} NOT NULL DEFAULT '', @@ -77,7 +78,7 @@ else { db_query_parsed($mysql, 0, " ENGINE = MYISAM COMMENT = 'PostfixAdmin settings'"); } -$sql = "SELECT * FROM " . table_by_key ('config') . " WHERE name = 'version'"; +$sql = "SELECT * FROM $table WHERE name = 'version'"; // insert into config('version', '01'); @@ -88,7 +89,7 @@ if($r['rows'] == 1) { $row = db_array($rs); $version = $row['value']; } else { - db_query_parsed("INSERT INTO " . table_by_key ('config') . " (name, value) VALUES ('version', '0')", 0, ''); + db_query_parsed("INSERT INTO $table (name, value) VALUES ('version', '0')", 0, ''); $version = 0; } @@ -105,7 +106,7 @@ function _do_upgrade($current_version) { return true; } - echo "

Updating database:

old version: $current_version; target version: $target_version"; + echo "

Updating database:

- old version: $current_version; target version: $target_version

"; for ($i = $current_version +1; $i <= $target_version; $i++) { $function = "upgrade_$i"; @@ -131,7 +132,8 @@ function _do_upgrade($current_version) { } // Update config table so we don't run the same query twice in the future. $i = (int) $i; - $sql = "UPDATE config SET value = $i WHERE name = 'version'"; + $table = table_by_key('config'); + $sql = "UPDATE $table SET value = $i WHERE name = 'version'"; db_query($sql); }; }