Add "Describe" command, with support for describing both (a) specific table(s) and...
[squelch.git] / src / main / java / net / jaekl / squelch / stmt / Select.java
index f34b8c9392014b4e210972f3f1dae4b5be10befe..c5f785e5a3d6acd651bc30b3822f362a255f5f30 100644 (file)
@@ -8,6 +8,8 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.Locale;
 
+import net.jaekl.squelch.db.DbDriver;
+
 public class Select extends Query {
 
        @Override
@@ -21,11 +23,17 @@ public class Select extends Query {
        }
 
        @Override
-       public int exec(Connection conn, PrintWriter pw, String line) throws IOException, SQLException 
+       public int exec(DbDriver driver, Connection conn, PrintWriter pw, String line) throws IOException, SQLException 
        {
                int rowCount = 0;
                
-               try (PreparedStatement ps = conn.prepareStatement(line)) 
+               // If there's a ';' on the end of this line, remove it.
+               String trimmed = line.trim();
+               if (trimmed.endsWith(";")) {
+                       trimmed = trimmed.substring(0, trimmed.length() - 1);
+               }
+               
+               try (PreparedStatement ps = conn.prepareStatement(trimmed)) 
                {
                        try (ResultSet rs = ps.executeQuery()) 
                        {
@@ -38,7 +46,8 @@ public class Select extends Query {
        private int printFormatted(PrintWriter pw, ResultSet rs) throws IOException, SQLException
        {
                TabularResultSet trs = new TabularResultSet(rs);
-               int rowCount = trs.printTable(pw);
+               // TODO:  StringTable i18n
+               int rowCount = trs.printTable(pw, "No rows returned.");
                pw.flush();
                
                return rowCount;