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'
true
Details- 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
null
Details- Type
- n/a


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


int
$goodSql= '0'
Count of how many statements were executed successfully.
0
Details- 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::$$projectnull
Details- 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
)
:
void
Adds a set of files (nested filelist attribute).
Name | Type | Description |
---|---|---|
$list |


addFileset(
$set
)
:
void
Adds a set of files (nested fileset attribute).
Name | Type | Description |
---|---|---|
$set |


addText(
$sql
)
:
void
Set an inline SQL command to execute.
NB: Properties are not expanded in this text.
Name | Type | Description |
---|---|---|
$sql |


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


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


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


getConnection(
)
:
\Connection
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.
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(
)
:
\Writer
Gets a default output writer for this task.
Type | Description |
---|---|
\Writer |


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


getLocation(
)
:
\Location
Returns 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(
)
:
\Target
Returns the owning target of this task.
Inherited from: \Task::getOwningTarget()\PDOTask::getOwningTarget()Type | Description |
---|---|
\Target | The target object that owns this task |


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


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


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


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


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


maybeConfigure(
)
:
void
Configure this task if it hasn't been done already.
Inherited from: \Task::maybeConfigure()\PDOTask::maybeConfigure()

processResults(
)
:
void
Passes results from query to any formatters.
Exception | Description |
---|---|
\PDOException |


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


setAutocommit(
\autocommit $autocommit
)
:
void
Auto commit flag for database connection; optional, default false.
Inherited from: \PDOTask::setAutocommit()Name | Type | Description |
---|---|---|
$autocommit | \autocommit | The autocommit to set |


setCaching(
$enable
)
:
void
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()Name | Type | Description |
---|---|---|
$enable |


setDelimiter(
$delimiter
)
:
void
Set 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
)
:
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.
Name | Type | Description |
---|---|---|
$delimiterType | string |


setDescription(
string $desc
)
:
void
Sets 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
)
:
void
Set 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
)
:
void
Sets the fetch mode to use for the PDO resultset.
Name | Type | Description |
---|---|---|
$mode | mixed | The PDO fetchmode integer or constant name. |


setLocation(
\Location $location
)
:
void
Sets 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
)
:
void
Action to perform when statement fails: continue, stop, or abort optional; default "abort"
Name | Type | Description |
---|---|---|
$action |


setOwningTarget(
\Target $target
)
:
void
Sets 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
)
:
void
References 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
)
:
void
Sets 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
)
:
void
Set 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
)
:
string
Sets 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
)
:
void
Sets 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
)
:
void
Sets the version string, execute task only if rdbms version match; optional.
Inherited from: \PDOTask::setVersion()Name | Type | Description |
---|---|---|
$version | \version | The version to set |