# tasks/ext/pdo/PDOSQLExecTask.php

## \PDOSQLExecTask
jump to top

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
  $Revision: 1274 $

### Constants

`DELIM_ROW = "row"`

`DELIM_NORMAL = "normal"`

### Properties

`\PDO $conn= 'null'`

Database connection

Default value `null` Details

Type
  \PDO

`string $delimiter= '";"'`

SQL Statement delimiter (for parsing files)

Default value`";"`Details

Type
  string

`$delimiterType= '"normal"'`

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

Default value`"normal"`Details

Type

`string $description= ''`
inherited

description of the taskInherited from: \Task::$description
Details

Type
  string
Inherited_from
  \Task::$description

`$encoding= 'null'`

Encoding to use when reading SQL statements from a file

Default value `null` Details

Type

`int $fetchMode= ''`

Fetch mode for PDO select queries.

Details

Type
  int

`array $filelists= 'array()'`

Files to load

FileList[]
Default value `array()`Details

Type
  array

`array $filesets= 'array()'`

Files to load

FileSet[]
Default value `array()`Details

Type
  array

`array $formatters= 'array()'`

Formatter elements.

PDOSQLExecFormatterElement[]
Default value `array()`Details

Type
  array

`int $goodSql= '0'`

Count of how many statements were executed successfully.

Default value `0` Details

Type
  int

`\Location $location= ''`
inherited

stored buildfile locationInherited from: \Task::$location
Details

Type
  \Location
Inherited_from
  \Task::$location

`$onError= '"abort"'`

Action to perform if an error is found

Default value`"abort"`Details

Type

`\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
Default value `null` Details

Type
  \Project
Inherited_from
  \ProjectComponent::$project

`string $sqlCommand= '""'`

SQL input command

Default value`""`Details

Type
  string

`\PhingFile $srcFile= ''`

SQL input file

Details

Type
  \PhingFile

`\PDOStatement $statement= ''`

SQL statement

Details

Type
  \PDOStatement

`\Target $target= ''`
inherited

owning Target objectInherited from: \Task::$target
Details

Type
  \Target
Inherited_from
  \Task::$target

`string $taskName= ''`
inherited

Taskname for loggerInherited from: \Task::$taskName
Details

Type
  string
Inherited_from
  \Task::$taskName

`string $taskType= ''`
inherited

internal taskname (req)Inherited from: \Task::$taskType
Details

Type
  string
Inherited_from
  \Task::$taskType

`int $totalSql= '0'`

Count of total number of SQL statements.

Default value `0` Details

Type
  int

`$transactions= 'array()'`

SQL transactions to perform

Default value `array()`Details

Type

`\RuntimeConfigurable $wrapper= ''`
inherited

wrapper of the taskInherited from: \Task::$wrapper
Details

Type
  \RuntimeConfigurable
Inherited_from
  \Task::$wrapper

### Methods

`addFilelist( $list ) : void`

Adds a set of files (nested filelist attribute).

Parameters

Name | Type | Description
--- | --- | ---
$list |  |

`addFileset( $set ) : void`

Adds a set of files (nested fileset attribute).

Parameters

Name | Type | Description
--- | --- | ---
$set |  |

`addText( $sql ) : void`

Set an inline SQL command to execute.

NB: Properties are not expanded in this text.

Parameters

Name | Type | Description
--- | --- | ---
$sql |  |

`closeConnection( ) : void`

Closes current connection

`closeFormatters( ) : void`

Run cleanup and close formatters.

`createFormatter( ) : \PDOSQLExecFormatterElement`

Creates a new PDOSQLExecFormatterElement for element.

Returns

Type | Description
--- | ---
\PDOSQLExecFormatterElement |

`createTransaction( ) : void`

Add a SQL transaction to execute

`execSQL( $sql ) : void`

Exec the sql statement.

Parameters

Name | Type | Description
--- | --- | ---
$sql |  |

Throws

Exception | Description
--- | ---
\PDOException |

`getConfiguredFormatters( ) : array`

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

Returns

Type | Description
--- | ---
array | PDOResultFormatter[]

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

`getDefaultOutput( ) : \Writer`

Gets a default output writer for this task.

Returns

Type | Description
--- | ---
\Writer |

`getDelimiter( ) : string`

Get the statement delimiter.

Returns

Type | Description
--- | ---
string |

`getDescription( ) : string`
inherited

Returns the textual description of the task

Inherited from: \Task::getDescription()
Returns

Type | Description
--- | ---
string | The text description of the task

`getLoaderMap( ) : void`
inherited

Inherited from: \PDOTask::getLoaderMap()
`getLocation( ) : \Location`
inherited

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

Inherited from: \Task::getLocation()
Returns

Type | Description
--- | ---
\Location | The location object describing the position of this task within the buildfile.

`getOwningTarget( ) : \Target`
inherited

Returns the owning target of this task.

Inherited from: \Task::getOwningTarget()
Returns

Type | Description
--- | ---
\Target | The target object that owns this task

`getPassword( ) : \Returns`
inherited

Gets the password.

Inherited from: \PDOTask::getPassword()
Returns

Type | Description
--- | ---
\Returns | a String

`getProject( ) : \Project`
inherited

Returns a reference to current project

Inherited from: \ProjectComponent::getProject()
Returns

Type | Description
--- | ---
\Project | Reference to current porject object

`getRegisterSlot( $slotName ) : void`
inherited

Returns a name

Inherited from: \Task::getRegisterSlot()
Parameters

Name | Type | Description
--- | --- | ---
$slotName |  |

`getRuntimeConfigurableWrapper( ) : \RuntimeConfigurable`
inherited

Returns the wrapper object for runtime configuration

Inherited from: \Task::getRuntimeConfigurableWrapper()
Returns

Type | Description
--- | ---
\RuntimeConfigurable | The wrapper object used by this task

`getTaskName( ) : string`
inherited

Returns the name of task, used only for log messages

Inherited from: \Task::getTaskName()
Returns

Type | Description
--- | ---
string | Name of this task

`getTaskType( ) : string`
inherited

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

Inherited from: \Task::getTaskType()
Returns

Type | Description
--- | ---
string | The type of this task (XML Tag)

`getUrl( ) : \Returns`
inherited

Gets the url.

Inherited from: \PDOTask::getUrl()
Returns

Type | Description
--- | ---
\Returns | a String

`getUserId( ) : \Returns`
inherited

Gets the userId.

Inherited from: \PDOTask::getUserId()
Returns

Type | Description
--- | ---
\Returns | a String

`init( ) : 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 |

`initFormatters( ) : void`

Initialize the formatters.

`isAutocommit( ) : \Returns`
inherited

Gets the autocommit.

Inherited from: \PDOTask::isAutocommit()
Returns

Type | Description
--- | ---
\Returns | a boolean

`isCaching( $value ) : void`
inherited

Inherited from: \PDOTask::isCaching()
Parameters

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').

Parameters

Name | Type | Description
--- | --- | ---
$sql | string |

Returns

Type | Description
--- | ---
boolean | Whether specified SQL looks like a SELECT query.

`log( string $msg, integer $level = Project::MSG_INFO ) : void`
inherited

Provides a project level log event to the task.

Inherited from: \Task::log()

@param string $msg The message to be logged.

Parameters

Name | Type | Description
--- | --- | ---
$msg | string | The message to log
$level | integer | The priority of the message

Details

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.

Throws

Exception | Description
--- | ---
\BuildException |

`maybeConfigure( ) : void`
inherited

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

Inherited from: \Task::maybeConfigure()
`perform( ) : void`
inherited

Perfrom this task

Inherited from: \Task::perform()
`processResults( ) : void`

Passes results from query to any formatters.

Throws

Exception | Description
--- | ---
\PDOException |

`runStatements( $reader ) : void`

read in lines and execute them

Parameters

Name | Type | Description
--- | --- | ---
$reader |  |

Throws

Exception | Description
--- | ---
\PDOException, | IOException

`setAutocommit( \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

`setCaching( $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 |  |

`setDelimiter( $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

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

Parameters

Name | Type | Description
--- | --- | ---
$delimiterType | string |

`setDescription( string $desc ) : void`
inherited

Sets a textual description of the task

Inherited from: \Task::setDescription()
Parameters

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

Parameters

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.

Parameters

Name | Type | Description
--- | --- | ---
$mode | mixed | The PDO fetchmode integer or constant name.

`setLocation( \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()
Parameters

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"

Parameters

Name | Type | Description
--- | --- | ---
$action |  |

`setOwningTarget( \Target $target ) : void`
inherited

Sets the owning target this task belongs to.

Inherited from: \Task::setOwningTarget()
Parameters

Name | Type | Description
--- | --- | ---
$target | \Target | Reference to owning target

`setPassword( \password $password ) : void`
inherited

Sets the password; required.

Inherited from: \PDOTask::setPassword()
Parameters

Name | Type | Description
--- | --- | ---
$password | \password | The password to set

`setProject( \Project $project ) : void`
inherited

References the project to the current component.

Inherited from: \ProjectComponent::setProject()
Parameters

Name | Type | Description
--- | --- | ---
$project | \Project | The reference to the current project

`setRuntimeConfigurableWrapper( \RuntimeConfigurable $wrapper ) : void`
inherited

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

Inherited from: \Task::setRuntimeConfigurableWrapper()
Parameters

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

Parameters

Name | Type | Description
--- | --- | ---
$srcFile |  |

`setTaskName( $name ) : string`
inherited

Sets the name of this task for log messages

Inherited from: \Task::setTaskName()
Parameters

Name | Type | Description
--- | --- | ---
$name |  |

Returns

Type | Description
--- | ---
string | A string representing the name of this task for log

`setTaskType( string $name ) : void`
inherited

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

Inherited from: \Task::setTaskType()
Parameters

Name | Type | Description
--- | --- | ---
$name | string | The type of this task (XML Tag)

`setUrl( \url $url ) : void`
inherited

Sets the database connection URL; required.

Inherited from: \PDOTask::setUrl()
Parameters

Name | Type | Description
--- | --- | ---
$url | \url | The url to set

`setUserid( \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

`setVersion( \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
jump to top

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

`$parent= ''`
Details

Type

`$tSqlCommand= '""'`
Default value`""`Details

Type

`$tSrcFile= 'null'`
Default value `null` Details

Type

### Methods

`__construct( $parent ) : void`

Parameters

Name | Type | Description
--- | --- | ---
$parent |  |

`addText( $sql ) : void`

Parameters

Name | Type | Description
--- | --- | ---
$sql |  |

`runTransaction( ) : void`

Throws

Exception | Description
--- | ---
\IOException, | PDOException

`setSrc( $src ) : void`

Parameters

Name | Type | Description
--- | --- | ---
$src |  |

Documentation was generated by DocBlox 0.15.1.