|
From: SVN by r. <sv...@ca...> - 2010-01-24 13:23:27
|
Author: roy
Date: 2010-01-24 14:23:17 +0100 (Sun, 24 Jan 2010)
New Revision: 455
Added:
src/test/java/nl/improved/sqlclient/AbstractSQLShellWindowTest.java
Modified:
src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java
Log:
fixes to real annoying character order messup
Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2010-01-24 11:07:18 UTC (rev 454)
+++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2010-01-24 13:23:17 UTC (rev 455)
@@ -147,6 +147,7 @@
commands.register("EXIT[\\s]*", new QuitCommand("exit"));
commands.register("SAVE[\\s]*.*", new SaveCommand());
commands.register("SET[\\s]*.*", new SettingsCommand());
+ commands.register("COUNT[\\s]*.*[\\d]+", new CountCommand());
//commands.register("\\\\Q[\\s]*", new QuitCommand("\\q"));
commands.register("@.*", new ExecuteBatchCommand(this));
commands.register("(SELECT|UPDATE|ALTER|INSERT|DELETE).*;[\\s]*", new QueryCommand());
@@ -707,7 +708,7 @@
repaint();
}
- public void insertText(CharSequence newText) {
+ public synchronized void insertText(CharSequence newText) {
if (newText.equals("\n")) {
newLine(); // TODO Fix return in middle of an other line
} else {
@@ -727,15 +728,16 @@
cursorPosition.x += newText.length();
// check if the new line is becoming too long
if (currentLine.length() > screen.MAX_LINE_LENGTH) {
+ //debug("BREAKING LINE IN MULTIPLE PIECES: " + screen.MAX_LINE_LENGTH);
// TODO search for lastspace that is not between '' ??
int lastSpace = SQLUtil.getLastBreakIndex(currentLine.toString().substring(0, screen.MAX_LINE_LENGTH-2));//currentLine.lastIndexOf(" ");
if (lastSpace == -1) {
- lastSpace = currentLine.length();
+ lastSpace = screen.MAX_LINE_LENGTH-1;//currentLine.length();
}
int lastChar = currentLine.charAt(lastSpace);
// check if there are enough 'next' lines
// if not.. add one
- if (editableLines.size()-1 == cursorPosition.y) {
+ if (editableLines.size()-1 >= cursorPosition.y) {
StringBuffer newLine = new StringBuffer();
editableLines.add(newLine);
}
@@ -752,18 +754,23 @@
// if there is not already a 'breaking character' there
if (nextLine.length() > 0 && ! SQLUtil.isBreakCharacter(nextLine.charAt(0))) {
nextLine.insert(0, ' ');
+ //debug("INSERTING SPACE");
}
// insert the new text at the beginning
nextLine.insert(0, currentLine.subSequence(lastSpace, currentLine.length()));
currentLine.delete(lastSpace, currentLine.length());
if (lastChar == ' ') {
+ //debug("DELEINT SPACE");
+ cursorPosition.x--;
nextLine.deleteCharAt(0);
}
// 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;
+ //debug("CHANGING POSITION" + cursorPosition);
+ cursorPosition.x = (cursorPosition.x - (lastSpace));
cursorPosition.y++;
+ //debug("->CHANGING POSITION" + cursorPosition);
}
}
}
@@ -1121,6 +1128,46 @@
return returnValue;
}
+ private class CountCommand implements Command {
+
+ public CommandResult execute(SQLCommand cmd) {
+ int count;
+ String cmdStr = cmd.getCommandString();
+ if (cmdStr.indexOf(' ') > 0) {
+ count = Integer.parseInt(cmdStr.substring(cmdStr.indexOf(' ')).trim());
+ } else {
+ count = 100;
+ }
+ StringBuffer result = new StringBuffer();
+ for (int i =0; i < count; i++) {
+ result.append(Integer.toString(i+1));
+ result.append(' ');
+ }
+
+ return new SimpleCommandResult(run, result.toString());
+ }
+
+ public CharSequence getCommandString() {
+ return "count";
+ }
+
+ public TabCompletionInfo getTabCompletionInfo(SQLCommand commandInfo, Point commandPoint) {
+ return null;
+ }
+
+ public CharSequence getHelp() {
+ return "";
+ }
+
+ public boolean abort() {
+ return false;
+ }
+
+ public boolean backgroundProcessSupported() {
+ return false;
+ }
+
+ }
/**
* Connect command for setting up a connection to a database.
*/
Added: src/test/java/nl/improved/sqlclient/AbstractSQLShellWindowTest.java
===================================================================
--- src/test/java/nl/improved/sqlclient/AbstractSQLShellWindowTest.java 2010-01-24 11:07:18 UTC (rev 454)
+++ src/test/java/nl/improved/sqlclient/AbstractSQLShellWindowTest.java 2010-01-24 13:23:17 UTC (rev 455)
@@ -0,0 +1,94 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package nl.improved.sqlclient;
+
+import java.io.File;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.List;
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author roy
+ */
+public class AbstractSQLShellWindowTest extends TestCase {
+
+ public AbstractSQLShellWindowTest(String testName) {
+ super(testName);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ /**
+ * Test of handleInput method, of class AbstractSQLShellWindow.
+ */
+ public void testHandleInput() {
+ String s = "select * from test;";
+ AbstractSQLShellWindow instance = new AbstractSQLShellWindowImpl();
+ InputKey inp = null;
+ for (char c : s.toCharArray()) {
+ inp = new InputKey(c);
+ instance.handleInput(inp);
+ }
+ assertEquals(s, instance.getCommand().getUntrimmedCommandString().trim());
+ }
+
+ public void testInsertText() {
+ String s = "select * from test;";
+ AbstractSQLShellWindow instance = new AbstractSQLShellWindowImpl();
+ instance.insertText(s);
+ assertEquals(s, instance.getCommand().getUntrimmedCommandString().trim());
+
+ instance = new AbstractSQLShellWindowImpl();
+ InputKey inp = null;
+ for (char c : s.toCharArray()) {
+ instance.insertText(Character.toString(c));
+ }
+ assertEquals(s, instance.getCommand().getUntrimmedCommandString().trim());
+ }
+
+ public class AbstractSQLShellWindowImpl extends AbstractSQLShellWindow {
+
+ public void show() {
+ }
+
+ public int getScreenWidth() {
+ return 10;//10;
+ }
+
+ public int getScreenHeight() {
+ return 20;
+ }
+
+ public void paint(Screen screen) {
+ }
+
+ public void beep() {
+ }
+
+ public void debug(String debug) {
+ System.out.println("DEBUG: "+ debug);
+ }
+
+ public String select(List<String> items, Point p) {
+ return "";
+ }
+
+ public String[] getLoginCredentials(String username, String password) throws SQLException {
+ return null;
+ }
+ }
+
+}
|