Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Environment variable in Database Data Source SQL query

apitester
apitester Posts: 6

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

  • jakubiak
    jakubiak Posts: 795 admin

    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

  • apitester
    apitester Posts: 6
    edited October 2019

    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

  • mthello
    mthello Posts: 1

    @apitester @jakubiak Anyone have a solution? I have the exact same problem. I am using Soatest 9.9.

  • goofy78270
    goofy78270 Posts: 133

    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)
    }

  • apitester
    apitester Posts: 6

    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!!

  • jakubiak
    jakubiak Posts: 795 admin

    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.

  • apitester
    apitester Posts: 6

    thank you so much @jakubiak...I will try reaching out to Parasoft support directly