Skip to content

Instantly share code, notes, and snippets.

@tbk303
Created December 30, 2010 13:59
Show Gist options
  • Save tbk303/759814 to your computer and use it in GitHub Desktop.
Save tbk303/759814 to your computer and use it in GitHub Desktop.
Multiple result set support
diff -Naur ./src/henplus/commands/SQLCommand.java ../henplus-0.9.8-mresult/src/henplus/commands/SQLCommand.java
--- ./src/henplus/commands/SQLCommand.java 2009-05-02 00:46:51.000000000 +1000
+++ ../henplus-0.9.8-mresult/src/henplus/commands/SQLCommand.java 2010-09-09 16:19:00.056898424 +1000
@@ -12,10 +12,10 @@
import henplus.PropertyRegistry;
import henplus.SQLSession;
import henplus.SigIntHandler;
-import henplus.property.PropertyHolder;
import henplus.property.BooleanPropertyHolder;
-import henplus.view.util.NameCompleter;
+import henplus.property.PropertyHolder;
import henplus.view.util.CancelWriter;
+import henplus.view.util.NameCompleter;
import java.sql.ResultSet;
import java.sql.Statement;
@@ -39,6 +39,7 @@
/**
* returns the command-strings this command can handle.
*/
+
public String[] getCommandList() {
return new String[] {
// provide tab-completion at least for these command starts..
@@ -92,6 +93,7 @@
* don't show the commands available in the toplevel
* command completion list ..
*/
+
public boolean participateInCommandCompletion() { return false; }
/**
@@ -103,6 +105,7 @@
* kind of statements complete with a single slash ('/') at the
* beginning of a line.
*/
+
public boolean isComplete(String command) {
command = command.toUpperCase(); // fixme: expensive.
if (command.startsWith("COMMIT")
@@ -168,6 +171,7 @@
*/
private final class CurrentStatementCancelTarget
implements StatementCanceller.CancelTarget {
+
public void cancelRunningStatement() {
try {
HenPlus.msg().println("cancel statement...");
@@ -200,6 +204,7 @@
/**
* execute the command given.
*/
+
public int execute(SQLSession session, String cmd, String param) {
String command = cmd + " " + param;
//boolean background = false;
@@ -214,7 +219,7 @@
// background = true;
// }
- final long startTime = System.currentTimeMillis();
+ long startTime = System.currentTimeMillis();
long lapTime = -1;
long execTime = -1;
ResultSet rset = null;
@@ -242,16 +247,17 @@
_statementCanceller.arm();
_longRunningDisplay.arm();
- final boolean hasResultSet = _stmt.execute(command);
+ _stmt.execute(command);
_longRunningDisplay.disarm();
if (!_running) {
HenPlus.msg().println("cancelled");
return SUCCESS;
}
-
- if (hasResultSet) {
- rset = _stmt.getResultSet();
+ rset = _stmt.getResultSet();
+ boolean moreResults = true;
+ while(moreResults) {
+ if (rset != null) {
ResultSetRenderer renderer;
renderer = new ResultSetRenderer(rset,
getColumnDelimiter(),
@@ -294,6 +300,15 @@
TimeRenderer.printTime(execTime, HenPlus.msg());
}
session.println(")");
+
+ // check for more results
+ moreResults = ! ((_stmt.getMoreResults() == false) && (_stmt.getUpdateCount() == -1));
+ if (moreResults) {
+ rset = _stmt.getResultSet();
+ startTime = System.currentTimeMillis();
+ session.println("");
+ }
+ }
}
// be smart and retrigger hashing of the tablenames.
@@ -333,6 +348,7 @@
// very simple completer: try to determine wether we can complete a
// table name. that is: if some keyword has been found before, switch to
// table-completer-mode :-)
+
public Iterator complete(CommandDispatcher disp,
String partialCommand, final String lastWord)
{
@@ -496,10 +512,12 @@
return result;
}
+
public void shutdown() {
_statementCanceller.stopThread();
}
+
public String getSynopsis(String cmd) {
cmd = cmd.toLowerCase();
String syn = null;
@@ -523,6 +541,7 @@
return syn;
}
+
public String getLongDescription(String cmd) {
String dsc;
dsc="\t'" + cmd + "': this is not a build-in command, so would be\n"
@@ -571,19 +590,23 @@
super(SQLCommand.this.getColumnDelimiter());
}
+
protected String propertyChanged(String newValue) {
SQLCommand.this.setColumnDelimiter(newValue);
return newValue;
}
+
public String getShortDescription() {
return "modify column separator in query results";
}
+
public String getDefaultValue() {
return "|";
}
+
public String getLongDescription() {
String dsc;
dsc= "\tSet another string that is used to separate columns in\n"
@@ -598,6 +621,7 @@
super(String.valueOf(SQLCommand.this.getRowLimit()));
}
+
protected String propertyChanged(String newValue) throws Exception {
newValue = newValue.trim();
int newIntValue;
@@ -615,10 +639,12 @@
return newValue;
}
+
public String getDefaultValue() {
return "2000";
}
+
public String getShortDescription() {
return "set the maximum number of rows printed";
}
@@ -630,10 +656,12 @@
super(true);
}
+
public void booleanPropertyChanged(boolean value){
setShowHeader( value );
}
+
public String getDefaultValue() {
return "on";
}
@@ -641,6 +669,7 @@
/**
* return a short descriptive string.
*/
+
public String getShortDescription() {
return "switches if header in selected tables should be shown";
}
@@ -652,10 +681,12 @@
super(true);
}
+
public void booleanPropertyChanged(boolean value){
setShowFooter( value );
}
+
public String getDefaultValue() {
return "on";
}
@@ -663,6 +694,7 @@
/**
* return a short descriptive string.
*/
+
public String getShortDescription() {
return "switches if footer in selected tables should be shown";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment