classes/phing/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.

Extends from
\CreoleTask
author
Hans Lellelid (Phing)
author
Jeff Martin (Ant)
author
Michael McCallum (Ant)
author
Tim Stephenson (Ant)
copyright
2001,2002 THYRELL. All rights reserved
package
phing.tasks.ext.creole
version
$Revision: 1084 $

Constants

Constant  DELIM_ROW = 'row'
Constant  DELIM_NORMAL = 'normal'

Properties

Propertyprivate  $append= 'false'

Append to an existing file or overwrite it?

Default valuefalseDetails
Type
Propertyprivate  $conn= 'null'

Database connection

Default valuenullDetails
Type
Propertyprivate  $delimiter= ';'

SQL Statement delimiter

Default value;Details
Type
Propertyprivate  $delimiterType= 'normal'

The delimiter type indicating whether the delimiter will only be recognized on a line by itself

Default valuenormalDetails
Type
Propertyprivate  $encoding= 'null'

Encoding to use when reading SQL statements from a file

Default valuenullDetails
Type
Propertyprivate  $filesets= 'array'

files to load

Default valuearrayDetails
Type
Propertyprivate  $filterChains= 'array'

all filterchains objects assigned to this task

Default valuearrayDetails
Type
Propertyprivate  $goodSql= '0'
Default value0Details
Type
Propertyprivate  $onError= 'abort'

Action to perform if an error is found

Default valueabortDetails
Type
Propertyprivate  $output= 'null'

Results Output file.

Default valuenullDetails
Type
Propertyprivate  $print= 'false'

Print SQL results.

Default valuefalseDetails
Type
Propertyprivate  $showheaders= 'true'

Print header columns.

Default valuetrueDetails
Type
Propertyprivate  $sqlCommand= ''

SQL input command

Details
Type
Propertyprivate  $srcFile= 'null'

SQL input file

Default valuenullDetails
Type
Propertyprivate  $statement= 'null'

SQL statement

Default valuenullDetails
Type
Propertyprivate  $totalSql= '0'
Default value0Details
Type
Propertyprivate  $transactions= 'array'

SQL transactions to perform

Default valuearrayDetails
Type

Methods

methodpublic  addFileset(  $set ) :
Adds a set of files (nested fileset attribute).
Parameters
Name Type Description
$set
methodpublic  addText(  $sql ) :
Set an inline SQL command to execute.

NB: Properties are not expanded in this text.

Parameters
Name Type Description
$sql
methodpublic  createFilterChain( ) : object
Creates a filterchain
Returns
Type Description
object
Details
access
public
methodpublic  createTransaction( ) :
Add a SQL transaction to execute
methodprotected  execSQL(  $sql,  $out = null ) :
Exec the sql statement.
Parameters
Name Type Description
$sql
$out
Details
throws
methodpublic  main( ) :
Load the sql file and then execute it
Details
throws
methodprotected  printResults(  $out = null ) :
print any results in the statement.
Parameters
Name Type Description
$out
Details
throws
methodpublic  runStatements(  $reader,  $out = null ) :
read in lines and execute them
Parameters
Name Type Description
$reader
$out
Details
throws
IOException
methodpublic  setAppend(  $append ) :
whether output should be appended to or overwrite an existing file. Defaults to false.
Parameters
Name Type Description
$append
methodpublic  setDelimiter(  $delimiter ) :
Set the statement delimiter.

For example, set this to "go" and delimitertype to "ROW" for Sybase ASE or MS SQL Server.

Parameters
Name Type Description
$delimiter delimiter
methodpublic  setDelimiterType( string $delimiterType ) :
Set 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.
Parameters
Name Type Description
$delimiterType string
methodpublic  setEncoding( \encoding $encoding ) :
Set the file encoding to use on the SQL files read in
Parameters
Name Type Description
$encoding \encoding the encoding to use on the files
methodpublic  setOnerror(  $action ) :
Action to perform when statement fails: continue, stop, or abort optional; default "abort"
Parameters
Name Type Description
$action
methodpublic  setOutput( \PhingFile $output ) :
Set the output file; optional, defaults to the console.
Parameters
Name Type Description
$output \PhingFile
methodpublic  setPrint( boolean $print ) :
Set the print flag.
Parameters
Name Type Description
$print boolean
methodpublic  setShowheaders( boolean $showheaders ) :
Print headers for result sets from the statements; optional, default true.
Parameters
Name Type Description
$showheaders boolean
methodpublic  setSrc(  $srcFile ) :
Set the name of the SQL file to be run.

Required unless statements are enclosed in the build file

Parameters
Name Type Description
$srcFile

\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.

package
phing.tasks.ext.creole

Properties

Propertyprivate  $parent= ''
Details
Type
Propertyprivate  $tSqlCommand= ''
Details
Type
Propertyprivate  $tSrcFile= 'null'
Default valuenullDetails
Type

Methods

methodpublic  __construct(  $parent ) :
Parameters
Name Type Description
$parent
methodpublic  addText(  $sql ) :
Parameters
Name Type Description
$sql
methodpublic  runTransaction(  $out = null ) :
Parameters
Name Type Description
$out
Details
throws
SQLException
methodpublic  setSrc(  $src ) :
Parameters
Name Type Description
$src
Documentation was generated by DocBlox 0.13.1.