提交 98d941d3 authored 作者: christian.peter.io's avatar christian.peter.io

For unecnrypted databases, the automatic upgrade temporary script file is now unencrypted again.

上级 eab1130c
......@@ -23,6 +23,7 @@ Change Log
</li><li>LOG=0 is now a bit faster (previously undo log entries were still written).
</li><li>The command line tools now say so if the source directory of an option doesn't exist.
</li><li>It is now allowed to truncate a table if referential integrity has been disabled for this table or database.
</li><li>For unencrypted databases, the automatic upgrade temporary script file is now unencrypted again.
</li></ul>
<h2>Version 1.2.140 (2010-07-25)</h2>
......
......@@ -140,15 +140,16 @@ public class DbUpgradeNonPageStoreToCurrent {
scriptFile = new File(oldDataFile.getAbsolutePath() + "_script.sql");
}
// outputStream.println("H2 Migrating '" + oldFile.getPath() +
// "' to '" + newFile.getPath() + "' via '" + scriptFile.getPath()
// + "'");
Utils.callStaticMethod("org.h2.upgrade.v1_1.Driver.load");
String uuid = UUID.randomUUID().toString();
Connection connection = DriverManager.getConnection(oldUrl, info);
Statement stmt = connection.createStatement();
stmt.execute("script to '" + scriptFile + "' CIPHER AES PASSWORD '" + uuid + "' --hide--");
boolean isEncrypted = StringUtils.toUpperEnglish(url).indexOf(";CIPHER=") >= 0;
String uuid = UUID.randomUUID().toString();
if (isEncrypted) {
stmt.execute("script to '" + scriptFile + "' CIPHER AES PASSWORD '" + uuid + "' --hide--");
} else {
stmt.execute("script to '" + scriptFile + "'");
}
stmt.close();
connection.close();
......@@ -158,7 +159,11 @@ public class DbUpgradeNonPageStoreToCurrent {
connection = DriverManager.getConnection(newUrl, info);
stmt = connection.createStatement();
stmt.execute("runscript from '" + scriptFile + "' CIPHER AES PASSWORD '" + uuid + "' --hide--");
if (isEncrypted) {
stmt.execute("runscript from '" + scriptFile + "' CIPHER AES PASSWORD '" + uuid + "' --hide--");
} else {
stmt.execute("runscript from '" + scriptFile + "'");
}
stmt.execute("analyze");
stmt.execute("shutdown compact");
stmt.close();
......@@ -169,9 +174,6 @@ public class DbUpgradeNonPageStoreToCurrent {
backupIndexFile.delete();
FileSystem.getInstance(backupLobsDir.getAbsolutePath()).deleteRecursive(backupLobsDir.getAbsolutePath(), false);
}
// outputStream.println("H2 Migration of '" + oldFile.getPath() +
// "' finished successfully");
} catch (Exception e) {
successful = false;
if (backupDataFile.exists()) {
......@@ -184,8 +186,6 @@ public class DbUpgradeNonPageStoreToCurrent {
backupLobsDir.renameTo(oldLobsDir);
}
newFile.delete();
// errorStream.println("H2 Migration of '" + oldFile.getPath() +
// "' finished with error: " + e.getMessage());
throw DbException.toSQLException(e);
} finally {
if (scriptFile != null) {
......
......@@ -12,6 +12,7 @@ import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import org.h2.test.TestBase;
import org.h2.util.IOUtils;
import org.h2.util.Utils;
/**
......@@ -35,6 +36,7 @@ public class TestUpgrade extends TestBase {
testNoDb();
testNoUpgradeOldAndNew();
testIfExists();
testCipher();
}
private void testNoDb() throws SQLException {
......@@ -130,6 +132,28 @@ public class TestUpgrade extends TestBase {
deleteDb("upgrade");
}
private void testCipher() throws Exception {
deleteDb("upgrade");
// Create old db
Utils.callStaticMethod("org.h2.upgrade.v1_1.Driver.load");
Connection conn = DriverManager.getConnection("jdbc:h2v1_1:data/test/upgrade;PAGE_STORE=FALSE;CIPHER=AES", "abc", "abc abc");
Statement stat = conn.createStatement();
stat.execute("create table test(id int)");
conn.close();
Utils.callStaticMethod("org.h2.upgrade.v1_1.Driver.unload");
assertTrue(new File("data/test/upgrade.data.db").exists());
// Connect to old DB with upgrade
conn = DriverManager.getConnection("jdbc:h2:data/test/upgrade;CIPHER=AES", "abc", "abc abc");
stat = conn.createStatement();
stat.executeQuery("select * from test");
conn.close();
assertTrue(new File("data/test/upgrade.h2.db").exists());
deleteDb("upgrade");
}
public void deleteDb(String dbName) throws SQLException {
super.deleteDb(dbName);
try {
......@@ -137,5 +161,7 @@ public class TestUpgrade extends TestBase {
} catch (Exception e) {
throw new SQLException(e.getMessage());
}
IOUtils.delete("data/test/" + dbName + ".data.db.backup");
IOUtils.delete("data/test/" + dbName + ".index.db.backup");
}
}
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论