| 370 | } |
| 371 | |
| 372 | func printResult(out io.Writer, result *Result, mode DisplayMode, interactive, verbose bool) { |
| 373 | if mode == DisplayModeTable { |
| 374 | table := tablewriter.NewWriter(out) |
| 375 | table.SetAutoFormatHeaders(false) |
| 376 | table.SetHeaderAlignment(tablewriter.ALIGN_LEFT) |
| 377 | table.SetAlignment(tablewriter.ALIGN_LEFT) |
| 378 | table.SetAutoWrapText(false) |
| 379 | |
| 380 | var forceTableRender bool |
| 381 | // This condition is true if statement is SelectStatement or DmlStatement |
| 382 | if verbose && len(result.ColumnTypes) > 0 { |
| 383 | forceTableRender = true |
| 384 | var headers []string |
| 385 | for _, field := range result.ColumnTypes { |
| 386 | typename := formatTypeSimple(field.GetType()) |
| 387 | headers = append(headers, field.GetName()+"\n"+typename) |
| 388 | } |
| 389 | table.SetHeader(headers) |
| 390 | } else { |
| 391 | table.SetHeader(result.ColumnNames) |
| 392 | } |
| 393 | |
| 394 | for _, row := range result.Rows { |
| 395 | table.Append(row.Columns) |
| 396 | } |
| 397 | |
| 398 | if forceTableRender || len(result.Rows) > 0 { |
| 399 | table.Render() |
| 400 | } |
| 401 | } else if mode == DisplayModeVertical { |
| 402 | max := 0 |
| 403 | for _, columnName := range result.ColumnNames { |
| 404 | if len(columnName) > max { |
| 405 | max = len(columnName) |
| 406 | } |
| 407 | } |
| 408 | format := fmt.Sprintf("%%%ds: %%s\n", max) // for align right |
| 409 | for i, row := range result.Rows { |
| 410 | fmt.Fprintf(out, "*************************** %d. row ***************************\n", i+1) |
| 411 | for j, column := range row.Columns { |
| 412 | fmt.Fprintf(out, format, result.ColumnNames[j], column) |
| 413 | } |
| 414 | } |
| 415 | } else if mode == DisplayModeTab { |
| 416 | if len(result.ColumnNames) > 0 { |
| 417 | fmt.Fprintln(out, strings.Join(result.ColumnNames, "\t")) |
| 418 | for _, row := range result.Rows { |
| 419 | fmt.Fprintln(out, strings.Join(row.Columns, "\t")) |
| 420 | } |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | if len(result.Predicates) > 0 { |
| 425 | fmt.Fprintln(out, "Predicates(identified by ID):") |
| 426 | for _, s := range result.Predicates { |
| 427 | fmt.Fprintf(out, " %s\n", s) |
| 428 | } |
| 429 | fmt.Fprintln(out) |