<sql>

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

AttributeTypeDescriptionRequired
connstringstring Connection string used to access database. This should be an OleDB connection string. True
delimiterstring String that separates statements from one another. True
delimstyleNAnt.Contrib.Util.DelimiterStyle Kind of delimiter used. Allowed values are Normal or Line. True
batchbool If true, the statements will be executed as a single batch. If false, they will be executed one by one. Default is true. False
cmdtimeoutint Command timeout to use when creating commands. False
expandpropsbool If true, the any nant-style properties on the sql will be expanded before execution. Default is true. False
outputstring If set, the results from the statements will be output to the specified file. False
printbool If set to true, results from the statements will be output to the build log. False
sourcestring File where the sql statements are defined. False
transactionbool If set to true, all statements will be executed within a single transaction. The default is true. False
failonerrorboolFalse
ifboolFalse
unlessboolFalse
verboseboolFalse

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"
            />