Forum Discussion

alibaba82's avatar
alibaba82
Super Contributor
16 years ago

how to get rowcount from jdbc datasource

Hello,
I have a jdbc datasource as a test step. I want to do something like this is my next groovy step.

if (rowcount in jdbc datasource step > 84)
throw new exception ('foo bar')

how can I access the row_count attribute ?

Thanks

Ali

7 Replies

  • omatzura's avatar
    omatzura
    Super Contributor
    Hi Ali,

    by "row_count" do you mean the number of rows that have been retrieved, or the number of rows available?

    regards!

    /Ole
    eviware.com
  • alibaba82's avatar
    alibaba82
    Super Contributor
    Also I would like to get the items in the datasource. How can I iterate over the items returned by the datasource.

    Thanks

    Ali
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi Ali,

    soapUI doesn't prefetch all data, so the number of rows is not available until the DataSource has been exhausted..

    Regarding the iterating, do you want to iterate the DataSource from a groovy script, and extract the items for each row?

    regards,

    /Ole
    eviware.com
  • alibaba82's avatar
    alibaba82
    Super Contributor
    so basically I have a test case with 2 steps.
    step1: JDBC datasource has a simple query like
    select itemid from tableA

    For this test to pass I would like the query to return 0 records, if it fails then I would like to throw an exception displaying all the itemid from the query.

    my current step 2 is like this

    if(testRunner.testCase.testSteps["jdbc_datasource"].currentRow) != 0)
      throw new Exceptions ("query returned some results --> Error")

    I want something like this instead
    if(testRunner.testCase.testSteps["jdbc_datasource"].currentRow) != 0)
      throw new Exceptions (Item1, Item2,...,Itemn)


    how can I do this
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi Ali,

    ok.. you would have to loop the rows to get all item values and then dump the resul, try the following:

    if(testRunner.testCase.testSteps["jdbc_datasource"].currentRow) != 0)
    {
      def ds = testRunner.testCase.testSteps["jdbc_datasource"]
        def list = [ds.getPropertyValue( "itemid" )]
        while( ds.next( testRunner, context ))
            list.add( ds.getPropertyValue( "itemid" ) )

        throw new Exception( list.toString() )
    }


    Does that work?

    regards,

    /Ole
    eviware.com