tasks/ext/pdo/PDOSQLExecTask.php
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
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
Properties

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

string
$delimiter= '";"'
SQL Statement delimiter (for parsing files)
";"Details- Type
- string

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

string
$description= ''
- Type
- string
- Inherited_from
- \Task::$$description
- Inherited_from
- \PDOTask::$$description

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

array
$formatters= 'array()'
Formatter elements.
PDOSQLExecFormatterElement[]array()Details- Type
- array

int
$goodSql= '0'
Count of how many statements were executed successfully.
0Details- Type
- int

\Location
$location= ''
- Type
- \Location
- Inherited_from
- \Task::$$location
- Inherited_from
- \PDOTask::$$location

\Project
$project= 'null'
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::$$projectnullDetails- Type
- \Project
- Inherited_from
- \ProjectComponent::$$project
- Inherited_from
- \Task::$$project
- Inherited_from
- \PDOTask::$$project

\Target
$target= ''
- Type
- \Target
- Inherited_from
- \Task::$$target
- Inherited_from
- \PDOTask::$$target

string
$taskName= ''
- Type
- string
- Inherited_from
- \Task::$$taskName
- Inherited_from
- \PDOTask::$$taskName

string
$taskType= ''
- Type
- string
- Inherited_from
- \Task::$$taskType
- Inherited_from
- \PDOTask::$$taskType

\RuntimeConfigurable
$wrapper= ''
- Type
- \RuntimeConfigurable
- Inherited_from
- \Task::$$wrapper
- Inherited_from
- \PDOTask::$$wrapper
Methods

addFilelist(
$list
)
:
voidAdds a set of files (nested filelist attribute).
| Name | Type | Description |
|---|---|---|
| $list |

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 |

createFormatter(
)
:
\PDOSQLExecFormatterElementCreates a new PDOSQLExecFormatterElement for
| Type | Description |
|---|---|
| \PDOSQLExecFormatterElement |

execSQL(
$sql
)
:
voidExec the sql statement.
| Name | Type | Description |
|---|---|---|
| $sql |
| Exception | Description |
|---|---|
| \PDOException |

getConfiguredFormatters(
)
:
arrayReturns configured PDOResultFormatter objects (which were created from PDOSQLExecFormatterElement objects).
| Type | Description |
|---|---|
| array | PDOResultFormatter[] |

getConnection(
)
:
\ConnectionCreates 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.
| 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. |

getDefaultOutput(
)
:
\WriterGets a default output writer for this task.
| Type | Description |
|---|---|
| \Writer |

getDescription(
)
:
stringReturns the textual description of the task
Inherited from: \Task::getDescription()\PDOTask::getDescription()| Type | Description |
|---|---|
| string | The text description of the task |

getLocation(
)
:
\LocationReturns the location within the buildfile this task occurs. Used by {@link BuildException} to give detailed error messages.
Inherited from: \Task::getLocation()\PDOTask::getLocation()| Type | Description |
|---|---|
| \Location | The location object describing the position of this task within the buildfile. |

getOwningTarget(
)
:
\TargetReturns the owning target of this task.
Inherited from: \Task::getOwningTarget()\PDOTask::getOwningTarget()| Type | Description |
|---|---|
| \Target | The target object that owns this task |

getProject(
)
:
\ProjectReturns a reference to current project
Inherited from: \ProjectComponent::getProject()\Task::getProject()\PDOTask::getProject()| Type | Description |
|---|---|
| \Project | Reference to current porject object |

getRuntimeConfigurableWrapper(
)
:
\RuntimeConfigurableReturns the wrapper object for runtime configuration
Inherited from: \Task::getRuntimeConfigurableWrapper()\PDOTask::getRuntimeConfigurableWrapper()| Type | Description |
|---|---|
| \RuntimeConfigurable | The wrapper object used by this task |

getTaskName(
)
:
stringReturns the name of task, used only for log messages
Inherited from: \Task::getTaskName()\PDOTask::getTaskName()| Type | Description |
|---|---|
| string | Name of this task |

getTaskType(
)
:
stringReturns the name of the task under which it was invoked, usually the XML tagname
Inherited from: \Task::getTaskType()\PDOTask::getTaskType()| Type | Description |
|---|---|
| string | The type of this task (XML Tag) |

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.
| Exception | Description |
|---|---|
| \BuildException |

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

isSelectSql(
string $sql
)
:
booleanWhether 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').
| Name | Type | Description |
|---|---|---|
| $sql | string |
| Type | Description |
|---|---|
| boolean | Whether specified SQL looks like a SELECT query. |

log(
string $msg, integer $level
=
Project::MSG_INFO
)
:
voidProvides a project level log event to the task.
Inherited from: \Task::log()\PDOTask::log()| Name | Type | Description |
|---|---|---|
| $msg | string | The message to log |
| $level | integer | The priority of the message |
- See
- \BuildEvent
- See
- \BuildListener

main(
)
:
voidLoad 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.
| Exception | Description |
|---|---|
| \BuildException |

maybeConfigure(
)
:
voidConfigure this task if it hasn't been done already.
Inherited from: \Task::maybeConfigure()\PDOTask::maybeConfigure()
processResults(
)
:
voidPasses results from query to any formatters.
| Exception | Description |
|---|---|
| \PDOException |

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

setAutocommit(
\autocommit $autocommit
)
:
voidAuto commit flag for database connection; optional, default false.
Inherited from: \PDOTask::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: \PDOTask::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 |

setDescription(
string $desc
)
:
voidSets a textual description of the task
Inherited from: \Task::setDescription()\PDOTask::setDescription()| Name | Type | Description |
|---|---|---|
| $desc | string | The text describing the task |

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 |

setFetchmode(
mixed $mode
)
:
voidSets the fetch mode to use for the PDO resultset.
| Name | Type | Description |
|---|---|---|
| $mode | mixed | The PDO fetchmode integer or constant name. |

setLocation(
\Location $location
)
:
voidSets the location within the buildfile this task occurs. Called by the parser to set location information.
Inherited from: \Task::setLocation()\PDOTask::setLocation()| Name | Type | Description |
|---|---|---|
| $location | \Location | The location object describing the position of this task within the buildfile. |

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

setOwningTarget(
\Target $target
)
:
voidSets the owning target this task belongs to.
Inherited from: \Task::setOwningTarget()\PDOTask::setOwningTarget()| Name | Type | Description |
|---|---|---|
| $target | \Target | Reference to owning target |

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

setProject(
\Project $project
)
:
voidReferences the project to the current component.
Inherited from: \ProjectComponent::setProject()\Task::setProject()\PDOTask::setProject()| Name | Type | Description |
|---|---|---|
| $project | \Project | The reference to the current project |

setRuntimeConfigurableWrapper(
\RuntimeConfigurable $wrapper
)
:
voidSets the wrapper object this task should use for runtime configurable elements.
Inherited from: \Task::setRuntimeConfigurableWrapper()\PDOTask::setRuntimeConfigurableWrapper()| Name | Type | Description |
|---|---|---|
| $wrapper | \RuntimeConfigurable | The wrapper object this task should use |

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 |

setTaskName(
string $name
)
:
stringSets the name of this task for log messages
Inherited from: \Task::setTaskName()\PDOTask::setTaskName()| Name | Type | Description |
|---|---|---|
| $name | string |
| Type | Description |
|---|---|
| string | A string representing the name of this task for log |

setTaskType(
string $name
)
:
voidSets the type of the task. Usually this is the name of the XML tag
Inherited from: \Task::setTaskType()\PDOTask::setTaskType()| Name | Type | Description |
|---|---|---|
| $name | string | The type of this task (XML Tag) |

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