Forum Discussion

agvillamizar's avatar
agvillamizar
New Contributor
12 years ago

Passing parameters to a Query in a keyword test.

Hello



I need some help with keyword testing.



I have a table with some fields and i need  to compare it with another table with the same fields. I need to find the differences between each field of both tables.



I created a driven data loop with a custom query for iterate the first table but i need to pass some parameters to the query.



Select* from table where date between :param1 and :param2



how can i pass those parameters to the query in a keyword test?



i tried to concatenate the query but i was incapable of return the name of columns when i try to get the values from the tables



Really thank you for the help
  • gid_216's avatar
    gid_216
    Frequent Contributor
    I don't think through keywrd tests we can handle parameterized queries.



    Better create a procedure to handle db queries where you can handle parameterized queries.



    If you are getting any solution post here.
  • I could do it with scripting test



    Thank for answer



    i got the result set for the first parameterized query and then, iterated it. for each row, i made a second query for comparing the two fields of the tables.



    i had to create two connections to the same string connection for executing both query, the question is that if there is a way to execute different query using the same connection?



    thanks  



    //////////////////////////////////////////////////////////////////////




    var Qry;

        Qry = ADO.CreateADOQuery();



        Qry.ConnectionString = "Provider=IBMDA400.DataSource.1;Password=xxx;"+

        "Persist Security Info=True;User ID=xxx;Data Source=xxxx";



        var query=  "Select* from table where date between  " + param1 + "  and  " + param2;

         

        Qry.SQL = query;



        Qry.Open();



        Qry.First();

     

        while (! Qry.EOF)

        {





        var Qry2;

        Qry2 = ADO.CreateADOQuery();



        Qry2.ConnectionString = "Provider=IBMDA400.DataSource.1;Password=xxx;"+

        "Persist Security Info=True;User ID=xxx;Data Source=xxxx";



        var query=  "Select* from table2 where field = " + Qry.FieldByName("xxx").Value;

         

        Qry2.SQL = query;



        Qry2.Open();



        Qry2.First();

     

        while (! Qry2.EOF)

        {

           //Comparing

            aqObject.CompareProperty(Qry.FieldByName("xxx").Value, cmpEqual, Qry2.FieldByName("xxx").Value, true, 3);



           Qry2.Next();

        };

       

        Qry2.Close();







        Qry.Next();

        };

       

        Qry.Close();







  • gid_216's avatar
    gid_216
    Frequent Contributor
    Why don't you use joins to form your query, with this, you don't have to create two differnt objects.



    For different queries with same connection, Parameterize the procedure that will take query as string and use that strin variable in the procedure/function.