Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于嵌套子查询的脱敏功能 #429

Closed
unknowissue opened this issue Feb 24, 2022 · 2 comments
Closed

关于嵌套子查询的脱敏功能 #429

unknowissue opened this issue Feb 24, 2022 · 2 comments

Comments

@unknowissue
Copy link

unknowissue commented Feb 24, 2022

描述您想要的功能:

想问下 select * from (select * from users ) t; 可以辛苦实现脱敏么?目前的返回结果是

[{"index":0,"field":"id","type":"","table":"t","schema":"","alias":"id"},
{"index":1,"field":"phone","type":"","table":"t","schema":"","alias":"phone"},
{"index":2,"field":"email","type":"","table":"t","schema":"","alias":"email"},
{"index":3,"field":"create_time","type":"","table":"t","schema":"","alias":"create_time"}] 

测试调用

#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import pymysql
import prettytable as pt
tb = pt.PrettyTable()
sql = '''/*--user=xx;--password=xxxxx==;--host=xxxx;--port=3308;--masking=1;*/
                          inception_magic_start;
                          use `db1`;
                          select * from  (select *  from users b ) t limit 100 ;
                          inception_magic_commit;'''
conn = pymysql.connect(host='127.0.0.1', user='', passwd='',db='', port=4000, charset="utf8mb4")
cur = conn.cursor()
ret = cur.execute(sql)
result = cur.fetchall()
print(result)
cur.close()
conn.close()
tb.field_names = [i[0] for i in cur.description]
for row in result:
    tb.add_row(row)
print(tb)

我看 query-print 也没有很好的打印语法树?

#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import pymysql
import prettytable as pt
tb = pt.PrettyTable()
sql = '''/*--user=xxx;--password=xxxx==;--host=xxxx;--port=3308;--enable-query-print;*/
                          inception_magic_start;
                          use `db1`;
                          select * from  (select *  from users b ) t limit 100 ;
                          inception_magic_commit;'''
conn = pymysql.connect(host='127.0.0.1', user='', passwd='',db='', port=4000, charset="utf8mb4")
cur = conn.cursor()
ret = cur.execute(sql)
result = cur.fetchall()
print(result)
cur.close()
conn.close()
tb.field_names = [i[0] for i in cur.description]
for row in result:
    tb.add_row(row)
print(tb)

结果json

{
	"text": "                          select * from  (select *  from users b ) t limit 100 ",
	"resultFields": null,
	"SQLBigResult": false,
	"SQLBufferResult": false,
	"SQLCache": true,
	"SQLSmallResult": false,
	"CalcFoundRows": false,
	"StraightJoin": false,
	"Priority": 0,
	"Distinct": false,
	"From": {
		"text": "",
		"TableRefs": {
			"text": "",
			"resultFields": null,
			"Left": {
				"text": "",
				"Source": {
					"text": "",
					"resultFields": null,
					"SQLBigResult": false,
					"SQLBufferResult": false,
					"SQLCache": true,
					"SQLSmallResult": false,
					"CalcFoundRows": false,
					"StraightJoin": false,
					"Priority": 0,
					"Distinct": false,
					"From": {
						"text": "",
						"TableRefs": {
							"text": "",
							"resultFields": null,
							"Left": {
								"text": "",
								"Source": {
									"text": "",
									"resultFields": null,
									"Schema": {
										"O": "",
										"L": ""
									},
									"Name": {
										"O": "users",
										"L": "users"
									},
									"DBInfo": null,
									"TableInfo": null,
									"IndexHints": null,
									"PartitionNames": null
								},
								"AsName": {
									"O": "b",
									"L": "b"
								}
							},
							"Right": null,
							"Tp": 0,
							"On": null,
							"Using": null,
							"NaturalJoin": false,
							"StraightJoin": false
						}
					},
					"Where": null,
					"Fields": {
						"text": "",
						"Fields": [{
							"text": "",
							"Offset": 49,
							"WildCard": {
								"text": "",
								"Table": {
									"O": "",
									"L": ""
								},
								"Schema": {
									"O": "",
									"L": ""
								}
							},
							"Expr": null,
							"AsName": {
								"O": "",
								"L": ""
							},
							"Auxiliary": false
						}]
					},
					"GroupBy": null,
					"Having": null,
					"WindowSpecs": null,
					"OrderBy": null,
					"Limit": null,
					"LockTp": 0,
					"TableHints": null,
					"IsAfterUnionDistinct": false,
					"IsInBraces": false,
					"QueryBlockOffset": 0
				},
				"AsName": {
					"O": "t",
					"L": "t"
				}
			},
			"Right": null,
			"Tp": 0,
			"On": null,
			"Using": null,
			"NaturalJoin": false,
			"StraightJoin": false
		}
	},
	"Where": null,
	"Fields": {
		"text": "",
		"Fields": [{
			"text": "",
			"Offset": 33,
			"WildCard": {
				"text": "",
				"Table": {
					"O": "",
					"L": ""
				},
				"Schema": {
					"O": "",
					"L": ""
				}
			},
			"Expr": null,
			"AsName": {
				"O": "",
				"L": ""
			},
			"Auxiliary": false
		}]
	},
	"GroupBy": null,
	"Having": null,
	"WindowSpecs": null,
	"OrderBy": null,
	"Limit": {
		"text": "",
		"Count": {
			"text": "",
			"k": 2,
			"collation": 0,
			"decimal": 0,
			"length": 0,
			"i": 100,
			"b": null,
			"x": null,
			"Type": {
				"Tp": 8,
				"Flag": 160,
				"Flen": 3,
				"Decimal": 0,
				"Charset": "binary",
				"Collate": "binary",
				"Elems": null
			},
			"flag": 0,
			"projectionOffset": -1
		},
		"Offset": null
	},
	"LockTp": 0,
	"TableHints": null,
	"IsAfterUnionDistinct": false,
	"IsInBraces": false,
	"QueryBlockOffset": 0
}

描述您考虑过的解决/替代方案:

可参考文档,资料,引用等:

@hanchuanchuan
Copy link
Owner

已更新版本 v1.2.5-29 ,请升级后重试。

@unknowissue
Copy link
Author

可以了,非常感谢!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants