postgresqldatabase-connectionopenedgeprogress-4glprogress-db

Read PostgreSQL tables from an Openedge program


I need to write an Openedge 11.6.4 ABL procedure that automatically:

My problem is in the connection part.

Is that possible?


Solution

  • You can do it with ADODB with a ODBC driver

    Example:

    DEFINE VARIABLE objAdoCon   AS COM-HANDLE NO-UNDO.
    DEFINE VARIABLE objAdoCmd   AS COM-HANDLE NO-UNDO.
    DEFINE VARIABLE objAdoRS    AS COM-HANDLE NO-UNDO.
    
    DEFINE VARIABLE cAdoSql AS CHARACTER   NO-UNDO.
    DEFINE VARIABLE cField AS CHARACTER   NO-UNDO.
    
    /* ODBC Connection */
    CREATE "ADODB.Connection" objAdoCon.
    
    objAdoCon:ConnectionString = "Provider=PostgreSQL OLE DB;" +
                                 "Data Source=myServerAddress;location=myDataBase;User ID=myUsername;password=myPassword".
    
    objAdoCon:OPEN(,,,).  /* makes the connection to the datasource */
    
    /* RecordSet */
    CREATE "ADODB.RecordSet"  objAdoRS.
    objAdoRS:CursorLocation = 3.  // Client
    objAdoRS:CursorType     = 0.  // ForwardOnly
    objAdoRS:locktype       = 3.  // LockOptimistic
    
    cAdoSql = "SELECT * FROM postgreTable".
    
    objAdoRS:OPEN (cAdoSql,objAdoCon,,,).
    
    DO WHILE NOT objAdoRS:eof:
    
     cField = objAdoRS:FIELDS("FieldFromPostgreTable"):VALUE. 
     
     CREATE Customer.
     ASSIGN
        Customer.NAME = cField.
     
     objAdoRS:MoveNext.
     
    END.
       
    
    FINALLY:  
        
    
       objAdoRS:CLOSE NO-ERROR.
       objAdoCon:CLOSE NO-ERROR.
       RELEASE OBJECT objAdoCon NO-ERROR.
       RELEASE OBJECT objAdoRS  NO-ERROR.
       ASSIGN objAdoCon = ?.
       ASSIGN objAdoRS  = ?.     
              
    END FINALLY. 
    

    Some other code samples:

    https://community.progress.com/s/question/0D74Q000007tLORSA2/detail https://www.w3schools.com/asp/ado_connect.asp