connecting to PostgreSQL using SQL RDD

61 views
Skip to first unread message

User For Sites

unread,
Jul 30, 2025, 1:35:06 AMJul 30
to Harbour Minigui
Is there an example for connecting to PostgreSQL using SQL RDD? I've tried, but I don't know where to get the libpq.dll file. I'd also like to know which libraries I need to link at compile time and which header file I need to include.
The examples included in the PRO version, which access MySQL using sqlrdd, work perfectly, but I don't see any examples with PostgreSQL. I have the PRO version from July 2025.

Grigory Filatov

unread,
Jul 30, 2025, 2:51:43 AMJul 30
to Harbour Minigui
Hi,

Thanks for your request!

You can see a minimal example below.

// SQLRDD
// test with PostgreSQL
// To compile:
// hbmk2 pgsql1 -llibpq

#include "sqlrdd.ch"

// Make a copy of this file and change the values below.
// NOTE: the database must exist before runnning the test.
#define SERVER "localhost"
#define UID    "postgres"
#define PWD    "password"
#define DTB    "dbtest"

REQUEST SQLRDD
REQUEST SR_PGS

PROCEDURE Main()

   LOCAL nConnection
   LOCAL n

   setMode(25, 80)

   rddSetDefault("SQLRDD")

   nConnection := sr_AddConnection(CONNECT_POSTGRES, "PGS=" + SERVER + ";UID=" + UID + ";PWD=" + PWD + ";DTB=" + DTB)

   IF nConnection < 0
      alert("Connection error. See sqlerror.log for details.")
      QUIT
   ENDIF
   
   sr_StartLog(nConnection)

   IF !sr_ExistTable("test")
      dbCreate("test", {{"ID",      "N", 10, 0}, ;
                        {"FIRST",   "C", 30, 0}, ;
                        {"LAST",    "C", 30, 0}, ;
                        {"AGE",     "N",  3, 0}, ;
                        {"DATE",    "D",  8, 0}, ;
                        {"MARRIED", "L",  1, 0}, ;
                        {"VALUE",   "N", 12, 2}}, "SQLRDD")
   ENDIF

   USE test EXCLUSIVE VIA "SQLRDD"

   IF reccount() < 100
      FOR n := 1 TO 100
         APPEND BLANK
         REPLACE ID      WITH n
         REPLACE FIRST   WITH "FIRST" + hb_ntos(n)
         REPLACE LAST    WITH "LAST" + hb_ntos(n)
         REPLACE AGE     WITH n + 18
         REPLACE DATE    WITH date() - n
         REPLACE MARRIED WITH iif(n / 2 == int(n / 2), .T., .F.)
         REPLACE VALUE   WITH n * 1000 / 100
      NEXT n
   ENDIF

   GO TOP

   browse()

   CLOSE DATABASE
   
   sr_StopLog(nConnection)
   
   sr_EndConnection(nConnection)

RETURN

Hope this is helpful.

Best regards,
Grigory

среда, 30 июля 2025 г. в 07:35:06 UTC+2, userfor...@gmail.com:
Reply all
Reply to author
Forward
0 new messages