| 497 | } |
| 498 | |
| 499 | func buildCommands(input string) ([]*command, error) { |
| 500 | var cmds []*command |
| 501 | var pendingDdls []string |
| 502 | for _, separated := range separateInput(input) { |
| 503 | // Ignore the last empty statement |
| 504 | if separated.delim == delimiterUndefined && separated.statementWithoutComments == "" { |
| 505 | continue |
| 506 | } |
| 507 | |
| 508 | stmt, err := BuildStatementWithComments(separated.statementWithoutComments, separated.statement) |
| 509 | if err != nil { |
| 510 | return nil, err |
| 511 | } |
| 512 | if ddl, ok := stmt.(*DdlStatement); ok { |
| 513 | pendingDdls = append(pendingDdls, ddl.Ddl) |
| 514 | continue |
| 515 | } |
| 516 | |
| 517 | // Flush pending DDLs |
| 518 | if len(pendingDdls) > 0 { |
| 519 | cmds = append(cmds, &command{&BulkDdlStatement{pendingDdls}, false}) |
| 520 | pendingDdls = nil |
| 521 | } |
| 522 | |
| 523 | cmds = append(cmds, &command{stmt, separated.delim == delimiterVertical}) |
| 524 | } |
| 525 | |
| 526 | // Flush pending DDLs |
| 527 | if len(pendingDdls) > 0 { |
| 528 | cmds = append(cmds, &command{&BulkDdlStatement{pendingDdls}, false}) |
| 529 | } |
| 530 | |
| 531 | return cmds, nil |
| 532 | } |
| 533 | |
| 534 | func confirm(out io.Writer, msg string) bool { |
| 535 | fmt.Fprintf(out, "%s [yes/no] ", msg) |