Files
harbour-core/harbour/contrib/hbpgsql/tests/test.prg
Viktor Szakats fd1e13d69a 2010-02-02 21:50 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)
* contrib/hbpgsql/postgres.c
  * contrib/hbpgsql/tests/test.prg
    * Destructor PQCLOSETRACE() marked as deprecated, replaced in
      test app with NIL assignment.
    ! Fixes to FILE object type.
    ; All this is only relevant if built with NODLL flag.
2010-02-02 20:52:22 +00:00

100 lines
2.6 KiB
Plaintext

/*
* $Id$
*/
#include "../postgres.ch"
Function main()
Local conn, res, aTemp, x, y, pFile
Local cDb := 'test'
Local cUser := 'user'
Local cPass := 'pass'
CLEAR SCREEN
conn := PQsetdbLogin( 'localhost', "5432", NIL, NIL, cDb, cUser, cPass)
? PQdb(conn), PQuser(conn), PQpass(conn), PQhost(conn), PQport(conn), PQtty(conn), PQoptions(conn)
? conn := NIL
conn := PQConnect(cDb, 'localhost', cuser, cpass, 5432)
? PQstatus(conn), PQerrormessage(conn)
if PQstatus(conn) != CONNECTION_OK
quit
endif
? "Blocking: ", PQisnonblocking(conn), PQsetnonblocking(conn, .t.), PQisnonblocking(conn)
pFile := PQcreatetrace( 'trace.log' )
PQtrace( conn, pFile )
? "Verbose: ", PQsetErrorVerbosity(conn, 2)
? "Protocol: ", PQprotocolVersion(conn), ;
" Server Version: ", PQserverVersion(conn), ;
" Client Encoding: ", PQsetClientEncoding(conn, "ASCII"), ;
"New encode: ", PQclientEncoding(conn)
? PQdb(conn), PQuser(conn), PQpass(conn), PQhost(conn), PQport(conn), PQtty(conn), PQoptions(conn)
res := PQexec('drop table products')
? PQresultStatus(res), PQresultErrorMessage(res)
res := NIL
res := PQexec('create table products ( product_no numeric(10), name varchar(20), price numeric(10,2) )')
? PQresultStatus(res), PQresultErrorMessage(res)
res := NIL
res := PQexecParams(conn, 'insert into products(product_no, name, price) values ($1, $2, $3)', {'2', 'bread', '10.95'})
? "Oid Row: ", PQoidValue(res), PQoidStatus(res)
if PQresultStatus(res) != PGRES_COMMAND_OK
? PQresultStatus(res), PQresultErrorMessage(res)
endif
res := NIL
res := PQexec(conn, 'select price, name, product_no as "produto" from products')
if PQresultStatus(res) != PGRES_TUPLES_OK
? PQresultStatus(res), PQresultErrorMessage(res)
endif
? "Binary: ", PQbinaryTuples(res)
? "Rows: ", PQntuples(res), "Cols: ", PQnfields(res)
? PQfname(res, 1), PQftable(res, 1), PQftype(res, 1), PQfnumber(res, "name"), PQfmod(res, 1), PQfsize(res, 1), PQgetisnull(res,1,1)
aTemp := PQmetadata(res)
for x := 1 to len(aTemp)
? "Linha 1: "
for y := 1 to 6
?? aTemp[x,y], ", "
next
next
? PQFcount(res)
? PQlastrec(res)
? PQGetvalue(res,1, 2)
? res := NIL
? "Large Objects, always should be in a transaction..."
res := PQexec(conn, 'begin')
res := NIL
? (x := lo_Import( conn, 'test.prg' ))
? lo_Export( conn, x, 'test.new' )
? lo_Unlink( conn, x )
res := PQexec(conn, 'commit')
res := NIL
PQuntrace( conn )
pFile := NIL
conn := NIL
return NIL