tasks/ext/creole/CreoleSQLExecTask.php
\CreoleSQLExecTask
Executes a series of SQL statements on a database using Creole.
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.
- Parent(s)
- \CreoleTask < \Task < \ProjectComponent
- Author
- Hans Lellelid
(Phing) - Author
- Jeff Martin
(Ant) - Author
- Michael McCallum
(Ant) - Author
- Tim Stephenson
(Ant) - Version
- $Revision: 1084 $
Constants
Properties

$caching= 'true'
trueDetails- Type
- n/a
- Inherited_from
- \CreoleTask::$$caching

$delimiterType= '"normal"'
The delimiter type indicating whether the delimiter will only be recognized on a line by itself
"normal"Details- Type
- n/a

$encoding= 'null'
Encoding to use when reading SQL statements from a file
nullDetails- Type
- n/a

$filterChains= 'array()'
all filterchains objects assigned to this task
array()Details- Type
- n/a

$loaderMap= 'array()'
Used for caching loaders / driver. This is to avoid getting an OutOfMemoryError when calling this task multiple times in a row.
Inherited from: \CreoleTask::$$loaderMapMethods

addFileset(
$set
)
:
voidAdds a set of files (nested fileset attribute).
| Name | Type | Description |
|---|---|---|
| $set |

addText(
$sql
)
:
voidSet an inline SQL command to execute.
NB: Properties are not expanded in this text.
| Name | Type | Description |
|---|---|---|
| $sql |

createFilterChain(
)
:
objectCreates a filterchain
| Type | Description |
|---|---|
| object | The created filterchain object |
- Access
- public

execSQL(
$sql, $out
=
null
)
:
voidExec the sql statement.
| Name | Type | Description |
|---|---|---|
| $sql | ||
| $out |
| Exception | Description |
|---|---|
| \SQLException |

getConnection(
)
:
\ConnectionCreates a new Connection as using the driver, url, userid and password specified.
Inherited from: \CreoleTask::getConnection()The calling method is responsible for closing the connection.
| Type | Description |
|---|---|
| \Connection | the newly created connection. |
| Exception | Description |
|---|---|
| \BuildException | if the UserId/Password/Url is not set or there is no suitable driver or the driver fails to load. |

getRuntimeConfigurableWrapper(
)
:
void
init(
)
:
void
This method includes any necessary Creole libraries and triggers appropriate error if they cannot be found. This is not done in header because we may want this class to be loaded w/o triggering an error.

isCaching(
$value
)
:
void| Name | Type | Description |
|---|---|---|
| $value |

printResults(
$out
=
null
)
:
voidprint any results in the statement.
| Name | Type | Description |
|---|---|---|
| $out |
| Exception | Description |
|---|---|
| \SQLException |

runStatements(
$reader, $out
=
null
)
:
voidread in lines and execute them
| Name | Type | Description |
|---|---|---|
| $reader | ||
| $out |
| Exception | Description |
|---|---|
| \SQLException, | IOException |

setAppend(
$append
)
:
voidwhether output should be appended to or overwrite an existing file. Defaults to false.
| Name | Type | Description |
|---|---|---|
| $append |

setAutocommit(
\autocommit $autocommit
)
:
voidAuto commit flag for database connection; optional, default false.
Inherited from: \CreoleTask::setAutocommit()| Name | Type | Description |
|---|---|---|
| $autocommit | \autocommit | The autocommit to set |

setCaching(
$enable
)
:
voidCaching loaders / driver. This is to avoid getting an OutOfMemoryError when calling this task multiple times in a row; default: true
Inherited from: \CreoleTask::setCaching()| Name | Type | Description |
|---|---|---|
| $enable |

setDelimiter(
$delimiter
)
:
voidSet the statement delimiter.
For example, set this to "go" and delimitertype to "ROW" for Sybase ASE or MS SQL Server.
| Name | Type | Description |
|---|---|---|
| $delimiter | delimiter |

setDelimiterType(
string $delimiterType
)
:
voidSet the Delimiter type for this sql task. The delimiter type takes two values - normal and row. Normal means that any occurence 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.
| Name | Type | Description |
|---|---|---|
| $delimiterType | string |

setDriver(
string $driver
)
:
void
| Name | Type | Description |
|---|---|---|
| $driver | string | driver class name |

setEncoding(
\encoding $encoding
)
:
voidSet the file encoding to use on the SQL files read in
| Name | Type | Description |
|---|---|---|
| $encoding | \encoding | the encoding to use on the files |

setOnerror(
$action
)
:
voidAction to perform when statement fails: continue, stop, or abort optional; default "abort"
| Name | Type | Description |
|---|---|---|
| $action |

setOutput(
\PhingFile $output
)
:
voidSet the output file; optional, defaults to the console.
| Name | Type | Description |
|---|---|---|
| $output | \PhingFile |

setPassword(
\password $password
)
:
void
| Name | Type | Description |
|---|---|---|
| $password | \password | The password to set |

setPrint(
boolean $print
)
:
voidSet the print flag.
| Name | Type | Description |
|---|---|---|
| boolean |

setRuntimeConfigurableWrapper(
)
:
void
setShowheaders(
boolean $showheaders
)
:
voidPrint headers for result sets from the statements; optional, default true.
| Name | Type | Description |
|---|---|---|
| $showheaders | boolean |

setSrc(
$srcFile
)
:
voidSet the name of the SQL file to be run.
Required unless statements are enclosed in the build file
| Name | Type | Description |
|---|---|---|
| $srcFile |

setUserid(
\userId $userId
)
:
void
| Name | Type | Description |
|---|---|---|
| $userId | \userId | The userId to set |

setVersion(
\version $version
)
:
voidSets the version string, execute task only if rdbms version match; optional.
Inherited from: \CreoleTask::setVersion()| Name | Type | Description |
|---|---|---|
| $version | \version | The version to set |
\SQLExecTransaction
"Inner" class that contains the definition of a new transaction element.
Transactions allow several files or blocks of statements to be executed using the same JDBC connection and commit operation in between.