Reputation: 21
I am writing a JDBC test plan for Add and Delete records. I have extracted queries from SQL Express Profiler for ADD and Delete. Now when i run JDBC request for add and delete then record is added but same record not deleted. because delete query having different unique key (e.g.35) of record which was added when query was taken from express profiler. Every time i run add jdbc request then new record having different value i.e. incremented. Is there any way to extract unique key from Jdbc request of ADD and use it in Delete JDBC request so that same record could be deleted?
Response of ADD JDBC Request:
Delete query where i want to use unique value from response of ADD request:
Upvotes: 2
Views: 6471
Reputation: 23
You can solve this using the varible field that you have in your JDBC Request sampler. More information on the parameters used in JDBC requests are found here: https://jmeter.apache.org/usermanual/component_reference.html#JDBC_Request
Let me explain how to use them with your problem as an example:
For the ADD query enter the variable name in the Variables Names field:
ScopeIdentity
This will result in the thread local value for Scopeidentity being saved in a variable named "Scopeidentity" with a suflix of the thread-number. So for one-thread scenario the variable is ScopeIdentity_1
For the DELETE query enter this where you want to refer to the value:
${__V(Scopeidentity_${__threadNum})}
Where ${__threadNum} gives the number of the current thread. https://jmeter.apache.org/usermanual/functions.html#__threadNum
Where ${__V()} is used to nest the variable name and the result of __threadNum. https://jmeter.apache.org/usermanual/functions.html#what_can_do
Upvotes: 1
Reputation: 318
Response for Add request wouldn't retrieve your unique_id.
Add an additional step between ADD and DELETE as below:
SELECT TOP 1 unique_id
FROM table
WHERE condition
order by unique_id desc;
Store this response to a variable and use it in the DELETE statement.
Upvotes: 0
Reputation: 168002
In JDBC Request sampler you have Variable Names
input where you can specify the JMeter Variables which will hold the results values. So given you put ScopeIdentity
there most likely you will be able to refer its value later on as ${ScopeIdentity_1}
References:
Upvotes: 2