Forum Discussion

_ivanovich_'s avatar
_ivanovich_
Frequent Contributor
5 years ago
Solved

How to simplify groovy code for several sql request in different table ?

Hi, how can we simplify a groovy code for several sql request which are not same. i'm querying different table for different data so i have at least 50 sql queries and for each query i set proper...
  • JHunt's avatar
    5 years ago

    I would probably just put the results into the test run context.

    context.type = sql.firstRow('select type from order where id = ?', ["abc123"]).type
    context.name = sql.firstRow('select name from product where desc = ?', ["yzx"]).name

    That form uses prepared statements, which you should be doing and is not much more difficult.

     

    To get the values in a request's body:

    ${type}
    ${name}

    To get the values in another groovy script:

    context.type
    context.name