postgres.c | |||
Type | Function | Source | Line |
---|---|---|---|
STATIC HB_GARBAGE_FUNC( | PGconn_release )
static HB_GARBAGE_FUNC( PGconn_release ) { void ** ph = ( void ** ) Cargo; /* Check if pointer is not NULL to avoid multiple freeing */ if( ph && * ph ) { /* Destroy the object */ PQfinish( ( PGconn * ) * ph ); /* set pointer to NULL to avoid multiple freeing */ * ph = NULL; } } | postgres.c | 96 |
STATIC VOID | PGconn_ret( PGconn * p )
static void PGconn_ret( PGconn * p ) { void ** ph = ( void ** ) hb_gcAlloc( sizeof( PGconn * ), PGconn_release ); * ph = p; if( * ph ) hb_retptrGC( ph ); } | postgres.c | 111 |
STATIC PGCONN * | PGconn_par( int iParam )
static PGconn * PGconn_par( int iParam ) { void ** ph = ( void ** ) hb_parptrGC( PGconn_release, iParam ); return ph ? ( PGconn * ) * ph : NULL; } | postgres.c | 121 |
HB_FUNC | PQCONNECT(void)
HB_FUNC( PQCONNECT ) { if( hb_pcount() == 5 ) { char conninfo[ 512 ]; snprintf( conninfo, sizeof( conninfo ), "dbname = %s host = %s user = %s password = %s port = %i", hb_parcx( 1 ), hb_parcx( 2 ), hb_parcx( 3 ), hb_parcx( 4 ), ( int ) hb_parni( 5 ) ); PGconn_ret( PQconnectdb( conninfo ) ); } else hb_retptr( NULL ); } | postgres.c | 128 |
HB_FUNC | PQSETDBLOGIN(void)
HB_FUNC( PQSETDBLOGIN ) { if( hb_pcount() == 7 ) { const char * pghost = hb_parcx( 1 ); const char * pgport = hb_parcx( 2 ); const char * pgoptions = hb_parcx( 3 ); const char * pgtty = hb_parcx( 4 ); const char * dbName = hb_parcx( 5 ); const char * login = hb_parcx( 6 ); const char * pwd = hb_parcx( 7 ); PGconn_ret( PQsetdbLogin( pghost, pgport, pgoptions, pgtty, dbName, login, pwd ) ); } else hb_retptr( NULL ); } | postgres.c | 143 |
HB_FUNC | PQCLOSE(void)
HB_FUNC( PQCLOSE ) { void ** ph = ( void ** ) hb_parptrGC( PGconn_release, 1 ); /* Check if pointer is not NULL to avoid multiple freeing */ if( ph && * ph ) { /* Destroy the object */ PQfinish( ( PGconn * ) * ph ); /* set pointer to NULL to avoid multiple freeing */ * ph = NULL; } } | postgres.c | 161 |
HB_FUNC | PQRESET(void)
HB_FUNC( PQRESET ) { if( hb_parinfo( 1 ) ) PQreset( PGconn_par( 1 ) ); } | postgres.c | 176 |
HB_FUNC | PQPROTOCOLVERSION(void)
HB_FUNC( PQPROTOCOLVERSION ) { if( hb_parinfo( 1 ) ) hb_retni( PQprotocolVersion( PGconn_par( 1 ) ) ); } | postgres.c | 182 |
HB_FUNC | PQCLIENTENCODING(void)
HB_FUNC( PQCLIENTENCODING ) { if( hb_parinfo( 1 ) ) hb_retni( PQclientEncoding( PGconn_par( 1 ) ) ); } | postgres.c | 188 |
HB_FUNC | PQSETCLIENTENCODING(void)
HB_FUNC( PQSETCLIENTENCODING ) { if( hb_pcount() == 2 ) hb_retni( PQsetClientEncoding( PGconn_par( 1 ), hb_parcx( 2 ) ) ); } | postgres.c | 194 |
HB_FUNC | PQDB(void)
HB_FUNC( PQDB ) { if( hb_parinfo( 1 ) ) hb_retc( PQdb( PGconn_par( 1 ) ) ); } | postgres.c | 200 |
HB_FUNC | PQUSER(void)
HB_FUNC( PQUSER ) { if( hb_parinfo( 1 ) ) hb_retc( PQuser( PGconn_par( 1 ) ) ); } | postgres.c | 206 |
HB_FUNC | PQPASS(void)
HB_FUNC( PQPASS ) { if( hb_parinfo( 1 ) ) hb_retc( PQpass( PGconn_par( 1 ) ) ); } | postgres.c | 212 |
HB_FUNC | PQHOST(void)
HB_FUNC( PQHOST ) { if( hb_parinfo( 1 ) ) hb_retc( PQhost( PGconn_par( 1 ) ) ); } | postgres.c | 218 |
HB_FUNC | PQPORT(void)
HB_FUNC( PQPORT ) { if( hb_parinfo( 1 ) ) hb_retc( PQport( PGconn_par( 1 ) ) ); } | postgres.c | 224 |
HB_FUNC | PQTTY(void)
HB_FUNC( PQTTY ) { if( hb_parinfo( 1 ) ) hb_retc( PQtty( PGconn_par( 1 ) ) ); } | postgres.c | 230 |
HB_FUNC | PQOPTIONS(void)
HB_FUNC( PQOPTIONS ) { if( hb_parinfo( 1 ) ) hb_retc( PQoptions( PGconn_par( 1 ) ) ); } | postgres.c | 236 |
HB_FUNC | PQCLEAR(void)
HB_FUNC( PQCLEAR ) { if( hb_parinfo( 1 ) ) PQclear( ( PGresult * ) hb_parptr( 1 ) ); } | postgres.c | 246 |
HB_FUNC | PQEXEC(void)
HB_FUNC( PQEXEC ) { PGresult * res = NULL; if( hb_pcount() == 2 ) res = PQexec( PGconn_par( 1 ), hb_parcx( 2 ) ); hb_retptr( res ); } | postgres.c | 252 |
HB_FUNC | PQEXECPARAMS(void)
HB_FUNC( PQEXECPARAMS ) { PGresult * res = NULL; if( hb_pcount() == 3 ) { PHB_ITEM aParam = hb_param( 3, HB_IT_ARRAY ); long n = hb_arrayLen( aParam ); long i; char ** paramvalues = ( char ** ) hb_xgrab( sizeof( char * ) * n ); for( i = 0; i < n; i++ ) paramvalues[ i ] = hb_arrayGetCPtr( aParam, i + 1 ); res = PQexecParams( PGconn_par( 1 ), hb_parcx( 2 ), n, NULL, ( const char * const * ) paramvalues, NULL, NULL, 1 ); hb_xfree( paramvalues ); } hb_retptr( res ); } | postgres.c | 262 |
HB_FUNC | PQFCOUNT(void)
HB_FUNC( PQFCOUNT ) { int nFields = 0; if( hb_parinfo( 1 ) ) { PGresult * res = ( PGresult * ) hb_parptr( 1 ); if( PQresultStatus( res ) == PGRES_TUPLES_OK ) nFields = PQnfields( res ); } hb_retni( nFields ); } | postgres.c | 285 |
HB_FUNC | PQLASTREC(void)
HB_FUNC( PQLASTREC ) { int nRows = 0; if( hb_parinfo( 1 ) ) { PGresult * res = ( PGresult * ) hb_parptr( 1 ); if( PQresultStatus( res ) == PGRES_TUPLES_OK ) nRows = PQntuples( res ); } hb_retni( nRows ); } | postgres.c | 300 |
HB_FUNC | PQGETVALUE(void)
HB_FUNC( PQGETVALUE ) { if( hb_pcount() == 3 ) { PGresult * res = ( PGresult * ) hb_parptr( 1 ); if( PQresultStatus( res ) == PGRES_TUPLES_OK ) { int nRow = hb_parni( 2 ) - 1; int nCol = hb_parni( 3 ) - 1; if( ! PQgetisnull( res, nRow, nCol ) ) hb_retc( PQgetvalue( res, nRow, nCol ) ); } } } | postgres.c | 315 |
HB_FUNC | PQGETLENGTH(void)
HB_FUNC( PQGETLENGTH ) { int result = 0; if( hb_pcount() == 3 ) { PGresult * res = ( PGresult * ) hb_parptr( 1 ); if( PQresultStatus( res ) == PGRES_TUPLES_OK ) { int nRow = hb_parni( 2 ) - 1; int nCol = hb_parni( 3 ) - 1; result = PQgetlength( res, nRow, nCol ); } } hb_retni( result ); } | postgres.c | 332 |
HB_FUNC | PQMETADATA(void)
HB_FUNC( PQMETADATA ) { if( hb_parinfo( 1 ) ) { PGresult * res = ( PGresult * ) hb_parptr( 1 ); if( PQresultStatus( res ) == PGRES_TUPLES_OK ) { int nFields = PQnfields( res ), i; PHB_ITEM pResult = hb_itemArrayNew( nFields ); for( i = 0; i < nFields; i++ ) { char buf[ 256 ]; Oid type_oid = PQftype( res, i ); int typemod = PQfmod( res, i ); int length = 0; int decimal = 0; PHB_ITEM pField; switch( type_oid ) { case BITOID: if( typemod >= 0 ) length = ( int ) typemod; hb_strncpy( buf, "bit", sizeof( buf ) - 1 ); break; case BOOLOID: length = 1; hb_strncpy( buf, "boolean", sizeof( buf ) - 1 ); break; case BPCHAROID: if( typemod >= 0 ) length = ( int ) ( typemod - VARHDRSZ ); hb_strncpy( buf, "character", sizeof( buf ) - 1 ); break; case FLOAT4OID: hb_strncpy( buf, "real", sizeof( buf ) - 1 ); break; case FLOAT8OID: hb_strncpy( buf, "double precision", sizeof( buf ) - 1 ); break; case INT2OID: hb_strncpy( buf, "smallint", sizeof( buf ) - 1 ); break; case INT4OID: hb_strncpy( buf, "integer", sizeof( buf ) - 1 ); break; case OIDOID: hb_strncpy( buf, "bigint", sizeof( buf ) - 1 ); break; case INT8OID: hb_strncpy( buf, "bigint", sizeof( buf ) - 1 ); break; case NUMERICOID: length = ( ( typemod - VARHDRSZ ) >> 16 ) & 0xffff; decimal = ( typemod - VARHDRSZ ) & 0xffff; hb_strncpy( buf, "numeric", sizeof( buf ) - 1 ); break; case DATEOID: hb_strncpy( buf, "date", sizeof( buf ) - 1 ); break; case TIMEOID: case TIMETZOID: hb_strncpy( buf, "timezone", sizeof( buf ) - 1 ); break; case TIMESTAMPOID: case TIMESTAMPTZOID: hb_strncpy( buf, "timestamp", sizeof( buf ) - 1 ); break; case VARBITOID: if( typemod >= 0 ) length = (int) typemod; hb_strncpy( buf, "bit varying", sizeof( buf ) - 1 ); break; case VARCHAROID: if( typemod >= 0 ) length = ( int ) ( typemod - VARHDRSZ ); hb_strncpy( buf, "character varying", sizeof( buf ) - 1 ); break; case TEXTOID: hb_strncpy( buf, "text", sizeof( buf ) - 1 ); break; case CASHOID: hb_strncpy( buf, "money", sizeof( buf ) - 1 ); break; default: hb_strncpy( buf, "not supported", sizeof( buf ) - 1 ); break; } pField = hb_arrayGetItemPtr( pResult, i + 1 ); hb_arrayNew( pField, 6 ); hb_arraySetC( pField, 1, PQfname( res, i ) ); hb_arraySetC( pField, 2, buf ); hb_arraySetNI( pField, 3, length ); hb_arraySetNI( pField, 4, decimal ); hb_arraySetNL( pField, 5, PQftable( res, i ) ); hb_arraySetNI( pField, 6, PQftablecol( res, i ) ); } hb_itemRelease( hb_itemReturnForward( pResult ) ); return; } } hb_reta( 0 ); } | postgres.c | 352 |
HB_FUNC | PQRESULT2ARRAY(void)
HB_FUNC( PQRESULT2ARRAY ) { if( hb_parinfo( 1 ) ) { PGresult * res = ( PGresult * ) hb_parptr( 1 ); if( PQresultStatus( res ) == PGRES_TUPLES_OK ) { int nRows = PQntuples( res ), nRow; int nCols = PQnfields( res ), nCol; PHB_ITEM pResult = hb_itemArrayNew( nRows ); for( nRow = 0; nRow < nRows ; nRow++ ) { PHB_ITEM pRow = hb_arrayGetItemPtr( pResult, nRow + 1 ); hb_arrayNew( pRow, nCols ); for( nCol = 0; nCol < nCols; nCol++ ) hb_arraySetC( pRow, nCol + 1, PQgetvalue( res, nRow, nCol ) ); } hb_itemRelease( hb_itemReturnForward( pResult ) ); return; } } hb_reta( 0 ); } | postgres.c | 479 |
HB_FUNC | PQTRANSACTIONSTATUS(void)
HB_FUNC( PQTRANSACTIONSTATUS ) { if( hb_parinfo( 1 ) ) hb_retni( PQtransactionStatus( PGconn_par( 1 ) ) ); } | postgres.c | 508 |
HB_FUNC | PQERRORMESSAGE(void)
HB_FUNC( PQERRORMESSAGE ) { if( hb_parinfo( 1 ) ) hb_retc( PQerrorMessage( PGconn_par( 1 ) ) ); } | postgres.c | 514 |
HB_FUNC | PQSTATUS(void)
HB_FUNC( PQSTATUS ) { if( hb_parinfo( 1 ) ) hb_retni( PQstatus( PGconn_par( 1 ) ) ); } | postgres.c | 520 |
HB_FUNC | PQRESULTERRORMESSAGE(void)
HB_FUNC( PQRESULTERRORMESSAGE ) { if( hb_parinfo( 1 ) ) hb_retc( PQresultErrorMessage( ( PGresult * ) hb_parptr( 1 ) ) ); } | postgres.c | 526 |
HB_FUNC | PQRESULTSTATUS(void)
HB_FUNC( PQRESULTSTATUS ) { if( hb_parinfo( 1 ) ) hb_retni( PQresultStatus( ( PGresult * ) hb_parptr( 1 ) ) ); } | postgres.c | 532 |
HB_FUNC | PQCMDSTATUS(void)
HB_FUNC( PQCMDSTATUS ) { if( hb_parinfo( 1 ) ) hb_retc( PQcmdStatus( ( PGresult * ) hb_parptr( 1 ) ) ); } | postgres.c | 539 |
HB_FUNC | PQCMDTUPLES(void)
HB_FUNC( PQCMDTUPLES ) { if( hb_parinfo( 1 ) ) hb_retc( PQcmdTuples( ( PGresult * ) hb_parptr( 1 ) ) ); } | postgres.c | 546 |
HB_FUNC | PQESCAPESTRING(void)
HB_FUNC( PQESCAPESTRING ) { char * source = hb_parcx( 1 ); size_t size = strlen( source ); char * dest = ( char * ) hb_xgrab( size * 2 + 1 ); PQescapeString( dest, source, size ); hb_retc_buffer( dest ); } | postgres.c | 553 |
HB_FUNC | PQESCAPEBYTEA(void)
HB_FUNC( PQESCAPEBYTEA ) /* deprecated */ { unsigned const char * from = ( BYTE * ) hb_parc( 1 ); size_t from_length = hb_parclen( 1 ); size_t to_length = from_length * 5 + 1; unsigned char * to = PQescapeBytea( from, from_length, &to_length ); hb_retc( ( char * ) to ); /* TOFIX: ? hb_retc( ( char * ) to, to_length ); */ PQfreemem( to ); } | postgres.c | 565 |
HB_FUNC | PQUNESCAPEBYTEA(void)
HB_FUNC( PQUNESCAPEBYTEA ) { size_t to_length; unsigned char * from = PQunescapeBytea( ( BYTE * ) hb_parcx( 1 ), &to_length ); hb_retclen( ( char * ) from, to_length ); PQfreemem( from ); } | postgres.c | 577 |
HB_FUNC | PQOIDVALUE(void)
HB_FUNC( PQOIDVALUE ) { if( hb_parinfo( 1 ) ) hb_retnl( ( Oid ) PQoidValue( ( PGresult * ) hb_parptr( 1 ) ) ); } | postgres.c | 586 |
HB_FUNC | PQOIDSTATUS(void)
HB_FUNC( PQOIDSTATUS ) { if( hb_parinfo( 1 ) ) hb_retc( PQoidStatus( ( PGresult * ) hb_parptr( 1 ) ) ); } | postgres.c | 592 |
HB_FUNC | PQBINARYTUPLES(void)
HB_FUNC( PQBINARYTUPLES ) { if( hb_parinfo( 1 ) ) hb_retl( PQbinaryTuples( ( PGresult * ) hb_parptr( 1 ) ) ); } | postgres.c | 598 |
HB_FUNC | PQFTABLE(void)
HB_FUNC( PQFTABLE ) { if( hb_pcount() == 2 ) hb_retnl( ( Oid ) PQftable( ( PGresult * ) hb_parptr( 1 ), hb_parni( 2 ) - 1 ) ); } | postgres.c | 604 |
HB_FUNC | PQFTYPE(void)
HB_FUNC( PQFTYPE ) { if( hb_pcount() == 2 ) hb_retnl( ( Oid ) PQftype( ( PGresult * ) hb_parptr( 1 ), hb_parni( 2 ) - 1 ) ); } | postgres.c | 610 |
HB_FUNC | PQFNAME(void)
HB_FUNC( PQFNAME ) { if( hb_pcount() == 2 ) hb_retc( PQfname( ( PGresult * ) hb_parptr( 1 ), hb_parni( 2 ) - 1 )); } | postgres.c | 616 |
HB_FUNC | PQFMOD(void)
HB_FUNC( PQFMOD ) { if( hb_pcount() == 2 ) hb_retni( PQfmod( ( PGresult * ) hb_parptr( 1 ), hb_parni( 2 ) - 1 ) ); } | postgres.c | 622 |
HB_FUNC | PQFSIZE(void)
HB_FUNC( PQFSIZE ) { if( hb_pcount() == 2 ) hb_retni( PQfsize( ( PGresult * ) hb_parptr( 1 ), hb_parni( 2 ) - 1 ) ); } | postgres.c | 628 |
HB_FUNC | PQGETISNULL(void)
HB_FUNC( PQGETISNULL ) { if( hb_pcount() == 3 ) hb_retl( PQgetisnull( ( PGresult * ) hb_parptr( 1 ), hb_parni( 2 ) - 1 , hb_parni( 3 ) - 1 ) ); } | postgres.c | 634 |
HB_FUNC | PQFNUMBER(void)
HB_FUNC( PQFNUMBER ) { if( hb_pcount() == 2 ) hb_retni( PQfnumber( ( PGresult * ) hb_parptr( 1 ), hb_parcx( 2 ) ) + 1 ); } | postgres.c | 640 |
HB_FUNC | PQNTUPLES(void)
HB_FUNC( PQNTUPLES ) { if( hb_parinfo( 1 ) ) hb_retnl( PQntuples( ( PGresult * ) hb_parptr( 1 ) ) ); } | postgres.c | 646 |
HB_FUNC | PQNFIELDS(void)
HB_FUNC( PQNFIELDS ) { if( hb_parinfo( 1 ) ) hb_retnl( PQnfields( ( PGresult * ) hb_parptr( 1 ) ) ); } | postgres.c | 652 |
HB_FUNC | PQSENDQUERY(void)
HB_FUNC( PQSENDQUERY ) { int res = FALSE; if( hb_pcount() == 2 ) res = PQsendQuery( PGconn_par( 1 ), hb_parcx( 2 ) ); hb_retl( res ); } | postgres.c | 662 |
HB_FUNC | PQGETRESULT(void)
HB_FUNC( PQGETRESULT ) { if( hb_parinfo( 1 ) ) { PGresult * res = PQgetResult( PGconn_par( 1 ) ); /* when null, no more result to catch */ if( res ) hb_retptr( res ); } } | postgres.c | 672 |
HB_FUNC | PQCONSUMEINPUT(void)
HB_FUNC( PQCONSUMEINPUT ) { int res = 0; if( hb_parinfo( 1 ) ) res = PQconsumeInput( PGconn_par( 1 ) ); hb_retl( res ); } | postgres.c | 684 |
HB_FUNC | PQISBUSY(void)
HB_FUNC( PQISBUSY ) { int res = FALSE; if( hb_parinfo( 1 ) ) res = PQisBusy( PGconn_par( 1 ) ); hb_retl( res ); } | postgres.c | 694 |
HB_FUNC | PQREQUESTCANCEL(void)
HB_FUNC( PQREQUESTCANCEL ) /* deprecated */ { int res = FALSE; if( hb_parinfo( 1 ) ) res = PQrequestCancel( PGconn_par( 1 ) ); hb_retl( res ); } | postgres.c | 704 |
HB_FUNC | PQFLUSH(void)
HB_FUNC( PQFLUSH ) { if( hb_parinfo( 1 ) ) hb_retni( PQflush( PGconn_par( 1 ) ) ); } | postgres.c | 715 |
HB_FUNC | PQSETNONBLOCKING(void)
HB_FUNC( PQSETNONBLOCKING ) { if( hb_pcount() == 2 ) hb_retl( PQsetnonblocking( PGconn_par( 1 ), hb_parl( 2 ) ) ); } | postgres.c | 722 |
HB_FUNC | PQISNONBLOCKING(void)
HB_FUNC( PQISNONBLOCKING ) { if( hb_parinfo( 1 ) ) hb_retl( PQisnonblocking( PGconn_par( 1 ) ) ); } | postgres.c | 728 |
HB_FUNC | PQCREATETRACE(void)
HB_FUNC( PQCREATETRACE ) { #ifdef NODLL if( hb_parinfo( 1 ) ) { FILE * pFile = fopen( hb_parcx( 1 ), "w+b" ); if( pFile != NULL ) hb_retptr( ( FILE * ) pFile ); } #endif } | postgres.c | 738 |
HB_FUNC | PQCLOSETRACE(void)
HB_FUNC( PQCLOSETRACE ) { #ifdef NODLL if( hb_parinfo( 1 ) ) fclose( ( FILE * ) hb_parptr( 1 ) ); #endif } | postgres.c | 751 |
HB_FUNC | PQTRACE(void)
HB_FUNC( PQTRACE ) { #ifdef NODLL if( hb_pcount() == 2 ) PQtrace( PGconn_par( 1 ), ( FILE * ) hb_parptr( 2 ) ); #endif } | postgres.c | 759 |
HB_FUNC | PQUNTRACE(void)
HB_FUNC( PQUNTRACE ) { if( hb_parinfo( 1 ) ) PQuntrace( PGconn_par( 1 ) ); } | postgres.c | 767 |
HB_FUNC | PQSETERRORVERBOSITY(void)
HB_FUNC( PQSETERRORVERBOSITY ) { /* PQERRORS_TERSE 0 PQERRORS_DEFAULT 1 PQERRORS_VERBOSE 2 */ if( hb_pcount() == 2 ) hb_retni( ( PGVerbosity ) PQsetErrorVerbosity( PGconn_par( 1 ), ( PGVerbosity ) hb_parni( 2 ) ) ); } | postgres.c | 773 |
HB_FUNC | LO_IMPORT(void)
HB_FUNC( LO_IMPORT ) { int ret = 0; if( hb_pcount() == 2 ) ret = lo_import( PGconn_par( 1 ), hb_parcx( 2 ) ); hb_retni( ret ); } | postgres.c | 790 |
HB_FUNC | LO_EXPORT(void)
HB_FUNC( LO_EXPORT ) { int ret = FALSE; if( hb_pcount() == 3 ) ret = ( lo_export( PGconn_par( 1 ), ( Oid ) hb_parnl( 2 ), hb_parcx( 3 ) ) == 1 ); hb_retl( ret ); } | postgres.c | 800 |
HB_FUNC | LO_UNLINK(void)
HB_FUNC( LO_UNLINK ) { int ret = FALSE; if( hb_pcount() == 2 ) ret = ( lo_unlink( PGconn_par( 1 ), ( Oid ) hb_parnl( 2 ) ) == 1 ); hb_retl( ret ); } | postgres.c | 810 |
HB_FUNC | PQSERVERVERSION(void)
HB_FUNC( PQSERVERVERSION ) { if( hb_parinfo( 1 ) ) hb_retni( PQserverVersion( PGconn_par( 1 ) ) ); } | postgres.c | 822 |
HB_FUNC | PQGETCANCEL(void)
HB_FUNC( PQGETCANCEL ) { if( hb_parinfo( 1 ) ) hb_retptr( ( PGcancel * ) PQgetCancel( PGconn_par( 1 ) ) ); } | postgres.c | 828 |
HB_FUNC | PQCANCEL(void)
HB_FUNC( PQCANCEL ) { int ret = FALSE; if( hb_parinfo( 1 ) ) { char errbuf[ 256 ]; if( PQcancel( ( PGcancel * ) hb_parptr( 1 ), errbuf, sizeof( errbuf ) - 1 ) == 1 ) { ret = TRUE; hb_storc( errbuf, 2 ); } } hb_retl( ret ); } | postgres.c | 834 |
HB_FUNC | PQFREECANCEL(void)
HB_FUNC( PQFREECANCEL ) { if( hb_parinfo( 1 ) ) PQfreeCancel( ( PGcancel * ) hb_parptr( 1 ) ) ; } | postgres.c | 852 |
HB_FUNC | PQESCAPEBYTEACONN(void)
HB_FUNC( PQESCAPEBYTEACONN ) { unsigned const char * from = ( BYTE * ) hb_parc( 2 ); size_t from_length = hb_parclen( 2 ); size_t to_length = from_length * 5 + 1; unsigned char * to = PQescapeByteaConn( PGconn_par( 1 ), from, from_length, &to_length ); hb_retc( ( char * ) to ); PQfreemem( to ); } | postgres.c | 858 |
pgrdd.prg | |||
Type | Function | Source | Line |
FUNCTION | DBPGCONNECTION( cConnString )
FUNCTION DBPGCONNECTION( cConnString ) LOCAL aParams LOCAL oServer LOCAL nConn aParams := HB_ATOKENS( cConnString, ";" ) asize( aParams, 6 ) oServer := TPQServer():New( aParams[1], aParams[2], aParams[3], aParams[4], aParams[5], aParams[6] ) IF oServer:NetErr() alert( oServer:ErrorMsg() ) RETURN FAILURE ELSE aadd( s_aConnections, oServer ) nConn := len( s_aConnections ) ENDIF RETURN nConn | pgrdd.prg | 77 |
FUNCTION | DBPGCLEARCONNECTION( nConn )
FUNCTION DBPGCLEARCONNECTION( nConn ) LOCAL oServer oServer := s_aConnections[ nConn ] oServer:Close() s_aConnections[ nConn ] := nil RETURN SUCCESS | pgrdd.prg | 99 |
STATIC FUNCTION | PG_INIT( nRDD )
STATIC FUNCTION PG_INIT( nRDD ) USRRDD_RDDDATA( nRDD ) RETURN SUCCESS | pgrdd.prg | 116 |
STATIC FUNCTION | PG_NEW( pWA )
STATIC FUNCTION PG_NEW( pWA ) USRRDD_AREADATA( pWA, array( AREA_LEN ) ) RETURN SUCCESS | pgrdd.prg | 129 |
STATIC FUNCTION | PG_OPEN( nWA, aOpenInfo )
STATIC FUNCTION PG_OPEN( nWA, aOpenInfo ) LOCAL aField, oError, lError, cError, nResult LOCAL oServer, oQuery, aStruct, aFieldStruct LOCAL aWAData := USRRDD_AREADATA( nWA ) lError := .F. if !empty( aOpenInfo[ UR_OI_CONNECT ] ) .and. aOpenInfo[ UR_OI_CONNECT ] <= len( s_aConnections ) oServer := s_aConnections[ aOpenInfo[ UR_OI_CONNECT ] ] endif if !empty( oServer ) oServer:lAllCols := .F. oQuery := oServer:Query( aOpenInfo[ UR_OI_NAME ] ) lError := oQuery:NetErr() cError := oQuery:ErrorMsg() else lError := .T. cError := "Invalid connection handle" endif IF lError oError := ErrorNew() oError:GenCode := EG_OPEN oError:SubCode := 1000 oError:Description := HB_LANGERRMSG( EG_OPEN ) + ", " + cError oError:FileName := aOpenInfo[ UR_OI_NAME ] oError:CanDefault := .T. UR_SUPER_ERROR( nWA, oError ) RETURN FAILURE ELSE aWAData[ AREA_QUERY ] := oQuery ENDIF UR_SUPER_SETFIELDEXTENT( nWA, oQuery:nFields ) aStruct := oQuery:Struct() FOR EACH aFieldStruct IN aStruct aField := ARRAY( UR_FI_SIZE ) aField[ UR_FI_NAME ] := aFieldStruct[ DBS_NAME ] aField[ UR_FI_TYPE ] := aFieldStruct[ DBS_TYPE ] aField[ UR_FI_TYPEEXT ] := 0 aField[ UR_FI_LEN ] := aFieldStruct[ DBS_LEN ] aField[ UR_FI_DEC ] := aFieldStruct[ DBS_DEC ] UR_SUPER_ADDFIELD( nWA, aField ) NEXT /* Call SUPER OPEN to finish allocating work area (f.e.: alias settings) */ nResult := UR_SUPER_OPEN( nWA, aOpenInfo ) RETURN nResult | pgrdd.prg | 135 |
STATIC FUNCTION | PG_CLOSE( nWA )
STATIC FUNCTION PG_CLOSE( nWA ) LOCAL aWAData := USRRDD_AREADATA( nWA ) aWAData[ AREA_QUERY ]:Close() RETURN UR_SUPER_CLOSE( nWA ) | pgrdd.prg | 190 |
STATIC FUNCTION | PG_GETVALUE( nWA, nField, xValue )
STATIC FUNCTION PG_GETVALUE( nWA, nField, xValue ) LOCAL aWAData := USRRDD_AREADATA( nWA ) if !empty( aWAData[ AREA_ROW ] ) xValue := aWAData[ AREA_ROW ]:FieldGet( nField ) else xValue := aWAData[ AREA_QUERY ]:FieldGet( nField ) endif RETURN SUCCESS | pgrdd.prg | 197 |
STATIC FUNCTION | PG_PUTVALUE( nWA, nField, xValue )
STATIC FUNCTION PG_PUTVALUE( nWA, nField, xValue ) LOCAL aWAData := USRRDD_AREADATA( nWA ) if empty( aWAData[ AREA_ROW ] ) aWAData[ AREA_ROW ] := aWAData[ AREA_QUERY ]:GetRow() endif aWAData[ AREA_ROW ]:FieldPut( nField, xValue ) RETURN SUCCESS | pgrdd.prg | 208 |
STATIC FUNCTION | PG_SKIP( nWA, nRecords )
STATIC FUNCTION PG_SKIP( nWA, nRecords ) LOCAL aWAData := USRRDD_AREADATA( nWA ) if !empty( aWAData[ AREA_ROW ] ) PG_FLUSH( nWA ) endif aWAData[ AREA_QUERY ]:Skip( nRecords ) RETURN SUCCESS | pgrdd.prg | 219 |
STATIC FUNCTION | PG_GOTOP( nWA )
STATIC FUNCTION PG_GOTOP( nWA ) RETURN PG_GOTO( nWA, 1 ) | pgrdd.prg | 230 |
STATIC FUNCTION | PG_GOBOTTOM( nWA )
STATIC FUNCTION PG_GOBOTTOM( nWA ) RETURN PG_GOTO( nWA, -1 ) | pgrdd.prg | 233 |
STATIC FUNCTION | PG_GOTOID( nWA, nRecord )
STATIC FUNCTION PG_GOTOID( nWA, nRecord ) RETURN PG_GOTO( nWA, nRecord ) | pgrdd.prg | 236 |
STATIC FUNCTION | PG_GOTO( nWA, nRecord )
STATIC FUNCTION PG_GOTO( nWA, nRecord ) LOCAL aWAData := USRRDD_AREADATA( nWA ) if !empty( aWAData[ AREA_ROW ] ) PG_FLUSH( nWA ) endif if nRecord < 0 nRecord := aWAData[ AREA_QUERY ]:nLastRec elseif nRecord == 0 nRecord := aWAData[ AREA_QUERY ]:nRecno endif aWAData[ AREA_QUERY ]:Goto( nRecord ) RETURN SUCCESS | pgrdd.prg | 239 |
STATIC FUNCTION | PG_RECCOUNT( nWA, nRecords )
STATIC FUNCTION PG_RECCOUNT( nWA, nRecords ) LOCAL aWAData := USRRDD_AREADATA( nWA ) nRecords := aWAData[ AREA_QUERY ]:nLastRec RETURN SUCCESS | pgrdd.prg | 256 |
STATIC FUNCTION | PG_BOF( nWA, lBof )
STATIC FUNCTION PG_BOF( nWA, lBof ) LOCAL aWAData := USRRDD_AREADATA( nWA ) lBof := aWAData[ AREA_QUERY ]:lBof RETURN SUCCESS | pgrdd.prg | 263 |
STATIC FUNCTION | PG_EOF( nWA, lEof )
STATIC FUNCTION PG_EOF( nWA, lEof ) LOCAL aWAData := USRRDD_AREADATA( nWA ) lEof := aWAData[ AREA_QUERY ]:lEof RETURN SUCCESS | pgrdd.prg | 270 |
STATIC FUNCTION | PG_RECID( nWA, nRecNo )
STATIC FUNCTION PG_RECID( nWA, nRecNo ) LOCAL aWAData := USRRDD_AREADATA( nWA ) nRecno := aWAData[ AREA_QUERY ]:nRecNo RETURN SUCCESS | pgrdd.prg | 277 |
STATIC FUNCTION | PG_DELETED( nWA, lDeleted )
STATIC FUNCTION PG_DELETED( nWA, lDeleted ) HB_SYMBOL_UNUSED( nWA ) lDeleted := .F. RETURN SUCCESS | pgrdd.prg | 284 |
STATIC FUNCTION | PG_FLUSH( nWA )
STATIC FUNCTION PG_FLUSH( nWA ) LOCAL oError LOCAL aWAData := USRRDD_AREADATA( nWA ) LOCAL nRecno if aWAData[ AREA_ROW ] != nil if !empty( aWAData[ AREA_APPEND ] ) aWAData[ AREA_QUERY ]:Append( aWAData[ AREA_ROW ] ) else nRecno := aWAData[ AREA_QUERY ]:nRecNo aWAData[ AREA_QUERY ]:Update( aWAData[ AREA_ROW ] ) endif IF aWAData[ AREA_QUERY ]:lError oError := ErrorNew() oError:GenCode := EG_DATATYPE oError:SubCode := 3000 oError:Description := HB_LANGERRMSG( EG_DATATYPE ) + ", " + aWAData[ AREA_QUERY ]:ErrorMsg() UR_SUPER_ERROR( nWA, oError ) RETURN FAILURE ENDIF /* * The :Refresh() below costs a lot in term of performance. * It redo the select to include inserts and updates. * It is the only solution I've found so far to simulate dbf behaviour */ aWAData[ AREA_QUERY ]:Refresh( .T., .F. ) if !empty( aWAData[ AREA_APPEND ] ) aWAData[ AREA_APPEND ] := .F. nRecno := aWAData[ AREA_QUERY ]:nLastRec endif aWAData[ AREA_ROW ] := nil PG_GOTO( nWA, nRecno ) endif RETURN SUCCESS | pgrdd.prg | 289 |
STATIC FUNCTION | PG_APPEND( nWA, nRecords )
STATIC FUNCTION PG_APPEND( nWA, nRecords ) LOCAL aWAData := USRRDD_AREADATA( nWA ) HB_SYMBOL_UNUSED( nRecords ) aWAData[ AREA_ROW ] := aWAData[ AREA_QUERY ]:GetBlankRow() aWAData[ AREA_APPEND ] := .T. RETURN SUCCESS | pgrdd.prg | 331 |
STATIC FUNCTION | PG_DELETE( nWA )
STATIC FUNCTION PG_DELETE( nWA ) LOCAL oError LOCAL aWAData := USRRDD_AREADATA( nWA ) aWAData[ AREA_ROW ] := aWAData[ AREA_QUERY ]:GetRow() aWAData[ AREA_QUERY ]:Delete( aWAData[ AREA_ROW ] ) IF aWAData[ AREA_QUERY ]:lError oError := ErrorNew() oError:GenCode := EG_DATATYPE oError:SubCode := 2000 oError:Description := HB_LANGERRMSG( EG_DATATYPE ) + ", " + aWAData[ AREA_QUERY ]:ErrorMsg() UR_SUPER_ERROR( nWA, oError ) RETURN FAILURE ENDIF aWAData[ AREA_ROW ] := nil RETURN SUCCESS | pgrdd.prg | 342 |
FUNCTION | PGRDD_GETFUNCTABLE( pFuncCount, pFuncTable, pSuperTable, nRddID )
FUNCTION PGRDD_GETFUNCTABLE( pFuncCount, pFuncTable, pSuperTable, nRddID ) LOCAL cSuperRDD := NIL /* NO SUPER RDD */ LOCAL aMyFunc[ UR_METHODCOUNT ] aMyFunc[ UR_INIT ] := ( @PG_INIT() ) aMyFunc[ UR_NEW ] := ( @PG_NEW() ) aMyFunc[ UR_OPEN ] := ( @PG_OPEN() ) aMyFunc[ UR_GETVALUE ] := ( @PG_GETVALUE() ) aMyFunc[ UR_PUTVALUE ] := ( @PG_PUTVALUE() ) aMyFunc[ UR_SKIP ] := ( @PG_SKIP() ) aMyFunc[ UR_GOTO ] := ( @PG_GOTO() ) aMyFunc[ UR_GOTOID ] := ( @PG_GOTOID() ) aMyFunc[ UR_GOTOP ] := ( @PG_GOTOP() ) aMyFunc[ UR_GOBOTTOM ] := ( @PG_GOBOTTOM() ) aMyFunc[ UR_RECCOUNT ] := ( @PG_RECCOUNT() ) aMyFunc[ UR_RECID ] := ( @PG_RECID() ) aMyFunc[ UR_BOF ] := ( @PG_BOF() ) aMyFunc[ UR_EOF ] := ( @PG_EOF() ) aMyFunc[ UR_DELETED ] := ( @PG_DELETED() ) aMyFunc[ UR_FLUSH ] := ( @PG_FLUSH() ) aMyFunc[ UR_APPEND ] := ( @PG_APPEND() ) aMyFunc[ UR_DELETE ] := ( @PG_DELETE() ) aMyFunc[ UR_CLOSE ] := ( @PG_CLOSE() ) RETURN USRRDD_GETFUNCTABLE( pFuncCount, pFuncTable, pSuperTable, nRddID, ; cSuperRDD, aMyFunc ) | pgrdd.prg | 367 |
INIT PROC | PG_INIT()
INIT PROC PG_INIT() rddRegister( "PGRDD", RDT_FULL ) RETURN | pgrdd.prg | 394 |
tpostgre.prg | |||
Type | Function | Source | Line |
CLASS | TPQServer
CLASS TPQServer DATA pDb DATA lTrans DATA lallCols INIT .T. DATA Schema INIT 'public' DATA lError INIT .F. DATA cError INIT '' DATA lTrace INIT .F. DATA pTrace METHOD New( cHost, cDatabase, cUser, cPass, nPort, Schema ) METHOD Destroy() | tpostgre.prg | 59 |
TPQSERVER:METHOD | Close()
METHOD Close() INLINE ::Destroy() METHOD StartTransaction() | tpostgre.prg | 71 |
TPQSERVER:METHOD | TransactionStatus()
METHOD TransactionStatus() INLINE PQtransactionstatus(::pDb) METHOD Commit() METHOD Rollback() METHOD Query( cQuery ) | tpostgre.prg | 74 |
TPQSERVER:METHOD | Execute( cQuery )
METHOD Execute( cQuery ) INLINE ::Query(cQuery) METHOD SetSchema( cSchema ) | tpostgre.prg | 79 |
TPQSERVER:METHOD | NetErr()
METHOD NetErr() INLINE ::lError | tpostgre.prg | 82 |
TPQSERVER:METHOD | ErrorMsg()
METHOD ErrorMsg() INLINE ::cError METHOD TableExists( cTable ) METHOD ListTables() METHOD TableStruct( cTable ) METHOD CreateTable( cTable, aStruct ) METHOD DeleteTable( cTable ) METHOD TraceOn(cFile) METHOD TraceOff() | tpostgre.prg | 83 |
TPQSERVER:METHOD | SetVerbosity(num)
METHOD SetVerbosity(num) INLINE PQsetErrorVerbosity( ::pDb, iif( num >= 0 .and. num <= 2, num, 1 ) ) //DESTRUCTOR Destroy ENDCLASS | tpostgre.prg | 92 |
TPQSERVER:METHOD | New( cHost, cDatabase, cUser, cPass, nPort, Schema ) CLASS TPQserver
METHOD New( cHost, cDatabase, cUser, cPass, nPort, Schema ) CLASS TPQserver Local res DEFAULT nPort TO 5432 ::pDB := PQconnect(cDatabase, cHost, cUser, cPass, nPort) if PQstatus(::pDb) != CONNECTION_OK ::lError := .T. ::cError := PQerrormessage(::pDb) else if ! Empty(Schema) ::SetSchema(Schema) else res := PQexec( ::pDB, 'SELECT current_schema()' ) if PQresultStatus(res) == PGRES_TUPLES_OK ::Schema := PQgetvalue( res, 1, 1 ) endif PQclear(res) endif endif RETURN self | tpostgre.prg | 98 |
TPQSERVER:METHOD | Destroy() CLASS TPQserver
METHOD Destroy() CLASS TPQserver ::TraceOff() PQClose(::pDb) RETURN nil | tpostgre.prg | 123 |
TPQSERVER:METHOD | SetSchema( cSchema ) CLASS TPQserver
METHOD SetSchema( cSchema ) CLASS TPQserver Local res Local result := .F. if PQstatus(::pDb) == CONNECTION_OK ::Schema := cSchema res := PQexec( ::pDB, 'SET search_path TO ' + cSchema ) result := (PQresultStatus(res) == PGRES_COMMAND_OK) PQclear(res) endif RETURN result | tpostgre.prg | 129 |
TPQSERVER:METHOD | StartTransaction() CLASS TPQserver
METHOD StartTransaction() CLASS TPQserver Local res, lError res := PQexec( ::pDB, 'BEGIN' ) lError := PQresultstatus(res) != PGRES_COMMAND_OK if lError ::lError := .T. ::cError := PQresultErrormessage(res) else ::lError := .F. ::cError := '' endif PQclear(res) RETURN lError | tpostgre.prg | 142 |
TPQSERVER:METHOD | Commit() CLASS TPQserver
METHOD Commit() CLASS TPQserver Local res, lError res := PQexec( ::pDB, 'COMMIT' ) lError := PQresultstatus(res) != PGRES_COMMAND_OK if lError ::lError := .T. ::cError := PQresultErrormessage(res) else ::lError := .F. ::cError := '' endif PQclear(res) RETURN lError | tpostgre.prg | 159 |
TPQSERVER:METHOD | Rollback() CLASS TPQserver
METHOD Rollback() CLASS TPQserver Local res, lError res := PQexec( ::pDB, 'ROLLBACK' ) lError := PQresultstatus(res) != PGRES_COMMAND_OK if lError ::lError := .T. ::cError := PQresultErrormessage(res) else ::lError := .F. ::cError := '' endif PQclear(res) RETURN lError | tpostgre.prg | 176 |
TPQSERVER:METHOD | Query( cQuery ) CLASS TPQserver
METHOD Query( cQuery ) CLASS TPQserver Local oQuery oQuery := TPQquery():New(::pDB, cQuery, ::lallCols, ::Schema) RETURN oQuery | tpostgre.prg | 193 |
TPQSERVER:METHOD | TableExists( cTable ) CLASS TPQserver
METHOD TableExists( cTable ) CLASS TPQserver Local result := .F. Local cQuery Local res cQuery := "select table_name " cQuery += " from information_schema.tables " cQuery += " where table_type = 'BASE TABLE' and table_schema = " + DataToSql(::Schema) + " and table_name = " + DataToSql(lower(cTable)) res := PQexec( ::pDB, cQuery ) if PQresultstatus(res) == PGRES_TUPLES_OK result := (PQlastrec(res) != 0) ::lError := .F. ::cError := '' else ::lError := .T. ::cError := PQresultErrormessage(res) endif PQclear(res) RETURN result | tpostgre.prg | 200 |
TPQSERVER:METHOD | ListTables() CLASS TPQserver
METHOD ListTables() CLASS TPQserver Local result := {} Local cQuery Local res Local i cQuery := "select table_name " cQuery += " from information_schema.tables " cQuery += " where table_schema = " + DataToSql(::Schema) + " and table_type = 'BASE TABLE' " res := PQexec( ::pDB, cQuery ) if PQresultstatus(res) == PGRES_TUPLES_OK For i := 1 to PQlastrec(res) aadd( result, PQgetvalue( res, i, 1 ) ) Next ::lError := .F. ::cError := '' else ::lError := .T. ::cError := PQresultErrormessage(res) endif PQclear(res) RETURN result | tpostgre.prg | 224 |
TPQSERVER:METHOD | TableStruct( cTable ) CLASS TPQserver
METHOD TableStruct( cTable ) CLASS TPQserver Local result := {} Local cQuery Local res Local i Local cField Local cType Local nSize Local nDec cQuery := "SELECT column_name, data_type, character_maximum_length, numeric_precision, numeric_scale " cQuery += " FROM information_schema.columns " cQuery += " WHERE table_schema = " + DataToSql(::Schema) + " and table_name = " + DataToSql(lower(cTable)) cQuery += "ORDER BY ordinal_position " res := PQexec( ::pDB, cQuery ) if PQresultstatus(res) == PGRES_TUPLES_OK For i := 1 to PQlastrec(res) cField := PQgetvalue(res, i, 1) cType := PQgetvalue(res, i, 2) nSize := PQgetvalue(res, i, 4) nDec := PQgetvalue(res, i, 5) if 'char' $ cType cType := 'C' nSize := Val(PQgetvalue(res, i, 3)) nDec := 0 elseif 'text' $ cType cType := 'M' nSize := 10 nDec := 0 elseif 'boolean' $ cType cType := 'L' nSize := 1 nDec := 0 elseif 'smallint' $ cType cType := 'N' nSize := 5 nDec := 0 elseif 'integer' $ cType .or. 'serial' $ cType cType := 'N' nSize := 9 nDec := 0 elseif 'bigint' $ cType .or. 'bigserial' $ cType cType := 'N' nSize := 19 nDec := 0 elseif 'decimal' $ cType .or. 'numeric' $ cType cType := 'N' nDec := val(nDec) // Postgres don't store ".", but .dbf does, it can cause data width problem nSize := val(nSize) + iif( nDec > 0, 1, 0 ) // Numeric/Decimal without scale/precision can genarete big values, so, i limit this to 10,5 if nDec > 100 nDec := 5 endif if nSize > 100 nSize := 15 endif elseif 'real' $ cType .or. 'float4' $ cType cType := 'N' nSize := 15 nDec := 4 elseif 'double precision' $ cType .or. 'float8' $ cType cType := 'N' nSize := 19 nDec := 9 elseif 'money' $ cType cType := 'N' nSize := 9 nDec := 2 elseif 'timestamp' $ cType cType := 'C' nSize := 20 nDec := 0 elseif 'date' $ cType cType := 'D' nSize := 8 nDec := 0 elseif 'time' $ cType cType := 'C' nSize := 10 nDec := 0 else // Unsuported cType := 'U' nSize := 0 nDec := -1 end if !( cType == 'U' ) aadd( result, { cField, cType, nSize, nDec } ) end Next ::lError := .F. ::cError := '' else ::lError := .T. ::cError := PQresultErrormessage(res) endif PQclear(res) RETURN result | tpostgre.prg | 250 |
TPQSERVER:METHOD | CreateTable( cTable, aStruct ) CLASS TPQserver
METHOD CreateTable( cTable, aStruct ) CLASS TPQserver Local result := .T. Local cQuery Local res Local i cQuery := 'CREATE TABLE ' + ::Schema + '.' + cTable + '( ' For i := 1 to Len(aStruct) cQuery += aStruct[i, 1] if aStruct[ i, 2 ] == "C" cQuery += ' Char(' + ltrim(str(aStruct[i, 3])) + ')' elseif aStruct[ i, 2 ] == "D" cQuery += ' Date ' elseif aStruct[ i, 2 ] == "N" cQuery += ' Numeric(' + ltrim(str(aStruct[i, 3])) + ',' + ltrim(str(aStruct[i,4])) + ')' elseif aStruct[ i, 2 ] == "L" cQuery += ' boolean ' elseif aStruct[ i, 2 ] == "M" cQuery += ' text ' end if i == Len(aStruct) cQuery += ')' else cQuery += ',' end Next res := PQexec( ::pDB, cQuery ) if PQresultstatus(res) != PGRES_COMMAND_OK result := .F. ::lError := .T. ::cError := PQresultErrormessage(res) else ::lError := .F. ::cError := '' end PQclear(res) RETURN result | tpostgre.prg | 373 |
TPQSERVER:METHOD | DeleteTable( cTable ) CLASS TPQserver
METHOD DeleteTable( cTable ) CLASS TPQserver Local result := .T. Local res res := PQexec( ::pDB, 'DROP TABLE ' + ::Schema + '.' + cTable ) if PQresultstatus(res) != PGRES_COMMAND_OK result := .F. ::lError := .T. ::cError := PQresultErrormessage(res) else ::lError := .F. ::cError := '' end PQclear(res) RETURN result | tpostgre.prg | 423 |
TPQSERVER:METHOD | TraceOn( cFile ) CLASS TPQserver
METHOD TraceOn( cFile ) CLASS TPQserver ::pTrace := PQcreatetrace( cFile ) if ::pTrace != NIL PQtrace( ::pDb, ::pTrace ) ::lTrace := .t. endif RETURN nil | tpostgre.prg | 442 |
TPQSERVER:METHOD | TraceOff() CLASS TPQserver
METHOD TraceOff() CLASS TPQserver if ::pTrace != NIL PQuntrace( ::pDb ) PQclosetrace( ::pTrace ) endif ::lTrace := .f. RETURN nil | tpostgre.prg | 452 |
CLASS | TPQQuery
CLASS TPQQuery DATA pQuery DATA pDB DATA nResultStatus DATA lBof DATA lEof DATA lRead DATA lAllCols INIT .T. DATA lError INIT .F. DATA cError INIT '' DATA cQuery DATA nRecno DATA nFields DATA nLastrec DATA aStruct DATA aKeys DATA TableName DATA Schema DATA rows INIT 0 METHOD New( pDB, cQuery, lallCols, cSchema, res ) METHOD Destroy() | tpostgre.prg | 463 |
TPQQUERY:METHOD | Close()
METHOD Close() INLINE ::Destroy() METHOD Refresh() | tpostgre.prg | 490 |
TPQQUERY:METHOD | Fetch()
METHOD Fetch() INLINE ::Skip() METHOD Read() METHOD Skip( nRecno ) | tpostgre.prg | 493 |
TPQQUERY:METHOD | Bof()
METHOD Bof() INLINE ::lBof | tpostgre.prg | 497 |
TPQQUERY:METHOD | Eof()
METHOD Eof() INLINE ::lEof | tpostgre.prg | 498 |
TPQQUERY:METHOD | RecNo()
METHOD RecNo() INLINE ::nRecno | tpostgre.prg | 499 |
TPQQUERY:METHOD | Lastrec()
METHOD Lastrec() INLINE ::nLastrec METHOD Goto(nRecno) | tpostgre.prg | 500 |
TPQQUERY:METHOD | NetErr()
METHOD NetErr() INLINE ::lError | tpostgre.prg | 503 |
TPQQUERY:METHOD | ErrorMsg()
METHOD ErrorMsg() INLINE ::cError | tpostgre.prg | 504 |
TPQQUERY:METHOD | FCount()
METHOD FCount() INLINE ::nFields METHOD FieldName( nField ) METHOD FieldPos( cField ) METHOD FieldLen( nField ) METHOD FieldDec( nField ) METHOD FieldType( nField ) METHOD Update( oRow ) METHOD Delete( oRow ) METHOD Append( oRow ) METHOD SetKey() | tpostgre.prg | 506 |
TPQQUERY:METHOD | Changed(nField)
METHOD Changed(nField) INLINE ::aRow[nField] != ::aOld[nField] | tpostgre.prg | 517 |
TPQQUERY:METHOD | Blank()
METHOD Blank() INLINE ::GetBlankRow() METHOD Struct() METHOD FieldGet( nField, nRow ) METHOD GetRow( nRow ) METHOD GetBlankRow() //DESTRUCTOR Destroy ENDCLASS | tpostgre.prg | 518 |
TPQQUERY:METHOD | New( pDB, cQuery, lallCols, cSchema, res ) CLASS TPQquery
METHOD New( pDB, cQuery, lallCols, cSchema, res ) CLASS TPQquery ::pDB := pDB ::nResultStatus := -1 ::cQuery := cQuery ::lallCols := lallCols ::Schema := cSchema if ! ISNIL(res) ::pQuery := res endif ::Refresh(ISNIL(res)) RETURN self | tpostgre.prg | 530 |
TPQQUERY:METHOD | Destroy() CLASS TPQquery
METHOD Destroy() CLASS TPQquery if !( ::nResultStatus == -1 ) PQclear( ::pQuery ) ::nResultStatus := -1 endif RETURN .T. | tpostgre.prg | 545 |
TPQQUERY:METHOD | Refresh(lQuery,lMeta) CLASS TPQquery
METHOD Refresh(lQuery,lMeta) CLASS TPQquery Local res Local cTableCodes := '' Local cFieldCodes := '' Local aStruct := {} Local aTemp := {} Local i Local cType, nDec, nSize Default lQuery To .T. Default lMeta To .T. ::Destroy() ::lBof := .T. ::lEof := .T. ::lRead := .F. ::nRecno := 0 ::nLastrec := 0 ::Rows := 0 if lQuery res := PQexec( ::pDB, ::cQuery ) else res := ::pQuery endif ::nResultStatus := PQresultstatus(res) if ::nResultStatus == PGRES_TUPLES_OK if lMeta ::aStruct := {} ::nFields := 0 // Get some information about metadata aTemp := PQmetadata(res) if ISARRAY(aTemp) For i := 1 to Len(aTemp) cType := aTemp[ i, 2 ] nSize := aTemp[ i, 3 ] nDec := aTemp[ i, 4 ] if 'char' $ cType cType := 'C' elseif 'numeric' $ cType .or. 'decimal' $ cType cType := 'N' // Postgres don't store ".", but .dbf does, it can cause data width problem if nDec > 0 nSize++ // Numeric/Decimal without scale/precision can genarete big values, so, i limit this to 10,5 if nDec > 100 nDec := 5 endif endif if nSize > 100 nSize := 15 endif elseif 'date' $ cType cType := 'D' nSize := 8 elseif 'text' $ cType cType := 'M' elseif 'boolean' $ cType cType := 'L' nSize := 1 elseif 'smallint' $ cType cType := 'N' nSize := 5 elseif 'integer' $ cType .or. 'serial' $ cType cType := 'N' nSize := 9 elseif 'bigint' $ cType .or. 'bigserial' $ cType cType := 'N' nSize := 19 elseif 'real' $ cType .or. 'float4' $ cType cType := 'N' nSize := 15 nDec := 4 elseif 'double precision' $ cType .or. 'float8' $ cType cType := 'N' nSize := 19 nDec := 9 elseif 'money' $ cType cType := 'N' nSize := 10 nDec := 2 elseif 'timestamp' $ cType cType := 'C' nSize := 20 elseif 'time' $ cType cType := 'C' nSize := 10 else // Unsuported cType := 'K' endif aadd( aStruct, {aTemp[ i, 1 ], cType, nSize, nDec, aTemp[i, 5], aTemp[i, 6]} ) Next ::nFields := PQfcount(res) ::aStruct := aStruct endif endif ::nLastrec := PQlastrec(res) ::lError := .F. ::cError := '' if ::nLastrec != 0 ::nRecno := 1 ::lBof := .F. ::lEof := .F. endif elseif ::nResultStatus == PGRES_COMMAND_OK ::lError := .F. ::cError := '' ::rows := val(PQcmdTuples(res)) else ::lError := .T. ::cError := PQresultErrormessage(res) endif ::pQuery := res RETURN ! ::lError | tpostgre.prg | 553 |
TPQQUERY:METHOD | Struct() CLASS TPQquery
METHOD Struct() CLASS TPQquery Local result := {} Local i For i := 1 to Len(::aStruct) aadd( result, { ::aStruct[i, 1], ::aStruct[i, 2], ::aStruct[i, 3], ::aStruct[i, 4] }) Next RETURN result | tpostgre.prg | 700 |
TPQQUERY:METHOD | Read() CLASS TPQquery
METHOD Read() CLASS TPQquery if !::lEof if !::lRead ::lRead := .T. else ::Skip( 1 ) endif endif RETURN !::lEof | tpostgre.prg | 709 |
TPQQUERY:METHOD | Skip( nrecno ) CLASS TPQquery
METHOD Skip( nrecno ) CLASS TPQquery DEFAULT nRecno TO 1 if ::nRecno + nRecno > 0 .and. ::nRecno + nRecno <= ::nLastrec ::nRecno := ::nRecno + nRecno ::lEof := .F. ::lBof := .F. else if ::nRecno + nRecno > ::nLastRec ::nRecno := ::nLastRec + 1 ::lEof := .T. end if ::nRecno + nRecno < 1 ::nRecno := 1 ::lBof := .T. end end RETURN .T. | tpostgre.prg | 721 |
TPQQUERY:METHOD | Goto( nRecno ) CLASS TPQquery
METHOD Goto( nRecno ) CLASS TPQquery if nRecno > 0 .and. nRecno <= ::nLastrec ::nRecno := nRecno ::lEof := .F. end RETURN .T. | tpostgre.prg | 743 |
TPQQUERY:METHOD | FieldPos( cField ) CLASS TPQquery
METHOD FieldPos( cField ) CLASS TPQquery cField := trim(Lower(cField)) RETURN AScan( ::aStruct, {|x| x[1] == cField }) | tpostgre.prg | 751 |
TPQQUERY:METHOD | FieldName( nField ) CLASS TPQquery
METHOD FieldName( nField ) CLASS TPQquery Local result if ISCHARACTER(nField) nField := ::Fieldpos(nField) elseif nField < 1 .or. nField > len(::aStruct) nField := 0 endif if nField > 0 result := ::aStruct[nField, 1] endif RETURN result | tpostgre.prg | 757 |
TPQQUERY:METHOD | FieldType( nField ) CLASS TPQquery
METHOD FieldType( nField ) CLASS TPQquery Local result if ISCHARACTER(nField) nField := ::Fieldpos(nField) elseif nField < 1 .or. nField > len(::aStruct) nField := 0 endif if nField > 0 result := ::aStruct[nField, 2] end RETURN result | tpostgre.prg | 772 |
TPQQUERY:METHOD | FieldLen( nField ) CLASS TPQquery
METHOD FieldLen( nField ) CLASS TPQquery Local result if ISCHARACTER(nField) nField := ::Fieldpos(nField) elseif nField < 1 .or. nField > len(::aStruct) nField := 0 endif if nField > 0 result := ::aStruct[nField, 3] end RETURN result | tpostgre.prg | 787 |
TPQQUERY:METHOD | FieldDec( nField ) CLASS TPQquery
METHOD FieldDec( nField ) CLASS TPQquery Local result if ISCHARACTER(nField) nField := ::Fieldpos(nField) elseif nField < 1 .or. nField > len(::aStruct) nField := 0 endif if nField > 0 result := ::aStruct[nField, 4] end RETURN result | tpostgre.prg | 802 |
TPQQUERY:METHOD | Delete(oRow) CLASS TPQquery
METHOD Delete(oRow) CLASS TPQquery Local res Local i Local nField Local xField Local cQuery Local cWhere := '' Local aParams := {} ::SetKey() if ! Empty(::Tablename) .and. ! Empty(::aKeys) For i := 1 to len(::aKeys) nField := oRow:Fieldpos(::aKeys[i]) xField := oRow:FieldGetOld(nField) cWhere += ::aKeys[i] + ' = $' + ltrim(str(i)) AADD( aParams, ValueToString(xField) ) if i != len(::aKeys) cWhere += ' and ' endif Next if ! (cWhere == '') cQuery := 'DELETE FROM ' + ::Schema + '.' + ::Tablename + ' WHERE ' + cWhere res := PQexecParams( ::pDB, cQuery, aParams) if PQresultstatus(res) != PGRES_COMMAND_OK ::lError := .T. ::cError := PQresultErrormessage(res) ::rows := 0 else ::lError := .F. ::cError := '' ::rows := val(PQcmdTuples(res)) endif PQclear(res) end else ::lError := .T. ::cError := 'There is no primary keys or query is a joined table' endif RETURN ! ::lError | tpostgre.prg | 817 |
TPQQUERY:METHOD | Append( oRow ) CLASS TPQquery
METHOD Append( oRow ) CLASS TPQquery Local cQuery Local i Local res Local lChanged := .f. Local aParams := {} Local nParams := 0 ::SetKey() if ! Empty(::Tablename) cQuery := 'INSERT INTO ' + ::Schema + '.' + ::Tablename + '(' For i := 1 to oRow:FCount() if ::lallCols .or. oRow:changed(i) lChanged := .t. cQuery += oRow:Fieldname(i) + ',' endif Next cQuery := Left( cQuery, len(cQuery) - 1 ) + ') VALUES (' For i := 1 to oRow:FCount() if ::lallCols .or. oRow:Changed(i) nParams++ cQuery += '$' + ltrim(str(nParams)) + ',' aadd( aParams, ValueToString(oRow:FieldGet(i)) ) endif Next cQuery := Left( cQuery, len(cQuery) - 1 ) + ')' if lChanged res := PQexecParams( ::pDB, cQuery, aParams) if PQresultstatus(res) != PGRES_COMMAND_OK ::lError := .T. ::cError := PQresultErrormessage(res) ::rows := 0 else ::lError := .F. ::cError := '' ::rows := val(PQcmdTuples(res)) endif PQclear(res) endif else ::lError := .T. ::cError := 'Cannot insert in a joined table, or unknown error' endif RETURN ! ::lError | tpostgre.prg | 864 |
TPQQUERY:METHOD | Update(oRow) CLASS TPQquery
METHOD Update(oRow) CLASS TPQquery Local result := .F. Local cQuery Local i Local nField Local xField Local cWhere Local res Local lChanged := .f. Local aParams := {} Local nParams := 0 ::SetKey() if ! Empty(::Tablename) .and. ! Empty(::aKeys) cWhere := '' For i := 1 to len(::aKeys) nField := oRow:Fieldpos(::aKeys[i]) xField := oRow:FieldGetOld(nField) cWhere += ::aKeys[i] + '=' + DataToSql(xField) if i != len(::aKeys) cWhere += ' and ' end Next cQuery := 'UPDATE ' + ::Schema + '.' + ::Tablename + ' SET ' For i := 1 to oRow:FCount() if ::lallcols .or. oRow:Changed(i) lChanged := .t. nParams++ cQuery += oRow:Fieldname(i) + ' = $' + ltrim(str(nParams)) + ',' aadd( aParams, ValueToString(oRow:FieldGet(i)) ) end Next if ! (cWhere == '') .and. lChanged cQuery := Left( cQuery, len(cQuery) - 1 ) + ' WHERE ' + cWhere res := PQexecParams( ::pDB, cQuery, aParams) if PQresultstatus(res) != PGRES_COMMAND_OK ::lError := .T. ::cError := PQresultErrormessage(res) ::rows := 0 else ::lError := .F. ::cError := '' ::rows := val(PQcmdTuples(res)) endif PQclear(res) end else ::lError := .T. ::cError := 'Cannot insert in a joined table, or unknown error' endif RETURN ! ::lError | tpostgre.prg | 917 |
TPQQUERY:METHOD | FieldGet( nField, nRow ) CLASS TPQquery
METHOD FieldGet( nField, nRow ) CLASS TPQquery Local result Local cType Local nSize if ISCHARACTER(nField) nField := ::Fieldpos(nField) elseif nField < 1 .or. nField > ::nFields nField := 0 endif if nField > 0 .and. ::nResultStatus == PGRES_TUPLES_OK if ISNIL(nRow) nRow := ::nRecno endif result := PQgetvalue( ::pQuery, nRow, nField) cType := ::aStruct[ nField, 2 ] nSize := ::aStruct[ nField, 3 ] if cType == "C" if ISNIL(result) result := "" else result := result end elseif cType == "N" if ! ISNIL(result) result := val(result) else result := 0 end elseif cType == "D" if ! ISNIL(result) result := StoD( strtran( result, "-", "" ) ) else result := CtoD('') end elseif cType == "L" if ! ISNIL(result) result := (result == 't') else result := .F. end elseif cType == "M" if ISNIL(result) result := "" else result := result end end end RETURN result | tpostgre.prg | 980 |
TPQQUERY:METHOD | Getrow( nRow ) CLASS TPQquery
METHOD Getrow( nRow ) CLASS TPQquery Local result, aRow := {}, aOld := {}, nCol DEFAULT nRow TO ::nRecno if ::nResultStatus == PGRES_TUPLES_OK if nRow > 0 .and. nRow <= ::nLastRec ASize(aRow, ::nFields) ASize(aOld, ::nFields) For nCol := 1 to ::nFields aRow[nCol] := ::Fieldget(nCol, nRow) aOld[nCol] := ::Fieldget(nCol, nRow) Next result := TPQRow():New( aRow, aOld, ::aStruct ) elseif nRow > ::nLastrec result := ::GetBlankRow() end end RETURN result | tpostgre.prg | 1041 |
TPQQUERY:METHOD | GetBlankRow() CLASS TPQquery
METHOD GetBlankRow() CLASS TPQquery Local result, aRow := {}, aOld := {}, i ASize(aRow, ::nFields) ASize(aOld, ::nFields) For i := 1 to ::nFields if ::aStruct[i, 2] == 'C' aRow[i] := '' aOld[i] := '' elseif ::aStruct[i, 2] == 'N' aRow[i] := 0 aOld[i] := 0 elseif ::aStruct[i, 2] == 'L' aRow[i] := .F. aOld[i] := .F. elseif ::aStruct[i, 2] == 'D' aRow[i] := CtoD('') aOld[i] := CtoD('') elseif ::aStruct[i, 2] == 'M' aRow[i] := '' aOld[i] := '' end Next result := TPQRow():New( aRow, aOld, ::aStruct ) RETURN result | tpostgre.prg | 1067 |
TPQQUERY:METHOD | SetKey() CLASS TPQquery
METHOD SetKey() CLASS TPQquery Local cQuery Local i, x Local nTableId, xTableId := -1 Local nCount := 0 Local res Local nPos if ::nResultStatus == PGRES_TUPLES_OK if ISNIL(::Tablename) /* set the table name looking for table oid */ for i := 1 to len(::aStruct) /* Store table codes oid */ nTableId := ::aStruct[i, 5] if nTableId != xTableId xTableId := nTableId nCount++ endif next if nCount == 1 /* first, try get the table name from select, else get from pg_catalog */ if (npos := at('FROM ', Upper(::cQuery))) != 0 cQuery := lower(ltrim(substr( ::cQuery, nPos + 5 ))) if (npos := at('.', cQuery)) != 0 ::Schema := alltrim(left(cQuery,npos-1)) cQuery := substr(cQuery, nPos + 1) endif if (npos := at(' ', cQuery)) != 0 ::Tablename := trim(Left(cQuery, npos)) else ::Tablename := cQuery endif endif if empty(::Tablename) cQuery := 'select relname from pg_class where oid = ' + str(xTableId) res := PQexec(::pDB, cQuery) if PQresultstatus(res) == PGRES_TUPLES_OK .and. PQlastrec(res) != 0 ::Tablename := trim(PQgetvalue(res, 1, 1)) endif PQclear(res) endif endif endif if ISNIL(::aKeys) .and. ! empty(::Tablename) /* Set the table primary keys */ cQuery := "SELECT c.attname " cQuery += " FROM pg_class a, pg_class b, pg_attribute c, pg_index d, pg_namespace e " cQuery += " WHERE a.oid = d.indrelid " cQuery += " AND a.relname = '" + ::Tablename + "'" cQuery += " AND b.oid = d.indexrelid " cQuery += " AND c.attrelid = b.oid " cQuery += " AND d.indisprimary " cQuery += " AND e.oid = a.relnamespace " cQuery += " AND e.nspname = " + DataToSql(::Schema) res := PQexec(::pDB, cQuery) if PQresultstatus(res) == PGRES_TUPLES_OK .and. PQlastrec(res) != 0 ::aKeys := {} For x := 1 To PQlastrec(res) aadd( ::aKeys, PQgetvalue( res, x, 1 ) ) Next endif PQclear(res) endif endif RETURN nil | tpostgre.prg | 1096 |
CLASS | TPQRow
CLASS TPQRow DATA aRow DATA aOld DATA aStruct METHOD New( row, old, struct ) | tpostgre.prg | 1176 |
TPQROW:METHOD | FCount()
METHOD FCount() INLINE Len(::aRow) METHOD FieldGet( nField ) METHOD FieldPut( nField, Value ) METHOD FieldName( nField ) METHOD FieldPos( cFieldName ) METHOD FieldLen( nField ) METHOD FieldDec( nField ) METHOD FieldType( nField ) | tpostgre.prg | 1183 |
TPQROW:METHOD | Changed( nField )
METHOD Changed( nField ) INLINE !(::aRow[nField] == ::aOld[nField]) | tpostgre.prg | 1191 |
TPQROW:METHOD | FieldGetOld( nField )
METHOD FieldGetOld( nField ) INLINE ::aOld[nField] ENDCLASS | tpostgre.prg | 1192 |
TPQROW:METHOD | new( row, old, struct) CLASS TPQrow
METHOD new( row, old, struct) CLASS TPQrow ::aRow := row ::aOld := old ::aStruct := struct RETURN self | tpostgre.prg | 1196 |
TPQROW:METHOD | FieldGet( nField ) CLASS TPQrow
METHOD FieldGet( nField ) CLASS TPQrow Local result if ISCHARACTER(nField) nField := ::Fieldpos(nField) endif if nField >= 1 .and. nField <= len(::aRow) result := ::aRow[nField] end RETURN result | tpostgre.prg | 1203 |
TPQROW:METHOD | FieldPut( nField, Value ) CLASS TPQrow
METHOD FieldPut( nField, Value ) CLASS TPQrow Local result if ISCHARACTER(nField) nField := ::Fieldpos(nField) endif if nField >= 1 .and. nField <= len(::aRow) result := ::aRow[nField] := Value end RETURN result | tpostgre.prg | 1217 |
TPQROW:METHOD | FieldName( nField ) CLASS TPQrow
METHOD FieldName( nField ) CLASS TPQrow Local result if ISCHARACTER(nField) nField := ::Fieldpos(nField) endif if nField >= 1 .and. nField <= len(::aStruct) result := ::aStruct[nField, 1] end RETURN result | tpostgre.prg | 1230 |
TPQROW:METHOD | FieldPos( cField ) CLASS TPQrow
METHOD FieldPos( cField ) CLASS TPQrow Local result := 0 result := AScan( ::aStruct, {|x| x[1] == trim(lower(cField)) }) RETURN result | tpostgre.prg | 1244 |
TPQROW:METHOD | FieldType( nField ) CLASS TPQrow
METHOD FieldType( nField ) CLASS TPQrow Local result if ISCHARACTER(nField) nField := ::Fieldpos(nField) endif if nField >= 1 .and. nField <= len(::aStruct) result := ::aStruct[nField, 2] end RETURN result | tpostgre.prg | 1252 |
TPQROW:METHOD | FieldLen( nField ) CLASS TPQrow
METHOD FieldLen( nField ) CLASS TPQrow Local result if ISCHARACTER(nField) nField := ::Fieldpos(nField) endif if nField >= 1 .and. nField <= len(::aStruct) result := ::aStruct[nField, 3] end RETURN result | tpostgre.prg | 1266 |
TPQROW:METHOD | FieldDec( nField ) CLASS TPQrow
METHOD FieldDec( nField ) CLASS TPQrow Local result if ISCHARACTER(nField) nField := ::Fieldpos(nField) endif if nField >= 1 .and. nField <= len(::aStruct) result := ::aStruct[nField, 4] end RETURN result | tpostgre.prg | 1279 |
STATIC FUNCTION | DataToSql(xField)
Static Function DataToSql(xField) Local cType, result := 'NULL' cType := ValType(xField) if cType == "C" .or. cType == "M" result := "'"+ strtran(xField, "'", ' ') + "'" elseif cType == "D" result := dtos( xField) elseif cType == "N" result := str(xField) elseif cType == "L" result := iif( xField, "'t'", "'f'" ) end return result | tpostgre.prg | 1292 |
STATIC FUNCTION | ValueToString(xField)
Static Function ValueToString(xField) Local cType, result := nil cType := ValType(xField) if cType == "D" result := dtos( xField ) elseif cType == "N" result := str(xField) elseif cType == "L" result := iif( xField, "t", "f" ) elseif cType == "C" .or. cType == "M" result := xField end return result | tpostgre.prg | 1308 |
Page url: http://www.yourdomain.com/help/index.html?hbpgsql.htm