Environment variable in Database Data Source SQL query
Hi,
I would like to know if an environment variable can actually be used in Database Data Source SQL query.I tried the below options & they did not seem to work. Any help would really be appreciated. I have a bunch of tests written already using the database data source already & I I would like to know if it is possible to use environment variable in database datasource instead of using a db tool
select * from ${db_schema}
select * from ${soa_env:db_schema}
Comments
-
In data sources, you need to use the soa_env prefix to reference environment variables. For example, ${soa_env:Variable}. See https://docs.parasoft.com/display/SOAVIRT9107CTP313/Configuring+Testing+in+Different+Environments#ConfiguringTestinginDifferentEnvironments-UsingEnvironmentVariablesinTests
0 -
Thank you so much!! I tried using the soa_env prefix in database datasource query but it did not work. I defined an Environment variable with Name db_schema & Value mytable.
Select * from mytable works but Select * from ${soa_env:db_schema} does not seem to work. On clicking Show columns error message "Can not execute query." is displayed
1 -
@apitester @jakubiak Anyone have a solution? I have the exact same problem. I am using Soatest 9.9.
0 -
I think you are looking for a local environment variable within your tst. If so, you can use this.
import com.parasoft.api.*
import java.lang.*
import java.util.*
import soaptest.api.*public String getDSVariable(input, ScriptingContext context)
{
envDS = context.getEnvironmentVariableValue("dataSourceEnv")
Application.showMessage("envDS: " + envDS)
}0 -
Thanks for the answer @goofy78270. Please note that I am not using an extension tool for scripting. I was unable to use a environment variable in Database Data Source SQL query. @jakubiak, ${soa_env:Variable} did not work within Database Data Source SQL query unfortunately.
Any other suggestions would really help!!
0 -
I just tried it myself and it works. I added an environment variable to a new environment in my .tst file, and then I referenced the variable simplying using the syntax ${varName}. And it just works. So there may be something specific to your environment going on? You may want to consider reaching out to Parasoft support directly.
0