|
From: SVN by r. <sv...@ca...> - 2007-09-30 09:47:41
|
Author: roy
Date: 2007-09-30 11:47:31 +0200 (Sun, 30 Sep 2007)
New Revision: 157
Modified:
src/main/java/nl/improved/sqlclient/SQLUtil.java
src/test/java/nl/improved/sqlclient/SQLUtilTest.java
Log:
slight improvement of update tab completion
Modified: src/main/java/nl/improved/sqlclient/SQLUtil.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLUtil.java 2007-09-28 14:09:32 UTC (rev 156)
+++ src/main/java/nl/improved/sqlclient/SQLUtil.java 2007-09-30 09:47:31 UTC (rev 157)
@@ -47,7 +47,7 @@
*/
private static final String VALUE = "('>*'|[0-9]+|"+VAR+")";
- public static List<String> KEYWORDS = Arrays.asList(new String[]{"SELECT", "FROM", "WHERE", "VALUES", "SET", "INSERT", "INTO", "DELETE", "IS", "NULL", "IN", "NOT", "GROUP BY"});
+ public static List<String> KEYWORDS = Arrays.asList(new String[]{"SELECT", "UPDATE", "FROM", "WHERE", "VALUES", "SET", "INSERT", "INTO", "DELETE", "IS", "NULL", "IN", "NOT", "GROUP BY"});
/**
* Private constructor.
@@ -121,20 +121,41 @@
public static TabCompletionInfo getTabCompletionInfo(List<? extends CharSequence> commandInfo, Point commandPoint) {
if (commandInfo.size() == 1 && commandInfo.get(0).length() == 0) {
return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD
- , Arrays.asList(new String[]{"SELECT", "INSERT INTO", "DELETE FROM"}));
+ , Arrays.asList(new String[]{"SELECT", "INSERT INTO", "DELETE FROM", "UPDATE"}));
}
String startOfCommand = getStartOfCommand(commandInfo, commandPoint);
String lastKeyword = getLastKeyWord(startOfCommand);
if (lastKeyword == null) {
return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD
- , Arrays.asList(new String[]{"SELECT", "INSERT INTO", "DELETE FROM"}), startOfCommand);
+ , Arrays.asList(new String[]{"SELECT", "INSERT INTO", "DELETE FROM", "UPDATE"}), startOfCommand);
}
- if (lastKeyword.equalsIgnoreCase("SELECT")) {
+ if (lastKeyword.equalsIgnoreCase("UPDATE")) {
+ String end = startOfCommand.substring(startOfCommand.lastIndexOf(' ')+1);
+ String upCommand = startOfCommand.toUpperCase();
+ if (upCommand.matches("UPDATE[\\s]+"+TABLE+"[\\s]+(|S|SE|SET)")) {
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD, Arrays.asList(new String[]{"SET"}), end);
+ }
+ if (upCommand.matches("UPDATE[\\s]+"+TABLE+"[\\s]+SET[\\s]+")) {
+ String tableName = upCommand.substring("UPDATE".length());
+ tableName = tableName.substring(0, tableName.indexOf("SET")).trim();
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES, Arrays.asList(tableName), end);
+ }
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.TABLE_NAMES, new ArrayList<String>(), end);
+ } else if (lastKeyword.equalsIgnoreCase("SET")) {
+ String end = startOfCommand.substring(startOfCommand.lastIndexOf(' ')+1);
+ String upCommand = startOfCommand.toUpperCase();
+ if (upCommand.matches("UPDATE[\\s]+"+TABLE+"[\\s]+SET[\\s]+")) {
+ String tableName = upCommand.substring("UPDATE".length());
+ tableName = tableName.substring(0, tableName.indexOf("SET")).trim();
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES, Arrays.asList(tableName), end);
+ }
+ } else if (lastKeyword.equalsIgnoreCase("SELECT")) {
// if it looks like:
// SELECT x
// return "FROM"
- if (startOfCommand.trim().length() > "SELECT".length()) {
- if (startOfCommand.substring("SELECT".length()).matches("[\\s]*(\\*|"+VAR+"[\\s])([\\s]*,[\\s]*"+VAR+"+)*( |\t)*(|F|FR|FRO|FROM|f|fr|fro|from)")) {
+ String upCommand = startOfCommand.trim().toUpperCase();
+ if (upCommand.length() > "SELECT".length()) {
+ if (upCommand.substring("SELECT".length()).matches("[\\s]*(\\*|"+VAR+"[\\s])([\\s]*,[\\s]*"+VAR+"+)*( |\t)*(|F|FR|FRO|FROM)")) {
String end = startOfCommand.substring(startOfCommand.lastIndexOf(' ')+1);
return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD
, Arrays.asList(new String[]{"FROM"}), end);
@@ -222,7 +243,6 @@
return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD
, Arrays.asList(new String[]{"AND", "OR", "IN", "GROUP BY", "ORDER BY"}));
}
-
return new TabCompletionInfo(TabCompletionInfo.MatchType.UNKNOWN, Arrays.asList(new String[0]));
}
Modified: src/test/java/nl/improved/sqlclient/SQLUtilTest.java
===================================================================
--- src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2007-09-28 14:09:32 UTC (rev 156)
+++ src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2007-09-30 09:47:31 UTC (rev 157)
@@ -285,4 +285,34 @@
assertTrue(tableNames.contains("A"));
}
+ public void testUpdateTabCompletion() {
+ List<String> sqlCommand = Arrays.asList(new String[]{"UPDATE A"});
+ Point cursorPos = new Point(sqlCommand.get(0).length(),0);
+ SQLUtil.TabCompletionInfo info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(SQLUtil.TabCompletionInfo.MatchType.TABLE_NAMES, info.getMatchType());
+ List<String> matches = info.getPossibleMatches();
+ assertEquals(0, matches.size());
+ assertEquals("A", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"UPDATE A "});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(SQLUtil.TabCompletionInfo.MatchType.SQL_KEYWORD, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(1, matches.size());
+ assertEquals("SET", matches.get(0));
+ assertEquals("", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"UPDATE A SET "});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(SQLUtil.TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(1, matches.size());
+ assertEquals("A", matches.get(0));
+ assertEquals("", info.getStart());
+ }
}
|
|
From: SVN by r. <sv...@ca...> - 2007-10-26 12:21:01
|
Author: roy
Date: 2007-10-26 14:20:56 +0200 (Fri, 26 Oct 2007)
New Revision: 185
Modified:
src/main/java/nl/improved/sqlclient/SQLUtil.java
src/test/java/nl/improved/sqlclient/SQLUtilTest.java
Log:
added more 'failing' queries .. and added fix
Modified: src/main/java/nl/improved/sqlclient/SQLUtil.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLUtil.java 2007-10-09 10:15:53 UTC (rev 184)
+++ src/main/java/nl/improved/sqlclient/SQLUtil.java 2007-10-26 12:20:56 UTC (rev 185)
@@ -37,7 +37,7 @@
/**
* A column name regular expression statement.
*/
- private static final String COLUMN = "[A-Z]+"+NAMING_CHAR+"*";
+ private static final String COLUMN = "(\\*|[A-Z]+"+NAMING_CHAR+"*)";
/**
* A variable (table name + columnname) regular expression statement.
*/
@@ -166,9 +166,10 @@
// if it looks like:
// SELECT x
// return "FROM"
- String upCommand = startOfCommand.trim().toUpperCase();
+ String upCommand = startOfCommand.toUpperCase();
if (upCommand.length() > "SELECT".length()) {
- if (upCommand.substring("SELECT".length()).matches("[\\s]*(\\*|"+VAR+"[\\s])([\\s]*,[\\s]*"+VAR+"+)*( |\t)*(|F|FR|FRO|FROM)")) {
+ if (upCommand.substring(upCommand.indexOf("SELECT") + "SELECT".length())
+ .matches("[\\s]+"+VAR+"(|[\\s]*,[\\s]*"+VAR+"[\\s]*)[\\s]+(|F|FR|FRO|FROM)")) {
String end = startOfCommand.substring(startOfCommand.lastIndexOf(' ')+1);
return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD
, Arrays.asList(new String[]{"FROM"}), end);
Modified: src/test/java/nl/improved/sqlclient/SQLUtilTest.java
===================================================================
--- src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2007-10-09 10:15:53 UTC (rev 184)
+++ src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2007-10-26 12:20:56 UTC (rev 185)
@@ -95,6 +95,26 @@
assertTrue(matches.contains("FROM"));
assertEquals("FR", info.getStart());
+ sqlCommand = Arrays.asList(new String[]{"SELECT a.test FR"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(SQLUtil.TabCompletionInfo.MatchType.SQL_KEYWORD, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(1, matches.size());
+ assertTrue(matches.contains("FROM"));
+ assertEquals("FR", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT a.test, a.tost FR"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(SQLUtil.TabCompletionInfo.MatchType.SQL_KEYWORD, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(1, matches.size());
+ assertTrue(matches.contains("FROM"));
+ assertEquals("FR", info.getStart());
+
sqlCommand = Arrays.asList(new String[]{"SELECT A."});
cursorPos = new Point(sqlCommand.get(0).length(),0);
info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
|
|
From: SVN by r. <sv...@ca...> - 2007-10-28 10:43:32
|
Author: roy
Date: 2007-10-28 11:42:25 +0100 (Sun, 28 Oct 2007)
New Revision: 186
Modified:
src/main/java/nl/improved/sqlclient/SQLUtil.java
src/test/java/nl/improved/sqlclient/SQLUtilTest.java
Log:
tab completion fix for from with multiple column select
Modified: src/main/java/nl/improved/sqlclient/SQLUtil.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLUtil.java 2007-10-26 12:20:56 UTC (rev 185)
+++ src/main/java/nl/improved/sqlclient/SQLUtil.java 2007-10-28 10:42:25 UTC (rev 186)
@@ -216,6 +216,7 @@
, Arrays.asList(new String[]{"WHERE"}), end);
}
String end;
+ startOfCommand = startOfCommand.substring(startOfCommand.indexOf("FROM"));
if (startOfCommand.indexOf(',') > 0) {
end = startOfCommand.substring(startOfCommand.lastIndexOf(',')+1).trim();
} else {
Modified: src/test/java/nl/improved/sqlclient/SQLUtilTest.java
===================================================================
--- src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2007-10-26 12:20:56 UTC (rev 185)
+++ src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2007-10-28 10:42:25 UTC (rev 186)
@@ -162,6 +162,15 @@
matches = info.getPossibleMatches();
assertEquals(0, matches.size());
assertEquals("A", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT A.b, A.c FROM A"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(SQLUtil.TabCompletionInfo.MatchType.TABLE_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(0, matches.size());
+ assertEquals("A", info.getStart());
}
public void testTabCompletionInfoWHERE() {
|
|
From: SVN by r. <sv...@ca...> - 2007-11-06 10:52:38
|
Author: roy
Date: 2007-11-06 11:50:30 +0100 (Tue, 06 Nov 2007)
New Revision: 194
Modified:
src/main/java/nl/improved/sqlclient/SQLUtil.java
src/test/java/nl/improved/sqlclient/SQLUtilTest.java
Log:
fixed index out of bounds
Modified: src/main/java/nl/improved/sqlclient/SQLUtil.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLUtil.java 2007-10-29 15:31:08 UTC (rev 193)
+++ src/main/java/nl/improved/sqlclient/SQLUtil.java 2007-11-06 10:50:30 UTC (rev 194)
@@ -216,7 +216,7 @@
, Arrays.asList(new String[]{"WHERE"}), end);
}
String end;
- startOfCommand = startOfCommand.substring(startOfCommand.indexOf("FROM"));
+ startOfCommand = startOfCommand.substring(startOfCommand.toUpperCase().indexOf("FROM"));
if (startOfCommand.indexOf(',') > 0) {
end = startOfCommand.substring(startOfCommand.lastIndexOf(',')+1).trim();
} else {
Modified: src/test/java/nl/improved/sqlclient/SQLUtilTest.java
===================================================================
--- src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2007-10-29 15:31:08 UTC (rev 193)
+++ src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2007-11-06 10:50:30 UTC (rev 194)
@@ -135,6 +135,15 @@
assertEquals(0, matches.size());
assertEquals("A", info.getStart());
+ sqlCommand = Arrays.asList(new String[]{"select * from A"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.TABLE_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(0, matches.size());
+ assertEquals("A", info.getStart());
+
sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A, B"});
cursorPos = new Point(sqlCommand.get(0).length(),0);
info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
|
|
From: SVN by r. <sv...@ca...> - 2007-12-02 12:46:45
|
Author: roy
Date: 2007-12-02 13:43:35 +0100 (Sun, 02 Dec 2007)
New Revision: 201
Modified:
src/main/java/nl/improved/sqlclient/SQLUtil.java
src/test/java/nl/improved/sqlclient/SQLUtilTest.java
Log:
added unit test for WHERE a=b AND a=c
Modified: src/main/java/nl/improved/sqlclient/SQLUtil.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLUtil.java 2007-11-14 21:26:47 UTC (rev 200)
+++ src/main/java/nl/improved/sqlclient/SQLUtil.java 2007-12-02 12:43:35 UTC (rev 201)
@@ -137,7 +137,9 @@
, Arrays.asList(new String[]{"SELECT", "INSERT INTO", "DELETE FROM", "UPDATE"}));
}
String startOfCommand = getStartOfCommand(commandInfo, commandPoint);
+//System.out.println("Startof command: "+ startOfCommand);
String lastKeyword = getLastKeyWord(startOfCommand);
+//System.out.println("Last keyword: "+ lastKeyword);
if (lastKeyword == null) {
return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD
, Arrays.asList(new String[]{"SELECT", "INSERT INTO", "DELETE FROM", "UPDATE"}), startOfCommand);
@@ -229,7 +231,17 @@
// 'SELECT x FROM A,B WHERE'
// or
// 'SELECT x FROM A,B WHERE A.x='x' AND/OR '
- String tmpCommand = startOfCommand.substring(startOfCommand.indexOf(lastKeyword)+lastKeyword.length()+1).toUpperCase();
+ String tmpCommand = startOfCommand.substring(startOfCommand.indexOf(lastKeyword)+lastKeyword.length()+1);
+ String upperCommandString = tmpCommand.toUpperCase();
+ String subPart = "(|"+VAR+"(|[\\s]+"+COMPARATOR+"[\\s]+(|"+VAR+")))";
+ if (upperCommandString.matches("("+subPart+"|"+VAR+"[\\s]+"+COMPARATOR+"[\\s]+"+VAR+"(|[\\s]+AND[\\s]+"+subPart+"|[\\s]+OR[\\s]+"+subPart+"))")) {
+ String end = tmpCommand.substring(tmpCommand.lastIndexOf(' ')+1);
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES
+ , parseTableNames(commandInfo, commandPoint), end);
+ }
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD
+ , Arrays.asList(new String[]{"AND", "OR", "IN", "GROUP BY", "ORDER BY"}));
+ /*String tmpCommand = startOfCommand.substring(startOfCommand.indexOf(lastKeyword)+lastKeyword.length()+1).toUpperCase();
if (startOfCommand.trim().endsWith(lastKeyword)
|| tmpCommand.matches(".*(AND|OR)(|[\\s]+(|"+VAR+"))")) {
int beginIndex = startOfCommand.lastIndexOf(lastKeyword) + lastKeyword.length();
@@ -257,6 +269,7 @@
}
return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD
, Arrays.asList(new String[]{"AND", "OR", "IN", "GROUP BY", "ORDER BY"}));
+ */
} else if (lastKeyword.equalsIgnoreCase("DESC")) {
}
return new TabCompletionInfo(TabCompletionInfo.MatchType.UNKNOWN, Arrays.asList(new String[0]));
Modified: src/test/java/nl/improved/sqlclient/SQLUtilTest.java
===================================================================
--- src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2007-11-14 21:26:47 UTC (rev 200)
+++ src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2007-12-02 12:43:35 UTC (rev 201)
@@ -18,9 +18,7 @@
import java.util.Arrays;
import java.util.List;
-import junit.framework.Test;
import junit.framework.TestCase;
-import junit.framework.TestSuite;
public class SQLUtilTest extends TestCase {
@@ -203,7 +201,7 @@
}
public void testTabCompletionInfoWHEREConditions() {
- List<String> sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE "});
+ /* List<String> sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE "});
Point cursorPos = new Point(sqlCommand.get(0).length(),0);
TabCompletionInfo info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
assertNotNull(info);
@@ -298,6 +296,15 @@
assertTrue(matches.contains("OR"));
assertTrue(matches.contains("GROUP BY"));
assertTrue(matches.contains("ORDER BY"));
+*/
+
+ List<String> sqlCommand = Arrays.asList(new String[]{"select makelaarnr from makelaar, tree, plugin where parent = makelaar.i_id and child = pl"});
+ Point cursorPos = new Point(sqlCommand.get(0).length(),0);
+ TabCompletionInfo info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ List matches = info.getPossibleMatches();
+ assertEquals("pl", info.getStart());
}
public void testParseTableNames() {
|
|
From: SVN by r. <sv...@ca...> - 2008-01-09 16:13:42
|
Author: roy
Date: 2008-01-09 16:41:37 +0100 (Wed, 09 Jan 2008)
New Revision: 203
Modified:
src/main/java/nl/improved/sqlclient/SQLUtil.java
src/test/java/nl/improved/sqlclient/SQLUtilTest.java
Log:
(re-)added support for a lot more query strings
Modified: src/main/java/nl/improved/sqlclient/SQLUtil.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLUtil.java 2007-12-02 12:49:15 UTC (rev 202)
+++ src/main/java/nl/improved/sqlclient/SQLUtil.java 2008-01-09 15:41:37 UTC (rev 203)
@@ -49,7 +49,7 @@
/**
* A sql variable description.
*/
- private static final String VALUE = "('>*'|[0-9]+|"+VAR+")";
+ private static final String VALUE = "('.*'|[0-9]+|"+VAR+")";
public static List<String> KEYWORDS = Arrays.asList(new String[]{"SELECT", "UPDATE", "FROM", "WHERE", "VALUES", "SET", "INSERT", "INTO", "DELETE", "IS", "NULL", "IN", "NOT", "GROUP BY", "DESC"});
@@ -234,11 +234,17 @@
String tmpCommand = startOfCommand.substring(startOfCommand.indexOf(lastKeyword)+lastKeyword.length()+1);
String upperCommandString = tmpCommand.toUpperCase();
String subPart = "(|"+VAR+"(|[\\s]+"+COMPARATOR+"[\\s]+(|"+VAR+")))";
- if (upperCommandString.matches("("+subPart+"|"+VAR+"[\\s]+"+COMPARATOR+"[\\s]+"+VAR+"(|[\\s]+AND[\\s]+"+subPart+"|[\\s]+OR[\\s]+"+subPart+"))")) {
+ //String regExp = "(|"+VALUE+"(|[\\s]+"+COMPARATOR+"[\\s]+(|"+VALUE+"(|([\\s]+(AND|OR)[\\s]+)))))";
+ String regExp = "(|"+VALUE+"(|[\\s]+"+COMPARATOR+"[\\s]+(|"+VALUE+"(|([\\s]+(AND|OR)[\\s]+(|"+VALUE+"(|[\\s]+"+COMPARATOR+"[\\s]+(|"+VALUE+"))))*))))";
+ if (upperCommandString.matches(regExp)) {
String end = tmpCommand.substring(tmpCommand.lastIndexOf(' ')+1);
+ if (end.indexOf(".") > 0) {
+ end = end.substring(end.indexOf(".")+1);
+ }
return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES
, parseTableNames(commandInfo, commandPoint), end);
}
+ //System.out.println("'"+upperCommandString +"'\n not matches\n"+regExp);
return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD
, Arrays.asList(new String[]{"AND", "OR", "IN", "GROUP BY", "ORDER BY"}));
/*String tmpCommand = startOfCommand.substring(startOfCommand.indexOf(lastKeyword)+lastKeyword.length()+1).toUpperCase();
Modified: src/test/java/nl/improved/sqlclient/SQLUtilTest.java
===================================================================
--- src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2007-12-02 12:49:15 UTC (rev 202)
+++ src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2008-01-09 15:41:37 UTC (rev 203)
@@ -201,7 +201,7 @@
}
public void testTabCompletionInfoWHEREConditions() {
- /* List<String> sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE "});
+ List<String> sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE "});
Point cursorPos = new Point(sqlCommand.get(0).length(),0);
TabCompletionInfo info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
assertNotNull(info);
@@ -222,7 +222,7 @@
assertTrue(matches.contains("B"));
assertEquals("I", info.getStart());
- sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE I=bla AND I"});
+ /*sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE I=bla AND I"});
cursorPos = new Point(sqlCommand.get(0).length(),0);
info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
assertNotNull(info);
@@ -231,7 +231,7 @@
assertEquals(2, matches.size());
assertTrue(matches.contains("A"));
assertTrue(matches.contains("B"));
- assertEquals("I", info.getStart());
+ assertEquals("I", info.getStart());*/
sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE A.I"});
cursorPos = new Point(sqlCommand.get(0).length(),0);
@@ -239,8 +239,9 @@
assertNotNull(info);
assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
matches = info.getPossibleMatches();
- assertEquals(1, matches.size());
+ //assertEquals(1, matches.size());
assertTrue(matches.contains("A"));
+ System.out.println("I: " + info.getStart());
assertEquals("I", info.getStart());
// with other conditions
@@ -296,14 +297,14 @@
assertTrue(matches.contains("OR"));
assertTrue(matches.contains("GROUP BY"));
assertTrue(matches.contains("ORDER BY"));
-*/
- List<String> sqlCommand = Arrays.asList(new String[]{"select makelaarnr from makelaar, tree, plugin where parent = makelaar.i_id and child = pl"});
- Point cursorPos = new Point(sqlCommand.get(0).length(),0);
- TabCompletionInfo info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
+
+ sqlCommand = Arrays.asList(new String[]{"select makelaarnr from makelaar, tree, plugin where parent = makelaar.i_id and child = pl"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
assertNotNull(info);
assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
- List matches = info.getPossibleMatches();
+ matches = info.getPossibleMatches();
assertEquals("pl", info.getStart());
}
|
|
From: SVN by r. <sv...@ca...> - 2008-01-09 16:18:05
|
Author: roy
Date: 2008-01-09 16:48:47 +0100 (Wed, 09 Jan 2008)
New Revision: 204
Modified:
src/main/java/nl/improved/sqlclient/SQLUtil.java
src/test/java/nl/improved/sqlclient/SQLUtilTest.java
Log:
added another test
no longer spaces around operators required
Modified: src/main/java/nl/improved/sqlclient/SQLUtil.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLUtil.java 2008-01-09 15:41:37 UTC (rev 203)
+++ src/main/java/nl/improved/sqlclient/SQLUtil.java 2008-01-09 15:48:47 UTC (rev 204)
@@ -235,7 +235,7 @@
String upperCommandString = tmpCommand.toUpperCase();
String subPart = "(|"+VAR+"(|[\\s]+"+COMPARATOR+"[\\s]+(|"+VAR+")))";
//String regExp = "(|"+VALUE+"(|[\\s]+"+COMPARATOR+"[\\s]+(|"+VALUE+"(|([\\s]+(AND|OR)[\\s]+)))))";
- String regExp = "(|"+VALUE+"(|[\\s]+"+COMPARATOR+"[\\s]+(|"+VALUE+"(|([\\s]+(AND|OR)[\\s]+(|"+VALUE+"(|[\\s]+"+COMPARATOR+"[\\s]+(|"+VALUE+"))))*))))";
+ String regExp = "(|"+VALUE+"(|[\\s]*"+COMPARATOR+"[\\s]*(|"+VALUE+"(|([\\s]+(AND|OR)[\\s]+(|"+VALUE+"(|[\\s]+"+COMPARATOR+"[\\s]+(|"+VALUE+"))))*))))";
if (upperCommandString.matches(regExp)) {
String end = tmpCommand.substring(tmpCommand.lastIndexOf(' ')+1);
if (end.indexOf(".") > 0) {
@@ -244,7 +244,7 @@
return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES
, parseTableNames(commandInfo, commandPoint), end);
}
- //System.out.println("'"+upperCommandString +"'\n not matches\n"+regExp);
+ System.out.println("'"+upperCommandString +"'\n not matches\n"+regExp);
return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD
, Arrays.asList(new String[]{"AND", "OR", "IN", "GROUP BY", "ORDER BY"}));
/*String tmpCommand = startOfCommand.substring(startOfCommand.indexOf(lastKeyword)+lastKeyword.length()+1).toUpperCase();
Modified: src/test/java/nl/improved/sqlclient/SQLUtilTest.java
===================================================================
--- src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2008-01-09 15:41:37 UTC (rev 203)
+++ src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2008-01-09 15:48:47 UTC (rev 204)
@@ -222,7 +222,7 @@
assertTrue(matches.contains("B"));
assertEquals("I", info.getStart());
- /*sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE I=bla AND I"});
+ sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE I=bla AND I"});
cursorPos = new Point(sqlCommand.get(0).length(),0);
info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
assertNotNull(info);
@@ -231,7 +231,7 @@
assertEquals(2, matches.size());
assertTrue(matches.contains("A"));
assertTrue(matches.contains("B"));
- assertEquals("I", info.getStart());*/
+ assertEquals("I", info.getStart());
sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE A.I"});
cursorPos = new Point(sqlCommand.get(0).length(),0);
|
|
From: SVN by r. <sv...@ca...> - 2008-01-09 16:23:00
|
Author: roy
Date: 2008-01-09 16:53:31 +0100 (Wed, 09 Jan 2008)
New Revision: 205
Modified:
src/main/java/nl/improved/sqlclient/SQLUtil.java
src/test/java/nl/improved/sqlclient/SQLUtilTest.java
Log:
added 'start' recognizion for 'and'
Modified: src/main/java/nl/improved/sqlclient/SQLUtil.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLUtil.java 2008-01-09 15:48:47 UTC (rev 204)
+++ src/main/java/nl/improved/sqlclient/SQLUtil.java 2008-01-09 15:53:31 UTC (rev 205)
@@ -244,9 +244,15 @@
return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES
, parseTableNames(commandInfo, commandPoint), end);
}
- System.out.println("'"+upperCommandString +"'\n not matches\n"+regExp);
+ //System.out.println("'"+upperCommandString +"'\n not matches\n"+regExp);
+ String end = "";
+ if (upperCommandString.matches(".*[\\s]+")) {
+ end = "";
+ } else {
+ end = upperCommandString.substring(upperCommandString.lastIndexOf(' ')+1);
+ }
return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD
- , Arrays.asList(new String[]{"AND", "OR", "IN", "GROUP BY", "ORDER BY"}));
+ , Arrays.asList(new String[]{"AND", "OR", "IN", "GROUP BY", "ORDER BY"}), end);
/*String tmpCommand = startOfCommand.substring(startOfCommand.indexOf(lastKeyword)+lastKeyword.length()+1).toUpperCase();
if (startOfCommand.trim().endsWith(lastKeyword)
|| tmpCommand.matches(".*(AND|OR)(|[\\s]+(|"+VAR+"))")) {
@@ -276,7 +282,6 @@
return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD
, Arrays.asList(new String[]{"AND", "OR", "IN", "GROUP BY", "ORDER BY"}));
*/
- } else if (lastKeyword.equalsIgnoreCase("DESC")) {
}
return new TabCompletionInfo(TabCompletionInfo.MatchType.UNKNOWN, Arrays.asList(new String[0]));
}
Modified: src/test/java/nl/improved/sqlclient/SQLUtilTest.java
===================================================================
--- src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2008-01-09 15:48:47 UTC (rev 204)
+++ src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2008-01-09 15:53:31 UTC (rev 205)
@@ -297,6 +297,7 @@
assertTrue(matches.contains("OR"));
assertTrue(matches.contains("GROUP BY"));
assertTrue(matches.contains("ORDER BY"));
+ assertEquals("", info.getStart());
sqlCommand = Arrays.asList(new String[]{"select makelaarnr from makelaar, tree, plugin where parent = makelaar.i_id and child = pl"});
@@ -306,6 +307,15 @@
assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
matches = info.getPossibleMatches();
assertEquals("pl", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE A.x = 'x' A"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.SQL_KEYWORD, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertTrue(matches.contains("AND"));
+ assertEquals("A", info.getStart());
}
public void testParseTableNames() {
|
|
From: SVN by r. <sv...@ca...> - 2008-01-09 17:00:01
|
Author: roy
Date: 2008-01-09 17:11:26 +0100 (Wed, 09 Jan 2008)
New Revision: 206
Modified:
src/main/java/nl/improved/sqlclient/SQLUtil.java
src/test/java/nl/improved/sqlclient/SQLUtilTest.java
Log:
made completion for 'and' case sensitive (a=>and ,A=>AND)
Modified: src/main/java/nl/improved/sqlclient/SQLUtil.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLUtil.java 2008-01-09 15:53:31 UTC (rev 205)
+++ src/main/java/nl/improved/sqlclient/SQLUtil.java 2008-01-09 16:11:26 UTC (rev 206)
@@ -249,7 +249,7 @@
if (upperCommandString.matches(".*[\\s]+")) {
end = "";
} else {
- end = upperCommandString.substring(upperCommandString.lastIndexOf(' ')+1);
+ end = tmpCommand.substring(tmpCommand.lastIndexOf(' ')+1);
}
return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD
, Arrays.asList(new String[]{"AND", "OR", "IN", "GROUP BY", "ORDER BY"}), end);
Modified: src/test/java/nl/improved/sqlclient/SQLUtilTest.java
===================================================================
--- src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2008-01-09 15:53:31 UTC (rev 205)
+++ src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2008-01-09 16:11:26 UTC (rev 206)
@@ -316,6 +316,15 @@
matches = info.getPossibleMatches();
assertTrue(matches.contains("AND"));
assertEquals("A", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE A.x = 'x' a"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.SQL_KEYWORD, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertTrue(matches.contains("AND"));
+ assertEquals("a", info.getStart());
}
public void testParseTableNames() {
|
|
From: SVN by r. <sv...@ca...> - 2008-01-10 20:06:22
|
Author: roy
Date: 2008-01-10 20:20:50 +0100 (Thu, 10 Jan 2008)
New Revision: 207
Modified:
src/main/java/nl/improved/sqlclient/SQLUtil.java
src/test/java/nl/improved/sqlclient/SQLUtilTest.java
Log:
added another test
(no spaces required around '=' operator for code completion
Modified: src/main/java/nl/improved/sqlclient/SQLUtil.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLUtil.java 2008-01-09 16:11:26 UTC (rev 206)
+++ src/main/java/nl/improved/sqlclient/SQLUtil.java 2008-01-10 19:20:50 UTC (rev 207)
@@ -235,12 +235,20 @@
String upperCommandString = tmpCommand.toUpperCase();
String subPart = "(|"+VAR+"(|[\\s]+"+COMPARATOR+"[\\s]+(|"+VAR+")))";
//String regExp = "(|"+VALUE+"(|[\\s]+"+COMPARATOR+"[\\s]+(|"+VALUE+"(|([\\s]+(AND|OR)[\\s]+)))))";
- String regExp = "(|"+VALUE+"(|[\\s]*"+COMPARATOR+"[\\s]*(|"+VALUE+"(|([\\s]+(AND|OR)[\\s]+(|"+VALUE+"(|[\\s]+"+COMPARATOR+"[\\s]+(|"+VALUE+"))))*))))";
+ String regExp = "(|"+VALUE+"(|[\\s]*"+COMPARATOR+"[\\s]*(|"+VALUE+"(|([\\s]+(AND|OR)[\\s]+(|"+VALUE+"(|[\\s]*"+COMPARATOR+"[\\s]*(|"+VALUE+"))))*))))";
if (upperCommandString.matches(regExp)) {
- String end = tmpCommand.substring(tmpCommand.lastIndexOf(' ')+1);
+/* String end = tmpCommand.substring(tmpCommand.lastIndexOf(' ')+1);
if (end.indexOf(".") > 0) {
end = end.substring(end.indexOf(".")+1);
}
+*/
+ int lastIndex = tmpCommand.lastIndexOf(' ');
+ lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('.'));
+ lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('\t'));
+ lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('='));
+ lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('>'));
+ lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('>'));
+ String end = tmpCommand.substring(lastIndex+1);
return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES
, parseTableNames(commandInfo, commandPoint), end);
}
@@ -249,7 +257,12 @@
if (upperCommandString.matches(".*[\\s]+")) {
end = "";
} else {
- end = tmpCommand.substring(tmpCommand.lastIndexOf(' ')+1);
+ int lastIndex = tmpCommand.lastIndexOf(' ');
+ lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('\t'));
+ lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('='));
+ lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('>'));
+ lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('>'));
+ end = tmpCommand.substring(lastIndex+1);
}
return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD
, Arrays.asList(new String[]{"AND", "OR", "IN", "GROUP BY", "ORDER BY"}), end);
Modified: src/test/java/nl/improved/sqlclient/SQLUtilTest.java
===================================================================
--- src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2008-01-09 16:11:26 UTC (rev 206)
+++ src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2008-01-10 19:20:50 UTC (rev 207)
@@ -299,7 +299,6 @@
assertTrue(matches.contains("ORDER BY"));
assertEquals("", info.getStart());
-
sqlCommand = Arrays.asList(new String[]{"select makelaarnr from makelaar, tree, plugin where parent = makelaar.i_id and child = pl"});
cursorPos = new Point(sqlCommand.get(0).length(),0);
info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
@@ -308,6 +307,14 @@
matches = info.getPossibleMatches();
assertEquals("pl", info.getStart());
+ sqlCommand = Arrays.asList(new String[]{"select makelaarnr from makelaar, tree, plugin where parent = makelaar.i_id and child=pl"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals("pl", info.getStart());
+
sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE A.x = 'x' A"});
cursorPos = new Point(sqlCommand.get(0).length(),0);
info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
|
|
From: SVN by r. <sv...@ca...> - 2008-01-12 11:08:09
|
Author: roy
Date: 2008-01-12 11:52:04 +0100 (Sat, 12 Jan 2008)
New Revision: 208
Modified:
src/main/java/nl/improved/sqlclient/SQLUtil.java
src/test/java/nl/improved/sqlclient/SQLUtilTest.java
Log:
group by: initial support for tab completion added
Modified: src/main/java/nl/improved/sqlclient/SQLUtil.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLUtil.java 2008-01-10 19:20:50 UTC (rev 207)
+++ src/main/java/nl/improved/sqlclient/SQLUtil.java 2008-01-12 10:52:04 UTC (rev 208)
@@ -212,10 +212,13 @@
// 'SELECT x FROM A '
// return WHERE
String tmpCommand = startOfCommand.substring(startOfCommand.indexOf(lastKeyword)+lastKeyword.length()+1).toUpperCase();
- if (tmpCommand.matches("[\\s]*"+VAR+"+([\\s]*,[\\s]*"+VAR+"+)*[\\s]+(|W|WH|WHE|WHER|WHERE)")) {
+ String WHERE = "W|WH|WHE|WHER|WHERE";
+ String GROUP_BY = "G|GR|GRO|GROU|GROUP|GROUP |GROUP B|GROUP BY";
+ String ORDER_BY = "O|OR|ORD|ORDE|ORDER|ORDER |ORDER B|ORDER BY";
+ if (tmpCommand.matches("[\\s]*"+VAR+"+([\\s]*,[\\s]*"+VAR+"+)*[\\s]+(|"+WHERE+"|"+GROUP_BY+"|"+ORDER_BY+")")) {
String end = startOfCommand.substring(startOfCommand.lastIndexOf(' ')+1);
return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD
- , Arrays.asList(new String[]{"WHERE"}), end);
+ , Arrays.asList(new String[]{"WHERE", "GROUP BY", "ORDER BY"}), end);
}
String end;
startOfCommand = startOfCommand.substring(startOfCommand.toUpperCase().indexOf("FROM"));
@@ -295,6 +298,10 @@
return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD
, Arrays.asList(new String[]{"AND", "OR", "IN", "GROUP BY", "ORDER BY"}));
*/
+ } else if (lastKeyword.equalsIgnoreCase("GROUP BY")) {
+ String upperStart = startOfCommand.toUpperCase();
+ String columns = startOfCommand.substring(upperStart.indexOf("SELECT")+"SELECT".length(), upperStart.indexOf("FROM")).replaceAll(" ","");
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES, Arrays.asList(columns.split(",")));
}
return new TabCompletionInfo(TabCompletionInfo.MatchType.UNKNOWN, Arrays.asList(new String[0]));
}
Modified: src/test/java/nl/improved/sqlclient/SQLUtilTest.java
===================================================================
--- src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2008-01-10 19:20:50 UTC (rev 207)
+++ src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2008-01-12 10:52:04 UTC (rev 208)
@@ -186,8 +186,10 @@
assertNotNull(info);
assertEquals(TabCompletionInfo.MatchType.SQL_KEYWORD, info.getMatchType());
List<String> matches = info.getPossibleMatches();
- assertEquals(1, matches.size());
+ assertEquals(3, matches.size());
assertTrue(matches.contains("WHERE"));
+ assertTrue(matches.contains("GROUP BY"));
+ assertTrue(matches.contains("ORDER BY"));
sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WH"});
cursorPos = new Point(sqlCommand.get(0).length(),0);
@@ -195,7 +197,7 @@
assertNotNull(info);
assertEquals(TabCompletionInfo.MatchType.SQL_KEYWORD, info.getMatchType());
matches = info.getPossibleMatches();
- assertEquals(1, matches.size());
+ assertEquals(3, matches.size());
assertTrue(matches.contains("WHERE"));
assertEquals("WH", info.getStart());
}
@@ -334,6 +336,29 @@
assertEquals("a", info.getStart());
}
+ public void testGroupBy() {
+ List<String> sqlCommand = Arrays.asList(new String[]{"SELECT c1,c2 FROM A,B WHERE a.b=b.b GROUP BY "});
+ Point cursorPos = new Point(sqlCommand.get(0).length(),0);
+ TabCompletionInfo info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ List<String> matches = info.getPossibleMatches();
+ assertEquals(2, matches.size());
+ assertTrue(matches.contains("c1"));
+ assertTrue(matches.contains("c2"));
+
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT c1 , c2 FROM A,B WHERE a.b=b.b GROUP BY "});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(2, matches.size());
+ assertTrue(matches.contains("c1"));
+ assertTrue(matches.contains("c2"));
+ }
+
public void testParseTableNames() {
List<String> sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A WHERE "});
Point cursorPos = new Point(sqlCommand.get(0).length(),0);
|
|
From: SVN by r. <sv...@ca...> - 2008-01-12 11:15:05
|
Author: roy
Date: 2008-01-12 11:58:07 +0100 (Sat, 12 Jan 2008)
New Revision: 209
Modified:
src/main/java/nl/improved/sqlclient/SQLUtil.java
src/test/java/nl/improved/sqlclient/SQLUtilTest.java
Log:
added (initial) support for order by tab completion
Modified: src/main/java/nl/improved/sqlclient/SQLUtil.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLUtil.java 2008-01-12 10:52:04 UTC (rev 208)
+++ src/main/java/nl/improved/sqlclient/SQLUtil.java 2008-01-12 10:58:07 UTC (rev 209)
@@ -51,7 +51,7 @@
*/
private static final String VALUE = "('.*'|[0-9]+|"+VAR+")";
- public static List<String> KEYWORDS = Arrays.asList(new String[]{"SELECT", "UPDATE", "FROM", "WHERE", "VALUES", "SET", "INSERT", "INTO", "DELETE", "IS", "NULL", "IN", "NOT", "GROUP BY", "DESC"});
+ public static List<String> KEYWORDS = Arrays.asList(new String[]{"SELECT", "UPDATE", "FROM", "WHERE", "VALUES", "SET", "INSERT", "INTO", "DELETE", "IS", "NULL", "IN", "NOT", "GROUP BY", "ORDER BY", "DESC"});
/**
* Private constructor.
@@ -298,7 +298,8 @@
return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD
, Arrays.asList(new String[]{"AND", "OR", "IN", "GROUP BY", "ORDER BY"}));
*/
- } else if (lastKeyword.equalsIgnoreCase("GROUP BY")) {
+ } else if (lastKeyword.equalsIgnoreCase("GROUP BY")
+ || lastKeyword.equalsIgnoreCase("ORDER BY")) {
String upperStart = startOfCommand.toUpperCase();
String columns = startOfCommand.substring(upperStart.indexOf("SELECT")+"SELECT".length(), upperStart.indexOf("FROM")).replaceAll(" ","");
return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES, Arrays.asList(columns.split(",")));
Modified: src/test/java/nl/improved/sqlclient/SQLUtilTest.java
===================================================================
--- src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2008-01-12 10:52:04 UTC (rev 208)
+++ src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2008-01-12 10:58:07 UTC (rev 209)
@@ -359,6 +359,29 @@
assertTrue(matches.contains("c2"));
}
+ public void testOrderBy() {
+ List<String> sqlCommand = Arrays.asList(new String[]{"SELECT c1,c2 FROM A,B WHERE a.b=b.b ORDER BY "});
+ Point cursorPos = new Point(sqlCommand.get(0).length(),0);
+ TabCompletionInfo info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ List<String> matches = info.getPossibleMatches();
+ assertEquals(2, matches.size());
+ assertTrue(matches.contains("c1"));
+ assertTrue(matches.contains("c2"));
+
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT c1 , c2 FROM A,B WHERE a.b=b.b ORDER BY "});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(2, matches.size());
+ assertTrue(matches.contains("c1"));
+ assertTrue(matches.contains("c2"));
+ }
+
public void testParseTableNames() {
List<String> sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A WHERE "});
Point cursorPos = new Point(sqlCommand.get(0).length(),0);
|
|
From: SVN by r. <sv...@ca...> - 2008-01-30 12:05:52
|
Author: roy
Date: 2008-01-30 12:49:04 +0100 (Wed, 30 Jan 2008)
New Revision: 232
Modified:
src/main/java/nl/improved/sqlclient/SQLUtil.java
src/test/java/nl/improved/sqlclient/SQLUtilTest.java
Log:
more tab completion fixes
Modified: src/main/java/nl/improved/sqlclient/SQLUtil.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLUtil.java 2008-01-27 12:43:39 UTC (rev 231)
+++ src/main/java/nl/improved/sqlclient/SQLUtil.java 2008-01-30 11:49:04 UTC (rev 232)
@@ -236,6 +236,8 @@
// 'SELECT x FROM A,B WHERE A.x='x' AND/OR '
String tmpCommand = startOfCommand.substring(startOfCommand.indexOf(lastKeyword)+lastKeyword.length()+1);
String upperCommandString = tmpCommand.toUpperCase();
+ String VAR = "(|"+TABLE+"\\.)(|"+COLUMN+")";
+ String VALUE = "('.*'|[0-9]+|"+VAR+")";
String subPart = "(|"+VAR+"(|[\\s]+"+COMPARATOR+"[\\s]+(|"+VAR+")))";
//String regExp = "(|"+VALUE+"(|[\\s]+"+COMPARATOR+"[\\s]+(|"+VALUE+"(|([\\s]+(AND|OR)[\\s]+)))))";
String regExp = "(|"+VALUE+"(|[\\s]*"+COMPARATOR+"[\\s]*(|"+VALUE+"(|([\\s]+(AND|OR)[\\s]+(|"+VALUE+"(|[\\s]*"+COMPARATOR+"[\\s]*(|"+VALUE+"))))*))))";
@@ -255,7 +257,7 @@
return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES
, parseTableNames(commandInfo, commandPoint), end);
}
- //System.out.println("'"+upperCommandString +"'\n not matches\n"+regExp);
+ System.out.println("'"+upperCommandString +"'\n not matches\n"+regExp);
String end = "";
if (upperCommandString.matches(".*[\\s]+")) {
end = "";
Modified: src/test/java/nl/improved/sqlclient/SQLUtilTest.java
===================================================================
--- src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2008-01-27 12:43:39 UTC (rev 231)
+++ src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2008-01-30 11:49:04 UTC (rev 232)
@@ -246,6 +246,17 @@
System.out.println("I: " + info.getStart());
assertEquals("I", info.getStart());
+ sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE A."});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ //assertEquals(1, matches.size());
+ assertTrue(matches.contains("A"));
+ System.out.println("I:'" + info.getStart() +"'");
+ assertEquals("", info.getStart());
+
// with other conditions
sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE A.x = 'x' AND "});
cursorPos = new Point(sqlCommand.get(0).length(),0);
|
|
From: SVN by r. <sv...@ca...> - 2008-02-10 16:33:56
|
Author: roy
Date: 2008-02-10 16:17:36 +0100 (Sun, 10 Feb 2008)
New Revision: 233
Modified:
src/main/java/nl/improved/sqlclient/SQLUtil.java
src/test/java/nl/improved/sqlclient/SQLUtilTest.java
Log:
fixed deadlock because of a bug in the regular expression code of java
Modified: src/main/java/nl/improved/sqlclient/SQLUtil.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLUtil.java 2008-01-30 11:49:04 UTC (rev 232)
+++ src/main/java/nl/improved/sqlclient/SQLUtil.java 2008-02-10 15:17:36 UTC (rev 233)
@@ -215,7 +215,9 @@
String WHERE = "W|WH|WHE|WHER|WHERE";
String GROUP_BY = "G|GR|GRO|GROU|GROUP|GROUP |GROUP B|GROUP BY";
String ORDER_BY = "O|OR|ORD|ORDE|ORDER|ORDER |ORDER B|ORDER BY";
- if (tmpCommand.matches("[\\s]*"+VAR+"+([\\s]*,[\\s]*"+VAR+"+)*[\\s]+(|"+WHERE+"|"+GROUP_BY+"|"+ORDER_BY+")")) {
+ //String regexpSQL = "[\\s]*"+VAR+"+([\\s]*,[\\s]*"+VAR+"+)*[\\s]+(|"+WHERE+"|"+GROUP_BY+"|"+ORDER_BY+")";
+ String regexpSQL = ".*"+VAR+"[\\s]+(|"+WHERE+"|"+GROUP_BY+"|"+ORDER_BY+")";
+ if (tmpCommand.matches(regexpSQL)) {
String end = startOfCommand.substring(startOfCommand.lastIndexOf(' ')+1);
return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD
, Arrays.asList(new String[]{"WHERE", "GROUP BY", "ORDER BY"}), end);
@@ -257,7 +259,7 @@
return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES
, parseTableNames(commandInfo, commandPoint), end);
}
- System.out.println("'"+upperCommandString +"'\n not matches\n"+regExp);
+ //System.out.println("'"+upperCommandString +"'\n not matches\n"+regExp);
String end = "";
if (upperCommandString.matches(".*[\\s]+")) {
end = "";
Modified: src/test/java/nl/improved/sqlclient/SQLUtilTest.java
===================================================================
--- src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2008-01-30 11:49:04 UTC (rev 232)
+++ src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2008-02-10 15:17:36 UTC (rev 233)
@@ -160,6 +160,24 @@
assertEquals(0, matches.size());
assertEquals("B", info.getStart());
+ sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B,C"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.TABLE_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(0, matches.size());
+ assertEquals("C", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"select * from testdata, TESTDATA, TESTDATA, t"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.TABLE_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(0, matches.size());
+ assertEquals("t", info.getStart());
+
sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A WHERE 1=1"});
cursorPos = new Point("SELECT * FROM A".length(),0);
info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
@@ -243,7 +261,7 @@
matches = info.getPossibleMatches();
//assertEquals(1, matches.size());
assertTrue(matches.contains("A"));
- System.out.println("I: " + info.getStart());
+ //System.out.println("I: " + info.getStart());
assertEquals("I", info.getStart());
sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE A."});
@@ -254,7 +272,7 @@
matches = info.getPossibleMatches();
//assertEquals(1, matches.size());
assertTrue(matches.contains("A"));
- System.out.println("I:'" + info.getStart() +"'");
+ //System.out.println("I:'" + info.getStart() +"'");
assertEquals("", info.getStart());
// with other conditions
|
|
From: SVN by r. <sv...@ca...> - 2008-03-03 07:39:31
|
Author: roy
Date: 2008-03-03 08:39:20 +0100 (Mon, 03 Mar 2008)
New Revision: 248
Modified:
src/main/java/nl/improved/sqlclient/SQLUtil.java
src/test/java/nl/improved/sqlclient/SQLUtilTest.java
Log:
more tab completion issues fixed
Modified: src/main/java/nl/improved/sqlclient/SQLUtil.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLUtil.java 2008-03-02 14:09:51 UTC (rev 247)
+++ src/main/java/nl/improved/sqlclient/SQLUtil.java 2008-03-03 07:39:20 UTC (rev 248)
@@ -45,13 +45,13 @@
/**
* SQL Comparators.
*/
- private static final String COMPARATOR = "(IN|=|<>|<|>)";
+ private static final String COMPARATOR = "(=|<>|<|>)";
/**
* A sql variable description.
*/
private static final String VALUE = "('.*'|[0-9]+|"+VAR+")";
- public static List<String> KEYWORDS = Arrays.asList(new String[]{"SELECT", "UPDATE", "FROM", "WHERE", "VALUES", "SET", "INSERT", "INTO", "DELETE", "IS", "NULL", "IN", "NOT", "GROUP BY", "ORDER BY", "DESC"});
+ public static List<String> KEYWORDS = Arrays.asList(new String[]{"SELECT", "UPDATE", "FROM", "WHERE", "VALUES", "SET", "INSERT", "INTO", "DELETE", "GROUP BY", "ORDER BY", "DESC"});
/**
* Private constructor.
@@ -240,15 +240,11 @@
String upperCommandString = tmpCommand.toUpperCase();
String VAR = "(|"+TABLE+"\\.)(|"+COLUMN+")";
String VALUE = "('.*'|[0-9]+|"+VAR+")";
- String subPart = "(|"+VAR+"(|[\\s]+"+COMPARATOR+"[\\s]+(|"+VAR+")))";
- //String regExp = "(|"+VALUE+"(|[\\s]+"+COMPARATOR+"[\\s]+(|"+VALUE+"(|([\\s]+(AND|OR)[\\s]+)))))";
- String regExp = "(|"+VALUE+"(|[\\s]*"+COMPARATOR+"[\\s]*(|"+VALUE+"(|([\\s]+(AND|OR)[\\s]+(|"+VALUE+"(|[\\s]*"+COMPARATOR+"[\\s]*(|"+VALUE+"))))*))))";
+ // VALUE COMPERATOR VALUE
+ // VALUE IN (.*)
+
+ String regExp = "(|"+VALUE+"(|[\\s]*"+COMPARATOR+"[\\s]*(|"+VALUE+"(|([\\s]+(AND|OR)[\\s]+(|"+VALUE+"(|[\\s]*"+COMPARATOR+"[\\s]*(|"+VALUE+"))))*))|[\\s]*IN[\\s]*(.*)[\\s]*))";
if (upperCommandString.matches(regExp)) {
-/* String end = tmpCommand.substring(tmpCommand.lastIndexOf(' ')+1);
- if (end.indexOf(".") > 0) {
- end = end.substring(end.indexOf(".")+1);
- }
-*/
int lastIndex = tmpCommand.lastIndexOf(' ');
lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('.'));
lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('\t'));
@@ -259,7 +255,7 @@
return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES
, parseTableNames(commandInfo, commandPoint), end);
}
- //System.out.println("'"+upperCommandString +"'\n not matches\n"+regExp);
+ //else System.out.println("'"+upperCommandString +"'\n not matches\n"+regExp);
String end = "";
if (upperCommandString.matches(".*[\\s]+")) {
end = "";
@@ -273,35 +269,6 @@
}
return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD
, Arrays.asList(new String[]{"AND", "OR", "IN", "GROUP BY", "ORDER BY"}), end);
- /*String tmpCommand = startOfCommand.substring(startOfCommand.indexOf(lastKeyword)+lastKeyword.length()+1).toUpperCase();
- if (startOfCommand.trim().endsWith(lastKeyword)
- || tmpCommand.matches(".*(AND|OR)(|[\\s]+(|"+VAR+"))")) {
- int beginIndex = startOfCommand.lastIndexOf(lastKeyword) + lastKeyword.length();
- if (startOfCommand.endsWith(" ")) {
- return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES
- , parseTableNames(commandInfo, commandPoint));
- } else {
- int lastSpace = startOfCommand.lastIndexOf(' ');
- return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES
- , parseTableNames(commandInfo, commandPoint), startOfCommand.substring(lastSpace+1));
- }
- }
- if (tmpCommand.matches(VAR+"[\\s]*(|(|("+COMPARATOR+")[\\s]*"+VALUE+"*))")) {
- String tmp = startOfCommand.substring(Math.max(startOfCommand.lastIndexOf(',')+1
- , startOfCommand.lastIndexOf(' ')+1));
- List<String> tableNames;
- if (tmp.indexOf('.') > 0) {
- tableNames = Arrays.asList(new String[]{tmp.substring(0, tmp.indexOf('.'))});
- tmp = tmp.substring(tmp.indexOf('.')+1);
- } else {
- tableNames = parseTableNames(commandInfo, commandPoint);
- }
- return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES
- , tableNames, tmp);
- }
- return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD
- , Arrays.asList(new String[]{"AND", "OR", "IN", "GROUP BY", "ORDER BY"}));
- */
} else if (lastKeyword.equalsIgnoreCase("GROUP BY")
|| lastKeyword.equalsIgnoreCase("ORDER BY")) {
String upperStart = startOfCommand.toUpperCase();
Modified: src/test/java/nl/improved/sqlclient/SQLUtilTest.java
===================================================================
--- src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2008-03-02 14:09:51 UTC (rev 247)
+++ src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2008-03-03 07:39:20 UTC (rev 248)
@@ -363,6 +363,17 @@
matches = info.getPossibleMatches();
assertTrue(matches.contains("AND"));
assertEquals("a", info.getStart());
+
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE c in('c','d','e') and A.x"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ assertEquals("WHERE", SQLUtil.getLastKeyWord(sqlCommand.get(0)));
+ info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertTrue(matches.contains("A"));
+ assertEquals("x", info.getStart());
}
public void testGroupBy() {
@@ -386,6 +397,25 @@
assertEquals(2, matches.size());
assertTrue(matches.contains("c1"));
assertTrue(matches.contains("c2"));
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT c1 , c2 FROM A,B WHERE a.b=b.b GROUP BY c"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(2, matches.size());
+ assertTrue(matches.contains("c1"));
+ assertTrue(matches.contains("c2"));
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT c1 , c2 FROM A,B WHERE a.b=b.b GROUP BY c1, "});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(2, matches.size());
+ assertTrue(matches.contains("c2"));
}
public void testOrderBy() {
|
|
From: SVN by r. <sv...@ca...> - 2008-04-04 11:07:17
|
Author: roy
Date: 2008-04-04 13:07:07 +0200 (Fri, 04 Apr 2008)
New Revision: 258
Modified:
src/main/java/nl/improved/sqlclient/SQLUtil.java
src/test/java/nl/improved/sqlclient/SQLUtilTest.java
Log:
added test for like with tabcompletion
Modified: src/main/java/nl/improved/sqlclient/SQLUtil.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLUtil.java 2008-04-03 13:20:14 UTC (rev 257)
+++ src/main/java/nl/improved/sqlclient/SQLUtil.java 2008-04-04 11:07:07 UTC (rev 258)
@@ -45,7 +45,7 @@
/**
* SQL Comparators.
*/
- private static final String COMPARATOR = "(=|<>|<|>)";
+ private static final String COMPARATOR = "(=|<>|<|>|LIKE)";
/**
* A sql variable description.
*/
@@ -242,7 +242,6 @@
String VALUE = "('.*'|[0-9]+|"+VAR+")";
// VALUE COMPERATOR VALUE
// VALUE IN (.*)
-
String regExp = "(|"+VALUE+"(|[\\s]*"+COMPARATOR+"[\\s]*(|"+VALUE+"(|([\\s]+(AND|OR)[\\s]+(|"+VALUE+"(|[\\s]*"+COMPARATOR+"[\\s]*(|"+VALUE+"))))*))|[\\s]*IN[\\s]*(.*)[\\s]*))";
if (upperCommandString.matches(regExp)) {
int lastIndex = tmpCommand.lastIndexOf(' ');
Modified: src/test/java/nl/improved/sqlclient/SQLUtilTest.java
===================================================================
--- src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2008-04-03 13:20:14 UTC (rev 257)
+++ src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2008-04-04 11:07:07 UTC (rev 258)
@@ -364,7 +364,6 @@
assertTrue(matches.contains("AND"));
assertEquals("a", info.getStart());
-
sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE c in('c','d','e') and A.x"});
cursorPos = new Point(sqlCommand.get(0).length(),0);
assertEquals("WHERE", SQLUtil.getLastKeyWord(sqlCommand.get(0)));
@@ -374,6 +373,16 @@
matches = info.getPossibleMatches();
assertTrue(matches.contains("A"));
assertEquals("x", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE c like 'a%' and A.x"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ assertEquals("WHERE", SQLUtil.getLastKeyWord(sqlCommand.get(0)));
+ info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertTrue(matches.contains("A"));
+ assertEquals("x", info.getStart());
}
public void testGroupBy() {
|
|
From: SVN by r. <sv...@ca...> - 2008-09-04 12:32:20
|
Author: roy
Date: 2008-09-04 14:32:02 +0200 (Thu, 04 Sep 2008)
New Revision: 303
Modified:
src/main/java/nl/improved/sqlclient/SQLUtil.java
src/test/java/nl/improved/sqlclient/SQLUtilTest.java
Log:
improve some tabcompletion
Modified: src/main/java/nl/improved/sqlclient/SQLUtil.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLUtil.java 2008-09-01 09:53:07 UTC (rev 302)
+++ src/main/java/nl/improved/sqlclient/SQLUtil.java 2008-09-04 12:32:02 UTC (rev 303)
@@ -246,14 +246,19 @@
String regExp = "(|"+VALUE+"(|[\\s]*"+COMPARATOR+"[\\s]*(|"+VALUE+"(|([\\s]+(AND|OR)[\\s]+(|"+VALUE+"(|[\\s]*"+COMPARATOR+"[\\s]*(|"+VALUE+"))))*))|[\\s]*IN[\\s]*(.*)[\\s]*))";
if (upperCommandString.matches(regExp)) {
int lastIndex = tmpCommand.lastIndexOf(' ');
- lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('.'));
lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('\t'));
lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('='));
lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('>'));
lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('>'));
+ int lastBreakIndex = lastIndex;
+ lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('.'));
String end = tmpCommand.substring(lastIndex+1);
+ if (lastBreakIndex < 0) lastBreakIndex = 0;
+ List tableNames = (lastIndex > lastBreakIndex) && lastBreakIndex >=0 ?
+ Arrays.asList(new String[]{tmpCommand.substring(lastBreakIndex,lastIndex).trim()}) :
+ parseTableNames(commandInfo, commandPoint);
return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES
- , parseTableNames(commandInfo, commandPoint), end);
+ , tableNames, end);
}
//else System.out.println("'"+upperCommandString +"'\n not matches\n"+regExp);
String end = "";
Modified: src/test/java/nl/improved/sqlclient/SQLUtilTest.java
===================================================================
--- src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2008-09-01 09:53:07 UTC (rev 302)
+++ src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2008-09-04 12:32:02 UTC (rev 303)
@@ -371,7 +371,7 @@
assertNotNull(info);
assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
matches = info.getPossibleMatches();
- assertTrue(matches.contains("A"));
+ assertTrue(matches.toString(), matches.contains("A"));
assertEquals("x", info.getStart());
sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE c like 'a%' and A.x"});
@@ -509,6 +509,18 @@
assertEquals("", info.getStart());
}
+ public void testGetTableName() {
+ List<String> sqlCommand = Arrays.asList(new String[]{"select * from a where mytable.b"});
+ Point cursorPos = new Point(sqlCommand.get(0).length(),0);
+ TabCompletionInfo info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ List<String> matches = info.getPossibleMatches();
+ assertEquals(1, matches.size());
+ assertEquals("b", info.getStart());
+ assertTrue("Table name should match 'mytable', but was " + matches.get(0), matches.contains("mytable"));
+ }
+
/* public void testTabCompletionInfoDESC() {
List<String> sqlCommand = Arrays.asList(new String[]{"DESC "});
Point cursorPos = new Point(sqlCommand.get(0).length(),0);
|
|
From: SVN by r. <sv...@ca...> - 2009-12-08 10:15:04
|
Author: roy
Date: 2009-12-08 11:14:51 +0100 (Tue, 08 Dec 2009)
New Revision: 431
Modified:
src/main/java/nl/improved/sqlclient/SQLUtil.java
src/test/java/nl/improved/sqlclient/SQLUtilTest.java
Log:
some tab completion fixes
Modified: src/main/java/nl/improved/sqlclient/SQLUtil.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLUtil.java 2009-12-08 10:14:25 UTC (rev 430)
+++ src/main/java/nl/improved/sqlclient/SQLUtil.java 2009-12-08 10:14:51 UTC (rev 431)
@@ -282,12 +282,44 @@
} else if (lastKeyword.equalsIgnoreCase("GROUP BY")
|| lastKeyword.equalsIgnoreCase("ORDER BY")) {
String upperStart = startOfCommand.toUpperCase();
- String columns = startOfCommand.substring(upperStart.indexOf("SELECT")+"SELECT".length(), upperStart.indexOf("FROM")).replaceAll(" ","");
- return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES, Arrays.asList(columns.split(",")));
+ //String columns = startOfCommand.substring(upperStart.indexOf("SELECT")+"SELECT".length(), upperStart.indexOf("FROM")).replaceAll(" ","");
+ String columns = startOfCommand.substring(upperStart.indexOf("SELECT")+"SELECT".length(), upperStart.indexOf("FROM"));
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES, getColumns(columns));
}
return new TabCompletionInfo(TabCompletionInfo.MatchType.OTHER, Arrays.asList(new String[0]));
}
+ static List<String> getColumns(String columnsString) {
+ int charOpenCount = 0;
+ int roundOpenCount = 0;
+ List<String> result = new ArrayList<String>();
+ StringBuffer tmp = new StringBuffer();
+ for (int i = 0; i < columnsString.length(); i++) {
+ char c = columnsString.charAt(i);
+ if (c == '(') {
+ roundOpenCount++;
+ tmp.append(c);
+ } else if (c == ')') {
+ roundOpenCount--;
+ tmp.append(c);
+ } else if (c == '\'') {
+ charOpenCount++;
+ tmp.append(c);
+ } else if (c == ',' && charOpenCount % 2 == 0 && roundOpenCount == 0) {
+ result.add(tmp.toString().trim());
+ tmp = new StringBuffer();
+ } else {
+ tmp.append(c);
+ }
+ }
+ if (tmp.length() > 0) {
+ result.add(tmp.toString().trim());
+ }
+
+ return result;
+
+ }
+
public static String getStartOfCommand(List<? extends CharSequence> commandInfo, Point commandPoint) {
StringBuffer buff = new StringBuffer();
for (int i = 0; i <= commandPoint.y; i++) {
Modified: src/test/java/nl/improved/sqlclient/SQLUtilTest.java
===================================================================
--- src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2009-12-08 10:14:25 UTC (rev 430)
+++ src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2009-12-08 10:14:51 UTC (rev 431)
@@ -27,6 +27,21 @@
public SQLUtilTest() {
}
+ public void testGetColumns() {
+ String columns = "A, B";
+ List<String> result = SQLUtil.getColumns(columns);
+ assertNotNull(result);
+ assertEquals(2, result.size());
+ assertTrue(result.contains("A"));
+ assertTrue(result.contains("B"));
+
+ columns = "A, to_char(datein, 'yyyy')";
+ result = SQLUtil.getColumns(columns);
+ assertNotNull(result);
+ assertEquals(2, result.size());
+ assertTrue(result.contains("A"));
+ assertTrue(result.toString(), result.contains("to_char(datein, 'yyyy')"));
+ }
public void testGetLastKeyWord() {
String sql = "SELECT *";
assertEquals("SELECT", SQLUtil.getLastKeyWord(sql));
@@ -425,6 +440,15 @@
matches = info.getPossibleMatches();
assertEquals(2, matches.size());
assertTrue(matches.contains("c2"));
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT c1 , to_char(datein, 'yyyymmdd') FROM A,B WHERE a.b=b.b GROUP BY c1, "});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(2, matches.size());
+ assertTrue(matches.toString(), matches.contains("to_char(datein, 'yyyymmdd')"));
}
public void testOrderBy() {
|
|
From: SVN by r. <sv...@ca...> - 2009-12-08 10:19:12
|
Author: roy
Date: 2009-12-08 11:18:57 +0100 (Tue, 08 Dec 2009)
New Revision: 432
Modified:
src/main/java/nl/improved/sqlclient/SQLUtil.java
src/test/java/nl/improved/sqlclient/SQLUtilTest.java
Log:
small fixx
Modified: src/main/java/nl/improved/sqlclient/SQLUtil.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLUtil.java 2009-12-08 10:14:51 UTC (rev 431)
+++ src/main/java/nl/improved/sqlclient/SQLUtil.java 2009-12-08 10:18:57 UTC (rev 432)
@@ -292,7 +292,16 @@
static List<String> getColumns(String columnsString) {
int charOpenCount = 0;
int roundOpenCount = 0;
- List<String> result = new ArrayList<String>();
+ List<String> result = new ArrayList<String>() {
+
+ @Override
+ public boolean add(String e) {
+ if (e.toUpperCase().indexOf(" AS ") > 0) {
+ e = e.substring(0, e.toUpperCase().indexOf(" AS")).trim();
+ }
+ return super.add(e);
+ }
+ };
StringBuffer tmp = new StringBuffer();
for (int i = 0; i < columnsString.length(); i++) {
char c = columnsString.charAt(i);
Modified: src/test/java/nl/improved/sqlclient/SQLUtilTest.java
===================================================================
--- src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2009-12-08 10:14:51 UTC (rev 431)
+++ src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2009-12-08 10:18:57 UTC (rev 432)
@@ -449,6 +449,15 @@
matches = info.getPossibleMatches();
assertEquals(2, matches.size());
assertTrue(matches.toString(), matches.contains("to_char(datein, 'yyyymmdd')"));
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT c1 , to_char(datein, 'yyyymmdd') AS D FROM A,B WHERE a.b=b.b GROUP BY c1, "});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(2, matches.size());
+ assertTrue(matches.toString(), matches.contains("to_char(datein, 'yyyymmdd')"));
}
public void testOrderBy() {
|
|
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;
+ }
+ }
+
+}
|