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.
| Modifier and Type | Class and Description |
|---|---|
| public static class | SQLExec.DelimiterType
delimiters we support, "normal" and "row" |
| public static class | SQLExec.OnError
The action a task should perform on an error, one of "continue", "stop" and "abort" |
| public class | SQLExec.Transaction
Contains the definition of a new transaction element. |
| Modifier and Type | Field and Description |
|---|---|
| private boolean | append
Append to an existing file or overwrite it? |
| private Connection | conn
Database connection |
| private String | csvColumnSep
The column separator used when printing the results. |
| private String | csvQuoteChar
The character used to quote column values. |
| private String | delimiter
SQL Statement delimiter |
| private String | delimiterType
The delimiter type indicating whether the delimiter will only be recognized on a line by itself |
| private String | encoding
Encoding to use when reading SQL statements from a file |
| private String | errorProperty
The name of the property to set in the event of an error |
| private boolean | escapeProcessing
Argument to Statement.setEscapeProcessing |
| private boolean | expandProperties
should properties be expanded in text? |
| private boolean | forceCsvQuoteChar
The name of the property to force the csv quote character |
| private int | |
| private boolean | keepformat
Keep the format of a sql block? |
| private String | onError
Action to perform if an error is found |
| private Resource | output
Results Output Resource. |
| private String | outputEncoding
Output encoding. |
| private boolean | print
Print SQL results. |
| private boolean | rawBlobs
should we print raw BLOB data? |
| private Union | resources
files to load |
| private String | rowCountProperty
The name of the property that receives the number of rows returned |
| private boolean | showheaders
Print header columns. |
| private boolean | showtrailers
Print SQL stats (rows affected) |
| private boolean | showWarnings
whether to show SQLWarnings as WARN messages. |
| private String | sqlCommand
SQL input command |
| private File | srcFile
SQL input file |
| private Statement | statement
SQL statement |
| private boolean | strictDelimiterMatching
delimiters must match in case and whitespace is significant. |
| private int | |
| private List | transactions
SQL transactions to perform |
| private boolean | treatWarningsAsErrors
Whether a warning is an error - in which case onError applies. |
| private String | warningProperty
The name of the property to set in the event of a warning |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | add(ResourceCollection
a collection of resources containing SQL commands,
each resource is run in a separate transaction. rc)Adds a collection of resources (nested element). |
| public void | addFileset(FileSet
a set of files contains SQL commands, each File is run in
a separate transaction. set)Adds a set of files (nested fileset attribute). |
| public void | |
| private void | |
| public SQLExec. | |
| protected void | execSQL(String
the SQL statement to execute sql, PrintStream the place to put output out)Exec the sql statement. |
| public void | |
| protected Connection | getConnection()
Overrides org. |
| public boolean | Returns: true if properties are to be expanded.is property expansion inside inline text enabled? |
| protected Statement | Returns: StatementCreates and configures a Statement instance which is then cached for subsequent calls. |
| public int | |
| private String | |
| protected void | printResults(PrintStream
the place to print results out)
Deprecated
since 1.6.x.
Use
print any results in the statement
the two arg version instead.
|
| protected void | printResults(ResultSet
the resultset to print information about rs, PrintStream the place to print results out)print any results in the result set. |
| private void | |
| private void | |
| protected void | runStatements(Reader
the reader contains sql lines. reader, PrintStream the place to output results. out)read in lines and execute them |
| public void | setAppend(boolean
if true append to an existing file. append)whether output should be appended to or overwrite an existing file. |
| public void | |
| public void | |
| public void | |
| public void | setDelimiterType(SQLExec.
the type of delimiter - "normal" or "row". delimiterTypeSet the delimiter type: "normal" or "row" (default "normal"). |
| public void | setEncoding(String
the encoding to use on the files encoding)Set the file encoding to use on the SQL files read in |
| public void | setErrorProperty(String
the name of the property to set in the
event of an error. errorProperty)Property to set to "true" if a statement throws an error. |
| protected final void | |
| public void | setEscapeProcessing(boolean
if true enable escape processing, default is true. enable)Set escape processing for statements. |
| public void | setExpandProperties(boolean
if true expand properties. expandProperties)Enable property expansion inside nested text |
| public void | |
| public void | |
| public void | setOnerror(SQLExec.
the action to perform on statement failure. actionAction to perform when statement fails: continue, stop, or abort optional; default "abort" |
| public void | |
| public void | |
| public void | setOutputEncoding(String
the name of the encoding or null for the
platform's default encoding outputEncoding)The encoding to use when writing the result to a resource. |
| public void | setPrint(boolean
if true print result sets. print)Print result sets from the statements; optional, default false |
| private void | |
| public void | setRawBlobs(boolean
whether to print raw BLOBs. rawBlobs)Set whether to print raw BLOBs rather than their string (hex) representations. |
| public void | setRowCountProperty(String
String rowCountProperty)Sets a given property to the number of rows in the first statement that returned a row count. |
| protected final void | |
| public void | setShowheaders(boolean
if true print headers of result sets. showheaders)Print headers for result sets from the statements; optional, default true. |
| public void | setShowtrailers(boolean
if true prints the SQL rows affected showtrailers)Print trailing info (rows affected) for the SQL Addresses Bug/Request #27446 |
| public void | |
| public void | |
| public void | setStrictDelimiterMatching(boolean
boolean b)If false, delimiters will be searched for in a case-insensitive manner (i.e. delimiter="go" matches "GO") and surrounding whitespace will be ignored (delimiter="go" matches "GO "). |
| public void | setTreatWarningsAsErrors(boolean
boolean b)Whether a warning is an error - in which case onError applies. |
| public void | setWarningProperty(String
the name of the property to set in the
event of a warning. warningProperty)Property to set to "true" if a statement produces a warning. |
| protected final void |
| append | back to summary |
|---|---|
| private boolean append Append to an existing file or overwrite it? | |
| conn | back to summary |
|---|---|
| private Connection conn Database connection | |
| csvColumnSep | back to summary |
|---|---|
| private String csvColumnSep The column separator used when printing the results. Defaults to ","
| |
| csvQuoteChar | back to summary |
|---|---|
| private String csvQuoteChar The character used to quote column values. If set, columns that contain either the column separator or the quote character itself will be surrounded by the quote character. The quote character itself will be doubled if it appears inside of the column's value. If this value is not set (the default), no column values will be quoted, not even if they contain the column separator. Note: BLOB values will never be quoted. Defaults to "not set"
| |
| delimiter | back to summary |
|---|---|
| private String delimiter SQL Statement delimiter | |
| delimiterType | back to summary |
|---|---|
| private String delimiterType The delimiter type indicating whether the delimiter will only be recognized on a line by itself | |
| encoding | back to summary |
|---|---|
| private String encoding Encoding to use when reading SQL statements from a file | |
| errorProperty | back to summary |
|---|---|
| private String errorProperty The name of the property to set in the event of an error
| |
| escapeProcessing | back to summary |
|---|---|
| private boolean escapeProcessing Argument to Statement.setEscapeProcessing
| |
| expandProperties | back to summary |
|---|---|
| private boolean expandProperties should properties be expanded in text? false for backwards compatibility
| |
| forceCsvQuoteChar | back to summary |
|---|---|
| private boolean forceCsvQuoteChar The name of the property to force the csv quote character | |
| goodSql | back to summary |
|---|---|
| private int goodSql | |
| keepformat | back to summary |
|---|---|
| private boolean keepformat Keep the format of a sql block? | |
| onError | back to summary |
|---|---|
| private String onError Action to perform if an error is found | |
| output | back to summary |
|---|---|
| private Resource output Results Output Resource. | |
| outputEncoding | back to summary |
|---|---|
| private String outputEncoding Output encoding. | |
| back to summary | |
|---|---|
| private boolean print Print SQL results. | |
| rawBlobs | back to summary |
|---|---|
| private boolean rawBlobs should we print raw BLOB data?
| |
| resources | back to summary |
|---|---|
| private Union resources files to load | |
| rowCountProperty | back to summary |
|---|---|
| private String rowCountProperty The name of the property that receives the number of rows returned
| |
| showheaders | back to summary |
|---|---|
| private boolean showheaders Print header columns. | |
| showtrailers | back to summary |
|---|---|
| private boolean showtrailers Print SQL stats (rows affected) | |
| showWarnings | back to summary |
|---|---|
| private boolean showWarnings whether to show SQLWarnings as WARN messages.
| |
| sqlCommand | back to summary |
|---|---|
| private String sqlCommand SQL input command | |
| srcFile | back to summary |
|---|---|
| private File srcFile SQL input file | |
| statement | back to summary |
|---|---|
| private Statement statement SQL statement | |
| strictDelimiterMatching | back to summary |
|---|---|
| private boolean strictDelimiterMatching delimiters must match in case and whitespace is significant.
| |
| totalSql | back to summary |
|---|---|
| private int totalSql | |
| transactions | back to summary |
|---|---|
| private List<SQLExec. SQL transactions to perform | |
| treatWarningsAsErrors | back to summary |
|---|---|
| private boolean treatWarningsAsErrors Whether a warning is an error - in which case onError applies.
| |
| warningProperty | back to summary |
|---|---|
| private String warningProperty The name of the property to set in the event of a warning
| |
| SQLExec | back to summary |
|---|---|
| public SQLExec() | |
| add | back to summary |
|---|---|
| public void add(ResourceCollection rc) Adds a collection of resources (nested element).
| |
| addFileset | back to summary |
|---|---|
| public void addFileset(FileSet set) Adds a set of files (nested fileset attribute).
| |
| addText | back to summary |
|---|---|
| public void addText(String sql) Set an inline SQL command to execute.
NB: Properties are not expanded in this text unless
| |
| closeQuietly | back to summary |
|---|---|
| private void closeQuietly() | |
| createTransaction | back to summary |
|---|---|
| public SQLExec. Add a SQL transaction to execute
| |
| execSQL | back to summary |
|---|---|
| protected void execSQL(String sql, PrintStream out) throws SQLException Exec the sql statement.
| |
| execute | back to summary |
|---|---|
| public void execute() throws BuildException Overrides org. Load the sql file and then execute it
| |
| getConnection | back to summary |
|---|---|
| protected Connection getConnection() Overrides org. Caches the connection returned by the base class's getConnection method. Subclasses that need to provide a different connection than the base class would, should override this method but keep in mind that this class expects to get the same connection instance on consecutive calls. returns null if the connection does not connect to the expected RDBMS.
| |
| getExpandProperties | back to summary |
|---|---|
| public boolean getExpandProperties() is property expansion inside inline text enabled?
| |
| getStatement | back to summary |
|---|---|
| protected Statement getStatement() throws SQLException Creates and configures a Statement instance which is then cached for subsequent calls. Subclasses that want to provide different Statement instances, should override this method but keep in mind that this class expects to get the same connection instance on consecutive calls.
| |
| lastDelimiterPosition | back to summary |
|---|---|
| public int lastDelimiterPosition(StringBuffer buf, String currentLine) | |
| maybeQuote | back to summary |
|---|---|
| private String maybeQuote(String s) | |
| printResults | back to summary |
|---|---|
| protected void printResults(PrintStream out) throws SQLException
Deprecated since 1.6.x.
Use print any results in the statement
| |
| printResults | back to summary |
|---|---|
| protected void printResults(ResultSet rs, PrintStream out) throws SQLException print any results in the result set.
| |
| printValue | back to summary |
|---|---|
| private void printValue(ResultSet rs, int col, PrintStream out) throws SQLException | |
| printWarnings | back to summary |
|---|---|
| private void printWarnings(SQLWarning warning, boolean force) throws SQLException | |
| runStatements | back to summary |
|---|---|
| protected void runStatements(Reader reader, PrintStream out) throws SQLException, IOException read in lines and execute them
| |
| setAppend | back to summary |
|---|---|
| public void setAppend(boolean append) whether output should be appended to or overwrite an existing file. Defaults to false.
| |
| setCsvColumnSeparator | back to summary |
|---|---|
| public void setCsvColumnSeparator(String s) The column separator used when printing the results. Defaults to ","
| |
| setCsvQuoteCharacter | back to summary |
|---|---|
| public void setCsvQuoteCharacter(String s) The character used to quote column values. If set, columns that contain either the column separator or the quote character itself will be surrounded by the quote character. The quote character itself will be doubled if it appears inside of the column's value. If this value is not set (the default), no column values will be quoted, not even if they contain the column separator. Note BLOB values will never be quoted. Defaults to "not set"
| |
| setDelimiter | back to summary |
|---|---|
| public void setDelimiter(String delimiter) Set the delimiter that separates SQL statements. Defaults to ";"; optional For example, set this to "go" and delimitertype to "ROW" for Sybase ASE or MS SQL Server.
| |
| setDelimiterType | back to summary |
|---|---|
| public void setDelimiterType(SQLExec. Set the delimiter type: "normal" or "row" (default "normal"). 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.
| |
| setEncoding | back to summary |
|---|---|
| public void setEncoding(String encoding) Set the file encoding to use on the SQL files read in
| |
| setErrorProperty | back to summary |
|---|---|
| public void setErrorProperty(String errorProperty) Property to set to "true" if a statement throws an error.
| |
| setErrorProperty | back to summary |
|---|---|
| protected final void setErrorProperty() | |
| setEscapeProcessing | back to summary |
|---|---|
| public void setEscapeProcessing(boolean enable) Set escape processing for statements.
| |
| setExpandProperties | back to summary |
|---|---|
| public void setExpandProperties(boolean expandProperties) Enable property expansion inside nested text
| |
| setForceCsvQuoteChar | back to summary |
|---|---|
| public void setForceCsvQuoteChar(boolean forceCsvQuoteChar) Force the csv quote character
| |
| setKeepformat | back to summary |
|---|---|
| public void setKeepformat(boolean keepformat) whether or not format should be preserved. Defaults to false.
| |
| setOnerror | back to summary |
|---|---|
| public void setOnerror(SQLExec. Action to perform when statement fails: continue, stop, or abort optional; default "abort" | |
| setOutput | back to summary |
|---|---|
| public void setOutput(File output) Set the output file; optional, defaults to the Ant log.
| |
| setOutput | back to summary |
|---|---|
| public void setOutput(Resource output) Set the output Resource; optional, defaults to the Ant log.
| |
| setOutputEncoding | back to summary |
|---|---|
| public void setOutputEncoding(String outputEncoding) The encoding to use when writing the result to a resource. Default's to the platform's default encoding
| |
| setPrint | back to summary |
|---|---|
| public void setPrint(boolean print) Print result sets from the statements; optional, default false
| |
| setProperty | back to summary |
|---|---|
| private void setProperty(String name, String value) | |
| setRawBlobs | back to summary |
|---|---|
| public void setRawBlobs(boolean rawBlobs) Set whether to print raw BLOBs rather than their string (hex) representations.
| |
| setRowCountProperty | back to summary |
|---|---|
| public void setRowCountProperty(String rowCountProperty) Sets a given property to the number of rows in the first statement that returned a row count.
| |
| setRowCountProperty | back to summary |
|---|---|
| protected final void setRowCountProperty(int rowCount) | |
| setShowheaders | back to summary |
|---|---|
| public void setShowheaders(boolean showheaders) Print headers for result sets from the statements; optional, default true.
| |
| setShowtrailers | back to summary |
|---|---|
| public void setShowtrailers(boolean showtrailers) Print trailing info (rows affected) for the SQL Addresses Bug/Request #27446
| |
| setShowWarnings | back to summary |
|---|---|
| public void setShowWarnings(boolean b) whether to show SQLWarnings as WARN messages.
| |
| setSrc | back to summary |
|---|---|
| public void setSrc(File srcFile) Set the name of the SQL file to be run. Required unless statements are enclosed in the build file
| |
| setStrictDelimiterMatching | back to summary |
|---|---|
| public void setStrictDelimiterMatching(boolean b) If false, delimiters will be searched for in a case-insensitive manner (i.e. delimiter="go" matches "GO") and surrounding whitespace will be ignored (delimiter="go" matches "GO ").
| |
| setTreatWarningsAsErrors | back to summary |
|---|---|
| public void setTreatWarningsAsErrors(boolean b) Whether a warning is an error - in which case onError applies.
| |
| setWarningProperty | back to summary |
|---|---|
| public void setWarningProperty(String warningProperty) Property to set to "true" if a statement produces a warning.
| |
| setWarningProperty | back to summary |
|---|---|
| protected final void setWarningProperty() | |
| Modifier and Type | Field and Description |
|---|---|
| public static final String | NORMAL
The enumerated strings |
| public static final String | ROW
The enumerated strings |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public String[] | Returns: the enumerated stringsImplements abstract org. |
| NORMAL | back to summary |
|---|---|
| public static final String NORMAL The enumerated strings | |
| ROW | back to summary |
|---|---|
| public static final String ROW The enumerated strings | |
| DelimiterType | back to summary |
|---|---|
| public DelimiterType() | |
| getValues | back to summary |
|---|---|
| public String[] getValues() Implements abstract org. Doc from org. This is the only method a subclass needs to implement. | |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public String[] | Returns: the enumerated valuesImplements abstract org. |
| OnError | back to summary |
|---|---|
| public OnError() | |
| getValues | back to summary |
|---|---|
| public String[] getValues() Implements abstract org. Doc from org. This is the only method a subclass needs to implement. | |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public void | |
| private void | |
| public void | |
| public void |
| tSqlCommand | back to summary |
|---|---|
| private String tSqlCommand | |
| tSrcResource | back to summary |
|---|---|
| private Resource tSrcResource | |
| Transaction | back to summary |
|---|---|
| public Transaction() | |
| addConfigured | back to summary |
|---|---|
| public void addConfigured(ResourceCollection a) Set the source resource.
| |
| addText | back to summary |
|---|---|
| public void addText(String sql) Set inline text
| |
| runTransaction | back to summary |
|---|---|
| private void runTransaction(PrintStream out) throws IOException, SQLException | |
| setSrc | back to summary |
|---|---|
| public void setSrc(File src) Set the source file attribute.
| |
| setSrcResource | back to summary |
|---|---|
| public void setSrcResource(Resource src) Set the source resource attribute.
| |