| 591 | protected boolean interactive = true; |
| 592 | |
| 593 | protected void start(String[] argv) throws IOException { |
| 594 | // first add tables to database |
| 595 | Database.getCatalog().loadSchema(argv[0]); |
| 596 | TableStats.computeStatistics(); |
| 597 | |
| 598 | String queryFile = null; |
| 599 | |
| 600 | if (argv.length > 1) { |
| 601 | for (int i = 1; i < argv.length; i++) { |
| 602 | if (argv[i].equals("-explain")) { |
| 603 | explain = true; |
| 604 | System.out.println("Explain mode enabled."); |
| 605 | } else if (argv[i].equals("-f")) { |
| 606 | interactive = false; |
| 607 | if (i++ == argv.length) { |
| 608 | System.out.println("Expected file name after -f\n" |
| 609 | + usage); |
| 610 | System.exit(0); |
| 611 | } |
| 612 | queryFile = argv[i]; |
| 613 | |
| 614 | } else { |
| 615 | System.out.println("Unknown argument " + argv[i] + "\n " |
| 616 | + usage); |
| 617 | } |
| 618 | } |
| 619 | } |
| 620 | if (!interactive) { |
| 621 | try { |
| 622 | // curtrans = new Transaction(); |
| 623 | // curtrans.start(); |
| 624 | try { |
| 625 | Thread.sleep(SLEEP_TIME); |
| 626 | } catch (InterruptedException e) { |
| 627 | e.printStackTrace(); |
| 628 | } |
| 629 | |
| 630 | long startTime = System.currentTimeMillis(); |
| 631 | processNextStatement(new FileInputStream(queryFile)); |
| 632 | long time = System.currentTimeMillis() - startTime; |
| 633 | System.out.printf("----------------\n%.2f seconds\n\n", |
| 634 | ((double) time / 1000.0)); |
| 635 | System.out.println("Press Enter to exit"); |
| 636 | System.in.read(); |
| 637 | this.shutdown(); |
| 638 | } catch (FileNotFoundException e) { |
| 639 | System.out.println("Unable to find query file" + queryFile); |
| 640 | e.printStackTrace(); |
| 641 | } |
| 642 | } else { // no query file, run interactive prompt |
| 643 | ConsoleReader reader = new ConsoleReader(); |
| 644 | |
| 645 | // Add really stupid tab completion for simple SQL |
| 646 | ArgumentCompletor completor = new ArgumentCompletor( |
| 647 | new SimpleCompletor(SQL_COMMANDS)); |
| 648 | completor.setStrict(false); // match at any position |
| 649 | reader.addCompletor(completor); |
| 650 | |