# <sql>

[This is preliminary documentation and subject to change.]

A task to execute arbitrary SQL statements against a OLEDB data source.

You can specify a set of sql statements inside the sql element, or execute them from a text file that contains them. You can also choose to execute the statements in a single batch, or execute them one by one (even inside a transaction, if you want to).

### Parameters

Attribute | Type | Description | Required
--- | --- | --- | ---
connstring | string | Connection string used to access database. This should be an OleDB connection string. | True
delimiter | string | String that separates statements from one another. | True
delimstyle | DelimiterStyle | Kind of delimiter used. Allowed values are Normal or Line. | True
append | bool | Whether output should be appended to or overwrite an existing file. The default is false. | False
batch | bool | If true, the statements will be executed as a single batch. If false, they will be executed one by one. Default is true. | False
cmdtimeout | int | Command timeout to use when creating commands. | False
encoding | Encoding | The encoding of the files containing SQL statements. The default is the system's current ANSI code page. | False
expandprops | bool | If true, the any nant-style properties on the sql will be expanded before execution. Default is true. | False
output | string | If set, the results from the statements will be output to the specified file. | False
print | bool | If set to true, results from the statements will be output to the build log. | False
quotechar | string | The character(s) to surround result columns with when printing, the default is an empty string. | False
showheaders | bool | If set to true, prints headers for result sets. The default is true. | False
source | string | File where the sql statements are defined. | False
transaction | bool | If set to true, all statements will be executed within a single transaction. The default is true. | False
failonerror | bool | Determines if task failure stops the build, or is just reported. The default is true. | False
if | bool | If true then the task will be executed; otherwise, skipped. The default is true. | False
unless | bool | Opposite of `if`. If false then the task will be executed; otherwise, skipped. The default is false. | False
verbose | bool | Determines whether the task should report detailed build log messages. The default is false. | False

### Examples

- Execute a set of statements inside a transaction.

      <sql
          connstring="Provider=SQLOLEDB;Data Source=localhost; Initial Catalog=Pruebas; Integrated Security=SSPI"
          transaction="true"
          delimiter=";"
          delimstyle="Normal"
      >
          INSERT INTO jobs (job_desc, min_lvl, max_lvl) VALUES('My Job', 22, 45);
          INSERT INTO jobs (job_desc, min_lvl, max_lvl) VALUES('Other Job', 09, 43);
          SELECT * FROM jobs;
      </sql>

- Execute a set of statements from a file and write all query results to a file.

      <sql
          connstring="Provider=SQLOLEDB;Data Source=localhost; Initial Catalog=Pruebas; Integrated Security=SSPI"
          transaction="true"
          delimiter=";"
          delimstyle="Normal"
          print="true"
          source="sql.txt"
          output="${outputdir}/results.txt"
      />

- Execute a SQL script generated by SQL Server Enterprise Manager.

      <sql
          connstring="Provider=SQLOLEDB;Data Source=localhost; Initial Catalog=Pruebas; Integrated Security=SSPI"
          transaction="true"
          delimiter="GO"
          delimstyle="Line"
          print="true"
          source="pubs.xml"
          batch="false"
          output="${outputdir}/results.txt"
      />

### Requirements

Assembly: NAnt.Contrib.Tasks (0.93.5002.0)