diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 0a655c5a44..ae7bc24098 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,51 @@ past entries belonging to author(s): Viktor Szakats. */ +2009-11-20 14:28 UTC+0200 Mindaugas Kavaliauskas (dbtopas/at/dbtopas.lt) + + harbour/contrib/rddsql/hbrddsql.ch + * harbour/contrib/rddsql/hbrddsql.h + * DBI_ and RDDI_ defines moved to .ch file + + * harbour/contrib/rddsql/sddmy/tests/test1.prg + * harbour/contrib/rddsql/sddodbc/tests/test1.prg + * harbour/contrib/rddsql/sddodbc/tests/test2.prg + * hbrddsql.ch include used + + * harbour/contrib/rddsql/sddodbc/tests/test2.prg + ! fixed small error in DSN + + * harbour/contrib/rddsql/sddodbc/odbcdd.c + * implemented error processing + + * harbour/contrib/rddsql/sddfb/fbirddd.c + * harbour/contrib/rddsql/sddmy/mysqldd.c + * harbour/contrib/rddsql/sddodbc/odbcdd.c + * harbour/contrib/rddsql/sddpg/pgsqldd.c + * harbour/contrib/rddsql/sqlbase.c + * harbour/contrib/rddsql/sqlmix.c + * source formatting + * changed error variables type to HB_ERRCODE + + * harbour/contrib/rddsql/sddfb/fbirddd.c + * harbour/contrib/rddsql/sddmy/mysqldd.c + * moved unsupported (by some compiler) compile time condition + check to RDD initialisation run-time condition check + + * harbour/contrib/rddsql/hbrddsql.h + * harbour/contrib/rddsql/sqlbase.c + * implemented connection area counter. Now connection can be + closed only after all its workareas are closed. + + * harbour/contrib/rddsql/hbrddsql.h + * harbour/contrib/rddsql/sqlbase.c + * SQL error text, error number, last query, etc. Moved from + connection to static variables, because I'm unable to return + errors for a failed connect otherwise. + ; TODO: MT support. Error text and code are stored in static + variable, it should be moved to thread static in the future. + But there is more problems in MT support. F.e., can we use + use the same connection for a few threads? + 2009-11-20 13:18 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * src/rtl/errapi.c * Renamed error variables to use new prefix. diff --git a/harbour/contrib/rddsql/hbrddsql.ch b/harbour/contrib/rddsql/hbrddsql.ch new file mode 100644 index 0000000000..82ba5a8d9d --- /dev/null +++ b/harbour/contrib/rddsql/hbrddsql.ch @@ -0,0 +1,67 @@ +/* + * $Id$ + */ + +/* + * SQL Database Driver include file + * + * Copyright 2009 Mindaugas Kavaliauskas + * www - http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +#ifndef HB_RDDSQL_CH_ +#define HB_RDDSQL_CH_ + +/* New ...INFO_ constants */ +#define DBI_QUERY 1001 + +#define RDDI_CONNECT 1001 +#define RDDI_DISCONNECT 1002 +#define RDDI_EXECUTE 1003 +#define RDDI_ERROR 1004 +#define RDDI_ERRORNO 1005 +#define RDDI_NEWID 1006 +#define RDDI_AFFECTEDROWS 1007 +#define RDDI_QUERY 1008 + +#endif \ No newline at end of file diff --git a/harbour/contrib/rddsql/hbrddsql.h b/harbour/contrib/rddsql/hbrddsql.h index 02b0d63819..f203bb1b79 100644 --- a/harbour/contrib/rddsql/hbrddsql.h +++ b/harbour/contrib/rddsql/hbrddsql.h @@ -50,28 +50,15 @@ */ -#ifndef HBSQLDD_H_ -#define HBSQLDD_H_ +#ifndef HB_RDDSQL_H_ +#define HB_RDDSQL_H_ #include "hbapirdd.h" #include "hbdbferr.h" #include "hbapierr.h" #include "hbapilng.h" #include "hbapi.h" - - -/* New ...INFO_ constants */ -#define DBI_QUERY 1001 - -#define RDDI_CONNECT 1001 -#define RDDI_DISCONNECT 1002 -#define RDDI_EXECUTE 1003 -#define RDDI_ERROR 1004 -#define RDDI_ERRORNO 1005 -#define RDDI_NEWID 1006 -#define RDDI_AFFECTEDROWS 1007 -#define RDDI_QUERY 1008 - +#include "hbrddsql.ch" /* ==================================================================== @@ -99,45 +86,41 @@ typedef struct _SQLBASEAREA LPDBRELINFO lpdbPendingRel; ULONG ulConnection; - struct _SQLDDCONNECTION* pConnection; - struct _SDDNODE* pSDD; + struct _SQLDDCONNECTION * pConnection; + struct _SDDNODE * pSDD; - char* szQuery; /* SQL query */ + char * szQuery; /* SQL query */ ULONG ulRecNo; /* Current record number */ ULONG ulRecCount; /* Total records */ ULONG ulRecMax; /* Size of pRow, pRowFlags buffer */ - void** pRow; /* array of native pointers or cached PHB_ITEM */ - BYTE* pRowFlags; + void ** pRow; /* array of native pointers or cached PHB_ITEM */ + BYTE * pRowFlags; - void* pRecord; + void * pRecord; BYTE bRecordFlags; - void* pResult; /* SQL result */ - void* pStmt; /* SQL statement */ - void* pTrans; /* SQL transaction */ + void * pResult; /* SQL result */ + void * pStmt; /* SQL statement */ + void * pTrans; /* SQL transaction */ - void* pNatRecord; - void* pNatLength; + void * pNatRecord; + void * pNatLength; BOOL fFetched; BOOL fPositioned; BOOL fAppend; BOOL fRecordChanged; -} SQLBASEAREA, *SQLBASEAREAP; +} SQLBASEAREA, * SQLBASEAREAP; typedef struct _SQLDDCONNECTION { struct _SDDNODE * pSDD; - void* hConnection; - void* hCargo; - int iError; - char* szError; - char* szQuery; - PHB_ITEM pNewID; - ULONG ulAffectedRows; + void * hConnection; + void * hCargo; + unsigned int uiAreaCount; } SQLDDCONNECTION; @@ -159,33 +142,33 @@ typedef struct _MIXKEY ULONG rec; BYTE notnul; BYTE val[ 1 ]; -} MIXKEY, *PMIXKEY; +} MIXKEY, * PMIXKEY; typedef struct _MIXNODE { unsigned int Leaf; unsigned int KeyCount; - struct _MIXNODE* Parent; - struct _MIXNODE* Child[ MIX_NODE_ORDER + 1 ]; -} MIXNODE, *PMIXNODE; + struct _MIXNODE * Parent; + struct _MIXNODE * Child[ MIX_NODE_ORDER + 1 ]; +} MIXNODE, * PMIXNODE; typedef struct _MIXNODELEAF { unsigned int Leaf; unsigned int KeyCount; - struct _MIXNODE* Parent; -} MIXNODELEAF, *PMIXNODELEAF; + struct _MIXNODE * Parent; +} MIXNODELEAF, * PMIXNODELEAF; typedef struct _MIXTAG { - struct _MIXTAG* pNext; - struct _SQLMIXAREA* pArea; - char* szName; - char* szKeyExpr; - char* szForExpr; + struct _MIXTAG * pNext; + struct _SQLMIXAREA * pArea; + char * szName; + char * szKeyExpr; + char * szForExpr; PHB_ITEM pKeyItem; PHB_ITEM pForItem; @@ -207,7 +190,7 @@ typedef struct _MIXTAG BOOL HotFor; PHB_CODEPAGE pCodepage; /* National sorttable for character key tags, NULL otherwise */ -} MIXTAG, *PMIXTAG; +} MIXTAG, * PMIXTAG; typedef struct _SQLMIXAREA @@ -221,7 +204,7 @@ typedef struct _SQLMIXAREA PMIXTAG pTagList; PMIXTAG pTag; PHB_CODEPAGE pCodepage; -} SQLMIXAREA, *SQLMIXAREAP; +} SQLMIXAREA, * SQLMIXAREAP; @@ -231,21 +214,21 @@ typedef struct _SQLMIXAREA ==================================================================== */ -typedef HB_ERRCODE (* SDDFUNC_CONNECT )( SQLDDCONNECTION* pConnection, PHB_ITEM pItem ); -typedef HB_ERRCODE (* SDDFUNC_DISCONNECT )( SQLDDCONNECTION* pConnection ); -typedef HB_ERRCODE (* SDDFUNC_EXECUTE )( SQLDDCONNECTION* pConnection, PHB_ITEM pItem ); -typedef HB_ERRCODE (* SDDFUNC_OPEN )( SQLBASEAREAP pArea ); -typedef HB_ERRCODE (* SDDFUNC_CLOSE )( SQLBASEAREAP pArea ); -typedef HB_ERRCODE (* SDDFUNC_GOTO )( SQLBASEAREAP pArea, ULONG ulRecNo ); -typedef HB_ERRCODE (* SDDFUNC_GETVALUE )( SQLBASEAREAP pArea, USHORT uiIndex, PHB_ITEM pItem ); -typedef HB_ERRCODE (* SDDFUNC_GETVARLEN )( SQLBASEAREAP pArea, USHORT uiIndex, ULONG * pLength ); +typedef HB_ERRCODE (* SDDFUNC_CONNECT )( SQLDDCONNECTION * pConnection, PHB_ITEM pItem ); +typedef HB_ERRCODE (* SDDFUNC_DISCONNECT )( SQLDDCONNECTION * pConnection ); +typedef HB_ERRCODE (* SDDFUNC_EXECUTE )( SQLDDCONNECTION * pConnection, PHB_ITEM pItem ); +typedef HB_ERRCODE (* SDDFUNC_OPEN )( SQLBASEAREAP pArea ); +typedef HB_ERRCODE (* SDDFUNC_CLOSE )( SQLBASEAREAP pArea ); +typedef HB_ERRCODE (* SDDFUNC_GOTO )( SQLBASEAREAP pArea, ULONG ulRecNo ); +typedef HB_ERRCODE (* SDDFUNC_GETVALUE )( SQLBASEAREAP pArea, USHORT uiIndex, PHB_ITEM pItem ); +typedef HB_ERRCODE (* SDDFUNC_GETVARLEN )( SQLBASEAREAP pArea, USHORT uiIndex, ULONG * pLength ); typedef struct _SDDNODE { struct _SDDNODE * pNext; - const char* Name; + const char * Name; SDDFUNC_CONNECT Connect; SDDFUNC_DISCONNECT Disconnect; SDDFUNC_EXECUTE Execute; @@ -257,16 +240,6 @@ typedef struct _SDDNODE } SDDNODE, * PSDDNODE; -int hb_sddRegister( PSDDNODE pSdd ); - - - -/* -==================================================================== - Misc -==================================================================== -*/ - /* Error subcodes */ #define ESQLDD_NOTCONNECTED 1901 #define ESQLDD_INVALIDFIELD 1902 @@ -279,5 +252,11 @@ int hb_sddRegister( PSDDNODE pSdd ); #define ESQLDD_FETCH 1909 #define ESQLDD_LOWMEMORY 1910 #define ESQLDD_NULLSDD 1911 +#define ESQLDD_CONNALLOC 1912 +#define ESQLDD_ENVALLOC 1913 + + +int hb_sddRegister( PSDDNODE pSdd ); +void hb_rddsqlSetError( HB_ERRCODE errCode, const char * szError, const char * szQuery, PHB_ITEM pItem, unsigned long ulAffectedRows ); #endif diff --git a/harbour/contrib/rddsql/sddfb/fbirddd.c b/harbour/contrib/rddsql/sddfb/fbirddd.c index 7458870c06..cf35244f9e 100644 --- a/harbour/contrib/rddsql/sddfb/fbirddd.c +++ b/harbour/contrib/rddsql/sddfb/fbirddd.c @@ -67,17 +67,11 @@ #include "ibase.h" -#if 0 /* Some compilers does not support this compile time check */ -#if sizeof( isc_db_handle ) != sizeof( void* ) - #error "SDDFB error: sizeof( isc_db_handle ) != sizeof( void* )" -#endif -#endif - #define DIALECT 1 -static HB_ERRCODE fbConnect( SQLDDCONNECTION* pConnection, PHB_ITEM pItem ); -static HB_ERRCODE fbDisconnect( SQLDDCONNECTION* pConnection ); -static HB_ERRCODE fbExecute( SQLDDCONNECTION* pConnection, PHB_ITEM pItem ); +static HB_ERRCODE fbConnect( SQLDDCONNECTION * pConnection, PHB_ITEM pItem ); +static HB_ERRCODE fbDisconnect( SQLDDCONNECTION * pConnection ); +static HB_ERRCODE fbExecute( SQLDDCONNECTION * pConnection, PHB_ITEM pItem ); static HB_ERRCODE fbOpen( SQLBASEAREAP pArea ); static HB_ERRCODE fbClose( SQLBASEAREAP pArea ); static HB_ERRCODE fbGoTo( SQLBASEAREAP pArea, ULONG ulRecNo ); @@ -86,14 +80,14 @@ static HB_ERRCODE fbGoTo( SQLBASEAREAP pArea, ULONG ulRecNo ); static SDDNODE firebirddd = { NULL, "FIREBIRD", - (SDDFUNC_CONNECT) fbConnect, - (SDDFUNC_DISCONNECT) fbDisconnect, - (SDDFUNC_EXECUTE) fbExecute, - (SDDFUNC_OPEN) fbOpen, - (SDDFUNC_CLOSE) fbClose, - (SDDFUNC_GOTO) fbGoTo, - (SDDFUNC_GETVALUE) NULL, - (SDDFUNC_GETVARLEN) NULL + ( SDDFUNC_CONNECT ) fbConnect, + ( SDDFUNC_DISCONNECT ) fbDisconnect, + ( SDDFUNC_EXECUTE ) fbExecute, + ( SDDFUNC_OPEN ) fbOpen, + ( SDDFUNC_CLOSE ) fbClose, + ( SDDFUNC_GOTO ) fbGoTo, + ( SDDFUNC_GETVALUE ) NULL, + ( SDDFUNC_GETVARLEN ) NULL }; @@ -103,7 +97,7 @@ static void hb_firebirddd_init( void * cargo ) { HB_SYMBOL_UNUSED( cargo ); - if ( ! hb_sddRegister( & firebirddd ) ) + if ( ! hb_sddRegister( & firebirddd ) || ( sizeof( isc_db_handle ) != sizeof( void * ) ) ) { hb_errInternal( HB_EI_RDDINVALID, NULL, NULL, NULL ); HB_FUNC_EXEC( SQLBASE ); /* force SQLBASE linking */ @@ -135,23 +129,20 @@ HB_CALL_ON_STARTUP_END( _hb_firebirddd_init_ ) /* ===================================================================================== */ -static USHORT hb_errRT_FireBirdDD( ULONG ulGenCode, ULONG ulSubCode, const char * szDescription, const char * szOperation, USHORT uiOsCode ) +static USHORT hb_errRT_FireBirdDD( HB_ERRCODE errGenCode, HB_ERRCODE errSubCode, const char * szDescription, const char * szOperation, HB_ERRCODE errOsCode ) { USHORT uiAction; PHB_ITEM pError; - pError = hb_errRT_New( ES_ERROR, "SDDFB", ulGenCode, ulSubCode, szDescription, szOperation, uiOsCode, EF_NONE ); - + pError = hb_errRT_New( ES_ERROR, "SDDFB", errGenCode, errSubCode, szDescription, szOperation, errOsCode, EF_NONE ); uiAction = hb_errLaunch( pError ); - hb_itemRelease( pError ); - return uiAction; } /* ============= SDD METHODS ============================================================= */ -static HB_ERRCODE fbConnect( SQLDDCONNECTION* pConnection, PHB_ITEM pItem ) +static HB_ERRCODE fbConnect( SQLDDCONNECTION * pConnection, PHB_ITEM pItem ) { ISC_STATUS status[ 5 ]; isc_db_handle db = ( isc_db_handle ) 0; @@ -177,26 +168,26 @@ static HB_ERRCODE fbConnect( SQLDDCONNECTION* pConnection, PHB_ITEM pItem ) i += ul; if ( isc_attach_database( status, ( short ) hb_arrayGetCLen( pItem, 5 ), hb_arrayGetCPtr( pItem, 5 ), - & db, (short) i, parambuf ) ) + & db, ( short ) i, parambuf ) ) { /* TODO: error code in status[1]; */ return HB_FAILURE; } - pConnection->hConnection = ( void* ) ( HB_PTRDIFF ) db; + pConnection->hConnection = ( void * ) ( HB_PTRDIFF ) db; return HB_SUCCESS; } -static HB_ERRCODE fbDisconnect( SQLDDCONNECTION* pConnection ) +static HB_ERRCODE fbDisconnect( SQLDDCONNECTION * pConnection ) { ISC_STATUS status[ 5 ]; - isc_detach_database( status, (isc_db_handle*) (void*) &pConnection->hConnection ); + isc_detach_database( status, ( isc_db_handle * ) ( void * ) &pConnection->hConnection ); return HB_SUCCESS; } -static HB_ERRCODE fbExecute( SQLDDCONNECTION* pConnection, PHB_ITEM pItem ) +static HB_ERRCODE fbExecute( SQLDDCONNECTION * pConnection, PHB_ITEM pItem ) { HB_SYMBOL_UNUSED( pConnection ); HB_SYMBOL_UNUSED( pItem ); @@ -219,19 +210,19 @@ static HB_ERRCODE fbOpen( SQLBASEAREAP pArea ) int iType; - if ( isc_start_transaction ( status, &pTrans, 1, (isc_db_handle*) (void*) &pArea->pConnection->hConnection, 0, NULL ) ) + if ( isc_start_transaction ( status, &pTrans, 1, ( isc_db_handle * ) ( void * ) &pArea->pConnection->hConnection, 0, NULL ) ) { - hb_errRT_FireBirdDD( EG_OPEN, ESQLDD_START, "Start transaction failed", NULL, ( USHORT ) status[ 1 ] ); + hb_errRT_FireBirdDD( EG_OPEN, ESQLDD_START, "Start transaction failed", NULL, ( HB_ERRCODE ) status[ 1 ] ); return HB_FAILURE; } - pSqlda = (XSQLDA*) hb_xgrab( XSQLDA_LENGTH( 1 ) ); + pSqlda = ( XSQLDA * ) hb_xgrab( XSQLDA_LENGTH( 1 ) ); pSqlda->sqln = 1; pSqlda->version = 1; - if ( isc_dsql_allocate_statement( status, (isc_db_handle*) (void*) &pArea->pConnection->hConnection, &pStmt ) ) + if ( isc_dsql_allocate_statement( status, ( isc_db_handle * ) ( void * ) &pArea->pConnection->hConnection, &pStmt ) ) { - hb_errRT_FireBirdDD( EG_OPEN, ESQLDD_STMTALLOC, "Allocate statement failed", NULL, ( USHORT ) status[ 1 ] ); + hb_errRT_FireBirdDD( EG_OPEN, ESQLDD_STMTALLOC, "Allocate statement failed", NULL, ( HB_ERRCODE ) status[ 1 ] ); isc_rollback_transaction( status, &pTrans ); hb_xfree( pSqlda ); return HB_FAILURE; @@ -239,7 +230,7 @@ static HB_ERRCODE fbOpen( SQLBASEAREAP pArea ) if ( isc_dsql_prepare( status, &pTrans, &pStmt, 0, pArea->szQuery, DIALECT, pSqlda ) ) { - hb_errRT_FireBirdDD( EG_OPEN, ESQLDD_INVALIDQUERY, "Prepare statement failed", pArea->szQuery, ( USHORT ) status[ 1 ] ); + hb_errRT_FireBirdDD( EG_OPEN, ESQLDD_INVALIDQUERY, "Prepare statement failed", pArea->szQuery, ( HB_ERRCODE ) status[ 1 ] ); isc_dsql_free_statement( status, &pStmt, DSQL_drop ); isc_rollback_transaction( status, &pTrans ); hb_xfree( pSqlda ); @@ -249,13 +240,13 @@ static HB_ERRCODE fbOpen( SQLBASEAREAP pArea ) if ( pSqlda->sqld > pSqlda->sqln ) { uiFields = pSqlda->sqld; hb_xfree( pSqlda ); - pSqlda = (XSQLDA*) hb_xgrab( XSQLDA_LENGTH( uiFields ) ); + pSqlda = ( XSQLDA * ) hb_xgrab( XSQLDA_LENGTH( uiFields ) ); pSqlda->sqln = uiFields; pSqlda->version = 1; if ( isc_dsql_describe( status, & pStmt, DIALECT, pSqlda ) ) { - hb_errRT_FireBirdDD( EG_OPEN, ESQLDD_STMTDESCR, "Describe statement failed", NULL, ( USHORT ) status[ 1 ] ); + hb_errRT_FireBirdDD( EG_OPEN, ESQLDD_STMTDESCR, "Describe statement failed", NULL, ( HB_ERRCODE ) status[ 1 ] ); isc_dsql_free_statement( status, &pStmt, DSQL_drop ); isc_rollback_transaction( status, &pTrans ); hb_xfree( pSqlda ); @@ -264,7 +255,7 @@ static HB_ERRCODE fbOpen( SQLBASEAREAP pArea ) } uiFields = pSqlda->sqld; - SELF_SETFIELDEXTENT( (AREAP) pArea, uiFields ); + SELF_SETFIELDEXTENT( ( AREAP ) pArea, uiFields ); pItemEof = hb_itemArrayNew( uiFields ); @@ -330,7 +321,7 @@ static HB_ERRCODE fbOpen( SQLBASEAREAP pArea ) } if ( pVar->sqltype & 1 ) - pVar->sqlind = (short*) hb_xgrab( sizeof( short ) ); + pVar->sqlind = ( short * ) hb_xgrab( sizeof( short ) ); if ( ! bError ) { @@ -388,7 +379,7 @@ static HB_ERRCODE fbOpen( SQLBASEAREAP pArea ) } */ if ( ! bError ) - bError = ( SELF_ADDFIELD( (AREAP) pArea, &pFieldInfo ) == HB_FAILURE ); + bError = ( SELF_ADDFIELD( ( AREAP ) pArea, &pFieldInfo ) == HB_FAILURE ); } if ( bError ) @@ -398,8 +389,8 @@ static HB_ERRCODE fbOpen( SQLBASEAREAP pArea ) hb_xfree( pBuffer ); pArea->pResult = pSqlda; - pArea->pStmt = ( void* ) ( HB_PTRDIFF ) pStmt; - pArea->pTrans = ( void* ) ( HB_PTRDIFF ) pTrans; + pArea->pStmt = ( void * ) ( HB_PTRDIFF ) pStmt; + pArea->pTrans = ( void * ) ( HB_PTRDIFF ) pTrans; if ( bError ) { @@ -411,8 +402,8 @@ static HB_ERRCODE fbOpen( SQLBASEAREAP pArea ) pArea->ulRecCount = 0; - pArea->pRow = (void**) hb_xgrab( SQLDD_ROWSET_INIT * sizeof( void* ) ); - pArea->pRowFlags = (BYTE*) hb_xgrab( SQLDD_ROWSET_INIT * sizeof( BYTE ) ); + pArea->pRow = ( void ** ) hb_xgrab( SQLDD_ROWSET_INIT * sizeof( void * ) ); + pArea->pRowFlags = ( BYTE * ) hb_xgrab( SQLDD_ROWSET_INIT * sizeof( BYTE ) ); memset( pArea->pRowFlags, 0, SQLDD_ROWSET_INIT * sizeof( BYTE ) ); pArea->ulRecMax = SQLDD_ROWSET_INIT; @@ -468,14 +459,14 @@ static HB_ERRCODE fbGoTo( SQLBASEAREAP pArea, ULONG ulRecNo ) isc_stmt_handle stmt = ( isc_stmt_handle ) ( HB_PTRDIFF ) pArea->pStmt; isc_tr_handle tr = ( isc_tr_handle ) ( HB_PTRDIFF ) pArea->pTrans; - lErr = isc_dsql_fetch( status, &stmt, DIALECT, (XSQLDA *) pArea->pResult ); + lErr = isc_dsql_fetch( status, &stmt, DIALECT, ( XSQLDA * ) pArea->pResult ); if ( lErr == 0 ) { pArray = hb_itemArrayNew( pArea->area.uiFieldCount ); for ( ui = 1; ui <= pArea->area.uiFieldCount; ui++ ) { - pVar = (XSQLVAR *) pArea->pResult; + pVar = ( XSQLVAR * ) pArea->pResult; pVar += ( ui - 1 ); if ( ( pVar->sqltype & 1 ) && ( * pVar->sqlind < 0 ) ) @@ -489,23 +480,23 @@ static HB_ERRCODE fbGoTo( SQLBASEAREAP pArea, ULONG ulRecNo ) break; case SQL_VARYING: - pItem = hb_itemPutCL( NULL, pVar->sqldata + 2, * (short*) pVar->sqldata ); + pItem = hb_itemPutCL( NULL, pVar->sqldata + 2, * ( short * ) pVar->sqldata ); break; case SQL_SHORT: - pItem = hb_itemPutNI( NULL, * (short*) pVar->sqldata ); + pItem = hb_itemPutNI( NULL, * ( short * ) pVar->sqldata ); break; case SQL_LONG: - pItem = hb_itemPutNL( NULL, * (long*) pVar->sqldata ); + pItem = hb_itemPutNL( NULL, * ( long * ) pVar->sqldata ); break; case SQL_FLOAT: - pItem = hb_itemPutND( NULL, * (float*) pVar->sqldata ); + pItem = hb_itemPutND( NULL, * ( float * ) pVar->sqldata ); break; case SQL_DOUBLE: - pItem = hb_itemPutND( NULL, * (double*) pVar->sqldata ); + pItem = hb_itemPutND( NULL, * ( double * ) pVar->sqldata ); break; default: @@ -518,8 +509,8 @@ static HB_ERRCODE fbGoTo( SQLBASEAREAP pArea, ULONG ulRecNo ) if ( pArea->ulRecCount + 1 <= pArea->ulRecMax ) { - pArea->pRow = (void**) hb_xrealloc( pArea->pRow, ( pArea->ulRecMax + SQLDD_ROWSET_RESIZE ) * sizeof( void* ) ); - pArea->pRowFlags = (BYTE*) hb_xrealloc( pArea->pRowFlags, ( pArea->ulRecMax + SQLDD_ROWSET_RESIZE ) * sizeof( BYTE ) ); + pArea->pRow = ( void ** ) hb_xrealloc( pArea->pRow, ( pArea->ulRecMax + SQLDD_ROWSET_RESIZE ) * sizeof( void * ) ); + pArea->pRowFlags = ( BYTE * ) hb_xrealloc( pArea->pRowFlags, ( pArea->ulRecMax + SQLDD_ROWSET_RESIZE ) * sizeof( BYTE ) ); pArea->ulRecMax += SQLDD_ROWSET_RESIZE; } @@ -532,14 +523,14 @@ static HB_ERRCODE fbGoTo( SQLBASEAREAP pArea, ULONG ulRecNo ) pArea->fFetched = TRUE; if ( isc_dsql_free_statement( status, &stmt, DSQL_drop ) ) { - hb_errRT_FireBirdDD( EG_OPEN, ESQLDD_STMTFREE, "Statement free error", NULL, ( USHORT ) status[ 1 ] ); + hb_errRT_FireBirdDD( EG_OPEN, ESQLDD_STMTFREE, "Statement free error", NULL, ( HB_ERRCODE ) status[ 1 ] ); return HB_FAILURE; } pArea->pStmt = NULL; if ( isc_commit_transaction( status, &tr ) ) { - hb_errRT_FireBirdDD( EG_OPEN, ESQLDD_COMMIT, "Transaction commit error", NULL, ( USHORT ) status[ 1 ] ); + hb_errRT_FireBirdDD( EG_OPEN, ESQLDD_COMMIT, "Transaction commit error", NULL, ( HB_ERRCODE ) status[ 1 ] ); return HB_FAILURE; } pArea->pTrans = NULL; @@ -550,7 +541,7 @@ static HB_ERRCODE fbGoTo( SQLBASEAREAP pArea, ULONG ulRecNo ) } else { - hb_errRT_FireBirdDD( EG_OPEN, ESQLDD_FETCH, "Fetch error", NULL, ( USHORT ) lErr ); + hb_errRT_FireBirdDD( EG_OPEN, ESQLDD_FETCH, "Fetch error", NULL, ( HB_ERRCODE ) lErr ); return HB_FAILURE; } } diff --git a/harbour/contrib/rddsql/sddmy/mysqldd.c b/harbour/contrib/rddsql/sddmy/mysqldd.c index 92bff09674..06869cbf1a 100644 --- a/harbour/contrib/rddsql/sddmy/mysqldd.c +++ b/harbour/contrib/rddsql/sddmy/mysqldd.c @@ -66,35 +66,14 @@ typedef int my_socket; #include "mysql.h" -/* TOFIX: HACK to make it compile under MSVC to avoid 'invalid integer constant expression' errors. */ - -/* sizeof() inside #if will not work with any C compiler which has - * preprocessor separated from compiler so it will not work with most of - * existing C compilers. To make it working is necessary to mix preprocessor - * and compiler logic so sizeof() for newly defined types by 'typedef' will - * work. It's rather seldom situation when C compiler authors make sth like - * that. - */ -#if defined( __BORLANDC__ ) - -#if sizeof( MYSQL_ROW_OFFSET ) != sizeof( void* ) - #error "MySQLDD error: sizeof( MYSQL_ROW_OFFSET ) != sizeof( void* )" -#endif - -#if sizeof( MYSQL_ROW ) != sizeof( void* ) - #error "MySQLDD error: sizeof( MYSQL_ROW ) != sizeof( void* )" -#endif - -#endif - #ifndef MYSQL_TYPE_NEWDECIMAL #define MYSQL_TYPE_NEWDECIMAL 246 #endif -static HB_ERRCODE mysqlConnect( SQLDDCONNECTION* pConnection, PHB_ITEM pItem ); -static HB_ERRCODE mysqlDisconnect( SQLDDCONNECTION* pConnection ); -static HB_ERRCODE mysqlExecute( SQLDDCONNECTION* pConnection, PHB_ITEM pItem ); +static HB_ERRCODE mysqlConnect( SQLDDCONNECTION * pConnection, PHB_ITEM pItem ); +static HB_ERRCODE mysqlDisconnect( SQLDDCONNECTION * pConnection ); +static HB_ERRCODE mysqlExecute( SQLDDCONNECTION * pConnection, PHB_ITEM pItem ); static HB_ERRCODE mysqlOpen( SQLBASEAREAP pArea ); static HB_ERRCODE mysqlClose( SQLBASEAREAP pArea ); static HB_ERRCODE mysqlGoTo( SQLBASEAREAP pArea, ULONG ulRecNo ); @@ -105,14 +84,14 @@ static SDDNODE mysqldd = { NULL, "MYSQL", - (SDDFUNC_CONNECT) mysqlConnect, - (SDDFUNC_DISCONNECT) mysqlDisconnect, - (SDDFUNC_EXECUTE) mysqlExecute, - (SDDFUNC_OPEN) mysqlOpen, - (SDDFUNC_CLOSE) mysqlClose, - (SDDFUNC_GOTO) mysqlGoTo, - (SDDFUNC_GETVALUE) mysqlGetValue, - (SDDFUNC_GETVARLEN) NULL + ( SDDFUNC_CONNECT ) mysqlConnect, + ( SDDFUNC_DISCONNECT ) mysqlDisconnect, + ( SDDFUNC_EXECUTE ) mysqlExecute, + ( SDDFUNC_OPEN ) mysqlOpen, + ( SDDFUNC_CLOSE ) mysqlClose, + ( SDDFUNC_GOTO ) mysqlGoTo, + ( SDDFUNC_GETVALUE ) mysqlGetValue, + ( SDDFUNC_GETVARLEN ) NULL }; @@ -122,7 +101,9 @@ static void hb_mysqldd_init( void * cargo ) { HB_SYMBOL_UNUSED( cargo ); - if ( ! hb_sddRegister( & mysqldd ) ) + if ( ! hb_sddRegister( & mysqldd ) || + ( sizeof( MYSQL_ROW_OFFSET ) != sizeof( void * ) ) || + ( sizeof( MYSQL_ROW ) != sizeof( void * ) ) ) { hb_errInternal( HB_EI_RDDINVALID, NULL, NULL, NULL ); HB_FUNC_EXEC( SQLBASE ); /* force SQLBASE linking */ @@ -154,23 +135,20 @@ HB_CALL_ON_STARTUP_END( _hb_mysqldd_init_ ) /*=====================================================================================*/ -static USHORT hb_errRT_MySQLDD( ULONG ulGenCode, ULONG ulSubCode, const char * szDescription, const char * szOperation, unsigned int uiOsCode ) +static USHORT hb_errRT_MySQLDD( HB_ERRCODE errGenCode, HB_ERRCODE errSubCode, const char * szDescription, const char * szOperation, HB_ERRCODE errOsCode ) { USHORT uiAction; PHB_ITEM pError; - pError = hb_errRT_New( ES_ERROR, "SDDMY", ulGenCode, ulSubCode, szDescription, szOperation, ( USHORT ) uiOsCode, EF_NONE ); - + pError = hb_errRT_New( ES_ERROR, "SDDMY", errGenCode, errSubCode, szDescription, szOperation, errOsCode, EF_NONE ); uiAction = hb_errLaunch( pError ); - hb_itemRelease( pError ); - return uiAction; } /*============= SDD METHODS =============================================================*/ -static HB_ERRCODE mysqlConnect( SQLDDCONNECTION* pConnection, PHB_ITEM pItem ) +static HB_ERRCODE mysqlConnect( SQLDDCONNECTION * pConnection, PHB_ITEM pItem ) { MYSQL* pMySql; @@ -178,64 +156,57 @@ static HB_ERRCODE mysqlConnect( SQLDDCONNECTION* pConnection, PHB_ITEM pItem ) if ( ! mysql_real_connect( pMySql, hb_arrayGetCPtr( pItem, 2 ), hb_arrayGetCPtr( pItem, 3 ), hb_arrayGetCPtr( pItem, 4 ), hb_arrayGetCPtr( pItem, 5 ), 0 /* port */, NULL /* pipe */, 0 /* flags*/ ) ) { + hb_rddsqlSetError( mysql_errno( pMySql ), mysql_error( pMySql ), NULL, NULL, 0 ); mysql_close( pMySql ); return HB_FAILURE; } - pConnection->hConnection = (void*) pMySql; + pConnection->hConnection = ( void * ) pMySql; return HB_SUCCESS; } -static HB_ERRCODE mysqlDisconnect( SQLDDCONNECTION* pConnection ) +static HB_ERRCODE mysqlDisconnect( SQLDDCONNECTION * pConnection ) { mysql_close( ( MYSQL * ) pConnection->hConnection ); return HB_SUCCESS; } -static HB_ERRCODE mysqlExecute( SQLDDCONNECTION* pConnection, PHB_ITEM pItem ) +static HB_ERRCODE mysqlExecute( SQLDDCONNECTION * pConnection, PHB_ITEM pItem ) { - MYSQL_RES* pResult; + MYSQL_RES * pResult; + ULONG ulAffectedRows; + PHB_ITEM pNewID = NULL; - if ( mysql_real_query( (MYSQL*) pConnection->hConnection, hb_itemGetCPtr( pItem ), hb_itemGetCLen( pItem ) ) ) + if ( mysql_real_query( ( MYSQL * ) pConnection->hConnection, hb_itemGetCPtr( pItem ), hb_itemGetCLen( pItem ) ) ) { - const char* szError; - - pConnection->iError = (int) mysql_errno( (MYSQL*) pConnection->hConnection ); - szError = mysql_error( (MYSQL*) pConnection->hConnection ); - if ( pConnection->szError ) - pConnection->szError = ( char * ) hb_xrealloc( pConnection->szError, strlen( szError ) + 1 ); - else - pConnection->szError = ( char * ) hb_xgrab( strlen( szError ) + 1 ); - hb_strncpy( pConnection->szError, szError, strlen( szError ) ); + hb_rddsqlSetError( mysql_errno( ( MYSQL * ) pConnection->hConnection ), mysql_error( ( MYSQL * ) pConnection->hConnection ), hb_itemGetCPtr( pItem ), NULL, 0 ); return HB_FAILURE; } - pResult = mysql_store_result( (MYSQL*) pConnection->hConnection ); + pResult = mysql_store_result( ( MYSQL * ) pConnection->hConnection ); if ( pResult ) { - pConnection->ulAffectedRows = (ULONG) mysql_num_rows( pResult ); + ulAffectedRows = ( ULONG ) mysql_num_rows( pResult ); mysql_free_result( pResult ); + hb_rddsqlSetError( 0, NULL, hb_itemGetCPtr( pItem ), NULL, ulAffectedRows ); } else { - if ( mysql_field_count( (MYSQL*) pConnection->hConnection ) == 0 ) + if ( mysql_field_count( ( MYSQL * ) pConnection->hConnection ) == 0 ) { - pConnection->ulAffectedRows = (ULONG) mysql_affected_rows( (MYSQL*) pConnection->hConnection ); - if ( mysql_insert_id( (MYSQL*) pConnection->hConnection ) != 0 ) - hb_itemPutNInt( pConnection->pNewID, mysql_insert_id( (MYSQL*) pConnection->hConnection ) ); + ulAffectedRows = ( ULONG ) mysql_affected_rows( ( MYSQL * ) pConnection->hConnection ); + if( mysql_insert_id( ( MYSQL * ) pConnection->hConnection ) != 0 ) + { + pNewID = hb_itemPutNInt( NULL, mysql_insert_id( ( MYSQL * ) pConnection->hConnection ) ); + } + hb_rddsqlSetError( 0, NULL, hb_itemGetCPtr( pItem ), pNewID, ulAffectedRows ); + if( pNewID ) + hb_itemRelease( pNewID ); } else /* error */ { - const char* szError; - - pConnection->iError = (int) mysql_errno( (MYSQL*) pConnection->hConnection ); - szError = mysql_error( (MYSQL*) pConnection->hConnection ); - if ( pConnection->szError ) - pConnection->szError = ( char * ) hb_xrealloc( pConnection->szError, strlen( szError ) + 1 ); - else - pConnection->szError = ( char * ) hb_xgrab( strlen( szError ) + 1 ); - hb_strncpy( pConnection->szError, szError, strlen( szError ) ); + hb_rddsqlSetError( mysql_errno( ( MYSQL * ) pConnection->hConnection ), mysql_error( ( MYSQL * ) pConnection->hConnection ), hb_itemGetCPtr( pItem ), NULL, 0 ); return HB_FAILURE; } } @@ -247,38 +218,39 @@ static HB_ERRCODE mysqlOpen( SQLBASEAREAP pArea ) { PHB_ITEM pItemEof, pItem; ULONG ulIndex; - USHORT uiFields, uiCount, uiError = 0; + USHORT uiFields, uiCount; + HB_ERRCODE errCode = 0; BOOL bError; - char* pBuffer; + char * pBuffer; DBFIELDINFO pFieldInfo; - MYSQL_FIELD* pMyField; - void** pRow; + MYSQL_FIELD * pMyField; + void ** pRow; - if ( mysql_real_query( (MYSQL*) pArea->pConnection->hConnection, pArea->szQuery, strlen( pArea->szQuery ) ) ) + if ( mysql_real_query( ( MYSQL * ) pArea->pConnection->hConnection, pArea->szQuery, strlen( pArea->szQuery ) ) ) { - hb_errRT_MySQLDD( EG_OPEN, ESQLDD_INVALIDQUERY, (char*) mysql_error( (MYSQL*) pArea->pConnection->hConnection ), pArea->szQuery, - mysql_errno( (MYSQL*) pArea->pConnection->hConnection ) ); + hb_errRT_MySQLDD( EG_OPEN, ESQLDD_INVALIDQUERY, ( char * ) mysql_error( ( MYSQL * ) pArea->pConnection->hConnection ), pArea->szQuery, + mysql_errno( ( MYSQL * ) pArea->pConnection->hConnection ) ); return HB_FAILURE; } - if ( ( pArea->pResult = mysql_store_result( (MYSQL*) pArea->pConnection->hConnection ) ) == NULL ) + if ( ( pArea->pResult = mysql_store_result( ( MYSQL * ) pArea->pConnection->hConnection ) ) == NULL ) { - hb_errRT_MySQLDD( EG_MEM, ESQLDD_INVALIDQUERY, (char*) mysql_error( (MYSQL*) pArea->pConnection->hConnection ), pArea->szQuery, - mysql_errno( (MYSQL*) pArea->pConnection->hConnection ) ); + hb_errRT_MySQLDD( EG_MEM, ESQLDD_INVALIDQUERY, ( char * ) mysql_error( ( MYSQL * ) pArea->pConnection->hConnection ), pArea->szQuery, + mysql_errno( ( MYSQL * ) pArea->pConnection->hConnection ) ); return HB_FAILURE; } - uiFields = ( USHORT ) mysql_num_fields( (MYSQL_RES*) pArea->pResult ); - SELF_SETFIELDEXTENT( (AREAP) pArea, uiFields ); + uiFields = ( USHORT ) mysql_num_fields( ( MYSQL_RES * ) pArea->pResult ); + SELF_SETFIELDEXTENT( ( AREAP ) pArea, uiFields ); pItemEof = hb_itemArrayNew( uiFields ); - pBuffer = (char*) hb_xgrab( 256 ); + pBuffer = ( char * ) hb_xgrab( 256 ); bError = FALSE; for ( uiCount = 0; uiCount < uiFields; uiCount++ ) { - pMyField = mysql_fetch_field_direct( (MYSQL_RES*) pArea->pResult, uiCount ); + pMyField = mysql_fetch_field_direct( ( MYSQL_RES * ) pArea->pResult, uiCount ); hb_strncpy( pBuffer, pMyField->name, 256 - 1 ); pBuffer[ MAX_FIELD_NAME ] = '\0'; @@ -346,7 +318,7 @@ static HB_ERRCODE mysqlOpen( SQLBASEAREAP pArea ) default: bError = TRUE; - uiError = (USHORT) pMyField->type; + errCode = ( HB_ERRCODE ) pMyField->type; pFieldInfo.uiType = 0; break; } @@ -359,7 +331,7 @@ static HB_ERRCODE mysqlOpen( SQLBASEAREAP pArea ) { char* pStr; - pStr = (char*) hb_xgrab( pFieldInfo.uiLen + 1 ); + pStr = ( char * ) hb_xgrab( pFieldInfo.uiLen + 1 ); memset( pStr, ' ', pFieldInfo.uiLen ); pStr[ pFieldInfo.uiLen ] = '\0'; @@ -408,7 +380,7 @@ static HB_ERRCODE mysqlOpen( SQLBASEAREAP pArea ) }*/ if ( ! bError ) - bError = ( SELF_ADDFIELD( (AREAP) pArea, &pFieldInfo ) == HB_FAILURE ); + bError = ( SELF_ADDFIELD( ( AREAP ) pArea, &pFieldInfo ) == HB_FAILURE ); } if ( bError ) @@ -420,14 +392,14 @@ static HB_ERRCODE mysqlOpen( SQLBASEAREAP pArea ) if ( bError ) { hb_itemRelease( pItemEof ); - hb_errRT_MySQLDD( EG_CORRUPTION, ESQLDD_INVALIDFIELD, "Invalid field type", pArea->szQuery, uiError ); + hb_errRT_MySQLDD( EG_CORRUPTION, ESQLDD_INVALIDFIELD, "Invalid field type", pArea->szQuery, errCode ); return HB_FAILURE; } - pArea->ulRecCount = (ULONG) mysql_num_rows( (MYSQL_RES*) pArea->pResult ); + pArea->ulRecCount = ( ULONG ) mysql_num_rows( ( MYSQL_RES * ) pArea->pResult ); - pArea->pRow = (void**) hb_xgrab( ( pArea->ulRecCount + 1 ) * sizeof( void* ) ); - pArea->pRowFlags = (BYTE*) hb_xgrab( ( pArea->ulRecCount + 1 ) * sizeof( BYTE ) ); + pArea->pRow = ( void ** ) hb_xgrab( ( pArea->ulRecCount + 1 ) * sizeof( void * ) ); + pArea->pRowFlags = ( BYTE * ) hb_xgrab( ( pArea->ulRecCount + 1 ) * sizeof( BYTE ) ); memset( pArea->pRowFlags, 0, ( pArea->ulRecCount + 1 ) * sizeof( BYTE ) ); pArea->ulRecMax = pArea->ulRecCount + 1; @@ -439,8 +411,8 @@ static HB_ERRCODE mysqlOpen( SQLBASEAREAP pArea ) pRow++; for ( ulIndex = 1; ulIndex <= pArea->ulRecCount; ulIndex++ ) { - *pRow++ = (void*) mysql_row_tell( (MYSQL_RES*) pArea->pResult ); - mysql_fetch_row( (MYSQL_RES*) pArea->pResult ); + *pRow++ = ( void * ) mysql_row_tell( ( MYSQL_RES * ) pArea->pResult ); + mysql_fetch_row( ( MYSQL_RES * ) pArea->pResult ); } pArea->fFetched = 1; @@ -452,7 +424,7 @@ static HB_ERRCODE mysqlClose( SQLBASEAREAP pArea ) { if ( pArea->pResult ) { - mysql_free_result( (MYSQL_RES*) pArea->pResult ); + mysql_free_result( ( MYSQL_RES * ) pArea->pResult ); pArea->pResult = NULL; } return HB_SUCCESS; @@ -499,8 +471,8 @@ static HB_ERRCODE mysqlGetValue( SQLBASEAREAP pArea, USHORT uiIndex, PHB_ITEM pI uiIndex--; pField = pArea->area.lpFields + uiIndex; - pValue = ( (MYSQL_ROW) ( pArea->pNatRecord ) ) [ uiIndex ]; - ulLen = ( (unsigned long*) ( pArea->pNatLength ) ) [ uiIndex ]; + pValue = ( ( MYSQL_ROW ) ( pArea->pNatRecord ) ) [ uiIndex ]; + ulLen = ( ( unsigned long * ) ( pArea->pNatLength ) ) [ uiIndex ]; /* NULL => NIL (?) */ if ( ! pValue ) @@ -517,11 +489,11 @@ static HB_ERRCODE mysqlGetValue( SQLBASEAREAP pArea, USHORT uiIndex, PHB_ITEM pI char* pStr; /* Expand strings to field length */ - pStr = (char*) hb_xgrab( pField->uiLen + 1 ); + pStr = ( char * ) hb_xgrab( pField->uiLen + 1 ); if ( pValue ) memcpy( pStr, pValue, ulLen ); - if ( (ULONG)pField->uiLen > ulLen ) + if ( ( ULONG )pField->uiLen > ulLen ) memset( pStr + ulLen, ' ', pField->uiLen - ulLen ); pStr[ pField->uiLen ] = '\0'; @@ -555,20 +527,20 @@ static HB_ERRCODE mysqlGetValue( SQLBASEAREAP pArea, USHORT uiIndex, PHB_ITEM pI if ( pField->uiDec ) { hb_itemPutNDLen( pItem, atof( szBuffer ), - (int) pField->uiLen - ( (int) pField->uiDec + 1 ), - (int) pField->uiDec ); + ( int ) pField->uiLen - ( ( int ) pField->uiDec + 1 ), + ( int ) pField->uiDec ); } else - hb_itemPutNLLen( pItem, atol( szBuffer ), (int) pField->uiLen ); + hb_itemPutNLLen( pItem, atol( szBuffer ), ( int ) pField->uiLen ); } else { if ( pField->uiDec ) hb_itemPutNDLen( pItem, 0.0, - (int) pField->uiLen - ( (int) pField->uiDec + 1 ), - (int) pField->uiDec ); + ( int ) pField->uiLen - ( ( int ) pField->uiDec + 1 ), + ( int ) pField->uiDec ); else - hb_itemPutNLLen( pItem, 0, (int) pField->uiLen ); + hb_itemPutNLLen( pItem, 0, ( int ) pField->uiLen ); } break; diff --git a/harbour/contrib/rddsql/sddmy/tests/test1.prg b/harbour/contrib/rddsql/sddmy/tests/test1.prg index 7084cbac01..5643161846 100644 --- a/harbour/contrib/rddsql/sddmy/tests/test1.prg +++ b/harbour/contrib/rddsql/sddmy/tests/test1.prg @@ -5,17 +5,7 @@ #include "dbinfo.ch" #include "error.ch" -#define DBI_QUERY 1001 - -#define RDDI_CONNECT 1001 -#define RDDI_DISCONNECT 1002 -#define RDDI_EXECUTE 1003 -#define RDDI_ERROR 1004 -#define RDDI_ERRORNO 1005 -#define RDDI_NEWID 1006 -#define RDDI_AFFECTEDROWS 1007 -#define RDDI_QUERY 1008 - +#include "../../hbrddsql.ch" REQUEST SDDMY, SQLMIX diff --git a/harbour/contrib/rddsql/sddodbc/odbcdd.c b/harbour/contrib/rddsql/sddodbc/odbcdd.c index 848d393bda..47ce3bb029 100644 --- a/harbour/contrib/rddsql/sddodbc/odbcdd.c +++ b/harbour/contrib/rddsql/sddodbc/odbcdd.c @@ -80,9 +80,9 @@ # endif #endif -static HB_ERRCODE odbcConnect( SQLDDCONNECTION* pConnection, PHB_ITEM pItem ); -static HB_ERRCODE odbcDisconnect( SQLDDCONNECTION* pConnection ); -static HB_ERRCODE odbcExecute( SQLDDCONNECTION* pConnection, PHB_ITEM pItem ); +static HB_ERRCODE odbcConnect( SQLDDCONNECTION * pConnection, PHB_ITEM pItem ); +static HB_ERRCODE odbcDisconnect( SQLDDCONNECTION * pConnection ); +static HB_ERRCODE odbcExecute( SQLDDCONNECTION * pConnection, PHB_ITEM pItem ); static HB_ERRCODE odbcOpen( SQLBASEAREAP pArea ); static HB_ERRCODE odbcClose( SQLBASEAREAP pArea ); static HB_ERRCODE odbcGoTo( SQLBASEAREAP pArea, ULONG ulRecNo ); @@ -92,14 +92,14 @@ static SDDNODE odbcdd = { NULL, "ODBC", - (SDDFUNC_CONNECT) odbcConnect, - (SDDFUNC_DISCONNECT) odbcDisconnect, - (SDDFUNC_EXECUTE) odbcExecute, - (SDDFUNC_OPEN) odbcOpen, - (SDDFUNC_CLOSE) odbcClose, - (SDDFUNC_GOTO) odbcGoTo, - (SDDFUNC_GETVALUE) NULL, - (SDDFUNC_GETVARLEN) NULL + ( SDDFUNC_CONNECT ) odbcConnect, + ( SDDFUNC_DISCONNECT ) odbcDisconnect, + ( SDDFUNC_EXECUTE ) odbcExecute, + ( SDDFUNC_OPEN ) odbcOpen, + ( SDDFUNC_CLOSE ) odbcClose, + ( SDDFUNC_GOTO ) odbcGoTo, + ( SDDFUNC_GETVALUE ) NULL, + ( SDDFUNC_GETVARLEN ) NULL }; @@ -141,24 +141,52 @@ HB_CALL_ON_STARTUP_END( _hb_odbcdd_init_ ) /*=====================================================================================*/ -static USHORT hb_errRT_ODBCDD( ULONG ulGenCode, ULONG ulSubCode, const char * szDescription, const char * szOperation, USHORT uiOsCode ) +static USHORT hb_errRT_ODBCDD( HB_ERRCODE errGenCode, HB_ERRCODE errSubCode, const char * szDescription, const char * szOperation, HB_ERRCODE errOsCode ) { USHORT uiAction; PHB_ITEM pError; - pError = hb_errRT_New( ES_ERROR, "SDDODBC", ulGenCode, ulSubCode, szDescription, szOperation, uiOsCode, EF_NONE ); + pError = hb_errRT_New( ES_ERROR, "SDDODBC", errGenCode, errSubCode, szDescription, szOperation, errOsCode, EF_NONE ); uiAction = hb_errLaunch( pError ); hb_itemRelease( pError ); return uiAction; } + +static char * odbcGetError( SQLHENV hEnv, SQLHDBC hConn, SQLHSTMT hStmt, HB_ERRCODE * pErrCode ) +{ + SQLTCHAR szError[ 6 + SQL_MAX_MESSAGE_LENGTH ]; + SQLINTEGER iNativeErr = 9999; + SQLSMALLINT iLen; + char * szRet; + + if( SQL_SUCCEEDED( SQLError( hEnv, hConn, hStmt, szError, &iNativeErr, szError + 6, SQL_MAX_MESSAGE_LENGTH, &iLen ) ) ) + { + char * szStr; + + szError[ 5 ] = ' '; + szStr = HB_TCHAR_CONVFROM( szError ); + szRet = hb_strdup( szStr ); + HB_TCHAR_FREE( szStr ); + } + else + szRet = hb_strdup( "HY000 Unable to get error message" ); + + if( pErrCode ) + * pErrCode = ( HB_ERRCODE ) iNativeErr; + return szRet; +} + + /*============= SDD METHODS =============================================================*/ -static HB_ERRCODE odbcConnect( SQLDDCONNECTION* pConnection, PHB_ITEM pItem ) +static HB_ERRCODE odbcConnect( SQLDDCONNECTION * pConnection, PHB_ITEM pItem ) { - SQLHENV hEnv = NULL; - SQLHDBC hConnect = NULL; - + SQLHENV hEnv = NULL; + SQLHDBC hConnect = NULL; + char * szError; + HB_ERRCODE errCode; + if( SQL_SUCCEEDED( SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hEnv ) ) ) { SQLSetEnvAttr( hEnv, SQL_ATTR_ODBC_VERSION, ( SQLPOINTER ) SQL_OV_ODBC3, SQL_IS_UINTEGER ); @@ -181,22 +209,38 @@ static HB_ERRCODE odbcConnect( SQLDDCONNECTION* pConnection, PHB_ITEM pItem ) SQL_DRIVER_NOPROMPT ) ) ) { HB_TCHAR_FREE( lpStr ); - pConnection->hConnection = ( void* ) hConnect; - pConnection->hCargo = ( void* ) hEnv; + pConnection->hCargo = ( void * ) hEnv; + pConnection->hConnection = ( void * ) hConnect; return HB_SUCCESS; } else + { HB_TCHAR_FREE( lpStr ); - + szError = odbcGetError( hEnv, hConnect, SQL_NULL_HSTMT, &errCode ); + hb_rddsqlSetError( errCode, szError, NULL, NULL, 0 ); + hb_xfree( szError ); + } SQLFreeHandle( SQL_HANDLE_DBC, hConnect ); } + else + { + szError = odbcGetError( hEnv, SQL_NULL_HDBC, SQL_NULL_HSTMT, &errCode ); + hb_errRT_ODBCDD( EG_OPEN, ESQLDD_CONNALLOC, szError, hb_arrayGetCPtr( pItem, 2 ), errCode ); + hb_xfree( szError ); + } SQLFreeHandle( SQL_HANDLE_ENV, hEnv ); } + else + { + szError = odbcGetError( SQL_NULL_HENV, SQL_NULL_HDBC, SQL_NULL_HSTMT, &errCode ); + hb_errRT_ODBCDD( EG_OPEN, ESQLDD_ENVALLOC, szError, hb_arrayGetCPtr( pItem, 2 ), errCode ); + hb_xfree( szError ); + } return HB_FAILURE; } -static HB_ERRCODE odbcDisconnect( SQLDDCONNECTION* pConnection ) +static HB_ERRCODE odbcDisconnect( SQLDDCONNECTION * pConnection ) { SQLDisconnect( ( SQLHDBC ) pConnection->hConnection ); SQLFreeHandle( SQL_HANDLE_DBC, ( SQLHDBC ) pConnection->hConnection ); @@ -205,20 +249,22 @@ static HB_ERRCODE odbcDisconnect( SQLDDCONNECTION* pConnection ) } -static HB_ERRCODE odbcExecute( SQLDDCONNECTION* pConnection, PHB_ITEM pItem ) +static HB_ERRCODE odbcExecute( SQLDDCONNECTION * pConnection, PHB_ITEM pItem ) { SQLTCHAR * lpStr; SQLHSTMT hStmt; SQLLEN iCount; + char * szError; + HB_ERRCODE errCode; if ( ! SQL_SUCCEEDED( SQLAllocStmt( ( SQLHDBC ) pConnection->hConnection, &hStmt ) ) ) { - hb_errRT_ODBCDD( EG_OPEN, ESQLDD_STMTALLOC, NULL, hb_itemGetCPtr( pItem ), 0 ); + szError = odbcGetError( ( SQLHENV ) pConnection->hCargo, ( SQLHDBC ) pConnection->hConnection, SQL_NULL_HSTMT, &errCode ); + hb_errRT_ODBCDD( EG_OPEN, ESQLDD_STMTALLOC, szError, hb_itemGetCPtr( pItem ), errCode ); + hb_xfree( szError ); return HB_FAILURE; } - pConnection->ulAffectedRows = 0; - lpStr = ( SQLTCHAR * ) HB_TCHAR_CONVTO( hb_itemGetCPtr( pItem ) ); if ( SQL_SUCCEEDED( SQLExecDirect( hStmt, lpStr, hb_itemGetCLen( pItem ) ) ) ) @@ -227,8 +273,8 @@ static HB_ERRCODE odbcExecute( SQLDDCONNECTION* pConnection, PHB_ITEM pItem ) if ( SQL_SUCCEEDED( SQLRowCount( hStmt, &iCount ) ) ) { - if( iCount > 0 ) - pConnection->ulAffectedRows = ( ULONG ) iCount; + /* TODO: new id */ + hb_rddsqlSetError( 0, NULL, hb_itemGetCPtr( pItem ), NULL, ( unsigned long ) iCount ); SQLFreeStmt( hStmt, SQL_DROP ); return HB_SUCCESS; } @@ -236,8 +282,9 @@ static HB_ERRCODE odbcExecute( SQLDDCONNECTION* pConnection, PHB_ITEM pItem ) else HB_TCHAR_FREE( lpStr ); - /* TODO: error processing */ - + szError = odbcGetError( ( SQLHENV ) pConnection->hCargo, ( SQLHDBC ) pConnection->hConnection, hStmt, &errCode ); + hb_rddsqlSetError( errCode, szError, hb_itemGetCPtr( pItem ), NULL, errCode ); + hb_xfree( szError ); SQLFreeStmt( hStmt, SQL_DROP ); return HB_FAILURE; } @@ -253,11 +300,15 @@ static HB_ERRCODE odbcOpen( SQLBASEAREAP pArea ) PHB_ITEM pItemEof, pItem; DBFIELDINFO pFieldInfo; BOOL bError; - USHORT uiFields, uiIndex, uiError = 0; + USHORT uiFields, uiIndex; + HB_ERRCODE errCode; + char * szError; if ( ! SQL_SUCCEEDED( SQLAllocHandle( SQL_HANDLE_STMT, ( SQLHDBC ) pArea->pConnection->hConnection, &hStmt ) ) ) { - hb_errRT_ODBCDD( EG_OPEN, ESQLDD_STMTALLOC, NULL, pArea->szQuery, 0 ); + szError = odbcGetError( ( SQLHENV ) pArea->pConnection->hCargo, ( SQLHDBC ) pArea->pConnection->hConnection, SQL_NULL_HSTMT, &errCode ); + hb_errRT_ODBCDD( EG_OPEN, ESQLDD_STMTALLOC, szError, pArea->szQuery, errCode ); + hb_xfree( szError ); return HB_FAILURE; } @@ -266,8 +317,10 @@ static HB_ERRCODE odbcOpen( SQLBASEAREAP pArea ) if ( ! SQL_SUCCEEDED( SQLExecDirect( hStmt, lpStr, strlen( pArea->szQuery ) ) ) ) { HB_TCHAR_FREE( lpStr ); + szError = odbcGetError( ( SQLHENV ) pArea->pConnection->hCargo, ( SQLHDBC ) pArea->pConnection->hConnection, hStmt, &errCode ); SQLFreeStmt( hStmt, SQL_DROP ); - hb_errRT_ODBCDD( EG_OPEN, ESQLDD_INVALIDQUERY, NULL, pArea->szQuery, 0 ); + hb_errRT_ODBCDD( EG_OPEN, ESQLDD_INVALIDQUERY, szError, pArea->szQuery, errCode ); + hb_xfree( szError ); return HB_FAILURE; } else @@ -275,26 +328,31 @@ static HB_ERRCODE odbcOpen( SQLBASEAREAP pArea ) if ( ! SQL_SUCCEEDED( SQLNumResultCols( hStmt, &iNameLen ) ) ) { + szError = odbcGetError( ( SQLHENV ) pArea->pConnection->hCargo, ( SQLHDBC ) pArea->pConnection->hConnection, hStmt, &errCode ); SQLFreeStmt( hStmt, SQL_DROP ); - hb_errRT_ODBCDD( EG_OPEN, ESQLDD_STMTDESCR + 1000, NULL, pArea->szQuery, 0 ); + hb_errRT_ODBCDD( EG_OPEN, ESQLDD_STMTDESCR + 1000, szError, pArea->szQuery, errCode ); + hb_xfree( szError ); return HB_FAILURE; } uiFields = ( USHORT ) iNameLen; - SELF_SETFIELDEXTENT( (AREAP) pArea, uiFields ); + SELF_SETFIELDEXTENT( ( AREAP ) pArea, uiFields ); pItemEof = hb_itemArrayNew( uiFields ); /* HB_TRACE( HB_TR_ALWAYS, ("fieldcount=%d", iNameLen) ); */ + errCode = 0; bError = FALSE; for ( uiIndex = 0; uiIndex < uiFields; uiIndex++ ) { if ( ! SQL_SUCCEEDED( SQLDescribeCol( hStmt, ( SQLSMALLINT ) uiIndex + 1, ( SQLTCHAR* ) cName, HB_SIZEOFARRAY( cName ), &iNameLen, &iDataType, &uiSize, &iDec, &iNull ) ) ) { hb_itemRelease( pItemEof ); + szError = odbcGetError( ( SQLHENV ) pArea->pConnection->hCargo, ( SQLHDBC ) pArea->pConnection->hConnection, hStmt, NULL ); SQLFreeStmt( hStmt, SQL_DROP ); - hb_errRT_ODBCDD( EG_OPEN, ESQLDD_STMTDESCR + 1001, NULL, pArea->szQuery, 0 ); + hb_errRT_ODBCDD( EG_OPEN, ESQLDD_STMTDESCR + 1001, szError, pArea->szQuery, 0 ); + hb_xfree( szError ); return HB_FAILURE; } @@ -357,7 +415,7 @@ static HB_ERRCODE odbcOpen( SQLBASEAREAP pArea ) default: /* HB_TRACE( HB_TR_ALWAYS, ("new sql type=%d", iDataType) ); */ bError = TRUE; - uiError = ( USHORT ) iDataType; + errCode = ( HB_ERRCODE ) iDataType; pFieldInfo.uiType = 0; pFieldInfo.uiType = HB_FT_STRING; break; @@ -371,7 +429,7 @@ static HB_ERRCODE odbcOpen( SQLBASEAREAP pArea ) { char* pStr; - pStr = (char*) hb_xgrab( ( ULONG ) pFieldInfo.uiLen + 1 ); + pStr = ( char * ) hb_xgrab( ( ULONG ) pFieldInfo.uiLen + 1 ); memset( pStr, ' ', pFieldInfo.uiLen ); pStr[ pFieldInfo.uiLen ] = '\0'; @@ -425,7 +483,7 @@ static HB_ERRCODE odbcOpen( SQLBASEAREAP pArea ) hb_itemRelease( pItem ); if ( ! bError ) - bError = ( SELF_ADDFIELD( (AREAP) pArea, &pFieldInfo ) == HB_FAILURE ); + bError = ( SELF_ADDFIELD( ( AREAP ) pArea, &pFieldInfo ) == HB_FAILURE ); } if ( bError ) @@ -436,22 +494,22 @@ static HB_ERRCODE odbcOpen( SQLBASEAREAP pArea ) { hb_itemRelease( pItemEof ); SQLFreeStmt( hStmt, SQL_DROP ); - hb_errRT_ODBCDD( EG_CORRUPTION, ESQLDD_INVALIDFIELD, "Invalid field type", pArea->szQuery, uiError ); + hb_errRT_ODBCDD( EG_CORRUPTION, ESQLDD_INVALIDFIELD, "Invalid field type", pArea->szQuery, errCode ); return HB_FAILURE; } pArea->ulRecCount = 0; pArea->ulRecMax = SQLDD_ROWSET_INIT; - pArea->pRow = ( void** ) hb_xgrab( SQLDD_ROWSET_INIT * sizeof( void* ) ); - memset( pArea->pRow, 0, SQLDD_ROWSET_INIT * sizeof( void* ) ); - pArea->pRowFlags = (BYTE*) hb_xgrab( SQLDD_ROWSET_INIT * sizeof( BYTE ) ); + pArea->pRow = ( void ** ) hb_xgrab( SQLDD_ROWSET_INIT * sizeof( void * ) ); + memset( pArea->pRow, 0, SQLDD_ROWSET_INIT * sizeof( void * ) ); + pArea->pRowFlags = ( BYTE * ) hb_xgrab( SQLDD_ROWSET_INIT * sizeof( BYTE ) ); memset( pArea->pRowFlags, 0, SQLDD_ROWSET_INIT * sizeof( BYTE ) ); pArea->pRow[ 0 ] = pItemEof; pArea->pRowFlags[ 0 ] = SQLDD_FLAG_CACHED; - pArea->pStmt = ( void* ) hStmt; + pArea->pStmt = ( void * ) hStmt; return HB_SUCCESS; } @@ -608,8 +666,8 @@ static HB_ERRCODE odbcGoTo( SQLBASEAREAP pArea, ULONG ulRecNo ) } if ( pArea->ulRecCount + 1 <= pArea->ulRecMax ) { - pArea->pRow = (void**) hb_xrealloc( pArea->pRow, ( pArea->ulRecMax + SQLDD_ROWSET_RESIZE ) * sizeof( void* ) ); - pArea->pRowFlags = (BYTE*) hb_xrealloc( pArea->pRowFlags, ( pArea->ulRecMax + SQLDD_ROWSET_RESIZE ) * sizeof( BYTE ) ); + pArea->pRow = ( void ** ) hb_xrealloc( pArea->pRow, ( pArea->ulRecMax + SQLDD_ROWSET_RESIZE ) * sizeof( void * ) ); + pArea->pRowFlags = ( BYTE * ) hb_xrealloc( pArea->pRowFlags, ( pArea->ulRecMax + SQLDD_ROWSET_RESIZE ) * sizeof( BYTE ) ); pArea->ulRecMax += SQLDD_ROWSET_RESIZE; } diff --git a/harbour/contrib/rddsql/sddodbc/tests/test1.prg b/harbour/contrib/rddsql/sddodbc/tests/test1.prg index addaaaadec..73e0d6a0e0 100644 --- a/harbour/contrib/rddsql/sddodbc/tests/test1.prg +++ b/harbour/contrib/rddsql/sddodbc/tests/test1.prg @@ -2,10 +2,10 @@ * $Id$ */ +#include "../../hbrddsql.ch" + REQUEST SDDODBC, SQLMIX -#define RDDI_CONNECT 1001 - PROC main() RDDSETDEFAULT( "SQLMIX" ) SET( _SET_DATEFORMAT, "yyyy-mm-dd" ) diff --git a/harbour/contrib/rddsql/sddodbc/tests/test2.prg b/harbour/contrib/rddsql/sddodbc/tests/test2.prg index 7cde750177..53169bf30b 100644 --- a/harbour/contrib/rddsql/sddodbc/tests/test2.prg +++ b/harbour/contrib/rddsql/sddodbc/tests/test2.prg @@ -2,8 +2,7 @@ * $Id$ */ -#define RDDI_CONNECT 1001 -#define RDDI_EXECUTE 1003 +#include "../../hbrddsql.ch" REQUEST SQLMIX, SDDODBC @@ -14,7 +13,7 @@ LOCAL nConnection, nI, aI SET( _SET_DATEFORMAT, "yyyy-mm-dd" ) nConnection := RDDINFO( RDDI_CONNECT, { "ODBC", "Server=localhost;Driver={MySQL ODBC 5.1 Driver};dsn=;User=test;database=test;" } ) IF nConnection == 0 - ? "Unable connect to server" + ? "Unable connect to server", RDDINFO( RDDI_ERRORNO ), RDDINFO( RDDI_ERROR ) RETURN ENDIF ? nConnection diff --git a/harbour/contrib/rddsql/sddpg/pgsqldd.c b/harbour/contrib/rddsql/sddpg/pgsqldd.c index 037600655c..77f9441ceb 100644 --- a/harbour/contrib/rddsql/sddpg/pgsqldd.c +++ b/harbour/contrib/rddsql/sddpg/pgsqldd.c @@ -94,9 +94,9 @@ #define NUMERICOID 1700 -static HB_ERRCODE pgsqlConnect( SQLDDCONNECTION* pConnection, PHB_ITEM pItem ); -static HB_ERRCODE pgsqlDisconnect( SQLDDCONNECTION* pConnection ); -static HB_ERRCODE pgsqlExecute( SQLDDCONNECTION* pConnection, PHB_ITEM pItem ); +static HB_ERRCODE pgsqlConnect( SQLDDCONNECTION * pConnection, PHB_ITEM pItem ); +static HB_ERRCODE pgsqlDisconnect( SQLDDCONNECTION * pConnection ); +static HB_ERRCODE pgsqlExecute( SQLDDCONNECTION * pConnection, PHB_ITEM pItem ); static HB_ERRCODE pgsqlOpen( SQLBASEAREAP pArea ); static HB_ERRCODE pgsqlClose( SQLBASEAREAP pArea ); static HB_ERRCODE pgsqlGetValue( SQLBASEAREAP pArea, USHORT uiIndex, PHB_ITEM pItem ); @@ -105,14 +105,14 @@ static HB_ERRCODE pgsqlGetValue( SQLBASEAREAP pArea, USHORT uiIndex, PHB_ITEM pI static SDDNODE pgsqldd = { NULL, "POSTGRESQL", - (SDDFUNC_CONNECT) pgsqlConnect, - (SDDFUNC_DISCONNECT) pgsqlDisconnect, - (SDDFUNC_EXECUTE) pgsqlExecute, - (SDDFUNC_OPEN) pgsqlOpen, - (SDDFUNC_CLOSE) pgsqlClose, - (SDDFUNC_GOTO) NULL, - (SDDFUNC_GETVALUE) pgsqlGetValue, - (SDDFUNC_GETVARLEN) NULL + ( SDDFUNC_CONNECT ) pgsqlConnect, + ( SDDFUNC_DISCONNECT ) pgsqlDisconnect, + ( SDDFUNC_EXECUTE ) pgsqlExecute, + ( SDDFUNC_OPEN ) pgsqlOpen, + ( SDDFUNC_CLOSE ) pgsqlClose, + ( SDDFUNC_GOTO ) NULL, + ( SDDFUNC_GETVALUE ) pgsqlGetValue, + ( SDDFUNC_GETVARLEN ) NULL }; @@ -154,24 +154,21 @@ HB_CALL_ON_STARTUP_END( _hb_sddpostgre_init_ ) /* ===================================================================================== */ -static USHORT hb_errRT_PostgreSQLDD( ULONG ulGenCode, ULONG ulSubCode, const char * szDescription, const char * szOperation, USHORT uiOsCode ) +static USHORT hb_errRT_PostgreSQLDD( HB_ERRCODE errGenCode, HB_ERRCODE errSubCode, const char * szDescription, const char * szOperation, HB_ERRCODE errOsCode ) { USHORT uiAction; PHB_ITEM pError; - pError = hb_errRT_New( ES_ERROR, "SDDPG", ulGenCode, ulSubCode, szDescription, szOperation, uiOsCode, EF_NONE ); - + pError = hb_errRT_New( ES_ERROR, "SDDPG", errGenCode, errSubCode, szDescription, szOperation, errOsCode, EF_NONE ); uiAction = hb_errLaunch( pError ); - hb_itemRelease( pError ); - return uiAction; } /* ============= SDD METHODS ============================================================= */ -static HB_ERRCODE pgsqlConnect( SQLDDCONNECTION* pConnection, PHB_ITEM pItem ) +static HB_ERRCODE pgsqlConnect( SQLDDCONNECTION * pConnection, PHB_ITEM pItem ) { PGconn* pConn; ConnStatusType status; @@ -180,15 +177,17 @@ static HB_ERRCODE pgsqlConnect( SQLDDCONNECTION* pConnection, PHB_ITEM pItem ) if ( ! pConn ) /* Low memory, etc */ { + /* TODO: error */ return HB_FAILURE; } status = PQstatus( pConn ); if ( status != CONNECTION_OK ) { + /* TODO: error */ PQfinish( pConn ); return HB_FAILURE; } - pConnection->hConnection = (void*) pConn; + pConnection->hConnection = ( void * ) pConn; return HB_SUCCESS; } @@ -197,39 +196,39 @@ static HB_ERRCODE pgsqlDisconnect( SQLDDCONNECTION* pConnection ) { if ( ! pConnection->hConnection ) return HB_FAILURE; - PQfinish( (PGconn *) pConnection->hConnection ); + PQfinish( ( PGconn * ) pConnection->hConnection ); return HB_SUCCESS; } static HB_ERRCODE pgsqlExecute( SQLDDCONNECTION* pConnection, PHB_ITEM pItem ) { - const char* szQuery; - int iTuples; - PGresult* pResult; + int iTuples; + PGresult* pResult; + ExecStatusType status; + unsigned long ulAffectedRows; - szQuery = hb_itemGetCPtr( pItem ); - if ( ! pConnection->hConnection || ! szQuery ) + pResult = PQexec( ( PGconn * ) pConnection->hConnection, hb_itemGetCPtr( pItem ) ); + if ( ! pResult ) { - hb_itemClear( pItem ); + hb_rddsqlSetError( 1, PQerrorMessage( ( PGconn * ) pConnection->hConnection ), hb_itemGetCPtr( pItem ), NULL, 0 ); return HB_FAILURE; } - pResult = PQexec( (PGconn *) pConnection->hConnection, szQuery ); - if ( ! pResult ) + status = PQresultStatus( pResult ); + if ( status != PGRES_TUPLES_OK && status != PGRES_COMMAND_OK ) { - hb_itemClear( pItem ); + hb_rddsqlSetError( status, PQresultErrorMessage( pResult ), hb_itemGetCPtr( pItem ), NULL, 0 ); return HB_FAILURE; } iTuples = PQntuples( pResult ); if ( iTuples > 0 ) - hb_itemPutNI( pItem, iTuples ); + ulAffectedRows = ( unsigned long ) iTuples; else - { - hb_itemPutNI( pItem, atol( PQcmdTuples( pResult ) ) ); -/* printf( "pgsqlExecute PQoidValue=%d [%s]\n", (int) PQoidValue( pResult ), PQoidStatus( pResult ) ); */ - } + ulAffectedRows = ( unsigned long ) atol( PQcmdTuples( pResult ) ); + + hb_rddsqlSetError( 0, NULL, hb_itemGetCPtr( pItem ), NULL, ulAffectedRows ); PQclear( pResult ); return HB_SUCCESS; } @@ -246,7 +245,7 @@ static HB_ERRCODE pgsqlOpen( SQLBASEAREAP pArea ) DBFIELDINFO pFieldInfo; - pResult = PQexec( (PGconn *) pArea->pConnection->hConnection, pArea->szQuery ); + pResult = PQexec( ( PGconn * ) pArea->pConnection->hConnection, pArea->szQuery ); if ( ! pResult ) { hb_errRT_PostgreSQLDD( EG_OPEN, ESQLDD_LOWMEMORY, "Query failed", NULL, 0 ); /* Low memory, etc */ @@ -256,14 +255,14 @@ static HB_ERRCODE pgsqlOpen( SQLBASEAREAP pArea ) status = PQresultStatus( pResult ); if ( status != PGRES_TUPLES_OK && status != PGRES_COMMAND_OK ) { - hb_errRT_PostgreSQLDD( EG_OPEN, ESQLDD_INVALIDQUERY, PQresultErrorMessage( pResult ), pArea->szQuery, ( USHORT ) status ); + hb_errRT_PostgreSQLDD( EG_OPEN, ESQLDD_INVALIDQUERY, PQresultErrorMessage( pResult ), pArea->szQuery, ( HB_ERRCODE ) status ); return HB_FAILURE; } pArea->pResult = pResult; uiFields = ( USHORT ) PQnfields( pResult ); - SELF_SETFIELDEXTENT( (AREAP) pArea, uiFields ); + SELF_SETFIELDEXTENT( ( AREAP ) pArea, uiFields ); pItemEof = hb_itemArrayNew( uiFields ); @@ -272,14 +271,14 @@ static HB_ERRCODE pgsqlOpen( SQLBASEAREAP pArea ) bError = FALSE; for ( uiCount = 0; uiCount < uiFields; uiCount++ ) { - hb_strncpy( pBuffer, PQfname( pResult, (int) uiCount ), 256 - 1 ); + hb_strncpy( pBuffer, PQfname( pResult, ( int ) uiCount ), 256 - 1 ); hb_strUpper( pBuffer, MAX_FIELD_NAME + 1 ); pBuffer[ MAX_FIELD_NAME ] = '\0'; pFieldInfo.atomName = pBuffer; pFieldInfo.uiDec = 0; - switch( PQftype( pResult, (int) uiCount ) ) + switch( PQftype( pResult, ( int ) uiCount ) ) { case BPCHAROID: case VARCHAROID: @@ -378,7 +377,7 @@ static HB_ERRCODE pgsqlOpen( SQLBASEAREAP pArea ) bError = TRUE; break; } - /* printf( "field:%s \ttype:%d \tsize:%d \tformat:%d \tmod:%d err=%d\n", pBuffer, PQftype( pResult, (int) uiCount ), PQfsize( pResult, uiCount ), PQfformat( pResult, uiCount ) , PQfmod( pResult, uiCount ), bError ); */ + /* printf( "field:%s \ttype:%d \tsize:%d \tformat:%d \tmod:%d err=%d\n", pBuffer, PQftype( pResult, ( int ) uiCount ), PQfsize( pResult, uiCount ), PQfformat( pResult, uiCount ) , PQfmod( pResult, uiCount ), bError ); */ if ( ! bError ) { @@ -388,7 +387,7 @@ static HB_ERRCODE pgsqlOpen( SQLBASEAREAP pArea ) { char* pStr; - pStr = (char*) hb_xgrab( pFieldInfo.uiLen + 1 ); + pStr = ( char * ) hb_xgrab( pFieldInfo.uiLen + 1 ); memset( pStr, ' ', pFieldInfo.uiLen ); pStr[ pFieldInfo.uiLen ] = '\0'; @@ -432,7 +431,7 @@ static HB_ERRCODE pgsqlOpen( SQLBASEAREAP pArea ) } */ if ( ! bError ) - bError = ( SELF_ADDFIELD( (AREAP) pArea, &pFieldInfo ) == HB_FAILURE ); + bError = ( SELF_ADDFIELD( ( AREAP ) pArea, &pFieldInfo ) == HB_FAILURE ); } if ( bError ) @@ -449,10 +448,10 @@ static HB_ERRCODE pgsqlOpen( SQLBASEAREAP pArea ) return HB_FAILURE; } - pArea->ulRecCount = (ULONG) PQntuples( pResult ); + pArea->ulRecCount = ( ULONG ) PQntuples( pResult ); - pArea->pRow = (void**) hb_xgrab( ( pArea->ulRecCount + 1 ) * sizeof( void* ) ); - pArea->pRowFlags = (BYTE*) hb_xgrab( ( pArea->ulRecCount + 1 ) * sizeof( BYTE ) ); + pArea->pRow = ( void ** ) hb_xgrab( ( pArea->ulRecCount + 1 ) * sizeof( void * ) ); + pArea->pRowFlags = ( BYTE * ) hb_xgrab( ( pArea->ulRecCount + 1 ) * sizeof( BYTE ) ); memset( pArea->pRowFlags, 0, ( pArea->ulRecCount + 1 ) * sizeof( BYTE ) ); * pArea->pRow = pItemEof; @@ -467,7 +466,7 @@ static HB_ERRCODE pgsqlClose( SQLBASEAREAP pArea ) { if ( pArea->pResult ) { - PQclear( (PGresult *) pArea->pResult ); + PQclear( ( PGresult * ) pArea->pResult ); pArea->pResult = NULL; } return HB_SUCCESS; @@ -486,11 +485,11 @@ static HB_ERRCODE pgsqlGetValue( SQLBASEAREAP pArea, USHORT uiIndex, PHB_ITEM pI uiIndex--; pField = pArea->area.lpFields + uiIndex; - if ( PQgetisnull( (PGresult *) pArea->pResult, pArea->ulRecNo - 1, uiIndex ) ) + if ( PQgetisnull( ( PGresult * ) pArea->pResult, pArea->ulRecNo - 1, uiIndex ) ) return HB_SUCCESS; - pValue = PQgetvalue( (PGresult *) pArea->pResult, pArea->ulRecNo - 1, uiIndex ); - ulLen = (ULONG) PQgetlength( (PGresult *) pArea->pResult, pArea->ulRecNo - 1, uiIndex ); + pValue = PQgetvalue( ( PGresult * ) pArea->pResult, pArea->ulRecNo - 1, uiIndex ); + ulLen = ( ULONG ) PQgetlength( ( PGresult * ) pArea->pResult, pArea->ulRecNo - 1, uiIndex ); /* printf( "fieldget recno:%d index:%d value:%s len:%d\n", pArea->ulRecNo, uiIndex, pValue, ulLen ); */ @@ -505,14 +504,14 @@ static HB_ERRCODE pgsqlGetValue( SQLBASEAREAP pArea, USHORT uiIndex, PHB_ITEM pI case HB_FT_DOUBLE: if ( pField->uiDec ) hb_itemPutNDLen( pItem, atof( pValue ), - (int) pField->uiLen - ( (int) pField->uiDec + 1 ), - (int) pField->uiDec ); + ( int ) pField->uiLen - ( ( int ) pField->uiDec + 1 ), + ( int ) pField->uiDec ); else if ( pField->uiLen > 9 ) hb_itemPutNDLen( pItem, atof( pValue ), - (int) pField->uiLen, (int) pField->uiDec ); + ( int ) pField->uiLen, ( int ) pField->uiDec ); else - hb_itemPutNLLen( pItem, atol( pValue ), (int) pField->uiLen ); + hb_itemPutNLLen( pItem, atol( pValue ), ( int ) pField->uiLen ); break; case HB_FT_LOGICAL: diff --git a/harbour/contrib/rddsql/sqlbase.c b/harbour/contrib/rddsql/sqlbase.c index 8a8031c109..51f89fc144 100644 --- a/harbour/contrib/rddsql/sqlbase.c +++ b/harbour/contrib/rddsql/sqlbase.c @@ -58,29 +58,60 @@ #include "hbtrace.h" - #define SUPERTABLE ( &sqlbaseSuper ) #define CONNECTION_LIST_EXPAND 4 - static USHORT s_rddidSQLBASE = 0; -static SQLDDCONNECTION* s_pConnection = NULL; +static SQLDDCONNECTION * s_pConnection = NULL; static ULONG s_ulConnectionCount = 0; static ULONG s_ulConnectionCurrent = 0; +static char * s_szError = NULL; +static HB_ERRCODE s_errCode = 0; +static char * s_szQuery = NULL; +static PHB_ITEM s_pItemNewID = NULL; +static unsigned long s_ulAffectedRows = 0; static RDDFUNCS sqlbaseSuper; -#define static -static HB_ERRCODE hb_errRT_SQLBASE( ULONG ulGenCode, ULONG ulSubCode, const char * szDescription, const char * szOperation ) +void hb_rddsqlSetError( HB_ERRCODE errCode, const char * szError, const char * szQuery, PHB_ITEM pItem, unsigned long ulAffectedRows ) +{ + s_errCode = errCode; + + if( s_szError ) + { + hb_xfree( s_szError ); + s_szError = NULL; + } + if( szError ) + s_szError = hb_strdup( szError ); + + if( s_szQuery ) + { + hb_xfree( s_szQuery ); + s_szQuery = NULL; + } + if( szQuery ) + s_szQuery = hb_strdup( szQuery ); + + if( pItem ) + hb_itemCopy( s_pItemNewID, pItem ); + else + hb_itemClear( s_pItemNewID ); + + s_ulAffectedRows = ulAffectedRows; +} + + +static HB_ERRCODE hb_errRT_SQLBASE( HB_ERRCODE errGenCode, HB_ERRCODE errSubCode, const char * szDescription, const char * szOperation ) { PHB_ITEM pError; HB_ERRCODE iRet = HB_FAILURE; if ( hb_vmRequestQuery() == 0 ) { - pError = hb_errRT_New( ES_ERROR, "SQLBASE", ulGenCode, ulSubCode, szDescription, szOperation, 0, EF_NONE ); + pError = hb_errRT_New( ES_ERROR, "SQLBASE", errGenCode, errSubCode, szDescription, szOperation, 0, EF_NONE ); iRet = hb_errLaunch( pError ); hb_itemRelease( pError ); } @@ -90,9 +121,9 @@ static HB_ERRCODE hb_errRT_SQLBASE( ULONG ulGenCode, ULONG ulSubCode, const char /*================ NULL SDD ==========================================================*/ -static HB_ERRCODE sddConnect( SQLDDCONNECTION* pConnection, PHB_ITEM pItem ); -static HB_ERRCODE sddDisconnect( SQLDDCONNECTION* pConnection ); -static HB_ERRCODE sddExecute( SQLDDCONNECTION* pConnection, PHB_ITEM pItem ); +static HB_ERRCODE sddConnect( SQLDDCONNECTION * pConnection, PHB_ITEM pItem ); +static HB_ERRCODE sddDisconnect( SQLDDCONNECTION * pConnection ); +static HB_ERRCODE sddExecute( SQLDDCONNECTION * pConnection, PHB_ITEM pItem ); static HB_ERRCODE sddOpen( SQLBASEAREAP pArea ); static HB_ERRCODE sddClose( SQLBASEAREAP pArea ); static HB_ERRCODE sddGoTo( SQLBASEAREAP pArea, ULONG ulRecNo ); @@ -103,18 +134,18 @@ static HB_ERRCODE sddGetVarLen( SQLBASEAREAP pArea, USHORT uiIndex, ULONG * pLen static SDDNODE sddNull = { NULL, "NULL", - (SDDFUNC_CONNECT) sddConnect, - (SDDFUNC_DISCONNECT) sddDisconnect, - (SDDFUNC_EXECUTE) sddExecute, - (SDDFUNC_OPEN) sddOpen, - (SDDFUNC_CLOSE) sddClose, - (SDDFUNC_GOTO) sddGoTo, - (SDDFUNC_GETVALUE) sddGetValue, - (SDDFUNC_GETVARLEN) sddGetVarLen + ( SDDFUNC_CONNECT ) sddConnect, + ( SDDFUNC_DISCONNECT ) sddDisconnect, + ( SDDFUNC_EXECUTE ) sddExecute, + ( SDDFUNC_OPEN ) sddOpen, + ( SDDFUNC_CLOSE ) sddClose, + ( SDDFUNC_GOTO ) sddGoTo, + ( SDDFUNC_GETVALUE ) sddGetValue, + ( SDDFUNC_GETVARLEN ) sddGetVarLen }; -static HB_ERRCODE sddConnect( SQLDDCONNECTION* pConnection, PHB_ITEM pItem ) +static HB_ERRCODE sddConnect( SQLDDCONNECTION * pConnection, PHB_ITEM pItem ) { HB_SYMBOL_UNUSED( pConnection ); HB_SYMBOL_UNUSED( pItem ); @@ -123,7 +154,7 @@ static HB_ERRCODE sddConnect( SQLDDCONNECTION* pConnection, PHB_ITEM pItem ) } -static HB_ERRCODE sddDisconnect( SQLDDCONNECTION* pConnection ) +static HB_ERRCODE sddDisconnect( SQLDDCONNECTION * pConnection ) { HB_SYMBOL_UNUSED( pConnection ); hb_errRT_SQLBASE( EG_UNSUPPORTED, ESQLDD_NULLSDD, NULL, NULL ); @@ -131,7 +162,7 @@ static HB_ERRCODE sddDisconnect( SQLDDCONNECTION* pConnection ) } -static HB_ERRCODE sddExecute( SQLDDCONNECTION* pConnection, PHB_ITEM pItem ) +static HB_ERRCODE sddExecute( SQLDDCONNECTION * pConnection, PHB_ITEM pItem ) { HB_SYMBOL_UNUSED( pConnection ); HB_SYMBOL_UNUSED( pItem ); @@ -238,26 +269,26 @@ int hb_sddRegister( PSDDNODE pSdd ) static HB_ERRCODE sqlbaseGoBottom( SQLBASEAREAP pArea ) { - if ( SELF_GOCOLD( (AREAP) pArea ) == HB_FAILURE ) + if ( SELF_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) return HB_FAILURE; - if ( ! pArea->fFetched && pArea->pSDD->GoTo( pArea, (ULONG) -1 ) == HB_FAILURE ) + if ( ! pArea->fFetched && pArea->pSDD->GoTo( pArea, ( ULONG ) -1 ) == HB_FAILURE ) return HB_FAILURE; pArea->area.fTop = FALSE; pArea->area.fBottom = TRUE; - if ( SELF_GOTO( (AREAP) pArea, pArea->ulRecCount ) != HB_SUCCESS ) + if ( SELF_GOTO( ( AREAP ) pArea, pArea->ulRecCount ) != HB_SUCCESS ) return HB_FAILURE; - return SELF_SKIPFILTER( (AREAP) pArea, -1 ); + return SELF_SKIPFILTER( ( AREAP ) pArea, -1 ); } static HB_ERRCODE sqlbaseGoTo( SQLBASEAREAP pArea, ULONG ulRecNo ) { - if ( SELF_GOCOLD( (AREAP) pArea ) == HB_FAILURE ) + if ( SELF_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) return HB_FAILURE; if ( pArea->pSDD->GoTo( pArea, ulRecNo ) == HB_FAILURE ) @@ -284,14 +315,14 @@ static HB_ERRCODE sqlbaseGoToId( SQLBASEAREAP pArea, PHB_ITEM pItem ) PHB_ITEM pError; if ( HB_IS_NUMERIC( pItem ) ) - return SELF_GOTO( (AREAP) pArea, hb_itemGetNL( pItem ) ); + return SELF_GOTO( ( AREAP ) pArea, hb_itemGetNL( pItem ) ); else { pError = hb_errNew(); hb_errPutGenCode( pError, EG_DATATYPE ); hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_DATATYPE ) ); hb_errPutSubCode( pError, EDBF_DATATYPE ); - SELF_ERROR( (AREAP) pArea, pError ); + SELF_ERROR( ( AREAP ) pArea, pError ); hb_itemRelease( pError ); return HB_FAILURE; } @@ -303,16 +334,16 @@ static HB_ERRCODE sqlbaseGoTop( SQLBASEAREAP pArea ) pArea->area.fTop = TRUE; pArea->area.fBottom = FALSE; - if ( SELF_GOTO( (AREAP) pArea, 1 ) == HB_FAILURE ) + if ( SELF_GOTO( ( AREAP ) pArea, 1 ) == HB_FAILURE ) return HB_FAILURE; - return SELF_SKIPFILTER( (AREAP) pArea, 1 ); + return SELF_SKIPFILTER( ( AREAP ) pArea, 1 ); } static HB_ERRCODE sqlbaseSkip( SQLBASEAREAP pArea, LONG lToSkip ) { - HB_ERRCODE uiError; + HB_ERRCODE errCode; if ( pArea->lpdbPendingRel ) { @@ -324,14 +355,14 @@ static HB_ERRCODE sqlbaseSkip( SQLBASEAREAP pArea, LONG lToSkip ) if ( lToSkip == 0 || hb_setGetDeleted() || pArea->area.dbfi.itmCobExpr || pArea->area.dbfi.fFilter ) - return SUPER_SKIP( (AREAP) pArea, lToSkip ); + return SUPER_SKIP( ( AREAP ) pArea, lToSkip ); - uiError = SELF_SKIPRAW( (AREAP) pArea, lToSkip ); + errCode = SELF_SKIPRAW( ( AREAP ) pArea, lToSkip ); /* Move first record and set Bof flag */ - if ( uiError == HB_SUCCESS && pArea->area.fBof && lToSkip < 0 ) + if ( errCode == HB_SUCCESS && pArea->area.fBof && lToSkip < 0 ) { - uiError = SELF_GOTOP( (AREAP) pArea ); + errCode = SELF_GOTOP( ( AREAP ) pArea ); pArea->area.fBof = TRUE; } @@ -340,13 +371,13 @@ static HB_ERRCODE sqlbaseSkip( SQLBASEAREAP pArea, LONG lToSkip ) else /* if ( lToSkip > 0 ) */ pArea->area.fBof = FALSE; - return uiError; + return errCode; } static HB_ERRCODE sqlbaseSkipRaw( SQLBASEAREAP pArea, LONG lToSkip ) { - HB_ERRCODE uiError; + HB_ERRCODE errCode; if ( pArea->lpdbPendingRel ) { @@ -363,23 +394,23 @@ static HB_ERRCODE sqlbaseSkipRaw( SQLBASEAREAP pArea, LONG lToSkip ) bBof = pArea->area.fBof; bEof = pArea->area.fEof; - uiError = SELF_GOTO( (AREAP) pArea, pArea->ulRecNo ); + errCode = SELF_GOTO( ( AREAP ) pArea, pArea->ulRecNo ); /* Restore flags */ pArea->area.fBof = bBof; pArea->area.fEof = bEof; } - else if ( lToSkip < 0 && (ULONG) ( -lToSkip ) >= pArea->ulRecNo ) + else if ( lToSkip < 0 && ( ULONG ) ( -lToSkip ) >= pArea->ulRecNo ) { - uiError = SELF_GOTO( (AREAP) pArea, 1 ); + errCode = SELF_GOTO( ( AREAP ) pArea, 1 ); pArea->area.fBof = TRUE; } else { - uiError = SELF_GOTO( (AREAP) pArea, pArea->ulRecNo + lToSkip ); + errCode = SELF_GOTO( ( AREAP ) pArea, pArea->ulRecNo + lToSkip ); } - return uiError; + return errCode; } @@ -396,7 +427,7 @@ static HB_ERRCODE sqlbaseAppend( SQLBASEAREAP pArea, BOOL bUnLockAll ) if ( pArea->ulRecCount + 1 >= pArea->ulRecMax ) { - pArea->pRow = (void**) hb_xrealloc( pArea->pRow, ( pArea->ulRecMax + SQLDD_ROWSET_RESIZE ) * sizeof( void* ) ); + pArea->pRow = ( void ** ) hb_xrealloc( pArea->pRow, ( pArea->ulRecMax + SQLDD_ROWSET_RESIZE ) * sizeof( void * ) ); pArea->pRowFlags = ( BYTE * ) hb_xrealloc( pArea->pRowFlags, ( pArea->ulRecMax + SQLDD_ROWSET_RESIZE ) * sizeof( BYTE ) ); pArea->ulRecMax += SQLDD_ROWSET_RESIZE; } @@ -481,7 +512,7 @@ static HB_ERRCODE sqlbaseGoHot( SQLBASEAREAP pArea ) for ( us = 1; us <= pArea->area.uiFieldCount; us++ ) { pItem = hb_itemNew( NULL ); - if ( SELF_GETVALUE( (AREAP) pArea, us, pItem ) == HB_SUCCESS ) + if ( SELF_GETVALUE( ( AREAP ) pArea, us, pItem ) == HB_SUCCESS ) hb_arraySetForward( pArray, us, pItem ); hb_itemRelease( pItem ); } @@ -495,7 +526,7 @@ static HB_ERRCODE sqlbaseGoHot( SQLBASEAREAP pArea ) static HB_ERRCODE sqlbasePutValue( SQLBASEAREAP pArea, USHORT uiIndex, PHB_ITEM pItem ) { LPFIELD pField; - HB_ERRCODE uiError; + HB_ERRCODE errCode; if ( ! pArea->fPositioned ) return HB_SUCCESS; @@ -503,7 +534,7 @@ static HB_ERRCODE sqlbasePutValue( SQLBASEAREAP pArea, USHORT uiIndex, PHB_ITEM if ( ! pArea->fRecordChanged && SELF_GOHOT( ( AREAP ) pArea ) == HB_FAILURE ) return HB_FAILURE; - uiError = HB_SUCCESS; + errCode = HB_SUCCESS; pField = pArea->area.lpFields + ( uiIndex - 1 ); if ( ( ( HB_IS_MEMO( pItem ) || HB_IS_STRING( pItem ) ) && pField->uiType == HB_FT_STRING ) || @@ -523,11 +554,11 @@ static HB_ERRCODE sqlbasePutValue( SQLBASEAREAP pArea, USHORT uiIndex, PHB_ITEM hb_errPutGenCode( pError, EG_DATATYPE ); hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_DATATYPE ) ); hb_errPutOperation( pError, hb_dynsymName( (PHB_DYNS) pField->sym ) ); - hb_errPutSubCode( pError, uiError ); + hb_errPutSubCode( pError, errCode ); hb_errPutFlags( pError, EF_CANDEFAULT ); - uiError = SELF_ERROR( (AREAP) pArea, pError ); + errCode = SELF_ERROR( ( AREAP ) pArea, pError ); hb_itemRelease( pError ); - return uiError == E_DEFAULT ? HB_SUCCESS : HB_FAILURE; + return errCode == E_DEFAULT ? HB_SUCCESS : HB_FAILURE; } return HB_SUCCESS; } @@ -565,7 +596,7 @@ static HB_ERRCODE sqlbaseRecId( SQLBASEAREAP pArea, PHB_ITEM pRecNo ) HB_ERRCODE errCode; ULONG ulRecNo; - errCode = SELF_RECNO( (AREAP) pArea, &ulRecNo ); + errCode = SELF_RECNO( ( AREAP ) pArea, &ulRecNo ); hb_itemPutNInt( pRecNo, ulRecNo ); return errCode; } @@ -573,10 +604,10 @@ static HB_ERRCODE sqlbaseRecId( SQLBASEAREAP pArea, PHB_ITEM pRecNo ) static HB_ERRCODE sqlbaseClose( SQLBASEAREAP pArea ) { - if ( SELF_GOCOLD( (AREAP) pArea ) == HB_FAILURE ) + if ( SELF_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) return HB_FAILURE; - if ( SUPER_CLOSE( (AREAP) pArea ) == HB_FAILURE ) + if ( SUPER_CLOSE( ( AREAP ) pArea ) == HB_FAILURE ) return HB_FAILURE; pArea->pSDD->Close( pArea ); @@ -601,6 +632,7 @@ static HB_ERRCODE sqlbaseClose( SQLBASEAREAP pArea ) hb_xfree( pArea->szQuery ); pArea->szQuery = NULL; } + pArea->pConnection->uiAreaCount--; return HB_SUCCESS; } @@ -623,6 +655,7 @@ static HB_ERRCODE sqlbaseCreate( SQLBASEAREAP pArea, LPDBOPENINFO pOpenInfo ) if ( pArea->ulConnection ) { pArea->pConnection = & s_pConnection[ pArea->ulConnection - 1 ]; + pArea->pConnection->uiAreaCount++; pArea->pSDD = pArea->pConnection->pSDD; } else @@ -704,13 +737,13 @@ static HB_ERRCODE sqlbaseCreate( SQLBASEAREAP pArea, LPDBOPENINFO pOpenInfo ) hb_itemClear( pItemEof ); hb_itemRelease( pItemEof ); hb_errRT_SQLBASE( EG_CORRUPTION, ESQLDD_INVALIDFIELD, "Invalid field type", NULL ); - SELF_CLOSE( (AREAP) pArea ); + SELF_CLOSE( ( AREAP ) pArea ); return HB_FAILURE; } pArea->ulRecCount = 0; - pArea->pRow = (void**) hb_xalloc( SQLDD_ROWSET_RESIZE * sizeof( void* ) ); + pArea->pRow = ( void ** ) hb_xalloc( SQLDD_ROWSET_RESIZE * sizeof( void * ) ); pArea->pRowFlags = ( BYTE * ) hb_xalloc( SQLDD_ROWSET_RESIZE * sizeof( BYTE ) ); pArea->ulRecMax = SQLDD_ROWSET_RESIZE; @@ -718,13 +751,13 @@ static HB_ERRCODE sqlbaseCreate( SQLBASEAREAP pArea, LPDBOPENINFO pOpenInfo ) pArea->pRowFlags[ 0 ] = SQLDD_FLAG_CACHED; pArea->fFetched = 1; - if ( SUPER_CREATE( (AREAP) pArea, pOpenInfo ) != HB_SUCCESS ) + if ( SUPER_CREATE( ( AREAP ) pArea, pOpenInfo ) != HB_SUCCESS ) { - SELF_CLOSE( (AREAP) pArea ); + SELF_CLOSE( ( AREAP ) pArea ); return HB_FAILURE; } - return SELF_GOTOP( (AREAP) pArea ); + return SELF_GOTOP( ( AREAP ) pArea ); } @@ -757,29 +790,30 @@ static HB_ERRCODE sqlbaseOpen( SQLBASEAREAP pArea, LPDBOPENINFO pOpenInfo ) return HB_FAILURE; } + if ( pArea->area.uiFieldCount ) + /* This should not happen (in __dbTrans()), because RDD is registered with RDT_FULL */ + return HB_FAILURE; + pArea->pConnection = & s_pConnection[ pArea->ulConnection - 1 ]; + pArea->pConnection->uiAreaCount++; pArea->pSDD = pArea->pConnection->pSDD; /* filename is a query */ pArea->szQuery = hb_strdup( pOpenInfo->abName ); - if ( pArea->area.uiFieldCount ) - /* This should not happen (in __dbTrans()), because RDD is registered with RDT_FULL */ - return HB_FAILURE; - errCode = pArea->pSDD->Open( pArea ); if ( errCode == HB_SUCCESS ) { - errCode = SUPER_OPEN( (AREAP) pArea, pOpenInfo ); + errCode = SUPER_OPEN( ( AREAP ) pArea, pOpenInfo ); } if( errCode != HB_SUCCESS ) { - SELF_CLOSE( (AREAP) pArea ); + SELF_CLOSE( ( AREAP ) pArea ); return HB_FAILURE; } - return SELF_GOTOP( (AREAP) pArea ); + return SELF_GOTOP( ( AREAP ) pArea ); } @@ -795,34 +829,34 @@ static HB_ERRCODE sqlbaseStructSize( SQLBASEAREAP pArea, USHORT * uiSize ) /* static HB_ERRCODE sqlbaseChildEnd( SQLBASEAREAP pArea, LPDBRELINFO pRelInfo ) { - HB_ERRCODE uiError; + HB_ERRCODE errCode; if ( pArea->lpdbPendingRel == pRelInfo ) - uiError = SELF_FORCEREL( (AREAP) pArea ); + errCode = SELF_FORCEREL( ( AREAP ) pArea ); else - uiError = HB_SUCCESS; - SUPER_CHILDEND( (AREAP) pArea, pRelInfo ); - return uiError; + errCode = HB_SUCCESS; + SUPER_CHILDEND( ( AREAP ) pArea, pRelInfo ); + return errCode; } static HB_ERRCODE sqlbaseChildStart( SQLBASEAREAP pArea, LPDBRELINFO pRelInfo ) { - if ( SELF_CHILDSYNC( (AREAP) pArea, pRelInfo ) != HB_SUCCESS ) + if ( SELF_CHILDSYNC( ( AREAP ) pArea, pRelInfo ) != HB_SUCCESS ) return HB_FAILURE; - return SUPER_CHILDSTART( (AREAP) pArea, pRelInfo ); + return SUPER_CHILDSTART( ( AREAP ) pArea, pRelInfo ); } static HB_ERRCODE sqlbaseChildSync( SQLBASEAREAP pArea, LPDBRELINFO pRelInfo ) { - if ( SELF_GOCOLD( (AREAP) pArea ) != HB_SUCCESS ) + if ( SELF_GOCOLD( ( AREAP ) pArea ) != HB_SUCCESS ) return HB_FAILURE; pArea->lpdbPendingRel = pRelInfo; if ( pArea->lpdbRelations ) - return SELF_SYNCCHILDREN( (AREAP) pArea ); + return SELF_SYNCCHILDREN( ( AREAP ) pArea ); return HB_SUCCESS; } @@ -836,7 +870,7 @@ static HB_ERRCODE sqlbaseForceRel( SQLBASEAREAP pArea ) lpdbPendingRel = pArea->lpdbPendingRel; pArea->lpdbPendingRel = NULL; - return SELF_RELEVAL( (AREAP) pArea, lpdbPendingRel ); + return SELF_RELEVAL( ( AREAP ) pArea, lpdbPendingRel ); } return HB_SUCCESS; } @@ -846,14 +880,23 @@ static HB_ERRCODE sqlbaseSetFilter( SQLBASEAREAP pArea, LPDBFILTERINFO pFilterIn { if ( pArea->lpdbPendingRel ) { - if ( SELF_FORCEREL( (AREAP) pArea ) != HB_SUCCESS ) + if ( SELF_FORCEREL( ( AREAP ) pArea ) != HB_SUCCESS ) return HB_FAILURE; } - return SUPER_SETFILTER( (AREAP) pArea, pFilterInfo ); + return SUPER_SETFILTER( ( AREAP ) pArea, pFilterInfo ); } */ +static HB_ERRCODE sqlbaseInit( LPRDDNODE pRDD ) +{ + HB_SYMBOL_UNUSED( pRDD ); + + s_pItemNewID = hb_itemNew( NULL ); + return HB_SUCCESS; +} + + static HB_ERRCODE sqlbaseExit( LPRDDNODE pRDD ) { ULONG ul; @@ -868,17 +911,24 @@ static HB_ERRCODE sqlbaseExit( LPRDDNODE pRDD ) if ( s_pConnection[ ul ].hConnection ) { s_pConnection[ ul ].pSDD->Disconnect( & s_pConnection[ ul ] ); - if ( s_pConnection[ ul ].szError ) - hb_xfree( s_pConnection[ ul ].szError ); - if ( s_pConnection[ ul ].szQuery ) - hb_xfree( s_pConnection[ ul ].szQuery ); - hb_itemRelease( s_pConnection[ ul ].pNewID ); } } hb_xfree( s_pConnection ); s_pConnection = NULL; s_ulConnectionCount = 0; s_ulConnectionCurrent = 0; + if ( s_szError ) + { + hb_xfree( s_szError ); + s_szError = NULL; + } + if ( s_szQuery ) + { + hb_xfree( s_szQuery ); + s_szQuery = NULL; + } + hb_itemRelease( s_pItemNewID ); + s_pItemNewID = NULL; } return HB_SUCCESS; @@ -947,9 +997,9 @@ static HB_ERRCODE sqlbaseRddInfo( LPRDDNODE pRDD, USHORT uiIndex, ULONG ulConnec { /* Realloc connection table */ if ( s_pConnection ) - s_pConnection = (SQLDDCONNECTION*) hb_xrealloc( s_pConnection, sizeof( SQLDDCONNECTION ) * ( s_ulConnectionCount + CONNECTION_LIST_EXPAND ) ); + s_pConnection = ( SQLDDCONNECTION * ) hb_xrealloc( s_pConnection, sizeof( SQLDDCONNECTION ) * ( s_ulConnectionCount + CONNECTION_LIST_EXPAND ) ); else - s_pConnection = (SQLDDCONNECTION*) hb_xgrab( sizeof( SQLDDCONNECTION ) * CONNECTION_LIST_EXPAND ); + s_pConnection = ( SQLDDCONNECTION * ) hb_xgrab( sizeof( SQLDDCONNECTION ) * CONNECTION_LIST_EXPAND ); memset( &s_pConnection[ s_ulConnectionCount ], 0, sizeof( SQLDDCONNECTION ) * CONNECTION_LIST_EXPAND ); ul = s_ulConnectionCount; @@ -970,10 +1020,10 @@ static HB_ERRCODE sqlbaseRddInfo( LPRDDNODE pRDD, USHORT uiIndex, ULONG ulConnec pConn = & s_pConnection[ ul ]; ul++; + hb_rddsqlSetError( 0, NULL, NULL, NULL, 0 ); if ( pNode && pNode->Connect( pConn, pItem ) == HB_SUCCESS ) { pConn->pSDD = pNode; - pConn->pNewID = hb_itemNew( NULL ); } else ul = 0; @@ -987,23 +1037,10 @@ static HB_ERRCODE sqlbaseRddInfo( LPRDDNODE pRDD, USHORT uiIndex, ULONG ulConnec case RDDI_DISCONNECT: { - - if ( pConn && pConn->pSDD->Disconnect( pConn ) == HB_SUCCESS ) + hb_rddsqlSetError( 0, NULL, NULL, NULL, 0 ); + if ( pConn && ! pConn->uiAreaCount && pConn->pSDD->Disconnect( pConn ) == HB_SUCCESS ) { pConn->hConnection = 0; - pConn->iError = 0; - if ( pConn->szError ) - { - hb_xfree( pConn->szError ); - pConn->szError = NULL; - } - if ( pConn->szQuery ) - { - hb_xfree( pConn->szQuery ); - pConn->szQuery = NULL; - } - hb_itemRelease( pConn->pNewID ); - hb_itemPutL( pItem, TRUE ); return HB_SUCCESS; } @@ -1013,22 +1050,9 @@ static HB_ERRCODE sqlbaseRddInfo( LPRDDNODE pRDD, USHORT uiIndex, ULONG ulConnec case RDDI_EXECUTE: { + hb_rddsqlSetError( 0, NULL, NULL, NULL, 0 ); if ( pConn ) { - hb_itemClear( pConn->pNewID ); - pConn->iError = 0; - if ( pConn->szError ) - { - hb_xfree( pConn->szError ); - pConn->szError = NULL; - } - if ( pConn->szQuery ) - { - hb_xfree( pConn->szQuery ); - pConn->szQuery = NULL; - } - pConn->szQuery = hb_strdup( hb_itemGetCPtr( pItem ) ); - hb_itemPutL( pItem, pConn->pSDD->Execute( pConn, pItem ) == HB_SUCCESS ); } else @@ -1039,46 +1063,31 @@ static HB_ERRCODE sqlbaseRddInfo( LPRDDNODE pRDD, USHORT uiIndex, ULONG ulConnec case RDDI_ERROR: { - if ( pConn ) - hb_itemPutC( pItem, pConn->szError ); - else - hb_itemClear( pItem ); + hb_itemPutC( pItem, s_szError ); return HB_SUCCESS; } case RDDI_ERRORNO: { - if ( pConn ) - hb_itemPutNI( pItem, pConn->iError ); - else - hb_itemClear( pItem ); + hb_itemPutNI( pItem, s_errCode ); return HB_SUCCESS; } case RDDI_QUERY: { - if ( pConn ) - hb_itemPutC( pItem, pConn->szQuery ); - else - hb_itemClear( pItem ); + hb_itemPutC( pItem, s_szQuery ); return HB_SUCCESS; } case RDDI_NEWID: { - if ( pConn ) - hb_itemCopy( pItem, pConn->pNewID ); - else - hb_itemClear( pItem ); + hb_itemCopy( pItem, s_pItemNewID ); return HB_SUCCESS; } case RDDI_AFFECTEDROWS: { - if ( pConn ) - hb_itemPutNInt( pItem, pConn->ulAffectedRows ); - else - hb_itemClear( pItem ); + hb_itemPutNInt( pItem, s_ulAffectedRows ); return HB_SUCCESS; } @@ -1190,7 +1199,7 @@ static RDDFUNCS sqlbaseTable = ( DBENTRYP_SCCS ) NULL, /* sqlbasePutValueFile */ ( DBENTRYP_V ) NULL, /* sqlbaseReadDBHeader */ ( DBENTRYP_V ) NULL, /* sqlbaseWriteDBHeader */ - ( DBENTRYP_R ) NULL, /* sqlbaseInit */ + ( DBENTRYP_R ) sqlbaseInit, ( DBENTRYP_R ) sqlbaseExit, ( DBENTRYP_RVVL ) NULL, /* sqlbaseDrop */ ( DBENTRYP_RVVL ) NULL, /* sqlbaseExists */ diff --git a/harbour/contrib/rddsql/sqlmix.c b/harbour/contrib/rddsql/sqlmix.c index 084b2810b5..aa431a572e 100644 --- a/harbour/contrib/rddsql/sqlmix.c +++ b/harbour/contrib/rddsql/sqlmix.c @@ -68,27 +68,27 @@ #define MIX_KEY( tag, node, index ) \ - ( (PMIXKEY) & ( (BYTE*) (node) ) [ ( (node)->Leaf ? sizeof( MIXNODELEAF ) : sizeof( MIXNODE ) ) + (index) * (tag)->uiTotalLen ] ) + ( ( PMIXKEY ) & ( ( BYTE * ) (node) ) [ ( (node)->Leaf ? sizeof( MIXNODELEAF ) : sizeof( MIXNODE ) ) + (index) * (tag)->uiTotalLen ] ) #define MIX_COPY_KEYS_INTERNAL( tag, node, dst, src, count ) \ - memmove( ( (BYTE*) (node) ) + ( (node)->Leaf ? sizeof( MIXNODELEAF ) : sizeof( MIXNODE ) ) + (dst) * (tag)->uiTotalLen, \ - ( (BYTE*) (node) ) + ( (node)->Leaf ? sizeof( MIXNODELEAF ) : sizeof( MIXNODE ) ) + (src) * (tag)->uiTotalLen, \ + memmove( ( ( BYTE * ) (node) ) + ( (node)->Leaf ? sizeof( MIXNODELEAF ) : sizeof( MIXNODE ) ) + (dst) * (tag)->uiTotalLen, \ + ( ( BYTE * ) (node) ) + ( (node)->Leaf ? sizeof( MIXNODELEAF ) : sizeof( MIXNODE ) ) + (src) * (tag)->uiTotalLen, \ (count) * (tag)->uiTotalLen ) #define MIX_COPY_KEYS_EXTERNAL( tag, ndst, dst, nsrc, src, count ) \ - memmove( ( (BYTE*) (ndst) ) + ( (ndst)->Leaf ? sizeof( MIXNODELEAF ) : sizeof( MIXNODE ) ) + (dst) * (tag)->uiTotalLen, \ - ( (BYTE*) (nsrc) ) + ( (nsrc)->Leaf ? sizeof( MIXNODELEAF ) : sizeof( MIXNODE ) ) + (src) * (tag)->uiTotalLen, \ + memmove( ( ( BYTE * ) (ndst) ) + ( (ndst)->Leaf ? sizeof( MIXNODELEAF ) : sizeof( MIXNODE ) ) + (dst) * (tag)->uiTotalLen, \ + ( ( BYTE * ) (nsrc) ) + ( (nsrc)->Leaf ? sizeof( MIXNODELEAF ) : sizeof( MIXNODE ) ) + (src) * (tag)->uiTotalLen, \ (count) * (tag)->uiTotalLen ) #define MIX_ASSIGN_KEY( tag, node, dst, src ) \ - memmove( ( (BYTE*) (node) ) + ( (node)->Leaf ? sizeof( MIXNODELEAF ) : sizeof( MIXNODE ) ) + (dst) * (tag)->uiTotalLen, \ + memmove( ( ( BYTE * ) (node) ) + ( (node)->Leaf ? sizeof( MIXNODELEAF ) : sizeof( MIXNODE ) ) + (dst) * (tag)->uiTotalLen, \ (src), (tag)->uiTotalLen ) #define MIX_COPY_CHILDS_INTERNAL( tag, node, dst, src, count ) \ - memmove( & ((node)->Child[ (dst) ]), & ((node)->Child[ (src) ]), (count) * sizeof( void* ) ) + memmove( & ((node)->Child[ (dst) ]), & ((node)->Child[ (src) ]), (count) * sizeof( void * ) ) #define MIX_COPY_CHILDS_EXTERNAL( tag, ndst, dst, nsrc, src, count ) \ - memmove( & ((ndst)->Child[ (dst) ]), & ((nsrc)->Child[ (src) ]), (count) * sizeof( void* ) ) + memmove( & ((ndst)->Child[ (dst) ]), & ((nsrc)->Child[ (src) ]), (count) * sizeof( void * ) ) @@ -104,7 +104,7 @@ static RDDFUNCS sqlmixSuper; */ -static HB_ERRCODE sqlmixErrorRT( SQLMIXAREAP pArea, USHORT uiGenCode, USHORT uiSubCode, char* filename, USHORT uiOsCode, USHORT uiFlags ) +static HB_ERRCODE sqlmixErrorRT( SQLMIXAREAP pArea, HB_ERRCODE errGenCode, HB_ERRCODE errSubCode, char * filename, HB_ERRCODE errOsCode, USHORT uiFlags ) { PHB_ITEM pError; HB_ERRCODE iRet = HB_FAILURE; @@ -112,15 +112,15 @@ static HB_ERRCODE sqlmixErrorRT( SQLMIXAREAP pArea, USHORT uiGenCode, USHORT uiS if ( hb_vmRequestQuery() == 0 ) { pError = hb_errNew(); - hb_errPutGenCode( pError, uiGenCode ); - hb_errPutSubCode( pError, uiSubCode ); - hb_errPutOsCode( pError, uiOsCode ); - hb_errPutDescription( pError, hb_langDGetErrorDesc( uiGenCode ) ); + hb_errPutGenCode( pError, errGenCode ); + hb_errPutSubCode( pError, errSubCode ); + hb_errPutOsCode( pError, errOsCode ); + hb_errPutDescription( pError, hb_langDGetErrorDesc( errGenCode ) ); if ( filename ) hb_errPutFileName( pError, filename ); if ( uiFlags ) hb_errPutFlags( pError, uiFlags ); - iRet = SELF_ERROR( (AREAP) pArea, pError ); + iRet = SELF_ERROR( ( AREAP ) pArea, pError ); hb_errRelease( pError ); } return iRet; @@ -160,13 +160,13 @@ static PMIXKEY hb_mixKeyPutItem( PMIXKEY pKey, PHB_ITEM pItem, ULONG ulRecNo, PM case 'C': ul = hb_itemGetCLen( pItem ); - if ( ul > (ULONG) pTag->uiKeyLen ) + if ( ul > ( ULONG ) pTag->uiKeyLen ) ul = pTag->uiKeyLen; memcpy( pKey->val, hb_itemGetCPtr( pItem ), ul ); - if ( ul < (ULONG) pTag->uiKeyLen ) - memset( pKey->val + ul, ' ', (ULONG) pTag->uiKeyLen - ul ); + if ( ul < ( ULONG ) pTag->uiKeyLen ) + memset( pKey->val + ul, ' ', ( ULONG ) pTag->uiKeyLen - ul ); break; @@ -177,7 +177,7 @@ static PMIXKEY hb_mixKeyPutItem( PMIXKEY pKey, PHB_ITEM pItem, ULONG ulRecNo, PM break; case 'D': - dbl = (double) hb_itemGetDL( pItem ); + dbl = ( double ) hb_itemGetDL( pItem ); HB_DBL2ORD( &dbl, buf ); memcpy( pKey->val, buf, 8 ); break; @@ -256,7 +256,7 @@ static int hb_mixKeyCompare( PMIXTAG pTag, PMIXKEY pKey1, PMIXKEY pKey2, unsigne if ( ! pKey1->notnul || ! pKey2->notnul ) { - return (int) pKey1->notnul - (int) pKey2->notnul; + return ( int ) pKey1->notnul - ( int ) pKey2->notnul; } i = 0; @@ -274,7 +274,7 @@ static int hb_mixKeyCompare( PMIXTAG pTag, PMIXKEY pKey1, PMIXKEY pKey2, unsigne if ( i == 0 ) { - if ( pKey2->rec == (ULONG) -1 ) + if ( pKey2->rec == ( ULONG ) -1 ) { /* This condition seems inverted, but it's ok for seek last */ if ( pTag->uiKeyLen > uiLen ) @@ -876,11 +876,11 @@ static PMIXTAG hb_mixTagCreate( const char* szTagName, PHB_ITEM pKeyExpr, PHB_IT if ( ulStartRec ) { - SELF_GOTO( (AREAP) pArea, ulStartRec ); + SELF_GOTO( ( AREAP ) pArea, ulStartRec ); } else { - SELF_GOTOP( (AREAP) pArea ); + SELF_GOTOP( ( AREAP ) pArea ); } while ( ! pArea->sqlarea.area.fEof ) @@ -1234,7 +1234,7 @@ static ULONG hb_mixDBOIKeyCount( PMIXTAG pTag, BOOL fFilter ) hb_mixTagSkip( pTag, 1 ); } hb_mixTagSetCurrent( pTag, pNode, uiPos ); - SELF_GOTO( (AREAP) pTag->pArea, ulRecNo ); + SELF_GOTO( ( AREAP ) pTag->pArea, ulRecNo ); } else @@ -1348,11 +1348,11 @@ static HB_ERRCODE sqlmixSeek( SQLMIXAREAP pArea, BOOL fSoftSeek, PHB_ITEM pItem, } else { - PMIXKEY pKey; - HB_ERRCODE retval = HB_SUCCESS; - BOOL fEOF; - PMIXTAG pTag = pArea->pTag; - PMIXNODE pNode; + PMIXKEY pKey; + HB_ERRCODE errCode = HB_SUCCESS; + BOOL fEOF; + PMIXTAG pTag = pArea->pTag; + PMIXNODE pNode; unsigned int uiKeyLen, ui; if ( pArea->sqlarea.lpdbPendingRel && pArea->sqlarea.lpdbPendingRel->isScoped ) @@ -1361,7 +1361,7 @@ static HB_ERRCODE sqlmixSeek( SQLMIXAREAP pArea, BOOL fSoftSeek, PHB_ITEM pItem, pArea->sqlarea.area.fTop = pArea->sqlarea.area.fBottom = FALSE; pArea->sqlarea.area.fEof = FALSE; - pKey = hb_mixKeyPutItem( NULL, pItem, fFindLast ? (ULONG) -1 : 0, pTag ); + pKey = hb_mixKeyPutItem( NULL, pItem, fFindLast ? ( ULONG ) -1 : 0, pTag ); uiKeyLen = pTag->uiKeyLen; if ( pTag->bType == 'C' ) @@ -1381,40 +1381,40 @@ static HB_ERRCODE sqlmixSeek( SQLMIXAREAP pArea, BOOL fSoftSeek, PHB_ITEM pItem, else hb_mixTagSkip( pTag, -1 ); - pArea->sqlarea.area.fFound = ! pTag->fEof && ( uiKeyLen == 0 || memcmp( pTag->CurKey->val, pKey->val, (ULONG) uiKeyLen ) == 0 ); + pArea->sqlarea.area.fFound = ! pTag->fEof && ( uiKeyLen == 0 || memcmp( pTag->CurKey->val, pKey->val, ( ULONG ) uiKeyLen ) == 0 ); if ( ! pArea->sqlarea.area.fFound ) hb_mixTagSetCurrent( pTag, pNode, ui ); } else { - pArea->sqlarea.area.fFound = ! pTag->fEof && ( uiKeyLen == 0 || memcmp( pTag->CurKey->val, pKey->val, (ULONG) uiKeyLen ) == 0 ); + pArea->sqlarea.area.fFound = ! pTag->fEof && ( uiKeyLen == 0 || memcmp( pTag->CurKey->val, pKey->val, ( ULONG ) uiKeyLen ) == 0 ); } fEOF = pTag->fEof; if ( !fEOF ) { - retval = SELF_GOTO( ( AREAP ) pArea, pTag->CurKey->rec ); - if ( retval != HB_FAILURE && pArea->sqlarea.fPositioned ) + errCode = SELF_GOTO( ( AREAP ) pArea, pTag->CurKey->rec ); + if ( errCode != HB_FAILURE && pArea->sqlarea.fPositioned ) { - retval = SELF_SKIPFILTER( ( AREAP ) pArea, fFindLast ? -1 : 1 ); - if ( retval != HB_FAILURE && pArea->sqlarea.fPositioned ) + errCode = SELF_SKIPFILTER( ( AREAP ) pArea, fFindLast ? -1 : 1 ); + if ( errCode != HB_FAILURE && pArea->sqlarea.fPositioned ) { - pArea->sqlarea.area.fFound = ( uiKeyLen == 0 || memcmp( pTag->CurKey->val, pKey->val, (ULONG) uiKeyLen ) == 0 ); + pArea->sqlarea.area.fFound = ( uiKeyLen == 0 || memcmp( pTag->CurKey->val, pKey->val, ( ULONG ) uiKeyLen ) == 0 ); if ( ! pArea->sqlarea.area.fFound && ! fSoftSeek ) fEOF = TRUE; } } } - if ( retval != HB_FAILURE && fEOF ) + if ( errCode != HB_FAILURE && fEOF ) { - retval = SELF_GOTO( ( AREAP ) pArea, 0 ); + errCode = SELF_GOTO( ( AREAP ) pArea, 0 ); } pArea->sqlarea.area.fBof = FALSE; hb_mixKeyFree( pKey ); - return retval; + return errCode; } } @@ -1532,7 +1532,7 @@ static HB_ERRCODE sqlmixGoHot( SQLMIXAREAP pArea ) printf( "sqlmixGoHot: multiple marking buffer as hot." ); */ - if ( SUPER_GOHOT( (AREAP) pArea ) == HB_FAILURE ) + if ( SUPER_GOHOT( ( AREAP ) pArea ) == HB_FAILURE ) return HB_FAILURE; pTag = pArea->pTagList; @@ -1551,13 +1551,13 @@ static HB_ERRCODE sqlmixGoHot( SQLMIXAREAP pArea ) static HB_ERRCODE sqlmixClose( SQLMIXAREAP pArea ) { - if ( SELF_GOCOLD( (AREAP) pArea ) == HB_FAILURE ) + if ( SELF_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) return HB_FAILURE; - if ( SUPER_CLOSE( (AREAP) pArea ) == HB_FAILURE ) + if ( SUPER_CLOSE( ( AREAP ) pArea ) == HB_FAILURE ) return HB_FAILURE; - if ( SELF_ORDLSTCLEAR( (AREAP) pArea ) == HB_FAILURE ) + if ( SELF_ORDLSTCLEAR( ( AREAP ) pArea ) == HB_FAILURE ) return HB_FAILURE; return HB_SUCCESS; @@ -1618,7 +1618,7 @@ static HB_ERRCODE sqlmixOrderCreate( SQLMIXAREAP pArea, LPDBORDERCREATEINFO pOrd } else { - if ( SELF_COMPILE( (AREAP) pArea, hb_itemGetCPtr( pOrderInfo->abExpr ) ) == HB_FAILURE ) + if ( SELF_COMPILE( ( AREAP ) pArea, hb_itemGetCPtr( pOrderInfo->abExpr ) ) == HB_FAILURE ) return HB_FAILURE; pKeyItem = pArea->sqlarea.area.valResult; pArea->sqlarea.area.valResult = NULL; @@ -1626,11 +1626,11 @@ static HB_ERRCODE sqlmixOrderCreate( SQLMIXAREAP pArea, LPDBORDERCREATEINFO pOrd /* Test key codeblock on EOF */ ulRecNo = pArea->sqlarea.ulRecNo; - SELF_GOTO( (AREAP) pArea, 0 ); - if ( SELF_EVALBLOCK( (AREAP) pArea, pKeyItem ) == HB_FAILURE ) + SELF_GOTO( ( AREAP ) pArea, 0 ); + if ( SELF_EVALBLOCK( ( AREAP ) pArea, pKeyItem ) == HB_FAILURE ) { hb_vmDestroyBlockOrMacro( pKeyItem ); - SELF_GOTO( (AREAP) pArea, ulRecNo ); + SELF_GOTO( ( AREAP ) pArea, ulRecNo ); return HB_FAILURE; } @@ -1642,7 +1642,7 @@ static HB_ERRCODE sqlmixOrderCreate( SQLMIXAREAP pArea, LPDBORDERCREATEINFO pOrd case HB_IT_STRING: case HB_IT_STRING | HB_IT_MEMO: bType = 'C'; - uiLen = (USHORT) hb_itemGetCLen( pResult ); + uiLen = ( USHORT ) hb_itemGetCLen( pResult ); if ( uiLen > MIX_MAXKEYLEN ) uiLen = MIX_MAXKEYLEN; break; @@ -1672,7 +1672,7 @@ static HB_ERRCODE sqlmixOrderCreate( SQLMIXAREAP pArea, LPDBORDERCREATEINFO pOrd if ( bType == 'U' || uiLen == 0 ) { hb_vmDestroyBlockOrMacro( pKeyItem ); - SELF_GOTO( (AREAP) pArea, ulRecNo ); + SELF_GOTO( ( AREAP ) pArea, ulRecNo ); sqlmixErrorRT( pArea, bType == 'U' ? EG_DATATYPE : EG_DATAWIDTH, 1026, NULL, 0, 0 ); return HB_FAILURE; } @@ -1686,10 +1686,10 @@ static HB_ERRCODE sqlmixOrderCreate( SQLMIXAREAP pArea, LPDBORDERCREATEINFO pOrd } else if ( pArea->sqlarea.area.lpdbOrdCondInfo->abFor ) { - if ( SELF_COMPILE( (AREAP) pArea, pArea->sqlarea.area.lpdbOrdCondInfo->abFor ) == HB_FAILURE ) + if ( SELF_COMPILE( ( AREAP ) pArea, pArea->sqlarea.area.lpdbOrdCondInfo->abFor ) == HB_FAILURE ) { hb_vmDestroyBlockOrMacro( pKeyItem ); - SELF_GOTO( (AREAP) pArea, ulRecNo ); + SELF_GOTO( ( AREAP ) pArea, ulRecNo ); return HB_FAILURE; } pForItem = pArea->sqlarea.area.valResult; @@ -1703,12 +1703,12 @@ static HB_ERRCODE sqlmixOrderCreate( SQLMIXAREAP pArea, LPDBORDERCREATEINFO pOrd } else if ( pArea->sqlarea.area.lpdbOrdCondInfo->abWhile ) { - if ( SELF_COMPILE( (AREAP) pArea, pArea->sqlarea.area.lpdbOrdCondInfo->abWhile ) == HB_FAILURE ) + if ( SELF_COMPILE( ( AREAP ) pArea, pArea->sqlarea.area.lpdbOrdCondInfo->abWhile ) == HB_FAILURE ) { hb_vmDestroyBlockOrMacro( pKeyItem ); if ( pForItem ) hb_vmDestroyBlockOrMacro( pForItem ); - SELF_GOTO( (AREAP) pArea, ulRecNo ); + SELF_GOTO( ( AREAP ) pArea, ulRecNo ); return HB_FAILURE; } pWhileItem = pArea->sqlarea.area.valResult; @@ -1719,13 +1719,13 @@ static HB_ERRCODE sqlmixOrderCreate( SQLMIXAREAP pArea, LPDBORDERCREATEINFO pOrd /* Test FOR codeblock on EOF */ if ( pForItem ) { - if ( SELF_EVALBLOCK( (AREAP) pArea, pForItem ) == HB_FAILURE ) + if ( SELF_EVALBLOCK( ( AREAP ) pArea, pForItem ) == HB_FAILURE ) { hb_vmDestroyBlockOrMacro( pKeyItem ); hb_vmDestroyBlockOrMacro( pForItem ); if ( pWhileItem ) hb_vmDestroyBlockOrMacro( pWhileItem ); - SELF_GOTO( (AREAP) pArea, ulRecNo ); + SELF_GOTO( ( AREAP ) pArea, ulRecNo ); return HB_FAILURE; } if ( hb_itemType( pArea->sqlarea.area.valResult ) != HB_IT_LOGICAL ) @@ -1736,7 +1736,7 @@ static HB_ERRCODE sqlmixOrderCreate( SQLMIXAREAP pArea, LPDBORDERCREATEINFO pOrd hb_vmDestroyBlockOrMacro( pForItem ); if ( pWhileItem ) hb_vmDestroyBlockOrMacro( pWhileItem ); - SELF_GOTO( (AREAP) pArea, ulRecNo ); + SELF_GOTO( ( AREAP ) pArea, ulRecNo ); sqlmixErrorRT( pArea, EG_DATATYPE, EDBF_INVALIDFOR, NULL, 0, 0 ); return HB_FAILURE; } @@ -1746,7 +1746,7 @@ static HB_ERRCODE sqlmixOrderCreate( SQLMIXAREAP pArea, LPDBORDERCREATEINFO pOrd /* TODO: WHILE condition is not tested, like in DBFCDX. Why? Compatibility with Clipper? */ - SELF_GOTO( (AREAP) pArea, ulRecNo ); + SELF_GOTO( ( AREAP ) pArea, ulRecNo ); pTagNew = hb_mixTagCreate( pOrderInfo->atomBagName, pOrderInfo->abExpr, pKeyItem, pForItem, pWhileItem, bType, uiLen, pArea ); @@ -1778,7 +1778,6 @@ static HB_ERRCODE sqlmixOrderInfo( SQLMIXAREAP pArea, USHORT uiIndex, LPDBORDERI PMIXTAG pTag; USHORT uiTag = 0; - switch( uiIndex ) { case DBOI_EVALSTEP: @@ -1797,17 +1796,14 @@ static HB_ERRCODE sqlmixOrderInfo( SQLMIXAREAP pArea, USHORT uiIndex, LPDBORDERI return HB_SUCCESS; } - if ( SELF_GOCOLD( ( AREAP ) pArea ) == HB_FAILURE ) return HB_FAILURE; - if ( pOrderInfo->itmOrder ) pTag = hb_mixFindTag( pArea, pOrderInfo->itmOrder ); else pTag = pArea->pTag; - switch( uiIndex ) { case DBOI_CONDITION: @@ -1828,12 +1824,12 @@ static HB_ERRCODE sqlmixOrderInfo( SQLMIXAREAP pArea, USHORT uiIndex, LPDBORDERI { const char* pForExpr = hb_itemGetCPtr( pOrderInfo->itmNewVal ); - if ( SELF_COMPILE( (AREAP) pArea, pForExpr ) == HB_SUCCESS ) + if ( SELF_COMPILE( ( AREAP ) pArea, pForExpr ) == HB_SUCCESS ) { PHB_ITEM pForItem = pArea->sqlarea.area.valResult; pArea->sqlarea.area.valResult = NULL; - if ( SELF_EVALBLOCK( (AREAP) pArea, pForItem ) == HB_SUCCESS ) + if ( SELF_EVALBLOCK( ( AREAP ) pArea, pForItem ) == HB_SUCCESS ) { if ( hb_itemType( pArea->sqlarea.area.valResult ) == HB_IT_LOGICAL ) { @@ -2054,6 +2050,14 @@ static HB_ERRCODE sqlmixOrderInfo( SQLMIXAREAP pArea, USHORT uiIndex, LPDBORDERI } +static HB_ERRCODE sqlmixInit( LPRDDNODE pRDD ) +{ + /* This empty method is used to avoid duplicated sqlbase init call */ + HB_SYMBOL_UNUSED( pRDD ); + return HB_SUCCESS; +} + + static HB_ERRCODE sqlmixExit( LPRDDNODE pRDD ) { /* This empty method is used to avoid duplicated sqlbase exit call */ @@ -2156,7 +2160,7 @@ static RDDFUNCS sqlmixTable = ( DBENTRYP_SCCS ) NULL, /* sqlmixPutValueFile */ ( DBENTRYP_V ) NULL, /* sqlmixReadDBHeader */ ( DBENTRYP_V ) NULL, /* sqlmixWriteDBHeader */ - ( DBENTRYP_R ) NULL, /* sqlmixInit */ + ( DBENTRYP_R ) sqlmixInit, ( DBENTRYP_R ) sqlmixExit, ( DBENTRYP_RVVL) NULL, /* sqlmixDrop */ ( DBENTRYP_RVVL) NULL, /* sqlmixExists */