tasks/ext/creole/CreoleSQLExecTask.php

Show: inherited
Table of Contents

\CreoleSQLExecTask

Package: phing\tasks\ext\creole

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

Constant  DELIM_ROW = "row"
Constant  DELIM_NORMAL = "normal"

Properties

Propertyprivate  $append= 'false'

Append to an existing file or overwrite it?

Default valuefalseDetails
Type
n/a
Propertyprivate  $autocommit= 'false'
inherited

Autocommit flag. Default value is false

Inherited from: \CreoleTask::$$autocommit
Default valuefalseDetails
Type
n/a
Inherited_from
\CreoleTask::$$autocommit  
Propertyprivate  $caching= 'true'
inheritedInherited from: \CreoleTask::$$caching
Default valuetrueDetails
Type
n/a
Inherited_from
\CreoleTask::$$caching  
Propertyprivate  $conn= 'null'

Database connection

Default valuenullDetails
Type
n/a
Propertyprivate  $delimiter= '";"'

SQL Statement delimiter

Default value";"Details
Type
n/a
Propertyprivate  $delimiterType= '"normal"'

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

Default value"normal"Details
Type
n/a
Propertyprivate  $driver= ''
inherited

[optional] Classpath to Creole driver to use.

Inherited from: \CreoleTask::$$driver
Details
Type
n/a
Inherited_from
\CreoleTask::$$driver  
$driver

string

Propertyprivate  $encoding= 'null'

Encoding to use when reading SQL statements from a file

Default valuenullDetails
Type
n/a
Propertyprivate  $filesets= 'array()'

files to load

Default valuearray()Details
Type
n/a
Propertyprivate  $filterChains= 'array()'

all filterchains objects assigned to this task

Default valuearray()Details
Type
n/a
Propertyprivate  $goodSql= '0'
Default value0Details
Type
n/a
Propertyprivate  $loaderMap= 'array()'
staticinherited

Used for caching loaders / driver. This is to avoid getting an OutOfMemoryError when calling this task multiple times in a row.

Inherited from: \CreoleTask::$$loaderMap

NOT IMPLEMENTED YET

Default valuearray()Details
Type
n/a
Inherited_from
\CreoleTask::$$loaderMap  
Propertyprivate  $onError= '"abort"'

Action to perform if an error is found

Default value"abort"Details
Type
n/a
Propertyprivate  $output= 'null'

Results Output file.

Default valuenullDetails
Type
n/a
Propertyprivate  $password= ''
inherited

Password

Inherited from: \CreoleTask::$$password
Details
Type
n/a
Inherited_from
\CreoleTask::$$password  
Propertyprivate  $print= 'false'

Print SQL results.

Default valuefalseDetails
Type
n/a
Propertyprivate  $rdbms= ''
inherited

RDBMS Product needed for this SQL.

Inherited from: \CreoleTask::$$rdbms
Details
Type
n/a
Inherited_from
\CreoleTask::$$rdbms  
Propertyprivate  $showheaders= 'true'

Print header columns.

Default valuetrueDetails
Type
n/a
Propertyprivate  $sqlCommand= '""'

SQL input command

Default value""Details
Type
n/a
Propertyprivate  $srcFile= 'null'

SQL input file

Default valuenullDetails
Type
n/a
Propertyprivate  $statement= 'null'

SQL statement

Default valuenullDetails
Type
n/a
Propertyprivate  $totalSql= '0'
Default value0Details
Type
n/a
Propertyprivate  $transactions= 'array()'

SQL transactions to perform

Default valuearray()Details
Type
n/a
Propertyprivate  $url= ''
inherited

DB url.

Inherited from: \CreoleTask::$$url
Details
Type
n/a
Inherited_from
\CreoleTask::$$url  
Propertyprivate  $userId= ''
inherited

User name.

Inherited from: \CreoleTask::$$userId
Details
Type
n/a
Inherited_from
\CreoleTask::$$userId  

Methods

methodpublicaddFileset(  $set ) : void

Adds a set of files (nested fileset attribute).

Parameters
Name Type Description
$set
methodpublicaddText(  $sql ) : void

Set an inline SQL command to execute.

NB: Properties are not expanded in this text.

Parameters
Name Type Description
$sql
methodpubliccreateFilterChain( ) : object

Creates a filterchain

Returns
Type Description
object The created filterchain object
Details
Access
public  
methodpubliccreateTransaction( ) : void

Add a SQL transaction to execute

methodprotectedexecSQL(  $sql,  $out = null ) : void

Exec the sql statement.

Parameters
Name Type Description
$sql
$out
Throws
Exception Description
\SQLException
methodprotectedgetConnection( ) : \Connection
inherited

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

Returns
Type Description
\Connection the newly created connection.
Throws
Exception Description
\BuildException if the UserId/Password/Url is not set or there is no suitable driver or the driver fails to load.
methodpublicgetDescription( ) : void
methodprotectedgetLoaderMap( ) : void
inherited

Inherited from: \CreoleTask::getLoaderMap()
methodpublicgetLocation( ) : void
methodpublicgetOwningTarget( ) : void
methodpublicgetPassword( ) : \Returns
inherited

Gets the password.

Inherited from: \CreoleTask::getPassword()
Returns
Type Description
\Returns a String
methodpublicgetProject( ) : void
methodprotectedgetRegisterSlot( ) : void
methodpublicgetRuntimeConfigurableWrapper( ) : void
methodpublicgetTaskName( ) : void
methodpublicgetTaskType( ) : void
methodpublicgetUrl( ) : \Returns
inherited

Gets the url.

Inherited from: \CreoleTask::getUrl()
Returns
Type Description
\Returns a String
methodpublicgetUserId( ) : \Returns
inherited

Gets the userId.

Inherited from: \CreoleTask::getUserId()
Returns
Type Description
\Returns a String
methodpublicinit( ) : void
inherited

Initialize CreoleTask.

Inherited from: \CreoleTask::init()

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.

methodpublicisAutocommit( ) : \Returns
inherited

Gets the autocommit.

Inherited from: \CreoleTask::isAutocommit()
Returns
Type Description
\Returns a boolean
methodpublicisCaching(  $value ) : void
inherited

Inherited from: \CreoleTask::isCaching()
Parameters
Name Type Description
$value
methodpubliclog( ) : void
inherited

Inherited from: Task::log()\CreoleTask::log()
methodpublicmain( ) : void

Load the sql file and then execute it

Throws
Exception Description
\BuildException
methodpublicmaybeConfigure( ) : void
methodpublicperform( ) : void
inherited

Inherited from: Task::perform()\CreoleTask::perform()
methodprotectedprintResults(  $out = null ) : void

print any results in the statement.

Parameters
Name Type Description
$out
Throws
Exception Description
\SQLException
methodpublicrunStatements(  $reader,  $out = null ) : void

read in lines and execute them

Parameters
Name Type Description
$reader
$out
Throws
Exception Description
\SQLException, IOException
methodpublicsetAppend(  $append ) : void

whether output should be appended to or overwrite an existing file. Defaults to false.

Parameters
Name Type Description
$append
methodpublicsetAutocommit( \autocommit $autocommit ) : void
inherited

Auto commit flag for database connection; optional, default false.

Inherited from: \CreoleTask::setAutocommit()
Parameters
Name Type Description
$autocommit \autocommit

The autocommit to set

methodpublicsetCaching(  $enable ) : void
inherited

Caching loaders / driver. This is to avoid getting an OutOfMemoryError when calling this task multiple times in a row; default: true

Inherited from: \CreoleTask::setCaching()
Parameters
Name Type Description
$enable
methodpublicsetDelimiter(  $delimiter ) : void

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

methodpublicsetDelimiterType( string $delimiterType ) : void

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
methodpublicsetDescription( ) : void
methodpublicsetDriver( string $driver ) : void
inherited

Set the Creole driver to be used.

Inherited from: \CreoleTask::setDriver()
Parameters
Name Type Description
$driver string

driver class name

methodpublicsetEncoding( \encoding $encoding ) : void

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

methodpublicsetLocation( ) : void
methodpublicsetOnerror(  $action ) : void

Action to perform when statement fails: continue, stop, or abort optional; default "abort"

Parameters
Name Type Description
$action
methodpublicsetOutput( \PhingFile $output ) : void

Set the output file; optional, defaults to the console.

Parameters
Name Type Description
$output \PhingFile
methodpublicsetOwningTarget( ) : void
methodpublicsetPassword( \password $password ) : void
inherited

Sets the password; required.

Inherited from: \CreoleTask::setPassword()
Parameters
Name Type Description
$password \password

The password to set

methodpublicsetPrint( boolean $print ) : void

Set the print flag.

Parameters
Name Type Description
$print boolean
methodpublicsetProject( ) : void
methodpublicsetRuntimeConfigurableWrapper( ) : void
methodpublicsetShowheaders( boolean $showheaders ) : void

Print headers for result sets from the statements; optional, default true.

Parameters
Name Type Description
$showheaders boolean
methodpublicsetSrc(  $srcFile ) : void

Set the name of the SQL file to be run.

Required unless statements are enclosed in the build file

Parameters
Name Type Description
$srcFile
methodpublicsetTaskName( ) : void
methodpublicsetTaskType( ) : void
methodpublicsetUrl( \url $url ) : void
inherited

Sets the database connection URL; required.

Inherited from: \CreoleTask::setUrl()
Parameters
Name Type Description
$url \url

The url to set

methodpublicsetUserid( \userId $userId ) : void
inherited

Set the user name for the connection; required.

Inherited from: \CreoleTask::setUserid()
Parameters
Name Type Description
$userId \userId

The userId to set

methodpublicsetVersion( \version $version ) : void
inherited

Sets the version string, execute task only if rdbms version match; optional.

Inherited from: \CreoleTask::setVersion()
Parameters
Name Type Description
$version \version

The version to set

\SQLExecTransaction

Package: phing\tasks\ext\creole

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

Properties

Propertyprivate  $parent= ''
Details
Type
n/a
Propertyprivate  $tSqlCommand= '""'
Default value""Details
Type
n/a
Propertyprivate  $tSrcFile= 'null'
Default valuenullDetails
Type
n/a

Methods

methodpublic__construct(  $parent ) : void

Parameters
Name Type Description
$parent
methodpublicaddText(  $sql ) : void

Parameters
Name Type Description
$sql
methodpublicrunTransaction(  $out = null ) : void

Parameters
Name Type Description
$out
Throws
Exception Description
\IOException, SQLException
methodpublicsetSrc(  $src ) : void

Parameters
Name Type Description
$src
Documentation was generated by DocBlox 0.17.1.