Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
f35a2f43
提交
f35a2f43
authored
10月 07, 2008
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
RUNSCRIPT no longer uses a temporary file.
上级
fe1e4d93
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
101 行增加
和
35 行删除
+101
-35
ScriptCommand.java
h2/src/main/org/h2/command/dml/ScriptCommand.java
+101
-35
没有找到文件。
h2/src/main/org/h2/command/dml/ScriptCommand.java
浏览文件 @
f35a2f43
...
...
@@ -10,9 +10,7 @@ import java.io.BufferedInputStream;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.io.Reader
;
import
java.io.Writer
;
import
java.sql.Connection
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
...
...
@@ -48,9 +46,7 @@ import org.h2.schema.TriggerObject;
import
org.h2.table.Column
;
import
org.h2.table.PlanItem
;
import
org.h2.table.Table
;
import
org.h2.util.AutoCloseInputStream
;
import
org.h2.util.ByteUtils
;
import
org.h2.util.FileUtils
;
import
org.h2.util.IOUtils
;
import
org.h2.util.MathUtils
;
import
org.h2.util.ObjectArray
;
...
...
@@ -65,7 +61,6 @@ import org.h2.value.ValueString;
*/
public
class
ScriptCommand
extends
ScriptBase
{
private
static
final
String
TEMP_LOB_FILENAME
=
"system_temp_lob.db"
;
private
boolean
passwords
;
private
boolean
data
;
private
boolean
settings
;
...
...
@@ -420,18 +415,48 @@ public class ScriptCommand extends ScriptBase {
*/
public
static
InputStream
combineBlob
(
Connection
conn
,
int
id
)
throws
SQLException
,
IOException
{
if
(
id
<
0
)
{
FileUtils
.
delete
(
TEMP_LOB_FILENAME
);
return
null
;
}
ResultSet
rs
=
getLobStream
(
conn
,
"BDATA"
,
id
);
OutputStream
out
=
FileUtils
.
openFileOutputStream
(
TEMP_LOB_FILENAME
,
false
);
while
(
rs
.
next
())
{
InputStream
in
=
rs
.
getBinaryStream
(
1
);
IOUtils
.
copyAndCloseInput
(
in
,
out
);
}
out
.
close
();
deleteLobStream
(
conn
,
id
);
return
openAutoCloseInput
();
final
ResultSet
rs
=
getLobStream
(
conn
,
"BDATA"
,
id
);
return
new
InputStream
()
{
private
InputStream
current
;
private
boolean
closed
;
public
int
read
()
throws
IOException
{
while
(
true
)
{
try
{
if
(
current
==
null
)
{
if
(
closed
)
{
return
-
1
;
}
if
(!
rs
.
next
())
{
close
();
return
-
1
;
}
current
=
rs
.
getBinaryStream
(
1
);
current
=
new
BufferedInputStream
(
current
);
}
int
x
=
current
.
read
();
if
(
x
>=
0
)
{
return
x
;
}
current
=
null
;
}
catch
(
SQLException
e
)
{
Message
.
convertToIOException
(
e
);
}
}
}
public
void
close
()
throws
IOException
{
if
(
closed
)
{
return
;
}
closed
=
true
;
try
{
rs
.
close
();
}
catch
(
SQLException
e
)
{
Message
.
convertToIOException
(
e
);
}
}
};
}
/**
...
...
@@ -443,15 +468,68 @@ public class ScriptCommand extends ScriptBase {
* @return a reader for the combined data
*/
public
static
Reader
combineClob
(
Connection
conn
,
int
id
)
throws
SQLException
,
IOException
{
ResultSet
rs
=
getLobStream
(
conn
,
"CDATA"
,
id
);
Writer
out
=
IOUtils
.
getWriter
(
FileUtils
.
openFileOutputStream
(
TEMP_LOB_FILENAME
,
false
));
while
(
rs
.
next
())
{
Reader
in
=
new
BufferedReader
(
rs
.
getCharacterStream
(
1
));
IOUtils
.
copyAndCloseInput
(
in
,
out
);
if
(
id
<
0
)
{
return
null
;
}
out
.
close
();
deleteLobStream
(
conn
,
id
);
return
IOUtils
.
getReader
(
openAutoCloseInput
());
final
ResultSet
rs
=
getLobStream
(
conn
,
"CDATA"
,
id
);
return
new
Reader
()
{
private
Reader
current
;
private
boolean
closed
;
public
int
read
()
throws
IOException
{
while
(
true
)
{
try
{
if
(
current
==
null
)
{
if
(
closed
)
{
return
-
1
;
}
if
(!
rs
.
next
())
{
close
();
return
-
1
;
}
current
=
rs
.
getCharacterStream
(
1
);
current
=
new
BufferedReader
(
current
);
}
int
x
=
current
.
read
();
if
(
x
>=
0
)
{
return
x
;
}
current
=
null
;
}
catch
(
SQLException
e
)
{
Message
.
convertToIOException
(
e
);
}
}
}
public
void
close
()
throws
IOException
{
if
(
closed
)
{
return
;
}
closed
=
true
;
try
{
rs
.
close
();
}
catch
(
SQLException
e
)
{
Message
.
convertToIOException
(
e
);
}
}
public
int
read
(
char
[]
buffer
,
int
off
,
int
len
)
throws
IOException
{
if
(
len
==
0
)
{
return
0
;
}
int
c
=
read
();
if
(
c
==
-
1
)
{
return
-
1
;
}
buffer
[
off
]
=
(
char
)
c
;
int
i
=
1
;
for
(;
i
<
len
;
i
++)
{
c
=
read
();
if
(
c
==
-
1
)
{
break
;
}
buffer
[
off
+
i
]
=
(
char
)
c
;
}
return
i
;
}
};
}
private
static
ResultSet
getLobStream
(
Connection
conn
,
String
column
,
int
id
)
throws
SQLException
{
...
...
@@ -461,18 +539,6 @@ public class ScriptCommand extends ScriptBase {
return
prep
.
executeQuery
();
}
private
static
void
deleteLobStream
(
Connection
conn
,
int
id
)
throws
SQLException
{
PreparedStatement
prep
=
conn
.
prepareStatement
(
"DELETE FROM SYSTEM_LOB_STREAM WHERE ID=?"
);
prep
.
setInt
(
1
,
id
);
prep
.
execute
();
}
private
static
InputStream
openAutoCloseInput
()
throws
IOException
{
InputStream
in
=
FileUtils
.
openFileInputStream
(
TEMP_LOB_FILENAME
);
in
=
new
BufferedInputStream
(
in
);
return
new
AutoCloseInputStream
(
in
);
}
private
void
reset
()
throws
SQLException
{
result
=
null
;
buffer
=
null
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论