提交 4690af0c authored 作者: noelgrandin's avatar noelgrandin

Support BOM at the beginning of files for the RUNSCRIPT command

上级 71dc1bef
...@@ -21,6 +21,7 @@ Change Log ...@@ -21,6 +21,7 @@ Change Log
<ul><li>PostgreSQL compatibility: support for EXTRACT(WEEK FROM dateColumn). <ul><li>PostgreSQL compatibility: support for EXTRACT(WEEK FROM dateColumn).
Thanks to Prashant Bhat for the patch! Thanks to Prashant Bhat for the patch!
</li><li>Fix for a bug where we would sometimes use the wrong unique constraint to validate foreign key constraints. </li><li>Fix for a bug where we would sometimes use the wrong unique constraint to validate foreign key constraints.
</li><li>Support BOM at the beginning of files for the RUNSCRIPT command
</li></ul> </li></ul>
<h2>Version 1.3.169 (2012-09-09)</h2> <h2>Version 1.3.169 (2012-09-09)</h2>
......
...@@ -6,9 +6,9 @@ ...@@ -6,9 +6,9 @@
*/ */
package org.h2.command.dml; package org.h2.command.dml;
import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.Reader;
import org.h2.command.CommandInterface; import org.h2.command.CommandInterface;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.engine.Constants; import org.h2.engine.Constants;
...@@ -23,6 +23,9 @@ import org.h2.util.ScriptReader; ...@@ -23,6 +23,9 @@ import org.h2.util.ScriptReader;
*/ */
public class RunScriptCommand extends ScriptBase { public class RunScriptCommand extends ScriptBase {
/** FEFF because this is the Unicode char represented by the UTF-8 byte order mark (EF BB BF). */
public static final char UTF8_BOM = '\uFEFF';
private String charset = Constants.UTF8; private String charset = Constants.UTF8;
public RunScriptCommand(Session session) { public RunScriptCommand(Session session) {
...@@ -34,7 +37,12 @@ public class RunScriptCommand extends ScriptBase { ...@@ -34,7 +37,12 @@ public class RunScriptCommand extends ScriptBase {
int count = 0; int count = 0;
try { try {
openInput(); openInput();
Reader reader = new InputStreamReader(in, charset); BufferedReader reader = new BufferedReader(new InputStreamReader(in, charset));
// if necessary, strip the BOM from the front of the file
reader.mark(1);
if (reader.read() != UTF8_BOM) {
reader.reset();
}
ScriptReader r = new ScriptReader(reader); ScriptReader r = new ScriptReader(reader);
while (true) { while (true) {
String sql = r.readStatement(); String sql = r.readStatement();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论