Skip to content

Commit

Permalink
Merge pull request #474 from liquidata-inc/zachmu/batch-bug
Browse files Browse the repository at this point in the history
Fixed bug caused by overzealous refactoring
  • Loading branch information
zachmu authored Mar 18, 2020
2 parents 47165da + 0874fd1 commit ed0666e
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions go/cmd/dolt/commands/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,14 @@ func (cmd SqlCmd) Exec(ctx context.Context, commandStr string, args []string, dE

_, forceBatchMode := apr.GetValue(batchFlag)

se, err := newSqlEngine(ctx, dEnv, dsqle.NewDatabase("dolt", root, dEnv.DoltDB, dEnv.RepoState), format)
if err != nil {
return HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage)
}

// run a single command and exit
if query, ok := apr.GetValue(queryFlag); !forceBatchMode && ok {

se, err := newSqlEngine(ctx, dEnv, dsqle.NewDatabase("dolt", root, dEnv.DoltDB, dEnv.RepoState), format)
if err != nil {
return HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage)
}

sqlSch, rowIter, err := processQuery(ctx, query, se)
if err != nil {
return HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage)
Expand All @@ -193,6 +193,8 @@ func (cmd SqlCmd) Exec(ctx context.Context, commandStr string, args []string, dE
return 0
}

var se *sqlEngine

// Run in either batch mode for piped input, or shell mode for interactive
fi, err := os.Stdin.Stat()
// Windows has a bug where STDIN can't be statted in some cases, see https://github.com/golang/go/issues/33570
Expand All @@ -206,6 +208,11 @@ func (cmd SqlCmd) Exec(ctx context.Context, commandStr string, args []string, dE
batchInput = strings.NewReader(query)
}

se, err = newSqlEngine(ctx, dEnv, dsqle.NewBatchedDatabase("dolt", root, dEnv.DoltDB, dEnv.RepoState), format)
if err != nil {
return HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage)
}

err = runBatchMode(ctx, se, batchInput)
if err != nil {
_, _ = fmt.Fprintf(cli.CliErr, "Error processing batch: %s\n", err.Error())
Expand All @@ -214,6 +221,11 @@ func (cmd SqlCmd) Exec(ctx context.Context, commandStr string, args []string, dE
} else if err != nil {
HandleVErrAndExitCode(errhand.BuildDError("Couldn't stat STDIN. This is a bug.").Build(), usage)
} else {
se, err = newSqlEngine(ctx, dEnv, dsqle.NewDatabase("dolt", root, dEnv.DoltDB, dEnv.RepoState), format)
if err != nil {
return HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage)
}

err = runShell(ctx, se, dEnv)
if err != nil {
return HandleVErrAndExitCode(errhand.BuildDError("unable to start shell").AddCause(err).Build(), usage)
Expand Down

0 comments on commit ed0666e

Please sign in to comment.