35 #include "StDbFieldI.h"
37 using namespace TxLogging;
40 std::map<StDbFieldI::EDataType,std::string> StDbFieldI::fTypeMap;
41 std::map<StDbFieldI::EDataType,std::string> StDbFieldI::fTypeMapName;
42 std::map<std::string,StDbFieldI::EDataType> StDbFieldI::fTypeMapInv;
58 if (
string(name).empty()) {
60 StDataException::FIELD,
61 StUCMException::ERROR);
68 throw StDataException(
"String type specified with length < 0 in field '"
69 +
string(name) +
"'.",
70 StDataException::FIELD,
71 StUCMException::ERROR);
96 if (
string(name).empty()) {
98 StDataException::FIELD,
99 StUCMException::ERROR);
106 throw StDataException(
"String type specified with length <= 0 in field '"
107 +
string(name) +
"'.",
108 StDataException::FIELD,
109 StUCMException::ERROR);
120 if (!value) value =
" ";
124 <<
": name =" << name
125 <<
"; value =" << value
127 <<
"; lenght=" << length
167 return fName.c_str();
174 static string tostring;
175 tostring = string(
getName()) +
"::"
179 return tostring.c_str();
187 std::string value = strValue;
188 if (fType == kSTRING) {
189 if (value.length() > fMaxLength) {
190 value = string(strValue).substr(0,fMaxLength);
195 fNull =string(strValue).empty();
198 fEncodedValue = value;
215 return fEncodedValue.c_str();
243 return fTypeMapName[
getType()].c_str();
266 void StDbFieldI::MakeTypeMap() {
268 #error TYPEtypeNAME redefinitions
270 #define TYPEtypeNAME(TYPENAME,datatype) \
271 case k##TYPENAME: { \
272 fTypeMap.insert(pair<EDataType,std::string>(k##TYPENAME,typeid(datatype).name())); \
273 fTypeMapName.insert(pair<EDataType,std::string>(k##TYPENAME,#TYPENAME)); \
274 fTypeMapInv.insert(pair<std::string,EDataType>(typeid(datatype).name(),k##TYPENAME)); \
277 for (
int i=kBOOL;i<kEND;++i) {
279 TYPEtypeNAME(BOOL,
bool)
280 TYPEtypeNAME(INT,
int)
281 TYPEtypeNAME(UINT,
unsigned int)
282 TYPEtypeNAME(LONG,
long)
283 TYPEtypeNAME(ULONG,
unsigned long)
284 TYPEtypeNAME(DOUBLE,
double)
285 TYPEtypeNAME(CHAR,
char)
286 TYPEtypeNAME(UNIXTIME,
unsigned int)
289 fTypeMap.insert(pair<EDataType,std::string>(kINVALID,
"invalid"));
290 fTypeMapName.insert(pair<EDataType,std::string>(kINVALID,
"unkown"));
291 fTypeMapInv.insert(pair<std::string,EDataType>(
"unkown",kINVALID));
298 #error DBVALUECONV_ redefinitions
300 #define DBVALUECONV_(DATATYPE,dataname) \
301 void StDbFieldI::setValue(const DATATYPE &value) {setValue<DATATYPE>(value);} \
302 DATATYPE StDbFieldI::to##dataname() const { return toValue<DATATYPE>(); }
304 DBVALUECONV_(
char,Char)
305 DBVALUECONV_(
int,Int)
306 DBVALUECONV_(
unsigned int,UInt)
307 DBVALUECONV_(
long,Long)
308 DBVALUECONV_(
unsigned long,ULong)
309 DBVALUECONV_(
double,Double)
EDataType getType() const
virtual ~StDbFieldI()
Deconstructor.
StDbFieldI(const char *name, StDbFieldI::EDataType type, int length=0)
void setIgnore(bool ignore)
const char * getTypeAsString() const
const char * fieldAsString() const
const char * getName() const
const char * getValueAsString() const
void setValueFromString(const char *strValue)