|
From: SVN by r. <sv...@ca...> - 2007-09-28 12:53:11
|
Author: rotman
Date: 2007-09-28 14:53:04 +0200 (Fri, 28 Sep 2007)
New Revision: 154
Modified:
src/main/java/nl/improved/sqlclient/SQLShell.java
Log:
Bugfix for spooled lines being appended to each other.
Modified: src/main/java/nl/improved/sqlclient/SQLShell.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLShell.java 2007-09-20 12:51:38 UTC (rev 153)
+++ src/main/java/nl/improved/sqlclient/SQLShell.java 2007-09-28 12:53:04 UTC (rev 154)
@@ -415,6 +415,7 @@
if (spoolWriter != null) {
try {
spoolWriter.write(data.toString());
+ spoolWriter.write("\n");
} catch(IOException e) {
screenBuffer.add("WARNING: Could not write to spool file");
error(e);
|
|
From: SVN by r. <sv...@ca...> - 2007-10-02 09:24:52
|
Author: rotman
Date: 2007-10-02 11:24:45 +0200 (Tue, 02 Oct 2007)
New Revision: 160
Modified:
src/main/java/nl/improved/sqlclient/SQLProperties.java
Log:
Avoid NullPointerException when not running from jar.
Modified: src/main/java/nl/improved/sqlclient/SQLProperties.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLProperties.java 2007-09-30 09:54:09 UTC (rev 159)
+++ src/main/java/nl/improved/sqlclient/SQLProperties.java 2007-10-02 09:24:45 UTC (rev 160)
@@ -32,7 +32,7 @@
} catch(Exception e) {
//System.err.println("Failed to load pom.properties");
}
- props.put(PropertyName.VERSION, props.get("version"));
+ props.put(PropertyName.VERSION, props.getProperty("version", "")); //Add an empty version as default
}
private static SQLProperties getInstance() {
|
|
From: SVN by r. <sv...@ca...> - 2007-10-02 09:57:33
|
Author: roy
Date: 2007-10-02 11:57:31 +0200 (Tue, 02 Oct 2007)
New Revision: 163
Modified:
src/main/java/nl/improved/sqlclient/SQLProperties.java
Log:
only put version when property file load succeeded
Modified: src/main/java/nl/improved/sqlclient/SQLProperties.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLProperties.java 2007-10-02 09:34:21 UTC (rev 162)
+++ src/main/java/nl/improved/sqlclient/SQLProperties.java 2007-10-02 09:57:31 UTC (rev 163)
@@ -29,10 +29,10 @@
props = new Properties();
try {
props.load(getClass().getResourceAsStream("/META-INF/maven/nl.improved/sqlshell/pom.properties"));
+ props.put(PropertyName.VERSION, props.get("version"));
} catch(Exception e) {
//System.err.println("Failed to load pom.properties");
}
- props.put(PropertyName.VERSION, props.getProperty("version", "")); //Add an empty version as default
}
private static SQLProperties getInstance() {
|
|
From: SVN by r. <sv...@ca...> - 2007-10-08 15:29:39
|
Author: rotman
Date: 2007-10-08 17:29:40 +0200 (Mon, 08 Oct 2007)
New Revision: 172
Modified:
src/main/java/nl/improved/sqlclient/SQLShell.java
Log:
Implement commandline connect
Modified: src/main/java/nl/improved/sqlclient/SQLShell.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLShell.java 2007-10-08 15:18:39 UTC (rev 171)
+++ src/main/java/nl/improved/sqlclient/SQLShell.java 2007-10-08 15:29:40 UTC (rev 172)
@@ -25,7 +25,6 @@
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
-import javax.sound.midi.SysexMessage;
import jcurses.widgets.Window;
import jcurses.system.InputChar;
import jcurses.system.Toolkit;
@@ -281,7 +280,7 @@
debug("Unknown character: "+ inp.getCode());
} else if (inp.toString().equals("")) { //Ctrl+D
if (commandLines.getCommandString().length() == 0) { //Quit on empty commandline, ignore otherwise
- new QuitCommand().execute(new SQLCommand());
+ executeCommand(new InputCommand("quit"));
}
} else {
if (inp.getCharacter() == '\n') {
@@ -1077,8 +1076,42 @@
"Note that all statements must be terminated with ';' (sql statements as well as connect statements or spool)";
}
}
+
+ /**
+ * Command class to execute a 'custom command'.
+ * this makes it possible to have 'automated' commands executed.
+ * E.g.:
+ * executeCommand(new InputCommand("connect"));
+ * will eventually execute the Connect command.
+ */
+ private static class InputCommand extends SQLCommand {
+ private StringBuilder command;
+
+ public InputCommand(String command) {
+ this.command = new StringBuilder(command);
+ }
+
+ @Override
+ public String getUntrimmedCommandString() {
+ return command.toString();
+ }
+ @Override
+ public List<StringBuilder> getEditableLines() {
+ return Arrays.asList(new StringBuilder[]{command});
+ }
+ @Override
+ public List<? extends CharSequence> getLines() {
+ return Arrays.asList(new StringBuilder[]{command});
+ }
+ }
+
public static void main(String[] args) {
SQLShell shell = new SQLShell();
shell.show();
+
+ //Interpret first argument as a connect argument
+ if (args.length > 0) {
+ shell.executeCommand(new InputCommand("connect "+args[0]));
+ }
}
}
|
|
From: SVN by r. <sv...@ca...> - 2007-10-08 15:43:13
|
Author: rotman
Date: 2007-10-08 17:43:13 +0200 (Mon, 08 Oct 2007)
New Revision: 175
Modified:
src/main/java/nl/improved/sqlclient/SQLShell.java
Log:
Use InputCommand for batch executions
Modified: src/main/java/nl/improved/sqlclient/SQLShell.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLShell.java 2007-10-08 15:31:56 UTC (rev 174)
+++ src/main/java/nl/improved/sqlclient/SQLShell.java 2007-10-08 15:43:13 UTC (rev 175)
@@ -1042,20 +1042,8 @@
cmd.append(line);
if (line.endsWith(";")) {
// Exec cmd
- final StringBuilder cmdStringBuilder = cmd;
- executeCommand(new SQLCommand() {
- public String getUntrimmedCommandString() {
- return cmdStringBuilder.toString();
- }
- public List<StringBuilder> getEditableLines() {
- return Arrays.asList(new StringBuilder[]{cmdStringBuilder});
- }
- public List<? extends CharSequence> getLines() {
- return Arrays.asList(new StringBuilder[]{cmdStringBuilder});
- }
-
- });
- cmd = new StringBuilder();
+ executeCommand(new InputCommand(cmd));
+ cmd=new StringBuilder();
}
}
} catch(IOException e) {
@@ -1091,6 +1079,10 @@
this.command = new StringBuilder(command);
}
+ public InputCommand(StringBuilder command) {
+ this.command = command;
+ }
+
@Override
public String getUntrimmedCommandString() {
return command.toString();
|
|
From: SVN by r. <sv...@ca...> - 2007-10-28 19:26:48
|
Author: roy
Date: 2007-10-28 20:25:48 +0100 (Sun, 28 Oct 2007)
New Revision: 190
Modified:
src/main/java/nl/improved/sqlclient/SQLShell.java
Log:
more tab completion fixes for @ command
Modified: src/main/java/nl/improved/sqlclient/SQLShell.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLShell.java 2007-10-28 11:57:24 UTC (rev 189)
+++ src/main/java/nl/improved/sqlclient/SQLShell.java 2007-10-28 19:25:48 UTC (rev 190)
@@ -1160,8 +1160,15 @@
dirName = ".";
} else {
fileName = toFileName(fileName);
- if (fileName.indexOf('/') > 0) {
- dirName = new File(fileName).getParent();
+ if (fileName.indexOf('/') >= 0) {
+ File file = new File(fileName);
+ if (file.isDirectory()) {
+ fileName = "";
+ dirName = file.getAbsolutePath()+"/";
+ } else {
+ fileName = file.getName();
+ dirName = file.getParent();
+ }
} else {
dirName = ".";
}
|
|
From: SVN by r. <sv...@ca...> - 2007-10-29 08:15:13
|
Author: roy
Date: 2007-10-29 09:15:01 +0100 (Mon, 29 Oct 2007)
New Revision: 192
Modified:
src/main/java/nl/improved/sqlclient/DBConnector.java
Log:
per request: make enter in pwd field press ok
Modified: src/main/java/nl/improved/sqlclient/DBConnector.java
===================================================================
--- src/main/java/nl/improved/sqlclient/DBConnector.java 2007-10-28 20:08:10 UTC (rev 191)
+++ src/main/java/nl/improved/sqlclient/DBConnector.java 2007-10-29 08:15:01 UTC (rev 192)
@@ -23,6 +23,7 @@
import java.util.Set;
import java.util.Map;
import java.util.Properties;
+import jcurses.system.InputChar;
import jcurses.event.ActionEvent;
import jcurses.event.ActionListener;
import jcurses.widgets.Button;
@@ -316,14 +317,21 @@
super(10,10, 50, 7, true,"Connect");
userfield = new TextField();
setUsername(username);
- passfield = new PasswordField();
+ passfield = new PasswordField() {
+ protected boolean handleInput(InputChar ch) {
+ if (ch.getCharacter() == '\n') {
+ okButtonPressedSlot();
+ return false;
+ }
+ return super.handleInput(ch);
+ }
+ };
setPassword(password);
Button okButton = new Button("Ok");
okButton.addListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- LoginDialog.this.exitOk = true;
- LoginDialog.this.close();
+ public void actionPerformed(ActionEvent event) {
+ okButtonPressedSlot();
}
});
Button cancelButton = new Button("Cancel");
@@ -344,7 +352,12 @@
glm.addWidget(okButton, 1,2,1,1, WidgetsConstants.ALIGNMENT_CENTER, WidgetsConstants.ALIGNMENT_CENTER);
glm.addWidget(cancelButton, 2,2,1,1, WidgetsConstants.ALIGNMENT_CENTER, WidgetsConstants.ALIGNMENT_CENTER);
+
}
+ public void okButtonPressedSlot() {
+ exitOk = true;
+ close();
+ }
@Override
protected void activate() {
|
|
From: SVN by r. <sv...@ca...> - 2007-10-29 15:31:11
|
Author: roy
Date: 2007-10-29 16:31:08 +0100 (Mon, 29 Oct 2007)
New Revision: 193
Modified:
src/main/java/nl/improved/sqlclient/SQLShell.java
Log:
made exit quit the application as well (as per request)
Modified: src/main/java/nl/improved/sqlclient/SQLShell.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLShell.java 2007-10-29 08:15:01 UTC (rev 192)
+++ src/main/java/nl/improved/sqlclient/SQLShell.java 2007-10-29 15:31:08 UTC (rev 193)
@@ -126,7 +126,7 @@
commands.register("HELP[\\s]*.*", new HelpCommand());
commands.register("HISTORY[\\s]*.*", new HistoryCommand());
commands.register("SPOOL[\\s]*.*", new SpoolCommand());
- commands.register("QUIT[\\s]*", new QuitCommand());
+ commands.register("(QUIT|EXIT)[\\s]*", new QuitCommand());
commands.register("@.*", new ExecuteBatchCommand());
MAX_LINE_LENGTH = Toolkit.getScreenWidth()-(2+PROMPT.length()+2+1); // 2 spaces bouds.. prompt + "> "
@@ -952,7 +952,7 @@
return "Application terminated.";
}
public CharSequence getHelp() {
- return "Quit the application.";
+ return "Quit(exit) the application.";
}
public CharSequence getCommandString() {
return "quit";
|
|
From: SVN by r. <sv...@ca...> - 2007-11-06 12:09:52
|
Author: robert
Date: 2007-11-06 13:07:48 +0100 (Tue, 06 Nov 2007)
New Revision: 195
Modified:
src/main/java/nl/improved/sqlclient/SQLShell.java
Log:
Added possibility to quit with the \q command
Modified: src/main/java/nl/improved/sqlclient/SQLShell.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLShell.java 2007-11-06 10:50:30 UTC (rev 194)
+++ src/main/java/nl/improved/sqlclient/SQLShell.java 2007-11-06 12:07:48 UTC (rev 195)
@@ -126,7 +126,7 @@
commands.register("HELP[\\s]*.*", new HelpCommand());
commands.register("HISTORY[\\s]*.*", new HistoryCommand());
commands.register("SPOOL[\\s]*.*", new SpoolCommand());
- commands.register("(QUIT|EXIT)[\\s]*", new QuitCommand());
+ commands.register("(QUIT|EXIT|\\\Q)[\\s]*", new QuitCommand());
commands.register("@.*", new ExecuteBatchCommand());
MAX_LINE_LENGTH = Toolkit.getScreenWidth()-(2+PROMPT.length()+2+1); // 2 spaces bouds.. prompt + "> "
|
|
From: SVN by r. <sv...@ca...> - 2007-11-06 12:19:20
|
Author: robert
Date: 2007-11-06 13:17:19 +0100 (Tue, 06 Nov 2007)
New Revision: 196
Modified:
src/main/java/nl/improved/sqlclient/SQLShell.java
Log:
Added possibility to quit with the \q command
Modified: src/main/java/nl/improved/sqlclient/SQLShell.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLShell.java 2007-11-06 12:07:48 UTC (rev 195)
+++ src/main/java/nl/improved/sqlclient/SQLShell.java 2007-11-06 12:17:19 UTC (rev 196)
@@ -126,7 +126,7 @@
commands.register("HELP[\\s]*.*", new HelpCommand());
commands.register("HISTORY[\\s]*.*", new HistoryCommand());
commands.register("SPOOL[\\s]*.*", new SpoolCommand());
- commands.register("(QUIT|EXIT|\\\Q)[\\s]*", new QuitCommand());
+ commands.register("(QUIT|EXIT|\\\\Q)[\\s]*", new QuitCommand());
commands.register("@.*", new ExecuteBatchCommand());
MAX_LINE_LENGTH = Toolkit.getScreenWidth()-(2+PROMPT.length()+2+1); // 2 spaces bouds.. prompt + "> "
|
|
From: SVN by r. <sv...@ca...> - 2007-11-07 11:53:14
|
Author: roy
Date: 2007-11-07 12:50:04 +0100 (Wed, 07 Nov 2007)
New Revision: 197
Modified:
src/main/java/nl/improved/sqlclient/DBConnector.java
Log:
added check for special char
Modified: src/main/java/nl/improved/sqlclient/DBConnector.java
===================================================================
--- src/main/java/nl/improved/sqlclient/DBConnector.java 2007-11-06 12:17:19 UTC (rev 196)
+++ src/main/java/nl/improved/sqlclient/DBConnector.java 2007-11-07 11:50:04 UTC (rev 197)
@@ -319,7 +319,7 @@
setUsername(username);
passfield = new PasswordField() {
protected boolean handleInput(InputChar ch) {
- if (ch.getCharacter() == '\n') {
+ if (!ch.isSpecialCode() && ch.getCharacter() == '\n') {
okButtonPressedSlot();
return false;
}
|
|
From: SVN by r. <sv...@ca...> - 2007-11-14 21:24:35
|
Author: roy
Date: 2007-11-14 22:22:34 +0100 (Wed, 14 Nov 2007)
New Revision: 199
Modified:
src/main/java/nl/improved/sqlclient/DBConnector.java
Log:
reset pwd when usernmae is provided
Modified: src/main/java/nl/improved/sqlclient/DBConnector.java
===================================================================
--- src/main/java/nl/improved/sqlclient/DBConnector.java 2007-11-07 11:50:18 UTC (rev 198)
+++ src/main/java/nl/improved/sqlclient/DBConnector.java 2007-11-14 21:22:34 UTC (rev 199)
@@ -209,18 +209,28 @@
throw new SQLException("Failed to connect: Could not initialize driver '"+settings.getDriver()+"'", e);
}
+
String username;
+ String password;
if (usr == null || usr.length() == 0) {
username = settings.getUsername();
+ if (pwd == null) {
+ password = settings.getPassword();
+ } else {
+ password = pwd;
+ }
} else {
username = usr;
+ if (username != null && !username.equals(settings.getUsername())) {
+ password = pwd;
+ } else {
+ if (pwd == null) {
+ password = settings.getPassword();
+ } else {
+ password = pwd;
+ }
+ }
}
- String password;
- if (pwd == null) {
- password = settings.getPassword();
- } else {
- password = pwd;
- }
if (username == null || password == null) {
LoginDialog ld = new LoginDialog(username, password);
|
|
From: SVN by r. <sv...@ca...> - 2007-11-14 21:28:43
|
Author: roy
Date: 2007-11-14 22:26:47 +0100 (Wed, 14 Nov 2007)
New Revision: 200
Modified:
src/main/java/nl/improved/sqlclient/SQLShell.java
Log:
some quit command changes..
made last executed command the last in the history list
Modified: src/main/java/nl/improved/sqlclient/SQLShell.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLShell.java 2007-11-14 21:22:34 UTC (rev 199)
+++ src/main/java/nl/improved/sqlclient/SQLShell.java 2007-11-14 21:26:47 UTC (rev 200)
@@ -126,7 +126,9 @@
commands.register("HELP[\\s]*.*", new HelpCommand());
commands.register("HISTORY[\\s]*.*", new HistoryCommand());
commands.register("SPOOL[\\s]*.*", new SpoolCommand());
- commands.register("(QUIT|EXIT|\\\\Q)[\\s]*", new QuitCommand());
+ commands.register("QUIT[\\s]*", new QuitCommand("quit"));
+ commands.register("EXIT[\\s]*", new QuitCommand("exit"));
+ //commands.register("\\\\Q[\\s]*", new QuitCommand("\\q"));
commands.register("@.*", new ExecuteBatchCommand());
MAX_LINE_LENGTH = Toolkit.getScreenWidth()-(2+PROMPT.length()+2+1); // 2 spaces bouds.. prompt + "> "
@@ -312,9 +314,16 @@
if (executeCommand(sqlCommand)) {
// clear command history
if (commandIndex != commandHistory.size()-1) {
+ SQLCommand tmpLines = commandLines;
commandLines = commandHistory.get(commandHistory.size()-1);
+ if (commandLines.getCommandString().equals("")) {
+ commandHistory.add(commandHistory.size()-1, tmpLines);
+ } else {
+ commandHistory.add(tmpLines);
+ commandLines = tmpLines;
+ }
}
- if (commandLines.getLines().size() != 1 || commandLines.getLines().get(0).length() != 0) {
+ if (!commandLines.getCommandString().equals("")) {
commandLines = new SQLCommand();
commandHistory.add(commandLines);
newLine();
@@ -947,6 +956,11 @@
* Exit the client.
*/
private class QuitCommand implements Command {
+ private String cmd;
+
+ public QuitCommand(String cmd) {
+ this.cmd = cmd;
+ }
public CharSequence execute(SQLCommand command) {
hide(); // quit
return "Application terminated.";
@@ -955,7 +969,7 @@
return "Quit(exit) the application.";
}
public CharSequence getCommandString() {
- return "quit";
+ return cmd;
}
/**
* Returns some tab completion info for the specified command.
|
|
From: SVN by r. <sv...@ca...> - 2008-01-12 19:45:21
|
Author: roy
Date: 2008-01-12 20:05:47 +0100 (Sat, 12 Jan 2008)
New Revision: 213
Modified:
src/main/java/nl/improved/sqlclient/QueryExecutor.java
Log:
fix datetime issue (at least for oracle)
Modified: src/main/java/nl/improved/sqlclient/QueryExecutor.java
===================================================================
--- src/main/java/nl/improved/sqlclient/QueryExecutor.java 2008-01-12 11:33:22 UTC (rev 212)
+++ src/main/java/nl/improved/sqlclient/QueryExecutor.java 2008-01-12 19:05:47 UTC (rev 213)
@@ -126,7 +126,7 @@
if (colValue == null) {
return "NULL";
} else if (isDate(metadata, column)) {
- return defaultDateFormat.format(colValue);
+ return defaultDateFormat.format(rset.getTimestamp(column));
} else {
return colValue.toString();
}
|
|
From: SVN by r. <sv...@ca...> - 2008-01-12 19:53:17
|
Author: roy
Date: 2008-01-12 20:13:08 +0100 (Sat, 12 Jan 2008)
New Revision: 215
Modified:
src/main/java/nl/improved/sqlclient/QueryExecutor.java
Log:
added log of query time
Modified: src/main/java/nl/improved/sqlclient/QueryExecutor.java
===================================================================
--- src/main/java/nl/improved/sqlclient/QueryExecutor.java 2008-01-12 19:08:46 UTC (rev 214)
+++ src/main/java/nl/improved/sqlclient/QueryExecutor.java 2008-01-12 19:13:08 UTC (rev 215)
@@ -145,6 +145,7 @@
//StringBuffer displayValue = new StringBuffer();
ResultSetMetaData metadata = results.getMetaData();
+ long start = System.currentTimeMillis();
// TODO specify labels
List<String> labels = new ArrayList<String>();
@@ -168,7 +169,8 @@
if (rowCount != 1) {
footer.append("s");
}
- footer.append(" selected.\n\n");
+ footer.append(" selected.\n");
+ footer.append("Query took: "+ (System.currentTimeMillis() - start) +" millis\n\n");
displayValue.setFooter(footer);
return displayValue.toString();
}
|
|
From: SVN by r. <sv...@ca...> - 2008-01-13 10:52:39
|
Author: roy Date: 2008-01-13 11:41:19 +0100 (Sun, 13 Jan 2008) New Revision: 216 Modified: src/main/java/nl/improved/sqlclient/DBConnector.java Log: removed unused import Modified: src/main/java/nl/improved/sqlclient/DBConnector.java =================================================================== --- src/main/java/nl/improved/sqlclient/DBConnector.java 2008-01-12 19:13:08 UTC (rev 215) +++ src/main/java/nl/improved/sqlclient/DBConnector.java 2008-01-13 10:41:19 UTC (rev 216) @@ -15,7 +15,6 @@ */ package nl.improved.sqlclient; -import com.sun.org.apache.bcel.internal.generic.Select; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; |
|
From: SVN by r. <sv...@ca...> - 2008-01-14 11:10:05
|
Author: roy
Date: 2008-01-14 11:57:59 +0100 (Mon, 14 Jan 2008)
New Revision: 221
Modified:
src/main/java/nl/improved/sqlclient/SQLShell.java
Log:
fix spool with ~ in filename
Modified: src/main/java/nl/improved/sqlclient/SQLShell.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLShell.java 2008-01-14 10:46:32 UTC (rev 220)
+++ src/main/java/nl/improved/sqlclient/SQLShell.java 2008-01-14 10:57:59 UTC (rev 221)
@@ -137,6 +137,7 @@
output("Type 'help' to get a list of available commands other then the default sql input.");
}
+
/**
* Returns the connection to the database
* @return the connection to the database
@@ -1094,16 +1095,16 @@
}
} else {
try {
- File f = new File(toFileName(nextPart));
+ File f = new File(toFileName(nextPart.trim()));
fileName = f.getAbsolutePath();
if ((f.exists() && !f.canWrite()) || (!f.exists() && !f.createNewFile())) {
throw new IllegalStateException("Failed to create spool to file: '"+fileName+"'");
}
- spoolWriter = new FileWriter(nextPart);
+ spoolWriter = new FileWriter(fileName);
} catch (IOException e) {
- throw new IllegalStateException("Failed to create spool: " + e.toString(), e);
+ throw new IllegalStateException("Failed to create spool ("+fileName+"): " + e.toString(), e);
}
- return "Spool created.";
+ return "Spool to "+fileName+" created.";
}
}
|
|
From: SVN by r. <sv...@ca...> - 2008-01-27 12:57:39
|
Author: roy
Date: 2008-01-27 13:39:29 +0100 (Sun, 27 Jan 2008)
New Revision: 230
Modified:
src/main/java/nl/improved/sqlclient/
src/main/java/nl/improved/sqlclient/DBConnector.java
src/main/java/nl/improved/sqlclient/QueryExecutor.java
src/main/java/nl/improved/sqlclient/SQLShell.java
Log:
fixes for displaying timestamp/date format on oracle and mysql
Property changes on: src/main/java/nl/improved/sqlclient
___________________________________________________________________
Name: svn:ignore
- .SQLPlusPlus.java.swp
.SQLPlus.java.swp
.DBConnector.java.swp
.SQLUtil.java.swp
.Point.java.swp
.SQLLineWrapper.java.swp
.SQLOutput.java.swp
+ .SQLPlusPlus.java.swp
.SQLPlus.java.swp
.DBConnector.java.swp
.SQLUtil.java.swp
.Point.java.swp
.SQLLineWrapper.java.swp
.SQLOutput.java.swp
.QueryExecutor.java.swp
Modified: src/main/java/nl/improved/sqlclient/DBConnector.java
===================================================================
--- src/main/java/nl/improved/sqlclient/DBConnector.java 2008-01-27 10:41:23 UTC (rev 229)
+++ src/main/java/nl/improved/sqlclient/DBConnector.java 2008-01-27 12:39:29 UTC (rev 230)
@@ -16,10 +16,14 @@
package nl.improved.sqlclient;
import java.sql.Connection;
+import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
+import java.sql.Types;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
import java.util.Hashtable;
import java.util.Set;
import java.util.Map;
@@ -36,7 +40,15 @@
import jcurses.widgets.WidgetsConstants;
public final class DBConnector {
+
+ /**
+ * The default formatting pattern for Date or Date-like columns.
+ */
+ private static final String DEFAULT_TIMESTAMP_PATTERN = "yyyy-MM-dd HH:mm:ss";
+ private static final String DEFAULT_DATE_PATTERN = "yyyy-MM-dd";
+ private static final String DEFAULT_TIME_PATTERN = "HH:mm:ss";
+
private static DBConnector instance = null;
private boolean tableNamesUppercase = false;
@@ -45,7 +57,10 @@
private Connection activeConnection;
private Statement statement;
+ private boolean dateIsTimeStamp;
+ private QueryExecutor queryExecutor;
+
private DBConnector() {
predefinedConnections = new Hashtable<String, ConnectionSettings>();
Properties dbProperties = new Properties();
@@ -91,6 +106,10 @@
return name.toLowerCase();
}
+ public boolean treatDateAsTimestamp() {
+ return dateIsTimeStamp;
+ }
+
/**
* Return the used schema.
* NOTE: hack because Oracle uses as a schema the current username
@@ -176,6 +195,17 @@
return connect(getPredefinedConnectionSettings(ident), username, password);
}
+ public QueryExecutor getQueryExecutor() {
+ if (queryExecutor == null) {
+ if (dateIsTimeStamp) {
+ queryExecutor = new QueryExecutor(DEFAULT_TIMESTAMP_PATTERN, DEFAULT_TIME_PATTERN, DEFAULT_TIMESTAMP_PATTERN);
+ } else {
+ queryExecutor = new QueryExecutor(DEFAULT_DATE_PATTERN, DEFAULT_TIME_PATTERN, DEFAULT_TIMESTAMP_PATTERN);
+ }
+ }
+ return queryExecutor;
+ }
+
private ConnectionSettings getPredefinedConnectionSettings(String identifier) {
if (predefinedConnections.containsKey(identifier)) {
return predefinedConnections.get(identifier);
@@ -256,10 +286,10 @@
activeConnection = DriverManager.getConnection(settings.getConnectionURL(), username, password);
activeConnection.setAutoCommit(autoCommit);
- // INITIALIZE to uppercase type
+ // INITIALIZE database settings
try {
- ResultSet rs = activeConnection.getMetaData()
- .getTables(activeConnection.getCatalog(), getSchema()
+ DatabaseMetaData metaData = activeConnection.getMetaData();
+ ResultSet rs = metaData.getTables(activeConnection.getCatalog(), getSchema()
, null, new String[]{"TABLE"});
while (rs.next()) {
String tableName = rs.getString("TABLE_NAME");
@@ -270,6 +300,20 @@
}
}
}
+ rs = metaData.getTypeInfo();
+ dateIsTimeStamp = true;
+ String timestampType = null, dateType =null;
+ while (rs.next() && (timestampType == null && dateType == null)) {
+ if (Types.TIMESTAMP == rs.getInt("DATA_TYPE")) {
+ timestampType = rs.getString("LOCAL_TYPE_NAME");
+ } if (Types.DATE == rs.getInt("DATA_TYPE")) {
+ dateType = rs.getString("LOCAL_TYPE_NAME");
+ }
+ }
+ if (timestampType != null && dateType != null) {
+ dateIsTimeStamp = dateType.equals(timestampType);
+ }
+
} catch(Exception e) {
/* ignore */
}
@@ -286,6 +330,7 @@
activeConnection.close();
activeConnection = null;
}
+ queryExecutor = null;
}
public Connection getConnection() {
Modified: src/main/java/nl/improved/sqlclient/QueryExecutor.java
===================================================================
--- src/main/java/nl/improved/sqlclient/QueryExecutor.java 2008-01-27 10:41:23 UTC (rev 229)
+++ src/main/java/nl/improved/sqlclient/QueryExecutor.java 2008-01-27 12:39:29 UTC (rev 230)
@@ -15,9 +15,12 @@
*/
package nl.improved.sqlclient;
+import java.sql.Date;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
+import java.sql.Time;
+import java.sql.Timestamp;
import java.sql.Types;
import java.util.List;
import java.util.ArrayList;
@@ -41,19 +44,24 @@
public class QueryExecutor {
/**
- * The default formatting pattern for Date or Date-like columns.
- */
- private static final String DEFAULTDATEPATTERN = "yyyy-MM-dd HH:mm:ss";
- /**
* Used to format dates with unspecified patterns.
*/
- private DateFormat defaultDateFormat;
+ private DateFormat defaultDateFormat, defaultTimeFormat, defaultTimestampFormat;
+ private String timeFormat;
+ private String timestampFormat;
+ private String dateFormat;
+
/**
* Constructor.
*/
- public QueryExecutor() {
- defaultDateFormat = new SimpleDateFormat(DEFAULTDATEPATTERN);
+ QueryExecutor(String dateFormat, String timeFormat, String timestampFormat) {
+ this.dateFormat = dateFormat;
+ this.timeFormat = timeFormat;
+ this.timestampFormat = timestampFormat;
+ defaultDateFormat = new SimpleDateFormat(dateFormat);
+ defaultTimeFormat = new SimpleDateFormat(timeFormat);
+ defaultTimestampFormat = new SimpleDateFormat(timestampFormat);
}
/**
@@ -79,22 +87,6 @@
}
/**
- * Check if a column is a Date or Date-like.
- * @param metadata the metadata describing the resultset
- * @param column the column to check
- * @return true if the column is date-like, false otherwise.
- */
- private boolean isDate(ResultSetMetaData metadata, int column) throws SQLException {
- switch (metadata.getColumnType(column)) {
- case Types.DATE:
- case Types.TIMESTAMP:
- case Types.TIME:
- return true;
- }
- return false;
- }
-
- /**
* Returns the width at wich a column should be displayed.
* Usually the ResultSetMetaData will be responsible for this width, but a few exceptions
* are made (this would typicall be the case for dates).
@@ -104,8 +96,13 @@
* @return the width in characters that should be used to display the column.
*/
private int getColumnWidth(ResultSetMetaData metadata, int column) throws SQLException {
- if (isDate(metadata, column)) {
- return DEFAULTDATEPATTERN.length();
+ switch (metadata.getColumnType(column)) {
+ case Types.DATE:
+ return dateFormat.length();
+ case Types.TIMESTAMP:
+ return timestampFormat.length();
+ case Types.TIME:
+ return timeFormat.length();
}
// Let's assume for now that most columns CAN actually contain NULL values, and therefore we want every column to have a minimum width of 4
return Math.max(4, metadata.getColumnDisplaySize(column));
@@ -122,11 +119,43 @@
private CharSequence getDisplayValue(ResultSet rset, int column) throws SQLException {
ResultSetMetaData metadata = rset.getMetaData();
+ switch (metadata.getColumnType(column)) {
+ case Types.DATE: {
+ if (dateFormat.equals(timestampFormat)) {// for databases that see date as a timestamp
+ Timestamp date = rset.getTimestamp(column);
+ if (date == null) {
+ return "NULL";
+ }
+ return defaultTimestampFormat.format(date);
+ }
+ Date date = rset.getDate(column);
+ if (date == null) {
+ return "NULL";
+ }
+ return defaultDateFormat.format(date);
+ }
+ case Types.TIMESTAMP: {
+ try {
+ Timestamp date = rset.getTimestamp(column);
+ if (date == null) {
+ return "NULL";
+ }
+ return defaultTimestampFormat.format(rset.getTimestamp(column));
+ } catch(SQLException e) {
+ return "NULL";
+ }
+ }
+ case Types.TIME: {
+ Time date = rset.getTime(column);
+ if (date == null) {
+ return "NULL";
+ }
+ return defaultTimeFormat.format(date);
+ }
+ }
Object colValue = rset.getObject(column);
if (colValue == null) {
return "NULL";
- } else if (isDate(metadata, column)) {
- return defaultDateFormat.format(rset.getTimestamp(column));
} else {
return colValue.toString();
}
Modified: src/main/java/nl/improved/sqlclient/SQLShell.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLShell.java 2008-01-27 10:41:23 UTC (rev 229)
+++ src/main/java/nl/improved/sqlclient/SQLShell.java 2008-01-27 12:39:29 UTC (rev 230)
@@ -94,10 +94,6 @@
private CommandManager commands = new CommandManager();
/**
- * Executor for SQL Queries
- */
- private QueryExecutor querySelector;
- /**
* Executor for SQL Statements
*/
private StatementExecutor queryExecutor;
@@ -648,10 +644,7 @@
*/
protected CharSequence getResult(CharSequence command) throws SQLException {
if (command.length() > "select".length() && "select".equalsIgnoreCase(command.subSequence(0, "create".length()).toString())) {
- if (querySelector == null) {
- querySelector = new QueryExecutor();
- }
- return querySelector.executeQuery(command);
+ return DBConnector.getInstance().getQueryExecutor().executeQuery(command);
}
if (queryExecutor == null) {
queryExecutor = new StatementExecutor();
|
|
From: SVN by r. <sv...@ca...> - 2008-01-27 13:01:52
|
Author: roy
Date: 2008-01-27 13:43:39 +0100 (Sun, 27 Jan 2008)
New Revision: 231
Modified:
src/main/java/nl/improved/sqlclient/SQLShell.java
Log:
fix find column matchin tab completion for mysql (lowercase match databases)
Modified: src/main/java/nl/improved/sqlclient/SQLShell.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLShell.java 2008-01-27 12:39:29 UTC (rev 230)
+++ src/main/java/nl/improved/sqlclient/SQLShell.java 2008-01-27 12:43:39 UTC (rev 231)
@@ -476,7 +476,7 @@
List<String> returnValues = new ArrayList<String>();
Iterator<String> iTableNames = tableNames.iterator();
while (iTableNames.hasNext()) {
- String tableName = iTableNames.next().trim().toUpperCase();
+ String tableName = DBConnector.getInstance().translateDbVar(iTableNames.next().trim());
try {
ResultSet rs = getConnection().getMetaData().getColumns(getConnection().getCatalog(), DBConnector.getInstance().getSchema(), tableName, "%");
while (rs.next()) {
|
|
From: SVN by r. <sv...@ca...> - 2008-02-14 21:05:32
|
Author: roy
Date: 2008-02-14 22:05:21 +0100 (Thu, 14 Feb 2008)
New Revision: 235
Modified:
src/main/java/nl/improved/sqlclient/SQLShell.java
Log:
started background thread..
currently it is a little 'hackish'
Modified: src/main/java/nl/improved/sqlclient/SQLShell.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLShell.java 2008-02-13 07:23:46 UTC (rev 234)
+++ src/main/java/nl/improved/sqlclient/SQLShell.java 2008-02-14 21:05:21 UTC (rev 235)
@@ -39,6 +39,7 @@
public class SQLShell extends Window {
private CommandThread commandThread;
+ private boolean showPrompt = true;
/**
* The (default) maximum matches to show in a selection dialog.
@@ -619,7 +620,7 @@
if (cCommand != null) {
output(sqlCommand.getUntrimmedCommandString());
commandThread = new CommandThread(cCommand) {
- public void run() {
+ public void execute() {
try {
output(cCommand.execute(sqlCommand));
} catch(Exception e) {
@@ -630,8 +631,7 @@
if (direct || cCommand instanceof QuitCommand || cCommand instanceof ConnectCommand) {
commandThread.run();
} else {
- //commandThread.start(); // TODO
- commandThread.run();
+ commandThread.start();
}
return true;
}
@@ -639,15 +639,14 @@
// execute sql command
output(sqlCommand.getUntrimmedCommandString());
commandThread = new CommandThread(new QueryCommand()) {
- public void run() {
+ public void execute() {
output(getCommand().execute(sqlCommand));
}
};
if (direct) {
commandThread.run();
} else {
- //commandThread.start(); // TODO
- commandThread.run();
+ commandThread.start();
}
return true;
} else if (command.equalsIgnoreCase("printStackTrace")) {
@@ -676,7 +675,7 @@
//add prompt
List<? extends CharSequence> currentLines = commandLines.getLines();
for (int i = 0; i < currentLines.size(); i++) {
- if (i == 0) {
+ if (i == 0 && showPrompt) {
tmpList.add(PROMPT+"> "+currentLines.get(i));
} else {
String nrI = Integer.toString(i+1);
@@ -1302,12 +1301,25 @@
}
}
- private static class CommandThread extends Thread {
+ private abstract class CommandThread extends Thread {
private Command cmd;
public CommandThread(Command cmd) {
this.cmd = cmd;
}
+ public final void run() {
+ showPrompt = false;
+ try {
+ execute();
+ } finally {
+ showPrompt = true;
+ try { Thread.sleep(500);} catch(InterruptedException e) {} // hack
+ paint();
+ }
+ }
+
+ abstract void execute();
+
Command getCommand() {
return cmd;
}
|
|
From: SVN by r. <sv...@ca...> - 2008-02-15 13:29:27
|
Author: roy
Date: 2008-02-15 14:29:16 +0100 (Fri, 15 Feb 2008)
New Revision: 236
Modified:
src/main/java/nl/improved/sqlclient/SQLShell.java
Log:
added keyaction (Help for keys) support
Modified: src/main/java/nl/improved/sqlclient/SQLShell.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLShell.java 2008-02-14 21:05:21 UTC (rev 235)
+++ src/main/java/nl/improved/sqlclient/SQLShell.java 2008-02-15 13:29:16 UTC (rev 236)
@@ -23,6 +23,8 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import jcurses.widgets.Window;
@@ -96,6 +98,8 @@
*/
private CommandManager commands = new CommandManager();
+ private Map<String, KeyAction> actionKeys = new HashMap<String, KeyAction>();
+
/**
* Constructor.
*/
@@ -125,6 +129,178 @@
//commands.register("\\\\Q[\\s]*", new QuitCommand("\\q"));
commands.register("@.*", new ExecuteBatchCommand());
+ // keys
+ actionKeys.put(Integer.toString(InputChar.KEY_LEFT), new KeyAction() {
+ public void execute() {
+ if (cursorPosition.x > 0) {
+ cursorPosition.x--;
+ } else if (cursorPosition.y > 0) {
+ cursorPosition.y--;
+ cursorPosition.x = commandLines.getLines().get(cursorPosition.y).length();
+ }
+ }
+ public CharSequence getHelp() {
+ return "Arrow Left:\tMove cursor to the left";
+ }
+ });
+ actionKeys.put(Integer.toString(InputChar.KEY_RIGHT), new KeyAction() {
+ public void execute() {
+ CharSequence tmp = commandLines.getLines().get(cursorPosition.y);
+ if (cursorPosition.x < tmp.length()) {
+ cursorPosition.x++;
+ } else if (cursorPosition.y < commandLines.getLines().size()-1) {
+ cursorPosition.x = 0;
+ cursorPosition.y++;
+ }
+ }
+ public CharSequence getHelp() {
+ return "Arrow Right:\tMove cursor to the right";
+ }
+ });
+ actionKeys.put(Integer.toString(InputChar.KEY_UP), new KeyAction() {
+ public void execute() {
+ if (commandIndex > 0) {
+ commandLines = commandHistory.get(--commandIndex);
+ cursorPosition.y = commandLines.getLines().size()-1;
+ CharSequence lineBuffer = commandLines.getLines().get(cursorPosition.y);
+ cursorPosition.x = lineBuffer.length();
+ }
+ }
+ public CharSequence getHelp() {
+ return "Arrow Up:\tBrowse to previous command in the history";
+ }
+ });
+ actionKeys.put(Integer.toString(InputChar.KEY_DOWN), new KeyAction() {
+ public void execute() {
+ if (commandIndex < commandHistory.size()-1) {
+ commandLines = commandHistory.get(++commandIndex);
+ cursorPosition.y = commandLines.getLines().size()-1;
+ CharSequence lineBuffer = commandLines.getLines().get(cursorPosition.y);
+ cursorPosition.x = lineBuffer.length();
+ }
+ }
+ public CharSequence getHelp() {
+ return "Arrow Down:\tBrowse to next command in the history";
+ }
+ });
+ actionKeys.put(Integer.toString(InputChar.KEY_BACKSPACE), new KeyAction() {
+ public void execute() {
+ if (cursorPosition.x == 0) {
+ if (cursorPosition.y > 0) {
+ StringBuilder line = getEditableCommand().getEditableLines().remove(cursorPosition.y);
+ cursorPosition.y--;
+ StringBuilder lineBuffer = commandLines.getEditableLines().get(cursorPosition.y);
+ cursorPosition.x = lineBuffer.length();
+ lineBuffer.append(line);
+ }
+ } else {
+ StringBuilder tmp = getEditableCommand().getEditableLines().get(cursorPosition.y);
+ if (cursorPosition.x > 0) {
+ tmp.deleteCharAt(cursorPosition.x-1);
+ cursorPosition.x--;
+ }
+ }
+ }
+ public CharSequence getHelp() {
+ return "Backspace:\tRemove the character before the cursor position";
+ }
+ });
+ actionKeys.put(Integer.toString(InputChar.KEY_DC), new KeyAction() {
+ public void execute() {
+ StringBuilder lineBuffer = commandLines.getEditableLines().get(cursorPosition.y);
+ if (cursorPosition.x < lineBuffer.length()) {
+ StringBuilder tmp = getEditableCommand().getEditableLines().get(cursorPosition.y);
+ tmp.deleteCharAt(cursorPosition.x);
+ }
+ }
+ public CharSequence getHelp() {
+ return "Del:\tDelete the charactor at the current cursor position";
+ }
+ });
+ actionKeys.put(Integer.toString(InputChar.KEY_PPAGE), new KeyAction() {
+ public void execute() {
+ if ((screenBuffer.size() + commandLines.getLines().size()
+ - (Toolkit.getScreenHeight()/2) * pageUpCount) > 0) {
+ pageUpCount++;
+
+ }
+ }
+ public CharSequence getHelp() {
+ return "PageUp:\tMove back in screen history";
+ }
+ });
+ actionKeys.put(Integer.toString(InputChar.KEY_NPAGE), new KeyAction() {
+ public void execute() {
+ if (pageUpCount > 0) {
+ pageUpCount--;
+ }
+ }
+ public CharSequence getHelp() {
+ return "PageDown:\tMove forward in screen history";
+ }
+ });
+ actionKeys.put(Integer.toString(InputChar.KEY_END),new KeyAction() {
+ public void execute() {
+ cursorPosition.y = commandLines.getLines().size()-1;
+ CharSequence lineBuffer = commandLines.getLines().get(cursorPosition.y);
+ cursorPosition.x = lineBuffer.length();
+ }
+ public CharSequence getHelp() {
+ return "End:\tMove the cursor to the end of the command";
+ }
+ });
+ actionKeys.put(Integer.toString(InputChar.KEY_HOME), new KeyAction() {
+ public void execute() {
+ cursorPosition.y = 0;
+ cursorPosition.x = 0;
+ }
+ public CharSequence getHelp() {
+ return "Home:\tMove the cursor to the start of the command";
+ }
+ });
+ actionKeys.put("", new KeyAction() {
+ public void execute() {
+ StringBuilder lineBuffer = commandLines.getEditableLines().get(cursorPosition.y);
+ int previousBreak = SQLUtil.getLastBreakIndex(lineBuffer.substring(0, cursorPosition.x));
+ lineBuffer.delete(previousBreak, cursorPosition.x);
+ cursorPosition.x = previousBreak;
+ }
+ public CharSequence getHelp() {
+ return "Control-W:\tRemove word before cursor position";
+ }
+ });
+ actionKeys.put("", new KeyAction() { // ctrl+u
+ public void execute() {
+ StringBuilder lineBuffer = commandLines.getEditableLines().get(cursorPosition.y);
+ lineBuffer.delete(0, cursorPosition.x);
+ cursorPosition.x = 0;
+ }
+ public CharSequence getHelp() {
+ return "Control-U:\tRemove all characters before the cursor position";
+ }
+ });
+ actionKeys.put("", new KeyAction() { //Ctrl+D
+ public void execute() {
+ if (commandLines.getCommandString().length() == 0) { //Quit on empty commandline, ignore otherwise
+ executeCommand(new InputCommand("quit"));
+ }
+ }
+ public CharSequence getHelp() {
+ return "Control-D:\tExit sqlshell";
+ }
+ });
+ actionKeys.put("", new KeyAction() { // ctrl+a
+ public void execute() {
+ output("Abort requested");
+ if (commandThread.isAlive() && commandThread.getCommand().abort()) {
+ output("Abort done..");
+ }
+ }
+ public CharSequence getHelp() {
+ return "Control-A:\tAbort current command (if it is supported by that command)";
+ }
+ });
+
MAX_LINE_LENGTH = Toolkit.getScreenWidth()-(2+PROMPT.length()+2+1); // 2 spaces bouds.. prompt + "> "
output("Welcome to the SQLShell client.");
@@ -196,197 +372,119 @@
if (inp.getCode() != InputChar.KEY_PPAGE && inp.getCode() != InputChar.KEY_NPAGE) {
pageUpCount = 0; // some character entered, so reset pageup count
}
- if (inp.isSpecialCode() || inp.toString().equals("") || inp.toString().equals("")) {
- if (inp.getCode() == InputChar.KEY_LEFT) {
- if (cursorPosition.x > 0) {
- cursorPosition.x--;
- } else if (cursorPosition.y > 0) {
- cursorPosition.y--;
- cursorPosition.x = commandLines.getLines().get(cursorPosition.y).length();
- }
- } else if (inp.getCode() == InputChar.KEY_RIGHT) {
- CharSequence tmp = commandLines.getLines().get(cursorPosition.y);
- if (cursorPosition.x < tmp.length()) {
- cursorPosition.x++;
- } else if (cursorPosition.y < commandLines.getLines().size()-1) {
- cursorPosition.x = 0;
- cursorPosition.y++;
- }
- } else if (inp.getCode() == InputChar.KEY_UP) {
- if (commandIndex > 0) {
- commandLines = commandHistory.get(--commandIndex);
- cursorPosition.y = commandLines.getLines().size()-1;
- CharSequence lineBuffer = commandLines.getLines().get(cursorPosition.y);
- cursorPosition.x = lineBuffer.length();
- }
- } else if (inp.getCode() == InputChar.KEY_DOWN) {
- if (commandIndex < commandHistory.size()-1) {
- commandLines = commandHistory.get(++commandIndex);
- cursorPosition.y = commandLines.getLines().size()-1;
- CharSequence lineBuffer = commandLines.getLines().get(cursorPosition.y);
- cursorPosition.x = lineBuffer.length();
- }
- } else if (inp.getCode() == InputChar.KEY_BACKSPACE) {
- if (cursorPosition.x == 0) {
- if (cursorPosition.y > 0) {
- StringBuilder line = getEditableCommand().getEditableLines().remove(cursorPosition.y);
- cursorPosition.y--;
- StringBuilder lineBuffer = commandLines.getEditableLines().get(cursorPosition.y);
- cursorPosition.x = lineBuffer.length();
- lineBuffer.append(line);
- }
- } else {
- StringBuilder tmp = getEditableCommand().getEditableLines().get(cursorPosition.y);
- if (cursorPosition.x > 0) {
- tmp.deleteCharAt(cursorPosition.x-1);
- cursorPosition.x--;
- }
- }
- } else if (inp.getCode() == InputChar.KEY_DC) {
- StringBuilder lineBuffer = commandLines.getEditableLines().get(cursorPosition.y);
- if (cursorPosition.x < lineBuffer.length()) {
- StringBuilder tmp = getEditableCommand().getEditableLines().get(cursorPosition.y);
- tmp.deleteCharAt(cursorPosition.x);
- }
- } else if (inp.getCode() == InputChar.KEY_PPAGE) {
- if ((screenBuffer.size() + commandLines.getLines().size()
- - (Toolkit.getScreenHeight()/2) * pageUpCount) > 0) {
- pageUpCount++;
-
- }
- } else if (inp.getCode() == InputChar.KEY_NPAGE) {
- if (pageUpCount > 0) {
- pageUpCount--;
- }
- } else if (inp.getCode() == InputChar.KEY_END) {
- cursorPosition.y = commandLines.getLines().size()-1;
- CharSequence lineBuffer = commandLines.getLines().get(cursorPosition.y);
- cursorPosition.x = lineBuffer.length();
- } else if (inp.getCode() == InputChar.KEY_HOME) {
- cursorPosition.y = 0;
- cursorPosition.x = 0;
- } else if (inp.toString() != null && inp.toString().equals("")) { // ctrl+w
- StringBuilder lineBuffer = commandLines.getEditableLines().get(cursorPosition.y);
- int previousBreak = SQLUtil.getLastBreakIndex(lineBuffer.substring(0, cursorPosition.x));
- lineBuffer.delete(previousBreak, cursorPosition.x);
- cursorPosition.x = previousBreak;
- } else if (inp.toString() != null && inp.toString().equals("")) { // ctrl+u
- StringBuilder lineBuffer = commandLines.getEditableLines().get(cursorPosition.y);
- lineBuffer.delete(0, cursorPosition.x);
- cursorPosition.x = 0;
- } else
+ if (inp.isSpecialCode()) {
+ KeyAction ke = actionKeys.get(Integer.toString(inp.getCode()));// || inp.toString().equals("") || inp.toString().equals("")) {
+ if (ke != null) {
+ ke.execute();
+ } else {
debug("Unknown character: "+ inp.getCode());
- } else if (inp.toString().equals("")) { //Ctrl+D
- if (commandLines.getCommandString().length() == 0) { //Quit on empty commandline, ignore otherwise
- executeCommand(new InputCommand("quit"));
}
- } else if (inp.toString() != null && inp.toString().equals("")) { // ctrl+a
- output("Abort requested");
- if (commandThread.isAlive() && commandThread.getCommand().abort()) {
- output("Abort done..");
- }
} else {
- if (inp.getCharacter() == '\n') {
- // execute the command
- SQLCommand sqlCommand = getCommand();
- String command = sqlCommand.getCommandString();
- // search command...
- if (command.length() > 0 && command.charAt(0) == '/') {
- String matchPattern=".*"+command.substring(1,command.length())+".*";
- for (int cIndex = commandHistory.size()-1; cIndex >=0; cIndex--) {
- if (cIndex == commandIndex) {
- continue; // skip current command
+ KeyAction ke = actionKeys.get(inp.toString());
+ if (ke != null) {
+ ke.execute();
+ } else {
+ if (inp.getCharacter() == '\n') { // newline... see if the command can be executed
+ // execute the command
+ SQLCommand sqlCommand = getCommand();
+ String command = sqlCommand.getCommandString();
+ // search command...
+ if (command.length() > 0 && command.charAt(0) == '/') { // search in history
+ String matchPattern=".*"+command.substring(1,command.length())+".*";
+ for (int cIndex = commandHistory.size()-1; cIndex >=0; cIndex--) {
+ if (cIndex == commandIndex) {
+ continue; // skip current command
+ }
+ SQLCommand newSqlCommand = commandHistory.get(cIndex);
+ String commandString = newSqlCommand.getCommandString();
+ if (commandString.matches(matchPattern)) {
+ commandHistory.remove(commandIndex);
+ commandIndex = commandHistory.indexOf(newSqlCommand);
+ commandLines = newSqlCommand;
+ cursorPosition.y = 0;
+ cursorPosition.x = 0;
+ paint(); // force repaint
+ return;
+ }
}
- SQLCommand newSqlCommand = commandHistory.get(cIndex);
- String commandString = newSqlCommand.getCommandString();
- if (commandString.matches(matchPattern)) {
- commandHistory.remove(commandIndex);
- commandIndex = commandHistory.indexOf(newSqlCommand);
- commandLines = newSqlCommand;
- cursorPosition.y = 0;
- cursorPosition.x = 0;
- paint(); // force repaint
- return;
+ Toolkit.beep(); // TODO clear search??
+ return;
+ } else if (executeCommand(sqlCommand)) {
+ // clear command history
+ if (commandIndex != commandHistory.size()-1) {
+ SQLCommand tmpLines = commandLines;
+ commandLines = commandHistory.get(commandHistory.size()-1);
+ if (commandLines.getCommandString().equals("")) {
+ commandHistory.add(commandHistory.size()-1, tmpLines);
+ } else {
+ commandHistory.add(tmpLines);
+ commandLines = tmpLines;
+ }
}
+ if (!commandLines.getCommandString().equals("")) {
+ commandLines = new SQLCommand();
+ commandHistory.add(commandLines);
+ newLine();
+ }
+ commandIndex = commandHistory.size()-1;
+ cursorPosition.y = commandLines.getLines().size()-1;
+ cursorPosition.x = commandLines.getLines().get(cursorPosition.y).length();
+ paint(); // force repaint
+ return;
}
- Toolkit.beep();
- return;
}
- if (executeCommand(sqlCommand)) {
- // clear command history
- if (commandIndex != commandHistory.size()-1) {
- SQLCommand tmpLines = commandLines;
- commandLines = commandHistory.get(commandHistory.size()-1);
- if (commandLines.getCommandString().equals("")) {
- commandHistory.add(commandHistory.size()-1, tmpLines);
- } else {
- commandHistory.add(tmpLines);
- commandLines = tmpLines;
- }
+ CharSequence newText;
+ if (inp.getCharacter() == '\t') {
+ try {
+ newText = getTabCompletion(commandLines, cursorPosition);
+ } catch(IllegalStateException e) {
+ output(getCommand().getCommandString()); // add command as well...
+ error(e);
+ return;
}
- if (!commandLines.getCommandString().equals("")) {
- commandLines = new SQLCommand();
- commandHistory.add(commandLines);
- newLine();
- }
- commandIndex = commandHistory.size()-1;
- cursorPosition.y = commandLines.getLines().size()-1;
- cursorPosition.x = commandLines.getLines().get(cursorPosition.y).length();
- paint(); // force repaint
- return;
+ } else {
+ newText = Character.toString(inp.getCharacter());
}
- }
- CharSequence newText;
- if (inp.getCharacter() == '\t') {
- try {
- newText = getTabCompletion(commandLines, cursorPosition);
- } catch(IllegalStateException e) {
- output(getCommand().getCommandString()); // add command as well...
- error(e);
- return;
- }
- } else {
- newText = Character.toString(inp.getCharacter());
- }
- if (newText.equals("\n")) {
- newLine(); // TODO Fix
- } else {
- List<StringBuilder> editableLines = getEditableCommand().getEditableLines();
- StringBuilder currentLine = editableLines.get(cursorPosition.y);
- currentLine.insert(cursorPosition.x, newText);
- cursorPosition.x += newText.length();
- // check if the new line is becoming too long
- if (currentLine.length() > MAX_LINE_LENGTH) {
- // TODO search for lastspace that is not between '' ??
- int lastSpace = currentLine.lastIndexOf(" ");
- // check if there are enough 'next' lines
- // if not.. add one
- if (editableLines.size()-1 == cursorPosition.y) {
- StringBuilder newLine = new StringBuilder();
- editableLines.add(newLine);
+ if (newText.equals("\n")) {
+ newLine(); // TODO Fix return in middle of an other line
+ } else {
+ List<StringBuilder> editableLines = getEditableCommand().getEditableLines();
+ StringBuilder currentLine = editableLines.get(cursorPosition.y);
+ currentLine.insert(cursorPosition.x, newText);
+ cursorPosition.x += newText.length();
+ // check if the new line is becoming too long
+ if (currentLine.length() > MAX_LINE_LENGTH) {
+ // TODO search for lastspace that is not between '' ??
+ int lastSpace = currentLine.lastIndexOf(" ");
+ // check if there are enough 'next' lines
+ // if not.. add one
+ if (editableLines.size()-1 == cursorPosition.y) {
+ StringBuilder newLine = new StringBuilder();
+ editableLines.add(newLine);
+ }
+ // check if the nextline has enough room for the new word
+ // if not.. add a new line
+ if (editableLines.get(cursorPosition.y+1).length()
+ + (currentLine.length()-lastSpace+1) > MAX_LINE_LENGTH) {
+ StringBuilder newLine = new StringBuilder();
+ editableLines.add(cursorPosition.y+1, newLine);
+ }
+ // fetch the next line
+ StringBuilder nextLine = editableLines.get(cursorPosition.y+1);
+ // if the nextline already has some text.. add a space in front of it
+ if (nextLine.length() > 0) {
+ nextLine.insert(0, ' ');
+ }
+ // insert the new text at the beginning
+ nextLine.insert(0, currentLine.subSequence(lastSpace+1, currentLine.length()));
+ currentLine.delete(lastSpace, currentLine.length());
+ // check if the cursor postition > the new line length
+ // calculate new x and go to nextline
+ if (cursorPosition.x >= lastSpace) {
+ cursorPosition.x = cursorPosition.x - (lastSpace+1);
+ cursorPosition.y++;
+ }
}
- // check if the nextline has enough room for the new word
- // if not.. add a new line
- if (editableLines.get(cursorPosition.y+1).length()
- + (currentLine.length()-lastSpace+1) > MAX_LINE_LENGTH) {
- StringBuilder newLine = new StringBuilder();
- editableLines.add(cursorPosition.y+1, newLine);
- }
- // fetch the next line
- StringBuilder nextLine = editableLines.get(cursorPosition.y+1);
- // if the nextline already has some text.. add a space in front of it
- if (nextLine.length() > 0) {
- nextLine.insert(0, ' ');
- }
- // insert the new text at the beginning
- nextLine.insert(0, currentLine.subSequence(lastSpace+1, currentLine.length()));
- currentLine.delete(lastSpace, currentLine.length());
- // check if the cursor postition > the new line length
- // calculate new x and go to nextline
- if (cursorPosition.x >= lastSpace) {
- cursorPosition.x = cursorPosition.x - (lastSpace+1);
- cursorPosition.y++;
- }
}
}
}
@@ -1076,20 +1174,41 @@
return "Unkown command '"+ cmdString+"'";
}
// default print all commands
+ // TODO iterate
+ StringBuilder returnValue = new StringBuilder();
+ returnValue.append("Available key mappings:\n");
+ int max = 0;
+ Iterator<KeyAction> iKeyActions = actionKeys.values().iterator();
+ while (iKeyActions.hasNext()) {
+ max = Math.max(max, iKeyActions.next().getHelp().toString().indexOf('\t'));
+ }
+ iKeyActions = actionKeys.values().iterator();
+ while (iKeyActions.hasNext()) {
+ returnValue.append(" ");
+ //returnValue.append(iKeyActions.next().getHelp());
+ String help = iKeyActions.next().getHelp().toString();
+ int index = help.indexOf('\t');
+ returnValue.append(help.substring(0, index));
+ for (int i = index; i < max; i++) {
+ returnValue.append(' ');
+ }
+ returnValue.append(help.substring(index));
+ returnValue.append('\n');
+ }
+ returnValue.append("\n\nAvailable commands:\n");
Iterator<Command> iCommands = commands.getCommands().iterator();
while (iCommands.hasNext()) {
Command cmd = iCommands.next();
availableCommands.add(cmd.getCommandString());
}
- StringBuilder returnValue = toColumns(availableCommands);
+ returnValue.append(toColumns(availableCommands));
String helpHeader = "\nHelp for SQLShell client "+SQLProperties.getProperty(SQLProperties.PropertyName.VERSION, "SVN Snapshot")+"\n"+
"Here you find a list of available commands. "+
"To get more information about a specific command enter:\n"+
" help command (for example 'help help')\n\n"+
"If the list is not sufficient enough you could try searching help using:\n"+
" help -k searchstring (for example help -k column)\n"+
- "This results in a list of commands matching the searchstring\n\n"+
- "Available commands:\n";
+ "This results in a list of commands matching the searchstring\n\n";
returnValue.insert(0, helpHeader);
return returnValue;
}
@@ -1381,6 +1500,11 @@
}
+ private interface KeyAction...
[truncated message content] |
|
From: SVN by r. <sv...@ca...> - 2008-02-15 14:43:31
|
Author: roy
Date: 2008-02-15 15:43:21 +0100 (Fri, 15 Feb 2008)
New Revision: 237
Modified:
src/main/java/nl/improved/sqlclient/QueryExecutor.java
src/main/java/nl/improved/sqlclient/SQLShell.java
Log:
improved cancel support
Modified: src/main/java/nl/improved/sqlclient/QueryExecutor.java
===================================================================
--- src/main/java/nl/improved/sqlclient/QueryExecutor.java 2008-02-15 13:29:16 UTC (rev 236)
+++ src/main/java/nl/improved/sqlclient/QueryExecutor.java 2008-02-15 14:43:21 UTC (rev 237)
@@ -53,6 +53,7 @@
private String timeFormat;
private String timestampFormat;
private String dateFormat;
+ private boolean cancelled = false;
/**
* Constructor.
@@ -166,6 +167,7 @@
public CharSequence cancel() {
try {
DBConnector.getInstance().getStatement().cancel();
+ cancelled = true;
return "Cancel accepted";
} catch (SQLException ex) {
return "Cancel Failed: "+ ex.toString();
@@ -179,6 +181,7 @@
* @throws SQLException if the database could not execute the SQL query for some reason.
*/
protected CharSequence executeQuery(CharSequence command) throws SQLException {
+ cancelled = false;
ResultSet results = DBConnector.getInstance().getStatement().executeQuery(command.toString());
//StringBuffer separator = new StringBuffer();
@@ -197,7 +200,7 @@
ResultBuilder displayValue = new ResultBuilder();
displayValue.setHeader(labels);
int rowCount = 0;
- while (results.next()) {
+ while (results.next() && !cancelled) {
for (int col = 1; col <= metadata.getColumnCount(); col++ ) {
displayValue.set(col-1, rowCount, getDisplayValue(results, col), isNumeric(metadata, col) ? ResultBuilder.Alignment.RIGHT : ResultBuilder.Alignment.LEFT);
//try {Thread.sleep(10);} catch(Exception e2) {}
@@ -211,6 +214,9 @@
footer.append("s");
}
footer.append(" selected.\n");
+ if (cancelled) {
+ footer.append("Aborted....\n");
+ }
footer.append("Query took: "+ (System.currentTimeMillis() - start) +" millis\n\n");
displayValue.setFooter(footer);
return displayValue.toString();
Modified: src/main/java/nl/improved/sqlclient/SQLShell.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLShell.java 2008-02-15 13:29:16 UTC (rev 236)
+++ src/main/java/nl/improved/sqlclient/SQLShell.java 2008-02-15 14:43:21 UTC (rev 237)
@@ -1489,13 +1489,9 @@
@Override
public boolean abort() {
- try {
- DBConnector.getInstance().getStatement().cancel();
- return true;
- } catch (SQLException ex) {
- Logger.getLogger(SQLShell.class.getName()).log(Level.SEVERE, null, ex);
- return false;
- }
+ //DBConnector.getInstance().getStatement().cancel();
+ output(DBConnector.getInstance().getQueryExecutor().cancel());
+ return true;
}
}
|
|
From: SVN by r. <sv...@ca...> - 2008-02-19 20:02:29
|
Author: roy
Date: 2008-02-19 21:02:17 +0100 (Tue, 19 Feb 2008)
New Revision: 238
Modified:
src/main/java/nl/improved/sqlclient/SQLShell.java
Log:
navigation fixes (end/home)
updates to ctrl-u
Modified: src/main/java/nl/improved/sqlclient/SQLShell.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLShell.java 2008-02-15 14:43:21 UTC (rev 237)
+++ src/main/java/nl/improved/sqlclient/SQLShell.java 2008-02-19 20:02:17 UTC (rev 238)
@@ -241,21 +241,28 @@
});
actionKeys.put(Integer.toString(InputChar.KEY_END),new KeyAction() {
public void execute() {
- cursorPosition.y = commandLines.getLines().size()-1;
- CharSequence lineBuffer = commandLines.getLines().get(cursorPosition.y);
- cursorPosition.x = lineBuffer.length();
+ int curLineEnd = commandLines.getLines().get(cursorPosition.y).length();
+ if (cursorPosition.x == curLineEnd) {
+ cursorPosition.y = commandLines.getLines().size()-1;
+ CharSequence lineBuffer = commandLines.getLines().get(cursorPosition.y);
+ cursorPosition.x = lineBuffer.length();
+ } else {
+ cursorPosition.x = curLineEnd;
+ }
}
public CharSequence getHelp() {
- return "End:\tMove the cursor to the end of the command";
+ return "End:\tMove the cursor to the end of the line, of if already there at the end of the command";
}
});
actionKeys.put(Integer.toString(InputChar.KEY_HOME), new KeyAction() {
public void execute() {
- cursorPosition.y = 0;
+ if (cursorPosition.x == 0) {
+ cursorPosition.y = 0;
+ }
cursorPosition.x = 0;
}
public CharSequence getHelp() {
- return "Home:\tMove the cursor to the start of the command";
+ return "End:\tMove the cursor to the start of the line, of if already there at the start of the command";
}
});
actionKeys.put("", new KeyAction() {
@@ -271,9 +278,19 @@
});
actionKeys.put("", new KeyAction() { // ctrl+u
public void execute() {
- StringBuilder lineBuffer = commandLines.getEditableLines().get(cursorPosition.y);
- lineBuffer.delete(0, cursorPosition.x);
- cursorPosition.x = 0;
+ if (cursorPosition.x > 0) {
+ StringBuilder lineBuffer = commandLines.getEditableLines().get(cursorPosition.y);
+ lineBuffer.delete(0, cursorPosition.x);
+ cursorPosition.x = 0;
+ } else if (cursorPosition.y > 0) {
+ StringBuilder lineBuffer = commandLines.getEditableLines().get(cursorPosition.y);
+ if (lineBuffer.length() == 0) {
+ commandLines.getEditableLines().remove(cursorPosition.y);
+ }
+ cursorPosition.y--;
+ lineBuffer = commandLines.getEditableLines().get(cursorPosition.y);
+ lineBuffer.delete(0, lineBuffer.length());
+ }
}
public CharSequence getHelp() {
return "Control-U:\tRemove all characters before the cursor position";
|
|
From: SVN by r. <sv...@ca...> - 2008-02-27 09:07:48
|
Author: roy
Date: 2008-02-27 10:07:38 +0100 (Wed, 27 Feb 2008)
New Revision: 240
Modified:
src/main/java/nl/improved/sqlclient/SQLShell.java
Log:
some abort fixes for batchcommand
Modified: src/main/java/nl/improved/sqlclient/SQLShell.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLShell.java 2008-02-26 20:43:14 UTC (rev 239)
+++ src/main/java/nl/improved/sqlclient/SQLShell.java 2008-02-27 09:07:38 UTC (rev 240)
@@ -1354,10 +1354,12 @@
}
private class ExecuteBatchCommand implements Command {
- private boolean cancelled = false;
+ private boolean cancelled;
+ private Command currentCommand;
@Override
public CharSequence execute(SQLCommand sqlCommand) {
cancelled = false;
+ currentCommand = null;
String command = sqlCommand.getCommandString();
// read file from file system and execute
FileInputStream fin = null;
@@ -1388,6 +1390,9 @@
error(e);
} finally {
if (fin != null) try { fin.close();}catch(Exception e) {/*ignore*/}
+ if (cancelled) {
+ return "Execution of file '" + toFileName(command.substring(1)) +"' aborted....";
+ }
return "File '" + toFileName(command.substring(1)) +"' executed successfully.";
}
}
@@ -1437,8 +1442,12 @@
@Override
public boolean abort() {
cancelled = true;
+ if (currentCommand != null) {
+ currentCommand.abort();
+ }
return true;
}
+
@Override
public boolean backgroundProcessSupported() {
return true;
|
|
From: SVN by r. <sv...@ca...> - 2008-02-27 09:49:24
|
Author: roy
Date: 2008-02-27 10:49:14 +0100 (Wed, 27 Feb 2008)
New Revision: 241
Modified:
src/main/java/nl/improved/sqlclient/SQLShell.java
Log:
output fix for background commands
Modified: src/main/java/nl/improved/sqlclient/SQLShell.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLShell.java 2008-02-27 09:07:38 UTC (rev 240)
+++ src/main/java/nl/improved/sqlclient/SQLShell.java 2008-02-27 09:49:14 UTC (rev 241)
@@ -777,7 +777,7 @@
* Paint the screen.
*/
@Override
- protected void paint() {
+ protected synchronized void paint() {
Toolkit.clearScreen(new CharColor(CharColor.WHITE, CharColor.BLACK, CharColor.REVERSE, CharColor.REVERSE));
CharColor color = new CharColor(CharColor.BLACK, CharColor.WHITE, CharColor.BOLD, CharColor.BOLD);
@@ -1380,9 +1380,9 @@
if (line.endsWith(";")) {
// Exec cmd
String commandString = cmd.toString();
- Command cCommand = createCommand(commandString);
+ currentCommand = createCommand(commandString);
output(commandString);
- output(cCommand.execute(new InputCommand(commandString))); // TODO start in background...
+ output(currentCommand.execute(new InputCommand(commandString)));
cmd=new StringBuilder();
}
}
|