TPQServer

Post Reply
Natter
Posts: 524
Joined: Mon May 14, 2007 9:49 am

TPQServer

Post by Natter »

Hi,

When you create a Postgresql object using TPWServer():New (), you are prompted to confirm that you are accessing the database. Is it possible to avoid automatically opening this query ?

FW 1806
User avatar
Jimmy
Posts: 165
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: TPQServer

Post by Jimmy »

Natter wrote:Hi,

When you create a Postgresql object using TPWServer():New (), you are prompted to confirm that you are accessing the database. Is it possible to avoid automatically opening this query ?

FW 1806
pass all Parameter and it will not ask you

Code: Select all

   oServer   := TPQServer():New( cHost, cDataBase, cUser, cPassword, , cSchema )
c:\fwh\samples\pgre01.prg
c:\fwh\samples\testpgre.prg
greeting,
Jimmy
Natter
Posts: 524
Joined: Mon May 14, 2007 9:49 am

Re: TPQServer

Post by Natter »

I pass all the parameters in, but the confirmation window still opens.

Can there be source code of TPQServer class ?
User avatar
Jimmy
Posts: 165
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: TPQServer

Post by Jimmy »

Natter wrote:I pass all the parameters in, but the confirmation window still opens.
for me it work ... hm

this is a Test Code from HMG

Code: Select all

#require "hbpgsql"                  // i guess FW use libpq.lib pgsql.lib 
#include "postgres.ch"   // some Constant

PROCEDURE Main()
   LOCAL conn, res, aTemp, x, y, pFile
   LOCAL cHost := "localhost"
   LOCAL cPort := "5432"
   LOCAL cDb   := "MyCatalog"
   LOCAL cUser := "MyUser"
   LOCAL cPass := "MyPW"

#IFDEF __XPP__
#ELSE
   REQUEST HB_GT_WIN_DEFAULT
   CLS
#ENDIF

   conn := PQsetdbLogin( cHost, cPort, NIL, NIL, cDb, cUser, cPass )
   ? PQdb( conn ), PQuser( conn ), PQpass( conn ), PQhost( conn ), PQport( conn ), PQtty( conn ), PQoptions( conn )

*  conn := PQconnectdb( "dbname = " + cDb + " host = localhost user = " + cUser + " password = " + cPass + " port = 5432" )
   conn := PQconnectdb( "host = "+ cHost     +;
                        " port = " +cPort    +;
                        " dbname = " + cDb   +;
                        " user = " + cUser   +;
                        " password = " + cPass )

   ? PQstatus( conn ), PQerrorMessage( conn )

   IF PQstatus( conn ) != CONNECTION_OK
      QUIT
   ENDIF

   ? "Blocking: ", PQisnonblocking( conn ), PQsetnonblocking( conn, .T. ), PQisnonblocking( conn )

   pFile := PQtracecreate( "trace.log" )
   PQtrace( conn, pFile )

   ? "Verbose: ", PQsetErrorVerbosity( conn, 2 )

   ? ;
      "Protocol: ", PQprotocolVersion( conn ), ;
      " Server Version: ", PQserverVersion( conn ), ;
      " Client Encoding: ", PQsetClientEncoding( conn, "ASCII" ), ;
      "New encode: ", PQclientEncoding( conn )

   ? PQdb( conn ), PQuser( conn ), PQpass( conn ), PQhost( conn ), PQport( conn ), PQtty( conn ), PQoptions( conn )

   res := PQexec( conn, "drop table products" )
   ? PQresultStatus( res ), PQresultErrorMessage( res )
   res := NIL

   res := PQexec( conn, "create table products ( product_no numeric(10), name varchar(20), price numeric(10,2) )" )
   ? PQresultStatus( res ), PQresultErrorMessage( res )

   res := PQexecParams( conn, "insert into products(product_no, name, price) values ($1, $2, $3)", { "2", "bread", "10.95" } )
   ? "Oid Row: ", PQoidValue( res ), PQoidStatus( res )

   IF PQresultStatus( res ) != PGRES_COMMAND_OK
      ? PQresultStatus( res ), PQresultErrorMessage( res )
   ENDIF

   res := PQexec( conn, 'select price, name, product_no as "produto" from products' )

   IF PQresultStatus( res ) != PGRES_TUPLES_OK
      ? PQresultStatus( res ), PQresultErrorMessage( res )
   ENDIF

   ? "Binary: ", PQbinaryTuples( res )
   ? "Rows: ", PQntuples( res ), "Cols: ", PQnfields( res )
   ? PQfname( res, 1 ), PQftable( res, 1 ), PQftype( res, 1 ), PQfnumber( res, "name" ), PQfmod( res, 1 ), PQfsize( res, 1 ), PQgetisnull( res, 1, 1 )

   aTemp := PQmetadata( res )

   FOR x := 1 TO Len( aTemp )
      ? "Linha 1: "
      FOR y := 1 TO 6
         ?? aTemp[ x ][ y ], ", "
      NEXT
   NEXT

   ? PQfcount( res )

   ? PQlastrec( res )

   ? PQgetvalue( res, 1, 2 )

   ? "Large Objects, always should be in a transaction..."

   PQexec( conn, "begin" )

   ? ( x := lo_import( conn, __FILE__ ) )
   ? lo_export( conn, x, hb_FNameExtSet( __FILE__, ".new" ) )
   ? lo_unlink( conn, x )

   PQexec( conn, "commit" )

   PQuntrace( conn )

WAIT

RETURN
 

Code: Select all

#ifndef HBPOSTGRES_CH_
#define HBPOSTGRES_CH_

#define CONNECTION_OK                   0
#define CONNECTION_BAD                  1
#define CONNECTION_STARTED              2
#define CONNECTION_MADE                 3
#define CONNECTION_AWAITING_RESPONSE    4
#define CONNECTION_AUTH_OK              5
#define CONNECTION_SETENV               6
#define CONNECTION_SSL_STARTUP          7
#define CONNECTION_NEEDED               8

#define PGRES_EMPTY_QUERY               0
#define PGRES_COMMAND_OK                1
#define PGRES_TUPLES_OK                 2
#define PGRES_COPY_OUT                  3
#define PGRES_COPY_IN                   4
#define PGRES_BAD_RESPONSE              5
#define PGRES_NONFATAL_ERROR            6
#define PGRES_FATAL_ERROR               7

#define PQTRANS_IDLE                    0
#define PQTRANS_ACTIVE                  1
#define PQTRANS_INTRANS                 2
#define PQTRANS_INERROR                 3
#define PQTRANS_UNKNOWN                 4

/* PQmetadata() positions for array returned */
#define HBPG_META_FIELDNAME             1
#define HBPG_META_FIELDTYPE             2
#define HBPG_META_FIELDLEN              3
#define HBPG_META_FIELDDEC              4
#define HBPG_META_TABLE                 5
#define HBPG_META_TABLECOL              6
#define HBPG_META_LEN_                  6

#endif
 
Natter wrote:Can there be source code of TPQServer class ?
are you asking for Source :?:
i have this
PostGreSQL wrapper for MiniGUI (libpq)

Contributed by Viktor Szakats
Arranged for MiniGUI by Mitja Podgornik

Script makelib.bat creates PostgreSQL wrapper lib for Harbour (../Harbour/lib/hbpgsql.lib) and transforms
original libpq.lib in this map (MSVC COFF type) to Borland OMF type (../Harbour/lib/libpq.lib)

All headers and libpq.lib are from PostgreSQL version 8.4

5.5.2011

Mitja Podgornik


Updated:

PostGreSQL wrapper from harbour-core (https://github.com/vszakats/harbour-core)

All headers and libpq.lib are from PostgreSQL version 9.5

Petr Chornyj <myorg63@mail.ru>
but i can't attach (upload) it here so please write a Email to "AUGE_OHR" at WEB.DE

i include Directory 8.4 and 9.5 LIB of PostgreSQL and *.h files

it have buildlib64.bat / tpostgre-64.hbp but IMHO include LIB are for 32 BIT so i had Problem to build 64 Bit LIB :(
MakeLib.bat is not complete so do NOT run it :!:

you need re-write tpostgre-64.hbp for 32 Bit ( just remove "-64" ) and change Path in buildlib64.bat to FiveWin and BCC
have not try it yet under FiveWin so i don't know if there are more Problem.
greeting,
Jimmy
Natter
Posts: 524
Joined: Mon May 14, 2007 9:49 am

Re: TPQServer

Post by Natter »

Thanks
Post Reply