00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _cpprecordset_h
00018 #define _cpprecordset_h
00019
00020 #include <spl/data/DataColumn.h>
00021 #include <spl/DateTime.h>
00022 #include <spl/Decimal.h>
00023 #include <spl/collection/Hashtable.h>
00024 #include <spl/IIterator.h>
00025 #include <spl/Memory.h>
00026 #include <spl/String.h>
00027 #include <spl/Variant.h>
00028 #include <spl/collection/Vector.h>
00029
00036 class IColumn : public IMemoryValidate
00037 {
00038 private:
00039 int m_currow;
00040
00041 protected:
00042 String m_name;
00043 int m_maxlen;
00044
00045 public:
00046 IColumn(const String& name, const int maxlen);
00047 virtual ~IColumn();
00048
00049 virtual IColumn *Clone() const = 0;
00050
00051 inline void BeginInter() { m_currow = -1; };
00052 inline bool Next() { if ( ++m_currow >= Count()) return false; return true; }
00053 inline void SeekRow(const int row) { if (row >= Count()) throw new InvalidArgumentException("EOF"); m_currow = row; }
00054 virtual int Count() const = 0;
00055
00056 virtual int Type() const = 0;
00057 inline const String &Name() const { return m_name; }
00058 inline int MaxLength() const { return m_maxlen; }
00059
00060 virtual void Append( int8 i ) = 0;
00061 virtual void Append( int16 i ) = 0;
00062 virtual void Append( int32 i ) = 0;
00063 virtual void Append( int64 i ) = 0;
00064 virtual void Append( Decimal i ) = 0;
00065 virtual void Append( float32 i ) = 0;
00066 virtual void Append( float64 i ) = 0;
00067 virtual void Append( bool i ) = 0;
00068 virtual void Append( DateTime i ) = 0;
00069 virtual void Append( Date i ) = 0;
00070 virtual void Append( const String& str ) = 0;
00071 virtual void AppendParse( const char *data, const int len) = 0;
00072 virtual void Append( void *data, int len ) = 0;
00073 virtual void Append( IColumn *col, const int row ) = 0;
00074 virtual void AppendNull() = 0;
00075
00076 inline int8 GetByte() { return GetByte(m_currow); }
00077 inline int16 GetInt16() { return GetInt16(m_currow); }
00078 inline int32 GetInt32() { return GetInt32(m_currow); }
00079 inline int64 GetInt64() { return GetInt64(m_currow); }
00080 inline Decimal GetDecimal() { return GetDecimal(m_currow); }
00081 inline float32 GetFloat32() { return GetFloat32(m_currow); }
00082 inline float64 GetFloat64() { return GetFloat64(m_currow); }
00083 inline bool GetBit() { return GetBit(m_currow); }
00084 inline DateTime GetTimeStamp() { return GetTimeStamp(m_currow); }
00085 inline Date GetDate() { return GetDate(m_currow); }
00086 inline DateTime GetDateTime() { return GetDateTime(m_currow); }
00087 inline StringPtr GetChar() { return GetChar(m_currow); }
00088 inline StringPtr GetVarchar() { return GetVarchar(m_currow); }
00089 inline Variant GetVariant() { return GetVariant(m_currow); }
00090
00091 virtual int8 GetByte(const int row) = 0;
00092 virtual int16 GetInt16(const int row) = 0;
00093 virtual int32 GetInt32(const int row) = 0;
00094 virtual int64 GetInt64(const int row) = 0;
00095 virtual Decimal GetDecimal(const int row) = 0;
00096 virtual float32 GetFloat32(const int row) = 0;
00097 virtual float64 GetFloat64(const int row) = 0;
00098 virtual bool GetBit(const int row) = 0;
00099 virtual DateTime GetTimeStamp(const int row) = 0;
00100 virtual Date GetDate(const int row) = 0;
00101 virtual DateTime GetDateTime(const int row) = 0;
00102 virtual StringPtr GetChar(const int row) = 0;
00103 virtual StringPtr GetVarchar(const int row) = 0;
00104 virtual Variant GetVariant(const int row) = 0;
00105
00106 #if defined(DEBUG)
00107 virtual void CheckMem() const;
00108 virtual void ValidateMem() const;
00109 #endif
00110 };
00111
00112 inline void ValidateType( IColumn *col )
00113 {
00114 if ( NULL != col )
00115 {
00116 ASSERT_PTR( col );
00117 col->ValidateMem();
00118 DEBUG_NOTE_MEM( col );
00119 col->CheckMem();
00120 }
00121 }
00122
00123 class RecordSet;
00124 typedef RefCountPtr<RecordSet> RecordSetPtr;
00125
00130 class RecordSet : public IMemoryValidate
00131 {
00132 protected:
00133 Hashtable<String, IColumn *> m_columnIdx;
00134 Vector<IColumn *> m_columns;
00135
00136 public:
00137 RecordSet();
00138 RecordSet(const RecordSet& rs);
00139 ~RecordSet();
00140
00141 RecordSet& operator =(const RecordSet& rs);
00142
00143 void SetCurrentRow(const int row);
00144 inline int RowCount() const { return (0 == m_columns.Count()) ? 0 : m_columns.ElementAt(0)->Count(); }
00145 void BeginIter();
00146 bool Next();
00147
00148 void Clear();
00149
00150 void DefineColumn(const String& name, int type, int fieldmaxlen);
00151 void SetColumns( RecordSet& rs );
00152 inline IColumn *GetColumn(const String& name) { return m_columnIdx.Get(String(name)); }
00153 inline IColumn *GetColumn(int idx) { return m_columns.ElementAt(idx); }
00154
00155 inline int ColumnCount() const { return m_columns.Count(); }
00156
00157 #if defined(DEBUG)
00158 virtual void CheckMem() const;
00159 virtual void ValidateMem() const;
00160 #endif
00161 };
00162
00165 #endif