1
1
package cli
2
2
3
3
import (
4
+ "database/sql"
4
5
"fmt"
5
6
6
7
"github.com/neilotoole/sq/cli/run"
@@ -64,7 +65,8 @@ func newTblCopyCmd() *cobra.Command {
64
65
}
65
66
66
67
func execTblCopy (cmd * cobra.Command , args []string ) error {
67
- ru := run .FromContext (cmd .Context ())
68
+ ctx := cmd .Context ()
69
+ ru := run .FromContext (ctx )
68
70
if len (args ) == 0 || len (args ) > 2 {
69
71
return errz .New ("one or two table args required" )
70
72
}
@@ -121,12 +123,17 @@ func execTblCopy(cmd *cobra.Command, args []string) error {
121
123
}
122
124
123
125
var dbase driver.Database
124
- dbase , err = ru .Databases .Open (cmd .Context (), tblHandles [0 ].src )
126
+ dbase , err = ru .Databases .Open (ctx , tblHandles [0 ].src )
127
+ if err != nil {
128
+ return err
129
+ }
130
+
131
+ db , err := dbase .DB (ctx )
125
132
if err != nil {
126
133
return err
127
134
}
128
135
129
- copied , err := sqlDrvr .CopyTable (cmd . Context (), dbase . DB () , tblHandles [0 ].tbl , tblHandles [1 ].tbl , copyData )
136
+ copied , err := sqlDrvr .CopyTable (ctx , db , tblHandles [0 ].tbl , tblHandles [1 ].tbl , copyData )
130
137
if err != nil {
131
138
return errz .Wrapf (err , "failed tbl copy %s.%s --> %s.%s" ,
132
139
tblHandles [0 ].handle , tblHandles [0 ].tbl ,
@@ -227,7 +234,8 @@ only applies to SQL sources.`,
227
234
}
228
235
229
236
func execTblDrop (cmd * cobra.Command , args []string ) (err error ) {
230
- ru := run .FromContext (cmd .Context ())
237
+ ctx := cmd .Context ()
238
+ ru := run .FromContext (ctx )
231
239
var tblHandles []tblHandle
232
240
tblHandles , err = parseTableHandleArgs (ru .DriverRegistry , ru .Config .Collection , args )
233
241
if err != nil {
@@ -245,12 +253,16 @@ func execTblDrop(cmd *cobra.Command, args []string) (err error) {
245
253
}
246
254
247
255
var dbase driver.Database
248
- dbase , err = ru .Databases .Open (cmd .Context (), tblH .src )
249
- if err != nil {
256
+ if dbase , err = ru .Databases .Open (ctx , tblH .src ); err != nil {
250
257
return err
251
258
}
252
- err = sqlDrvr .DropTable (cmd .Context (), dbase .DB (), tblH .tbl , false )
253
- if err != nil {
259
+
260
+ var db * sql.DB
261
+ if db , err = dbase .DB (ctx ); err != nil {
262
+ return err
263
+ }
264
+
265
+ if err = sqlDrvr .DropTable (cmd .Context (), db , tblH .tbl , false ); err != nil {
254
266
return err
255
267
}
256
268
0 commit comments