* contrib/hbpgsql/postgres.c
+ Added GC support for all remaining pointer types (result/cancel/FILE).
+ Added RTE when wrong pointer or wrong number of parameter is passed
to functions.
This means that behavior is now INCOMPATIBLE when wrong parameters
are encountered in these functions.
; Destructor functions PQFREECANCEL(), PQCLOSE(), PQCLEAR() marked
as 'deprecated'.
These are not needed, it's enough to assign NIL to their holder
variables on .prg level.
% Cleanups along the way.
; TODO: Fix sloppy parameter checking which only check number of
parameters instead of enforcing expected type.
; Please test.
* contrib/hbpgsql/tests/async.prg
* contrib/hbpgsql/tests/test.prg
* contrib/hbpgsql/tests/cache.prg
* contrib/hbpgsql/tests/stress.prg
% Replaced deprecated destructor functions with '<var> := NIL'.
* utils/hbmk2/hbmk2.prg
* Formatting.
70 lines
1.6 KiB
Plaintext
70 lines
1.6 KiB
Plaintext
/*
|
|
* $Id$
|
|
*
|
|
* This sample show howto use asynchronous/nonblocking queries
|
|
*
|
|
*/
|
|
|
|
Function Main( cServer, cDatabase, cUser, cPass )
|
|
Local conn
|
|
|
|
CLEAR SCREEN
|
|
|
|
? "Connect", conn := PQConnect( cDatabase, cServer, cUser, cPass, 5432)
|
|
|
|
? "Conection status", PQerrorMessage(conn), PQstatus(conn)
|
|
|
|
Query( conn, 'SELECT codigo, descri FROM client limit 100', .f. )
|
|
Query( conn, 'SELECT codigo, descri FROM fornec limit 100', .f. )
|
|
Query( conn, 'SELECT pedido, vlrped FROM pedido', .t. )
|
|
|
|
conn := NIL
|
|
|
|
return nil
|
|
|
|
Procedure Query( conn, cQuery, lCancel )
|
|
Local pCancel, cErrMsg := space(30)
|
|
Local res, x, y, xTime
|
|
|
|
? "PQSendQuery", PQsendQuery(conn, cQuery)
|
|
|
|
xTime := time()
|
|
CLEAR TYPEAHEAD
|
|
|
|
do while inkey() != 27
|
|
DevPos(Row(), 20)
|
|
DevOut("Processing: " + Elaptime(xtime, time()))
|
|
|
|
inkey(1)
|
|
|
|
if lCancel
|
|
if .t.
|
|
pCancel := PQgetCancel(conn)
|
|
? "Canceled: ", PQcancel( pCancel, @cErrMsg ), cErrMsg
|
|
pCancel := NIL
|
|
else
|
|
? PQrequestCancel(conn) // Deprecated
|
|
endif
|
|
endif
|
|
|
|
if PQconsumeInput(conn)
|
|
if ! PQisBusy(conn)
|
|
exit
|
|
endif
|
|
endif
|
|
enddo
|
|
|
|
if inkey() != 27
|
|
? "PQgetResult", hb_valtoexp(res := PQgetResult(conn))
|
|
|
|
for x := 1 to PQlastrec(res)
|
|
?
|
|
for y := 1 to PQfcount(res)
|
|
?? PQgetvalue(res, x, y), " "
|
|
next
|
|
next
|
|
else
|
|
? "Canceling Query", PQrequestCancel(conn)
|
|
endif
|
|
Return
|