Forum Discussion

mpolamuri's avatar
mpolamuri
Occasional Contributor
8 years ago

I want to integrate Test Complete with Postgres DB

I want to integrate Test Complete with Postgres DB? how to establish connects, Please provide steps 

In help there is no specific about integration Postgress DB with Test-complete  

  • ast's avatar
    ast
    8 years ago

    Hi there

    I got a connection:
    1. Installed an appropriate ODBC driver (same version as postgreSQL-DB) from https://www.postgresql.org/ftp/odbc/versions/msi/
    2. Got the connection string from https://www.connectionstrings.com/postgresql-odbc-driver-psqlodbc/

    Example of my code:

    function letsTest() {
        Log.Message(select("select * from config where configkey='smtpHost'", "configstring"));
    }

    function createAdoQuery(sqlStatement) {
      var query = ADO.CreateADOQuery();
      query.ConnectionString = "Driver={PostgreSQL ANSI};Server=<MyIP>;Port=<MyPort>;Database=<MyDB>;Uid=<MyDbUsername>;Pwd=<MyDbPassword>;";
      query.SQL = sqlStatement;
      return query;
    }

    function select(sqlStatement, columnName) {
      var query = createAdoQuery(sqlStatement);
      query.Open();
     
      var result;
      var noOfRecords = query.RecordCount;
      if (noOfRecords == 1) {     // I only expect one result
        query.First();
        while (! query.EOF)
        {
          result = query.FieldByName(columnName).Value;
          query.Next();
        }
      } else {
        Log.Error("There are " + noOfRecords + " records instead of one ?!")
      }

      query.Close();
      return result;
    }

     

    Have fun!

    • ast's avatar
      ast
      Contributor

      Hi there

      I got a connection:
      1. Installed an appropriate ODBC driver (same version as postgreSQL-DB) from https://www.postgresql.org/ftp/odbc/versions/msi/
      2. Got the connection string from https://www.connectionstrings.com/postgresql-odbc-driver-psqlodbc/

      Example of my code:

      function letsTest() {
          Log.Message(select("select * from config where configkey='smtpHost'", "configstring"));
      }

      function createAdoQuery(sqlStatement) {
        var query = ADO.CreateADOQuery();
        query.ConnectionString = "Driver={PostgreSQL ANSI};Server=<MyIP>;Port=<MyPort>;Database=<MyDB>;Uid=<MyDbUsername>;Pwd=<MyDbPassword>;";
        query.SQL = sqlStatement;
        return query;
      }

      function select(sqlStatement, columnName) {
        var query = createAdoQuery(sqlStatement);
        query.Open();
       
        var result;
        var noOfRecords = query.RecordCount;
        if (noOfRecords == 1) {     // I only expect one result
          query.First();
          while (! query.EOF)
          {
            result = query.FieldByName(columnName).Value;
            query.Next();
          }
        } else {
          Log.Error("There are " + noOfRecords + " records instead of one ?!")
        }

        query.Close();
        return result;
      }

       

      Have fun!

      • maxtester's avatar
        maxtester
        Contributor

        Hi,

         

        I am facing the same problem. I have installed the driver and I also have a connection string that should work (based on the link). The Problem is, that I get an error message: "Unspecified error".

        I don't know what to do with this message. The database is online, users are correct and I can create an ODBC Data Source. Can anybody help me out?

  • nitingambhir88's avatar
    nitingambhir88
    Occasional Contributor

    https://community.smartbear.com/t5/TestComplete-Desktop-Testing/I-want-to-integrate-Test-Complete-with-Postgres-DB/td-p/136731

     

    With the help of above thread, I am successfully able to get the results from my database. But, it provides with only one result at one time, as the code states --  if (noOfRecords == 1) .

    My query gives multiple rows, and hence the error. What could be the best possible solution for this.

     

    Also, i want to email the results of this query. Please suggest.

     

    Thanks,

    -Nitin