diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 7ab3e7ca1d..10edf00522 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -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() diff --git a/harbour/contrib/hbpgsql/postgres.c b/harbour/contrib/hbpgsql/postgres.c index 824df7c1be..9e93c26c51 100644 --- a/harbour/contrib/hbpgsql/postgres.c +++ b/harbour/contrib/hbpgsql/postgres.c @@ -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 ) { diff --git a/harbour/contrib/hbpgsql/tests/async.prg b/harbour/contrib/hbpgsql/tests/async.prg index 143530d344..79b862163c 100644 --- a/harbour/contrib/hbpgsql/tests/async.prg +++ b/harbour/contrib/hbpgsql/tests/async.prg @@ -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) diff --git a/harbour/contrib/hbpgsql/tests/stress.prg b/harbour/contrib/hbpgsql/tests/stress.prg index d743bf02cb..529099321f 100644 --- a/harbour/contrib/hbpgsql/tests/stress.prg +++ b/harbour/contrib/hbpgsql/tests/stress.prg @@ -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 ) diff --git a/harbour/contrib/hbpgsql/tests/test.prg b/harbour/contrib/hbpgsql/tests/test.prg index a4bb69af3b..a9ef650ea0 100644 --- a/harbour/contrib/hbpgsql/tests/test.prg +++ b/harbour/contrib/hbpgsql/tests/test.prg @@ -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 ) diff --git a/harbour/contrib/hbpgsql/tpostgre.prg b/harbour/contrib/hbpgsql/tpostgre.prg index c99a512370..c96b96e74a 100644 --- a/harbour/contrib/hbpgsql/tpostgre.prg +++ b/harbour/contrib/hbpgsql/tpostgre.prg @@ -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. diff --git a/harbour/contrib/sddpg/sddpg.c b/harbour/contrib/sddpg/sddpg.c index 22989a880f..73943e1320 100644 --- a/harbour/contrib/sddpg/sddpg.c +++ b/harbour/contrib/sddpg/sddpg.c @@ -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 {