tasks/ext/pdo/PDOSQLExecTask.php
\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) - Version
- $Revision: 1274 $
Constants
Properties

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

$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
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[] |

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

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

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 |

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 |

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

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

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 |