@@ -1014,7 +1014,21 @@ func (h *Handler) execSingle(ctx context.Context, w io.Writer, opt metacmd.Optio
1014
1014
f = h .query
1015
1015
}
1016
1016
// exec
1017
- return f (ctx , w , opt , prefix , sqlstr )
1017
+ start := time .Now ()
1018
+ if err := f (ctx , w , opt , prefix , sqlstr ); err != nil {
1019
+ return err
1020
+ }
1021
+ if h .timing {
1022
+ d := time .Since (start )
1023
+ format := text .TimingDesc
1024
+ v := []interface {}{float64 (d .Microseconds ()) / 1000 }
1025
+ if d > 1 * time .Second {
1026
+ format += " (%v)"
1027
+ v = append (v , d .Round (1 * time .Millisecond ))
1028
+ }
1029
+ h .Print (format , v ... )
1030
+ }
1031
+ return nil
1018
1032
}
1019
1033
1020
1034
// execSet executes a SQL query, setting all returned columns as variables.
@@ -1079,7 +1093,6 @@ func (h *Handler) execExec(ctx context.Context, w io.Writer, _ metacmd.Option, p
1079
1093
1080
1094
// query executes a query against the database.
1081
1095
func (h * Handler ) query (ctx context.Context , w io.Writer , opt metacmd.Option , typ , sqlstr string ) error {
1082
- start := time .Now ()
1083
1096
// run query
1084
1097
rows , err := h .DB ().QueryContext (ctx , sqlstr )
1085
1098
if err != nil {
@@ -1147,16 +1160,6 @@ func (h *Handler) query(ctx context.Context, w io.Writer, opt metacmd.Option, ty
1147
1160
case params ["format" ] == "aligned" :
1148
1161
fmt .Fprintln (w )
1149
1162
}
1150
- if h .timing {
1151
- d := time .Since (start )
1152
- format := text .TimingDesc
1153
- v := []interface {}{float64 (d .Microseconds ()) / 1000 }
1154
- if d > 1 * time .Second {
1155
- format += " (%v)"
1156
- v = append (v , d .Round (1 * time .Millisecond ))
1157
- }
1158
- h .Print (format , v ... )
1159
- }
1160
1163
if pipe != nil {
1161
1164
pipe .Close ()
1162
1165
if cmd != nil {
0 commit comments