Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
8d626f35
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,发现更多精彩内容 >>
提交
8d626f35
编写于
9月 28, 2020
作者:
L
LonwoLonwo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#9696 extra formatting options for SQL INSERT export format added
Former-commit-id:
3652a364
上级
97b87c65
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
72 addition
and
16 deletion
+72
-16
plugins/org.jkiss.dbeaver.data.transfer/OSGI-INF/l10n/bundle.properties
...iss.dbeaver.data.transfer/OSGI-INF/l10n/bundle.properties
+6
-0
plugins/org.jkiss.dbeaver.data.transfer/plugin.xml
plugins/org.jkiss.dbeaver.data.transfer/plugin.xml
+4
-0
plugins/org.jkiss.dbeaver.data.transfer/src/org/jkiss/dbeaver/tools/transfer/stream/exporter/DataExporterSQL.java
...eaver/tools/transfer/stream/exporter/DataExporterSQL.java
+62
-16
未找到文件。
plugins/org.jkiss.dbeaver.data.transfer/OSGI-INF/l10n/bundle.properties
浏览文件 @
8d626f35
...
...
@@ -76,6 +76,12 @@ dataTransfer.processor.sql.property.rowsInStatement.name=Data rows per statement
dataTransfer.processor.sql.property.rowsInStatement.description
=
Number of data rows per single insert statement
dataTransfer.processor.sql.property.nativeFormat.name
=
Native date/time format
dataTransfer.processor.sql.property.nativeFormat.description
=
Use native date/time format in INSERT statements
dataTransfer.processor.sql.property.lineBeforeValues.name
=
Insert line before VALUES
dataTransfer.processor.sql.property.lineBeforeValues.description
=
Insert line feeds before keyword VALUES
dataTransfer.processor.sql.property.lineBeforeRows.name
=
Insert line before rows
dataTransfer.processor.sql.property.lineBeforeRows.description
=
Insert line feeds before each VALUES line (for multi-row inserts)
dataTransfer.processor.sql.property.keywordCase.name
=
Keyword case
dataTransfer.processor.sql.property.keywordCase.description
=
You can choose lower or upper keyword case
dataTransfer.processor.xml.name
=
XML
dataTransfer.processor.xml.description
=
Export to XML file(s)
dataTransfer.processor.xml.propertyGroup.general.label
=
General
...
...
plugins/org.jkiss.dbeaver.data.transfer/plugin.xml
浏览文件 @
8d626f35
...
...
@@ -167,6 +167,10 @@
<property
id=
"nativeFormat"
label=
"%dataTransfer.processor.sql.property.nativeFormat.name"
type=
"boolean"
description=
"%dataTransfer.processor.sql.property.nativeFormat.description"
defaultValue=
"true"
/>
<property
id=
"omitSchema"
label=
"%dataTransfer.processor.sql.property.omitSchema.name"
type=
"boolean"
description=
"%dataTransfer.processor.sql.property.omitSchema.description"
required=
"false"
defaultValue=
"false"
/>
<property
id=
"rowsInStatement"
label=
"%dataTransfer.processor.sql.property.rowsInStatement.name"
type=
"integer"
description=
"%dataTransfer.processor.sql.property.rowsInStatement.description"
defaultValue=
"10"
required=
"true"
/>
<property
id=
"lineBeforeValues"
label=
"%dataTransfer.processor.sql.property.lineBeforeValues.name"
type=
"boolean"
description=
"%dataTransfer.processor.sql.property.lineBeforeValues.description"
defaultValue=
"false"
/>
<property
id=
"lineBeforeRows"
label=
"%dataTransfer.processor.sql.property.lineBeforeRows.name"
type=
"boolean"
description=
"%dataTransfer.processor.sql.property.lineBeforeRows.description"
defaultValue=
"true"
/>
<property
id=
"keywordCase"
label=
"%dataTransfer.processor.sql.property.keywordCase.name"
type=
"string"
description=
"%dataTransfer.processor.sql.property.keywordCase.description"
defaultValue=
"upper"
required=
"true"
validValues=
"upper,lower"
/>
</propertyGroup>
</processor>
<processor
...
...
plugins/org.jkiss.dbeaver.data.transfer/src/org/jkiss/dbeaver/tools/transfer/stream/exporter/DataExporterSQL.java
浏览文件 @
8d626f35
...
...
@@ -37,6 +37,8 @@ import java.io.File;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
java.io.Reader
;
import
java.util.Locale
;
import
java.util.Map
;
/**
* SQL Exporter
...
...
@@ -50,19 +52,33 @@ public class DataExporterSQL extends StreamExporterAbstract {
private
static
final
String
PROP_ROWS_IN_STATEMENT
=
"rowsInStatement"
;
private
static
final
String
PROP_DATA_FORMAT
=
"nativeFormat"
;
private
static
final
char
STRING_QUOTE
=
'\''
;
private
static
final
String
PROP_LINE_BEFORE_VALUES
=
"lineBeforeValues"
;
private
static
final
String
PROP_LINE_BEFORE_ROWS
=
"lineBeforeRows"
;
private
static
final
String
PROP_KEYWORD_CASE
=
"keywordCase"
;
private
boolean
includeAutoGenerated
;
private
String
rowDelimiter
;
private
boolean
omitSchema
;
private
int
rowsInStatement
;
private
boolean
useNativeDataFormat
=
true
;
private
boolean
lineBeforeValues
;
private
boolean
lineBeforeRows
=
true
;
private
String
tableName
;
private
DBDAttributeBinding
[]
columns
;
private
final
String
KEYWORD_INSERT_INTO
=
"INSERT INTO"
;
private
final
String
KEYWORD_VALUES
=
"VALUES"
;
private
transient
StringBuilder
sqlBuffer
=
new
StringBuilder
(
100
);
private
transient
long
rowCount
;
private
SQLDialect
dialect
;
enum
KeywordCase
{
upper
,
lower
}
private
KeywordCase
keywordCase
;
private
boolean
isSkipColumn
(
DBDAttributeBinding
attr
)
{
return
attr
.
isPseudoAttribute
()
||
(!
includeAutoGenerated
&&
attr
.
isAutoGenerated
())
||
attr
instanceof
DBDAttributeBindingCustom
;
...
...
@@ -72,20 +88,26 @@ public class DataExporterSQL extends StreamExporterAbstract {
public
void
init
(
IStreamDataExporterSite
site
)
throws
DBException
{
super
.
init
(
site
);
if
(
site
.
getProperties
().
containsKey
(
PROP_INCLUDE_AUTO_GENERATED
))
{
includeAutoGenerated
=
CommonUtils
.
toBoolean
(
site
.
getProperties
().
get
(
PROP_INCLUDE_AUTO_GENERATED
));
Map
<
String
,
Object
>
properties
=
site
.
getProperties
();
if
(
properties
.
containsKey
(
PROP_INCLUDE_AUTO_GENERATED
))
{
includeAutoGenerated
=
CommonUtils
.
toBoolean
(
properties
.
get
(
PROP_INCLUDE_AUTO_GENERATED
));
}
if
(
site
.
getProperties
()
.
containsKey
(
PROP_OMIT_SCHEMA
))
{
omitSchema
=
CommonUtils
.
toBoolean
(
site
.
getProperties
()
.
get
(
PROP_OMIT_SCHEMA
));
if
(
properties
.
containsKey
(
PROP_OMIT_SCHEMA
))
{
omitSchema
=
CommonUtils
.
toBoolean
(
properties
.
get
(
PROP_OMIT_SCHEMA
));
}
try
{
rowsInStatement
=
Integer
.
parseInt
(
String
.
valueOf
(
site
.
getProperties
()
.
get
(
PROP_ROWS_IN_STATEMENT
)));
rowsInStatement
=
Integer
.
parseInt
(
String
.
valueOf
(
properties
.
get
(
PROP_ROWS_IN_STATEMENT
)));
}
catch
(
NumberFormatException
e
)
{
rowsInStatement
=
10
;
}
useNativeDataFormat
=
CommonUtils
.
toBoolean
(
site
.
getProperties
().
get
(
PROP_DATA_FORMAT
));
useNativeDataFormat
=
CommonUtils
.
toBoolean
(
properties
.
get
(
PROP_DATA_FORMAT
));
lineBeforeValues
=
CommonUtils
.
toBoolean
(
properties
.
get
(
PROP_LINE_BEFORE_VALUES
));
lineBeforeRows
=
CommonUtils
.
toBoolean
(
properties
.
get
(
PROP_LINE_BEFORE_ROWS
));
rowDelimiter
=
GeneralUtils
.
getDefaultLineSeparator
();
dialect
=
SQLUtils
.
getDialectFromObject
(
site
.
getSource
());
keywordCase
=
CommonUtils
.
valueOf
(
KeywordCase
.
class
,
String
.
valueOf
(
properties
.
get
(
PROP_KEYWORD_CASE
)),
KeywordCase
.
upper
);
}
@Override
...
...
@@ -110,6 +132,7 @@ public class DataExporterSQL extends StreamExporterAbstract {
@Override
public
void
exportRow
(
DBCSession
session
,
DBCResultSet
resultSet
,
Object
[]
row
)
throws
DBException
,
IOException
{
PrintWriter
out
=
getWriter
();
boolean
upperCase
=
keywordCase
==
KeywordCase
.
upper
;
SQLDialect
.
MultiValueInsertMode
insertMode
=
rowsInStatement
==
1
?
SQLDialect
.
MultiValueInsertMode
.
NOT_SUPPORTED
:
getMultiValueInsertMode
();
if
(
insertMode
==
SQLDialect
.
MultiValueInsertMode
.
NOT_SUPPORTED
)
{
rowsInStatement
=
1
;
...
...
@@ -120,12 +143,20 @@ public class DataExporterSQL extends StreamExporterAbstract {
sqlBuffer
.
setLength
(
0
);
if
(
rowCount
>
0
)
{
if
(
insertMode
==
SQLDialect
.
MultiValueInsertMode
.
PLAIN
)
{
sqlBuffer
.
append
(
");"
)
.
append
(
rowDelimiter
)
;
sqlBuffer
.
append
(
");"
);
}
else
if
(
insertMode
==
SQLDialect
.
MultiValueInsertMode
.
GROUP_ROWS
)
{
sqlBuffer
.
append
(
";"
).
append
(
rowDelimiter
);
sqlBuffer
.
append
(
";"
);
}
if
(
lineBeforeRows
)
{
sqlBuffer
.
append
(
rowDelimiter
);
}
}
sqlBuffer
.
append
(
"INSERT INTO "
).
append
(
tableName
).
append
(
" ("
);
if
(
upperCase
)
{
sqlBuffer
.
append
(
KEYWORD_INSERT_INTO
);
}
else
{
sqlBuffer
.
append
(
KEYWORD_INSERT_INTO
.
toLowerCase
(
Locale
.
ENGLISH
));
}
sqlBuffer
.
append
(
" "
).
append
(
tableName
).
append
(
" ("
);
boolean
hasColumn
=
false
;
for
(
int
i
=
0
;
i
<
columnsSize
;
i
++)
{
DBDAttributeBinding
column
=
columns
[
i
];
...
...
@@ -138,11 +169,21 @@ public class DataExporterSQL extends StreamExporterAbstract {
hasColumn
=
true
;
sqlBuffer
.
append
(
DBUtils
.
getQuotedIdentifier
(
column
));
}
sqlBuffer
.
append
(
") VALUES "
);
sqlBuffer
.
append
(
")"
);
if
(
lineBeforeValues
)
{
sqlBuffer
.
append
(
rowDelimiter
).
append
(
"\t"
);
}
else
{
sqlBuffer
.
append
(
" "
);
}
if
(
upperCase
)
{
sqlBuffer
.
append
(
KEYWORD_VALUES
);
}
else
{
sqlBuffer
.
append
(
KEYWORD_VALUES
.
toLowerCase
(
Locale
.
ENGLISH
));
}
if
(
insertMode
!=
SQLDialect
.
MultiValueInsertMode
.
GROUP_ROWS
)
{
sqlBuffer
.
append
(
"("
);
sqlBuffer
.
append
(
"
\t
("
);
}
if
(
rowsInStatement
>
1
)
{
if
(
rowsInStatement
>
1
&&
lineBeforeRows
)
{
sqlBuffer
.
append
(
rowDelimiter
);
}
out
.
write
(
sqlBuffer
.
toString
());
...
...
@@ -150,9 +191,15 @@ public class DataExporterSQL extends StreamExporterAbstract {
}
if
(
insertMode
!=
SQLDialect
.
MultiValueInsertMode
.
NOT_SUPPORTED
&&
!
firstRow
)
{
out
.
write
(
","
);
if
(
lineBeforeRows
)
{
out
.
write
(
rowDelimiter
);
}
}
if
(
insertMode
==
SQLDialect
.
MultiValueInsertMode
.
GROUP_ROWS
)
{
out
.
write
(
"("
);
if
(
lineBeforeRows
)
{
out
.
write
(
"\t"
);
}
out
.
write
(
" ("
);
}
rowCount
++;
boolean
hasValue
=
false
;
...
...
@@ -206,9 +253,8 @@ public class DataExporterSQL extends StreamExporterAbstract {
out
.
write
(
")"
);
}
if
(
insertMode
==
SQLDialect
.
MultiValueInsertMode
.
NOT_SUPPORTED
)
{
out
.
write
(
";"
);
out
.
write
(
";"
+
rowDelimiter
);
}
out
.
write
(
rowDelimiter
);
}
@Override
...
...
@@ -265,7 +311,7 @@ public class DataExporterSQL extends StreamExporterAbstract {
private
SQLDialect
.
MultiValueInsertMode
getMultiValueInsertMode
()
{
SQLDialect
.
MultiValueInsertMode
insertMode
=
SQLDialect
.
MultiValueInsertMode
.
NOT_SUPPORTED
;
if
(
dialect
!=
null
)
{
if
(
dialect
!=
null
&&
rowsInStatement
!=
1
)
{
insertMode
=
dialect
.
getMultiValueInsertMode
();
}
return
insertMode
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录