tasks/ext/pdo/PDOSQLExecTask.php

Show: inherited
Table of Contents

Executes a series of SQL statements on a database using PDO.

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.pdo  
Version
$Id: 8b5a8e4f80b46f8a797b058dbb9a240a1185c12b $  

\PDOSQLExecTask

Package: phing\tasks\ext\pdo

Executes a series of SQL statements on a database using PDO.

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)
\PDOTask < \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: 8b5a8e4f80b46f8a797b058dbb9a240a1185c12b $  

Constants

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

Properties

Propertyprivate  $autocommit= 'false'
inherited

Autocommit flag. Default value is false

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

Database connection

Default valuenullDetails
Type
\PDO
Propertyprivatestring  $delimiter= '";"'

SQL Statement delimiter (for parsing files)

Default value";"Details
Type
string
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\PDOTask::$$description
Details
Type
string
Inherited_from
\Task::$$description  
Inherited_from
\PDOTask::$$description  
Propertyprivate  $encoding= 'null'

Encoding to use when reading SQL statements from a file

Default valuenullDetails
Type
n/a
Propertyprivateint  $fetchMode= ''

Fetch mode for PDO select queries.

Details
Type
int
Propertyprivatearray  $filelists= 'array()'

Files to load

FileList[]
Default valuearray()Details
Type
array
Propertyprivatearray  $filesets= 'array()'

Files to load

FileSet[]
Default valuearray()Details
Type
array
Propertyprivatearray  $formatters= 'array()'

Formatter elements.

PDOSQLExecFormatterElement[]
Default valuearray()Details
Type
array
Propertyprivateint  $goodSql= '0'

Count of how many statements were executed successfully.

Default value0Details
Type
int
Propertyprotected\Location  $location= ''
inherited

Stored buildfile location

Inherited from: \Task::$$location\PDOTask::$$location
Details
Type
\Location
Inherited_from
\Task::$$location  
Inherited_from
\PDOTask::$$location  
Propertyprivate  $onError= '"abort"'

Action to perform if an error is found

Default value"abort"Details
Type
n/a
Propertyprivate  $password= ''
inherited

Password

Inherited from: \PDOTask::$$password
Details
Type
n/a
Inherited_from
\PDOTask::$$password  
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\PDOTask::$$project
Default valuenullDetails
Type
\Project
Inherited_from
\ProjectComponent::$$project  
Inherited_from
\Task::$$project  
Inherited_from
\PDOTask::$$project  
Propertyprivate  $rdbms= ''
inherited

RDBMS Product needed for this SQL.

Inherited from: \PDOTask::$$rdbms
Details
Type
n/a
Inherited_from
\PDOTask::$$rdbms  
Propertyprivatestring  $sqlCommand= '""'

SQL input command

Default value""Details
Type
string
Propertyprivate\PhingFile  $srcFile= ''

SQL input file

Details
Type
\PhingFile
Propertyprivate\PDOStatement  $statement= ''

SQL statement

Details
Type
\PDOStatement
Propertyprotected\Target  $target= ''
inherited

Owning Target object

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

Taskname for logger

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

Internal taskname (req)

Inherited from: \Task::$$taskType\PDOTask::$$taskType
Details
Type
string
Inherited_from
\Task::$$taskType  
Inherited_from
\PDOTask::$$taskType  
Propertyprivateint  $totalSql= '0'

Count of total number of SQL statements.

Default value0Details
Type
int
Propertyprivate  $transactions= 'array()'

SQL transactions to perform

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

DB url.

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

User name.

Inherited from: \PDOTask::$$userId
Details
Type
n/a
Inherited_from
\PDOTask::$$userId  
Propertyprotected\RuntimeConfigurable  $wrapper= ''
inherited

Wrapper of the task

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

Methods

methodpublicaddFilelist(  $list ) : void

Adds a set of files (nested filelist attribute).

Parameters
Name Type Description
$list
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
methodprotectedcloseConnection( ) : void

Closes current connection

methodprotectedcloseFormatters( ) : void

Run cleanup and close formatters.

methodpubliccreateFormatter( ) : \PDOSQLExecFormatterElement

Creates a new PDOSQLExecFormatterElement for element.

Returns
Type Description
\PDOSQLExecFormatterElement
methodpubliccreateTransaction( ) : void

Add a SQL transaction to execute

methodprotectedexecSQL(  $sql ) : void

Exec the sql statement.

Parameters
Name Type Description
$sql
Throws
Exception Description
\PDOException
methodprotectedgetConfiguredFormatters( ) : array

Returns configured PDOResultFormatter objects (which were created from PDOSQLExecFormatterElement objects).

Returns
Type Description
array PDOResultFormatter[]
methodprotectedgetConnection( ) : \Connection
inherited

Creates a new Connection as using the driver, url, userid and password specified.

Inherited from: \PDOTask::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.
methodprivategetDefaultOutput( ) : \Writer

Gets a default output writer for this task.

Returns
Type Description
\Writer
methodpublicgetDelimiter( ) : string

Get the statement delimiter.

Returns
Type Description
string
methodpublicgetDescription( ) : string
inherited

Returns the textual description of the task

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

Inherited from: \PDOTask::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()\PDOTask::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()\PDOTask::getOwningTarget()
Returns
Type Description
\Target The target object that owns this task
methodpublicgetPassword( ) : \Returns
inherited

Gets the password.

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

Returns a reference to current project

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

Returns a name

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

Returns the wrapper object for runtime configuration

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

Gets the url.

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

Gets the userId.

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

Initialize CreoleTask.

Inherited from: \PDOTask::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
methodprotectedinitFormatters( ) : void

Initialize the formatters.

methodpublicisAutocommit( ) : \Returns
inherited

Gets the autocommit.

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

Inherited from: \PDOTask::isCaching()
Parameters
Name Type Description
$value
methodprotectedisSelectSql( string $sql ) : boolean

Whether the passed-in SQL statement is a SELECT statement.

This does a pretty simple match, checking to see if statement starts with 'select' (but not 'select into').

Parameters
Name Type Description
$sql string
Returns
Type Description
boolean Whether specified SQL looks like a SELECT query.
methodpubliclog( string $msg, integer $level = Project::MSG_INFO ) : void
inherited

Provides a project level log event to the task.

Inherited from: \Task::log()\PDOTask::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()\PDOTask::maybeConfigure()
methodpublicperform( ) : void
inherited

Perfrom this task

Inherited from: \Task::perform()\PDOTask::perform()
methodprotectedprocessResults( ) : void

Passes results from query to any formatters.

Throws
Exception Description
\PDOException
methodpublicrunStatements(  $reader ) : void

read in lines and execute them

Parameters
Name Type Description
$reader
Throws
Exception Description
\PDOException, IOException
methodpublicsetAutocommit( \autocommit $autocommit ) : void
inherited

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

Inherited from: \PDOTask::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: \PDOTask::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()\PDOTask::setDescription()
Parameters
Name Type Description
$desc string

The text describing the task

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

methodpublicsetFetchmode( mixed $mode ) : void

Sets the fetch mode to use for the PDO resultset.

Parameters
Name Type Description
$mode mixed

The PDO fetchmode integer or constant name.

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

Sets the owning target this task belongs to.

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

Reference to owning target

methodpublicsetPassword( \password $password ) : void
inherited

Sets the password; required.

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

The password to set

methodpublicsetProject( \Project $project ) : void
inherited

References the project to the current component.

Inherited from: \ProjectComponent::setProject()\Task::setProject()\PDOTask::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()\PDOTask::setRuntimeConfigurableWrapper()
Parameters
Name Type Description
$wrapper \RuntimeConfigurable

The wrapper object this task should use

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()\PDOTask::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()\PDOTask::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: \PDOTask::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: \PDOTask::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: \PDOTask::setVersion()
Parameters
Name Type Description
$version \version

The version to set

\PDOSQLExecTransaction

Package: phing\tasks\ext\pdo

"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( ) : void

Throws
Exception Description
\IOException, PDOException
methodpublicsetSrc(  $src ) : void

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