# tasks/ext/creole/CreoleSQLExecTask.php

## \CreoleSQLExecTask
jump to top

Package: phing\tasks\ext\creole

Executes a series of SQL statements on a database using Creole.

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)
  \CreoleTask < \Task < \ProjectComponent
Author
  Hans Lellelid (Phing)
Author
  Jeff Martin (Ant)
Author
  Michael McCallum (Ant)
Author
  Tim Stephenson (Ant)
Version
  $Revision: 1084 $

### Constants

`DELIM_ROW = "row"`

`DELIM_NORMAL = "normal"`

### Properties

`$append= 'false'`

Append to an existing file or overwrite it?

Default value `false` Details

Type
  n/a

`$autocommit= 'false'`
inherited

Autocommit flag. Default value is false

Inherited from: \CreoleTask::$$autocommit
Default value `false` Details

Type
  n/a
Inherited_from
  \CreoleTask::$$autocommit

`$caching= 'true'`
inherited Inherited from: \CreoleTask::$$caching
Default value `true` Details

Type
  n/a
Inherited_from
  \CreoleTask::$$caching

`$conn= 'null'`

Database connection

Default value `null` Details

Type
  n/a

`$delimiter= '";"'`

SQL Statement delimiter

Default value`";"`Details

Type
  n/a

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

`$driver= ''`
inherited

[optional] Classpath to Creole driver to use.

Inherited from: \CreoleTask::$$driver
Details

Type
  n/a
Inherited_from
  \CreoleTask::$$driver
$driver

  string

`$encoding= 'null'`

Encoding to use when reading SQL statements from a file

Default value `null` Details

Type
  n/a

`$filesets= 'array()'`

files to load

Default value `array()`Details

Type
  n/a

`$filterChains= 'array()'`

all filterchains objects assigned to this task

Default value `array()`Details

Type
  n/a

`$goodSql= '0'`
Default value `0` Details

Type
  n/a

`$loaderMap= 'array()'`
static inherited

Used for caching loaders / driver. This is to avoid getting an OutOfMemoryError when calling this task multiple times in a row.

Inherited from: \CreoleTask::$$loaderMap

NOT IMPLEMENTED YET

Default value `array()`Details

Type
  n/a
Inherited_from
  \CreoleTask::$$loaderMap

`$onError= '"abort"'`

Action to perform if an error is found

Default value`"abort"`Details

Type
  n/a

`$output= 'null'`

Results Output file.

Default value `null` Details

Type
  n/a

`$password= ''`
inherited

Password

Inherited from: \CreoleTask::$$password
Details

Type
  n/a
Inherited_from
  \CreoleTask::$$password

`$print= 'false'`

Print SQL results.

Default value `false` Details

Type
  n/a

`$rdbms= ''`
inherited

RDBMS Product needed for this SQL.

Inherited from: \CreoleTask::$$rdbms
Details

Type
  n/a
Inherited_from
  \CreoleTask::$$rdbms

`$showheaders= 'true'`

Print header columns.

Default value `true` Details

Type
  n/a

`$sqlCommand= '""'`

SQL input command

Default value`""`Details

Type
  n/a

`$srcFile= 'null'`

SQL input file

Default value `null` Details

Type
  n/a

`$statement= 'null'`

SQL statement

Default value `null` Details

Type
  n/a

`$totalSql= '0'`
Default value `0` Details

Type
  n/a

`$transactions= 'array()'`

SQL transactions to perform

Default value `array()`Details

Type
  n/a

`$url= ''`
inherited

DB url.

Inherited from: \CreoleTask::$$url
Details

Type
  n/a
Inherited_from
  \CreoleTask::$$url

`$userId= ''`
inherited

User name.

Inherited from: \CreoleTask::$$userId
Details

Type
  n/a
Inherited_from
  \CreoleTask::$$userId

### Methods

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

`createFilterChain( ) : object`

Creates a filterchain

Returns

Type | Description
--- | ---
object | The created filterchain object

Details

Access
  public

`createTransaction( ) : void`

Add a SQL transaction to execute

`execSQL( $sql, $out = null ) : void`

Exec the sql statement.

Parameters

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

Throws

Exception | Description
--- | ---
\SQLException |

`getConnection( ) : \Connection`
inherited

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

Inherited from: \CreoleTask::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.

`getDescription( ) : void`
inherited

Inherited from: Task::getDescription()\CreoleTask::getDescription()
`getLoaderMap( ) : void`
inherited

Inherited from: \CreoleTask::getLoaderMap()
`getLocation( ) : void`
inherited

Inherited from: Task::getLocation()\CreoleTask::getLocation()
`getOwningTarget( ) : void`
inherited

Inherited from: Task::getOwningTarget()\CreoleTask::getOwningTarget()
`getPassword( ) : \Returns`
inherited

Gets the password.

Inherited from: \CreoleTask::getPassword()
Returns

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

`getProject( ) : void`
inherited

Inherited from: ProjectComponent::getProject()\CreoleTask::getProject()
`getRegisterSlot( ) : void`
inherited

Inherited from: Task::getRegisterSlot()\CreoleTask::getRegisterSlot()
`getRuntimeConfigurableWrapper( ) : void`
inherited

Inherited from: Task::getRuntimeConfigurableWrapper()\CreoleTask::getRuntimeConfigurableWrapper()
`getTaskName( ) : void`
inherited

Inherited from: Task::getTaskName()\CreoleTask::getTaskName()
`getTaskType( ) : void`
inherited

Inherited from: Task::getTaskType()\CreoleTask::getTaskType()
`getUrl( ) : \Returns`
inherited

Gets the url.

Inherited from: \CreoleTask::getUrl()
Returns

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

`getUserId( ) : \Returns`
inherited

Gets the userId.

Inherited from: \CreoleTask::getUserId()
Returns

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

`init( ) : void`
inherited

Initialize CreoleTask.

Inherited from: \CreoleTask::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.

`isAutocommit( ) : \Returns`
inherited

Gets the autocommit.

Inherited from: \CreoleTask::isAutocommit()
Returns

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

`isCaching( $value ) : void`
inherited

Inherited from: \CreoleTask::isCaching()
Parameters

Name | Type | Description
--- | --- | ---
$value |  |

`log( ) : void`
inherited

Inherited from: Task::log()\CreoleTask::log()
`main( ) : void`

Load the sql file and then execute it

Throws

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

`maybeConfigure( ) : void`
inherited

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

Inherited from: Task::perform()\CreoleTask::perform()
`printResults( $out = null ) : void`

print any results in the statement.

Parameters

Name | Type | Description
--- | --- | ---
$out |  |

Throws

Exception | Description
--- | ---
\SQLException |

`runStatements( $reader, $out = null ) : void`

read in lines and execute them

Parameters

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

Throws

Exception | Description
--- | ---
\SQLException, | IOException

`setAppend( $append ) : void`

whether output should be appended to or overwrite an existing file. Defaults to false.

Parameters

Name | Type | Description
--- | --- | ---
$append |  |

`setAutocommit( \autocommit $autocommit ) : void`
inherited

Auto commit flag for database connection; optional, default false.

Inherited from: \CreoleTask::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: \CreoleTask::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( ) : void`
inherited

Inherited from: Task::setDescription()\CreoleTask::setDescription()
`setDriver( string $driver ) : void`
inherited

Set the Creole driver to be used.

Inherited from: \CreoleTask::setDriver()
Parameters

Name | Type | Description
--- | --- | ---
$driver | string | driver class name

`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

`setLocation( ) : void`
inherited

Inherited from: Task::setLocation()\CreoleTask::setLocation()
`setOnerror( $action ) : void`

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

Parameters

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

`setOutput( \PhingFile $output ) : void`

Set the output file; optional, defaults to the console.

Parameters

Name | Type | Description
--- | --- | ---
$output | \PhingFile |

`setOwningTarget( ) : void`
inherited

Inherited from: Task::setOwningTarget()\CreoleTask::setOwningTarget()
`setPassword( \password $password ) : void`
inherited

Sets the password; required.

Inherited from: \CreoleTask::setPassword()
Parameters

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

`setPrint( boolean $print ) : void`

Set the print flag.

Parameters

Name | Type | Description
--- | --- | ---
$print | boolean |

`setProject( ) : void`
inherited

Inherited from: ProjectComponent::setProject()\CreoleTask::setProject()
`setRuntimeConfigurableWrapper( ) : void`
inherited

Inherited from: Task::setRuntimeConfigurableWrapper()\CreoleTask::setRuntimeConfigurableWrapper()
`setShowheaders( boolean $showheaders ) : void`

Print headers for result sets from the statements; optional, default true.

Parameters

Name | Type | Description
--- | --- | ---
$showheaders | boolean |

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

Inherited from: Task::setTaskName()\CreoleTask::setTaskName()
`setTaskType( ) : void`
inherited

Inherited from: Task::setTaskType()\CreoleTask::setTaskType()
`setUrl( \url $url ) : void`
inherited

Sets the database connection URL; required.

Inherited from: \CreoleTask::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: \CreoleTask::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: \CreoleTask::setVersion()
Parameters

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

## \SQLExecTransaction
jump to top

Package: phing\tasks\ext\creole

"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( $out = null ) : void`

Parameters

Name | Type | Description
--- | --- | ---
$out |  |

Throws

Exception | Description
--- | ---
\IOException, | SQLException

`setSrc( $src ) : void`

Parameters

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

Documentation was generated by DocBlox 0.17.1.