-
Notifications
You must be signed in to change notification settings - Fork 12
Replacing tokens in SQL queries
Jakub Raczek edited this page Mar 14, 2020
·
3 revisions
We attached example of ANT build.xml script to demonstrate one of way how to replace tokens in SQL queries:
Ant and Maven must be installed first.
Passing values of parameters datefrom and dateto by ANT:
In main folder run command
ant -buildfile ./deploy/build.xml tokens.copy.files,testdbq.run -Dconfig=DEV03 -Ddatefrom="2003-02-21 00:00:00.000" -Ddateto="2004-02-21 00:00:00.000"
Implementation of replacing tokens in Sql queries by values passed to ANT build.xml scripts:
<replace dir="${dist}\test-definitions\" includes="**\*.sql,**\*.xml" excludes="cmpSqlResults-config.xml" summary="true" failOnNoReplacements="true" >
<replacefilter
token="@datefrom@"
value="${datefrom}"/>
<replacefilter
token="@dateto@"
value="${dateto}"/>
</replace>
Use parameters @datefrom@ and @dateto@ in SQL query:
<cmpSqlResultsTest>
<compare mode="FETCH" fetchSize="100" chunk="10" diffTableSize="5" fileOutputOn="false">
<sql datasourceName="SQL_SERVER">
<![CDATA[
SELECT [AddressID]
,[AddressLine1]
,[AddressLine2]
,[City]
,[StateProvinceID]
,[PostalCode]
,convert(varchar(30),[ModifiedDate],121)
FROM [AdventureWorks2008R2].[Person].[Address]
WHERE ModifiedDate BETWEEN '@datefrom@' AND '@dateto@'
order by AddressID
]]>
</sql>
<sql datasourceName="PostgreSQL">
<![CDATA[
SELECT addressid, addressline1, addressline2, city, stateprovinceid, postalcode, modifieddate
FROM public.personaddress
WHERE modifieddate BETWEEN '@datefrom@' AND '@dateto@'
order by addressid;
]]>
</sql>
</compare>
</cmpSqlResultsTest>
- Home
- Getting started
- Command line parameters
- Deploying licensed jdbc drivers
- Comparators
- Fetch
- KEY
- Minus
- NMB_OF_RESULTS
- FILE
- OLAP
- Building multilevel tests structure
- TeamCity support
- Test definitions
- Filtering tests for execution
- Test report
- Compiling, replacing tokens in connection definition
- Replacing tokens in SQL queries
- Execute Stored Procedure before test