The PDOSQLExecTask
executes SQL statements using PDO.
The combination of large SQL files and
delimitertype
set to normal
can trigger segmentation faults with large files.
Table C.66: Attributes
Name | Type | Description | Default | Required |
---|---|---|---|---|
url | String | PDO connection URL (DSN) | none | Yes |
userid | String | Username for connection (if it cannot be specified in URL) | none | No |
password | String | The password to use for the connection (if it cannot be specified in URL) | none | No |
src | File | A single source file of SQL statements to execute. | none | No |
onerror | String | The action to perform on error (continue, stop, or abort) | abort | No |
failonconnectionerror | Boolean | If false , will not execute any statement if the task fails to connect to the database. | true | No |
delimiter | String | The delimiter to separate SQL statements (e.g. "GO" in MSSQL) | ; | No |
delimitertype | String | The delimiter type ("normal", "row" or "none"). 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. None disables all delimiter detection. | none | No |
autocommit | Boolean | Whether to auto (implicitly) commit every single statement, disabling transactions. | false | No |
encoding | String | Encoding to use for read SQL files | none | No |
keepformat | Boolean | Control whether the format of SQL will be preserved. Useful when loading packages and procedures. | false | No |
expandproperties | Boolean | Set to false to turn off property expansion in nested SQL,
inline in the task or nested transactions. | true | No |
errorproperty | String | The name of a property to set in the event of an error. | none | No |
statementcountproperty | String | The name of a property to set to the number of statements executed successfully. | none | No |
You can also use PDOSQLExecTask as condition
<pdosqlexec url="pgsql:host=localhost dbname=test"> <fileset dir="sqlfiles"> <include name="*.sql"/> </fileset> </pdosqlexec>
<pdosqlexec url="mysql:host=localhost;dbname=test" userid="username" password="password"> <transaction src="path/to/sqlfile.sql"/> <formatter type="plain" outfile="path/to/output.txt"/> </pdosqlexec>
<property name="color" value="orange"/> <pdosqlexec url="mysql:host=localhost;dbname=test" userid="username" password="password"> <transaction> SELECT * FROM products WHERE color = '${color}'; </transaction> <formatter type="xml" outfile="path/to/output.xml"/> </pdosqlexec>
Because of backwards compatibility, the PDOSQLExecTask can also be called using
the 'pdo'
statement.
<pdo url="pgsql:host=localhost dbname=test"> <fileset dir="sqlfiles"> <include name="*.sql"/> </fileset> <!-- xml formatter --> <formatter type="xml" output="output.xml"/> <!-- custom formatter --> <formatter classname="path.to.CustomFormatterClass"> <param name="someClassAttrib" value="some-value"/> </formatter> <!-- No output file + usefile=false means it goes to phing log --> <formatter type="plain" usefile="false" /> </pdo>
transaction
Wrapper for a single transaction. Transactions allow several files or blocks of statements to be executed using the same PDO connection and commit operation in between.
Table C.67: Attributes
Name | Type | Description | Default | Required |
---|---|---|---|---|
src | String | File with statements to be run as one transaction | n/a | No |
Files containing SQL statements.
Files containing SQL statements.
formatter
The results of any queries that are executed can be printed in different
formats. Output will always be sent to a file, unless you set the
usefile
attribute to false
. The
path to the output file can be specified by the
outfile
attribute; there is a default filename that
will be returned by the formatter if no output file is specified.
There are three predefined formatters - one prints the query results in
XML format, the other emits plain text. Custom formatters that extend
Phing\Task\System\Pdo\PDOResultFormatter
can be specified.
Table C.68: Attributes
Name | Type | Description | Default | Required |
---|---|---|---|---|
type | String | Use a predefined formatter (either xml
or plain ). | n/a | One of these attributes is required. |
classname | String | Name of a custom formatter class (must extend
Phing\Task\System\Pdo\PDOResultFormatter ). | n/a | |
usefile | Boolean | Boolean that determines whether output should be sent to a file. | true | No |
outfile | File | Path to file in which to store result. | Depends on formatter | No |
append | Boolean | Whether output should be appended to or overwrite an existing file. | false | No |
showheaders | Boolean | (only applies to plain formatter) Whether to show column headers. | false | No |
showtrailers | Boolean | (only applies to plain formatter) Whether to show successful executed statement counter trailers. | false | No |
coldelim | String | (only applies to plain formatter) The column delimiter. | , | No |
rowdelim | String | (only applies to plain formatter) The row delimiter. | \n | No |
encoding | String | (only applies to XML formatter) The xml document encoding. | (PHP default) | No |
formatoutput | Boolean | (only applies to XML formatter) Whether to format XML output. | true | No |