<sql>
A task to execute arbitrary SQL statements against an 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). Attribute | Description | Required |
|---|
connstring | Connection string used to access database. This should be an OLEDB connection string. | True | source | File where the SQL statements are defined. You cannot specify both a source and an inline set of statements. | False | delimiter | String that separates statements from one another. | True | batch | If true, the statements will be executed as a single batch. If false, they will be executed one by one. Default is true. | False | expandprops | If true, then any NAnt-style properties on the SQL will be expanded before execution. Default is true. | False | delimstyle | Delimiters can be of two kinds: Normal delimiters are always specified inline, so they permit having two different statements in the same line. Line delimiters, however, need to be in a line by their own. Default is Normal. | True if using delimiter | print | If set to true, results from the statements will be output to the build log. | False | output | If set, the results from the statements will be output to the specified file. | False | transaction | If set to true, all statements will be executed within a single transaction. Default value is true. | False | failonerror | Determines whether task failure stops the build or is just reported. Default is "true." | False | verbose | Task reports detailed build log messages. Default is "false." | False | if | If true then the task will be executed; otherwise skipped. Default is "true." | False | unless | Opposite of if. If false then the task will be executed; otherwise skipped. Default is "false." | False |
Examples
Inline
<sql
connstring="Provider=SQLOLEDB;Data Source=localhost; Initial Catalog=Pruebas;
Integrated Security=SSPI"
transaction="true"
delimiter=";">
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=";"
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" />
|