Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
f6e9687c
D
dbeaver
项目概览
suliangchun
/
dbeaver
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dbeaver
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f6e9687c
编写于
10月 10, 2019
作者:
S
Serge Rider
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#6959 SQL parameter values preview
Former-commit-id:
6790331d
上级
595ef43e
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
50 addition
and
15 deletion
+50
-15
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/sql/SQLUtils.java
...eaver.model/src/org/jkiss/dbeaver/model/sql/SQLUtils.java
+16
-0
plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/SQLEditor.java
...s.sql/src/org/jkiss/dbeaver/ui/editors/sql/SQLEditor.java
+1
-13
plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/dialogs/SQLQueryParameterBindDialog.java
...r/ui/editors/sql/dialogs/SQLQueryParameterBindDialog.java
+33
-2
未找到文件。
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/sql/SQLUtils.java
浏览文件 @
f6e9687c
...
@@ -1090,4 +1090,20 @@ public final class SQLUtils {
...
@@ -1090,4 +1090,20 @@ public final class SQLUtils {
}
}
return
type
;
return
type
;
}
}
public
static
void
fillQueryParameters
(
SQLQuery
sqlStatement
,
List
<
SQLQueryParameter
>
parameters
)
{
// Set values for all parameters
// Replace parameter tokens with parameter values
String
query
=
sqlStatement
.
getText
();
for
(
int
i
=
parameters
.
size
();
i
>
0
;
i
--)
{
SQLQueryParameter
parameter
=
parameters
.
get
(
i
-
1
);
String
paramValue
=
parameter
.
getValue
();
if
(
paramValue
==
null
||
paramValue
.
isEmpty
())
{
paramValue
=
SQLConstants
.
NULL_VALUE
;
}
query
=
query
.
substring
(
0
,
parameter
.
getTokenOffset
())
+
paramValue
+
query
.
substring
(
parameter
.
getTokenOffset
()
+
parameter
.
getTokenLength
());
}
sqlStatement
.
setText
(
query
);
sqlStatement
.
setOriginalText
(
query
);
}
}
}
\ No newline at end of file
plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/SQLEditor.java
浏览文件 @
f6e9687c
...
@@ -1978,20 +1978,8 @@ public class SQLEditor extends SQLEditorBase implements
...
@@ -1978,20 +1978,8 @@ public class SQLEditor extends SQLEditorBase implements
if
(
ignoreParameters
)
{
if
(
ignoreParameters
)
{
return
true
;
return
true
;
}
}
SQLUtils
.
fillQueryParameters
(
sqlStatement
,
parameters
);
// Set values for all parameters
// Replace parameter tokens with parameter values
String
query
=
sqlStatement
.
getText
();
for
(
int
i
=
parameters
.
size
();
i
>
0
;
i
--)
{
SQLQueryParameter
parameter
=
parameters
.
get
(
i
-
1
);
String
paramValue
=
parameter
.
getValue
();
if
(
paramValue
==
null
||
paramValue
.
isEmpty
())
{
paramValue
=
SQLConstants
.
NULL_VALUE
;
}
query
=
query
.
substring
(
0
,
parameter
.
getTokenOffset
())
+
paramValue
+
query
.
substring
(
parameter
.
getTokenOffset
()
+
parameter
.
getTokenLength
());
}
sqlStatement
.
setText
(
query
);
sqlStatement
.
setOriginalText
(
query
);
return
true
;
return
true
;
}
}
...
...
plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/dialogs/SQLQueryParameterBindDialog.java
浏览文件 @
f6e9687c
...
@@ -33,6 +33,8 @@ import org.jkiss.dbeaver.model.DBIcon;
...
@@ -33,6 +33,8 @@ import org.jkiss.dbeaver.model.DBIcon;
import
org.jkiss.dbeaver.model.impl.DataSourceContextProvider
;
import
org.jkiss.dbeaver.model.impl.DataSourceContextProvider
;
import
org.jkiss.dbeaver.model.sql.SQLQuery
;
import
org.jkiss.dbeaver.model.sql.SQLQuery
;
import
org.jkiss.dbeaver.model.sql.SQLQueryParameter
;
import
org.jkiss.dbeaver.model.sql.SQLQueryParameter
;
import
org.jkiss.dbeaver.model.sql.SQLScriptContext
;
import
org.jkiss.dbeaver.model.sql.SQLUtils
;
import
org.jkiss.dbeaver.runtime.DBWorkbench
;
import
org.jkiss.dbeaver.runtime.DBWorkbench
;
import
org.jkiss.dbeaver.runtime.ui.UIServiceSQL
;
import
org.jkiss.dbeaver.runtime.ui.UIServiceSQL
;
import
org.jkiss.dbeaver.ui.DBeaverIcons
;
import
org.jkiss.dbeaver.ui.DBeaverIcons
;
...
@@ -44,8 +46,9 @@ import org.jkiss.dbeaver.ui.editors.sql.registry.SQLQueryParameterRegistry;
...
@@ -44,8 +46,9 @@ import org.jkiss.dbeaver.ui.editors.sql.registry.SQLQueryParameterRegistry;
import
org.jkiss.dbeaver.utils.GeneralUtils
;
import
org.jkiss.dbeaver.utils.GeneralUtils
;
import
org.jkiss.utils.CommonUtils
;
import
org.jkiss.utils.CommonUtils
;
import
java.
util.List
;
import
java.
io.StringWriter
;
import
java.util.*
;
import
java.util.*
;
import
java.util.List
;
/**
/**
* Parameter binding
* Parameter binding
...
@@ -58,6 +61,7 @@ public class SQLQueryParameterBindDialog extends StatusDialog {
...
@@ -58,6 +61,7 @@ public class SQLQueryParameterBindDialog extends StatusDialog {
private
static
final
Log
log
=
Log
.
getLog
(
SQLQueryParameterBindDialog
.
class
);
private
static
final
Log
log
=
Log
.
getLog
(
SQLQueryParameterBindDialog
.
class
);
private
IWorkbenchPartSite
site
;
private
IWorkbenchPartSite
site
;
private
SQLScriptContext
queryContext
;
private
SQLQuery
query
;
private
SQLQuery
query
;
private
List
<
SQLQueryParameter
>
parameters
;
private
List
<
SQLQueryParameter
>
parameters
;
private
final
Map
<
String
,
List
<
SQLQueryParameter
>>
dupParameters
=
new
HashMap
<>();
private
final
Map
<
String
,
List
<
SQLQueryParameter
>>
dupParameters
=
new
HashMap
<>();
...
@@ -65,11 +69,14 @@ public class SQLQueryParameterBindDialog extends StatusDialog {
...
@@ -65,11 +69,14 @@ public class SQLQueryParameterBindDialog extends StatusDialog {
private
static
Map
<
String
,
SQLQueryParameterRegistry
.
ParameterInfo
>
savedParamValues
=
new
HashMap
<>();
private
static
Map
<
String
,
SQLQueryParameterRegistry
.
ParameterInfo
>
savedParamValues
=
new
HashMap
<>();
private
Button
hideIfSetCheck
;
private
Button
hideIfSetCheck
;
private
Table
paramTable
;
private
Table
paramTable
;
private
Object
queryPreviewPanel
;
public
SQLQueryParameterBindDialog
(
IWorkbenchPartSite
site
,
SQLQuery
query
,
List
<
SQLQueryParameter
>
parameters
)
public
SQLQueryParameterBindDialog
(
IWorkbenchPartSite
site
,
SQLQuery
query
,
List
<
SQLQueryParameter
>
parameters
)
{
{
super
(
site
.
getShell
());
super
(
site
.
getShell
());
this
.
site
=
site
;
this
.
site
=
site
;
StringWriter
dummyWriter
=
new
StringWriter
();
this
.
queryContext
=
new
SQLScriptContext
(
null
,
new
DataSourceContextProvider
(
query
.
getDataSource
()),
null
,
dummyWriter
);
this
.
query
=
query
;
this
.
query
=
query
;
this
.
parameters
=
parameters
;
this
.
parameters
=
parameters
;
...
@@ -80,6 +87,8 @@ public class SQLQueryParameterBindDialog extends StatusDialog {
...
@@ -80,6 +87,8 @@ public class SQLQueryParameterBindDialog extends StatusDialog {
SQLQueryParameterRegistry
.
ParameterInfo
paramInfo
=
registry
.
getParameter
(
param
.
getName
());
SQLQueryParameterRegistry
.
ParameterInfo
paramInfo
=
registry
.
getParameter
(
param
.
getName
());
if
(
paramInfo
!=
null
)
{
if
(
paramInfo
!=
null
)
{
param
.
setValue
(
paramInfo
.
value
);
param
.
setValue
(
paramInfo
.
value
);
param
.
setVariableSet
(!
CommonUtils
.
isEmpty
(
paramInfo
.
value
));
queryContext
.
setVariable
(
paramInfo
.
name
,
paramInfo
.
value
);
}
}
}
}
}
}
...
@@ -166,6 +175,7 @@ public class SQLQueryParameterBindDialog extends StatusDialog {
...
@@ -166,6 +175,7 @@ public class SQLQueryParameterBindDialog extends StatusDialog {
item
.
setText
(
2
,
newValue
);
item
.
setText
(
2
,
newValue
);
param
.
setValue
(
newValue
);
param
.
setValue
(
newValue
);
param
.
setVariableSet
(!
CommonUtils
.
isEmpty
(
newValue
));
if
(
param
.
isNamed
())
{
if
(
param
.
isNamed
())
{
final
List
<
SQLQueryParameter
>
dups
=
dupParameters
.
get
(
param
.
getName
());
final
List
<
SQLQueryParameter
>
dups
=
dupParameters
.
get
(
param
.
getName
());
if
(
dups
!=
null
)
{
if
(
dups
!=
null
)
{
...
@@ -173,11 +183,14 @@ public class SQLQueryParameterBindDialog extends StatusDialog {
...
@@ -173,11 +183,14 @@ public class SQLQueryParameterBindDialog extends StatusDialog {
dup
.
setValue
(
newValue
);
dup
.
setValue
(
newValue
);
}
}
}
}
queryContext
.
setVariable
(
param
.
getVarName
(),
param
.
getValue
());
}
}
savedParamValues
.
put
(
savedParamValues
.
put
(
param
.
getName
().
toUpperCase
(
Locale
.
ENGLISH
),
param
.
getName
().
toUpperCase
(
Locale
.
ENGLISH
),
new
SQLQueryParameterRegistry
.
ParameterInfo
(
param
.
getName
(),
newValue
));
new
SQLQueryParameterRegistry
.
ParameterInfo
(
param
.
getName
(),
newValue
));
updateQueryPreview
();
}
}
};
};
...
@@ -193,7 +206,7 @@ public class SQLQueryParameterBindDialog extends StatusDialog {
...
@@ -193,7 +206,7 @@ public class SQLQueryParameterBindDialog extends StatusDialog {
queryComposite
.
setLayout
(
new
FillLayout
());
queryComposite
.
setLayout
(
new
FillLayout
());
try
{
try
{
DBWorkbench
.
getService
(
UIServiceSQL
.
class
).
createSQLPanel
(
queryPreviewPanel
=
DBWorkbench
.
getService
(
UIServiceSQL
.
class
).
createSQLPanel
(
site
,
site
,
queryComposite
,
queryComposite
,
new
DataSourceContextProvider
(
query
.
getDataSource
()),
new
DataSourceContextProvider
(
query
.
getDataSource
()),
...
@@ -219,6 +232,9 @@ public class SQLQueryParameterBindDialog extends StatusDialog {
...
@@ -219,6 +232,9 @@ public class SQLQueryParameterBindDialog extends StatusDialog {
});
});
updateStatus
(
GeneralUtils
.
makeInfoStatus
(
SQLEditorMessages
.
dialog_sql_param_hint
));
updateStatus
(
GeneralUtils
.
makeInfoStatus
(
SQLEditorMessages
.
dialog_sql_param_hint
));
updateQueryPreview
();
return
composite
;
return
composite
;
}
}
...
@@ -244,6 +260,21 @@ public class SQLQueryParameterBindDialog extends StatusDialog {
...
@@ -244,6 +260,21 @@ public class SQLQueryParameterBindDialog extends StatusDialog {
}
}
}
}
private
void
updateQueryPreview
()
{
SQLQuery
queryCopy
=
new
SQLQuery
(
query
.
getDataSource
(),
query
.
getText
(),
query
);
List
<
SQLQueryParameter
>
setParams
=
new
ArrayList
<>(
this
.
parameters
);
setParams
.
removeIf
(
parameter
->
!
parameter
.
isVariableSet
());
SQLUtils
.
fillQueryParameters
(
queryCopy
,
setParams
);
if
(!
CommonUtils
.
equalObjects
(
query
.
getText
(),
queryCopy
.
getText
()))
{
UIUtils
.
asyncExec
(()
->
{
DBWorkbench
.
getService
(
UIServiceSQL
.
class
).
setSQLPanelText
(
queryPreviewPanel
,
queryCopy
.
getText
());
});
}
}
@Override
@Override
protected
void
createButtonsForButtonBar
(
Composite
parent
)
{
protected
void
createButtonsForButtonBar
(
Composite
parent
)
{
Button
skipButton
=
UIUtils
.
createDialogButton
(
parent
,
IDialogConstants
.
IGNORE_LABEL
,
new
SelectionAdapter
()
{
Button
skipButton
=
UIUtils
.
createDialogButton
(
parent
,
IDialogConstants
.
IGNORE_LABEL
,
new
SelectionAdapter
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录