home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1997 October
/
Chip_1997-10_cd.bin
/
tema
/
sybase
/
powerj
/
hpp.z
/
WDATAOBJ.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1996-09-20
|
14KB
|
491 lines
#ifndef _WDATAOBJ_HPP_INCLUDED
#define _WDATAOBJ_HPP_INCLUDED
//-----------------------------------------------------------------------
//
// Interfaces used to implement the binding of objects to data sources.
//
// These interfaces are meant to be embedded in other objects. All
// methods are virtual so that specializations can be created.
//
//-----------------------------------------------------------------------
#ifndef _WOBJECT_HPP_INCLUDED
#include "wobject.hpp"
#endif
#ifndef _WEVENT_HPP_INCLUDED
#include "wevent.hpp"
#endif
#ifndef _WBUFFER_HPP_INCLUDED
#include "wbuffer.hpp"
#endif
#ifndef _WSTRING_HPP_INCLUDED
#include "wstring.hpp"
#endif
// Since we use the same types as ODBC, we include the header file,
// even if these classes are not ODBC-specific. Note that if needed,
// the windows header file must be included before it.
#ifndef _WODBC_HPP_INCLUDED
#include "wodbc.hpp"
#endif
// Errors
#define WDV_NO_ERROR 0
#define WDV_ERROR_OUTOFMEMORY 1
#define WDV_ERROR_TRUNCATION 2
#define WDV_ERROR_NOVALUE 3
#define WDV_ERROR_CONVERSION 4
class WDataColumn;
class WDataColumnReference;
class WDataSource;
class WDataTarget;
class WDataValueReference;
class WDataOpenEventData;
class WDataCloseEventData;
class WDataAvailableEventData;
class WDataRequestEventData;
// Define the two kinds of types. WColumnDataType represents the
// SQL_* data types, whereas WNativeDataType represents the SQL_C_*
// data types. We define separate types so that it is obvious
// which is meant to be used.
typedef int WColumnDataType;
typedef int WNativeDataType;
//
// WDataValue -- Represents the value of an individual cell in
// the data source.
//
class WCMCLASS WDataValue : public WObject {
friend class WDataValueReference;
public:
WDataValue();
WDataValue( const WDataValue & val );
WDataValue( const WString & str );
WDataValue( const WBuffer & buf );
WDataValue( SDOUBLE s );
WDataValue( SDWORD s );
WDataValue( const WChar *str );
WDataValue( WDataValueReference *ref, WBool bumpRef );
virtual ~WDataValue();
WDataValue & operator=( const WDataValue & val );
/***************************************************************
* Methods
***************************************************************/
// Clear
//
// Remove any value.
WBool Clear();
// CopyInto
WBool CopyInto( const WDataValue & val );
// CopyOnWrite
void CopyOnWrite( WBool force );
// Create
WBool Create();
WBool Create( SDWORD s );
WBool Create( SDOUBLE s );
WBool Create( const WString & str );
WBool Create( const WBuffer & buf );
WBool Create( const WDataValue & val );
WBool Create( const WChar *str );
WBool Create( WDataValueReference *ref, WBool bumpRef );
/***************************************************************
* Properties
***************************************************************/
// ColumnType
//
// Returns the column type of the value. The column type
// is used to determine how comparisons are done.
WColumnDataType GetColumnType() const;
WBool SetColumnType( WColumnDataType t );
// Data
//
// Returns a pointer to the raw data inside the value. The
// actual pointer type depends on what GetType() returns.
const void *GetData() const;
// ErrorCode
WDWord GetErrorCode() const;
void SetErrorCode( WDWord errCode );
// Length
//
// The length of the data inside the buffer.
WULong GetLength() const;
WBool SetLength( WULong length );
// Null
//
// Returns TRUE if the value is a null value.
WBool GetNull() const { return !_ref; }
// Size
WULong GetSize() const;
WBool SetSize( WULong size );
// Type
//
// The current type of the value. Setting the type will
// do a conversion if possible.
WNativeDataType GetType() const;
WBool SetType( WNativeDataType type );
// Value
//
// Covers for some of the more specific conversion methods below.
// The concept of a 'value' property is convenient, but
// because of C++ overloading rules there is a certain
// loss of accuracy and possibility for ambiguity in choosing
// which function to use.
WBool GetValue( WString & str ) const;
WBool GetValue( SWORD & s ) const;
WBool GetValue( UWORD & u ) const;
WBool GetValue( SDWORD & s ) const;
WBool GetValue( UDWORD & u ) const;
WBool GetValue( SFLOAT & f ) const;
WBool GetValue( SDOUBLE & d ) const;
WBool GetValue( SCHAR & c ) const;
WBool GetValue( UCHAR & c ) const;
WBool GetValue( WBuffer & buf ) const;
WBool GetValue( DATE_STRUCT & d ) const;
WBool GetValue( TIME_STRUCT & t ) const;
WBool GetValue( TIMESTAMP_STRUCT & t ) const;
WBool SetValue( const WString s );
WBool SetValue( SWORD s );
WBool SetValue( UWORD u );
WBool SetValue( SDWORD s );
WBool SetValue( UDWORD u );
WBool SetValue( SFLOAT f );
WBool SetValue( SDOUBLE d );
WBool SetValue( SCHAR c );
WBool SetValue( UCHAR c );
WBool SetValue( const WBuffer & b );
WBool SetValue( const DATE_STRUCT & d );
WBool SetValue( const TIME_STRUCT & t );
WBool SetValue( const TIMESTAMP_STRUCT & t );
WString GetCHAR() const;
WBool GetCHAR( WString & string ) const;
WBool SetCHAR( const WString & string );
SWORD GetSSHORT() const;
WBool GetSSHORT( SWORD & s ) const;
WBool SetSSHORT( SWORD s );
UWORD GetUSHORT() const;
WBool GetUSHORT( UWORD & u ) const;
WBool SetUSHORT( UWORD u );
SDWORD GetSLONG() const;
WBool GetSLONG( SDWORD & s ) const;
WBool SetSLONG( SDWORD s );
UDWORD GetULONG() const;
WBool GetULONG( UDWORD & u ) const;
WBool SetULONG( UDWORD u );
SFLOAT WCMRETURNSFLOAT GetFLOAT() const;
WBool GetFLOAT( SFLOAT & f ) const;
WBool SetFLOAT( SFLOAT f );
SDOUBLE WCMRETURNSFLOAT GetDOUBLE() const;
WBool GetDOUBLE( SDOUBLE & d ) const;
WBool SetDOUBLE( SDOUBLE d );
UCHAR GetBIT() const;
WBool GetBIT( UCHAR & c ) const;
WBool SetBIT( UCHAR c );
SCHAR GetSTINYINT() const;
WBool GetSTINYINT( SCHAR & c ) const;
WBool SetSTINYINT( SCHAR c );
UCHAR GetUTINYINT() const;
WBool GetUTINYINT( UCHAR & c ) const;
WBool SetUTINYINT( UCHAR c );
WBuffer GetBINARY() const;
WBool GetBINARY( WBuffer & buf ) const;
WBool SetBINARY( const WBuffer & buf );
BOOKMARK GetBOOKMARK() const;
WBool GetBOOKMARK( BOOKMARK & mark ) const;
WBool SetBOOKMARK( BOOKMARK mark );
DATE_STRUCT GetDATE() const;
WBool GetDATE( DATE_STRUCT & d ) const;
WBool SetDATE( const DATE_STRUCT & d );
TIME_STRUCT GetTIME() const;
WBool GetTIME( TIME_STRUCT & t ) const;
WBool SetTIME( const TIME_STRUCT & t );
TIMESTAMP_STRUCT GetTIMESTAMP() const;
WBool GetTIMESTAMP( TIMESTAMP_STRUCT & t ) const;
WBool SetTIMESTAMP( const TIMESTAMP_STRUCT & t );
/***************************************************************
* Static Properties
***************************************************************/
static const WDataValue & GetNullValue();
/***************************************************************
* Operators
***************************************************************/
operator SDWORD() const;
operator UDWORD() const;
operator SDOUBLE() const;
int operator==( const WDataValue & val ) const;
int operator!=( const WDataValue & val ) const;
int operator>( const WDataValue & val ) const;
int operator<( const WDataValue & val ) const;
int operator>=( const WDataValue & val ) const;
int operator<=( const WDataValue & val ) const;
/***************************************************************
* Data Members
***************************************************************/
protected:
WDataValueReference *_ref;
WDWord _errorCode;
wllist_link _link;
};
//
// WDataColumn -- Defines the name, type, etc. of a particular column.
// Used mostly by the data source. Reference-counted
// so that we can safely and easily pass it around and
// also makes it easier to trap accesses to invalid
// columns (such as after a query has changed).
//
class WCMCLASS WDataColumn : public WObject {
friend class WDataColumnReference;
public:
WDataColumn();
WDataColumn( const WDataColumn & col );
virtual ~WDataColumn();
WDataColumn & operator=( const WDataColumn & col );
/*********************************************************
* Properties
*********************************************************/
// Bound
//
// Returns TRUE if the column has been successfully bound.
WBool GetBound() const;
// CaseSensitive
WBool GetCaseSensitive() const;
// DataSource
//
// The data source that created this column.
WDataSource *GetDataSource() const;
// DisplaySize
//
// The display size for the column.
WDWord GetDisplaySize() const;
// Index
//
// The number of the column from 1 to n. Returns a
// negative value if the column is no longer valid.
WShort GetIndex() const;
// Label
//
// The column label.
WString GetLabel() const;
// Length
//
// The column length.
WDWord GetLength() const;
// Name
//
// The column name.
WString GetName() const;
// NativeType
//
// Returns the default native type that best represents the
// actual database type.
WNativeDataType GetNativeType() const;
// Null
//
// Returns TRUE if the column is null (does not exist).
WBool GetNull() const { return !_ref; }
// Nullable
//
// If column accepts NULLs, returns SQL_NULLABLE, otherwise
// returns either SQL_NO_NULLS or SQL_NULLABLE_UNKNOWN.
WShort GetNullable() const;
// Owner
//
// The name of the column's table's owner, if known.
WString GetOwner() const;
// Precision
//
// The column precision.
WDWord GetPrecision() const;
// Qualifier
//
// The name of the column's table's qualifier, if known.
// See the transaction object as well.
WString GetQualifier() const;
// ReadOnly
//
// Returns TRUE if GetUpdatable() returns SQL_ATTR_READONLY.
WBool GetReadOnly() const;
// Scale
//
// The column scale.
WShort GetScale() const;
// Table
//
// The name of the column's table, if applicable.
WString GetTable() const;
// Type
//
// The column type. Types are expressed in SQL terms.
WColumnDataType GetType() const;
// Unsigned
//
// Whether or not the column is unsigned.
WBool GetUnsigned() const;
// Updatable
//
// If column is updatable, returns SQL_ATTR_WRITE, otherwise
// returns SQL_ATTR_READONLY or SQL_ATTR_READWRITE_UNKNOWN.
WShort GetUpdatable() const;
// Value
//
// Set or get the value of the column in the current row.
WDataValue GetValue() const;
WBool SetValue( const WDataValue & value );
/*********************************************************
* Methods
*********************************************************/
// Clear
//
// Prepare for re-use. Does not clear the actual column!
WBool Clear();
// Create
//
WBool Create();
WBool Create( WDataColumnReference *ref, WBool bumpRef );
WBool Create( const WDataColumn & col );
// QueryNumericAttribute
//
// Return the value of a numeric attribute.
WLong QueryNumericAttribute( WUShort attribute ) const;
// QueryStringAttribute
WString QueryStringAttribute( WUShort attribute ) const;
/***************************************************************
* Static Properties
***************************************************************/
static const WDataColumn & GetNullColumn();
protected:
/***************************************************************
* Data Members
***************************************************************/
WDataColumnReference *_ref;
};
#endif