@@ -50,7 +50,6 @@ func (tf *TmysqlParseFile) DoParseRelationDbs(version string) (createDbs, relati
50
50
}
51
51
logger .Info ("all sqlfiles download ok ~" )
52
52
alreadExecutedSqlfileChan := make (chan string , len (tf .Param .FileNames ))
53
-
54
53
go func () {
55
54
if err = tf .Execute (alreadExecutedSqlfileChan , version ); err != nil {
56
55
logger .Error ("failed to execute tmysqlparse: %s" , err .Error ())
@@ -168,40 +167,41 @@ func (t *TmysqlParse) analyzeRelationDbs(inputfileName, mysqlVersion string) (
168
167
logger .Error ("json unmasrshal line:%s failed %s" , string (line ), err .Error ())
169
168
return nil , nil , nil , false , err
170
169
}
171
- // 判断是否有语法错误
170
+ // ErrorCode !=0 就是语法错误
172
171
if res .ErrorCode != 0 {
173
172
return nil , nil , nil , false , fmt .Errorf ("%s" , res .ErrorMsg )
174
173
}
175
- if lo .IsNotEmpty (res .Command ) {
176
- if res .Command == SQLTypeCreateTable {
177
- var c CreateTableResult
178
- if err = json .Unmarshal (line , & c ); err != nil {
179
- logger .Error ("json unmasrshal line:%s failed %s" , string (line ), err .Error ())
180
- return nil , nil , nil , false , err
181
- }
182
- // 需要排除create table like
183
- if c .IsCreateTableLike || c .IsCreateTableSelect {
184
- return nil , nil , allCommandType , true , nil
185
- }
186
- } else {
187
- allCommandType = append (allCommandType , res .Command )
188
- }
189
- }
190
- if slices .Contains ([]string {SQLTypeCreateProcedure , SQLTypeCreateFunction , SQLTypeCreateView , SQLTypeCreateTrigger ,
191
- SQLTypeInsertSelect , SQLTypeRelaceSelect },
192
- res .Command ) {
193
- return nil , nil , allCommandType , true , nil
194
- }
195
- if lo .IsEmpty (res .DbName ) {
174
+ if lo .IsEmpty (res .Command ) {
196
175
continue
197
176
}
177
+ if lo .IsNotEmpty (res .DbName ) {
178
+ relationDbs = append (relationDbs , res .DbName )
179
+ }
198
180
// create db not need dump db
199
181
if slices .Contains ([]string {SQLTypeCreateDb }, res .Command ) {
200
182
createDbs = append (createDbs , res .DbName )
201
183
continue
202
184
}
203
- relationDbs = append (relationDbs , res .DbName )
204
-
185
+ if res .HasSubQuery {
186
+ return nil , relationDbs , allCommandType , true , nil
187
+ }
188
+ if slices .Contains ([]string {SQLTypeCreateProcedure , SQLTypeCreateFunction , SQLTypeCreateView , SQLTypeCreateTrigger ,
189
+ SQLTypeInsertSelect , SQLTypeRelaceSelect },
190
+ res .Command ) {
191
+ return nil , relationDbs , allCommandType , true , nil
192
+ }
193
+ if res .Command == SQLTypeCreateTable {
194
+ var c CreateTableResult
195
+ if err = json .Unmarshal (line , & c ); err != nil {
196
+ logger .Error ("json unmasrshal line:%s failed %s" , string (line ), err .Error ())
197
+ return nil , nil , nil , false , err
198
+ }
199
+ // 需要排除create table like
200
+ if c .IsCreateTableLike || c .IsCreateTableSelect {
201
+ return nil , relationDbs , allCommandType , true , nil
202
+ }
203
+ }
204
+ allCommandType = append (allCommandType , res .Command )
205
205
}
206
206
return createDbs , relationDbs , allCommandType , false , nil
207
207
}
0 commit comments