PDOSQLExecTask

Extends \PDOTask

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 hans@xmpl.org (Phing)

author

Jeff Martin jeff@custommonkey.org (Ant)

author

Michael McCallum gholam@xtra.co.nz (Ant)

author

Tim Stephenson tim.stephenson@sybase.com (Ant)

package

phing.tasks.ext.pdo

version

$Id: 6f0271c4fe34f85450002311f9fdb18b359bea8d $

Methods

Adds a set of files (nested filelist attribute).

addFilelist(\FileList $list) 

Arguments

$list

\FileList

Adds a set of files (nested fileset attribute).

addFileset(\FileSet $set) 

Arguments

$set

\FileSet

Set an inline SQL command to execute.

addText( $sql) 

NB: Properties are not expanded in this text.

Arguments

$sql

Closes current connection

closeConnection() 

Run cleanup and close formatters.

closeFormatters() 

Creates a new PDOSQLExecFormatterElement for <formatter> element.

createFormatter() : \PDOSQLExecFormatterElement

Add a SQL transaction to execute

createTransaction() 

Exec the sql statement.

execSQL( $sql) 
throws

Arguments

$sql

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

getConfiguredFormatters() : array

Response

array

PDOResultFormatter[]

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

getConnection() : \Connection
inherited

The calling method is responsible for closing the connection.

throws

if the UserId/Password/Url is not set or there is no suitable driver or the driver fails to load.

Response

\Connection

the newly created connection.

Gets a default output writer for this task.

getDefaultOutput() : \Writer

Response

\Writer

Get the statement delimiter.

getDelimiter() : string

Response

string

Returns the textual description of the task

getDescription() : string
inherited

Response

string

The text description of the task

getLoaderMap

getLoaderMap() : mixed
inherited

Response

mixed

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

getLocation() : \Location
inherited

Response

\Location

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

Returns the owning target of this task.

getOwningTarget() : \Target
inherited

Response

\Target

The target object that owns this task

Gets the password.

getPassword() : string
inherited

Response

string

Returns a reference to current project

getProject() : \Project
inherited

Response

\Project

Reference to current porject object

Returns a name

getRegisterSlot(string $slotName) : \RegisterSlot
inherited

Arguments

$slotName

string

Response

\RegisterSlot

Returns the wrapper object for runtime configuration

getRuntimeConfigurableWrapper() : \RuntimeConfigurable
inherited

Response

\RuntimeConfigurable

The wrapper object used by this task

Returns the name of task, used only for log messages

getTaskName() : string
inherited

Response

string

Name of this task

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

getTaskType() : string
inherited

Response

string

The type of this task (XML Tag)

Gets the url.

getUrl() : string
inherited

Response

string

Gets the userId.

getUserId() : string
inherited

Response

string

Called by the parser to let the task initialize properly.

init() 
inherited

Should throw a BuildException if something goes wrong with the build

This is abstract here, but may not be overloaded by subclasses.

throws

Initialize the formatters.

initFormatters() 

Gets the autocommit.

isAutocommit() : \Returns
inherited

Response

\Returns

a boolean

isCaching

isCaching( $value) 
inherited

Arguments

$value

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

isSelectSql(string $sql) : boolean

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

Arguments

$sql

string

Response

boolean

Whether specified SQL looks like a SELECT query.

Logs a message with the given priority.

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

Arguments

$msg

string

The message to be logged.

$level

integer

The message's priority at this message should have

Called by the project to let the task do it's work. This method may be called more than once, if the task is invoked more than once. For example, if target1 and target2 both depend on target3, then running <em>phing target1 target2</em> will run all tasks in target3 twice.

main() 
inherited abstract

Should throw a BuildException if someting goes wrong with the build

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

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

maybeConfigure() 
inherited

Perfrom this task

perform() 
inherited
throws

Passes results from query to any formatters.

processResults() 
throws

read in lines and execute them

runStatements(\Reader $reader) 
throws

Arguments

$reader

\Reader

Caching loaders / driver. This is to avoid getting an OutOfMemoryError when calling this task multiple times in a row; default: true

setCaching( $enable) 
inherited

Arguments

$enable

Set the statement delimiter.

setDelimiter( $delimiter) 

For example, set this to "go" and delimitertype to "ROW" for Sybase ASE or MS SQL Server.

Arguments

$delimiter

Set the Delimiter type for this sql task. The delimiter type takes two values - normal and row. Normal means that any occurrence 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.

setDelimiterType(string $delimiterType) 

Arguments

$delimiterType

string

Sets a textual description of the task

setDescription(string $desc) 
inherited

Arguments

$desc

string

The text describing the task

Sets the fetch mode to use for the PDO resultset.

setFetchmode(mixed $mode) 
throws

Arguments

$mode

mixed

The PDO fetchmode integer or constant name.

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

setLocation(\Location $location) 
inherited

Arguments

$location

\Location

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

Action to perform when statement fails: continue, stop, or abort optional; default &quot;abort&quot;

setOnerror( $action) 

Arguments

$action

Sets the owning target this task belongs to.

setOwningTarget(\Target $target) 
inherited

Arguments

$target

\Target

References the project to the current component.

setProject(\Project $project) : void
inherited

Arguments

$project

\Project

The reference to the current project

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

setRuntimeConfigurableWrapper(\RuntimeConfigurable $wrapper) 
inherited

Arguments

$wrapper

\RuntimeConfigurable

The wrapper object this task should use

Set the name of the SQL file to be run.

setSrc(\PhingFile $srcFile) 

Required unless statements are enclosed in the build file

Arguments

$srcFile

\PhingFile

Sets the name of this task for log messages

setTaskName(string $name) : string
inherited

Arguments

$name

string

Response

string

A string representing the name of this task for log

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

setTaskType( $name) 
inherited

Arguments

$name

Set the user name for the connection; required.

setUserid(string $userId) 
inherited

Arguments

$userId

string

Constants

DELIM_ROW

DELIM_ROW

DELIM_NORMAL

DELIM_NORMAL

DELIM_NONE

DELIM_NONE

Properties

Count of how many statements were executed successfully.

goodSql : integer
var

Type(s)

integer

Count of total number of SQL statements.

totalSql : integer
var

Type(s)

integer

Database connection

conn : \PDO
var

Type(s)

\PDO

Files to load

filesets : array
var

FileSet[]

Type(s)

array

Files to load

filelists : array
var

FileList[]

Type(s)

array

Formatter elements.

formatters : array
var

PDOSQLExecFormatterElement[]

Type(s)

array

SQL statement

statement : \PDOStatement
var

Type(s)

\PDOStatement

SQL input file

srcFile : \PhingFile
var

Type(s)

\PhingFile

SQL input command

sqlCommand : string
var

Type(s)

string

SQL transactions to perform

transactions : 

Type(s)

SQL Statement delimiter (for parsing files)

delimiter : string
var

Type(s)

string

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

delimiterType : 

Type(s)

Action to perform if an error is found

onError : 

Type(s)

Encoding to use when reading SQL statements from a file

encoding : 

Type(s)

Fetch mode for PDO select queries.

fetchMode : integer
var

Type(s)

integer

caching

caching : 
inherited

Type(s)

Autocommit flag. Default value is false

autocommit : 
inherited

Type(s)

DB url.

url : 
inherited

Type(s)

User name.

userId : 
inherited

Type(s)

Password

password : 
inherited

Type(s)

RDBMS Product needed for this SQL.

rdbms : 
inherited

Type(s)

Owning Target object

target : \Target
inherited
var

Type(s)

\Target

Description of the task

description : string
inherited
var

Type(s)

string

Internal taskname (req)

taskType : string
inherited
var

Type(s)

string

Taskname for logger

taskName : string
inherited
var

Type(s)

string

Stored buildfile location

location : \Location
inherited
var

Type(s)

\Location

Wrapper of the task

wrapper : \RuntimeConfigurable
inherited
var

Type(s)

\RuntimeConfigurable

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

project : \Project
inherited
var

A reference to the current project instance

Type(s)

\Project