提交 5032d2b7 authored 作者: Thomas Mueller's avatar Thomas Mueller

The SCRIPT command and tool now also support the CHARSET option.

上级 b239f94c
...@@ -133,6 +133,7 @@ SCRIPT [ SIMPLE ] [ NODATA ] [ NOPASSWORDS ] [ NOSETTINGS ] ...@@ -133,6 +133,7 @@ SCRIPT [ SIMPLE ] [ NODATA ] [ NOPASSWORDS ] [ NOSETTINGS ]
[ DROP ] [ BLOCKSIZE blockSizeInt ] [ DROP ] [ BLOCKSIZE blockSizeInt ]
[ TO fileNameString [ COMPRESSION { DEFLATE | LZF | ZIP | GZIP } ] [ TO fileNameString [ COMPRESSION { DEFLATE | LZF | ZIP | GZIP } ]
[ CIPHER cipher PASSWORD string ] ] [ CIPHER cipher PASSWORD string ] ]
[ CHARSET charsetString ]
"," ","
Creates a SQL script from the database. Creates a SQL script from the database.
......
...@@ -4476,6 +4476,9 @@ public class Parser { ...@@ -4476,6 +4476,9 @@ public class Parser {
command.setPassword(readString().toCharArray()); command.setPassword(readString().toCharArray());
} }
} }
if (readIf("CHARSET")) {
command.setCharset(readString());
}
} }
return command; return command;
} }
......
...@@ -29,12 +29,31 @@ public class TestRunscript extends TestBase implements Trigger { ...@@ -29,12 +29,31 @@ public class TestRunscript extends TestBase implements Trigger {
} }
public void test() throws SQLException { public void test() throws SQLException {
testEncoding();
testClobPrimaryKey(); testClobPrimaryKey();
test(false); test(false);
test(true); test(true);
deleteDb("runscript"); deleteDb("runscript");
} }
private void testEncoding() throws SQLException {
deleteDb("runscript");
Connection conn;
Statement stat;
conn = getConnection("runscript");
stat = conn.createStatement();
stat.execute("create table \"T\u00f6\"(id int)");
stat.execute("script to '"+getBaseDir()+"/backup.sql'");
stat.execute("drop all objects");
stat.execute("runscript from '"+getBaseDir()+"/backup.sql'");
stat.execute("select * from \"t\u00f6\"");
stat.execute("script to '"+getBaseDir()+"/backup.sql' charset 'UTF-8'");
stat.execute("drop all objects");
stat.execute("runscript from '"+getBaseDir()+"/backup.sql' charset 'UTF-8'");
stat.execute("select * from \"t\u00f6\"");
conn.close();
}
/** /**
* This method is called via reflection from the database. * This method is called via reflection from the database.
* *
......
...@@ -570,18 +570,21 @@ public class TestTools extends TestBase { ...@@ -570,18 +570,21 @@ public class TestTools extends TestBase {
String fileName = getBaseDir() + "/b2.sql"; String fileName = getBaseDir() + "/b2.sql";
DeleteDbFiles.main("-dir", getBaseDir(), "-db", "utils", "-quiet"); DeleteDbFiles.main("-dir", getBaseDir(), "-db", "utils", "-quiet");
Connection conn = DriverManager.getConnection(url, user, password); Connection conn = DriverManager.getConnection(url, user, password);
conn.createStatement().execute("CREATE TABLE \u00f6()");
conn.createStatement().execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)"); conn.createStatement().execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)");
conn.createStatement().execute("INSERT INTO TEST VALUES(1, 'Hello')"); conn.createStatement().execute("INSERT INTO TEST VALUES(1, 'Hello')");
conn.close(); conn.close();
Script.main("-url", url, "-user", user, "-password", password, "-script", fileName, "-options", Script.main("-url", url, "-user", user, "-password", password, "-script", fileName, "-options",
"nodata", "compression", "lzf", "cipher", "xtea", "password", "'123'"); "nodata", "compression", "lzf", "cipher", "xtea", "password", "'123'", "charset", "'utf-8'");
Script.main("-url", url, "-user", user, "-password", password, "-script", fileName + ".txt"); Script.main("-url", url, "-user", user, "-password", password, "-script", fileName + ".txt");
DeleteDbFiles.main("-dir", getBaseDir(), "-db", "utils", "-quiet"); DeleteDbFiles.main("-dir", getBaseDir(), "-db", "utils", "-quiet");
RunScript.main("-url", url, "-user", user, "-password", password, "-script", fileName, RunScript.main("-url", url, "-user", user, "-password", password, "-script", fileName,
"-options", "compression", "lzf", "cipher", "xtea", "password", "'123'"); "-options", "compression", "lzf", "cipher", "xtea", "password", "'123'", "charset", "'utf-8'");
conn = DriverManager.getConnection("jdbc:h2:" + getBaseDir() + "/utils", "sa", "abc"); conn = DriverManager.getConnection("jdbc:h2:" + getBaseDir() + "/utils", "sa", "abc");
ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM TEST"); ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM TEST");
assertFalse(rs.next()); assertFalse(rs.next());
rs = conn.createStatement().executeQuery("SELECT * FROM \u00f6");
assertFalse(rs.next());
conn.close(); conn.close();
DeleteDbFiles.main("-dir", getBaseDir(), "-db", "utils", "-quiet"); DeleteDbFiles.main("-dir", getBaseDir(), "-db", "utils", "-quiet");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论