00001
00002
00003
00004
00005
00006
00007 #ifndef FBwBLOBH
00008 #define FBwBLOBH
00009 #include <string>
00010 #include <ibase.h>
00011
00012 namespace fbwrap {
00013
00014 #ifndef FBwDBH
00015 class FBwDb;
00016 class FBwTransaction;
00017 #endif
00018
00020 class FBwBlobDesc
00021 {
00022 FBwDb *db;
00023 ISC_BLOB_DESC bdesc;
00024 bool error;
00025 public:
00027
00030 FBwBlobDesc(FBwDb *pdb);
00031
00037 bool Lookup(string Table,string column,FBwTransaction *mtr);
00039 short Subtype();
00041 short Charset();
00043 short GetSegLen();
00045 bool Error()
00046 {
00047 return error;
00048 }
00049 };
00050
00053 class FBwBlob
00054 {
00055 FBwDb *db;
00056 ISC_QUAD *blob_id;
00057 isc_blob_handle bhnd;
00058 FBwBlobDesc bdesc;
00059 FBwTransaction *mtr;
00060 int nSegLen;
00061 int nSeg;
00062 int nSize;
00063 char *SegBuf;
00064 int bufCapacity;
00065 struct {
00066 bool opened:1;
00067 bool reading:1;
00068 bool writing:1;
00069 bool eof:1;
00070 bool error:1;
00071 } stat;
00072 void ClearStat()
00073 {
00074 stat.opened=false;
00075 stat.reading=false;
00076 stat.writing=false;
00077 stat.eof=true;
00078 stat.error=false;
00079 }
00080 bool NoInfoEnd(char p)
00081 {
00082 return p!= isc_info_end && p!= isc_info_truncated && p!= isc_info_error;
00083 }
00084 protected:
00086 void AllocSegBuf();
00088 void GetBlobInfo();
00089 public:
00091
00095 FBwBlob(FBwDb *pdb);
00097
00103 FBwBlob(FBwDb *pdb,string Tabla,string Columna);
00105 void WriteSegment(const char *buffer,int size);
00107 void Write(const string &value);
00109 int ReadSegment()
00110 {
00111 return ReadSegment(SegBuf,nSegLen);
00112 }
00114
00122 int ReadSegment(char *buffer,int seglen);
00124
00129 int Read(char *b, int len);
00131 int Size()
00132 {
00133 return nSize;
00134 }
00136 void SetDB(FBwDb *pdb)
00137 {
00138 if( IsOpened() )
00139 Close();
00140 db=pdb;
00141 }
00143
00146 bool Open(ISC_QUAD *pblob_id);
00148 bool Rewind()
00149 {
00150 if( stat.writing )
00151 return false;
00152 if( IsOpened() )
00153 Close();
00154 Open(blob_id);
00155 }
00157
00160 bool Create(ISC_QUAD *pblob_id);
00162 bool Close();
00164 bool Cancel();
00166 char *GetSegmentBuffer()
00167 {
00168 return SegBuf;
00169 }
00171 int GetSegmentLength()
00172 {
00173 return nSegLen;
00174 }
00176
00179 bool IsOpened()
00180 {
00181 return stat.opened;
00182 }
00184
00187 bool eof()
00188 {
00189 return stat.eof;
00190 }
00192
00195 ISC_QUAD *GetBlobId()
00196 {
00197 return blob_id;
00198 }
00200
00203 virtual ~FBwBlob();
00205
00208 bool Error()
00209 {
00210 return stat.error;
00211 }
00212 };
00213
00214 };
00215 #endif