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!