|
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() {
|