|
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());
}
}
|