Forum Discussion

sriram_sig's avatar
sriram_sig
Contributor
6 years ago
Solved

How to make TestComplete execute custom sql queries with a variable name in where condition

I'm trying to add Database checkpoint by specifying a custom sql query like

Select * from Table1 where EmployeeID = id

In the previous step i fetch the value from the UI and store it in the id variable. But when i execute the test

DBTables.CheckNotification.RowCount

it is fetching the count of all the records in the table, rather than the specific record with the id. the previous line in the code to fetch the id from UI is working good

 

  • What method are you using to connect to SQL ? The syntax for a SQL query in ADO for example looks different than the SQL query you would use in a standard SQL and it may be that your query isn't sending the parameter correctly.  

     

    So for example your ADO command would specify the query as follows:

     

    var ADOConnection = ADO.CreateConnection();
    //Configure the ADOConnection var ADOCommand = ADO.CreateCommand();
    //Configure the ADOCommand

    ADOCommand.CommandText='select * from Table1 where Employeeid=? and EmployeeName=?'; //Here's the important bit: ADOCommand.Parameters.Item(0) = employeeIDValue; ADOCommand.Parameters.Item(1) = emplayeeNameValue; var RecordSet = ADOCommand.Execute(); //etc...

     

     

6 Replies

  • What method are you using to connect to SQL ? The syntax for a SQL query in ADO for example looks different than the SQL query you would use in a standard SQL and it may be that your query isn't sending the parameter correctly.  

     

    So for example your ADO command would specify the query as follows:

     

    var ADOConnection = ADO.CreateConnection();
    //Configure the ADOConnection var ADOCommand = ADO.CreateCommand();
    //Configure the ADOCommand

    ADOCommand.CommandText='select * from Table1 where Employeeid=? and EmployeeName=?'; //Here's the important bit: ADOCommand.Parameters.Item(0) = employeeIDValue; ADOCommand.Parameters.Item(1) = emplayeeNameValue; var RecordSet = ADOCommand.Execute(); //etc...

     

     

    • sriram_sig's avatar
      sriram_sig
      Contributor

      RUDOLF_BOTHMA i have used ADO.CreateConnection before and used the exact same piece of code to connect to db and fetch results. My question here is specific to the step where we can add custom sql queries while adding a DB checkpoint, how do i replace a variable in the where condition in this case. I'm able to fetch results and get recordcount, when i just mention a harcoded value instead of the variable. using the below code

      DBTables.DBTable1.RowCount

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        This is one of the limitations of DB Checkpoints.  They don't allow for passing in variables.  Hence why RUDOLF_BOTHMA  suggested you use the ADO connections to build and create your own comparison code.