MCPcopy Index your code
hub / github.com/apache/calcite / run

Method run

plus/src/main/java/org/apache/calcite/adapter/os/SqlShell.java:137–186  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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) {

Callers

nothing calls this directly

Calls 15

asEnumerableMethod · 0.95
outputMethod · 0.95
flushMethod · 0.80
enumeratorMethod · 0.65
moveNextMethod · 0.65
equalsMethod · 0.65
currentMethod · 0.65
appendMethod · 0.65
getConnectionMethod · 0.65
executeQueryMethod · 0.65
toStringMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected