示例#1
0
     $oldtables[] = $values[0];
 }
 $sql = implode('', file($sqlfile));
 preg_match_all("/CREATE\\s+TABLE.+?pre\\_(.+?)\\s+\\((.+?)\\)\\s*(ENGINE|TYPE)\\s*\\=/is", $sql, $matches);
 $newtables = empty($matches[1]) ? array() : $matches[1];
 $newsqls = empty($matches[0]) ? array() : $matches[0];
 $deltables = array();
 $delcolumns = array();
 foreach ($oldtables as $tname) {
     $tname = substr($tname, strlen($config['tablepre']));
     if (in_array($tname, $newtables)) {
         $query = DB::query("SHOW CREATE TABLE " . DB::table($tname));
         $cvalue = DB::fetch($query);
         $oldcolumns = getcolumn($cvalue['Create Table']);
         $i = array_search($tname, $newtables);
         $newcolumns = getcolumn($newsqls[$i]);
         foreach ($oldcolumns as $colname => $colstruct) {
             if ($colname == 'UNIQUE' || $colname == 'KEY') {
                 foreach ($colstruct as $key_index => $key_value) {
                     if (empty($newcolumns[$colname][$key_index])) {
                         $delcolumns[$tname][$colname][$key_index] = $key_value;
                     }
                 }
             } else {
                 if (empty($newcolumns[$colname])) {
                     $delcolumns[$tname][] = $colname;
                 }
             }
         }
     } else {
         if (!strexists($tname, 'uc_') && !strexists($tname, 'ucenter_') && !preg_match('/forum_(thread|post)_(\\d+)$/i', $tname)) {
示例#2
0
     preg_match("/(CREATE TABLE .+?)\\s*(ENGINE|TYPE)\\s*\\=/is", $newsqls[$i], $maths);
     if (strpos($newtable, 'common_session')) {
         $type = mysql_get_server_info() > '4.1' ? " ENGINE=MEMORY" . (empty($config['dbcharset']) ? '' : " DEFAULT CHARSET={$config['dbcharset']}") : " TYPE=HEAP";
     } else {
         $type = mysql_get_server_info() > '4.1' ? " ENGINE=MYISAM" . (empty($config['dbcharset']) ? '' : " DEFAULT CHARSET={$config['dbcharset']}") : " TYPE=MYISAM";
     }
     $usql = $maths[1] . $type;
     $usql = str_replace("CREATE TABLE IF NOT EXISTS pre_", 'CREATE TABLE IF NOT EXISTS ' . $config['tablepre'], $usql);
     if (!DB::query($usql, 'SILENT')) {
         show_msg('添加表 ' . DB::table($newtable) . ' 出錯,請手工執行以下SQL語句後,再重新運行本升級程序:<br><br>' . dhtmlspecialchars($usql));
     } else {
         $msg = '添加表 ' . DB::table($newtable) . ' 完成';
     }
 } else {
     $value = DB::fetch($query);
     $oldcols = getcolumn($value['Create Table']);
     //獲取升級SQL文
     $updates = array();
     foreach ($newcols as $key => $value) {
         if ($key == 'PRIMARY') {
             if ($value != $oldcols[$key]) {
                 if (!empty($oldcols[$key])) {
                     $usql = "RENAME TABLE " . DB::table($newtable) . " TO " . DB::table($newtable . '_bak');
                     if (!DB::query($usql, 'SILENT')) {
                         show_msg('升級表 ' . DB::table($newtable) . ' 出錯,請手工執行以下升級語句後,再重新運行本升級程序:<br><br><b>升級SQL語句</b>:<div style=\\"position:absolute;font-size:11px;font-family:verdana,arial;background:#EBEBEB;padding:0.5em;\\">' . dhtmlspecialchars($usql) . "</div><br><b>Error</b>: " . DB::error() . "<br><b>Errno.</b>: " . DB::errno());
                     } else {
                         $msg = '表改名 ' . DB::table($newtable) . ' 完成!';
                         show_msg($msg, $theurl . '?step=sql&i=' . $_GET['i']);
                     }
                 }
                 $updates[] = "ADD PRIMARY KEY {$value}";