3#include "rdbModel/Tables/Datatype.h"
4#include "facilities/Timestamp.h"
5#include "facilities/Util.h"
12 bool initDone =
false;
14 std::string typenames[N_SUPPORTED_TYPES];
18 typenames[Datatype::TYPEenum] = std::string(
"enum" );
19 typenames[Datatype::TYPEdatetime] = std::string(
"datetime" );
20 typenames[Datatype::TYPEtimestamp] = std::string(
"timestamp" );
21 typenames[Datatype::TYPEint] = std::string(
"int" );
22 typenames[Datatype::TYPEmediumint] = std::string(
"mediumint" );
23 typenames[Datatype::TYPEsmallint] = std::string(
"smallint" );
24 typenames[Datatype::TYPEreal] = std::string(
"real" );
25 typenames[Datatype::TYPEdouble] = std::string(
"double" );
26 typenames[Datatype::TYPEvarchar] = std::string(
"varchar" );
27 typenames[Datatype::TYPEchar] = std::string(
"char" );
31 int findType( std::string aType ) {
32 if ( !initDone ) init();
33 for (
unsigned int i = 0; i < N_SUPPORTED_TYPES; i++ )
35 if ( aType == typenames[i] )
return i;
37 return (
int)Datatype::TYPEnotFound;
39 enum TYPE_OF_TYPE { TOTinteger = 0, TOTreal, TOTchar, TOTdate };
40 int findTOT( Datatype::TYPES aType ) {
41 if ( ( aType == Datatype::TYPEint ) || ( aType == Datatype::TYPEmediumint ) ||
42 ( aType == Datatype::TYPEsmallint ) )
44 else if ( ( aType == Datatype::TYPEreal ) || ( aType == Datatype::TYPEdouble ) )
46 else if ( ( aType == Datatype::TYPEdatetime ) || ( aType == Datatype::TYPEtimestamp ) )
55 int Datatype::setType( std::string name ) {
56 m_type = (
TYPES)findType( name );
57 if ( m_type >= 0 ) { m_typename = name; }
65 m_maxInt = 2147483647;
66 m_minInt = -2147483647;
88 bool Datatype::setInterval(
const std::string&
min,
const std::string&
max ) {
93 std::cerr <<
"From rdbModel::Datatype::setInterval " << std::endl;
94 std::cerr <<
"Cannot set interval restriction for type " << typenames[m_type]
111 if ( minInt > m_minInt ) m_minInt = minInt;
112 if ( maxInt < m_maxInt ) m_maxInt = maxInt;
113 }
catch ( facilities::WrongType ex )
115 std::cerr <<
"Error detected in XercesBuilder::buildDatatype " << std::endl;
116 std::cerr << ex.
getMsg() << std::endl;
119 ret = ( m_min < m_max );
129 ret = ( minFloat < maxFloat );
130 }
catch ( facilities::WrongType ex )
132 std::cerr <<
"Error detected in XercesBuilder::buildDatatype " << std::endl;
133 std::cerr << ex.
getMsg() << std::endl;
141 facilities::Timestamp minTime(
min );
142 facilities::Timestamp maxTime(
max );
143 ret = ( minTime < maxTime );
144 }
catch ( facilities::BadTimeInput ex )
146 std::cerr <<
"From rdbModel::Datatype::setInterval" << std::endl;
176 else if ( m_restrict ==
RESTRICTpos )
return ( doubleVal > 0.0 );
179 double min = Util::stringToDouble( m_min );
180 double max = Util::stringToDouble( m_max );
181 return ( (
min <= doubleVal ) && ( doubleVal <=
max ) );
194 return ( ( intVal >= m_minInt ) && ( intVal <= m_maxInt ) );
201 if ( !m_enum->choicesRequired() )
return true;
203 unsigned nChoice = m_enum->getChoices().size();
204 for (
unsigned i = 0; i < nChoice; i++ )
206 if ( val == m_enum->getChoices()[i] )
return true;
219 return ( (
min <= aTime ) && ( aTime <=
max ) );
224 std::cerr <<
"From rdbModel::Datatype::okValue" << std::endl;
229 default:
return false;
237 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