Skip to content

Commit

Permalink
2021-03-31 20:38 UTC+0200 Aleksander Czajczynski (hb fki.pl)
Browse files Browse the repository at this point in the history
  * contrib/hbpgsql/hbpgsql.h
  * contrib/hbpgsql/postgres.c
  * contrib/hbpgsql/tpostgre.prg
    + recognize NAMEOID columns
    + added :SetNull( <lSet> ) to TPQServer class
      and a param to :Query( <cQuery>, [ <lNull> ] )
      TPQQuery class constructor is also extended.

      With :SetNull( .T. ) retains NULL information as NIL. Standard
      behaviour of hbpgsql library, until now, was to substitute NULL
      as blank xBase value - thus :SetNull( .F. ) is the default setting.

  ; changes imported from https://github.com/alcz/harbour
    2015-05-07 22:24 UTC+0200 Aleksander Czajczynski (hb fki.pl)
  • Loading branch information
alcz committed Mar 31, 2021
1 parent d407898 commit 864c0e6
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 9 deletions.
16 changes: 16 additions & 0 deletions ChangeLog.txt
Expand Up @@ -7,6 +7,22 @@
Entries may not always be in chronological/commit order.
See license at the end of file. */

2021-03-31 20:38 UTC+0200 Aleksander Czajczynski (hb fki.pl)
* contrib/hbpgsql/hbpgsql.h
* contrib/hbpgsql/postgres.c
* contrib/hbpgsql/tpostgre.prg
+ recognize NAMEOID columns
+ added :SetNull( <lSet> ) to TPQServer class
and a param to :Query( <cQuery>, [ <lNull> ] )
TPQQuery class constructor is also extended.

With :SetNull( .T. ) retains NULL information as NIL. Standard
behaviour of hbpgsql library, until now, was to substitute NULL
as blank xBase value - thus :SetNull( .F. ) is the default setting.

; changes imported from https://github.com/alcz/harbour
2015-05-07 22:24 UTC+0200 Aleksander Czajczynski (hb fki.pl)

2021-01-26 18:27 UTC+0200 Oleksii Myronenko (m.oleksa ukr.net)
* src/debug/dbgtarr.prg
* src/debug/dbgthsh.prg
Expand Down
1 change: 1 addition & 0 deletions contrib/hbpgsql/hbpgsql.h
Expand Up @@ -55,6 +55,7 @@

#define VARHDRSZ 4
#define BOOLOID 16
#define NAMEOID 19
#define INT8OID 20
#define INT2OID 21
#define INT4OID 23
Expand Down
4 changes: 4 additions & 0 deletions contrib/hbpgsql/postgres.c
Expand Up @@ -616,6 +616,10 @@ HB_FUNC( PQMETADATA ) /* not a direct wrapper */
hb_strncpy( buf, "money", sizeof( buf ) - 1 );
break;

case NAMEOID:
hb_strncpy( buf, "name", sizeof( buf ) - 1 );
break;

default:
hb_strncpy( buf, "not supported", sizeof( buf ) - 1 );
break;
Expand Down
44 changes: 35 additions & 9 deletions contrib/hbpgsql/tpostgre.prg
Expand Up @@ -64,6 +64,7 @@ CREATE CLASS TPQServer
VAR cError INIT ""
VAR lTrace INIT .F.
VAR pTrace
VAR lNull INIT .F.

METHOD New( cHost, cDatabase, cUser, cPass, nPort, Schema )
METHOD Destroy()
Expand All @@ -74,7 +75,7 @@ CREATE CLASS TPQServer
METHOD Commit()
METHOD Rollback()

METHOD Query( cQuery )
METHOD Query( cQuery, lNull )
METHOD Execute( cQuery ) INLINE ::Query( cQuery )
METHOD SetSchema( cSchema )

Expand All @@ -89,6 +90,7 @@ CREATE CLASS TPQServer
METHOD TraceOn( cFile )
METHOD TraceOff()
METHOD SetVerbosity( num ) INLINE PQsetErrorVerbosity( ::pDb, iif( num >= 0 .AND. num <= 2, num, 1 ) )
METHOD SetNull( lNewSet )

ENDCLASS

Expand Down Expand Up @@ -193,8 +195,11 @@ METHOD Rollback() CLASS TPQserver

RETURN lError

METHOD Query( cQuery ) CLASS TPQserver
RETURN TPQQuery():New( ::pDB, cQuery, ::lallCols, ::Schema )
METHOD Query( cQuery, lNull ) CLASS TPQserver
IF !HB_IsLogical( lNull )
lNull := ::lNull
ENDIF
RETURN TPQQuery():New( ::pDB, cQuery, ::lallCols, ::Schema,, lNull )

METHOD TableExists( cTable ) CLASS TPQserver

Expand Down Expand Up @@ -461,6 +466,14 @@ METHOD TraceOff() CLASS TPQserver

RETURN NIL

METHOD SetNull( lNewSet ) CLASS TPQserver
LOCAL lSet := ::lNull

IF HB_IsLogical( lNewSet )
::lNull := lNewSet
ENDIF

RETURN lSet

CREATE CLASS TPQQuery

Expand All @@ -487,8 +500,9 @@ CREATE CLASS TPQQuery
VAR TableName
VAR Schema
VAR rows INIT 0
VAR lNull INIT .F.

METHOD New( pDB, cQuery, lallCols, cSchema, res )
METHOD New( pDB, cQuery, lallCols, cSchema, res, lNull )
METHOD Destroy()
METHOD Close() INLINE ::Destroy()

Expand Down Expand Up @@ -529,7 +543,7 @@ CREATE CLASS TPQQuery
ENDCLASS


METHOD New( pDB, cQuery, lallCols, cSchema, res ) CLASS TPQquery
METHOD New( pDB, cQuery, lallCols, cSchema, res, lNull ) CLASS TPQquery

::pDB := pDB
::nResultStatus := -1
Expand All @@ -541,6 +555,10 @@ METHOD New( pDB, cQuery, lallCols, cSchema, res ) CLASS TPQquery
::pQuery := res
ENDIF

IF HB_IsLogical( lNull )
::lNull := lNull
ENDIF

::Refresh( res == NIL )

RETURN Self
Expand Down Expand Up @@ -665,6 +683,14 @@ METHOD Refresh( lQuery, lMeta ) CLASS TPQquery
cType := "C"
nSize := 10

ELSEIF "name" $ cType
cType := "C"
nSize := 64

ELSEIF "oid" $ cType
cType := "N"
nSize := 19

ELSE
/* Unsuported */
cType := "K"
Expand Down Expand Up @@ -1021,31 +1047,31 @@ METHOD FieldGet( nField, nRow ) CLASS TPQquery
CASE "M"
IF result != NIL
result := result
ELSE
ELSEIF ! ::lNull
result := ""
ENDIF
EXIT

CASE "N"
IF result != NIL
result := Val( result )
ELSE
ELSEIF ! ::lNull
result := 0
ENDIF
EXIT

CASE "D"
IF result != NIL
result := hb_SToD( StrTran( result, "-" ) )
ELSE
ELSEIF ! ::lNull
result := hb_SToD()
ENDIF
EXIT

CASE "L"
IF result != NIL
result := ( result == "t" )
ELSE
ELSEIF ! ::lNull
result := .F.
ENDIF
EXIT
Expand Down

0 comments on commit 864c0e6

Please sign in to comment.