Eviware Forum

soapUI => soapUI => Topic started by: Juergen on November 29, 2007, 04:19:20 pm



Title: Groovy Script SQL - Problems with the assignment of variables
Post by: Juergen on November 29, 2007, 04:19:20 pm
I have the following problem I liked to select from a data bank a Sequence TEST_CASE_ID_SEQ and write this afterwards
in another table. Unfortunately, the handing over of the variable TEST_CASE_ID_SEQ into the variable TEST_CASE_ID does not work.
However, I get only the value 'null' I have written the following script.

What do I make wrong ??

##########################
import java.sql.Connection
import java.sql.DriverManager
import javax.sql.DataSource
import groovy.sql.Sql
import oracle.jdbc.driver.OracleTypes
import groovy.sql.DataSet


def driver = oracle.jdbc.driver.OracleDriver
def sql = Sql.newInstance ('jdbc:oracle:thin:pt_xxx/pt_xxx@localhost:31521:pt_xxx')

def TEST_CASE_ID_SEQ
def TEST_CASE_ID

//READ next Value of TEST_CASE_ID_SEQ
TEST_CASE_ID = sql.eachRow("SELECT TEST_CASE_ID_SEQ.nextval as TEST_CASE_ID_SEQ from dual")
{
}

println TEST_CASE_ID
// result null

//Write Value TEST_CASE_ID
//TEST_CASE_ID = "2345"
sql.execute("Insert into log TEST_CASE_ID values (?)", [TEST_CASE_ID])
#####################

Thanks and best regards

Juergen


Title: Re: Groovy Script SQL - Problems with the assignment of variables
Post by: omatzura on November 29, 2007, 07:59:16 pm
Hi Juergen,

I think the problem is the statement

//READ next Value of TEST_CASE_ID_SEQ
TEST_CASE_ID = sql.eachRow("SELECT TEST_CASE_ID_SEQ.nextval as TEST_CASE_ID_SEQ from dual")
{
}

please try the following instead:

sql.eachRow("SELECT TEST_CASE_ID_SEQ.nextval as TEST_CASE_ID_SEQ from dual")
{
    row -> TEST_CASE_ID = row[0]
}

Hope this helps!

regards,

/Ole
eviware.com