提交 54d5672c authored 作者: Thomas Mueller's avatar Thomas Mueller

Improved error message for some syntax errors.

上级 aea17cdf
...@@ -18,7 +18,8 @@ Change Log ...@@ -18,7 +18,8 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul><li>File system abstraction: if used directly, some file systems did not work correctly <ul><li>Improved error message for some syntax errors.
</li><li>File system abstraction: if used directly, some file systems did not work correctly
with spliced byte buffers (the database engine doesn't use those). with spliced byte buffers (the database engine doesn't use those).
</li><li>To use the MVStore storage engine (which is still work in progress), append </li><li>To use the MVStore storage engine (which is still work in progress), append
";mv_store=true" to the database URL. Using the MVTableEngine when creating the table ";mv_store=true" to the database URL. Using the MVTableEngine when creating the table
......
...@@ -224,9 +224,13 @@ public class Parser { ...@@ -224,9 +224,13 @@ public class Parser {
public Command prepareCommand(String sql) { public Command prepareCommand(String sql) {
try { try {
Prepared p = parse(sql); Prepared p = parse(sql);
boolean hasMore = isToken(";");
if (!hasMore && currentTokenType != END) {
throw getSyntaxError();
}
p.prepare(); p.prepare();
Command c = new CommandContainer(this, sql, p); Command c = new CommandContainer(this, sql, p);
if (isToken(";")) { if (hasMore) {
String remaining = originalSQL.substring(parseIndex); String remaining = originalSQL.substring(parseIndex);
if (remaining.trim().length() != 0) { if (remaining.trim().length() != 0) {
CommandList list = new CommandList(this, sql, c, remaining); CommandList list = new CommandList(this, sql, c, remaining);
...@@ -237,8 +241,6 @@ public class Parser { ...@@ -237,8 +241,6 @@ public class Parser {
// } while(currentToken.equals(";")); // } while(currentToken.equals(";"));
c = list; c = list;
} }
} else if (currentTokenType != END) {
throw getSyntaxError();
} }
return c; return c;
} catch (DbException e) { } catch (DbException e) {
......
...@@ -39,6 +39,7 @@ public class TestCases extends TestBase { ...@@ -39,6 +39,7 @@ public class TestCases extends TestBase {
@Override @Override
public void test() throws Exception { public void test() throws Exception {
testClearSyntaxException();
testEmptyStatements(); testEmptyStatements();
testViewParameters(); testViewParameters();
testLargeKeys(); testLargeKeys();
...@@ -102,6 +103,19 @@ public class TestCases extends TestBase { ...@@ -102,6 +103,19 @@ public class TestCases extends TestBase {
deleteDb("cases"); deleteDb("cases");
} }
private void testClearSyntaxException() throws SQLException {
Connection conn = getConnection("cases");
Statement stat = conn.createStatement();
try {
stat.execute("select t.x, t.x t.y from dual t");
fail();
} catch (SQLException e) {
assertEquals("42000", e.getSQLState());
}
conn.close();
}
private void testEmptyStatements() throws SQLException { private void testEmptyStatements() throws SQLException {
Connection conn = getConnection("cases"); Connection conn = getConnection("cases");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论