Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
437073c1
提交
437073c1
authored
4月 22, 2007
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
--no commit message
--no commit message
上级
da6e461b
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
13 个修改的文件
包含
402 行增加
和
146 行删除
+402
-146
ClassUtils.java
h2/src/main/org/h2/util/ClassUtils.java
+13
-0
DateTimeUtils.java
h2/src/main/org/h2/util/DateTimeUtils.java
+1
-0
FileUtils.java
h2/src/main/org/h2/util/FileUtils.java
+30
-8
JdbcUtils.java
h2/src/main/org/h2/util/JdbcUtils.java
+14
-0
StringUtils.java
h2/src/main/org/h2/util/StringUtils.java
+4
-0
DataType.java
h2/src/main/org/h2/value/DataType.java
+4
-2
Transfer.java
h2/src/main/org/h2/value/Transfer.java
+7
-1
ValueLob.java
h2/src/main/org/h2/value/ValueLob.java
+6
-6
Compact.java
h2/src/test/org/h2/samples/Compact.java
+4
-4
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+235
-119
TestBase.java
h2/src/test/org/h2/test/TestBase.java
+21
-0
test.in.txt
h2/src/test/org/h2/test/test.in.txt
+49
-6
testSimple.in.txt
h2/src/test/org/h2/test/testSimple.in.txt
+14
-0
没有找到文件。
h2/src/main/org/h2/util/ClassUtils.java
0 → 100644
浏览文件 @
437073c1
/*
* Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
util
;
public
class
ClassUtils
{
public
static
Class
loadClass
(
String
className
)
throws
ClassNotFoundException
{
// TODO support special syntax to load classes using another classloader
return
Class
.
forName
(
className
);
}
}
h2/src/main/org/h2/util/DateTimeUtils.java
浏览文件 @
437073c1
...
...
@@ -151,6 +151,7 @@ public class DateTimeUtils {
if
(
s
.
endsWith
(
"Z"
))
{
s
=
s
.
substring
(
0
,
s
.
length
()-
1
);
tz
=
TimeZone
.
getTimeZone
(
"UTC"
);
}
else
{
int
timezoneStart
=
s
.
indexOf
(
'+'
,
s2
+
1
);
if
(
timezoneStart
<
0
)
{
...
...
h2/src/main/org/h2/util/FileUtils.java
浏览文件 @
437073c1
...
...
@@ -314,7 +314,7 @@ public class FileUtils {
return
fileName
.
startsWith
(
MEMORY_PREFIX
)
||
fileName
.
startsWith
(
MEMORY_PREFIX_2
);
}
public
static
String
createTempFile
(
String
name
,
String
suffix
,
boolean
deleteOnExit
)
throws
IOException
,
SQLException
{
public
static
String
createTempFile
(
String
name
,
String
suffix
,
boolean
deleteOnExit
,
boolean
inTempDir
)
throws
IOException
,
SQLException
{
name
+=
"."
;
if
(
isInMemory
(
name
))
{
for
(
int
i
=
0
;;
i
++)
{
...
...
@@ -327,12 +327,18 @@ public class FileUtils {
}
}
String
prefix
=
new
File
(
name
).
getName
();
File
dir
=
new
File
(
name
).
getAbsoluteFile
().
getParentFile
();
dir
.
mkdirs
();
File
dir
;
if
(
inTempDir
)
{
dir
=
null
;
}
else
{
dir
=
new
File
(
name
).
getAbsoluteFile
().
getParentFile
();
dir
.
mkdirs
();
}
File
f
=
File
.
createTempFile
(
prefix
,
suffix
,
dir
);
if
(
deleteOnExit
)
{
f
.
deleteOnExit
();
}
// return f.getPath();
return
f
.
getCanonicalPath
();
}
...
...
@@ -344,6 +350,7 @@ public class FileUtils {
}
public
static
String
[]
listFiles
(
String
path
)
throws
SQLException
{
//System.out.println("listFiles: " + path);
if
(
isInMemory
(
path
))
{
String
[]
list
=
new
String
[
memoryFiles
.
size
()];
MemoryFile
[]
l
=
new
MemoryFile
[
memoryFiles
.
size
()];
...
...
@@ -353,19 +360,34 @@ public class FileUtils {
}
return
list
;
}
File
f
=
new
File
(
path
);
try
{
File
[]
files
=
new
File
(
path
).
listFiles
();
if
(
files
==
null
)
{
String
[]
list
=
f
.
list
();
if
(
list
==
null
)
{
return
new
String
[
0
];
}
String
[]
list
=
new
String
[
files
.
length
]
;
for
(
int
i
=
0
;
i
<
files
.
length
;
i
++)
{
list
[
i
]
=
files
[
i
].
getCanonicalPath
()
;
String
base
=
f
.
getCanonicalPath
()
+
File
.
separator
;
for
(
int
i
=
0
;
i
<
list
.
length
;
i
++)
{
list
[
i
]
=
base
+
list
[
i
]
;
}
return
list
;
}
catch
(
IOException
e
)
{
throw
Message
.
convert
(
e
);
}
// try {
// File[] files = new File(path).listFiles();
// if(files == null) {
// return new String[0];
// }
// String[] list = new String[files.length];
// for(int i=0; i<files.length; i++) {
// list[i] = files[i].getCanonicalPath();
// }
// return list;
// } catch (IOException e) {
// throw Message.convert(e);
// }
}
public
static
boolean
isDirectory
(
String
fileName
)
{
...
...
h2/src/main/org/h2/util/JdbcUtils.java
浏览文件 @
437073c1
...
...
@@ -5,6 +5,7 @@
package
org
.
h2
.
util
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
...
...
@@ -13,6 +14,8 @@ import java.sql.Statement;
import
javax.sql.XAConnection
;
//#endif
import
org.h2.message.Message
;
public
class
JdbcUtils
{
public
static
void
closeSilently
(
Statement
stat
)
{
...
...
@@ -65,4 +68,15 @@ public class JdbcUtils {
}
//#endif
public
static
Connection
getConnection
(
String
driver
,
String
url
,
String
user
,
String
password
)
throws
SQLException
{
if
(!
StringUtils
.
isNullOrEmpty
(
driver
))
{
try
{
ClassUtils
.
loadClass
(
driver
);
}
catch
(
ClassNotFoundException
e
)
{
throw
Message
.
getSQLException
(
Message
.
CLASS_NOT_FOUND_1
,
new
String
[]{
driver
},
e
);
}
}
return
DriverManager
.
getConnection
(
url
,
user
,
password
);
}
}
h2/src/main/org/h2/util/StringUtils.java
浏览文件 @
437073c1
...
...
@@ -601,4 +601,8 @@ public class StringUtils {
return
buff
.
append
(
'\"'
).
toString
();
}
public
static
boolean
isNullOrEmpty
(
String
s
)
{
return
s
==
null
||
s
.
length
()
==
0
;
}
}
h2/src/main/org/h2/value/DataType.java
浏览文件 @
437073c1
...
...
@@ -175,11 +175,13 @@ public class DataType {
createString
(
true
),
new
String
[]{
"CLOB"
,
"TINYTEXT"
,
"TEXT"
,
"MEDIUMTEXT"
,
"LONGTEXT"
,
"NTEXT"
,
"NCLOB"
}
);
DataType
dataType
=
new
DataType
();
dataType
.
prefix
=
"("
;
dataType
.
suffix
=
"')"
;
add
(
Value
.
ARRAY
,
Types
.
ARRAY
,
"Array"
,
createString
(
false
)
,
dataType
,
new
String
[]{
"ARRAY"
}
);
// TODO data types: try to support other types as well (longvarchar for odbc/access,...) - maybe map them to regular types?
}
...
...
h2/src/main/org/h2/value/Transfer.java
浏览文件 @
437073c1
...
...
@@ -262,7 +262,13 @@ public class Transfer {
}
writeLong
(
length
);
Reader
reader
=
v
.
getReader
();
Writer
writer
=
new
OutputStreamWriter
(
out
,
Constants
.
UTF8
);
// below, writer.flush needs to be called to ensure the buffer is written
// but, this will also flush the output stream, and this slows things down
// so construct an output stream that will ignore this chained flush call
java
.
io
.
OutputStream
out2
=
new
java
.
io
.
FilterOutputStream
(
out
)
{
public
void
flush
()
{}
};
Writer
writer
=
new
OutputStreamWriter
(
out2
,
Constants
.
UTF8
);
long
written
=
IOUtils
.
copyAndCloseInput
(
reader
,
writer
);
if
(
Constants
.
CHECK
&&
written
!=
length
)
{
throw
Message
.
getInternalError
(
"length:"
+
length
+
" written:"
+
written
);
...
...
h2/src/main/org/h2/value/ValueLob.java
浏览文件 @
437073c1
...
...
@@ -194,9 +194,9 @@ public class ValueLob extends Value {
return
name
;
}
private
static
int
getNewObjectId
(
String
path
)
throws
SQLException
{
int
objectId
;
objectId
=
0
;
private
int
getNewObjectId
(
DataHandler
handler
)
throws
SQLException
{
String
path
=
handler
.
getDatabasePath
()
;
int
objectId
=
0
;
while
(
true
)
{
String
dir
=
getFileNamePrefix
(
path
,
objectId
);
String
[]
list
=
FileUtils
.
listFiles
(
dir
);
...
...
@@ -204,7 +204,7 @@ public class ValueLob extends Value {
boolean
[]
used
=
new
boolean
[
Constants
.
LOB_FILES_PER_DIRECTORY
];
for
(
int
i
=
0
;
i
<
list
.
length
;
i
++)
{
String
name
=
list
[
i
];
if
(
name
.
endsWith
(
".db"
))
{
if
(
name
.
endsWith
(
Constants
.
SUFFIX_DB_FILE
))
{
name
=
name
.
substring
(
name
.
lastIndexOf
(
File
.
separatorChar
)
+
1
);
String
n
=
name
.
substring
(
0
,
name
.
indexOf
(
'.'
));
int
id
;
...
...
@@ -282,7 +282,7 @@ public class ValueLob extends Value {
this
.
compression
=
compressionAlgorithm
!=
null
;
synchronized
(
handler
)
{
if
(
Constants
.
LOB_FILES_IN_DIRECTORIES
)
{
objectId
=
getNewObjectId
(
handler
.
getDatabasePath
()
);
objectId
=
getNewObjectId
(
handler
);
fileName
=
getFileNamePrefix
(
handler
.
getDatabasePath
(),
objectId
)
+
".temp.db"
;
}
else
{
objectId
=
handler
.
allocateObjectId
(
false
,
true
);
...
...
@@ -377,7 +377,7 @@ public class ValueLob extends Value {
if
(
linked
)
{
ValueLob
copy
=
ValueLob
.
copy
(
this
);
if
(
Constants
.
LOB_FILES_IN_DIRECTORIES
)
{
copy
.
objectId
=
getNewObjectId
(
handler
.
getDatabasePath
()
);
copy
.
objectId
=
getNewObjectId
(
handler
);
}
else
{
copy
.
objectId
=
handler
.
allocateObjectId
(
false
,
true
);
}
...
...
h2/src/test/org/h2/samples/Compact.java
浏览文件 @
437073c1
...
...
@@ -8,7 +8,7 @@ import java.sql.Connection;
import
java.sql.DriverManager
;
import
java.sql.Statement
;
import
org.h2.tools.
Backup
;
import
org.h2.tools.
Script
;
import
org.h2.tools.DeleteDbFiles
;
import
org.h2.tools.RunScript
;
...
...
@@ -30,9 +30,9 @@ public class Compact {
public
static
void
compact
(
String
dir
,
String
dbName
,
String
user
,
String
password
)
throws
Exception
{
String
url
=
"jdbc:h2:"
+
dir
+
"/"
+
dbName
;
String
script
=
"data/test.sql"
;
Backup
.
execute
(
url
,
user
,
password
,
script
);
String
file
=
"data/test.sql"
;
Script
.
execute
(
url
,
user
,
password
,
file
);
DeleteDbFiles
.
execute
(
dir
,
dbName
,
true
);
RunScript
.
execute
(
url
,
user
,
password
,
script
,
null
,
false
);
RunScript
.
execute
(
url
,
user
,
password
,
file
,
null
,
false
);
}
}
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
437073c1
差异被折叠。
点击展开。
h2/src/test/org/h2/test/TestBase.java
浏览文件 @
437073c1
...
...
@@ -16,6 +16,7 @@ import java.sql.SQLException;
import
java.sql.Statement
;
import
java.sql.Types
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Properties
;
import
org.h2.jdbc.JdbcConnection
;
...
...
@@ -561,4 +562,24 @@ public abstract class TestBase {
}
}
protected
void
compareDatabases
(
Statement
stat1
,
Statement
stat2
)
throws
Exception
{
ResultSet
rs1
=
stat1
.
executeQuery
(
"SCRIPT NOPASSWORDS"
);
ResultSet
rs2
=
stat2
.
executeQuery
(
"SCRIPT NOPASSWORDS"
);
ArrayList
list1
=
new
ArrayList
();
ArrayList
list2
=
new
ArrayList
();
while
(
rs1
.
next
())
{
check
(
rs2
.
next
());
list1
.
add
(
rs1
.
getString
(
1
));
list2
.
add
(
rs2
.
getString
(
1
));
}
for
(
int
i
=
0
;
i
<
list1
.
size
();
i
++)
{
String
s
=
(
String
)
list1
.
get
(
i
);
if
(!
list2
.
remove
(
s
))
{
error
(
"not found: "
+
s
);
}
}
check
(
list2
.
size
(),
0
);
checkFalse
(
rs2
.
next
());
}
}
h2/src/test/org/h2/test/test.in.txt
浏览文件 @
437073c1
--- special grammar and test cases ---------------------------------------------------------------------------------------------
select (1, 2);
> 1, 2
> ------
> (1, 2)
> rows: 1
select * from table(id int=(1, 2), name varchar=('Hello', 'World')) x order by id;
> ID NAME
> -- -----
> 1 Hello
> 2 World
> rows (ordered): 2
create table array_test(x array);
> ok
insert into array_test values((1, 2, 3)), ((2, 3, 4));
> update count: 2
select * from array_test where x = (1, 2, 3);
> X
> ---------
> (1, 2, 3)
> rows: 1
drop table array_test;
> ok
select * from (select 1), (select 2);
> 1 2
> - -
> 1 2
> rows: 1
CREATE TABLE TEST(A VARCHAR, B VARCHAR, C VARCHAR AS LOWER(A));
> ok
ALTER TABLE TEST DROP COLUMN B;
> ok
DROP TABLE TEST;
> ok
create table t1(c1 int, c2 int);
> ok
...
...
@@ -92,14 +135,14 @@ CREATE TABLE test (family_name VARCHAR_IGNORECASE(63) NOT NULL);
INSERT INTO test VALUES('Smith'), ('de Smith'), ('el Smith'), ('von Smith');
> update count: 4
SELECT * FROM test WHERE family_name IN ('de Smith', 'Smith');
SELECT * FROM test WHERE family_name IN ('de Smith', 'Smith');
> FAMILY_NAME
> -----------
> Smith
> de Smith
> rows: 2
SELECT * FROM test WHERE family_name BETWEEN 'D' AND 'T';
SELECT * FROM test WHERE family_name BETWEEN 'D' AND 'T';
> FAMILY_NAME
> -----------
> Smith
...
...
@@ -110,7 +153,7 @@ SELECT * FROM test WHERE family_name BETWEEN 'D' AND 'T';
CREATE INDEX family_name ON test(family_name);
> ok
SELECT * FROM test WHERE family_name IN ('de Smith', 'Smith');
SELECT * FROM test WHERE family_name IN ('de Smith', 'Smith');
> FAMILY_NAME
> -----------
> Smith
...
...
@@ -7430,9 +7473,9 @@ select ifnull(null, '1') x1, ifnull(null, null) xn, ifnull('a', 'b') xa from tes
> rows: 1
select casewhen(null, '1', '2') xn, casewhen(1>0, 'n', 'y') xy, casewhen(0<1, 'a', 'b') xa from test;
> XN
XY XA
> --
--
-- --
>
null
n a
> XN XY XA
> -- -- --
>
2
n a
> rows: 1
select x, case when x=0 then 'zero' else 'not zero' end y from system_range(0, 2);
...
...
h2/src/test/org/h2/test/testSimple.in.txt
浏览文件 @
437073c1
create table test(id int primary key check id>1);
drop table test;
create table table1(f1 int not null primary key);
create table table2(f2 int not null references table1(f1) on delete cascade);
drop table table2;
drop table table1;
create table table1(f1 int not null primary key);
create table table2(f2 int not null primary key references table1(f1));
drop table table1;
drop table table2;
select case when 1=null then 1 else 2 end;
> 2;
select case (1) when 1 then 1 else 2 end;
> 1;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论