StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StDbBuffer.h
1 /***************************************************************************
2  *
3  * $Id: StDbBuffer.h,v 1.10 2015/05/21 19:46:53 dmitry Exp $
4  *
5  * Author: Laurent Conin
6  ***************************************************************************
7  *
8  * Description: Buffer that negotiates data I/O between mysql database
9  *
10  ***************************************************************************
11  *
12  * $Log: StDbBuffer.h,v $
13  * Revision 1.10 2015/05/21 19:46:53 dmitry
14  * fixed - unused internal pseudotype access considered as array out of bounds access
15  *
16  * Revision 1.9 2004/01/15 00:02:25 fisyak
17  * Replace ostringstream => StString, add option for alpha
18  *
19  * Revision 1.8 2003/04/11 22:47:36 porter
20  * Added a fast multi-row write model specifically needed by the daqEventTag
21  * writer. Speed increased from about 100Hz to ~3000Hz. It is only invoked if
22  * the table is marked as Non-Indexed (daqTags & scalers). For non-indexed tables
23  * which include binary stored data (we don't have any yet), the fast writer has
24  * to invoke a slower buffer so that the rates are a bit slower (~500Hz at 50 rows/insert).
25  *
26  * Revision 1.7 2001/10/26 20:59:46 porter
27  * fixed new endtime flag from previous checkin. made StDataBaseI available
28  * at root-cli.
29  *
30  * Revision 1.6 2001/10/24 04:05:19 porter
31  * added long long type to I/O and got rid of obsolete dataIndex table
32  *
33  * Revision 1.5 2000/01/27 05:54:33 porter
34  * Updated for compiling on CC5 + HPUX-aCC + KCC (when flags are reset)
35  * Fixed reConnect()+transaction model mismatch
36  * added some in-code comments
37  *
38  * Revision 1.4 1999/10/19 14:30:37 porter
39  * modifications relevant to use with StDbBroker and future merging with
40  * "params" database structure + some docs + suppressing diagnostics messages
41  *
42  * Revision 1.3 1999/09/30 02:06:01 porter
43  * add StDbTime to better handle timestamps, modify SQL content (mysqlAccessor)
44  * allow multiple rows (StDbTable), & Added the comment sections at top of
45  * each header and src file
46  *
47  **************************************************************************/
48 #ifndef STDBBUFFER_H
49 #define STDBBUFFER_H
50 #ifndef __CINT__
51 #include "mysql.h"
52 #include "mysql_com.h"
53 #endif
54 
55 #include "StDbBufferI.h"
56 
57 enum myctype{_char,_uchar,_short,_ushort,_int,_uint,_long,_ulong,_longlong,_float,_double,_ascii,_string};
58 
59 const int mycsize[]={sizeof(char),sizeof(unsigned char),sizeof(short),sizeof(unsigned short),sizeof(int),sizeof(unsigned int),sizeof(long),sizeof(unsigned long),sizeof(long long),sizeof(float),sizeof(double),sizeof(char*),sizeof(char*)};
60 
61 #if defined(__sun) && !defined(__i386) || defined(__hpux) || defined(__alpha) && !defined(linux)
62 const int mycswapl[]={1,1,1,1,4,4,4,4,8,4,8,1,1}; // same swapping than Solaris
63 #else
64 const int mycswapl[]={1,1,1,1,1,1,1,1,1,1,1,1,1};
65 #endif
66 
67 struct column {
68  char* name;
69  enum myctype type;
70  char *val;
71  unsigned length; };
72 
73 enum BuffMode{Auto,Client,Storage};
74 
75 class StDbBuffer : public StDbBufferI {
76 
77 
78 private:
79 
80  int mMax;
81  int mCur;
82  int mLast;
83  column *mCol;
84  BuffMode mMode;
85 
86  void zeroColumn(int istart, int iend);
87 
88 public:
89 
90  StDbBuffer(){
91  mCur=0;
92  mLast=-1;
93  mMax=100;
94  mCol= new column[mMax+1];
95  zeroColumn(0,mMax);
96  mMode=Storage;
97  };
98 
99  StDbBuffer(unsigned int anum_fields, column *acol){
100  Init( anum_fields,acol);}
101 
102  void Init(unsigned int anum_fields, column * acol){
103  mCur=0;
104  mLast=anum_fields;
105  mCol=acol;};
106 
107  ~StDbBuffer(){Raz();delete [] mCol; };
108 
109  virtual void SetClientMode() {mMode=Client;};
110  virtual void SetStorageMode() {mMode=Storage;};
111  virtual bool IsClientMode() {return (mMode==Client) ? true : false;};
112  virtual bool IsStorageMode() {return (mMode==Storage) ? true : false;};
113 
114  void Raz();
115  void Print();
116 
117  virtual char** WhatsIn(); // debug , not to be use
118 
119  virtual bool ReadScalar(char &c, const char *aName) ;
120  virtual bool ReadScalar(unsigned char &c, const char *) ;
121  virtual bool ReadScalar(short &h, const char *) ;
122  virtual bool ReadScalar(unsigned short &h, const char *) ;
123  virtual bool ReadScalar(int &i, const char *) ;
124  virtual bool ReadScalar(unsigned int &i, const char *) ;
125  virtual bool ReadScalar(long &l, const char *) ;
126  virtual bool ReadScalar(unsigned long &l, const char *) ;
127  virtual bool ReadScalar(long long &l, const char *) ;
128  virtual bool ReadScalar(float &f, const char *) ;
129  virtual bool ReadScalar(double &d, const char *) ;
130  virtual bool ReadScalar(char *&c, const char *) ;
131 
132  virtual bool WriteScalar(const char c, const char *) ;
133  virtual bool WriteScalar(const unsigned char c, const char *) ;
134  virtual bool WriteScalar(const short h, const char *) ;
135  virtual bool WriteScalar(const unsigned short h, const char *) ;
136  virtual bool WriteScalar(const int i, const char *) ;
137  virtual bool WriteScalar(const unsigned int i, const char *) ;
138  virtual bool WriteScalar(const long l, const char *) ;
139  virtual bool WriteScalar(const unsigned long l, const char *) ;
140  virtual bool WriteScalar(const long long l, const char *) ;
141  virtual bool WriteScalar(const float f, const char *) ;
142  virtual bool WriteScalar(const double d, const char *) ;
143  virtual bool WriteScalar(const char *c, const char *);
144 
145  virtual bool ReadArray(char *&c, int &len, const char *);
146  virtual bool ReadArray(unsigned char *&c, int &len, const char *);
147  virtual bool ReadArray( short *&c, int &len, const char *);
148  virtual bool ReadArray( unsigned short *&c, int &len, const char *);
149  virtual bool ReadArray(int *&c, int &len, const char *);
150  virtual bool ReadArray(unsigned int *&c, int &len, const char *);
151  virtual bool ReadArray(long *&c, int &len, const char *);
152  virtual bool ReadArray(unsigned long *&c, int &len, const char *);
153  virtual bool ReadArray(long long *&c, int &len, const char *);
154  virtual bool ReadArray(float *&c, int &len, const char *);
155  virtual bool ReadArray(double *&c, int &len, const char *);
156  virtual bool ReadArray(char **&c, int &len, const char *);
157 
158  virtual bool WriteArray(char *c, int len, const char *);
159  virtual bool WriteArray(unsigned char *c, int len, const char *);
160  virtual bool WriteArray(short *c, int len, const char *);
161  virtual bool WriteArray(unsigned short *c, int len, const char *);
162  virtual bool WriteArray(int *c, int len, const char *);
163  virtual bool WriteArray(unsigned int *c, int len, const char *);
164  virtual bool WriteArray(long *c, int len, const char *);
165  virtual bool WriteArray(unsigned long *c, int len, const char *);
166  virtual bool WriteArray(long long *c, int len, const char *);
167  virtual bool WriteArray(float *c, int len, const char *);
168  virtual bool WriteArray(double *c, int len, const char *);
169  virtual bool WriteArray(char **c, int len, const char *);
170 
171 
172 
173 protected:
174  //char* Raw_result (const char *aName);
175 
176  bool Find_Col (const char *aName);
177  void AddField(const char *aName, const myctype aTpe,const void* aVal,const int aLen);
178  void ChangeField(const myctype aTpe,const void* aVal,const int aLen);
179 
180 //bool WriteMem(char &s,void* aVal, myctype type);
181 
182  bool WriteMem(char *s,void* aVal, myctype type);
183  bool WriteMem(unsigned char *s,void* aVal, myctype type);
184  bool WriteMem(short *s,void* aVal, myctype type);
185  bool WriteMem(unsigned short *s,void* aVal, myctype type);
186  bool WriteMem(int *s,void* aVal, myctype type);
187  bool WriteMem(unsigned int *s,void* aVal, myctype type);
188  bool WriteMem(long *s,void* aVal, myctype type);
189  bool WriteMem(unsigned long *s,void* aVal, myctype type);
190  bool WriteMem(long long *s,void* aVal, myctype type);
191  bool WriteMem(float *s,void* aVal, myctype type);
192  bool WriteMem(double *s,void* aVal, myctype type);
193  bool WriteMem(char **s,void* aVal, myctype type);
194 
195  void StrConv(char* aVal,char &s);
196  void StrConv(char* aVal,unsigned char &s);
197  void StrConv(char* aVal,short &s);
198  void StrConv(char* aVal,unsigned short &s);
199  void StrConv(char* aVal,int &s);
200  void StrConv(char* aVal,unsigned int &s);
201  void StrConv(char* aVal,long &s);
202  void StrConv(char* aVal,unsigned long &s);
203  void StrConv(char* aVal,long long &s);
204  void StrConv(char* aVal,float &s);
205  void StrConv(char* aVal,double &s);
206  void StrConv(char* aVal,char* &s);
207 
208  void MemSwapCpy(char* where,char* from,int len,int swaplen,BuffMode mode);
209 
210  //ClassDef(StDbBuffer,0)
211 
212 
213 };
214 
215 
216 
217 #endif
218 
219 
220 
221 
222 
223