X-Git-Url: http://jaekl.net/gitweb/?p=squelch.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fjaekl%2Fsquelch%2FSquelch.java;h=848ede7db05c9a5d88c783f66bd250a7c4211e55;hp=88515e0bd6502b11ed87f9429bdc573991478ebf;hb=5c97ab69edb44c0f1a7dc416ffaf1b934f7a3d7d;hpb=dde7f6828b7e2fc479d2285754e4a150be7958a5 diff --git a/src/main/java/net/jaekl/squelch/Squelch.java b/src/main/java/net/jaekl/squelch/Squelch.java index 88515e0..848ede7 100644 --- a/src/main/java/net/jaekl/squelch/Squelch.java +++ b/src/main/java/net/jaekl/squelch/Squelch.java @@ -11,6 +11,7 @@ import net.jaekl.squelch.db.MsSqlDriver; 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; @@ -26,6 +27,7 @@ public class Squelch { new PostgresqlDriver() }; private static final Stmt[] READ_ONLY_STATEMENTS = { + new Describe(), new Select() }; @@ -76,11 +78,9 @@ public class Squelch { 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()); } @@ -97,7 +97,10 @@ public class Squelch { 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; @@ -105,7 +108,12 @@ public class Squelch { 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; } @@ -118,8 +126,8 @@ public class Squelch { // Unrecognized command // TODO: add a string table, and a natural-language error message. pw.println("??? \"" + line + "\""); - pw.flush(); } + pw.flush(); } } }