@@ -14,7 +14,7 @@ import (
14
14
"github.com/actiontech/sqle/sqle/utils"
15
15
)
16
16
17
- func GetSQLFromPath (pathName string , skipErrorQuery , skipErrorFile bool , fileSuffix string ) (allSQL []driverV2.Node , err error ) {
17
+ func GetSQLFromPath (pathName string , skipErrorQuery , skipErrorFile bool , fileSuffix string , showFileContent bool ) (allSQL []driverV2.Node , err error ) {
18
18
if ! path .IsAbs (pathName ) {
19
19
pwd , err := os .Getwd ()
20
20
if err != nil {
@@ -32,9 +32,9 @@ func GetSQLFromPath(pathName string, skipErrorQuery, skipErrorFile bool, fileSuf
32
32
pathJoin := path .Join (pathName , fi .Name ())
33
33
34
34
if fi .IsDir () {
35
- sqlList , err = GetSQLFromPath (pathJoin , skipErrorQuery , skipErrorFile , fileSuffix )
35
+ sqlList , err = GetSQLFromPath (pathJoin , skipErrorQuery , skipErrorFile , fileSuffix , showFileContent )
36
36
} else if strings .HasSuffix (fi .Name (), fileSuffix ) {
37
- sqlList , err = GetSQLFromFile (pathJoin , skipErrorQuery , fileSuffix )
37
+ sqlList , err = GetSQLFromFile (pathJoin , skipErrorQuery , fileSuffix , showFileContent )
38
38
}
39
39
40
40
if err != nil {
@@ -49,7 +49,7 @@ func GetSQLFromPath(pathName string, skipErrorQuery, skipErrorFile bool, fileSuf
49
49
return allSQL , err
50
50
}
51
51
52
- func GetSQLFromFile (file string , skipErrorQuery bool , fileSuffix string ) (r []driverV2.Node , err error ) {
52
+ func GetSQLFromFile (file string , skipErrorQuery bool , fileSuffix string , showFileContent bool ) (r []driverV2.Node , err error ) {
53
53
content , err := ReadFileContent (file )
54
54
if err != nil {
55
55
return nil , err
@@ -64,18 +64,27 @@ func GetSQLFromFile(file string, skipErrorQuery bool, fileSuffix string) (r []dr
64
64
sqls , err = mybatisParser .ParseXMLQuery (content , mybatisParser .RestoreOriginSql )
65
65
}
66
66
if err != nil {
67
+ if showFileContent {
68
+ fmt .Printf ("failed to parse xml file content: %s" , content )
69
+ }
67
70
return nil , err
68
71
}
69
72
for _ , sql := range sqls {
70
73
n , err := Parse (context .TODO (), sql )
71
74
if err != nil {
75
+ if showFileContent {
76
+ fmt .Printf ("failed to parse xml file content: %s" , content )
77
+ }
72
78
return nil , err
73
79
}
74
80
r = append (r , n ... )
75
81
}
76
82
case utils .SQLFileSuffix :
77
83
n , err := Parse (context .TODO (), content )
78
84
if err != nil {
85
+ if showFileContent {
86
+ fmt .Printf ("failed to parse sql file content: %s" , content )
87
+ }
79
88
return nil , err
80
89
}
81
90
r = append (r , n ... )
0 commit comments