@@ -60,39 +60,35 @@ func (si *SQLite3Interactor) Exec(ctx context.Context, statement string) (int64,
60
60
return si .Repository .Exec (ctx , statement )
61
61
}
62
62
63
- // ExecSQL execute "SELECT/EXPLAIN"query or "INSERT/UPDATE/DELETE" statement
63
+ // ExecSQL executes "SELECT/EXPLAIN" query or "INSERT/UPDATE/DELETE" statement
64
64
func (si * SQLite3Interactor ) ExecSQL (ctx context.Context , statement string ) (* model.Table , int64 , error ) {
65
65
argv := strings .Split (trimWordGaps (statement ), " " )
66
66
67
67
// NOTE: SQLY uses SQLite3. There is some SQL that can be changed from non-support
68
68
// to support in the future. Currently, it is not supported because it is not needed
69
69
// for developer ( == me:) ) use cases.
70
- if si .sql .isDDL (argv [0 ]) {
70
+ switch {
71
+ case si .sql .isDDL (argv [0 ]):
71
72
return nil , 0 , errors .New ("not support data definition language: " + strings .Join (si .sql .ddl , ", " ))
72
- }
73
- if si .sql .isTCL (argv [0 ]) {
73
+ case si .sql .isTCL (argv [0 ]):
74
74
return nil , 0 , errors .New ("not support transaction control language: " + strings .Join (si .sql .tcl , ", " ))
75
- }
76
- if si .sql .isDCL (argv [0 ]) {
75
+ case si .sql .isDCL (argv [0 ]):
77
76
return nil , 0 , errors .New ("not support data control language: " + strings .Join (si .sql .dcl , ", " ))
78
- }
79
- if ! si .sql .isDML (argv [0 ]) {
77
+ case ! si .sql .isDML (argv [0 ]):
80
78
return nil , 0 , errors .New ("this input is not sql query or sqly helper command: " + color .CyanString (statement ))
81
- }
82
-
83
- if si .sql .isSelect (argv [0 ]) || si .sql .isExplain (argv [0 ]) {
79
+ case si .sql .isSelect (argv [0 ]) || si .sql .isExplain (argv [0 ]):
84
80
table , err := si .Query (ctx , statement )
85
81
if err != nil {
86
82
return nil , 0 , fmt .Errorf ("execute query error: %v: %s" , err , color .CyanString (statement ))
87
83
}
88
84
return table , 0 , nil
89
- } else if si .sql .isInsert (argv [0 ]) || si .sql .isUpdate (argv [0 ]) || si .sql .isDelete (argv [0 ]) {
85
+ case si .sql .isInsert (argv [0 ]) || si .sql .isUpdate (argv [0 ]) || si .sql .isDelete (argv [0 ]):
90
86
affectedRows , err := si .Repository .Exec (ctx , statement )
91
87
if err != nil {
92
88
return nil , 0 , fmt .Errorf ("execute statement error: %v: %s" , err , color .CyanString (statement ))
93
89
}
94
90
return nil , affectedRows , nil
95
- } else {
91
+ default :
96
92
return nil , 0 , fmt .Errorf ("%s\n %s: %s\n %s" ,
97
93
color .HiRedString ("*** sqly bug ***" ),
98
94
"please report this log" , color .CyanString (statement ),
0 commit comments