From: SVN by r. <sv...@ca...> - 2007-10-08 10:51:00
|
Author: rotman Date: 2007-10-08 12:50:54 +0200 (Mon, 08 Oct 2007) New Revision: 165 Modified: ChangeLog src/main/java/nl/improved/sqlclient/SQLShell.java src/main/java/nl/improved/sqlclient/SQLUtil.java src/test/java/nl/improved/sqlclient/SQLUtilTest.java Log: Added tab extention for desc Modified: ChangeLog =================================================================== --- ChangeLog 2007-10-08 09:49:45 UTC (rev 164) +++ ChangeLog 2007-10-08 10:50:54 UTC (rev 165) @@ -5,6 +5,7 @@ * Improve tab completion for update * NullPointerException fix when not running from jar. * Quit with ^D (on empty commandline) + * Added tab-completion for DESC command 0.2 (17-09-2007) * Search in history (for example by entering '/query' to make the current command the last command with query in it) Modified: src/main/java/nl/improved/sqlclient/SQLShell.java =================================================================== --- src/main/java/nl/improved/sqlclient/SQLShell.java 2007-10-08 09:49:45 UTC (rev 164) +++ src/main/java/nl/improved/sqlclient/SQLShell.java 2007-10-08 10:50:54 UTC (rev 165) @@ -25,6 +25,7 @@ import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; +import javax.sound.midi.SysexMessage; import jcurses.widgets.Window; import jcurses.system.InputChar; import jcurses.system.Toolkit; @@ -558,6 +559,7 @@ return nullToEmpty(findMatch(info.getPossibleMatches(), info.getStart())); } if (info.getMatchType() == SQLUtil.TabCompletionInfo.MatchType.TABLE_NAMES) { + //debug("table completion for \""+info.getStart()+"\""); return nullToEmpty(findMatch(getTableNames(), info.getStart())); } if (info.getMatchType() == SQLUtil.TabCompletionInfo.MatchType.COLUMN_NAMES) { Modified: src/main/java/nl/improved/sqlclient/SQLUtil.java =================================================================== --- src/main/java/nl/improved/sqlclient/SQLUtil.java 2007-10-08 09:49:45 UTC (rev 164) +++ src/main/java/nl/improved/sqlclient/SQLUtil.java 2007-10-08 10:50:54 UTC (rev 165) @@ -47,7 +47,7 @@ */ private static final String VALUE = "('>*'|[0-9]+|"+VAR+")"; - public static List<String> KEYWORDS = Arrays.asList(new String[]{"SELECT", "UPDATE", "FROM", "WHERE", "VALUES", "SET", "INSERT", "INTO", "DELETE", "IS", "NULL", "IN", "NOT", "GROUP BY"}); + public static List<String> KEYWORDS = Arrays.asList(new String[]{"SELECT", "UPDATE", "FROM", "WHERE", "VALUES", "SET", "INSERT", "INTO", "DELETE", "IS", "NULL", "IN", "NOT", "GROUP BY", "DESC"}); /** * Private constructor. @@ -121,13 +121,13 @@ public static TabCompletionInfo getTabCompletionInfo(List<? extends CharSequence> commandInfo, Point commandPoint) { if (commandInfo.size() == 1 && commandInfo.get(0).length() == 0) { return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD - , Arrays.asList(new String[]{"SELECT", "INSERT INTO", "DELETE FROM", "UPDATE"})); + , Arrays.asList(new String[]{"SELECT", "INSERT INTO", "DELETE FROM", "UPDATE", "DESC"})); } String startOfCommand = getStartOfCommand(commandInfo, commandPoint); String lastKeyword = getLastKeyWord(startOfCommand); if (lastKeyword == null) { return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD - , Arrays.asList(new String[]{"SELECT", "INSERT INTO", "DELETE FROM", "UPDATE"}), startOfCommand); + , Arrays.asList(new String[]{"SELECT", "INSERT INTO", "DELETE FROM", "UPDATE", "DESC"}), startOfCommand); } if (lastKeyword.equalsIgnoreCase("UPDATE")) { String end = startOfCommand.substring(startOfCommand.lastIndexOf(' ')+1); @@ -242,6 +242,9 @@ } return new TabCompletionInfo(TabCompletionInfo.MatchType.SQL_KEYWORD , Arrays.asList(new String[]{"AND", "OR", "IN", "GROUP BY", "ORDER BY"})); + } else if (lastKeyword.equalsIgnoreCase("DESC")) { + String end = startOfCommand.substring(startOfCommand.lastIndexOf(' ')+1); + return new TabCompletionInfo(TabCompletionInfo.MatchType.TABLE_NAMES, new ArrayList<String>(), end); } return new TabCompletionInfo(TabCompletionInfo.MatchType.UNKNOWN, Arrays.asList(new String[0])); } Modified: src/test/java/nl/improved/sqlclient/SQLUtilTest.java =================================================================== --- src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2007-10-08 09:49:45 UTC (rev 164) +++ src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2007-10-08 10:50:54 UTC (rev 165) @@ -50,6 +50,8 @@ assertTrue(matches.contains("SELECT")); assertTrue(matches.contains("INSERT INTO")); assertTrue(matches.contains("DELETE FROM")); + assertTrue(matches.contains("UPDATE")); + assertTrue(matches.contains("DESC")); } public void testTabCompletionInfoSELECT() { @@ -315,4 +317,14 @@ assertEquals("A", matches.get(0)); assertEquals("", info.getStart()); } + + public void testTabCompletionInfoDESC() { + List<String> sqlCommand = Arrays.asList(new String[]{"DESC "}); + Point cursorPos = new Point(sqlCommand.get(0).length(),0); + SQLUtil.TabCompletionInfo info = SQLUtil.getTabCompletionInfo(sqlCommand, cursorPos); + assertNotNull(info); + assertEquals(SQLUtil.TabCompletionInfo.MatchType.TABLE_NAMES, info.getMatchType()); + List<String> matches = info.getPossibleMatches(); + assertEquals(0, matches.size()); + } } |
From: SVN by r. <sv...@ca...> - 2007-10-08 12:16:15
|
Author: rotman Date: 2007-10-08 14:16:13 +0200 (Mon, 08 Oct 2007) New Revision: 166 Modified: ChangeLog src/main/java/nl/improved/sqlclient/SQLUtil.java src/test/java/nl/improved/sqlclient/SQLUtilTest.java Log: Fix tab completion for in-word keyword matches Modified: ChangeLog =================================================================== --- ChangeLog 2007-10-08 10:50:54 UTC (rev 165) +++ ChangeLog 2007-10-08 12:16:13 UTC (rev 166) @@ -1,11 +1,12 @@ 0.3 (Unreleased) * focus fix in login dialog * Improve desc table to show primary key - * fix to stop spooled lines being appended to each other. + * BUGFIX: fix to stop spooled lines being appended to each other. * Improve tab completion for update - * NullPointerException fix when not running from jar. + * BUGFIX: NullPointerException fix when not running from jar. * Quit with ^D (on empty commandline) - * Added tab-completion for DESC command + * Added tab completion for DESC command + * BUGFIX: fix tab completion when a "keyword" was found as part of a name. 0.2 (17-09-2007) * Search in history (for example by entering '/query' to make the current command the last command with query in it) Modified: src/main/java/nl/improved/sqlclient/SQLUtil.java =================================================================== --- src/main/java/nl/improved/sqlclient/SQLUtil.java 2007-10-08 10:50:54 UTC (rev 165) +++ src/main/java/nl/improved/sqlclient/SQLUtil.java 2007-10-08 12:16:13 UTC (rev 166) @@ -27,13 +27,17 @@ public class SQLUtil { /** + * 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]+(_|-|[0-9]|[A-Z])*"; + private static final String TABLE = "[A-Z]+"+NAMING_CHAR+"*"; /** * A column name regular expression statement. */ - private static final String COLUMN = "[A-Z]+(_|-|[0-9]|[A-Z])*"; + private static final String COLUMN = "[A-Z]+"+NAMING_CHAR+"*"; /** * A variable (table name + columnname) regular expression statement. */ @@ -69,6 +73,15 @@ while (iKeywords.hasNext()) { String keyword = iKeywords.next(); int tmpIndex = seqUpper.indexOf(keyword); + int tmpEndIndex = tmpIndex+keyword.length(); + + //Ensuring the keyword is not a in-word match + if (tmpIndex > 0 && seqUpper.substring(tmpIndex-1, tmpIndex).matches(NAMING_CHAR)) { + continue; + } else if (tmpIndex != -1 && tmpEndIndex < seqUpper.length() && seqUpper.substring(tmpEndIndex, tmpEndIndex+1).matches(NAMING_CHAR)) { + continue; + } + if (tmpIndex > maxIndex) { maxIndex = tmpIndex; lastKeyWord = seq.substring(maxIndex, maxIndex+keyword.length()); Modified: src/test/java/nl/improved/sqlclient/SQLUtilTest.java =================================================================== --- src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2007-10-08 10:50:54 UTC (rev 165) +++ src/test/java/nl/improved/sqlclient/SQLUtilTest.java 2007-10-08 12:16:13 UTC (rev 166) @@ -38,6 +38,10 @@ assertEquals("from", SQLUtil.getLastKeyWord(sql)); sql = "SELECT * FROM"; assertEquals("FROM", SQLUtil.getLastKeyWord(sql)); + sql = "DESC indummy"; + assertEquals("DESC", SQLUtil.getLastKeyWord(sql)); + sql = "DESC dummyin "; + assertEquals("DESC", SQLUtil.getLastKeyWord(sql)); } public void testTabCompletionInfoBLANK() { |