org.apache.tools.ant.taskdefs
public class SQLExec extends JDBCTask
Statements can either be read in from a text file using the src attribute or from between the enclosing SQL tags.
Multiple statements can be provided, separated by semicolons (or the defined delimiter). Individual lines within the statements can be commented using either --, // or REM at the start of the line.
The autocommit attribute specifies whether auto-commit should be turned on or off whilst executing the statements. If auto-commit is turned on each statement will be executed and committed. If it is turned off the statements will all be executed as one transaction.
The onerror attribute specifies how to proceed when an error occurs during the execution of one of the statements. The possible values are: continue execution, only show the error; stop execution and commit transaction; and abort execution and transaction and fail task.
Since: Ant 1.2
UNKNOWN: name="sql" category="database"
Nested Class Summary | |
---|---|
static class | SQLExec.DelimiterType
delimiters we support, "normal" and "row" |
static class | SQLExec.OnError
The action a task should perform on an error,
one of "continue", "stop" and "abort" |
class | SQLExec.Transaction
Contains the definition of a new transaction element.
|
Method Summary | |
---|---|
void | add(ResourceCollection rc)
Adds a collection of resources (nested element). |
void | addFileset(FileSet set)
Adds a set of files (nested fileset attribute). |
void | addText(String sql)
Set an inline SQL command to execute.
|
SQLExec.Transaction | createTransaction()
Add a SQL transaction to execute |
protected void | execSQL(String sql, PrintStream out)
Exec the sql statement. |
void | execute()
Load the sql file and then execute it |
boolean | getExpandProperties()
is property expansion inside inline text enabled?
|
protected void | printResults(PrintStream out)
print any results in the statement |
protected void | printResults(ResultSet rs, PrintStream out)
print any results in the result set. |
protected void | runStatements(Reader reader, PrintStream out)
read in lines and execute them |
void | setAppend(boolean append)
whether output should be appended to or overwrite
an existing file. |
void | setDelimiter(String delimiter)
Set the delimiter that separates SQL statements. |
void | setDelimiterType(SQLExec.DelimiterType delimiterType)
Set the delimiter type: "normal" or "row" (default "normal").
|
void | setEncoding(String encoding)
Set the file encoding to use on the SQL files read in
|
void | setEscapeProcessing(boolean enable)
Set escape processing for statements. |
void | setExpandProperties(boolean expandProperties)
Enable property expansion inside nested text
|
void | setKeepformat(boolean keepformat)
whether or not format should be preserved.
|
void | setOnerror(SQLExec.OnError action)
Action to perform when statement fails: continue, stop, or abort
optional; default "abort" |
void | setOutput(File output)
Set the output file;
optional, defaults to the Ant log. |
void | setPrint(boolean print)
Print result sets from the statements;
optional, default false |
void | setShowheaders(boolean showheaders)
Print headers for result sets from the
statements; optional, default true. |
void | setShowtrailers(boolean showtrailers)
Print trailing info (rows affected) for the SQL
Addresses Bug/Request #27446 |
void | setSrc(File srcFile)
Set the name of the SQL file to be run.
|
Parameters: rc a collection of resources containing SQL commands, each resource is run in a separate transaction.
Since: Ant 1.7
Parameters: set a set of files contains SQL commands, each File is run in a separate transaction.
Parameters: sql an inline string containing the SQL command.
Returns: a Transaction to be configured.
Parameters: sql the SQL statement to execute out the place to put output
Throws: SQLException on SQL problems
Throws: BuildException on error.
Returns: true if properties are to be expanded.
Since: Ant 1.7
Deprecated: since 1.6.x.
Use
the two arg version
instead.
Parameters: out the place to print results
Throws: SQLException on SQL problems.
Parameters: rs the resultset to print information about out the place to print results
Throws: SQLException on SQL problems.
Since: Ant 1.6.3
Parameters: reader the reader contains sql lines. out the place to output results.
Throws: SQLException on sql problems IOException on io problems
Parameters: append if true append to an existing file.
Since: Ant 1.5
For example, set this to "go" and delimitertype to "ROW" for Sybase ASE or MS SQL Server.
Parameters: delimiter the separator.
The delimiter type takes two values - normal and row. Normal means that any occurrence of the delimiter terminate the SQL command whereas with row, only a line containing just the delimiter is recognized as the end of the command.
Parameters: delimiterType the type of delimiter - "normal" or "row".
Parameters: encoding the encoding to use on the files
Parameters: enable if true enable escape processing, default is true.
Since: Ant 1.6
Parameters: expandProperties if true expand properties.
Since: Ant 1.7
Parameters: keepformat The keepformat to set
Parameters: action the action to perform on statement failure.
Parameters: output the output file to use for logging messages.
Parameters: print if true print result sets.
Parameters: showheaders if true print headers of result sets.
Parameters: showtrailers if true prints the SQL rows affected
Since: Ant 1.7
Parameters: srcFile the file containing the SQL command.