2010-11-18 10:43 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)

* contrib/sddpg/sddpg.c
  * contrib/hbpgsql/postgres.c
    ! Reverted previous fix because it didn't work on non-*nix platform.
    - Deleted TOFIX comment, as apparently there is no better official way
      to get these macros.

  * contrib/hbpgsql/postgres.c
    + Added PQCONNECTDB() wrapper. Based on Tamas's patch, but implemented 
      little bit differently.
    + Extended PQCONNECT() (now deprecated compatibility function) to be more 
      flexible in accepting parameters and not create wrong low level call if 
      some of them are missing. Patch from Tamas, with my cleanups.
    * Marked PQCONNECT() wrapper with HB_LEGACY_LEVEL3. It's now deprecated.
      INCOMPATIBLE: Switch to PQCONNECTDB() ASAP.

  * contrib/hbpgsql/tests/async.prg
  * contrib/hbpgsql/tests/test.prg
  * contrib/hbpgsql/tests/stress.prg
  * contrib/hbpgsql/tpostgre.prg
    + Changed to use PQCONNECTDB() direct wrapper instead of PQCONNECT.
This commit is contained in:
Viktor Szakats
2010-11-18 09:44:10 +00:00
parent 0d2defaf8b
commit bd40c4068a
7 changed files with 116 additions and 16 deletions

View File

@@ -16,6 +16,28 @@
The license applies to all entries newer than 2009-04-28.
*/
2010-11-18 10:43 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)
* contrib/sddpg/sddpg.c
* contrib/hbpgsql/postgres.c
! Reverted previous fix because it didn't work on non-*nix platform.
- Deleted TOFIX comment, as apparently there is no better official way
to get these macros.
* contrib/hbpgsql/postgres.c
+ Added PQCONNECTDB() wrapper. Based on Tamas's patch, but implemented
little bit differently.
+ Extended PQCONNECT() (now deprecated compatibility function) to be more
flexible in accepting parameters and not create wrong low level call if
some of them are missing. Patch from Tamas, with my cleanups.
* Marked PQCONNECT() wrapper with HB_LEGACY_LEVEL3. It's now deprecated.
INCOMPATIBLE: Switch to PQCONNECTDB() ASAP.
* contrib/hbpgsql/tests/async.prg
* contrib/hbpgsql/tests/test.prg
* contrib/hbpgsql/tests/stress.prg
* contrib/hbpgsql/tpostgre.prg
+ Changed to use PQCONNECTDB() direct wrapper instead of PQCONNECT.
2010-11-17 21:59 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)
* src/common/hbver.c
* Commented not-yet-implemented function hb_verHostCPU()

View File

@@ -58,8 +58,30 @@
#include "hbapiitm.h"
#include "libpq-fe.h"
#include "postgres.h"
#include "catalog/pg_type.h"
#define VARHDRSZ 4
#define BOOLOID 16
#define INT8OID 20
#define INT2OID 21
#define INT4OID 23
#define TEXTOID 25
#define OIDOID 26
#define FLOAT4OID 700
#define FLOAT8OID 701
#define CASHOID 790
#define BPCHAROID 1042
#define VARCHAROID 1043
#define DATEOID 1082
#define TIMEOID 1083
#define TIMESTAMPOID 1114
#define TIMESTAMPTZOID 1184
#define TIMETZOID 1266
#define BITOID 1560
#define VARBITOID 1562
#define NUMERICOID 1700
#define INV_WRITE 0x00020000
#define INV_READ 0x00040000
#ifndef PG_VERSION_NUM
#define PG_VERSION_NUM 0
@@ -245,21 +267,53 @@ static FILE * hb_FILE_par( int iParam )
* Connection handling functions
*/
HB_FUNC( PQCONNECTDB )
{
if( HB_ISCHAR( 1 ) )
hb_PGconn_ret( PQconnectdb( hb_parc( 1 ) ) );
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
#if defined( HB_LEGACY_LEVEL3 )
/* NOTE: Deprecated. Because it's not 1 to 1 wrapper. Please use PQCONNECTDB() instead. */
HB_FUNC( PQCONNECT )
{
char conninfo[ 512 ];
char buf[ 128 ];
hb_snprintf( conninfo, sizeof( conninfo ),
"dbname = %s host = %s user = %s password = %s port = %i",
hb_parcx( 1 ),
hb_parcx( 2 ),
hb_parcx( 3 ),
hb_parcx( 4 ),
hb_parni( 5 ) );
conninfo[ 0 ] = '\0';
switch( hb_pcount() )
{
case 5:
hb_snprintf( buf, sizeof( buf ), "port = %i ", hb_parni( 5 ) );
hb_strncat( conninfo, buf, sizeof( conninfo ) - 1 );
/* FALLTHROUGH */
case 4:
hb_snprintf( buf, sizeof( buf ), "password = %s ", hb_parc( 4 ) );
hb_strncat( conninfo, buf, sizeof( conninfo ) - 1 );
/* FALLTHROUGH */
case 3:
hb_snprintf( buf, sizeof( buf ), "user = %s ", hb_parc( 3 ) );
hb_strncat( conninfo, buf, sizeof( conninfo ) - 1 );
/* FALLTHROUGH */
case 2:
hb_snprintf( buf, sizeof( buf ), "host = %s ", hb_parc( 2 ) );
hb_strncat( conninfo, buf, sizeof( conninfo ) - 1 );
/* FALLTHROUGH */
case 1:
hb_snprintf( buf, sizeof( buf ), "dbname = %s ", hb_parc( 1 ) );
hb_strncat( conninfo, buf, sizeof( conninfo ) - 1 );
}
hb_PGconn_ret( PQconnectdb( conninfo ) );
}
#endif /* defined( HB_LEGACY_LEVEL3 ) */
/* NOTE: Deprecated */
HB_FUNC( PQSETDBLOGIN )
{
hb_PGconn_ret( PQsetdbLogin( hb_parcx( 1 ) /* pghost */,
@@ -289,7 +343,7 @@ HB_FUNC( PQCLOSE )
}
}
#endif
#endif /* defined( HB_LEGACY_LEVEL3 ) */
HB_FUNC( PQRESET )
{

View File

@@ -13,7 +13,7 @@ FUNCTION Main( cServer, cDatabase, cUser, cPass )
CLEAR SCREEN
? "Connect", conn := PQConnect( cDatabase, cServer, cUser, cPass, 5432 )
? "Connect", conn := PQconnectDB( "dbname = " + cDatabase + " host = " + cServer + " user = " + cUser + " password = " + cPass + " port = 5432" )
? "Conection status", PQerrorMessage(conn), PQstatus(conn)

View File

@@ -17,7 +17,7 @@ PROCEDURE Main( cServer, cDatabase, cUser, cPass )
CLEAR SCREEN
? "Connecting...."
conn := PQconnect( cDatabase, cServer, cUser, cPass, 5432 )
conn := PQconnectDB( "dbname = " + cDatabase + " host = " + cServer + " user = " + cUser + " password = " + cPass + " port = 5432" )
? PQstatus( conn ), PQerrormessage( conn )

View File

@@ -15,7 +15,7 @@ PROCEDURE main()
conn := PQsetdbLogin( "localhost", "5432", NIL, NIL, cDb, cUser, cPass )
? PQdb( conn ), PQuser( conn ), PQpass( conn ), PQhost( conn ), PQport( conn ), PQtty( conn ), PQoptions( conn )
conn := PQConnect( cDb, "localhost", cuser, cpass, 5432 )
conn := PQconnectDB( "dbname = " + cDb + " host = localhost user = " + cUser + " password = " + cPass + " port = 5432" )
? PQstatus( conn ), PQerrormessage( conn )

View File

@@ -108,7 +108,7 @@ METHOD New( cHost, cDatabase, cUser, cPass, nPort, Schema ) CLASS TPQserver
nPort := 5432
ENDIF
::pDB := PQconnect( cDatabase, cHost, cUser, cPass, nPort )
::pDB := PQconnectDB( "dbname = " + cDatabase + " host = " + cHost + " user = " + cUser + " password = " + cPass + " port = " + hb_ntos( nPort ) )
IF PQstatus( ::pDb ) != CONNECTION_OK
::lError := .T.

View File

@@ -57,8 +57,32 @@
#include "hbrddsql.h"
#include "libpq-fe.h"
#include "postgres.h"
#include "catalog/pg_type.h"
#define BOOLOID 16
#define BYTEAOID 17
#define CHAROID 18
#define NAMEOID 19
#define INT8OID 20
#define INT2OID 21
#define INT4OID 23
#define TEXTOID 25
#define OIDOID 26
#define CIDROID 650
#define FLOAT4OID 700
#define FLOAT8OID 701
#define CASHOID 790
#define MACADDROID 829
#define INETOID 869
#define BPCHAROID 1042
#define VARCHAROID 1043
#define DATEOID 1082
#define TIMEOID 1083
#define TIMESTAMPOID 1114
#define TIMESTAMPTZOID 1184
#define TIMETZOID 1266
#define BITOID 1560
#define VARBITOID 1562
#define NUMERICOID 1700
typedef struct
{