home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 October / Chip_1997-10_cd.bin / tema / sybase / powerj / hpp.z / WQUERYDR.HPP < prev    next >
C/C++ Source or Header  |  1997-01-08  |  18KB  |  547 lines

  1. /*************************************************************************
  2.  *
  3.  * WODBCQuery -- Low-level Query interface for ODBC.
  4.  *
  5.  *************************************************************************/
  6.  
  7. #ifndef _WQUERYDR_HPP_INCLUDED
  8. #define _WQUERYDR_HPP_INCLUDED
  9.  
  10. #ifndef _WVECTOR_HPP_INCLUDED
  11. #include "wvector.hpp"
  12. #endif
  13. #ifndef _WREFOBJ_HPP_INCLUDED
  14. #include "wrefobj.hpp"
  15. #endif
  16. #ifndef _WQUERY_HPP_INCLUDED
  17. #include "wquery.hpp"
  18. #endif
  19. #ifndef _WSQLSTMT_HPP_INCLUDED
  20. #include "wsqlstmt.hpp"
  21. #endif
  22.  
  23. class WODBCDriver;
  24. class WODBCTransaction;
  25. class WODBCQueryColumnInfo;
  26. class WCriticalSection;
  27.  
  28. extern template WVector<WQuery>;
  29.  
  30. //
  31. // WBaseQuery
  32. //
  33. // Skeleton class for implementing real query drivers
  34. //
  35.  
  36. class WCMCLASS WBaseQuery : public WQuery {
  37.  
  38.     WDeclareSubclass( WBaseQuery, WQuery );
  39.  
  40.     public:
  41.  
  42.         WBaseQuery( WQuery *proxy=NULL );
  43.  
  44.         ~WBaseQuery();
  45.  
  46.     public:
  47.  
  48.         /****************************************************************
  49.          * Overrides
  50.          ****************************************************************/
  51.  
  52.         // AlwaysFetchOptions
  53.  
  54.         WBool GetAlwaysFetchOptions() const;
  55.         WBool SetAlwaysFetchOptions( WBool always );
  56.  
  57.         // AlwaysFetchRowPosition
  58.  
  59.         WBool GetAlwaysFetchRowPosition() const;
  60.         WBool SetAlwaysFetchRowPosition( WBool always );
  61.  
  62.         // AlwaysMoveCursor
  63.  
  64.         WBool GetAlwaysMoveCursor() const;
  65.         WBool SetAlwaysMoveCursor( WBool always );
  66.  
  67.         // AutoPrepare
  68.  
  69.         WBool GetAutoPrepare() const;
  70.         WBool SetAutoPrepare( WBool on );
  71.  
  72.         // BindLimit
  73.  
  74.         WULong GetBindLimit() const;
  75.         WBool  SetBindLimit( WULong limit );
  76.  
  77.         // BindPolicy
  78.  
  79.         WQueryBindPolicy GetBindPolicy() const;
  80.         WBool            SetBindPolicy( WQueryBindPolicy policy );
  81.  
  82.         // CurrentRow
  83.  
  84.         WLong GetCurrentRow() const;
  85.  
  86.         // DisplayErrorDialog
  87.  
  88.         WBool GetDisplayErrorDialog() const;
  89.         WBool SetDisplayErrorDialog( WBool display );
  90.  
  91.         // DisplayWarningDialog
  92.  
  93.         WBool GetDisplayWarningDialog() const;
  94.         WBool SetDisplayWarningDialog( WBool display );
  95.  
  96.         WICursorProxyBase *GetICursorProxy() const;
  97.         WBool              SetICursorProxy( WICursorProxyBase *p );
  98.  
  99.         // LongColumnBindSize
  100.  
  101.         WULong GetLongColumnBindSize() const;
  102.         WBool  SetLongColumnBindSize( WULong size );
  103.  
  104.         // SQL
  105.  
  106.         WString GetSQL() const;
  107.         WBool   SetSQL( const WString & str );
  108.  
  109.         // State
  110.         
  111.         WDWord GetState() const;
  112.  
  113.         WBool GetUseDefaultBindTypes() const;
  114.         WBool SetUseDefaultBindTypes( WBool use );
  115.  
  116.         WLong Reference();
  117.         WLong Unreference();
  118.  
  119.         /****************************************************************
  120.          * Item Properties
  121.          ****************************************************************/
  122.  
  123.         // NumericOption
  124.  
  125.         WLong GetNumericOption( WULong id, WBool *ok=NULL ) const;
  126.         WBool SetNumericOption( WULong id, WLong value );
  127.  
  128.         /****************************************************************
  129.          * Internal
  130.          ****************************************************************/
  131.  
  132.     public:
  133.  
  134.         WBool CopySettingsToDriver( WBool assumeDefaults );
  135.         WBool AddClone( WQuery *clone );
  136.         WBool RemoveClone( WQuery *clone );
  137.  
  138.         WBool GetThreadSafe() const;
  139.         WBool SetThreadSafe( WBool safe );
  140.  
  141.         WBool ThreadLock( WBool wait=TRUE, WDWord time=0xFFFFFFFF );
  142.  
  143.         WBool ThreadUnlock();
  144.  
  145.     protected:
  146.  
  147.         WString GetTableNameFromStatement() const;
  148.         virtual void ResetState( WBool requery=FALSE );
  149.  
  150.         WQuery             *_proxy;
  151.         WString             _sqlStatement;
  152.         WDWord              _state;
  153.         WBool               _autoPrepare;
  154.         WLong               _rowsetSize;
  155.         WLong               _keysetSize;
  156.         WQueryCursorType    _cursorType;
  157.         WString             _cursorName;
  158.         WBool               _alwaysGetOptions;
  159.         WQueryBindPolicy    _bindPolicy;
  160.         WULong              _bindLimit;
  161.         WULong              _longColumnBindSize;
  162.         WBool               _alwaysFetchRowPosition;
  163.         WBool               _alwaysMoveCursor;
  164.         WBool               _displayErrors;
  165.         WBool               _displayWarnings;
  166.         WBool               _traceToLog;
  167.         WULong              _traceLevel;
  168.         WULong              _maxRows;
  169.         WULong              _queryTimeout;
  170.         WQueryUpdatePolicy  _updatePolicy;
  171.         WBool               _useDefaultBindTypes;
  172.         WBool               _isRequery;
  173.         WBool               _fetchAbsoluteOK;
  174.  
  175.         //
  176.         // The actual policy being use by the query object as
  177.         // _updatePolicy can be WQUPAuto.
  178.         //
  179.         WQueryUpdatePolicy  _updatePolicyInUse;
  180.         WBool               _isClone;
  181.         WQuery             *_cloneMaster;
  182.         WVector<WQuery>     _cloneList;
  183.         WLong               _refCount;
  184.         WICursorProxyBase  *_qiProxy;
  185.  
  186.         WCriticalSection   *_critSect;
  187.         wllist_header       _states;
  188.  
  189.         #ifdef _DEBUG
  190.  
  191.         class WCMCLASS QTrace {
  192.             public:
  193.                 QTrace( const WBaseQuery *, const WChar * );
  194.                 ~QTrace();
  195.  
  196.                 const WBaseQuery *query;
  197.                 const WChar      *function;
  198.         };
  199.  
  200.         friend class QTrace;
  201.  
  202.         void QDbg( const QTrace *q, const WChar *format, ... ) const;
  203.  
  204.         #endif
  205. };
  206.  
  207. //
  208. // WODBCQuery
  209. //
  210. // Implements the query interface for ODBC.
  211. //
  212.  
  213. class WCMCLASS WODBCQuery : public WBaseQuery {
  214.  
  215.     WDeclareSubclass( WODBCQuery, WBaseQuery );
  216.  
  217.     public:
  218.  
  219.         WODBCQuery( WQuery *proxy=NULL );
  220.  
  221.         virtual ~WODBCQuery();
  222.  
  223.         /***************************************************************
  224.          * Properties
  225.          ***************************************************************/
  226.  
  227.         /****************************************************************
  228.          * Overrides
  229.          ****************************************************************/
  230.  
  231.     public:
  232.  
  233.         WBool GetAutoEdit() const;
  234.         WBool SetAutoEdit( WBool autoEdit );
  235.  
  236.         WBool GetAutoRefresh() const;
  237.         WBool SetAutoRefresh( WBool autoRefresh );
  238.  
  239.         WBool GetBOF() const;
  240.  
  241.         WDWord GetBookmark() const;
  242.  
  243.         WQueryConcurrencyLevel GetConcurrencyLevel() const;
  244.         WBool                  SetConcurrencyLevel( WQueryConcurrencyLevel l );
  245.  
  246.         WString GetCursorName() const;
  247.         WBool   SetCursorName( const WString & str );
  248.  
  249.         WQueryCursorType GetCursorType() const;
  250.         WBool            SetCursorType( WQueryCursorType type );
  251.  
  252.         WBool GetDriverPacksRows() const;
  253.         WBool SetDriverPacksRows( WBool packsRows );
  254.  
  255.         WBool GetEOF() const;
  256.  
  257.         WDWord GetHandle() const;
  258.  
  259.         WTransaction *GetTransactionObject() const;
  260.         WBool         SetTransactionObject( WTransaction *obj );
  261.  
  262.         const WDataColumn & GetColumn( WShort index ) const;
  263.         const WDataColumn & GetColumn( const WString & name ) const;
  264.  
  265.         WShort GetColumnCount() const;
  266.  
  267.         WShort GetColumnIndex( const WString & str ) const;
  268.  
  269.         WLong GetCurrentOffset() const;
  270.  
  271.         WDSEditMode GetEditMode() const;
  272.  
  273.         WBool GetEmpty() const;
  274.  
  275.         WLong GetErrorCode( WLong *apiCode=NULL ) const;
  276.  
  277.         WDataErrorArray GetErrorList() const;
  278.  
  279.         WBool GetErrorInfo( WString *errorMessage,
  280.                             WString *state=NULL,
  281.                             WLong *nativeErrorCode=NULL ) const;
  282.  
  283.         WLong GetFetchedRows() const;
  284.  
  285.         WLong GetKeysetSize() const;
  286.         WBool SetKeysetSize( WLong size );
  287.  
  288.         WULong GetMaxLength() const;
  289.         WBool  SetMaxLength( WULong maxLength );
  290.  
  291.         WULong GetMaxRows() const;
  292.         WBool  SetMaxRows( WULong maxRows );
  293.  
  294.         WBool GetNull() const;
  295.  
  296.         WDataValue GetParameter( WShort index ) const;
  297.         WBool      SetParameter( WShort index,
  298.                                  const WDataValue & val,
  299.                                  WColumnDataType sqlType=SQL_TYPE_NULL,
  300.                                  WQueryParameterType type=WQPTInput,
  301.                                  SDWORD maxSize=0 );
  302.  
  303.         WULong GetQueryTimeout() const;
  304.         WBool  SetQueryTimeout( WULong seconds );
  305.  
  306.         WBool GetRawData( WShort index, WNativeDataType type,
  307.                           void *buffer, WLong bufferSize=0,
  308.                           WLong *bytesRemaining=NULL ) const;
  309.  
  310.         WBool GetReadOnly() const;
  311.  
  312.         WBool GetRetrieveData() const;
  313.         WBool SetRetrieveData( WBool ret );
  314.  
  315.         WBool GetRowTargetChanged() const;
  316.         WBool SetRowTargetChanged( WBool changed );
  317.  
  318.         WBool GetRowChanged() const;
  319.         WBool SetRowChanged( WBool changed );
  320.  
  321.         WLong  GetRowCount( WBool forceCount=TRUE ) const;
  322.  
  323.         WLong  GetRowsetSize() const;
  324.         WBool  SetRowsetSize( WLong size );
  325.  
  326.         UWORD GetRowsetStatus( WLong row=1 ) const;
  327.  
  328.         WBool GetTargetsEnabled() const;
  329.         WBool SetTargetsEnabled( WBool enabled );
  330.  
  331.         WBool GetAlwaysReadWriteTargets() const;
  332.         WBool SetAlwaysReadWriteTargets( WBool enabled );
  333.  
  334.         WBool GetTraceToLog() const;
  335.         WBool SetTraceToLog( WBool on );
  336.  
  337.         WQueryUpdatePolicy GetUpdatePolicy() const;
  338.         WBool              SetUpdatePolicy( WQueryUpdatePolicy policy );
  339.  
  340.         WBool GetUseBookmarks() const;
  341.         WBool SetUseBookmarks( WBool use );
  342.  
  343.         WBool Add( WBool copyValues=FALSE, WBool append=FALSE,
  344.                    WBool copyIntoBuffer=FALSE );
  345.  
  346.         WBool AddSearchParameter( WShort columnIndex, WDataValue value,
  347.                       WStmtCondition=WSNAnd,WStmtCompare compare=WSMLike);
  348.         WBool AddSearchParameter( const WString & columnName, WDataValue value,
  349.                       WStmtCondition=WSNAnd,WStmtCompare compare=WSMLike);
  350.  
  351.         WBool BindColumn( WShort column, WNativeDataType type=SQL_C_DEFAULT,
  352.                           void *arrayStart=NULL, SDWORD elementSize=0,
  353.                           SDWORD *lengthArray=NULL );
  354.  
  355.         WBool BindParameter( WShort column, WQueryParameterType type,
  356.                              WNativeDataType cType,
  357.                              WColumnDataType sqlType,
  358.                              UDWORD precision, SWORD scale,
  359.                              void *dataBuffer, SDWORD maxSize,
  360.                              SDWORD *actualLength );
  361.  
  362.         WBool BoundControlSearch(WStmtCondition=WSNAnd,
  363.                       WStmtCompare compare=WSMLike);
  364.  
  365.         WBool CancelUpdate( WBool notifyTargets=TRUE );
  366.  
  367.         WBool  Close( WBool closeCursor=TRUE, WBool r=FALSE );
  368.  
  369.         WBool  Create( WTransaction *trans );
  370.  
  371.         WBool ClearTargets();
  372.  
  373.         WQuery *Clone();
  374.  
  375.         WBool Delete( WBool triggerEvent=TRUE, WBool notifyTargets=TRUE );
  376.  
  377.         WBool DeleteSearchParameters();
  378.  
  379.         WBool  Destroy();
  380.  
  381.         WBool Edit();
  382.  
  383.         WBool  Execute( const WString & str=WString::GetNullString() );
  384.  
  385.         WBool  Fetch( WLong row, WBool notifyTargets=TRUE,
  386.                       WDSMoveType type=WDSMoveAbsolute, WBool trigger=TRUE );
  387.  
  388.         WBool FetchErrors( WLong errorCode, WLong funcCode );
  389.  
  390.         WBool  FlushUnboundValues();
  391.  
  392.         WBool  Open( WBool e=TRUE, WBool r=FALSE );
  393.  
  394.         WBool  Prepare();
  395.  
  396.         WBool MarkColumnForUpdate( WShort column, WBool mark );
  397.  
  398.         WBool MoreResults();
  399.  
  400.         WBool  Move( WLong row, WBool notifyTargets=TRUE,
  401.                      WDSMoveType type=WDSMoveAbsolute, WBool trigger=TRUE );
  402.  
  403.         WBool Refresh();
  404.  
  405.         WBool RefreshTargets( WBool multiRow=FALSE );
  406.  
  407.         WBool ResetSearch();
  408.  
  409.         WBool Resubmit( WBool executeStatement=TRUE, WBool closeCursor=TRUE );
  410.  
  411.         WBool Search();
  412.         WBool Search( WShort columnIndex, WDataValue value,
  413.                       WStmtCondition=WSNAnd,WStmtCompare compare=WSMLike);
  414.         WBool Search( const WString & columnName, WDataValue value,
  415.                       WStmtCondition=WSNAnd,WStmtCompare compare=WSMLike);
  416.  
  417.         WBool Update( WBool triggerEvent=TRUE, WBool notifyTargets=TRUE );
  418.  
  419.         WDataValue GetValue( WShort index, WNativeDataType type=SQL_C_DEFAULT ) const;
  420.         WBool      SetValue( WShort index, const WDataValue & val );
  421.  
  422.         WLong GetNumericOption( WULong id, WBool *ok=NULL ) const;
  423.         WBool SetNumericOption( WULong id, WLong value );
  424.  
  425.         WBool QueryColumnBinding( WShort column,
  426.                                   WNativeDataType *boundAs=NULL,
  427.                                   void **arrayStart=NULL,
  428.                                   SDWORD *elementSize=NULL,
  429.                                   SDWORD **lengthArray=NULL );
  430.  
  431.         WBool UnbindColumn( WShort column );
  432.  
  433.         WBool UnbindParameter( WShort index );
  434.  
  435.         WBool Connect( WEventData *data=NULL );
  436.         WBool Disconnect( WEventData *data=NULL );
  437.  
  438.         /****************************************************************
  439.          * Internal
  440.          ****************************************************************/
  441.  
  442.     public:
  443.  
  444.         WBool CopySettingsToDriver( WBool assumeDefaults );
  445.         WBool TransactionEvent( WEventID id, WEventData *data=NULL );
  446.         WBool CountRows( WBool ensureValid=FALSE );
  447.         WBool SetSearchValue( WShort index, const WDataValue & val );
  448.  
  449.     protected:
  450.  
  451.         WBool BuildSearch(WStmtCondition condition,
  452.                       WStmtCompare compare);
  453.         WBool Check( RETCODE retcode, int func=0 ) const;
  454.         void  InternalError( WInt err=0 );
  455.         WBool PrepareForFetch( WBool bind=TRUE ) const;
  456.         WBool AllocateColumnInfo();
  457.         WBool CallEvent( WEventID id, WEventData *data=NULL );
  458.         WBool AutoBind();
  459.         void  LoadColumnTargets();
  460.         WBool SyncDataValues();
  461.         WBool DetachDataValues();
  462.         void  AdjustEventMask();
  463.         WBool DoUpdate();
  464.         WLong GetBoundColumns() const;
  465.         void  NotifyTargets( WLong row, WULong reason,
  466.                              WULong action = WDataActionNone,
  467.                              WBool multiValueOnly = FALSE ) const;
  468.  
  469.         WBool GetDriverOption( WULong id, WLong & num, WBool def ) const;
  470.         WBool GetDriverOption( WULong id, WString & str, WBool def ) const;
  471.         WBool SetDriverOption( WULong id, WLong num, WBool def );
  472.         WBool SetDriverOption( WULong id, const WString & str, WBool def );
  473.         WBool RefreshRowset();
  474.         WBool DoParameterBinding();
  475.         WBool DoParameterSyncing();
  476.         WBool LateBindTarget( WQuery *query, WDataTarget *target );
  477.         WBool PerformCursorUpdate( const WULong action );
  478.         void  EventNotice( WEventID id, WEventNotice type );
  479.         void  ResetState( WBool requery=FALSE );
  480.  
  481.         WBool RestoreState( const WDataSourceState state, WBool restore=TRUE );
  482.         WBool SaveState( WDataSourceState & state );
  483.  
  484.         WQueryUpdatePolicy TryOtherUP() const;
  485.  
  486.     protected:
  487.  
  488.         WTransaction           *_transDriver;
  489.         WODBCTransaction       *_realTransDriver;
  490.         WODBCDriver            *_driver;
  491.         WODBCStmtHandle         _handle;
  492.         WULong                  _maxLength;
  493.         WQueryConcurrencyLevel  _concurrencyLevel;
  494.         WDSEditMode             _editMode;
  495.         WBool                   _rowCountValid;
  496.         WBool                   _retrieveData;
  497.         WBool                   _useBookmarks;
  498.         WBool                   _autoRefresh;
  499.         WBool                   _autoEdit;
  500.         WBool                   _fetchedError;
  501.         WLong                   _lastCode;      
  502.         WLong                   _lastFunc;
  503.         WDataErrorArray         _errorList;
  504.         WDWord                  _eventMask;
  505.  
  506.         // Column info
  507.  
  508.         SWORD                   _numCols;
  509.         WDataColumn            *_columnList;
  510.         WODBCQueryColumnInfo  **_columnInfo;
  511.         WShort                  _lastVisited;
  512.  
  513.         // Parameter info
  514.  
  515.         wllist_header           _paramList;
  516.         WBool                   _bindParams;
  517.         WBool                   _paramsBound;
  518.  
  519.         // Rowset info
  520.  
  521.         UDWORD                  _numRows;         // number of valid rows
  522.         SDWORD                  _cursorRow;       // current row in rowset
  523.         SDWORD                  _firstRow;        // row # of first row in set
  524.         SDWORD                  _actualCursorRow;
  525.         UWORD                  *_rowStatusList;
  526.         WBool                   _bof;
  527.         WBool                   _eof;
  528.         WBool                   _needToSync;
  529.         WLong                   _rowCount;        // total # of rows
  530.         WLong                   _deltaRows;       // # add/del'd rows in rowset
  531.         // Relative move required to set the current row after fetching
  532.         // backwards
  533.         WLong                   _rowOffset;
  534.         WBool                   _addingInRowset;
  535.         WLong                   _deltaRowsInRowset;
  536.         WBool                   _driverPacksRows;
  537.  
  538.         // Search info
  539.         WSQLStatement           _wSqlStmt;
  540.         WShort                  _initParms; // user's initial number of parms
  541.         WShort                  _noOfParms; // final number of parms after
  542.                                             // incrementing
  543.  
  544. };
  545.  
  546. #endif
  547.