Revision: 24841
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at March 12, 2010 08:23 by svendiego
Initial Code
template <int N>
struct sqlbuffN
{ char bf[N];
char * p;
sqlbuffN() { clear(); }
operator const char *() const { return bf; }
void clear() { p=bf; *p=0; }
void set(const char *s) { strcpy(bf,s); p=bf+strlen(s); }
sqlbuffN & operator < (int i)
{ p+=sprintf(p,"%d",i); return *this; }
sqlbuffN & operator <= (int i)
{ p+=sprintf(p,"%d",i); return *this; }
sqlbuffN & operator < (const char * cp)
{ strcpy(p,cp); p+=strlen(p); return *this; }
sqlbuffN & operator <= (const char * cp)
{ p+=sqlQuote(p,cp); return * this;}
sqlbuffN & operator < (const std::string & s) { return *this<(s.c_str()); }
sqlbuffN & operator <=(const std::string & s) { return *this<=(s.c_str()); }
};
struct sqlbuff
{ mem_buffer bf;
int off;
explicit sqlbuff(int sz = 4096)
{ bf.resize(sz,0); }
void clear() { off=0; }
sqlbuff & operator <(const char * txt)
{ int len = strlen(txt);
bf.growto2(off+len+1,mem_buffer::copydata);
strcpy(bf.p+off,txt); off+=len;
return *this;
}
sqlbuff & operator <= (const char * txt)
{ int len = 2*strlen(txt)+2;
bf.growto2(off+len+1,mem_buffer::copydata);
off+=sqlQuote(bf.p+off,txt);
return * this;
}
sqlbuff & operator < (const std::string & s) { return *this<(s.c_str()); }
sqlbuff & operator <=(const std::string & s) { return *this<=(s.c_str()); }
sqlbuff & operator < (int i)
{ bf.growto2(off+15,mem_buffer::copydata); off+=sprintf(bf.p+off,"%d",i); return *this; }
sqlbuff & operator <= (int i)
{ bf.growto2(off+15,mem_buffer::copydata); off+=sprintf(bf.p+off,"%d",i); return *this; }
operator const char *() const { return bf.p; }
};
Initial URL
Initial Description
Initial Title
really simple sql buffer
Initial Tags
Initial Language
C++