home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1997 October
/
Chip_1997-10_cd.bin
/
tema
/
sybase
/
powerj
/
hpp.z
/
WTRANSAC.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1996-10-18
|
22KB
|
822 lines
/*************************************************************************
*
* WTransaction -- WClass Transaction object.
*
*************************************************************************/
#ifndef _WTRANSAC_HPP_INCLUDED
#define _WTRANSAC_HPP_INCLUDED
#ifndef _WDATAERR_HPP_INCLUDED
#include "wdataerr.hpp"
#endif
#ifndef _WDATAOBJ_HPP_INCLUDED
#include "wdataobj.hpp"
#endif
#ifndef _WVECTOR_HPP_INCLUDED
#include "wvector.hpp"
#endif
#ifndef _WQUERY_HPP_INCLUDED
#include "wquery.hpp"
#endif
extern template WVector<WQuery>;
//
// Bytes used to hold messages
//
#define WT_STATE_LEN 6
#define WT_ERRORMESSAGE_LEN 2048
#define WT_CONNSTR_LEN 1024
#define WT_DSNAME_LEN 256
#define WT_DSDESC_LEN 1024
#define WT_OPTION_VALUE_LEN 512
//
// Flags used with the List method
//
#define WTF_INDEX_UNIQUE 0x00000001
#define WTF_ENSURE_VALIDITY 0x00000002
//
// WTListType
//
// Standard list types returned by the List method
//
enum WTListType {
WTLColumnPrivileges = 1,
WTLColumns,
WTLForeignKeys,
WTLIndexes,
WTLPrimaryKeys,
WTLProcedureColumns,
WTLProcedures,
WTLTablePrivileges,
WTLTables,
WTLLASTLISTTYPE = LAST_32BIT
};
//
// WTOptionID
//
// Standard option ids for use with Get*Option and Set*Option.
// Values match those for the corresponding ODBC connection options for
// convenience.
//
enum WTOptionID {
WTONULLOPTION = 0,
WTOAccessMode = SQL_ACCESS_MODE,
WTOAutoCommit = SQL_AUTOCOMMIT,
WTOCurrentQualifier = SQL_CURRENT_QUALIFIER,
WTOIsolationLevel = SQL_TXN_ISOLATION,
WTOLoginTimeout = SQL_LOGIN_TIMEOUT,
WTOODBCCursors = SQL_ODBC_CURSORS,
WTOPacketSize = SQL_PACKET_SIZE,
WTOQuietMode = SQL_QUIET_MODE,
WTOTrace = SQL_OPT_TRACE,
WTOTraceFile = SQL_OPT_TRACEFILE,
WTOTranslateDll = SQL_TRANSLATE_DLL,
WTOTranslateOption = SQL_TRANSLATE_OPTION,
WTOCursorDriver = SQL_ODBC_CURSORS,
WTOLASTSTANDARDOPTION = SQL_CONNECT_OPT_DRVR_START - 1,
WTOLASTOPTION = LAST_32BIT
};
//
// WTOptionInfo
//
// Hold information about an option -- used to implement GetOptionInfo.
//
struct WTOptionInfo {
WTOptionID id;
const WChar * name;
WBool isString; // isNumeric otherwise
};
//
// Possible property values.
//
// These match ODBC for convenience.
//
//
// WTAccessMode
//
enum WTAccessMode {
WTAMUnknown = -1,
WTAMReadOnly = SQL_MODE_READ_ONLY,
WTAMReadWrite = SQL_MODE_READ_WRITE
};
//
// WTBookmarkPersistence
//
typedef WDWord WTBookmarkPersistence;
#define WTBPUnknown 0x80000000
#define WTBPClose SQL_BP_CLOSE
#define WTBPDelete SQL_BP_DELETE
#define WTBPDrop SQL_BP_DROP
#define WTBPScroll SQL_BP_SCROLL
#define WTBPTransaction SQL_BP_TRANSACTION
#define WTBPUpdate SQL_BP_UPDATE
#define WTBPOtherStatement SQL_BP_OTHER_HSTMT
//
// WTFetchDirection
//
typedef WDWord WTFetchDirection;
#define WTFDUnknown 0x80000000
#define WTFDNext SQL_FD_FETCH_NEXT
#define WTFDFirst SQL_FD_FETCH_FIRST
#define WTFDLast SQL_FD_FETCH_LAST
#define WTFDPrevious SQL_FD_FETCH_PRIOR
#define WTFDAbsolute SQL_FD_FETCH_ABSOLUTE
#define WTFDRelative SQL_FD_FETCH_RELATIVE
#define WTFDBookmark SQL_FD_FETCH_BOOKMARK
//
// WTIsolationLevel
//
enum WTIsolationLevel {
WTILUnknown = 0xFFFFFFFF,
WTILReadUncommitted = SQL_TXN_READ_UNCOMMITTED,
WTILReadCommitted = SQL_TXN_READ_COMMITTED,
WTILRepeatableRead = SQL_TXN_REPEATABLE_READ,
WTILSerializable = SQL_TXN_SERIALIZABLE,
WTILVersioning = SQL_TXN_VERSIONING
};
//
// WTLoginPrompt
//
enum WTLoginPrompt {
WTLPAlways = SQL_DRIVER_PROMPT,
WTLPIfRequired = SQL_DRIVER_COMPLETE_REQUIRED,
WTLPNever = SQL_DRIVER_NOPROMPT
};
//
// WTStaticSensitivity
//
typedef WDWord WTStaticSensitivity;
#define WTSSUnknown 0x80000000
#define WTSSAdditions SQL_SS_ADDITIONS
#define WTSSDeletions SQL_SS_DELETIONS
#define WTSSUpdates SQL_SS_UPDATES
//
// WTCursorTypes
//
typedef WDWord WTCursorTypes;
#define WTCTForwardOnly SQL_SO_FORWARD_ONLY
#define WTCTStatic SQL_SO_STATIC
#define WTCTKeysetDriven SQL_SO_KEYSET_DRIVEN
#define WTCTDynamic SQL_SO_DYNAMIC
#define WTCTMixed SQL_SO_MIXED
//
// WTUpdateTypes
//
typedef WDWord WTUpdateTypes;
//
// bitmask for supported update types.
//
#define WTUTNone 0x01
#define WTUTDirect 0x02
#define WTUTCursor 0x04
#define WTUTKey 0x08
//
// WTCursorDriver
//
enum WTCursorDriver {
WTCDSimulateIfNeeded = SQL_CUR_USE_IF_NEEDED,
WTCDSimulate = SQL_CUR_USE_ODBC,
WTCDNative = SQL_CUR_USE_DRIVER
};
//
// WTQualifierLocation
//
enum WTQualifierLocation {
WTQLStart = SQL_QL_START,
WTQLEnd = SQL_QL_END
};
//
// WTFileUsage
//
enum WTFileUsage {
WTFUNotSupported = SQL_FILE_NOT_SUPPORTED,
WTFUTable = SQL_FILE_TABLE,
WTFUQualifier = SQL_FILE_QUALIFIER,
};
//
// WTCursorCommitBehaviour, WTCursorRollbackBehaviour values
//
#define WTCBUnknown -1
#define WTCBDelete SQL_CB_DELETE
#define WTCBClose SQL_CB_CLOSE
#define WTCBPreserve SQL_CB_PRESERVE
//
// WTCursorRollbackBehaviour
//
typedef WShort WTCursorCommitBehavior;
typedef WShort WTCursorRollbackBehavior;
//
// ListSource
//
// Used with the List* methods to specify a table, column, procedure, ...
//
class WCMCLASS WTListSource {
public:
WTListSource();
~WTListSource();
WString qualifier;
WString owner;
WString name;
WString column;
WString type; // TABLE, VIEW, PROCEDURE, etc.
};
//
// WTransaction
//
class WCMCLASS WTransaction : public WObject {
WDeclareSubclass( WTransaction, WObject );
public:
WTransaction();
virtual ~WTransaction();
/***************************************************************
* Properties
***************************************************************/
// AccessMode
//
// Set the access mode for the connection. Read/write by
// default.
virtual WTAccessMode GetAccessMode() const;
virtual WBool SetAccessMode( WTAccessMode accessMode );
// AutoCommit
//
// Controls whether operations on the database are
// committed automatically.
virtual WBool GetAutoCommit() const;
virtual WBool SetAutoCommit( WBool autoCommit );
// BookmarkPersistence
//
// Returns a set of flags describing the bookmark
// persistence.
virtual WTBookmarkPersistence GetBookmarkPersistence() const;
// Connected
//
// Returns TRUE if a connection is active.
virtual WBool GetConnected() const;
// ConnectionHandle
//
// ConnectionHandle is a read-only property.
virtual WDWord GetConnectionHandle() const;
// ConnectParams
//
// Database-specific string used when connecting.
virtual WString GetConnectParams() const;
virtual WBool SetConnectParams( const WString & connectParams );
// CursorDriver
//
// Determines if cursor scrolling should be simulated
// or whether the native driver should be used. The
// default is to use the native driver.
virtual WTCursorDriver GetCursorDriver() const;
virtual WBool SetCursorDriver( WTCursorDriver driv );
// DataSource
//
// Identifies the database to use.
virtual WString GetDataSource() const;
virtual WBool SetDataSource( const WString & dataSource );
// DBMSName
//
// Identifies the type of database interface to use. The
// default is "ODBC".
virtual WString GetDBMSName() const;
virtual WBool SetDBMSName( const WString & dbmsName );
// DisplayErrorDialog
//
// When an error occurs, display a dialog describing the
// error. TRUE by default.
virtual WBool GetDisplayErrorDialog() const;
virtual WBool SetDisplayErrorDialog( WBool display );
// DisplayWarningDialog
//
// When a warning occurs, display a dialog describing the
// warning. FALSE by default.
virtual WBool GetDisplayWarningDialog() const;
virtual WBool SetDisplayWarningDialog( WBool display );
// Driver
//
// Return a pointer to the underlying WTransaction subclass.
virtual WTransaction *GetDriver() const;
// EnvironmentHandle
//
// EnvironmentHandle is a read-only property.
virtual WDWord GetEnvironmentHandle() const;
// ErrorCode
//
// Returns the error code of the last driver operation.
// Can optionally return a code specifying which driver
// API was called (driver-specific).
virtual WLong GetErrorCode( WLong *apiFunc = NULL ) const;
// ErrorList
//
// Returns the list of errors from the last operation.
virtual WDataErrorArray GetErrorList() const;
// FetchDirection
//
// Returns which fetch operations are supported by the
// database. Read-only.
virtual WTFetchDirection GetFetchDirection() const;
// FileUsage
//
// Determines how files are treated (as databases or tables).
virtual WTFileUsage GetFileUsage() const;
// IsolationLevel
//
//
virtual WTIsolationLevel GetIsolationLevel() const;
virtual WBool SetIsolationLevel( WTIsolationLevel level );
// LoginID
//
// The login ID for the server (optional).
virtual WString GetLoginID() const;
virtual WBool SetLoginID( const WString & lid );
// LoginPassword
//
// The login password for the server (optional).
virtual WString GetLoginPassword() const;
virtual WBool SetLoginPassword( const WString & pwd );
// LoginPrompt
//
//
virtual WTLoginPrompt GetLoginPrompt() const;
virtual WBool SetLoginPrompt( WTLoginPrompt prompt );
// MaxOptionIndex
//
// Index of the last option (largest index value that may be passed
// to GetOptionInfo).
virtual WLong GetMaxOptionIndex() const;
// NumericOption
//
//
virtual WLong GetNumericOption( WTOptionID id ) const;
virtual WBool SetNumericOption( WTOptionID id, const WLong value );
// Password
//
//
virtual WString GetPassword() const;
virtual WBool SetPassword( const WString & password );
// ServerName
//
// The name of the server (optional).
virtual WString GetServerName() const;
virtual WBool SetServerName( const WString & server );
// QualifierLocation
//
// The location of the qualifier in a fully qualified table
// name.
virtual WTQualifierLocation GetQualifierLocation() const;
// QualifierSeparator
//
// The string that separates the qualifier from the rest
// of the table name.
virtual WString GetQualifierSeparator() const;
// StaticSensitivity
//
// Returns whether static or keyset cursors know about changes
// made by the current user.
virtual WTStaticSensitivity GetStaticSensitivity() const;
// StringOption
//
//
virtual WString GetStringOption( WTOptionID id ) const;
virtual WBool SetStringOption( WTOptionID id, const WString & value );
// SupportedCursorTypes
//
// Returns a mask of supported cursor types.
virtual WTCursorTypes GetSupportedCursorTypes() const;
// SupportedUpdateTypes
//
// Returns a mask of supported update types.
virtual WTUpdateTypes GetSupportedUpdateTypes() const;
// SupportsBookmarks
//
// Returns TRUE if the database supports bookmarks. Read-only.
WBool GetSupportsBookmarks() const;
// TraceToLog
//
// In debug mode, if TRUE traces important actions
// to the debug log. Has no effect for release mode
// applications. (This is not the same as the ODBC
// trace log.)
virtual WBool GetTraceToLog() const;
virtual WBool SetTraceToLog( WBool on );
// Userid
//
//
virtual WString GetUserid() const;
virtual WBool SetUserid( const WString & userid );
// CursorCommitBehavior
//
// Returns how a COMMIT operation affects cursors and prepared
// statements in the data source.
//
virtual WTCursorCommitBehavior GetCursorCommitBehavior() const;
// CursorRollbackBehavior
//
// Returns how a ROLLBACK operation affects cursors and prepared
// statements in the data source.
//
virtual WTCursorRollbackBehavior GetCursorRollbackBehavior() const;
/***************************************************************
* Methods
***************************************************************/
// Commit
//
//
virtual WBool Commit();
// Connect
//
//
virtual WBool Connect( WWindow *parent = NULL );
// Create
//
//
virtual WBool Create();
virtual WBool Create( const WString & dbmsName );
// Destroy
//
//
virtual WBool Destroy();
// Disconnect
//
//
virtual WBool Disconnect();
// FetchErrors
//
// Clear the current error list and fetch errors from the
// driver for later retrieval with
// GetErrorList. Note that this function is called automatically
// by most of the other methods, so you should only call it
// after directly invoking an operation on the driver.
// You pass in the return code and function code of the
// last operation. Returns TRUE if messages were fetched
// from the driver.
virtual WBool FetchErrors( WLong errorCode, WLong funcCode );
// List
//
// Pass NULL for parameters that are not required.
virtual WBool List( WQuery & query, WTListType type,
const WTListSource *source,
const WTListSource *source2 = NULL,
WDWord flags = WTF_ENSURE_VALIDITY );
// ListColumnPrivileges
//
//
WBool ListColumnPrivileges( WQuery & query,
const WString & qualifier,
const WString & owner,
const WString & name,
const WString & column );
// ListColumns
//
//
WBool ListColumns( WQuery & query,
const WString & qualifier,
const WString & owner,
const WString & name,
const WString & column );
// ListForeignKeys
//
//
WBool ListForeignKeys( WQuery & query,
const WString & primaryQualifier,
const WString & primaryOwner,
const WString & primaryName,
const WString & foreignQualifier,
const WString & foreignOwner,
const WString & foreignName );
// ListIndexes
//
//
WBool ListIndexes( WQuery & query,
const WString & qualifier,
const WString & owner,
const WString & name,
WBool uniqueOnly = FALSE,
WBool ensureValidity = TRUE );
// ListPrimaryKeys
//
//
WBool ListPrimaryKeys( WQuery & query,
const WString & qualifier,
const WString & owner,
const WString & name );
// ListProcedureColumns
//
//
WBool ListProcedureColumns( WQuery & query,
const WString & qualifier,
const WString & owner,
const WString & name,
const WString & column );
// ListProcedures
//
//
WBool ListProcedures( WQuery & query,
const WString & qualifier,
const WString & owner,
const WString & name );
// ListTablePrivileges
//
//
WBool ListTablePrivileges( WQuery & query,
const WString & qualifier,
const WString & owner,
const WString & name );
// ListTables
//
//
WBool ListTables( WQuery & query,
const WString & qualifier,
const WString & owner,
const WString & name,
const WString & type );
// Rollback
//
//
virtual WBool Rollback();
/***************************************************************
* Item Properties
***************************************************************/
// DataSourceInfo
//
//
virtual WBool GetDataSourceInfo( WString *name, WString *description,
WBool getFirst = FALSE ) const;
// OptionInfo
//
//
virtual WBool GetOptionInfo( WTOptionID & id, WString & name,
WBool *isString = NULL,
WLong index = -1 ) const;
/***************************************************************
* Query object interface functions
***************************************************************/
// AddQuery
//
//
virtual WBool AddQuery( WQuery *query );
// RemoveQuery
//
//
virtual WBool RemoveQuery( WQuery *query );
// RemoveAllQueries
//
// Calls SetTransactionObject(NULL) on each query object.
virtual WBool RemoveAllQueries();
// NotifyQueries
//
//
virtual WBool NotifyQueries( WEventID id, WEventData *data=NULL );
/****************************************************************
* Deprecated
****************************************************************/
virtual WBool GetErrorInfo( WString *errorMessage,
WString *state = NULL,
WLong *nativeErrorCode = NULL ) const;
/****************************************************************
* Internal
****************************************************************/
private:
// AllocateTransaction
//
//
WBool AllocateTransaction();
protected:
WVector<WQuery> _queries; // attached WQuery objects
WTransaction * _trans; // transaction driver
WString _dbmsName;
WBool _traceToLog;
WULong _traceLevel;
#ifdef _DEBUG
class WCMCLASS TTrace {
public:
TTrace( const WTransaction *, const WChar * );
~TTrace();
const WTransaction *transaction;
const WChar *function;
};
friend class TTrace;
void TDbg( const TTrace *q, const WChar *format, ... ) const;
#endif
};
class WCMCLASS WTransactionFactory : public WObject {
protected:
WTransactionFactory();
~WTransactionFactory();
public:
static WTransactionFactory *GetFactoryObject();
static WTransaction *Allocate( const WString & dbmsName, WTransaction *proxy );
static void Register( WTransaction * WCMDEF (*func)( const WString &, WTransaction * ) );
static void Deregister( WTransaction * WCMDEF (*func)( const WString &, WTransaction * ) );
protected:
wllist_header list;
private:
static WTransactionFactory *_theObject;
};
#endif