Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
N
NsePlugin
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Members
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
吴超
NsePlugin
Commits
daadfce1
Commit
daadfce1
authored
Sep 17, 2025
by
wuchao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复bug
parent
f88168cb
全部展开
显示空白字符变更
内嵌
并排
正在显示
34 个修改的文件
包含
917 行增加
和
169 行删除
+917
-169
.idea/encodings.xml
+1
-1
src/main/java/com/palacesun/engine/wrapper/ConnectionWrapper.java
+0
-0
src/main/java/com/palacesun/engine/wrapper/MysqlSchemaExtractor.java
+0
-0
src/main/java/com/palacesun/engine/wrapper/PreparedStatementWrapper.java
+0
-0
src/main/java/com/palacesun/engine/wrapper/StatementWrapper.java
+0
-0
src/main/java/util/ColumnMeta.java
+107
-0
src/main/java/util/ThreadLocalVariable.java
+49
-0
src/main/java/util/sqlparse/HiveTDHParse.java
+1
-1
src/main/java/util/sqlparse/PostgreSqlParse.java
+0
-0
src/main/java/util/sqlparse/SqlServerParse.java
+1
-1
src/main/java/util/sqlparse/visitor/common/scope/SQLParseUtils.java
+128
-0
src/main/java/util/sqlparse/visitor/common/scope/Scope.java
+23
-4
src/main/java/util/sqlparse/visitor/mongo/FieldVisitor.java
+1
-1
src/main/java/util/sqlparse/visitor/mongo/ScopeVisitor.java
+2
-2
src/main/java/util/sqlparse/visitor/mongo/WhereVisitor.java
+1
-1
src/main/java/util/sqlparse/visitor/oracle/visitor/DefaultOracleASTVisitor.java
+0
-0
src/main/java/util/sqlparse/visitor/oracle/visitor/ParseVisitor.java
+28
-28
src/main/java/util/sqlparse/visitor/oracle/visitor/PassViewVisitor.java
+93
-0
src/main/java/util/sqlparse/visitor/oracle/visitor/ScopeVisitor.java
+0
-0
src/main/java/util/sqlparse/visitor/postgresql/PostgresqlNameWrapper.java
+29
-15
src/main/java/util/sqlparse/visitor/postgresql/SQLParser.java
+74
-26
src/main/java/util/sqlparse/visitor/postgresql/visitor/Desensitization.java
+18
-5
src/main/java/util/sqlparse/visitor/postgresql/visitor/FieldReplaceController.java
+31
-6
src/main/java/util/sqlparse/visitor/postgresql/visitor/FieldVisitor.java
+56
-38
src/main/java/util/sqlparse/visitor/postgresql/visitor/FormatVisitor.java
+8
-1
src/main/java/util/sqlparse/visitor/postgresql/visitor/ParseVisitor.java
+30
-20
src/main/java/util/sqlparse/visitor/postgresql/visitor/ReplaceVisitor.java
+1
-1
src/main/java/util/sqlparse/visitor/postgresql/visitor/RowVisitController.java
+39
-10
src/main/java/util/sqlparse/visitor/postgresql/visitor/ScopeVisitor.java
+0
-0
src/main/java/util/sqlparse/visitor/postgresql/visitor/ValueReplacer.java
+14
-7
src/main/java/util/sqlparse/visitor/postgresql/visitor/WhereVisitor.java
+8
-1
src/main/resources/gatewayconfig/config.properties.kingbase
+58
-0
src/main/resources/gatewayconfig/config.properties.postgre
+58
-0
src/main/resources/gatewayconfig/config.properties.sqlserver
+58
-0
没有找到文件。
.idea/encodings.xml
View file @
daadfce1
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"Encoding"
>
<component
name=
"Encoding"
defaultCharsetForPropertiesFiles=
"UTF-8"
>
<file
url=
"file://$PROJECT_DIR$/src/main/java"
charset=
"UTF-8"
/>
<file
url=
"file://$PROJECT_DIR$/src/main/resources"
charset=
"UTF-8"
/>
</component>
...
...
src/main/java/com/palacesun/engine/wrapper/ConnectionWrapper.java
View file @
daadfce1
差异被折叠。
点击展开。
src/main/java/com/palacesun/engine/wrapper/MysqlSchemaExtractor.java
0 → 100644
View file @
daadfce1
差异被折叠。
点击展开。
src/main/java/com/palacesun/engine/wrapper/PreparedStatementWrapper.java
View file @
daadfce1
差异被折叠。
点击展开。
src/main/java/com/palacesun/engine/wrapper/StatementWrapper.java
View file @
daadfce1
差异被折叠。
点击展开。
src/main/java/util/ColumnMeta.java
0 → 100644
View file @
daadfce1
package
util
;
public
class
ColumnMeta
{
String
database
=
null
;
String
schema
;
String
table
;
String
column
;
public
ColumnMeta
(
String
schema
,
String
table
,
String
column
)
{
this
.
schema
=
schema
;
this
.
table
=
table
;
this
.
column
=
column
;
}
public
String
getDatabase
()
{
return
this
.
database
;
}
public
void
setDatabase
(
String
database
)
{
this
.
database
=
database
;
}
public
String
getSchema
()
{
return
this
.
schema
;
}
public
void
setSchema
(
String
schema
)
{
this
.
schema
=
schema
;
}
public
String
getTable
()
{
return
this
.
table
;
}
public
void
setTable
(
String
table
)
{
this
.
table
=
table
;
}
public
String
getColumn
()
{
return
this
.
column
;
}
public
void
setColumn
(
String
column
)
{
this
.
column
=
column
;
}
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
{
return
true
;
}
else
if
(
o
!=
null
&&
this
.
getClass
()
==
o
.
getClass
())
{
ColumnMeta
that
;
label57:
{
that
=
(
ColumnMeta
)
o
;
if
(
this
.
database
!=
null
)
{
if
(
this
.
database
.
equalsIgnoreCase
(
that
.
database
))
{
break
label57
;
}
}
else
if
(
that
.
database
==
null
)
{
break
label57
;
}
return
false
;
}
label50:
{
if
(
this
.
schema
!=
null
)
{
if
(
this
.
schema
.
equalsIgnoreCase
(
that
.
schema
))
{
break
label50
;
}
}
else
if
(
that
.
schema
==
null
)
{
break
label50
;
}
return
false
;
}
if
(
this
.
table
!=
null
)
{
if
(!
this
.
table
.
equalsIgnoreCase
(
that
.
table
))
{
return
false
;
}
}
else
if
(
that
.
table
!=
null
)
{
return
false
;
}
if
(
this
.
column
!=
null
)
{
if
(!
this
.
column
.
equalsIgnoreCase
(
that
.
column
))
{
return
false
;
}
}
else
if
(
that
.
column
!=
null
)
{
return
false
;
}
return
true
;
}
else
{
return
false
;
}
}
public
int
hashCode
()
{
int
result
=
17
;
result
=
31
*
result
+
(
this
.
database
!=
null
?
this
.
database
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
this
.
schema
!=
null
?
this
.
schema
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
this
.
table
!=
null
?
this
.
table
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
this
.
column
!=
null
?
this
.
column
.
hashCode
()
:
0
);
return
result
;
}
}
src/main/java/util/ThreadLocalVariable.java
0 → 100644
View file @
daadfce1
package
util
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Map
;
import
java.util.Set
;
public
class
ThreadLocalVariable
{
private
static
ThreadLocal
<
Map
>
threadLocal
=
new
ThreadLocal
();
public
ThreadLocalVariable
()
{
}
public
static
void
remove
()
{
threadLocal
.
remove
();
}
public
static
ThreadLocal
<
Map
>
getThreadLocal
()
{
return
threadLocal
;
}
public
static
boolean
checkColumn
(
String
schema
,
String
table
,
String
column
)
{
Map
map
=
(
Map
)
threadLocal
.
get
();
if
(
map
==
null
)
{
return
true
;
}
else
{
Object
columns
=
map
.
get
(
"columns"
);
if
(
columns
!=
null
)
{
Set
<
ColumnMeta
>
columnsSet
=
(
HashSet
)
columns
;
if
(
columnsSet
.
isEmpty
())
{
return
true
;
}
else
{
ColumnMeta
temp
=
new
ColumnMeta
(
schema
,
table
,
column
);
return
columnsSet
.
contains
(
temp
);
}
}
else
{
return
true
;
}
}
}
public
static
void
setcolumns
(
Set
<
ColumnMeta
>
columnMetas
)
{
remove
();
Map
threadMap
=
new
HashMap
();
threadMap
.
put
(
"columns"
,
columnMetas
);
ThreadLocal
<
Map
>
threadLocal
=
getThreadLocal
();
threadLocal
.
set
(
threadMap
);
}
}
src/main/java/util/sqlparse/HiveTDHParse.java
View file @
daadfce1
...
...
@@ -57,7 +57,7 @@ import java.util.HashMap;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Map
;
import
org.apache.commons.lang
.StringUtils
;
import
com.chenyang.druid.util
.StringUtils
;
import
util.DataUtil
;
import
util.JdbcUtil
;
import
util.SqlUtil
;
...
...
src/main/java/util/sqlparse/PostgreSqlParse.java
View file @
daadfce1
差异被折叠。
点击展开。
src/main/java/util/sqlparse/SqlServerParse.java
View file @
daadfce1
...
...
@@ -606,7 +606,7 @@ public class SqlServerParse {
public
static
String
getSqlType
(
String
sql
,
String
dbType
)
{
String
sqlType
=
JdbcUtil
.
getSqlType
(
sql
,
dbType
);
if
(
org
.
apache
.
commons
.
lang
.
StringUtils
.
isNotEmpty
(
sqlType
)
&&
!
"with_select"
.
equalsIgnoreCase
(
sqlType
))
{
if
(
com
.
chenyang
.
druid
.
util
.
StringUtils
.
isNotEmpty
(
sqlType
)
&&
!
"with_select"
.
equalsIgnoreCase
(
sqlType
))
{
return
sqlType
;
}
else
{
SQLStatement
sqlStatement
=
null
;
...
...
src/main/java/util/sqlparse/visitor/common/scope/SQLParseUtils.java
0 → 100644
View file @
daadfce1
package
util
.
sqlparse
.
visitor
.
common
.
scope
;
import
com.chenyang.druid.DbType
;
import
util.sqlparse.visitor.common.bean.FieldInfo
;
import
util.sqlparse.visitor.common.bean.TableInfo
;
import
util.sqlparse.visitor.common.memo.FieldMemo
;
import
util.sqlparse.visitor.common.memo.TableMemo
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
public
class
SQLParseUtils
{
public
SQLParseUtils
()
{
}
public
static
void
getAtomTables
(
DbType
dbType
,
FieldMemo
field
,
List
<
TableMemo
>
tables
,
Map
<
String
,
TableInfo
>
tableMap
,
Map
<
String
,
TableInfo
>
atomTableMap
)
{
if
(
tables
!=
null
&&
tables
.
size
()
!=
0
)
{
boolean
common
=
false
;
switch
(
dbType
)
{
default
:
common
=
true
;
if
(
common
)
{
Iterator
i
$
=
tables
.
iterator
();
while
(
i
$
.
hasNext
())
{
TableMemo
table
=
(
TableMemo
)
i
$
.
next
();
if
(
table
.
getChildren
().
size
()
==
0
)
{
TableInfo
tableInfo
=
(
TableInfo
)
tableMap
.
get
(
table
.
getAtomName
());
if
(
tableInfo
!=
null
)
{
atomTableMap
.
put
(
tableInfo
.
getAtomName
(),
tableInfo
);
}
}
}
getTables
(
field
,
field
.
scope
,
tableMap
,
atomTableMap
);
}
}
}
}
static
void
getTables
(
FieldMemo
field
,
Scope
scope
,
Map
<
String
,
TableInfo
>
tableMap
,
Map
<
String
,
TableInfo
>
atomTableMap
)
{
String
name
=
field
.
name
;
Iterator
i
$
=
scope
.
getChildren
().
iterator
();
while
(
true
)
{
Scope
child
;
label55:
while
(
true
)
{
if
(!
i
$
.
hasNext
())
{
return
;
}
child
=
(
Scope
)
i
$
.
next
();
List
<
FieldMemo
>
childFieldMap
=
child
.
getFieldMap
().
orderValues
();
if
(
childFieldMap
.
isEmpty
())
{
break
;
}
FieldMemo
fieldMemo
=
null
;
Iterator
i
$
3
=
childFieldMap
.
iterator
();
while
(
i
$
3
.
hasNext
())
{
FieldMemo
item
=
(
FieldMemo
)
i
$
3
.
next
();
if
(
item
.
name
!=
null
&&
item
.
alias
!=
null
&&
item
.
alias
.
equalsIgnoreCase
(
name
))
{
fieldMemo
=
item
;
break
;
}
}
if
(
fieldMemo
!=
null
&&
!
fieldMemo
.
tables
.
isEmpty
()
&&
fieldMemo
.
isSelectItem
)
{
i
$
3
=
fieldMemo
.
tables
.
iterator
();
while
(
true
)
{
if
(!
i
$
3
.
hasNext
())
{
break
label55
;
}
TableMemo
table
=
(
TableMemo
)
i
$
3
.
next
();
TableInfo
tableInfo
=
(
TableInfo
)
tableMap
.
get
(
table
.
getAtomName
());
if
(
tableInfo
!=
null
)
{
atomTableMap
.
put
(
tableInfo
.
getAtomName
(),
tableInfo
);
}
}
}
}
getTables
(
field
,
child
,
tableMap
,
atomTableMap
);
}
}
public
static
void
getFieldInfos
(
FieldMemo
fieldMemo
,
Map
<
String
,
FieldInfo
>
fields
,
Map
<
String
,
FieldInfo
>
output
)
{
getFieldInfosInternal
(
fieldMemo
,
fields
,
false
,
output
);
}
public
static
void
getSelectFieldInfos
(
FieldMemo
fieldMemo
,
Map
<
String
,
FieldInfo
>
fields
,
Map
<
String
,
FieldInfo
>
output
)
{
getFieldInfosInternal
(
fieldMemo
,
fields
,
true
,
output
);
}
static
void
getFieldInfosInternal
(
FieldMemo
fieldMemo
,
Map
<
String
,
FieldInfo
>
fields
,
boolean
onlySelectItem
,
Map
<
String
,
FieldInfo
>
output
)
{
if
(
fieldMemo
.
children
!=
null
&&
fieldMemo
.
children
.
size
()
!=
0
)
{
Iterator
i
$
=
fieldMemo
.
children
.
iterator
();
while
(
i
$
.
hasNext
())
{
FieldMemo
child
=
(
FieldMemo
)
i
$
.
next
();
if
(
onlySelectItem
)
{
if
(
fieldMemo
.
scope
==
child
.
scope
)
{
getFieldInfosInternal
(
child
,
fields
,
onlySelectItem
,
output
);
}
else
if
(
child
.
isSelectItem
)
{
getFieldInfosInternal
(
child
,
fields
,
onlySelectItem
,
output
);
}
}
else
{
getFieldInfosInternal
(
child
,
fields
,
onlySelectItem
,
output
);
}
}
}
else
{
String
name
=
fieldMemo
.
getAtomName
();
if
(
fields
.
containsKey
(
name
))
{
FieldInfo
fieldInfo
=
(
FieldInfo
)
fields
.
get
(
name
);
fieldInfo
.
getMemos
().
add
(
fieldMemo
);
output
.
put
(
name
,
fieldInfo
);
}
}
}
}
src/main/java/util/sqlparse/visitor/common/scope/Scope.java
View file @
daadfce1
package
util
.
sqlparse
.
visitor
.
common
.
scope
;
import
bean.Column
;
import
com.chenyang.druid.sql.ast.SQLExpr
;
import
com.chenyang.druid.sql.ast.SQLObject
;
import
com.chenyang.druid.sql.ast.SQLOrderBy
;
import
com.chenyang.druid.sql.ast.SQLOver
;
import
com.chenyang.druid.sql.ast.*
;
import
com.chenyang.druid.sql.ast.expr.SQLAllColumnExpr
;
import
com.chenyang.druid.sql.ast.expr.SQLBinaryOpExpr
;
import
com.chenyang.druid.sql.ast.expr.SQLCaseExpr
;
...
...
@@ -1138,6 +1135,28 @@ public class Scope extends ID {
field
=
value
;
break
;
}
// 增加额外的查找逻辑:如果exprs为空但字段名称匹配
if
(!
found
&&
value
.
exprs
.
isEmpty
()
&&
expr
instanceof
SQLName
)
{
String
exprName
=
((
SQLName
)
expr
).
getSimpleName
();
if
(
value
.
name
!=
null
&&
value
.
name
.
equalsIgnoreCase
(
exprName
))
{
// 将表达式添加到字段的exprs列表中
value
.
exprs
.
add
(
expr
);
field
=
value
;
break
;
}
}
// 增加更宽松的查找:通过字段名称匹配
if
(!
found
&&
expr
instanceof
SQLName
)
{
String
exprName
=
((
SQLName
)
expr
).
getSimpleName
();
if
(
value
.
name
!=
null
&&
value
.
name
.
equalsIgnoreCase
(
exprName
))
{
// 将表达式添加到字段的exprs列表中
value
.
exprs
.
add
(
expr
);
field
=
value
;
break
;
}
}
}
if
(
field
!=
null
)
{
...
...
src/main/java/util/sqlparse/visitor/mongo/FieldVisitor.java
View file @
daadfce1
...
...
@@ -4,7 +4,7 @@ import bean.DataBase;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
org.apache.commons.lang
.StringUtils
;
import
com.chenyang.druid.util
.StringUtils
;
import
org.bson.BsonString
;
import
util.sqlparse.visitor.common.memo.FieldMemo
;
import
util.sqlparse.visitor.common.memo.TableMemo
;
...
...
src/main/java/util/sqlparse/visitor/mongo/ScopeVisitor.java
View file @
daadfce1
...
...
@@ -9,7 +9,7 @@ import java.util.ArrayList;
import
java.util.List
;
import
java.util.Map
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang
.StringUtils
;
import
com.chenyang.druid.util
.StringUtils
;
import
org.bson.BsonDocument
;
import
org.bson.BsonDouble
;
import
util.StringJoin
;
...
...
@@ -237,7 +237,7 @@ public class ScopeVisitor implements MongoVisitor<ParseResult> {
BsonBasicNode
bfilter
=
(
BsonBasicNode
)
json
;
if
(
bfilter
.
value
()
instanceof
String
)
{
String
name
=
(
String
)
bfilter
.
value
();
if
(
StringUtils
.
isNot
Blank
(
name
)
&&
name
.
length
()
>
0
)
{
if
(
StringUtils
.
isNot
Empty
(
name
)
&&
name
.
length
()
>
0
)
{
if
(
name
.
substring
(
0
,
1
).
equals
(
"$"
))
{
name
=
name
.
substring
(
1
);
}
...
...
src/main/java/util/sqlparse/visitor/mongo/WhereVisitor.java
View file @
daadfce1
...
...
@@ -4,7 +4,7 @@ import bean.DataBase;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
org.apache.commons.lang
.StringUtils
;
import
com.chenyang.druid.util
.StringUtils
;
import
util.sqlparse.visitor.common.Objects
;
public
class
WhereVisitor
implements
MongoVisitor
<
Boolean
>
{
...
...
src/main/java/util/sqlparse/visitor/oracle/visitor/DefaultOracleASTVisitor.java
0 → 100644
View file @
daadfce1
差异被折叠。
点击展开。
src/main/java/util/sqlparse/visitor/oracle/visitor/ParseVisitor.java
View file @
daadfce1
...
...
@@ -40,10 +40,10 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
public
void
perform
(
List
<
SQLStatement
>
statements
)
{
if
(
statements
!=
null
&&
statements
.
size
()
!=
0
)
{
Iterator
var2
=
statements
.
iterator
();
Iterator
i
$
=
statements
.
iterator
();
while
(
var2
.
hasNext
())
{
SQLStatement
statement
=
(
SQLStatement
)
var2
.
next
();
while
(
i
$
.
hasNext
())
{
SQLStatement
statement
=
(
SQLStatement
)
i
$
.
next
();
statement
.
accept
(
this
);
}
...
...
@@ -56,7 +56,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
System
.
out
.
println
(
"enter SQLSelectStatement"
+
x
.
toString
());
}
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
return
true
;
}
...
...
@@ -69,7 +69,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
}
public
boolean
visit
(
SQLInsertStatement
x
)
{
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
return
true
;
}
...
...
@@ -86,7 +86,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
}
public
boolean
visit
(
OracleMultiInsertStatement
x
)
{
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
return
true
;
}
...
...
@@ -95,7 +95,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
}
public
boolean
visit
(
SQLUpdateStatement
x
)
{
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
return
true
;
}
...
...
@@ -104,7 +104,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
}
public
boolean
visit
(
SQLMergeStatement
x
)
{
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
return
true
;
}
...
...
@@ -113,7 +113,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
}
public
boolean
visit
(
OracleUpdateStatement
x
)
{
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
return
true
;
}
...
...
@@ -122,7 +122,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
}
public
boolean
visit
(
SQLDeleteStatement
x
)
{
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
return
true
;
}
...
...
@@ -131,7 +131,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
}
public
boolean
visit
(
OracleDeleteStatement
x
)
{
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
return
true
;
}
...
...
@@ -144,7 +144,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
System
.
out
.
println
(
"enter SQLWithSubqueryClause"
+
x
.
toString
());
}
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
return
true
;
}
...
...
@@ -161,7 +161,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
System
.
out
.
println
(
"enter SQLWithSubqueryClause.Entry"
+
x
.
toString
());
}
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
return
true
;
}
...
...
@@ -178,7 +178,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
System
.
out
.
println
(
"enter SQLWithSubqueryClause.Entry"
+
x
.
toString
());
}
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
return
true
;
}
...
...
@@ -195,7 +195,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
System
.
out
.
println
(
"enter OracleSelectQueryBlock "
+
x
.
toString
());
}
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
return
true
;
}
...
...
@@ -208,7 +208,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
}
public
boolean
visit
(
SQLUnionQuery
x
)
{
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
return
true
;
}
...
...
@@ -217,7 +217,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
}
public
boolean
visit
(
SQLLateralViewTableSource
x
)
{
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
return
true
;
}
...
...
@@ -230,7 +230,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
System
.
out
.
println
(
"enter SQLSubqueryTableSource"
+
x
.
toString
());
}
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
return
true
;
}
...
...
@@ -247,7 +247,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
System
.
out
.
println
(
"enter OracleSelectSubqueryTableSource"
+
x
.
toString
());
}
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
return
true
;
}
...
...
@@ -268,7 +268,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
System
.
out
.
println
(
"enter SQLUnionQueryTableSource"
+
x
.
toString
());
}
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
return
true
;
}
...
...
@@ -303,7 +303,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
System
.
out
.
println
(
"enter OracleSelectTableReference "
+
x
);
}
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
}
else
if
(
this
.
debug
)
{
System
.
out
.
println
(
"begin OracleSelectTableReference"
+
x
.
toString
());
}
...
...
@@ -312,7 +312,7 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
}
public
void
endVisit
(
OracleSelectTableReference
x
)
{
if
(!(
x
.
getExpr
()
instanceof
SQLIdentifierExpr
)
&&
!(
x
.
get
Parent
()
instanceof
SQLPropertyExpr
))
{
if
(!(
x
.
getExpr
()
instanceof
SQLIdentifierExpr
)
&&
!(
x
.
get
Expr
()
instanceof
SQLPropertyExpr
))
{
if
(
this
.
debug
)
{
System
.
out
.
println
(
"exit OracleSelectTableReference "
+
x
);
}
...
...
@@ -326,10 +326,10 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
protected
void
acceptChild
(
List
<?
extends
SQLObject
>
children
)
{
if
(
children
!=
null
&&
children
.
size
()
!=
0
)
{
Iterator
var2
=
children
.
iterator
();
Iterator
i
$
=
children
.
iterator
();
while
(
var2
.
hasNext
())
{
SQLObject
child
=
(
SQLObject
)
var2
.
next
();
while
(
i
$
.
hasNext
())
{
SQLObject
child
=
(
SQLObject
)
i
$
.
next
();
child
.
accept
(
this
);
}
...
...
@@ -344,10 +344,10 @@ public abstract class ParseVisitor extends DefaultOracleASTVisitor {
protected
void
visitChild
(
List
<?
extends
SQLObject
>
x
)
{
if
(
x
!=
null
&&
x
.
size
()
!=
0
)
{
Iterator
var2
=
x
.
iterator
();
Iterator
i
$
=
x
.
iterator
();
while
(
var2
.
hasNext
())
{
SQLObject
sqlObject
=
(
SQLObject
)
var2
.
next
();
while
(
i
$
.
hasNext
())
{
SQLObject
sqlObject
=
(
SQLObject
)
i
$
.
next
();
this
.
visitChild
(
sqlObject
);
}
...
...
src/main/java/util/sqlparse/visitor/oracle/visitor/PassViewVisitor.java
0 → 100644
View file @
daadfce1
package
util
.
sqlparse
.
visitor
.
oracle
.
visitor
;
import
com.chenyang.druid.sql.ast.SQLObject
;
import
com.chenyang.druid.sql.ast.statement.*
;
import
com.chenyang.druid.sql.dialect.oracle.ast.stmt.OracleSelectJoin
;
import
com.chenyang.druid.sql.dialect.oracle.ast.stmt.OracleSelectQueryBlock
;
import
com.chenyang.druid.sql.dialect.oracle.ast.stmt.OracleSelectTableReference
;
import
com.chenyang.druid.sql.dialect.oracle.visitor.DefaultOracleASTVisitor
;
import
com.chenyang.druid.sql.visitor.SQLASTVisitor
;
import
com.chenyang.druid.stat.TableStat
;
import
util.sqlparse.visitor.common.scope.Scope
;
public
class
PassViewVisitor
extends
DefaultOracleASTVisitor
{
protected
Scope
scope
;
protected
String
schema
;
public
PassViewVisitor
(
Scope
scope
,
String
schema
)
{
this
.
scope
=
scope
;
this
.
schema
=
schema
;
}
public
boolean
visit
(
OracleSelectJoin
from
)
{
visit
((
SQLJoinTableSource
)
from
);
return
false
;
}
public
boolean
visit
(
SQLJoinTableSource
from
)
{
SQLJoinTableSource
jts
=
from
;
if
(
jts
.
getLeft
()
instanceof
SQLExprTableSource
||
jts
.
getLeft
()
instanceof
OracleSelectTableReference
)
{
SQLSelect
subSelect
=
getViewTableSource
(
jts
.
getLeft
());
if
(
subSelect
!=
null
)
subSelect
.
accept
((
SQLASTVisitor
)
this
);
}
else
{
jts
.
getLeft
().
accept
((
SQLASTVisitor
)
this
);
}
if
(
jts
.
getRight
()
instanceof
SQLExprTableSource
||
jts
.
getRight
()
instanceof
OracleSelectTableReference
)
{
SQLSelect
subSelect
=
getViewTableSource
(
jts
.
getRight
());
if
(
subSelect
!=
null
)
subSelect
.
accept
((
SQLASTVisitor
)
this
);
}
else
{
jts
.
getRight
().
accept
((
SQLASTVisitor
)
this
);
}
return
false
;
}
public
boolean
visit
(
OracleSelectTableReference
from
)
{
if
(
from
instanceof
SQLExprTableSource
||
from
instanceof
OracleSelectTableReference
)
{
SQLSelect
subSelect
=
getViewTableSource
((
SQLTableSource
)
from
);
if
(
subSelect
!=
null
)
{
subSelect
.
accept
((
SQLASTVisitor
)
this
);
}
else
{
String
selfSchema
=
from
.
getSchema
();
if
(
null
==
selfSchema
||
selfSchema
.
length
()
==
0
)
from
.
setSchema
(
this
.
schema
);
}
}
return
false
;
}
private
SQLSelect
getViewTableSource
(
SQLTableSource
ts
)
{
SQLExprTableSource
e
=
(
SQLExprTableSource
)
ts
;
String
name
=
e
.
getTableName
();
if
(
name
==
null
)
return
null
;
String
schema
=
(
e
.
getSchema
()
==
null
)
?
this
.
scope
.
getDefaultSchema
()
:
e
.
getSchema
();
SQLSelect
view
=
this
.
scope
.
context
.
getView
(
schema
.
toLowerCase
(),
name
.
toLowerCase
());
if
(
view
!=
null
&&
this
.
scope
.
context
.
sqlType
==
TableStat
.
Mode
.
Select
)
{
SQLSubqueryTableSource
subQuery
=
new
SQLSubqueryTableSource
();
String
alias
=
(
e
.
getAlias
()
==
null
)
?
e
.
getTableName
()
:
e
.
getAlias
();
subQuery
.
setAlias
(
alias
);
subQuery
.
setSelect
(
view
.
clone
());
SQLObject
parent
=
ts
.
getParent
();
if
(
parent
instanceof
OracleSelectQueryBlock
)
{
OracleSelectQueryBlock
block
=
(
OracleSelectQueryBlock
)
parent
;
block
.
setFrom
((
SQLTableSource
)
subQuery
);
subQuery
.
setParent
(
parent
);
}
else
if
(
parent
instanceof
OracleSelectJoin
)
{
OracleSelectJoin
join
=
(
OracleSelectJoin
)
parent
;
if
(
join
.
getLeft
()
==
ts
)
{
join
.
setLeft
((
SQLTableSource
)
subQuery
);
}
else
{
join
.
setRight
((
SQLTableSource
)
subQuery
);
}
}
return
subQuery
.
getSelect
();
}
return
null
;
}
}
src/main/java/util/sqlparse/visitor/oracle/visitor/ScopeVisitor.java
View file @
daadfce1
差异被折叠。
点击展开。
src/main/java/util/sqlparse/visitor/postgresql/PostgresqlNameWrapper.java
View file @
daadfce1
...
...
@@ -5,6 +5,7 @@ import bean.Schema;
import
bean.Table
;
import
bean.View
;
import
com.chenyang.druid.util.StringUtils
;
import
java.util.Iterator
;
import
java.util.Map
;
import
util.getdata.DatabaseCache
;
import
util.sqlparse.visitor.common.names.NameWrapper
;
...
...
@@ -63,7 +64,7 @@ public class PostgresqlNameWrapper extends NameWrapper {
}
else
{
String
column
=
c
.
getColumnName
();
if
(
column
!=
null
&&
column
.
length
()
!=
0
)
{
ColInfo
colInfo
=
this
.
getColumnInfo
(
c
);
NameWrapper
.
ColInfo
colInfo
=
this
.
getColumnInfo
(
c
);
if
(
colInfo
.
schema
==
null
)
{
colInfo
.
schema
=
this
.
defschema
;
}
...
...
@@ -91,14 +92,19 @@ public class PostgresqlNameWrapper extends NameWrapper {
if
(
sch
!=
null
)
{
return
sch
;
}
else
{
for
(
Map
.
Entry
<
String
,
Schema
>
pair
:
schemas
.
entrySet
())
{
if
(((
String
)
pair
.
getKey
()).
equalsIgnoreCase
(
schema
))
{
return
(
Schema
)
pair
.
getValue
();
}
}
Iterator
i
$
=
schemas
.
entrySet
().
iterator
();
Map
.
Entry
pair
;
do
{
if
(!
i
$
.
hasNext
())
{
return
null
;
}
pair
=
(
Map
.
Entry
)
i
$
.
next
();
}
while
(!((
String
)
pair
.
getKey
()).
equalsIgnoreCase
(
schema
));
return
(
Schema
)
pair
.
getValue
();
}
}
}
}
else
{
...
...
@@ -119,26 +125,32 @@ public class PostgresqlNameWrapper extends NameWrapper {
}
else
{
table
=
table
.
trim
();
Map
<
String
,
Table
>
tables
=
this
.
cache
.
getTables
();
String
id
;
if
(
table
.
startsWith
(
"\""
))
{
table
=
this
.
unwrapName
(
table
);
String
id
=
this
.
cache
.
getSchemaTableId
(
sch
.
getName
(),
table
);
id
=
this
.
cache
.
getSchemaTableId
(
sch
.
getName
(),
table
);
return
(
Table
)
tables
.
get
(
id
);
}
else
{
table
=
this
.
unwrapName
(
table
);
table
=
table
.
toUpperCase
();
String
id
=
this
.
cache
.
getSchemaTableId
(
sch
.
getName
(),
table
);
id
=
this
.
cache
.
getSchemaTableId
(
sch
.
getName
(),
table
);
Table
tb
=
(
Table
)
tables
.
get
(
id
);
if
(
tb
!=
null
)
{
return
tb
;
}
else
{
for
(
Map
.
Entry
<
String
,
Table
>
pair
:
tables
.
entrySet
())
{
if
(((
String
)
pair
.
getKey
()).
equalsIgnoreCase
(
id
))
{
return
(
Table
)
pair
.
getValue
();
}
}
Iterator
i
$
=
tables
.
entrySet
().
iterator
();
Map
.
Entry
pair
;
do
{
if
(!
i
$
.
hasNext
())
{
return
null
;
}
pair
=
(
Map
.
Entry
)
i
$
.
next
();
}
while
(!((
String
)
pair
.
getKey
()).
equalsIgnoreCase
(
id
));
return
(
Table
)
pair
.
getValue
();
}
}
}
}
...
...
@@ -156,7 +168,7 @@ public class PostgresqlNameWrapper extends NameWrapper {
}
}
public
void
unwrapColumn
(
ColInfo
colInfo
)
{
public
void
unwrapColumn
(
NameWrapper
.
ColInfo
colInfo
)
{
String
schema
=
colInfo
.
schema
;
String
table
=
colInfo
.
table
;
String
col
=
colInfo
.
column
;
...
...
@@ -175,8 +187,10 @@ public class PostgresqlNameWrapper extends NameWrapper {
col
=
col
.
trim
();
boolean
isCase
=
col
.
startsWith
(
"\""
);
col
=
this
.
unwrapName
(
col
);
Iterator
i
$
=
tb
.
getColumnList
().
iterator
();
for
(
Column
column
:
tb
.
getColumnList
())
{
while
(
i
$
.
hasNext
())
{
Column
column
=
(
Column
)
i
$
.
next
();
if
(
isCase
)
{
if
(
column
.
getColumnName
().
equals
(
col
))
{
colInfo
.
column
=
column
.
getColumnName
();
...
...
src/main/java/util/sqlparse/visitor/postgresql/SQLParser.java
View file @
daadfce1
...
...
@@ -38,13 +38,9 @@ import com.chenyang.druid.sql.ast.statement.SQLShowIndexesStatement;
import
com.chenyang.druid.sql.ast.statement.SQLTableSource
;
import
com.chenyang.druid.sql.ast.statement.SQLTruncateStatement
;
import
com.chenyang.druid.sql.ast.statement.SQLUpdateStatement
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.HashMap
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.ListIterator
;
import
java.util.Map
;
import
java.util.*
;
import
util.sqlparse.visitor.common.Context
;
import
util.sqlparse.visitor.common.bean.FieldInfo
;
import
util.sqlparse.visitor.common.bean.SQLResult
;
...
...
@@ -54,6 +50,7 @@ import util.sqlparse.visitor.common.bean.ValueInfo;
import
util.sqlparse.visitor.common.memo.FieldMemo
;
import
util.sqlparse.visitor.common.memo.TableMemo
;
import
util.sqlparse.visitor.common.memo.ValueMemo
;
import
util.sqlparse.visitor.common.scope.SQLParseUtils
;
import
util.sqlparse.visitor.common.scope.Scope
;
import
util.sqlparse.visitor.postgresql.visitor.FieldVisitor
;
import
util.sqlparse.visitor.postgresql.visitor.FormatVisitor
;
...
...
@@ -65,6 +62,9 @@ import util.sqlparse.visitor.postgresql.visitor.WhereVisitor;
public
class
SQLParser
{
public
static
final
String
VIRTUAL_TABLE_TAG
=
"virtualTable"
;
public
SQLParser
()
{
}
public
SQLResult
parse
(
String
sql
,
DataBase
dataBase
,
String
schema
)
{
List
<
SQLStatement
>
statements
=
SQLUtils
.
parseStatements
(
sql
,
"postgresql"
);
Context
context
=
new
Context
();
...
...
@@ -84,8 +84,10 @@ public class SQLParser {
this
.
getAllTables
(
scope
,
tables
);
Collection
<
TableMemo
>
tablesTemp
=
tables
.
values
();
List
<
TableMemo
>
tableMemoList
=
new
ArrayList
();
Iterator
i
$
=
tablesTemp
.
iterator
();
for
(
TableMemo
tableMemo
:
tablesTemp
)
{
while
(
i
$
.
hasNext
())
{
TableMemo
tableMemo
=
(
TableMemo
)
i
$
.
next
();
if
(!
tableMemo
.
topTable
)
{
tableMemoList
.
add
(
tableMemo
);
}
...
...
@@ -114,8 +116,14 @@ public class SQLParser {
}
private
void
getAllTables
(
Scope
scope
,
Map
<
String
,
TableMemo
>
tableMap
)
{
for
(
Scope
child
:
scope
.
getChildren
())
{
for
(
Map
.
Entry
<
String
,
TableMemo
>
entry
:
child
.
getTableMap
().
entrySet
())
{
Iterator
i
$
=
scope
.
getChildren
().
iterator
();
while
(
i
$
.
hasNext
())
{
Scope
child
=
(
Scope
)
i
$
.
next
();
Iterator
i
$
1
=
child
.
getTableMap
().
entrySet
().
iterator
();
while
(
i
$
1
.
hasNext
())
{
Map
.
Entry
<
String
,
TableMemo
>
entry
=
(
Map
.
Entry
)
i
$
1
.
next
();
TableMemo
value
=
(
TableMemo
)
entry
.
getValue
();
this
.
trimVirtaulTable
(
value
);
tableMap
.
put
(((
TableMemo
)
entry
.
getValue
()).
getUniqueName
(),
entry
.
getValue
());
...
...
@@ -152,9 +160,14 @@ public class SQLParser {
private
void
getAllFields
(
Scope
scope
,
Map
<
String
,
FieldMemo
>
fieldMap
,
Map
<
String
,
FieldInfo
>
fields
)
{
Map
<
String
,
TableInfo
>
tables
=
scope
.
context
.
getTableMap
();
Iterator
i
$
=
scope
.
getChildren
().
iterator
();
for
(
Scope
child
:
scope
.
getChildren
())
{
for
(
Map
.
Entry
<
String
,
FieldMemo
>
entry
:
child
.
getFieldMap
().
entrySet
())
{
while
(
i
$
.
hasNext
())
{
Scope
child
=
(
Scope
)
i
$
.
next
();
Iterator
i
$
1
=
child
.
getFieldMap
().
entrySet
().
iterator
();
while
(
i
$
1
.
hasNext
())
{
Map
.
Entry
<
String
,
FieldMemo
>
entry
=
(
Map
.
Entry
)
i
$
1
.
next
();
fieldMap
.
put
(((
FieldMemo
)
entry
.
getValue
()).
getUniqueName
(),
entry
.
getValue
());
FieldMemo
fieldMemo
=
(
FieldMemo
)
entry
.
getValue
();
Map
<
String
,
TableInfo
>
tableMap
=
new
HashMap
();
...
...
@@ -165,7 +178,10 @@ public class SQLParser {
tableMemos
.
add
(
fieldMemo
.
table
);
}
for
(
TableMemo
table
:
tableMemos
)
{
Iterator
i
$
2
=
tableMemos
.
iterator
();
while
(
i
$
2
.
hasNext
())
{
TableMemo
table
=
(
TableMemo
)
i
$
2
.
next
();
TableInfo
tableInfo
=
(
TableInfo
)
tables
.
get
(
table
.
getAtomName
());
if
(
tableInfo
==
null
)
{
isValid
=
false
;
...
...
@@ -196,18 +212,40 @@ public class SQLParser {
}
private
void
getSelectFields
(
Scope
scope
,
Map
<
String
,
FieldInfo
>
fields
,
Map
<
String
,
FieldMemo
>
fieldMap
,
Map
<
String
,
TableInfo
>
tables
,
List
<
FieldInfo
>
outputFields
)
{
for
(
Scope
child
:
scope
.
getChildren
())
{
Iterator
i
$
=
scope
.
getChildren
().
iterator
();
while
(
true
)
{
label56:
while
(
true
)
{
Scope
child
;
do
{
if
(!
i
$
.
hasNext
())
{
return
;
}
child
=
(
Scope
)
i
$
.
next
();
if
(
child
.
fromField
)
{
return
;
}
}
while
(
child
.
top
);
if
(!
child
.
top
)
{
if
(!
child
.
top
&&
child
.
getFieldMap
().
size
()
>
0
)
{
int
i
=
0
;
List
<
FieldMemo
>
fieldMemos
=
child
.
getFieldMap
().
orderValues
();
Iterator
i
$
3
=
fieldMemos
.
iterator
();
for
(
FieldMemo
field
:
child
.
getFieldMap
().
orderValues
())
{
while
(
true
)
{
FieldMemo
field
;
do
{
do
{
if
(!
i
$
3
.
hasNext
())
{
continue
label56
;
}
field
=
(
FieldMemo
)
i
$
3
.
next
();
++
i
;
if
(
field
.
isSelectItem
)
{
}
while
(!
field
.
isSelectItem
);
List
<
FieldMemo
>
childs
=
field
.
getChildren
();
if
(
null
!=
childs
&&
childs
.
size
()
>
0
)
{
ListIterator
<
FieldMemo
>
listIterator
=
childs
.
listIterator
();
...
...
@@ -219,8 +257,8 @@ public class SQLParser {
}
}
}
}
while
(
field
.
isConstant
);
if
(!
field
.
isConstant
)
{
FieldInfo
info
=
new
FieldInfo
();
info
.
setFullName
(
field
.
ref
==
null
?
field
.
name
:
field
.
ref
.
toString
());
info
.
setName
(
field
.
name
);
...
...
@@ -231,11 +269,14 @@ public class SQLParser {
Map
<
String
,
FieldInfo
>
relations
=
new
HashMap
();
this
.
getFieldInfos
(
field
,
fields
,
relations
);
if
(
field
.
tables
.
size
()
>
0
)
{
this
.
getAtomTables
(
field
.
tables
,
tables
,
info
.
getTables
());
SQLParseUtils
.
getAtomTables
(
DbType
.
postgresql
,
field
,
field
.
tables
,
tables
,
info
.
getTables
());
}
if
(
relations
.
size
()
>
0
)
{
for
(
Map
.
Entry
<
String
,
FieldInfo
>
e
:
relations
.
entrySet
())
{
Iterator
i
$
4
=
relations
.
entrySet
().
iterator
();
while
(
i
$
4
.
hasNext
())
{
Map
.
Entry
<
String
,
FieldInfo
>
e
=
(
Map
.
Entry
)
i
$
4
.
next
();
info
.
getTables
().
putAll
(((
FieldInfo
)
e
.
getValue
()).
getTables
());
}
...
...
@@ -245,19 +286,19 @@ public class SQLParser {
fieldMap
.
put
(
field
.
getUniqueName
(),
field
);
outputFields
.
add
(
info
);
}
}
}
}
else
{
this
.
getSelectFields
(
child
,
fields
,
fieldMap
,
tables
,
outputFields
);
}
}
}
}
private
void
getFieldInfos
(
FieldMemo
fieldMemo
,
Map
<
String
,
FieldInfo
>
fields
,
Map
<
String
,
FieldInfo
>
output
)
{
if
(
fieldMemo
.
children
!=
null
&&
fieldMemo
.
children
.
size
()
!=
0
)
{
for
(
FieldMemo
child
:
fieldMemo
.
children
)
{
Iterator
i
$
=
fieldMemo
.
children
.
iterator
();
while
(
i
$
.
hasNext
())
{
FieldMemo
child
=
(
FieldMemo
)
i
$
.
next
();
this
.
getFieldInfos
(
child
,
fields
,
output
);
}
}
else
{
...
...
@@ -273,7 +314,10 @@ public class SQLParser {
private
void
getAtomTables
(
List
<
TableMemo
>
tables
,
Map
<
String
,
TableInfo
>
tableMap
,
Map
<
String
,
TableInfo
>
atomTableMap
)
{
if
(
tables
!=
null
&&
tables
.
size
()
!=
0
)
{
for
(
TableMemo
table
:
tables
)
{
Iterator
i
$
=
tables
.
iterator
();
while
(
i
$
.
hasNext
())
{
TableMemo
table
=
(
TableMemo
)
i
$
.
next
();
if
(
table
.
getChildren
().
size
()
==
0
)
{
TableInfo
tableInfo
=
(
TableInfo
)
tableMap
.
get
(
table
.
getAtomName
());
if
(
tableInfo
!=
null
)
{
...
...
@@ -288,7 +332,10 @@ public class SQLParser {
}
private
void
getValues
(
Scope
scope
,
Map
<
String
,
FieldInfo
>
fieldMap
,
List
<
ValueInfo
>
values
)
{
for
(
ValueMemo
value
:
scope
.
getValues
())
{
Iterator
i
$
=
scope
.
getValues
().
iterator
();
while
(
i
$
.
hasNext
())
{
ValueMemo
value
=
(
ValueMemo
)
i
$
.
next
();
ValueInfo
valueInfo
=
new
ValueInfo
(
value
);
FieldMemo
field
=
value
.
field
;
Map
<
String
,
FieldInfo
>
fields
=
new
HashMap
();
...
...
@@ -387,3 +434,4 @@ public class SQLParser {
return
((
SQLStatement
)
statements
.
get
(
0
)).
toString
();
}
}
src/main/java/util/sqlparse/visitor/postgresql/visitor/Desensitization.java
View file @
daadfce1
...
...
@@ -14,6 +14,7 @@ import com.chenyang.druid.sql.ast.statement.SQLSelectQuery;
import
com.chenyang.druid.sql.ast.statement.SQLSelectStatement
;
import
com.chenyang.druid.sql.ast.statement.SQLTableSource
;
import
com.chenyang.druid.sql.ast.statement.SQLUpdateStatement
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
util.JdbcUtil
;
...
...
@@ -25,6 +26,9 @@ import util.sqlparse.visitor.postgresql.PostgresqlNameWrapper;
import
util.sqlparse.visitor.postgresql.SQLParser
;
public
class
Desensitization
{
public
Desensitization
()
{
}
public
Map
parseColumn
(
Map
params
)
{
return
this
.
parseData
(
params
);
}
...
...
@@ -36,8 +40,10 @@ public class Desensitization {
params
.
put
(
"newSql"
,
sql
);
String
url
=
(
String
)
params
.
get
(
"url"
);
String
ipPort
=
PostgreSqlParse
.
getIpPort
(
url
);
Iterator
i
$
=
JdbcUtil
.
dataBaseList
.
iterator
();
for
(
DataBase
base
:
JdbcUtil
.
dataBaseList
)
{
while
(
i
$
.
hasNext
())
{
DataBase
base
=
(
DataBase
)
i
$
.
next
();
if
(
base
.
getIp_port
().
equalsIgnoreCase
(
ipPort
))
{
dataBase
=
base
;
}
...
...
@@ -61,9 +67,14 @@ public class Desensitization {
SQLResult
result
=
this
.
getSqlResult
(
params
);
List
<
TableInfo
>
tables
=
result
.
tables
;
params
.
put
(
"isMatched"
,
"false"
);
Iterator
i
$
=
tables
.
iterator
();
while
(
i
$
.
hasNext
())
{
TableInfo
table
=
(
TableInfo
)
i
$
.
next
();
Iterator
i
$
1
=
table
.
getMemos
().
iterator
();
for
(
TableInfo
table
:
tables
)
{
for
(
TableMemo
tableMemo
:
table
.
getMemos
())
{
while
(
i
$
1
.
hasNext
()
)
{
TableMemo
tableMemo
=
(
TableMemo
)
i
$
1
.
next
();
String
sourceName
=
PostgresqlNameWrapper
.
normalize
(
tableMemo
.
name
);
boolean
isMatched
=
JdbcUtil
.
followRulesCaseSens
(
sourceName
,
"\"?"
+
replaceTable
+
"\"?"
);
if
(
isMatched
)
{
...
...
@@ -97,7 +108,7 @@ public class Desensitization {
if
(
ts
==
null
)
{
return
0
;
}
else
{
for
(
SQLObject
cursor
=
ts
;
cursor
!=
null
;
cursor
=
cursor
.
getParent
())
{
for
(
SQLObject
cursor
=
ts
;
cursor
!=
null
;
cursor
=
((
SQLObject
)
cursor
)
.
getParent
())
{
if
(
cursor
instanceof
SQLUpdateStatement
)
{
return
0
;
}
...
...
@@ -145,8 +156,10 @@ public class Desensitization {
params
.
put
(
"newSql"
,
sql
);
String
url
=
(
String
)
params
.
get
(
"url"
);
String
ipPort
=
PostgreSqlParse
.
getIpPort
(
url
);
Iterator
i
$
=
JdbcUtil
.
dataBaseList
.
iterator
();
for
(
DataBase
base
:
JdbcUtil
.
dataBaseList
)
{
while
(
i
$
.
hasNext
())
{
DataBase
base
=
(
DataBase
)
i
$
.
next
();
if
(
base
.
getIp_port
().
equalsIgnoreCase
(
ipPort
))
{
dataBase
=
base
;
}
...
...
src/main/java/util/sqlparse/visitor/postgresql/visitor/FieldReplaceController.java
View file @
daadfce1
...
...
@@ -9,12 +9,15 @@ import com.chenyang.druid.sql.ast.expr.SQLMethodInvokeExpr;
import
com.chenyang.druid.sql.ast.expr.SQLPropertyExpr
;
import
com.chenyang.druid.sql.ast.statement.SQLSelectItem
;
import
com.chenyang.druid.sql.ast.statement.SQLSelectQueryBlock
;
import
com.chenyang.druid.util.StringUtils
;
import
java.util.HashSet
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
com.chenyang.druid.util.StringUtils
;
import
util.JdbcUtil
;
import
util.ThreadLocalVariable
;
import
util.sqlparse.visitor.common.bean.FieldInfo
;
import
util.sqlparse.visitor.common.bean.SQLResult
;
import
util.sqlparse.visitor.common.memo.FieldMemo
;
...
...
@@ -43,17 +46,34 @@ public class FieldReplaceController {
List
<
FieldInfo
>
fields
=
this
.
result
.
outputs
;
Set
<
SQLObject
>
parsed
=
new
HashSet
();
this
.
params
.
put
(
"isMatched"
,
"false"
);
Iterator
i
$
=
fields
.
iterator
();
for
(
FieldInfo
fieldInfo
:
fields
)
{
while
(
true
)
{
label40:
while
(
i
$
.
hasNext
())
{
FieldInfo
fieldInfo
=
(
FieldInfo
)
i
$
.
next
();
if
(
fieldInfo
.
getRelations
().
size
()
<=
0
)
{
if
(
this
.
isHit
(
fieldInfo
,
this
.
result
.
isCaseSensitive
))
{
this
.
repalceFromRef
(
fieldInfo
.
getMemo
(),
parsed
);
this
.
params
.
put
(
"isMatched"
,
"true"
);
}
}
else
{
for
(
FieldInfo
fieldInfo1
:
fieldInfo
.
getRelations
())
{
if
(
this
.
isHit
(
fieldInfo1
,
this
.
result
.
isCaseSensitive
))
{
for
(
FieldMemo
memo
:
fieldInfo1
.
getMemos
())
{
Iterator
i
$
1
=
fieldInfo
.
getRelations
().
iterator
();
while
(
true
)
{
FieldInfo
fieldInfo1
;
do
{
if
(!
i
$
1
.
hasNext
())
{
continue
label40
;
}
fieldInfo1
=
(
FieldInfo
)
i
$
1
.
next
();
}
while
(!
this
.
isHit
(
fieldInfo1
,
this
.
result
.
isCaseSensitive
));
Iterator
i
$
2
=
fieldInfo1
.
getMemos
().
iterator
();
while
(
i
$
2
.
hasNext
())
{
FieldMemo
memo
=
(
FieldMemo
)
i
$
2
.
next
();
this
.
repalceFromRef
(
memo
,
parsed
);
}
...
...
@@ -62,9 +82,10 @@ public class FieldReplaceController {
}
}
}
}
this
.
params
.
put
(
"newSql"
,
statement
.
toString
());
return
;
}
}
private
void
repalceFromRef
(
FieldMemo
memo
,
Set
<
SQLObject
>
parsed
)
{
...
...
@@ -149,6 +170,9 @@ public class FieldReplaceController {
}
else
{
String
tableName
=
GreenplumNameWrapper
.
normalize
(
fieldMemo
.
table
.
name
);
String
schema
=
GreenplumNameWrapper
.
normalize
(
fieldMemo
.
table
.
schema
);
if
(!
ThreadLocalVariable
.
checkColumn
(
schema
,
tableName
,
columnName
))
{
return
false
;
}
else
{
if
(
isCaseSensitive
)
{
if
(
JdbcUtil
.
followRulesCaseSens
(
columnName
,
this
.
replaceColumn
)
&&
JdbcUtil
.
followRulesCaseSens
(
tableName
,
this
.
replaceTable
)
&&
JdbcUtil
.
followRulesCaseSens
(
schema
,
this
.
replaceSchema
))
{
return
true
;
...
...
@@ -159,6 +183,7 @@ public class FieldReplaceController {
return
false
;
}
}
}
else
{
return
true
;
}
...
...
src/main/java/util/sqlparse/visitor/postgresql/visitor/FieldVisitor.java
View file @
daadfce1
...
...
@@ -45,6 +45,7 @@ import com.chenyang.druid.sql.ast.statement.SQLUpdateSetItem;
import
com.chenyang.druid.sql.ast.statement.SQLValuesTableSource
;
import
com.chenyang.druid.sql.dialect.postgresql.ast.stmt.PGInsertStatement
;
import
java.util.ArrayList
;
import
java.util.Iterator
;
import
java.util.List
;
import
util.sqlparse.visitor.common.memo.FieldMemo
;
import
util.sqlparse.visitor.common.memo.ValueMemo
;
...
...
@@ -108,21 +109,26 @@ public class FieldVisitor extends ParseVisitor {
private
void
setListExpr
(
SQLExpr
valueExpr
,
SQLObject
parent
)
{
SQLObject
pa
=
parent
.
getParent
();
SQLListExpr
columns
;
int
i
;
List
valueItems
;
int
index
;
ValueMemo
value
;
if
(
pa
instanceof
SQLUpdateSetItem
)
{
SQLUpdateSetItem
setItem
=
(
SQLUpdateSetItem
)
pa
;
SQLListExpr
columns
=
(
SQLListExpr
)
setItem
.
getColumn
();
i
nt
index
=
0
;
columns
=
(
SQLListExpr
)
setItem
.
getColumn
();
i
=
0
;
SQLListExpr
item
=
(
SQLListExpr
)
parent
;
List
<
SQLExpr
>
i
tems
=
item
.
getItems
();
valueI
tems
=
item
.
getItems
();
for
(
in
t
i
=
0
;
i
<
items
.
size
();
++
i
)
{
if
(
items
.
get
(
i
)
==
valueExpr
)
{
i
ndex
=
i
;
for
(
in
dex
=
0
;
index
<
valueItems
.
size
();
++
index
)
{
if
(
valueItems
.
get
(
index
)
==
valueExpr
)
{
i
=
index
;
break
;
}
}
ValueMemo
value
=
this
.
getValueMemo
((
SQLExpr
)
columns
.
getItems
().
get
(
index
),
valueExpr
);
value
=
this
.
getValueMemo
((
SQLExpr
)
columns
.
getItems
().
get
(
i
),
valueExpr
);
value
.
setRef
(
valueExpr
);
value
.
setExpr
(
parent
);
value
.
setValue
(
this
.
getValue
(
valueExpr
));
...
...
@@ -131,15 +137,15 @@ public class FieldVisitor extends ParseVisitor {
this
.
scope
.
getValues
().
add
(
value
);
}
else
if
(
pa
instanceof
SQLAssignItem
)
{
SQLAssignItem
assignItem
=
(
SQLAssignItem
)
pa
;
SQLListExpr
target
=
(
SQLListExpr
)
assignItem
.
getTarget
();
SQLListExpr
value
=
(
SQLListExpr
)
assignItem
.
getValue
();
List
<
SQLExpr
>
targetItems
=
target
.
getItems
();
List
<
SQLExpr
>
valueItems
=
value
.
getItems
();
in
t
in
dex
=
0
;
for
(
int
i
=
0
;
i
<
valueItems
.
size
();
++
i
)
{
if
(
valueItems
.
get
(
i
)
==
valueExpr
)
{
index
=
i
;
columns
=
(
SQLListExpr
)
assignItem
.
getTarget
();
SQLListExpr
value
2
=
(
SQLListExpr
)
assignItem
.
getValue
();
List
<
SQLExpr
>
targetItems
=
columns
.
getItems
();
valueItems
=
value2
.
getItems
();
index
=
0
;
for
(
int
i
1
=
0
;
i1
<
valueItems
.
size
();
++
i1
)
{
if
(
valueItems
.
get
(
i
1
)
==
valueExpr
)
{
index
=
i
1
;
break
;
}
}
...
...
@@ -148,26 +154,26 @@ public class FieldVisitor extends ParseVisitor {
val
.
setRef
(
valueExpr
);
val
.
setExpr
(
parent
);
val
.
setValue
(
this
.
getValue
(
valueExpr
));
val
.
setPreDefined
(
value
.
toString
().
equals
(
"?"
));
val
.
setPreDefined
(
value
2
.
toString
().
equals
(
"?"
));
val
.
setOperator
(
"SET"
);
this
.
scope
.
getValues
().
add
(
val
);
}
else
if
(
pa
instanceof
SQLValuesTableSource
)
{
SQLValuesTableSource
tableSource
=
(
SQLValuesTableSource
)
pa
;
in
t
in
dex
=
0
;
index
=
0
;
for
(
i
nt
i
=
0
;
i
<
((
SQLListExpr
)
parent
).
getItems
().
size
();
++
i
)
{
for
(
i
=
0
;
i
<
((
SQLListExpr
)
parent
).
getItems
().
size
();
++
i
)
{
if
(((
SQLListExpr
)
parent
).
getItems
().
get
(
i
)
==
valueExpr
)
{
index
=
i
;
break
;
}
}
List
<
SQLName
>
columns
=
tableSource
.
getColumns
();
if
(
columns
!=
null
&&
columns
.
size
()
>
0
)
{
int
size
=
columns
.
size
();
List
<
SQLName
>
columns
1
=
tableSource
.
getColumns
();
if
(
columns
1
!=
null
&&
columns1
.
size
()
>
0
)
{
int
size
=
columns
1
.
size
();
index
%=
size
;
SQLExpr
columnExpr
=
(
SQLExpr
)
columns
.
get
(
index
);
ValueMemo
value
=
this
.
getValueMemo
(
columnExpr
,
valueExpr
);
SQLExpr
columnExpr
=
(
SQLExpr
)
columns
1
.
get
(
index
);
value
=
this
.
getValueMemo
(
columnExpr
,
valueExpr
);
value
.
setRef
(
valueExpr
);
value
.
setExpr
(
parent
);
value
.
setValue
(
this
.
getValue
(
valueExpr
));
...
...
@@ -293,12 +299,13 @@ public class FieldVisitor extends ParseVisitor {
if
(
x
instanceof
SQLBinaryOpExpr
)
{
SQLBinaryOpExpr
bin
=
(
SQLBinaryOpExpr
)
x
;
if
(
bin
.
getOperator
()
!=
null
)
{
SQLExpr
cmp
;
switch
(
bin
.
getOperator
())
{
case
Like:
case
Like2:
case
Like4:
case
Likec:
SQLExpr
cmp
=
bin
.
getLeft
().
equals
(
y
)
?
bin
.
getRight
()
:
bin
.
getLeft
();
cmp
=
bin
.
getLeft
().
equals
(
y
)
?
bin
.
getRight
()
:
bin
.
getLeft
();
operators
.
add
(
"LIKE"
);
return
cmp
;
case
Equality:
...
...
@@ -306,9 +313,9 @@ public class FieldVisitor extends ParseVisitor {
case
GreaterThanOrEqual:
case
LessThan:
case
LessThanOrEqual:
SQLExpr
cmp2
=
bin
.
getLeft
().
equals
(
y
)
?
bin
.
getRight
()
:
bin
.
getLeft
();
cmp
=
bin
.
getLeft
().
equals
(
y
)
?
bin
.
getRight
()
:
bin
.
getLeft
();
operators
.
add
(
bin
.
getOperator
().
getName
().
toUpperCase
());
return
cmp
2
;
return
cmp
;
case
BooleanAnd:
case
BooleanOr:
if
(
y
instanceof
SQLExpr
)
{
...
...
@@ -373,8 +380,10 @@ public class FieldVisitor extends ParseVisitor {
if
(
insert
.
getQuery
()
!=
null
)
{
SQLSelect
query
=
insert
.
getQuery
();
Scope
selectScope
=
this
.
scope
.
getScope
(
query
);
Iterator
i
$
=
selectScope
.
getFieldMap
().
orderValues
().
iterator
();
for
(
FieldMemo
orderValue
:
selectScope
.
getFieldMap
().
orderValues
())
{
while
(
i
$
.
hasNext
())
{
FieldMemo
orderValue
=
(
FieldMemo
)
i
$
.
next
();
if
(
orderValue
.
isSelectItem
)
{
fields
.
add
(
orderValue
);
}
...
...
@@ -382,22 +391,24 @@ public class FieldVisitor extends ParseVisitor {
}
}
int
size
;
ValueMemo
value
;
if
(
columns
!=
null
&&
columns
.
size
()
>
0
)
{
int
size
=
columns
.
size
();
size
=
columns
.
size
();
index
%=
size
;
SQLExpr
columnExpr
=
(
SQLExpr
)
columns
.
get
(
index
);
ValueMemo
value
=
this
.
getValueMemo
(
columnExpr
,
valueExpr
);
value
=
this
.
getValueMemo
(
columnExpr
,
valueExpr
);
value
.
ref
=
valueExpr
;
value
.
expr
=
parent
;
value
.
value
=
this
.
getValue
(
valueExpr
);
value
.
isPreDefined
=
value
.
toString
().
equals
(
"?"
);
value
.
operator
=
"SET"
;
this
.
scope
.
getValues
().
add
(
value
);
}
else
if
(
fields
!=
null
)
{
int
size
=
fields
.
size
();
}
else
if
(
fields
!=
null
&&
fields
.
size
()
>
0
)
{
size
=
fields
.
size
();
index
%=
size
;
FieldMemo
field
=
(
FieldMemo
)
fields
.
get
(
index
);
ValueMemo
value
=
new
ValueMemo
();
value
=
new
ValueMemo
();
value
.
field
=
field
;
value
.
ref
=
valueExpr
;
value
.
expr
=
parent
;
...
...
@@ -478,27 +489,29 @@ public class FieldVisitor extends ParseVisitor {
private
void
setLimit
(
SQLExpr
valueExpr
,
SQLObject
parent
)
{
SQLLimit
limit
=
(
SQLLimit
)
parent
;
ValueMemo
value
;
FieldMemo
field
;
if
(
limit
.
getOffset
()
!=
null
&&
limit
.
getOffset
()
==
valueExpr
)
{
ValueMemo
value
=
new
ValueMemo
();
value
=
new
ValueMemo
();
value
.
ref
=
limit
.
getOffset
();
value
.
expr
=
parent
;
value
.
value
=
this
.
getValue
(
valueExpr
);
value
.
isPreDefined
=
valueExpr
.
toString
().
equals
(
"?"
);
value
.
operator
=
"LIMIT"
;
FieldMemo
field
=
new
FieldMemo
();
field
=
new
FieldMemo
();
field
.
name
=
parent
+
"limit_offset"
;
value
.
field
=
field
;
this
.
scope
.
getValues
().
add
(
value
);
}
if
(
limit
.
getRowCount
()
!=
null
&&
limit
.
getRowCount
()
==
valueExpr
)
{
ValueMemo
value
=
new
ValueMemo
();
value
=
new
ValueMemo
();
value
.
ref
=
limit
.
getRowCount
();
value
.
expr
=
parent
;
value
.
value
=
this
.
getValue
(
valueExpr
);
value
.
isPreDefined
=
valueExpr
.
toString
().
equals
(
"?"
);
value
.
operator
=
"LIMIT"
;
FieldMemo
field
=
new
FieldMemo
();
field
=
new
FieldMemo
();
field
.
name
=
parent
+
"limit_rowcount"
;
value
.
field
=
field
;
this
.
scope
.
getValues
().
add
(
value
);
...
...
@@ -523,7 +536,12 @@ public class FieldVisitor extends ParseVisitor {
}
private
ValueMemo
getValueMemo
(
SQLExpr
x
,
SQLExpr
valueExpr
,
boolean
nullIfNoField
)
{
ValueMemo
value
=
this
.
scope
.
getCurrent
().
getFieldValueInfo
(
x
);
Scope
current
=
this
.
scope
.
getCurrent
();
if
(
current
.
getFieldMap
().
isEmpty
()
&&
!
current
.
getChildren
().
isEmpty
())
{
current
=
(
Scope
)
current
.
getChildren
().
get
(
0
);
}
ValueMemo
value
=
current
.
getFieldValueInfo
(
x
);
if
(
value
==
null
&&
!
nullIfNoField
)
{
value
=
new
ValueMemo
(
valueExpr
);
FieldMemo
field
=
new
FieldMemo
();
...
...
src/main/java/util/sqlparse/visitor/postgresql/visitor/FormatVisitor.java
View file @
daadfce1
...
...
@@ -71,15 +71,22 @@ import com.chenyang.druid.sql.dialect.postgresql.ast.stmt.alterTable.PGAlterTabl
import
com.chenyang.druid.sql.dialect.postgresql.ast.stmt.alterTable.PGAlterTableValidateConstraint
;
import
com.chenyang.druid.sql.dialect.postgresql.ast.stmt.alterTable.PGColumnDefinition
;
import
com.chenyang.druid.sql.dialect.postgresql.visitor.PGASTVisitor
;
import
java.util.Iterator
;
import
java.util.List
;
import
util.sqlparse.visitor.Formater
;
public
class
FormatVisitor
extends
Formater
implements
PGASTVisitor
{
private
boolean
debug
=
false
;
public
FormatVisitor
()
{
}
public
void
perform
(
List
<
SQLStatement
>
statements
)
{
if
(
statements
!=
null
&&
statements
.
size
()
!=
0
)
{
for
(
SQLStatement
statement
:
statements
)
{
Iterator
i
$
=
statements
.
iterator
();
while
(
i
$
.
hasNext
())
{
SQLStatement
statement
=
(
SQLStatement
)
i
$
.
next
();
statement
.
accept
(
this
);
}
...
...
src/main/java/util/sqlparse/visitor/postgresql/visitor/ParseVisitor.java
View file @
daadfce1
...
...
@@ -25,6 +25,7 @@ import com.chenyang.druid.sql.dialect.postgresql.ast.stmt.PGInsertStatement;
import
com.chenyang.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock
;
import
com.chenyang.druid.sql.dialect.postgresql.ast.stmt.PGUpdateStatement
;
import
com.chenyang.druid.sql.dialect.postgresql.visitor.DefaultPGASTVisitor
;
import
java.util.Iterator
;
import
java.util.List
;
import
util.sqlparse.visitor.common.scope.Scope
;
...
...
@@ -38,7 +39,10 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
public
void
perform
(
List
<
SQLStatement
>
statements
)
{
if
(
statements
!=
null
&&
statements
.
size
()
!=
0
)
{
for
(
SQLStatement
statement
:
statements
)
{
Iterator
i
$
=
statements
.
iterator
();
while
(
i
$
.
hasNext
())
{
SQLStatement
statement
=
(
SQLStatement
)
i
$
.
next
();
statement
.
accept
(
this
);
}
...
...
@@ -51,7 +55,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
System
.
out
.
println
(
"enter SQLSelectStatement"
+
x
.
toString
());
}
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
return
true
;
}
...
...
@@ -64,7 +68,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
}
public
boolean
visit
(
SQLInsertStatement
x
)
{
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
return
true
;
}
...
...
@@ -81,7 +85,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
}
public
boolean
visit
(
SQLUpdateStatement
x
)
{
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
return
true
;
}
...
...
@@ -90,7 +94,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
}
public
boolean
visit
(
PGUpdateStatement
x
)
{
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
return
true
;
}
...
...
@@ -99,7 +103,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
}
public
boolean
visit
(
SQLDeleteStatement
x
)
{
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
return
true
;
}
...
...
@@ -108,7 +112,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
}
public
boolean
visit
(
PGDeleteStatement
x
)
{
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
return
true
;
}
...
...
@@ -117,7 +121,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
}
public
boolean
visit
(
PGGrantStatement
x
)
{
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
return
true
;
}
...
...
@@ -126,7 +130,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
}
public
boolean
visit
(
SQLRevokeStatement
x
)
{
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
return
true
;
}
...
...
@@ -139,7 +143,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
System
.
out
.
println
(
"enter SQLWithSubqueryClause"
+
x
.
toString
());
}
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
return
true
;
}
...
...
@@ -156,7 +160,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
System
.
out
.
println
(
"enter SQLWithSubqueryClause.Entry"
+
x
.
toString
());
}
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
return
true
;
}
...
...
@@ -173,7 +177,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
System
.
out
.
println
(
"enter PGSelectQueryBlock "
+
x
.
toString
());
}
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
return
true
;
}
...
...
@@ -194,7 +198,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
}
public
boolean
visit
(
SQLUnionQuery
x
)
{
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
return
true
;
}
...
...
@@ -203,7 +207,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
}
public
boolean
visit
(
SQLLateralViewTableSource
x
)
{
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
return
true
;
}
...
...
@@ -216,7 +220,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
System
.
out
.
println
(
"enter SQLSubqueryTableSource"
+
x
.
toString
());
}
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
return
true
;
}
...
...
@@ -233,7 +237,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
System
.
out
.
println
(
"enter PGSubqueryTableSource"
+
x
.
toString
());
}
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
return
true
;
}
...
...
@@ -254,7 +258,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
System
.
out
.
println
(
"enter SQLUnionQueryTableSource"
+
x
.
toString
());
}
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
return
true
;
}
...
...
@@ -282,7 +286,7 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
System
.
out
.
println
(
"enter PGExprTableSource "
+
x
);
}
this
.
scope
.
enterScope
(
(
SQLObject
)
x
);
this
.
scope
.
enterScope
(
x
);
}
else
if
(
this
.
debug
)
{
System
.
out
.
println
(
"begin PGExprTableSource"
+
x
.
toString
());
}
...
...
@@ -305,7 +309,10 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
protected
void
acceptChild
(
List
<?
extends
SQLObject
>
children
)
{
if
(
children
!=
null
&&
children
.
size
()
!=
0
)
{
for
(
SQLObject
child
:
children
)
{
Iterator
i
$
=
children
.
iterator
();
while
(
i
$
.
hasNext
())
{
SQLObject
child
=
(
SQLObject
)
i
$
.
next
();
child
.
accept
(
this
);
}
...
...
@@ -320,7 +327,10 @@ public abstract class ParseVisitor extends DefaultPGASTVisitor {
protected
void
visitChild
(
List
<?
extends
SQLObject
>
x
)
{
if
(
x
!=
null
&&
x
.
size
()
!=
0
)
{
for
(
SQLObject
sqlObject
:
x
)
{
Iterator
i
$
=
x
.
iterator
();
while
(
i
$
.
hasNext
())
{
SQLObject
sqlObject
=
(
SQLObject
)
i
$
.
next
();
this
.
visitChild
(
sqlObject
);
}
...
...
src/main/java/util/sqlparse/visitor/postgresql/visitor/ReplaceVisitor.java
View file @
daadfce1
...
...
@@ -45,7 +45,7 @@ public class ReplaceVisitor extends ParseVisitor {
this
.
scope
.
setReplaceInfo
(
replaceInfo
);
}
return
super
.
visit
(
(
SQLBinaryOpExpr
)
x
);
return
super
.
visit
(
x
);
}
public
String
visitReplace
(
SQLStatement
stmt
,
ReplaceInfo
replaceInfo
,
String
encType
,
String
secretKey
)
{
...
...
src/main/java/util/sqlparse/visitor/postgresql/visitor/RowVisitController.java
View file @
daadfce1
...
...
@@ -25,6 +25,7 @@ import com.chenyang.druid.sql.ast.statement.SQLUpdateStatement;
import
com.chenyang.druid.sql.dialect.postgresql.ast.expr.tablesource.PGExprTableSource
;
import
com.chenyang.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock
;
import
java.util.HashSet
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
...
...
@@ -62,13 +63,39 @@ public class RowVisitController {
Pattern
pattern
=
Pattern
.
compile
(
"\"?"
+
tempTableRegex
+
"\"?"
);
List
<
TableInfo
>
tables
=
this
.
result
.
tables
;
Set
<
SQLObject
>
parsed
=
new
HashSet
();
Iterator
i
$
=
tables
.
iterator
();
label53:
while
(
true
)
{
TableInfo
table
;
String
name
;
do
{
if
(!
i
$
.
hasNext
())
{
this
.
params
.
put
(
"newSql"
,
statement
.
toString
());
return
;
}
table
=
(
TableInfo
)
i
$
.
next
();
name
=
PostgresqlNameWrapper
.
normalize
(
table
.
getTable
().
name
);
}
while
(!
pattern
.
matcher
(
name
).
matches
());
List
<
TableMemo
>
memos
=
table
.
getMemos
();
Iterator
i
$
2
=
memos
.
iterator
();
while
(
true
)
{
while
(
true
)
{
SQLObject
ref
;
do
{
do
{
if
(!
i
$
2
.
hasNext
())
{
continue
label53
;
}
TableMemo
memo
=
(
TableMemo
)
i
$
2
.
next
();
ref
=
memo
.
ref
;
}
while
(
parsed
.
contains
(
ref
));
}
while
(!(
ref
instanceof
SQLTableSource
));
for
(
TableInfo
table
:
tables
)
{
String
name
=
PostgresqlNameWrapper
.
normalize
(
table
.
getTable
().
name
);
if
(
pattern
.
matcher
(
name
).
matches
())
{
for
(
TableMemo
memo
:
table
.
getMemos
())
{
SQLObject
ref
=
memo
.
ref
;
if
(!
parsed
.
contains
(
ref
)
&&
ref
instanceof
SQLTableSource
)
{
this
.
params
.
put
(
"isMatched"
,
"true"
);
switch
(
this
.
result
.
statementType
)
{
case
select:
...
...
@@ -95,9 +122,6 @@ public class RowVisitController {
}
}
}
this
.
params
.
put
(
"newSql"
,
statement
.
toString
());
}
}
private
void
limitStatement
()
{
...
...
@@ -232,7 +256,11 @@ public class RowVisitController {
SQLExpr
expr
=
this
.
createBinaryExpr
(
alias
);
SQLSelectQuery
query
=
select
.
getQuery
();
if
(
query
instanceof
SQLUnionQuery
)
{
for
(
SQLSelectQuery
relation
:
((
SQLUnionQuery
)
query
).
getRelations
())
{
List
<
SQLSelectQuery
>
relations
=
((
SQLUnionQuery
)
query
).
getRelations
();
Iterator
i
$
=
relations
.
iterator
();
while
(
i
$
.
hasNext
())
{
SQLSelectQuery
relation
=
(
SQLSelectQuery
)
i
$
.
next
();
if
(
relation
instanceof
PGSelectQueryBlock
)
{
SQLTableSource
from
=
((
PGSelectQueryBlock
)
relation
).
getFrom
();
if
(
this
.
tableMatch
(
from
,
alias
))
{
...
...
@@ -347,3 +375,4 @@ public class RowVisitController {
return
true
;
}
}
src/main/java/util/sqlparse/visitor/postgresql/visitor/ScopeVisitor.java
View file @
daadfce1
差异被折叠。
点击展开。
src/main/java/util/sqlparse/visitor/postgresql/visitor/ValueReplacer.java
View file @
daadfce1
...
...
@@ -13,6 +13,7 @@ import com.chenyang.druid.sql.ast.statement.SQLMergeStatement;
import
com.chenyang.druid.sql.ast.statement.SQLUpdateSetItem
;
import
com.chenyang.druid.sql.dialect.mysql.ast.expr.MySqlCharExpr
;
import
java.util.HashSet
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
...
...
@@ -37,8 +38,11 @@ public class ValueReplacer {
public
void
replaceValues
(
List
<
ValueInfo
>
values
)
{
if
(
values
!=
null
&&
values
.
size
()
!=
0
)
{
for
(
ValueMemo
value
:
values
)
{
this
.
replaceValue
(
value
,
null
);
Iterator
i
$
=
values
.
iterator
();
while
(
i
$
.
hasNext
())
{
ValueMemo
value
=
(
ValueInfo
)
i
$
.
next
();
this
.
replaceValue
(
value
,
(
String
)
null
);
}
}
...
...
@@ -205,7 +209,10 @@ public class ValueReplacer {
if
(
field
.
getChildren
().
size
()
==
0
&&
this
.
replace
!=
null
&&
this
.
replace
.
containsKey
(
this
.
replace
.
get
(
field
.
getAtomName
())))
{
output
.
add
(
field
.
getAtomName
());
}
else
{
for
(
FieldMemo
child
:
field
.
children
)
{
Iterator
i
$
=
field
.
children
.
iterator
();
while
(
i
$
.
hasNext
())
{
FieldMemo
child
=
(
FieldMemo
)
i
$
.
next
();
this
.
getAtomFields
(
child
,
output
);
}
...
...
@@ -214,15 +221,15 @@ public class ValueReplacer {
private
SQLExpr
createValueExpr
(
ValueMemo
value
,
SQLObject
parent
,
String
newVal
)
{
SQLTextLiteralExpr
expr
=
new
MySqlCharExpr
();
expr
.
setParent
(
parent
);
((
SQLTextLiteralExpr
)
expr
)
.
setParent
(
parent
);
if
(
newVal
!=
null
)
{
expr
.
setText
(
newVal
);
((
SQLTextLiteralExpr
)
expr
)
.
setText
(
newVal
);
}
else
{
String
val
=
value
.
value
.
toString
();
if
(
this
.
replace
!=
null
&&
this
.
replace
.
containsKey
(
value
.
field
.
getAtomName
()))
{
expr
.
setText
((
String
)
this
.
replace
.
get
(
value
.
field
.
getAtomName
()));
((
SQLTextLiteralExpr
)
expr
)
.
setText
((
String
)
this
.
replace
.
get
(
value
.
field
.
getAtomName
()));
}
else
{
expr
.
setText
(
val
);
((
SQLTextLiteralExpr
)
expr
)
.
setText
(
val
);
}
}
...
...
src/main/java/util/sqlparse/visitor/postgresql/visitor/WhereVisitor.java
View file @
daadfce1
...
...
@@ -10,6 +10,7 @@ import com.chenyang.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock;
import
com.chenyang.druid.sql.dialect.postgresql.ast.stmt.PGUpdateStatement
;
import
com.chenyang.druid.sql.dialect.postgresql.visitor.DefaultPGASTVisitor
;
import
java.util.ArrayList
;
import
java.util.Iterator
;
import
java.util.List
;
public
class
WhereVisitor
extends
DefaultPGASTVisitor
{
...
...
@@ -20,9 +21,15 @@ public class WhereVisitor extends DefaultPGASTVisitor {
return
this
.
wheres
;
}
public
WhereVisitor
()
{
}
public
void
perform
(
List
<
SQLStatement
>
statements
)
{
if
(
statements
!=
null
&&
statements
.
size
()
!=
0
)
{
for
(
SQLStatement
statement
:
statements
)
{
Iterator
i
$
=
statements
.
iterator
();
while
(
i
$
.
hasNext
())
{
SQLStatement
statement
=
(
SQLStatement
)
i
$
.
next
();
statement
.
accept
(
this
);
}
...
...
src/main/resources/gatewayconfig/config.properties.kingbase
0 → 100644
View file @
daadfce1
#网关地址
gatewayurl=https://172.19.1.167:9005
#插件对应的网关项目的projectId
projectid=a22254df-da51-421f-b5a0-e66ba1d74b4a
#插件同步数据的方式(推/拉)
dataSynchronousMode=pull
#轮询时间(默认1分钟)
pullInterval=60000
#是否记录本地同步日志
isSave=false
#加密标识
encryption.label=jm_
#单个字符加密后连接起来用某个字符进行分割
encryption.like.split=#
##like是否执行按照单个字符进行加密开关。1表示按照单个字符进行加密。0表示按照字符串整体进行加密, 默认不开启
encryption.like.open=1
#is remote enc/dec
encryption.remote=0
#是否采用远程加密卡加解密,false不使用加密卡,true使用加密卡,encryption.remote=1表示远程加解密
ccoresdf=false
mode=CCORESDF
#key location cache or (cache and file)
encryption.keyCache=1
#插件集成的项目启动后,向平台时注册自己的端口号标识
rootport=54321
#秘钥存放位置
encryption.location=/home/ghca/data/encryption.properties
#完整性规则存放位置
digest.location=/home/ghca/data/digest.properties
#外部配置文件信息地址
encryption.config.location=/home/ghca/data/plugin/config.properties
#驱动列表,如有多个以#分割
encryption.drivers=
#插件是否打印日志,如果为空或者为0不打印日志信息,1为打印日志信息
encryption.log=0
#插件是否开启sql查询时where条件like替换功能,1为开启,0为不开启
replaceSql=0
#是否根据登录账号开启脱敏功能,1为开启,0为未开启
maskingRule=0
#密文分隔符
encryption.separator=_jm
#******************************** 规则配置信息 ***********************************
#localfile/gateway
encryption.rule-origin=gateway
#localfile/gateway
masking.rule-origin=gateway
#reload config
rule.load-period=30
#gateway config
gateway.protocol=https
gateway.host=172.19.1.167
gateway.port=9005
#0:ry系统,1:masking 系统
getUserType=0
\ No newline at end of file
src/main/resources/gatewayconfig/config.properties.postgre
0 → 100644
View file @
daadfce1
#网关地址
gatewayurl=https://172.19.1.167:9005
#插件对应的网关项目的projectId
projectid=5e75836f-da94-4a6c-b897-a131bdc23107
#插件同步数据的方式(推/拉)
dataSynchronousMode=pull
#轮询时间(默认1分钟)
pullInterval=60000
#是否记录本地同步日志
isSave=false
#加密标识
encryption.label=jm_
#单个字符加密后连接起来用某个字符进行分割
encryption.like.split=#
##like是否执行按照单个字符进行加密开关。1表示按照单个字符进行加密。0表示按照字符串整体进行加密, 默认不开启
encryption.like.open=1
#is remote enc/dec
encryption.remote=0
#是否采用远程加密卡加解密,false不使用加密卡,true使用加密卡,encryption.remote=1表示远程加解密
ccoresdf=false
mode=CCORESDF
#key location cache or (cache and file)
encryption.keyCache=1
#插件集成的项目启动后,向平台时注册自己的端口号标识
rootport=54321
#秘钥存放位置
encryption.location=/home/ghca/data/encryption.properties
#完整性规则存放位置
digest.location=/home/ghca/data/digest.properties
#外部配置文件信息地址
encryption.config.location=/home/ghca/data/plugin/config.properties
#驱动列表,如有多个以#分割
encryption.drivers=
#插件是否打印日志,如果为空或者为0不打印日志信息,1为打印日志信息
encryption.log=0
#插件是否开启sql查询时where条件like替换功能,1为开启,0为不开启
replaceSql=0
#是否根据登录账号开启脱敏功能,1为开启,0为未开启
maskingRule=0
#密文分隔符
encryption.separator=_jm
#******************************** 规则配置信息 ***********************************
#localfile/gateway
encryption.rule-origin=gateway
#localfile/gateway
masking.rule-origin=gateway
#reload config
rule.load-period=30
#gateway config
gateway.protocol=https
gateway.host=172.19.1.167
gateway.port=9005
#0:ry系统,1:masking 系统
getUserType=0
\ No newline at end of file
src/main/resources/gatewayconfig/config.properties.sqlserver
0 → 100644
View file @
daadfce1
#网关地址
gatewayurl=https://172.19.1.167:9005
#插件对应的网关项目的projectId
projectid=6d486188-ee80-42d3-8183-fbaf4016044e
#插件同步数据的方式(推/拉)
dataSynchronousMode=pull
#轮询时间(默认1分钟)
pullInterval=60000
#是否记录本地同步日志
isSave=false
#加密标识
encryption.label=jm_
#单个字符加密后连接起来用某个字符进行分割
encryption.like.split=#
##like是否执行按照单个字符进行加密开关。1表示按照单个字符进行加密。0表示按照字符串整体进行加密, 默认不开启
encryption.like.open=1
#is remote enc/dec
encryption.remote=0
#是否采用远程加密卡加解密,false不使用加密卡,true使用加密卡,encryption.remote=1表示远程加解密
ccoresdf=false
mode=CCORESDF
#key location cache or (cache and file)
encryption.keyCache=1
#插件集成的项目启动后,向平台时注册自己的端口号标识
rootport=54321
#秘钥存放位置
encryption.location=/home/ghca/data/encryption.properties
#完整性规则存放位置
digest.location=/home/ghca/data/digest.properties
#外部配置文件信息地址
encryption.config.location=/home/ghca/data/plugin/config.properties
#驱动列表,如有多个以#分割
encryption.drivers=
#插件是否打印日志,如果为空或者为0不打印日志信息,1为打印日志信息
encryption.log=0
#插件是否开启sql查询时where条件like替换功能,1为开启,0为不开启
replaceSql=0
#是否根据登录账号开启脱敏功能,1为开启,0为未开启
maskingRule=0
#密文分隔符
encryption.separator=_jm
#******************************** 规则配置信息 ***********************************
#localfile/gateway
encryption.rule-origin=gateway
#localfile/gateway
masking.rule-origin=gateway
#reload config
rule.load-period=30
#gateway config
gateway.protocol=https
gateway.host=172.19.1.167
gateway.port=9005
#0:ry系统,1:masking 系统
getUserType=0
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论