Files
harbour-core/harbour/contrib/hbpgsql/tests/async.prg
Viktor Szakats bd40c4068a 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-18 09:44:10 +00:00

74 lines
1.6 KiB
Plaintext

/*
* $Id$
*/
/*
* This sample show howto use asynchronous/nonblocking queries
*/
#include "inkey.ch"
FUNCTION Main( cServer, cDatabase, cUser, cPass )
LOCAL conn
CLEAR SCREEN
? "Connect", conn := PQconnectDB( "dbname = " + cDatabase + " host = " + cServer + " user = " + cUser + " password = " + cPass + " port = 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, cTime
? "PQSendQuery", PQsendQuery( conn, cQuery )
cTime := Time()
CLEAR TYPEAHEAD
DO WHILE Inkey() != K_ESC
DevPos( Row(), 20 )
DevOut( "Processing: " + Elaptime( cTime, 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() != K_ESC
? "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