Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
40e873c7
提交
40e873c7
authored
2月 21, 2008
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
--no commit message
--no commit message
上级
1c06fd6a
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
99 行增加
和
5 行删除
+99
-5
Parser.java
h2/src/main/org/h2/command/Parser.java
+1
-1
SysProperties.java
h2/src/main/org/h2/constant/SysProperties.java
+0
-1
Function.java
h2/src/main/org/h2/expression/Function.java
+44
-1
help.csv
h2/src/main/org/h2/res/help.csv
+14
-0
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+2
-0
TestFunctions.java
h2/src/test/org/h2/test/db/TestFunctions.java
+32
-0
SelfDestructor.java
h2/src/test/org/h2/test/unit/SelfDestructor.java
+4
-1
dictionary.txt
h2/src/tools/org/h2/tools/doc/dictionary.txt
+2
-1
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
40e873c7
...
...
@@ -1407,7 +1407,7 @@ public class Parser {
private
void
parseSelectSimpleSelectPart
(
Select
command
)
throws
SQLException
{
Select
temp
=
currentSelect
;
// make sure aggregate functions will not work in TOP and LIMIT
clauses
// make sure aggregate functions will not work in TOP and LIMIT
currentSelect
=
null
;
if
(
readIf
(
"TOP"
))
{
// can't read more complex expressions here because
...
...
h2/src/main/org/h2/constant/SysProperties.java
浏览文件 @
40e873c7
...
...
@@ -301,7 +301,6 @@ public class SysProperties {
* System property <code>h2.reuseSpaceQuickly</code> (default: true).<br />
* Reuse space in database files quickly.
*/
private
int
test
;
public
static
final
boolean
REUSE_SPACE_QUICKLY
=
getBooleanSetting
(
"h2.reuseSpaceQuickly"
,
true
);
/**
...
...
h2/src/main/org/h2/expression/Function.java
浏览文件 @
40e873c7
...
...
@@ -4,6 +4,10 @@
*/
package
org
.
h2
.
expression
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.io.Reader
;
import
java.sql.Connection
;
import
java.sql.Date
;
import
java.sql.ResultSet
;
...
...
@@ -33,6 +37,8 @@ import org.h2.table.LinkSchema;
import
org.h2.table.TableFilter
;
import
org.h2.tools.CompressTool
;
import
org.h2.tools.Csv
;
import
org.h2.util.AutoCloseInputStream
;
import
org.h2.util.FileUtils
;
import
org.h2.util.MathUtils
;
import
org.h2.util.MemoryUtils
;
import
org.h2.util.ObjectArray
;
...
...
@@ -46,6 +52,7 @@ import org.h2.value.ValueBytes;
import
org.h2.value.ValueDate
;
import
org.h2.value.ValueDouble
;
import
org.h2.value.ValueInt
;
import
org.h2.value.ValueLob
;
import
org.h2.value.ValueLong
;
import
org.h2.value.ValueNull
;
import
org.h2.value.ValueResultSet
;
...
...
@@ -84,7 +91,8 @@ public class Function extends Expression implements FunctionCall {
public
static
final
int
IFNULL
=
200
,
CASEWHEN
=
201
,
CONVERT
=
202
,
CAST
=
203
,
COALESCE
=
204
,
NULLIF
=
205
,
CASE
=
206
,
NEXTVAL
=
207
,
CURRVAL
=
208
,
ARRAY_GET
=
209
,
CSVREAD
=
210
,
CSVWRITE
=
211
,
MEMORY_FREE
=
212
,
MEMORY_USED
=
213
,
LOCK_MODE
=
214
,
SCHEMA
=
215
,
SESSION_ID
=
216
,
ARRAY_LENGTH
=
217
,
LINK_SCHEMA
=
218
,
GREATEST
=
219
,
LEAST
=
220
,
CANCEL_SESSION
=
221
,
SET
=
222
,
TABLE
=
223
,
TABLE_DISTINCT
=
224
;
LINK_SCHEMA
=
218
,
GREATEST
=
219
,
LEAST
=
220
,
CANCEL_SESSION
=
221
,
SET
=
222
,
TABLE
=
223
,
TABLE_DISTINCT
=
224
,
FILE_READ
=
225
;
private
static
final
int
VAR_ARGS
=
-
1
;
...
...
@@ -281,6 +289,7 @@ public class Function extends Expression implements FunctionCall {
addFunctionWithNull
(
"GREATEST"
,
GREATEST
,
VAR_ARGS
,
Value
.
NULL
);
addFunction
(
"CANCEL_SESSION"
,
CANCEL_SESSION
,
1
,
Value
.
BOOLEAN
);
addFunction
(
"SET"
,
SET
,
2
,
Value
.
NULL
,
false
,
false
);
addFunction
(
"FILE_READ"
,
FILE_READ
,
VAR_ARGS
,
Value
.
NULL
,
false
,
true
);
// TableFunction
addFunctionWithNull
(
"TABLE"
,
TABLE
,
VAR_ARGS
,
Value
.
RESULT_SET
);
...
...
@@ -1024,6 +1033,28 @@ public class Function extends Expression implements FunctionCall {
result
=
v1
;
break
;
}
case
FILE_READ:
{
session
.
getUser
().
checkAdmin
();
String
fileName
=
v0
.
getString
();
boolean
blob
=
args
.
length
==
1
;
try
{
InputStream
in
=
new
AutoCloseInputStream
(
FileUtils
.
openFileInputStream
(
fileName
));
if
(
blob
)
{
result
=
ValueLob
.
createBlob
(
in
,
-
1
,
database
);
}
else
{
Reader
reader
;
if
(
v1
==
ValueNull
.
INSTANCE
)
{
reader
=
new
InputStreamReader
(
in
);
}
else
{
reader
=
new
InputStreamReader
(
in
,
v1
.
getString
());
}
result
=
ValueLob
.
createClob
(
reader
,
-
1
,
database
);
}
}
catch
(
IOException
e
)
{
throw
Message
.
convertIOException
(
e
,
fileName
);
}
break
;
}
default
:
throw
Message
.
getInternalError
(
"type="
+
info
.
type
);
}
...
...
@@ -1459,6 +1490,7 @@ public class Function extends Expression implements FunctionCall {
case
LTRIM:
case
RTRIM:
case
TRIM:
case
FILE_READ:
min
=
1
;
max
=
2
;
break
;
...
...
@@ -1607,6 +1639,17 @@ public class Function extends Expression implements FunctionCall {
}
break
;
}
case
FILE_READ:
{
if
(
args
.
length
==
1
)
{
dataType
=
Value
.
BLOB
;
}
else
{
dataType
=
Value
.
CLOB
;
}
precision
=
Integer
.
MAX_VALUE
;
scale
=
0
;
displaySize
=
Integer
.
MAX_VALUE
;
break
;
}
default
:
dataType
=
info
.
dataType
;
precision
=
0
;
...
...
h2/src/main/org/h2/res/help.csv
浏览文件 @
40e873c7
...
...
@@ -2694,6 +2694,20 @@ Returns NULL otherwise.
DATABASE_PATH()
"
"Functions (System)","FILE_READ","
FILE_READ(fileNameString [,encodingString]): value
","
Returns the contents of a file. If only one parameter is supplied,
the data are returned as a BLOB. If two parameters are used,
the data is returned as a CLOB (text). The second parameter
is the character set to use, NULL meaning the default character set
for this system. File names and URLs are supported.
Admin rights are required to execute this command.
","
SELECT LENGTH(FILE_READ('~/.h2.server.properties')) LEN;
SELECT FILE_READ('http://localhost:8182/stylesheet.css', NULL) CSS;
"
"Functions (System)","GREATEST","
GREATEST(aValue, bValue [,...]): value
","
...
...
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
40e873c7
...
...
@@ -161,6 +161,8 @@ link to new changelog and roadmap, remove pages from google groups
Can sometimes not delete log file? need test case
History:
New function FILE_READ to read a file or from an URL.
Both binary and text data is supported.
Roadmap:
...
...
h2/src/test/org/h2/test/db/TestFunctions.java
浏览文件 @
40e873c7
...
...
@@ -5,6 +5,9 @@
package
org
.
h2
.
test
.
db
;
import
java.io.BufferedInputStream
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.FileReader
;
import
java.io.InputStream
;
import
java.sql.Blob
;
import
java.sql.Connection
;
...
...
@@ -15,10 +18,12 @@ import java.sql.SQLException;
import
java.sql.Statement
;
import
java.sql.Types
;
import
java.util.ArrayList
;
import
java.util.Properties
;
import
org.h2.api.AggregateFunction
;
import
org.h2.test.TestBase
;
import
org.h2.tools.SimpleResultSet
;
import
org.h2.util.IOUtils
;
/**
* Tests for user defined functions and aggregates.
...
...
@@ -30,6 +35,33 @@ public class TestFunctions extends TestBase {
public
void
test
()
throws
Exception
{
testAggregate
();
testFunctions
();
testFileRead
();
}
public
void
testFileRead
()
throws
Exception
{
Connection
conn
=
getConnection
(
"functions"
);
stat
=
conn
.
createStatement
();
File
f
=
new
File
(
baseDir
+
"/test.txt"
);
Properties
prop
=
System
.
getProperties
();
FileOutputStream
out
=
new
FileOutputStream
(
f
);
prop
.
store
(
out
,
""
);
out
.
close
();
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT LENGTH(FILE_READ('"
+
baseDir
+
"/test.txt')) LEN"
);
rs
.
next
();
check
(
f
.
length
(),
rs
.
getInt
(
1
));
rs
=
stat
.
executeQuery
(
"SELECT FILE_READ('"
+
baseDir
+
"/test.txt') PROP"
);
rs
.
next
();
Properties
p2
=
new
Properties
();
p2
.
load
(
rs
.
getBinaryStream
(
1
));
check
(
prop
.
size
(),
p2
.
size
());
rs
=
stat
.
executeQuery
(
"SELECT FILE_READ('"
+
baseDir
+
"/test.txt', NULL) PROP"
);
rs
.
next
();
String
ps
=
rs
.
getString
(
1
);
FileReader
r
=
new
FileReader
(
f
);
String
ps2
=
IOUtils
.
readStringAndClose
(
r
,
-
1
);
check
(
ps
,
ps2
);
f
.
delete
();
conn
.
close
();
}
public
static
class
MedianString
implements
AggregateFunction
{
...
...
h2/src/test/org/h2/test/unit/SelfDestructor.java
浏览文件 @
40e873c7
...
...
@@ -4,6 +4,8 @@
*/
package
org
.
h2
.
test
.
unit
;
import
java.sql.Timestamp
;
/**
* This is a self-destructor class to kill a long running process automatically after
* a pre-defined time. The class reads the number of minutes
...
...
@@ -32,7 +34,8 @@ public class SelfDestructor extends Thread {
// ignore
}
}
System
.
out
.
println
(
"Killing the process after "
+
minutes
+
" minutes"
);
String
time
=
new
Timestamp
(
System
.
currentTimeMillis
()).
toString
();
System
.
out
.
println
(
time
+
" Killing the process after "
+
minutes
+
" minutes"
);
Runtime
.
getRuntime
().
halt
(
1
);
}
};
...
...
h2/src/tools/org/h2/tools/doc/dictionary.txt
浏览文件 @
40e873c7
...
...
@@ -527,4 +527,5 @@ violate verysmallint eremainder iee cgi adjust estimation consumption occupy ikv
upgrading consecutive acting
simulates dispatcher servlets chf destruction separating consulting reached
unreferenced longest enum jira jackcess track unreleased processors nearest fits shadow
cmu cosh tanh sinh contrib bzip contiguous huffman bitwise des
\ No newline at end of file
cmu cosh tanh sinh contrib bzip contiguous huffman bitwise des
nederlands italy berlini destructor destruct elisabetta
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论