MCPcopy Create free account
hub / github.com/actiontech/dtle / resolveQuery

Method resolveQuery

driver/mysql/binlog/binlog_reader.go:1027–1183  ·  view source on GitHub ↗

schemaTables is the schema.table that the query has invalidated. For unrecognized query, it is nil.

(currentSchema string, sql string,
	skipFunc func(schema string, tableName string) bool)

Source from the content-addressed store, hash-verified

1025
1026// schemaTables is the schema.table that the query has invalidated. For unrecognized query, it is nil.
1027func (b *BinlogReader) resolveQuery(currentSchema string, sql string,
1028 skipFunc func(schema string, tableName string) bool) (result parseQueryResult, err error) {
1029
1030 rewrite := false
1031
1032 result.sql = sql
1033 result.isRecognized = true
1034 result.isSkip = false
1035
1036 if b.lowerCaseTableNames != mysqlconfig.LowerCaseTableNames0 {
1037 rewrite = true
1038 }
1039
1040 stmt, err := parser.New().ParseOneStmt(sql, "", "")
1041 if err != nil {
1042 result.isRecognized = false
1043 return result, nil
1044 }
1045
1046 setSchema := func(schema *string) {
1047 if b.lowerCaseTableNames != mysqlconfig.LowerCaseTableNames0 {
1048 g.LowerString(schema)
1049 }
1050 result.table = common.SchemaTable{Schema: *schema, Table: ""}
1051 }
1052 mayLowerTable := func(tn *ast.TableName) {
1053 if b.lowerCaseTableNames != mysqlconfig.LowerCaseTableNames0 {
1054 tn.Schema = model.NewCIStr(tn.Schema.L)
1055 tn.Name = model.NewCIStr(tn.Name.L)
1056 }
1057 }
1058 setTable := func(tn *ast.TableName, extra bool) {
1059 mayLowerTable(tn)
1060 item := common.SchemaTable{Schema: tn.Schema.String(), Table: tn.Name.String()}
1061 if extra {
1062 result.extraTables = append(result.extraTables, item)
1063 } else {
1064 result.table = item
1065 }
1066 }
1067
1068 switch v := stmt.(type) {
1069 case *ast.CreateDatabaseStmt:
1070 setSchema(&v.Name)
1071 case *ast.DropDatabaseStmt:
1072 setSchema(&v.Name)
1073 case *ast.AlterDatabaseStmt:
1074 setSchema(&v.Name)
1075 case *ast.CreateIndexStmt:
1076 setTable(v.Table, false)
1077 case *ast.DropIndexStmt:
1078 setTable(v.Table, false)
1079 case *ast.TruncateTableStmt:
1080 setTable(v.Table, false)
1081 case *ast.CreateTableStmt:
1082 setTable(v.Table, false)
1083 case *ast.CreateViewStmt:
1084 result.isSkip = true

Callers 2

handleQueryEventMethod · 0.95

Calls 3

LowerStringFunction · 0.92
StringElseFunction · 0.92
StringMethod · 0.45

Tested by 1