3#include "rdbModel/Tables/Datatype.h"
4#include "facilities/Util.h"
5#include "facilities/Timestamp.h"
11 bool initDone =
false;
13 std::string typenames[N_SUPPORTED_TYPES];
16 typenames[Datatype::TYPEenum] = std::string(
"enum");
17 typenames[Datatype::TYPEdatetime] = std::string(
"datetime");
18 typenames[Datatype::TYPEtimestamp] = std::string(
"timestamp");
19 typenames[Datatype::TYPEint] = std::string(
"int");
20 typenames[Datatype::TYPEmediumint] = std::string(
"mediumint");
21 typenames[Datatype::TYPEsmallint] = std::string(
"smallint");
22 typenames[Datatype::TYPEreal] = std::string(
"real");
23 typenames[Datatype::TYPEdouble] = std::string(
"double");
24 typenames[Datatype::TYPEvarchar] = std::string(
"varchar");
25 typenames[Datatype::TYPEchar] = std::string(
"char");
29 int findType(std::string aType) {
30 if (!initDone)
init();
31 for (
unsigned int i = 0; i < N_SUPPORTED_TYPES; i++) {
32 if (aType == typenames[i])
return i;
34 return (
int) Datatype::TYPEnotFound;
42 int findTOT(Datatype::TYPES aType) {
43 if ((aType == Datatype::TYPEint) || (aType == Datatype::TYPEmediumint) ||
44 (aType == Datatype::TYPEsmallint))
return TOTinteger;
45 else if ((aType == Datatype::TYPEreal) || (aType == Datatype::TYPEdouble))
47 else if ((aType == Datatype::TYPEdatetime) ||
48 (aType == Datatype::TYPEtimestamp))
57 int Datatype::setType(std::string name) {
58 m_type = (
TYPES) findType(name);
68 m_maxInt = 2147483647;
69 m_minInt = -2147483647;
92 bool Datatype::setInterval(
const std::string&
min,
const std::string&
max) {
97 std::cerr <<
"From rdbModel::Datatype::setInterval " << std::endl;
98 std::cerr <<
"Cannot set interval restriction for type " <<
99 typenames[m_type] << std::endl;
113 if (minInt > m_minInt) m_minInt = minInt;
114 if (maxInt < m_maxInt) m_maxInt = maxInt;
117 std::cerr <<
"Error detected in XercesBuilder::buildDatatype "
119 std::cerr << ex.
getMsg() << std::endl;
122 ret = (m_min < m_max);
130 ret = (minFloat < maxFloat);
133 std::cerr <<
"Error detected in XercesBuilder::buildDatatype "
135 std::cerr << ex.
getMsg() << std::endl;
143 ret = (minTime < maxTime);
146 std::cerr <<
"From rdbModel::Datatype::setInterval" << std::endl;
172 doubleVal = Util::stringToDouble(val);
178 else if (m_restrict ==
RESTRICTpos)
return (doubleVal > 0.0);
180 double min = Util::stringToDouble(m_min);
181 double max = Util::stringToDouble(m_max);
182 return ((
min <= doubleVal) && (doubleVal <=
max));
194 intVal = Util::stringToInt(val);
199 return ((intVal >= m_minInt) && (intVal <= m_maxInt));
208 unsigned nChoice = m_enum->
getChoices().size();
209 for (
unsigned i = 0; i < nChoice; i++) {
210 if (val == m_enum->
getChoices()[i])
return true;
221 return ((
min <= aTime) && (aTime <=
max));
226 std::cerr <<
"From rdbModel::Datatype::okValue" << std::endl;
241 return (findTOT(m_type) == findTOT(other->m_type));
static double stringToDouble(const std::string &InStr)
static int stringToInt(const std::string &InStr)
Exception class used when converting from string to numeric type.
bool okValue(const std::string &val) const
bool getInterval(std::string &min, std::string &max)
bool isCompatible(const Datatype *other) const
const std::vector< std::string > & getChoices() const
bool choicesRequired() const