# 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)
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
  n/a

`$encoding= 'null'`

Encoding to use when reading SQL statements from a file

Default value `null` Details

Type
  n/a

`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

`$onError= '"abort"'`

Action to perform if an error is found

Default value`"abort"`Details

Type
  n/a

`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

`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
  n/a

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

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

`getLoaderMap( ) : void`

`getLocation( ) : void`

`getOwningTarget( ) : void`

`getPassword( ) : void`

`getProject( ) : void`

`getRegisterSlot( ) : void`

`getRuntimeConfigurableWrapper( ) : void`

`getTaskName( ) : void`

`getTaskType( ) : void`

`getUrl( ) : void`

`getUserId( ) : void`

`init( ) : void`

`initFormatters( ) : void`

Initialize the formatters.

`isAutocommit( ) : void`

`isCaching( ) : void`

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

`main( ) : void`

Load the sql file and then execute it

Throws

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

`maybeConfigure( ) : void`

`perform( ) : void`

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

`setCaching( ) : void`

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

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

`setOnerror( $action ) : void`

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

Parameters

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

`setOwningTarget( ) : void`

`setPassword( ) : void`

`setProject( ) : void`

`setRuntimeConfigurableWrapper( ) : void`

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

`setTaskType( ) : void`

`setUrl( ) : void`

`setUserid( ) : void`

`setVersion( ) : void`

## \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
  n/a

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

Type
  n/a

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

Type
  n/a

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