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-01-16 20:44:19
|
Author: roy Date: 2009-01-16 21:44:06 +0100 (Fri, 16 Jan 2009) New Revision: 351 Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java src/main/java/nl/improved/sqlclient/QueryExecutor.java Log: improved exception handling Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java =================================================================== --- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2009-01-16 20:10:20 UTC (rev 350) +++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2009-01-16 20:44:06 UTC (rev 351) @@ -455,16 +455,23 @@ commandThread = new CommandThread(cmd.cmd) { @Override void execute() { - CommandResult result = getCommand().execute(cmd.sql); - Iterator<CharSequence> iResult = result.getResult(); - while (iResult.hasNext()) { - output(iResult.next()); + try { + CommandResult result = getCommand().execute(cmd.sql); + if (result.getResult() == null) { + output("NULL FOR: "+ result); + } + Iterator<CharSequence> iResult = result.getResult(); + while (iResult.hasNext()) { + output(iResult.next()); + repaint(); + } + if (!result.executedSuccessfully()) { + output("Execution Failed...\n"); + } repaint(); + } catch(Exception e) { + error(e); } - if (!result.executedSuccessfully()) { - output("Execution Failed...\n"); - } - repaint(); } }; commandThread.setDaemon(true); @@ -1035,15 +1042,19 @@ } output(sqlCommand.getLines()); //repaint(); - CommandResult commandResult = command.execute(sqlCommand); - Iterator<CharSequence> result = commandResult.getResult(); - while (result.hasNext()) { - output(result.next()); - repaint(); + try { + CommandResult commandResult = command.execute(sqlCommand); + Iterator<CharSequence> result = commandResult.getResult(); + while (result.hasNext()) { + output(result.next()); + repaint(); + } + if (!commandResult.executedSuccessfully()) { + output("Execution Failed...\n"); + } + } catch(Exception e) { + error(e); } - if (!commandResult.executedSuccessfully()) { - output("Execution Failed...\n"); - } repaint(); return true; } @@ -2083,14 +2094,14 @@ continue; } cmd.append(line); - //if (line.endsWith(";")) { - String commandString = cmd.toString(); - currentCommand = sqlShell.createCommand(commandString); - if (currentCommand == null) { - continue; - } - // Exec cmd - sqlShell.output(commandString); + String commandString = cmd.toString(); + currentCommand = sqlShell.createCommand(commandString); + if (currentCommand == null) { + continue; + } + // Exec cmd + sqlShell.output(commandString); + try { CommandResult result = currentCommand.execute(new InputCommand(commandString)); Iterator<CharSequence> output = result.getResult(); while (output.hasNext()) { @@ -2108,7 +2119,9 @@ sqlShell.repaint(); } }.start(); - //} + } catch(Exception e) { + sqlShell.error(e); + } } if (cancelled) { return new SimpleCommandResult(true, "Execution of file '" + toFileName(command.substring(1)) +"' aborted...."); @@ -2330,7 +2343,7 @@ try { return DBConnector.getInstance().getQueryExecutor().executeQuery(command); } catch (SQLException ex) { - return null; + throw new IllegalArgumentException(ex); } } }; Modified: src/main/java/nl/improved/sqlclient/QueryExecutor.java =================================================================== --- src/main/java/nl/improved/sqlclient/QueryExecutor.java 2009-01-16 20:10:20 UTC (rev 350) +++ src/main/java/nl/improved/sqlclient/QueryExecutor.java 2009-01-16 20:44:06 UTC (rev 351) @@ -237,7 +237,8 @@ } return displayValue.toString(); } catch(SQLException e) { - return null; + //return ""; + throw new IllegalArgumentException("Failed to execute query", e); } } |
From: SVN by r. <sv...@ca...> - 2009-01-16 20:10:28
|
Author: roy Date: 2009-01-16 21:10:20 +0100 (Fri, 16 Jan 2009) New Revision: 350 Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java Log: command result is now paged.. so repaint after each result Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java =================================================================== --- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2009-01-16 20:09:43 UTC (rev 349) +++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2009-01-16 20:10:20 UTC (rev 350) @@ -442,6 +442,7 @@ Iterator<CharSequence> iResult = result.getResult(); while (iResult.hasNext()) { output(iResult.next()); + repaint(); } if (!result.executedSuccessfully()) { output("Execution Failed...\n"); @@ -458,6 +459,7 @@ Iterator<CharSequence> iResult = result.getResult(); while (iResult.hasNext()) { output(iResult.next()); + repaint(); } if (!result.executedSuccessfully()) { output("Execution Failed...\n"); @@ -1037,6 +1039,7 @@ Iterator<CharSequence> result = commandResult.getResult(); while (result.hasNext()) { output(result.next()); + repaint(); } if (!commandResult.executedSuccessfully()) { output("Execution Failed...\n"); @@ -2092,6 +2095,7 @@ Iterator<CharSequence> output = result.getResult(); while (output.hasNext()) { sqlShell.output(output.next()); + sqlShell.repaint(); } if (!result.executedSuccessfully()) { errorCount++; @@ -2371,7 +2375,6 @@ public boolean backgroundProcessSupported() { return true; } - } |
From: SVN by r. <sv...@ca...> - 2009-01-16 20:09:50
|
Author: roy Date: 2009-01-16 21:09:43 +0100 (Fri, 16 Jan 2009) New Revision: 349 Modified: src/main/java/nl/improved/sqlclient/SQLShell.java Log: fix output from commandline Modified: src/main/java/nl/improved/sqlclient/SQLShell.java =================================================================== --- src/main/java/nl/improved/sqlclient/SQLShell.java 2009-01-16 19:46:42 UTC (rev 348) +++ src/main/java/nl/improved/sqlclient/SQLShell.java 2009-01-16 20:09:43 UTC (rev 349) @@ -39,7 +39,7 @@ public static void main(String[] args) throws InterruptedException, IOException { PrintStream errorStream = System.err; PrintStream outStream = System.out; - Map<String, String> argsMap = new HashMap<String, String>(); + final Map<String, String> argsMap = new HashMap<String, String>(); if (args.length > 0) { if (args[0].equals("--help") || args.length %2 == 1) { System.err.println("Usage: "); @@ -88,15 +88,19 @@ @Override public void show() { } + + @Override + protected void output(CharSequence data) { + if (!argsMap.containsKey("-o")) { + System.out.println(data); + } + } + + }; Command cmd = new nl.improved.sqlclient.AbstractSQLShellWindow.ExecuteBatchCommand(sqlshellWindow); cmd.execute(new SQLCommand("@"+ argsMap.get("-i"))); - if (!argsMap.containsKey("-o")) { - for (CharSequence s : sqlshellWindow.getScreen().getScreenBuffer()) { - System.out.println(s); - } - //System.out.println(output); - } else { + if (argsMap.containsKey("-o")) { File f = new File(argsMap.get("-o")); FileOutputStream fout = new FileOutputStream(f); for (CharSequence s : sqlshellWindow.getScreen().getScreenBuffer()) { |
From: SVN by r. <sv...@ca...> - 2009-01-16 19:46:53
|
Author: roy Date: 2009-01-16 20:46:42 +0100 (Fri, 16 Jan 2009) New Revision: 348 Added: src/main/java/nl/improved/sqlclient/commands/CommandResult.java src/main/java/nl/improved/sqlclient/commands/SimpleCommandResult.java Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java src/main/java/nl/improved/sqlclient/QueryExecutor.java src/main/java/nl/improved/sqlclient/SQLShell.java src/main/java/nl/improved/sqlclient/commands/Command.java src/main/java/nl/improved/sqlclient/commands/DescCommand.java src/main/java/nl/improved/sqlclient/commands/InfoCommand.java src/main/java/nl/improved/sqlclient/commands/ShowCommand.java Log: lot of refactoring in command classes results can now be paged (initial version) Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java =================================================================== --- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2009-01-15 20:09:47 UTC (rev 347) +++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2009-01-16 19:46:42 UTC (rev 348) @@ -438,7 +438,14 @@ repaint(); if (/*direct ||*/ !cmd.cmd.backgroundProcessSupported()) { try { - output(cmd.cmd.execute(cmd.sql)); + CommandResult result = cmd.cmd.execute(cmd.sql); + Iterator<CharSequence> iResult = result.getResult(); + while (iResult.hasNext()) { + output(iResult.next()); + } + if (!result.executedSuccessfully()) { + output("Execution Failed...\n"); + } } catch(Exception e) { error(e); } @@ -447,7 +454,14 @@ commandThread = new CommandThread(cmd.cmd) { @Override void execute() { - output(getCommand().execute(cmd.sql)); + CommandResult result = getCommand().execute(cmd.sql); + Iterator<CharSequence> iResult = result.getResult(); + while (iResult.hasNext()) { + output(iResult.next()); + } + if (!result.executedSuccessfully()) { + output("Execution Failed...\n"); + } repaint(); } }; @@ -1019,7 +1033,14 @@ } output(sqlCommand.getLines()); //repaint(); - output(command.execute(sqlCommand)); + CommandResult commandResult = command.execute(sqlCommand); + Iterator<CharSequence> result = commandResult.getResult(); + while (result.hasNext()) { + output(result.next()); + } + if (!commandResult.executedSuccessfully()) { + output("Execution Failed...\n"); + } repaint(); return true; } @@ -1100,7 +1121,7 @@ * @return a readable result of the execution of this command. */ @Override - public CharSequence execute(SQLCommand cmd) { + public CommandResult execute(SQLCommand cmd) { String command = cmd.getCommandString(); try { String cmdString = command.substring("connect".length()).trim(); @@ -1108,7 +1129,7 @@ cmdString = cmdString.substring(0, cmdString.length()-1); } if (connect(cmdString) == null) { - return "Connect failed. Unknown reason\n\n"; + return new SimpleCommandResult(false, "Connect failed. Unknown reason\n\n"); } } catch(SQLException e) { throw new IllegalStateException("Failed to connect: " + e.getMessage(), e); @@ -1116,12 +1137,11 @@ try { int tot = HistoryPersister.loadHistory(AbstractSQLShellWindow.this, ident, getScreen().MAX_LINE_LENGTH, getScreen().MAX_LINE_LENGTH); - return "Connected and history loaded (" + tot + " command(s)).\n\n"; + return new SimpleCommandResult(true, "Connected and history loaded (" + tot + " command(s)).\n\n"); } catch (CouldNotLoadHistoryException e) { // this.shell.setCommandIndex(0); - return "Connected (no history loaded).\n\n"; + return new SimpleCommandResult(true, "Connected (no history loaded).\n\n"); } - } @Override public CharSequence getCommandString() { @@ -1274,20 +1294,20 @@ private class DisConnectCommand implements Command { @Override - public CharSequence execute(SQLCommand cmd) { + public CommandResult execute(SQLCommand cmd) { try { DBConnector.getInstance().disconnect(); if (ident != null) { try { HistoryPersister.saveHistory(AbstractSQLShellWindow.this, ident, true); ident = null; - return "Disconnected (history saved).\n\n"; + return new SimpleCommandResult(true, "Disconnected (history saved).\n\n"); } catch (CouldNotSaveHistoryException e) { - return "Disconnected, could not save history: " + e.getMessage() - + "\n\n"; + return new SimpleCommandResult(false, "Disconnected, could not save history: " + e.getMessage() + + "\n\n"); } } - return "Disconnected"; + return new SimpleCommandResult(true, "Disconnected"); } catch(SQLException e) { throw new IllegalStateException("Failed to disconnect: " + e.getMessage(), e); } @@ -1326,7 +1346,7 @@ */ private class HistoryCommand implements Command { @Override - public CharSequence execute(SQLCommand command) { + public CommandResult execute(SQLCommand command) { StringBuffer returnValue = new StringBuffer(); Iterator<SQLCommand> iCommands = commandHistory.iterator(); returnValue.append("\n**** History Overview ****\n"); @@ -1342,8 +1362,9 @@ returnValue.append(cmdString); returnValue.append('\n'); } - return returnValue; + return new SimpleCommandResult(true, returnValue); } + @Override public CharSequence getCommandString() { return "history"; @@ -1384,11 +1405,11 @@ this.cmd = cmd; } @Override - public CharSequence execute(SQLCommand command) { + public CommandResult execute(SQLCommand command) { run = false; new DisConnectCommand().execute(null); close(); - return "Application terminated."; + return new SimpleCommandResult(true, "Application terminated."); } @Override public CharSequence getHelp() { @@ -1422,7 +1443,7 @@ */ private class HelpCommand implements Command { @Override - public CharSequence execute(SQLCommand sqlCommand) { + public CommandResult execute(SQLCommand sqlCommand) { // the execution of help consists of: // 1. is general help.. // 2. is detailed help about a specific command @@ -1451,21 +1472,21 @@ } } if (returnValue.length() == 0) { - return "Don't know what you mean by '"+ keyword+"'"; + return new SimpleCommandResult(false, "Don't know what you mean by '"+ keyword+"'"); } - return returnValue; + return new SimpleCommandResult(true, returnValue); } else { Iterator<Command> iCommands = commands.getCommands().iterator(); while (iCommands.hasNext()) { Command cmd= iCommands.next(); if (cmd.getCommandString().equals(cmdString)) { - return cmd.getCommandString()+": " + return new SimpleCommandResult(true, cmd.getCommandString()+": " + cmd.getHelp().toString().replaceAll("\n" - , "\n"+screen.getEmptyLine().substring(0, cmd.getCommandString().length()+3)); + , "\n"+screen.getEmptyLine().substring(0, cmd.getCommandString().length()+3))); } } } - return "Unkown command '"+ cmdString+"'"; + return new SimpleCommandResult(true, "Unkown command '"+ cmdString+"'"); } // default print all commands // TODO iterate @@ -1506,7 +1527,7 @@ " help -k searchstring (for example help -k column)\n"+ "This results in a list of commands matching the searchstring\n\n"; returnValue.insert(0, helpHeader); - return returnValue; + return new SimpleCommandResult(true, returnValue); } @Override public CharSequence getCommandString() { @@ -1639,7 +1660,7 @@ private String fileName; @Override - public CharSequence execute(SQLCommand cmd) { + public CommandResult execute(SQLCommand cmd) { String command = cmd.getCommandString(); String nextPart = command.substring("spool".length()).trim(); if (nextPart.equalsIgnoreCase("off")) { @@ -1648,9 +1669,9 @@ spoolWriter.close(); } catch(Exception e) {/*ignore*/} spoolWriter = null; - return "Spool closed."; + return new SimpleCommandResult(true, "Spool closed."); } else { - return "No spool to close."; + return new SimpleCommandResult(true, "No spool to close."); } } else { StringBuffer returnValue = new StringBuffer(100); @@ -1675,7 +1696,7 @@ throw new IllegalStateException("Failed to create spool ("+fileName+"): " + e.toString(), e); } returnValue.append("Spool to "+fileName+" created."); - return returnValue.toString(); + return new SimpleCommandResult(true, returnValue.toString()); } } @@ -1739,7 +1760,7 @@ private String fileName; @Override - public CharSequence execute(SQLCommand cmd) { + public CommandResult execute(SQLCommand cmd) { String command = cmd.getCommandString(); String nextPart = command.substring("dump".length()).trim(); String dumpFileName; @@ -1843,7 +1864,7 @@ out.close(); } } - return "Dump to "+fileName+" done. ("+ rowCount+" rows written)"; + return new SimpleCommandResult(true, "Dump to "+fileName+" done. ("+ rowCount+" rows written)"); } @Override @@ -1889,7 +1910,7 @@ private String fileName; @Override - public CharSequence execute(SQLCommand cmd) { + public CommandResult execute(SQLCommand cmd) { String command = cmd.getCommandString(); String nextPart = command.substring("read".length()).trim(); String dumpFileName; @@ -1993,7 +2014,7 @@ } catch (Exception e) { throw new IllegalStateException("Failed to read dump ("+fileName+"): " + e.toString(), e); } - return "Read from "+fileName+" done. (" + rowCount+" rows imported)"; + return new SimpleCommandResult(true, "Read from "+fileName+" done. (" + rowCount+" rows imported)"); } @Override @@ -2038,7 +2059,7 @@ } @Override - public CharSequence execute(SQLCommand sqlCommand) { + public CommandResult execute(SQLCommand sqlCommand) { cancelled = false; currentCommand = null; String command = sqlCommand.getCommandString(); @@ -2050,20 +2071,32 @@ BufferedReader reader = new BufferedReader(new InputStreamReader(fin)); StringBuffer cmd = new StringBuffer(); String line; + int errorCount = 0; while ( ((line = reader.readLine()) != null)) { if (cancelled) { - return "Aborted"; + return new SimpleCommandResult(true, "Aborted"); } if (line.startsWith("--")) { continue; } cmd.append(line); - if (line.endsWith(";")) { - // Exec cmd + //if (line.endsWith(";")) { String commandString = cmd.toString(); currentCommand = sqlShell.createCommand(commandString); + if (currentCommand == null) { + continue; + } + // Exec cmd sqlShell.output(commandString); - sqlShell.output(currentCommand.execute(new InputCommand(commandString))); + CommandResult result = currentCommand.execute(new InputCommand(commandString)); + Iterator<CharSequence> output = result.getResult(); + while (output.hasNext()) { + sqlShell.output(output.next()); + } + if (!result.executedSuccessfully()) { + errorCount++; + sqlShell.output("Execution Failed...\n"); + } cmd=new StringBuffer(); new Thread() { @Override @@ -2071,19 +2104,19 @@ sqlShell.repaint(); } }.start(); - } + //} } if (cancelled) { - return "Execution of file '" + toFileName(command.substring(1)) +"' aborted...."; + return new SimpleCommandResult(true, "Execution of file '" + toFileName(command.substring(1)) +"' aborted...."); } if (cmd.toString().trim().length() > 0) { - return "File '"+ toFileName(command.substring(1)) +"' missing a ';' at the end of the last command"; + return new SimpleCommandResult(false, "File '"+ toFileName(command.substring(1)) +"' missing a ';' at the end of the last command"); } else { - return "File '" + toFileName(command.substring(1)) +"' executed successfully."; + return new SimpleCommandResult(true, "File '" + toFileName(command.substring(1)) +"' executed " + (errorCount > 0 ? "with "+ errorCount+" errors." : "successfully.")); } } catch(IOException e) { sqlShell.error(e); - return "File '" + toFileName(command.substring(1)) +"' ended with errors."; + return new SimpleCommandResult(true, "File '" + toFileName(command.substring(1)) +"' ended with errors."); } finally { if (fin != null) try { fin.close();}catch(Exception e) {/*ignore*/} } @@ -2131,13 +2164,13 @@ * Simple command to save the current visible screen history (commands and it"s output). */ private class SaveCommand implements Command { - public CharSequence execute(SQLCommand cmd) { + public CommandResult execute(SQLCommand cmd) { String command = cmd.getCommandString().substring("save".length()).trim(); if (command.startsWith("history")) { String fileName = toFileName(command.substring("history".length()).trim()); File f = new File(fileName); if (f.exists() && !f.canWrite()) { - return "Unable to overwrite existing file : " + f.getAbsolutePath(); + return new SimpleCommandResult(false, "Unable to overwrite existing file : " + f.getAbsolutePath()); } FileWriter writer = null; try { @@ -2146,10 +2179,10 @@ writer.write(c.toString()); writer.write('\n'); } - return "History successfully written to : "+ f.getAbsolutePath(); + return new SimpleCommandResult(true, "History successfully written to : "+ f.getAbsolutePath()); } catch (IOException ex) { Logger.getLogger(AbstractSQLShellWindow.class.getName()).log(Level.SEVERE, null, ex); - return "Unable to write to file: "+ f.getAbsolutePath() +"("+ ex+")"; + return new SimpleCommandResult(false, "Unable to write to file: "+ f.getAbsolutePath() +"("+ ex+")"); } finally { if (writer != null) { try { @@ -2281,22 +2314,33 @@ * @return the result of the sql query. */ @Override - public CharSequence execute(SQLCommand cmd) { + public CommandResult execute(SQLCommand cmd) { try { - String command = cmd.getCommandString(); + final String command = cmd.getCommandString(); if (command.length() > "select".length() && "select".equalsIgnoreCase(command.subSequence(0, "create".length()).toString())) { - return DBConnector.getInstance().getQueryExecutor().executeQuery(command); + return new CommandResult() { + public boolean executedSuccessfully() { + return true; + } + public Iterator<CharSequence> getResult() { + try { + return DBConnector.getInstance().getQueryExecutor().executeQuery(command); + } catch (SQLException ex) { + return null; + } + } + }; } if (statementExecutor == null) { statementExecutor = new StatementExecutor(); } - return statementExecutor.execute(command); + return new SimpleCommandResult(true, statementExecutor.execute(command)); } catch(SQLException e) { error(e); - return ""; + return new SimpleCommandResult(false, ""); } catch(IllegalStateException e) { error(e); - return ""; + return new SimpleCommandResult(false, ""); } } Modified: src/main/java/nl/improved/sqlclient/QueryExecutor.java =================================================================== --- src/main/java/nl/improved/sqlclient/QueryExecutor.java 2009-01-15 20:09:47 UTC (rev 347) +++ src/main/java/nl/improved/sqlclient/QueryExecutor.java 2009-01-16 19:46:42 UTC (rev 348) @@ -26,6 +26,7 @@ import java.util.ArrayList; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.util.Iterator; import java.util.logging.Level; import java.util.logging.Logger; import nl.improved.sqlclient.util.ResultBuilder; @@ -90,28 +91,6 @@ } /** - * Returns the width at wich a column should be displayed. - * Usually the ResultSetMetaData will be responsible for this width, but a few exceptions - * are made (this would typicall be the case for dates). - * A minimum of 4 is used, so that NULL values won't break the layout. - * @param metadata the metadata describing the resultset - * @param column the column to check - * @return the width in characters that should be used to display the column. - */ - private int getColumnWidth(ResultSetMetaData metadata, int column) throws SQLException { - switch (metadata.getColumnType(column)) { - case Types.DATE: - return dateFormat.length(); - case Types.TIMESTAMP: - return timestampFormat.length(); - case Types.TIME: - return timeFormat.length(); - } - // Let's assume for now that most columns CAN actually contain NULL values, and therefore we want every column to have a minimum width of 4 - return Math.max(4, metadata.getColumnDisplaySize(column)); - } - - /** * Returns the value to display. * This deals with alignment for numeric columns, formatting for dates and special * treatment for NULL values. @@ -180,7 +159,7 @@ * @return the formatted result. * @throws SQLException if the database could not execute the SQL query for some reason. */ - protected CharSequence executeQuery(CharSequence command) throws SQLException { + protected Iterator<CharSequence> executeQuery(CharSequence command) throws SQLException { cancelled = false; ResultSet results = DBConnector.getInstance().getStatement().executeQuery(command.toString()); @@ -197,28 +176,74 @@ labels.add(metadata.getColumnLabel(col)); } - ResultBuilder displayValue = new ResultBuilder(); - displayValue.setHeader(labels); - int rowCount = 0; - while (results.next() && !cancelled) { - for (int col = 1; col <= metadata.getColumnCount(); col++ ) { - displayValue.set(col-1, rowCount, getDisplayValue(results, col), isNumeric(metadata, col) ? ResultBuilder.Alignment.RIGHT : ResultBuilder.Alignment.LEFT); - //try {Thread.sleep(10);} catch(Exception e2) {} + return new QueryExecutorIterator(results, labels, metadata); + } + + private class QueryExecutorIterator implements Iterator<CharSequence> { + + private ResultSet results; + private List<String> labels; + private int rowCount = 0; + private int columnCount; + private long start = System.currentTimeMillis(); + private ResultSetMetaData metadata; + private boolean next = true; + + public QueryExecutorIterator(ResultSet results, List<String> labels, ResultSetMetaData metadata) throws SQLException { + this.results = results; + this.labels = labels; + this.metadata = metadata; + columnCount = metadata.getColumnCount(); + } + + + + public boolean hasNext() { + return next; + } + + public CharSequence next() { + try { + next = false; + ResultBuilder displayValue = new ResultBuilder(); + displayValue.setHeader(labels); + int max = 1000; + while (results.next() && !cancelled) { + for (int col = 1; col <= columnCount; col++ ) { + displayValue.set(col-1, rowCount, getDisplayValue(results, col), isNumeric(metadata, col) ? ResultBuilder.Alignment.RIGHT : ResultBuilder.Alignment.LEFT); + //try {Thread.sleep(10);} catch(Exception e2) {} + } + rowCount++; + if (rowCount % max == 0) { + next = true; + break; + } + } + if (!next) { + StringBuilder footer = new StringBuilder(); + footer.append(rowCount); + footer.append(" row"); + if (rowCount != 1) { + footer.append("s"); + } + footer.append(" selected.\n"); + if (cancelled) { + footer.append("Aborted....\n"); + } + footer.append("Query took: "+ (System.currentTimeMillis() - start) +" millis\n\n"); + displayValue.setFooter(footer); + } else { + displayValue.setFooter("More...\n\n"); + } + return displayValue.toString(); + } catch(SQLException e) { + return null; } - rowCount++; } - StringBuilder footer = new StringBuilder(); - footer.append(rowCount); - footer.append(" row"); - if (rowCount != 1) { - footer.append("s"); + + public void remove() { + throw new UnsupportedOperationException("Not supported yet."); } - footer.append(" selected.\n"); - if (cancelled) { - footer.append("Aborted....\n"); - } - footer.append("Query took: "+ (System.currentTimeMillis() - start) +" millis\n\n"); - displayValue.setFooter(footer); - return displayValue.toString(); + } } Modified: src/main/java/nl/improved/sqlclient/SQLShell.java =================================================================== --- src/main/java/nl/improved/sqlclient/SQLShell.java 2009-01-15 20:09:47 UTC (rev 347) +++ src/main/java/nl/improved/sqlclient/SQLShell.java 2009-01-16 19:46:42 UTC (rev 348) @@ -90,12 +90,12 @@ } }; Command cmd = new nl.improved.sqlclient.AbstractSQLShellWindow.ExecuteBatchCommand(sqlshellWindow); - CharSequence output = cmd.execute(new SQLCommand("@"+ argsMap.get("-i"))); + cmd.execute(new SQLCommand("@"+ argsMap.get("-i"))); if (!argsMap.containsKey("-o")) { for (CharSequence s : sqlshellWindow.getScreen().getScreenBuffer()) { System.out.println(s); } - System.out.println(output); + //System.out.println(output); } else { File f = new File(argsMap.get("-o")); FileOutputStream fout = new FileOutputStream(f); @@ -103,8 +103,8 @@ fout.write(s.toString().getBytes()); fout.write('\n'); } - fout.write(output.toString().getBytes()); - fout.write('\n'); + //fout.write(output.toString().getBytes()); + //fout.write('\n'); } } else { //sqlshellWindow = new SQLShellWindow(); Modified: src/main/java/nl/improved/sqlclient/commands/Command.java =================================================================== --- src/main/java/nl/improved/sqlclient/commands/Command.java 2009-01-15 20:09:47 UTC (rev 347) +++ src/main/java/nl/improved/sqlclient/commands/Command.java 2009-01-16 19:46:42 UTC (rev 348) @@ -27,7 +27,7 @@ * @param command the command to execute * @return a readable result so the user knows what happened */ - CharSequence execute(SQLCommand cmd); + CommandResult execute(SQLCommand cmd); /** * Return the command key (like quit, help, connect) that should show up in the help list. * @return the command key that should show up in the help list. Added: src/main/java/nl/improved/sqlclient/commands/CommandResult.java =================================================================== --- src/main/java/nl/improved/sqlclient/commands/CommandResult.java 2009-01-15 20:09:47 UTC (rev 347) +++ src/main/java/nl/improved/sqlclient/commands/CommandResult.java 2009-01-16 19:46:42 UTC (rev 348) @@ -0,0 +1,18 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package nl.improved.sqlclient.commands; + +import java.util.Iterator; + +/** + * + * @author roy + */ +public interface CommandResult { + + boolean executedSuccessfully(); + Iterator<CharSequence> getResult(); +} Modified: src/main/java/nl/improved/sqlclient/commands/DescCommand.java =================================================================== --- src/main/java/nl/improved/sqlclient/commands/DescCommand.java 2009-01-15 20:09:47 UTC (rev 347) +++ src/main/java/nl/improved/sqlclient/commands/DescCommand.java 2009-01-16 19:46:42 UTC (rev 348) @@ -35,7 +35,7 @@ * Execute the describe command. */ @Override - public CharSequence execute(SQLCommand command) { + public CommandResult execute(SQLCommand command) { java.sql.Connection conn = DBConnector.getInstance().getConnection(); String cmd = command.getCommandString(); if (cmd.endsWith(";")) { @@ -69,7 +69,7 @@ .getTables(conn.getCatalog(), DBConnector.getInstance().getSchema() , tableName, new String[]{"TABLE"}); if (!rs.next()) { - return "Failed to find table '"+tableName+"'"; + return new SimpleCommandResult(false, "Failed to find table '"+tableName+"'"); } } else { rs = conn.getMetaData().getPrimaryKeys(conn.getCatalog(), DBConnector.getInstance().getSchema(), tableName); @@ -95,7 +95,7 @@ } catch (SQLException ex) { throw new IllegalStateException("Failed to find columnnames for table: "+ tableName, ex); } - return result.toString(); + return new SimpleCommandResult(true, result.toString()); } /** Modified: src/main/java/nl/improved/sqlclient/commands/InfoCommand.java =================================================================== --- src/main/java/nl/improved/sqlclient/commands/InfoCommand.java 2009-01-15 20:09:47 UTC (rev 347) +++ src/main/java/nl/improved/sqlclient/commands/InfoCommand.java 2009-01-16 19:46:42 UTC (rev 348) @@ -34,13 +34,13 @@ * @return the info of the connection */ @Override - public CharSequence execute(SQLCommand cmd) { + public CommandResult execute(SQLCommand cmd) { java.sql.Connection conn; try { conn = DBConnector.getInstance().getConnection(); } catch(IllegalStateException e) { - return "This command shows information about the current connection.\nCurrently SQLShell is not connected to a database server.\n"+ - "Please use the connect command to create a connection"; + return new SimpleCommandResult(false, "This command shows information about the current connection.\nCurrently SQLShell is not connected to a database server.\n"+ + "Please use the connect command to create a connection"); } StringBuffer returnValue = new StringBuffer(); try { @@ -64,7 +64,7 @@ throw new IllegalStateException("Failed to find table info: "+ ex, ex); } returnValue.append("\n"); - return returnValue; + return new SimpleCommandResult(true, returnValue); } /** Modified: src/main/java/nl/improved/sqlclient/commands/ShowCommand.java =================================================================== --- src/main/java/nl/improved/sqlclient/commands/ShowCommand.java 2009-01-15 20:09:47 UTC (rev 347) +++ src/main/java/nl/improved/sqlclient/commands/ShowCommand.java 2009-01-16 19:46:42 UTC (rev 348) @@ -35,7 +35,7 @@ * Execute the describe command. */ @Override - public CharSequence execute(SQLCommand command) { + public CommandResult execute(SQLCommand command) { java.sql.Connection conn = DBConnector.getInstance().getConnection(); String cmd = command.getCommandString(); if (cmd.endsWith(";")) { @@ -82,7 +82,7 @@ returnValue.append('\n'); } returnValue.append("DONE\n"); - return returnValue.toString(); + return new SimpleCommandResult(true, returnValue.toString()); } catch(SQLException e) { throw new IllegalStateException("Failed to find tablenames" , e); } @@ -104,7 +104,7 @@ } else { returnValue.append("Don't know what to show for: '"+ cmd.substring(cmd.lastIndexOf(' ')).trim()+"'\n"); } - return returnValue; + return new SimpleCommandResult(true, returnValue); } /** Added: src/main/java/nl/improved/sqlclient/commands/SimpleCommandResult.java =================================================================== --- src/main/java/nl/improved/sqlclient/commands/SimpleCommandResult.java 2009-01-15 20:09:47 UTC (rev 347) +++ src/main/java/nl/improved/sqlclient/commands/SimpleCommandResult.java 2009-01-16 19:46:42 UTC (rev 348) @@ -0,0 +1,33 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package nl.improved.sqlclient.commands; + +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + +/** + * + * @author roy + */ +public class SimpleCommandResult implements CommandResult { + private boolean success; + private CharSequence result; + + public SimpleCommandResult(boolean success, CharSequence result) { + this.success = success; + this.result = result; + } + + public boolean executedSuccessfully() { + return success; + } + + public Iterator<CharSequence> getResult() { + List<CharSequence> list = Arrays.asList(new CharSequence[]{result}); + return list.iterator(); + } +} |
From: SVN by r. <sv...@ca...> - 2009-01-15 20:10:01
|
Author: roy Date: 2009-01-15 21:09:47 +0100 (Thu, 15 Jan 2009) New Revision: 347 Modified: src/main/java/nl/improved/sqlclient/SQLShell.java Log: print errors after quit Modified: src/main/java/nl/improved/sqlclient/SQLShell.java =================================================================== --- src/main/java/nl/improved/sqlclient/SQLShell.java 2009-01-15 20:09:29 UTC (rev 346) +++ src/main/java/nl/improved/sqlclient/SQLShell.java 2009-01-15 20:09:47 UTC (rev 347) @@ -20,6 +20,7 @@ import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; +import java.io.PrintStream; import java.sql.SQLException; import java.util.HashMap; import java.util.List; @@ -36,6 +37,8 @@ public class SQLShell { public static void main(String[] args) throws InterruptedException, IOException { + PrintStream errorStream = System.err; + PrintStream outStream = System.out; Map<String, String> argsMap = new HashMap<String, String>(); if (args.length > 0) { if (args[0].equals("--help") || args.length %2 == 1) { @@ -112,6 +115,8 @@ } } sqlshellWindow.show(); + System.setErr(errorStream); + System.setOut(outStream); File errFile = sqlshellWindow.getErrFile(); if (errFile != null && errFile.length() > 0L) { System.out.println("There where errors during execution of sqlshell:"); |
From: SVN by r. <sv...@ca...> - 2009-01-15 20:09:43
|
Author: roy Date: 2009-01-15 21:09:29 +0100 (Thu, 15 Jan 2009) New Revision: 346 Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java Log: print error/warning when ; is missing in batch command Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java =================================================================== --- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2009-01-07 15:53:45 UTC (rev 345) +++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2009-01-15 20:09:29 UTC (rev 346) @@ -2076,7 +2076,11 @@ if (cancelled) { return "Execution of file '" + toFileName(command.substring(1)) +"' aborted...."; } - return "File '" + toFileName(command.substring(1)) +"' executed successfully."; + if (cmd.toString().trim().length() > 0) { + return "File '"+ toFileName(command.substring(1)) +"' missing a ';' at the end of the last command"; + } else { + return "File '" + toFileName(command.substring(1)) +"' executed successfully."; + } } catch(IOException e) { sqlShell.error(e); return "File '" + toFileName(command.substring(1)) +"' ended with errors."; |
From: SVN by r. <sv...@ca...> - 2009-01-07 15:53:53
|
Author: roy Date: 2009-01-07 16:53:45 +0100 (Wed, 07 Jan 2009) New Revision: 345 Removed: src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java Modified: sqlshell sqlshell.bat src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java src/main/java/nl/improved/sqlclient/SQLShell.java src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java Log: use single startup file again (SQLShell) implemented execution of statements without interface (via inputfile) output errors if they appeared fixed display problems after pageup/page-down when using charva Modified: sqlshell =================================================================== --- sqlshell 2009-01-07 15:52:30 UTC (rev 344) +++ sqlshell 2009-01-07 15:53:45 UTC (rev 345) @@ -15,11 +15,15 @@ # limitations under the License. # Path to java executable -#JAVA=$(which java) -JAVA=${JAVA_HOME}/bin/java +JAVA=$(which java) +#JAVA=${JAVA_HOME}/bin/java # Dir to use as base for relative locations +CURDIR=$(pwd) +TMPDIR=$(dirname $0) +cd $TMPDIR WORKINGDIR=$(pwd) +cd $CURDIR # The directory where the JCurses jar and library are located. # Please note that JCurses requires the jcurses.jar and libjcurses.so to @@ -46,4 +50,4 @@ #Enable the file below to use the jcurses version #${JAVA} -cp ${CP} nl.improved.sqlclient.jcurses.SQLShell $@ #Charva version -${JAVA} -Djava.library.path=${CHARVA} -cp ${CP} nl.improved.sqlclient.charva.SQLShellComponent $@ +${JAVA} -Djava.library.path=${CHARVA} -cp ${CP} nl.improved.sqlclient.SQLShell $@ Modified: sqlshell.bat =================================================================== --- sqlshell.bat 2009-01-07 15:52:30 UTC (rev 344) +++ sqlshell.bat 2009-01-07 15:53:45 UTC (rev 345) @@ -13,7 +13,7 @@ REM limitations under the License. REM Dir to use as base for relative locations -set WORKINGDIR=c:\sqlshell\ +set WORKINGDIR=y:\sqlshell\sqlclient\ REM The directory where the JCurses jar and library are located. REM Please note that JCurses requires tje jcurses.jar and libjcurses.so to @@ -21,7 +21,7 @@ set JCURSES=%WORKINGDIR%\lib REM Where to find the SQLShell classes -set SQLSHELL=%WORKINGDIR%\sqlshell.jar +set SQLSHELL=%WORKINGDIR%\target\sqlshell-0.6.jar # REM providing drivers for the databases to support. set DRIVERS="%WORKINGDIR%\lib\hsqldb-1.8.0.jar" Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java =================================================================== --- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2009-01-07 15:52:30 UTC (rev 344) +++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2009-01-07 15:53:45 UTC (rev 345) @@ -129,12 +129,11 @@ * All threads should stop when this is set to false */ private boolean run = true; // set to false on quit - + private File errFile; /** * Constructor. */ public AbstractSQLShellWindow() { - File errFile; try { errFile = File.createTempFile("sqlshell", ".err"); errFile.deleteOnExit(); @@ -381,7 +380,7 @@ @Override public void execute() { output("Abort requested"); - if (commandThread.isAlive() && commandThread.getCommand().abort()) { + if (commandThread != null && commandThread.isAlive() && commandThread.getCommand().abort()) { output("Abort done.."); } } @@ -483,6 +482,7 @@ this.commandIndex = i; } + public abstract void show(); /** * Return the visible screen width. @@ -577,6 +577,9 @@ } } + protected File getErrFile() { + return errFile; + } /** * Returns a string representation of the current command. @@ -1604,7 +1607,7 @@ * Returns the screen implementation. * @return the screen. */ - protected Screen getScreen() { + public Screen getScreen() { return screen; } Modified: src/main/java/nl/improved/sqlclient/SQLShell.java =================================================================== --- src/main/java/nl/improved/sqlclient/SQLShell.java 2009-01-07 15:52:30 UTC (rev 344) +++ src/main/java/nl/improved/sqlclient/SQLShell.java 2009-01-07 15:53:45 UTC (rev 345) @@ -15,6 +15,17 @@ */ package nl.improved.sqlclient; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import nl.improved.sqlclient.charva.CharvaSQLShellWindow; +import nl.improved.sqlclient.commands.Command; import nl.improved.sqlclient.jcurses.SQLShellWindow; @@ -24,9 +35,91 @@ */ public class SQLShell { - public static void main(String[] args) throws InterruptedException { - System.out.println("This class is no longer used. Please start nl.improved.sqlclient.jcurses.SQLShellWindow"); - Thread.sleep(2000); - SQLShellWindow.main(args); + public static void main(String[] args) throws InterruptedException, IOException { + Map<String, String> argsMap = new HashMap<String, String>(); + if (args.length > 0) { + if (args[0].equals("--help") || args.length %2 == 1) { + System.err.println("Usage: "); + System.exit(-1); + } + for (int i = 0; i < args.length; i+=2) { + argsMap.put(args[i], args[i+1]); + } + } + AbstractSQLShellWindow sqlshellWindow; + if (argsMap.get("-i") != null) { + sqlshellWindow = new AbstractSQLShellWindow() { + @Override + public int getScreenWidth() { + return 1024; + } + @Override + public int getScreenHeight() { + return Integer.MAX_VALUE; + } + @Override + public void paint(Screen screen) { + + } + + @Override + public void beep() { + + } + + @Override + public void debug(String debug) { + + } + + @Override + public String select(List<String> items, Point p) { + return null; + } + + @Override + protected String[] getLoginCredentials(String username, String password) throws SQLException { + return new String[]{username, password}; + } + + @Override + public void show() { + } + }; + Command cmd = new nl.improved.sqlclient.AbstractSQLShellWindow.ExecuteBatchCommand(sqlshellWindow); + CharSequence output = cmd.execute(new SQLCommand("@"+ argsMap.get("-i"))); + if (!argsMap.containsKey("-o")) { + for (CharSequence s : sqlshellWindow.getScreen().getScreenBuffer()) { + System.out.println(s); + } + System.out.println(output); + } else { + File f = new File(argsMap.get("-o")); + FileOutputStream fout = new FileOutputStream(f); + for (CharSequence s : sqlshellWindow.getScreen().getScreenBuffer()) { + fout.write(s.toString().getBytes()); + fout.write('\n'); + } + fout.write(output.toString().getBytes()); + fout.write('\n'); + } + } else { + //sqlshellWindow = new SQLShellWindow(); + try { + sqlshellWindow = new CharvaSQLShellWindow(); + } catch(Error e) { + sqlshellWindow = new SQLShellWindow(); + } + } + sqlshellWindow.show(); + File errFile = sqlshellWindow.getErrFile(); + if (errFile != null && errFile.length() > 0L) { + System.out.println("There where errors during execution of sqlshell:"); + BufferedReader reader = new BufferedReader(new FileReader(errFile)); + String line; + while ( (line = reader.readLine()) != null) { + System.out.println(line); + } + } } } Modified: src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java =================================================================== --- src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2009-01-07 15:52:30 UTC (rev 344) +++ src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2009-01-07 15:53:45 UTC (rev 345) @@ -5,12 +5,15 @@ package nl.improved.sqlclient.charva; +import charva.awt.Dimension; import charva.awt.Toolkit; import charva.awt.event.ActionEvent; import charva.awt.event.ActionListener; import charva.awt.event.KeyEvent; +import charvax.swing.JFrame; import charvax.swing.JMenuItem; import charvax.swing.JPopupMenu; +import charvax.swing.JTextArea; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -32,16 +35,23 @@ * The sqlshell window implementation for charva. * @author roy */ -class CharvaSQLShellWindow extends AbstractSQLShellWindow { - private SQLShellComponent textComponent; +public class CharvaSQLShellWindow extends AbstractSQLShellWindow { + private JTextArea textComponent; private OutputStream debugOut; /** * Constructor. * @param textComponent the text component for rendering the text */ - public CharvaSQLShellWindow(SQLShellComponent textComponent) { - this.textComponent = textComponent; + public CharvaSQLShellWindow() { + this.textComponent = new JTextArea() { + + @Override + public void processKeyEvent(KeyEvent ke) { + keyTyped(ke); + } + + }; try { File tmpFile = File.createTempFile("charva", ".out"); tmpFile.deleteOnExit(); @@ -62,9 +72,9 @@ @Override public int getScreenHeight() { if (textComponent == null) { - return Toolkit.getDefaultToolkit().getScreenRows(); + return Toolkit.getDefaultToolkit().getScreenRows()-1; } - return textComponent.getHeight(); + return textComponent.getHeight()-1; } /** @@ -76,6 +86,7 @@ @Override public void paint(Screen screen) { + debug("PageUpCount: "+ screen.getPageUpCount()); if (screen.getPageUpCount() > 0) { paintSlow(screen); return; @@ -122,11 +133,11 @@ } } } - if (newText.toString().startsWith(textComponent.getText())) { + /*if (newText.toString().startsWith(textComponent.getText())) { textComponent.append(newText.substring(textComponent.getText().length())); - } else { + } else {*/ textComponent.replaceRange(newText.toString(), 0, textComponent.getText().length()); - } + //} Point cursorPos = screen.getCursorPosition(); try { int start = textComponent.getLineStartOffset(totalLineCount - (commandLines.size() - cursorPos.y)); @@ -334,4 +345,23 @@ return selectedValue; } } + + public void show() { + JFrame frame = new JFrame() { + + @Override + public void draw() { + //super.draw(); + } + + }; + frame.setLayout(null); // null layout + frame.add(this.textComponent); + this.textComponent.setBounds(new charva.awt.Point(0,0), new Dimension(Toolkit.getDefaultToolkit().getScreenColumns() + , Toolkit.getDefaultToolkit().getScreenRows() +1)); + frame.add(this.textComponent); + repaintScreen(); + frame.pack(); + frame.show(); + } } Deleted: src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java =================================================================== --- src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java 2009-01-07 15:52:30 UTC (rev 344) +++ src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java 2009-01-07 15:53:45 UTC (rev 345) @@ -1,188 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package nl.improved.sqlclient.charva; - -import java.util.Map; -import java.util.HashMap; -import charva.awt.Dimension; -import charva.awt.Point; -import charva.awt.Toolkit; -import charva.awt.event.KeyEvent; -import charva.awt.event.MouseEvent; -import charvax.swing.JFrame; -import charvax.swing.JTextArea; -import java.awt.datatransfer.Clipboard; -import java.awt.datatransfer.DataFlavor; -import java.awt.datatransfer.Transferable; -import java.awt.datatransfer.UnsupportedFlavorException; -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; -import nl.improved.sqlclient.SQLCommand; -import nl.improved.sqlclient.SQLProperties; -import nl.improved.sqlclient.SQLUtil; - -/** - * - * @author roy - */ -public class SQLShellComponent extends JTextArea { - - private CharvaSQLShellWindow sqlshellWindow = new CharvaSQLShellWindow(this); - private Point startPos; - - public SQLShellComponent() { - setEditable(false); - setEnabled(true); - setBorder(null); - } - @Override - public void processKeyEvent(KeyEvent evt) { - //super.processKeyEvent(arg0); - sqlshellWindow.keyTyped(evt); - } - - void setSelection(int pStart, int pEnd) { - if (!"all".equals(SQLProperties.getProperty(SQLProperties.PropertyName.MOUSE_HANDLING))) { - return; - } - int start, end; - if (pEnd < pStart) { - end = pStart; - start = pEnd; - } else { - start = pStart; - end = pEnd; - } - end = Math.min(getText().length(), end); - sqlshellWindow.debug("SET SELECTION: "+ start +" -> "+ end); - sqlshellWindow.debug("SET TO CLIPBOARD: "+ getText().substring(start, end)); - Clipboard clipBoard = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard(); - final String text = getText().substring(start, Math.min(getText().length(), end)); - Transferable tf = new Transferable() { - - public DataFlavor[] getTransferDataFlavors() { - return new DataFlavor[] {DataFlavor.stringFlavor}; - } - - public boolean isDataFlavorSupported(DataFlavor flavor) { - return DataFlavor.stringFlavor == flavor; - } - - public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { - return text; - } - }; - clipBoard.setContents(tf, null); - } - - @Override - public void processMouseEvent(MouseEvent evt) { - super.processMouseEvent(evt); - if (evt.getModifiers() == MouseEvent.MOUSE_CLICKED) { - if (evt.getButton() == MouseEvent.BUTTON1) { - if (evt.getClickCount() == 2) { // double click.. select word under char - try { - int line = getLineStartOffset(evt.getY()-1); - String text = getText(); - int start, end; - for (start = line + evt.getX(); start > 0; start--) { - if (SQLUtil.isBreakCharacter(text.charAt(start))) { - break; - } - } - for (end = line + evt.getX(); end < text.length(); end++) { - if (SQLUtil.isBreakCharacter(text.charAt(end))) { - break; - } - } - setSelection(start, end); - } catch(Exception e) { } - } - } - } else if (evt.getModifiers() == MouseEvent.MOUSE_PRESSED) { - sqlshellWindow.debug("PRESSED"); - if (evt.getButton() == MouseEvent.BUTTON1) { - if (startPos == null) { - startPos = new Point(evt.getX()-1, evt.getY()-1); - } else { - try { - Point endPos = new Point(evt.getX()-1, evt.getY()-1); - int start = getLineStartOffset(startPos.y) + startPos.x; - int end = getLineStartOffset(endPos.y) + endPos.x; - setSelection(start, end); - startPos = null; - } catch(Exception e) {} - } - } - if (evt.getButton() == MouseEvent.BUTTON2) { // paste from clipboard - String mouseHandling = SQLProperties.getProperty(SQLProperties.PropertyName.MOUSE_HANDLING); - if ("all".equals(mouseHandling) || "paste".equals(mouseHandling)) { - Clipboard clipBoard = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard(); - try { - String clipBoardContents = (String) clipBoard.getData(DataFlavor.stringFlavor); - //sqlshellWindow.debug(clipBoardContents); - sqlshellWindow.insertText(clipBoardContents); - sqlshellWindow.repaintScreen(); - } catch (UnsupportedFlavorException ex) { - Logger.getLogger(SQLShellComponent.class.getName()).log(Level.SEVERE, null, ex); - } catch (IOException ex) { - Logger.getLogger(SQLShellComponent.class.getName()).log(Level.SEVERE, null, ex); - } - } - } - } else if (evt.getModifiers() == MouseEvent.MOUSE_RELEASED) { - sqlshellWindow.debug("RELEASED: " + startPos); - Point endPos = new Point(evt.getX()-1, evt.getY()-1); - if (startPos != null) { - try { - int start = getLineStartOffset(startPos.y) + startPos.x; - int end = getLineStartOffset(endPos.y) + endPos.x; - setSelection(start, end); - startPos = null; - } catch(Exception e) { /* ignore */ } - } - } - } - - - public static void main(String[] args) { - Map argsMap = new HashMap<String, String>(); - if (args.length > 0) { - if (args[0].equals("--help") || args.length %2 == 1) { - System.err.println("Usage: "); - System.exit(-1); - } - for (int i = 0; i < args.length; i+=2) { - argsMap.put(args[i], args[i+1]); - } - } - JFrame frame = new JFrame() { - - @Override - public void draw() { - //super.draw(); - } - - }; - SQLShellComponent component = new SQLShellComponent(); - frame.setLayout(null); // null layout - frame.add(component); - component.setBounds(new Point(0,0), new Dimension(Toolkit.getDefaultToolkit().getScreenColumns() - , Toolkit.getDefaultToolkit().getScreenRows() +1)); - frame.add(component); - component.sqlshellWindow.repaintScreen(); - frame.pack(); - if (argsMap.get("-i") != null) { - new nl.improved.sqlclient.AbstractSQLShellWindow.ExecuteBatchCommand(component.sqlshellWindow).execute(new SQLCommand("@"+ argsMap.get("-i"))); - } - if (argsMap.get("-q") != null) { - return; - } - frame.show(); - } - -} |
From: SVN by r. <sv...@ca...> - 2009-01-07 15:52:38
|
Author: roy Date: 2009-01-07 16:52:30 +0100 (Wed, 07 Jan 2009) New Revision: 344 Modified: src/main/java/nl/improved/sqlclient/jcurses/SQLShellWindow.java Log: made lockobject final Modified: src/main/java/nl/improved/sqlclient/jcurses/SQLShellWindow.java =================================================================== --- src/main/java/nl/improved/sqlclient/jcurses/SQLShellWindow.java 2008-12-24 15:25:23 UTC (rev 343) +++ src/main/java/nl/improved/sqlclient/jcurses/SQLShellWindow.java 2009-01-07 15:52:30 UTC (rev 344) @@ -41,7 +41,7 @@ private boolean repaint = true; private String debugString; - private Object lockObject = new Object(); + private final Object lockObject = new Object(); /** * Default constructor. |
From: SVN by r. <sv...@ca...> - 2008-12-24 15:25:29
|
Author: roy Date: 2008-12-24 16:25:23 +0100 (Wed, 24 Dec 2008) New Revision: 343 Modified: src/main/java/nl/improved/sqlclient/SQLCommand.java Log: added a constructor Modified: src/main/java/nl/improved/sqlclient/SQLCommand.java =================================================================== --- src/main/java/nl/improved/sqlclient/SQLCommand.java 2008-12-24 15:24:37 UTC (rev 342) +++ src/main/java/nl/improved/sqlclient/SQLCommand.java 2008-12-24 15:25:23 UTC (rev 343) @@ -15,6 +15,14 @@ commandLines = new ArrayList<StringBuffer>(); } + /** + * Constructor. + */ + public SQLCommand(CharSequence cmd) { + commandLines = new ArrayList<StringBuffer>(); + commandLines.add(new StringBuffer(cmd)); + } + public List<StringBuffer> getEditableLines() { return commandLines; } |
From: SVN by r. <sv...@ca...> - 2008-12-24 15:24:42
|
Author: roy Date: 2008-12-24 16:24:37 +0100 (Wed, 24 Dec 2008) New Revision: 342 Modified: ChangeLog Log: mention changes Modified: ChangeLog =================================================================== --- ChangeLog 2008-12-24 15:24:23 UTC (rev 341) +++ ChangeLog 2008-12-24 15:24:37 UTC (rev 342) @@ -1,4 +1,10 @@ -0.6 (2008-10-12) +0.7 + * Commandline input support (currently only supported in charva mode) + +0.6.1 (2008-12-24) + * Bugfix release for not starting + +0.6 (2008-12-23) * Mysql case sensitivity fixes * Fix desc table for columns containing numbers * Added tab completion for connect @ @@ -43,6 +49,7 @@ * allow enter in pwd field to 'ok' data * fix in replace ~/ with users home dir in spool TODO: flush pwd when username manually set and doesn't match default username + 0.3 (09-10-2007) * focus fix in login dialog * Improve desc table to show primary key |
From: SVN by r. <sv...@ca...> - 2008-12-24 15:24:29
|
Author: roy Date: 2008-12-24 16:24:23 +0100 (Wed, 24 Dec 2008) New Revision: 341 Modified: src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java Log: added startup options.. currently undocumented Modified: src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java =================================================================== --- src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java 2008-12-24 15:24:02 UTC (rev 340) +++ src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java 2008-12-24 15:24:23 UTC (rev 341) @@ -5,6 +5,8 @@ package nl.improved.sqlclient.charva; +import java.util.Map; +import java.util.HashMap; import charva.awt.Dimension; import charva.awt.Point; import charva.awt.Toolkit; @@ -19,6 +21,7 @@ import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; +import nl.improved.sqlclient.SQLCommand; import nl.improved.sqlclient.SQLProperties; import nl.improved.sqlclient.SQLUtil; @@ -147,6 +150,16 @@ public static void main(String[] args) { + Map argsMap = new HashMap<String, String>(); + if (args.length > 0) { + if (args[0].equals("--help") || args.length %2 == 1) { + System.err.println("Usage: "); + System.exit(-1); + } + for (int i = 0; i < args.length; i+=2) { + argsMap.put(args[i], args[i+1]); + } + } JFrame frame = new JFrame() { @Override @@ -163,6 +176,12 @@ frame.add(component); component.sqlshellWindow.repaintScreen(); frame.pack(); + if (argsMap.get("-i") != null) { + new nl.improved.sqlclient.AbstractSQLShellWindow.ExecuteBatchCommand(component.sqlshellWindow).execute(new SQLCommand("@"+ argsMap.get("-i"))); + } + if (argsMap.get("-q") != null) { + return; + } frame.show(); } |
From: SVN by r. <sv...@ca...> - 2008-12-24 15:24:09
|
Author: roy Date: 2008-12-24 16:24:02 +0100 (Wed, 24 Dec 2008) New Revision: 340 Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java Log: code cleanup made executebatch command a static command Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java =================================================================== --- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-12-24 15:14:20 UTC (rev 339) +++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-12-24 15:24:02 UTC (rev 340) @@ -18,7 +18,6 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; @@ -168,7 +167,7 @@ commands.register("EXIT[\\s]*", new QuitCommand("exit")); commands.register("SAVE[\\s]*.*", new SaveCommand()); //commands.register("\\\\Q[\\s]*", new QuitCommand("\\q")); - commands.register("@.*", new ExecuteBatchCommand()); + commands.register("@.*", new ExecuteBatchCommand(this)); commands.register("(SELECT|UPDATE|ALTER|INSERT|DELETE).*;[\\s]*", new QueryCommand()); // keys @@ -459,9 +458,9 @@ } } }; - Thread t = new Thread(r); - t.setDaemon(true); - t.start(); + Thread thread = new Thread(r); + thread.setDaemon(true); + thread.start(); } /** @@ -697,8 +696,8 @@ insertText(newText); } } - } catch(Throwable t) { - error(t); + } catch(Throwable th) { + error(th); } repaint(); } @@ -2026,9 +2025,15 @@ } } - private class ExecuteBatchCommand implements Command { + public static class ExecuteBatchCommand implements Command { private boolean cancelled; private Command currentCommand; + private final AbstractSQLShellWindow sqlShell; + + public ExecuteBatchCommand(AbstractSQLShellWindow sqlShell) { + this.sqlShell = sqlShell; + } + @Override public CharSequence execute(SQLCommand sqlCommand) { cancelled = false; @@ -2038,7 +2043,7 @@ FileInputStream fin = null; try { fin = new FileInputStream(toFileName(command.substring(1))); - output("Reading file: "+ toFileName(command.substring(1))); + sqlShell.output("Reading file: "+ toFileName(command.substring(1))); BufferedReader reader = new BufferedReader(new InputStreamReader(fin)); StringBuffer cmd = new StringBuffer(); String line; @@ -2053,14 +2058,14 @@ if (line.endsWith(";")) { // Exec cmd String commandString = cmd.toString(); - currentCommand = createCommand(commandString); - output(commandString); - output(currentCommand.execute(new InputCommand(commandString))); + currentCommand = sqlShell.createCommand(commandString); + sqlShell.output(commandString); + sqlShell.output(currentCommand.execute(new InputCommand(commandString))); cmd=new StringBuffer(); new Thread() { @Override public void run() { - repaint(); + sqlShell.repaint(); } }.start(); } @@ -2070,7 +2075,7 @@ } return "File '" + toFileName(command.substring(1)) +"' executed successfully."; } catch(IOException e) { - error(e); + sqlShell.error(e); return "File '" + toFileName(command.substring(1)) +"' ended with errors."; } finally { if (fin != null) try { fin.close();}catch(Exception e) {/*ignore*/} |
From: SVN by r. <sv...@ca...> - 2008-12-24 15:14:32
|
Author: roy Date: 2008-12-24 16:14:20 +0100 (Wed, 24 Dec 2008) New Revision: 339 Modified: pom.xml Log: start work on 0.7 Modified: pom.xml =================================================================== --- pom.xml 2008-12-24 14:53:30 UTC (rev 338) +++ pom.xml 2008-12-24 15:14:20 UTC (rev 339) @@ -19,7 +19,7 @@ <groupId>nl.improved</groupId> <artifactId>sqlshell</artifactId> <packaging>jar</packaging> - <version>0.6.1</version> + <version>0.7-SNAPSHOT</version> <name>SQLShell ~ the improved sqlclient</name> <url>http://sqlshell.sourceforge.org</url> <build> |
From: SVN by r. <sv...@ca...> - 2008-12-24 14:53:40
|
Author: roy Date: 2008-12-24 15:53:30 +0100 (Wed, 24 Dec 2008) New Revision: 338 Modified: pom.xml src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java Log: hmm.. fix error introduced in code cleanup :( Modified: pom.xml =================================================================== --- pom.xml 2008-12-22 14:13:50 UTC (rev 337) +++ pom.xml 2008-12-24 14:53:30 UTC (rev 338) @@ -19,7 +19,7 @@ <groupId>nl.improved</groupId> <artifactId>sqlshell</artifactId> <packaging>jar</packaging> - <version>0.6</version> + <version>0.6.1</version> <name>SQLShell ~ the improved sqlclient</name> <url>http://sqlshell.sourceforge.org</url> <build> Modified: src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java =================================================================== --- src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2008-12-22 14:13:50 UTC (rev 337) +++ src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2008-12-24 14:53:30 UTC (rev 338) @@ -53,11 +53,17 @@ @Override public int getScreenWidth() { + if (textComponent == null) { + return Toolkit.getDefaultToolkit().getScreenColumns(); + } return textComponent.getWidth(); } @Override public int getScreenHeight() { + if (textComponent == null) { + return Toolkit.getDefaultToolkit().getScreenRows(); + } return textComponent.getHeight(); } |
From: SVN by r. <sv...@ca...> - 2008-12-22 14:14:00
|
Author: roy Date: 2008-12-22 15:13:50 +0100 (Mon, 22 Dec 2008) New Revision: 337 Modified: sqlshell.bat Log: use jcurses on windows Modified: sqlshell.bat =================================================================== --- sqlshell.bat 2008-12-22 13:50:19 UTC (rev 336) +++ sqlshell.bat 2008-12-22 14:13:50 UTC (rev 337) @@ -29,4 +29,4 @@ REM The classpath to use when running set CP=%WORKINGDIR%;%SQLSHELL%;%JCURSES%\jcurses.jar;%WORKINGDIR%\lib\charva\charva.jar;%WORKINGDIR%\lib\commons-logging.jar -java -Djava.library.path=%WORKINGDIR%\lib\charva -classpath %CP%;%DRIVERS% nl.improved.sqlclient.charva.SQLShellComponent +java -Djava.library.path=%WORKINGDIR%\lib\charva -classpath %CP%;%DRIVERS% nl.improved.sqlclient.jcurses.SQLShell |
From: SVN by r. <sv...@ca...> - 2008-12-22 13:50:24
|
Author: roy Date: 2008-12-22 14:50:19 +0100 (Mon, 22 Dec 2008) New Revision: 336 Added: lib/charva/Terminal.dll Log: windows version Added: lib/charva/Terminal.dll =================================================================== (Binary files differ) Property changes on: lib/charva/Terminal.dll ___________________________________________________________________ Name: svn:mime-type + application/octet-stream |
From: SVN by r. <sv...@ca...> - 2008-12-22 13:49:52
|
Author: roy Date: 2008-12-22 14:49:46 +0100 (Mon, 22 Dec 2008) New Revision: 335 Modified: lib/charva/libTerminal.so Log: removed mouse code.. not used in sqlshell and is causing problems in some shells Modified: lib/charva/libTerminal.so =================================================================== (Binary files differ) |
From: SVN by r. <sv...@ca...> - 2008-12-22 13:47:15
|
Author: roy Date: 2008-12-22 14:47:10 +0100 (Mon, 22 Dec 2008) New Revision: 334 Modified: src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java Log: optimize paint (a little should be able to improve more though) removed borders and use optimum screen Modified: src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java =================================================================== --- src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2008-12-22 13:45:09 UTC (rev 333) +++ src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2008-12-22 13:47:10 UTC (rev 334) @@ -17,6 +17,7 @@ import java.io.OutputStream; import java.sql.SQLException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Vector; import java.util.logging.Level; @@ -52,12 +53,12 @@ @Override public int getScreenWidth() { - return Toolkit.getDefaultToolkit().getScreenColumns()-1; + return textComponent.getWidth(); } @Override public int getScreenHeight() { - return Toolkit.getDefaultToolkit().getScreenRows()-1; + return textComponent.getHeight(); } /** @@ -69,8 +70,69 @@ @Override public void paint(Screen screen) { + if (screen.getPageUpCount() > 0) { + paintSlow(screen); + return; + } int totalLineCount = 0; StringBuilder newText = new StringBuilder(); + List<String> commandLines = formatCommandLines(screen.getShowPrompt() + , screen.getEmptyLine(),(List<CharSequence>) getCommand().getLines()); + for (int i = 0; i < commandLines.size(); i++) { + CharSequence seq = commandLines.get(i); + newText.append(seq.toString()); + if (i < commandLines.size()-1) { + newText.append("\n"); + } + totalLineCount++; + } + if (totalLineCount > getScreenHeight()-1) { + totalLineCount = getScreenHeight()-1; + } + int restLines = (getScreenHeight() -1) - totalLineCount; + if (restLines > 0) { + ArrayList<SQLCommand> commands = new ArrayList<SQLCommand>(getUnprocessedCommands()); + Collections.reverse(commands); + commands: for (SQLCommand command : commands) { + List<? extends CharSequence> lines = command.getLines(); + for (int i = lines.size() -1; i >=0; i--) { + newText.insert(0, lines.get(i) +"\n"); + restLines--; + totalLineCount++; + if(restLines == 0) { + break commands; + } + } + } + } + if (restLines > 0) { + List<CharSequence> buffer = new ArrayList<CharSequence>(screen.getScreenBuffer()); + for (int i = buffer.size() -1; i>=0; i--) { + newText.insert(0, buffer.get(i)+"\n"); + restLines--; + totalLineCount++; + if(restLines == 0) { + break; + } + } + } + if (newText.toString().startsWith(textComponent.getText())) { + textComponent.append(newText.substring(textComponent.getText().length())); + } else { + textComponent.replaceRange(newText.toString(), 0, textComponent.getText().length()); + } + Point cursorPos = screen.getCursorPosition(); + try { + int start = textComponent.getLineStartOffset(totalLineCount - (commandLines.size() - cursorPos.y)); + textComponent.setCaretPosition(start + cursorPos.x + (Screen.PROMPT+" >").length()); + } catch(Exception e) { + debug("ERROR: failed to calculate line end: "+ totalLineCount +"-"+ cursorPos.y +"/"+ getScreenHeight()); + } + textComponent.draw(); + } + public void paintSlow(Screen screen) { + int totalLineCount = 0; + StringBuilder newText = new StringBuilder(); for (CharSequence seq: new ArrayList<CharSequence>(screen.getScreenBuffer())) { newText.append(seq.toString()); newText.append("\n"); @@ -119,7 +181,7 @@ Toolkit.getDefaultToolkit().getTopWindow().hide(); } - + @Override public void beep() { Toolkit.getDefaultToolkit().beep(); @@ -212,7 +274,7 @@ if (strText.indexOf('\n') < 0) { return strText; } - int maxHeight = getScreenHeight()-1; + int maxHeight = getScreenHeight(); String[] lines = strText.split("\n"); if (lines.length <= maxHeight) { return strText; |
From: SVN by r. <sv...@ca...> - 2008-12-22 13:45:15
|
Author: roy Date: 2008-12-22 14:45:09 +0100 (Mon, 22 Dec 2008) New Revision: 333 Modified: src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java Log: remove border Modified: src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java =================================================================== --- src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java 2008-12-22 12:54:27 UTC (rev 332) +++ src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java 2008-12-22 13:45:09 UTC (rev 333) @@ -34,6 +34,7 @@ public SQLShellComponent() { setEditable(false); setEnabled(true); + setBorder(null); } @Override public void processKeyEvent(KeyEvent evt) { @@ -146,12 +147,19 @@ public static void main(String[] args) { - JFrame frame = new JFrame(); + JFrame frame = new JFrame() { + + @Override + public void draw() { + //super.draw(); + } + + }; SQLShellComponent component = new SQLShellComponent(); + frame.setLayout(null); // null layout frame.add(component); - //frame.pack(); - component.setBounds(new Point(0,0), new Dimension(Toolkit.getDefaultToolkit().getScreenColumns()-2 - , Toolkit.getDefaultToolkit().getScreenRows()-2)); + component.setBounds(new Point(0,0), new Dimension(Toolkit.getDefaultToolkit().getScreenColumns() + , Toolkit.getDefaultToolkit().getScreenRows() +1)); frame.add(component); component.sqlshellWindow.repaintScreen(); frame.pack(); |
From: SVN by r. <sv...@ca...> - 2008-12-22 12:54:34
|
Author: roy Date: 2008-12-22 13:54:27 +0100 (Mon, 22 Dec 2008) New Revision: 332 Modified: ChangeLog Log: mention changes Modified: ChangeLog =================================================================== --- ChangeLog 2008-12-22 12:53:46 UTC (rev 331) +++ ChangeLog 2008-12-22 12:54:27 UTC (rev 332) @@ -11,6 +11,10 @@ * Fix error message in @ command when file could not be read * Add persistent history * Improved multithreading support by changing (default) toolkit used (charva) + * Add description of column in 'show tables having <column>' command + * Fix line splitting cursor issues + * Added error log file (temporary) which will write a file to your temporary + directory 0.5 (2008-03-14) * Allow for commands to start in the background, this will allow to continue |
From: SVN by r. <sv...@ca...> - 2008-12-22 12:53:51
|
Author: roy Date: 2008-12-22 13:53:46 +0100 (Mon, 22 Dec 2008) New Revision: 331 Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java Log: fix cursor position when line is split up into multiple lines Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java =================================================================== --- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-12-17 13:47:37 UTC (rev 330) +++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-12-22 12:53:46 UTC (rev 331) @@ -18,10 +18,12 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.PrintStream; import java.io.PrintWriter; import java.io.StringWriter; import java.io.Writer; @@ -133,6 +135,14 @@ * Constructor. */ public AbstractSQLShellWindow() { + File errFile; + try { + errFile = File.createTempFile("sqlshell", ".err"); + errFile.deleteOnExit(); + System.setErr(new PrintStream(errFile)); + } catch (IOException ex) { + Logger.getLogger(AbstractSQLShellWindow.class.getName()).log(Level.SEVERE, null, ex); + } screen = new Screen(); char[] emptyLineChar = new char[getScreenWidth()]; Arrays.fill(emptyLineChar, ' '); @@ -443,6 +453,7 @@ repaint(); } }; + commandThread.setDaemon(true); commandThread.start(); } } @@ -516,9 +527,11 @@ } private synchronized void waitAndPaint() { + long oWait = wait; wait = System.currentTimeMillis(); - if (t == null || !t.isAlive()) { + if (t == null || !t.isAlive() || System.currentTimeMillis() - oWait > 4 ) { t = new RepaintThread(); + t.setDaemon(true); t.start(); } } @@ -738,12 +751,11 @@ currentLine.delete(lastSpace, currentLine.length()); if (lastChar == ' ') { nextLine.deleteCharAt(0); - cursorPosition.x--; } // check if the cursor postition > the new line length // calculate new x and go to nextline if (cursorPosition.x >= lastSpace) { - cursorPosition.x = cursorPosition.x - (lastSpace); + cursorPosition.x = (cursorPosition.x - (lastSpace))-1; cursorPosition.y++; } } |
From: SVN by r. <sv...@ca...> - 2008-12-17 14:15:45
|
Author: roy Date: 2008-12-17 14:47:37 +0100 (Wed, 17 Dec 2008) New Revision: 330 Modified: src/main/java/nl/improved/sqlclient/commands/ShowCommand.java Log: show description of column when using show tables having columnname Modified: src/main/java/nl/improved/sqlclient/commands/ShowCommand.java =================================================================== --- src/main/java/nl/improved/sqlclient/commands/ShowCommand.java 2008-11-09 21:16:45 UTC (rev 329) +++ src/main/java/nl/improved/sqlclient/commands/ShowCommand.java 2008-12-17 13:47:37 UTC (rev 330) @@ -15,6 +15,7 @@ */ package nl.improved.sqlclient.commands; +import java.sql.DatabaseMetaData; import nl.improved.sqlclient.SQLCommand; import nl.improved.sqlclient.DBConnector; import nl.improved.sqlclient.Point; @@ -51,10 +52,26 @@ ResultSet rs = conn.getMetaData().getColumns(conn.getCatalog() , DBConnector.getInstance().getSchema(), "%" , columnName); - List matches = new ArrayList<String>(); + List<String> matches = new ArrayList<String>(); while (rs.next()) { if (!matches.contains(rs.getString("TABLE_NAME"))) { - matches.add(rs.getString("TABLE_NAME")); + //matches.add(rs.getString("TABLE_NAME")); + StringBuilder match = new StringBuilder(); + match.append(rs.getString("TABLE_NAME")); + match.append('\t'); + match.append(rs.getString("COLUMN_NAME")); + match.append('\t'); + String columnSize = rs.getString("COLUMN_SIZE"); + if (columnSize != null) { + match.append(rs.getString("TYPE_NAME") +"("+columnSize+")"); + } else { + match.append(rs.getString("TYPE_NAME")); + } + int nullable = rs.getInt("NULLABLE"); + if (nullable == DatabaseMetaData.columnNoNulls) { + match.append(" NOT NULL"); + } + matches.add(match.toString()); } } returnValue.append("\nTables with column name: '"+ columnName+"'\n"); |
From: SVN by r. <sv...@ca...> - 2008-11-09 21:16:57
|
Author: roy Date: 2008-11-09 22:16:45 +0100 (Sun, 09 Nov 2008) New Revision: 329 Modified: src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java Log: implement 'non native' paste and copy methods using mouse Modified: src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java =================================================================== --- src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java 2008-11-09 21:07:33 UTC (rev 328) +++ src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java 2008-11-09 21:16:45 UTC (rev 329) @@ -14,10 +14,13 @@ import charvax.swing.JTextArea; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.Transferable; import java.awt.datatransfer.UnsupportedFlavorException; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; +import nl.improved.sqlclient.SQLProperties; +import nl.improved.sqlclient.SQLUtil; /** * @@ -26,6 +29,7 @@ public class SQLShellComponent extends JTextArea { private CharvaSQLShellWindow sqlshellWindow = new CharvaSQLShellWindow(this); + private Point startPos; public SQLShellComponent() { setEditable(false); @@ -37,24 +41,106 @@ sqlshellWindow.keyTyped(evt); } + void setSelection(int pStart, int pEnd) { + if (!"all".equals(SQLProperties.getProperty(SQLProperties.PropertyName.MOUSE_HANDLING))) { + return; + } + int start, end; + if (pEnd < pStart) { + end = pStart; + start = pEnd; + } else { + start = pStart; + end = pEnd; + } + end = Math.min(getText().length(), end); + sqlshellWindow.debug("SET SELECTION: "+ start +" -> "+ end); + sqlshellWindow.debug("SET TO CLIPBOARD: "+ getText().substring(start, end)); + Clipboard clipBoard = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard(); + final String text = getText().substring(start, Math.min(getText().length(), end)); + Transferable tf = new Transferable() { + + public DataFlavor[] getTransferDataFlavors() { + return new DataFlavor[] {DataFlavor.stringFlavor}; + } + + public boolean isDataFlavorSupported(DataFlavor flavor) { + return DataFlavor.stringFlavor == flavor; + } + + public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { + return text; + } + }; + clipBoard.setContents(tf, null); + } + @Override public void processMouseEvent(MouseEvent evt) { super.processMouseEvent(evt); - if (evt.getModifiers() == evt.MOUSE_PRESSED) { - if (evt.getButton() == MouseEvent.BUTTON2) { - Clipboard clipBoard = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard(); - try { - String clipBoardContents = (String) clipBoard.getData(DataFlavor.stringFlavor); - //sqlshellWindow.debug(clipBoardContents); - sqlshellWindow.insertText(clipBoardContents); - sqlshellWindow.repaintScreen(); - } catch (UnsupportedFlavorException ex) { - Logger.getLogger(SQLShellComponent.class.getName()).log(Level.SEVERE, null, ex); - } catch (IOException ex) { - Logger.getLogger(SQLShellComponent.class.getName()).log(Level.SEVERE, null, ex); + if (evt.getModifiers() == MouseEvent.MOUSE_CLICKED) { + if (evt.getButton() == MouseEvent.BUTTON1) { + if (evt.getClickCount() == 2) { // double click.. select word under char + try { + int line = getLineStartOffset(evt.getY()-1); + String text = getText(); + int start, end; + for (start = line + evt.getX(); start > 0; start--) { + if (SQLUtil.isBreakCharacter(text.charAt(start))) { + break; + } + } + for (end = line + evt.getX(); end < text.length(); end++) { + if (SQLUtil.isBreakCharacter(text.charAt(end))) { + break; + } + } + setSelection(start, end); + } catch(Exception e) { } } - } + } else if (evt.getModifiers() == MouseEvent.MOUSE_PRESSED) { + sqlshellWindow.debug("PRESSED"); + if (evt.getButton() == MouseEvent.BUTTON1) { + if (startPos == null) { + startPos = new Point(evt.getX()-1, evt.getY()-1); + } else { + try { + Point endPos = new Point(evt.getX()-1, evt.getY()-1); + int start = getLineStartOffset(startPos.y) + startPos.x; + int end = getLineStartOffset(endPos.y) + endPos.x; + setSelection(start, end); + startPos = null; + } catch(Exception e) {} + } + } + if (evt.getButton() == MouseEvent.BUTTON2) { // paste from clipboard + String mouseHandling = SQLProperties.getProperty(SQLProperties.PropertyName.MOUSE_HANDLING); + if ("all".equals(mouseHandling) || "paste".equals(mouseHandling)) { + Clipboard clipBoard = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard(); + try { + String clipBoardContents = (String) clipBoard.getData(DataFlavor.stringFlavor); + //sqlshellWindow.debug(clipBoardContents); + sqlshellWindow.insertText(clipBoardContents); + sqlshellWindow.repaintScreen(); + } catch (UnsupportedFlavorException ex) { + Logger.getLogger(SQLShellComponent.class.getName()).log(Level.SEVERE, null, ex); + } catch (IOException ex) { + Logger.getLogger(SQLShellComponent.class.getName()).log(Level.SEVERE, null, ex); + } + } + } + } else if (evt.getModifiers() == MouseEvent.MOUSE_RELEASED) { + sqlshellWindow.debug("RELEASED: " + startPos); + Point endPos = new Point(evt.getX()-1, evt.getY()-1); + if (startPos != null) { + try { + int start = getLineStartOffset(startPos.y) + startPos.x; + int end = getLineStartOffset(endPos.y) + endPos.x; + setSelection(start, end); + startPos = null; + } catch(Exception e) { /* ignore */ } + } } } |
From: SVN by r. <sv...@ca...> - 2008-11-09 21:07:41
|
Author: roy Date: 2008-11-09 22:07:33 +0100 (Sun, 09 Nov 2008) New Revision: 328 Added: src/main/resources/defaultconfig.properties Modified: src/main/java/nl/improved/sqlclient/SQLProperties.java Log: some property settings Modified: src/main/java/nl/improved/sqlclient/SQLProperties.java =================================================================== --- src/main/java/nl/improved/sqlclient/SQLProperties.java 2008-11-07 21:32:35 UTC (rev 327) +++ src/main/java/nl/improved/sqlclient/SQLProperties.java 2008-11-09 21:07:33 UTC (rev 328) @@ -15,11 +15,17 @@ */ package nl.improved.sqlclient; -import java.util.Map; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; import java.util.Properties; +import java.util.logging.Level; +import java.util.logging.Logger; + public class SQLProperties { - public static enum PropertyName {VERSION}; + public static enum PropertyName {VERSION, CONFIG_VERSION, MOUSE_HANDLING}; private static SQLProperties instance; @@ -27,14 +33,37 @@ private SQLProperties() { props = new Properties(); + Properties defaultProperties = new Properties(); try { - props.load(getClass().getResourceAsStream("/META-INF/maven/nl.improved/sqlshell/pom.properties")); + defaultProperties.load(getClass().getResourceAsStream("/defaultconfig.properties")); + } catch (IOException ex) {ex.printStackTrace(); } + try { + File configFile = getPropertyFile(); + if (configFile.exists()) { + props.load(new FileInputStream(configFile)); + } + } catch(Exception e) {/* ignore */} + if (!props.getProperty(PropertyName.CONFIG_VERSION.name(), "0") + .equals(defaultProperties.getProperty(PropertyName.CONFIG_VERSION.name(), "0"))) { + try { + migrateProperies(defaultProperties, props); + props = defaultProperties; + } catch (IOException ex) { + Logger.getLogger(SQLProperties.class.getName()).log(Level.SEVERE, null, ex); + } + } + try { + Properties pomProps = new Properties(); + pomProps.load(getClass().getResourceAsStream("/META-INF/maven/nl.improved/sqlshell/pom.properties")); props.put(PropertyName.VERSION, props.get("version")); } catch(Exception e) { //System.err.println("Failed to load pom.properties"); } } + private static File getPropertyFile() { + return new File(System.getProperty("user.home")+File.separator+".sqlshell"+File.separator+"config.properties"); + } private static SQLProperties getInstance() { if (instance == null) { instance = new SQLProperties(); @@ -43,7 +72,7 @@ } public static String getProperty(PropertyName property) { - return (String)getInstance().props.get(property); + return (String)getInstance().props.get(property.name()); } public static String getProperty(PropertyName property, String defaultValue) { @@ -53,4 +82,13 @@ } return prop; } + + private void migrateProperies(Properties defaultProps, Properties currentProps) throws IOException { + for (Object key : currentProps.keySet()) { + if (!key.equals(PropertyName.CONFIG_VERSION.name())) { + defaultProps.put(key, currentProps.getProperty((String)key)); + } + } + defaultProps.save(new FileOutputStream(getPropertyFile()), "SQLShell properties file"); + } } Added: src/main/resources/defaultconfig.properties =================================================================== --- src/main/resources/defaultconfig.properties 2008-11-07 21:32:35 UTC (rev 327) +++ src/main/resources/defaultconfig.properties 2008-11-09 21:07:33 UTC (rev 328) @@ -0,0 +1,9 @@ +#this is the sqlshell propertiesfile +#Please don't change this value.. it is used to upgrade your properties file +CONFIG_VERSION=1 +# +#Set the mouse handling for the 'Charva' implementation. Possible values: +#native (default) : ignore mouse events in java and use default system behaviour +#paste : use middle mouse button to paste the clipboard contents +#all : paste and implement selection and copy the selection to the clipboard +MOUSE_HANDLING=native |
From: SVN by r. <sv...@ca...> - 2008-11-07 21:59:24
|
Author: roy Date: 2008-11-07 22:32:35 +0100 (Fri, 07 Nov 2008) New Revision: 327 Modified: src/main/java/nl/improved/sqlclient/ src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java Log: use insert text when middle mouse button pressed Property changes on: src/main/java/nl/improved/sqlclient ___________________________________________________________________ Name: svn:ignore - .SQLPlusPlus.java.swp .SQLPlus.java.swp .DBConnector.java.swp .SQLUtil.java.swp .Point.java.swp .SQLLineWrapper.java.swp .SQLOutput.java.swp .QueryExecutor.java.swp .SQLShell.java.swp .AbstractSQLShellWindow.java.swo .AbstractSQLShellWindow.java.swp + .SQLPlusPlus.java.swp .SQLPlus.java.swp .DBConnector.java.swp .SQLUtil.java.swp .Point.java.swp .SQLLineWrapper.java.swp .SQLOutput.java.swp .QueryExecutor.java.swp .SQLShell.java.swp .AbstractSQLShellWindow.java.swo .AbstractSQLShellWindow.java.swp .TabCompletionInfo.java.swp Modified: src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java =================================================================== --- src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java 2008-11-07 21:31:58 UTC (rev 326) +++ src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java 2008-11-07 21:32:35 UTC (rev 327) @@ -12,6 +12,12 @@ import charva.awt.event.MouseEvent; import charvax.swing.JFrame; import charvax.swing.JTextArea; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.UnsupportedFlavorException; +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; /** * @@ -23,13 +29,36 @@ public SQLShellComponent() { setEditable(false); + setEnabled(true); } @Override - public void processKeyEvent(KeyEvent arg0) { + public void processKeyEvent(KeyEvent evt) { //super.processKeyEvent(arg0); - sqlshellWindow.keyTyped(arg0); + sqlshellWindow.keyTyped(evt); } + @Override + public void processMouseEvent(MouseEvent evt) { + super.processMouseEvent(evt); + if (evt.getModifiers() == evt.MOUSE_PRESSED) { + if (evt.getButton() == MouseEvent.BUTTON2) { + Clipboard clipBoard = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard(); + try { + String clipBoardContents = (String) clipBoard.getData(DataFlavor.stringFlavor); + //sqlshellWindow.debug(clipBoardContents); + sqlshellWindow.insertText(clipBoardContents); + sqlshellWindow.repaintScreen(); + } catch (UnsupportedFlavorException ex) { + Logger.getLogger(SQLShellComponent.class.getName()).log(Level.SEVERE, null, ex); + } catch (IOException ex) { + Logger.getLogger(SQLShellComponent.class.getName()).log(Level.SEVERE, null, ex); + } + + } + } + } + + public static void main(String[] args) { JFrame frame = new JFrame(); SQLShellComponent component = new SQLShellComponent(); |