RunSQLProgramAndPrintResult execute SQL statement and print the logs and select result TODO(yancey1989): more meanful argument isTerminal and it2Check
(sqlStmt string, modelDir string, session *pb.Session, table tablewriter.TableWriter, isTerminal, it2Check bool)
| 35 | // RunSQLProgramAndPrintResult execute SQL statement and print the logs and select result |
| 36 | // TODO(yancey1989): more meanful argument isTerminal and it2Check |
| 37 | func RunSQLProgramAndPrintResult(sqlStmt string, modelDir string, session *pb.Session, table tablewriter.TableWriter, isTerminal, it2Check bool) error { |
| 38 | startTime := time.Now().UnixNano() |
| 39 | defer log.Printf("(%.2f sec)\n", float64(time.Now().UnixNano()-startTime)/1e9) |
| 40 | // note(yancey1989): if the input sql program contain `\n`, bufio.Text() would deal with |
| 41 | // it as a text string with two character instead of one character "\n". |
| 42 | // readStmt(bufio.Scanner) should deal with that by replacing `\n` with '\n' |
| 43 | // TODO(yancey1989): finding a normative way to deal with that. |
| 44 | replacer := strings.NewReplacer(`\n`, "\n", `\t`, "\t", `\r`, "\r") |
| 45 | sqlStmt = replacer.Replace(sqlStmt) |
| 46 | |
| 47 | log.SetFlags(0) |
| 48 | stream := sql.RunSQLProgram(sqlStmt, modelDir, session) |
| 49 | for res := range stream.ReadAll() { |
| 50 | if e := Render(res, table, isTerminal, it2Check); e != nil { |
| 51 | return e |
| 52 | } |
| 53 | } |
| 54 | return table.Flush() |
| 55 | } |
| 56 | |
| 57 | // Render output according to calling environment |
| 58 | func Render(rsp interface{}, table tablewriter.TableWriter, isTerminal, it2Check bool) error { |