|
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;
|