From: SVN by r. <sv...@ca...> - 2007-10-28 20:09:03
|
Author: roy Date: 2007-10-28 21:08:10 +0100 (Sun, 28 Oct 2007) New Revision: 191 Added: src/test/java/nl/improved/sqlclient/commands/ src/test/java/nl/improved/sqlclient/commands/ShowCommandTest.java Modified: ChangeLog src/main/java/nl/improved/sqlclient/SQLCommand.java src/main/java/nl/improved/sqlclient/commands/ShowCommand.java Log: added tab completion for show command Modified: ChangeLog =================================================================== --- ChangeLog 2007-10-28 19:25:48 UTC (rev 190) +++ ChangeLog 2007-10-28 20:08:10 UTC (rev 191) @@ -3,6 +3,7 @@ * Added tabcompletion for: * desc * execute batch command + * show 0.3 (09-10-2007) * focus fix in login dialog * Improve desc table to show primary key Modified: src/main/java/nl/improved/sqlclient/SQLCommand.java =================================================================== --- src/main/java/nl/improved/sqlclient/SQLCommand.java 2007-10-28 19:25:48 UTC (rev 190) +++ src/main/java/nl/improved/sqlclient/SQLCommand.java 2007-10-28 20:08:10 UTC (rev 191) @@ -55,7 +55,7 @@ } returnValue.append(parts.next()); } - return returnValue.toString().trim(); + return returnValue.toString(); } public String getCommandString() { String returnString = getUntrimmedCommandString(); Modified: src/main/java/nl/improved/sqlclient/commands/ShowCommand.java =================================================================== --- src/main/java/nl/improved/sqlclient/commands/ShowCommand.java 2007-10-28 19:25:48 UTC (rev 190) +++ src/main/java/nl/improved/sqlclient/commands/ShowCommand.java 2007-10-28 20:08:10 UTC (rev 191) @@ -20,6 +20,7 @@ import nl.improved.sqlclient.Point; import nl.improved.sqlclient.SQLUtil; import nl.improved.sqlclient.TabCompletionInfo; +import java.util.Arrays; import java.util.List; import java.util.ArrayList; import java.util.Iterator; @@ -103,7 +104,24 @@ * @return some tab completion info for the specified command. */ public TabCompletionInfo getTabCompletionInfo(SQLCommand command, Point commandPoint) { - return null; + String commandString = command.getUntrimmedCommandString(); + String commandStringUpper = commandString.toUpperCase(); + + if (commandStringUpper.matches("[\\s]*SHOW[\\s]+TABLES[\\s]+HAVING[\\s]+([A-Z]|_|-|[0-9])*")) { + String end = commandString.trim().substring(commandString.trim().lastIndexOf(' ')+1).trim(); + if (end.equalsIgnoreCase("HAVING")) { + return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES, Arrays.asList(new String[]{"%"}), ""); + } else { + return new TabCompletionInfo(TabCompletionInfo.MatchType.COLUMN_NAMES, Arrays.asList(new String[]{"%"}), end); + } + } + + String startOfCommand = SQLUtil.getStartOfCommand(command.getLines(), commandPoint); + String end = startOfCommand.substring(startOfCommand.lastIndexOf(' ')+1); + if (commandStringUpper.matches("SHOW[\\s]+(|T|TA|TAB|TABL|TABLE)")) { + return new TabCompletionInfo(TabCompletionInfo.MatchType.UNKNOWN, Arrays.asList(new String[]{"TABLES"}), end); + } + return new TabCompletionInfo(TabCompletionInfo.MatchType.UNKNOWN, Arrays.asList(new String[]{"HAVING"}), end); } /** Added: src/test/java/nl/improved/sqlclient/commands/ShowCommandTest.java =================================================================== --- src/test/java/nl/improved/sqlclient/commands/ShowCommandTest.java (rev 0) +++ src/test/java/nl/improved/sqlclient/commands/ShowCommandTest.java 2007-10-28 20:08:10 UTC (rev 191) @@ -0,0 +1,46 @@ +/* + * Copyright 2007 Roy van der Kuil (ro...@va...) and Stefan Rotman (st...@ro...) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package nl.improved.sqlclient.commands; + +import nl.improved.sqlclient.*; +import java.util.Arrays; +import java.util.List; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +public class ShowCommandTest extends TestCase { + + private static final boolean testFailures = true; + + public ShowCommandTest() { + } + + public void testGetTabCompletionInfo() { + ShowCommand cmd = new ShowCommand(); + SQLCommand sqlCommand = new SQLCommand(); + sqlCommand.getEditableLines().add(new StringBuilder("SHOW TABLES HAVING ")); + Point cursorPos = new Point(sqlCommand.getLines().get(0).length(),0); + TabCompletionInfo info = cmd.getTabCompletionInfo(sqlCommand, cursorPos); + assertNotNull(info); + assertEquals(TabCompletionInfo.MatchType.COLUMN_NAMES, info.getMatchType()); + assertEquals(1, info.getPossibleMatches().size()); + assertEquals("%", info.getPossibleMatches().get(0)); + assertEquals("", info.getStart()); + } + +} |