tasks/ext/creole/CreoleSQLExecTask.php

Show: inherited
Table of Contents

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.

Author
Hans Lellelid (Phing)  
Author
Jeff Martin (Ant)  
Author
Michael McCallum (Ant)  
Author
Tim Stephenson (Ant)  
Package
phing.tasks.ext.creole  
Version
$Id: f8f62d67a784faced2621d2ffc3b1c92e8703b05 $  

\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)  
Copyright
2001,2002 THYRELL. All rights reserved  
Version
$Id: f8f62d67a784faced2621d2ffc3b1c92e8703b05 $  

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
Propertyprotectedstring  $description= ''
inherited

Description of the task

Inherited from: \Task::$$description\CreoleTask::$$description
Details
Type
string
Inherited_from
\Task::$$description  
Inherited_from
\CreoleTask::$$description  
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  
Propertyprotected\Location  $location= ''
inherited

Stored buildfile location

Inherited from: \Task::$$location\CreoleTask::$$location
Details
Type
\Location
Inherited_from
\Task::$$location  
Inherited_from
\CreoleTask::$$location  
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
Propertyprotected\Project  $project= 'null'
inherited

Holds a reference to the project that a project component (a task, a target, etc.) belongs to

A reference to the current project instanceInherited from: \ProjectComponent::$$project\Task::$$project\CreoleTask::$$project
Default valuenullDetails
Type
\Project
Inherited_from
\ProjectComponent::$$project  
Inherited_from
\Task::$$project  
Inherited_from
\CreoleTask::$$project  
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
Propertyprotected\Target  $target= ''
inherited

Owning Target object

Inherited from: \Task::$$target\CreoleTask::$$target
Details
Type
\Target
Inherited_from
\Task::$$target  
Inherited_from
\CreoleTask::$$target  
Propertyprotectedstring  $taskName= ''
inherited

Taskname for logger

Inherited from: \Task::$$taskName\CreoleTask::$$taskName
Details
Type
string
Inherited_from
\Task::$$taskName  
Inherited_from
\CreoleTask::$$taskName  
Propertyprotectedstring  $taskType= ''
inherited

Internal taskname (req)

Inherited from: \Task::$$taskType\CreoleTask::$$taskType
Details
Type
string
Inherited_from
\Task::$$taskType  
Inherited_from
\CreoleTask::$$taskType  
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  
Propertyprotected\RuntimeConfigurable  $wrapper= ''
inherited

Wrapper of the task

Inherited from: \Task::$$wrapper\CreoleTask::$$wrapper
Details
Type
\RuntimeConfigurable
Inherited_from
\Task::$$wrapper  
Inherited_from
\CreoleTask::$$wrapper  

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( ) : string
inherited

Returns the textual description of the task

Inherited from: \Task::getDescription()\CreoleTask::getDescription()
Returns
Type Description
string The text description of the task
methodprotectedgetLoaderMap( ) : void
inherited

Inherited from: \CreoleTask::getLoaderMap()
methodpublicgetLocation( ) : \Location
inherited

Returns the location within the buildfile this task occurs. Used by {@link BuildException} to give detailed error messages.

Inherited from: \Task::getLocation()\CreoleTask::getLocation()
Returns
Type Description
\Location The location object describing the position of this task within the buildfile.
methodpublicgetOwningTarget( ) : \Target
inherited

Returns the owning target of this task.

Inherited from: \Task::getOwningTarget()\CreoleTask::getOwningTarget()
Returns
Type Description
\Target The target object that owns this task
methodpublicgetPassword( ) : \Returns
inherited

Gets the password.

Inherited from: \CreoleTask::getPassword()
Returns
Type Description
\Returns a String
methodpublicgetProject( ) : \Project
inherited

Returns a reference to current project

Inherited from: \ProjectComponent::getProject()\Task::getProject()\CreoleTask::getProject()
Returns
Type Description
\Project Reference to current porject object
methodprotectedgetRegisterSlot( string $slotName ) : void
inherited

Returns a name

Inherited from: \Task::getRegisterSlot()\CreoleTask::getRegisterSlot()
Parameters
Name Type Description
$slotName string
methodpublicgetRuntimeConfigurableWrapper( ) : \RuntimeConfigurable
inherited

Returns the wrapper object for runtime configuration

Inherited from: \Task::getRuntimeConfigurableWrapper()\CreoleTask::getRuntimeConfigurableWrapper()
Returns
Type Description
\RuntimeConfigurable The wrapper object used by this task
methodpublicgetTaskName( ) : string
inherited

Returns the name of task, used only for log messages

Inherited from: \Task::getTaskName()\CreoleTask::getTaskName()
Returns
Type Description
string Name of this task
methodpublicgetTaskType( ) : string
inherited

Returns the name of the task under which it was invoked, usually the XML tagname

Inherited from: \Task::getTaskType()\CreoleTask::getTaskType()
Returns
Type Description
string The type of this task (XML Tag)
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.

Throws
Exception Description
\BuildException
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( string $msg, integer $level = Project::MSG_INFO ) : void
inherited

Provides a project level log event to the task.

Inherited from: \Task::log()\CreoleTask::log()
Parameters
Name Type Description
$msg string

The message to log

$level integer

The priority of the message

Details
See
\BuildEvent  
See
\BuildListener  
methodpublicmain( ) : void

Load the sql file and then execute it

Should throw a BuildException if someting goes wrong with the build

This is abstract here. Must be overloaded by real tasks.

Throws
Exception Description
\BuildException
methodpublicmaybeConfigure( ) : void
inherited

Configure this task if it hasn't been done already.

Inherited from: \Task::maybeConfigure()\CreoleTask::maybeConfigure()
methodpublicperform( ) : void
inherited

Perfrom this task

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( string $desc ) : void
inherited

Sets a textual description of the task

Inherited from: \Task::setDescription()\CreoleTask::setDescription()
Parameters
Name Type Description
$desc string

The text describing the task

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( \Location $location ) : void
inherited

Sets the location within the buildfile this task occurs. Called by the parser to set location information.

Inherited from: \Task::setLocation()\CreoleTask::setLocation()
Parameters
Name Type Description
$location \Location

The location object describing the position of this task within the buildfile.

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( \Target $target ) : void
inherited

Sets the owning target this task belongs to.

Inherited from: \Task::setOwningTarget()\CreoleTask::setOwningTarget()
Parameters
Name Type Description
$target \Target

Reference to owning target

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( \Project $project ) : void
inherited

References the project to the current component.

Inherited from: \ProjectComponent::setProject()\Task::setProject()\CreoleTask::setProject()
Parameters
Name Type Description
$project \Project

The reference to the current project

methodpublicsetRuntimeConfigurableWrapper( \RuntimeConfigurable $wrapper ) : void
inherited

Sets the wrapper object this task should use for runtime configurable elements.

Inherited from: \Task::setRuntimeConfigurableWrapper()\CreoleTask::setRuntimeConfigurableWrapper()
Parameters
Name Type Description
$wrapper \RuntimeConfigurable

The wrapper object this task should use

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( string $name ) : string
inherited

Sets the name of this task for log messages

Inherited from: \Task::setTaskName()\CreoleTask::setTaskName()
Parameters
Name Type Description
$name string
Returns
Type Description
string A string representing the name of this task for log
methodpublicsetTaskType( string $name ) : void
inherited

Sets the type of the task. Usually this is the name of the XML tag

Inherited from: \Task::setTaskType()\CreoleTask::setTaskType()
Parameters
Name Type Description
$name string

The type of this task (XML Tag)

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