* contrib/hbpgsql/hbpgsql.hbx
* contrib/hbpgsql/postgres.c
* contrib/hbpgsql/postgres.ch
+ add most new wrappers from this repository of Petr Chornyj:
https://github.com/petr-ch/hbpgsql9
Version guards have been added and "params" functions reworked
to accept hashes instead of two arrays. Other minor corrections
to fit into the contrib env.
+ add PQsslAttribute()
* some existing functions were modified to make the parameter
check (and fail if wrong) even if the underlying API is not
available, instead of silently returning a default value.
; all of the above was build-tested only and some features
require at least postgresql 8, 9 or 9.1
+ add PQlibVersion() -> <nVersion> (returns 0 for pre-9.1 postresql
versions)
Ref: https://github.com/harbour/core/pull/127/ by @VerchenkoAG
+ PQEXECPARAMS(): add 4th parameter to set <resultFormat>
Refs:
https://www.postgresql.org/docs/9.1/static/libpq-exec.html
https://groups.google.com/d/msg/harbour-users/hXhuVzU9pHA/RrDGLIiUAwAJ
+ add PQresStatus( <nNum> ) -> <cString>
+ added wrapper function
PQresultErrorField( result, nFieldCode ) -> cString
based on:
https://groups.google.com/d/msg/harbour-users/XSvRpbzfcHc/ztSL32fYpl4J
+ added PG_DIAG_* constants
+ added pg_encoding_to_char() wrapper to convert numeric
encoding ID to string
! fixed to use hb_fopen() instead of fopen()
+ TPQserver():New(): all parameters are now optional
! TPQserver():New(): fixed to escape connect parameter values
+ TPQserver():New(): added 7th optional hash parameter to pass
custom
connection parameters (e.g. SSL)
https://www.postgresql.org/docs/devel/static/libpq-connect.html
* contrib/hbpgsql/tests/test.prg
+ use pg_encoding_to_char(), plus some more feedback regarding
encodings
* contrib/hbpgsql/tests/dbf2pg.prg
+ use VF IO
+ support more source field types
; synced with Viktor's 3.4 branch at https://github.com/vszakats/hb
2017-02-15 15:14 UTC Viktor Szakats (vszakats users.noreply.github.com)
2016-09-05 18:55 UTC+0200 Viktor Szakats (vszakats users.noreply.github.com)
2016-09-05 10:43 UTC+0200 Viktor Szakats (vszakats users.noreply.github.com)
2016-09-02 01:58 UTC+0200 Viktor Szakats (vszakats users.noreply.github.com)
2016-06-20 22:50 UTC+0200 Viktor Szakats (vszakats users.noreply.github.com)
2015-07-19 11:56 UTC+0200 Viktor Szakats (vszakats users.noreply.github.com)
2015-04-06 18:39 UTC+0200 Viktor Szakats (vszakats users.noreply.github.com)
2015-03-31 23:31 UTC+0200 Viktor Szakats (vszakats users.noreply.github.com)
2014-11-29 02:47 UTC+0100 Viktor Szakats (vszakats users.noreply.github.com)
2014-07-08 13:21 UTC+0200 Viktor Szakats (vszakats users.noreply.github.com)
2014-02-11 18:18 UTC+0100 Viktor Szakats (vszakats users.noreply.github.com)
; tons of cleanups in this library, many thanks
161 lines
3.5 KiB
Plaintext
161 lines
3.5 KiB
Plaintext
#require "hbpgsql"
|
|
|
|
PROCEDURE Main( cHost, cDatabase, cUser, cPass )
|
|
|
|
LOCAL cQuery, oQuery, oRow, i, x
|
|
|
|
LOCAL oServer := TPQServer():New( cHost, hb_defaultValue( cDatabase, "postgres" ), cUser, cPass )
|
|
|
|
IF oServer:NetErr()
|
|
? oServer:ErrorMsg()
|
|
RETURN
|
|
ENDIF
|
|
|
|
oServer:SetVerbosity( 2 )
|
|
oServer:traceon( "simple.log" )
|
|
|
|
? "Tables..."
|
|
|
|
FOR EACH i IN oServer:ListTables()
|
|
? i
|
|
NEXT
|
|
|
|
IF oServer:TableExists( "test" )
|
|
? oQuery := oServer:Execute( "DROP TABLE test" )
|
|
|
|
oQuery:Destroy()
|
|
ENDIF
|
|
|
|
? "Creating test table..."
|
|
cQuery := ;
|
|
"CREATE TABLE test(" + ;
|
|
" Code integer not null primary key," + ;
|
|
" dept Integer," + ;
|
|
" Name Varchar(40)," + ;
|
|
" Sales boolean," + ;
|
|
" Tax Float4," + ;
|
|
" Salary Double Precision," + ;
|
|
" Budget Numeric(12,2)," + ;
|
|
" Discount Numeric(5,2)," + ;
|
|
" Creation Date," + ;
|
|
" Description text )"
|
|
|
|
oQuery := oServer:Query( cQuery )
|
|
|
|
IF oQuery:NetErr()
|
|
? oQuery:ErrorMsg()
|
|
ENDIF
|
|
|
|
oQuery:Destroy()
|
|
|
|
? "Structure of test table"
|
|
|
|
FOR EACH i IN oServer:TableStruct( "test" )
|
|
?
|
|
FOR EACH x IN i
|
|
?? x, ""
|
|
NEXT
|
|
NEXT
|
|
|
|
? "Inserting, declared transaction control"
|
|
oServer:StartTransaction()
|
|
|
|
FOR i := 1 TO 10
|
|
cQuery := "INSERT INTO test(code, dept, name, sales, tax, salary, budget, Discount, Creation, Description) " + ;
|
|
"VALUES( " + hb_ntos( i ) + ", 2, 'TEST', 'y', 5, 3000, 1500.2, 7.5, '2003-12-17', 'Short Description about what ?')"
|
|
|
|
oQuery := oServer:Query( cQuery )
|
|
|
|
IF oQuery:NetErr()
|
|
? oQuery:errorMsg()
|
|
ENDIF
|
|
|
|
oQuery:destroy()
|
|
NEXT
|
|
|
|
oServer:Commit()
|
|
|
|
oQuery := oServer:Query( "SELECT code, name, description, sales FROM test" )
|
|
|
|
FOR EACH i IN oQuery:Struct()
|
|
? i[ 1 ], i[ 2 ], i[ 3 ], i[ 4 ]
|
|
NEXT
|
|
|
|
? "Fields:", oQuery:FCount()
|
|
|
|
oRow := oQuery:Blank()
|
|
|
|
? ;
|
|
oRow:FCount(), ;
|
|
oRow:FieldPos( "sales" ), ;
|
|
oRow:FieldGet( 1 ), ;
|
|
oRow:FieldName( 2 ), ;
|
|
oRow:FieldType( 1 ), ;
|
|
oRow:FieldDec( 1 ), ;
|
|
oRow:FieldLen( 1 )
|
|
|
|
oRow:FieldPut( 1, 150 )
|
|
oRow:FieldPut( 2, "MY TEST" )
|
|
|
|
? oRow:FieldGet( 1 ), oRow:FieldGet( 2 )
|
|
|
|
? oRow:aRow[ 1 ], oRow:aRow[ 2 ], oRow:aOld[ 1 ], oRow:aOld[ 2 ]
|
|
|
|
? oQuery:Append( oRow )
|
|
|
|
? oQuery:ErrorMsg()
|
|
|
|
DO WHILE ! oQuery:Eof()
|
|
? ;
|
|
oQuery:RecNo(), ;
|
|
oQuery:FieldPos( "code" ), ;
|
|
oQuery:FieldGet( oQuery:FieldPos( "code" ) ), ;
|
|
oQuery:FieldGet( 4 ), ;
|
|
oQuery:FieldGet( 2 ), ;
|
|
oQuery:FieldName( 1 ), ;
|
|
oQuery:FieldType( 1 ), ;
|
|
oQuery:FieldDec( 1 ), ;
|
|
oQuery:FieldLen( 1 ), ;
|
|
oQuery:FieldGet( 3 )
|
|
|
|
IF oQuery:RecNo() == 50
|
|
oRow := oQuery:getrow()
|
|
|
|
oRow:FieldPut( 2, "My Second test" )
|
|
? "Update:", oQuery:Update( oRow )
|
|
ENDIF
|
|
|
|
IF oQuery:RecNo() == 60
|
|
oRow := oQuery:getrow()
|
|
? "Delete:", oQuery:Delete( oRow )
|
|
ENDIF
|
|
|
|
oQuery:Skip()
|
|
|
|
ENDDO
|
|
|
|
oQuery:Refresh()
|
|
|
|
FOR i := 1 TO oQuery:LastRec()
|
|
oRow := oQuery:getrow( i )
|
|
|
|
? i, ;
|
|
oRow:FieldGet( oRow:FieldPos( "code" ) ), ;
|
|
oRow:FieldGet( 4 ), ;
|
|
oRow:FieldGet( 2 ), ;
|
|
oRow:FieldName( 1 ), ;
|
|
oRow:FieldType( 1 ), ;
|
|
oRow:FieldDec( 1 ), ;
|
|
oRow:FieldLen( 1 ), ;
|
|
oRow:FieldGet( i, 3 )
|
|
|
|
NEXT
|
|
|
|
oQuery:Destroy()
|
|
|
|
oServer:Destroy()
|
|
|
|
? "Closing..."
|
|
|
|
RETURN
|