Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
b3836d31
提交
b3836d31
authored
3月 01, 2014
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Limit line length to 80 characters
上级
fda7e2d5
隐藏空白字符变更
内嵌
并排
正在显示
32 个修改的文件
包含
1082 行增加
和
569 行删除
+1082
-569
SimpleResultSet.java
h2/src/main/org/h2/tools/SimpleResultSet.java
+2
-1
TriggerAdapter.java
h2/src/main/org/h2/tools/TriggerAdapter.java
+8
-5
DbUpgrade.java
h2/src/main/org/h2/upgrade/DbUpgrade.java
+16
-8
CacheLRU.java
h2/src/main/org/h2/util/CacheLRU.java
+7
-3
CacheTQ.java
h2/src/main/org/h2/util/CacheTQ.java
+2
-1
CloseWatcher.java
h2/src/main/org/h2/util/CloseWatcher.java
+4
-2
DateTimeUtils.java
h2/src/main/org/h2/util/DateTimeUtils.java
+20
-11
DbDriverActivator.java
h2/src/main/org/h2/util/DbDriverActivator.java
+12
-4
OsgiDataSourceFactory.java
h2/src/main/org/h2/util/OsgiDataSourceFactory.java
+69
-50
SourceCompiler.java
h2/src/main/org/h2/util/SourceCompiler.java
+2
-1
Coverage.java
h2/src/test/org/h2/test/coverage/Coverage.java
+25
-13
Profile.java
h2/src/test/org/h2/test/coverage/Profile.java
+3
-2
Db.java
h2/src/test/org/h2/test/db/Db.java
+2
-1
TaskProcess.java
h2/src/test/org/h2/test/db/TaskProcess.java
+3
-1
TestBackup.java
h2/src/test/org/h2/test/db/TestBackup.java
+24
-12
TestBigDb.java
h2/src/test/org/h2/test/db/TestBigDb.java
+38
-19
TestBigResult.java
h2/src/test/org/h2/test/db/TestBigResult.java
+8
-4
TestCases.java
h2/src/test/org/h2/test/db/TestCases.java
+168
-86
TestCluster.java
h2/src/test/org/h2/test/db/TestCluster.java
+62
-31
TestCompatibility.java
h2/src/test/org/h2/test/db/TestCompatibility.java
+85
-46
TestCompatibilityOracle.java
h2/src/test/org/h2/test/db/TestCompatibilityOracle.java
+18
-9
TestCsv.java
h2/src/test/org/h2/test/db/TestCsv.java
+70
-37
TestDateStorage.java
h2/src/test/org/h2/test/db/TestDateStorage.java
+2
-1
TestDeadlock.java
h2/src/test/org/h2/test/db/TestDeadlock.java
+2
-1
TestDrop.java
h2/src/test/org/h2/test/db/TestDrop.java
+2
-1
TestDuplicateKeyUpdate.java
h2/src/test/org/h2/test/db/TestDuplicateKeyUpdate.java
+38
-20
TestFullText.java
h2/src/test/org/h2/test/db/TestFullText.java
+100
-50
TestFunctionOverload.java
h2/src/test/org/h2/test/db/TestFunctionOverload.java
+6
-3
TestFunctions.java
h2/src/test/org/h2/test/db/TestFunctions.java
+157
-79
TestIndex.java
h2/src/test/org/h2/test/db/TestIndex.java
+46
-23
TestLinkedTable.java
h2/src/test/org/h2/test/db/TestLinkedTable.java
+79
-43
TestView.java
h2/src/test/org/h2/test/db/TestView.java
+2
-1
没有找到文件。
h2/src/main/org/h2/tools/SimpleResultSet.java
浏览文件 @
b3836d31
...
@@ -2312,7 +2312,8 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData {
...
@@ -2312,7 +2312,8 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData {
private
void
checkColumnIndex
(
int
columnIndex
)
throws
SQLException
{
private
void
checkColumnIndex
(
int
columnIndex
)
throws
SQLException
{
if
(
columnIndex
<
1
||
columnIndex
>
columns
.
size
())
{
if
(
columnIndex
<
1
||
columnIndex
>
columns
.
size
())
{
throw
DbException
.
getInvalidValueException
(
"columnIndex"
,
columnIndex
).
getSQLException
();
throw
DbException
.
getInvalidValueException
(
"columnIndex"
,
columnIndex
).
getSQLException
();
}
}
}
}
...
...
h2/src/main/org/h2/tools/TriggerAdapter.java
浏览文件 @
b3836d31
...
@@ -140,9 +140,10 @@ public abstract class TriggerAdapter implements Trigger {
...
@@ -140,9 +140,10 @@ public abstract class TriggerAdapter implements Trigger {
* @throws SQLException if the operation must be undone
* @throws SQLException if the operation must be undone
*/
*/
@Override
@Override
public
void
fire
(
Connection
conn
,
Object
[]
oldRow
,
public
void
fire
(
Connection
conn
,
Object
[]
oldRow
,
Object
[]
newRow
)
Object
[]
newRow
)
throws
SQLException
{
throws
SQLException
{
fire
(
conn
,
wrap
(
oldResultSet
,
oldSource
,
oldRow
),
wrap
(
newResultSet
,
newSource
,
newRow
));
fire
(
conn
,
wrap
(
oldResultSet
,
oldSource
,
oldRow
),
wrap
(
newResultSet
,
newSource
,
newRow
));
}
}
/**
/**
...
@@ -162,9 +163,11 @@ public abstract class TriggerAdapter implements Trigger {
...
@@ -162,9 +163,11 @@ public abstract class TriggerAdapter implements Trigger {
* DELETE)
* DELETE)
* @throws SQLException if the operation must be undone
* @throws SQLException if the operation must be undone
*/
*/
public
abstract
void
fire
(
Connection
conn
,
ResultSet
oldRow
,
ResultSet
newRow
)
throws
SQLException
;
public
abstract
void
fire
(
Connection
conn
,
ResultSet
oldRow
,
ResultSet
newRow
)
throws
SQLException
;
private
static
SimpleResultSet
wrap
(
SimpleResultSet
rs
,
TriggerRowSource
source
,
Object
[]
row
)
throws
SQLException
{
private
static
SimpleResultSet
wrap
(
SimpleResultSet
rs
,
TriggerRowSource
source
,
Object
[]
row
)
throws
SQLException
{
if
(
row
==
null
)
{
if
(
row
==
null
)
{
return
null
;
return
null
;
}
}
...
...
h2/src/main/org/h2/upgrade/DbUpgrade.java
浏览文件 @
b3836d31
...
@@ -45,7 +45,8 @@ public class DbUpgrade {
...
@@ -45,7 +45,8 @@ public class DbUpgrade {
* @param info the properties
* @param info the properties
* @return the connection if connected with the old version (NO_UPGRADE)
* @return the connection if connected with the old version (NO_UPGRADE)
*/
*/
public
static
Connection
connectOrUpgrade
(
String
url
,
Properties
info
)
throws
SQLException
{
public
static
Connection
connectOrUpgrade
(
String
url
,
Properties
info
)
throws
SQLException
{
if
(!
UPGRADE_CLASSES_PRESENT
)
{
if
(!
UPGRADE_CLASSES_PRESENT
)
{
return
null
;
return
null
;
}
}
...
@@ -100,12 +101,15 @@ public class DbUpgrade {
...
@@ -100,12 +101,15 @@ public class DbUpgrade {
DbUpgrade
.
deleteOldDb
=
deleteOldDb
;
DbUpgrade
.
deleteOldDb
=
deleteOldDb
;
}
}
private
static
Connection
connectWithOldVersion
(
String
url
,
Properties
info
)
throws
SQLException
{
private
static
Connection
connectWithOldVersion
(
String
url
,
Properties
info
)
url
=
"jdbc:h2v1_1:"
+
url
.
substring
(
"jdbc:h2:"
.
length
())
+
";IGNORE_UNKNOWN_SETTINGS=TRUE"
;
throws
SQLException
{
url
=
"jdbc:h2v1_1:"
+
url
.
substring
(
"jdbc:h2:"
.
length
())
+
";IGNORE_UNKNOWN_SETTINGS=TRUE"
;
return
DriverManager
.
getConnection
(
url
,
info
);
return
DriverManager
.
getConnection
(
url
,
info
);
}
}
private
static
void
upgrade
(
ConnectionInfo
ci
,
Properties
info
)
throws
SQLException
{
private
static
void
upgrade
(
ConnectionInfo
ci
,
Properties
info
)
throws
SQLException
{
String
name
=
ci
.
getName
();
String
name
=
ci
.
getName
();
String
data
=
name
+
".data.db"
;
String
data
=
name
+
".data.db"
;
String
index
=
name
+
".index.db"
;
String
index
=
name
+
".index.db"
;
...
@@ -117,11 +121,13 @@ public class DbUpgrade {
...
@@ -117,11 +121,13 @@ public class DbUpgrade {
try
{
try
{
if
(
scriptInTempDir
)
{
if
(
scriptInTempDir
)
{
new
File
(
Utils
.
getProperty
(
"java.io.tmpdir"
,
"."
)).
mkdirs
();
new
File
(
Utils
.
getProperty
(
"java.io.tmpdir"
,
"."
)).
mkdirs
();
script
=
File
.
createTempFile
(
"h2dbmigration"
,
"backup.sql"
).
getAbsolutePath
();
script
=
File
.
createTempFile
(
"h2dbmigration"
,
"backup.sql"
).
getAbsolutePath
();
}
else
{
}
else
{
script
=
name
+
".script.sql"
;
script
=
name
+
".script.sql"
;
}
}
String
oldUrl
=
"jdbc:h2v1_1:"
+
name
+
";UNDO_LOG=0;LOG=0;LOCK_MODE=0"
;
String
oldUrl
=
"jdbc:h2v1_1:"
+
name
+
";UNDO_LOG=0;LOG=0;LOCK_MODE=0"
;
String
cipher
=
ci
.
getProperty
(
"CIPHER"
,
null
);
String
cipher
=
ci
.
getProperty
(
"CIPHER"
,
null
);
if
(
cipher
!=
null
)
{
if
(
cipher
!=
null
)
{
oldUrl
+=
";CIPHER="
+
cipher
;
oldUrl
+=
";CIPHER="
+
cipher
;
...
@@ -130,7 +136,8 @@ public class DbUpgrade {
...
@@ -130,7 +136,8 @@ public class DbUpgrade {
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
String
uuid
=
UUID
.
randomUUID
().
toString
();
String
uuid
=
UUID
.
randomUUID
().
toString
();
if
(
cipher
!=
null
)
{
if
(
cipher
!=
null
)
{
stat
.
execute
(
"script to '"
+
script
+
"' cipher aes password '"
+
uuid
+
"' --hide--"
);
stat
.
execute
(
"script to '"
+
script
+
"' cipher aes password '"
+
uuid
+
"' --hide--"
);
}
else
{
}
else
{
stat
.
execute
(
"script to '"
+
script
+
"'"
);
stat
.
execute
(
"script to '"
+
script
+
"'"
);
}
}
...
@@ -144,7 +151,8 @@ public class DbUpgrade {
...
@@ -144,7 +151,8 @@ public class DbUpgrade {
conn
=
new
JdbcConnection
(
ci
,
true
);
conn
=
new
JdbcConnection
(
ci
,
true
);
stat
=
conn
.
createStatement
();
stat
=
conn
.
createStatement
();
if
(
cipher
!=
null
)
{
if
(
cipher
!=
null
)
{
stat
.
execute
(
"runscript from '"
+
script
+
"' cipher aes password '"
+
uuid
+
"' --hide--"
);
stat
.
execute
(
"runscript from '"
+
script
+
"' cipher aes password '"
+
uuid
+
"' --hide--"
);
}
else
{
}
else
{
stat
.
execute
(
"runscript from '"
+
script
+
"'"
);
stat
.
execute
(
"runscript from '"
+
script
+
"'"
);
}
}
...
...
h2/src/main/org/h2/util/CacheLRU.java
浏览文件 @
b3836d31
...
@@ -65,7 +65,8 @@ public class CacheLRU implements Cache {
...
@@ -65,7 +65,8 @@ public class CacheLRU implements Cache {
* @param cacheSize the size
* @param cacheSize the size
* @return the cache object
* @return the cache object
*/
*/
public
static
Cache
getCache
(
CacheWriter
writer
,
String
cacheType
,
int
cacheSize
)
{
public
static
Cache
getCache
(
CacheWriter
writer
,
String
cacheType
,
int
cacheSize
)
{
Map
<
Integer
,
CacheObject
>
secondLevel
=
null
;
Map
<
Integer
,
CacheObject
>
secondLevel
=
null
;
if
(
cacheType
.
startsWith
(
"SOFT_"
))
{
if
(
cacheType
.
startsWith
(
"SOFT_"
))
{
secondLevel
=
new
SoftHashMap
<
Integer
,
CacheObject
>();
secondLevel
=
new
SoftHashMap
<
Integer
,
CacheObject
>();
...
@@ -121,7 +122,8 @@ public class CacheLRU implements Cache {
...
@@ -121,7 +122,8 @@ public class CacheLRU implements Cache {
}
else
{
}
else
{
if
(
SysProperties
.
CHECK
)
{
if
(
SysProperties
.
CHECK
)
{
if
(
old
!=
rec
)
{
if
(
old
!=
rec
)
{
DbException
.
throwInternalError
(
"old!=record pos:"
+
pos
+
" old:"
+
old
+
" new:"
+
rec
);
DbException
.
throwInternalError
(
"old!=record pos:"
+
pos
+
" old:"
+
old
+
" new:"
+
rec
);
}
}
}
}
if
(!
fifo
)
{
if
(!
fifo
)
{
...
@@ -170,7 +172,9 @@ public class CacheLRU implements Cache {
...
@@ -170,7 +172,9 @@ public class CacheLRU implements Cache {
}
else
{
}
else
{
// can't remove any record, because the records can not be removed
// can't remove any record, because the records can not be removed
// hopefully this does not happen frequently, but it can happen
// hopefully this does not happen frequently, but it can happen
writer
.
getTrace
().
info
(
"cannot remove records, cache size too small? records:"
+
recordCount
+
" memory:"
+
memory
);
writer
.
getTrace
().
info
(
"cannot remove records, cache size too small? records:"
+
recordCount
+
" memory:"
+
memory
);
break
;
break
;
}
}
}
}
...
...
h2/src/main/org/h2/util/CacheTQ.java
浏览文件 @
b3836d31
...
@@ -22,7 +22,8 @@ public class CacheTQ implements Cache {
...
@@ -22,7 +22,8 @@ public class CacheTQ implements Cache {
private
final
Cache
lru
;
private
final
Cache
lru
;
private
final
Cache
fifo
;
private
final
Cache
fifo
;
private
final
SmallLRUCache
<
Integer
,
Object
>
recentlyUsed
=
SmallLRUCache
.
newInstance
(
1024
);
private
final
SmallLRUCache
<
Integer
,
Object
>
recentlyUsed
=
SmallLRUCache
.
newInstance
(
1024
);
private
int
lastUsed
=
-
1
;
private
int
lastUsed
=
-
1
;
private
int
maxMemory
;
private
int
maxMemory
;
...
...
h2/src/main/org/h2/util/CloseWatcher.java
浏览文件 @
b3836d31
...
@@ -45,7 +45,8 @@ public class CloseWatcher extends PhantomReference<Object> {
...
@@ -45,7 +45,8 @@ public class CloseWatcher extends PhantomReference<Object> {
*/
*/
private
Closeable
closeable
;
private
Closeable
closeable
;
public
CloseWatcher
(
Object
referent
,
ReferenceQueue
<
Object
>
q
,
Closeable
closeable
)
{
public
CloseWatcher
(
Object
referent
,
ReferenceQueue
<
Object
>
q
,
Closeable
closeable
)
{
super
(
referent
,
q
);
super
(
referent
,
q
);
this
.
closeable
=
closeable
;
this
.
closeable
=
closeable
;
}
}
...
@@ -88,7 +89,8 @@ public class CloseWatcher extends PhantomReference<Object> {
...
@@ -88,7 +89,8 @@ public class CloseWatcher extends PhantomReference<Object> {
* relatively slow)
* relatively slow)
* @return the close watcher
* @return the close watcher
*/
*/
public
static
CloseWatcher
register
(
Object
o
,
Closeable
closeable
,
boolean
stackTrace
)
{
public
static
CloseWatcher
register
(
Object
o
,
Closeable
closeable
,
boolean
stackTrace
)
{
ReferenceQueue
<
Object
>
q
=
queue
;
ReferenceQueue
<
Object
>
q
=
queue
;
if
(
q
==
null
)
{
if
(
q
==
null
)
{
q
=
new
ReferenceQueue
<
Object
>();
q
=
new
ReferenceQueue
<
Object
>();
...
...
h2/src/main/org/h2/util/DateTimeUtils.java
浏览文件 @
b3836d31
...
@@ -42,12 +42,14 @@ public class DateTimeUtils {
...
@@ -42,12 +42,14 @@ public class DateTimeUtils {
private
static
final
int
SHIFT_YEAR
=
9
;
private
static
final
int
SHIFT_YEAR
=
9
;
private
static
final
int
SHIFT_MONTH
=
5
;
private
static
final
int
SHIFT_MONTH
=
5
;
private
static
final
int
[]
NORMAL_DAYS_PER_MONTH
=
{
0
,
31
,
28
,
31
,
30
,
31
,
30
,
31
,
31
,
30
,
31
,
30
,
31
};
private
static
final
int
[]
NORMAL_DAYS_PER_MONTH
=
{
0
,
31
,
28
,
31
,
30
,
31
,
30
,
31
,
31
,
30
,
31
,
30
,
31
};
/**
/**
* Offsets of month within a year, starting with March, April,...
* Offsets of month within a year, starting with March, April,...
*/
*/
private
static
final
int
[]
DAYS_OFFSET
=
{
0
,
31
,
61
,
92
,
122
,
153
,
184
,
214
,
245
,
275
,
306
,
337
,
366
};
private
static
final
int
[]
DAYS_OFFSET
=
{
0
,
31
,
61
,
92
,
122
,
153
,
184
,
214
,
245
,
275
,
306
,
337
,
366
};
private
static
int
zoneOffset
;
private
static
int
zoneOffset
;
private
static
Calendar
cachedCalendar
;
private
static
Calendar
cachedCalendar
;
...
@@ -341,7 +343,8 @@ public class DateTimeUtils {
...
@@ -341,7 +343,8 @@ public class DateTimeUtils {
* @param millis the number of milliseconds
* @param millis the number of milliseconds
* @return the number of milliseconds (UTC)
* @return the number of milliseconds (UTC)
*/
*/
public
static
long
getMillis
(
TimeZone
tz
,
int
year
,
int
month
,
int
day
,
int
hour
,
int
minute
,
int
second
,
int
millis
)
{
public
static
long
getMillis
(
TimeZone
tz
,
int
year
,
int
month
,
int
day
,
int
hour
,
int
minute
,
int
second
,
int
millis
)
{
try
{
try
{
return
getTimeTry
(
false
,
tz
,
year
,
month
,
day
,
hour
,
minute
,
second
,
millis
);
return
getTimeTry
(
false
,
tz
,
year
,
month
,
day
,
hour
,
minute
,
second
,
millis
);
}
catch
(
IllegalArgumentException
e
)
{
}
catch
(
IllegalArgumentException
e
)
{
...
@@ -391,8 +394,8 @@ public class DateTimeUtils {
...
@@ -391,8 +394,8 @@ public class DateTimeUtils {
}
}
}
}
private
static
void
setCalendarFields
(
Calendar
cal
,
int
year
,
int
month
,
int
day
,
private
static
void
setCalendarFields
(
Calendar
cal
,
int
year
,
int
month
,
int
hour
,
int
minute
,
int
second
,
int
millis
)
{
int
day
,
int
hour
,
int
minute
,
int
second
,
int
millis
)
{
if
(
year
<=
0
)
{
if
(
year
<=
0
)
{
cal
.
set
(
Calendar
.
ERA
,
GregorianCalendar
.
BC
);
cal
.
set
(
Calendar
.
ERA
,
GregorianCalendar
.
BC
);
cal
.
set
(
Calendar
.
YEAR
,
1
-
year
);
cal
.
set
(
Calendar
.
YEAR
,
1
-
year
);
...
@@ -539,7 +542,8 @@ public class DateTimeUtils {
...
@@ -539,7 +542,8 @@ public class DateTimeUtils {
* @param timeZone the timezone
* @param timeZone the timezone
* @return the formatted date
* @return the formatted date
*/
*/
public
static
String
formatDateTime
(
java
.
util
.
Date
date
,
String
format
,
String
locale
,
String
timeZone
)
{
public
static
String
formatDateTime
(
java
.
util
.
Date
date
,
String
format
,
String
locale
,
String
timeZone
)
{
SimpleDateFormat
dateFormat
=
getDateFormat
(
format
,
locale
,
timeZone
);
SimpleDateFormat
dateFormat
=
getDateFormat
(
format
,
locale
,
timeZone
);
synchronized
(
dateFormat
)
{
synchronized
(
dateFormat
)
{
return
dateFormat
.
format
(
date
);
return
dateFormat
.
format
(
date
);
...
@@ -555,7 +559,8 @@ public class DateTimeUtils {
...
@@ -555,7 +559,8 @@ public class DateTimeUtils {
* @param timeZone the timeZone
* @param timeZone the timeZone
* @return the parsed date
* @return the parsed date
*/
*/
public
static
java
.
util
.
Date
parseDateTime
(
String
date
,
String
format
,
String
locale
,
String
timeZone
)
{
public
static
java
.
util
.
Date
parseDateTime
(
String
date
,
String
format
,
String
locale
,
String
timeZone
)
{
SimpleDateFormat
dateFormat
=
getDateFormat
(
format
,
locale
,
timeZone
);
SimpleDateFormat
dateFormat
=
getDateFormat
(
format
,
locale
,
timeZone
);
try
{
try
{
synchronized
(
dateFormat
)
{
synchronized
(
dateFormat
)
{
...
@@ -567,7 +572,8 @@ public class DateTimeUtils {
...
@@ -567,7 +572,8 @@ public class DateTimeUtils {
}
}
}
}
private
static
SimpleDateFormat
getDateFormat
(
String
format
,
String
locale
,
String
timeZone
)
{
private
static
SimpleDateFormat
getDateFormat
(
String
format
,
String
locale
,
String
timeZone
)
{
try
{
try
{
// currently, a new instance is create for each call
// currently, a new instance is create for each call
// however, could cache the last few instances
// however, could cache the last few instances
...
@@ -583,7 +589,8 @@ public class DateTimeUtils {
...
@@ -583,7 +589,8 @@ public class DateTimeUtils {
}
}
return
df
;
return
df
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
throw
DbException
.
get
(
ErrorCode
.
PARSE_ERROR_1
,
e
,
format
+
"/"
+
locale
+
"/"
+
timeZone
);
throw
DbException
.
get
(
ErrorCode
.
PARSE_ERROR_1
,
e
,
format
+
"/"
+
locale
+
"/"
+
timeZone
);
}
}
}
}
...
@@ -641,7 +648,8 @@ public class DateTimeUtils {
...
@@ -641,7 +648,8 @@ public class DateTimeUtils {
* @param nanos the nanoseconds since midnight
* @param nanos the nanoseconds since midnight
* @return the timestamp
* @return the timestamp
*/
*/
public
static
Timestamp
convertDateValueToTimestamp
(
long
dateValue
,
long
nanos
)
{
public
static
Timestamp
convertDateValueToTimestamp
(
long
dateValue
,
long
nanos
)
{
long
millis
=
nanos
/
1000000
;
long
millis
=
nanos
/
1000000
;
nanos
-=
millis
*
1000000
;
nanos
-=
millis
*
1000000
;
long
s
=
millis
/
1000
;
long
s
=
millis
/
1000
;
...
@@ -800,7 +808,8 @@ public class DateTimeUtils {
...
@@ -800,7 +808,8 @@ public class DateTimeUtils {
nanos
-=
d
*
NANOS_PER_DAY
;
nanos
-=
d
*
NANOS_PER_DAY
;
absoluteDay
+=
d
;
absoluteDay
+=
d
;
}
}
return
ValueTimestamp
.
fromDateValueAndNanos
(
dateValueFromAbsoluteDay
(
absoluteDay
),
nanos
);
return
ValueTimestamp
.
fromDateValueAndNanos
(
dateValueFromAbsoluteDay
(
absoluteDay
),
nanos
);
}
}
/**
/**
...
...
h2/src/main/org/h2/util/DbDriverActivator.java
浏览文件 @
b3836d31
...
@@ -27,10 +27,18 @@ public class DbDriverActivator implements BundleActivator {
...
@@ -27,10 +27,18 @@ public class DbDriverActivator implements BundleActivator {
public
void
start
(
BundleContext
bundleContext
)
{
public
void
start
(
BundleContext
bundleContext
)
{
org
.
h2
.
Driver
driver
=
org
.
h2
.
Driver
.
load
();
org
.
h2
.
Driver
driver
=
org
.
h2
.
Driver
.
load
();
Properties
properties
=
new
Properties
();
Properties
properties
=
new
Properties
();
properties
.
put
(
DataSourceFactory
.
OSGI_JDBC_DRIVER_CLASS
,
org
.
h2
.
Driver
.
class
.
getName
());
properties
.
put
(
properties
.
put
(
DataSourceFactory
.
OSGI_JDBC_DRIVER_NAME
,
"H2 JDBC Driver"
);
DataSourceFactory
.
OSGI_JDBC_DRIVER_CLASS
,
properties
.
put
(
DataSourceFactory
.
OSGI_JDBC_DRIVER_VERSION
,
Constants
.
getFullVersion
());
org
.
h2
.
Driver
.
class
.
getName
());
bundleContext
.
registerService
(
DataSourceFactory
.
class
.
getName
(),
new
OsgiDataSourceFactory
(
driver
),
properties
);
properties
.
put
(
DataSourceFactory
.
OSGI_JDBC_DRIVER_NAME
,
"H2 JDBC Driver"
);
properties
.
put
(
DataSourceFactory
.
OSGI_JDBC_DRIVER_VERSION
,
Constants
.
getFullVersion
());
bundleContext
.
registerService
(
DataSourceFactory
.
class
.
getName
(),
new
OsgiDataSourceFactory
(
driver
),
properties
);
}
}
/**
/**
...
...
h2/src/main/org/h2/util/OsgiDataSourceFactory.java
浏览文件 @
b3836d31
...
@@ -50,7 +50,8 @@ public class OsgiDataSourceFactory implements DataSourceFactory {
...
@@ -50,7 +50,8 @@ public class OsgiDataSourceFactory implements DataSourceFactory {
* @return a new data source.
* @return a new data source.
*/
*/
@Override
@Override
public
DataSource
createDataSource
(
Properties
properties
)
throws
SQLException
{
public
DataSource
createDataSource
(
Properties
properties
)
throws
SQLException
{
// Make copy of properties
// Make copy of properties
Properties
propertiesCopy
=
new
Properties
();
Properties
propertiesCopy
=
new
Properties
();
if
(
properties
!=
null
)
{
if
(
properties
!=
null
)
{
...
@@ -79,7 +80,8 @@ public class OsgiDataSourceFactory implements DataSourceFactory {
...
@@ -79,7 +80,8 @@ public class OsgiDataSourceFactory implements DataSourceFactory {
* @return a new data source.
* @return a new data source.
*/
*/
@Override
@Override
public
ConnectionPoolDataSource
createConnectionPoolDataSource
(
Properties
properties
)
throws
SQLException
{
public
ConnectionPoolDataSource
createConnectionPoolDataSource
(
Properties
properties
)
throws
SQLException
{
// Make copy of properties
// Make copy of properties
Properties
propertiesCopy
=
new
Properties
();
Properties
propertiesCopy
=
new
Properties
();
if
(
properties
!=
null
)
{
if
(
properties
!=
null
)
{
...
@@ -108,7 +110,8 @@ public class OsgiDataSourceFactory implements DataSourceFactory {
...
@@ -108,7 +110,8 @@ public class OsgiDataSourceFactory implements DataSourceFactory {
* @return a new data source.
* @return a new data source.
*/
*/
@Override
@Override
public
XADataSource
createXADataSource
(
Properties
properties
)
throws
SQLException
{
public
XADataSource
createXADataSource
(
Properties
properties
)
throws
SQLException
{
// Make copy of properties
// Make copy of properties
Properties
propertiesCopy
=
new
Properties
();
Properties
propertiesCopy
=
new
Properties
();
if
(
properties
!=
null
)
{
if
(
properties
!=
null
)
{
...
@@ -136,7 +139,8 @@ public class OsgiDataSourceFactory implements DataSourceFactory {
...
@@ -136,7 +139,8 @@ public class OsgiDataSourceFactory implements DataSourceFactory {
* @return a driver.
* @return a driver.
*/
*/
@Override
@Override
public
java
.
sql
.
Driver
createDriver
(
Properties
properties
)
throws
SQLException
{
public
java
.
sql
.
Driver
createDriver
(
Properties
properties
)
throws
SQLException
{
if
(
properties
!=
null
&&
!
properties
.
isEmpty
())
{
if
(
properties
!=
null
&&
!
properties
.
isEmpty
())
{
// No properties supported
// No properties supported
throw
new
SQLException
();
throw
new
SQLException
();
...
@@ -147,77 +151,88 @@ public class OsgiDataSourceFactory implements DataSourceFactory {
...
@@ -147,77 +151,88 @@ public class OsgiDataSourceFactory implements DataSourceFactory {
/**
/**
* Checker method that will throw if any unsupported standard OSGi options
* Checker method that will throw if any unsupported standard OSGi options
* is present.
* is present.
*
*
* @param p
roperties
the properties to check
* @param p the properties to check
* @throws SQLFeatureNotSupportedException if unsupported properties are
* @throws SQLFeatureNotSupportedException if unsupported properties are
* present
* present
*/
*/
private
static
void
rejectUnsupportedOptions
(
Properties
properties
)
throws
SQLFeatureNotSupportedException
{
private
static
void
rejectUnsupportedOptions
(
Properties
p
)
throws
SQLFeatureNotSupportedException
{
// Unsupported standard properties in OSGi
// Unsupported standard properties in OSGi
if
(
properties
.
containsKey
(
DataSourceFactory
.
JDBC_ROLE_NAME
))
{
if
(
p
.
containsKey
(
DataSourceFactory
.
JDBC_ROLE_NAME
))
{
throw
new
SQLFeatureNotSupportedException
(
"The "
+
DataSourceFactory
.
JDBC_ROLE_NAME
throw
new
SQLFeatureNotSupportedException
(
"The "
+
+
" property is not supported by H2"
);
DataSourceFactory
.
JDBC_ROLE_NAME
+
" property is not supported by H2"
);
}
}
if
(
properties
.
containsKey
(
DataSourceFactory
.
JDBC_DATASOURCE_NAME
))
{
if
(
p
.
containsKey
(
DataSourceFactory
.
JDBC_DATASOURCE_NAME
))
{
throw
new
SQLFeatureNotSupportedException
(
"The "
+
DataSourceFactory
.
JDBC_DATASOURCE_NAME
throw
new
SQLFeatureNotSupportedException
(
"The "
+
+
" property is not supported by H2"
);
DataSourceFactory
.
JDBC_DATASOURCE_NAME
+
" property is not supported by H2"
);
}
}
}
}
/**
/**
* Applies common OSGi properties to a H2 data source. Non standard
* Applies common OSGi properties to a H2 data source. Non standard
* properties will be applied as H2 options.
* properties will be applied as H2 options.
*
*
* @param dataSource the data source to configure
* @param dataSource the data source to configure
* @param p
roperties
the properties to apply to the data source
* @param p the properties to apply to the data source
*/
*/
private
static
void
setupH2DataSource
(
JdbcDataSource
dataSource
,
Properties
properties
)
{
private
static
void
setupH2DataSource
(
JdbcDataSource
dataSource
,
Properties
p
)
{
// Setting user and password
// Setting user and password
if
(
p
roperties
.
containsKey
(
DataSourceFactory
.
JDBC_USER
))
{
if
(
p
.
containsKey
(
DataSourceFactory
.
JDBC_USER
))
{
dataSource
.
setUser
((
String
)
p
roperties
.
remove
(
DataSourceFactory
.
JDBC_USER
));
dataSource
.
setUser
((
String
)
p
.
remove
(
DataSourceFactory
.
JDBC_USER
));
}
}
if
(
properties
.
containsKey
(
DataSourceFactory
.
JDBC_PASSWORD
))
{
if
(
p
.
containsKey
(
DataSourceFactory
.
JDBC_PASSWORD
))
{
dataSource
.
setPassword
((
String
)
properties
.
remove
(
DataSourceFactory
.
JDBC_PASSWORD
));
dataSource
.
setPassword
((
String
)
p
.
remove
(
DataSourceFactory
.
JDBC_PASSWORD
));
}
}
// Setting description
// Setting description
if
(
properties
.
containsKey
(
DataSourceFactory
.
JDBC_DESCRIPTION
))
{
if
(
p
.
containsKey
(
DataSourceFactory
.
JDBC_DESCRIPTION
))
{
dataSource
.
setDescription
((
String
)
properties
.
remove
(
DataSourceFactory
.
JDBC_DESCRIPTION
));
dataSource
.
setDescription
((
String
)
p
.
remove
(
DataSourceFactory
.
JDBC_DESCRIPTION
));
}
}
// Setting URL
// Setting URL
StringBuffer
connectionUrl
=
new
StringBuffer
();
StringBuffer
connectionUrl
=
new
StringBuffer
();
if
(
p
roperties
.
containsKey
(
DataSourceFactory
.
JDBC_URL
))
{
if
(
p
.
containsKey
(
DataSourceFactory
.
JDBC_URL
))
{
// Use URL if specified
// Use URL if specified
connectionUrl
.
append
(
p
roperties
.
remove
(
DataSourceFactory
.
JDBC_URL
));
connectionUrl
.
append
(
p
.
remove
(
DataSourceFactory
.
JDBC_URL
));
// Remove individual properties
// Remove individual properties
p
roperties
.
remove
(
DataSourceFactory
.
JDBC_NETWORK_PROTOCOL
);
p
.
remove
(
DataSourceFactory
.
JDBC_NETWORK_PROTOCOL
);
p
roperties
.
remove
(
DataSourceFactory
.
JDBC_SERVER_NAME
);
p
.
remove
(
DataSourceFactory
.
JDBC_SERVER_NAME
);
p
roperties
.
remove
(
DataSourceFactory
.
JDBC_PORT_NUMBER
);
p
.
remove
(
DataSourceFactory
.
JDBC_PORT_NUMBER
);
p
roperties
.
remove
(
DataSourceFactory
.
JDBC_DATABASE_NAME
);
p
.
remove
(
DataSourceFactory
.
JDBC_DATABASE_NAME
);
}
else
{
}
else
{
// Creating URL from individual properties
// Creating URL from individual properties
connectionUrl
.
append
(
Constants
.
START_URL
);
connectionUrl
.
append
(
Constants
.
START_URL
);
// Set network protocol (tcp/ssl) or DB type (mem/file)
// Set network protocol (tcp/ssl) or DB type (mem/file)
String
protocol
=
""
;
String
protocol
=
""
;
if
(
p
roperties
.
containsKey
(
DataSourceFactory
.
JDBC_NETWORK_PROTOCOL
))
{
if
(
p
.
containsKey
(
DataSourceFactory
.
JDBC_NETWORK_PROTOCOL
))
{
protocol
=
(
String
)
p
roperties
.
remove
(
DataSourceFactory
.
JDBC_NETWORK_PROTOCOL
);
protocol
=
(
String
)
p
.
remove
(
DataSourceFactory
.
JDBC_NETWORK_PROTOCOL
);
connectionUrl
.
append
(
protocol
).
append
(
":"
);
connectionUrl
.
append
(
protocol
).
append
(
":"
);
}
}
// Host name and/or port
// Host name and/or port
if
(
properties
.
containsKey
(
DataSourceFactory
.
JDBC_SERVER_NAME
))
{
if
(
p
.
containsKey
(
DataSourceFactory
.
JDBC_SERVER_NAME
))
{
connectionUrl
.
append
(
"//"
).
append
(
properties
.
remove
(
DataSourceFactory
.
JDBC_SERVER_NAME
));
connectionUrl
.
append
(
"//"
).
append
(
p
.
remove
(
DataSourceFactory
.
JDBC_SERVER_NAME
));
if
(
properties
.
containsKey
(
DataSourceFactory
.
JDBC_PORT_NUMBER
))
{
if
(
p
.
containsKey
(
DataSourceFactory
.
JDBC_PORT_NUMBER
))
{
connectionUrl
.
append
(
":"
).
append
(
properties
.
remove
(
DataSourceFactory
.
JDBC_PORT_NUMBER
));
connectionUrl
.
append
(
":"
).
append
(
p
.
remove
(
DataSourceFactory
.
JDBC_PORT_NUMBER
));
}
}
connectionUrl
.
append
(
"/"
);
connectionUrl
.
append
(
"/"
);
}
else
if
(
properties
.
containsKey
(
DataSourceFactory
.
JDBC_PORT_NUMBER
))
{
}
else
if
(
p
.
containsKey
(
DataSourceFactory
.
JDBC_PORT_NUMBER
))
{
// Assume local host if only port was set
// Assume local host if only port was set
connectionUrl
.
append
(
"//localhost:"
).
append
(
properties
.
remove
(
DataSourceFactory
.
JDBC_PORT_NUMBER
))
connectionUrl
.
append
(
"//localhost:"
)
.
append
(
p
.
remove
(
DataSourceFactory
.
JDBC_PORT_NUMBER
))
.
append
(
"/"
);
.
append
(
"/"
);
}
else
if
(
protocol
.
equals
(
"tcp"
)
||
protocol
.
equals
(
"ssl"
))
{
}
else
if
(
protocol
.
equals
(
"tcp"
)
||
protocol
.
equals
(
"ssl"
))
{
// Assume local host if network protocol is set, but no host or
// Assume local host if network protocol is set, but no host or
...
@@ -226,14 +241,16 @@ public class OsgiDataSourceFactory implements DataSourceFactory {
...
@@ -226,14 +241,16 @@ public class OsgiDataSourceFactory implements DataSourceFactory {
}
}
// DB path and name
// DB path and name
if
(
properties
.
containsKey
(
DataSourceFactory
.
JDBC_DATABASE_NAME
))
{
if
(
p
.
containsKey
(
DataSourceFactory
.
JDBC_DATABASE_NAME
))
{
connectionUrl
.
append
(
properties
.
remove
(
DataSourceFactory
.
JDBC_DATABASE_NAME
));
connectionUrl
.
append
(
p
.
remove
(
DataSourceFactory
.
JDBC_DATABASE_NAME
));
}
}
}
}
// Add remaining properties as options
// Add remaining properties as options
for
(
Object
option
:
properties
.
keySet
())
{
for
(
Object
option
:
p
.
keySet
())
{
connectionUrl
.
append
(
";"
).
append
(
option
).
append
(
"="
).
append
(
properties
.
get
(
option
));
connectionUrl
.
append
(
";"
).
append
(
option
).
append
(
"="
)
.
append
(
p
.
get
(
option
));
}
}
if
(
connectionUrl
.
length
()
>
Constants
.
START_URL
.
length
())
{
if
(
connectionUrl
.
length
()
>
Constants
.
START_URL
.
length
())
{
...
@@ -244,19 +261,21 @@ public class OsgiDataSourceFactory implements DataSourceFactory {
...
@@ -244,19 +261,21 @@ public class OsgiDataSourceFactory implements DataSourceFactory {
/**
/**
* Checker method that will throw if any pooling related standard OSGi
* Checker method that will throw if any pooling related standard OSGi
* options are present.
* options are present.
*
*
* @param p
roperties
the properties to check
* @param p the properties to check
* @throws SQLFeatureNotSupportedException if unsupported properties are
* @throws SQLFeatureNotSupportedException if unsupported properties are
* present
* present
*/
*/
private
static
void
rejectPoolingOptions
(
Properties
properties
)
throws
SQLFeatureNotSupportedException
{
private
static
void
rejectPoolingOptions
(
Properties
p
)
if
(
properties
.
containsKey
(
DataSourceFactory
.
JDBC_INITIAL_POOL_SIZE
)
throws
SQLFeatureNotSupportedException
{
||
properties
.
containsKey
(
DataSourceFactory
.
JDBC_MAX_IDLE_TIME
)
if
(
p
.
containsKey
(
DataSourceFactory
.
JDBC_INITIAL_POOL_SIZE
)
||
||
properties
.
containsKey
(
DataSourceFactory
.
JDBC_MAX_POOL_SIZE
)
p
.
containsKey
(
DataSourceFactory
.
JDBC_MAX_IDLE_TIME
)
||
||
properties
.
containsKey
(
DataSourceFactory
.
JDBC_MAX_STATEMENTS
)
p
.
containsKey
(
DataSourceFactory
.
JDBC_MAX_POOL_SIZE
)
||
||
properties
.
containsKey
(
DataSourceFactory
.
JDBC_MIN_POOL_SIZE
)
p
.
containsKey
(
DataSourceFactory
.
JDBC_MAX_STATEMENTS
)
||
||
properties
.
containsKey
(
DataSourceFactory
.
JDBC_PROPERTY_CYCLE
))
{
p
.
containsKey
(
DataSourceFactory
.
JDBC_MIN_POOL_SIZE
)
||
throw
new
SQLFeatureNotSupportedException
(
"Pooling properties are not supported by H2"
);
p
.
containsKey
(
DataSourceFactory
.
JDBC_PROPERTY_CYCLE
))
{
throw
new
SQLFeatureNotSupportedException
(
"Pooling properties are not supported by H2"
);
}
}
}
}
}
}
h2/src/main/org/h2/util/SourceCompiler.java
浏览文件 @
b3836d31
...
@@ -52,7 +52,8 @@ public class SourceCompiler {
...
@@ -52,7 +52,8 @@ public class SourceCompiler {
private
static
final
Class
<?>
JAVAC_SUN
;
private
static
final
Class
<?>
JAVAC_SUN
;
private
static
final
String
COMPILE_DIR
=
Utils
.
getProperty
(
"java.io.tmpdir"
,
"."
);
private
static
final
String
COMPILE_DIR
=
Utils
.
getProperty
(
"java.io.tmpdir"
,
"."
);
/**
/**
* The class name to source code map.
* The class name to source code map.
...
...
h2/src/test/org/h2/test/coverage/Coverage.java
浏览文件 @
b3836d31
...
@@ -23,7 +23,8 @@ import org.h2.util.New;
...
@@ -23,7 +23,8 @@ import org.h2.util.New;
* runtime of the tested application.
* runtime of the tested application.
*/
*/
public
class
Coverage
{
public
class
Coverage
{
private
static
final
String
IMPORT
=
"import "
+
Coverage
.
class
.
getPackage
().
getName
()
+
".Profile"
;
private
static
final
String
IMPORT
=
"import "
+
Coverage
.
class
.
getPackage
().
getName
()
+
".Profile"
;
private
final
ArrayList
<
String
>
files
=
New
.
arrayList
();
private
final
ArrayList
<
String
>
files
=
New
.
arrayList
();
private
final
ArrayList
<
String
>
exclude
=
New
.
arrayList
();
private
final
ArrayList
<
String
>
exclude
=
New
.
arrayList
();
private
Tokenizer
tokenizer
;
private
Tokenizer
tokenizer
;
...
@@ -41,15 +42,22 @@ public class Coverage {
...
@@ -41,15 +42,22 @@ public class Coverage {
private
boolean
perFunction
=
true
;
private
boolean
perFunction
=
true
;
private
void
printUsage
()
{
private
void
printUsage
()
{
System
.
out
.
println
(
"Usage:\n"
+
"- copy all your source files to another directory\n"
System
.
out
+
" (be careful, they will be modified - don't take originals!)\n"
+
"- java "
+
getClass
().
getName
()
.
println
(
"Usage:\n"
+
+
" <directory>\n"
+
" this will modified the source code and create 'profile.txt'\n"
"- copy all your source files to another directory\n"
+
+
"- compile the modified source files\n"
+
"- run your main application\n"
" (be careful, they will be modified - don't take originals!)\n"
+
+
"- after the application exits, a file 'notCovered.txt' is created,\n"
"- java "
+
getClass
().
getName
()
+
" <directory>\n"
+
+
" which contains the class names, function names and line numbers\n"
" this will modified the source code and create 'profile.txt'\n"
+
+
" of code that has not been covered\n\n"
+
"Options:\n"
+
"-r recurse all subdirectories\n"
"- compile the modified source files\n"
+
+
"-e exclude files\n"
+
"-c coverage on a per-class basis\n"
"- run your main application\n"
+
+
"-f coverage on a per-function basis\n"
+
"<dir> directory name (. for current directory)"
);
"- after the application exits, a file 'notCovered.txt' is created,\n"
+
" which contains the class names, function names and line numbers\n"
+
" of code that has not been covered\n\n"
+
"Options:\n"
+
"-r recurse all subdirectories\n"
+
"-e exclude files\n"
+
"-c coverage on a per-class basis\n"
+
"-f coverage on a per-function basis\n"
+
"<dir> directory name (. for current directory)"
);
}
}
/**
/**
...
@@ -124,7 +132,8 @@ public class Coverage {
...
@@ -124,7 +132,8 @@ public class Coverage {
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
long
t2
=
System
.
currentTimeMillis
();
long
t2
=
System
.
currentTimeMillis
();
if
(
t2
-
time
>
1000
||
i
>=
len
-
1
)
{
if
(
t2
-
time
>
1000
||
i
>=
len
-
1
)
{
System
.
out
.
println
((
i
+
1
)
+
" of "
+
len
+
" "
+
(
100
*
i
/
len
)
+
"%"
);
System
.
out
.
println
((
i
+
1
)
+
" of "
+
len
+
" "
+
(
100
*
i
/
len
)
+
"%"
);
time
=
t2
;
time
=
t2
;
}
}
String
fileName
=
files
.
get
(
i
);
String
fileName
=
files
.
get
(
i
);
...
@@ -149,7 +158,9 @@ public class Coverage {
...
@@ -149,7 +158,9 @@ public class Coverage {
}
}
file
=
file
.
substring
(
0
,
i
)
+
"."
+
file
.
substring
(
i
+
1
);
file
=
file
.
substring
(
0
,
i
)
+
"."
+
file
.
substring
(
i
+
1
);
}
}
if
(
name
.
endsWith
(
"Coverage.java"
)
||
name
.
endsWith
(
"Tokenizer.java"
)
||
name
.
endsWith
(
"Profile.java"
))
{
if
(
name
.
endsWith
(
"Coverage.java"
)
||
name
.
endsWith
(
"Tokenizer.java"
)
||
name
.
endsWith
(
"Profile.java"
))
{
return
;
return
;
}
}
File
f
=
new
File
(
name
);
File
f
=
new
File
(
name
);
...
@@ -359,7 +370,8 @@ public class Coverage {
...
@@ -359,7 +370,8 @@ public class Coverage {
private
void
processStatement
()
throws
IOException
{
private
void
processStatement
()
throws
IOException
{
while
(
true
)
{
while
(
true
)
{
if
(
token
.
equals
(
"while"
)
||
token
.
equals
(
"for"
)
||
token
.
equals
(
"synchronized"
))
{
if
(
token
.
equals
(
"while"
)
||
token
.
equals
(
"for"
)
||
token
.
equals
(
"synchronized"
))
{
read
();
read
();
readThis
(
"("
);
readThis
(
"("
);
processBracket
();
processBracket
();
...
...
h2/src/test/org/h2/test/coverage/Profile.java
浏览文件 @
b3836d31
...
@@ -155,8 +155,9 @@ public class Profile extends Thread {
...
@@ -155,8 +155,9 @@ public class Profile extends Thread {
}
}
}
}
int
percent
=
100
*
unvisited
/
maxIndex
;
int
percent
=
100
*
unvisited
/
maxIndex
;
print
(
"Not covered: "
+
percent
+
" % "
+
" ("
+
unvisited
+
" of "
+
maxIndex
+
"; throw="
print
(
"Not covered: "
+
percent
+
" % "
+
" ("
+
+
unvisitedThrow
+
")"
);
unvisited
+
" of "
+
maxIndex
+
"; throw="
+
unvisitedThrow
+
")"
);
}
finally
{
}
finally
{
IOUtils
.
closeSilently
(
writer
);
IOUtils
.
closeSilently
(
writer
);
IOUtils
.
closeSilently
(
r
);
IOUtils
.
closeSilently
(
r
);
...
...
h2/src/test/org/h2/test/db/Db.java
浏览文件 @
b3836d31
...
@@ -31,7 +31,8 @@ public class Db {
...
@@ -31,7 +31,8 @@ public class Db {
private
Connection
conn
;
private
Connection
conn
;
private
Statement
stat
;
private
Statement
stat
;
private
final
HashMap
<
String
,
PreparedStatement
>
prepared
=
new
HashMap
<
String
,
PreparedStatement
>();
private
final
HashMap
<
String
,
PreparedStatement
>
prepared
=
new
HashMap
<
String
,
PreparedStatement
>();
/**
/**
* Create a database object using the given connection.
* Create a database object using the given connection.
...
...
h2/src/test/org/h2/test/db/TaskProcess.java
浏览文件 @
b3836d31
...
@@ -67,7 +67,9 @@ public class TaskProcess {
...
@@ -67,7 +67,9 @@ public class TaskProcess {
writer
=
new
BufferedWriter
(
new
OutputStreamWriter
(
process
.
getOutputStream
()));
writer
=
new
BufferedWriter
(
new
OutputStreamWriter
(
process
.
getOutputStream
()));
String
line
=
reader
.
readLine
();
String
line
=
reader
.
readLine
();
if
(
line
==
null
)
{
if
(
line
==
null
)
{
throw
new
RuntimeException
(
"No reply from process, command: "
+
StringUtils
.
arrayCombine
(
procDef
,
' '
));
throw
new
RuntimeException
(
"No reply from process, command: "
+
StringUtils
.
arrayCombine
(
procDef
,
' '
));
}
else
if
(
line
.
startsWith
(
"running"
))
{
}
else
if
(
line
.
startsWith
(
"running"
))
{
traceOperation
(
"got reply: "
+
line
);
traceOperation
(
"got reply: "
+
line
);
}
else
if
(
line
.
startsWith
(
"init error"
))
{
}
else
if
(
line
.
startsWith
(
"init error"
))
{
...
...
h2/src/test/org/h2/test/db/TestBackup.java
浏览文件 @
b3836d31
...
@@ -78,7 +78,8 @@ public class TestBackup extends TestBase {
...
@@ -78,7 +78,8 @@ public class TestBackup extends TestBase {
}
}
};
};
Connection
conn2
;
Connection
conn2
;
conn2
=
getConnection
(
url
+
";database_event_listener='"
+
BackupListener
.
class
.
getName
()
+
"'"
);
conn2
=
getConnection
(
url
+
";database_event_listener='"
+
BackupListener
.
class
.
getName
()
+
"'"
);
Statement
stat2
=
conn2
.
createStatement
();
Statement
stat2
=
conn2
.
createStatement
();
task
.
execute
();
task
.
execute
();
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
...
@@ -90,7 +91,8 @@ public class TestBackup extends TestBase {
...
@@ -90,7 +91,8 @@ public class TestBackup extends TestBase {
conn3
=
getConnection
(
"t2/backup"
);
conn3
=
getConnection
(
"t2/backup"
);
Statement
stat3
=
conn3
.
createStatement
();
Statement
stat3
=
conn3
.
createStatement
();
stat3
.
execute
(
"script"
);
stat3
.
execute
(
"script"
);
ResultSet
rs
=
stat3
.
executeQuery
(
"select * from test where name='Hallo'"
);
ResultSet
rs
=
stat3
.
executeQuery
(
"select * from test where name='Hallo'"
);
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
fail
();
fail
();
}
}
...
@@ -145,21 +147,27 @@ public class TestBackup extends TestBase {
...
@@ -145,21 +147,27 @@ public class TestBackup extends TestBase {
private
void
testBackupRestoreLob
()
throws
SQLException
{
private
void
testBackupRestoreLob
()
throws
SQLException
{
deleteDb
(
"backup"
);
deleteDb
(
"backup"
);
Connection
conn
=
getConnection
(
"backup"
);
Connection
conn
=
getConnection
(
"backup"
);
conn
.
createStatement
().
execute
(
"create table test(x clob) as select space(10000)"
);
conn
.
createStatement
().
execute
(
"create table test(x clob) as select space(10000)"
);
conn
.
close
();
conn
.
close
();
Backup
.
execute
(
getBaseDir
()
+
"/backup.zip"
,
getBaseDir
(),
"backup"
,
true
);
Backup
.
execute
(
getBaseDir
()
+
"/backup.zip"
,
getBaseDir
(),
"backup"
,
true
);
deleteDb
(
"backup"
);
deleteDb
(
"backup"
);
Restore
.
execute
(
getBaseDir
()
+
"/backup.zip"
,
getBaseDir
(),
"backup"
);
Restore
.
execute
(
getBaseDir
()
+
"/backup.zip"
,
getBaseDir
(),
"backup"
);
}
}
private
void
testBackupRestoreLobStatement
()
throws
SQLException
{
private
void
testBackupRestoreLobStatement
()
throws
SQLException
{
deleteDb
(
"backup"
);
deleteDb
(
"backup"
);
Connection
conn
=
getConnection
(
"backup"
);
Connection
conn
=
getConnection
(
"backup"
);
conn
.
createStatement
().
execute
(
"create table test(x clob) as select space(10000)"
);
conn
.
createStatement
().
execute
(
conn
.
createStatement
().
execute
(
"backup to '"
+
getBaseDir
()
+
"/backup.zip"
+
"'"
);
"create table test(x clob) as select space(10000)"
);
conn
.
createStatement
().
execute
(
"backup to '"
+
getBaseDir
()
+
"/backup.zip"
+
"'"
);
conn
.
close
();
conn
.
close
();
deleteDb
(
"backup"
);
deleteDb
(
"backup"
);
Restore
.
execute
(
getBaseDir
()
+
"/backup.zip"
,
getBaseDir
(),
"backup"
);
Restore
.
execute
(
getBaseDir
()
+
"/backup.zip"
,
getBaseDir
(),
"backup"
);
}
}
private
void
testBackup
()
throws
SQLException
{
private
void
testBackup
()
throws
SQLException
{
...
@@ -169,10 +177,14 @@ public class TestBackup extends TestBase {
...
@@ -169,10 +177,14 @@ public class TestBackup extends TestBase {
Statement
stat1
,
stat2
,
stat3
;
Statement
stat1
,
stat2
,
stat3
;
conn1
=
getConnection
(
"backup"
);
conn1
=
getConnection
(
"backup"
);
stat1
=
conn1
.
createStatement
();
stat1
=
conn1
.
createStatement
();
stat1
.
execute
(
"create table test(id int primary key, name varchar(255))"
);
stat1
.
execute
(
"create table test"
+
stat1
.
execute
(
"insert into test values(1, 'first'), (2, 'second')"
);
"(id int primary key, name varchar(255))"
);
stat1
.
execute
(
"create table testlob(id int primary key, b blob, c clob)"
);
stat1
.
execute
(
"insert into test values"
+
stat1
.
execute
(
"insert into testlob values(1, space(10000), repeat('00', 10000))"
);
"(1, 'first'), (2, 'second')"
);
stat1
.
execute
(
"create table testlob"
+
"(id int primary key, b blob, c clob)"
);
stat1
.
execute
(
"insert into testlob values"
+
"(1, space(10000), repeat('00', 10000))"
);
conn2
=
getConnection
(
"backup"
);
conn2
=
getConnection
(
"backup"
);
stat2
=
conn2
.
createStatement
();
stat2
=
conn2
.
createStatement
();
stat2
.
execute
(
"insert into test values(3, 'third')"
);
stat2
.
execute
(
"insert into test values(3, 'third')"
);
...
...
h2/src/test/org/h2/test/db/TestBigDb.java
浏览文件 @
b3836d31
...
@@ -47,30 +47,46 @@ public class TestBigDb extends TestBase {
...
@@ -47,30 +47,46 @@ public class TestBigDb extends TestBase {
deleteDb
(
"bigDb"
);
deleteDb
(
"bigDb"
);
Connection
conn
=
getConnection
(
"bigDb"
);
Connection
conn
=
getConnection
(
"bigDb"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE CACHED TABLE TEST("
+
"M_CODE CHAR(1) DEFAULT CAST(RAND()*9 AS INT),"
stat
.
execute
(
"CREATE CACHED TABLE TEST("
+
"PRD_CODE CHAR(20) DEFAULT SECURE_RAND(10),"
+
"ORG_CODE_SUPPLIER CHAR(13) DEFAULT SECURE_RAND(6),"
+
"M_CODE CHAR(1) DEFAULT CAST(RAND()*9 AS INT),"
+
"PRD_CODE_1 CHAR(14) DEFAULT SECURE_RAND(7),"
+
"PRD_CODE_2 CHAR(20) DEFAULT SECURE_RAND(10),"
+
"PRD_CODE CHAR(20) DEFAULT SECURE_RAND(10),"
+
"ORG_CODE CHAR(13) DEFAULT SECURE_RAND(6),"
+
"SUBSTITUTED_BY CHAR(20) DEFAULT SECURE_RAND(10),"
+
"ORG_CODE_SUPPLIER CHAR(13) DEFAULT SECURE_RAND(6),"
+
"PRD_CODE_1 CHAR(14) DEFAULT SECURE_RAND(7),"
+
"PRD_CODE_2 CHAR(20) DEFAULT SECURE_RAND(10),"
+
"ORG_CODE CHAR(13) DEFAULT SECURE_RAND(6),"
+
"SUBSTITUTED_BY CHAR(20) DEFAULT SECURE_RAND(10),"
+
"SUBSTITUTED_BY_2 CHAR(14) DEFAULT SECURE_RAND(7),"
+
"SUBSTITUTED_BY_2 CHAR(14) DEFAULT SECURE_RAND(7),"
+
"SUBSTITUTION_FOR CHAR(20) DEFAULT SECURE_RAND(10),"
+
"SUBSTITUTION_FOR CHAR(20) DEFAULT SECURE_RAND(10),"
+
"SUBSTITUTION_FOR_2 CHAR(14) DEFAULT SECURE_RAND(7),"
+
"TEST CHAR(2) DEFAULT SECURE_RAND(1),"
+
"SUBSTITUTION_FOR_2 CHAR(14) DEFAULT SECURE_RAND(7),"
+
"TEST_2 CHAR(2) DEFAULT SECURE_RAND(1),"
+
"TEST_3 DECIMAL(7,2) DEFAULT RAND(),"
+
"TEST CHAR(2) DEFAULT SECURE_RAND(1),"
+
"TEST_2 CHAR(2) DEFAULT SECURE_RAND(1),"
+
"TEST_3 DECIMAL(7,2) DEFAULT RAND(),"
+
"PRIMARY_UNIT_CODE CHAR(3) DEFAULT SECURE_RAND(1),"
+
"PRIMARY_UNIT_CODE CHAR(3) DEFAULT SECURE_RAND(1),"
+
"RATE_PRICE_ORDER_UNIT DECIMAL(9,3) DEFAULT RAND(),"
+
"RATE_PRICE_ORDER_UNIT DECIMAL(9,3) DEFAULT RAND(),"
+
"ORDER_UNIT_CODE CHAR(3) DEFAULT SECURE_RAND(1),"
+
"ORDER_QTY_MIN DECIMAL(6,1) DEFAULT RAND(),"
+
"ORDER_UNIT_CODE CHAR(3) DEFAULT SECURE_RAND(1),"
+
"ORDER_QTY_MIN DECIMAL(6,1) DEFAULT RAND(),"
+
"ORDER_QTY_LOT_SIZE DECIMAL(6,1) DEFAULT RAND(),"
+
"ORDER_QTY_LOT_SIZE DECIMAL(6,1) DEFAULT RAND(),"
+
"ORDER_UNIT_CODE_2 CHAR(3) DEFAULT SECURE_RAND(1),"
+
"PRICE_GROUP CHAR(20) DEFAULT SECURE_RAND(10),"
+
"ORDER_UNIT_CODE_2 CHAR(3) DEFAULT SECURE_RAND(1),"
+
"LEAD_TIME INTEGER DEFAULT RAND(),"
+
"LEAD_TIME_UNIT_CODE CHAR(3) DEFAULT SECURE_RAND(1),"
+
"PRICE_GROUP CHAR(20) DEFAULT SECURE_RAND(10),"
+
"PRD_GROUP CHAR(10) DEFAULT SECURE_RAND(5),"
+
"WEIGHT_GROSS DECIMAL(7,3) DEFAULT RAND(),"
+
"LEAD_TIME INTEGER DEFAULT RAND(),"
+
"WEIGHT_UNIT_CODE CHAR(3) DEFAULT SECURE_RAND(1),"
+
"PACK_UNIT_CODE CHAR(3) DEFAULT SECURE_RAND(1),"
+
"LEAD_TIME_UNIT_CODE CHAR(3) DEFAULT SECURE_RAND(1),"
+
"PACK_LENGTH DECIMAL(7,3) DEFAULT RAND(),"
+
"PACK_WIDTH DECIMAL(7,3) DEFAULT RAND(),"
+
"PRD_GROUP CHAR(10) DEFAULT SECURE_RAND(5),"
+
"PACK_HEIGHT DECIMAL(7,3) DEFAULT RAND(),"
+
"SIZE_UNIT_CODE CHAR(3) DEFAULT SECURE_RAND(1),"
+
"WEIGHT_GROSS DECIMAL(7,3) DEFAULT RAND(),"
+
"STATUS_CODE CHAR(3) DEFAULT SECURE_RAND(1),"
+
"INTRA_STAT_CODE CHAR(12) DEFAULT SECURE_RAND(6),"
+
"WEIGHT_UNIT_CODE CHAR(3) DEFAULT SECURE_RAND(1),"
+
"PRD_TITLE CHAR(50) DEFAULT SECURE_RAND(25),"
+
"VALID_FROM DATE DEFAULT NOW(),"
+
"PACK_UNIT_CODE CHAR(3) DEFAULT SECURE_RAND(1),"
+
"PACK_LENGTH DECIMAL(7,3) DEFAULT RAND(),"
+
"PACK_WIDTH DECIMAL(7,3) DEFAULT RAND(),"
+
"PACK_HEIGHT DECIMAL(7,3) DEFAULT RAND(),"
+
"SIZE_UNIT_CODE CHAR(3) DEFAULT SECURE_RAND(1),"
+
"STATUS_CODE CHAR(3) DEFAULT SECURE_RAND(1),"
+
"INTRA_STAT_CODE CHAR(12) DEFAULT SECURE_RAND(6),"
+
"PRD_TITLE CHAR(50) DEFAULT SECURE_RAND(25),"
+
"VALID_FROM DATE DEFAULT NOW(),"
+
"MOD_DATUM DATE DEFAULT NOW())"
);
+
"MOD_DATUM DATE DEFAULT NOW())"
);
int
len
=
getSize
(
10
,
50000
);
int
len
=
getSize
(
10
,
50000
);
try
{
try
{
PreparedStatement
prep
=
conn
.
prepareStatement
(
"INSERT INTO TEST(PRD_CODE) VALUES('abc' || ?)"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"INSERT INTO TEST(PRD_CODE) VALUES('abc' || ?)"
);
long
time
=
System
.
currentTimeMillis
();
long
time
=
System
.
currentTimeMillis
();
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
if
((
i
%
1000
)
==
0
)
{
if
((
i
%
1000
)
==
0
)
{
...
@@ -104,9 +120,11 @@ public class TestBigDb extends TestBase {
...
@@ -104,9 +120,11 @@ public class TestBigDb extends TestBase {
deleteDb
(
"bigDb"
);
deleteDb
(
"bigDb"
);
Connection
conn
=
getConnection
(
"bigDb"
);
Connection
conn
=
getConnection
(
"bigDb"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE TABLE TEST(ID INT, NEG INT AS -ID, NAME VARCHAR, PRIMARY KEY(ID, NAME))"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT, NEG INT AS -ID, "
+
"NAME VARCHAR, PRIMARY KEY(ID, NAME))"
);
stat
.
execute
(
"CREATE INDEX IDX_NEG ON TEST(NEG, NAME)"
);
stat
.
execute
(
"CREATE INDEX IDX_NEG ON TEST(NEG, NAME)"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"INSERT INTO TEST(ID, NAME) VALUES(?, '1234567890')"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"INSERT INTO TEST(ID, NAME) VALUES(?, '1234567890')"
);
int
len
=
getSize
(
10
,
1000
);
int
len
=
getSize
(
10
,
1000
);
int
block
=
getSize
(
3
,
10
);
int
block
=
getSize
(
3
,
10
);
int
left
,
x
=
0
;
int
left
,
x
=
0
;
...
@@ -130,7 +148,8 @@ public class TestBigDb extends TestBase {
...
@@ -130,7 +148,8 @@ public class TestBigDb extends TestBase {
Connection
conn
=
getConnection
(
"bigDb"
);
Connection
conn
=
getConnection
(
"bigDb"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE TABLE TEST(ID IDENTITY, NAME VARCHAR)"
);
stat
.
execute
(
"CREATE TABLE TEST(ID IDENTITY, NAME VARCHAR)"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"INSERT INTO TEST(NAME) VALUES('Hello World')"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"INSERT INTO TEST(NAME) VALUES('Hello World')"
);
int
len
=
getSize
(
1000
,
10000
);
int
len
=
getSize
(
1000
,
10000
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
if
(
i
%
1000
==
0
)
{
if
(
i
%
1000
==
0
)
{
...
...
h2/src/test/org/h2/test/db/TestBigResult.java
浏览文件 @
b3836d31
...
@@ -53,7 +53,8 @@ public class TestBigResult extends TestBase {
...
@@ -53,7 +53,8 @@ public class TestBigResult extends TestBase {
stat
.
execute
(
"INSERT INTO RECOVERY "
+
stat
.
execute
(
"INSERT INTO RECOVERY "
+
"SELECT X, CASE MOD(X, 2) WHEN 0 THEN 'commit' ELSE 'begin' END "
+
"SELECT X, CASE MOD(X, 2) WHEN 0 THEN 'commit' ELSE 'begin' END "
+
"FROM SYSTEM_RANGE(1, "
+
len
+
")"
);
"FROM SYSTEM_RANGE(1, "
+
len
+
")"
);
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM RECOVERY WHERE SQL_STMT LIKE 'begin%' AND "
+
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM RECOVERY "
+
"WHERE SQL_STMT LIKE 'begin%' AND "
+
"TRANSACTION_ID NOT IN(SELECT TRANSACTION_ID FROM RECOVERY "
+
"TRANSACTION_ID NOT IN(SELECT TRANSACTION_ID FROM RECOVERY "
+
"WHERE SQL_STMT='commit' OR SQL_STMT='rollback')"
);
"WHERE SQL_STMT='commit' OR SQL_STMT='rollback')"
);
int
count
=
0
,
last
=
1
;
int
count
=
0
,
last
=
1
;
...
@@ -90,7 +91,8 @@ public class TestBigResult extends TestBase {
...
@@ -90,7 +91,8 @@ public class TestBigResult extends TestBase {
// rs.close();
// rs.close();
conn
.
close
();
conn
.
close
();
deleteDb
(
"bigResult"
);
deleteDb
(
"bigResult"
);
ArrayList
<
String
>
files
=
FileLister
.
getDatabaseFiles
(
getBaseDir
(),
"bigResult"
,
true
);
ArrayList
<
String
>
files
=
FileLister
.
getDatabaseFiles
(
getBaseDir
(),
"bigResult"
,
true
);
if
(
files
.
size
()
>
0
)
{
if
(
files
.
size
()
>
0
)
{
fail
(
"file not deleted: "
+
files
.
get
(
0
));
fail
(
"file not deleted: "
+
files
.
get
(
0
));
}
}
...
@@ -134,7 +136,8 @@ public class TestBigResult extends TestBase {
...
@@ -134,7 +136,8 @@ public class TestBigResult extends TestBase {
"Points INT,"
+
"Points INT,"
+
"LicenseID INT)"
);
"LicenseID INT)"
);
int
len
=
getSize
(
10
,
5000
);
int
len
=
getSize
(
10
,
5000
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"INSERT INTO TEST VALUES(?, ?, ?, ?, ?)"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"INSERT INTO TEST VALUES(?, ?, ?, ?, ?)"
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
prep
.
setInt
(
1
,
i
);
prep
.
setInt
(
1
,
i
);
prep
.
setString
(
2
,
"Name "
+
i
);
prep
.
setString
(
2
,
"Name "
+
i
);
...
@@ -185,7 +188,8 @@ public class TestBigResult extends TestBase {
...
@@ -185,7 +188,8 @@ public class TestBigResult extends TestBase {
prep
.
setString
(
2
,
""
+
i
/
200
);
prep
.
setString
(
2
,
""
+
i
/
200
);
prep
.
execute
();
prep
.
execute
();
}
}
Statement
s2
=
conn
.
createStatement
(
ResultSet
.
TYPE_SCROLL_INSENSITIVE
,
ResultSet
.
CONCUR_UPDATABLE
);
Statement
s2
=
conn
.
createStatement
(
ResultSet
.
TYPE_SCROLL_INSENSITIVE
,
ResultSet
.
CONCUR_UPDATABLE
);
rs
=
s2
.
executeQuery
(
"SELECT NAME FROM DATA"
);
rs
=
s2
.
executeQuery
(
"SELECT NAME FROM DATA"
);
rs
.
last
();
rs
.
last
();
conn
.
setAutoCommit
(
true
);
conn
.
setAutoCommit
(
true
);
...
...
h2/src/test/org/h2/test/db/TestCases.java
浏览文件 @
b3836d31
...
@@ -111,7 +111,8 @@ public class TestCases extends TestBase {
...
@@ -111,7 +111,8 @@ public class TestCases extends TestBase {
stat
.
execute
(
"create table a(id int, x int) as select 1, 100"
);
stat
.
execute
(
"create table a(id int, x int) as select 1, 100"
);
stat
.
execute
(
"create index idx1 on a(id, x)"
);
stat
.
execute
(
"create index idx1 on a(id, x)"
);
stat
.
execute
(
"create table b(id int primary key, a_id int) as select 1, 1"
);
stat
.
execute
(
"create table b(id int primary key, a_id int) as select 1, 1"
);
stat
.
execute
(
"alter table b add constraint x foreign key(a_id) references a(id)"
);
stat
.
execute
(
"alter table b add constraint x "
+
"foreign key(a_id) references a(id)"
);
stat
.
execute
(
"update a set x=200"
);
stat
.
execute
(
"update a set x=200"
);
stat
.
execute
(
"drop table if exists a, b"
);
stat
.
execute
(
"drop table if exists a, b"
);
conn
.
close
();
conn
.
close
();
...
@@ -190,7 +191,8 @@ public class TestCases extends TestBase {
...
@@ -190,7 +191,8 @@ public class TestCases extends TestBase {
stat
.
execute
(
"create table test(a int, b int)"
);
stat
.
execute
(
"create table test(a int, b int)"
);
stat
.
execute
(
"create index idx on test(a)"
);
stat
.
execute
(
"create index idx on test(a)"
);
stat
.
execute
(
"insert into test values (1, 9), (2, 9), (3, 9)"
);
stat
.
execute
(
"insert into test values (1, 9), (2, 9), (3, 9)"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select (select count(*) from test where a = t.a and b = 0) from test t group by a"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select (select count(*)"
+
" from test where a = t.a and b = 0) from test t group by a"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
0
,
rs
.
getInt
(
1
));
assertEquals
(
0
,
rs
.
getInt
(
1
));
conn
.
close
();
conn
.
close
();
...
@@ -200,7 +202,8 @@ public class TestCases extends TestBase {
...
@@ -200,7 +202,8 @@ public class TestCases extends TestBase {
deleteDb
(
"cases"
);
deleteDb
(
"cases"
);
Connection
conn
=
getConnection
(
"cases"
);
Connection
conn
=
getConnection
(
"cases"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int not null) as select 1 from system_range(1, 10)"
);
stat
.
execute
(
"create table test(id int not null) as "
+
"select 1 from system_range(1, 10)"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select count(distinct id) from test"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select count(distinct id) from test"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
1
,
rs
.
getInt
(
1
));
assertEquals
(
1
,
rs
.
getInt
(
1
));
...
@@ -214,13 +217,15 @@ public class TestCases extends TestBase {
...
@@ -214,13 +217,15 @@ public class TestCases extends TestBase {
// avoid endless recursion when adding dependencies
// avoid endless recursion when adding dependencies
stat
.
execute
(
"create table test(id int primary key, parent int)"
);
stat
.
execute
(
"create table test(id int primary key, parent int)"
);
stat
.
execute
(
"alter table test add constraint test check (select count(*) from test) < 10"
);
stat
.
execute
(
"alter table test add constraint test check "
+
"(select count(*) from test) < 10"
);
stat
.
execute
(
"create table b()"
);
stat
.
execute
(
"create table b()"
);
stat
.
execute
(
"drop table b"
);
stat
.
execute
(
"drop table b"
);
stat
.
execute
(
"drop table test"
);
stat
.
execute
(
"drop table test"
);
// ensure the dependency is detected
// ensure the dependency is detected
stat
.
execute
(
"create alias is_positive as 'boolean isPositive(int x) { return x > 0; }'"
);
stat
.
execute
(
"create alias is_positive as "
+
"'boolean isPositive(int x) { return x > 0; }'"
);
stat
.
execute
(
"create table a(a integer, constraint test check is_positive(a))"
);
stat
.
execute
(
"create table a(a integer, constraint test check is_positive(a))"
);
assertThrows
(
ErrorCode
.
CANNOT_DROP_2
,
stat
).
assertThrows
(
ErrorCode
.
CANNOT_DROP_2
,
stat
).
execute
(
"drop alias is_positive"
);
execute
(
"drop alias is_positive"
);
...
@@ -231,7 +236,8 @@ public class TestCases extends TestBase {
...
@@ -231,7 +236,8 @@ public class TestCases extends TestBase {
// (otherwise re-opening the database is not possible)
// (otherwise re-opening the database is not possible)
stat
.
execute
(
"create table test(id int primary key)"
);
stat
.
execute
(
"create table test(id int primary key)"
);
assertThrows
(
ErrorCode
.
COLUMN_IS_REFERENCED_1
,
stat
).
assertThrows
(
ErrorCode
.
COLUMN_IS_REFERENCED_1
,
stat
).
execute
(
"alter table test alter column id set default ifnull((select max(id) from test for update)+1, 0)"
);
execute
(
"alter table test alter column id "
+
"set default ifnull((select max(id) from test for update)+1, 0)"
);
stat
.
execute
(
"drop table test"
);
stat
.
execute
(
"drop table test"
);
conn
.
close
();
conn
.
close
();
}
}
...
@@ -261,13 +267,17 @@ public class TestCases extends TestBase {
...
@@ -261,13 +267,17 @@ public class TestCases extends TestBase {
private
void
testMaxMemoryRowsDistinct
()
throws
SQLException
{
private
void
testMaxMemoryRowsDistinct
()
throws
SQLException
{
deleteDb
(
"cases"
);
deleteDb
(
"cases"
);
Connection
conn
=
getConnection
(
"cases;max_memory_rows_distinct=1"
);
Connection
conn
=
getConnection
(
"cases;max_memory_rows_distinct=1"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int primary key)"
);
stat
.
execute
(
"create table test(id int primary key)"
);
stat
.
execute
(
"insert into test values(1), (2)"
);
stat
.
execute
(
"insert into test values(1), (2)"
);
stat
.
execute
(
"select * from dual where x not in (select id from test order by id)"
);
stat
.
execute
(
"select * from dual where x not in "
+
stat
.
execute
(
"select * from dual where x not in (select id from test union select id from test)"
);
"(select id from test order by id)"
);
stat
.
execute
(
"(select id from test order by id) intersect (select id from test order by id)"
);
stat
.
execute
(
"select * from dual where x not in "
+
"(select id from test union select id from test)"
);
stat
.
execute
(
"(select id from test order by id) "
+
"intersect (select id from test order by id)"
);
conn
.
close
();
conn
.
close
();
}
}
...
@@ -277,7 +287,8 @@ public class TestCases extends TestBase {
...
@@ -277,7 +287,8 @@ public class TestCases extends TestBase {
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id identity, name text)"
);
stat
.
execute
(
"create table test(id identity, name text)"
);
String
[]
data
=
{
"\uff1e"
,
"\ud848\udf1e"
};
String
[]
data
=
{
"\uff1e"
,
"\ud848\udf1e"
};
PreparedStatement
prep
=
conn
.
prepareStatement
(
"insert into test(name) values(?)"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"insert into test(name) values(?)"
);
for
(
int
i
=
0
;
i
<
data
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
data
.
length
;
i
++)
{
prep
.
setString
(
1
,
data
[
i
]);
prep
.
setString
(
1
,
data
[
i
]);
prep
.
execute
();
prep
.
execute
();
...
@@ -296,7 +307,8 @@ public class TestCases extends TestBase {
...
@@ -296,7 +307,8 @@ public class TestCases extends TestBase {
deleteDb
(
"cases"
);
deleteDb
(
"cases"
);
Connection
conn
=
getConnection
(
"cases"
);
Connection
conn
=
getConnection
(
"cases"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create alias is_email as 'boolean isEmail(String x) { return x != null && x.indexOf(''@'') > 0; }'"
);
stat
.
execute
(
"create alias is_email as "
+
"'boolean isEmail(String x) { return x != null && x.indexOf(''@'') > 0; }'"
);
stat
.
execute
(
"create domain email as varchar check is_email(value)"
);
stat
.
execute
(
"create domain email as varchar check is_email(value)"
);
stat
.
execute
(
"create table test(e email)"
);
stat
.
execute
(
"create table test(e email)"
);
conn
.
close
();
conn
.
close
();
...
@@ -310,7 +322,8 @@ public class TestCases extends TestBase {
...
@@ -310,7 +322,8 @@ public class TestCases extends TestBase {
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table parent(p int primary key) as select 1"
);
stat
.
execute
(
"create table parent(p int primary key) as select 1"
);
stat
.
execute
(
"create table child(c int primary key, pc int) as select 2, 1"
);
stat
.
execute
(
"create table child(c int primary key, pc int) as select 2, 1"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select * from parent left outer join child on p = pc where c is null"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select * from parent "
+
"left outer join child on p = pc where c is null"
);
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
stat
.
execute
(
"drop all objects"
);
stat
.
execute
(
"drop all objects"
);
conn
.
close
();
conn
.
close
();
...
@@ -322,8 +335,10 @@ public class TestCases extends TestBase {
...
@@ -322,8 +335,10 @@ public class TestCases extends TestBase {
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create schema cases"
);
stat
.
execute
(
"create schema cases"
);
stat
.
execute
(
"create table cases.cases(cases int)"
);
stat
.
execute
(
"create table cases.cases(cases int)"
);
stat
.
execute
(
"comment on column cases.cases.cases is 'schema.table.column'"
);
stat
.
execute
(
"comment on column "
+
stat
.
execute
(
"comment on column cases.cases.cases.cases is 'db.schema.table.column'"
);
"cases.cases.cases is 'schema.table.column'"
);
stat
.
execute
(
"comment on column "
+
"cases.cases.cases.cases is 'db.schema.table.column'"
);
conn
.
close
();
conn
.
close
();
}
}
...
@@ -346,7 +361,8 @@ public class TestCases extends TestBase {
...
@@ -346,7 +361,8 @@ public class TestCases extends TestBase {
Connection
conn
=
getConnection
(
"cases"
);
Connection
conn
=
getConnection
(
"cases"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table parent(id identity) as select 0"
);
stat
.
execute
(
"create table parent(id identity) as select 0"
);
stat
.
execute
(
"create table child(id identity, parent int references parent(id)) as select 0, 0"
);
stat
.
execute
(
"create table child(id identity, "
+
"parent int references parent(id)) as select 0, 0"
);
assertThrows
(
ErrorCode
.
CANNOT_TRUNCATE_1
,
stat
).
assertThrows
(
ErrorCode
.
CANNOT_TRUNCATE_1
,
stat
).
execute
(
"truncate table parent"
);
execute
(
"truncate table parent"
);
assertThrows
(
ErrorCode
.
REFERENTIAL_INTEGRITY_VIOLATED_CHILD_EXISTS_1
,
stat
).
assertThrows
(
ErrorCode
.
REFERENTIAL_INTEGRITY_VIOLATED_CHILD_EXISTS_1
,
stat
).
...
@@ -370,7 +386,9 @@ public class TestCases extends TestBase {
...
@@ -370,7 +386,9 @@ public class TestCases extends TestBase {
stat
.
execute
(
"insert into test values(1, 'Hello')"
);
stat
.
execute
(
"insert into test values(1, 'Hello')"
);
stat
.
execute
(
"insert into test values(2, 'World')"
);
stat
.
execute
(
"insert into test values(2, 'World')"
);
PreparedStatement
ps
=
conn
.
prepareStatement
(
"select name from test where id in (select id from test where name = ?)"
);
PreparedStatement
ps
=
conn
.
prepareStatement
(
"select name from test where id in "
+
"(select id from test where name = ?)"
);
ps
.
setString
(
1
,
"Hello"
);
ps
.
setString
(
1
,
"Hello"
);
ResultSet
rs
=
ps
.
executeQuery
();
ResultSet
rs
=
ps
.
executeQuery
();
if
(
rs
.
next
())
{
if
(
rs
.
next
())
{
...
@@ -460,8 +478,10 @@ public class TestCases extends TestBase {
...
@@ -460,8 +478,10 @@ public class TestCases extends TestBase {
deleteDb
(
"cases"
);
deleteDb
(
"cases"
);
Connection
conn
=
getConnection
(
"cases"
);
Connection
conn
=
getConnection
(
"cases"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE TABLE IF NOT EXISTS test (rowid INTEGER PRIMARY KEY AUTO_INCREMENT, txt VARCHAR(64000));"
);
stat
.
execute
(
"CREATE TABLE IF NOT EXISTS test "
+
PreparedStatement
prep
=
conn
.
prepareStatement
(
"insert into test (txt) values(space(?))"
);
"(rowid INTEGER PRIMARY KEY AUTO_INCREMENT, txt VARCHAR(64000));"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"insert into test (txt) values(space(?))"
);
for
(
int
i
=
0
;
i
<
3000
;
i
++)
{
for
(
int
i
=
0
;
i
<
3000
;
i
++)
{
prep
.
setInt
(
1
,
i
*
3
);
prep
.
setInt
(
1
,
i
*
3
);
prep
.
execute
();
prep
.
execute
();
...
@@ -507,10 +527,12 @@ public class TestCases extends TestBase {
...
@@ -507,10 +527,12 @@ public class TestCases extends TestBase {
conn
=
getConnection
(
"cases"
);
conn
=
getConnection
(
"cases"
);
conn
.
createStatement
().
execute
(
"set MAX_MEMORY_UNDO 1"
);
conn
.
createStatement
().
execute
(
"set MAX_MEMORY_UNDO 1"
);
conn
.
createStatement
().
execute
(
"create table test(id number primary key)"
);
conn
.
createStatement
().
execute
(
"create table test(id number primary key)"
);
conn
.
createStatement
().
execute
(
"insert into test(id) select x from system_range(1, 2)"
);
conn
.
createStatement
().
execute
(
"insert into test(id) select x from system_range(1, 2)"
);
Connection
conn2
=
getConnection
(
"cases"
);
Connection
conn2
=
getConnection
(
"cases"
);
conn2
.
setAutoCommit
(
false
);
conn2
.
setAutoCommit
(
false
);
assertEquals
(
2
,
conn2
.
createStatement
().
executeUpdate
(
"delete from test"
));
assertEquals
(
2
,
conn2
.
createStatement
().
executeUpdate
(
"delete from test"
));
conn2
.
close
();
conn2
.
close
();
conn
.
close
();
conn
.
close
();
...
@@ -519,7 +541,8 @@ public class TestCases extends TestBase {
...
@@ -519,7 +541,8 @@ public class TestCases extends TestBase {
conn
.
createStatement
().
execute
(
"set MAX_MEMORY_UNDO 8"
);
conn
.
createStatement
().
execute
(
"set MAX_MEMORY_UNDO 8"
);
conn
.
createStatement
().
execute
(
"create table test(id number primary key)"
);
conn
.
createStatement
().
execute
(
"create table test(id number primary key)"
);
conn
.
setAutoCommit
(
false
);
conn
.
setAutoCommit
(
false
);
conn
.
createStatement
().
execute
(
"insert into test select x from system_range(1, 10)"
);
conn
.
createStatement
().
execute
(
"insert into test select x from system_range(1, 10)"
);
conn
.
createStatement
().
execute
(
"delete from test"
);
conn
.
createStatement
().
execute
(
"delete from test"
);
conn
.
rollback
();
conn
.
rollback
();
conn
.
close
();
conn
.
close
();
...
@@ -542,7 +565,8 @@ public class TestCases extends TestBase {
...
@@ -542,7 +565,8 @@ public class TestCases extends TestBase {
Connection
conn
;
Connection
conn
;
conn
=
getConnection
(
"cases"
);
conn
=
getConnection
(
"cases"
);
conn
.
createStatement
().
execute
(
"CREATE TABLE test(id int PRIMARY KEY);"
);
conn
.
createStatement
().
execute
(
"CREATE TABLE test(id int PRIMARY KEY);"
);
conn
.
createStatement
().
execute
(
"INSERT INTO test SELECT X FROM SYSTEM_RANGE(1, 77)"
);
conn
.
createStatement
().
execute
(
"INSERT INTO test SELECT X FROM SYSTEM_RANGE(1, 77)"
);
conn
.
createStatement
().
execute
(
"DELETE from test"
);
conn
.
createStatement
().
execute
(
"DELETE from test"
);
conn
.
close
();
conn
.
close
();
conn
=
getConnection
(
"cases"
);
conn
=
getConnection
(
"cases"
);
...
@@ -573,14 +597,16 @@ public class TestCases extends TestBase {
...
@@ -573,14 +597,16 @@ public class TestCases extends TestBase {
Connection
conn
=
getConnection
(
"cases"
);
Connection
conn
=
getConnection
(
"cases"
);
String
key
=
"key"
;
String
key
=
"key"
;
String
value
=
"Hello World"
;
String
value
=
"Hello World"
;
PreparedStatement
prep
=
conn
.
prepareStatement
(
"CALL ENCRYPT('AES', RAWTOHEX(?), STRINGTOUTF8(?))"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"CALL ENCRYPT('AES', RAWTOHEX(?), STRINGTOUTF8(?))"
);
prep
.
setCharacterStream
(
1
,
new
StringReader
(
key
),
-
1
);
prep
.
setCharacterStream
(
1
,
new
StringReader
(
key
),
-
1
);
prep
.
setCharacterStream
(
2
,
new
StringReader
(
value
),
-
1
);
prep
.
setCharacterStream
(
2
,
new
StringReader
(
value
),
-
1
);
ResultSet
rs
=
prep
.
executeQuery
();
ResultSet
rs
=
prep
.
executeQuery
();
rs
.
next
();
rs
.
next
();
String
encrypted
=
rs
.
getString
(
1
);
String
encrypted
=
rs
.
getString
(
1
);
PreparedStatement
prep2
=
conn
PreparedStatement
prep2
=
conn
.
prepareStatement
(
.
prepareStatement
(
"CALL TRIM(CHAR(0) FROM UTF8TOSTRING(DECRYPT('AES', RAWTOHEX(?), ?)))"
);
"CALL TRIM(CHAR(0) FROM "
+
"UTF8TOSTRING(DECRYPT('AES', RAWTOHEX(?), ?)))"
);
prep2
.
setCharacterStream
(
1
,
new
StringReader
(
key
),
-
1
);
prep2
.
setCharacterStream
(
1
,
new
StringReader
(
key
),
-
1
);
prep2
.
setCharacterStream
(
2
,
new
StringReader
(
encrypted
),
-
1
);
prep2
.
setCharacterStream
(
2
,
new
StringReader
(
encrypted
),
-
1
);
ResultSet
rs2
=
prep2
.
executeQuery
();
ResultSet
rs2
=
prep2
.
executeQuery
();
...
@@ -611,7 +637,8 @@ public class TestCases extends TestBase {
...
@@ -611,7 +637,8 @@ public class TestCases extends TestBase {
if
(
config
.
memory
)
{
if
(
config
.
memory
)
{
return
;
return
;
}
}
assertThrows
(
ErrorCode
.
INVALID_DATABASE_NAME_1
,
this
).
getConnection
(
"cases/"
);
assertThrows
(
ErrorCode
.
INVALID_DATABASE_NAME_1
,
this
).
getConnection
(
"cases/"
);
}
}
private
void
testReuseSpace
()
throws
SQLException
{
private
void
testReuseSpace
()
throws
SQLException
{
...
@@ -646,7 +673,8 @@ public class TestCases extends TestBase {
...
@@ -646,7 +673,8 @@ public class TestCases extends TestBase {
stat
.
execute
(
"set max_memory_rows 2"
);
stat
.
execute
(
"set max_memory_rows 2"
);
stat
.
execute
(
"create table test(id int primary key, x int)"
);
stat
.
execute
(
"create table test(id int primary key, x int)"
);
stat
.
execute
(
"insert into test values(0, 0), (1, 1), (2, 2)"
);
stat
.
execute
(
"insert into test values(0, 0), (1, 1), (2, 2)"
);
stat
.
execute
(
"delete from test where id not in (select min(x) from test group by id)"
);
stat
.
execute
(
"delete from test where id not in "
+
"(select min(x) from test group by id)"
);
conn
.
close
();
conn
.
close
();
}
}
...
@@ -655,23 +683,40 @@ public class TestCases extends TestBase {
...
@@ -655,23 +683,40 @@ public class TestCases extends TestBase {
Connection
conn
=
getConnection
(
"cases"
);
Connection
conn
=
getConnection
(
"cases"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
assertThrows
(
ErrorCode
.
SYNTAX_ERROR_2
,
stat
).
assertThrows
(
ErrorCode
.
SYNTAX_ERROR_2
,
stat
).
execute
(
"create table address(id identity, name varchar check? instr(value, '@') > 1)"
);
execute
(
"create table address"
+
stat
.
execute
(
"SET AUTOCOMMIT OFF; \n//create sequence if not exists object_id;\n"
);
"(id identity, name varchar check? instr(value, '@') > 1)"
);
stat
.
execute
(
"SET AUTOCOMMIT OFF;\n//create sequence if not exists object_id;\n"
);
stat
.
execute
(
"SET AUTOCOMMIT OFF; \n//"
+
stat
.
execute
(
"SET AUTOCOMMIT OFF; //create sequence if not exists object_id;"
);
"create sequence if not exists object_id;\n"
);
stat
.
execute
(
"SET AUTOCOMMIT OFF;//create sequence if not exists object_id;"
);
stat
.
execute
(
"SET AUTOCOMMIT OFF;\n//"
+
stat
.
execute
(
"SET AUTOCOMMIT OFF \n//create sequence if not exists object_id;"
);
"create sequence if not exists object_id;\n"
);
stat
.
execute
(
"SET AUTOCOMMIT OFF\n//create sequence if not exists object_id;"
);
stat
.
execute
(
"SET AUTOCOMMIT OFF; //"
+
stat
.
execute
(
"SET AUTOCOMMIT OFF //create sequence if not exists object_id;"
);
"create sequence if not exists object_id;"
);
stat
.
execute
(
"SET AUTOCOMMIT OFF//create sequence if not exists object_id;"
);
stat
.
execute
(
"SET AUTOCOMMIT OFF;//"
+
stat
.
execute
(
"SET AUTOCOMMIT OFF; \n///create sequence if not exists object_id;"
);
"create sequence if not exists object_id;"
);
stat
.
execute
(
"SET AUTOCOMMIT OFF;\n///create sequence if not exists object_id;"
);
stat
.
execute
(
"SET AUTOCOMMIT OFF \n//"
+
stat
.
execute
(
"SET AUTOCOMMIT OFF; ///create sequence if not exists object_id;"
);
"create sequence if not exists object_id;"
);
stat
.
execute
(
"SET AUTOCOMMIT OFF;///create sequence if not exists object_id;"
);
stat
.
execute
(
"SET AUTOCOMMIT OFF\n//"
+
stat
.
execute
(
"SET AUTOCOMMIT OFF \n///create sequence if not exists object_id;"
);
"create sequence if not exists object_id;"
);
stat
.
execute
(
"SET AUTOCOMMIT OFF\n///create sequence if not exists object_id;"
);
stat
.
execute
(
"SET AUTOCOMMIT OFF //"
+
stat
.
execute
(
"SET AUTOCOMMIT OFF ///create sequence if not exists object_id;"
);
"create sequence if not exists object_id;"
);
stat
.
execute
(
"SET AUTOCOMMIT OFF///create sequence if not exists object_id;"
);
stat
.
execute
(
"SET AUTOCOMMIT OFF//"
+
"create sequence if not exists object_id;"
);
stat
.
execute
(
"SET AUTOCOMMIT OFF; \n///"
+
"create sequence if not exists object_id;"
);
stat
.
execute
(
"SET AUTOCOMMIT OFF;\n///"
+
"create sequence if not exists object_id;"
);
stat
.
execute
(
"SET AUTOCOMMIT OFF; ///"
+
"create sequence if not exists object_id;"
);
stat
.
execute
(
"SET AUTOCOMMIT OFF;///"
+
"create sequence if not exists object_id;"
);
stat
.
execute
(
"SET AUTOCOMMIT OFF \n///"
+
"create sequence if not exists object_id;"
);
stat
.
execute
(
"SET AUTOCOMMIT OFF\n///"
+
"create sequence if not exists object_id;"
);
stat
.
execute
(
"SET AUTOCOMMIT OFF ///"
+
"create sequence if not exists object_id;"
);
stat
.
execute
(
"SET AUTOCOMMIT OFF///"
+
"create sequence if not exists object_id;"
);
conn
.
close
();
conn
.
close
();
}
}
...
@@ -732,7 +777,8 @@ public class TestCases extends TestBase {
...
@@ -732,7 +777,8 @@ public class TestCases extends TestBase {
stat
.
execute
(
"create table s.test(id identity)"
);
stat
.
execute
(
"create table s.test(id identity)"
);
conn
.
close
();
conn
.
close
();
conn
=
getConnection
(
"cases"
);
conn
=
getConnection
(
"cases"
);
ResultSet
rs
=
conn
.
createStatement
().
executeQuery
(
"SELECT * FROM S.TEST"
);
ResultSet
rs
=
conn
.
createStatement
().
executeQuery
(
"SELECT * FROM S.TEST"
);
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
// ignore
// ignore
}
}
...
@@ -756,11 +802,13 @@ public class TestCases extends TestBase {
...
@@ -756,11 +802,13 @@ public class TestCases extends TestBase {
public
void
run
()
{
public
void
run
()
{
try
{
try
{
long
time
=
System
.
currentTimeMillis
();
long
time
=
System
.
currentTimeMillis
();
ResultSet
rs
=
stat
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT MAX(T.ID) "
+
.
executeQuery
(
"SELECT MAX(T.ID) FROM TEST T, TEST, TEST, TEST, TEST, TEST, TEST, TEST, TEST, TEST, TEST"
);
"FROM TEST T, TEST, TEST, TEST, TEST, "
+
"TEST, TEST, TEST, TEST, TEST, TEST"
);
rs
.
next
();
rs
.
next
();
time
=
System
.
currentTimeMillis
()
-
time
;
time
=
System
.
currentTimeMillis
()
-
time
;
TestBase
.
logError
(
"query was too quick; result: "
+
rs
.
getInt
(
1
)
+
" time:"
+
time
,
null
);
TestBase
.
logError
(
"query was too quick; result: "
+
rs
.
getInt
(
1
)
+
" time:"
+
time
,
null
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
stopped
[
0
]
=
e
;
stopped
[
0
]
=
e
;
// ok
// ok
...
@@ -790,12 +838,14 @@ public class TestCases extends TestBase {
...
@@ -790,12 +838,14 @@ public class TestCases extends TestBase {
deleteDb
(
"cases"
);
deleteDb
(
"cases"
);
Connection
conn
=
getConnection
(
"cases"
);
Connection
conn
=
getConnection
(
"cases"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT ? FROM DUAL {1: 'Hello'}"
);
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT ? FROM DUAL {1: 'Hello'}"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
"Hello"
,
rs
.
getString
(
1
));
assertEquals
(
"Hello"
,
rs
.
getString
(
1
));
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
rs
=
stat
.
executeQuery
(
"SELECT ? FROM DUAL UNION ALL SELECT ? FROM DUAL {1: 'Hello', 2:'World' }"
);
rs
=
stat
.
executeQuery
(
"SELECT ? FROM DUAL UNION ALL "
+
"SELECT ? FROM DUAL {1: 'Hello', 2:'World' }"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
"Hello"
,
rs
.
getString
(
1
));
assertEquals
(
"Hello"
,
rs
.
getString
(
1
));
rs
.
next
();
rs
.
next
();
...
@@ -815,7 +865,8 @@ public class TestCases extends TestBase {
...
@@ -815,7 +865,8 @@ public class TestCases extends TestBase {
execute
(
"alter table test add column name varchar not null;"
);
execute
(
"alter table test add column name varchar not null;"
);
conn
.
close
();
conn
.
close
();
conn
=
getConnection
(
"cases"
);
conn
=
getConnection
(
"cases"
);
ResultSet
rs
=
conn
.
createStatement
().
executeQuery
(
"SELECT * FROM TEST"
);
ResultSet
rs
=
conn
.
createStatement
().
executeQuery
(
"SELECT * FROM TEST"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
"1"
,
rs
.
getString
(
1
));
assertEquals
(
"1"
,
rs
.
getString
(
1
));
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
...
@@ -850,8 +901,10 @@ public class TestCases extends TestBase {
...
@@ -850,8 +901,10 @@ public class TestCases extends TestBase {
Connection
conn
=
getConnection
(
"cases"
);
Connection
conn
=
getConnection
(
"cases"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"SET COLLATION ENGLISH STRENGTH PRIMARY"
);
stat
.
execute
(
"SET COLLATION ENGLISH STRENGTH PRIMARY"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, "
+
stat
.
execute
(
"INSERT INTO TEST VALUES(1, 'Hello'), (2, 'World'), (3, 'WORLD'), (4, 'HELLO')"
);
"NAME VARCHAR(255))"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(1, 'Hello'), "
+
"(2, 'World'), (3, 'WORLD'), (4, 'HELLO')"
);
stat
.
execute
(
"create index idxname on test(name)"
);
stat
.
execute
(
"create index idxname on test(name)"
);
ResultSet
rs
;
ResultSet
rs
;
rs
=
stat
.
executeQuery
(
"select name from test order by name"
);
rs
=
stat
.
executeQuery
(
"select name from test order by name"
);
...
@@ -913,13 +966,16 @@ public class TestCases extends TestBase {
...
@@ -913,13 +966,16 @@ public class TestCases extends TestBase {
Connection
conn
=
getConnection
(
"cases"
);
Connection
conn
=
getConnection
(
"cases"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"SET COLLATION de_DE"
);
stat
.
execute
(
"SET COLLATION de_DE"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, "
+
"NAME VARCHAR)"
);
stat
.
execute
(
"CREATE INDEX IDXNAME ON TEST(NAME)"
);
stat
.
execute
(
"CREATE INDEX IDXNAME ON TEST(NAME)"
);
// \u00f6 = oe
// \u00f6 = oe
stat
.
execute
(
"INSERT INTO TEST VALUES(1, 'B\u00f6hlen'), (2, 'Bach'), (3, 'Bucher')"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(1, 'B\u00f6hlen'), "
+
"(2, 'Bach'), (3, 'Bucher')"
);
conn
.
close
();
conn
.
close
();
conn
=
getConnection
(
"cases"
);
conn
=
getConnection
(
"cases"
);
ResultSet
rs
=
conn
.
createStatement
().
executeQuery
(
"SELECT NAME FROM TEST ORDER BY NAME"
);
ResultSet
rs
=
conn
.
createStatement
().
executeQuery
(
"SELECT NAME FROM TEST ORDER BY NAME"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
"Bach"
,
rs
.
getString
(
1
));
assertEquals
(
"Bach"
,
rs
.
getString
(
1
));
rs
.
next
();
rs
.
next
();
...
@@ -933,10 +989,13 @@ public class TestCases extends TestBase {
...
@@ -933,10 +989,13 @@ public class TestCases extends TestBase {
deleteDb
(
"cases"
);
deleteDb
(
"cases"
);
Connection
conn
=
getConnection
(
"cases"
);
Connection
conn
=
getConnection
(
"cases"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE TABLE TEST(ORDER_ID INT PRIMARY KEY, ORDER_DATE DATETIME, "
+
stat
.
execute
(
"CREATE TABLE TEST(ORDER_ID INT PRIMARY KEY, "
+
"USER_ID INT, DESCRIPTION VARCHAR, STATE VARCHAR, TRACKING_ID VARCHAR)"
);
"ORDER_DATE DATETIME, "
+
"USER_ID INT, DESCRIPTION VARCHAR, STATE VARCHAR, "
+
"TRACKING_ID VARCHAR)"
);
Timestamp
orderDate
=
Timestamp
.
valueOf
(
"2005-05-21 17:46:00"
);
Timestamp
orderDate
=
Timestamp
.
valueOf
(
"2005-05-21 17:46:00"
);
String
sql
=
"insert into TEST (ORDER_ID,ORDER_DATE,USER_ID,DESCRIPTION,STATE,TRACKING_ID) "
+
String
sql
=
"insert into TEST (ORDER_ID,ORDER_DATE,"
+
"USER_ID,DESCRIPTION,STATE,TRACKING_ID) "
+
"select cast(? as int),cast(? as date),cast(? as int),cast(? as varchar),"
+
"select cast(? as int),cast(? as date),cast(? as int),cast(? as varchar),"
+
"cast(? as varchar),cast(? as varchar) union all select ?,?,?,?,?,?"
;
"cast(? as varchar),cast(? as varchar) union all select ?,?,?,?,?,?"
;
PreparedStatement
ps
=
conn
.
prepareStatement
(
sql
);
PreparedStatement
ps
=
conn
.
prepareStatement
(
sql
);
...
@@ -980,7 +1039,8 @@ public class TestCases extends TestBase {
...
@@ -980,7 +1039,8 @@ public class TestCases extends TestBase {
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table parent(id int)"
);
stat
.
execute
(
"create table parent(id int)"
);
stat
.
execute
(
"insert into parent values(1)"
);
stat
.
execute
(
"insert into parent values(1)"
);
stat
.
execute
(
"create table test(id int default (select max(id) from parent), name varchar)"
);
stat
.
execute
(
"create table test(id int default "
+
"(select max(id) from parent), name varchar)"
);
conn
.
close
();
conn
.
close
();
conn
=
getConnection
(
"cases"
);
conn
=
getConnection
(
"cases"
);
...
@@ -1002,7 +1062,8 @@ public class TestCases extends TestBase {
...
@@ -1002,7 +1062,8 @@ public class TestCases extends TestBase {
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"DROP TABLE IF EXISTS TEST"
);
stat
.
execute
(
"DROP TABLE IF EXISTS TEST"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT, TEXT VARCHAR, TEXT_C CLOB)"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT, TEXT VARCHAR, TEXT_C CLOB)"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"INSERT INTO TEST VALUES(?, ?, ?)"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"INSERT INTO TEST VALUES(?, ?, ?)"
);
int
len
=
getSize
(
1000
,
66000
);
int
len
=
getSize
(
1000
,
66000
);
char
[]
buff
=
new
char
[
len
];
char
[]
buff
=
new
char
[
len
];
...
@@ -1055,7 +1116,8 @@ public class TestCases extends TestBase {
...
@@ -1055,7 +1116,8 @@ public class TestCases extends TestBase {
stat
.
execute
(
"drop table if exists parent"
);
stat
.
execute
(
"drop table if exists parent"
);
stat
.
execute
(
"drop table if exists child"
);
stat
.
execute
(
"drop table if exists child"
);
stat
.
execute
(
"create table parent(id int)"
);
stat
.
execute
(
"create table parent(id int)"
);
stat
.
execute
(
"create table child(c_id int, p_id int, foreign key(p_id) references parent(id))"
);
stat
.
execute
(
"create table child(c_id int, p_id int, "
+
"foreign key(p_id) references parent(id))"
);
stat
.
execute
(
"insert into parent values(1), (2)"
);
stat
.
execute
(
"insert into parent values(1), (2)"
);
stat
.
execute
(
"insert into child values(1, 1)"
);
stat
.
execute
(
"insert into child values(1, 1)"
);
stat
.
execute
(
"insert into child values(2, 2)"
);
stat
.
execute
(
"insert into child values(2, 2)"
);
...
@@ -1076,7 +1138,8 @@ public class TestCases extends TestBase {
...
@@ -1076,7 +1138,8 @@ public class TestCases extends TestBase {
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"SET WRITE_DELAY 0"
);
stat
.
execute
(
"SET WRITE_DELAY 0"
);
stat
.
execute
(
"DROP TABLE IF EXISTS TEST"
);
stat
.
execute
(
"DROP TABLE IF EXISTS TEST"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))"
);
stat
.
execute
(
"CREATE TABLE TEST"
+
"(ID INT PRIMARY KEY, NAME VARCHAR(255))"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(1, 'Hello')"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(1, 'Hello')"
);
conn
.
setAutoCommit
(
false
);
conn
.
setAutoCommit
(
false
);
stat
.
execute
(
"INSERT INTO TEST VALUES(2, 'World')"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(2, 'World')"
);
...
@@ -1104,10 +1167,13 @@ public class TestCases extends TestBase {
...
@@ -1104,10 +1167,13 @@ public class TestCases extends TestBase {
trace
(
"testRenameReconnect"
);
trace
(
"testRenameReconnect"
);
deleteDb
(
"cases"
);
deleteDb
(
"cases"
);
Connection
conn
=
getConnection
(
"cases"
);
Connection
conn
=
getConnection
(
"cases"
);
conn
.
createStatement
().
execute
(
"CREATE TABLE TEST_SEQ(ID INT IDENTITY, NAME VARCHAR(255))"
);
conn
.
createStatement
().
execute
(
"CREATE TABLE TEST_SEQ"
+
conn
.
createStatement
().
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY)"
);
"(ID INT IDENTITY, NAME VARCHAR(255))"
);
conn
.
createStatement
().
execute
(
"CREATE TABLE TEST"
+
"(ID INT PRIMARY KEY)"
);
conn
.
createStatement
().
execute
(
"ALTER TABLE TEST RENAME TO TEST2"
);
conn
.
createStatement
().
execute
(
"ALTER TABLE TEST RENAME TO TEST2"
);
conn
.
createStatement
().
execute
(
"CREATE TABLE TEST_B(ID INT PRIMARY KEY, NAME VARCHAR, UNIQUE(NAME))"
);
conn
.
createStatement
().
execute
(
"CREATE TABLE TEST_B"
+
"(ID INT PRIMARY KEY, NAME VARCHAR, UNIQUE(NAME))"
);
conn
.
close
();
conn
.
close
();
conn
=
getConnection
(
"cases"
);
conn
=
getConnection
(
"cases"
);
conn
.
createStatement
().
execute
(
"INSERT INTO TEST_SEQ(NAME) VALUES('Hi')"
);
conn
.
createStatement
().
execute
(
"INSERT INTO TEST_SEQ(NAME) VALUES('Hi')"
);
...
@@ -1120,7 +1186,8 @@ public class TestCases extends TestBase {
...
@@ -1120,7 +1186,8 @@ public class TestCases extends TestBase {
conn
.
close
();
conn
.
close
();
conn
=
getConnection
(
"cases"
);
conn
=
getConnection
(
"cases"
);
conn
.
createStatement
().
execute
(
"SELECT * FROM TEST_B2"
);
conn
.
createStatement
().
execute
(
"SELECT * FROM TEST_B2"
);
conn
.
createStatement
().
execute
(
"INSERT INTO TEST_SEQ(NAME) VALUES('World')"
);
conn
.
createStatement
().
execute
(
"INSERT INTO TEST_SEQ(NAME) VALUES('World')"
);
rs
=
conn
.
createStatement
().
executeQuery
(
"CALL IDENTITY()"
);
rs
=
conn
.
createStatement
().
executeQuery
(
"CALL IDENTITY()"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
2
,
rs
.
getInt
(
1
));
assertEquals
(
2
,
rs
.
getInt
(
1
));
...
@@ -1184,8 +1251,10 @@ public class TestCases extends TestBase {
...
@@ -1184,8 +1251,10 @@ public class TestCases extends TestBase {
Connection
conn
=
getConnection
(
"cases"
);
Connection
conn
=
getConnection
(
"cases"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE TABLE TEST(ID INT, D DATE, T TIME, TS TIMESTAMP)"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT, D DATE, T TIME, TS TIMESTAMP)"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(1, '2001-01-01', '20:00:00', '2002-02-02 22:22:22.2')"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(1, '2001-01-01', "
+
stat
.
execute
(
"INSERT INTO TEST VALUES(1, '2001-01-01', '20:00:00', '2002-02-02 22:22:22.2')"
);
"'20:00:00', '2002-02-02 22:22:22.2')"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(1, '2001-01-01', "
+
"'20:00:00', '2002-02-02 22:22:22.2')"
);
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM TEST"
);
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM TEST"
);
rs
.
next
();
rs
.
next
();
Date
d1
=
rs
.
getDate
(
"D"
);
Date
d1
=
rs
.
getDate
(
"D"
);
...
@@ -1210,9 +1279,11 @@ public class TestCases extends TestBase {
...
@@ -1210,9 +1279,11 @@ public class TestCases extends TestBase {
deleteDb
(
"cases"
);
deleteDb
(
"cases"
);
Connection
conn
=
getConnection
(
"cases"
);
Connection
conn
=
getConnection
(
"cases"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table employee(id int, firstName VARCHAR(50), salary decimal(10, 2), "
stat
.
execute
(
"create table employee(id int, firstName VARCHAR(50), "
+
"salary decimal(10, 2), "
+
"superior_id int, CONSTRAINT PK_employee PRIMARY KEY (id), "
+
"superior_id int, CONSTRAINT PK_employee PRIMARY KEY (id), "
+
"CONSTRAINT FK_superior FOREIGN KEY (superior_id) REFERENCES employee(ID))"
);
+
"CONSTRAINT FK_superior FOREIGN KEY (superior_id) "
+
"REFERENCES employee(ID))"
);
stat
.
execute
(
"DROP TABLE employee"
);
stat
.
execute
(
"DROP TABLE employee"
);
conn
.
close
();
conn
.
close
();
conn
=
getConnection
(
"cases"
);
conn
=
getConnection
(
"cases"
);
...
@@ -1264,16 +1335,18 @@ public class TestCases extends TestBase {
...
@@ -1264,16 +1335,18 @@ public class TestCases extends TestBase {
c0
=
getConnection
(
"cases"
);
c0
=
getConnection
(
"cases"
);
c0
.
createStatement
().
executeUpdate
(
"SET AUTOCOMMIT FALSE"
);
c0
.
createStatement
().
executeUpdate
(
"SET AUTOCOMMIT FALSE"
);
c0
.
createStatement
().
executeUpdate
(
"drop table australia"
);
c0
.
createStatement
().
executeUpdate
(
"drop table australia"
);
c0
.
createStatement
().
executeUpdate
(
c0
.
createStatement
().
executeUpdate
(
"create table australia "
+
"create table australia (ID INTEGER NOT NULL, Name VARCHAR(100), "
"(ID INTEGER NOT NULL, Name VARCHAR(100), "
+
+
"firstName VARCHAR(100), Points INTEGER, LicenseID INTEGER, PRIMARY KEY(ID))"
);
"firstName VARCHAR(100), Points INTEGER, "
+
"LicenseID INTEGER, PRIMARY KEY(ID))"
);
c0
.
createStatement
().
executeUpdate
(
"COMMIT"
);
c0
.
createStatement
().
executeUpdate
(
"COMMIT"
);
c0
.
close
();
c0
.
close
();
c0
=
getConnection
(
"cases"
);
c0
=
getConnection
(
"cases"
);
c0
.
createStatement
().
executeUpdate
(
"SET AUTOCOMMIT FALSE"
);
c0
.
createStatement
().
executeUpdate
(
"SET AUTOCOMMIT FALSE"
);
PreparedStatement
p65
=
c0
.
prepareStatement
(
"insert into australia"
PreparedStatement
p65
=
c0
.
prepareStatement
(
+
"(id, Name, FirstName, Points, LicenseID) values (?, ?, ?, ?, ?)"
);
"insert into australia"
+
"(id, Name, FirstName, Points, LicenseID) values (?, ?, ?, ?, ?)"
);
len
=
getSize
(
1
,
1000
);
len
=
getSize
(
1
,
1000
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
p65
.
setInt
(
1
,
i
);
p65
.
setInt
(
1
,
i
);
...
@@ -1297,10 +1370,12 @@ public class TestCases extends TestBase {
...
@@ -1297,10 +1370,12 @@ public class TestCases extends TestBase {
deleteDb
(
"cases"
);
deleteDb
(
"cases"
);
Connection
c0
=
getConnection
(
"cases"
);
Connection
c0
=
getConnection
(
"cases"
);
c0
.
createStatement
().
executeUpdate
(
"create table test (ID int PRIMARY KEY)"
);
c0
.
createStatement
().
executeUpdate
(
"create table test (ID int PRIMARY KEY)"
);
c0
.
createStatement
().
executeUpdate
(
"insert into test values(1)"
);
c0
.
createStatement
().
executeUpdate
(
"insert into test values(1)"
);
c0
.
createStatement
().
executeUpdate
(
"drop table test"
);
c0
.
createStatement
().
executeUpdate
(
"drop table test"
);
c0
.
createStatement
().
executeUpdate
(
"create table test (ID int PRIMARY KEY)"
);
c0
.
createStatement
().
executeUpdate
(
"create table test (ID int PRIMARY KEY)"
);
c0
.
close
();
c0
.
close
();
c0
=
getConnection
(
"cases"
);
c0
=
getConnection
(
"cases"
);
...
@@ -1316,8 +1391,10 @@ public class TestCases extends TestBase {
...
@@ -1316,8 +1391,10 @@ public class TestCases extends TestBase {
Connection
conn
=
getConnection
(
"cases"
);
Connection
conn
=
getConnection
(
"cases"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table master(id number primary key, name varchar2(30));"
);
stat
.
execute
(
"create table master"
+
stat
.
execute
(
"create table detail(id number references master(id), location varchar2(30));"
);
"(id number primary key, name varchar2(30));"
);
stat
.
execute
(
"create table detail"
+
"(id number references master(id), location varchar2(30));"
);
stat
.
execute
(
"Insert into master values(1,'a'), (2,'b'), (3,'c');"
);
stat
.
execute
(
"Insert into master values(1,'a'), (2,'b'), (3,'c');"
);
stat
.
execute
(
"Insert into detail values(1,'a'), (2,'b'), (3,'c');"
);
stat
.
execute
(
"Insert into detail values(1,'a'), (2,'b'), (3,'c');"
);
...
@@ -1337,14 +1414,16 @@ public class TestCases extends TestBase {
...
@@ -1337,14 +1414,16 @@ public class TestCases extends TestBase {
conn
.
close
();
conn
.
close
();
}
}
private
void
testDeleteAndDropTableWithLobs
(
boolean
useDrop
)
throws
SQLException
{
private
void
testDeleteAndDropTableWithLobs
(
boolean
useDrop
)
throws
SQLException
{
deleteDb
(
"cases"
);
deleteDb
(
"cases"
);
Connection
conn
=
getConnection
(
"cases"
);
Connection
conn
=
getConnection
(
"cases"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE TABLE TEST(id int, content BLOB)"
);
stat
.
execute
(
"CREATE TABLE TEST(id int, content BLOB)"
);
stat
.
execute
(
"set MAX_LENGTH_INPLACE_LOB 1"
);
stat
.
execute
(
"set MAX_LENGTH_INPLACE_LOB 1"
);
PreparedStatement
prepared
=
conn
.
prepareStatement
(
"INSERT INTO TEST VALUES(?, ?)"
);
PreparedStatement
prepared
=
conn
.
prepareStatement
(
"INSERT INTO TEST VALUES(?, ?)"
);
byte
[]
blobContent
=
"BLOB_CONTENT"
.
getBytes
();
byte
[]
blobContent
=
"BLOB_CONTENT"
.
getBytes
();
prepared
.
setInt
(
1
,
1
);
prepared
.
setInt
(
1
,
1
);
prepared
.
setBytes
(
2
,
blobContent
);
prepared
.
setBytes
(
2
,
blobContent
);
...
@@ -1358,7 +1437,8 @@ public class TestCases extends TestBase {
...
@@ -1358,7 +1437,8 @@ public class TestCases extends TestBase {
conn
.
close
();
conn
.
close
();
List
<
String
>
list
=
FileUtils
.
newDirectoryStream
(
getBaseDir
()
+
"/cases.lobs.db"
);
List
<
String
>
list
=
FileUtils
.
newDirectoryStream
(
getBaseDir
()
+
"/cases.lobs.db"
);
assertEquals
(
"Lob file was not deleted: "
+
list
,
0
,
list
.
size
());
assertEquals
(
"Lob file was not deleted: "
+
list
,
0
,
list
.
size
());
}
}
...
@@ -1367,7 +1447,8 @@ public class TestCases extends TestBase {
...
@@ -1367,7 +1447,8 @@ public class TestCases extends TestBase {
Connection
conn
=
getConnection
(
"cases"
);
Connection
conn
=
getConnection
(
"cases"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE TABLE TEST(id int) AS SELECT x FROM system_range(1, 100)"
);
stat
.
execute
(
"CREATE TABLE TEST(id int) AS "
+
"SELECT x FROM system_range(1, 100)"
);
stat
.
execute
(
"DELETE TOP 10 FROM TEST"
);
stat
.
execute
(
"DELETE TOP 10 FROM TEST"
);
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT COUNT(*) FROM TEST"
);
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT COUNT(*) FROM TEST"
);
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
next
());
...
@@ -1378,7 +1459,8 @@ public class TestCases extends TestBase {
...
@@ -1378,7 +1459,8 @@ public class TestCases extends TestBase {
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
next
());
assertEquals
(
81
,
rs
.
getInt
(
1
));
assertEquals
(
81
,
rs
.
getInt
(
1
));
rs
=
stat
.
executeQuery
(
"EXPLAIN DELETE FROM TEST LIMIT ((SELECT COUNT(*) FROM TEST) / 10)"
);
rs
=
stat
.
executeQuery
(
"EXPLAIN DELETE "
+
"FROM TEST LIMIT ((SELECT COUNT(*) FROM TEST) / 10)"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
"DELETE FROM PUBLIC.TEST\n"
+
assertEquals
(
"DELETE FROM PUBLIC.TEST\n"
+
" /* PUBLIC.TEST.tableScan */\n"
+
" /* PUBLIC.TEST.tableScan */\n"
+
...
...
h2/src/test/org/h2/test/db/TestCluster.java
浏览文件 @
b3836d31
...
@@ -58,7 +58,8 @@ public class TestCluster extends TestBase {
...
@@ -58,7 +58,8 @@ public class TestCluster extends TestBase {
Statement
stat
;
Statement
stat
;
String
url1
=
getURL
(
"jdbc:h2:tcp://localhost:"
+
port1
+
"/test"
,
false
);
String
url1
=
getURL
(
"jdbc:h2:tcp://localhost:"
+
port1
+
"/test"
,
false
);
Server
n1
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
port1
,
"-baseDir"
,
getBaseDir
()
+
"/node1"
).
start
();
Server
n1
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
port1
,
"-baseDir"
,
getBaseDir
()
+
"/node1"
).
start
();
conn
=
getConnection
(
url1
,
user
,
password
);
conn
=
getConnection
(
url1
,
user
,
password
);
stat
=
conn
.
createStatement
();
stat
=
conn
.
createStatement
();
...
@@ -67,10 +68,12 @@ public class TestCluster extends TestBase {
...
@@ -67,10 +68,12 @@ public class TestCluster extends TestBase {
conn
.
close
();
conn
.
close
();
String
url2
=
getURL
(
"jdbc:h2:tcp://localhost:"
+
port2
+
"/test"
,
false
);
String
url2
=
getURL
(
"jdbc:h2:tcp://localhost:"
+
port2
+
"/test"
,
false
);
Server
n2
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
port2
,
"-baseDir"
,
getBaseDir
()
+
"/node2"
).
start
();
Server
n2
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
port2
,
"-baseDir"
,
getBaseDir
()
+
"/node2"
).
start
();
String
urlCluster
=
getURL
(
"jdbc:h2:tcp://"
+
serverList
+
"/test"
,
true
);
String
urlCluster
=
getURL
(
"jdbc:h2:tcp://"
+
serverList
+
"/test"
,
true
);
CreateCluster
.
main
(
"-urlSource"
,
url1
,
"-urlTarget"
,
url2
,
"-user"
,
user
,
"-password"
,
password
,
"-serverList"
,
CreateCluster
.
main
(
"-urlSource"
,
url1
,
"-urlTarget"
,
url2
,
"-user"
,
user
,
"-password"
,
password
,
"-serverList"
,
serverList
);
serverList
);
conn
=
getConnection
(
urlCluster
,
user
,
password
);
conn
=
getConnection
(
urlCluster
,
user
,
password
);
...
@@ -104,7 +107,8 @@ public class TestCluster extends TestBase {
...
@@ -104,7 +107,8 @@ public class TestCluster extends TestBase {
Server
server2
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
Server
server2
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
port2
,
"-baseDir"
,
getBaseDir
()
+
"/node2"
).
start
();
"-tcpPort"
,
""
+
port2
,
"-baseDir"
,
getBaseDir
()
+
"/node2"
).
start
();
CreateCluster
.
main
(
"-urlSource"
,
url1
,
"-urlTarget"
,
url2
,
"-user"
,
user
,
"-password"
,
password
,
"-serverList"
,
CreateCluster
.
main
(
"-urlSource"
,
url1
,
"-urlTarget"
,
url2
,
"-user"
,
user
,
"-password"
,
password
,
"-serverList"
,
serverList
);
serverList
);
conn
=
getConnection
(
urlCluster
,
user
,
password
);
conn
=
getConnection
(
urlCluster
,
user
,
password
);
...
@@ -123,8 +127,10 @@ public class TestCluster extends TestBase {
...
@@ -123,8 +127,10 @@ public class TestCluster extends TestBase {
rs
.
next
();
rs
.
next
();
assertEquals
(
5
,
rs
.
getInt
(
1
));
assertEquals
(
5
,
rs
.
getInt
(
1
));
server2
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
port2
,
"-baseDir"
,
getBaseDir
()
+
"/node2"
).
start
();
server2
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
CreateCluster
.
main
(
"-urlSource"
,
url1
,
"-urlTarget"
,
url2
,
"-user"
,
user
,
"-password"
,
password
,
"-serverList"
,
""
+
port2
,
"-baseDir"
,
getBaseDir
()
+
"/node2"
).
start
();
CreateCluster
.
main
(
"-urlSource"
,
url1
,
"-urlTarget"
,
url2
,
"-user"
,
user
,
"-password"
,
password
,
"-serverList"
,
serverList
);
serverList
);
conn
.
close
();
conn
.
close
();
...
@@ -159,10 +165,13 @@ public class TestCluster extends TestBase {
...
@@ -159,10 +165,13 @@ public class TestCluster extends TestBase {
String
url2
=
getURL
(
"jdbc:h2:tcp://localhost:"
+
port2
+
"/test"
,
true
);
String
url2
=
getURL
(
"jdbc:h2:tcp://localhost:"
+
port2
+
"/test"
,
true
);
String
urlCluster
=
getURL
(
"jdbc:h2:tcp://"
+
serverList
+
"/test"
,
true
);
String
urlCluster
=
getURL
(
"jdbc:h2:tcp://"
+
serverList
+
"/test"
,
true
);
Server
n1
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
port1
,
"-baseDir"
,
getBaseDir
()
+
"/node1"
).
start
();
Server
n1
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
Server
n2
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
port2
,
"-baseDir"
,
getBaseDir
()
+
"/node2"
).
start
();
""
+
port1
,
"-baseDir"
,
getBaseDir
()
+
"/node1"
).
start
();
Server
n2
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
port2
,
"-baseDir"
,
getBaseDir
()
+
"/node2"
).
start
();
CreateCluster
.
main
(
"-urlSource"
,
url1
,
"-urlTarget"
,
url2
,
"-user"
,
user
,
"-password"
,
password
,
"-serverList"
,
CreateCluster
.
main
(
"-urlSource"
,
url1
,
"-urlTarget"
,
url2
,
"-user"
,
user
,
"-password"
,
password
,
"-serverList"
,
serverList
);
serverList
);
conn
=
getConnection
(
urlCluster
,
user
,
password
);
conn
=
getConnection
(
urlCluster
,
user
,
password
);
...
@@ -204,10 +213,13 @@ public class TestCluster extends TestBase {
...
@@ -204,10 +213,13 @@ public class TestCluster extends TestBase {
String
url2
=
getURL
(
"jdbc:h2:tcp://localhost:"
+
port2
+
"/test"
,
true
);
String
url2
=
getURL
(
"jdbc:h2:tcp://localhost:"
+
port2
+
"/test"
,
true
);
String
urlCluster
=
getURL
(
"jdbc:h2:tcp://"
+
serverList
+
"/test"
,
true
);
String
urlCluster
=
getURL
(
"jdbc:h2:tcp://"
+
serverList
+
"/test"
,
true
);
Server
n1
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
port1
,
"-baseDir"
,
getBaseDir
()
+
"/node1"
).
start
();
Server
n1
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
Server
n2
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
port2
,
"-baseDir"
,
getBaseDir
()
+
"/node2"
).
start
();
""
+
port1
,
"-baseDir"
,
getBaseDir
()
+
"/node1"
).
start
();
Server
n2
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
port2
,
"-baseDir"
,
getBaseDir
()
+
"/node2"
).
start
();
CreateCluster
.
main
(
"-urlSource"
,
url1
,
"-urlTarget"
,
url2
,
"-user"
,
user
,
"-password"
,
password
,
"-serverList"
,
CreateCluster
.
main
(
"-urlSource"
,
url1
,
"-urlTarget"
,
url2
,
"-user"
,
user
,
"-password"
,
password
,
"-serverList"
,
serverList
);
serverList
);
conn
=
getConnection
(
urlCluster
,
user
,
password
);
conn
=
getConnection
(
urlCluster
,
user
,
password
);
...
@@ -257,7 +269,8 @@ public class TestCluster extends TestBase {
...
@@ -257,7 +269,8 @@ public class TestCluster extends TestBase {
int
len
=
10
;
int
len
=
10
;
// initialize the database
// initialize the database
Server
n1
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
port1
,
"-baseDir"
,
getBaseDir
()
+
"/node1"
).
start
();
Server
n1
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
port1
,
"-baseDir"
,
getBaseDir
()
+
"/node1"
).
start
();
conn
=
getConnection
(
url1
,
user
,
password
);
conn
=
getConnection
(
url1
,
user
,
password
);
stat
=
conn
.
createStatement
();
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int primary key, name varchar) as "
+
stat
.
execute
(
"create table test(id int primary key, name varchar) as "
+
...
@@ -266,10 +279,12 @@ public class TestCluster extends TestBase {
...
@@ -266,10 +279,12 @@ public class TestCluster extends TestBase {
stat
.
execute
(
"grant all on test to test"
);
stat
.
execute
(
"grant all on test to test"
);
// start the second server
// start the second server
Server
n2
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
port2
,
"-baseDir"
,
getBaseDir
()
+
"/node2"
).
start
();
Server
n2
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
port2
,
"-baseDir"
,
getBaseDir
()
+
"/node2"
).
start
();
// copy the database and initialize the cluster
// copy the database and initialize the cluster
CreateCluster
.
main
(
"-urlSource"
,
url1
,
"-urlTarget"
,
url2
,
"-user"
,
user
,
"-password"
,
password
,
"-serverList"
,
CreateCluster
.
main
(
"-urlSource"
,
url1
,
"-urlTarget"
,
url2
,
"-user"
,
user
,
"-password"
,
password
,
"-serverList"
,
serverList
);
serverList
);
// check the original connection is closed
// check the original connection is closed
...
@@ -278,7 +293,8 @@ public class TestCluster extends TestBase {
...
@@ -278,7 +293,8 @@ public class TestCluster extends TestBase {
JdbcUtils
.
closeSilently
(
conn
);
JdbcUtils
.
closeSilently
(
conn
);
// test the cluster connection
// test the cluster connection
Connection
connApp
=
getConnection
(
urlCluster
+
";AUTO_RECONNECT=TRUE"
,
user
,
password
);
Connection
connApp
=
getConnection
(
urlCluster
+
";AUTO_RECONNECT=TRUE"
,
user
,
password
);
check
(
connApp
,
len
,
"'"
+
serverList
+
"'"
);
check
(
connApp
,
len
,
"'"
+
serverList
+
"'"
);
// delete the rows, but don't commit
// delete the rows, but don't commit
...
@@ -295,8 +311,10 @@ public class TestCluster extends TestBase {
...
@@ -295,8 +311,10 @@ public class TestCluster extends TestBase {
connApp
.
setAutoCommit
(
true
);
connApp
.
setAutoCommit
(
true
);
// re-create the cluster
// re-create the cluster
n2
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
port2
,
"-baseDir"
,
getBaseDir
()
+
"/node2"
).
start
();
n2
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
port2
,
CreateCluster
.
main
(
"-urlSource"
,
url1
,
"-urlTarget"
,
url2
,
"-user"
,
user
,
"-password"
,
password
,
"-serverList"
,
"-baseDir"
,
getBaseDir
()
+
"/node2"
).
start
();
CreateCluster
.
main
(
"-urlSource"
,
url1
,
"-urlTarget"
,
url2
,
"-user"
,
user
,
"-password"
,
password
,
"-serverList"
,
serverList
);
serverList
);
// test the cluster connection
// test the cluster connection
...
@@ -312,11 +330,13 @@ public class TestCluster extends TestBase {
...
@@ -312,11 +330,13 @@ public class TestCluster extends TestBase {
n1
.
stop
();
n1
.
stop
();
// test non-admin cluster connection if only one server runs
// test non-admin cluster connection if only one server runs
Connection
connApp2
=
getConnection
(
urlCluster
+
";AUTO_RECONNECT=TRUE"
,
user2
,
password2
);
Connection
connApp2
=
getConnection
(
urlCluster
+
";AUTO_RECONNECT=TRUE"
,
user2
,
password2
);
check
(
connApp2
,
len
,
"''"
);
check
(
connApp2
,
len
,
"''"
);
connApp2
.
close
();
connApp2
.
close
();
// test non-admin cluster connection if only one server runs
// test non-admin cluster connection if only one server runs
connApp2
=
getConnection
(
urlCluster
+
";AUTO_RECONNECT=TRUE"
,
user2
,
password2
);
connApp2
=
getConnection
(
urlCluster
+
";AUTO_RECONNECT=TRUE"
,
user2
,
password2
);
check
(
connApp2
,
len
,
"''"
);
check
(
connApp2
,
len
,
"''"
);
connApp2
.
close
();
connApp2
.
close
();
...
@@ -344,7 +364,8 @@ public class TestCluster extends TestBase {
...
@@ -344,7 +364,8 @@ public class TestCluster extends TestBase {
stat
=
conn
.
createStatement
();
stat
=
conn
.
createStatement
();
stat
.
execute
(
"DROP TABLE IF EXISTS TEST"
);
stat
.
execute
(
"DROP TABLE IF EXISTS TEST"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"INSERT INTO TEST VALUES(?, ?)"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"INSERT INTO TEST VALUES(?, ?)"
);
int
len
=
getSize
(
10
,
1000
);
int
len
=
getSize
(
10
,
1000
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
prep
.
setInt
(
1
,
i
);
prep
.
setInt
(
1
,
i
);
...
@@ -360,8 +381,10 @@ public class TestCluster extends TestBase {
...
@@ -360,8 +381,10 @@ public class TestCluster extends TestBase {
serverList
);
serverList
);
// start both servers
// start both servers
Server
n1
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
port1
,
"-baseDir"
,
getBaseDir
()
+
"/node1"
).
start
();
Server
n1
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
Server
n2
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
port2
,
"-baseDir"
,
getBaseDir
()
+
"/node2"
).
start
();
port1
,
"-baseDir"
,
getBaseDir
()
+
"/node1"
).
start
();
Server
n2
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
port2
,
"-baseDir"
,
getBaseDir
()
+
"/node2"
).
start
();
// try to connect in standalone mode - should fail
// try to connect in standalone mode - should fail
// should not be able to connect in standalone mode
// should not be able to connect in standalone mode
...
@@ -385,7 +408,8 @@ public class TestCluster extends TestBase {
...
@@ -385,7 +408,8 @@ public class TestCluster extends TestBase {
conn
.
close
();
conn
.
close
();
// disable the cluster
// disable the cluster
conn
=
getConnection
(
"jdbc:h2:tcp://localhost:"
+
port1
+
"/test;CLUSTER=''"
,
user
,
password
);
conn
=
getConnection
(
"jdbc:h2:tcp://localhost:"
+
port1
+
"/test;CLUSTER=''"
,
user
,
password
);
conn
.
close
();
conn
.
close
();
n1
.
stop
();
n1
.
stop
();
...
@@ -394,8 +418,10 @@ public class TestCluster extends TestBase {
...
@@ -394,8 +418,10 @@ public class TestCluster extends TestBase {
CreateCluster
.
main
(
"-urlSource"
,
urlNode1
,
"-urlTarget"
,
CreateCluster
.
main
(
"-urlSource"
,
urlNode1
,
"-urlTarget"
,
urlNode2
,
"-user"
,
user
,
"-password"
,
password
,
"-serverList"
,
urlNode2
,
"-user"
,
user
,
"-password"
,
password
,
"-serverList"
,
serverList
);
serverList
);
n1
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
port1
,
"-baseDir"
,
getBaseDir
()
+
"/node1"
).
start
();
n1
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
n2
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
port2
,
"-baseDir"
,
getBaseDir
()
+
"/node2"
).
start
();
port1
,
"-baseDir"
,
getBaseDir
()
+
"/node1"
).
start
();
n2
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
port2
,
"-baseDir"
,
getBaseDir
()
+
"/node2"
).
start
();
conn
=
getConnection
(
"jdbc:h2:tcp://"
+
serverList
+
"/test"
,
user
,
password
);
conn
=
getConnection
(
"jdbc:h2:tcp://"
+
serverList
+
"/test"
,
user
,
password
);
stat
=
conn
.
createStatement
();
stat
=
conn
.
createStatement
();
...
@@ -407,14 +433,18 @@ public class TestCluster extends TestBase {
...
@@ -407,14 +433,18 @@ public class TestCluster extends TestBase {
conn
.
close
();
conn
.
close
();
n2
.
stop
();
n2
.
stop
();
n1
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
port1
,
"-baseDir"
,
getBaseDir
()
+
"/node1"
).
start
();
n1
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
conn
=
getConnection
(
"jdbc:h2:tcp://localhost:"
+
port1
+
"/test;CLUSTER=''"
,
user
,
password
);
port1
,
"-baseDir"
,
getBaseDir
()
+
"/node1"
).
start
();
conn
=
getConnection
(
"jdbc:h2:tcp://localhost:"
+
port1
+
"/test;CLUSTER=''"
,
user
,
password
);
check
(
conn
,
len
,
"''"
);
check
(
conn
,
len
,
"''"
);
conn
.
close
();
conn
.
close
();
n1
.
stop
();
n1
.
stop
();
n2
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
port2
,
"-baseDir"
,
getBaseDir
()
+
"/node2"
).
start
();
n2
=
org
.
h2
.
tools
.
Server
.
createTcpServer
(
"-tcpPort"
,
""
+
conn
=
getConnection
(
"jdbc:h2:tcp://localhost:"
+
port2
+
"/test;CLUSTER=''"
,
user
,
password
);
port2
,
"-baseDir"
,
getBaseDir
()
+
"/node2"
).
start
();
conn
=
getConnection
(
"jdbc:h2:tcp://localhost:"
+
port2
+
"/test;CLUSTER=''"
,
user
,
password
);
check
(
conn
,
len
,
"''"
);
check
(
conn
,
len
,
"''"
);
conn
.
createStatement
().
execute
(
"SELECT * FROM A"
);
conn
.
createStatement
().
execute
(
"SELECT * FROM A"
);
conn
.
close
();
conn
.
close
();
...
@@ -429,7 +459,8 @@ public class TestCluster extends TestBase {
...
@@ -429,7 +459,8 @@ public class TestCluster extends TestBase {
FileUtils
.
delete
(
getBaseDir
()
+
"/node2"
);
FileUtils
.
delete
(
getBaseDir
()
+
"/node2"
);
}
}
private
void
check
(
Connection
conn
,
int
len
,
String
expectedCluster
)
throws
SQLException
{
private
void
check
(
Connection
conn
,
int
len
,
String
expectedCluster
)
throws
SQLException
{
PreparedStatement
prep
=
conn
.
prepareStatement
(
"SELECT * FROM TEST WHERE ID=?"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"SELECT * FROM TEST WHERE ID=?"
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
prep
.
setInt
(
1
,
i
);
prep
.
setInt
(
1
,
i
);
...
...
h2/src/test/org/h2/test/db/TestCompatibility.java
浏览文件 @
b3836d31
...
@@ -66,7 +66,8 @@ public class TestCompatibility extends TestBase {
...
@@ -66,7 +66,8 @@ public class TestCompatibility extends TestBase {
private
void
testCaseSensitiveIdentifiers
()
throws
SQLException
{
private
void
testCaseSensitiveIdentifiers
()
throws
SQLException
{
Connection
c
=
getConnection
(
"compatibility;DATABASE_TO_UPPER=FALSE"
);
Connection
c
=
getConnection
(
"compatibility;DATABASE_TO_UPPER=FALSE"
);
Statement
stat
=
c
.
createStatement
();
Statement
stat
=
c
.
createStatement
();
stat
.
execute
(
"create table test(id int primary key, name varchar) as select 1, 'hello'"
);
stat
.
execute
(
"create table test(id int primary key, name varchar) "
+
"as select 1, 'hello'"
);
assertThrows
(
ErrorCode
.
TABLE_OR_VIEW_ALREADY_EXISTS_1
,
stat
).
assertThrows
(
ErrorCode
.
TABLE_OR_VIEW_ALREADY_EXISTS_1
,
stat
).
execute
(
"create table test(id int primary key, name varchar)"
);
execute
(
"create table test(id int primary key, name varchar)"
);
assertThrows
(
ErrorCode
.
DUPLICATE_COLUMN_NAME_1
,
stat
).
assertThrows
(
ErrorCode
.
DUPLICATE_COLUMN_NAME_1
,
stat
).
...
@@ -122,7 +123,8 @@ public class TestCompatibility extends TestBase {
...
@@ -122,7 +123,8 @@ public class TestCompatibility extends TestBase {
private
void
testColumnAlias
()
throws
SQLException
{
private
void
testColumnAlias
()
throws
SQLException
{
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
String
[]
modes
=
{
"PostgreSQL"
,
"MySQL"
,
"HSQLDB"
,
"MSSQLServer"
,
"Derby"
,
"Oracle"
,
"Regular"
};
String
[]
modes
=
{
"PostgreSQL"
,
"MySQL"
,
"HSQLDB"
,
"MSSQLServer"
,
"Derby"
,
"Oracle"
,
"Regular"
};
String
columnAlias
;
String
columnAlias
;
columnAlias
=
"MySQL,Regular"
;
columnAlias
=
"MySQL,Regular"
;
stat
.
execute
(
"CREATE TABLE TEST(ID INT)"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT)"
);
...
@@ -133,9 +135,11 @@ public class TestCompatibility extends TestBase {
...
@@ -133,9 +135,11 @@ public class TestCompatibility extends TestBase {
String
columnName
=
meta
.
getColumnName
(
1
);
String
columnName
=
meta
.
getColumnName
(
1
);
String
tableName
=
meta
.
getTableName
(
1
);
String
tableName
=
meta
.
getTableName
(
1
);
if
(
"ID"
.
equals
(
columnName
)
&&
"TEST"
.
equals
(
tableName
))
{
if
(
"ID"
.
equals
(
columnName
)
&&
"TEST"
.
equals
(
tableName
))
{
assertTrue
(
mode
+
" mode should not support columnAlias"
,
columnAlias
.
indexOf
(
mode
)
>=
0
);
assertTrue
(
mode
+
" mode should not support columnAlias"
,
columnAlias
.
indexOf
(
mode
)
>=
0
);
}
else
if
(
"I"
.
equals
(
columnName
)
&&
tableName
.
equals
(
""
))
{
}
else
if
(
"I"
.
equals
(
columnName
)
&&
tableName
.
equals
(
""
))
{
assertTrue
(
mode
+
" mode should support columnAlias"
,
columnAlias
.
indexOf
(
mode
)
<
0
);
assertTrue
(
mode
+
" mode should support columnAlias"
,
columnAlias
.
indexOf
(
mode
)
<
0
);
}
else
{
}
else
{
fail
();
fail
();
}
}
...
@@ -145,7 +149,8 @@ public class TestCompatibility extends TestBase {
...
@@ -145,7 +149,8 @@ public class TestCompatibility extends TestBase {
private
void
testUniqueIndexSingleNull
()
throws
SQLException
{
private
void
testUniqueIndexSingleNull
()
throws
SQLException
{
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
String
[]
modes
=
{
"PostgreSQL"
,
"MySQL"
,
"HSQLDB"
,
"MSSQLServer"
,
"Derby"
,
"Oracle"
,
"Regular"
};
String
[]
modes
=
{
"PostgreSQL"
,
"MySQL"
,
"HSQLDB"
,
"MSSQLServer"
,
"Derby"
,
"Oracle"
,
"Regular"
};
String
multiNull
=
"PostgreSQL,MySQL,Oracle,Regular"
;
String
multiNull
=
"PostgreSQL,MySQL,Oracle,Regular"
;
for
(
String
mode
:
modes
)
{
for
(
String
mode
:
modes
)
{
stat
.
execute
(
"SET MODE "
+
mode
);
stat
.
execute
(
"SET MODE "
+
mode
);
...
@@ -153,9 +158,11 @@ public class TestCompatibility extends TestBase {
...
@@ -153,9 +158,11 @@ public class TestCompatibility extends TestBase {
stat
.
execute
(
"CREATE UNIQUE INDEX IDX_ID_U ON TEST(ID)"
);
stat
.
execute
(
"CREATE UNIQUE INDEX IDX_ID_U ON TEST(ID)"
);
try
{
try
{
stat
.
execute
(
"INSERT INTO TEST VALUES(1), (2), (NULL), (NULL)"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(1), (2), (NULL), (NULL)"
);
assertTrue
(
mode
+
" mode should not support multiple NULL"
,
multiNull
.
indexOf
(
mode
)
>=
0
);
assertTrue
(
mode
+
" mode should not support multiple NULL"
,
multiNull
.
indexOf
(
mode
)
>=
0
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
assertTrue
(
mode
+
" mode should support multiple NULL"
,
multiNull
.
indexOf
(
mode
)
<
0
);
assertTrue
(
mode
+
" mode should support multiple NULL"
,
multiNull
.
indexOf
(
mode
)
<
0
);
}
}
stat
.
execute
(
"DROP TABLE TEST"
);
stat
.
execute
(
"DROP TABLE TEST"
);
}
}
...
@@ -182,7 +189,8 @@ public class TestCompatibility extends TestBase {
...
@@ -182,7 +189,8 @@ public class TestCompatibility extends TestBase {
stat
.
execute
(
"set mode hsqldb"
);
stat
.
execute
(
"set mode hsqldb"
);
testLog
(
Math
.
log
(
10
),
stat
);
testLog
(
Math
.
log
(
10
),
stat
);
stat
.
execute
(
"DROP TABLE TEST IF EXISTS; CREATE TABLE TEST(ID INT PRIMARY KEY); "
);
stat
.
execute
(
"DROP TABLE TEST IF EXISTS; "
+
"CREATE TABLE TEST(ID INT PRIMARY KEY); "
);
stat
.
execute
(
"CALL CURRENT_TIME"
);
stat
.
execute
(
"CALL CURRENT_TIME"
);
stat
.
execute
(
"CALL CURRENT_TIMESTAMP"
);
stat
.
execute
(
"CALL CURRENT_TIMESTAMP"
);
stat
.
execute
(
"CALL CURRENT_DATE"
);
stat
.
execute
(
"CALL CURRENT_DATE"
);
...
@@ -192,7 +200,8 @@ public class TestCompatibility extends TestBase {
...
@@ -192,7 +200,8 @@ public class TestCompatibility extends TestBase {
stat
.
execute
(
"DROP TABLE TEST IF EXISTS"
);
stat
.
execute
(
"DROP TABLE TEST IF EXISTS"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT)"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT)"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(1)"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(1)"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"SELECT LIMIT ? 1 ID FROM TEST"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"SELECT LIMIT ? 1 ID FROM TEST"
);
prep
.
setInt
(
1
,
2
);
prep
.
setInt
(
1
,
2
);
prep
.
executeQuery
();
prep
.
executeQuery
();
stat
.
execute
(
"DROP TABLE TEST IF EXISTS"
);
stat
.
execute
(
"DROP TABLE TEST IF EXISTS"
);
...
@@ -227,10 +236,14 @@ public class TestCompatibility extends TestBase {
...
@@ -227,10 +236,14 @@ public class TestCompatibility extends TestBase {
stat
.
execute
(
"INSERT INTO TEST VALUES(1, 'Hello'), (2, 'World')"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(1, 'Hello'), (2, 'World')"
);
org
.
h2
.
mode
.
FunctionsMySQL
.
register
(
conn
);
org
.
h2
.
mode
.
FunctionsMySQL
.
register
(
conn
);
assertResult
(
"0"
,
stat
,
"SELECT UNIX_TIMESTAMP('1970-01-01 00:00:00Z')"
);
assertResult
(
"0"
,
stat
,
"SELECT UNIX_TIMESTAMP('1970-01-01 00:00:00Z')"
);
assertResult
(
"1196418619"
,
stat
,
"SELECT UNIX_TIMESTAMP('2007-11-30 10:30:19Z')"
);
assertResult
(
"1196418619"
,
stat
,
assertResult
(
"1196418619"
,
stat
,
"SELECT UNIX_TIMESTAMP(FROM_UNIXTIME(1196418619))"
);
"SELECT UNIX_TIMESTAMP('2007-11-30 10:30:19Z')"
);
assertResult
(
"2007 November"
,
stat
,
"SELECT FROM_UNIXTIME(1196300000, '%Y %M')"
);
assertResult
(
"1196418619"
,
stat
,
assertResult
(
"2003-12-31"
,
stat
,
"SELECT DATE('2003-12-31 11:02:03')"
);
"SELECT UNIX_TIMESTAMP(FROM_UNIXTIME(1196418619))"
);
assertResult
(
"2007 November"
,
stat
,
"SELECT FROM_UNIXTIME(1196300000, '%Y %M')"
);
assertResult
(
"2003-12-31"
,
stat
,
"SELECT DATE('2003-12-31 11:02:03')"
);
if
(
config
.
memory
)
{
if
(
config
.
memory
)
{
return
;
return
;
...
@@ -249,7 +262,8 @@ public class TestCompatibility extends TestBase {
...
@@ -249,7 +262,8 @@ public class TestCompatibility extends TestBase {
assertFalse
(
meta
.
storesUpperCaseIdentifiers
());
assertFalse
(
meta
.
storesUpperCaseIdentifiers
());
assertTrue
(
meta
.
storesUpperCaseQuotedIdentifiers
());
assertTrue
(
meta
.
storesUpperCaseQuotedIdentifiers
());
stat
=
conn
.
createStatement
(
ResultSet
.
TYPE_SCROLL_INSENSITIVE
,
ResultSet
.
CONCUR_UPDATABLE
);
stat
=
conn
.
createStatement
(
ResultSet
.
TYPE_SCROLL_INSENSITIVE
,
ResultSet
.
CONCUR_UPDATABLE
);
assertResult
(
"test"
,
stat
,
"SHOW TABLES"
);
assertResult
(
"test"
,
stat
,
"SHOW TABLES"
);
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM TEST"
);
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM TEST"
);
rs
.
next
();
rs
.
next
();
...
@@ -257,17 +271,27 @@ public class TestCompatibility extends TestBase {
...
@@ -257,17 +271,27 @@ public class TestCompatibility extends TestBase {
rs
.
updateRow
();
rs
.
updateRow
();
// we used to have an NullPointerException in the MetaTable.checkIndex() method
// we used to have an NullPointerException in the MetaTable.checkIndex() method
rs
=
stat
.
executeQuery
(
"SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME > 'aaaa'"
);
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
rs
=
stat
.
executeQuery
(
"SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME < 'aaaa'"
);
"INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME > 'aaaa'"
);
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
stat
.
execute
(
"CREATE TABLE TEST_1(ID INT PRIMARY KEY) ENGINE=InnoDb"
);
"INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME < 'aaaa'"
);
stat
.
execute
(
"CREATE TABLE TEST_2(ID INT PRIMARY KEY) ENGINE=MyISAM"
);
stat
.
execute
(
"CREATE TABLE TEST_3(ID INT PRIMARY KEY) ENGINE=InnoDb charset=UTF8"
);
stat
.
execute
(
"CREATE TABLE TEST_1"
+
stat
.
execute
(
"CREATE TABLE TEST_4(ID INT PRIMARY KEY) charset=UTF8"
);
"(ID INT PRIMARY KEY) ENGINE=InnoDb"
);
stat
.
execute
(
"CREATE TABLE TEST_5(ID INT PRIMARY KEY) ENGINE=InnoDb auto_increment=3 default charset=UTF8"
);
stat
.
execute
(
"CREATE TABLE TEST_2"
+
stat
.
execute
(
"CREATE TABLE TEST_6(ID INT PRIMARY KEY) ENGINE=InnoDb auto_increment=3 charset=UTF8"
);
"(ID INT PRIMARY KEY) ENGINE=MyISAM"
);
stat
.
execute
(
"CREATE TABLE TEST_7(ID INT, KEY TEST_7_IDX(ID) USING BTREE)"
);
stat
.
execute
(
"CREATE TABLE TEST_3"
+
stat
.
execute
(
"CREATE TABLE TEST_8(ID INT, UNIQUE KEY TEST_8_IDX(ID) USING BTREE)"
);
"(ID INT PRIMARY KEY) ENGINE=InnoDb charset=UTF8"
);
stat
.
execute
(
"CREATE TABLE TEST_4"
+
"(ID INT PRIMARY KEY) charset=UTF8"
);
stat
.
execute
(
"CREATE TABLE TEST_5"
+
"(ID INT PRIMARY KEY) ENGINE=InnoDb auto_increment=3 default charset=UTF8"
);
stat
.
execute
(
"CREATE TABLE TEST_6"
+
"(ID INT PRIMARY KEY) ENGINE=InnoDb auto_increment=3 charset=UTF8"
);
stat
.
execute
(
"CREATE TABLE TEST_7"
+
"(ID INT, KEY TEST_7_IDX(ID) USING BTREE)"
);
stat
.
execute
(
"CREATE TABLE TEST_8"
+
"(ID INT, UNIQUE KEY TEST_8_IDX(ID) USING BTREE)"
);
// this maps to SET REFERENTIAL_INTEGRITY TRUE/FALSE
// this maps to SET REFERENTIAL_INTEGRITY TRUE/FALSE
stat
.
execute
(
"SET foreign_key_checks = 0"
);
stat
.
execute
(
"SET foreign_key_checks = 0"
);
...
@@ -278,7 +302,8 @@ public class TestCompatibility extends TestBase {
...
@@ -278,7 +302,8 @@ public class TestCompatibility extends TestBase {
conn
=
getConnection
(
"compatibility;MODE=MYSQL"
);
conn
=
getConnection
(
"compatibility;MODE=MYSQL"
);
stat
=
conn
.
createStatement
();
stat
=
conn
.
createStatement
();
stat
.
execute
(
"DROP TABLE IF EXISTS TEST_NO_COMMENT"
);
stat
.
execute
(
"DROP TABLE IF EXISTS TEST_NO_COMMENT"
);
stat
.
execute
(
"CREATE table TEST_NO_COMMENT (ID bigint not null auto_increment, "
+
stat
.
execute
(
"CREATE table TEST_NO_COMMENT "
+
"(ID bigint not null auto_increment, "
+
"SOME_STR varchar(255), primary key (ID))"
);
"SOME_STR varchar(255), primary key (ID))"
);
// now test creating a table with a comment
// now test creating a table with a comment
stat
.
execute
(
"DROP TABLE IF EXISTS TEST_COMMENT"
);
stat
.
execute
(
"DROP TABLE IF EXISTS TEST_COMMENT"
);
...
@@ -287,9 +312,12 @@ public class TestCompatibility extends TestBase {
...
@@ -287,9 +312,12 @@ public class TestCompatibility extends TestBase {
// now test creating a table with a comment and engine
// now test creating a table with a comment and engine
// and other typical mysql stuff as generated by hibernate
// and other typical mysql stuff as generated by hibernate
stat
.
execute
(
"DROP TABLE IF EXISTS TEST_COMMENT_ENGINE"
);
stat
.
execute
(
"DROP TABLE IF EXISTS TEST_COMMENT_ENGINE"
);
stat
.
execute
(
"create table TEST_COMMENT_ENGINE (ID bigint not null auto_increment, "
+
stat
.
execute
(
"create table TEST_COMMENT_ENGINE "
+
"ATTACHMENT_ID varchar(255), SOME_ITEM_ID bigint not null, primary key (ID), "
+
"(ID bigint not null auto_increment, "
+
"unique (ATTACHMENT_ID, SOME_ITEM_ID)) comment='Comment Again' ENGINE=InnoDB"
);
"ATTACHMENT_ID varchar(255), "
+
"SOME_ITEM_ID bigint not null, primary key (ID), "
+
"unique (ATTACHMENT_ID, SOME_ITEM_ID)) "
+
"comment='Comment Again' ENGINE=InnoDB"
);
conn
.
close
();
conn
.
close
();
conn
=
getConnection
(
"compatibility"
);
conn
=
getConnection
(
"compatibility"
);
...
@@ -306,13 +334,15 @@ public class TestCompatibility extends TestBase {
...
@@ -306,13 +334,15 @@ public class TestCompatibility extends TestBase {
assertResult
(
"abcd123"
,
stat
,
"SELECT 'abc' + 'd123'"
);
assertResult
(
"abcd123"
,
stat
,
"SELECT 'abc' + 'd123'"
);
assertResult
(
"Doe, John"
,
stat
,
assertResult
(
"Doe, John"
,
stat
,
"SELECT surname + ', ' + name FROM test WHERE SUBSTRING(NAME,1,1)+SUBSTRING(SURNAME,1,1) = 'JD'"
);
"SELECT surname + ', ' + name FROM test "
+
"WHERE SUBSTRING(NAME,1,1)+SUBSTRING(SURNAME,1,1) = 'JD'"
);
stat
.
execute
(
"ALTER TABLE TEST ADD COLUMN full_name VARCHAR(100)"
);
stat
.
execute
(
"ALTER TABLE TEST ADD COLUMN full_name VARCHAR(100)"
);
stat
.
execute
(
"UPDATE TEST SET full_name = name + ', ' + surname"
);
stat
.
execute
(
"UPDATE TEST SET full_name = name + ', ' + surname"
);
assertResult
(
"John, Doe"
,
stat
,
"SELECT full_name FROM TEST where name='John'"
);
assertResult
(
"John, Doe"
,
stat
,
"SELECT full_name FROM TEST where name='John'"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"INSERT INTO TEST VALUES(?, ?, ? + ', ' + ?)"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"INSERT INTO TEST VALUES(?, ?, ? + ', ' + ?)"
);
int
ca
=
1
;
int
ca
=
1
;
prep
.
setString
(
ca
++,
"Paul"
);
prep
.
setString
(
ca
++,
"Paul"
);
prep
.
setString
(
ca
++,
"Frank"
);
prep
.
setString
(
ca
++,
"Frank"
);
...
@@ -321,7 +351,8 @@ public class TestCompatibility extends TestBase {
...
@@ -321,7 +351,8 @@ public class TestCompatibility extends TestBase {
prep
.
executeUpdate
();
prep
.
executeUpdate
();
prep
.
close
();
prep
.
close
();
assertResult
(
"Paul, Frank"
,
stat
,
"SELECT full_name FROM test WHERE name = 'Paul'"
);
assertResult
(
"Paul, Frank"
,
stat
,
"SELECT full_name FROM test "
+
"WHERE name = 'Paul'"
);
prep
=
conn
.
prepareStatement
(
"SELECT ? + ?"
);
prep
=
conn
.
prepareStatement
(
"SELECT ? + ?"
);
int
cb
=
1
;
int
cb
=
1
;
...
@@ -330,7 +361,8 @@ public class TestCompatibility extends TestBase {
...
@@ -330,7 +361,8 @@ public class TestCompatibility extends TestBase {
prep
.
executeQuery
();
prep
.
executeQuery
();
prep
.
close
();
prep
.
close
();
prep
=
conn
.
prepareStatement
(
"SELECT full_name FROM test WHERE (SUBSTRING(name, 1, 1) + SUBSTRING(surname, 2, 3)) = ?"
);
prep
=
conn
.
prepareStatement
(
"SELECT full_name FROM test "
+
"WHERE (SUBSTRING(name, 1, 1) + SUBSTRING(surname, 2, 3)) = ?"
);
prep
.
setString
(
1
,
"Joe"
);
prep
.
setString
(
1
,
"Joe"
);
ResultSet
rs
=
prep
.
executeQuery
();
ResultSet
rs
=
prep
.
executeQuery
();
assertTrue
(
"Result cannot be empty"
,
rs
.
next
());
assertTrue
(
"Result cannot be empty"
,
rs
.
next
());
...
@@ -355,7 +387,8 @@ public class TestCompatibility extends TestBase {
...
@@ -355,7 +387,8 @@ public class TestCompatibility extends TestBase {
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
testLog
(
Math
.
log
(
10
),
stat
);
testLog
(
Math
.
log
(
10
),
stat
);
ResultSet
res
=
conn
.
createStatement
().
executeQuery
(
"SELECT 1 FROM sysibm.sysdummy1"
);
ResultSet
res
=
conn
.
createStatement
().
executeQuery
(
"SELECT 1 FROM sysibm.sysdummy1"
);
res
.
next
();
res
.
next
();
assertEquals
(
"1"
,
res
.
getString
(
1
));
assertEquals
(
"1"
,
res
.
getString
(
1
));
conn
.
close
();
conn
.
close
();
...
@@ -368,7 +401,8 @@ public class TestCompatibility extends TestBase {
...
@@ -368,7 +401,8 @@ public class TestCompatibility extends TestBase {
stat
.
execute
(
"drop table test if exists"
);
stat
.
execute
(
"drop table test if exists"
);
stat
.
execute
(
"create table test(id varchar)"
);
stat
.
execute
(
"create table test(id varchar)"
);
stat
.
execute
(
"insert into test values ('3'),('1'),('2')"
);
stat
.
execute
(
"insert into test values ('3'),('1'),('2')"
);
res
=
stat
.
executeQuery
(
"select id from test order by id fetch next 2 rows only"
);
res
=
stat
.
executeQuery
(
"select id from test order by id "
+
"fetch next 2 rows only"
);
res
.
next
();
res
.
next
();
assertEquals
(
"1"
,
res
.
getString
(
1
));
assertEquals
(
"1"
,
res
.
getString
(
1
));
res
.
next
();
res
.
next
();
...
@@ -382,17 +416,21 @@ public class TestCompatibility extends TestBase {
...
@@ -382,17 +416,21 @@ public class TestCompatibility extends TestBase {
res
=
stat
.
executeQuery
(
"select * from test with ur"
);
res
=
stat
.
executeQuery
(
"select * from test with ur"
);
stat
.
executeUpdate
(
"insert into test values (1) with ur"
);
stat
.
executeUpdate
(
"insert into test values (1) with ur"
);
res
=
stat
.
executeQuery
(
"select * from test where id = 1 with rr"
);
res
=
stat
.
executeQuery
(
"select * from test where id = 1 with rr"
);
res
=
stat
.
executeQuery
(
"select * from test order by id fetch next 2 rows only with rr"
);
res
=
stat
.
executeQuery
(
"select * from test order by id "
+
res
=
stat
.
executeQuery
(
"select * from test order by id fetch next 2 rows only with rs"
);
"fetch next 2 rows only with rr"
);
res
=
stat
.
executeQuery
(
"select * from test order by id fetch next 2 rows only with cs"
);
res
=
stat
.
executeQuery
(
"select * from test order by id "
+
res
=
stat
.
executeQuery
(
"select * from test order by id fetch next 2 rows only with ur"
);
"fetch next 2 rows only with rs"
);
res
=
stat
.
executeQuery
(
"select * from test order by id "
+
"fetch next 2 rows only with cs"
);
res
=
stat
.
executeQuery
(
"select * from test order by id "
+
"fetch next 2 rows only with ur"
);
// test isolation-clause with lock-request-clause
// test isolation-clause with lock-request-clause
res
=
stat
res
=
stat
.
executeQuery
(
"select * from test order by id "
+
.
executeQuery
(
"select * from test order by id
fetch next 2 rows only with rr use and keep share locks"
);
"
fetch next 2 rows only with rr use and keep share locks"
);
res
=
stat
res
=
stat
.
executeQuery
(
"select * from test order by id "
+
.
executeQuery
(
"select * from test order by id
fetch next 2 rows only with rs use and keep update locks"
);
"
fetch next 2 rows only with rs use and keep update locks"
);
res
=
stat
res
=
stat
.
executeQuery
(
"select * from test order by id "
+
.
executeQuery
(
"select * from test order by id
fetch next 2 rows only with rr use and keep exclusive locks"
);
"
fetch next 2 rows only with rr use and keep exclusive locks"
);
}
}
private
void
testDerby
()
throws
SQLException
{
private
void
testDerby
()
throws
SQLException
{
...
@@ -401,7 +439,8 @@ public class TestCompatibility extends TestBase {
...
@@ -401,7 +439,8 @@ public class TestCompatibility extends TestBase {
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
testLog
(
Math
.
log
(
10
),
stat
);
testLog
(
Math
.
log
(
10
),
stat
);
ResultSet
res
=
conn
.
createStatement
().
executeQuery
(
"SELECT 1 FROM sysibm.sysdummy1 fetch next 1 row only"
);
ResultSet
res
=
conn
.
createStatement
().
executeQuery
(
"SELECT 1 FROM sysibm.sysdummy1 fetch next 1 row only"
);
res
.
next
();
res
.
next
();
assertEquals
(
"1"
,
res
.
getString
(
1
));
assertEquals
(
"1"
,
res
.
getString
(
1
));
conn
.
close
();
conn
.
close
();
...
...
h2/src/test/org/h2/test/db/TestCompatibilityOracle.java
浏览文件 @
b3836d31
...
@@ -49,8 +49,10 @@ public class TestCompatibilityOracle extends TestBase {
...
@@ -49,8 +49,10 @@ public class TestCompatibilityOracle extends TestBase {
assertResult
(
"1"
,
stat
,
"SELECT COUNT(*) FROM A WHERE X IS NULL"
);
assertResult
(
"1"
,
stat
,
"SELECT COUNT(*) FROM A WHERE X IS NULL"
);
assertResult
(
"2"
,
stat
,
"SELECT COUNT(*) FROM A WHERE TRIM(X) IS NULL"
);
assertResult
(
"2"
,
stat
,
"SELECT COUNT(*) FROM A WHERE TRIM(X) IS NULL"
);
assertResult
(
"0"
,
stat
,
"SELECT COUNT(*) FROM A WHERE X = ''"
);
assertResult
(
"0"
,
stat
,
"SELECT COUNT(*) FROM A WHERE X = ''"
);
assertResult
(
new
Object
[][]
{
{
1
,
"a"
},
{
2
,
null
},
{
3
,
" "
}
},
stat
,
"SELECT * FROM A"
);
assertResult
(
new
Object
[][]
{
{
1
,
"a"
},
{
2
,
null
},
{
3
,
" "
}
},
assertResult
(
new
Object
[][]
{
{
1
,
"a"
},
{
2
,
null
},
{
3
,
null
}
},
stat
,
"SELECT ID, TRIM(X) FROM A"
);
stat
,
"SELECT * FROM A"
);
assertResult
(
new
Object
[][]
{
{
1
,
"a"
},
{
2
,
null
},
{
3
,
null
}
},
stat
,
"SELECT ID, TRIM(X) FROM A"
);
stat
.
execute
(
"CREATE TABLE B (ID NUMBER, X NUMBER)"
);
stat
.
execute
(
"CREATE TABLE B (ID NUMBER, X NUMBER)"
);
stat
.
execute
(
"INSERT INTO B VALUES (1, '5')"
);
stat
.
execute
(
"INSERT INTO B VALUES (1, '5')"
);
...
@@ -58,7 +60,8 @@ public class TestCompatibilityOracle extends TestBase {
...
@@ -58,7 +60,8 @@ public class TestCompatibilityOracle extends TestBase {
assertResult
(
"2"
,
stat
,
"SELECT COUNT(*) FROM B"
);
assertResult
(
"2"
,
stat
,
"SELECT COUNT(*) FROM B"
);
assertResult
(
"1"
,
stat
,
"SELECT COUNT(*) FROM B WHERE X IS NULL"
);
assertResult
(
"1"
,
stat
,
"SELECT COUNT(*) FROM B WHERE X IS NULL"
);
assertResult
(
"0"
,
stat
,
"SELECT COUNT(*) FROM B WHERE X = ''"
);
assertResult
(
"0"
,
stat
,
"SELECT COUNT(*) FROM B WHERE X = ''"
);
assertResult
(
new
Object
[][]
{
{
1
,
5
},
{
2
,
null
}
},
stat
,
"SELECT * FROM B"
);
assertResult
(
new
Object
[][]
{
{
1
,
5
},
{
2
,
null
}
},
stat
,
"SELECT * FROM B"
);
stat
.
execute
(
"CREATE TABLE C (ID NUMBER, X TIMESTAMP)"
);
stat
.
execute
(
"CREATE TABLE C (ID NUMBER, X TIMESTAMP)"
);
stat
.
execute
(
"INSERT INTO C VALUES (1, '1979-11-12')"
);
stat
.
execute
(
"INSERT INTO C VALUES (1, '1979-11-12')"
);
...
@@ -66,7 +69,8 @@ public class TestCompatibilityOracle extends TestBase {
...
@@ -66,7 +69,8 @@ public class TestCompatibilityOracle extends TestBase {
assertResult
(
"2"
,
stat
,
"SELECT COUNT(*) FROM C"
);
assertResult
(
"2"
,
stat
,
"SELECT COUNT(*) FROM C"
);
assertResult
(
"1"
,
stat
,
"SELECT COUNT(*) FROM C WHERE X IS NULL"
);
assertResult
(
"1"
,
stat
,
"SELECT COUNT(*) FROM C WHERE X IS NULL"
);
assertResult
(
"0"
,
stat
,
"SELECT COUNT(*) FROM C WHERE X = ''"
);
assertResult
(
"0"
,
stat
,
"SELECT COUNT(*) FROM C WHERE X = ''"
);
assertResult
(
new
Object
[][]
{
{
1
,
"1979-11-12 00:00:00.0"
},
{
2
,
null
}
},
stat
,
"SELECT * FROM C"
);
assertResult
(
new
Object
[][]
{
{
1
,
"1979-11-12 00:00:00.0"
},
{
2
,
null
}
},
stat
,
"SELECT * FROM C"
);
stat
.
execute
(
"CREATE TABLE D (ID NUMBER, X VARCHAR2(1))"
);
stat
.
execute
(
"CREATE TABLE D (ID NUMBER, X VARCHAR2(1))"
);
stat
.
execute
(
"INSERT INTO D VALUES (1, 'a')"
);
stat
.
execute
(
"INSERT INTO D VALUES (1, 'a')"
);
...
@@ -75,7 +79,8 @@ public class TestCompatibilityOracle extends TestBase {
...
@@ -75,7 +79,8 @@ public class TestCompatibilityOracle extends TestBase {
assertResult
(
"2"
,
stat
,
"SELECT COUNT(*) FROM D"
);
assertResult
(
"2"
,
stat
,
"SELECT COUNT(*) FROM D"
);
assertResult
(
"1"
,
stat
,
"SELECT COUNT(*) FROM D WHERE X IS NULL"
);
assertResult
(
"1"
,
stat
,
"SELECT COUNT(*) FROM D WHERE X IS NULL"
);
assertResult
(
"0"
,
stat
,
"SELECT COUNT(*) FROM D WHERE X = ''"
);
assertResult
(
"0"
,
stat
,
"SELECT COUNT(*) FROM D WHERE X = ''"
);
assertResult
(
new
Object
[][]
{
{
1
,
"a"
},
{
2
,
null
}
},
stat
,
"SELECT * FROM D"
);
assertResult
(
new
Object
[][]
{
{
1
,
"a"
},
{
2
,
null
}
},
stat
,
"SELECT * FROM D"
);
stat
.
execute
(
"CREATE TABLE E (ID NUMBER, X RAW(1))"
);
stat
.
execute
(
"CREATE TABLE E (ID NUMBER, X RAW(1))"
);
stat
.
execute
(
"INSERT INTO E VALUES (1, '0A')"
);
stat
.
execute
(
"INSERT INTO E VALUES (1, '0A')"
);
...
@@ -83,7 +88,8 @@ public class TestCompatibilityOracle extends TestBase {
...
@@ -83,7 +88,8 @@ public class TestCompatibilityOracle extends TestBase {
assertResult
(
"2"
,
stat
,
"SELECT COUNT(*) FROM E"
);
assertResult
(
"2"
,
stat
,
"SELECT COUNT(*) FROM E"
);
assertResult
(
"1"
,
stat
,
"SELECT COUNT(*) FROM E WHERE X IS NULL"
);
assertResult
(
"1"
,
stat
,
"SELECT COUNT(*) FROM E WHERE X IS NULL"
);
assertResult
(
"0"
,
stat
,
"SELECT COUNT(*) FROM E WHERE X = ''"
);
assertResult
(
"0"
,
stat
,
"SELECT COUNT(*) FROM E WHERE X = ''"
);
assertResult
(
new
Object
[][]
{
{
1
,
new
byte
[]
{
10
}
},
{
2
,
null
}
},
stat
,
"SELECT * FROM E"
);
assertResult
(
new
Object
[][]
{
{
1
,
new
byte
[]
{
10
}
},
{
2
,
null
}
},
stat
,
"SELECT * FROM E"
);
conn
.
close
();
conn
.
close
();
}
}
...
@@ -98,16 +104,19 @@ public class TestCompatibilityOracle extends TestBase {
...
@@ -98,16 +104,19 @@ public class TestCompatibilityOracle extends TestBase {
stat
.
execute
(
"INSERT INTO A VALUES (2, 4.3)"
);
stat
.
execute
(
"INSERT INTO A VALUES (2, 4.3)"
);
stat
.
execute
(
"INSERT INTO A VALUES (3, '6.78')"
);
stat
.
execute
(
"INSERT INTO A VALUES (3, '6.78')"
);
assertResult
(
"3"
,
stat
,
"SELECT COUNT(*) FROM A"
);
assertResult
(
"3"
,
stat
,
"SELECT COUNT(*) FROM A"
);
assertResult
(
new
Object
[][]
{
{
1
,
2
},
{
2
,
4.3
},
{
3
,
6.78
}
},
stat
,
"SELECT * FROM A"
);
assertResult
(
new
Object
[][]
{
{
1
,
2
},
{
2
,
4.3
},
{
3
,
6.78
}
},
stat
,
"SELECT * FROM A"
);
conn
.
close
();
conn
.
close
();
}
}
private
void
assertResult
(
Object
[][]
expectedRowsOfValues
,
Statement
stat
,
String
sql
)
throws
SQLException
{
private
void
assertResult
(
Object
[][]
expectedRowsOfValues
,
Statement
stat
,
String
sql
)
throws
SQLException
{
assertResult
(
newSimpleResultSet
(
expectedRowsOfValues
),
stat
,
sql
);
assertResult
(
newSimpleResultSet
(
expectedRowsOfValues
),
stat
,
sql
);
}
}
private
void
assertResult
(
ResultSet
expected
,
Statement
stat
,
String
sql
)
throws
SQLException
{
private
void
assertResult
(
ResultSet
expected
,
Statement
stat
,
String
sql
)
throws
SQLException
{
ResultSet
actual
=
stat
.
executeQuery
(
sql
);
ResultSet
actual
=
stat
.
executeQuery
(
sql
);
int
expectedColumnCount
=
expected
.
getMetaData
().
getColumnCount
();
int
expectedColumnCount
=
expected
.
getMetaData
().
getColumnCount
();
assertEquals
(
expectedColumnCount
,
actual
.
getMetaData
().
getColumnCount
());
assertEquals
(
expectedColumnCount
,
actual
.
getMetaData
().
getColumnCount
());
...
...
h2/src/test/org/h2/test/db/TestCsv.java
浏览文件 @
b3836d31
...
@@ -75,11 +75,15 @@ public class TestCsv extends TestBase {
...
@@ -75,11 +75,15 @@ public class TestCsv extends TestBase {
private
void
testWriteColumnHeader
()
throws
Exception
{
private
void
testWriteColumnHeader
()
throws
Exception
{
Connection
conn
=
getConnection
(
"csv"
);
Connection
conn
=
getConnection
(
"csv"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"call csvwrite('"
+
getBaseDir
()
+
"/test.tsv', 'select x from dual', 'writeColumnHeader=false')"
);
stat
.
execute
(
"call csvwrite('"
+
getBaseDir
()
+
String
x
=
IOUtils
.
readStringAndClose
(
IOUtils
.
getReader
(
FileUtils
.
newInputStream
(
getBaseDir
()
+
"/test.tsv"
)),
-
1
);
"/test.tsv', 'select x from dual', 'writeColumnHeader=false')"
);
String
x
=
IOUtils
.
readStringAndClose
(
IOUtils
.
getReader
(
FileUtils
.
newInputStream
(
getBaseDir
()
+
"/test.tsv"
)),
-
1
);
assertEquals
(
"\"1\""
,
x
.
trim
());
assertEquals
(
"\"1\""
,
x
.
trim
());
stat
.
execute
(
"call csvwrite('"
+
getBaseDir
()
+
"/test.tsv', 'select x from dual', 'writeColumnHeader=true')"
);
stat
.
execute
(
"call csvwrite('"
+
getBaseDir
()
+
x
=
IOUtils
.
readStringAndClose
(
IOUtils
.
getReader
(
FileUtils
.
newInputStream
(
getBaseDir
()
+
"/test.tsv"
)),
-
1
);
"/test.tsv', 'select x from dual', 'writeColumnHeader=true')"
);
x
=
IOUtils
.
readStringAndClose
(
IOUtils
.
getReader
(
FileUtils
.
newInputStream
(
getBaseDir
()
+
"/test.tsv"
)),
-
1
);
x
=
x
.
trim
();
x
=
x
.
trim
();
assertTrue
(
x
.
startsWith
(
"\"X\""
));
assertTrue
(
x
.
startsWith
(
"\"X\""
));
assertTrue
(
x
.
endsWith
(
"\"1\""
));
assertTrue
(
x
.
endsWith
(
"\"1\""
));
...
@@ -94,7 +98,8 @@ public class TestCsv extends TestBase {
...
@@ -94,7 +98,8 @@ public class TestCsv extends TestBase {
StringWriter
writer
=
new
StringWriter
();
StringWriter
writer
=
new
StringWriter
();
Connection
conn
=
getConnection
(
"csv"
);
Connection
conn
=
getConnection
(
"csv"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
ResultSet
rs
=
stat
.
executeQuery
(
"select timestamp '-100-01-01 12:00:00.0' ts, null n"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select timestamp '-100-01-01 12:00:00.0' ts, null n"
);
Csv
csv
=
new
Csv
();
Csv
csv
=
new
Csv
();
csv
.
setFieldDelimiter
((
char
)
0
);
csv
.
setFieldDelimiter
((
char
)
0
);
csv
.
setLineSeparator
(
";"
);
csv
.
setLineSeparator
(
";"
);
...
@@ -106,19 +111,22 @@ public class TestCsv extends TestBase {
...
@@ -106,19 +111,22 @@ public class TestCsv extends TestBase {
}
}
private
void
testCaseSensitiveColumnNames
()
throws
Exception
{
private
void
testCaseSensitiveColumnNames
()
throws
Exception
{
OutputStream
out
=
FileUtils
.
newOutputStream
(
getBaseDir
()
+
"/test.tsv"
,
false
);
OutputStream
out
=
FileUtils
.
newOutputStream
(
getBaseDir
()
+
"/test.tsv"
,
false
);
out
.
write
(
"lower,Mixed,UPPER\n 1 , 2, 3 \n"
.
getBytes
());
out
.
write
(
"lower,Mixed,UPPER\n 1 , 2, 3 \n"
.
getBytes
());
out
.
close
();
out
.
close
();
Connection
conn
=
getConnection
(
"csv"
);
Connection
conn
=
getConnection
(
"csv"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
ResultSet
rs
;
ResultSet
rs
;
rs
=
stat
.
executeQuery
(
"select * from csvread('"
+
getBaseDir
()
+
"/test.tsv')"
);
rs
=
stat
.
executeQuery
(
"select * from csvread('"
+
getBaseDir
()
+
"/test.tsv')"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
"LOWER"
,
rs
.
getMetaData
().
getColumnName
(
1
));
assertEquals
(
"LOWER"
,
rs
.
getMetaData
().
getColumnName
(
1
));
assertEquals
(
"MIXED"
,
rs
.
getMetaData
().
getColumnName
(
2
));
assertEquals
(
"MIXED"
,
rs
.
getMetaData
().
getColumnName
(
2
));
assertEquals
(
"UPPER"
,
rs
.
getMetaData
().
getColumnName
(
3
));
assertEquals
(
"UPPER"
,
rs
.
getMetaData
().
getColumnName
(
3
));
rs
=
stat
.
executeQuery
(
"select * from csvread('"
+
getBaseDir
()
rs
=
stat
.
executeQuery
(
"select * from csvread('"
+
+
"/test.tsv', null, 'caseSensitiveColumnNames=true')"
);
getBaseDir
()
+
"/test.tsv', null, 'caseSensitiveColumnNames=true')"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
"lower"
,
rs
.
getMetaData
().
getColumnName
(
1
));
assertEquals
(
"lower"
,
rs
.
getMetaData
().
getColumnName
(
1
));
assertEquals
(
"Mixed"
,
rs
.
getMetaData
().
getColumnName
(
2
));
assertEquals
(
"Mixed"
,
rs
.
getMetaData
().
getColumnName
(
2
));
...
@@ -127,18 +135,20 @@ public class TestCsv extends TestBase {
...
@@ -127,18 +135,20 @@ public class TestCsv extends TestBase {
}
}
private
void
testPreserveWhitespace
()
throws
Exception
{
private
void
testPreserveWhitespace
()
throws
Exception
{
OutputStream
out
=
FileUtils
.
newOutputStream
(
getBaseDir
()
+
"/test.tsv"
,
false
);
OutputStream
out
=
FileUtils
.
newOutputStream
(
getBaseDir
()
+
"/test.tsv"
,
false
);
out
.
write
(
"a,b\n 1 , 2 \n"
.
getBytes
());
out
.
write
(
"a,b\n 1 , 2 \n"
.
getBytes
());
out
.
close
();
out
.
close
();
Connection
conn
=
getConnection
(
"csv"
);
Connection
conn
=
getConnection
(
"csv"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
ResultSet
rs
;
ResultSet
rs
;
rs
=
stat
.
executeQuery
(
"select * from csvread('"
+
getBaseDir
()
+
"/test.tsv')"
);
rs
=
stat
.
executeQuery
(
"select * from csvread('"
+
getBaseDir
()
+
"/test.tsv')"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
"1"
,
rs
.
getString
(
1
));
assertEquals
(
"1"
,
rs
.
getString
(
1
));
assertEquals
(
"2"
,
rs
.
getString
(
2
));
assertEquals
(
"2"
,
rs
.
getString
(
2
));
rs
=
stat
.
executeQuery
(
"select * from csvread('"
+
getBaseDir
()
rs
=
stat
.
executeQuery
(
"select * from csvread('"
+
+
"/test.tsv', null, 'preserveWhitespace=true')"
);
getBaseDir
()
+
"/test.tsv', null, 'preserveWhitespace=true')"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
" 1 "
,
rs
.
getString
(
1
));
assertEquals
(
" 1 "
,
rs
.
getString
(
1
));
assertEquals
(
" 2 "
,
rs
.
getString
(
2
));
assertEquals
(
" 2 "
,
rs
.
getString
(
2
));
...
@@ -146,12 +156,14 @@ public class TestCsv extends TestBase {
...
@@ -146,12 +156,14 @@ public class TestCsv extends TestBase {
}
}
private
void
testChangeData
()
throws
Exception
{
private
void
testChangeData
()
throws
Exception
{
OutputStream
out
=
FileUtils
.
newOutputStream
(
getBaseDir
()
+
"/test.tsv"
,
false
);
OutputStream
out
=
FileUtils
.
newOutputStream
(
getBaseDir
()
+
"/test.tsv"
,
false
);
out
.
write
(
"a,b,c,d,e,f,g\n1"
.
getBytes
());
out
.
write
(
"a,b,c,d,e,f,g\n1"
.
getBytes
());
out
.
close
();
out
.
close
();
Connection
conn
=
getConnection
(
"csv"
);
Connection
conn
=
getConnection
(
"csv"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
ResultSet
rs
=
stat
.
executeQuery
(
"select * from csvread('"
+
getBaseDir
()
+
"/test.tsv')"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select * from csvread('"
+
getBaseDir
()
+
"/test.tsv')"
);
assertEquals
(
7
,
rs
.
getMetaData
().
getColumnCount
());
assertEquals
(
7
,
rs
.
getMetaData
().
getColumnCount
());
assertEquals
(
"A"
,
rs
.
getMetaData
().
getColumnLabel
(
1
));
assertEquals
(
"A"
,
rs
.
getMetaData
().
getColumnLabel
(
1
));
rs
.
next
();
rs
.
next
();
...
@@ -159,7 +171,8 @@ public class TestCsv extends TestBase {
...
@@ -159,7 +171,8 @@ public class TestCsv extends TestBase {
out
=
FileUtils
.
newOutputStream
(
getBaseDir
()
+
"/test.tsv"
,
false
);
out
=
FileUtils
.
newOutputStream
(
getBaseDir
()
+
"/test.tsv"
,
false
);
out
.
write
(
"x"
.
getBytes
());
out
.
write
(
"x"
.
getBytes
());
out
.
close
();
out
.
close
();
rs
=
stat
.
executeQuery
(
"select * from csvread('"
+
getBaseDir
()
+
"/test.tsv')"
);
rs
=
stat
.
executeQuery
(
"select * from csvread('"
+
getBaseDir
()
+
"/test.tsv')"
);
assertEquals
(
1
,
rs
.
getMetaData
().
getColumnCount
());
assertEquals
(
1
,
rs
.
getMetaData
().
getColumnCount
());
assertEquals
(
"X"
,
rs
.
getMetaData
().
getColumnLabel
(
1
));
assertEquals
(
"X"
,
rs
.
getMetaData
().
getColumnLabel
(
1
));
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
...
@@ -192,8 +205,10 @@ public class TestCsv extends TestBase {
...
@@ -192,8 +205,10 @@ public class TestCsv extends TestBase {
assertFalse
(
csv
.
getPreserveWhitespace
());
assertFalse
(
csv
.
getPreserveWhitespace
());
assertFalse
(
csv
.
getCaseSensitiveColumnNames
());
assertFalse
(
csv
.
getCaseSensitiveColumnNames
());
charset
=
csv
.
setOptions
(
"escape=1x fieldDelimiter=2x fieldSeparator=3x "
+
"lineComment=4x lineSeparator=5x "
charset
=
csv
.
setOptions
(
"escape=1x fieldDelimiter=2x "
+
+
"null=6x rowSeparator=7x charset=8x preserveWhitespace=true caseSensitiveColumnNames=true"
);
"fieldSeparator=3x "
+
"lineComment=4x lineSeparator=5x "
+
"null=6x rowSeparator=7x charset=8x "
+
"preserveWhitespace=true caseSensitiveColumnNames=true"
);
assertEquals
(
'1'
,
csv
.
getEscapeCharacter
());
assertEquals
(
'1'
,
csv
.
getEscapeCharacter
());
assertEquals
(
'2'
,
csv
.
getFieldDelimiter
());
assertEquals
(
'2'
,
csv
.
getFieldDelimiter
());
assertEquals
(
'3'
,
csv
.
getFieldSeparatorRead
());
assertEquals
(
'3'
,
csv
.
getFieldSeparatorRead
());
...
@@ -206,8 +221,9 @@ public class TestCsv extends TestBase {
...
@@ -206,8 +221,9 @@ public class TestCsv extends TestBase {
assertTrue
(
csv
.
getPreserveWhitespace
());
assertTrue
(
csv
.
getPreserveWhitespace
());
assertTrue
(
csv
.
getCaseSensitiveColumnNames
());
assertTrue
(
csv
.
getCaseSensitiveColumnNames
());
charset
=
csv
.
setOptions
(
"escape= fieldDelimiter= fieldSeparator= "
+
"lineComment= lineSeparator=\r\n "
charset
=
csv
.
setOptions
(
"escape= fieldDelimiter= "
+
+
"null=\0 rowSeparator= charset="
);
"fieldSeparator= "
+
"lineComment= lineSeparator=\r\n "
+
"null=\0 rowSeparator= charset="
);
assertEquals
(
0
,
csv
.
getEscapeCharacter
());
assertEquals
(
0
,
csv
.
getEscapeCharacter
());
assertEquals
(
0
,
csv
.
getFieldDelimiter
());
assertEquals
(
0
,
csv
.
getFieldDelimiter
());
assertEquals
(
0
,
csv
.
getFieldSeparatorRead
());
assertEquals
(
0
,
csv
.
getFieldSeparatorRead
());
...
@@ -219,7 +235,8 @@ public class TestCsv extends TestBase {
...
@@ -219,7 +235,8 @@ public class TestCsv extends TestBase {
assertEquals
(
""
,
charset
);
assertEquals
(
""
,
charset
);
createClassProxy
(
Csv
.
class
);
createClassProxy
(
Csv
.
class
);
assertThrows
(
ErrorCode
.
FEATURE_NOT_SUPPORTED_1
,
csv
).
setOptions
(
"escape=a error=b"
);
assertThrows
(
ErrorCode
.
FEATURE_NOT_SUPPORTED_1
,
csv
).
setOptions
(
"escape=a error=b"
);
assertEquals
(
'a'
,
csv
.
getEscapeCharacter
());
assertEquals
(
'a'
,
csv
.
getEscapeCharacter
());
}
}
...
@@ -266,11 +283,15 @@ public class TestCsv extends TestBase {
...
@@ -266,11 +283,15 @@ public class TestCsv extends TestBase {
stat
.
execute
(
"create temporary table test (a int, b int, c int)"
);
stat
.
execute
(
"create temporary table test (a int, b int, c int)"
);
stat
.
execute
(
"insert into test values(1,2,3)"
);
stat
.
execute
(
"insert into test values(1,2,3)"
);
stat
.
execute
(
"insert into test values(4,null,5)"
);
stat
.
execute
(
"insert into test values(4,null,5)"
);
stat
.
execute
(
"call csvwrite('"
+
getBaseDir
()
+
"/test.tsv','select * from test',null,' ')"
);
stat
.
execute
(
"call csvwrite('"
+
getBaseDir
()
+
"/test.tsv','select * from test',null,' ')"
);
ResultSet
rs1
=
stat
.
executeQuery
(
"select * from test"
);
ResultSet
rs1
=
stat
.
executeQuery
(
"select * from test"
);
assertResultSetOrdered
(
rs1
,
new
String
[][]
{
new
String
[]
{
"1"
,
"2"
,
"3"
},
new
String
[]
{
"4"
,
null
,
"5"
}
});
assertResultSetOrdered
(
rs1
,
new
String
[][]
{
ResultSet
rs2
=
stat
.
executeQuery
(
"select * from csvread('"
+
getBaseDir
()
+
"/test.tsv',null,null,' ')"
);
new
String
[]
{
"1"
,
"2"
,
"3"
},
new
String
[]
{
"4"
,
null
,
"5"
}
});
assertResultSetOrdered
(
rs2
,
new
String
[][]
{
new
String
[]
{
"1"
,
"2"
,
"3"
},
new
String
[]
{
"4"
,
null
,
"5"
}
});
ResultSet
rs2
=
stat
.
executeQuery
(
"select * from csvread('"
+
getBaseDir
()
+
"/test.tsv',null,null,' ')"
);
assertResultSetOrdered
(
rs2
,
new
String
[][]
{
new
String
[]
{
"1"
,
"2"
,
"3"
},
new
String
[]
{
"4"
,
null
,
"5"
}
});
conn
.
close
();
conn
.
close
();
FileUtils
.
delete
(
f
.
getAbsolutePath
());
FileUtils
.
delete
(
f
.
getAbsolutePath
());
FileUtils
.
delete
(
getBaseDir
()
+
"/test.tsv"
);
FileUtils
.
delete
(
getBaseDir
()
+
"/test.tsv"
);
...
@@ -311,8 +332,10 @@ public class TestCsv extends TestBase {
...
@@ -311,8 +332,10 @@ public class TestCsv extends TestBase {
Connection
conn
=
getConnection
(
"csv"
);
Connection
conn
=
getConnection
(
"csv"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"call csvwrite('"
+
fileName
+
stat
.
execute
(
"call csvwrite('"
+
fileName
+
"', 'select NULL as a, '''' as b, ''\\N'' as c, NULL as d', 'UTF8', ',', '\"', NULL, '\\N', '\n')"
);
"', 'select NULL as a, '''' as b, ''\\N'' as c, NULL as d', "
+
InputStreamReader
reader
=
new
InputStreamReader
(
FileUtils
.
newInputStream
(
fileName
));
"'UTF8', ',', '\"', NULL, '\\N', '\n')"
);
InputStreamReader
reader
=
new
InputStreamReader
(
FileUtils
.
newInputStream
(
fileName
));
// on read, an empty string is treated like null,
// on read, an empty string is treated like null,
// but on write a null is always written with the nullString
// but on write a null is always written with the nullString
String
data
=
IOUtils
.
readStringAndClose
(
reader
,
-
1
);
String
data
=
IOUtils
.
readStringAndClose
(
reader
,
-
1
);
...
@@ -329,7 +352,8 @@ public class TestCsv extends TestBase {
...
@@ -329,7 +352,8 @@ public class TestCsv extends TestBase {
stat
.
execute
(
"drop table if exists test"
);
stat
.
execute
(
"drop table if exists test"
);
stat
.
execute
(
"create table test(a varchar, b varchar)"
);
stat
.
execute
(
"create table test(a varchar, b varchar)"
);
int
len
=
getSize
(
1000
,
10000
);
int
len
=
getSize
(
1000
,
10000
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"insert into test values(?, ?)"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"insert into test values(?, ?)"
);
ArrayList
<
String
[]>
list
=
New
.
arrayList
();
ArrayList
<
String
[]>
list
=
New
.
arrayList
();
Random
random
=
new
Random
(
1
);
Random
random
=
new
Random
(
1
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
...
@@ -339,7 +363,8 @@ public class TestCsv extends TestBase {
...
@@ -339,7 +363,8 @@ public class TestCsv extends TestBase {
list
.
add
(
new
String
[]
{
a
,
b
});
list
.
add
(
new
String
[]
{
a
,
b
});
prep
.
execute
();
prep
.
execute
();
}
}
stat
.
execute
(
"CALL CSVWRITE('"
+
getBaseDir
()
+
"/test.csv', 'SELECT * FROM test', 'UTF-8', '|', '#')"
);
stat
.
execute
(
"CALL CSVWRITE('"
+
getBaseDir
()
+
"/test.csv', 'SELECT * FROM test', 'UTF-8', '|', '#')"
);
Csv
csv
=
new
Csv
();
Csv
csv
=
new
Csv
();
csv
.
setFieldSeparatorRead
(
'|'
);
csv
.
setFieldSeparatorRead
(
'|'
);
csv
.
setFieldDelimiter
(
'#'
);
csv
.
setFieldDelimiter
(
'#'
);
...
@@ -375,11 +400,13 @@ public class TestCsv extends TestBase {
...
@@ -375,11 +400,13 @@ public class TestCsv extends TestBase {
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"call csvwrite('"
+
fileName
stat
.
execute
(
"call csvwrite('"
+
fileName
+
"', 'select 1 id, ''Hello'' name', null, '|', '', null, null, chr(10))"
);
+
"', 'select 1 id, ''Hello'' name', null, '|', '', null, null, chr(10))"
);
InputStreamReader
reader
=
new
InputStreamReader
(
FileUtils
.
newInputStream
(
fileName
));
InputStreamReader
reader
=
new
InputStreamReader
(
FileUtils
.
newInputStream
(
fileName
));
String
text
=
IOUtils
.
readStringAndClose
(
reader
,
-
1
).
trim
();
String
text
=
IOUtils
.
readStringAndClose
(
reader
,
-
1
).
trim
();
text
=
StringUtils
.
replaceAll
(
text
,
"\n"
,
" "
);
text
=
StringUtils
.
replaceAll
(
text
,
"\n"
,
" "
);
assertEquals
(
"ID|NAME 1|Hello"
,
text
);
assertEquals
(
"ID|NAME 1|Hello"
,
text
);
ResultSet
rs
=
stat
.
executeQuery
(
"select * from csvread('"
+
fileName
+
"', null, null, '|', '')"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select * from csvread('"
+
fileName
+
"', null, null, '|', '')"
);
ResultSetMetaData
meta
=
rs
.
getMetaData
();
ResultSetMetaData
meta
=
rs
.
getMetaData
();
assertEquals
(
2
,
meta
.
getColumnCount
());
assertEquals
(
2
,
meta
.
getColumnCount
());
assertEquals
(
"ID"
,
meta
.
getColumnLabel
(
1
));
assertEquals
(
"ID"
,
meta
.
getColumnLabel
(
1
));
...
@@ -402,7 +429,8 @@ public class TestCsv extends TestBase {
...
@@ -402,7 +429,8 @@ public class TestCsv extends TestBase {
out
.
close
();
out
.
close
();
Connection
conn
=
getConnection
(
"csv"
);
Connection
conn
=
getConnection
(
"csv"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
ResultSet
rs
=
stat
.
executeQuery
(
"select * from csvread('"
+
fileName
+
"', null, null, ';', '''', '\\')"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select * from csvread('"
+
fileName
+
"', null, null, ';', '''', '\\')"
);
ResultSetMetaData
meta
=
rs
.
getMetaData
();
ResultSetMetaData
meta
=
rs
.
getMetaData
();
assertEquals
(
2
,
meta
.
getColumnCount
());
assertEquals
(
2
,
meta
.
getColumnCount
());
assertEquals
(
"A"
,
meta
.
getColumnLabel
(
1
));
assertEquals
(
"A"
,
meta
.
getColumnLabel
(
1
));
...
@@ -433,8 +461,10 @@ public class TestCsv extends TestBase {
...
@@ -433,8 +461,10 @@ public class TestCsv extends TestBase {
deleteDb
(
"csv"
);
deleteDb
(
"csv"
);
Connection
conn
=
getConnection
(
"csv"
);
Connection
conn
=
getConnection
(
"csv"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"call csvwrite('"
+
getBaseDir
()
+
"/test.csv', 'select 1 id, ''Hello'' name', 'utf-8', '|')"
);
stat
.
execute
(
"call csvwrite('"
+
getBaseDir
()
+
ResultSet
rs
=
stat
.
executeQuery
(
"select * from csvread('"
+
getBaseDir
()
+
"/test.csv', null, 'utf-8', '|')"
);
"/test.csv', 'select 1 id, ''Hello'' name', 'utf-8', '|')"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select * from csvread('"
+
getBaseDir
()
+
"/test.csv', null, 'utf-8', '|')"
);
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
next
());
assertEquals
(
1
,
rs
.
getInt
(
1
));
assertEquals
(
1
,
rs
.
getInt
(
1
));
assertEquals
(
"Hello"
,
rs
.
getString
(
2
));
assertEquals
(
"Hello"
,
rs
.
getString
(
2
));
...
@@ -456,8 +486,10 @@ public class TestCsv extends TestBase {
...
@@ -456,8 +486,10 @@ public class TestCsv extends TestBase {
deleteDb
(
"csv"
);
deleteDb
(
"csv"
);
Connection
conn
=
getConnection
(
"csv"
);
Connection
conn
=
getConnection
(
"csv"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"call csvwrite('"
+
getBaseDir
()
+
"/test.csv', 'select 1 id, ''Hello'' name')"
);
stat
.
execute
(
"call csvwrite('"
+
getBaseDir
()
+
ResultSet
rs
=
stat
.
executeQuery
(
"select name from csvread('"
+
getBaseDir
()
+
"/test.csv')"
);
"/test.csv', 'select 1 id, ''Hello'' name')"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select name from csvread('"
+
getBaseDir
()
+
"/test.csv')"
);
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
next
());
assertEquals
(
"Hello"
,
rs
.
getString
(
1
));
assertEquals
(
"Hello"
,
rs
.
getString
(
1
));
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
...
@@ -474,7 +506,8 @@ public class TestCsv extends TestBase {
...
@@ -474,7 +506,8 @@ public class TestCsv extends TestBase {
String
fileName
=
getBaseDir
()
+
"/test.csv"
;
String
fileName
=
getBaseDir
()
+
"/test.csv"
;
FileUtils
.
delete
(
fileName
);
FileUtils
.
delete
(
fileName
);
OutputStream
out
=
FileUtils
.
newOutputStream
(
fileName
,
false
);
OutputStream
out
=
FileUtils
.
newOutputStream
(
fileName
,
false
);
byte
[]
b
=
"a,b,c,d\n201,-2,0,18\n, \"abc\"\"\" ,,\"\"\n 1 ,2 , 3, 4 \n5, 6, 7, 8"
.
getBytes
();
byte
[]
b
=
(
"a,b,c,d\n201,-2,0,18\n, \"abc\"\"\" ,"
+
",\"\"\n 1 ,2 , 3, 4 \n5, 6, 7, 8"
).
getBytes
();
out
.
write
(
b
,
0
,
b
.
length
);
out
.
write
(
b
,
0
,
b
.
length
);
out
.
close
();
out
.
close
();
ResultSet
rs
=
new
Csv
().
read
(
fileName
,
null
,
"UTF8"
);
ResultSet
rs
=
new
Csv
().
read
(
fileName
,
null
,
"UTF8"
);
...
...
h2/src/test/org/h2/test/db/TestDateStorage.java
浏览文件 @
b3836d31
...
@@ -64,7 +64,8 @@ public class TestDateStorage extends TestBase {
...
@@ -64,7 +64,8 @@ public class TestDateStorage extends TestBase {
TimeZone
.
setDefault
(
tz
);
TimeZone
.
setDefault
(
tz
);
DateTimeUtils
.
resetCalendar
();
DateTimeUtils
.
resetCalendar
();
conn
=
getConnection
(
db
);
conn
=
getConnection
(
db
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"insert into date_list values(?, ?, ?)"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"insert into date_list values(?, ?, ?)"
);
prep
.
setString
(
1
,
tz
.
getID
());
prep
.
setString
(
1
,
tz
.
getID
());
for
(
int
m
=
1
;
m
<
10
;
m
++)
{
for
(
int
m
=
1
;
m
<
10
;
m
++)
{
String
s
=
"2000-0"
+
m
+
"-01 15:00:00"
;
String
s
=
"2000-0"
+
m
+
"-01 15:00:00"
;
...
...
h2/src/test/org/h2/test/db/TestDeadlock.java
浏览文件 @
b3836d31
...
@@ -66,7 +66,8 @@ public class TestDeadlock extends TestBase {
...
@@ -66,7 +66,8 @@ public class TestDeadlock extends TestBase {
conn2
=
getConnection
(
url
);
conn2
=
getConnection
(
url
);
final
Statement
stat
=
conn
.
createStatement
();
final
Statement
stat
=
conn
.
createStatement
();
Statement
stat2
=
conn2
.
createStatement
();
Statement
stat2
=
conn2
.
createStatement
();
stat
.
execute
(
"create alias if not exists ft_init for \"org.h2.fulltext.FullText.init\""
);
stat
.
execute
(
"create alias if not exists ft_init for "
+
"\"org.h2.fulltext.FullText.init\""
);
stat
.
execute
(
"call ft_init()"
);
stat
.
execute
(
"call ft_init()"
);
stat
.
execute
(
"create table test(id int primary key, name varchar)"
);
stat
.
execute
(
"create table test(id int primary key, name varchar)"
);
stat
.
execute
(
"call ft_create_index('PUBLIC', 'TEST', null)"
);
stat
.
execute
(
"call ft_create_index('PUBLIC', 'TEST', null)"
);
...
...
h2/src/test/org/h2/test/db/TestDrop.java
浏览文件 @
b3836d31
...
@@ -57,7 +57,8 @@ public class TestDrop extends TestBase {
...
@@ -57,7 +57,8 @@ public class TestDrop extends TestBase {
stat
.
execute
(
"DROP ALL OBJECTS"
);
stat
.
execute
(
"DROP ALL OBJECTS"
);
stat
.
execute
(
"CREATE SCHEMA TEST_SCHEMA"
);
stat
.
execute
(
"CREATE SCHEMA TEST_SCHEMA"
);
stat
.
execute
(
"CREATE TABLE TEST_SCHEMA.A (A INT);"
);
stat
.
execute
(
"CREATE TABLE TEST_SCHEMA.A (A INT);"
);
stat
.
execute
(
"CREATE TABLE TEST_SCHEMA.B (B INT AS SELECT A FROM TEST_SCHEMA.A);"
);
stat
.
execute
(
"CREATE TABLE TEST_SCHEMA.B "
+
"(B INT AS SELECT A FROM TEST_SCHEMA.A);"
);
stat
.
execute
(
"DROP SCHEMA TEST_SCHEMA"
);
stat
.
execute
(
"DROP SCHEMA TEST_SCHEMA"
);
}
}
...
...
h2/src/test/org/h2/test/db/TestDuplicateKeyUpdate.java
浏览文件 @
b3836d31
...
@@ -80,29 +80,40 @@ public class TestDuplicateKeyUpdate extends TestBase {
...
@@ -80,29 +80,40 @@ public class TestDuplicateKeyUpdate extends TestBase {
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
ResultSet
rs
;
ResultSet
rs
;
stat
.
execute
(
"CREATE TABLE table_test2 (\n"
+
" id bigint(20) NOT NULL AUTO_INCREMENT,\n"
stat
.
execute
(
"CREATE TABLE table_test2 (\n"
+
" a_text varchar(254) NOT NULL,\n"
+
" some_text varchar(254) NOT NULL,\n"
+
" id bigint(20) NOT NULL AUTO_INCREMENT,\n"
+
" updatable_text varchar(254) NULL,\n"
+
" PRIMARY KEY (id)\n"
+
") ;"
);
+
" a_text varchar(254) NOT NULL,\n"
+
" some_text varchar(254) NOT NULL,\n"
stat
.
execute
(
"CREATE UNIQUE INDEX index_name \n"
+
"ON table_test2 (a_text, some_text);"
);
+
" updatable_text varchar(254) NULL,\n"
+
" PRIMARY KEY (id)\n"
+
") ;"
);
stat
.
execute
(
"INSERT INTO table_test2 ( a_text, some_text, updatable_text ) VALUES ('a', 'a', '1')"
);
stat
.
execute
(
"INSERT INTO table_test2 ( a_text, some_text, updatable_text ) VALUES ('b', 'b', '2')"
);
stat
.
execute
(
"CREATE UNIQUE INDEX index_name \n"
stat
.
execute
(
"INSERT INTO table_test2 ( a_text, some_text, updatable_text ) VALUES ('c', 'c', '3')"
);
+
"ON table_test2 (a_text, some_text);"
);
stat
.
execute
(
"INSERT INTO table_test2 ( a_text, some_text, updatable_text ) VALUES ('d', 'd', '4')"
);
stat
.
execute
(
"INSERT INTO table_test2 ( a_text, some_text, updatable_text ) VALUES ('e', 'e', '5')"
);
stat
.
execute
(
"INSERT INTO table_test2 "
+
"( a_text, some_text, updatable_text ) VALUES ('a', 'a', '1')"
);
stat
.
execute
(
"INSERT INTO table_test2 "
+
"( a_text, some_text, updatable_text ) VALUES ('b', 'b', '2')"
);
stat
.
execute
(
"INSERT INTO table_test2 "
+
"( a_text, some_text, updatable_text ) VALUES ('c', 'c', '3')"
);
stat
.
execute
(
"INSERT INTO table_test2 "
+
"( a_text, some_text, updatable_text ) VALUES ('d', 'd', '4')"
);
stat
.
execute
(
"INSERT INTO table_test2 "
+
"( a_text, some_text, updatable_text ) VALUES ('e', 'e', '5')"
);
stat
.
execute
(
"INSERT INTO table_test2 ( a_text, some_text ) "
+
stat
.
execute
(
"INSERT INTO table_test2 ( a_text, some_text ) "
+
"VALUES ('e', 'e') ON DUPLICATE KEY UPDATE updatable_text='UPDATE'"
);
"VALUES ('e', 'e') ON DUPLICATE KEY UPDATE updatable_text='UPDATE'"
);
rs
=
stat
.
executeQuery
(
"SELECT updatable_text FROM table_test2 where a_text = 'e'"
);
rs
=
stat
.
executeQuery
(
"SELECT updatable_text "
+
"FROM table_test2 where a_text = 'e'"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
"UPDATE"
,
rs
.
getNString
(
1
));
assertEquals
(
"UPDATE"
,
rs
.
getNString
(
1
));
stat
.
execute
(
"INSERT INTO table_test2 (a_text, some_text, updatable_text ) "
+
stat
.
execute
(
"INSERT INTO table_test2 (a_text, some_text, updatable_text ) "
+
"VALUES ('b', 'b', 'test') "
+
"VALUES ('b', 'b', 'test') "
+
"ON DUPLICATE KEY UPDATE updatable_text=values(updatable_text)"
);
"ON DUPLICATE KEY UPDATE updatable_text=values(updatable_text)"
);
rs
=
stat
.
executeQuery
(
"SELECT updatable_text FROM table_test2 where a_text = 'b'"
);
rs
=
stat
.
executeQuery
(
"SELECT updatable_text "
+
"FROM table_test2 where a_text = 'b'"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
"test"
,
rs
.
getNString
(
1
));
assertEquals
(
"test"
,
rs
.
getNString
(
1
));
}
}
...
@@ -154,16 +165,20 @@ public class TestDuplicateKeyUpdate extends TestBase {
...
@@ -154,16 +165,20 @@ public class TestDuplicateKeyUpdate extends TestBase {
stat
.
execute
(
"INSERT INTO table_test4 ( id, a_text, some_value ) "
+
stat
.
execute
(
"INSERT INTO table_test4 ( id, a_text, some_value ) "
+
"VALUES (2, 'aaaaaaaaaa', 5)"
);
"VALUES (2, 'aaaaaaaaaa', 5)"
);
stat
.
execute
(
"INSERT INTO table_test4 ( id , a_text, some_value ) VALUES (1, 'b', 1) "
+
stat
.
execute
(
"INSERT INTO table_test4 ( id , a_text, some_value ) "
+
"VALUES (1, 'b', 1) "
+
"ON DUPLICATE KEY UPDATE some_value=some_value + values(some_value)"
);
"ON DUPLICATE KEY UPDATE some_value=some_value + values(some_value)"
);
stat
.
execute
(
"INSERT INTO table_test4 ( id , a_text, some_value ) VALUES (1, 'b', 1) "
+
stat
.
execute
(
"INSERT INTO table_test4 ( id , a_text, some_value ) "
+
"VALUES (1, 'b', 1) "
+
"ON DUPLICATE KEY UPDATE some_value=some_value + 100"
);
"ON DUPLICATE KEY UPDATE some_value=some_value + 100"
);
stat
.
execute
(
"INSERT INTO table_test4 ( id , a_text, some_value ) VALUES (2, 'b', 1) "
+
stat
.
execute
(
"INSERT INTO table_test4 ( id , a_text, some_value ) "
+
"VALUES (2, 'b', 1) "
+
"ON DUPLICATE KEY UPDATE some_value=values(some_value) + 1"
);
"ON DUPLICATE KEY UPDATE some_value=values(some_value) + 1"
);
rs
=
stat
.
executeQuery
(
"SELECT some_value FROM table_test4 where id = 1"
);
rs
=
stat
.
executeQuery
(
"SELECT some_value FROM table_test4 where id = 1"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
106
,
rs
.
getInt
(
1
));
assertEquals
(
106
,
rs
.
getInt
(
1
));
rs
=
stat
.
executeQuery
(
"SELECT some_value FROM table_test4 where id = 2"
);
rs
=
stat
.
executeQuery
(
"SELECT some_value FROM table_test4 where id = 2"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
2
,
rs
.
getInt
(
1
));
assertEquals
(
2
,
rs
.
getInt
(
1
));
}
}
...
@@ -171,7 +186,8 @@ public class TestDuplicateKeyUpdate extends TestBase {
...
@@ -171,7 +186,8 @@ public class TestDuplicateKeyUpdate extends TestBase {
public
void
testOnDuplicateKeyInsertBatch
(
Connection
conn
)
public
void
testOnDuplicateKeyInsertBatch
(
Connection
conn
)
throws
SQLException
{
throws
SQLException
{
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test (key varchar(1) primary key, count int not null)"
);
stat
.
execute
(
"create table test "
+
"(key varchar(1) primary key, count int not null)"
);
// Insert multiple values as a batch
// Insert multiple values as a batch
for
(
int
i
=
0
;
i
<=
2
;
++
i
)
{
for
(
int
i
=
0
;
i
<=
2
;
++
i
)
{
...
@@ -191,7 +207,8 @@ public class TestDuplicateKeyUpdate extends TestBase {
...
@@ -191,7 +207,8 @@ public class TestDuplicateKeyUpdate extends TestBase {
}
}
// Check result
// Check result
ResultSet
rs
=
stat
.
executeQuery
(
"select count from test where key = 'a'"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select count from test where key = 'a'"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
3
,
rs
.
getInt
(
1
));
assertEquals
(
3
,
rs
.
getInt
(
1
));
...
@@ -201,7 +218,8 @@ public class TestDuplicateKeyUpdate extends TestBase {
...
@@ -201,7 +218,8 @@ public class TestDuplicateKeyUpdate extends TestBase {
public
void
testOnDuplicateKeyInsertMultiValue
(
Connection
conn
)
public
void
testOnDuplicateKeyInsertMultiValue
(
Connection
conn
)
throws
SQLException
{
throws
SQLException
{
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(key varchar(1) primary key, count int not null)"
);
stat
.
execute
(
"create table test"
+
"(key varchar(1) primary key, count int not null)"
);
// Insert multiple values in single insert operation
// Insert multiple values in single insert operation
for
(
int
i
=
0
;
i
<=
2
;
++
i
)
{
for
(
int
i
=
0
;
i
<=
2
;
++
i
)
{
...
...
h2/src/test/org/h2/test/db/TestFullText.java
浏览文件 @
b3836d31
...
@@ -32,8 +32,10 @@ public class TestFullText extends TestBase {
...
@@ -32,8 +32,10 @@ public class TestFullText extends TestBase {
/**
/**
* The words used in this test.
* The words used in this test.
*/
*/
static
final
String
[]
KNOWN_WORDS
=
{
"skiing"
,
"balance"
,
"storage"
,
"water"
,
"train"
};
static
final
String
[]
KNOWN_WORDS
=
{
"skiing"
,
"balance"
,
"storage"
,
private
static
final
String
LUCENE_FULLTEXT_CLASS_NAME
=
"org.h2.fulltext.FullTextLucene"
;
"water"
,
"train"
};
private
static
final
String
LUCENE_FULLTEXT_CLASS_NAME
=
"org.h2.fulltext.FullTextLucene"
;
/**
/**
* Run just this test.
* Run just this test.
...
@@ -89,7 +91,8 @@ public class TestFullText extends TestBase {
...
@@ -89,7 +91,8 @@ public class TestFullText extends TestBase {
}
}
}
}
private
Connection
getConnection
(
String
name
,
Collection
<
Connection
>
list
)
throws
SQLException
{
private
Connection
getConnection
(
String
name
,
Collection
<
Connection
>
list
)
throws
SQLException
{
Connection
conn
=
getConnection
(
name
);
Connection
conn
=
getConnection
(
name
);
list
.
add
(
conn
);
list
.
add
(
conn
);
return
conn
;
return
conn
;
...
@@ -104,7 +107,8 @@ public class TestFullText extends TestBase {
...
@@ -104,7 +107,8 @@ public class TestFullText extends TestBase {
conn
=
getConnection
(
"fullTextNative"
,
connList
);
conn
=
getConnection
(
"fullTextNative"
,
connList
);
stat
=
conn
.
createStatement
();
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create alias if not exists ft_init for \"org.h2.fulltext.FullText.init\""
);
stat
.
execute
(
"create alias if not exists ft_init "
+
"for \"org.h2.fulltext.FullText.init\""
);
stat
.
execute
(
"call ft_init()"
);
stat
.
execute
(
"call ft_init()"
);
stat
.
execute
(
"create table test(id int primary key, name varchar)"
);
stat
.
execute
(
"create table test(id int primary key, name varchar)"
);
stat
.
execute
(
"call ft_create_index('PUBLIC', 'TEST', 'NAME')"
);
stat
.
execute
(
"call ft_create_index('PUBLIC', 'TEST', 'NAME')"
);
...
@@ -124,7 +128,8 @@ public class TestFullText extends TestBase {
...
@@ -124,7 +128,8 @@ public class TestFullText extends TestBase {
ArrayList
<
Connection
>
connList
=
new
ArrayList
<
Connection
>();
ArrayList
<
Connection
>
connList
=
new
ArrayList
<
Connection
>();
Connection
conn
=
getConnection
(
"fullTextNative"
,
connList
);
Connection
conn
=
getConnection
(
"fullTextNative"
,
connList
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE ALIAS IF NOT EXISTS FT_INIT FOR \"org.h2.fulltext.FullText.init\""
);
stat
.
execute
(
"CREATE ALIAS IF NOT EXISTS FT_INIT "
+
"FOR \"org.h2.fulltext.FullText.init\""
);
stat
.
execute
(
"CALL FT_INIT()"
);
stat
.
execute
(
"CALL FT_INIT()"
);
FullText
.
setIgnoreList
(
conn
,
"to,this"
);
FullText
.
setIgnoreList
(
conn
,
"to,this"
);
FullText
.
setWhitespaceChars
(
conn
,
" ,.-"
);
FullText
.
setWhitespaceChars
(
conn
,
" ,.-"
);
...
@@ -184,13 +189,16 @@ public class TestFullText extends TestBase {
...
@@ -184,13 +189,16 @@ public class TestFullText extends TestBase {
String
id
=
UUID
.
randomUUID
().
toString
();
String
id
=
UUID
.
randomUUID
().
toString
();
stat
.
execute
(
"INSERT INTO TEST VALUES('"
+
id
+
"', 'Hello World')"
);
stat
.
execute
(
"INSERT INTO TEST VALUES('"
+
id
+
"', 'Hello World')"
);
stat
.
execute
(
"CALL "
+
prefix
+
"_CREATE_INDEX('PUBLIC', 'TEST', 'NAME')"
);
stat
.
execute
(
"CALL "
+
prefix
+
"_CREATE_INDEX('PUBLIC', 'TEST', 'NAME')"
);
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"_SEARCH('Hello', 0, 0)"
);
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"_SEARCH('Hello', 0, 0)"
);
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
next
());
stat
.
execute
(
"UPDATE TEST SET NAME=NULL WHERE ID='"
+
id
+
"'"
);
stat
.
execute
(
"UPDATE TEST SET NAME=NULL WHERE ID='"
+
id
+
"'"
);
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"_SEARCH('Hello', 0, 0)"
);
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"_SEARCH('Hello', 0, 0)"
);
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
stat
.
execute
(
"UPDATE TEST SET NAME='Good Bye' WHERE ID='"
+
id
+
"'"
);
stat
.
execute
(
"UPDATE TEST SET NAME='Good Bye' WHERE ID='"
+
id
+
"'"
);
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"_SEARCH('bye', 0, 0)"
);
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"_SEARCH('bye', 0, 0)"
);
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
next
());
FullText
.
dropAll
(
conn
);
FullText
.
dropAll
(
conn
);
conn
.
close
();
conn
.
close
();
...
@@ -208,7 +216,8 @@ public class TestFullText extends TestBase {
...
@@ -208,7 +216,8 @@ public class TestFullText extends TestBase {
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(1, 'Hello World')"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(1, 'Hello World')"
);
stat
.
execute
(
"CALL "
+
prefix
+
"_CREATE_INDEX('PUBLIC', 'TEST', NULL)"
);
stat
.
execute
(
"CALL "
+
prefix
+
"_CREATE_INDEX('PUBLIC', 'TEST', NULL)"
);
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"_SEARCH('Hello', 0, 0)"
);
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"_SEARCH('Hello', 0, 0)"
);
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
next
());
stat
.
execute
(
"UPDATE TEST SET NAME=NULL WHERE ID=1"
);
stat
.
execute
(
"UPDATE TEST SET NAME=NULL WHERE ID=1"
);
stat
.
execute
(
"UPDATE TEST SET NAME='Hello World' WHERE ID=1"
);
stat
.
execute
(
"UPDATE TEST SET NAME='Hello World' WHERE ID=1"
);
...
@@ -220,9 +229,11 @@ public class TestFullText extends TestBase {
...
@@ -220,9 +229,11 @@ public class TestFullText extends TestBase {
}
}
conn
=
getConnection
(
"fullTextTransaction"
,
connList
);
conn
=
getConnection
(
"fullTextTransaction"
,
connList
);
stat
=
conn
.
createStatement
();
stat
=
conn
.
createStatement
();
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"_SEARCH('Hello', 0, 0)"
);
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"_SEARCH('Hello', 0, 0)"
);
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
next
());
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"_SEARCH('Moon', 0, 0)"
);
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"_SEARCH('Moon', 0, 0)"
);
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
FullText
.
dropAll
(
conn
);
FullText
.
dropAll
(
conn
);
close
(
connList
);
close
(
connList
);
...
@@ -245,13 +256,16 @@ public class TestFullText extends TestBase {
...
@@ -245,13 +256,16 @@ public class TestFullText extends TestBase {
initFullText
(
stat
,
lucene
);
initFullText
(
stat
,
lucene
);
initFullText
(
stat
,
lucene
);
initFullText
(
stat
,
lucene
);
final
String
tableName
=
"TEST"
+
i
;
final
String
tableName
=
"TEST"
+
i
;
stat
.
execute
(
"CREATE TABLE "
+
tableName
+
"(ID INT PRIMARY KEY, DATA VARCHAR)"
);
stat
.
execute
(
"CREATE TABLE "
+
tableName
+
stat
.
execute
(
"CALL "
+
prefix
+
"_CREATE_INDEX('PUBLIC', '"
+
tableName
+
"', NULL)"
);
"(ID INT PRIMARY KEY, DATA VARCHAR)"
);
stat
.
execute
(
"CALL "
+
prefix
+
"_CREATE_INDEX('PUBLIC', '"
+
tableName
+
"', NULL)"
);
task
[
i
]
=
new
Task
()
{
task
[
i
]
=
new
Task
()
{
@Override
@Override
public
void
call
()
throws
SQLException
{
public
void
call
()
throws
SQLException
{
trace
(
"starting thread "
+
Thread
.
currentThread
());
trace
(
"starting thread "
+
Thread
.
currentThread
());
PreparedStatement
prep
=
conn
.
prepareStatement
(
"INSERT INTO "
+
tableName
+
" VALUES(?, ?)"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"INSERT INTO "
+
tableName
+
" VALUES(?, ?)"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
Random
random
=
new
Random
();
Random
random
=
new
Random
();
int
x
=
0
;
int
x
=
0
;
...
@@ -269,7 +283,8 @@ public class TestFullText extends TestBase {
...
@@ -269,7 +283,8 @@ public class TestFullText extends TestBase {
x
++;
x
++;
for
(
String
knownWord
:
KNOWN_WORDS
)
{
for
(
String
knownWord
:
KNOWN_WORDS
)
{
trace
(
"searching for "
+
knownWord
+
" with "
+
Thread
.
currentThread
());
trace
(
"searching for "
+
knownWord
+
" with "
+
Thread
.
currentThread
());
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"_SEARCH('"
+
knownWord
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"_SEARCH('"
+
knownWord
+
"', 0, 0)"
);
+
"', 0, 0)"
);
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
next
());
}
}
...
@@ -301,7 +316,8 @@ public class TestFullText extends TestBase {
...
@@ -301,7 +316,8 @@ public class TestFullText extends TestBase {
deleteDb
(
"fullText"
);
deleteDb
(
"fullText"
);
Connection
conn
=
getConnection
(
"fullText"
);
Connection
conn
=
getConnection
(
"fullText"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE ALIAS IF NOT EXISTS FT_INIT FOR \"org.h2.fulltext.FullText.init\""
);
stat
.
execute
(
"CREATE ALIAS IF NOT EXISTS FT_INIT "
+
"FOR \"org.h2.fulltext.FullText.init\""
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, DATA CLOB)"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, DATA CLOB)"
);
FullText
.
createIndex
(
conn
,
"PUBLIC"
,
"TEST"
,
null
);
FullText
.
createIndex
(
conn
,
"PUBLIC"
,
"TEST"
,
null
);
conn
.
setAutoCommit
(
false
);
conn
.
setAutoCommit
(
false
);
...
@@ -309,7 +325,8 @@ public class TestFullText extends TestBase {
...
@@ -309,7 +325,8 @@ public class TestFullText extends TestBase {
conn
.
rollback
();
conn
.
rollback
();
conn
.
setAutoCommit
(
true
);
conn
.
setAutoCommit
(
true
);
stat
.
execute
(
"insert into test values(0, 'Hello World!')"
);
stat
.
execute
(
"insert into test values(0, 'Hello World!')"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"insert into test values(1, ?)"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"insert into test values(1, ?)"
);
final
int
length
=
1024
*
1024
;
final
int
length
=
1024
*
1024
;
prep
.
setCharacterStream
(
1
,
new
Reader
()
{
prep
.
setCharacterStream
(
1
,
new
Reader
()
{
int
remaining
=
length
;
int
remaining
=
length
;
...
@@ -330,7 +347,8 @@ public class TestFullText extends TestBase {
...
@@ -330,7 +347,8 @@ public class TestFullText extends TestBase {
}
}
},
length
);
},
length
);
prep
.
execute
();
prep
.
execute
();
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM FT_SEARCH('World', 0, 0)"
);
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM FT_SEARCH('World', 0, 0)"
);
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
next
());
rs
=
stat
.
executeQuery
(
"SELECT * FROM FT_SEARCH('Moon', 0, 0)"
);
rs
=
stat
.
executeQuery
(
"SELECT * FROM FT_SEARCH('Moon', 0, 0)"
);
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
...
@@ -344,7 +362,8 @@ public class TestFullText extends TestBase {
...
@@ -344,7 +362,8 @@ public class TestFullText extends TestBase {
FileUtils
.
deleteRecursive
(
getBaseDir
()
+
"/fullText"
,
false
);
FileUtils
.
deleteRecursive
(
getBaseDir
()
+
"/fullText"
,
false
);
Connection
conn
=
getConnection
(
"fullText"
);
Connection
conn
=
getConnection
(
"fullText"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE ALIAS IF NOT EXISTS FT_INIT FOR \"org.h2.fulltext.FullText.init\""
);
stat
.
execute
(
"CREATE ALIAS IF NOT EXISTS FT_INIT "
+
"FOR \"org.h2.fulltext.FullText.init\""
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)"
);
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
FullText
.
createIndex
(
conn
,
"PUBLIC"
,
"TEST"
,
null
);
FullText
.
createIndex
(
conn
,
"PUBLIC"
,
"TEST"
,
null
);
...
@@ -355,18 +374,24 @@ public class TestFullText extends TestBase {
...
@@ -355,18 +374,24 @@ public class TestFullText extends TestBase {
FileUtils
.
deleteRecursive
(
getBaseDir
()
+
"/fullText"
,
false
);
FileUtils
.
deleteRecursive
(
getBaseDir
()
+
"/fullText"
,
false
);
}
}
private
void
testCreateDropLucene
()
throws
SQLException
,
SecurityException
,
NoSuchMethodException
,
private
void
testCreateDropLucene
()
throws
SQLException
,
SecurityException
,
ClassNotFoundException
,
IllegalArgumentException
,
IllegalAccessException
,
InvocationTargetException
{
NoSuchMethodException
,
ClassNotFoundException
,
IllegalArgumentException
,
IllegalAccessException
,
InvocationTargetException
{
deleteDb
(
"fullText"
);
deleteDb
(
"fullText"
);
FileUtils
.
deleteRecursive
(
getBaseDir
()
+
"/fullText"
,
false
);
FileUtils
.
deleteRecursive
(
getBaseDir
()
+
"/fullText"
,
false
);
Connection
conn
=
getConnection
(
"fullText"
);
Connection
conn
=
getConnection
(
"fullText"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
initFullText
(
stat
,
true
);
initFullText
(
stat
,
true
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)"
);
Method
createIndexMethod
=
Class
.
forName
(
LUCENE_FULLTEXT_CLASS_NAME
).
getMethod
(
"createIndex"
,
Method
createIndexMethod
=
Class
.
forName
(
new
Class
[]
{
java
.
sql
.
Connection
.
class
,
String
.
class
,
String
.
class
,
String
.
class
});
LUCENE_FULLTEXT_CLASS_NAME
).
getMethod
(
"createIndex"
,
Method
dropIndexMethod
=
Class
.
forName
(
LUCENE_FULLTEXT_CLASS_NAME
).
getMethod
(
"dropIndex"
,
new
Class
[]
{
java
.
sql
.
Connection
.
class
,
new
Class
[]
{
java
.
sql
.
Connection
.
class
,
String
.
class
,
String
.
class
});
String
.
class
,
String
.
class
,
String
.
class
});
Method
dropIndexMethod
=
Class
.
forName
(
LUCENE_FULLTEXT_CLASS_NAME
).
getMethod
(
"dropIndex"
,
new
Class
[]
{
java
.
sql
.
Connection
.
class
,
String
.
class
,
String
.
class
});
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
createIndexMethod
.
invoke
(
null
,
conn
,
"PUBLIC"
,
"TEST"
,
null
);
createIndexMethod
.
invoke
(
null
,
conn
,
"PUBLIC"
,
"TEST"
,
null
);
dropIndexMethod
.
invoke
(
null
,
conn
,
"PUBLIC"
,
"TEST"
);
dropIndexMethod
.
invoke
(
null
,
conn
,
"PUBLIC"
,
"TEST"
);
...
@@ -395,7 +420,8 @@ public class TestFullText extends TestBase {
...
@@ -395,7 +420,8 @@ public class TestFullText extends TestBase {
conn
=
getConnection
(
"fullTextReopen"
);
conn
=
getConnection
(
"fullTextReopen"
);
stat
=
conn
.
createStatement
();
stat
=
conn
.
createStatement
();
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"_SEARCH('Hello', 0, 0)"
);
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"_SEARCH('Hello', 0, 0)"
);
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
next
());
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"_SEARCH(NULL, 0, 0)"
);
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"_SEARCH(NULL, 0, 0)"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(2, NULL)"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(2, NULL)"
);
...
@@ -417,19 +443,22 @@ public class TestFullText extends TestBase {
...
@@ -417,19 +443,22 @@ public class TestFullText extends TestBase {
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
initFullText
(
stat
,
lucene
);
initFullText
(
stat
,
lucene
);
stat
.
execute
(
"DROP TABLE IF EXISTS TEST"
);
stat
.
execute
(
"DROP TABLE IF EXISTS TEST"
);
stat
.
execute
(
"CREATE TABLE TEST AS SELECT * FROM INFORMATION_SCHEMA.HELP"
);
stat
.
execute
(
"CREATE TABLE TEST AS SELECT * FROM INFORMATION_SCHEMA.HELP"
);
stat
.
execute
(
"ALTER TABLE TEST ALTER COLUMN ID INT NOT NULL"
);
stat
.
execute
(
"ALTER TABLE TEST ALTER COLUMN ID INT NOT NULL"
);
stat
.
execute
(
"CREATE PRIMARY KEY ON TEST(ID)"
);
stat
.
execute
(
"CREATE PRIMARY KEY ON TEST(ID)"
);
long
time
=
System
.
currentTimeMillis
();
long
time
=
System
.
currentTimeMillis
();
stat
.
execute
(
"CALL "
+
prefix
+
"_CREATE_INDEX('PUBLIC', 'TEST', NULL)"
);
stat
.
execute
(
"CALL "
+
prefix
+
"_CREATE_INDEX('PUBLIC', 'TEST', NULL)"
);
println
(
"create "
+
prefix
+
": "
+
(
System
.
currentTimeMillis
()
-
time
));
println
(
"create "
+
prefix
+
": "
+
(
System
.
currentTimeMillis
()
-
time
));
PreparedStatement
prep
=
conn
.
prepareStatement
(
"SELECT * FROM "
+
prefix
+
"_SEARCH(?, 0, 0)"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"SELECT * FROM "
+
prefix
+
"_SEARCH(?, 0, 0)"
);
time
=
System
.
currentTimeMillis
();
time
=
System
.
currentTimeMillis
();
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT TEXT FROM TEST"
);
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT TEXT FROM TEST"
);
int
count
=
0
;
int
count
=
0
;
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
String
text
=
rs
.
getString
(
1
);
String
text
=
rs
.
getString
(
1
);
StringTokenizer
tokenizer
=
new
StringTokenizer
(
text
,
" ()[].,;:-+*/!?=<>{}#@'\"~$_%&|"
);
StringTokenizer
tokenizer
=
new
StringTokenizer
(
text
,
" ()[].,;:-+*/!?=<>{}#@'\"~$_%&|"
);
while
(
tokenizer
.
hasMoreTokens
())
{
while
(
tokenizer
.
hasMoreTokens
())
{
String
word
=
tokenizer
.
nextToken
();
String
word
=
tokenizer
.
nextToken
();
if
(
word
.
length
()
<
10
)
{
if
(
word
.
length
()
<
10
)
{
...
@@ -443,7 +472,8 @@ public class TestFullText extends TestBase {
...
@@ -443,7 +472,8 @@ public class TestFullText extends TestBase {
}
}
}
}
}
}
println
(
"search "
+
prefix
+
": "
+
(
System
.
currentTimeMillis
()
-
time
)
+
" count: "
+
count
);
println
(
"search "
+
prefix
+
": "
+
(
System
.
currentTimeMillis
()
-
time
)
+
" count: "
+
count
);
stat
.
execute
(
"CALL "
+
prefix
+
"_DROP_ALL()"
);
stat
.
execute
(
"CALL "
+
prefix
+
"_DROP_ALL()"
);
conn
.
close
();
conn
.
close
();
}
}
...
@@ -458,35 +488,42 @@ public class TestFullText extends TestBase {
...
@@ -458,35 +488,42 @@ public class TestFullText extends TestBase {
String
prefix
=
lucene
?
"FTL_"
:
"FT_"
;
String
prefix
=
lucene
?
"FTL_"
:
"FT_"
;
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
String
className
=
lucene
?
"FullTextLucene"
:
"FullText"
;
String
className
=
lucene
?
"FullTextLucene"
:
"FullText"
;
stat
.
execute
(
"CREATE ALIAS IF NOT EXISTS "
+
prefix
+
"INIT FOR \"org.h2.fulltext."
+
className
+
".init\""
);
stat
.
execute
(
"CREATE ALIAS IF NOT EXISTS "
+
prefix
+
"INIT FOR \"org.h2.fulltext."
+
className
+
".init\""
);
stat
.
execute
(
"CALL "
+
prefix
+
"INIT()"
);
stat
.
execute
(
"CALL "
+
prefix
+
"INIT()"
);
stat
.
execute
(
"DROP TABLE IF EXISTS TEST"
);
stat
.
execute
(
"DROP TABLE IF EXISTS TEST"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME "
+
dataType
+
")"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME "
+
dataType
+
")"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(1, 'Hello World')"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(1, 'Hello World')"
);
stat
.
execute
(
"CALL "
+
prefix
+
"CREATE_INDEX('PUBLIC', 'TEST', NULL)"
);
stat
.
execute
(
"CALL "
+
prefix
+
"CREATE_INDEX('PUBLIC', 'TEST', NULL)"
);
ResultSet
rs
;
ResultSet
rs
;
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"SEARCH('Hello', 0, 0)"
);
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"SEARCH('Hello', 0, 0)"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
"\"PUBLIC\".\"TEST\" WHERE \"ID\"=1"
,
rs
.
getString
(
1
));
assertEquals
(
"\"PUBLIC\".\"TEST\" WHERE \"ID\"=1"
,
rs
.
getString
(
1
));
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"SEARCH('Hallo', 0, 0)"
);
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"SEARCH('Hallo', 0, 0)"
);
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
stat
.
execute
(
"INSERT INTO TEST VALUES(2, 'Hallo Welt')"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(2, 'Hallo Welt')"
);
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"SEARCH('Hello', 0, 0)"
);
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"SEARCH('Hello', 0, 0)"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
"\"PUBLIC\".\"TEST\" WHERE \"ID\"=1"
,
rs
.
getString
(
1
));
assertEquals
(
"\"PUBLIC\".\"TEST\" WHERE \"ID\"=1"
,
rs
.
getString
(
1
));
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"SEARCH('Hallo', 0, 0)"
);
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"SEARCH('Hallo', 0, 0)"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
"\"PUBLIC\".\"TEST\" WHERE \"ID\"=2"
,
rs
.
getString
(
1
));
assertEquals
(
"\"PUBLIC\".\"TEST\" WHERE \"ID\"=2"
,
rs
.
getString
(
1
));
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
stat
.
execute
(
"CALL "
+
prefix
+
"REINDEX()"
);
stat
.
execute
(
"CALL "
+
prefix
+
"REINDEX()"
);
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"SEARCH('Hello', 0, 0)"
);
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"SEARCH('Hello', 0, 0)"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
"\"PUBLIC\".\"TEST\" WHERE \"ID\"=1"
,
rs
.
getString
(
1
));
assertEquals
(
"\"PUBLIC\".\"TEST\" WHERE \"ID\"=1"
,
rs
.
getString
(
1
));
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"SEARCH('Hallo', 0, 0)"
);
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"SEARCH('Hallo', 0, 0)"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
"\"PUBLIC\".\"TEST\" WHERE \"ID\"=2"
,
rs
.
getString
(
1
));
assertEquals
(
"\"PUBLIC\".\"TEST\" WHERE \"ID\"=2"
,
rs
.
getString
(
1
));
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
...
@@ -495,7 +532,8 @@ public class TestFullText extends TestBase {
...
@@ -495,7 +532,8 @@ public class TestFullText extends TestBase {
stat
.
execute
(
"INSERT INTO TEST VALUES(4, 'Hello World')"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(4, 'Hello World')"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(5, 'Hello World')"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(5, 'Hello World')"
);
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"SEARCH('World', 0, 0) ORDER BY QUERY"
);
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"SEARCH('World', 0, 0) ORDER BY QUERY"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
"\"PUBLIC\".\"TEST\" WHERE \"ID\"=1"
,
rs
.
getString
(
1
));
assertEquals
(
"\"PUBLIC\".\"TEST\" WHERE \"ID\"=1"
,
rs
.
getString
(
1
));
rs
.
next
();
rs
.
next
();
...
@@ -506,32 +544,37 @@ public class TestFullText extends TestBase {
...
@@ -506,32 +544,37 @@ public class TestFullText extends TestBase {
assertEquals
(
"\"PUBLIC\".\"TEST\" WHERE \"ID\"=5"
,
rs
.
getString
(
1
));
assertEquals
(
"\"PUBLIC\".\"TEST\" WHERE \"ID\"=5"
,
rs
.
getString
(
1
));
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"SEARCH('World', 1, 0)"
);
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"SEARCH('World', 1, 0)"
);
rs
.
next
();
rs
.
next
();
assertTrue
(
rs
.
getString
(
1
).
startsWith
(
"\"PUBLIC\".\"TEST\" WHERE \"ID\"="
));
assertTrue
(
rs
.
getString
(
1
).
startsWith
(
"\"PUBLIC\".\"TEST\" WHERE \"ID\"="
));
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"SEARCH('World', 0, 2) ORDER BY QUERY"
);
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"SEARCH('World', 0, 2) ORDER BY QUERY"
);
rs
.
next
();
rs
.
next
();
assertTrue
(
rs
.
getString
(
1
).
startsWith
(
"\"PUBLIC\".\"TEST\" WHERE \"ID\"="
));
assertTrue
(
rs
.
getString
(
1
).
startsWith
(
"\"PUBLIC\".\"TEST\" WHERE \"ID\"="
));
rs
.
next
();
rs
.
next
();
assertTrue
(
rs
.
getString
(
1
).
startsWith
(
"\"PUBLIC\".\"TEST\" WHERE \"ID\"="
));
assertTrue
(
rs
.
getString
(
1
).
startsWith
(
"\"PUBLIC\".\"TEST\" WHERE \"ID\"="
));
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"SEARCH('World', 2, 1) ORDER BY QUERY"
);
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"SEARCH('World', 2, 1) ORDER BY QUERY"
);
rs
.
next
();
rs
.
next
();
assertTrue
(
rs
.
getString
(
1
).
startsWith
(
"\"PUBLIC\".\"TEST\" WHERE \"ID\"="
));
assertTrue
(
rs
.
getString
(
1
).
startsWith
(
"\"PUBLIC\".\"TEST\" WHERE \"ID\"="
));
rs
.
next
();
rs
.
next
();
assertTrue
(
rs
.
getString
(
1
).
startsWith
(
"\"PUBLIC\".\"TEST\" WHERE \"ID\"="
));
assertTrue
(
rs
.
getString
(
1
).
startsWith
(
"\"PUBLIC\".\"TEST\" WHERE \"ID\"="
));
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"SEARCH('1', 0, 0)"
);
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"SEARCH('1', 0, 0)"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
"\"PUBLIC\".\"TEST\" WHERE \"ID\"=1"
,
rs
.
getString
(
1
));
assertEquals
(
"\"PUBLIC\".\"TEST\" WHERE \"ID\"=1"
,
rs
.
getString
(
1
));
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
if
(
lucene
)
{
if
(
lucene
)
{
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"SEARCH('NAME:Hallo', 0, 0)"
);
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
prefix
+
"SEARCH('NAME:Hallo', 0, 0)"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
"\"PUBLIC\".\"TEST\" WHERE \"ID\"=2"
,
rs
.
getString
(
1
));
assertEquals
(
"\"PUBLIC\".\"TEST\" WHERE \"ID\"=2"
,
rs
.
getString
(
1
));
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
...
@@ -560,13 +603,18 @@ public class TestFullText extends TestBase {
...
@@ -560,13 +603,18 @@ public class TestFullText extends TestBase {
Connection
conn
=
getConnection
(
"fullTextDropIndex"
);
Connection
conn
=
getConnection
(
"fullTextDropIndex"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
initFullText
(
stat
,
lucene
);
initFullText
(
stat
,
lucene
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME1 VARCHAR, NAME2 VARCHAR)"
);
stat
.
execute
(
"CREATE TABLE TEST"
+
stat
.
execute
(
"INSERT INTO TEST VALUES(1, 'Hello World', 'Hello Again')"
);
"(ID INT PRIMARY KEY, NAME1 VARCHAR, NAME2 VARCHAR)"
);
stat
.
execute
(
"CALL "
+
prefix
+
"_CREATE_INDEX('PUBLIC', 'TEST', 'NAME1')"
);
stat
.
execute
(
"INSERT INTO TEST VALUES"
+
"(1, 'Hello World', 'Hello Again')"
);
stat
.
execute
(
"CALL "
+
prefix
+
"_CREATE_INDEX('PUBLIC', 'TEST', 'NAME1')"
);
stat
.
execute
(
"UPDATE TEST SET NAME1=NULL WHERE ID=1"
);
stat
.
execute
(
"UPDATE TEST SET NAME1=NULL WHERE ID=1"
);
stat
.
execute
(
"UPDATE TEST SET NAME1='Hello World' WHERE ID=1"
);
stat
.
execute
(
"UPDATE TEST SET NAME1='Hello World' WHERE ID=1"
);
stat
.
execute
(
"CALL "
+
prefix
+
"_DROP_INDEX('PUBLIC', 'TEST')"
);
stat
.
execute
(
"CALL "
+
prefix
+
stat
.
execute
(
"CALL "
+
prefix
+
"_CREATE_INDEX('PUBLIC', 'TEST', 'NAME1, NAME2')"
);
"_DROP_INDEX('PUBLIC', 'TEST')"
);
stat
.
execute
(
"CALL "
+
prefix
+
"_CREATE_INDEX('PUBLIC', 'TEST', 'NAME1, NAME2')"
);
stat
.
execute
(
"UPDATE TEST SET NAME2=NULL WHERE ID=1"
);
stat
.
execute
(
"UPDATE TEST SET NAME2=NULL WHERE ID=1"
);
stat
.
execute
(
"UPDATE TEST SET NAME2='Hello World' WHERE ID=1"
);
stat
.
execute
(
"UPDATE TEST SET NAME2='Hello World' WHERE ID=1"
);
conn
.
close
();
conn
.
close
();
...
@@ -575,10 +623,12 @@ public class TestFullText extends TestBase {
...
@@ -575,10 +623,12 @@ public class TestFullText extends TestBase {
FileUtils
.
deleteRecursive
(
getBaseDir
()
+
"/fullTextDropIndex"
,
false
);
FileUtils
.
deleteRecursive
(
getBaseDir
()
+
"/fullTextDropIndex"
,
false
);
}
}
private
static
void
initFullText
(
Statement
stat
,
boolean
lucene
)
throws
SQLException
{
private
static
void
initFullText
(
Statement
stat
,
boolean
lucene
)
throws
SQLException
{
String
prefix
=
lucene
?
"FTL"
:
"FT"
;
String
prefix
=
lucene
?
"FTL"
:
"FT"
;
String
className
=
lucene
?
"FullTextLucene"
:
"FullText"
;
String
className
=
lucene
?
"FullTextLucene"
:
"FullText"
;
stat
.
execute
(
"CREATE ALIAS IF NOT EXISTS "
+
prefix
+
"_INIT FOR \"org.h2.fulltext."
+
className
+
".init\""
);
stat
.
execute
(
"CREATE ALIAS IF NOT EXISTS "
+
prefix
+
"_INIT FOR \"org.h2.fulltext."
+
className
+
".init\""
);
stat
.
execute
(
"CALL "
+
prefix
+
"_INIT()"
);
stat
.
execute
(
"CALL "
+
prefix
+
"_INIT()"
);
}
}
}
}
h2/src/test/org/h2/test/db/TestFunctionOverload.java
浏览文件 @
b3836d31
...
@@ -89,7 +89,8 @@ public class TestFunctionOverload extends TestBase {
...
@@ -89,7 +89,8 @@ public class TestFunctionOverload extends TestBase {
private
void
testOverloadNamedArgs
()
throws
SQLException
{
private
void
testOverloadNamedArgs
()
throws
SQLException
{
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create alias overload1or2Named for \""
+
ME
+
".overload1or2(int)\""
);
stat
.
execute
(
"create alias overload1or2Named for \""
+
ME
+
".overload1or2(int)\""
);
ResultSet
rs
=
stat
.
executeQuery
(
"select overload1or2Named(1) from dual"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select overload1or2Named(1) from dual"
);
assertTrue
(
"First Row"
,
rs
.
next
());
assertTrue
(
"First Row"
,
rs
.
next
());
...
@@ -104,7 +105,8 @@ public class TestFunctionOverload extends TestBase {
...
@@ -104,7 +105,8 @@ public class TestFunctionOverload extends TestBase {
private
void
testOverloadWithConnection
()
throws
SQLException
{
private
void
testOverloadWithConnection
()
throws
SQLException
{
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create alias overload1or2WithConn for \""
+
ME
+
".overload1or2WithConn\""
);
stat
.
execute
(
"create alias overload1or2WithConn for \""
+
ME
+
".overload1or2WithConn\""
);
ResultSet
rs
=
stat
.
executeQuery
(
"select overload1or2WithConn(1) from dual"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select overload1or2WithConn(1) from dual"
);
rs
.
next
();
rs
.
next
();
...
@@ -158,7 +160,8 @@ public class TestFunctionOverload extends TestBase {
...
@@ -158,7 +160,8 @@ public class TestFunctionOverload extends TestBase {
* @param one the value
* @param one the value
* @return the value
* @return the value
*/
*/
public
static
int
overload1or2WithConn
(
Connection
conn
,
int
one
)
throws
SQLException
{
public
static
int
overload1or2WithConn
(
Connection
conn
,
int
one
)
throws
SQLException
{
conn
.
createStatement
().
executeQuery
(
"select 1 from dual"
);
conn
.
createStatement
().
executeQuery
(
"select 1 from dual"
);
return
one
;
return
one
;
}
}
...
...
h2/src/test/org/h2/test/db/TestFunctions.java
浏览文件 @
b3836d31
...
@@ -116,8 +116,10 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -116,8 +116,10 @@ public class TestFunctions extends TestBase implements AggregateFunction {
private
void
testFunctionTable
()
throws
SQLException
{
private
void
testFunctionTable
()
throws
SQLException
{
Connection
conn
=
getConnection
(
"functions"
);
Connection
conn
=
getConnection
(
"functions"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create alias simple_function_table for \""
+
TestFunctions
.
class
.
getName
()
+
".simpleFunctionTable\""
);
stat
.
execute
(
"create alias simple_function_table for \""
+
stat
.
execute
(
"select * from simple_function_table() where a>0 and b in ('x', 'y')"
);
TestFunctions
.
class
.
getName
()
+
".simpleFunctionTable\""
);
stat
.
execute
(
"select * from simple_function_table() "
+
"where a>0 and b in ('x', 'y')"
);
conn
.
close
();
conn
.
close
();
}
}
...
@@ -139,17 +141,26 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -139,17 +141,26 @@ public class TestFunctions extends TestBase implements AggregateFunction {
Connection
conn
=
getConnection
(
"functions"
);
Connection
conn
=
getConnection
(
"functions"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
String
createSQL
=
"CREATE TABLE testNvl2(id BIGINT, txt1 varchar, txt2 varchar, num number(9, 0));"
;
String
createSQL
=
"CREATE TABLE testNvl2(id BIGINT, txt1 "
+
"varchar, txt2 varchar, num number(9, 0));"
;
stat
.
execute
(
createSQL
);
stat
.
execute
(
createSQL
);
stat
.
execute
(
"insert into testNvl2(id, txt1, txt2, num) values(1, 'test1', 'test2', null)"
);
stat
.
execute
(
"insert into testNvl2(id, txt1, txt2, num) "
+
stat
.
execute
(
"insert into testNvl2(id, txt1, txt2, num) values(2, null, 'test4', null)"
);
"values(1, 'test1', 'test2', null)"
);
stat
.
execute
(
"insert into testNvl2(id, txt1, txt2, num) values(3, 'test5', null, null)"
);
stat
.
execute
(
"insert into testNvl2(id, txt1, txt2, num) "
+
stat
.
execute
(
"insert into testNvl2(id, txt1, txt2, num) values(4, null, null, null)"
);
"values(2, null, 'test4', null)"
);
stat
.
execute
(
"insert into testNvl2(id, txt1, txt2, num) values(5, '2', null, 1)"
);
stat
.
execute
(
"insert into testNvl2(id, txt1, txt2, num) "
+
stat
.
execute
(
"insert into testNvl2(id, txt1, txt2, num) values(6, '2', null, null)"
);
"values(3, 'test5', null, null)"
);
stat
.
execute
(
"insert into testNvl2(id, txt1, txt2, num) values(7, 'test2', null, null)"
);
stat
.
execute
(
"insert into testNvl2(id, txt1, txt2, num) "
+
"values(4, null, null, null)"
);
String
query
=
"SELECT NVL2(txt1, txt1, txt2), txt1 FROM testNvl2 order by id asc"
;
stat
.
execute
(
"insert into testNvl2(id, txt1, txt2, num) "
+
"values(5, '2', null, 1)"
);
stat
.
execute
(
"insert into testNvl2(id, txt1, txt2, num) "
+
"values(6, '2', null, null)"
);
stat
.
execute
(
"insert into testNvl2(id, txt1, txt2, num) "
+
"values(7, 'test2', null, null)"
);
String
query
=
"SELECT NVL2(txt1, txt1, txt2), txt1 "
+
"FROM testNvl2 order by id asc"
;
ResultSet
rs
=
stat
.
executeQuery
(
query
);
ResultSet
rs
=
stat
.
executeQuery
(
query
);
rs
.
next
();
rs
.
next
();
String
actual
=
rs
.
getString
(
1
);
String
actual
=
rs
.
getString
(
1
);
...
@@ -163,22 +174,27 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -163,22 +174,27 @@ public class TestFunctions extends TestBase implements AggregateFunction {
rs
.
next
();
rs
.
next
();
actual
=
rs
.
getString
(
1
);
actual
=
rs
.
getString
(
1
);
assertEquals
(
null
,
actual
);
assertEquals
(
null
,
actual
);
assertEquals
(
rs
.
getMetaData
().
getColumnType
(
2
),
rs
.
getMetaData
().
getColumnType
(
1
));
assertEquals
(
rs
.
getMetaData
().
getColumnType
(
2
),
rs
.
getMetaData
().
getColumnType
(
1
));
rs
.
close
();
rs
.
close
();
rs
=
stat
.
executeQuery
(
"SELECT NVL2(num, num, txt1), num FROM testNvl2 where id in(5, 6) order by id asc"
);
rs
=
stat
.
executeQuery
(
"SELECT NVL2(num, num, txt1), num "
+
"FROM testNvl2 where id in(5, 6) order by id asc"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
rs
.
getMetaData
().
getColumnType
(
2
),
rs
.
getMetaData
().
getColumnType
(
1
));
assertEquals
(
rs
.
getMetaData
().
getColumnType
(
2
),
rs
.
getMetaData
().
getColumnType
(
1
));
assertThrows
(
ErrorCode
.
DATA_CONVERSION_ERROR_1
,
stat
).
assertThrows
(
ErrorCode
.
DATA_CONVERSION_ERROR_1
,
stat
).
executeQuery
(
"SELECT NVL2(num, num, txt1), num FROM testNvl2 where id = 7 order by id asc"
);
executeQuery
(
"SELECT NVL2(num, num, txt1), num "
+
"FROM testNvl2 where id = 7 order by id asc"
);
// nvl2 should return expr2's datatype, if expr2 is character data.
// nvl2 should return expr2's datatype, if expr2 is character data.
rs
=
stat
.
executeQuery
(
"SELECT NVL2(1, 'test', 123), 'test' FROM dual"
);
rs
=
stat
.
executeQuery
(
"SELECT NVL2(1, 'test', 123), 'test' FROM dual"
);
rs
.
next
();
rs
.
next
();
actual
=
rs
.
getString
(
1
);
actual
=
rs
.
getString
(
1
);
assertEquals
(
"test"
,
actual
);
assertEquals
(
"test"
,
actual
);
assertEquals
(
rs
.
getMetaData
().
getColumnType
(
2
),
rs
.
getMetaData
().
getColumnType
(
1
));
assertEquals
(
rs
.
getMetaData
().
getColumnType
(
2
),
rs
.
getMetaData
().
getColumnType
(
1
));
conn
.
close
();
conn
.
close
();
}
}
...
@@ -187,15 +203,22 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -187,15 +203,22 @@ public class TestFunctions extends TestBase implements AggregateFunction {
Connection
conn
=
getConnection
(
"functions"
);
Connection
conn
=
getConnection
(
"functions"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
String
createSQL
=
"CREATE TABLE testConcat(id BIGINT, txt1 varchar, txt2 varchar, txt3 varchar);"
;
String
createSQL
=
"CREATE TABLE testConcat(id BIGINT, txt1 "
+
"varchar, txt2 varchar, txt3 varchar);"
;
stat
.
execute
(
createSQL
);
stat
.
execute
(
createSQL
);
stat
.
execute
(
"insert into testConcat(id, txt1, txt2, txt3) values(1, 'test1', 'test2', 'test3')"
);
stat
.
execute
(
"insert into testConcat(id, txt1, txt2, txt3) "
+
stat
.
execute
(
"insert into testConcat(id, txt1, txt2, txt3) values(2, 'test1', 'test2', null)"
);
"values(1, 'test1', 'test2', 'test3')"
);
stat
.
execute
(
"insert into testConcat(id, txt1, txt2, txt3) values(3, 'test1', null, null)"
);
stat
.
execute
(
"insert into testConcat(id, txt1, txt2, txt3) "
+
stat
.
execute
(
"insert into testConcat(id, txt1, txt2, txt3) values(4, null, 'test2', null)"
);
"values(2, 'test1', 'test2', null)"
);
stat
.
execute
(
"insert into testConcat(id, txt1, txt2, txt3) values(5, null, null, null)"
);
stat
.
execute
(
"insert into testConcat(id, txt1, txt2, txt3) "
+
"values(3, 'test1', null, null)"
);
String
query
=
"SELECT concat_ws('_',txt1, txt2, txt3), txt1 FROM testConcat order by id asc"
;
stat
.
execute
(
"insert into testConcat(id, txt1, txt2, txt3) "
+
"values(4, null, 'test2', null)"
);
stat
.
execute
(
"insert into testConcat(id, txt1, txt2, txt3) "
+
"values(5, null, null, null)"
);
String
query
=
"SELECT concat_ws('_',txt1, txt2, txt3), txt1 "
+
"FROM testConcat order by id asc"
;
ResultSet
rs
=
stat
.
executeQuery
(
query
);
ResultSet
rs
=
stat
.
executeQuery
(
query
);
rs
.
next
();
rs
.
next
();
String
actual
=
rs
.
getString
(
1
);
String
actual
=
rs
.
getString
(
1
);
...
@@ -226,8 +249,10 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -226,8 +249,10 @@ public class TestFunctions extends TestBase implements AggregateFunction {
Connection
conn
=
getConnection
(
"functions"
);
Connection
conn
=
getConnection
(
"functions"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
ResultSet
rs
;
ResultSet
rs
;
stat
.
execute
(
"create alias TO_CHAR_2 for \""
+
getClass
().
getName
()
+
".toChar\""
);
stat
.
execute
(
"create alias TO_CHAR_2 for \""
+
rs
=
stat
.
executeQuery
(
"call TO_CHAR_2(TIMESTAMP '2001-02-03 04:05:06', 'format')"
);
getClass
().
getName
()
+
".toChar\""
);
rs
=
stat
.
executeQuery
(
"call TO_CHAR_2(TIMESTAMP '2001-02-03 04:05:06', 'format')"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
"2001-02-03 04:05:06.0"
,
rs
.
getString
(
1
));
assertEquals
(
"2001-02-03 04:05:06.0"
,
rs
.
getString
(
1
));
stat
.
execute
(
"drop alias TO_CHAR_2"
);
stat
.
execute
(
"drop alias TO_CHAR_2"
);
...
@@ -250,7 +275,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -250,7 +275,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
private
void
testDefaultConnection
()
throws
SQLException
{
private
void
testDefaultConnection
()
throws
SQLException
{
Connection
conn
=
getConnection
(
"functions;DEFAULT_CONNECTION=TRUE"
);
Connection
conn
=
getConnection
(
"functions;DEFAULT_CONNECTION=TRUE"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create alias test for \""
+
TestFunctions
.
class
.
getName
()+
".testDefaultConn\""
);
stat
.
execute
(
"create alias test for \""
+
TestFunctions
.
class
.
getName
()+
".testDefaultConn\""
);
stat
.
execute
(
"call test()"
);
stat
.
execute
(
"call test()"
);
stat
.
execute
(
"drop alias test"
);
stat
.
execute
(
"drop alias test"
);
conn
.
close
();
conn
.
close
();
...
@@ -289,13 +315,15 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -289,13 +315,15 @@ public class TestFunctions extends TestBase implements AggregateFunction {
stat
.
execute
(
createSQL
);
stat
.
execute
(
createSQL
);
stat
.
execute
(
"insert into testGreatest values (1)"
);
stat
.
execute
(
"insert into testGreatest values (1)"
);
String
query
=
"SELECT GREATEST(id, "
+
((
long
)
Integer
.
MAX_VALUE
)
+
") FROM testGreatest"
;
String
query
=
"SELECT GREATEST(id, "
+
((
long
)
Integer
.
MAX_VALUE
)
+
") FROM testGreatest"
;
ResultSet
rs
=
stat
.
executeQuery
(
query
);
ResultSet
rs
=
stat
.
executeQuery
(
query
);
rs
.
next
();
rs
.
next
();
Object
o
=
rs
.
getObject
(
1
);
Object
o
=
rs
.
getObject
(
1
);
assertEquals
(
Long
.
class
.
getName
(),
o
.
getClass
().
getName
());
assertEquals
(
Long
.
class
.
getName
(),
o
.
getClass
().
getName
());
String
query2
=
"SELECT GREATEST(id, "
+
((
long
)
Integer
.
MAX_VALUE
+
1
)
+
") FROM testGreatest"
;
String
query2
=
"SELECT GREATEST(id, "
+
((
long
)
Integer
.
MAX_VALUE
+
1
)
+
") FROM testGreatest"
;
ResultSet
rs2
=
stat
.
executeQuery
(
query2
);
ResultSet
rs2
=
stat
.
executeQuery
(
query2
);
rs2
.
next
();
rs2
.
next
();
Object
o2
=
rs2
.
getObject
(
1
);
Object
o2
=
rs2
.
getObject
(
1
);
...
@@ -310,7 +338,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -310,7 +338,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
ResultSet
rs
;
ResultSet
rs
;
stat
.
execute
(
"create force alias sayHi as 'String test(String name) {\n"
+
stat
.
execute
(
"create force alias sayHi as 'String test(String name) {\n"
+
"return \"Hello \" + name;\n}'"
);
"return \"Hello \" + name;\n}'"
);
rs
=
stat
.
executeQuery
(
"SELECT ALIAS_NAME FROM INFORMATION_SCHEMA.FUNCTION_ALIASES"
);
rs
=
stat
.
executeQuery
(
"SELECT ALIAS_NAME "
+
"FROM INFORMATION_SCHEMA.FUNCTION_ALIASES"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
"SAY"
+
"HI"
,
rs
.
getString
(
1
));
assertEquals
(
"SAY"
+
"HI"
,
rs
.
getString
(
1
));
rs
=
stat
.
executeQuery
(
"call sayHi('Joe')"
);
rs
=
stat
.
executeQuery
(
"call sayHi('Joe')"
);
...
@@ -332,7 +361,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -332,7 +361,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
Connection
conn
=
getConnection
(
"functions"
);
Connection
conn
=
getConnection
(
"functions"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
ResultSet
rs
;
ResultSet
rs
;
stat
.
execute
(
"create alias dynamic deterministic for \""
+
getClass
().
getName
()
+
".dynamic\""
);
stat
.
execute
(
"create alias dynamic deterministic for \""
+
getClass
().
getName
()
+
".dynamic\""
);
setCount
(
0
);
setCount
(
0
);
rs
=
stat
.
executeQuery
(
"call dynamic(('a', 1))[0]"
);
rs
=
stat
.
executeQuery
(
"call dynamic(('a', 1))[0]"
);
rs
.
next
();
rs
.
next
();
...
@@ -347,7 +377,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -347,7 +377,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
ResultSet
rs
;
ResultSet
rs
;
stat
.
execute
(
"create alias xorUUID for \""
+
getClass
().
getName
()+
".xorUUID\""
);
stat
.
execute
(
"create alias xorUUID for \""
+
getClass
().
getName
()+
".xorUUID\""
);
setCount
(
0
);
setCount
(
0
);
rs
=
stat
.
executeQuery
(
"call xorUUID(random_uuid(), random_uuid())"
);
rs
=
stat
.
executeQuery
(
"call xorUUID(random_uuid(), random_uuid())"
);
rs
.
next
();
rs
.
next
();
...
@@ -363,7 +394,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -363,7 +394,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
ResultSet
rs
;
ResultSet
rs
;
stat
.
execute
(
"create alias getCount for \""
+
getClass
().
getName
()+
".getCount\""
);
stat
.
execute
(
"create alias getCount for \""
+
getClass
().
getName
()+
".getCount\""
);
setCount
(
0
);
setCount
(
0
);
rs
=
stat
.
executeQuery
(
"select getCount() from system_range(1, 2)"
);
rs
=
stat
.
executeQuery
(
"select getCount() from system_range(1, 2)"
);
rs
.
next
();
rs
.
next
();
...
@@ -372,7 +404,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -372,7 +404,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertEquals
(
1
,
rs
.
getInt
(
1
));
assertEquals
(
1
,
rs
.
getInt
(
1
));
stat
.
execute
(
"drop alias getCount"
);
stat
.
execute
(
"drop alias getCount"
);
stat
.
execute
(
"create alias getCount deterministic for \""
+
getClass
().
getName
()+
".getCount\""
);
stat
.
execute
(
"create alias getCount deterministic for \""
+
getClass
().
getName
()+
".getCount\""
);
setCount
(
0
);
setCount
(
0
);
rs
=
stat
.
executeQuery
(
"select getCount() from system_range(1, 2)"
);
rs
=
stat
.
executeQuery
(
"select getCount() from system_range(1, 2)"
);
rs
.
next
();
rs
.
next
();
...
@@ -380,9 +413,12 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -380,9 +413,12 @@ public class TestFunctions extends TestBase implements AggregateFunction {
rs
.
next
();
rs
.
next
();
assertEquals
(
0
,
rs
.
getInt
(
1
));
assertEquals
(
0
,
rs
.
getInt
(
1
));
stat
.
execute
(
"drop alias getCount"
);
stat
.
execute
(
"drop alias getCount"
);
rs
=
stat
.
executeQuery
(
"SELECT * FROM INFORMATION_SCHEMA.FUNCTION_ALIASES WHERE UPPER(ALIAS_NAME) = 'GET' || 'COUNT'"
);
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
"INFORMATION_SCHEMA.FUNCTION_ALIASES "
+
"WHERE UPPER(ALIAS_NAME) = 'GET' || 'COUNT'"
);
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
stat
.
execute
(
"create alias reverse deterministic for \""
+
getClass
().
getName
()+
".reverse\""
);
stat
.
execute
(
"create alias reverse deterministic for \""
+
getClass
().
getName
()+
".reverse\""
);
rs
=
stat
.
executeQuery
(
"select reverse(x) from system_range(700, 700)"
);
rs
=
stat
.
executeQuery
(
"select reverse(x) from system_range(700, 700)"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
"007"
,
rs
.
getString
(
1
));
assertEquals
(
"007"
,
rs
.
getString
(
1
));
...
@@ -419,7 +455,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -419,7 +455,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
Connection
conn
=
getConnection
(
"functions"
);
Connection
conn
=
getConnection
(
"functions"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create alias no_op for \""
+
getClass
().
getName
()+
".noOp\""
);
stat
.
execute
(
"create alias no_op for \""
+
getClass
().
getName
()+
".noOp\""
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"select * from dual where no_op(1.6)=?"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"select * from dual where no_op(1.6)=?"
);
prep
.
setBigDecimal
(
1
,
new
BigDecimal
(
"1.6"
));
prep
.
setBigDecimal
(
1
,
new
BigDecimal
(
"1.6"
));
ResultSet
rs
=
prep
.
executeQuery
();
ResultSet
rs
=
prep
.
executeQuery
();
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
next
());
...
@@ -477,12 +514,14 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -477,12 +514,14 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertEquals
(
"PUBLIC"
,
rs
.
getString
(
"PROCEDURE_SCHEM"
));
assertEquals
(
"PUBLIC"
,
rs
.
getString
(
"PROCEDURE_SCHEM"
));
assertEquals
(
"MEAN2"
,
rs
.
getString
(
"PROCEDURE_NAME"
));
assertEquals
(
"MEAN2"
,
rs
.
getString
(
"PROCEDURE_NAME"
));
assertEquals
(
"P2"
,
rs
.
getString
(
"COLUMN_NAME"
));
assertEquals
(
"P2"
,
rs
.
getString
(
"COLUMN_NAME"
));
assertEquals
(
DatabaseMetaData
.
procedureColumnIn
,
rs
.
getInt
(
"COLUMN_TYPE"
));
assertEquals
(
DatabaseMetaData
.
procedureColumnIn
,
rs
.
getInt
(
"COLUMN_TYPE"
));
assertEquals
(
"OTHER"
,
rs
.
getString
(
"TYPE_NAME"
));
assertEquals
(
"OTHER"
,
rs
.
getString
(
"TYPE_NAME"
));
assertEquals
(
Integer
.
MAX_VALUE
,
rs
.
getInt
(
"PRECISION"
));
assertEquals
(
Integer
.
MAX_VALUE
,
rs
.
getInt
(
"PRECISION"
));
assertEquals
(
Integer
.
MAX_VALUE
,
rs
.
getInt
(
"LENGTH"
));
assertEquals
(
Integer
.
MAX_VALUE
,
rs
.
getInt
(
"LENGTH"
));
assertEquals
(
0
,
rs
.
getInt
(
"SCALE"
));
assertEquals
(
0
,
rs
.
getInt
(
"SCALE"
));
assertEquals
(
DatabaseMetaData
.
columnNullable
,
rs
.
getInt
(
"NULLABLE"
));
assertEquals
(
DatabaseMetaData
.
columnNullable
,
rs
.
getInt
(
"NULLABLE"
));
assertEquals
(
""
,
rs
.
getString
(
"REMARKS"
));
assertEquals
(
""
,
rs
.
getString
(
"REMARKS"
));
assertEquals
(
null
,
rs
.
getString
(
"COLUMN_DEF"
));
assertEquals
(
null
,
rs
.
getString
(
"COLUMN_DEF"
));
assertEquals
(
0
,
rs
.
getInt
(
"SQL_DATA_TYPE"
));
assertEquals
(
0
,
rs
.
getInt
(
"SQL_DATA_TYPE"
));
...
@@ -514,15 +553,18 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -514,15 +553,18 @@ public class TestFunctions extends TestBase implements AggregateFunction {
OutputStream
out
=
FileUtils
.
newOutputStream
(
fileName
,
false
);
OutputStream
out
=
FileUtils
.
newOutputStream
(
fileName
,
false
);
prop
.
store
(
out
,
""
);
prop
.
store
(
out
,
""
);
out
.
close
();
out
.
close
();
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT LENGTH(FILE_READ('"
+
fileName
+
"')) LEN"
);
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT LENGTH(FILE_READ('"
+
fileName
+
"')) LEN"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
FileUtils
.
size
(
fileName
),
rs
.
getInt
(
1
));
assertEquals
(
FileUtils
.
size
(
fileName
),
rs
.
getInt
(
1
));
rs
=
stat
.
executeQuery
(
"SELECT FILE_READ('"
+
fileName
+
"') PROP"
);
rs
=
stat
.
executeQuery
(
"SELECT FILE_READ('"
+
fileName
+
"') PROP"
);
rs
.
next
();
rs
.
next
();
Properties
p2
=
new
Properties
();
Properties
p2
=
new
Properties
();
p2
.
load
(
rs
.
getBinaryStream
(
1
));
p2
.
load
(
rs
.
getBinaryStream
(
1
));
assertEquals
(
prop
.
size
(),
p2
.
size
());
assertEquals
(
prop
.
size
(),
p2
.
size
());
rs
=
stat
.
executeQuery
(
"SELECT FILE_READ('"
+
fileName
+
"', NULL) PROP"
);
rs
=
stat
.
executeQuery
(
"SELECT FILE_READ('"
+
fileName
+
"', NULL) PROP"
);
rs
.
next
();
rs
.
next
();
String
ps
=
rs
.
getString
(
1
);
String
ps
=
rs
.
getString
(
1
);
InputStreamReader
r
=
new
InputStreamReader
(
FileUtils
.
newInputStream
(
fileName
));
InputStreamReader
r
=
new
InputStreamReader
(
FileUtils
.
newInputStream
(
fileName
));
...
@@ -594,9 +636,12 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -594,9 +636,12 @@ public class TestFunctions extends TestBase implements AggregateFunction {
deleteDb
(
"functions"
);
deleteDb
(
"functions"
);
Connection
conn
=
getConnection
(
"functions"
);
Connection
conn
=
getConnection
(
"functions"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE AGGREGATE MEDIAN FOR \""
+
MedianStringType
.
class
.
getName
()
+
"\""
);
stat
.
execute
(
"CREATE AGGREGATE MEDIAN FOR \""
+
stat
.
execute
(
"CREATE AGGREGATE IF NOT EXISTS MEDIAN FOR \""
+
MedianStringType
.
class
.
getName
()
+
"\""
);
MedianStringType
.
class
.
getName
()
+
"\""
);
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT MEDIAN(X) FROM SYSTEM_RANGE(1, 9)"
);
stat
.
execute
(
"CREATE AGGREGATE IF NOT EXISTS MEDIAN FOR \""
+
MedianStringType
.
class
.
getName
()
+
"\""
);
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT MEDIAN(X) FROM SYSTEM_RANGE(1, 9)"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
"5"
,
rs
.
getString
(
1
));
assertEquals
(
"5"
,
rs
.
getString
(
1
));
conn
.
close
();
conn
.
close
();
...
@@ -630,9 +675,12 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -630,9 +675,12 @@ public class TestFunctions extends TestBase implements AggregateFunction {
deleteDb
(
"functions"
);
deleteDb
(
"functions"
);
Connection
conn
=
getConnection
(
"functions"
);
Connection
conn
=
getConnection
(
"functions"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE AGGREGATE MEDIAN FOR \""
+
MedianString
.
class
.
getName
()
+
"\""
);
stat
.
execute
(
"CREATE AGGREGATE MEDIAN FOR \""
+
stat
.
execute
(
"CREATE AGGREGATE IF NOT EXISTS MEDIAN FOR \""
+
MedianString
.
class
.
getName
()
+
"\""
);
MedianString
.
class
.
getName
()
+
"\""
);
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT MEDIAN(X) FROM SYSTEM_RANGE(1, 9)"
);
stat
.
execute
(
"CREATE AGGREGATE IF NOT EXISTS MEDIAN FOR \""
+
MedianString
.
class
.
getName
()
+
"\""
);
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT MEDIAN(X) FROM SYSTEM_RANGE(1, 9)"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
"5"
,
rs
.
getString
(
1
));
assertEquals
(
"5"
,
rs
.
getString
(
1
));
conn
.
close
();
conn
.
close
();
...
@@ -671,7 +719,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -671,7 +719,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertCallResult
(
"1"
,
stat
,
"abs(1)"
);
assertCallResult
(
"1"
,
stat
,
"abs(1)"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)"
);
stat
.
execute
(
"CREATE ALIAS ADD_ROW FOR \""
+
getClass
().
getName
()
+
".addRow\""
);
stat
.
execute
(
"CREATE ALIAS ADD_ROW FOR \""
+
getClass
().
getName
()
+
".addRow\""
);
ResultSet
rs
;
ResultSet
rs
;
rs
=
stat
.
executeQuery
(
"CALL ADD_ROW(1, 'Hello')"
);
rs
=
stat
.
executeQuery
(
"CALL ADD_ROW(1, 'Hello')"
);
rs
.
next
();
rs
.
next
();
...
@@ -689,7 +738,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -689,7 +738,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertEquals
(
"PUBLIC"
,
rs
.
getString
(
"PROCEDURE_SCHEM"
));
assertEquals
(
"PUBLIC"
,
rs
.
getString
(
"PROCEDURE_SCHEM"
));
assertEquals
(
"ADD_ROW"
,
rs
.
getString
(
"PROCEDURE_NAME"
));
assertEquals
(
"ADD_ROW"
,
rs
.
getString
(
"PROCEDURE_NAME"
));
assertEquals
(
"P2"
,
rs
.
getString
(
"COLUMN_NAME"
));
assertEquals
(
"P2"
,
rs
.
getString
(
"COLUMN_NAME"
));
assertEquals
(
DatabaseMetaData
.
procedureColumnIn
,
rs
.
getInt
(
"COLUMN_TYPE"
));
assertEquals
(
DatabaseMetaData
.
procedureColumnIn
,
rs
.
getInt
(
"COLUMN_TYPE"
));
assertEquals
(
"INTEGER"
,
rs
.
getString
(
"TYPE_NAME"
));
assertEquals
(
"INTEGER"
,
rs
.
getString
(
"TYPE_NAME"
));
assertEquals
(
10
,
rs
.
getInt
(
"PRECISION"
));
assertEquals
(
10
,
rs
.
getInt
(
"PRECISION"
));
assertEquals
(
10
,
rs
.
getInt
(
"LENGTH"
));
assertEquals
(
10
,
rs
.
getInt
(
"LENGTH"
));
...
@@ -710,8 +760,10 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -710,8 +760,10 @@ public class TestFunctions extends TestBase implements AggregateFunction {
stat
.
executeQuery
(
"CALL ADD_ROW(2, 'World')"
);
stat
.
executeQuery
(
"CALL ADD_ROW(2, 'World')"
);
stat
.
execute
(
"CREATE ALIAS SELECT_F FOR \""
+
getClass
().
getName
()
+
".select\""
);
stat
.
execute
(
"CREATE ALIAS SELECT_F FOR \""
+
rs
=
stat
.
executeQuery
(
"CALL SELECT_F('SELECT * FROM TEST ORDER BY ID')"
);
getClass
().
getName
()
+
".select\""
);
rs
=
stat
.
executeQuery
(
"CALL SELECT_F('SELECT * "
+
"FROM TEST ORDER BY ID')"
);
assertEquals
(
2
,
rs
.
getMetaData
().
getColumnCount
());
assertEquals
(
2
,
rs
.
getMetaData
().
getColumnCount
());
rs
.
next
();
rs
.
next
();
assertEquals
(
1
,
rs
.
getInt
(
1
));
assertEquals
(
1
,
rs
.
getInt
(
1
));
...
@@ -721,7 +773,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -721,7 +773,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertEquals
(
"World"
,
rs
.
getString
(
2
));
assertEquals
(
"World"
,
rs
.
getString
(
2
));
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
rs
=
stat
.
executeQuery
(
"SELECT NAME FROM SELECT_F('SELECT * FROM TEST ORDER BY NAME') ORDER BY NAME DESC"
);
rs
=
stat
.
executeQuery
(
"SELECT NAME FROM SELECT_F('SELECT * "
+
"FROM TEST ORDER BY NAME') ORDER BY NAME DESC"
);
assertEquals
(
1
,
rs
.
getMetaData
().
getColumnCount
());
assertEquals
(
1
,
rs
.
getMetaData
().
getColumnCount
());
rs
.
next
();
rs
.
next
();
assertEquals
(
"World"
,
rs
.
getString
(
1
));
assertEquals
(
"World"
,
rs
.
getString
(
1
));
...
@@ -729,7 +782,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -729,7 +782,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertEquals
(
"Hello"
,
rs
.
getString
(
1
));
assertEquals
(
"Hello"
,
rs
.
getString
(
1
));
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
rs
=
stat
.
executeQuery
(
"SELECT SELECT_F('SELECT * FROM TEST WHERE ID=' || ID) FROM TEST ORDER BY ID"
);
rs
=
stat
.
executeQuery
(
"SELECT SELECT_F('SELECT * "
+
"FROM TEST WHERE ID=' || ID) FROM TEST ORDER BY ID"
);
assertEquals
(
1
,
rs
.
getMetaData
().
getColumnCount
());
assertEquals
(
1
,
rs
.
getMetaData
().
getColumnCount
());
rs
.
next
();
rs
.
next
();
assertEquals
(
"((1, Hello))"
,
rs
.
getString
(
1
));
assertEquals
(
"((1, Hello))"
,
rs
.
getString
(
1
));
...
@@ -737,14 +791,16 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -737,14 +791,16 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertEquals
(
"((2, World))"
,
rs
.
getString
(
1
));
assertEquals
(
"((2, World))"
,
rs
.
getString
(
1
));
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
rs
=
stat
.
executeQuery
(
"SELECT SELECT_F('SELECT * FROM TEST ORDER BY ID') FROM DUAL"
);
rs
=
stat
.
executeQuery
(
"SELECT SELECT_F('SELECT * "
+
"FROM TEST ORDER BY ID') FROM DUAL"
);
assertEquals
(
1
,
rs
.
getMetaData
().
getColumnCount
());
assertEquals
(
1
,
rs
.
getMetaData
().
getColumnCount
());
rs
.
next
();
rs
.
next
();
assertEquals
(
"((1, Hello), (2, World))"
,
rs
.
getString
(
1
));
assertEquals
(
"((1, Hello), (2, World))"
,
rs
.
getString
(
1
));
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
assertThrows
(
ErrorCode
.
SYNTAX_ERROR_2
,
stat
).
assertThrows
(
ErrorCode
.
SYNTAX_ERROR_2
,
stat
).
executeQuery
(
"CALL SELECT_F('ERROR')"
);
executeQuery
(
"CALL SELECT_F('ERROR')"
);
stat
.
execute
(
"CREATE ALIAS SIMPLE FOR \""
+
getClass
().
getName
()
+
".simpleResultSet\""
);
stat
.
execute
(
"CREATE ALIAS SIMPLE FOR \""
+
getClass
().
getName
()
+
".simpleResultSet\""
);
rs
=
stat
.
executeQuery
(
"CALL SIMPLE(2, 1, 1, 1, 1, 1, 1, 1)"
);
rs
=
stat
.
executeQuery
(
"CALL SIMPLE(2, 1, 1, 1, 1, 1, 1, 1)"
);
assertEquals
(
2
,
rs
.
getMetaData
().
getColumnCount
());
assertEquals
(
2
,
rs
.
getMetaData
().
getColumnCount
());
rs
.
next
();
rs
.
next
();
...
@@ -762,7 +818,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -762,7 +818,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertEquals
(
"Hello"
,
rs
.
getString
(
2
));
assertEquals
(
"Hello"
,
rs
.
getString
(
2
));
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
stat
.
execute
(
"CREATE ALIAS ARRAY FOR \""
+
getClass
().
getName
()
+
".getArray\""
);
stat
.
execute
(
"CREATE ALIAS ARRAY FOR \""
+
getClass
().
getName
()
+
".getArray\""
);
rs
=
stat
.
executeQuery
(
"CALL ARRAY()"
);
rs
=
stat
.
executeQuery
(
"CALL ARRAY()"
);
assertEquals
(
1
,
rs
.
getMetaData
().
getColumnCount
());
assertEquals
(
1
,
rs
.
getMetaData
().
getColumnCount
());
rs
.
next
();
rs
.
next
();
...
@@ -831,7 +888,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -831,7 +888,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertEquals
(
3
,
rs
.
getInt
(
1
));
assertEquals
(
3
,
rs
.
getInt
(
1
));
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
stat
.
execute
(
"CREATE ALIAS MAX_ID FOR \""
+
getClass
().
getName
()
+
".selectMaxId\""
);
stat
.
execute
(
"CREATE ALIAS MAX_ID FOR \""
+
getClass
().
getName
()
+
".selectMaxId\""
);
rs
=
stat
.
executeQuery
(
"CALL MAX_ID()"
);
rs
=
stat
.
executeQuery
(
"CALL MAX_ID()"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
2
,
rs
.
getInt
(
1
));
assertEquals
(
2
,
rs
.
getInt
(
1
));
...
@@ -861,7 +919,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -861,7 +919,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
}
}
rs
.
close
();
rs
.
close
();
stat
.
execute
(
"create alias sql as 'ResultSet sql(Connection conn, String sql) "
+
stat
.
execute
(
"create alias sql as "
+
"'ResultSet sql(Connection conn, String sql) "
+
"throws SQLException { return conn.createStatement().executeQuery(sql); }'"
);
"throws SQLException { return conn.createStatement().executeQuery(sql); }'"
);
rs
=
stat
.
executeQuery
(
"select * from sql('select cast(''Hello'' as clob)')"
);
rs
=
stat
.
executeQuery
(
"select * from sql('select cast(''Hello'' as clob)')"
);
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
next
());
...
@@ -885,8 +944,10 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -885,8 +944,10 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertEquals
(
"VARCHAR"
,
meta2
.
getColumnTypeName
(
2
));
assertEquals
(
"VARCHAR"
,
meta2
.
getColumnTypeName
(
2
));
assertEquals
(
"java.lang.String"
,
meta2
.
getColumnClassName
(
2
));
assertEquals
(
"java.lang.String"
,
meta2
.
getColumnClassName
(
2
));
stat
.
execute
(
"CREATE ALIAS blob2stream FOR \""
+
getClass
().
getName
()
+
".blob2stream\""
);
stat
.
execute
(
"CREATE ALIAS blob2stream FOR \""
+
stat
.
execute
(
"CREATE ALIAS stream2stream FOR \""
+
getClass
().
getName
()
+
".stream2stream\""
);
getClass
().
getName
()
+
".blob2stream\""
);
stat
.
execute
(
"CREATE ALIAS stream2stream FOR \""
+
getClass
().
getName
()
+
".stream2stream\""
);
stat
.
execute
(
"CREATE TABLE TEST_BLOB(ID INT PRIMARY KEY, VALUE BLOB)"
);
stat
.
execute
(
"CREATE TABLE TEST_BLOB(ID INT PRIMARY KEY, VALUE BLOB)"
);
stat
.
execute
(
"INSERT INTO TEST_BLOB VALUES(0, null)"
);
stat
.
execute
(
"INSERT INTO TEST_BLOB VALUES(0, null)"
);
stat
.
execute
(
"INSERT INTO TEST_BLOB VALUES(1, 'edd1f011edd1f011edd1f011')"
);
stat
.
execute
(
"INSERT INTO TEST_BLOB VALUES(1, 'edd1f011edd1f011edd1f011')"
);
...
@@ -900,7 +961,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -900,7 +961,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
// ignore
// ignore
}
}
stat
.
execute
(
"CREATE ALIAS NULL_RESULT FOR \""
+
getClass
().
getName
()
+
".nullResultSet\""
);
stat
.
execute
(
"CREATE ALIAS NULL_RESULT FOR \""
+
getClass
().
getName
()
+
".nullResultSet\""
);
rs
=
stat
.
executeQuery
(
"CALL NULL_RESULT()"
);
rs
=
stat
.
executeQuery
(
"CALL NULL_RESULT()"
);
assertEquals
(
1
,
rs
.
getMetaData
().
getColumnCount
());
assertEquals
(
1
,
rs
.
getMetaData
().
getColumnCount
());
rs
.
next
();
rs
.
next
();
...
@@ -916,13 +978,15 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -916,13 +978,15 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertEquals
(
0
,
rs
.
getInt
(
"NUM_OUTPUT_PARAMS"
));
assertEquals
(
0
,
rs
.
getInt
(
"NUM_OUTPUT_PARAMS"
));
assertEquals
(
0
,
rs
.
getInt
(
"NUM_RESULT_SETS"
));
assertEquals
(
0
,
rs
.
getInt
(
"NUM_RESULT_SETS"
));
assertEquals
(
""
,
rs
.
getString
(
"REMARKS"
));
assertEquals
(
""
,
rs
.
getString
(
"REMARKS"
));
assertEquals
(
DatabaseMetaData
.
procedureReturnsResult
,
rs
.
getInt
(
"PROCEDURE_TYPE"
));
assertEquals
(
DatabaseMetaData
.
procedureReturnsResult
,
rs
.
getInt
(
"PROCEDURE_TYPE"
));
assertEquals
(
"NULL_RESULT"
,
rs
.
getString
(
"SPECIFIC_NAME"
));
assertEquals
(
"NULL_RESULT"
,
rs
.
getString
(
"SPECIFIC_NAME"
));
rs
=
meta
.
getProcedureColumns
(
null
,
null
,
"NULL_RESULT"
,
null
);
rs
=
meta
.
getProcedureColumns
(
null
,
null
,
"NULL_RESULT"
,
null
);
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
stat
.
execute
(
"CREATE ALIAS RESULT_WITH_NULL FOR \""
+
getClass
().
getName
()
+
".resultSetWithNull\""
);
stat
.
execute
(
"CREATE ALIAS RESULT_WITH_NULL FOR \""
+
getClass
().
getName
()
+
".resultSetWithNull\""
);
rs
=
stat
.
executeQuery
(
"CALL RESULT_WITH_NULL()"
);
rs
=
stat
.
executeQuery
(
"CALL RESULT_WITH_NULL()"
);
assertEquals
(
1
,
rs
.
getMetaData
().
getColumnCount
());
assertEquals
(
1
,
rs
.
getMetaData
().
getColumnCount
());
rs
.
next
();
rs
.
next
();
...
@@ -937,14 +1001,16 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -937,14 +1001,16 @@ public class TestFunctions extends TestBase implements AggregateFunction {
Connection
conn
=
getConnection
(
"functions"
);
Connection
conn
=
getConnection
(
"functions"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
// with white space
// with white space
stat
.
execute
(
"CREATE ALIAS PARSE_INT2 FOR \"java.lang.Integer.parseInt(java.lang.String, int)\""
);
stat
.
execute
(
"CREATE ALIAS PARSE_INT2 FOR "
+
"\"java.lang.Integer.parseInt(java.lang.String, int)\""
);
ResultSet
rs
;
ResultSet
rs
;
rs
=
stat
.
executeQuery
(
"CALL PARSE_INT2('473', 10)"
);
rs
=
stat
.
executeQuery
(
"CALL PARSE_INT2('473', 10)"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
473
,
rs
.
getInt
(
1
));
assertEquals
(
473
,
rs
.
getInt
(
1
));
stat
.
execute
(
"DROP ALIAS PARSE_INT2"
);
stat
.
execute
(
"DROP ALIAS PARSE_INT2"
);
// without white space
// without white space
stat
.
execute
(
"CREATE ALIAS PARSE_INT2 FOR \"java.lang.Integer.parseInt(java.lang.String,int)\""
);
stat
.
execute
(
"CREATE ALIAS PARSE_INT2 FOR "
+
"\"java.lang.Integer.parseInt(java.lang.String,int)\""
);
stat
.
execute
(
"DROP ALIAS PARSE_INT2"
);
stat
.
execute
(
"DROP ALIAS PARSE_INT2"
);
conn
.
close
();
conn
.
close
();
}
}
...
@@ -956,20 +1022,24 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -956,20 +1022,24 @@ public class TestFunctions extends TestBase implements AggregateFunction {
ResultSet
rs
;
ResultSet
rs
;
stat
.
execute
(
"CREATE SCHEMA TEST"
);
stat
.
execute
(
"CREATE SCHEMA TEST"
);
stat
.
execute
(
"SET SCHEMA TEST"
);
stat
.
execute
(
"SET SCHEMA TEST"
);
stat
.
execute
(
"CREATE ALIAS PARSE_INT2 FOR \"java.lang.Integer.parseInt(java.lang.String, int)\";"
);
stat
.
execute
(
"CREATE ALIAS PARSE_INT2 FOR "
+
rs
=
stat
.
executeQuery
(
"SELECT ALIAS_NAME FROM INFORMATION_SCHEMA.FUNCTION_ALIASES WHERE ALIAS_SCHEMA ='TEST'"
);
"\"java.lang.Integer.parseInt(java.lang.String, int)\";"
);
rs
=
stat
.
executeQuery
(
"SELECT ALIAS_NAME FROM "
+
"INFORMATION_SCHEMA.FUNCTION_ALIASES WHERE ALIAS_SCHEMA ='TEST'"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
"PARSE_INT2"
,
rs
.
getString
(
1
));
assertEquals
(
"PARSE_INT2"
,
rs
.
getString
(
1
));
stat
.
execute
(
"DROP ALIAS PARSE_INT2"
);
stat
.
execute
(
"DROP ALIAS PARSE_INT2"
);
stat
.
execute
(
"SET SCHEMA PUBLIC"
);
stat
.
execute
(
"SET SCHEMA PUBLIC"
);
stat
.
execute
(
"CREATE ALIAS TEST.PARSE_INT2 FOR \"java.lang.Integer.parseInt(java.lang.String, int)\";"
);
stat
.
execute
(
"CREATE ALIAS TEST.PARSE_INT2 FOR "
+
"\"java.lang.Integer.parseInt(java.lang.String, int)\";"
);
stat
.
execute
(
"SET SCHEMA_SEARCH_PATH PUBLIC, TEST"
);
stat
.
execute
(
"SET SCHEMA_SEARCH_PATH PUBLIC, TEST"
);
rs
=
stat
.
executeQuery
(
"CALL PARSE_INT2('-FF', 16)"
);
rs
=
stat
.
executeQuery
(
"CALL PARSE_INT2('-FF', 16)"
);
rs
.
next
();
rs
.
next
();
assertEquals
(-
255
,
rs
.
getInt
(
1
));
assertEquals
(-
255
,
rs
.
getInt
(
1
));
rs
=
stat
.
executeQuery
(
"SELECT ALIAS_NAME FROM INFORMATION_SCHEMA.FUNCTION_ALIASES WHERE ALIAS_SCHEMA ='TEST'"
);
rs
=
stat
.
executeQuery
(
"SELECT ALIAS_NAME FROM "
+
"INFORMATION_SCHEMA.FUNCTION_ALIASES WHERE ALIAS_SCHEMA ='TEST'"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
"PARSE_INT2"
,
rs
.
getString
(
1
));
assertEquals
(
"PARSE_INT2"
,
rs
.
getString
(
1
));
rs
=
stat
.
executeQuery
(
"CALL TEST.PARSE_INT2('-2147483648', 10)"
);
rs
=
stat
.
executeQuery
(
"CALL TEST.PARSE_INT2('-2147483648', 10)"
);
...
@@ -990,17 +1060,20 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -990,17 +1060,20 @@ public class TestFunctions extends TestBase implements AggregateFunction {
+
"$$ Integer[] array_test(Integer[] in_array) "
+
"$$ Integer[] array_test(Integer[] in_array) "
+
"{ return in_array; } $$;"
);
+
"{ return in_array; } $$;"
);
PreparedStatement
stmt
=
conn
.
prepareStatement
(
"select array_test(?) from dual"
);
PreparedStatement
stmt
=
conn
.
prepareStatement
(
"select array_test(?) from dual"
);
stmt
.
setObject
(
1
,
new
Integer
[]
{
1
,
2
});
stmt
.
setObject
(
1
,
new
Integer
[]
{
1
,
2
});
rs
=
stmt
.
executeQuery
();
rs
=
stmt
.
executeQuery
();
rs
.
next
();
rs
.
next
();
assertEquals
(
Integer
[].
class
.
getName
(),
rs
.
getObject
(
1
).
getClass
().
getName
());
assertEquals
(
Integer
[].
class
.
getName
(),
rs
.
getObject
(
1
).
getClass
()
.
getName
());
CallableStatement
call
=
conn
.
prepareCall
(
"{ ? = call array_test(?) }"
);
CallableStatement
call
=
conn
.
prepareCall
(
"{ ? = call array_test(?) }"
);
call
.
setObject
(
2
,
new
Integer
[]
{
2
,
1
});
call
.
setObject
(
2
,
new
Integer
[]
{
2
,
1
});
call
.
registerOutParameter
(
1
,
Types
.
ARRAY
);
call
.
registerOutParameter
(
1
,
Types
.
ARRAY
);
call
.
execute
();
call
.
execute
();
assertEquals
(
Integer
[].
class
.
getName
(),
call
.
getArray
(
1
).
getArray
().
getClass
().
getName
());
assertEquals
(
Integer
[].
class
.
getName
(),
call
.
getArray
(
1
).
getArray
()
.
getClass
().
getName
());
assertEquals
(
new
Integer
[]
{
2
,
1
},
(
Integer
[])
call
.
getObject
(
1
));
assertEquals
(
new
Integer
[]
{
2
,
1
},
(
Integer
[])
call
.
getObject
(
1
));
stat
.
execute
(
"drop alias array_test"
);
stat
.
execute
(
"drop alias array_test"
);
...
@@ -1067,9 +1140,11 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -1067,9 +1140,11 @@ public class TestFunctions extends TestBase implements AggregateFunction {
String
tzLongName
=
tz
.
getID
();
String
tzLongName
=
tz
.
getID
();
stat
.
executeUpdate
(
"CREATE TABLE T (X TIMESTAMP(6))"
);
stat
.
executeUpdate
(
"CREATE TABLE T (X TIMESTAMP(6))"
);
stat
.
executeUpdate
(
"INSERT INTO T VALUES (TIMESTAMP '1979-11-12 08:12:34.560')"
);
stat
.
executeUpdate
(
"INSERT INTO T VALUES "
+
"(TIMESTAMP '1979-11-12 08:12:34.560')"
);
stat
.
executeUpdate
(
"CREATE TABLE U (X TIMESTAMP(6))"
);
stat
.
executeUpdate
(
"CREATE TABLE U (X TIMESTAMP(6))"
);
stat
.
executeUpdate
(
"INSERT INTO U VALUES (TIMESTAMP '-100-01-15 14:04:02.120')"
);
stat
.
executeUpdate
(
"INSERT INTO U VALUES "
+
"(TIMESTAMP '-100-01-15 14:04:02.120')"
);
assertResult
(
"1979-11-12 08:12:34.56"
,
stat
,
"SELECT X FROM T"
);
assertResult
(
"1979-11-12 08:12:34.56"
,
stat
,
"SELECT X FROM T"
);
assertResult
(
"-100-01-15 14:04:02.12"
,
stat
,
"SELECT X FROM U"
);
assertResult
(
"-100-01-15 14:04:02.12"
,
stat
,
"SELECT X FROM U"
);
...
@@ -1521,7 +1596,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -1521,7 +1596,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
* @param name the text
* @param name the text
* @return the count
* @return the count
*/
*/
public
static
int
addRow
(
Connection
conn
,
int
id
,
String
name
)
throws
SQLException
{
public
static
int
addRow
(
Connection
conn
,
int
id
,
String
name
)
throws
SQLException
{
conn
.
createStatement
().
execute
(
conn
.
createStatement
().
execute
(
"INSERT INTO TEST VALUES("
+
id
+
", '"
+
name
+
"')"
);
"INSERT INTO TEST VALUES("
+
id
+
", '"
+
name
+
"')"
);
ResultSet
rs
=
conn
.
createStatement
().
executeQuery
(
ResultSet
rs
=
conn
.
createStatement
().
executeQuery
(
...
@@ -1539,7 +1615,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -1539,7 +1615,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
* @param sql the SQL statement
* @param sql the SQL statement
* @return the result set
* @return the result set
*/
*/
public
static
ResultSet
select
(
Connection
conn
,
String
sql
)
throws
SQLException
{
public
static
ResultSet
select
(
Connection
conn
,
String
sql
)
throws
SQLException
{
Statement
stat
=
conn
.
createStatement
(
Statement
stat
=
conn
.
createStatement
(
ResultSet
.
TYPE_SCROLL_INSENSITIVE
,
ResultSet
.
CONCUR_READ_ONLY
);
ResultSet
.
TYPE_SCROLL_INSENSITIVE
,
ResultSet
.
CONCUR_READ_ONLY
);
return
stat
.
executeQuery
(
sql
);
return
stat
.
executeQuery
(
sql
);
...
@@ -1606,7 +1683,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
...
@@ -1606,7 +1683,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
rs
.
addColumn
(
"ID"
,
Types
.
INTEGER
,
10
,
0
);
rs
.
addColumn
(
"ID"
,
Types
.
INTEGER
,
10
,
0
);
rs
.
addColumn
(
"NAME"
,
Types
.
VARCHAR
,
255
,
0
);
rs
.
addColumn
(
"NAME"
,
Types
.
VARCHAR
,
255
,
0
);
if
(
rowCount
==
null
)
{
if
(
rowCount
==
null
)
{
if
(
ip
!=
0
||
bp
||
fp
!=
0.0
||
dp
!=
0.0
||
sp
!=
0
||
lp
!=
0
||
byParam
!=
0
)
{
if
(
ip
!=
0
||
bp
||
fp
!=
0.0
||
dp
!=
0.0
||
sp
!=
0
||
lp
!=
0
||
byParam
!=
0
)
{
throw
new
AssertionError
(
"params not 0/false"
);
throw
new
AssertionError
(
"params not 0/false"
);
}
}
}
}
...
...
h2/src/test/org/h2/test/db/TestIndex.java
浏览文件 @
b3836d31
...
@@ -131,7 +131,8 @@ public class TestIndex extends TestBase {
...
@@ -131,7 +131,8 @@ public class TestIndex extends TestBase {
testErrorMessage
(
"PRIMARY"
,
"KEY"
,
" ON PUBLIC.TEST(NAME)"
);
testErrorMessage
(
"PRIMARY"
,
"KEY"
,
" ON PUBLIC.TEST(NAME)"
);
stat
.
execute
(
"create table test(id int, name int, unique(name))"
);
stat
.
execute
(
"create table test(id int, name int, unique(name))"
);
testErrorMessage
(
"CONSTRAINT_INDEX_2 ON PUBLIC.TEST(NAME)"
);
testErrorMessage
(
"CONSTRAINT_INDEX_2 ON PUBLIC.TEST(NAME)"
);
stat
.
execute
(
"create table test(id int, name int, constraint abc unique(name, id))"
);
stat
.
execute
(
"create table test(id int, name int, "
+
"constraint abc unique(name, id))"
);
testErrorMessage
(
"ABC_INDEX_2 ON PUBLIC.TEST(NAME, ID)"
);
testErrorMessage
(
"ABC_INDEX_2 ON PUBLIC.TEST(NAME, ID)"
);
}
}
...
@@ -175,9 +176,12 @@ public class TestIndex extends TestBase {
...
@@ -175,9 +176,12 @@ public class TestIndex extends TestBase {
stat
.
execute
(
"create memory table test(id bigint, data bigint)"
);
stat
.
execute
(
"create memory table test(id bigint, data bigint)"
);
stat
.
execute
(
"create hash index on test(id)"
);
stat
.
execute
(
"create hash index on test(id)"
);
Random
rand
=
new
Random
(
1
);
Random
rand
=
new
Random
(
1
);
PreparedStatement
prepInsert
=
conn
.
prepareStatement
(
"insert into test values(?, ?)"
);
PreparedStatement
prepInsert
=
conn
.
prepareStatement
(
PreparedStatement
prepDelete
=
conn
.
prepareStatement
(
"delete from test where id=?"
);
"insert into test values(?, ?)"
);
PreparedStatement
prepSelect
=
conn
.
prepareStatement
(
"select count(*) from test where id=?"
);
PreparedStatement
prepDelete
=
conn
.
prepareStatement
(
"delete from test where id=?"
);
PreparedStatement
prepSelect
=
conn
.
prepareStatement
(
"select count(*) from test where id=?"
);
HashMap
<
Long
,
Integer
>
map
=
New
.
hashMap
();
HashMap
<
Long
,
Integer
>
map
=
New
.
hashMap
();
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
long
key
=
rand
.
nextInt
(
10
)
*
1000000000L
;
long
key
=
rand
.
nextInt
(
10
)
*
1000000000L
;
...
@@ -266,8 +270,10 @@ public class TestIndex extends TestBase {
...
@@ -266,8 +270,10 @@ public class TestIndex extends TestBase {
stat
.
execute
(
"create table testA(id int primary key, name varchar)"
);
stat
.
execute
(
"create table testA(id int primary key, name varchar)"
);
stat
.
execute
(
"create table testB(id int primary key hash, name varchar)"
);
stat
.
execute
(
"create table testB(id int primary key hash, name varchar)"
);
int
len
=
getSize
(
300
,
3000
);
int
len
=
getSize
(
300
,
3000
);
stat
.
execute
(
"insert into testA select x, 'Hello' from system_range(1, "
+
len
+
")"
);
stat
.
execute
(
"insert into testA select x, 'Hello' from "
+
stat
.
execute
(
"insert into testB select x, 'Hello' from system_range(1, "
+
len
+
")"
);
"system_range(1, "
+
len
+
")"
);
stat
.
execute
(
"insert into testB select x, 'Hello' from "
+
"system_range(1, "
+
len
+
")"
);
Random
rand
=
new
Random
(
1
);
Random
rand
=
new
Random
(
1
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
int
x
=
rand
.
nextInt
(
len
);
int
x
=
rand
.
nextInt
(
len
);
...
@@ -323,7 +329,8 @@ public class TestIndex extends TestBase {
...
@@ -323,7 +329,8 @@ public class TestIndex extends TestBase {
assertEquals
(
"D"
,
rs
.
getString
(
"ASC_OR_DESC"
));
assertEquals
(
"D"
,
rs
.
getString
(
"ASC_OR_DESC"
));
assertEquals
(
SortOrder
.
DESCENDING
,
rs
.
getInt
(
"SORT_TYPE"
));
assertEquals
(
SortOrder
.
DESCENDING
,
rs
.
getInt
(
"SORT_TYPE"
));
stat
.
execute
(
"INSERT INTO TEST SELECT X FROM SYSTEM_RANGE(1, 30)"
);
stat
.
execute
(
"INSERT INTO TEST SELECT X FROM SYSTEM_RANGE(1, 30)"
);
rs
=
stat
.
executeQuery
(
"SELECT COUNT(*) FROM TEST WHERE ID BETWEEN 10 AND 20"
);
rs
=
stat
.
executeQuery
(
"SELECT COUNT(*) FROM TEST WHERE ID BETWEEN 10 AND 20"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
11
,
rs
.
getInt
(
1
));
assertEquals
(
11
,
rs
.
getInt
(
1
));
reconnect
();
reconnect
();
...
@@ -331,7 +338,8 @@ public class TestIndex extends TestBase {
...
@@ -331,7 +338,8 @@ public class TestIndex extends TestBase {
rs
.
next
();
rs
.
next
();
assertEquals
(
"D"
,
rs
.
getString
(
"ASC_OR_DESC"
));
assertEquals
(
"D"
,
rs
.
getString
(
"ASC_OR_DESC"
));
assertEquals
(
SortOrder
.
DESCENDING
,
rs
.
getInt
(
"SORT_TYPE"
));
assertEquals
(
SortOrder
.
DESCENDING
,
rs
.
getInt
(
"SORT_TYPE"
));
rs
=
stat
.
executeQuery
(
"SELECT COUNT(*) FROM TEST WHERE ID BETWEEN 10 AND 20"
);
rs
=
stat
.
executeQuery
(
"SELECT COUNT(*) FROM TEST WHERE ID BETWEEN 10 AND 20"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
11
,
rs
.
getInt
(
1
));
assertEquals
(
11
,
rs
.
getInt
(
1
));
stat
.
execute
(
"DROP TABLE TEST"
);
stat
.
execute
(
"DROP TABLE TEST"
);
...
@@ -359,7 +367,8 @@ public class TestIndex extends TestBase {
...
@@ -359,7 +367,8 @@ public class TestIndex extends TestBase {
stat
.
execute
(
"CREATE TABLE TEST(ID INT, NAME VARCHAR)"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT, NAME VARCHAR)"
);
stat
.
execute
(
"CREATE INDEX IDXNAME ON TEST(NAME)"
);
stat
.
execute
(
"CREATE INDEX IDXNAME ON TEST(NAME)"
);
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
stat
.
execute
(
"INSERT INTO TEST VALUES("
+
i
+
", SPACE("
+
length
+
") || "
+
i
+
" )"
);
stat
.
execute
(
"INSERT INTO TEST VALUES("
+
i
+
", SPACE("
+
length
+
") || "
+
i
+
" )"
);
}
}
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM TEST ORDER BY NAME"
);
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM TEST ORDER BY NAME"
);
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
...
@@ -383,7 +392,8 @@ public class TestIndex extends TestBase {
...
@@ -383,7 +392,8 @@ public class TestIndex extends TestBase {
reconnect
();
reconnect
();
stat
.
execute
(
"CREATE TABLE ABC(ID INT, NAME VARCHAR)"
);
stat
.
execute
(
"CREATE TABLE ABC(ID INT, NAME VARCHAR)"
);
stat
.
execute
(
"INSERT INTO ABC VALUES(1, 'Hello')"
);
stat
.
execute
(
"INSERT INTO ABC VALUES(1, 'Hello')"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"SELECT * FROM ABC WHERE NAME LIKE CAST(? AS VARCHAR)"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"SELECT * FROM ABC WHERE NAME LIKE CAST(? AS VARCHAR)"
);
prep
.
setString
(
1
,
"Hi%"
);
prep
.
setString
(
1
,
"Hi%"
);
prep
.
execute
();
prep
.
execute
();
stat
.
execute
(
"DROP TABLE ABC"
);
stat
.
execute
(
"DROP TABLE ABC"
);
...
@@ -394,7 +404,8 @@ public class TestIndex extends TestBase {
...
@@ -394,7 +404,8 @@ public class TestIndex extends TestBase {
return
;
return
;
}
}
stat
.
execute
(
"CREATE TABLE PARENT(ID INT PRIMARY KEY)"
);
stat
.
execute
(
"CREATE TABLE PARENT(ID INT PRIMARY KEY)"
);
stat
.
execute
(
"CREATE TABLE CHILD(ID INT PRIMARY KEY, PID INT, FOREIGN KEY(PID) REFERENCES PARENT(ID))"
);
stat
.
execute
(
"CREATE TABLE CHILD(ID INT PRIMARY KEY, "
+
"PID INT, FOREIGN KEY(PID) REFERENCES PARENT(ID))"
);
reconnect
();
reconnect
();
stat
.
execute
(
"DROP TABLE PARENT"
);
stat
.
execute
(
"DROP TABLE PARENT"
);
stat
.
execute
(
"DROP TABLE CHILD"
);
stat
.
execute
(
"DROP TABLE CHILD"
);
...
@@ -406,7 +417,8 @@ public class TestIndex extends TestBase {
...
@@ -406,7 +417,8 @@ public class TestIndex extends TestBase {
stat
.
execute
(
"DROP TABLE IF EXISTS TEST"
);
stat
.
execute
(
"DROP TABLE IF EXISTS TEST"
);
stat
.
execute
(
"CREATE TABLE TEST(NAME VARCHAR("
+
i
+
"))"
);
stat
.
execute
(
"CREATE TABLE TEST(NAME VARCHAR("
+
i
+
"))"
);
stat
.
execute
(
"CREATE INDEX IDXNAME ON TEST(NAME)"
);
stat
.
execute
(
"CREATE INDEX IDXNAME ON TEST(NAME)"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"INSERT INTO TEST VALUES(?)"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"INSERT INTO TEST VALUES(?)"
);
for
(
int
j
=
0
;
j
<
getSize
(
2
,
5
);
j
++)
{
for
(
int
j
=
0
;
j
<
getSize
(
2
,
5
);
j
++)
{
prep
.
setString
(
1
,
getRandomString
(
i
));
prep
.
setString
(
1
,
getRandomString
(
i
));
prep
.
execute
();
prep
.
execute
();
...
@@ -416,7 +428,8 @@ public class TestIndex extends TestBase {
...
@@ -416,7 +428,8 @@ public class TestIndex extends TestBase {
conn
=
getConnection
(
"index"
);
conn
=
getConnection
(
"index"
);
stat
=
conn
.
createStatement
();
stat
=
conn
.
createStatement
();
}
}
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT COUNT(*) FROM TEST WHERE NAME > 'mdd'"
);
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT COUNT(*) FROM TEST WHERE NAME > 'mdd'"
);
rs
.
next
();
rs
.
next
();
int
count
=
rs
.
getInt
(
1
);
int
count
=
rs
.
getInt
(
1
);
trace
(
i
+
" count="
+
count
);
trace
(
i
+
" count="
+
count
);
...
@@ -425,7 +438,8 @@ public class TestIndex extends TestBase {
...
@@ -425,7 +438,8 @@ public class TestIndex extends TestBase {
stat
.
execute
(
"DROP TABLE IF EXISTS TEST"
);
stat
.
execute
(
"DROP TABLE IF EXISTS TEST"
);
}
}
private
void
testHashIndex
(
boolean
primaryKey
,
boolean
hash
)
throws
SQLException
{
private
void
testHashIndex
(
boolean
primaryKey
,
boolean
hash
)
throws
SQLException
{
if
(
config
.
memory
)
{
if
(
config
.
memory
)
{
return
;
return
;
}
}
...
@@ -434,7 +448,8 @@ public class TestIndex extends TestBase {
...
@@ -434,7 +448,8 @@ public class TestIndex extends TestBase {
stat
.
execute
(
"DROP TABLE IF EXISTS TEST"
);
stat
.
execute
(
"DROP TABLE IF EXISTS TEST"
);
if
(
primaryKey
)
{
if
(
primaryKey
)
{
stat
.
execute
(
"CREATE TABLE TEST(A INT PRIMARY KEY "
+
(
hash
?
"HASH"
:
""
)
+
", B INT)"
);
stat
.
execute
(
"CREATE TABLE TEST(A INT PRIMARY KEY "
+
(
hash
?
"HASH"
:
""
)
+
", B INT)"
);
}
else
{
}
else
{
stat
.
execute
(
"CREATE TABLE TEST(A INT, B INT)"
);
stat
.
execute
(
"CREATE TABLE TEST(A INT, B INT)"
);
stat
.
execute
(
"CREATE UNIQUE "
+
(
hash
?
"HASH"
:
""
)
+
" INDEX ON TEST(A)"
);
stat
.
execute
(
"CREATE UNIQUE "
+
(
hash
?
"HASH"
:
""
)
+
" INDEX ON TEST(A)"
);
...
@@ -446,8 +461,10 @@ public class TestIndex extends TestBase {
...
@@ -446,8 +461,10 @@ public class TestIndex extends TestBase {
prep
.
setInt
(
1
,
a
);
prep
.
setInt
(
1
,
a
);
prep
.
setInt
(
2
,
a
);
prep
.
setInt
(
2
,
a
);
prep
.
execute
();
prep
.
execute
();
assertEquals
(
1
,
getValue
(
"SELECT COUNT(*) FROM TEST WHERE A="
+
a
));
assertEquals
(
1
,
assertEquals
(
0
,
getValue
(
"SELECT COUNT(*) FROM TEST WHERE A=-1-"
+
a
));
getValue
(
"SELECT COUNT(*) FROM TEST WHERE A="
+
a
));
assertEquals
(
0
,
getValue
(
"SELECT COUNT(*) FROM TEST WHERE A=-1-"
+
a
));
}
}
reconnect
();
reconnect
();
...
@@ -455,7 +472,8 @@ public class TestIndex extends TestBase {
...
@@ -455,7 +472,8 @@ public class TestIndex extends TestBase {
prep
=
conn
.
prepareStatement
(
"DELETE FROM TEST WHERE A=?"
);
prep
=
conn
.
prepareStatement
(
"DELETE FROM TEST WHERE A=?"
);
for
(
int
a
=
0
;
a
<
len
;
a
++)
{
for
(
int
a
=
0
;
a
<
len
;
a
++)
{
if
(
getValue
(
"SELECT COUNT(*) FROM TEST WHERE A="
+
a
)
!=
1
)
{
if
(
getValue
(
"SELECT COUNT(*) FROM TEST WHERE A="
+
a
)
!=
1
)
{
assertEquals
(
1
,
getValue
(
"SELECT COUNT(*) FROM TEST WHERE A="
+
a
));
assertEquals
(
1
,
getValue
(
"SELECT COUNT(*) FROM TEST WHERE A="
+
a
));
}
}
prep
.
setInt
(
1
,
a
);
prep
.
setInt
(
1
,
a
);
assertEquals
(
1
,
prep
.
executeUpdate
());
assertEquals
(
1
,
prep
.
executeUpdate
());
...
@@ -479,7 +497,8 @@ public class TestIndex extends TestBase {
...
@@ -479,7 +497,8 @@ public class TestIndex extends TestBase {
prep
=
conn
.
prepareStatement
(
"DELETE FROM TEST WHERE A=?"
);
prep
=
conn
.
prepareStatement
(
"DELETE FROM TEST WHERE A=?"
);
for
(
int
a
=
0
;
a
<
len
;
a
++)
{
for
(
int
a
=
0
;
a
<
len
;
a
++)
{
log
(
"SELECT * FROM TEST"
);
log
(
"SELECT * FROM TEST"
);
assertEquals
(
2
,
getValue
(
"SELECT COUNT(*) FROM TEST WHERE A="
+
(
len
-
a
-
1
)));
assertEquals
(
2
,
getValue
(
"SELECT COUNT(*) FROM TEST WHERE A="
+
(
len
-
a
-
1
)));
assertEquals
((
len
-
a
)
*
2
,
getValue
(
"SELECT COUNT(*) FROM TEST"
));
assertEquals
((
len
-
a
)
*
2
,
getValue
(
"SELECT COUNT(*) FROM TEST"
));
prep
.
setInt
(
1
,
len
-
a
-
1
);
prep
.
setInt
(
1
,
len
-
a
-
1
);
prep
.
execute
();
prep
.
execute
();
...
@@ -510,7 +529,8 @@ public class TestIndex extends TestBase {
...
@@ -510,7 +529,8 @@ public class TestIndex extends TestBase {
reconnect
();
reconnect
();
prep
=
conn
.
prepareStatement
(
"UPDATE TEST SET DATA=DATA||? WHERE A=? AND B=?"
);
prep
=
conn
.
prepareStatement
(
"UPDATE TEST SET DATA=DATA||? WHERE A=? AND B=?"
);
for
(
int
a
=
0
;
a
<
len
;
a
++)
{
for
(
int
a
=
0
;
a
<
len
;
a
++)
{
for
(
int
b
=
0
;
b
<
len
;
b
+=
2
)
{
for
(
int
b
=
0
;
b
<
len
;
b
+=
2
)
{
prep
.
setString
(
1
,
"u("
+
a
+
","
+
b
+
")"
);
prep
.
setString
(
1
,
"u("
+
a
+
","
+
b
+
")"
);
...
@@ -522,7 +542,8 @@ public class TestIndex extends TestBase {
...
@@ -522,7 +542,8 @@ public class TestIndex extends TestBase {
reconnect
();
reconnect
();
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM TEST WHERE DATA <> 'i('||a||','||b||')u('||a||','||b||')'"
);
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM TEST WHERE DATA <> 'i('||a||','||b||')u('||a||','||b||')'"
);
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
assertEquals
(
len
*
(
len
/
2
),
getValue
(
"SELECT COUNT(*) FROM TEST"
));
assertEquals
(
len
*
(
len
/
2
),
getValue
(
"SELECT COUNT(*) FROM TEST"
));
stat
.
execute
(
"DROP TABLE TEST"
);
stat
.
execute
(
"DROP TABLE TEST"
);
...
@@ -534,11 +555,13 @@ public class TestIndex extends TestBase {
...
@@ -534,11 +555,13 @@ public class TestIndex extends TestBase {
stat
.
execute
(
"create memory table hash_index_test as "
+
stat
.
execute
(
"create memory table hash_index_test as "
+
"select x as id, x % 10 as data from (select * from system_range(1, 100))"
);
"select x as id, x % 10 as data from (select * from system_range(1, 100))"
);
stat
.
execute
(
"create hash index idx2 on hash_index_test(data)"
);
stat
.
execute
(
"create hash index idx2 on hash_index_test(data)"
);
assertEquals
(
10
,
getValue
(
"select count(*) from hash_index_test where data = 1"
));
assertEquals
(
10
,
getValue
(
"select count(*) from hash_index_test where data = 1"
));
stat
.
execute
(
"drop index idx2"
);
stat
.
execute
(
"drop index idx2"
);
stat
.
execute
(
"create unique hash index idx2 on hash_index_test(id)"
);
stat
.
execute
(
"create unique hash index idx2 on hash_index_test(id)"
);
assertEquals
(
1
,
getValue
(
"select count(*) from hash_index_test where id = 1"
));
assertEquals
(
1
,
getValue
(
"select count(*) from hash_index_test where id = 1"
));
}
}
private
int
getValue
(
String
sql
)
throws
SQLException
{
private
int
getValue
(
String
sql
)
throws
SQLException
{
...
...
h2/src/test/org/h2/test/db/TestLinkedTable.java
浏览文件 @
b3836d31
...
@@ -74,7 +74,8 @@ public class TestLinkedTable extends TestBase {
...
@@ -74,7 +74,8 @@ public class TestLinkedTable extends TestBase {
conn
.
close
();
conn
.
close
();
conn
=
getConnection
(
"linkedTable1"
);
conn
=
getConnection
(
"linkedTable1"
);
stat
=
conn
.
createStatement
();
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create linked table link(null, '"
+
url2
+
"', '"
+
user
+
"', '"
+
password
+
"', 'TEST')"
);
stat
.
execute
(
"create linked table link(null, '"
+
url2
+
"', '"
+
user
+
"', '"
+
password
+
"', 'TEST')"
);
conn
.
close
();
conn
.
close
();
conn
=
getConnection
(
"linkedTable1"
);
conn
=
getConnection
(
"linkedTable1"
);
conn
.
close
();
conn
.
close
();
...
@@ -91,8 +92,10 @@ public class TestLinkedTable extends TestBase {
...
@@ -91,8 +92,10 @@ public class TestLinkedTable extends TestBase {
Connection
conn
=
getConnection
(
"linkedTable"
);
Connection
conn
=
getConnection
(
"linkedTable"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create linked table test1('', 'jdbc:h2:mem:linkedTable', '', '', 'TEST') emit updates"
);
stat
.
execute
(
"create linked table test1('', "
+
stat
.
execute
(
"create linked table test2('', 'jdbc:h2:mem:linkedTable', '', '', 'TEST')"
);
"'jdbc:h2:mem:linkedTable', '', '', 'TEST') emit updates"
);
stat
.
execute
(
"create linked table test2('', "
+
"'jdbc:h2:mem:linkedTable', '', '', 'TEST')"
);
stat
.
execute
(
"insert into test1 values(default, default)"
);
stat
.
execute
(
"insert into test1 values(default, default)"
);
stat
.
execute
(
"insert into test2 values(default, default)"
);
stat
.
execute
(
"insert into test2 values(default, default)"
);
stat
.
execute
(
"merge into test2 values(3, default)"
);
stat
.
execute
(
"merge into test2 values(3, default)"
);
...
@@ -127,17 +130,18 @@ public class TestLinkedTable extends TestBase {
...
@@ -127,17 +130,18 @@ public class TestLinkedTable extends TestBase {
}
}
org
.
h2
.
Driver
.
load
();
org
.
h2
.
Driver
.
load
();
deleteDb
(
"linkedTable"
);
deleteDb
(
"linkedTable"
);
Connection
conn
=
getConnection
(
"linkedTable;SHARE_LINKED_CONNECTIONS=TRUE"
);
Connection
conn
=
getConnection
(
"linkedTable;SHARE_LINKED_CONNECTIONS=TRUE"
);
try
{
try
{
conn
.
createStatement
().
execute
(
conn
.
createStatement
().
execute
(
"create linked table test"
+
"
create linked table test
(null, 'jdbc:h2:mem:', 'sa', 'pwd', 'DUAL2')"
);
"(null, 'jdbc:h2:mem:', 'sa', 'pwd', 'DUAL2')"
);
fail
();
fail
();
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
assertTrue
(
e
.
toString
().
indexOf
(
"pwd"
)
>=
0
);
assertTrue
(
e
.
toString
().
indexOf
(
"pwd"
)
>=
0
);
}
}
try
{
try
{
conn
.
createStatement
().
execute
(
conn
.
createStatement
().
execute
(
"create linked table test"
+
"
create linked table test
(null, 'jdbc:h2:mem:', 'sa', 'pwd', 'DUAL2') --hide--"
);
"(null, 'jdbc:h2:mem:', 'sa', 'pwd', 'DUAL2') --hide--"
);
fail
();
fail
();
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
assertTrue
(
e
.
toString
().
indexOf
(
"pwd"
)
<
0
);
assertTrue
(
e
.
toString
().
indexOf
(
"pwd"
)
<
0
);
...
@@ -180,8 +184,10 @@ public class TestLinkedTable extends TestBase {
...
@@ -180,8 +184,10 @@ public class TestLinkedTable extends TestBase {
ca
.
close
();
ca
.
close
();
Connection
cb
=
DriverManager
.
getConnection
(
"jdbc:h2:mem:two"
,
"sa"
,
"sa"
);
Connection
cb
=
DriverManager
.
getConnection
(
"jdbc:h2:mem:two"
,
"sa"
,
"sa"
);
Statement
sb
=
cb
.
createStatement
();
Statement
sb
=
cb
.
createStatement
();
sb
.
execute
(
"CREATE LINKED TABLE T1(NULL, '"
+
url
+
"', '"
+
user
+
"', '"
+
password
+
"', 'TEST')"
);
sb
.
execute
(
"CREATE LINKED TABLE T1(NULL, '"
+
sb
.
executeQuery
(
"SELECT * FROM DUAL A LEFT OUTER JOIN T1 A ON A.ID=1 LEFT OUTER JOIN T1 B ON B.ID=1"
);
url
+
"', '"
+
user
+
"', '"
+
password
+
"', 'TEST')"
);
sb
.
executeQuery
(
"SELECT * FROM DUAL A "
+
"LEFT OUTER JOIN T1 A ON A.ID=1 LEFT OUTER JOIN T1 B ON B.ID=1"
);
sb
.
execute
(
"DROP ALL OBJECTS"
);
sb
.
execute
(
"DROP ALL OBJECTS"
);
cb
.
close
();
cb
.
close
();
}
}
...
@@ -201,8 +207,10 @@ public class TestLinkedTable extends TestBase {
...
@@ -201,8 +207,10 @@ public class TestLinkedTable extends TestBase {
ca
.
close
();
ca
.
close
();
Connection
cb
=
DriverManager
.
getConnection
(
"jdbc:h2:mem:two"
,
"sa"
,
"sa"
);
Connection
cb
=
DriverManager
.
getConnection
(
"jdbc:h2:mem:two"
,
"sa"
,
"sa"
);
Statement
sb
=
cb
.
createStatement
();
Statement
sb
=
cb
.
createStatement
();
sb
.
execute
(
"CREATE LINKED TABLE T1(NULL, '"
+
url
+
";OPEN_NEW=TRUE', '"
+
user
+
"', '"
+
password
+
"', 'TEST')"
);
sb
.
execute
(
"CREATE LINKED TABLE T1(NULL, '"
+
url
+
sb
.
execute
(
"CREATE LINKED TABLE T2(NULL, '"
+
url
+
";OPEN_NEW=TRUE', '"
+
user
+
"', '"
+
password
+
"', 'TEST')"
);
";OPEN_NEW=TRUE', '"
+
user
+
"', '"
+
password
+
"', 'TEST')"
);
sb
.
execute
(
"CREATE LINKED TABLE T2(NULL, '"
+
url
+
";OPEN_NEW=TRUE', '"
+
user
+
"', '"
+
password
+
"', 'TEST')"
);
sb
.
execute
(
"DROP ALL OBJECTS"
);
sb
.
execute
(
"DROP ALL OBJECTS"
);
cb
.
close
();
cb
.
close
();
}
}
...
@@ -219,9 +227,12 @@ public class TestLinkedTable extends TestBase {
...
@@ -219,9 +227,12 @@ public class TestLinkedTable extends TestBase {
sa
.
execute
(
"INSERT INTO TEST VALUES(1)"
);
sa
.
execute
(
"INSERT INTO TEST VALUES(1)"
);
sa
.
execute
(
"INSERT INTO P.TEST VALUES(2)"
);
sa
.
execute
(
"INSERT INTO P.TEST VALUES(2)"
);
assertThrows
(
ErrorCode
.
SCHEMA_NAME_MUST_MATCH
,
sb
).
assertThrows
(
ErrorCode
.
SCHEMA_NAME_MUST_MATCH
,
sb
).
execute
(
"CREATE LINKED TABLE T(NULL, 'jdbc:h2:mem:one', 'sa', 'sa', 'TEST')"
);
execute
(
"CREATE LINKED TABLE T(NULL, "
+
sb
.
execute
(
"CREATE LINKED TABLE T(NULL, 'jdbc:h2:mem:one', 'sa', 'sa', 'PUBLIC', 'TEST')"
);
"'jdbc:h2:mem:one', 'sa', 'sa', 'TEST')"
);
sb
.
execute
(
"CREATE LINKED TABLE T2(NULL, 'jdbc:h2:mem:one', 'sa', 'sa', 'P', 'TEST')"
);
sb
.
execute
(
"CREATE LINKED TABLE T(NULL, "
+
"'jdbc:h2:mem:one', 'sa', 'sa', 'PUBLIC', 'TEST')"
);
sb
.
execute
(
"CREATE LINKED TABLE T2(NULL, "
+
"'jdbc:h2:mem:one', 'sa', 'sa', 'P', 'TEST')"
);
assertSingleValue
(
sb
,
"SELECT * FROM T"
,
1
);
assertSingleValue
(
sb
,
"SELECT * FROM T"
,
1
);
assertSingleValue
(
sb
,
"SELECT * FROM T2"
,
2
);
assertSingleValue
(
sb
,
"SELECT * FROM T2"
,
2
);
sa
.
execute
(
"DROP ALL OBJECTS"
);
sa
.
execute
(
"DROP ALL OBJECTS"
);
...
@@ -242,10 +253,12 @@ public class TestLinkedTable extends TestBase {
...
@@ -242,10 +253,12 @@ public class TestLinkedTable extends TestBase {
sa
.
execute
(
"INSERT INTO TEST VALUES(1)"
);
sa
.
execute
(
"INSERT INTO TEST VALUES(1)"
);
String
[]
suffix
=
{
""
,
"READONLY"
,
"EMIT UPDATES"
};
String
[]
suffix
=
{
""
,
"READONLY"
,
"EMIT UPDATES"
};
for
(
int
i
=
0
;
i
<
suffix
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
suffix
.
length
;
i
++)
{
String
sql
=
"CREATE LINKED TABLE T(NULL, 'jdbc:h2:mem:one', 'sa', 'sa', 'TEST')"
+
suffix
[
i
];
String
sql
=
"CREATE LINKED TABLE T(NULL, "
+
"'jdbc:h2:mem:one', 'sa', 'sa', 'TEST')"
+
suffix
[
i
];
sb
.
execute
(
sql
);
sb
.
execute
(
sql
);
sb
.
executeQuery
(
"SELECT * FROM T"
);
sb
.
executeQuery
(
"SELECT * FROM T"
);
String
[]
update
=
{
"DELETE FROM T"
,
"INSERT INTO T VALUES(2)"
,
"UPDATE T SET ID = 3"
};
String
[]
update
=
{
"DELETE FROM T"
,
"INSERT INTO T VALUES(2)"
,
"UPDATE T SET ID = 3"
};
for
(
String
u
:
update
)
{
for
(
String
u
:
update
)
{
try
{
try
{
sb
.
execute
(
u
);
sb
.
execute
(
u
);
...
@@ -275,8 +288,10 @@ public class TestLinkedTable extends TestBase {
...
@@ -275,8 +288,10 @@ public class TestLinkedTable extends TestBase {
sa
.
execute
(
"CREATE TABLE GOOD (X NUMBER)"
);
sa
.
execute
(
"CREATE TABLE GOOD (X NUMBER)"
);
sa
.
execute
(
"CREATE SCHEMA S"
);
sa
.
execute
(
"CREATE SCHEMA S"
);
sa
.
execute
(
"CREATE TABLE S.BAD (X NUMBER)"
);
sa
.
execute
(
"CREATE TABLE S.BAD (X NUMBER)"
);
sb
.
execute
(
"CALL LINK_SCHEMA('G', '', 'jdbc:h2:mem:one', 'sa', 'sa', 'PUBLIC'); "
);
sb
.
execute
(
"CALL LINK_SCHEMA('G', '', "
+
sb
.
execute
(
"CALL LINK_SCHEMA('B', '', 'jdbc:h2:mem:one', 'sa', 'sa', 'S'); "
);
"'jdbc:h2:mem:one', 'sa', 'sa', 'PUBLIC'); "
);
sb
.
execute
(
"CALL LINK_SCHEMA('B', '', "
+
"'jdbc:h2:mem:one', 'sa', 'sa', 'S'); "
);
// OK
// OK
sb
.
executeQuery
(
"SELECT * FROM G.GOOD"
);
sb
.
executeQuery
(
"SELECT * FROM G.GOOD"
);
// FAILED
// FAILED
...
@@ -287,7 +302,8 @@ public class TestLinkedTable extends TestBase {
...
@@ -287,7 +302,8 @@ public class TestLinkedTable extends TestBase {
private
void
testLinkTwoTables
()
throws
SQLException
{
private
void
testLinkTwoTables
()
throws
SQLException
{
org
.
h2
.
Driver
.
load
();
org
.
h2
.
Driver
.
load
();
Connection
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:mem:one"
,
"sa"
,
"sa"
);
Connection
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:mem:one"
,
"sa"
,
"sa"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE SCHEMA Y"
);
stat
.
execute
(
"CREATE SCHEMA Y"
);
stat
.
execute
(
"CREATE TABLE A( C INT)"
);
stat
.
execute
(
"CREATE TABLE A( C INT)"
);
...
@@ -296,8 +312,10 @@ public class TestLinkedTable extends TestBase {
...
@@ -296,8 +312,10 @@ public class TestLinkedTable extends TestBase {
stat
.
execute
(
"INSERT INTO Y.A VALUES(2)"
);
stat
.
execute
(
"INSERT INTO Y.A VALUES(2)"
);
Connection
conn2
=
DriverManager
.
getConnection
(
"jdbc:h2:mem:two"
);
Connection
conn2
=
DriverManager
.
getConnection
(
"jdbc:h2:mem:two"
);
Statement
stat2
=
conn2
.
createStatement
();
Statement
stat2
=
conn2
.
createStatement
();
stat2
.
execute
(
"CREATE LINKED TABLE one('org.h2.Driver', 'jdbc:h2:mem:one', 'sa', 'sa', 'Y.A');"
);
stat2
.
execute
(
"CREATE LINKED TABLE one('org.h2.Driver', "
+
stat2
.
execute
(
"CREATE LINKED TABLE two('org.h2.Driver', 'jdbc:h2:mem:one', 'sa', 'sa', 'PUBLIC.A');"
);
"'jdbc:h2:mem:one', 'sa', 'sa', 'Y.A');"
);
stat2
.
execute
(
"CREATE LINKED TABLE two('org.h2.Driver', "
+
"'jdbc:h2:mem:one', 'sa', 'sa', 'PUBLIC.A');"
);
ResultSet
rs
=
stat2
.
executeQuery
(
"SELECT * FROM one"
);
ResultSet
rs
=
stat2
.
executeQuery
(
"SELECT * FROM one"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
2
,
rs
.
getInt
(
1
));
assertEquals
(
2
,
rs
.
getInt
(
1
));
...
@@ -315,7 +333,8 @@ public class TestLinkedTable extends TestBase {
...
@@ -315,7 +333,8 @@ public class TestLinkedTable extends TestBase {
statA
.
execute
(
"CREATE TABLE TEST(ID INT)"
);
statA
.
execute
(
"CREATE TABLE TEST(ID INT)"
);
Connection
connB
=
DriverManager
.
getConnection
(
"jdbc:h2:mem:b"
);
Connection
connB
=
DriverManager
.
getConnection
(
"jdbc:h2:mem:b"
);
Statement
statB
=
connB
.
createStatement
();
Statement
statB
=
connB
.
createStatement
();
statB
.
execute
(
"CREATE LINKED TABLE TEST_LINK('', 'jdbc:h2:mem:a', '', '', 'TEST')"
);
statB
.
execute
(
"CREATE LINKED TABLE "
+
"TEST_LINK('', 'jdbc:h2:mem:a', '', '', 'TEST')"
);
connA
.
close
();
connA
.
close
();
// the connection should be closed now
// the connection should be closed now
// (and the table should disappear because the last connection was
// (and the table should disappear because the last connection was
...
@@ -350,7 +369,8 @@ public class TestLinkedTable extends TestBase {
...
@@ -350,7 +369,8 @@ public class TestLinkedTable extends TestBase {
String
link
=
"CREATE LINKED TABLE TEST_LINK_U('', '"
+
url1
String
link
=
"CREATE LINKED TABLE TEST_LINK_U('', '"
+
url1
+
"', 'sa1', 'abc abc', 'TEST') EMIT UPDATES"
;
+
"', 'sa1', 'abc abc', 'TEST') EMIT UPDATES"
;
stat2
.
execute
(
link
);
stat2
.
execute
(
link
);
link
=
"CREATE LINKED TABLE TEST_LINK_DI('', '"
+
url1
+
"', 'sa1', 'abc abc', 'TEST')"
;
link
=
"CREATE LINKED TABLE TEST_LINK_DI('', '"
+
url1
+
"', 'sa1', 'abc abc', 'TEST')"
;
stat2
.
execute
(
link
);
stat2
.
execute
(
link
);
stat2
.
executeUpdate
(
"INSERT INTO TEST_LINK_U VALUES(1, 'Hello')"
);
stat2
.
executeUpdate
(
"INSERT INTO TEST_LINK_U VALUES(1, 'Hello')"
);
stat2
.
executeUpdate
(
"INSERT INTO TEST_LINK_DI VALUES(2, 'World')"
);
stat2
.
executeUpdate
(
"INSERT INTO TEST_LINK_DI VALUES(2, 'World')"
);
...
@@ -408,7 +428,8 @@ public class TestLinkedTable extends TestBase {
...
@@ -408,7 +428,8 @@ public class TestLinkedTable extends TestBase {
Connection
conn2
=
DriverManager
.
getConnection
(
url2
,
"sa2"
,
"def def"
);
Connection
conn2
=
DriverManager
.
getConnection
(
url2
,
"sa2"
,
"def def"
);
Statement
stat2
=
conn2
.
createStatement
();
Statement
stat2
=
conn2
.
createStatement
();
String
link
=
"CALL LINK_SCHEMA('LINKED', '', '"
+
url1
+
"', 'sa1', 'abc abc', 'PUBLIC')"
;
String
link
=
"CALL LINK_SCHEMA('LINKED', '', '"
+
url1
+
"', 'sa1', 'abc abc', 'PUBLIC')"
;
stat2
.
execute
(
link
);
stat2
.
execute
(
link
);
stat2
.
executeQuery
(
"SELECT * FROM LINKED.TEST1"
);
stat2
.
executeQuery
(
"SELECT * FROM LINKED.TEST1"
);
...
@@ -465,10 +486,12 @@ public class TestLinkedTable extends TestBase {
...
@@ -465,10 +486,12 @@ public class TestLinkedTable extends TestBase {
conn
=
DriverManager
.
getConnection
(
url2
,
"sa2"
,
"def def"
);
conn
=
DriverManager
.
getConnection
(
url2
,
"sa2"
,
"def def"
);
stat
=
conn
.
createStatement
();
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE LINKED TABLE IF NOT EXISTS LINK_TEST('org.h2.Driver', '"
+
url1
stat
.
execute
(
"CREATE LINKED TABLE IF NOT EXISTS "
+
+
"', 'sa1', 'abc abc', 'TEST')"
);
"LINK_TEST('org.h2.Driver', '"
+
url1
+
stat
.
execute
(
"CREATE LINKED TABLE IF NOT EXISTS LINK_TEST('org.h2.Driver', '"
+
url1
"', 'sa1', 'abc abc', 'TEST')"
);
+
"', 'sa1', 'abc abc', 'TEST')"
);
stat
.
execute
(
"CREATE LINKED TABLE IF NOT EXISTS "
+
"LINK_TEST('org.h2.Driver', '"
+
url1
+
"', 'sa1', 'abc abc', 'TEST')"
);
testRow
(
stat
,
"LINK_TEST"
);
testRow
(
stat
,
"LINK_TEST"
);
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM LINK_TEST"
);
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM LINK_TEST"
);
ResultSetMetaData
meta
=
rs
.
getMetaData
();
ResultSetMetaData
meta
=
rs
.
getMetaData
();
...
@@ -499,7 +522,8 @@ public class TestLinkedTable extends TestBase {
...
@@ -499,7 +522,8 @@ public class TestLinkedTable extends TestBase {
rs
.
next
();
rs
.
next
();
assertEquals
(
3
,
rs
.
getInt
(
1
));
assertEquals
(
3
,
rs
.
getInt
(
1
));
rs
=
stat
.
executeQuery
(
"SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='LINK_TEST'"
);
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
"INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='LINK_TEST'"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
"TABLE LINK"
,
rs
.
getString
(
"TABLE_TYPE"
));
assertEquals
(
"TABLE LINK"
,
rs
.
getString
(
"TABLE_TYPE"
));
...
@@ -561,19 +585,26 @@ public class TestLinkedTable extends TestBase {
...
@@ -561,19 +585,26 @@ public class TestLinkedTable extends TestBase {
private
void
testCachingResults
()
throws
SQLException
{
private
void
testCachingResults
()
throws
SQLException
{
org
.
h2
.
Driver
.
load
();
org
.
h2
.
Driver
.
load
();
Connection
ca
=
DriverManager
.
getConnection
(
"jdbc:h2:mem:one"
,
"sa"
,
"sa"
);
Connection
ca
=
DriverManager
.
getConnection
(
Connection
cb
=
DriverManager
.
getConnection
(
"jdbc:h2:mem:two"
,
"sa"
,
"sa"
);
"jdbc:h2:mem:one"
,
"sa"
,
"sa"
);
Connection
cb
=
DriverManager
.
getConnection
(
"jdbc:h2:mem:two"
,
"sa"
,
"sa"
);
Statement
sa
=
ca
.
createStatement
();
Statement
sa
=
ca
.
createStatement
();
Statement
sb
=
cb
.
createStatement
();
Statement
sb
=
cb
.
createStatement
();
sa
.
execute
(
"CREATE TABLE TEST(ID VARCHAR)"
);
sa
.
execute
(
"CREATE TABLE TEST(ID VARCHAR)"
);
sa
.
execute
(
"INSERT INTO TEST (ID) VALUES('abc')"
);
sa
.
execute
(
"INSERT INTO TEST (ID) VALUES('abc')"
);
sb
.
execute
(
"CREATE LOCAL TEMPORARY LINKED TABLE T(NULL, 'jdbc:h2:mem:one', 'sa', 'sa', 'TEST')"
);
sb
.
execute
(
"CREATE LOCAL TEMPORARY LINKED TABLE T"
+
"(NULL, 'jdbc:h2:mem:one', 'sa', 'sa', 'TEST')"
);
PreparedStatement
paData
=
ca
.
prepareStatement
(
"select id from TEST where id = ?"
);
PreparedStatement
pbData
=
cb
.
prepareStatement
(
"select id from T where id = ?"
);
PreparedStatement
paData
=
ca
.
prepareStatement
(
PreparedStatement
paCount
=
ca
.
prepareStatement
(
"select count(*) from TEST"
);
"select id from TEST where id = ?"
);
PreparedStatement
pbCount
=
cb
.
prepareStatement
(
"select count(*) from T"
);
PreparedStatement
pbData
=
cb
.
prepareStatement
(
"select id from T where id = ?"
);
PreparedStatement
paCount
=
ca
.
prepareStatement
(
"select count(*) from TEST"
);
PreparedStatement
pbCount
=
cb
.
prepareStatement
(
"select count(*) from T"
);
// Direct query => Result 1
// Direct query => Result 1
testCachingResultsCheckResult
(
paData
,
1
,
"abc"
);
testCachingResultsCheckResult
(
paData
,
1
,
"abc"
);
...
@@ -597,13 +628,15 @@ public class TestLinkedTable extends TestBase {
...
@@ -597,13 +628,15 @@ public class TestLinkedTable extends TestBase {
cb
.
close
();
cb
.
close
();
}
}
private
void
testCachingResultsCheckResult
(
PreparedStatement
ps
,
int
expected
)
throws
SQLException
{
private
void
testCachingResultsCheckResult
(
PreparedStatement
ps
,
int
expected
)
throws
SQLException
{
ResultSet
rs
=
ps
.
executeQuery
();
ResultSet
rs
=
ps
.
executeQuery
();
rs
.
next
();
rs
.
next
();
assertEquals
(
expected
,
rs
.
getInt
(
1
));
assertEquals
(
expected
,
rs
.
getInt
(
1
));
}
}
private
void
testCachingResultsCheckResult
(
PreparedStatement
ps
,
int
expected
,
String
value
)
throws
SQLException
{
private
void
testCachingResultsCheckResult
(
PreparedStatement
ps
,
int
expected
,
String
value
)
throws
SQLException
{
ps
.
setString
(
1
,
value
);
ps
.
setString
(
1
,
value
);
ResultSet
rs
=
ps
.
executeQuery
();
ResultSet
rs
=
ps
.
executeQuery
();
int
counter
=
0
;
int
counter
=
0
;
...
@@ -623,7 +656,8 @@ public class TestLinkedTable extends TestBase {
...
@@ -623,7 +656,8 @@ public class TestLinkedTable extends TestBase {
deleteDb
(
"testLinkedTableInReadOnlyDb"
);
deleteDb
(
"testLinkedTableInReadOnlyDb"
);
org
.
h2
.
Driver
.
load
();
org
.
h2
.
Driver
.
load
();
Connection
memConn
=
DriverManager
.
getConnection
(
"jdbc:h2:mem:one"
,
"sa"
,
"sa"
);
Connection
memConn
=
DriverManager
.
getConnection
(
"jdbc:h2:mem:one"
,
"sa"
,
"sa"
);
Statement
memStat
=
memConn
.
createStatement
();
Statement
memStat
=
memConn
.
createStatement
();
memStat
.
execute
(
"CREATE TABLE TEST(ID VARCHAR)"
);
memStat
.
execute
(
"CREATE TABLE TEST(ID VARCHAR)"
);
...
@@ -635,7 +669,8 @@ public class TestLinkedTable extends TestBase {
...
@@ -635,7 +669,8 @@ public class TestLinkedTable extends TestBase {
for
(
String
file
:
FileUtils
.
newDirectoryStream
(
getBaseDir
()))
{
for
(
String
file
:
FileUtils
.
newDirectoryStream
(
getBaseDir
()))
{
String
name
=
FileUtils
.
getName
(
file
);
String
name
=
FileUtils
.
getName
(
file
);
if
((
name
.
startsWith
(
"testLinkedTableInReadOnlyDb"
))
&&
(!
name
.
endsWith
(
".trace.db"
)))
{
if
((
name
.
startsWith
(
"testLinkedTableInReadOnlyDb"
))
&&
(!
name
.
endsWith
(
".trace.db"
)))
{
FileUtils
.
setReadOnly
(
file
);
FileUtils
.
setReadOnly
(
file
);
boolean
isReadOnly
=
!
FileUtils
.
canWrite
(
file
);
boolean
isReadOnly
=
!
FileUtils
.
canWrite
(
file
);
if
(!
isReadOnly
)
{
if
(!
isReadOnly
)
{
...
@@ -647,7 +682,8 @@ public class TestLinkedTable extends TestBase {
...
@@ -647,7 +682,8 @@ public class TestLinkedTable extends TestBase {
// Now it's read only
// Now it's read only
conn
=
DriverManager
.
getConnection
(
url1
,
"sa1"
,
"abc abc"
);
conn
=
DriverManager
.
getConnection
(
url1
,
"sa1"
,
"abc abc"
);
stat
=
conn
.
createStatement
();
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE LOCAL TEMPORARY LINKED TABLE T(NULL, 'jdbc:h2:mem:one', 'sa', 'sa', 'TEST')"
);
stat
.
execute
(
"CREATE LOCAL TEMPORARY LINKED TABLE T"
+
"(NULL, 'jdbc:h2:mem:one', 'sa', 'sa', 'TEST')"
);
// This is valid because it's a linked table
// This is valid because it's a linked table
stat
.
execute
(
"INSERT INTO T VALUES('abc')"
);
stat
.
execute
(
"INSERT INTO T VALUES('abc')"
);
...
...
h2/src/test/org/h2/test/db/TestView.java
浏览文件 @
b3836d31
...
@@ -188,7 +188,8 @@ public class TestView extends TestBase {
...
@@ -188,7 +188,8 @@ public class TestView extends TestBase {
for
(
int
i
=
0
;
i
<
30
;
i
++)
{
for
(
int
i
=
0
;
i
<
30
;
i
++)
{
s
.
execute
(
"create view t"
+
(
i
+
1
)
+
" as select * from t"
+
i
);
s
.
execute
(
"create view t"
+
(
i
+
1
)
+
" as select * from t"
+
i
);
s
.
execute
(
"select * from t"
+
(
i
+
1
));
s
.
execute
(
"select * from t"
+
(
i
+
1
));
ResultSet
rs
=
s
.
executeQuery
(
"select count(*) from t"
+
(
i
+
1
)
+
" where id=2"
);
ResultSet
rs
=
s
.
executeQuery
(
"select count(*) from t"
+
(
i
+
1
)
+
" where id=2"
);
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
next
());
assertEquals
(
1
,
rs
.
getInt
(
1
));
assertEquals
(
1
,
rs
.
getInt
(
1
));
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论