//---------------------- CSPODBCField.h -----------------------

//*************************************************************
//*****       Copyright ©2002 - 2004 Micronovae Ltd       *****
//*****                All rights reserved                *****
//*************************************************************


#ifndef _CSPODBCFIELD
#define _CSPODBCFIELD

#include "CSPConf.h"
#include "CSPLib.h"
#include "CSPString.h"
#include "CSPWString.h"
#include "CSPTime.h"
#include "CSPVariant.h"
#include <sql.h>
#include <sqlext.h>

//#pragma warning ( disable : 4251 )

class CSPODBC_CLASS_EXPORT CSPODBCField : public CSPVariant
{
	friend class CSPODBCRecordset;
	public:
		CSPODBCField();
		virtual ~CSPODBCField();

		CSPODBCField& operator =(const CSPODBCField& fField);

		unsigned long GetFieldType() const;
		const CSPString& GetName() const;
		unsigned long GetSize() const;
		bool IsNull() const;
		bool IsNullable() const;

		CSPODBCField& operator = ( const CSPVariant& varVariant );
		CSPODBCField& operator = ( const CSPVarArray& VarArray );
		CSPODBCField& operator = ( const CSPString& strString );
		CSPODBCField& operator = ( const char* strString );
		CSPODBCField& operator = ( const CSPWString& wstrString );
		CSPODBCField& operator = ( const wchar_t* wstrString );
		CSPODBCField& operator = ( const CSPTime& tTime );
		CSPODBCField& operator = ( const CSPDate& dDate );		
		CSPODBCField& operator = ( const CSPDateTime& dtDateTime );
		CSPODBCField& operator = ( unsigned long ulULongVal );
		CSPODBCField& operator = ( long lLongVal );
		CSPODBCField& operator = ( unsigned int uiUIntVal );
		CSPODBCField& operator = ( int iIntVal );
		CSPODBCField& operator = ( unsigned __int64 ui64UIntVal );
		CSPODBCField& operator = ( __int64 i64IntVal );
		CSPODBCField& operator = ( unsigned short ushUShortVal );
		CSPODBCField& operator = ( short shShortVal );
		CSPODBCField& operator = ( unsigned char uchUCharVal );
		CSPODBCField& operator = ( char chCharVal );
		CSPODBCField& operator = ( bool bBoolVal );
		CSPODBCField& operator = ( long double ldblLDoubleVal );
		CSPODBCField& operator = ( double dblDoubleVal );
		CSPODBCField& operator = ( float fFloatVal );

	protected:

		unsigned long ulType;
		CSPScalarArray<char> pData;
		unsigned long ulSize;
		unsigned long ulRows;
		unsigned long ulRowOffset;
		CSPString strName;
		CSPScalarArray<long> plContentSize;
		bool bOriginal;
		unsigned long ulRowIndex;
		bool bNullable;

		void SetSize(unsigned long ulNewSize, unsigned long ulNewRows = 1);
		void SetType(unsigned long ulNewType);
		bool PointToRow(unsigned long ulRow);
		bool SetValue();
		bool SetValueBack();
		
	private:
		CSPODBCField(const CSPODBCField& fField);	
};

typedef CSPODBCField CSPField;

#endif
