You can subscribe to this list here.
| 2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(8) |
Oct
(34) |
Nov
(7) |
Dec
(2) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2008 |
Jan
(29) |
Feb
(10) |
Mar
(14) |
Apr
(4) |
May
(2) |
Jun
|
Jul
(14) |
Aug
(25) |
Sep
(6) |
Oct
(18) |
Nov
(4) |
Dec
(14) |
| 2009 |
Jan
(28) |
Feb
(15) |
Mar
(15) |
Apr
(8) |
May
|
Jun
|
Jul
(1) |
Aug
(4) |
Sep
(12) |
Oct
(1) |
Nov
|
Dec
(22) |
| 2010 |
Jan
(14) |
Feb
|
Mar
(2) |
Apr
|
May
(7) |
Jun
|
Jul
(3) |
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
|
|
From: SVN by r. <sv...@ca...> - 2009-03-31 19:41:11
|
Author: roy
Date: 2009-03-31 21:40:54 +0200 (Tue, 31 Mar 2009)
New Revision: 400
Modified:
src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java
Log:
removed function calls
Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2009-03-31 19:39:40 UTC (rev 399)
+++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2009-03-31 19:40:54 UTC (rev 400)
@@ -62,7 +62,7 @@
import nl.improved.sqlclient.history.exception.CouldNotSaveHistoryException;
import nl.improved.sqlclient.util.Function;
import nl.improved.sqlclient.util.LimitedArrayList;
-import nl.improved.sqlclient.util.oracle.Functions;
+//import nl.improved.sqlclient.util.oracle.Functions;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -1020,7 +1020,7 @@
return nullToEmpty(findMatch(getTableNames(), info.getStart()));
}
if (info.getMatchType() == TabCompletionInfo.MatchType.COLUMN_NAMES) {
- if (info.getStart().length() > 0) {
+ /*if (info.getStart().length() > 0) {
try {
List<Function> functions = Functions.getFunctionMatches(getConnection(), info.getStart());
if (functions.size() > 0) {
@@ -1029,7 +1029,7 @@
} catch (SQLException ex) {
Logger.getLogger(AbstractSQLShellWindow.class.getName()).log(Level.SEVERE, null, ex);
}
- }
+ }*/
return nullToEmpty(findMatch(getColumnNames(info.getPossibleMatches()), info.getStart()));
}
if (info.getMatchType() == TabCompletionInfo.MatchType.OTHER) {
|
|
From: SVN by r. <sv...@ca...> - 2009-03-31 19:41:10
|
Author: roy
Date: 2009-03-31 21:41:04 +0200 (Tue, 31 Mar 2009)
New Revision: 401
Modified:
src/test/java/nl/improved/sqlclient/util/SQLParserTest.java
Log:
update test
Modified: src/test/java/nl/improved/sqlclient/util/SQLParserTest.java
===================================================================
--- src/test/java/nl/improved/sqlclient/util/SQLParserTest.java 2009-03-31 19:40:54 UTC (rev 400)
+++ src/test/java/nl/improved/sqlclient/util/SQLParserTest.java 2009-03-31 19:41:04 UTC (rev 401)
@@ -217,6 +217,16 @@
matches = info.getPossibleMatches();
assertEquals(0, matches.size());
assertEquals("B", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT test FROM A"});
+ cursorPos = new Point("SELECT ".length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(1, matches.size());
+ assertTrue(matches.contains("A"));
+ assertEquals("", info.getStart());
}
public void testTabCompletionInfoFROM() {
|
|
From: SVN by r. <sv...@ca...> - 2009-03-31 19:39:47
|
Author: roy
Date: 2009-03-31 21:39:40 +0200 (Tue, 31 Mar 2009)
New Revision: 399
Added:
src/main/java/nl/improved/sqlclient/util/Function.java
Log:
very initial stuff for fuction support
Added: src/main/java/nl/improved/sqlclient/util/Function.java
===================================================================
--- src/main/java/nl/improved/sqlclient/util/Function.java 2009-03-31 19:38:19 UTC (rev 398)
+++ src/main/java/nl/improved/sqlclient/util/Function.java 2009-03-31 19:39:40 UTC (rev 399)
@@ -0,0 +1,62 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package nl.improved.sqlclient.util;
+
+/**
+ *
+ * @author roy
+ */
+public class Function {
+ private FunctionArg[] types;
+ private String name;
+
+ public Function(String name, int... types) {
+ this.name = name;
+ this.types = new FunctionArg[types.length];
+ for (int i = 0; i < types.length; i++) {
+ this.types[i] = new FunctionArg(types[i]);
+ }
+ }
+
+ public Function(String name, FunctionArg... types) {
+ this.name = name;
+ this.types = types;
+ }
+
+
+ public int getArgumentCount() {
+ return types == null ? 0 : types.length;
+ }
+
+ public FunctionArg getArgumentType(int arg) {
+ return types[arg];
+ }
+
+ public boolean matches(CharSequence s) {
+ return s.length() > 0 && name.startsWith(s.toString());
+ }
+
+ public class FunctionArg {
+ private int type;
+ private String help;
+ public FunctionArg(int type) {
+ this.type = type;
+
+ }
+ public FunctionArg(int type, String help) {
+ this.type = type;
+ this.help = help;
+ }
+
+ public int getType() {
+ return type;
+ }
+
+ public String getHelp() {
+ return help;
+ }
+ }
+}
|
|
From: SVN by r. <sv...@ca...> - 2009-03-31 19:38:36
|
Author: roy
Date: 2009-03-31 21:38:19 +0200 (Tue, 31 Mar 2009)
New Revision: 398
Modified:
src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java
src/main/java/nl/improved/sqlclient/util/SQLParser.java
Log:
tab completion fixes in select
Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2009-03-26 18:49:51 UTC (rev 397)
+++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2009-03-31 19:38:19 UTC (rev 398)
@@ -60,7 +60,9 @@
import nl.improved.sqlclient.history.HistoryPersister;
import nl.improved.sqlclient.history.exception.CouldNotLoadHistoryException;
import nl.improved.sqlclient.history.exception.CouldNotSaveHistoryException;
+import nl.improved.sqlclient.util.Function;
import nl.improved.sqlclient.util.LimitedArrayList;
+import nl.improved.sqlclient.util.oracle.Functions;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -727,6 +729,7 @@
}
CharSequence newText;
if (inp.getCharacter() == '\t') {
+ new Throwable().printStackTrace();
try {
Point cursorPosition = screen.getCursorPosition();
newText = getTabCompletion(commandLines, cursorPosition);
@@ -1017,6 +1020,16 @@
return nullToEmpty(findMatch(getTableNames(), info.getStart()));
}
if (info.getMatchType() == TabCompletionInfo.MatchType.COLUMN_NAMES) {
+ if (info.getStart().length() > 0) {
+ try {
+ List<Function> functions = Functions.getFunctionMatches(getConnection(), info.getStart());
+ if (functions.size() > 0) {
+ debug("Found function matches: "+ functions);
+ }
+ } catch (SQLException ex) {
+ Logger.getLogger(AbstractSQLShellWindow.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
return nullToEmpty(findMatch(getColumnNames(info.getPossibleMatches()), info.getStart()));
}
if (info.getMatchType() == TabCompletionInfo.MatchType.OTHER) {
Modified: src/main/java/nl/improved/sqlclient/util/SQLParser.java
===================================================================
--- src/main/java/nl/improved/sqlclient/util/SQLParser.java 2009-03-26 18:49:51 UTC (rev 397)
+++ src/main/java/nl/improved/sqlclient/util/SQLParser.java 2009-03-31 19:38:19 UTC (rev 398)
@@ -7,6 +7,7 @@
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import nl.improved.sqlclient.Point;
import nl.improved.sqlclient.SQLCommand;
@@ -311,11 +312,12 @@
return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES, getTableNames(parts), end);
}
- private static TabCompletionInfo getSelectTabCompletionInfo(SQLPart part, List<SQLPart> parts, int position) {
+ private static TabCompletionInfo getSelectTabCompletionInfo(SQLPart part, List<SQLPart> parts, int charsLeft) {
// if it looks like:
// SELECT x
// return "FROM"
- String startOfCommand = part.getPart().toString();
+ String stringPart = part.getPart().toString();
+ String startOfCommand = stringPart.substring(0, charsLeft);
String upCommand = startOfCommand.toUpperCase();
if (upCommand.equals("SELECT")) {
return new TabCompletionInfo(TabCompletionInfo.MatchType.OTHER
@@ -347,6 +349,11 @@
, Arrays.asList(new String[]{tableName.substring(0,tableName.indexOf('.'))})
, tableName.substring(tableName.indexOf('.')+1));
}
+ List<String> tableNames = getTableNames(parts);
+ if (tableNames.size() > 0) {
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES
+ , tableNames, tableName);
+ }
return new TabCompletionInfo(TabCompletionInfo.MatchType.TABLE_NAMES
, Arrays.asList(new String[0]), tableName);
}
@@ -413,6 +420,9 @@
tableNamesSqlPart = tmpPart;
}
}
+ if (tableNamesSqlPart == null) {
+ return Collections.emptyList();
+ }
return tableNamesSqlPart.getTableNames();
}
|
|
From: SVN by r. <sv...@ca...> - 2009-03-26 18:50:00
|
Author: roy
Date: 2009-03-26 19:49:51 +0100 (Thu, 26 Mar 2009)
New Revision: 397
Modified:
src/main/java/nl/improved/sqlclient/util/SQLParser.java
src/main/java/nl/improved/sqlclient/util/SQLPart.java
src/test/java/nl/improved/sqlclient/util/SQLParserTest.java
Log:
added support for tab completion for 'insert into' sql statements
Modified: src/main/java/nl/improved/sqlclient/util/SQLParser.java
===================================================================
--- src/main/java/nl/improved/sqlclient/util/SQLParser.java 2009-03-16 08:38:36 UTC (rev 396)
+++ src/main/java/nl/improved/sqlclient/util/SQLParser.java 2009-03-26 18:49:51 UTC (rev 397)
@@ -93,6 +93,10 @@
return getUpdateTabCompletionInfo(part, parts, charsLeft);
case SET :
return getSetTabCompletionInfo(part, parts, charsLeft);
+ case INSERT :
+ return getInsertTabCompletionInfo(part, parts, charsLeft);
+ case VALUES :
+ return getValuesTabCompletionInfo(part, parts, charsLeft);
}
} else {
charsLeft -=part.getPart().length();
@@ -164,6 +168,13 @@
if (sql.matches(".*[\\s]*WHERE.*")) {
end = sql.indexOf("WHERE");
}
+ } else if (sql.matches("[\\s]*INSERT INTO.*")) {
+ sqlType = SQLPart.SQLType.INSERT;
+ if (sql.matches(".*[\\s]*VALUES.*")) {
+ end = sql.indexOf("VALUES");
+ }
+ } else if (sql.matches("[\\s]*VALUES.*")) {
+ sqlType = SQLPart.SQLType.VALUES;
} else {
sqlType = SQLPart.SQLType.OTHER;
}
@@ -258,6 +269,36 @@
return new TabCompletionInfo(TabCompletionInfo.MatchType.OTHER, possibleMatches, end);
}
+ private static TabCompletionInfo getInsertTabCompletionInfo(SQLPart part, List<SQLPart> parts, int charsLeft) {
+ String startOfCommand = part.getPart().toString().substring(0, charsLeft);
+ if (startOfCommand.equalsIgnoreCase("INSERT INTO")) {
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.OTHER
+ , Arrays.asList(new String[]{" "}));
+ }
+ String tmpCommand = startOfCommand.substring(startOfCommand.toUpperCase().indexOf("INSERT INTO")+"INSERT INTO".length()+1);
+ if (tmpCommand.toUpperCase().matches("[\\s]*"+TABLE+"[\\s]+")) {
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.OTHER
+ , Arrays.asList(new String[]{"(", "VALUES"}));
+ }
+ if (tmpCommand.indexOf('(') >=0 && tmpCommand.indexOf(')') < 0) {
+ String start;
+ if (tmpCommand.indexOf(',') > 0) {
+ start = tmpCommand.substring(tmpCommand.lastIndexOf(',')+1);
+ } else {
+ start = tmpCommand.substring(tmpCommand.indexOf('(')+1);
+ }
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES
+ , getTableNames(parts), start.trim());
+ }
+ if (tmpCommand.indexOf(')') > 0) {
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD
+ , Arrays.asList(new String[]{"VALUES"}), tmpCommand.substring(tmpCommand.lastIndexOf(')')+1).trim());
+ }
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.TABLE_NAMES
+ , Arrays.asList(new String[]{}), tmpCommand.trim());
+
+ }
+
private static TabCompletionInfo getOrderByTabCompletionInfo(SQLPart part, List<SQLPart> parts, int charsLeft) {
String stringPart = part.getPart().toString();
String subPart = stringPart.substring(stringPart.toUpperCase().indexOf("ORDER BY")+"ORDER BY".length(), charsLeft);
@@ -366,13 +407,13 @@
return alias;
}
private static List<String> getTableNames(List<SQLPart> parts) {
- SQLPart fromSqlPart = null;
+ SQLPart tableNamesSqlPart = null;
for (SQLPart tmpPart : parts) {
- if (tmpPart.getSQLType() == SQLPart.SQLType.FROM || tmpPart.getSQLType() == SQLPart.SQLType.UPDATE) {
- fromSqlPart = tmpPart;
+ if (tmpPart.getSQLType() == SQLPart.SQLType.FROM || tmpPart.getSQLType() == SQLPart.SQLType.UPDATE || tmpPart.getSQLType() == SQLPart.SQLType.INSERT) {
+ tableNamesSqlPart = tmpPart;
}
}
- return fromSqlPart.getTableNames();
+ return tableNamesSqlPart.getTableNames();
}
private static TabCompletionInfo getUpdateTabCompletionInfo(SQLPart part, List<SQLPart> parts, int charsLeft) {
@@ -387,6 +428,26 @@
, new ArrayList(), tmpCommand.trim());
}
+ private static TabCompletionInfo getValuesTabCompletionInfo(SQLPart part, List<SQLPart> parts, int charsLeft) {
+ String startOfCommand = part.getPart().toString().substring(0, charsLeft);
+ if (startOfCommand.equalsIgnoreCase("VALUES")) {
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.OTHER
+ , Arrays.asList(new String[]{" ", "("}));
+ }
+ String tmpCommand = startOfCommand.substring(startOfCommand.toUpperCase().indexOf("VALUES")+"VALUES".length());
+ if (tmpCommand.indexOf('(') < 0) {
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.OTHER
+ , Arrays.asList(new String[]{"("}));
+ }
+ tmpCommand = tmpCommand.substring(tmpCommand.indexOf('(')+1);
+ if (tmpCommand.indexOf(',') > 0) {
+ tmpCommand = tmpCommand.substring(tmpCommand.lastIndexOf(',')+1);
+ }
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES
+ , getTableNames(parts), tmpCommand);
+
+ }
+
private static TabCompletionInfo getWhereTabCompletionInfo(SQLPart part, List<SQLPart> parts, int charsLeft) {
// find out if it looks like
// 'SELECT x FROM A,B WHERE'
Modified: src/main/java/nl/improved/sqlclient/util/SQLPart.java
===================================================================
--- src/main/java/nl/improved/sqlclient/util/SQLPart.java 2009-03-16 08:38:36 UTC (rev 396)
+++ src/main/java/nl/improved/sqlclient/util/SQLPart.java 2009-03-26 18:49:51 UTC (rev 397)
@@ -6,6 +6,7 @@
package nl.improved.sqlclient.util;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import nl.improved.sqlclient.TabCompletionInfo;
@@ -106,6 +107,14 @@
}
public List<String> getTableNames() {
+ if (sqlType == SQLType.INSERT) {
+ String stringPart = getPart().toString();
+ String tableName = stringPart.substring(stringPart.toUpperCase().indexOf("INSERT INTO")+"INSERT INTO".length()).trim();
+ if (tableName.indexOf(" ") > 0) {
+ tableName = tableName.substring(0, tableName.indexOf(' '));
+ }
+ return Arrays.asList(new String[]{tableName});
+ }
if (sqlType == SQLType.FROM || sqlType == SQLType.UPDATE) {
List<String> returnValue = new ArrayList<String>();
String stringPart = getPart().toString();
@@ -134,7 +143,7 @@
}
return returnValue;
}
- throw new IllegalStateException("Table names are only available for FROM,UPDATE ("+ sqlType+")");
+ throw new IllegalStateException("Table names are only available for FROM,UPDATE,INSERT INTO ("+ sqlType+")");
}
}
Modified: src/test/java/nl/improved/sqlclient/util/SQLParserTest.java
===================================================================
--- src/test/java/nl/improved/sqlclient/util/SQLParserTest.java 2009-03-16 08:38:36 UTC (rev 396)
+++ src/test/java/nl/improved/sqlclient/util/SQLParserTest.java 2009-03-26 18:49:51 UTC (rev 397)
@@ -817,6 +817,77 @@
assertEquals("", info.getStart());
}
+ public void testInsertInto() {
+ List<String> sqlCommand = Arrays.asList(new String[]{"insert into "});
+ Point cursorPos = new Point(sqlCommand.get(0).length(),0);
+ TabCompletionInfo info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.TABLE_NAMES, info.getMatchType());
+ List<String> matches = info.getPossibleMatches();
+ assertEquals(0, matches.size());
+ assertEquals("", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"insert into tab"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.TABLE_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(0, matches.size());
+ assertEquals("tab", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"insert into tab "});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.OTHER, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(2, matches.size());
+ assertTrue(matches.contains("("));
+ assertTrue(matches.contains("VALUES"));
+ assertEquals("", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"insert into tab ("});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(1, matches.size());
+ assertTrue(matches.contains("tab"));
+ assertEquals("", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"insert into tab (A"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(1, matches.size());
+ assertTrue(matches.contains("tab"));
+ assertEquals("A", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"insert into tab (A, "});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(1, matches.size());
+ assertTrue(matches.contains("tab"));
+ assertEquals("", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"insert into tab (A,b) "});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.SQL_KEYWORD, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(1, matches.size());
+ assertTrue(matches.contains("VALUES"));
+ 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);
|
|
From: SVN by r. <sv...@ca...> - 2009-03-16 08:38:46
|
Author: roy
Date: 2009-03-16 09:38:36 +0100 (Mon, 16 Mar 2009)
New Revision: 396
Modified:
src/main/java/nl/improved/sqlclient/util/SQLParser.java
src/test/java/nl/improved/sqlclient/util/SQLParserTest.java
Log:
more tab compl fixes
Modified: src/main/java/nl/improved/sqlclient/util/SQLParser.java
===================================================================
--- src/main/java/nl/improved/sqlclient/util/SQLParser.java 2009-03-15 20:44:38 UTC (rev 395)
+++ src/main/java/nl/improved/sqlclient/util/SQLParser.java 2009-03-16 08:38:36 UTC (rev 396)
@@ -47,6 +47,7 @@
List<? extends CharSequence> lines = command.getLines();
return getTabCompletionInfo(lines, commandPoint);
}
+
public static TabCompletionInfo getTabCompletionInfo(List<? extends CharSequence> lines, Point commandPoint) {
StringBuffer buf = new StringBuffer();
int position = 0;
@@ -396,13 +397,29 @@
return new TabCompletionInfo(TabCompletionInfo.MatchType.OTHER
, Arrays.asList(new String[]{" "}));
}
- String tmpCommand = startOfCommand.substring(startOfCommand.toUpperCase().indexOf("WHERE")+"WHERE".length()+1);
+ String tmpCommand = startOfCommand.substring(startOfCommand.toUpperCase().indexOf("WHERE")+"WHERE".length());
String upperCommandString = tmpCommand.toUpperCase();
+ if (upperCommandString.indexOf("AND") >= 0) {
+ String tmp = upperCommandString.substring(upperCommandString.lastIndexOf("AND")+3);
+ if (tmp.trim().length() > 0) {
+ upperCommandString = tmp;
+ }
+ }
+ if (upperCommandString.indexOf("OR") >= 0) {
+ String tmp = upperCommandString.substring(upperCommandString.lastIndexOf("OR")+2);
+ if (tmp.trim().length() > 0) {
+ upperCommandString = tmp;
+ }
+ }
+ if (upperCommandString.equals("")) {
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.OTHER
+ , Arrays.asList(new String[]{" "}));
+ }
//String VAR = "(|"+TABLE+"\\.)(|"+COLUMN+")";
//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]*))";
+ String regExp = "[\\s]*(|"+VALUE+"(|[\\s]*"+COMPARATOR+"[\\s]*(|"+VALUE+"(|([\\s]+(AND|OR)[\\s]+(|"+VALUE+"(|[\\s]*"+COMPARATOR+"[\\s]*(|"+VALUE+"))))*))|[\\s]*IN[\\s]*(.*)[\\s]*))";
if (upperCommandString.matches(regExp) || upperCommandString.endsWith(".")) {
int lastIndex = tmpCommand.lastIndexOf(' ');
lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('\t'));
Modified: src/test/java/nl/improved/sqlclient/util/SQLParserTest.java
===================================================================
--- src/test/java/nl/improved/sqlclient/util/SQLParserTest.java 2009-03-15 20:44:38 UTC (rev 395)
+++ src/test/java/nl/improved/sqlclient/util/SQLParserTest.java 2009-03-16 08:38:36 UTC (rev 396)
@@ -400,7 +400,7 @@
Point cursorPos = new Point(sqlCommand.get(0).length(),0);
TabCompletionInfo info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
assertNotNull(info);
- assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ assertEquals(info.getPossibleMatches().toString(), TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
List<String> matches = info.getPossibleMatches();
assertEquals(2, matches.size());
assertTrue(matches.contains("A"));
@@ -605,6 +605,15 @@
matches = info.getPossibleMatches();
assertTrue(matches.contains("A"));
assertEquals("", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"select * from L where s is not null and t='p' and m"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(info.getPossibleMatches().toString(), TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertTrue(matches.contains("L"));
+ assertEquals("m", info.getStart());
}
public void testGroupBy() {
|
|
From: SVN by r. <sv...@ca...> - 2009-03-15 20:44:51
|
Author: roy
Date: 2009-03-15 21:44:38 +0100 (Sun, 15 Mar 2009)
New Revision: 395
Modified:
src/main/java/nl/improved/sqlclient/util/SQLParser.java
src/test/java/nl/improved/sqlclient/util/SQLParserTest.java
Log:
set/where unit test added + fix
Modified: src/main/java/nl/improved/sqlclient/util/SQLParser.java
===================================================================
--- src/main/java/nl/improved/sqlclient/util/SQLParser.java 2009-03-14 15:23:00 UTC (rev 394)
+++ src/main/java/nl/improved/sqlclient/util/SQLParser.java 2009-03-15 20:44:38 UTC (rev 395)
@@ -160,7 +160,7 @@
}
} else if (sql.matches("[\\s]*SET.*")) {
sqlType = SQLPart.SQLType.SET;
- if (sql.matches("[\\s]*WHERE.*")) {
+ if (sql.matches(".*[\\s]*WHERE.*")) {
end = sql.indexOf("WHERE");
}
} else {
@@ -196,8 +196,6 @@
if (end.lastIndexOf(" ") >0) {
end = end.substring(end.lastIndexOf(' ')+1);
}
- System.err.println("SUB: "+"'"+ subPart+"'");
- System.err.println("END: "+ "'"+end+"'");
return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD, Arrays.asList(new String[]{"WHERE", "GROUP BY", "ORDER BY", ","}), end.trim());
}
return new TabCompletionInfo(TabCompletionInfo.MatchType.TABLE_NAMES, Arrays.asList(new String[]{}), end.trim());
@@ -423,7 +421,7 @@
return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES
, tableNames, end);
}
- if (upperCommandString.matches(".*[\\s]+(AND|OR)[\\s]+")) {
+ if (upperCommandString.matches("[\\s]*") || upperCommandString.matches(".*[\\s]+(AND|OR)[\\s]+")) {
return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES
, getTableNames(parts));
}
Modified: src/test/java/nl/improved/sqlclient/util/SQLParserTest.java
===================================================================
--- src/test/java/nl/improved/sqlclient/util/SQLParserTest.java 2009-03-14 15:23:00 UTC (rev 394)
+++ src/test/java/nl/improved/sqlclient/util/SQLParserTest.java 2009-03-15 20:44:38 UTC (rev 395)
@@ -796,6 +796,16 @@
matches = info.getPossibleMatches();
assertTrue("WHERE not in " + matches , matches.contains("WHERE"));
assertEquals("WH", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"update l set s='' where "});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(info.getPossibleMatches().toString(), TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(1, matches.size());
+ assertTrue(matches.contains("l"));
+ assertEquals("", info.getStart());
}
public void testGetTableName() {
|
|
From: SVN by r. <sv...@ca...> - 2009-03-14 15:23:19
|
Author: roy
Date: 2009-03-14 16:23:00 +0100 (Sat, 14 Mar 2009)
New Revision: 394
Modified:
src/main/java/nl/improved/sqlclient/util/SQLParser.java
src/test/java/nl/improved/sqlclient/util/SQLParserTest.java
Log:
more sqlparsing fixes
Modified: src/main/java/nl/improved/sqlclient/util/SQLParser.java
===================================================================
--- src/main/java/nl/improved/sqlclient/util/SQLParser.java 2009-03-04 11:12:53 UTC (rev 393)
+++ src/main/java/nl/improved/sqlclient/util/SQLParser.java 2009-03-14 15:23:00 UTC (rev 394)
@@ -60,7 +60,9 @@
}
if (buf.length() > 0) {
buf.append(' ');
- position++;
+ if (y <= commandPoint.y) {
+ position++;
+ }
}
buf.append(seq);
}
@@ -70,7 +72,6 @@
public static TabCompletionInfo getTabCompletionInfo(CharSequence sql, int position) {
List<SQLPart> parts = parse(sql);
- System.err.println("PARTS: "+ parts);
int charsLeft = position;
for (SQLPart part : parts) {
if (charsLeft <= part.getPart().length()) {
@@ -176,6 +177,10 @@
private static TabCompletionInfo getFromTabCompletionInfo(SQLPart part, List<SQLPart> parts, int charsLeft) {
String stringPart = part.getPart().toString();
+ if (stringPart.equalsIgnoreCase("FROM")) {
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.OTHER
+ , Arrays.asList(new String[]{" "}));
+ }
String subPart = stringPart.substring(stringPart.toUpperCase().indexOf("FROM") +"FROM".length(), charsLeft);
String end;
if (subPart.indexOf(',') > 0) {
@@ -188,9 +193,11 @@
String ORDER_BY = "O|OR|ORD|ORDE|ORDER|ORDER |ORDER B|ORDER BY";
if (subPart.trim().length() > 0 && (end.endsWith(" ") || subPart.toUpperCase().matches(".*"+TABLE+"[\\s]+("+WHERE+"|"+GROUP_BY+"|"+ORDER_BY+")")) &&
!subPart.trim().endsWith(",")) {
- if (subPart.lastIndexOf(" ") >0) {
+ if (end.lastIndexOf(" ") >0) {
end = end.substring(end.lastIndexOf(' ')+1);
}
+ System.err.println("SUB: "+"'"+ subPart+"'");
+ System.err.println("END: "+ "'"+end+"'");
return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD, Arrays.asList(new String[]{"WHERE", "GROUP BY", "ORDER BY", ","}), end.trim());
}
return new TabCompletionInfo(TabCompletionInfo.MatchType.TABLE_NAMES, Arrays.asList(new String[]{}), end.trim());
@@ -255,22 +262,13 @@
private static TabCompletionInfo getOrderByTabCompletionInfo(SQLPart part, List<SQLPart> parts, int charsLeft) {
String stringPart = part.getPart().toString();
String subPart = stringPart.substring(stringPart.toUpperCase().indexOf("ORDER BY")+"ORDER BY".length(), charsLeft);
- List<String> possibleMatches = new ArrayList<String>();
- for (SQLPart pPart : parts) {
- if (pPart.getSQLType() == SQLPart.SQLType.SELECT) {
- possibleMatches.addAll(pPart.getColumnNames());
- }
- }
- if (subPart.trim().length() == 0 || subPart.trim().endsWith(",")) {
- return new TabCompletionInfo(TabCompletionInfo.MatchType.OTHER, possibleMatches);
- }
String end;
if (subPart.indexOf(',') > 0) {
end = subPart.substring(subPart.lastIndexOf(',')).trim();
} else {
end = subPart.trim();
}
- return new TabCompletionInfo(TabCompletionInfo.MatchType.OTHER, possibleMatches, end);
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES, getTableNames(parts), end);
}
private static TabCompletionInfo getSelectTabCompletionInfo(SQLPart part, List<SQLPart> parts, int position) {
@@ -279,6 +277,10 @@
// return "FROM"
String startOfCommand = part.getPart().toString();
String upCommand = startOfCommand.toUpperCase();
+ if (upCommand.equals("SELECT")) {
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.OTHER
+ , Arrays.asList(new String[]{" "}));
+ }
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);
@@ -392,6 +394,10 @@
// or
// 'SELECT x FROM A,B WHERE A.x='x' AND/OR '
String startOfCommand = part.getPart().toString().substring(0, charsLeft);
+ if (startOfCommand.equalsIgnoreCase("WHERE")) {
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.OTHER
+ , Arrays.asList(new String[]{" "}));
+ }
String tmpCommand = startOfCommand.substring(startOfCommand.toUpperCase().indexOf("WHERE")+"WHERE".length()+1);
String upperCommandString = tmpCommand.toUpperCase();
//String VAR = "(|"+TABLE+"\\.)(|"+COLUMN+")";
@@ -400,7 +406,6 @@
// 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) || upperCommandString.endsWith(".")) {
- System.err.println("****** MATCHES: "+ upperCommandString);
int lastIndex = tmpCommand.lastIndexOf(' ');
lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('\t'));
lastIndex = Math.max(lastIndex, tmpCommand.lastIndexOf('='));
@@ -418,12 +423,15 @@
return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES
, tableNames, end);
}
+ if (upperCommandString.matches(".*[\\s]+(AND|OR)[\\s]+")) {
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES
+ , getTableNames(parts));
+ }
if (upperCommandString.matches(".*"+NAMING_CHAR+"\\(.*")) {
String end = tmpCommand.substring(tmpCommand.lastIndexOf('(')+1);
return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES
, getTableNames(parts), end);
}
- System.err.println("****** NOT MATCHES: "+ upperCommandString+"\n"+ regExp);
//else System.out.println("'"+upperCommandString +"'\n not matches\n"+regExp);
String end;
if (upperCommandString.matches(".*[\\s]+")) {
Modified: src/test/java/nl/improved/sqlclient/util/SQLParserTest.java
===================================================================
--- src/test/java/nl/improved/sqlclient/util/SQLParserTest.java 2009-03-04 11:12:53 UTC (rev 393)
+++ src/test/java/nl/improved/sqlclient/util/SQLParserTest.java 2009-03-14 15:23:00 UTC (rev 394)
@@ -142,6 +142,15 @@
matches = info.getPossibleMatches();
assertEquals(0, matches.size());
+ sqlCommand = Arrays.asList(new String[]{"SELECT"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.OTHER, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(1, matches.size());
+ assertEquals(" ", matches.get(0));
+
sqlCommand = Arrays.asList(new String[]{"SELECT * "});
cursorPos = new Point(sqlCommand.get(0).length(),0);
info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
@@ -190,6 +199,24 @@
assertEquals(1, matches.size());
assertEquals("A", matches.get(0));
assertEquals("", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT A"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.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 A , B"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.TABLE_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(0, matches.size());
+ assertEquals("B", info.getStart());
}
public void testTabCompletionInfoFROM() {
@@ -264,6 +291,34 @@
matches = info.getPossibleMatches();
assertEquals(0, matches.size());
assertEquals("A", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT A.b, A.c FROM "});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.TABLE_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(0, matches.size());
+ assertEquals("", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT A.b, A.c FROM"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.OTHER, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(1, matches.size());
+ assertEquals(" ", matches.get(0));
+ assertEquals("", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"select id, type from t, p", "where a=b"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(info.getPossibleMatches().toString(), TabCompletionInfo.MatchType.TABLE_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(0, matches.size());
+ assertEquals("p", info.getStart());
}
public void testTabCompletionInfoWHERE() {
@@ -351,6 +406,28 @@
assertTrue(matches.contains("A"));
assertTrue(matches.contains("B"));
+ sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE "});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(2, matches.size());
+ assertTrue(matches.contains("A"));
+ assertTrue(matches.contains("B"));
+ assertEquals("", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.OTHER, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(1, matches.size());
+ assertTrue(matches.contains(" "));
+ assertEquals("", info.getStart());
+
+
sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE I"});
cursorPos = new Point(sqlCommand.get(0).length(),0);
info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
@@ -510,6 +587,24 @@
matches = info.getPossibleMatches();
assertTrue(matches.contains("A"));
assertEquals("", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE d is null "});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.SQL_KEYWORD, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertTrue(matches.contains("AND"));
+ assertEquals("", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE d is null and "});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(info.getPossibleMatches().toString(), TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertTrue(matches.contains("A"));
+ assertEquals("", info.getStart());
}
public void testGroupBy() {
@@ -589,22 +684,24 @@
Point cursorPos = new Point(sqlCommand.get(0).length(),0);
TabCompletionInfo info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
assertNotNull(info);
- assertEquals(TabCompletionInfo.MatchType.OTHER, info.getMatchType());
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
List<String> matches = info.getPossibleMatches();
assertEquals(2, matches.size());
- assertTrue(matches.contains("c1"));
- assertTrue(matches.contains("c2"));
+ assertTrue(matches.contains("A"));
+ assertTrue(matches.contains("B"));
+ assertEquals("", info.getStart());
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 = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
assertNotNull(info);
- assertEquals(TabCompletionInfo.MatchType.OTHER, info.getMatchType());
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
matches = info.getPossibleMatches();
assertEquals(2, matches.size());
- assertTrue(matches.contains("c1"));
- assertTrue(matches.contains("c2"));
+ assertTrue(matches.contains("A"));
+ assertTrue(matches.contains("B"));
+ assertEquals("", info.getStart());
}
public void testUpdateTabCompletion() {
@@ -682,6 +779,15 @@
assertTrue("A", matches.contains("A"));
assertEquals("", info.getStart());
+ sqlCommand = Arrays.asList(new String[]{"UPDATE A SET B = C, D"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertTrue("A", matches.contains("A"));
+ assertEquals("D", info.getStart());
+
sqlCommand = Arrays.asList(new String[]{"UPDATE A SET B = B WH"});
cursorPos = new Point(sqlCommand.get(0).length(),0);
info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
|
|
From: SVN by r. <sv...@ca...> - 2009-03-04 11:13:06
|
Author: roy
Date: 2009-03-04 12:12:53 +0100 (Wed, 04 Mar 2009)
New Revision: 393
Modified:
src/main/java/nl/improved/sqlclient/SQLShell.java
Log:
fix check if file can be created
Modified: src/main/java/nl/improved/sqlclient/SQLShell.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLShell.java 2009-03-04 08:08:46 UTC (rev 392)
+++ src/main/java/nl/improved/sqlclient/SQLShell.java 2009-03-04 11:12:53 UTC (rev 393)
@@ -84,7 +84,7 @@
System.err.println("Filename '"+f.getAbsolutePath()+"' cannot be written.\nAborting...");
System.exit(-1);
}
- } else if (f.createNewFile()) {
+ } else if (!f.createNewFile()) {
System.err.println("Filename '"+f.getAbsolutePath()+"' cannot be created.\nAborting...");
System.exit(-1);
}
|
|
From: SVN by r. <sv...@ca...> - 2009-03-04 08:09:00
|
Author: roy
Date: 2009-03-04 09:08:46 +0100 (Wed, 04 Mar 2009)
New Revision: 392
Modified:
src/main/java/nl/improved/sqlclient/util/SQLParser.java
src/test/java/nl/improved/sqlclient/util/SQLParserTest.java
Log:
some tab compl fixes
Modified: src/main/java/nl/improved/sqlclient/util/SQLParser.java
===================================================================
--- src/main/java/nl/improved/sqlclient/util/SQLParser.java 2009-03-02 08:54:07 UTC (rev 391)
+++ src/main/java/nl/improved/sqlclient/util/SQLParser.java 2009-03-04 08:08:46 UTC (rev 392)
@@ -336,15 +336,24 @@
String end;
if (tmpCommand.indexOf(' ') > 0) {
end = tmpCommand.substring(tmpCommand.lastIndexOf(' ')+1).trim();
+ if (tmpCommand.matches(".*"+COMPARATOR+"[\\s]*"+VAR+"[\\s]+(|W|WH|WHE|WHER|WHERE)")) {
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD
+ , Arrays.asList(new String[]{",", "WHERE"}), end);
+ }
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD
+ , Arrays.asList(new String[]{"=", "<>", "LIKE", "<", ">"}), end);
} else {
end = tmpCommand.trim();
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES
+ , getTableNames(parts), end);
}
- if (tmpCommand.trim().length() > 0) {
+ /*if (tmpCommand.trim().length() > 0) {
return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD
, Arrays.asList(new String[]{"=", "<>", "LIKE", "<", ">"}), end);
}
return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD
, Arrays.asList(new String[]{",", "WHERE"})); // TODO END
+*/
}
private static String getTableName(String alias, List<SQLPart> parts) {
Modified: src/test/java/nl/improved/sqlclient/util/SQLParserTest.java
===================================================================
--- src/test/java/nl/improved/sqlclient/util/SQLParserTest.java 2009-03-02 08:54:07 UTC (rev 391)
+++ src/test/java/nl/improved/sqlclient/util/SQLParserTest.java 2009-03-04 08:08:46 UTC (rev 392)
@@ -664,6 +664,15 @@
assertTrue("=", matches.contains("="));
assertEquals("", info.getStart());
+ sqlCommand = Arrays.asList(new String[]{"UPDATE A SET B"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertTrue("A", matches.contains("A"));
+ assertEquals("B", info.getStart());
+
sqlCommand = Arrays.asList(new String[]{"UPDATE A SET B = "});
cursorPos = new Point(sqlCommand.get(0).length(),0);
info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
@@ -672,6 +681,15 @@
matches = info.getPossibleMatches();
assertTrue("A", matches.contains("A"));
assertEquals("", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"UPDATE A SET B = B WH"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.SQL_KEYWORD, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertTrue("WHERE not in " + matches , matches.contains("WHERE"));
+ assertEquals("WH", info.getStart());
}
public void testGetTableName() {
|
|
From: SVN by r. <sv...@ca...> - 2009-03-02 08:54:14
|
Author: roy
Date: 2009-03-02 09:54:07 +0100 (Mon, 02 Mar 2009)
New Revision: 391
Modified:
src/main/java/nl/improved/sqlclient/util/SQLParser.java
src/test/java/nl/improved/sqlclient/util/SQLParserTest.java
Log:
more tests and fixes
Modified: src/main/java/nl/improved/sqlclient/util/SQLParser.java
===================================================================
--- src/main/java/nl/improved/sqlclient/util/SQLParser.java 2009-03-02 08:53:55 UTC (rev 390)
+++ src/main/java/nl/improved/sqlclient/util/SQLParser.java 2009-03-02 08:54:07 UTC (rev 391)
@@ -132,10 +132,11 @@
} else if (sql.matches("[\\s]*WHERE.*")) {
sqlType = SQLPart.SQLType.WHERE;
if (sql.matches("[\\s]*WHERE.*ORDER BY.*")) {
- end = sql.indexOf(" ORDER BY");
- } else if (sql.matches("[\\s]*WHERE.*GROUP BY.*")) {
- end = sql.indexOf("GROUP BY");
+ end = sql.indexOf("ORDER BY");
}
+ if (sql.matches("[\\s]*WHERE.*GROUP BY.*")) {
+ end = Math.min(end, sql.indexOf("GROUP BY"));
+ }
} else if (sql.matches("[\\s]*ORDER BY.*")) {
sqlType = SQLPart.SQLType.ORDERBY;
if (sql.matches("[\\s]*ORDER BY.*GROUP BY.*")) {
@@ -143,27 +144,23 @@
}
} else if (sql.matches("[\\s]*GROUP BY.*")) {
sqlType = SQLPart.SQLType.GROUPBY;
- end = sqlSequence.length();
+ if (sql.matches("[\\s]*GROUP BY.*ORDER BY.*")) {
+ end = sql.indexOf("ORDER BY");
+ }
} else if (sql.matches("[\\s]*DELETE.*")) {
sqlType = SQLPart.SQLType.DELETE;
if (sql.matches("[\\s]*DELETE FROM.*")) {
end = sql.indexOf("FROM");
- } else {
- end = sqlSequence.length();
}
} else if (sql.matches("[\\s]*UPDATE.*")) {
sqlType = SQLPart.SQLType.UPDATE;
if (sql.matches("[\\s]*UPDATE.*SET.*")) {
end = sql.indexOf("SET");
- } else {
- end = sqlSequence.length();
}
} else if (sql.matches("[\\s]*SET.*")) {
sqlType = SQLPart.SQLType.SET;
if (sql.matches("[\\s]*WHERE.*")) {
end = sql.indexOf("WHERE");
- } else {
- end = sqlSequence.length();
}
} else {
sqlType = SQLPart.SQLType.OTHER;
@@ -412,6 +409,11 @@
return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES
, tableNames, end);
}
+ if (upperCommandString.matches(".*"+NAMING_CHAR+"\\(.*")) {
+ String end = tmpCommand.substring(tmpCommand.lastIndexOf('(')+1);
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES
+ , getTableNames(parts), end);
+ }
System.err.println("****** NOT MATCHES: "+ upperCommandString+"\n"+ regExp);
//else System.out.println("'"+upperCommandString +"'\n not matches\n"+regExp);
String end;
Modified: src/test/java/nl/improved/sqlclient/util/SQLParserTest.java
===================================================================
--- src/test/java/nl/improved/sqlclient/util/SQLParserTest.java 2009-03-02 08:53:55 UTC (rev 390)
+++ src/test/java/nl/improved/sqlclient/util/SQLParserTest.java 2009-03-02 08:54:07 UTC (rev 391)
@@ -62,23 +62,34 @@
assertEquals(expResult, result);
}
- public void _testParseOrderBy() {
+ public void testParseOrderBy() {
CharSequence sql = "SELECT * FROM TESTTABLE WHERE A=B ORDER BY a";
List<SQLPart> expResult = new ArrayList(Arrays.asList(new SQLPart[]{
new SQLPart(SQLPart.SQLType.SELECT, "SELECT * "),
new SQLPart(SQLPart.SQLType.FROM, "FROM TESTTABLE "),
new SQLPart(SQLPart.SQLType.WHERE, "WHERE A=B "),
- new SQLPart(SQLPart.SQLType.ORDERBY, "ORDER BY a ")
+ new SQLPart(SQLPart.SQLType.ORDERBY, "ORDER BY a")
}));
List<SQLPart> result = SQLParser.parse(sql);
assertEquals(expResult.size(), result.size());
+ assertEquals(expResult.get(0), result.get(0));
+ assertEquals(expResult.get(1), result.get(1));
+ assertEquals(expResult.get(2), result.get(2));
+ assertEquals(expResult.get(3), result.get(3));
assertEquals(expResult, result);
+ expResult.remove(expResult.size()-1);
+ expResult.add(new SQLPart(SQLPart.SQLType.ORDERBY, "ORDER BY a "));
expResult.add(new SQLPart(SQLPart.SQLType.GROUPBY, "GROUP BY test.a"));
sql = "SELECT * FROM TESTTABLE WHERE A=B ORDER BY a GROUP BY test.a";
result = SQLParser.parse(sql);
assertEquals(expResult.size(), result.size());
+ assertEquals(expResult.get(0), result.get(0));
+ assertEquals(expResult.get(1), result.get(1));
+ assertEquals(expResult.get(2), result.get(2));
+ assertEquals(expResult.get(3), result.get(3));
+ assertEquals(expResult.get(4), result.get(4));
assertEquals(expResult, result);
sql = "SELECT * FROM TESTTABLE WHERE A=B GROUP BY test.a ORDER BY a";
@@ -86,11 +97,17 @@
new SQLPart(SQLPart.SQLType.SELECT, "SELECT * "),
new SQLPart(SQLPart.SQLType.FROM, "FROM TESTTABLE "),
new SQLPart(SQLPart.SQLType.WHERE, "WHERE A=B "),
- new SQLPart(SQLPart.SQLType.ORDERBY, "GROUP BY test.a "),
+ new SQLPart(SQLPart.SQLType.GROUPBY, "GROUP BY test.a "),
new SQLPart(SQLPart.SQLType.ORDERBY, "ORDER BY a"),
}));
result = SQLParser.parse(sql);
+ assertEquals(result.toString(), expResult.size(), result.size());
assertEquals(expResult.size(), result.size());
+ assertEquals(expResult.get(0), result.get(0));
+ assertEquals(expResult.get(1), result.get(1));
+ assertEquals(expResult.get(2), result.get(2));
+ assertEquals(expResult.get(3), result.get(3));
+ assertEquals(expResult.get(4), result.get(4));
assertEquals(expResult, result);
}
@@ -484,6 +501,15 @@
matches = info.getPossibleMatches();
assertTrue(matches.contains("A"));
assertEquals("x", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE to_char("});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertTrue(matches.contains("A"));
+ assertEquals("", info.getStart());
}
public void testGroupBy() {
|
|
From: SVN by r. <sv...@ca...> - 2009-03-02 08:54:05
|
Author: roy
Date: 2009-03-02 09:53:55 +0100 (Mon, 02 Mar 2009)
New Revision: 390
Modified:
src/main/java/nl/improved/sqlclient/SQLShell.java
Log:
made new tc the default
Modified: src/main/java/nl/improved/sqlclient/SQLShell.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLShell.java 2009-03-01 16:55:05 UTC (rev 389)
+++ src/main/java/nl/improved/sqlclient/SQLShell.java 2009-03-02 08:53:55 UTC (rev 390)
@@ -199,7 +199,7 @@
}
} else {
//sqlshellWindow = new SQLShellWindow();
- if (argsMap.containsKey(TABCOMPLETION) && argsMap.get(TABCOMPLETION).equals("new")) {
+ if (!argsMap.containsKey(TABCOMPLETION) || argsMap.get(TABCOMPLETION).equals("new")) {
SQLUtil.USE_V2=true;
}
if (!argsMap.containsKey(ENGINE) || argsMap.get(ENGINE).equals(ENGINE_CHARVA)) {
|
|
From: SVN by r. <sv...@ca...> - 2009-03-01 16:55:15
|
Author: roy
Date: 2009-03-01 17:55:05 +0100 (Sun, 01 Mar 2009)
New Revision: 389
Modified:
src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java
Log:
fixed npe when cancelling login
Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2009-03-01 16:46:31 UTC (rev 388)
+++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2009-03-01 16:55:05 UTC (rev 389)
@@ -1315,6 +1315,9 @@
password = predefinedSettings.getPassword();
}
String[] credentials = getLoginCredentials(username, password);
+ if (credentials == null) {
+ return null;
+ }
username = credentials[0];
password = credentials[1];
}
|
|
From: SVN by r. <sv...@ca...> - 2009-03-01 16:46:44
|
Author: roy
Date: 2009-03-01 17:46:31 +0100 (Sun, 01 Mar 2009)
New Revision: 388
Modified:
ChangeLog
Log:
mention changes
Modified: ChangeLog
===================================================================
--- ChangeLog 2009-03-01 14:22:52 UTC (rev 387)
+++ ChangeLog 2009-03-01 16:46:31 UTC (rev 388)
@@ -1,3 +1,8 @@
+0.7
+ * Rewritten tab completion engine
+ - improved group by and order by
+ - added support for aliases in table names
+
0.6.2 (2009-02-20)
* Commandline input support
* -engine option to switch between charva (default) and jcurses
|
|
From: SVN by r. <sv...@ca...> - 2009-03-01 14:23:02
|
Author: roy
Date: 2009-03-01 15:22:52 +0100 (Sun, 01 Mar 2009)
New Revision: 387
Modified:
src/main/java/nl/improved/sqlclient/util/SQLParser.java
src/main/java/nl/improved/sqlclient/util/SQLPart.java
src/test/java/nl/improved/sqlclient/util/SQLParserTest.java
Log:
added more test
fix where tab completion when using table alias names
Modified: src/main/java/nl/improved/sqlclient/util/SQLParser.java
===================================================================
--- src/main/java/nl/improved/sqlclient/util/SQLParser.java 2009-02-28 13:42:08 UTC (rev 386)
+++ src/main/java/nl/improved/sqlclient/util/SQLParser.java 2009-03-01 14:22:52 UTC (rev 387)
@@ -350,6 +350,14 @@
, Arrays.asList(new String[]{",", "WHERE"})); // TODO END
}
+ private static String getTableName(String alias, List<SQLPart> parts) {
+ for (SQLPart tmpPart : parts) {
+ if (tmpPart.getSQLType() == SQLPart.SQLType.FROM || tmpPart.getSQLType() == SQLPart.SQLType.UPDATE) {
+ return tmpPart.getTableName(alias);
+ }
+ }
+ return alias;
+ }
private static List<String> getTableNames(List<SQLPart> parts) {
SQLPart fromSqlPart = null;
for (SQLPart tmpPart : parts) {
@@ -399,7 +407,7 @@
lastBreakIndex = 0;
}
List tableNames = (lastIndex > lastBreakIndex) && lastBreakIndex >=0 ?
- Arrays.asList(new String[]{tmpCommand.substring(lastBreakIndex,lastIndex).trim()}) :
+ Arrays.asList(new String[]{getTableName(tmpCommand.substring(lastBreakIndex,lastIndex).trim(), parts)}) :
getTableNames(parts);
return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES
, tableNames, end);
Modified: src/main/java/nl/improved/sqlclient/util/SQLPart.java
===================================================================
--- src/main/java/nl/improved/sqlclient/util/SQLPart.java 2009-02-28 13:42:08 UTC (rev 386)
+++ src/main/java/nl/improved/sqlclient/util/SQLPart.java 2009-03-01 14:22:52 UTC (rev 387)
@@ -74,6 +74,37 @@
}
throw new IllegalStateException("Table names are only available for SELECT ("+ sqlType+")");
}
+ public String getTableName(String alias) {
+ if (sqlType == SQLType.FROM || sqlType == SQLType.UPDATE) {
+ String stringPart = getPart().toString();
+ String sub;
+ if (sqlType == SQLType.FROM) {
+ sub = stringPart.substring(stringPart.toUpperCase().indexOf("FROM")+"FROM".length());
+ } else {
+ sub = stringPart.substring(stringPart.toUpperCase().indexOf("UPDATE")+"UPDATE".length());
+ }
+ int lastIndex = 0;
+ int newIndex;
+ while ( (newIndex = sub.indexOf(',', lastIndex)) > 0) {
+ String tableName = sub.substring(lastIndex, newIndex).trim();
+ if (tableName.indexOf(" ") > 0 && tableName.endsWith(" "+alias)) {
+ tableName = tableName.substring(0, tableName.indexOf(" ")).trim();
+ return tableName;
+ }
+ lastIndex = newIndex+1;
+ }
+ String tmp = sub.substring(lastIndex).trim();
+ if (tmp.length() > 0) {
+ if (tmp.indexOf(" ") > 0 && tmp.endsWith(" "+alias)) {
+ tmp = tmp.substring(0, tmp.indexOf(" ")).trim();
+ return tmp;
+ }
+ }
+ return alias;
+ }
+ throw new IllegalStateException("Table names are only available for FROM,UPDATE ("+ sqlType+")");
+ }
+
public List<String> getTableNames() {
if (sqlType == SQLType.FROM || sqlType == SQLType.UPDATE) {
List<String> returnValue = new ArrayList<String>();
@@ -106,4 +137,4 @@
throw new IllegalStateException("Table names are only available for FROM,UPDATE ("+ sqlType+")");
}
-}
\ No newline at end of file
+}
Modified: src/test/java/nl/improved/sqlclient/util/SQLParserTest.java
===================================================================
--- src/test/java/nl/improved/sqlclient/util/SQLParserTest.java 2009-02-28 13:42:08 UTC (rev 386)
+++ src/test/java/nl/improved/sqlclient/util/SQLParserTest.java 2009-03-01 14:22:52 UTC (rev 387)
@@ -658,6 +658,36 @@
assertEquals(1, matches.size());
assertEquals("b", info.getStart());
assertTrue("Table name should match 'mytable', but was " + matches.get(0), matches.contains("mytable"));
+
+ sqlCommand = Arrays.asList(new String[]{"select * from a where b"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(1, matches.size());
+ assertEquals("b", info.getStart());
+ assertTrue("Table name should match 'a', but was " + matches.get(0), matches.contains("a"));
+
+ sqlCommand = Arrays.asList(new String[]{"select * from testtable a where b"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(1, matches.size());
+ assertEquals("b", info.getStart());
+ assertTrue("Table name should match 'testtable', but was " + matches.get(0), matches.contains("testtable"));
+
+ sqlCommand = Arrays.asList(new String[]{"select * from testtable a where a.b"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(1, matches.size());
+ assertEquals("b", info.getStart());
+ assertTrue("Table name should match 'testtable', but was " + matches.get(0), matches.contains("testtable"));
}
}
|
|
From: SVN by r. <sv...@ca...> - 2009-02-28 13:43:11
|
Author: roy
Date: 2009-02-28 14:36:27 +0100 (Sat, 28 Feb 2009)
New Revision: 385
Modified:
src/main/java/nl/improved/sqlclient/util/SQLParser.java
Log:
fix set tc
Modified: src/main/java/nl/improved/sqlclient/util/SQLParser.java
===================================================================
--- src/main/java/nl/improved/sqlclient/util/SQLParser.java 2009-02-28 13:31:11 UTC (rev 384)
+++ src/main/java/nl/improved/sqlclient/util/SQLParser.java 2009-02-28 13:36:27 UTC (rev 385)
@@ -329,7 +329,7 @@
}
if (tmpCommand.trim().length() > 0) {
return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD
- , Arrays.asList(new String[]{"=", "<>", "LIKE", "<", ">"}));
+ , Arrays.asList(new String[]{"="}));
}
}
if (tmpCommand.trim().length() == 0) {
|
|
From: SVN by r. <sv...@ca...> - 2009-02-28 13:42:11
|
Author: roy
Date: 2009-02-28 14:42:08 +0100 (Sat, 28 Feb 2009)
New Revision: 386
Modified:
src/test/java/nl/improved/sqlclient/util/SQLParserTest.java
Log:
added test cases
Modified: src/test/java/nl/improved/sqlclient/util/SQLParserTest.java
===================================================================
--- src/test/java/nl/improved/sqlclient/util/SQLParserTest.java 2009-02-28 13:36:27 UTC (rev 385)
+++ src/test/java/nl/improved/sqlclient/util/SQLParserTest.java 2009-02-28 13:42:08 UTC (rev 386)
@@ -628,6 +628,24 @@
matches = info.getPossibleMatches();
assertTrue("=", matches.contains("="));
assertEquals("", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"UPDATE A SET B "});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.SQL_KEYWORD, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertTrue("=", matches.contains("="));
+ assertEquals("", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"UPDATE A SET B = "});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertTrue("A", matches.contains("A"));
+ assertEquals("", info.getStart());
}
public void testGetTableName() {
|
|
From: SVN by r. <sv...@ca...> - 2009-02-28 13:42:01
|
Author: roy
Date: 2009-02-28 14:31:11 +0100 (Sat, 28 Feb 2009)
New Revision: 384
Modified:
src/main/java/nl/improved/sqlclient/util/SQLParser.java
Log:
more tabcompletion fixes
Modified: src/main/java/nl/improved/sqlclient/util/SQLParser.java
===================================================================
--- src/main/java/nl/improved/sqlclient/util/SQLParser.java 2009-02-28 13:29:07 UTC (rev 383)
+++ src/main/java/nl/improved/sqlclient/util/SQLParser.java 2009-02-28 13:31:11 UTC (rev 384)
@@ -216,7 +216,7 @@
}
if (!possibleMatches.contains(colName)) {
possibleMatches.add(colName);
- if (colName.indexOf('(') < 0) {
+ if (colName.indexOf("max") < 0 && colName.indexOf("min") < 0 && colName.indexOf("count") < 0) {
if (bestMatch.length() > 0) {
bestMatch.append(',');
}
@@ -231,7 +231,7 @@
}
if (!possibleMatches.contains(colName) && colName.length() > 0) {
possibleMatches.add(colName);
- if (colName.indexOf('(') < 0) {
+ if (colName.indexOf("max") < 0 && colName.indexOf("min") < 0 && colName.indexOf("count") < 0) {
if (bestMatch.length() > 0) {
bestMatch.append(',');
}
|
|
From: SVN by r. <sv...@ca...> - 2009-02-28 13:29:20
|
Author: roy
Date: 2009-02-28 14:29:07 +0100 (Sat, 28 Feb 2009)
New Revision: 383
Added:
src/test/java/nl/improved/sqlclient/util/
src/test/java/nl/improved/sqlclient/util/SQLParserTest.java
Modified:
src/main/java/nl/improved/sqlclient/util/SQLParser.java
src/test/java/nl/improved/sqlclient/
Log:
added tests
fixed lowercase group by tab completion
Modified: src/main/java/nl/improved/sqlclient/util/SQLParser.java
===================================================================
--- src/main/java/nl/improved/sqlclient/util/SQLParser.java 2009-02-27 21:15:25 UTC (rev 382)
+++ src/main/java/nl/improved/sqlclient/util/SQLParser.java 2009-02-28 13:29:07 UTC (rev 383)
@@ -189,7 +189,7 @@
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 (subPart.trim().length() > 0 && (end.endsWith(" ") || subPart.matches(".*"+TABLE+"[\\s]+("+WHERE+"|"+GROUP_BY+"|"+ORDER_BY+")")) &&
+ if (subPart.trim().length() > 0 && (end.endsWith(" ") || subPart.toUpperCase().matches(".*"+TABLE+"[\\s]+("+WHERE+"|"+GROUP_BY+"|"+ORDER_BY+")")) &&
!subPart.trim().endsWith(",")) {
if (subPart.lastIndexOf(" ") >0) {
end = end.substring(end.lastIndexOf(' ')+1);
Property changes on: src/test/java/nl/improved/sqlclient
___________________________________________________________________
Name: svn:ignore
+ .SQLUtilTest.java.swp
Added: src/test/java/nl/improved/sqlclient/util/SQLParserTest.java
===================================================================
--- src/test/java/nl/improved/sqlclient/util/SQLParserTest.java 2009-02-27 21:15:25 UTC (rev 382)
+++ src/test/java/nl/improved/sqlclient/util/SQLParserTest.java 2009-02-28 13:29:07 UTC (rev 383)
@@ -0,0 +1,645 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package nl.improved.sqlclient.util;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import junit.framework.TestCase;
+import nl.improved.sqlclient.TabCompletionInfo;
+import nl.improved.sqlclient.Point;
+
+/**
+ *
+ * @author roy
+ */
+public class SQLParserTest extends TestCase {
+
+ public SQLParserTest(String testName) {
+ super(testName);
+ }
+
+
+ /**
+ * Test of parse method, of class SQLParser.
+ */
+ public void testParseSimple() {
+ CharSequence sql = "SELECT * FROM TESTTABLE";
+ List<SQLPart> expResult = Arrays.asList(new SQLPart[]{
+ new SQLPart(SQLPart.SQLType.SELECT, "SELECT * "),
+ new SQLPart(SQLPart.SQLType.FROM, "FROM TESTTABLE")
+ });
+ List<SQLPart> result = SQLParser.parse(sql);
+ assertEquals(expResult.size(), result.size());
+ assertEquals(expResult, result);
+ }
+
+ public void testParseWhere() {
+ CharSequence sql = "SELECT * FROM TESTTABLE WHERE A=B";
+ List<SQLPart> expResult = Arrays.asList(new SQLPart[]{
+ new SQLPart(SQLPart.SQLType.SELECT, "SELECT * "),
+ new SQLPart(SQLPart.SQLType.FROM, "FROM TESTTABLE "),
+ new SQLPart(SQLPart.SQLType.WHERE, "WHERE A=B")
+ });
+ List<SQLPart> result = SQLParser.parse(sql);
+ assertEquals(expResult.size(), result.size());
+ assertEquals(expResult, result);
+ }
+
+ public void testParseGroupBy() {
+ CharSequence sql = "SELECT * FROM TESTTABLE WHERE A=B GROUP BY test.a";
+ List<SQLPart> expResult = Arrays.asList(new SQLPart[]{
+ new SQLPart(SQLPart.SQLType.SELECT, "SELECT * "),
+ new SQLPart(SQLPart.SQLType.FROM, "FROM TESTTABLE "),
+ new SQLPart(SQLPart.SQLType.WHERE, "WHERE A=B "),
+ new SQLPart(SQLPart.SQLType.GROUPBY, "GROUP BY test.a")
+ });
+ List<SQLPart> result = SQLParser.parse(sql);
+ assertEquals(expResult.size(), result.size());
+ assertEquals(expResult, result);
+ }
+
+ public void _testParseOrderBy() {
+ CharSequence sql = "SELECT * FROM TESTTABLE WHERE A=B ORDER BY a";
+ List<SQLPart> expResult = new ArrayList(Arrays.asList(new SQLPart[]{
+ new SQLPart(SQLPart.SQLType.SELECT, "SELECT * "),
+ new SQLPart(SQLPart.SQLType.FROM, "FROM TESTTABLE "),
+ new SQLPart(SQLPart.SQLType.WHERE, "WHERE A=B "),
+ new SQLPart(SQLPart.SQLType.ORDERBY, "ORDER BY a ")
+ }));
+ List<SQLPart> result = SQLParser.parse(sql);
+ assertEquals(expResult.size(), result.size());
+ assertEquals(expResult, result);
+
+ expResult.add(new SQLPart(SQLPart.SQLType.GROUPBY, "GROUP BY test.a"));
+ sql = "SELECT * FROM TESTTABLE WHERE A=B ORDER BY a GROUP BY test.a";
+
+ result = SQLParser.parse(sql);
+ assertEquals(expResult.size(), result.size());
+ assertEquals(expResult, result);
+
+ sql = "SELECT * FROM TESTTABLE WHERE A=B GROUP BY test.a ORDER BY a";
+ expResult = new ArrayList(Arrays.asList(new SQLPart[]{
+ new SQLPart(SQLPart.SQLType.SELECT, "SELECT * "),
+ new SQLPart(SQLPart.SQLType.FROM, "FROM TESTTABLE "),
+ new SQLPart(SQLPart.SQLType.WHERE, "WHERE A=B "),
+ new SQLPart(SQLPart.SQLType.ORDERBY, "GROUP BY test.a "),
+ new SQLPart(SQLPart.SQLType.ORDERBY, "ORDER BY a"),
+ }));
+ result = SQLParser.parse(sql);
+ assertEquals(expResult.size(), result.size());
+ assertEquals(expResult, result);
+ }
+
+ public void testTabCompletionInfoBLANK() {
+ List<String> sqlCommand = Arrays.asList(new String[]{""});
+ Point cursorPos = new Point(0,0);
+ TabCompletionInfo info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.SQL_KEYWORD, info.getMatchType());
+ List<String> matches = info.getPossibleMatches();
+ assertTrue(matches.contains("SELECT"));
+ assertTrue(matches.contains("INSERT INTO"));
+ assertTrue(matches.contains("DELETE FROM"));
+ assertTrue(matches.contains("UPDATE"));
+ }
+
+ public void testTabCompletionInfoSELECT() {
+ List<String> sqlCommand = Arrays.asList(new String[]{"SELECT A"});
+ Point cursorPos = new Point(sqlCommand.get(0).length(),0);
+ TabCompletionInfo info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.TABLE_NAMES, info.getMatchType());
+ List<String> matches = info.getPossibleMatches();
+ assertEquals(0, matches.size());
+ assertEquals("A", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT "});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.TABLE_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(0, matches.size());
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT * "});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.SQL_KEYWORD, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(1, matches.size());
+ assertTrue(matches.contains("FROM"));
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT * FR"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(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 FR"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(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 = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(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 = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(1, matches.size());
+ assertEquals("A", matches.get(0));
+ assertEquals("", info.getStart());
+ }
+
+ public void testTabCompletionInfoFROM() {
+ List<String> sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A"});
+ Point cursorPos = new Point(sqlCommand.get(0).length(),0);
+ TabCompletionInfo info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.TABLE_NAMES, info.getMatchType());
+ List<String> matches = info.getPossibleMatches();
+ 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 = SQLParser.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 = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.TABLE_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(0, matches.size());
+ assertEquals("B", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.TABLE_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ 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 = SQLParser.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 = SQLParser.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 = SQLParser.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 A.b, A.c FROM A"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.TABLE_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(0, matches.size());
+ assertEquals("A", info.getStart());
+ }
+
+ public void testTabCompletionInfoWHERE() {
+ List<String> sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B "});
+ Point cursorPos = new Point(sqlCommand.get(0).length(),0);
+ TabCompletionInfo info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.SQL_KEYWORD, info.getMatchType());
+ List<String> matches = info.getPossibleMatches();
+ //assertEquals(3, matches.size());
+ assertTrue("At least 3 keyword matches required", matches.size() >=3);
+ assertTrue(matches.contains("WHERE"));
+ assertTrue(matches.contains("GROUP BY"));
+ assertTrue(matches.contains("ORDER BY"));
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A "});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.SQL_KEYWORD, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertTrue("At least 3 keyword matches required", matches.size() >=3);
+ assertTrue(matches.contains("WHERE"));
+ assertTrue(matches.contains("GROUP BY"));
+ assertEquals("", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A GR"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.SQL_KEYWORD, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertTrue("At least 3 keyword matches required", matches.size() >=3);
+ assertTrue(matches.contains("WHERE"));
+ assertTrue(matches.contains("GROUP BY"));
+ assertEquals("GR", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A gr"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.SQL_KEYWORD, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertTrue("At least 3 keyword matches required", matches.size() >=3);
+ assertTrue(matches.contains("WHERE"));
+ assertTrue(matches.contains("GROUP BY"));
+ assertEquals("gr", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A, "});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.TABLE_NAMES, info.getMatchType());
+ assertEquals("", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B "});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.SQL_KEYWORD, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertTrue("At least 3 keyword matches required", matches.size() >=3);
+ assertTrue(matches.contains("WHERE"));
+ assertEquals("", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WH"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.SQL_KEYWORD, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertTrue("At least 3 keyword matches required", matches.size() >=3);
+ assertTrue(matches.contains("WHERE"));
+ assertEquals("WH", info.getStart());
+ }
+
+ public void testTabCompletionInfoWHEREConditions() {
+ List<String> sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE "});
+ Point cursorPos = new Point(sqlCommand.get(0).length(),0);
+ TabCompletionInfo info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ List<String> matches = info.getPossibleMatches();
+ assertEquals(2, matches.size());
+ assertTrue(matches.contains("A"));
+ assertTrue(matches.contains("B"));
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE I"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(2, matches.size());
+ assertTrue(matches.contains("A"));
+ assertTrue(matches.contains("B"));
+ assertEquals("I", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE I=bla AND I"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(2, matches.size());
+ assertTrue(matches.contains("A"));
+ assertTrue(matches.contains("B"));
+ assertEquals("I", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE A.I"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.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("I", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE A."});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.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);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(2, matches.size());
+ assertTrue(matches.contains("A"));
+ assertTrue(matches.contains("B"));
+
+ // same but with different casings
+ sqlCommand = Arrays.asList(new String[]{"select * From A,B whEre A.x = 'x' aNd "});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(2, matches.size());
+ assertTrue(matches.contains("A"));
+ assertTrue(matches.contains("B"));
+
+ // with other conditions
+ sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE A.x = a"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertTrue(matches.contains("A"));
+ assertTrue(matches.contains("B"));
+ assertEquals("a", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE A.x = "});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertTrue(matches.contains("A"));
+ assertTrue(matches.contains("B"));
+ assertEquals("", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT * FROM A,B WHERE A.x = 'x' "});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.SQL_KEYWORD, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertTrue(matches.contains("AND"));
+ 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"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.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 makelaarnr from makelaar, tree, plugin where parent = makelaar.i_id and child=pl"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.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 = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.SQL_KEYWORD, info.getMatchType());
+ 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 = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.SQL_KEYWORD, info.getMatchType());
+ 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);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ 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"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.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() {
+ List<String> sqlCommand = Arrays.asList(new String[]{"SELECT c1,c2, count(*) FROM A,B WHERE a.b=b.b GROUP BY "});
+ Point cursorPos = new Point(sqlCommand.get(0).length(),0);
+ TabCompletionInfo info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.OTHER, info.getMatchType());
+ List<String> matches = info.getPossibleMatches();
+ assertEquals(4, matches.size());
+ assertTrue(matches.contains("c1"));
+ assertTrue(matches.contains("c2"));
+ assertTrue(matches.contains("count(*)"));
+ assertTrue(matches.contains("c1,c2"));
+ assertEquals("", info.getStart());
+
+
+ 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 = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.OTHER, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(3, 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 = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.OTHER, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(3, 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 = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.OTHER, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(3, matches.size());
+ assertTrue(matches.contains("c2"));
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT c1 , c2 FROM A,B GR"});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.SQL_KEYWORD, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertTrue(matches.contains("GROUP BY"));
+ assertEquals("GR", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT c1 , c2 FROM A,B", "GR"});
+ cursorPos = new Point(sqlCommand.get(1).length(),1);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.SQL_KEYWORD, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertTrue(matches.contains("GROUP BY"));
+ assertEquals("GR", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"SELECT c1 , c2 FROM A,B", "GROUP BY "});
+ cursorPos = new Point(sqlCommand.get(1).length(),1);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.OTHER, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertTrue(matches.contains("c1"));
+ assertEquals("", info.getStart());
+ }
+
+ 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 = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.OTHER, 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 = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.OTHER, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(2, matches.size());
+ assertTrue(matches.contains("c1"));
+ assertTrue(matches.contains("c2"));
+ }
+
+ public void testUpdateTabCompletion() {
+ List<String> sqlCommand = Arrays.asList(new String[]{"UPDATE A"});
+ Point cursorPos = new Point(sqlCommand.get(0).length(),0);
+ TabCompletionInfo info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(info.getPossibleMatches().toString(), 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 = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(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 = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertEquals(1, matches.size());
+ assertEquals("A", matches.get(0));
+ assertEquals("", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"UPDATE A SET B=C "});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.SQL_KEYWORD, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertTrue("WHERE", matches.contains("WHERE"));
+ assertEquals("", info.getStart());
+
+ sqlCommand = Arrays.asList(new String[]{"UPDATE A SET B=C, ID "});
+ cursorPos = new Point(sqlCommand.get(0).length(),0);
+ info = SQLParser.getTabCompletionInfo(sqlCommand, cursorPos);
+ assertNotNull(info);
+ assertEquals(TabCompletionInfo.MatchType.SQL_KEYWORD, info.getMatchType());
+ matches = info.getPossibleMatches();
+ assertTrue("=", matches.contains("="));
+ 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 = SQLParser.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"));
+ }
+
+}
|
|
From: SVN by r. <sv...@ca...> - 2009-02-27 21:15:30
|
Author: roy
Date: 2009-02-27 22:15:25 +0100 (Fri, 27 Feb 2009)
New Revision: 382
Modified:
src/main/java/nl/improved/sqlclient/SQLShell.java
src/main/java/nl/improved/sqlclient/SQLUtil.java
src/main/java/nl/improved/sqlclient/util/SQLParser.java
Log:
more test
more tabcompletion fixes
added option -tc [new/old] for tabcompletion switch
Modified: src/main/java/nl/improved/sqlclient/SQLShell.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLShell.java 2009-02-27 20:13:20 UTC (rev 381)
+++ src/main/java/nl/improved/sqlclient/SQLShell.java 2009-02-27 21:15:25 UTC (rev 382)
@@ -41,6 +41,7 @@
public static final String INPUT = "-i";
public static final String OUTPUT = "-o";
public static final String ENGINE = "-engine";
+ public static final String TABCOMPLETION = "-tc";
public static final String ENGINE_CHARVA = "charva";
public static final String ENGINE_JCURSES = "jcurses";
@@ -100,6 +101,18 @@
System.exit(-1);
}
argsMap.put(args[i], args[i+1]);
+ } else if (args[i].equals(TABCOMPLETION)) {
+ if (args.length < i+1) {
+ System.err.println("Missing type parameter for -tc argument.");
+ System.err.println("Possible values are 'new' and 'old'");
+ System.exit(-1);
+ }
+ if (!(args[i+1].equals("new")) && !(args[i+1].equals("old"))) {
+ System.err.println("Unknown parameter for tabcompletion '"+ args[i+1]+"'");
+ System.err.println("Possible values are 'new' and 'new'");
+ System.exit(-1);
+ }
+ argsMap.put(args[i], args[i+1]);
} else {
System.err.println("Uknown option: "+ args[i]+"\nAborting...");
System.exit(-1);
@@ -186,6 +199,9 @@
}
} else {
//sqlshellWindow = new SQLShellWindow();
+ if (argsMap.containsKey(TABCOMPLETION) && argsMap.get(TABCOMPLETION).equals("new")) {
+ SQLUtil.USE_V2=true;
+ }
if (!argsMap.containsKey(ENGINE) || argsMap.get(ENGINE).equals(ENGINE_CHARVA)) {
try {
sqlshellWindow = new CharvaSQLShellWindow();
Modified: src/main/java/nl/improved/sqlclient/SQLUtil.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLUtil.java 2009-02-27 20:13:20 UTC (rev 381)
+++ src/main/java/nl/improved/sqlclient/SQLUtil.java 2009-02-27 21:15:25 UTC (rev 382)
@@ -54,6 +54,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", "GROUP BY", "ORDER BY", "DESC"});
+ public static boolean USE_V2 = false;
/**
* Private constructor.
@@ -134,9 +135,9 @@
* @return tab completion info for the provided command lines.
*/
public static TabCompletionInfo getTabCompletionInfo(List<? extends CharSequence> commandInfo, Point commandPoint) {
- /*if (true) {
+ if (USE_V2) {
return SQLParser.getTabCompletionInfo(commandInfo, 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", "UPDATE"}));
Modified: src/main/java/nl/improved/sqlclient/util/SQLParser.java
===================================================================
--- src/main/java/nl/improved/sqlclient/util/SQLParser.java 2009-02-27 20:13:20 UTC (rev 381)
+++ src/main/java/nl/improved/sqlclient/util/SQLParser.java 2009-02-27 21:15:25 UTC (rev 382)
@@ -58,6 +58,10 @@
if (y == commandPoint.y) {
position+=commandPoint.x;
}
+ if (buf.length() > 0) {
+ buf.append(' ');
+ position++;
+ }
buf.append(seq);
}
return getTabCompletionInfo(buf, position);
@@ -120,6 +124,10 @@
sqlType = SQLPart.SQLType.FROM;
if (sql.matches("[\\s]*FROM.*WHERE.*")) {
end = sql.indexOf("WHERE");
+ } else if (sql.matches("[\\s]*FROM.*GROUP BY.*")) {
+ end = sql.indexOf("GROUP BY");
+ } else if (sql.matches("[\\s]*FROM.*ORDER BY.*")) {
+ end = sql.indexOf("ORDER BY");
}
} else if (sql.matches("[\\s]*WHERE.*")) {
sqlType = SQLPart.SQLType.WHERE;
@@ -135,6 +143,7 @@
}
} else if (sql.matches("[\\s]*GROUP BY.*")) {
sqlType = SQLPart.SQLType.GROUPBY;
+ end = sqlSequence.length();
} else if (sql.matches("[\\s]*DELETE.*")) {
sqlType = SQLPart.SQLType.DELETE;
if (sql.matches("[\\s]*DELETE FROM.*")) {
@@ -191,7 +200,7 @@
}
private static TabCompletionInfo getGroupByTabCompletionInfo(SQLPart part, List<SQLPart> parts, int charsLeft) {
- String stringPart = part.getPart().toString();
+ String stringPart = part.getPart().toString().substring(0,charsLeft);
String subPart = stringPart.substring(stringPart.toUpperCase().indexOf("GROUP BY")+"GROUP BY".length(), charsLeft);
List<String> possibleMatches = new ArrayList<String>();
for (SQLPart pPart : parts) {
@@ -229,7 +238,7 @@
bestMatch.append(colName);
}
}
- if (bestMatch.length() > 0) {
+ if (bestMatch.length() > 0 && !possibleMatches.contains(bestMatch)) {
possibleMatches.add(0, bestMatch.toString());
}
}
|
|
From: SVN by r. <sv...@ca...> - 2009-02-27 20:13:28
|
Author: roy
Date: 2009-02-27 21:13:20 +0100 (Fri, 27 Feb 2009)
New Revision: 381
Modified:
src/main/java/nl/improved/sqlclient/SQLUtil.java
src/main/java/nl/improved/sqlclient/util/SQLParser.java
src/main/java/nl/improved/sqlclient/util/SQLPart.java
Log:
added unit test stuff
improved group by and order by tab completion
Modified: src/main/java/nl/improved/sqlclient/SQLUtil.java
===================================================================
--- src/main/java/nl/improved/sqlclient/SQLUtil.java 2009-02-27 08:10:51 UTC (rev 380)
+++ src/main/java/nl/improved/sqlclient/SQLUtil.java 2009-02-27 20:13:20 UTC (rev 381)
@@ -19,6 +19,7 @@
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Iterator;
+import nl.improved.sqlclient.util.SQLParser;
/**
* A SQL Utility class.
@@ -133,6 +134,9 @@
* @return tab completion info for the provided command lines.
*/
public static TabCompletionInfo getTabCompletionInfo(List<? extends CharSequence> commandInfo, Point commandPoint) {
+ /*if (true) {
+ return SQLParser.getTabCompletionInfo(commandInfo, 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", "UPDATE"}));
Modified: src/main/java/nl/improved/sqlclient/util/SQLParser.java
===================================================================
--- src/main/java/nl/improved/sqlclient/util/SQLParser.java 2009-02-27 08:10:51 UTC (rev 380)
+++ src/main/java/nl/improved/sqlclient/util/SQLParser.java 2009-02-27 20:13:20 UTC (rev 381)
@@ -199,6 +199,7 @@
String pSubPart = pPart.getPart().toString().substring("SELECT".length()).trim();
int lastIndex = 0;
int newIndex;
+ StringBuffer bestMatch = new StringBuffer();
while ( (newIndex = pSubPart.indexOf(',', lastIndex)) > 0) {
String colName = pSubPart.substring(lastIndex, newIndex).trim();
if (colName.indexOf(' ') >=0) {
@@ -206,6 +207,12 @@
}
if (!possibleMatches.contains(colName)) {
possibleMatches.add(colName);
+ if (colName.indexOf('(') < 0) {
+ if (bestMatch.length() > 0) {
+ bestMatch.append(',');
+ }
+ bestMatch.append(colName);
+ }
}
lastIndex = newIndex+1;
}
@@ -215,7 +222,16 @@
}
if (!possibleMatches.contains(colName) && colName.length() > 0) {
possibleMatches.add(colName);
+ if (colName.indexOf('(') < 0) {
+ if (bestMatch.length() > 0) {
+ bestMatch.append(',');
+ }
+ bestMatch.append(colName);
+ }
}
+ if (bestMatch.length() > 0) {
+ possibleMatches.add(0, bestMatch.toString());
+ }
}
}
if (subPart.trim().length() == 0 || subPart.trim().endsWith(",")) {
@@ -235,6 +251,9 @@
String subPart = stringPart.substring(stringPart.toUpperCase().indexOf("ORDER BY")+"ORDER BY".length(), charsLeft);
List<String> possibleMatches = new ArrayList<String>();
for (SQLPart pPart : parts) {
+ if (pPart.getSQLType() == SQLPart.SQLType.SELECT) {
+ possibleMatches.addAll(pPart.getColumnNames());
+ }
}
if (subPart.trim().length() == 0 || subPart.trim().endsWith(",")) {
return new TabCompletionInfo(TabCompletionInfo.MatchType.OTHER, possibleMatches);
Modified: src/main/java/nl/improved/sqlclient/util/SQLPart.java
===================================================================
--- src/main/java/nl/improved/sqlclient/util/SQLPart.java 2009-02-27 08:10:51 UTC (rev 380)
+++ src/main/java/nl/improved/sqlclient/util/SQLPart.java 2009-02-27 20:13:20 UTC (rev 381)
@@ -47,6 +47,33 @@
return sqlType+": "+ part.toString();
}
+ public List<String> getColumnNames() {
+
+ if (sqlType == SQLType.SELECT) {
+ String stringPart = getPart().toString();
+ String sub = stringPart.substring(stringPart.toUpperCase().indexOf("SELECT")+"SELECT".length());
+ List<String> returnValue = new ArrayList<String>();
+ int lastIndex = 0;
+ int newIndex;
+ while ( (newIndex = sub.indexOf(',', lastIndex)) > 0) {
+ String tableName = sub.substring(lastIndex, newIndex).trim();
+ if (tableName.indexOf(" ") > 0) {
+ tableName = tableName.substring(0, tableName.indexOf(" ")).trim();
+ }
+ returnValue.add(tableName);
+ lastIndex = newIndex+1;
+ }
+ String tmp = sub.substring(lastIndex).trim();
+ if (tmp.length() > 0) {
+ if (tmp.indexOf(" ") > 0) {
+ tmp = tmp.substring(0, tmp.indexOf(" ")).trim();
+ }
+ returnValue.add(tmp);
+ }
+ return returnValue;
+ }
+ throw new IllegalStateException("Table names are only available for SELECT ("+ sqlType+")");
+ }
public List<String> getTableNames() {
if (sqlType == SQLType.FROM || sqlType == SQLType.UPDATE) {
List<String> returnValue = new ArrayList<String>();
@@ -64,7 +91,6 @@
if (tableName.indexOf(" ") > 0) {
tableName = tableName.substring(0, tableName.indexOf(" ")).trim();
}
- System.err.println("********ADDTN: "+ tableName);
returnValue.add(tableName);
lastIndex = newIndex+1;
}
@@ -73,7 +99,6 @@
if (tmp.indexOf(" ") > 0) {
tmp = tmp.substring(0, tmp.indexOf(" ")).trim();
}
- System.err.println("********ADD: "+ tmp);
returnValue.add(tmp);
}
return returnValue;
|
|
From: SVN by r. <sv...@ca...> - 2009-02-27 08:10:59
|
Author: roy
Date: 2009-02-27 09:10:51 +0100 (Fri, 27 Feb 2009)
New Revision: 380
Added:
src/main/java/nl/improved/sqlclient/util/SQLParser.java
src/main/java/nl/improved/sqlclient/util/SQLPart.java
Log:
new sql parsing api
Added: src/main/java/nl/improved/sqlclient/util/SQLParser.java
===================================================================
--- src/main/java/nl/improved/sqlclient/util/SQLParser.java 2009-02-20 21:59:19 UTC (rev 379)
+++ src/main/java/nl/improved/sqlclient/util/SQLParser.java 2009-02-27 08:10:51 UTC (rev 380)
@@ -0,0 +1,396 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package nl.improved.sqlclient.util;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import nl.improved.sqlclient.Point;
+import nl.improved.sqlclient.SQLCommand;
+import nl.improved.sqlclient.TabCompletionInfo;
+
+/**
+ *
+ * @author roy
+ */
+public class SQLParser {
+ final static char[] breakCharacters = new char[]{' ', '\t', '.', ',', '(',')'};
+ /**
+ * A regular expression statement for name chars.
+ */
+ private static final String NAMING_CHAR = "(_|-|[0-9]|[A-Z])";
+ /**
+ * A table name regular expression statement.
+ */
+ private static final String TABLE = "[A-Z]+"+NAMING_CHAR+"*";
+ /**
+ * A column name regular expression statement.
+ */
+ private static final String COLUMN = "(\\*|[A-Z]+"+NAMING_CHAR+"*)";
+ /**
+ * A variable (table name + columnname) regular expression statement.
+ */
+ private static final String VAR = "(|"+TABLE+"\\.)"+COLUMN;
+ /**
+ * SQL Comparators.
+ */
+ private static final String COMPARATOR = "(=|<>|<|>|LIKE)";
+ /**
+ * A sql variable description.
+ */
+ private static final String VALUE = "('.*'|[0-9]+|"+VAR+")";
+
+ public static TabCompletionInfo getTabCompletionInfo(SQLCommand command, Point commandPoint) {
+ List<? extends CharSequence> lines = command.getLines();
+ return getTabCompletionInfo(lines, commandPoint);
+ }
+ public static TabCompletionInfo getTabCompletionInfo(List<? extends CharSequence> lines, Point commandPoint) {
+ StringBuffer buf = new StringBuffer();
+ int position = 0;
+ for (int y = 0; y < lines.size(); y++) {
+ CharSequence seq = lines.get(y);
+ if (y < commandPoint.y) {
+ position+=seq.length();
+ }
+ if (y == commandPoint.y) {
+ position+=commandPoint.x;
+ }
+ buf.append(seq);
+ }
+ return getTabCompletionInfo(buf, position);
+ }
+
+ public static TabCompletionInfo getTabCompletionInfo(CharSequence sql, int position) {
+
+ List<SQLPart> parts = parse(sql);
+ System.err.println("PARTS: "+ parts);
+ int charsLeft = position;
+ for (SQLPart part : parts) {
+ if (charsLeft <= part.getPart().length()) {
+ switch (part.getSQLType()) {
+ case SELECT :
+ return getSelectTabCompletionInfo(part, parts, charsLeft);
+ case FROM :
+ return getFromTabCompletionInfo(part, parts, charsLeft);
+ case WHERE :
+ return getWhereTabCompletionInfo(part, parts, charsLeft);
+ case GROUPBY :
+ return getGroupByTabCompletionInfo(part, parts, charsLeft);
+ case ORDERBY :
+ return getOrderByTabCompletionInfo(part, parts, charsLeft);
+ case DELETE :
+ return getDeleteTabCompletionInfo(part, parts, charsLeft);
+ case UPDATE :
+ return getUpdateTabCompletionInfo(part, parts, charsLeft);
+ case SET :
+ return getSetTabCompletionInfo(part, parts, charsLeft);
+ }
+ } else {
+ charsLeft -=part.getPart().length();
+ }
+ }
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD
+ , Arrays.asList(new String[]{"SELECT", "INSERT INTO", "UPDATE", "DELETE FROM", "ALTER TABLE"})
+ , sql);
+ }
+
+
+ static List<SQLPart> parse(CharSequence sqlSequence) {
+ List<SQLPart> returnValue = new ArrayList<SQLPart>();
+ if (sqlSequence.length() == 0) {
+ return returnValue;
+ }
+ SQLPart.SQLType sqlType;
+ int start = 0;
+ int end = sqlSequence.length();
+ String sql = sqlSequence.toString().toUpperCase();
+ //System.out.println("SQL: "+ sql);
+ //System.out.println("MATCHES: "+ sql.matches("SELECT.*"));
+ if (sql.matches("[\\s]*SELECT.*")) {
+ sqlType = SQLPart.SQLType.SELECT;
+ if (sql.matches("[\\s]*SELECT.*FROM.*")) {
+ end = sql.indexOf("FROM");
+ } else {
+ end = sqlSequence.length();
+ }
+ } else if (sql.matches("[\\s]*FROM.*")) {
+ sqlType = SQLPart.SQLType.FROM;
+ if (sql.matches("[\\s]*FROM.*WHERE.*")) {
+ end = sql.indexOf("WHERE");
+ }
+ } else if (sql.matches("[\\s]*WHERE.*")) {
+ sqlType = SQLPart.SQLType.WHERE;
+ if (sql.matches("[\\s]*WHERE.*ORDER BY.*")) {
+ end = sql.indexOf(" ORDER BY");
+ } else if (sql.matches("[\\s]*WHERE.*GROUP BY.*")) {
+ end = sql.indexOf("GROUP BY");
+ }
+ } else if (sql.matches("[\\s]*ORDER BY.*")) {
+ sqlType = SQLPart.SQLType.ORDERBY;
+ if (sql.matches("[\\s]*ORDER BY.*GROUP BY.*")) {
+ end = sql.indexOf("GROUP BY");
+ }
+ } else if (sql.matches("[\\s]*GROUP BY.*")) {
+ sqlType = SQLPart.SQLType.GROUPBY;
+ } else if (sql.matches("[\\s]*DELETE.*")) {
+ sqlType = SQLPart.SQLType.DELETE;
+ if (sql.matches("[\\s]*DELETE FROM.*")) {
+ end = sql.indexOf("FROM");
+ } else {
+ end = sqlSequence.length();
+ }
+ } else if (sql.matches("[\\s]*UPDATE.*")) {
+ sqlType = SQLPart.SQLType.UPDATE;
+ if (sql.matches("[\\s]*UPDATE.*SET.*")) {
+ end = sql.indexOf("SET");
+ } else {
+ end = sqlSequence.length();
+ }
+ } else if (sql.matches("[\\s]*SET.*")) {
+ sqlType = SQLPart.SQLType.SET;
+ if (sql.matches("[\\s]*WHERE.*")) {
+ end = sql.indexOf("WHERE");
+ } else {
+ end = sqlSequence.length();
+ }
+ } else {
+ sqlType = SQLPart.SQLType.OTHER;
+ }
+ returnValue.add(new SQLPart(sqlType, sqlSequence.subSequence(start, end)));
+ returnValue.addAll(parse(sqlSequence.subSequence(end, sqlSequence.length())));
+ return returnValue;
+ }
+
+ private static TabCompletionInfo getDeleteTabCompletionInfo(SQLPart part, List<SQLPart> parts, int charsLeft) {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ private static TabCompletionInfo getFromTabCompletionInfo(SQLPart part, List<SQLPart> parts, int charsLeft) {
+ String stringPart = part.getPart().toString();
+ String subPart = stringPart.substring(stringPart.toUpperCase().indexOf("FROM") +"FROM".length(), charsLeft);
+ String end;
+ if (subPart.indexOf(',') > 0) {
+ end = subPart.substring(subPart.lastIndexOf(',')+1);
+ } else {
+ end = subPart;
+ }
+ 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 (subPart.trim().length() > 0 && (end.endsWith(" ") || subPart.matches(".*"+TABLE+"[\\s]+("+WHERE+"|"+GROUP_BY+"|"+ORDER_BY+")")) &&
+ !subPart.trim().endsWith(",")) {
+ if (subPart.lastIndexOf(" ") >0) {
+ end = end.substring(end.lastIndexOf(' ')+1);
+ }
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD, Arrays.asList(new String[]{"WHERE", "GROUP BY", "ORDER BY", ","}), end.trim());
+ }
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.TABLE_NAMES, Arrays.asList(new String[]{}), end.trim());
+ }
+
+ private static TabCompletionInfo getGroupByTabCompletionInfo(SQLPart part, List<SQLPart> parts, int charsLeft) {
+ String stringPart = part.getPart().toString();
+ String subPart = stringPart.substring(stringPart.toUpperCase().indexOf("GROUP BY")+"GROUP BY".length(), charsLeft);
+ List<String> possibleMatches = new ArrayList<String>();
+ for (SQLPart pPart : parts) {
+ if (pPart.getSQLType() == SQLPart.SQLType.SELECT) {
+ String pSubPart = pPart.getPart().toString().substring("SELECT".length()).trim();
+ int lastIndex = 0;
+ int newIndex;
+ while ( (newIndex = pSubPart.indexOf(',', lastIndex)) > 0) {
+ String colName = pSubPart.substring(lastIndex, newIndex).trim();
+ if (colName.indexOf(' ') >=0) {
+ colName = colName.substring(colName.lastIndexOf(' '));
+ }
+ if (!possibleMatches.contains(colName)) {
+ possibleMatches.add(colName);
+ }
+ lastIndex = newIndex+1;
+ }
+ String colName = pSubPart.substring(lastIndex).trim();
+ if (colName.indexOf(' ') >=0) { // alias
+ colName = colName.substring(colName.lastIndexOf(' '));
+ }
+ if (!possibleMatches.contains(colName) && colName.length() > 0) {
+ possibleMatches.add(colName);
+ }
+ }
+ }
+ if (subPart.trim().length() == 0 || subPart.trim().endsWith(",")) {
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.OTHER, possibleMatches);
+ }
+ String end;
+ if (subPart.indexOf(',') > 0) {
+ end = subPart.substring(subPart.lastIndexOf(',')).trim();
+ } else {
+ end = subPart.trim();
+ }
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.OTHER, possibleMatches, end);
+ }
+
+ private static TabCompletionInfo getOrderByTabCompletionInfo(SQLPart part, List<SQLPart> parts, int charsLeft) {
+ String stringPart = part.getPart().toString();
+ String subPart = stringPart.substring(stringPart.toUpperCase().indexOf("ORDER BY")+"ORDER BY".length(), charsLeft);
+ List<String> possibleMatches = new ArrayList<String>();
+ for (SQLPart pPart : parts) {
+ }
+ if (subPart.trim().length() == 0 || subPart.trim().endsWith(",")) {
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.OTHER, possibleMatches);
+ }
+ String end;
+ if (subPart.indexOf(',') > 0) {
+ end = subPart.substring(subPart.lastIndexOf(',')).trim();
+ } else {
+ end = subPart.trim();
+ }
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.OTHER, possibleMatches, end);
+ }
+
+ private static TabCompletionInfo getSelectTabCompletionInfo(SQLPart part, List<SQLPart> parts, int position) {
+ // if it looks like:
+ // SELECT x
+ // return "FROM"
+ String startOfCommand = part.getPart().toString();
+ String upCommand = startOfCommand.toUpperCase();
+ 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);
+ }
+ // if it looks like:
+ // SELECT
+ // or
+ // SELECT A,
+ // return matching columnnames when table names are provided in from clause
+ // other wise return table names
+ // TODO check for WHERE Clause
+ String lastKeyword = "SELECT";
+ String sub = startOfCommand.substring(upCommand.indexOf(lastKeyword)+lastKeyword.length()).trim();
+ String tableName;
+ if (sub.indexOf(',') > 0) {
+ tableName = sub.substring(sub.lastIndexOf(',')+1).trim();
+ } else {
+ tableName = sub;
+ }
+ if (tableName.indexOf('.') > 0) {
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES
+ , Arrays.asList(new String[]{tableName.substring(0,tableName.indexOf('.'))})
+ , tableName.substring(tableName.indexOf('.')+1));
+ }
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.TABLE_NAMES
+ , Arrays.asList(new String[0]), tableName);
+ }
+
+ private static TabCompletionInfo getSetTabCompletionInfo(SQLPart part, List<SQLPart> parts, int charsLeft) {
+ String startOfCommand = part.getPart().toString().substring(0, charsLeft);
+ String tmpCommand = startOfCommand.substring(startOfCommand.toUpperCase().indexOf("SET")+"SET".length()+1);
+ if (tmpCommand.indexOf(',') >0) {
+ tmpCommand = tmpCommand.substring(tmpCommand.lastIndexOf(',')+1);
+ }
+ if (tmpCommand.endsWith(" ")) {
+ if (tmpCommand.matches(".*"+COMPARATOR+"[\\s]*")) {
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES
+ , getTableNames(parts));
+ }
+ if (tmpCommand.matches(".*"+COMPARATOR+"[\\s]*"+VAR+"[\\s]*")) {
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD
+ , Arrays.asList(new String[]{",", "WHERE"}));
+ }
+ if (tmpCommand.trim().length() > 0) {
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD
+ , Arrays.asList(new String[]{"=", "<>", "LIKE", "<", ">"}));
+ }
+ }
+ if (tmpCommand.trim().length() == 0) {
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES
+ , getTableNames(parts));
+ }
+ String end;
+ if (tmpCommand.indexOf(' ') > 0) {
+ end = tmpCommand.substring(tmpCommand.lastIndexOf(' ')+1).trim();
+ } else {
+ end = tmpCommand.trim();
+ }
+ if (tmpCommand.trim().length() > 0) {
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD
+ , Arrays.asList(new String[]{"=", "<>", "LIKE", "<", ">"}), end);
+ }
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD
+ , Arrays.asList(new String[]{",", "WHERE"})); // TODO END
+ }
+
+ private static List<String> getTableNames(List<SQLPart> parts) {
+ SQLPart fromSqlPart = null;
+ for (SQLPart tmpPart : parts) {
+ if (tmpPart.getSQLType() == SQLPart.SQLType.FROM || tmpPart.getSQLType() == SQLPart.SQLType.UPDATE) {
+ fromSqlPart = tmpPart;
+ }
+ }
+ return fromSqlPart.getTableNames();
+ }
+
+ private static TabCompletionInfo getUpdateTabCompletionInfo(SQLPart part, List<SQLPart> parts, int charsLeft) {
+ String startOfCommand = part.getPart().toString().substring(0, charsLeft);
+ String tmpCommand = startOfCommand.substring(startOfCommand.toUpperCase().indexOf("UPDATE")+"UPDATE".length()+1);
+ if (tmpCommand.trim().length() > 0 && tmpCommand.lastIndexOf(' ') > 0) {
+ String end = tmpCommand.substring(tmpCommand.lastIndexOf(' ') +1);
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD
+ , Arrays.asList(new String[]{"SET"}), end);
+ }
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.TABLE_NAMES
+ , new ArrayList(), tmpCommand.trim());
+ }
+
+ private static TabCompletionInfo getWhereTabCompletionInfo(SQLPart part, List<SQLPart> parts, int charsLeft) {
+ // find out if it looks like
+ // 'SELECT x FROM A,B WHERE'
+ // or
+ // 'SELECT x FROM A,B WHERE A.x='x' AND/OR '
+ String startOfCommand = part.getPart().toString().substring(0, charsLeft);
+ String tmpCommand = startOfCommand.substring(startOfCommand.toUpperCase().indexOf("WHERE")+"WHERE".length()+1);
+ String upperCommandString = tmpCommand.toUpperCase();
+ //String VAR = "(|"+TABLE+"\\.)(|"+COLUMN+")";
+ //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) || upperCommandString.endsWith(".")) {
+ System.err.println("****** MATCHES: "+ upperCommandString);
+ 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('>'));
+ 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()}) :
+ getTableNames(parts);
+ return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES
+ , tableNames, end);
+ }
+ System.err.println("****** NOT MATCHES: "+ upperCommandString+"\n"+ regExp);
+ //else System.out.println("'"+upperCommandString +"'\n not matches\n"+regExp);
+ String end;
+ if (upperCommandString.matches(".*[\\s]+")) {
+ end = "";
+ } else {
+ 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);
+ }
+
+}
Added: src/main/java/nl/improved/sqlclient/util/SQLPart.java
===================================================================
--- src/main/java/nl/improved/sqlclient/util/SQLPart.java 2009-02-20 21:59:19 UTC (rev 379)
+++ src/main/java/nl/improved/sqlclient/util/SQLPart.java 2009-02-27 08:10:51 UTC (rev 380)
@@ -0,0 +1,84 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package nl.improved.sqlclient.util;
+
+import java.util.ArrayList;
+import java.util.List;
+import nl.improved.sqlclient.TabCompletionInfo;
+
+/**
+ *
+ * @author roy
+ */
+public class SQLPart {
+
+ enum SQLType {SELECT, INSERT, UPDATE, DELETE, WHERE, VALUES, FROM, GROUPBY, ORDERBY, OTHER, SET}
+
+ private SQLType sqlType;
+ private CharSequence part;
+
+ public SQLPart(SQLType sqlType, CharSequence part) {
+ this.sqlType = sqlType;
+ this.part = part;
+ }
+
+ public SQLType getSQLType() {
+ return sqlType;
+ }
+
+ public CharSequence getPart() {
+ return part;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null || !(obj instanceof SQLPart)) {
+ return false;
+ }
+ SQLPart other = (SQLPart) obj;
+ return other.part.equals(part) && other.sqlType == sqlType;
+ }
+
+ @Override
+ public String toString() {
+ return sqlType+": "+ part.toString();
+ }
+
+ public List<String> getTableNames() {
+ if (sqlType == SQLType.FROM || sqlType == SQLType.UPDATE) {
+ List<String> returnValue = new ArrayList<String>();
+ String stringPart = getPart().toString();
+ String sub;
+ if (sqlType == SQLType.FROM) {
+ sub = stringPart.substring(stringPart.toUpperCase().indexOf("FROM")+"FROM".length());
+ } else {
+ sub = stringPart.substring(stringPart.toUpperCase().indexOf("UPDATE")+"UPDATE".length());
+ }
+ int lastIndex = 0;
+ int newIndex;
+ while ( (newIndex = sub.indexOf(',', lastIndex)) > 0) {
+ String tableName = sub.substring(lastIndex, newIndex).trim();
+ if (tableName.indexOf(" ") > 0) {
+ tableName = tableName.substring(0, tableName.indexOf(" ")).trim();
+ }
+ System.err.println("********ADDTN: "+ tableName);
+ returnValue.add(tableName);
+ lastIndex = newIndex+1;
+ }
+ String tmp = sub.substring(lastIndex).trim();
+ if (tmp.length() > 0) {
+ if (tmp.indexOf(" ") > 0) {
+ tmp = tmp.substring(0, tmp.indexOf(" ")).trim();
+ }
+ System.err.println("********ADD: "+ tmp);
+ returnValue.add(tmp);
+ }
+ return returnValue;
+ }
+ throw new IllegalStateException("Table names are only available for FROM,UPDATE ("+ sqlType+")");
+ }
+
+}
\ No newline at end of file
|
|
From: SVN by r. <sv...@ca...> - 2009-02-20 23:46:05
|
Author: roy Date: 2009-02-20 22:59:19 +0100 (Fri, 20 Feb 2009) New Revision: 379 Modified: pom.xml src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java src/main/java/nl/improved/sqlclient/TabCompletionInfo.java Log: small code cleanup version 0.7 started Modified: pom.xml =================================================================== --- pom.xml 2009-02-20 20:54:04 UTC (rev 378) +++ pom.xml 2009-02-20 21:59:19 UTC (rev 379) @@ -19,7 +19,7 @@ <groupId>nl.improved</groupId> <artifactId>sqlshell</artifactId> <packaging>jar</packaging> - <version>0.6.2</version> + <version>0.7-SNAPSHOT</version> <name>SQLShell ~ the improved sqlclient</name> <url>http://sqlshell.sourceforge.org</url> <build> Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java =================================================================== --- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2009-02-20 20:54:04 UTC (rev 378) +++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2009-02-20 21:59:19 UTC (rev 379) @@ -927,12 +927,13 @@ * @param sub the start of the match * @return the match starting with sub minus the sub itself in the correct casing */ - protected CharSequence findMatch(List<String> values, String sub) { + protected CharSequence findMatch(List<String> values, CharSequence sub) { List<String> matches = new ArrayList<String>(); Iterator<String> iValues = values.iterator(); + String subUpper = sub.toString().toUpperCase(); while (iValues.hasNext()) { String value = iValues.next(); - if (value.toUpperCase().startsWith(sub.toUpperCase())) { + if (value.toUpperCase().startsWith(subUpper)) { matches.add(value); } } @@ -954,7 +955,7 @@ } if (match != null) { match = DBConnector.getInstance().translateDbVar(match); - if (sub.length() > 0 && !match.startsWith(sub)) { // case insensitive change + if (sub.length() > 0 && !match.startsWith(sub.toString())) { // case insensitive change Point cursorPosition = screen.getCursorPosition(); List<StringBuffer> lines = getEditableCommand().getEditableLines(); if (lines.get(cursorPosition.y).length() >=sub.length()) { Modified: src/main/java/nl/improved/sqlclient/TabCompletionInfo.java =================================================================== --- src/main/java/nl/improved/sqlclient/TabCompletionInfo.java 2009-02-20 20:54:04 UTC (rev 378) +++ src/main/java/nl/improved/sqlclient/TabCompletionInfo.java 2009-02-20 21:59:19 UTC (rev 379) @@ -22,13 +22,13 @@ private MatchType type; private List<String> possibleMatches; - private String start; + private CharSequence start; public TabCompletionInfo(MatchType type, List<String> possibleMatches) { this(type, possibleMatches, ""); } - public TabCompletionInfo(MatchType type, List<String> possibleMatches, String start) { + public TabCompletionInfo(MatchType type, List<String> possibleMatches, CharSequence start) { this.type = type; this.possibleMatches = possibleMatches; this.start = start; @@ -40,7 +40,7 @@ public List<String> getPossibleMatches() { return possibleMatches; } - public String getStart() { + public CharSequence getStart() { return start; } |
|
From: SVN by r. <sv...@ca...> - 2009-02-20 20:54:15
|
Author: roy
Date: 2009-02-20 21:54:04 +0100 (Fri, 20 Feb 2009)
New Revision: 378
Added:
docs/
docs/release-0.6.2.txt
Log:
release info
Added: docs/release-0.6.2.txt
===================================================================
--- docs/release-0.6.2.txt 2009-02-20 20:53:57 UTC (rev 377)
+++ docs/release-0.6.2.txt 2009-02-20 20:54:04 UTC (rev 378)
@@ -0,0 +1,19 @@
+The Internet: Februari 20 2009
+This is a new maintenance release of the 0.6 version of sqlshell. We decided
+to move back to having only one startup file instead of one per engine. The startup
+file figures out which version to load. This also introduced command line sql command
+execution (via a batch file).
+
+Furthermore the windows startup file should be fixed (thanks for pointing that out to me).
+Please let us know if you have any more issues. We love to get them fixed/fix them for you.
+
+Some new features of 0.6 include:
+* Added command line input support. (See --help for more info)
+* pageup/down bugfix
+* All kind of sqlcommand parsing fixes in batch ('@') command
+* Added continue/abort parameters for batch command (See help @)
+
+See the Changelog file for a complete list.
+
+Kind regards,
+Roy
|
|
From: SVN by r. <sv...@ca...> - 2009-02-20 20:54:02
|
Author: roy
Date: 2009-02-20 21:53:57 +0100 (Fri, 20 Feb 2009)
New Revision: 377
Modified:
ChangeLog
makejars.sh
pom.xml
Log:
0.6.2 mainenance release
Modified: ChangeLog
===================================================================
--- ChangeLog 2009-02-20 20:46:47 UTC (rev 376)
+++ ChangeLog 2009-02-20 20:53:57 UTC (rev 377)
@@ -1,4 +1,4 @@
-0.7
+0.6.2 (2009-02-20)
* Commandline input support
* -engine option to switch between charva (default) and jcurses
* Paged command output (no longer out of memory exceptions with large
Modified: makejars.sh
===================================================================
--- makejars.sh 2009-02-20 20:46:47 UTC (rev 376)
+++ makejars.sh 2009-02-20 20:53:57 UTC (rev 377)
@@ -1,6 +1,6 @@
#!/bin/bash
PROJECT=sqlshell
-VERSION=0.7
+VERSION=0.6.2
#cleanup
rm -Rf release
Modified: pom.xml
===================================================================
--- pom.xml 2009-02-20 20:46:47 UTC (rev 376)
+++ pom.xml 2009-02-20 20:53:57 UTC (rev 377)
@@ -19,7 +19,7 @@
<groupId>nl.improved</groupId>
<artifactId>sqlshell</artifactId>
<packaging>jar</packaging>
- <version>0.7-SNAPSHOT</version>
+ <version>0.6.2</version>
<name>SQLShell ~ the improved sqlclient</name>
<url>http://sqlshell.sourceforge.org</url>
<build>
|