home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1997 October
/
Chip_1997-10_cd.bin
/
tema
/
sybase
/
powerj
/
hpp.z
/
WQUERYDR.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1997-01-08
|
18KB
|
547 lines
/*************************************************************************
*
* WODBCQuery -- Low-level Query interface for ODBC.
*
*************************************************************************/
#ifndef _WQUERYDR_HPP_INCLUDED
#define _WQUERYDR_HPP_INCLUDED
#ifndef _WVECTOR_HPP_INCLUDED
#include "wvector.hpp"
#endif
#ifndef _WREFOBJ_HPP_INCLUDED
#include "wrefobj.hpp"
#endif
#ifndef _WQUERY_HPP_INCLUDED
#include "wquery.hpp"
#endif
#ifndef _WSQLSTMT_HPP_INCLUDED
#include "wsqlstmt.hpp"
#endif
class WODBCDriver;
class WODBCTransaction;
class WODBCQueryColumnInfo;
class WCriticalSection;
extern template WVector<WQuery>;
//
// WBaseQuery
//
// Skeleton class for implementing real query drivers
//
class WCMCLASS WBaseQuery : public WQuery {
WDeclareSubclass( WBaseQuery, WQuery );
public:
WBaseQuery( WQuery *proxy=NULL );
~WBaseQuery();
public:
/****************************************************************
* Overrides
****************************************************************/
// AlwaysFetchOptions
WBool GetAlwaysFetchOptions() const;
WBool SetAlwaysFetchOptions( WBool always );
// AlwaysFetchRowPosition
WBool GetAlwaysFetchRowPosition() const;
WBool SetAlwaysFetchRowPosition( WBool always );
// AlwaysMoveCursor
WBool GetAlwaysMoveCursor() const;
WBool SetAlwaysMoveCursor( WBool always );
// AutoPrepare
WBool GetAutoPrepare() const;
WBool SetAutoPrepare( WBool on );
// BindLimit
WULong GetBindLimit() const;
WBool SetBindLimit( WULong limit );
// BindPolicy
WQueryBindPolicy GetBindPolicy() const;
WBool SetBindPolicy( WQueryBindPolicy policy );
// CurrentRow
WLong GetCurrentRow() const;
// DisplayErrorDialog
WBool GetDisplayErrorDialog() const;
WBool SetDisplayErrorDialog( WBool display );
// DisplayWarningDialog
WBool GetDisplayWarningDialog() const;
WBool SetDisplayWarningDialog( WBool display );
WICursorProxyBase *GetICursorProxy() const;
WBool SetICursorProxy( WICursorProxyBase *p );
// LongColumnBindSize
WULong GetLongColumnBindSize() const;
WBool SetLongColumnBindSize( WULong size );
// SQL
WString GetSQL() const;
WBool SetSQL( const WString & str );
// State
WDWord GetState() const;
WBool GetUseDefaultBindTypes() const;
WBool SetUseDefaultBindTypes( WBool use );
WLong Reference();
WLong Unreference();
/****************************************************************
* Item Properties
****************************************************************/
// NumericOption
WLong GetNumericOption( WULong id, WBool *ok=NULL ) const;
WBool SetNumericOption( WULong id, WLong value );
/****************************************************************
* Internal
****************************************************************/
public:
WBool CopySettingsToDriver( WBool assumeDefaults );
WBool AddClone( WQuery *clone );
WBool RemoveClone( WQuery *clone );
WBool GetThreadSafe() const;
WBool SetThreadSafe( WBool safe );
WBool ThreadLock( WBool wait=TRUE, WDWord time=0xFFFFFFFF );
WBool ThreadUnlock();
protected:
WString GetTableNameFromStatement() const;
virtual void ResetState( WBool requery=FALSE );
WQuery *_proxy;
WString _sqlStatement;
WDWord _state;
WBool _autoPrepare;
WLong _rowsetSize;
WLong _keysetSize;
WQueryCursorType _cursorType;
WString _cursorName;
WBool _alwaysGetOptions;
WQueryBindPolicy _bindPolicy;
WULong _bindLimit;
WULong _longColumnBindSize;
WBool _alwaysFetchRowPosition;
WBool _alwaysMoveCursor;
WBool _displayErrors;
WBool _displayWarnings;
WBool _traceToLog;
WULong _traceLevel;
WULong _maxRows;
WULong _queryTimeout;
WQueryUpdatePolicy _updatePolicy;
WBool _useDefaultBindTypes;
WBool _isRequery;
WBool _fetchAbsoluteOK;
//
// The actual policy being use by the query object as
// _updatePolicy can be WQUPAuto.
//
WQueryUpdatePolicy _updatePolicyInUse;
WBool _isClone;
WQuery *_cloneMaster;
WVector<WQuery> _cloneList;
WLong _refCount;
WICursorProxyBase *_qiProxy;
WCriticalSection *_critSect;
wllist_header _states;
#ifdef _DEBUG
class WCMCLASS QTrace {
public:
QTrace( const WBaseQuery *, const WChar * );
~QTrace();
const WBaseQuery *query;
const WChar *function;
};
friend class QTrace;
void QDbg( const QTrace *q, const WChar *format, ... ) const;
#endif
};
//
// WODBCQuery
//
// Implements the query interface for ODBC.
//
class WCMCLASS WODBCQuery : public WBaseQuery {
WDeclareSubclass( WODBCQuery, WBaseQuery );
public:
WODBCQuery( WQuery *proxy=NULL );
virtual ~WODBCQuery();
/***************************************************************
* Properties
***************************************************************/
/****************************************************************
* Overrides
****************************************************************/
public:
WBool GetAutoEdit() const;
WBool SetAutoEdit( WBool autoEdit );
WBool GetAutoRefresh() const;
WBool SetAutoRefresh( WBool autoRefresh );
WBool GetBOF() const;
WDWord GetBookmark() const;
WQueryConcurrencyLevel GetConcurrencyLevel() const;
WBool SetConcurrencyLevel( WQueryConcurrencyLevel l );
WString GetCursorName() const;
WBool SetCursorName( const WString & str );
WQueryCursorType GetCursorType() const;
WBool SetCursorType( WQueryCursorType type );
WBool GetDriverPacksRows() const;
WBool SetDriverPacksRows( WBool packsRows );
WBool GetEOF() const;
WDWord GetHandle() const;
WTransaction *GetTransactionObject() const;
WBool SetTransactionObject( WTransaction *obj );
const WDataColumn & GetColumn( WShort index ) const;
const WDataColumn & GetColumn( const WString & name ) const;
WShort GetColumnCount() const;
WShort GetColumnIndex( const WString & str ) const;
WLong GetCurrentOffset() const;
WDSEditMode GetEditMode() const;
WBool GetEmpty() const;
WLong GetErrorCode( WLong *apiCode=NULL ) const;
WDataErrorArray GetErrorList() const;
WBool GetErrorInfo( WString *errorMessage,
WString *state=NULL,
WLong *nativeErrorCode=NULL ) const;
WLong GetFetchedRows() const;
WLong GetKeysetSize() const;
WBool SetKeysetSize( WLong size );
WULong GetMaxLength() const;
WBool SetMaxLength( WULong maxLength );
WULong GetMaxRows() const;
WBool SetMaxRows( WULong maxRows );
WBool GetNull() const;
WDataValue GetParameter( WShort index ) const;
WBool SetParameter( WShort index,
const WDataValue & val,
WColumnDataType sqlType=SQL_TYPE_NULL,
WQueryParameterType type=WQPTInput,
SDWORD maxSize=0 );
WULong GetQueryTimeout() const;
WBool SetQueryTimeout( WULong seconds );
WBool GetRawData( WShort index, WNativeDataType type,
void *buffer, WLong bufferSize=0,
WLong *bytesRemaining=NULL ) const;
WBool GetReadOnly() const;
WBool GetRetrieveData() const;
WBool SetRetrieveData( WBool ret );
WBool GetRowTargetChanged() const;
WBool SetRowTargetChanged( WBool changed );
WBool GetRowChanged() const;
WBool SetRowChanged( WBool changed );
WLong GetRowCount( WBool forceCount=TRUE ) const;
WLong GetRowsetSize() const;
WBool SetRowsetSize( WLong size );
UWORD GetRowsetStatus( WLong row=1 ) const;
WBool GetTargetsEnabled() const;
WBool SetTargetsEnabled( WBool enabled );
WBool GetAlwaysReadWriteTargets() const;
WBool SetAlwaysReadWriteTargets( WBool enabled );
WBool GetTraceToLog() const;
WBool SetTraceToLog( WBool on );
WQueryUpdatePolicy GetUpdatePolicy() const;
WBool SetUpdatePolicy( WQueryUpdatePolicy policy );
WBool GetUseBookmarks() const;
WBool SetUseBookmarks( WBool use );
WBool Add( WBool copyValues=FALSE, WBool append=FALSE,
WBool copyIntoBuffer=FALSE );
WBool AddSearchParameter( WShort columnIndex, WDataValue value,
WStmtCondition=WSNAnd,WStmtCompare compare=WSMLike);
WBool AddSearchParameter( const WString & columnName, WDataValue value,
WStmtCondition=WSNAnd,WStmtCompare compare=WSMLike);
WBool BindColumn( WShort column, WNativeDataType type=SQL_C_DEFAULT,
void *arrayStart=NULL, SDWORD elementSize=0,
SDWORD *lengthArray=NULL );
WBool BindParameter( WShort column, WQueryParameterType type,
WNativeDataType cType,
WColumnDataType sqlType,
UDWORD precision, SWORD scale,
void *dataBuffer, SDWORD maxSize,
SDWORD *actualLength );
WBool BoundControlSearch(WStmtCondition=WSNAnd,
WStmtCompare compare=WSMLike);
WBool CancelUpdate( WBool notifyTargets=TRUE );
WBool Close( WBool closeCursor=TRUE, WBool r=FALSE );
WBool Create( WTransaction *trans );
WBool ClearTargets();
WQuery *Clone();
WBool Delete( WBool triggerEvent=TRUE, WBool notifyTargets=TRUE );
WBool DeleteSearchParameters();
WBool Destroy();
WBool Edit();
WBool Execute( const WString & str=WString::GetNullString() );
WBool Fetch( WLong row, WBool notifyTargets=TRUE,
WDSMoveType type=WDSMoveAbsolute, WBool trigger=TRUE );
WBool FetchErrors( WLong errorCode, WLong funcCode );
WBool FlushUnboundValues();
WBool Open( WBool e=TRUE, WBool r=FALSE );
WBool Prepare();
WBool MarkColumnForUpdate( WShort column, WBool mark );
WBool MoreResults();
WBool Move( WLong row, WBool notifyTargets=TRUE,
WDSMoveType type=WDSMoveAbsolute, WBool trigger=TRUE );
WBool Refresh();
WBool RefreshTargets( WBool multiRow=FALSE );
WBool ResetSearch();
WBool Resubmit( WBool executeStatement=TRUE, WBool closeCursor=TRUE );
WBool Search();
WBool Search( WShort columnIndex, WDataValue value,
WStmtCondition=WSNAnd,WStmtCompare compare=WSMLike);
WBool Search( const WString & columnName, WDataValue value,
WStmtCondition=WSNAnd,WStmtCompare compare=WSMLike);
WBool Update( WBool triggerEvent=TRUE, WBool notifyTargets=TRUE );
WDataValue GetValue( WShort index, WNativeDataType type=SQL_C_DEFAULT ) const;
WBool SetValue( WShort index, const WDataValue & val );
WLong GetNumericOption( WULong id, WBool *ok=NULL ) const;
WBool SetNumericOption( WULong id, WLong value );
WBool QueryColumnBinding( WShort column,
WNativeDataType *boundAs=NULL,
void **arrayStart=NULL,
SDWORD *elementSize=NULL,
SDWORD **lengthArray=NULL );
WBool UnbindColumn( WShort column );
WBool UnbindParameter( WShort index );
WBool Connect( WEventData *data=NULL );
WBool Disconnect( WEventData *data=NULL );
/****************************************************************
* Internal
****************************************************************/
public:
WBool CopySettingsToDriver( WBool assumeDefaults );
WBool TransactionEvent( WEventID id, WEventData *data=NULL );
WBool CountRows( WBool ensureValid=FALSE );
WBool SetSearchValue( WShort index, const WDataValue & val );
protected:
WBool BuildSearch(WStmtCondition condition,
WStmtCompare compare);
WBool Check( RETCODE retcode, int func=0 ) const;
void InternalError( WInt err=0 );
WBool PrepareForFetch( WBool bind=TRUE ) const;
WBool AllocateColumnInfo();
WBool CallEvent( WEventID id, WEventData *data=NULL );
WBool AutoBind();
void LoadColumnTargets();
WBool SyncDataValues();
WBool DetachDataValues();
void AdjustEventMask();
WBool DoUpdate();
WLong GetBoundColumns() const;
void NotifyTargets( WLong row, WULong reason,
WULong action = WDataActionNone,
WBool multiValueOnly = FALSE ) const;
WBool GetDriverOption( WULong id, WLong & num, WBool def ) const;
WBool GetDriverOption( WULong id, WString & str, WBool def ) const;
WBool SetDriverOption( WULong id, WLong num, WBool def );
WBool SetDriverOption( WULong id, const WString & str, WBool def );
WBool RefreshRowset();
WBool DoParameterBinding();
WBool DoParameterSyncing();
WBool LateBindTarget( WQuery *query, WDataTarget *target );
WBool PerformCursorUpdate( const WULong action );
void EventNotice( WEventID id, WEventNotice type );
void ResetState( WBool requery=FALSE );
WBool RestoreState( const WDataSourceState state, WBool restore=TRUE );
WBool SaveState( WDataSourceState & state );
WQueryUpdatePolicy TryOtherUP() const;
protected:
WTransaction *_transDriver;
WODBCTransaction *_realTransDriver;
WODBCDriver *_driver;
WODBCStmtHandle _handle;
WULong _maxLength;
WQueryConcurrencyLevel _concurrencyLevel;
WDSEditMode _editMode;
WBool _rowCountValid;
WBool _retrieveData;
WBool _useBookmarks;
WBool _autoRefresh;
WBool _autoEdit;
WBool _fetchedError;
WLong _lastCode;
WLong _lastFunc;
WDataErrorArray _errorList;
WDWord _eventMask;
// Column info
SWORD _numCols;
WDataColumn *_columnList;
WODBCQueryColumnInfo **_columnInfo;
WShort _lastVisited;
// Parameter info
wllist_header _paramList;
WBool _bindParams;
WBool _paramsBound;
// Rowset info
UDWORD _numRows; // number of valid rows
SDWORD _cursorRow; // current row in rowset
SDWORD _firstRow; // row # of first row in set
SDWORD _actualCursorRow;
UWORD *_rowStatusList;
WBool _bof;
WBool _eof;
WBool _needToSync;
WLong _rowCount; // total # of rows
WLong _deltaRows; // # add/del'd rows in rowset
// Relative move required to set the current row after fetching
// backwards
WLong _rowOffset;
WBool _addingInRowset;
WLong _deltaRowsInRowset;
WBool _driverPacksRows;
// Search info
WSQLStatement _wSqlStmt;
WShort _initParms; // user's initial number of parms
WShort _noOfParms; // final number of parms after
// incrementing
};
#endif