Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
084f6452
提交
084f6452
authored
12月 05, 2009
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
The shell tool now has a very simple statement history.
上级
fb222b67
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
46 行增加
和
1 行删除
+46
-1
Shell.java
h2/src/main/org/h2/tools/Shell.java
+46
-1
没有找到文件。
h2/src/main/org/h2/tools/Shell.java
浏览文件 @
084f6452
...
@@ -19,6 +19,7 @@ import java.sql.ResultSet;
...
@@ -19,6 +19,7 @@ import java.sql.ResultSet;
import
java.sql.ResultSetMetaData
;
import
java.sql.ResultSetMetaData
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.sql.Statement
;
import
java.util.ArrayList
;
import
java.util.Properties
;
import
java.util.Properties
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Constants
;
import
org.h2.server.web.ConnectionInfo
;
import
org.h2.server.web.ConnectionInfo
;
...
@@ -26,6 +27,7 @@ import org.h2.util.ClassUtils;
...
@@ -26,6 +27,7 @@ import org.h2.util.ClassUtils;
import
org.h2.util.FileUtils
;
import
org.h2.util.FileUtils
;
import
org.h2.util.JdbcDriverUtils
;
import
org.h2.util.JdbcDriverUtils
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.New
;
import
org.h2.util.SortedProperties
;
import
org.h2.util.SortedProperties
;
import
org.h2.util.Tool
;
import
org.h2.util.Tool
;
...
@@ -35,6 +37,8 @@ import org.h2.util.Tool;
...
@@ -35,6 +37,8 @@ import org.h2.util.Tool;
*/
*/
public
class
Shell
extends
Tool
{
public
class
Shell
extends
Tool
{
private
static
final
int
HISTORY_COUNT
=
20
;
private
PrintStream
err
=
System
.
err
;
private
PrintStream
err
=
System
.
err
;
private
InputStream
in
=
System
.
in
;
private
InputStream
in
=
System
.
in
;
private
BufferedReader
reader
;
private
BufferedReader
reader
;
...
@@ -44,6 +48,7 @@ public class Shell extends Tool {
...
@@ -44,6 +48,7 @@ public class Shell extends Tool {
private
int
maxColumnSize
=
100
;
private
int
maxColumnSize
=
100
;
// Windows: '\u00b3';
// Windows: '\u00b3';
private
char
boxVertical
=
'|'
;
private
char
boxVertical
=
'|'
;
private
ArrayList
<
String
>
history
=
New
.
arrayList
();
/**
/**
* Options are case sensitive. Supported options are:
* Options are case sensitive. Supported options are:
...
@@ -138,6 +143,7 @@ public class Shell extends Tool {
...
@@ -138,6 +143,7 @@ public class Shell extends Tool {
println
(
"maxwidth Set maximum column width (default is 100)"
);
println
(
"maxwidth Set maximum column width (default is 100)"
);
println
(
"show List all tables"
);
println
(
"show List all tables"
);
println
(
"describe Describe a table"
);
println
(
"describe Describe a table"
);
println
(
"history Show the last 20 statements"
);
println
(
"quit or exit Close the connection and exit"
);
println
(
"quit or exit Close the connection and exit"
);
println
(
""
);
println
(
""
);
}
}
...
@@ -185,6 +191,17 @@ public class Shell extends Tool {
...
@@ -185,6 +191,17 @@ public class Shell extends Tool {
}
else
if
(
"LIST"
.
equals
(
upper
))
{
}
else
if
(
"LIST"
.
equals
(
upper
))
{
listMode
=
!
listMode
;
listMode
=
!
listMode
;
println
(
"Result list mode is now "
+
(
listMode
?
"on"
:
"off"
));
println
(
"Result list mode is now "
+
(
listMode
?
"on"
:
"off"
));
}
else
if
(
"HISTORY"
.
equals
(
upper
))
{
for
(
int
i
=
0
;
i
<
history
.
size
();
i
++)
{
String
s
=
history
.
get
(
i
);
s
=
s
.
replace
(
'\n'
,
' '
).
replace
(
'\r'
,
' '
);
println
(
"#"
+
(
1
+
i
)
+
": "
+
s
);
}
if
(
history
.
size
()
>
0
)
{
println
(
"To re-run a statement, type the number and press and enter"
);
}
else
{
println
(
"No history"
);
}
}
else
if
(
upper
.
startsWith
(
"DESCRIBE"
))
{
}
else
if
(
upper
.
startsWith
(
"DESCRIBE"
))
{
String
tableName
=
upper
.
substring
(
"DESCRIBE"
.
length
()).
trim
();
String
tableName
=
upper
.
substring
(
"DESCRIBE"
.
length
()).
trim
();
if
(
tableName
.
length
()
==
0
)
{
if
(
tableName
.
length
()
==
0
)
{
...
@@ -247,12 +264,31 @@ public class Shell extends Tool {
...
@@ -247,12 +264,31 @@ public class Shell extends Tool {
}
}
println
(
"Maximum column width is now "
+
maxColumnSize
);
println
(
"Maximum column width is now "
+
maxColumnSize
);
}
else
{
}
else
{
boolean
addToHistory
=
true
;
if
(
statement
==
null
)
{
if
(
statement
==
null
)
{
statement
=
line
;
if
(
isNumber
(
line
))
{
int
pos
=
Integer
.
parseInt
(
line
);
if
(
pos
==
0
||
pos
>
history
.
size
())
{
println
(
"Not found"
);
}
else
{
statement
=
history
.
get
(
pos
-
1
);
addToHistory
=
false
;
println
(
statement
);
end
=
true
;
}
}
else
{
statement
=
line
;
}
}
else
{
}
else
{
statement
+=
"\n"
+
line
;
statement
+=
"\n"
+
line
;
}
}
if
(
end
)
{
if
(
end
)
{
if
(
addToHistory
)
{
history
.
add
(
0
,
statement
);
if
(
history
.
size
()
>=
HISTORY_COUNT
)
{
history
.
remove
(
HISTORY_COUNT
);
}
}
execute
(
statement
);
execute
(
statement
);
statement
=
null
;
statement
=
null
;
}
}
...
@@ -280,6 +316,15 @@ public class Shell extends Tool {
...
@@ -280,6 +316,15 @@ public class Shell extends Tool {
}
}
}
}
private
boolean
isNumber
(
String
s
)
{
for
(
char
c
:
s
.
toCharArray
())
{
if
(!
Character
.
isDigit
(
c
))
{
return
false
;
}
}
return
true
;
}
private
void
connect
()
throws
IOException
,
SQLException
{
private
void
connect
()
throws
IOException
,
SQLException
{
String
propertiesFileName
=
FileUtils
.
getFileInUserHome
(
Constants
.
SERVER_PROPERTIES_FILE
);
String
propertiesFileName
=
FileUtils
.
getFileInUserHome
(
Constants
.
SERVER_PROPERTIES_FILE
);
String
url
=
"jdbc:h2:~/test"
;
String
url
=
"jdbc:h2:~/test"
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论