00001 
00002 
00003 
00004 
00005 
00006 
00007 
00009 
00010 #ifndef __wx_dbi_record_h__
00011 #define __wx_dbi_record_h__
00012 
00013 
00014 #define WX_DBI_USE_BLOB 0
00015 
00016 #if _MSC_VER > 1000
00017 #pragma once
00018 #endif // _MSC_VER > 1000
00019 
00020 #include "wx/wx.h"
00021 
00022 #ifdef _MSC_VER
00023 #pragma warning (disable : 4786) // identifier was truncated to '255' characters in the browser information
00024 #endif // def _MSC_VER
00025 
00026 #include <map>
00027 #include <vector>
00028 
00029 #include <wx/variant.h>
00030 
00031 #include <wx/exception.h>
00032 
00033 namespace wx
00034 {
00035 
00036 namespace DBI
00037 {
00038 
00039 #if WX_DBI_USE_BLOB
00040 class BLOB;
00041 #endif // WX_DBI_USE_BLOB
00042 
00047 template<typename Type>
00048 class Record
00049   {
00050   public:
00051     virtual ~Record()
00052       {}
00053 
00054   
00055   public:
00056 #ifdef _MSC_VER
00057     
00058     long GetLong(Type typKey) const
00059       {
00060       wxVariant v;
00061       GetValue(typKey, v, TYPENAME_LONG);
00062       long n = v.GetLong();
00063       return n;
00064       }
00065 
00066     wxString GetString(Type typKey) const
00067       {
00068       wxVariant v;
00069       GetValue(typKey, v, TYPENAME_STRING);
00070       wxString s = v.GetString();
00071       return s;
00072       }
00073 
00074     double GetDouble(Type typKey) const
00075       {
00076       wxVariant v;
00077       GetValue(typKey, v, TYPENAME_DOUBLE);
00078       double d = v.GetDouble();
00079       return d;
00080       }
00081 #else
00082     long          GetLong(Type typKey) const;
00083     wxString      GetString(Type typKey) const;
00084 # if WX_DBI_USE_BLOB
00085     BLOB *        GetBLOB(Type typKey); 
00086 # endif // WX_DBI_USE_BLOB
00087     double        GetDouble(Type typKey) const;
00088 #endif // def _MSC_VER
00089 
00100     virtual void  GetValue
00101       (
00102       Type typKey,
00103       wxVariant& v,
00104       const wxString& sExpectedType
00105       ) const                                           = 0;
00106     virtual void  Dump()                                = 0;
00107 
00108   protected:
00109     void          DumpField(wxVariant& v);
00110   };
00111 
00115 class ArrayRecord :
00116   public Record<int>,
00117   public std::vector<wxVariant>
00118   {
00119   
00120   public:
00121     ~ArrayRecord();
00122 
00123   
00124   public:
00125 
00130     wxArrayString GetArrayString() const;
00131     
00132 
00133   
00134 
00135   
00136   public:
00139     void GetValue
00140       (
00141       int i,
00142       wxVariant& v,
00143       const wxString& sExpectedType = wxT("")
00144       ) const;
00145     void        Dump();
00146   };
00147 
00148 class HashRecord :
00149   public Record<const wxString&>,
00150   public std::map<wxString, wxVariant>
00151   {
00152   
00153 
00154   
00155   public:
00156     ~HashRecord();
00157 
00158   
00159   
00160   public:
00167     void GetValue
00168       (
00169       const wxString& sKey,
00170       wxVariant& v,
00171       const wxString& sExpectedType = wxT("")
00172       ) const;
00173     void        Dump();
00174   };
00175 
00176 template<class Type>
00177 class RecordArray : public std::vector<Type>
00178   {
00179   
00180   public:
00181     
00182     
00183     
00184     void Dump()
00185       {
00186       for(int i = 0; i < this->size(); i++)
00187         {
00188         wxLogDebug(wxT("Record %u"), i);
00189         this->at(i).Dump();
00190         }
00191       }
00192   };
00193 
00194 class ArrayRecordArray : public RecordArray<ArrayRecord>
00195   {
00196   };
00197 
00198 class HashRecordArray : public RecordArray<HashRecord>
00199   {
00200   };
00201 
00202 #if WX_DBI_USE_BLOB
00203 
00204 
00205 
00206 
00207 
00208 class BLOB : public wxObject
00209   {
00210   public:
00211     BLOB(const void * pvc, int nLengthNew);
00212     ~BLOB();
00213 
00214   public:
00215     const void *  GetPtr() const;
00216     int           GetLength() const;
00217     int           AddRef();
00218     int           Release();
00219 
00220   private:
00221     wxObject      poData; 
00222     int           nLength;
00223     
00224     
00225     void *        pv; 
00226     int           nRefCount;
00227   };
00228 #endif // WX_DBI_USE_BLOB
00229 
00230 } 
00231 
00232 } 
00233 
00234 #endif // ndef __wx_dbi_record_h__