PostgreSQL hbpgsql.lib vs rddsql + sddpg

202 views
Skip to first unread message

Kaddath

unread,
Jul 9, 2020, 9:43:25 PM7/9/20
to Harbour Developers
Hi everyone:

I'm trying to get our app connect to a PostgreSQL database (disclaimer: I know next to nothing about PostgreSQL).

After compiling hbpgsql.lib (and libpq.lib import library) as well as rddsql + sddpg  I notice the following difference just connecting to the database

Via TPQserver() class (in hbpgsql.lib) I can connect and obtain a pointer to said connection, but using rddInfo( RDDI_CONNECT, { "PostgreSQL", string } ) never works - connection handle is always zero but error no is also zero and error description is blank (and therefore attempt to open a table via SQLMIX rdd will fail).



I created this small sample (database name, user and pwd are not the actual ones but you get the picture):

sddtest1.prg
#require "rddsql"
#require "sddpg"
#require "hbpgsql"

#include "postgres.ch"
#include "dbInfo.ch"

ANNOUNCE RDDSYS

REQUEST SQLMIX

PROCEDURE
Main()
   
local nConn
   
local cHost := "127.0.0.1"
   
local cUser := "username"
   
local cPwd  := "password"
   
local cDB   := "database"
   
local nPort := 5432
   
local oPG

   CLS

   rddSetDefault
( "SQLMIX" )
   
? "RDD list:"
   
AEval( rddList(), {|x| qout(x) } )
   
?
   
? "Default RDD:"
   
? RddSetDefault()

   oPG
:= TPQserver():New( cHost, cDB, cUser, cPwd, nPort )   // internally calls PQconnectdb() and connects just fine

   
if oPG:NetErr()
     
? oPG:ErrorMsg()
     
// if f.e., I send the wrong pwd the error msg would be:  FATAL:  password authentication failed for user "postgres"
   
else
     
? "Successfully connected via hbpgsql.lib"
     
? "Pointer to the postgreSQL db is ", oPG:pDB
   endif
   oPG
:Destroy()
   
?
   
? "-------"

   
// this one also calls PQconnectdb(), yet it fails to connect always returning ZERO, yet no error code/message is provided
   nConn
:= rddInfo( RDDI_CONNECT, { "PostgreSQL", "dbname = " + cDB + " host = " + cHost + " user = " + cUser + " password = " + cPwd + " port = " +  hb_ntos( nPort ) } )
   
//nConn := rddInfo( RDDI_CONNECT, { "PostgreSQL", cHost, cUser, cPwd, cDB, hb_ntos( nPort ), nil, nil } )

   
? nConn

   
if nConn == 0
     
? "Connection error - " + LTrim( Str( rddInfo( RDDI_ERRORNO ) ) ) + ": " + rddInfo( RDDI_ERROR )
     
// here error no is always 0 and error text always blank :-(
   
else
     
? rddName()
   endif

   dbUseArea
( .t., "SQLMIX", "SELECT * FROM law1", "pgNames", , , , nConn )

   dbGoTop
()
   
Browse()
   dbCloseAll
()

RETURN


sddtest1.hbp
-hbexe
-inc

-osddtest1

sddtest1
.hbc
$
{HDIR}\contrib\rddsql\rddsql.hbc
$
{HDIR}\contrib\sddpg\sddpg.hbc
$
{HDIR}\contrib\hbpgsql\hbpgsql.hbc

sddtest1
.prg


hbmk.hbm
sddtest1.hbc

-w3 -es2


I compile like this

%hdir%\bin\win\bcc\hbmk2 sddtest1.hbp -rebuild




And this is the result of the above sample:

RDD list:
SQLBASE
SQLMIX
                                                                               
Default RDD:
SQLMIX
Successfully connected via hbpgsql.lib
Pointer to the postgreSQL db is  0x001FC79C                                                                                                                                                                                                    
-------
0
Connection error - 0:
Error SQLBASE/1901  Not connected
Called from DBUSEAREA(0)
Called from MAIN(56)


Appreciate any guidance as to what I'm missing here to get the rddsql+sddpg aproach to work too.
Reply all
Reply to author
Forward
0 new messages