import net.jaekl.squelch.db.MySqlDriver;
import net.jaekl.squelch.db.OracleDriver;
import net.jaekl.squelch.db.PostgresqlDriver;
+import net.jaekl.squelch.stmt.Describe;
import net.jaekl.squelch.stmt.Select;
import net.jaekl.squelch.stmt.Stmt;
import net.jaekl.squelch.util.ConsoleInput;
new PostgresqlDriver()
};
private static final Stmt[] READ_ONLY_STATEMENTS = {
+ new Describe(),
new Select()
};
return false;
}
- Connection getConnection() throws ClassNotFoundException, SQLException, SquelchException
+ Connection getConnection(DbDriver driver, String jdbcUrl)
+ throws ClassNotFoundException, SQLException, SquelchException
{
- String jdbcUrl = m_args.getUrl();
- DbDriver driver = getDriverFor(jdbcUrl);
-
return driver.connect(jdbcUrl, m_args.getUser(), m_args.getPass());
}
void pumpLines(PrintWriter pw, ConsoleInput ci) throws IOException, ClassNotFoundException, SQLException, SquelchException
{
String line = null;
- try (Connection conn = getConnection())
+ String jdbcUrl = m_args.getUrl();
+ DbDriver driver = getDriverFor(jdbcUrl);
+
+ try (Connection conn = getConnection(driver, jdbcUrl))
{
while (true) {
boolean processed = false;
for (Stmt statement : m_statements) {
if (statement.handles(line)) {
- statement.exec(conn, pw, line);
+ try {
+ statement.exec(driver, conn, pw, line);
+ }
+ catch (SQLException exc) {
+ exc.printStackTrace(pw);
+ }
processed = true;
break;
}
// Unrecognized command
// TODO: add a string table, and a natural-language error message.
pw.println("??? \"" + line + "\"");
- pw.flush();
}
+ pw.flush();
}
}
}