From: SVN by r. <sv...@ca...> - 2008-08-19 20:32:59
|
Author: roy Date: 2008-08-19 22:32:51 +0200 (Tue, 19 Aug 2008) New Revision: 292 Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java Log: some code cleanups Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java =================================================================== --- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-08-19 20:30:37 UTC (rev 291) +++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-08-19 20:32:51 UTC (rev 292) @@ -1629,10 +1629,28 @@ return false; } } + private abstract class ReadDumpCommand implements Command { + public static final String DATE_FORMAT = "yyyyMMddHHmmss"; + + boolean isBinary(int columnType) { + if (columnType == Types.BINARY || + columnType == Types.BLOB || + columnType == Types.CLOB || + columnType == Types.LONGNVARCHAR || + columnType == Types.LONGVARBINARY || + columnType == Types.LONGVARCHAR || + columnType == Types.NCLOB || + columnType == Types.OTHER) { + return true; + } + return false; + + } + } /** * Writes the result of a query into a dump file so that it can be read back. */ - private class DumpCommand implements Command { + private class DumpCommand extends ReadDumpCommand { private String fileName; @Override @@ -1672,7 +1690,7 @@ Connection c = DBConnector.getInstance().getConnection(); Statement stmt = c.createStatement(); ResultSet rs = stmt.executeQuery(query); - SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss"); + SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT); while (rs.next()) { atts.clear(); hd.startElement("","","row",atts); @@ -1687,14 +1705,7 @@ String dateString = formatter.format(date); hd.characters(dateString.toCharArray(), 0, dateString.length()); } - } else if (metaData.getColumnType(col) == Types.BINARY || - metaData.getColumnType(col) == Types.BLOB || - metaData.getColumnType(col) == Types.CLOB || - metaData.getColumnType(col) == Types.LONGNVARCHAR || - metaData.getColumnType(col) == Types.LONGVARBINARY || - metaData.getColumnType(col) == Types.LONGVARCHAR || - metaData.getColumnType(col) == Types.NCLOB || - metaData.getColumnType(col) == Types.OTHER) { + } else if (isBinary(metaData.getColumnType(col))) { atts.addAttribute("","","type","","binary"); hd.startElement("","","col",atts); @@ -1786,7 +1797,7 @@ /** * Read the result of a dump file. */ - private class ReadCommand implements Command { + private class ReadCommand extends ReadDumpCommand { private String fileName; @Override @@ -1834,7 +1845,7 @@ query = query + values +")"; Connection c = DBConnector.getInstance().getConnection(); PreparedStatement pstmt = c.prepareStatement(query); - SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss"); + SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT); for (int nodeNr = 0; nodeNr < nodeList.getLength(); nodeNr++) { Element row = (Element) nodeList.item(nodeNr); // row NodeList columns = row.getElementsByTagName("col"); |
From: SVN by r. <sv...@ca...> - 2008-08-22 07:51:26
|
Author: roy Date: 2008-08-22 09:51:14 +0200 (Fri, 22 Aug 2008) New Revision: 293 Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java Log: made login dialog cause less problems (direct commands where still being executed in an other thread) Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java =================================================================== --- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-08-19 20:32:51 UTC (rev 292) +++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-08-22 07:51:14 UTC (rev 293) @@ -959,6 +959,19 @@ if (command == null) { return false; } + if (direct || !command.backgroundProcessSupported()) { + while (commandQueue.size() != 0) { + debug("Waiting for command queue to be cleared"); + try { + Thread.sleep(1000); + } catch (InterruptedException ex) { + Logger.getLogger(AbstractSQLShellWindow.class.getName()).log(Level.SEVERE, null, ex); + } + } + output(command.execute(sqlCommand)); + repaint(); + return true; + } commandQueue.add(new CommandInfo(sqlCommand, command)); return true; } @@ -1636,10 +1649,10 @@ if (columnType == Types.BINARY || columnType == Types.BLOB || columnType == Types.CLOB || - columnType == Types.LONGNVARCHAR || + //columnType == Types.LONGNVARCHAR || // jdk 1.6 columnType == Types.LONGVARBINARY || columnType == Types.LONGVARCHAR || - columnType == Types.NCLOB || + //columnType == Types.NCLOB || // jdk 1.6 columnType == Types.OTHER) { return true; } |
From: SVN by r. <sv...@ca...> - 2008-08-23 12:32:53
|
Author: roy Date: 2008-08-23 14:32:42 +0200 (Sat, 23 Aug 2008) New Revision: 295 Modified: src/main/java/nl/improved/sqlclient/DBConnector.java Log: java 6-5 fixes Modified: src/main/java/nl/improved/sqlclient/DBConnector.java =================================================================== --- src/main/java/nl/improved/sqlclient/DBConnector.java 2008-08-23 12:32:22 UTC (rev 294) +++ src/main/java/nl/improved/sqlclient/DBConnector.java 2008-08-23 12:32:42 UTC (rev 295) @@ -162,7 +162,9 @@ try { Class.forName(settings.getDriver()); } catch (ClassNotFoundException e) { - throw new SQLException("Failed to connect: Could not initialize driver '"+settings.getDriver()+"'", e); + SQLException se = new SQLException("Failed to connect: Could not initialize driver '"+settings.getDriver()+"'"); + se.initCause(e); + throw se; } |
From: SVN by r. <sv...@ca...> - 2008-08-24 18:49:41
|
Author: roy Date: 2008-08-24 20:49:27 +0200 (Sun, 24 Aug 2008) New Revision: 297 Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java Log: don't return 'succesfully' when failed to read file to be executed '@' Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java =================================================================== --- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-08-23 12:32:57 UTC (rev 296) +++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-08-24 18:49:27 UTC (rev 297) @@ -1961,14 +1961,15 @@ }.start(); } } + if (cancelled) { + return "Execution of file '" + toFileName(command.substring(1)) +"' aborted...."; + } + return "File '" + toFileName(command.substring(1)) +"' executed successfully."; } catch(IOException e) { error(e); + return "File '" + toFileName(command.substring(1)) +"' ended with errors."; } finally { if (fin != null) try { fin.close();}catch(Exception e) {/*ignore*/} - if (cancelled) { - return "Execution of file '" + toFileName(command.substring(1)) +"' aborted...."; - } - return "File '" + toFileName(command.substring(1)) +"' executed successfully."; } } |
From: SVN by r. <sv...@ca...> - 2008-08-28 08:08:23
|
Author: roy Date: 2008-08-28 10:08:11 +0200 (Thu, 28 Aug 2008) New Revision: 300 Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java Log: output 'direct' commands as well Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java =================================================================== --- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-08-24 20:18:29 UTC (rev 299) +++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-08-28 08:08:11 UTC (rev 300) @@ -423,6 +423,7 @@ Logger.getLogger(AbstractSQLShellWindow.class.getName()).log(Level.SEVERE, null, ex); } } + output(cmd.sql.getLines()); repaint(); if (/*direct ||*/ !cmd.cmd.backgroundProcessSupported()) { @@ -968,6 +969,8 @@ Logger.getLogger(AbstractSQLShellWindow.class.getName()).log(Level.SEVERE, null, ex); } } + output(sqlCommand.getLines()); + //repaint(); output(command.execute(sqlCommand)); repaint(); return true; |
From: SVN by r. <sv...@ca...> - 2008-09-15 12:00:53
|
Author: roy Date: 2008-09-15 21:00:41 +0200 (Mon, 15 Sep 2008) New Revision: 304 Modified: src/main/java/nl/improved/sqlclient/SQLUtil.java Log: added ( and ) as 'break' character Modified: src/main/java/nl/improved/sqlclient/SQLUtil.java =================================================================== --- src/main/java/nl/improved/sqlclient/SQLUtil.java 2008-09-04 12:32:02 UTC (rev 303) +++ src/main/java/nl/improved/sqlclient/SQLUtil.java 2008-09-15 19:00:41 UTC (rev 304) @@ -26,7 +26,7 @@ */ public class SQLUtil { - final static char[] breakCharacters = new char[]{' ', '\t', '.', ','}; + final static char[] breakCharacters = new char[]{' ', '\t', '.', ',', '(',')'}; /** * A regular expression statement for name chars. */ |
From: SVN by r. <sv...@ca...> - 2008-09-15 12:02:11
|
Author: roy Date: 2008-09-15 21:01:58 +0200 (Mon, 15 Sep 2008) New Revision: 305 Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java Log: added binary support for read added integer/float support for read added 'save' command to save the previous history as addon to 'spool' Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java =================================================================== --- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-09-15 19:00:41 UTC (rev 304) +++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-09-15 19:01:58 UTC (rev 305) @@ -16,6 +16,7 @@ package nl.improved.sqlclient; import java.io.BufferedReader; +import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileWriter; @@ -65,6 +66,7 @@ import org.w3c.dom.NodeList; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; +import sun.misc.BASE64Decoder; import sun.misc.BASE64Encoder; /** @@ -155,6 +157,7 @@ commands.register("READ[\\s]*.*[A-Z]+.*", new ReadCommand()); commands.register("QUIT[\\s]*", new QuitCommand("quit")); 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("(SELECT|UPDATE|ALTER|INSERT|DELETE).*;[\\s]*", new QueryCommand()); @@ -1715,6 +1718,7 @@ atts.addAttribute("","","name","",metaData.getColumnName(col)); if (metaData.getColumnType(col) == Types.DATE) { atts.addAttribute("","","type","","date"); + atts.addAttribute("","","type_name","",metaData.getColumnTypeName(col)); hd.startElement("","","col",atts); Date date = rs.getDate(col); if (date != null) { @@ -1723,6 +1727,7 @@ } } else if (isBinary(metaData.getColumnType(col))) { atts.addAttribute("","","type","","binary"); + atts.addAttribute("","","type_name","",metaData.getColumnTypeName(col)); hd.startElement("","","col",atts); BASE64Encoder enc = new BASE64Encoder(); @@ -1744,7 +1749,8 @@ } } } else { - atts.addAttribute("","","type","",metaData.getColumnTypeName(col)); + atts.addAttribute("","","type","",Integer.toString(metaData.getColumnType(col))); + atts.addAttribute("","","type_name","",metaData.getColumnTypeName(col)); hd.startElement("","","col",atts); String value= rs.getString(col); if (value != null) { @@ -1868,12 +1874,43 @@ for (int colNr = 0; colNr < columns.getLength(); colNr++) { Element column = (Element) columns.item(colNr); Node type = column.getAttributes().getNamedItem("type"); - if (type != null && type.getNodeValue().equals("date")) { - String nodeValue = column.getTextContent(); - if (nodeValue == null || nodeValue.equals("")) { - pstmt.setDate(colNr+1, null); + if (type != null) { + String typeString = type.getNodeValue(); + if (typeString.equals("date")) { + String nodeValue = column.getTextContent(); + if (nodeValue == null || nodeValue.equals("")) { + pstmt.setDate(colNr+1, null); + } else { + pstmt.setDate(colNr+1, new Date(formatter.parse(nodeValue).getTime())); + } + } else if (typeString.equals("binary")) { // (isBinary(metaData.getColumnType(col))) + String nodeValue = column.getTextContent(); + BASE64Decoder decoder = new BASE64Decoder(); + byte[] value = decoder.decodeBuffer(nodeValue); + //pstmt.setBinaryStream(colNr+1, new ByteArrayInputStream(value)); + pstmt.setBytes(colNr+1, value); } else { - pstmt.setDate(colNr+1, new Date(formatter.parse(nodeValue).getTime())); + String nodeValue = column.getTextContent(); + int iType = Integer.parseInt(typeString); + switch (iType) { + case Types.INTEGER : + case Types.SMALLINT : + case Types.BIGINT : + pstmt.setInt(colNr+1, Integer.parseInt(nodeValue)); + break; + case Types.DOUBLE : pstmt.setDouble(colNr+1, Double.parseDouble(nodeValue)); + break; + case Types.VARCHAR : + case Types.CHAR : + case Types.LONGNVARCHAR : + case Types.NCHAR : + case Types.NVARCHAR : + pstmt.setString(colNr+1, nodeValue); + break; + default: + debug("WARNING Unhandled type: "+ typeString +" trying to fallback to String"); + pstmt.setString(colNr+1, nodeValue); + } } } else { //debug(nodeNr +" ? "+column.getTextContent()); @@ -2015,6 +2052,68 @@ } /** + * Simple command to save the current visible screen history (commands and it"s output). + */ + private class SaveCommand implements Command { + public CharSequence 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(); + } + FileWriter writer = null; + try { + writer = new FileWriter(f); + for (CharSequence c : getScreen().getScreenBuffer()) { + writer.write(c.toString()); + writer.write('\n'); + } + return "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+")"; + } finally { + if (writer != null) { + try { + writer.close(); + } catch (IOException ex) { + Logger.getLogger(AbstractSQLShellWindow.class.getName()).log(Level.SEVERE, null, ex); + } + } + } + } + + return null; + } + + public CharSequence getCommandString() { + return "save"; + } + + public TabCompletionInfo getTabCompletionInfo(SQLCommand commandInfo, Point commandPoint) { + return null; + } + + public CharSequence getHelp() { + return "history filename\nSaves the history of the screen to the filename provided\n"+ + "This command is an addition to the 'dump' command. It doesn't write future output, "+ + "but it saves the output that is still in the history of 'SQLShell' to the file specified.\n"+ + "Please note that it doesn't write new command output to that file.\n"+ + "For example:'save history ~/history.txt'"; + } + + public boolean abort() { + return false; + } + + public boolean backgroundProcessSupported() { + return false; + } + + } + /** * Command class to execute a 'custom command'. * this makes it possible to have 'automated' commands executed. * E.g.: @@ -2046,6 +2145,7 @@ } } + /** * Command thread responsible for executing commands in the background. * It holds a reference to the current command that is being executed. |
From: SVN by r. <sv...@ca...> - 2008-11-07 21:58:45
|
Author: roy Date: 2008-11-07 22:31:58 +0100 (Fri, 07 Nov 2008) New Revision: 326 Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java Log: added method insertText Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java =================================================================== --- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-10-16 21:16:38 UTC (rev 325) +++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-11-07 21:31:58 UTC (rev 326) @@ -16,7 +16,6 @@ package nl.improved.sqlclient; import java.io.BufferedReader; -import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileWriter; @@ -492,10 +491,38 @@ */ protected void repaint() { if (isRunning()) { - paint(getScreen()); + waitAndPaint(); + //paint(getScreen()); } } + long wait = 0; + Thread t; + private class RepaintThread extends Thread { + @Override + public void run() { + while (true) { + try { + Thread.sleep(5); + } catch (InterruptedException ex) { + Logger.getLogger(AbstractSQLShellWindow.class.getName()).log(Level.SEVERE, null, ex); + } + if (wait <= (System.currentTimeMillis() +5) ) { + paint(screen); + return; + } + } + } + } + + private synchronized void waitAndPaint() { + wait = System.currentTimeMillis(); + if (t == null || !t.isAlive()) { + t = new RepaintThread(); + t.start(); + } + } + /** * Paints the screen. * @param screen the screen to be painted @@ -654,63 +681,7 @@ } else { newText = Character.toString(inp.getCharacter()); } - if (newText.equals("\n")) { - newLine(); // TODO Fix return in middle of an other line - } else { - Point cursorPosition = screen.getCursorPosition(); - List<StringBuffer> editableLines = getEditableCommand().getEditableLines(); - StringBuffer currentLine = editableLines.get(cursorPosition.y); - if (cursorPosition.x > currentLine.length()) { - for (int i = currentLine.length(); i < cursorPosition.x; i++) { - currentLine.append(' '); - } - debug("WARNING: Fixing: cursorposition: "+ cursorPosition.x +" /" + currentLine.length()); - } - currentLine.insert(cursorPosition.x, newText); - cursorPosition.x += newText.length(); - // check if the new line is becoming too long - if (currentLine.length() > screen.MAX_LINE_LENGTH) { - // TODO search for lastspace that is not between '' ?? - int lastSpace = SQLUtil.getLastBreakIndex(currentLine.toString());//currentLine.lastIndexOf(" "); - int lastChar = currentLine.charAt(lastSpace); - if (lastSpace == -1) { - lastSpace = currentLine.length(); - } - // check if there are enough 'next' lines - // if not.. add one - if (editableLines.size()-1 == cursorPosition.y) { - StringBuffer newLine = new StringBuffer(); - editableLines.add(newLine); - } - // check if the nextline has enough room for the new word - // if not.. add a new line - if (editableLines.get(cursorPosition.y+1).length() - + (currentLine.length()-lastSpace+1) > screen.MAX_LINE_LENGTH) { - StringBuffer newLine = new StringBuffer(); - editableLines.add(cursorPosition.y+1, newLine); - } - // fetch the next line - StringBuffer nextLine = editableLines.get(cursorPosition.y+1); - // if the nextline already has some text.. add a space in front of it - // if there is not already a 'breaking character' there - if (nextLine.length() > 0 && ! SQLUtil.isBreakCharacter(nextLine.charAt(0))) { - nextLine.insert(0, ' '); - } - // insert the new text at the beginning - nextLine.insert(0, currentLine.subSequence(lastSpace, currentLine.length())); - 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.y++; - } - } - } + insertText(newText); } } } catch(Throwable t) { @@ -719,6 +690,66 @@ repaint(); } + public void insertText(CharSequence newText) { + if (newText.equals("\n")) { + newLine(); // TODO Fix return in middle of an other line + } else { + Point cursorPosition = screen.getCursorPosition(); + List<StringBuffer> editableLines = getEditableCommand().getEditableLines(); + StringBuffer currentLine = editableLines.get(cursorPosition.y); + if (cursorPosition.x > currentLine.length()) { + for (int i = currentLine.length(); i < cursorPosition.x; i++) { + currentLine.append(' '); + } + debug("WARNING: Fixing: cursorposition: "+ cursorPosition.x +" /" + currentLine.length()); + } + currentLine.insert(cursorPosition.x, newText); + cursorPosition.x += newText.length(); + // check if the new line is becoming too long + if (currentLine.length() > screen.MAX_LINE_LENGTH) { + // TODO search for lastspace that is not between '' ?? + int lastSpace = SQLUtil.getLastBreakIndex(currentLine.toString());//currentLine.lastIndexOf(" "); + int lastChar = currentLine.charAt(lastSpace); + if (lastSpace == -1) { + lastSpace = currentLine.length(); + } + // check if there are enough 'next' lines + // if not.. add one + if (editableLines.size()-1 == cursorPosition.y) { + StringBuffer newLine = new StringBuffer(); + editableLines.add(newLine); + } + // check if the nextline has enough room for the new word + // if not.. add a new line + if (editableLines.get(cursorPosition.y+1).length() + + (currentLine.length()-lastSpace+1) > screen.MAX_LINE_LENGTH) { + StringBuffer newLine = new StringBuffer(); + editableLines.add(cursorPosition.y+1, newLine); + } + // fetch the next line + StringBuffer nextLine = editableLines.get(cursorPosition.y+1); + // if the nextline already has some text.. add a space in front of it + // if there is not already a 'breaking character' there + if (nextLine.length() > 0 && ! SQLUtil.isBreakCharacter(nextLine.charAt(0))) { + nextLine.insert(0, ' '); + } + // insert the new text at the beginning + nextLine.insert(0, currentLine.subSequence(lastSpace, currentLine.length())); + 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.y++; + } + } + } + } + /** * Return the editable version of the commandlines. * If editing a previous command clone it and return the clone |
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-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: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...> - 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-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-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 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: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:58:55
|
Author: roy Date: 2009-01-16 21:58:47 +0100 (Fri, 16 Jan 2009) New Revision: 352 Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java Log: error handling in batch command Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java =================================================================== --- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2009-01-16 20:44:06 UTC (rev 351) +++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2009-01-16 20:58:47 UTC (rev 352) @@ -2112,16 +2112,17 @@ errorCount++; sqlShell.output("Execution Failed...\n"); } - cmd=new StringBuffer(); - new Thread() { - @Override - public void run() { - sqlShell.repaint(); - } - }.start(); } catch(Exception e) { + errorCount++; sqlShell.error(e); } + cmd=new StringBuffer(); + new Thread() { + @Override + public void run() { + sqlShell.repaint(); + } + }.start(); } if (cancelled) { return new SimpleCommandResult(true, "Execution of file '" + toFileName(command.substring(1)) +"' aborted...."); |
From: SVN by r. <sv...@ca...> - 2009-01-17 14:55:45
|
Author: roy Date: 2009-01-17 15:55:32 +0100 (Sat, 17 Jan 2009) New Revision: 353 Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java Log: fix parsing of sqlcommands when using batch commands Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java =================================================================== --- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2009-01-16 20:58:47 UTC (rev 352) +++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2009-01-17 14:55:32 UTC (rev 353) @@ -2083,7 +2083,7 @@ fin = new FileInputStream(toFileName(command.substring(1))); sqlShell.output("Reading file: "+ toFileName(command.substring(1))); BufferedReader reader = new BufferedReader(new InputStreamReader(fin)); - StringBuffer cmd = new StringBuffer(); + SQLCommand sqlCmd = new SQLCommand(); String line; int errorCount = 0; while ( ((line = reader.readLine()) != null)) { @@ -2093,8 +2093,8 @@ if (line.startsWith("--")) { continue; } - cmd.append(line); - String commandString = cmd.toString(); + sqlCmd.getEditableLines().add(new StringBuffer(line)); + String commandString = sqlCmd.getUntrimmedCommandString(); currentCommand = sqlShell.createCommand(commandString); if (currentCommand == null) { continue; @@ -2116,7 +2116,7 @@ errorCount++; sqlShell.error(e); } - cmd=new StringBuffer(); + sqlCmd=new SQLCommand(); new Thread() { @Override public void run() { @@ -2127,8 +2127,8 @@ if (cancelled) { return new SimpleCommandResult(true, "Execution of file '" + toFileName(command.substring(1)) +"' aborted...."); } - if (cmd.toString().trim().length() > 0) { - return new SimpleCommandResult(false, "File '"+ toFileName(command.substring(1)) +"' missing a ';' at the end of the last command"); + if (sqlCmd.getCommandString().trim().length() > 0) { + return new SimpleCommandResult(false, "File '"+ toFileName(command.substring(1)) +"' missing a ';' at the end of the last command (" + sqlCmd.getUntrimmedCommandString()+")"); } else { return new SimpleCommandResult(true, "File '" + toFileName(command.substring(1)) +"' executed " + (errorCount > 0 ? "with "+ errorCount+" errors." : "successfully.")); } |
From: SVN by r. <sv...@ca...> - 2009-01-17 15:11:48
|
Author: roy Date: 2009-01-17 16:11:40 +0100 (Sat, 17 Jan 2009) New Revision: 354 Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java Log: added more help and fixed existing help for batchcommand added options to abort on error in execute batch command Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java =================================================================== --- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2009-01-17 14:55:32 UTC (rev 353) +++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2009-01-17 15:11:40 UTC (rev 354) @@ -2086,7 +2086,9 @@ SQLCommand sqlCmd = new SQLCommand(); String line; int errorCount = 0; - while ( ((line = reader.readLine()) != null)) { + boolean continueOnError = true; + boolean abortedOnError = false; + while ( !abortedOnError && ((line = reader.readLine()) != null)) { if (cancelled) { return new SimpleCommandResult(true, "Aborted"); } @@ -2095,6 +2097,16 @@ } sqlCmd.getEditableLines().add(new StringBuffer(line)); String commandString = sqlCmd.getUntrimmedCommandString(); + if (commandString.matches("@@continue_on_error.*")) { + continueOnError = true; + sqlCmd = new SQLCommand(); + continue; + } + if (commandString.matches("@@abort_on_error.*")) { + continueOnError = false; + sqlCmd = new SQLCommand(); + continue; + } currentCommand = sqlShell.createCommand(commandString); if (currentCommand == null) { continue; @@ -2110,10 +2122,16 @@ } if (!result.executedSuccessfully()) { errorCount++; + if (!continueOnError) { + abortedOnError = true; + } sqlShell.output("Execution Failed...\n"); } } catch(Exception e) { errorCount++; + if (!continueOnError) { + abortedOnError = true; + } sqlShell.error(e); } sqlCmd=new SQLCommand(); @@ -2124,6 +2142,10 @@ } }.start(); } + if (abortedOnError) { + return new SimpleCommandResult(false, "Execution of file '" + toFileName(command.substring(1)) +"' aborted because of an error in statement '"+ + sqlCmd.getUntrimmedCommandString()+"'...."); + } if (cancelled) { return new SimpleCommandResult(true, "Execution of file '" + toFileName(command.substring(1)) +"' aborted...."); } @@ -2160,9 +2182,15 @@ @Override public CharSequence getHelp() { return "Specify filename to execute a 'batch' command.\n"+ - "For example '@mystatements.sql' executes all statements part of the mystatements.sql file in the current directory."+ - "Note that all statements must be terminated with ';' (sql statements as well as connect statements or spool)"; + "For example '@mystatements.sql' executes all statements part of the mystatements.sql file in the current directory.\n"+ + "Statements can include all sqlshell supported commands such as spool, dump, read as well as all supported sql statements.\n\n" + + "Aborting the command stops the execution of the batch command, however there won't be an automatic rollback of successfull update/delete statements," + + "so rollback (if supported and required) has to be called by the user.\n\n" + + "You can include commands in the batch to control behaviour on errors:\n" + + "* @@continue_on_error (this is the default behaviour)\n" + + "* @@abort_on_error"; } + @Override public boolean abort() { cancelled = true; |
From: SVN by r. <sv...@ca...> - 2009-01-17 15:15:39
|
Author: roy Date: 2009-01-17 16:15:31 +0100 (Sat, 17 Jan 2009) New Revision: 355 Modified: src/main/java/nl/improved/sqlclient/SQLShell.java Log: added output result of batch command from commandline call again Modified: src/main/java/nl/improved/sqlclient/SQLShell.java =================================================================== --- src/main/java/nl/improved/sqlclient/SQLShell.java 2009-01-17 15:11:40 UTC (rev 354) +++ src/main/java/nl/improved/sqlclient/SQLShell.java 2009-01-17 15:15:31 UTC (rev 355) @@ -23,10 +23,12 @@ import java.io.PrintStream; import java.sql.SQLException; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import nl.improved.sqlclient.charva.CharvaSQLShellWindow; import nl.improved.sqlclient.commands.Command; +import nl.improved.sqlclient.commands.CommandResult; import nl.improved.sqlclient.jcurses.SQLShellWindow; @@ -99,7 +101,7 @@ }; Command cmd = new nl.improved.sqlclient.AbstractSQLShellWindow.ExecuteBatchCommand(sqlshellWindow); - cmd.execute(new SQLCommand("@"+ argsMap.get("-i"))); + CommandResult result = cmd.execute(new SQLCommand("@"+ argsMap.get("-i"))); if (argsMap.containsKey("-o")) { File f = new File(argsMap.get("-o")); FileOutputStream fout = new FileOutputStream(f); @@ -107,8 +109,16 @@ fout.write(s.toString().getBytes()); fout.write('\n'); } - //fout.write(output.toString().getBytes()); - //fout.write('\n'); + Iterator<CharSequence> iResult = result.getResult(); + while (iResult.hasNext()) { + fout.write(iResult.next().toString().getBytes()); + } + fout.write('\n'); + } else { + Iterator<CharSequence> iResult = result.getResult(); + while (iResult.hasNext()) { + System.out.println(iResult.next()); + } } } else { //sqlshellWindow = new SQLShellWindow(); |
From: SVN by r. <sv...@ca...> - 2009-01-23 16:27:33
|
Author: roy Date: 2009-01-23 17:27:25 +0100 (Fri, 23 Jan 2009) New Revision: 362 Modified: src/main/java/nl/improved/sqlclient/SQLShell.java Log: added -engine support more help information Modified: src/main/java/nl/improved/sqlclient/SQLShell.java =================================================================== --- src/main/java/nl/improved/sqlclient/SQLShell.java 2009-01-19 15:43:49 UTC (rev 361) +++ src/main/java/nl/improved/sqlclient/SQLShell.java 2009-01-23 16:27:25 UTC (rev 362) @@ -38,21 +38,78 @@ */ public class SQLShell { + public static final String INPUT = "-i"; + public static final String OUTPUT = "-o"; + public static final String ENGINE = "-engine"; + public static final String ENGINE_CHARVA = "charva"; + public static final String ENGINE_JCURSES = "jcurses"; + + public static Map<String, String> parseHelp(String[] args) throws IOException { + Map<String, String> argsMap = new HashMap<String, String>(); + if (args[0].equals("--help") || args.length %2 == 1) { + System.err.println("Usage: "); + System.err.println(" java nl.improved.sqlclient.SQLShell [-i inputfile] [-o outputfile] [-engine charva/jcurses]"); + System.exit(-1); + } + for (int i = 0; i < args.length; i+=2) { + if (args[i].equals(INPUT)) { + if (args.length < i+1) { + System.err.println("Missing filename parameter for -i argument"); + System.exit(-1); + } + File f = new File(args[i+1]); + if (!f.exists()) { + System.err.println("Filename '"+f.getAbsolutePath()+"' does not exist.\nAborting..."); + System.exit(-1); + } + if (!f.canRead()) { + System.err.println("Filename '"+f.getAbsolutePath()+"' cannot be read.\nAborting..."); + System.exit(-1); + } + argsMap.put(args[i], args[i+1]); + } else if (args[i].equals(OUTPUT)) { + if (args.length < i+1) { + System.err.println("Missing filename parameter for -i argument"); + System.exit(-1); + } + File f = new File(args[i+1]); + if (f.exists()) { + if (f.canWrite()) { + System.err.println("Filename already exists.. overwriting"); + } else { + System.err.println("Filename '"+f.getAbsolutePath()+"' cannot be written.\nAborting..."); + System.exit(-1); + } + } else if (f.createNewFile()) { + System.err.println("Filename '"+f.getAbsolutePath()+"' cannot be created.\nAborting..."); + System.exit(-1); + } + argsMap.put(args[i], args[i+1]); + } else if (args[i].equals(ENGINE)) { + if (args.length < i+1) { + System.err.println("Missing engine type parameter for -i argument."); + System.err.println("Possible values are 'jcurses' and 'charva'"); + System.exit(-1); + } + if (!(args[i+1].equals(ENGINE_CHARVA)) && !(args[i+1].equals(ENGINE_JCURSES))) { + System.err.println("Unknown parameter for engine type '"+ args[i+1]+"'"); + System.err.println("Possible values are 'jcurses' and 'charva'"); + System.exit(-1); + } + argsMap.put(args[i], args[i+1]); + } else { + System.err.println("Uknown option: "+ args[i]+"\nAborting..."); + System.exit(-1); + } + } + return argsMap; + } public static void main(String[] args) throws InterruptedException, IOException { PrintStream errorStream = System.err; PrintStream outStream = System.out; - 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: "); - System.exit(-1); - } - for (int i = 0; i < args.length; i+=2) { - argsMap.put(args[i], args[i+1]); - } - } + final Map<String, String> argsMap = parseHelp(args); AbstractSQLShellWindow sqlshellWindow; - if (argsMap.get("-i") != null) { + if (argsMap.get(INPUT) != null) { sqlshellWindow = new AbstractSQLShellWindow() { @Override public int getScreenWidth() { @@ -93,7 +150,7 @@ @Override protected void output(CharSequence data) { - if (!argsMap.containsKey("-o")) { + if (!argsMap.containsKey(OUTPUT)) { System.out.println(data); } } @@ -102,8 +159,8 @@ }; Command cmd = new nl.improved.sqlclient.AbstractSQLShellWindow.ExecuteBatchCommand(sqlshellWindow); CommandResult result = cmd.execute(new SQLCommand("@"+ argsMap.get("-i"))); - if (argsMap.containsKey("-o")) { - File f = new File(argsMap.get("-o")); + if (argsMap.containsKey(OUTPUT)) { + File f = new File(argsMap.get(OUTPUT)); FileOutputStream fout = new FileOutputStream(f); for (CharSequence s : sqlshellWindow.getScreen().getScreenBuffer()) { fout.write(s.toString().getBytes()); @@ -122,9 +179,19 @@ } } else { //sqlshellWindow = new SQLShellWindow(); - try { - sqlshellWindow = new CharvaSQLShellWindow(); - } catch(Error e) { + if (!argsMap.containsKey(ENGINE) || argsMap.get(ENGINE).equals(ENGINE_CHARVA)) { + try { + sqlshellWindow = new CharvaSQLShellWindow(); + } catch(Error e) { + if (!argsMap.containsKey(ENGINE)) { + sqlshellWindow = new SQLShellWindow(); + } else { + System.err.println("Failed to instantiate charva version of sqlshell.\nCaused by: "+ e); + e.printStackTrace(); + return; + } + } + } else { sqlshellWindow = new SQLShellWindow(); } } |
From: SVN by r. <sv...@ca...> - 2009-01-23 16:28:04
|
Author: roy Date: 2009-01-23 17:27:51 +0100 (Fri, 23 Jan 2009) New Revision: 364 Modified: src/main/java/nl/improved/sqlclient/QueryExecutor.java Log: code cleanup Modified: src/main/java/nl/improved/sqlclient/QueryExecutor.java =================================================================== --- src/main/java/nl/improved/sqlclient/QueryExecutor.java 2009-01-23 16:27:40 UTC (rev 363) +++ src/main/java/nl/improved/sqlclient/QueryExecutor.java 2009-01-23 16:27:51 UTC (rev 364) @@ -167,12 +167,10 @@ //StringBuffer displayValue = new StringBuffer(); ResultSetMetaData metadata = results.getMetaData(); - long start = System.currentTimeMillis(); // TODO specify labels List<String> labels = new ArrayList<String>(); for ( int col = 1; col <= metadata.getColumnCount(); col++) { - StringBuffer labelBuffer = new StringBuffer(); labels.add(metadata.getColumnLabel(col)); } |
From: SVN by r. <sv...@ca...> - 2009-01-25 13:58:47
|
Author: roy Date: 2009-01-25 14:58:39 +0100 (Sun, 25 Jan 2009) New Revision: 365 Modified: src/main/java/nl/improved/sqlclient/SQLShell.java Log: fix parse error in parsehelp when no arguments provided Modified: src/main/java/nl/improved/sqlclient/SQLShell.java =================================================================== --- src/main/java/nl/improved/sqlclient/SQLShell.java 2009-01-23 16:27:51 UTC (rev 364) +++ src/main/java/nl/improved/sqlclient/SQLShell.java 2009-01-25 13:58:39 UTC (rev 365) @@ -46,6 +46,9 @@ public static Map<String, String> parseHelp(String[] args) throws IOException { Map<String, String> argsMap = new HashMap<String, String>(); + if (args.length == 0) { + return argsMap; + } if (args[0].equals("--help") || args.length %2 == 1) { System.err.println("Usage: "); System.err.println(" java nl.improved.sqlclient.SQLShell [-i inputfile] [-o outputfile] [-engine charva/jcurses]"); |
From: SVN by r. <sv...@ca...> - 2009-02-20 20:45:32
|
Author: roy Date: 2009-02-20 21:45:25 +0100 (Fri, 20 Feb 2009) New Revision: 374 Modified: src/main/java/nl/improved/sqlclient/SQLProperties.java Log: make sure the config dir exists Modified: src/main/java/nl/improved/sqlclient/SQLProperties.java =================================================================== --- src/main/java/nl/improved/sqlclient/SQLProperties.java 2009-02-18 22:19:47 UTC (rev 373) +++ src/main/java/nl/improved/sqlclient/SQLProperties.java 2009-02-20 20:45:25 UTC (rev 374) @@ -89,6 +89,8 @@ defaultProps.put(key, currentProps.getProperty((String)key)); } } + File f = getPropertyFile(); + f.getParentFile().mkdirs(); defaultProps.save(new FileOutputStream(getPropertyFile()), "SQLShell properties file"); } } |
From: SVN by r. <sv...@ca...> - 2009-03-01 16:55:15
|
Author: roy Date: 2009-03-01 17:55:05 +0100 (Sun, 01 Mar 2009) New Revision: 389 Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java Log: fixed npe when cancelling login Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java =================================================================== --- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2009-03-01 16:46:31 UTC (rev 388) +++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2009-03-01 16:55:05 UTC (rev 389) @@ -1315,6 +1315,9 @@ password = predefinedSettings.getPassword(); } String[] credentials = getLoginCredentials(username, password); + if (credentials == null) { + return null; + } username = credentials[0]; password = credentials[1]; } |