Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
1bb9cb16
提交
1bb9cb16
authored
9月 03, 2013
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove JdbcParseSQLException
上级
fd9cd70d
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
25 行增加
和
141 行删除
+25
-141
JdbcParseSQLException.java
h2/src/main/org/h2/api/JdbcParseSQLException.java
+0
-59
Parser.java
h2/src/main/org/h2/command/Parser.java
+1
-1
DbException.java
h2/src/main/org/h2/message/DbException.java
+24
-57
TestPreparedStatement.java
h2/src/test/org/h2/test/jdbc/TestPreparedStatement.java
+0
-24
没有找到文件。
h2/src/main/org/h2/api/JdbcParseSQLException.java
deleted
100644 → 0
浏览文件 @
fd9cd70d
/*
* Copyright 2004-2013 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
api
;
import
java.util.List
;
import
org.h2.jdbc.JdbcSQLException
;
/**
* A JDBC SQL Exception with additional parameters, it provides the syntax error
* position and expected token.
* <p>
* When the H2 parser encounters an error, it normally throws one of these
* exceptions. Clients may use this information to implement things like
* autocomplete in editors, or just better display of errors.
*
* @author Nicolas Fortin, Atelier SIG, IRSTV FR CNRS 24888
*/
public
class
JdbcParseSQLException
extends
JdbcSQLException
{
private
final
List
<
String
>
expectedTokens
;
private
final
int
syntaxErrorPosition
;
/**
* Creates a JdbcParseSQLException.
*
* @param message the reason
* @param sql the SQL statement
* @param state the SQL state
* @param errorCode the error code
* @param cause the exception that was the reason for this exception
* @param stackTrace the stack trace
* @param expectedTokens H2 parser expected tokens
* @param syntaxErrorPosition Syntax error character index
*/
public
JdbcParseSQLException
(
String
message
,
String
sql
,
String
state
,
int
errorCode
,
Throwable
cause
,
String
stackTrace
,
List
<
String
>
expectedTokens
,
int
syntaxErrorPosition
)
{
super
(
message
,
sql
,
state
,
errorCode
,
cause
,
stackTrace
);
this
.
expectedTokens
=
expectedTokens
;
this
.
syntaxErrorPosition
=
syntaxErrorPosition
;
}
/**
* H2 parser expected tokens
*/
public
List
<
String
>
getExpectedTokens
()
{
return
expectedTokens
;
}
/**
* Syntax error character position
*/
public
int
getSyntaxErrorPosition
()
{
return
syntaxErrorPosition
;
}
}
h2/src/main/org/h2/command/Parser.java
浏览文件 @
1bb9cb16
...
...
@@ -499,7 +499,7 @@ public class Parser {
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
e
);
}
return
DbException
.
getSyntaxError
(
sqlCommand
,
parseIndex
,
buff
.
toString
()
,
expectedList
);
return
DbException
.
getSyntaxError
(
sqlCommand
,
parseIndex
,
buff
.
toString
());
}
private
Prepared
parseBackup
()
{
...
...
h2/src/main/org/h2/message/DbException.java
浏览文件 @
1bb9cb16
...
...
@@ -11,11 +11,10 @@ import java.io.IOException;
import
java.lang.reflect.InvocationTargetException
;
import
java.sql.SQLException
;
import
java.text.MessageFormat
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Map.Entry
;
import
java.util.Properties
;
import
org.h2.api.JdbcParseSQLException
;
import
org.h2.constant.ErrorCode
;
import
org.h2.jdbc.JdbcSQLException
;
import
org.h2.util.SortedProperties
;
...
...
@@ -190,24 +189,12 @@ public class DbException extends RuntimeException {
*
* @param sql the SQL statement
* @param index the position of the error in the SQL statement
* @param
expected the expected keyword at the given position
* @param
message the message
* @return the exception
*/
public
static
DbException
getSyntaxError
(
String
sql
,
int
index
,
String
expected
)
{
return
getSyntaxError
(
sql
,
index
,
expected
,
java
.
util
.
Arrays
.
asList
(
expected
));
}
/**
* Create a syntax error exception.
*
* @param sql the SQL statement
* @param index the position of the error in the SQL statement
* @param expected the expected keyword(s) at the given position
* @return the exception
*/
public
static
DbException
getSyntaxError
(
String
sql
,
int
index
,
String
message
,
List
<
String
>
expected
)
{
public
static
DbException
getSyntaxError
(
String
sql
,
int
index
,
String
message
)
{
sql
=
StringUtils
.
addAsterisk
(
sql
,
index
);
return
new
DbException
(
get
ParseJdbcSQLException
(
ErrorCode
.
SYNTAX_ERROR_2
,
null
,
index
,
expected
,
sql
,
message
));
return
new
DbException
(
get
JdbcSQLException
(
ErrorCode
.
SYNTAX_ERROR_2
,
null
,
sql
,
message
));
}
/**
...
...
@@ -340,29 +327,9 @@ public class DbException extends RuntimeException {
* @return the SQLException object
*/
private
static
JdbcSQLException
getJdbcSQLException
(
int
errorCode
,
Throwable
cause
,
String
...
params
)
{
return
getParseJdbcSQLException
(
errorCode
,
cause
,
0
,
null
,
params
);
}
/**
* Gets the SQL exception object for a specific error code.
*
* @param errorCode the error code
* @param cause the cause of the exception
* @param syntaxErrorPosition Syntax error character index
* @param expectedTokens H2 parser expected tokens
* @param params the list of parameters of the message
* @return the SQLException object
*/
private
static
JdbcSQLException
getParseJdbcSQLException
(
int
errorCode
,
Throwable
cause
,
int
syntaxErrorPosition
,
List
<
String
>
expectedTokens
,
String
...
params
)
{
String
sqlstate
=
ErrorCode
.
getState
(
errorCode
);
String
message
=
translate
(
sqlstate
,
params
);
if
(
expectedTokens
==
null
)
{
return
new
JdbcSQLException
(
message
,
null
,
sqlstate
,
errorCode
,
cause
,
null
);
}
else
{
return
new
JdbcParseSQLException
(
message
,
null
,
sqlstate
,
errorCode
,
cause
,
null
,
expectedTokens
,
syntaxErrorPosition
);
}
}
/**
...
...
h2/src/test/org/h2/test/jdbc/TestPreparedStatement.java
浏览文件 @
1bb9cb16
...
...
@@ -26,7 +26,6 @@ import java.util.GregorianCalendar;
import
java.util.SimpleTimeZone
;
import
java.util.TimeZone
;
import
java.util.UUID
;
import
org.h2.api.JdbcParseSQLException
;
import
org.h2.api.Trigger
;
import
org.h2.constant.ErrorCode
;
import
org.h2.test.TestBase
;
...
...
@@ -87,7 +86,6 @@ public class TestPreparedStatement extends TestBase {
testBlob
(
conn
);
testClob
(
conn
);
testParameterMetaData
(
conn
);
testParseException
(
conn
);
conn
.
close
();
deleteDb
(
"preparedStatement"
);
}
...
...
@@ -1184,26 +1182,4 @@ public class TestPreparedStatement extends TestBase {
assertTrue
(!
rs
.
next
());
}
private
void
testParseException
(
Connection
conn
)
{
try
{
conn
.
prepareStatement
(
"SELECT * FROM"
);
fail
();
}
catch
(
JdbcParseSQLException
ex
)
{
assertEquals
(
14
,
ex
.
getSyntaxErrorPosition
());
assertEquals
(
new
Object
[]
{
"identifier"
},
ex
.
getExpectedTokens
().
toArray
());
}
catch
(
SQLException
ex
)
{
fail
();
}
try
{
conn
.
prepareStatement
(
"ALTER"
);
fail
();
}
catch
(
JdbcParseSQLException
ex
)
{
assertEquals
(
6
,
ex
.
getSyntaxErrorPosition
());
assertEquals
(
new
Object
[]
{
"TABLE"
,
"USER"
,
"INDEX"
,
"SCHEMA"
,
"SEQUENCE"
,
"VIEW"
},
ex
.
getExpectedTokens
().
toArray
());
}
catch
(
SQLException
ex
)
{
fail
();
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论