Forum Discussion

CraigTM's avatar
CraigTM
New Contributor
13 years ago

Dynamic query construction in JDBC request

I realize that this is posted in the SoapUI section and not the Pro section, but I'm not masked to post in that area. Please move the topic if necessary, but I'm blocked on this problem so I'm posting now in hopes of finding an answer sooner rather than later.

My problem is this: I have a query like

SELECT * FROM foo
WHERE item IN (item1, item2, item3, etc.);

The JDBC Request test step requires me to build the query like this:

SELECT * FROM foo
WHERE item IN (:item1, :item2, :item3);

The problem is that this requires me to know in advance how many "items" will be in the IN list. That doesn't really work for me. What I need is to be able to dynamically build a variable-length list of items. It may be only item1, or it may be items 1 to 100. Basically, what I want to do is this:

:item_list = 'value 1', 'value 2', 'value 3', 'value 4'

SELECT * FROM foo
WHERE item IN (:item_list);

Is this possible? Is there another way to accomplish this same goal?

Thanks in advance!
-Craig

2 Replies

  • CraigTM's avatar
    CraigTM
    New Contributor
    I spammed the admins asking them to fix my account so I could post in the Pro section, but it's been a while (a week or more) with no response, and my account is still not masked correctly.

    Anyhow, my question seems pretty simple, and I'd be surprised if someone hasn't attempted to do what I'm trying to do.
  • why don't you simply iterate through your item_list?


    item_list = ['value 1', 'value 2', 'value 3', 'value 4']

    query = 'SELECT * FROM foo WHERE item IN ('

    item_list.each{
    query += it + ','
    }
    query = query[0 .. -2] + ')'