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

  1.  
  2. #ifndef _WQUERY_HPP_INCLUDED
  3. #define _WQUERY_HPP_INCLUDED
  4.  
  5. //-----------------------------------------------------------------------
  6. //
  7. // SQL Query object.
  8. //
  9. // The query object is patterned on the ODBC model.  The simplest way
  10. // to use it is as follows:
  11. //
  12. //     WQuery query;
  13. //
  14. //     query.Create( &transObject );
  15. //     query.SetSQLStatement( "select * from table" );
  16. //
  17. //     if( query.Open() ){
  18. //         query.Close();
  19. //     }
  20. //
  21. // The query object will only work when attached to a transaction object.
  22. // The transaction object must be connected to a database for most of
  23. // the methods to work.
  24. //
  25. //-----------------------------------------------------------------------
  26.  
  27. /*************************************************************************
  28.  *
  29.  *   Events:
  30.  *
  31.  *       AdjustCursor --
  32.  *
  33.  *       BeginFetchData --
  34.  *
  35.  *       BeginMoveCursor --
  36.  *
  37.  *       DatabaseError --
  38.  *
  39.  *       FetchData --
  40.  *
  41.  *       MoveCursor --
  42.  *
  43.  *       QueryBusy --
  44.  *
  45.  *       QueryClose --
  46.  *
  47.  *       QueryOpen --
  48.  *
  49.  *       QueryPrepare --
  50.  *
  51.  *       ValidateData --
  52.  *
  53.  ************************************************************************/
  54.  
  55. #ifndef _WDATASRC_HPP_INCLUDED
  56. #include "wdatasrc.hpp"
  57. #endif
  58. #ifndef _WDATAERR_HPP_INCLUDED
  59. #include "wdataerr.hpp"
  60. #endif
  61.  
  62. class WTransaction;
  63. class WQuery;
  64.  
  65. //
  66. // BindPolicy
  67. //
  68. //    Determines the policy the query object uses to bind the various
  69. //    columns.  The policy applies to columns that are not explicitly
  70. //    bound by the user or by any bound controls:
  71. //
  72. //      All     -- Bind all columns below a size threshhold
  73. //      Minimal -- If column "n" is bound, make sure columns 1 to n-1 are
  74. //                 bound.
  75. //      None    -- Do not do any default binding.
  76.  
  77. enum WQueryBindPolicy {
  78.     WQBPAll,    
  79.     WQBPMinimal,
  80.     WQBPNone
  81. };
  82.  
  83. //
  84. // UpdatePolicy
  85. //
  86. //    This policy determines the type of action to perform an update.
  87. //
  88. //    Auto       -- The query object determines which type to use.
  89. //    Direct     -- Directly updates the current row by using driver specific
  90. //                  functions if it's supported. i.e. in ODBC, SQLSetPos()
  91. //    Cursor     -- Open another query to execute a statement of type
  92. //                  UPDATE .... SET .... WHERE CURRENT OF <cursorname>
  93. //                  if it's supported.
  94. //    UserDefine -- The user defines an event handler for the ValidateData
  95. //                  event and writes their own code to perform the update.
  96. //
  97.  
  98. enum WQueryUpdatePolicy {
  99.     WQUPAuto,
  100.     WQUPDirect,
  101.     WQUPCursor,
  102.     WQUPUserDefine
  103. };
  104.  
  105. enum WQueryCursorType {
  106.     WQCTForwardOnly = SQL_CURSOR_FORWARD_ONLY,
  107.     WQCTKeysetDriven = SQL_CURSOR_KEYSET_DRIVEN,
  108.     WQCTDynamic = SQL_CURSOR_DYNAMIC,
  109.     WQCTStatic = SQL_CURSOR_STATIC
  110. };
  111.  
  112. enum WQueryConcurrencyLevel {
  113.     WQCLReadOnly = SQL_CONCUR_READ_ONLY,
  114.     WQCLLock = SQL_CONCUR_LOCK,
  115.     WQCLOptimisticByRowVer = SQL_CONCUR_ROWVER,
  116.     WQCLOptimisticByValues = SQL_CONCUR_VALUES
  117. };
  118.  
  119. enum WQueryParameterType {
  120.     WQPTInput = SQL_PARAM_INPUT,
  121.     WQPTInputOutput = SQL_PARAM_INPUT_OUTPUT,
  122.     WQPTOutput = SQL_PARAM_OUTPUT
  123. };
  124.  
  125. enum WQOption {
  126.  
  127.     // These are defined by ODBC
  128.  
  129.     WQOCursorType = SQL_CURSOR_TYPE,
  130.     WQORowsetSize = SQL_ROWSET_SIZE,
  131.     WQOMaxLength  = SQL_MAX_LENGTH,
  132.     WQOConcurrency = SQL_CONCURRENCY,
  133.     WQORetrieveData = SQL_RETRIEVE_DATA,
  134.     WQOUseBookmarks = SQL_USE_BOOKMARKS,
  135.     WQOKeysetSize = SQL_KEYSET_SIZE,
  136.     WQOMaxRows = SQL_MAX_ROWS,
  137.     WQOQueryTimeout = SQL_QUERY_TIMEOUT,
  138.  
  139.     // These are our own...
  140.  
  141.     WQOFirstNonODBC = 65536,
  142.  
  143.     WQOAutoPrepare,
  144.     WQOBindPolicy,
  145.     WQOBindLimit,
  146.     WQOAlwaysFetchOptions,
  147.     WQOAlwaysFetchRowPosition,
  148.     WQOAlwaysMoveCursor,
  149. };
  150.  
  151. enum WStmtCompare {
  152.     WSMLike = 0,
  153.     WSMNotLike,
  154.     WSMEqual,
  155.     WSMNotEqual,
  156.     WSMLessThan,
  157.     WSMGreaterThan,
  158.     WSMLessThanEqual,
  159.     WSMGreaterThanEqual,
  160. };
  161.  
  162. enum WStmtCondition {
  163.     WSNAnd = 0,
  164.     WSNOr,
  165. };
  166.  
  167. //
  168. // State information
  169. //
  170.  
  171. #define WQDRSTATE_OPENED       0x01
  172. #define WQDRSTATE_PREPARED     0x02
  173. #define WQDRSTATE_NOTFETCHED   0x04
  174. #define WQDRSTATE_NOTBOUND     0x08
  175. #define WQDRSTATE_NOTALLOCATED 0x10
  176. #define WQDRSTATE_NOTDATAOPEN  0x20
  177.  
  178. enum WODBCStmtHandle { NULLHSTMT = 0, LASTHSTMT = LAST_32BIT };
  179.  
  180. //
  181. // WICursorProxy
  182. //
  183.  
  184. class WQueryICursor;
  185.  
  186. class WCMCLASS WICursorProxyBase : public WReferenceObject {
  187.  
  188.     WDeclareSubclass( WICursorProxyBase, WReferenceObject );
  189.  
  190.     protected:
  191.         WICursorProxyBase( const WICursorProxyBase & ref );
  192.         WICursorProxyBase& operator=( const WICursorProxyBase & ref );
  193.  
  194.     protected:
  195.         WICursorProxyBase();
  196.  
  197.     public:
  198.         virtual ~WICursorProxyBase();
  199.  
  200.         virtual WBool DetachQuery( WQuery * ) = 0;
  201. };
  202.  
  203. //
  204. // WQuery -- Represents the results of a SQL statement.
  205. //
  206.  
  207. class WCMCLASS WQuery : public WDataSource {
  208.  
  209.     WDeclareSubclass( WQuery, WDataSource );
  210.  
  211.     public:
  212.  
  213.         WQuery();
  214.  
  215.         virtual ~WQuery();
  216.  
  217.  
  218.  
  219.         /***************************************************************
  220.          * Properties
  221.          ***************************************************************/
  222.  
  223.         // AlwaysFetchOptions
  224.         //
  225.         //    If TRUE, the query object always asks the database for
  226.         //    the state of a particular option.  If FALSE it uses the
  227.         //    value from its own cache.  If options are being set directly
  228.         //    by bypassing the query object you should set this to TRUE.
  229.         //    FALSE by default.
  230.  
  231.         virtual WBool GetAlwaysFetchOptions() const;
  232.         virtual WBool SetAlwaysFetchOptions( WBool always );
  233.  
  234.         // AlwaysFetchRowPosition
  235.         //
  236.         //    If TRUE, the query object always asks the database for
  237.         //    the current row position after each fetch.  Otherwise
  238.         //    the query object maintains its own count, which may not
  239.         //    be accurate if bookmarks are being used.  Because this
  240.         //    adds overhead, it is FALSE by default.  Also, not all
  241.         //    database drivers support this capability.
  242.  
  243.         virtual WBool GetAlwaysFetchRowPosition() const;
  244.         virtual WBool SetAlwaysFetchRowPosition( WBool always );
  245.  
  246.         // AlwaysMoveCursor
  247.         //
  248.         //    If TRUE, the query object always notifies the database
  249.         //    whenever the cursor is moved within the current rowset.
  250.         //    If FALSE, the database is only notified when necessary
  251.         //    (to get BLOB data, for example).  Default is FALSE.
  252.  
  253.         virtual WBool GetAlwaysMoveCursor() const;
  254.         virtual WBool SetAlwaysMoveCursor( WBool always );
  255.  
  256.         // AutoPrepare
  257.         //
  258.         //    If TRUE, the Prepare method will be called automatically
  259.         //    the first time a SQL statement is opened.
  260.  
  261.         virtual WBool GetAutoPrepare() const;
  262.         virtual WBool SetAutoPrepare( WBool on );
  263.  
  264.         // BindPolicy
  265.         //
  266.         //    The bind policy for default column binding.
  267.  
  268.         virtual WQueryBindPolicy GetBindPolicy() const;
  269.         virtual WBool            SetBindPolicy( WQueryBindPolicy policy );
  270.  
  271.         // BindLimit
  272.         //
  273.         //    The maximum size which a character or binary column can be
  274.         //    to be bindable.  A value of 0 means no limits.
  275.  
  276.         virtual WULong GetBindLimit() const;
  277.         virtual WBool  SetBindLimit( WULong limit );
  278.  
  279.         // ConcurrencyLevel
  280.         //
  281.         //    The concurrency level for the query. Can only be set
  282.         //    if the query is not open.  The default is read-only.
  283.  
  284.         virtual WQueryConcurrencyLevel GetConcurrencyLevel() const;
  285.         virtual WBool                  SetConcurrencyLevel( WQueryConcurrencyLevel l );
  286.  
  287.         // CurrentOffset
  288.         //
  289.         //    Returns the offset of the current row within the rowset
  290.         //    buffer, a value from 0 to RowsetSize-1.
  291.  
  292.         virtual WLong GetCurrentOffset() const;
  293.  
  294.         // CursorName
  295.         //
  296.         //    The name of the cursor.  If none is specified,
  297.         //    it is generated automatically.
  298.  
  299.         virtual WString GetCursorName() const;
  300.         virtual WBool   SetCursorName( const WString & str );
  301.  
  302.         // CursorType
  303.         //
  304.         //    Return the cursor type.
  305.  
  306.         virtual WQueryCursorType GetCursorType() const;
  307.         virtual WBool            SetCursorType( WQueryCursorType type );
  308.  
  309.         // DisplayErrorDialog
  310.         //
  311.         //    When an error occurs, display a dialog describing the
  312.         //    error.  TRUE by default.
  313.  
  314.         virtual WBool GetDisplayErrorDialog() const;
  315.         virtual WBool SetDisplayErrorDialog( WBool display );
  316.  
  317.         // DisplayWarningDialog
  318.         //
  319.         //    When a warning occurs, display a dialog describing the
  320.         //    warning.  FALSE by default.
  321.  
  322.         virtual WBool GetDisplayWarningDialog() const;
  323.         virtual WBool SetDisplayWarningDialog( WBool display );
  324.  
  325.         // DriverPacksRows
  326.         //
  327.         //    Set to true if the underlying query driver packs inserted and
  328.         //    deleted rows.
  329.  
  330.         virtual WBool GetDriverPacksRows() const;
  331.         virtual WBool SetDriverPacksRows( WBool packsRows );
  332.  
  333.         // ErrorList
  334.         //
  335.         //    Returns the list of errors from the last operation.
  336.  
  337.         virtual WDataErrorArray GetErrorList() const;
  338.  
  339.         // FetchedRows
  340.         //
  341.         //    Returns the number of rows that were actually fetched.
  342.         //    Can be 0 (none) up to RowsetSize.
  343.  
  344.         virtual WLong GetFetchedRows() const;
  345.  
  346.         // Handle
  347.         //
  348.         //    Returns a handle, which is driver-specific.  After a
  349.         //    valid Create, should be non-zero.  After a Destroy,
  350.         //    should be zero.
  351.  
  352.         virtual WDWord GetHandle() const;
  353.  
  354.         // KeysetSize
  355.         //
  356.         //    Determines the keyset size for keyset-driven cursors.
  357.         //    The default is 0, which means a fully keyset-driven
  358.         //    cursor, otherwise the cursor is mixed.  The keyset
  359.         //    size must be greater than the rowset size.
  360.  
  361.         virtual WLong GetKeysetSize() const;
  362.         virtual WBool SetKeysetSize( WLong size );
  363.  
  364.         // LongColumnBindSize
  365.         //
  366.         //    Sets the amount of memory to allocate for LONGVARCHAR
  367.         //    and LONGVARBINARY columns if a buffer size of 0 is
  368.         //    passed to BindColumn.  The default is 0, which means
  369.         //    that long columns are never bound.  Any other value is
  370.         //    the maximum amount of data that can be set or gotten
  371.         //    from the column, up to the BindLimit property.
  372.  
  373.         virtual WULong GetLongColumnBindSize() const;
  374.         virtual WBool  SetLongColumnBindSize( WULong size );
  375.  
  376.         // MaxLength
  377.         //
  378.         //    The maximum of binary or character data that can be
  379.         //    fetched in a single call.  The default value is 0,
  380.         //    which means return as much as possible.  The maximum
  381.         //    value for this property is 64K (=65536 bytes).  Note
  382.         //    that the MaxLength property affects the amount of
  383.         //    data returned by GetRawData.
  384.  
  385.         virtual WULong GetMaxLength() const;
  386.         virtual WBool  SetMaxLength( WULong maxLength );
  387.  
  388.         // MaxRows
  389.         //
  390.         //    The maximum number of rows to return in a result set.
  391.         //    If 0, all rows are returned.
  392.  
  393.         virtual WULong GetMaxRows() const;
  394.         virtual WBool  SetMaxRows( WULong maxRows );
  395.  
  396.         // Parameter
  397.         //
  398.         //    Defines a parameter value for use in parameterized
  399.         //    queries.  Setting a parameter will implicitly cause
  400.         //    the BindParameter method to be called.  Parameters
  401.         //    are numbered starting at 1.  Can optionally declare
  402.         //    whether the parameter should be input, input/output
  403.         //    or output only.  
  404.  
  405.         virtual WDataValue GetParameter( WShort paramNo ) const;
  406.         virtual WBool      SetParameter( WShort paramNo,
  407.                                          const WDataValue & val,
  408.                                          WColumnDataType sqlType=SQL_TYPE_NULL,
  409.                                          WQueryParameterType type=WQPTInput,
  410.                                          SDWORD maxSize=0 );
  411.  
  412.         // Prepared
  413.         //
  414.         //    Returns TRUE if the statement has been prepared for execution.
  415.  
  416.         virtual WBool GetPrepared() const;
  417.  
  418.         // QueryTimeout
  419.         //
  420.         //    Defines the time in seconds to wait for a statement
  421.         //    to execute.  The default is 0, which means wait
  422.         //    indefinitely.
  423.  
  424.         virtual WULong GetQueryTimeout() const;
  425.         virtual WBool  SetQueryTimeout( WULong seconds );
  426.  
  427.         // RetrieveData
  428.         //
  429.         //    If FALSE, no data is actually retrieved when a fetch
  430.         //    is done.  Use this to move around through the data
  431.         //    to get bookmarks, etc.  Default is TRUE.  Can only be
  432.         //    set at run time.
  433.  
  434.         virtual WBool GetRetrieveData() const;
  435.         virtual WBool SetRetrieveData( WBool ret );
  436.  
  437.         // RowsetSize
  438.         //
  439.         //    The maximum number of rows that are buffered locally by the
  440.         //    query object.  Setting the rowset size automatically
  441.         //    unbinds any bound columns.
  442.  
  443.         virtual WLong  GetRowsetSize() const;
  444.         virtual WBool  SetRowsetSize( WLong size );
  445.  
  446.         // RowsetStatus
  447.         //
  448.         //    Returns the status of a row in the current rowset.  Rows
  449.         //    are numbered from 1 to n (where n = GetRowsetSize() ).
  450.  
  451.         virtual UWORD GetRowsetStatus( WLong row=1 ) const;
  452.  
  453.         // SQL
  454.         //
  455.         //    Stores the SQL statement to be executed.  Setting a new
  456.         //    statement closes the current query (if open).
  457.  
  458.         virtual WString GetSQL() const;
  459.         virtual WBool   SetSQL( const WString & str );
  460.  
  461.         // State
  462.         //
  463.         //    Return the current state of the query.
  464.  
  465.         virtual WDWord GetState() const;
  466.  
  467.         // TraceToLog
  468.         //
  469.         //    In debug mode, if TRUE traces important actions
  470.         //    to the debug log.  Has no effect for release mode
  471.         //    applications.  (This is not the same as the ODBC
  472.         //    trace log.)
  473.  
  474.         virtual WBool GetTraceToLog() const;
  475.         virtual WBool SetTraceToLog( WBool on );
  476.  
  477.         // TransactionObject
  478.         //
  479.         //    The transaction object to use.
  480.  
  481.         virtual WTransaction *GetTransactionObject() const;
  482.         virtual WBool         SetTransactionObject( WTransaction *obj );
  483.  
  484.         // UpdatePolicy
  485.         //
  486.         //    The update policy for the type of action to take when
  487.         //    updating.
  488.  
  489.         virtual WQueryUpdatePolicy GetUpdatePolicy() const;
  490.         virtual WBool              SetUpdatePolicy( WQueryUpdatePolicy policy );
  491.  
  492.         // UseBookmarks
  493.         //
  494.         //    If TRUE, bookmarks can be used.  Must be set before
  495.         //    the cursor is opened.  Default is FALSE.
  496.  
  497.         virtual WBool GetUseBookmarks() const;
  498.         virtual WBool SetUseBookmarks( WBool use );
  499.  
  500.         // UseDefaultBindTypes
  501.         //
  502.         //    If TRUE, BindColumn is called with SQL_C_DEFAULT when
  503.         //    a column is bound by a data target.  If FALSE, the
  504.         //    type suggested by the data target is used instead.  This
  505.         //    controls who does the conversion between data types: the
  506.         //    database driver or the WDataValue class.  Calls to
  507.         //    BindColumn by the user are not affected.
  508.  
  509.         virtual WBool GetUseDefaultBindTypes() const;
  510.         virtual WBool SetUseDefaultBindTypes( WBool use );
  511.  
  512.         /***************************************************************
  513.          * Methods
  514.          ***************************************************************/
  515.  
  516.         // AddSearchParameter
  517.         //
  518.         //    Add a search parameter to the current query. The query must
  519.         //    be open if you want to specify a column index instead of a
  520.         //    column name.
  521.  
  522.         virtual WBool AddSearchParameter( const WString & columnName, WDataValue value,
  523.                       WStmtCondition=WSNAnd,WStmtCompare compare=WSMLike);
  524.         virtual WBool AddSearchParameter( WShort columnIndex, WDataValue value,
  525.                       WStmtCondition=WSNAnd,WStmtCompare compare=WSMLike);
  526.  
  527.         // BindColumn
  528.         //
  529.         //    Bind a column in the current query, which must be open.
  530.         //    By default it will allocate internal storage for the binding
  531.         //    based on the type of the column and the rowset size as
  532.         //    well as an array for storing the actual length of retrieved
  533.         //    data.  The user can provide alternates for any of these.
  534.  
  535.         virtual WBool BindColumn( WShort column, WNativeDataType type=SQL_C_DEFAULT,
  536.                                   void *arrayStart=NULL, SDWORD elementSize=0,
  537.                                   SDWORD *lengthArray=NULL );
  538.  
  539.         // BindParameter
  540.         //
  541.         //    Bind a parameter for execution with the next query.
  542.         //    In most cases you call SetParameter instead of this method,
  543.         //    and the binding will be done automatically for you.
  544.         //    This method provides low-level access to the binding
  545.         //    process.  Parameters start at 1.
  546.  
  547.         virtual WBool BindParameter( WShort paramNo, WQueryParameterType type,
  548.                                      WNativeDataType cType,
  549.                                      WColumnDataType sqlType,
  550.                                      UDWORD precision, SWORD scale,
  551.                                      void *dataBuffer, SDWORD maxSize,
  552.                                      SDWORD *actualLength );
  553.  
  554.         // BoundControlSearch
  555.         //    Opens a new result set given the search parameters from
  556.         //    changed bound controls.
  557.  
  558.         virtual WBool BoundControlSearch( WStmtCondition condition=WSNAnd,
  559.                                  WStmtCompare compare=WSMLike);
  560.         // Clone
  561.         //
  562.         //    Allocates and returns a "clone" of the query object.
  563.         //    The clone is a semi-independent query object needed
  564.         //    for use with complex OCX data binding.
  565.  
  566.         virtual WQuery *Clone();
  567.  
  568.         // Close
  569.         //
  570.         //    Close the current query, if any.
  571.  
  572.         virtual WBool Close( WBool discardResults=TRUE,
  573.                              WBool isRequery=FALSE );
  574.  
  575.         // Create
  576.         //
  577.         //    Calls SetTransactionObject and then checks to see if
  578.         //    the transaction object is ready for use.
  579.  
  580.         virtual WBool Create( WTransaction *trans );
  581.  
  582.         // DeleteSearchParameters
  583.         //
  584.         //    Deletes the search parameters added to the current query
  585.  
  586.         virtual WBool DeleteSearchParameters();
  587.  
  588.         // Destroy
  589.  
  590.         virtual WBool Destroy();
  591.  
  592.         // Execute
  593.         //
  594.         //    Execute a non-select SQL statement.  Closes the current
  595.         //    query, if any.  If an empty or null string is passed in, simply
  596.         //    executes the string in the SQL property.
  597.  
  598.         virtual WBool Execute( const WString & stmt=WString::GetNullString() );
  599.  
  600.         // Fetch
  601.         //
  602.         //    Fetch a rowset of data from the database.
  603.  
  604.         virtual WBool Fetch( WLong row, WBool notifyTargets=TRUE,
  605.                              WDSMoveType type=WDSMoveAbsolute,
  606.                              WBool triggerEvents=TRUE );
  607.  
  608.         // FetchBookmark
  609.         //
  610.         //    Fetch to a bookmark.
  611.  
  612.         WBool FetchBookmark( WDWord bookmark, WBool notify=TRUE,
  613.                              WBool triggerEvents=TRUE );
  614.  
  615.         // FetchErrors
  616.         //
  617.         //    Clear the current error list and fetch errors from the
  618.         //    driver for later retrieval with
  619.         //    GetErrorList.  Note that this function is called automatically
  620.         //    by most of the other methods, so you should only call it
  621.         //    after directly invoking an operation on the driver.
  622.         //    You pass in the return code and function code of the
  623.         //    last operation.  Returns TRUE if messages were fetched
  624.         //    from the driver.
  625.  
  626.         virtual WBool FetchErrors( WLong errorCode, WLong funcCode );
  627.  
  628.         // FetchFirst
  629.         //
  630.         //    Fetch to the first row.
  631.  
  632.         WBool FetchFirst( WBool notifyTargets=TRUE, WBool triggerEvents=TRUE );
  633.  
  634.         // FetchLast
  635.         //
  636.         //    Fetch to the last row.
  637.  
  638.         WBool FetchLast( WBool notifyTargets=TRUE, WBool triggerEvents=TRUE );
  639.  
  640.         // FetchNext
  641.         //
  642.         //    Fetch to the next row.
  643.  
  644.         WBool FetchNext( WBool notifyTargets=TRUE, WBool triggerEvents=TRUE );
  645.  
  646.         // FetchPrevious
  647.         //
  648.         //    Fetch to the previous row.
  649.  
  650.         WBool FetchPrevious( WBool notifyTargets=TRUE, WBool triggerEvents=TRUE );
  651.  
  652.         // FetchRelative
  653.         //
  654.         //    Fetch to a relative row.
  655.  
  656.         WBool FetchRelative( WLong offset, WBool notifyTargets=TRUE,
  657.                              WBool triggerEvents=TRUE );
  658.  
  659.         // FlushUnboundValues
  660.         //
  661.         //    Flushes the unbound value cache.  When data is fetched from
  662.         //    an unbound column, a copy is kept in memory.  This method
  663.         //    frees any copies currently in memory.  It is called implicitly
  664.         //    whenever a move occurs.
  665.  
  666.         virtual WBool FlushUnboundValues();
  667.  
  668.         // MarkColumnForUpdate
  669.         //
  670.         //    After entering add/edit mode, call this method before
  671.         //    calling Update if you wish to manually set the length
  672.         //    field of a bound column so that it will be updated.
  673.         //    Otherwise the length field is set to SQL_IGNORE unless
  674.         //    you call SetValue for that column.  Returns success.
  675.  
  676.         virtual WBool MarkColumnForUpdate( WShort column, WBool mark );
  677.  
  678.         // Open
  679.         //
  680.         //    Execute the SQL statement and open the result set for
  681.         //    processing.
  682.  
  683.         virtual WBool Open( WBool executeStatement=TRUE,
  684.                             WBool isRequery=FALSE );
  685.  
  686.         // Prepare
  687.         //
  688.         //    Prepare the SQL statement for execution.  Call this
  689.         //    if you intend to execute the same SQL statement multiple
  690.         //    times.  Closes any open query.
  691.  
  692.         virtual WBool Prepare();
  693.  
  694.         // QueryColumnBinding
  695.         //
  696.         //    Return information on how a column is bound.  Returns TRUE
  697.         //    if the column is bound, FALSE otherwise. Can optionally
  698.         //    get pointer to data area, element size, etc.
  699.  
  700.         virtual WBool QueryColumnBinding( WShort column,
  701.                                           WNativeDataType *boundAs=NULL,
  702.                                           void **arrayStart=NULL,
  703.                                           SDWORD *elementSize=NULL,
  704.                                           SDWORD **lengthArray=NULL );
  705.  
  706.         // Reference
  707.         //
  708.         //    Bump up the reference count.  Only useful for clones.
  709.         //    Returns the new reference count.
  710.  
  711.         virtual WLong Reference();
  712.  
  713.         // ResetSearch
  714.         //
  715.         //    Resets the search parameters. This is called before using
  716.         //    search.
  717.  
  718.         virtual WBool ResetSearch();
  719.  
  720.         // Resubmit
  721.         //
  722.         //    Re-executes the SQL statement that was last set using
  723.         //    the SQL property.  This is equivalent to calling Close
  724.         //    and then Open, but is a bit more efficient.
  725.  
  726.         virtual WBool Resubmit( WBool executeStatement=TRUE,
  727.                                 WBool closeCursor=TRUE );
  728.  
  729.         // Search
  730.         //
  731.         //    Opens a new result set given the current query and the added
  732.         //    search parameters. This closes the current query and opens
  733.         //    a new query based on the added search parameters.
  734.         //
  735.  
  736.         virtual WBool Search();
  737.  
  738.         // Search
  739.         //
  740.         //    This form of search is used if only one parameter is to be
  741.         //    added to the current query.  This closes the current query
  742.         //    and opens a new query based on the added parameter.
  743.         //
  744.         virtual WBool Search( WShort columnIndex, WDataValue value,
  745.                       WStmtCondition=WSNAnd,WStmtCompare compare=WSMLike);
  746.         virtual WBool Search( const WString & columnName, WDataValue value,
  747.                       WStmtCondition=WSNAnd,WStmtCompare compare=WSMLike);
  748.  
  749.         // UnbindColumn
  750.         //
  751.         //    Undo the binding of a column.  Pass a negative value
  752.         //    to unbind all bound columns.
  753.  
  754.         virtual WBool UnbindColumn( WShort column );
  755.  
  756.         // UnbindParameter
  757.         //
  758.         //    Undo the binding of a parameter.  Pass a negative value
  759.         //    to unbind all parameters.
  760.  
  761.         virtual WBool UnbindParameter( WShort paramNo );
  762.  
  763.         // Unreference
  764.         //
  765.         //    Decrements the reference count.  Only useful for clones.
  766.         //    Returns the new reference count.
  767.  
  768.         virtual WLong Unreference();
  769.  
  770.         /***************************************************************
  771.          * Item Properties
  772.          ***************************************************************/
  773.  
  774.         // NumericOption
  775.         //
  776.         //    Set/get a query option.
  777.  
  778.         virtual WLong GetNumericOption( WULong id, WBool *ok=NULL ) const;
  779.         virtual WBool SetNumericOption( WULong id, WLong value );
  780.  
  781.         // OptionID
  782.         //
  783.         //    Return the ID associated with an option string.  Can also
  784.         //    return whether the option is numeric or string.  A value of
  785.         //    zero means an invalid option.
  786.  
  787.         virtual WULong GetOptionID( const WString & str,
  788.                                     WBool *isString=NULL ) const;
  789.  
  790.         // StringOption
  791.         //
  792.         //    Set/get a query option.
  793.  
  794.         virtual WString GetStringOption( WULong id ) const;
  795.         virtual WBool   SetStringOption( WULong id, const WString & str );
  796.  
  797.         /***************************************************************
  798.          * Other
  799.          ***************************************************************/
  800.  
  801.         virtual WICursorProxyBase *GetICursorProxy() const;
  802.         virtual WBool              SetICursorProxy( WICursorProxyBase *p );
  803.  
  804.         /***************************************************************
  805.          * Overrides
  806.          ***************************************************************/
  807.  
  808.         WBool AddTarget( WDataTarget *target );
  809.  
  810.         WBool GetAutoEdit() const;
  811.         WBool SetAutoEdit( WBool autoEdit );
  812.  
  813.         WBool GetAutoRefresh() const;
  814.         WBool SetAutoRefresh( WBool autoRefresh );
  815.  
  816.         WBool GetBOF() const;
  817.  
  818.         WDWord GetBookmark() const;
  819.  
  820.         WShort GetColumnCount() const;
  821.  
  822.         const WDataColumn & GetColumn( WShort index ) const;
  823.         const WDataColumn & GetColumn( const WString & name ) const;
  824.  
  825.         WShort GetColumnIndex( const WString & str ) const;
  826.  
  827.         WLong GetCurrentRow() const;
  828.  
  829.         WDSEditMode GetEditMode() const;
  830.  
  831.         WBool GetEmpty() const;
  832.  
  833.         WBool GetEOF() const;
  834.  
  835.         WLong GetErrorCode( WLong *apiCode=NULL ) const;
  836.  
  837.         WBool GetForwardOnly() const;
  838.  
  839.         WBool GetNull() const;
  840.  
  841.         WBool GetOpened() const;
  842.  
  843.         WBool GetRawData( WShort index, WNativeDataType type,
  844.                           void *buffer, WLong bufferSize=0,
  845.                           WLong *bytesRemaining=NULL ) const;
  846.  
  847.         WBool GetReadOnly() const;
  848.  
  849.         WBool GetRowTargetChanged() const;
  850.         WBool SetRowTargetChanged( WBool changed );
  851.  
  852.         WBool GetRowChanged() const;
  853.         WBool SetRowChanged( WBool changed );
  854.  
  855.         WLong GetRowCount( WBool force=TRUE ) const;
  856.  
  857.         WBool GetTargetsEnabled() const;
  858.         WBool SetTargetsEnabled( WBool enabled );
  859.  
  860.         WBool GetAlwaysReadWriteTargets() const;
  861.         WBool SetAlwaysReadWriteTargets( WBool enabled );
  862.  
  863.         WBool GetThreadSafe() const;
  864.         WBool SetThreadSafe( WBool safe );
  865.  
  866.         WBool Add( WBool copyValues=FALSE, WBool append=FALSE,
  867.                    WBool copyIntoBuffer=FALSE );
  868.  
  869.         WBool CancelUpdate( WBool notifyTargets=TRUE );
  870.  
  871.         WBool ClearTargets();
  872.  
  873.         WBool Delete( WBool triggerEvent=TRUE, WBool notifyTargets=TRUE );
  874.  
  875.         WBool Edit();
  876.  
  877.         WBool MoreResults();
  878.  
  879.         WBool Move( WLong row, WBool notifyTargets=TRUE,
  880.                     WDSMoveType type=WDSMoveAbsolute, WBool trigger=TRUE );
  881.  
  882.         WBool Refresh();
  883.  
  884.         WBool RefreshTargets( WBool multiRow=FALSE );
  885.  
  886.         WBool RestoreState( const WDataSourceState state, WBool restore=TRUE );
  887.  
  888.         WBool SaveState( WDataSourceState & state );
  889.  
  890.         WBool SearchUsingTargets() { return BoundControlSearch(); }
  891.  
  892.         WBool ThreadLock( WBool wait=TRUE, WDWord timeout=0xFFFFFFFF );
  893.  
  894.         WBool ThreadUnlock();
  895.  
  896.         WBool Update( WBool triggerEvent=TRUE, WBool notifyTargets=TRUE );
  897.  
  898.         WDataValue GetValue( WShort index, WNativeDataType type=SQL_C_DEFAULT ) const;
  899.         WBool      SetValue( WShort index, const WDataValue & val );
  900.  
  901.         /***************************************************************
  902.          * Deprecated
  903.          ***************************************************************/
  904.  
  905.         virtual WBool GetErrorInfo( WString *errorMessage,
  906.                                     WString *state=NULL,
  907.                                     WLong *nativeErrorCode=NULL ) const;
  908.  
  909.         /***************************************************************
  910.          * Internal
  911.          ***************************************************************/
  912.  
  913.     public:
  914.  
  915.         virtual WBool CountRows( WBool ensureValid=TRUE );
  916.         virtual WBool CopySettingsToDriver( WBool assumeDefaults );
  917.         virtual WBool TransactionEvent( WEventID id, WEventData *data );
  918.         virtual WBool AddClone( WQuery *clone );
  919.         virtual WBool RemoveClone( WQuery *clone );
  920.  
  921.     protected:
  922.  
  923.         virtual WBool LateBindTarget( WQuery *query, WDataTarget *target );
  924.         virtual void  EventNotice( WEventID id, WEventNotice type );
  925.  
  926.         // These are called when the transaction object connects or
  927.         // disconnects from a database.  The Connect method gets called
  928.         // before the Connect event, the Disconnect event gets called
  929.         // before the method.
  930.  
  931.         virtual WBool Connect( WEventData *data );
  932.         virtual WBool Disconnect( WEventData *data );
  933.  
  934.         WTransaction  *_transaction;
  935.         WQuery        *_queryDriver;
  936. };
  937.  
  938. class WCMCLASS WQueryFactory : public WObject {
  939.  
  940.     protected:
  941.  
  942.         WQueryFactory();
  943.  
  944.         ~WQueryFactory();
  945.  
  946.     public:
  947.  
  948.         static WQueryFactory *GetFactoryObject();
  949.  
  950.         static WQuery *Allocate( const WString & dbmsName, WQuery *proxy );
  951.  
  952.         static void Register( WQuery * WCMDEF (*func)( const WString &, WQuery * ) );
  953.         static void Deregister( WQuery * WCMDEF (*func)( const WString &, WQuery * ) );
  954.  
  955.     protected:
  956.         wllist_header                list;
  957.  
  958.     private:
  959.         static WQueryFactory *_theObject;
  960. };
  961.  
  962. #endif
  963.