Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
e6ca5750
提交
e6ca5750
authored
2月 18, 2010
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add tests.
上级
ad71fc46
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
96 行增加
和
6 行删除
+96
-6
PrepareProcedure.java
h2/src/main/org/h2/command/ddl/PrepareProcedure.java
+7
-0
SimpleResultSet.java
h2/src/main/org/h2/tools/SimpleResultSet.java
+10
-4
TestTools.java
h2/src/test/org/h2/test/unit/TestTools.java
+79
-2
没有找到文件。
h2/src/main/org/h2/command/ddl/PrepareProcedure.java
浏览文件 @
e6ca5750
...
@@ -6,9 +6,12 @@
...
@@ -6,9 +6,12 @@
*/
*/
package
org
.
h2
.
command
.
ddl
;
package
org
.
h2
.
command
.
ddl
;
import
java.util.ArrayList
;
import
org.h2.command.Prepared
;
import
org.h2.command.Prepared
;
import
org.h2.engine.Procedure
;
import
org.h2.engine.Procedure
;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
import
org.h2.expression.Parameter
;
import
org.h2.util.New
;
/**
/**
* This class represents the statement
* This class represents the statement
...
@@ -44,4 +47,8 @@ public class PrepareProcedure extends DefineCommand {
...
@@ -44,4 +47,8 @@ public class PrepareProcedure extends DefineCommand {
this
.
prepared
=
prep
;
this
.
prepared
=
prep
;
}
}
public
ArrayList
<
Parameter
>
getParameters
()
{
return
New
.
arrayList
();
}
}
}
h2/src/main/org/h2/tools/SimpleResultSet.java
浏览文件 @
e6ca5750
...
@@ -26,6 +26,8 @@ import java.sql.Types;
...
@@ -26,6 +26,8 @@ import java.sql.Types;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Calendar
;
import
java.util.Calendar
;
import
java.util.Map
;
import
java.util.Map
;
import
org.h2.constant.ErrorCode
;
import
org.h2.message.DbException
;
import
org.h2.util.New
;
import
org.h2.util.New
;
/*## Java 1.6 begin ##
/*## Java 1.6 begin ##
...
@@ -514,7 +516,7 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData {
...
@@ -514,7 +516,7 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData {
return
i
+
1
;
return
i
+
1
;
}
}
}
}
throw
new
SQLException
(
"Column not found: "
+
columnLabel
,
"42S22"
);
throw
DbException
.
get
(
ErrorCode
.
COLUMN_NOT_FOUND_1
,
columnLabel
).
getSQLException
(
);
}
}
/**
/**
...
@@ -1610,18 +1612,18 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData {
...
@@ -1610,18 +1612,18 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData {
* INTERNAL
* INTERNAL
*/
*/
static
SQLException
getUnsupportedException
()
{
static
SQLException
getUnsupportedException
()
{
return
new
SQLException
(
"Feature not supported"
,
"HYC00"
);
return
DbException
.
get
(
ErrorCode
.
FEATURE_NOT_SUPPORTED_1
).
getSQLException
(
);
}
}
private
void
checkColumnIndex
(
int
columnIndex
)
throws
SQLException
{
private
void
checkColumnIndex
(
int
columnIndex
)
throws
SQLException
{
if
(
columnIndex
<
0
||
columnIndex
>=
columns
.
size
())
{
if
(
columnIndex
<
0
||
columnIndex
>=
columns
.
size
())
{
throw
new
SQLException
(
"Invalid column index "
+
(
columnIndex
+
1
),
"90009"
);
throw
DbException
.
getInvalidValueException
(
""
+
columnIndex
,
"columnIndex"
).
getSQLException
(
);
}
}
}
}
private
Object
get
(
int
columnIndex
)
throws
SQLException
{
private
Object
get
(
int
columnIndex
)
throws
SQLException
{
if
(
currentRow
==
null
)
{
if
(
currentRow
==
null
)
{
throw
new
SQLException
(
"No data is available"
,
"02000"
);
throw
DbException
.
get
(
ErrorCode
.
NO_DATA_AVAILABLE
).
getSQLException
(
);
}
}
columnIndex
--;
columnIndex
--;
checkColumnIndex
(
columnIndex
);
checkColumnIndex
(
columnIndex
);
...
@@ -1790,16 +1792,20 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData {
...
@@ -1790,16 +1792,20 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData {
/**
/**
* INTERNAL
* INTERNAL
*/
*/
/*## Java 1.6 begin ##
public String getNString(int columnIndex) throws SQLException {
public String getNString(int columnIndex) throws SQLException {
return getString(columnIndex);
return getString(columnIndex);
}
}
## Java 1.6 end ##*/
/**
/**
* INTERNAL
* INTERNAL
*/
*/
/*## Java 1.6 begin ##
public String getNString(String columnLabel) throws SQLException {
public String getNString(String columnLabel) throws SQLException {
return getString(columnLabel);
return getString(columnLabel);
}
}
## Java 1.6 end ##*/
/**
/**
* INTERNAL
* INTERNAL
...
...
h2/src/test/org/h2/test/unit/TestTools.java
浏览文件 @
e6ca5750
...
@@ -9,6 +9,8 @@ package org.h2.test.unit;
...
@@ -9,6 +9,8 @@ package org.h2.test.unit;
import
java.io.ByteArrayOutputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.File
;
import
java.io.PrintStream
;
import
java.io.PrintStream
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.net.ServerSocket
;
import
java.net.ServerSocket
;
import
java.net.Socket
;
import
java.net.Socket
;
...
@@ -19,6 +21,8 @@ import java.sql.PreparedStatement;
...
@@ -19,6 +21,8 @@ import java.sql.PreparedStatement;
import
java.sql.ResultSet
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.sql.Statement
;
import
java.sql.Time
;
import
java.sql.Timestamp
;
import
java.sql.Types
;
import
java.sql.Types
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Random
;
import
java.util.Random
;
...
@@ -79,7 +83,7 @@ public class TestTools extends TestBase {
...
@@ -79,7 +83,7 @@ public class TestTools extends TestBase {
deleteDb
(
"utils"
);
deleteDb
(
"utils"
);
}
}
private
void
testSimpleResultSet
()
throws
SQL
Exception
{
private
void
testSimpleResultSet
()
throws
Exception
{
SimpleResultSet
rs
;
SimpleResultSet
rs
;
rs
=
new
SimpleResultSet
();
rs
=
new
SimpleResultSet
();
rs
.
addColumn
(
"a"
,
Types
.
BIGINT
,
0
,
0
);
rs
.
addColumn
(
"a"
,
Types
.
BIGINT
,
0
,
0
);
...
@@ -89,37 +93,110 @@ public class TestTools extends TestBase {
...
@@ -89,37 +93,110 @@ public class TestTools extends TestBase {
rs
.
addColumn
(
"e"
,
Types
.
DECIMAL
,
0
,
0
);
rs
.
addColumn
(
"e"
,
Types
.
DECIMAL
,
0
,
0
);
rs
.
addColumn
(
"f"
,
Types
.
FLOAT
,
0
,
0
);
rs
.
addColumn
(
"f"
,
Types
.
FLOAT
,
0
,
0
);
rs
.
addColumn
(
"g"
,
Types
.
VARCHAR
,
0
,
0
);
rs
.
addColumn
(
"g"
,
Types
.
VARCHAR
,
0
,
0
);
rs
.
addColumn
(
"h"
,
Types
.
ARRAY
,
0
,
0
);
rs
.
addColumn
(
"i"
,
Types
.
TIME
,
0
,
0
);
rs
.
addColumn
(
"j"
,
Types
.
TIMESTAMP
,
0
,
0
);
Date
d
=
Date
.
valueOf
(
"2001-02-03"
);
Date
d
=
Date
.
valueOf
(
"2001-02-03"
);
byte
[]
b
=
new
byte
[]{(
byte
)
0xab
};
byte
[]
b
=
new
byte
[]{(
byte
)
0xab
};
rs
.
addRow
(
1
,
b
,
true
,
d
,
"10.3"
,
Math
.
PI
,
"-3"
);
Object
[]
a
=
new
Object
[]{
1
,
2
};
Time
t
=
Time
.
valueOf
(
"10:20:30"
);
Timestamp
ts
=
Timestamp
.
valueOf
(
"2002-03-04 10:20:30"
);
rs
.
addRow
(
1
,
b
,
true
,
d
,
"10.3"
,
Math
.
PI
,
"-3"
,
a
,
t
,
ts
);
rs
.
next
();
rs
.
next
();
assertEquals
(
1
,
rs
.
getLong
(
1
));
assertEquals
(
1
,
rs
.
getLong
(
1
));
assertEquals
((
byte
)
1
,
rs
.
getByte
(
1
));
assertEquals
((
byte
)
1
,
rs
.
getByte
(
1
));
assertEquals
((
short
)
1
,
rs
.
getShort
(
1
));
assertEquals
((
short
)
1
,
rs
.
getShort
(
1
));
assertEquals
(
1
,
rs
.
getLong
(
"a"
));
assertEquals
(
1
,
rs
.
getLong
(
"a"
));
assertEquals
((
byte
)
1
,
rs
.
getByte
(
"a"
));
assertEquals
((
byte
)
1
,
rs
.
getByte
(
"a"
));
assertEquals
(
1
,
rs
.
getInt
(
"a"
));
assertEquals
((
short
)
1
,
rs
.
getShort
(
"a"
));
assertEquals
((
short
)
1
,
rs
.
getShort
(
"a"
));
assertTrue
(
rs
.
getObject
(
1
).
getClass
()
==
Integer
.
class
);
assertTrue
(
rs
.
getObject
(
"a"
).
getClass
()
==
Integer
.
class
);
assertEquals
(
b
,
rs
.
getBytes
(
2
));
assertEquals
(
b
,
rs
.
getBytes
(
2
));
assertEquals
(
b
,
rs
.
getBytes
(
"b"
));
assertEquals
(
b
,
rs
.
getBytes
(
"b"
));
assertTrue
(
rs
.
getBoolean
(
3
));
assertTrue
(
rs
.
getBoolean
(
3
));
assertTrue
(
rs
.
getBoolean
(
"c"
));
assertTrue
(
rs
.
getBoolean
(
"c"
));
assertEquals
(
d
.
getTime
(),
rs
.
getDate
(
4
).
getTime
());
assertEquals
(
d
.
getTime
(),
rs
.
getDate
(
4
).
getTime
());
assertEquals
(
d
.
getTime
(),
rs
.
getDate
(
"d"
).
getTime
());
assertEquals
(
d
.
getTime
(),
rs
.
getDate
(
"d"
).
getTime
());
assertTrue
(
new
BigDecimal
(
"10.3"
).
equals
(
rs
.
getBigDecimal
(
5
)));
assertTrue
(
new
BigDecimal
(
"10.3"
).
equals
(
rs
.
getBigDecimal
(
5
)));
assertTrue
(
new
BigDecimal
(
"10.3"
).
equals
(
rs
.
getBigDecimal
(
"e"
)));
assertTrue
(
new
BigDecimal
(
"10.3"
).
equals
(
rs
.
getBigDecimal
(
"e"
)));
assertEquals
(
10.3
,
rs
.
getDouble
(
5
));
assertEquals
(
10.3
,
rs
.
getDouble
(
5
));
assertEquals
((
float
)
10.3
,
rs
.
getFloat
(
5
));
assertEquals
((
float
)
10.3
,
rs
.
getFloat
(
5
));
assertTrue
(
Math
.
PI
==
rs
.
getDouble
(
6
));
assertTrue
(
Math
.
PI
==
rs
.
getDouble
(
6
));
assertTrue
(
Math
.
PI
==
rs
.
getDouble
(
"f"
));
assertTrue
(
Math
.
PI
==
rs
.
getDouble
(
"f"
));
assertTrue
((
float
)
Math
.
PI
==
rs
.
getFloat
(
6
));
assertTrue
((
float
)
Math
.
PI
==
rs
.
getFloat
(
6
));
assertTrue
((
float
)
Math
.
PI
==
rs
.
getFloat
(
"f"
));
assertTrue
((
float
)
Math
.
PI
==
rs
.
getFloat
(
"f"
));
assertEquals
(-
3
,
rs
.
getInt
(
7
));
assertEquals
(-
3
,
rs
.
getInt
(
7
));
assertEquals
(-
3
,
rs
.
getByte
(
7
));
assertEquals
(-
3
,
rs
.
getByte
(
7
));
assertEquals
(-
3
,
rs
.
getShort
(
7
));
assertEquals
(-
3
,
rs
.
getShort
(
7
));
assertEquals
(-
3
,
rs
.
getLong
(
7
));
assertEquals
(-
3
,
rs
.
getLong
(
7
));
Object
[]
a2
=
(
Object
[])
rs
.
getArray
(
8
).
getArray
();
assertEquals
(
2
,
a2
.
length
);
assertTrue
(
a
==
a2
);
a2
=
(
Object
[])
rs
.
getArray
(
"h"
).
getArray
();
assertEquals
(
2
,
a2
.
length
);
assertTrue
(
a
==
a2
);
assertTrue
(
t
==
rs
.
getTime
(
"i"
));
assertTrue
(
t
==
rs
.
getTime
(
9
));
assertTrue
(
ts
==
rs
.
getTimestamp
(
"j"
));
assertTrue
(
ts
==
rs
.
getTimestamp
(
10
));
// all 'updateX' methods are not supported
for
(
Method
m:
rs
.
getClass
().
getMethods
())
{
if
(
m
.
getName
().
startsWith
(
"update"
))
{
int
len
=
m
.
getParameterTypes
().
length
;
Object
[]
params
=
new
Object
[
len
];
int
i
=
0
;
for
(
Class
<
?
>
type
:
m
.
getParameterTypes
())
{
Object
o
=
null
;
if
(
type
==
int
.
class
)
{
o
=
1
;
}
else
if
(
type
==
byte
.
class
)
{
o
=
(
byte
)
1
;
}
else
if
(
type
==
double
.
class
)
{
o
=
(
double
)
1
;
}
else
if
(
type
==
float
.
class
)
{
o
=
(
float
)
1
;
}
else
if
(
type
==
long
.
class
)
{
o
=
(
long
)
1
;
}
else
if
(
type
==
short
.
class
)
{
o
=
(
short
)
1
;
}
else
if
(
type
==
boolean
.
class
)
{
o
=
false
;
}
params
[
i
]
=
o
;
i
++;
}
try
{
m
.
invoke
(
rs
,
params
);
}
catch
(
InvocationTargetException
e
)
{
SQLException
e2
=
(
SQLException
)
e
.
getTargetException
();
assertEquals
(
ErrorCode
.
FEATURE_NOT_SUPPORTED_1
,
e2
.
getErrorCode
());
}
}
}
assertEquals
(
ResultSet
.
TYPE_FORWARD_ONLY
,
rs
.
getType
());
assertFalse
(
rs
.
isClosed
());
rs
.
beforeFirst
();
rs
.
beforeFirst
();
assertEquals
(
0
,
rs
.
getRow
());
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
next
());
assertFalse
(
rs
.
isClosed
());
assertEquals
(
1
,
rs
.
getRow
());
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
assertTrue
(
rs
.
isClosed
());
assertEquals
(
0
,
rs
.
getRow
());
}
}
private
void
testJdbcDriverUtils
()
{
private
void
testJdbcDriverUtils
()
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论