()
| 135 | } |
| 136 | |
| 137 | void run() throws SQLException { |
| 138 | final String url = "jdbc:calcite:lex=JAVA;conformance=LENIENT" |
| 139 | + ";model=inline:" + MODEL; |
| 140 | final String help = "Usage: sqlsh [OPTION]... SQL\n" |
| 141 | + "Execute a SQL command\n" |
| 142 | + "\n" |
| 143 | + "Options:\n" |
| 144 | + " -o FORMAT Print output in FORMAT; options are 'spaced' (the " |
| 145 | + "default), 'csv',\n" |
| 146 | + " 'headers', 'json', 'mysql'\n" |
| 147 | + " -h --help Print this help"; |
| 148 | final StringBuilder b = new StringBuilder(); |
| 149 | Format format = Format.SPACED; |
| 150 | try (Enumerator<String> args = |
| 151 | Linq4j.asEnumerable(this.args).enumerator()) { |
| 152 | while (args.moveNext()) { |
| 153 | if (args.current().equals("-o")) { |
| 154 | if (args.moveNext()) { |
| 155 | String formatString = args.current(); |
| 156 | try { |
| 157 | format = Format.valueOf(formatString.toUpperCase(Locale.ROOT)); |
| 158 | } catch (IllegalArgumentException e) { |
| 159 | throw new RuntimeException("unknown format: " + formatString); |
| 160 | } |
| 161 | } else { |
| 162 | throw new RuntimeException("missing format"); |
| 163 | } |
| 164 | } else if (args.current().equals("-h") |
| 165 | || args.current().equals("--help")) { |
| 166 | out.println(help); |
| 167 | return; |
| 168 | } else { |
| 169 | if (b.length() > 0) { |
| 170 | b.append(' '); |
| 171 | } |
| 172 | b.append(args.current()); |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | try (Connection connection = DriverManager.getConnection(url); |
| 177 | Statement s = connection.createStatement(); |
| 178 | Enumerator<String> args = |
| 179 | Linq4j.asEnumerable(this.args).enumerator()) { |
| 180 | final ResultSet r = s.executeQuery(b.toString()); |
| 181 | format.output(out, r); |
| 182 | r.close(); |
| 183 | } finally { |
| 184 | out.flush(); |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | |
| 189 | private static void addView(StringBuilder b, String name, String sql) { |
nothing calls this directly
no test coverage detected