OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ddl_utils::SqlType Class Reference

#include <DdlUtils.h>

+ Inheritance diagram for ddl_utils::SqlType:

Public Member Functions

 SqlType (SQLTypes type, int param1, int param2, bool is_array, int array_size)
 
virtual SQLTypes get_type () const
 
virtual int get_param1 () const
 
virtual void set_param1 (int param)
 
virtual int get_param2 () const
 
virtual bool get_is_array () const
 
virtual void set_is_array (bool a)
 
virtual int get_array_size () const
 
virtual void set_array_size (int s)
 
virtual std::string to_string () const
 
virtual void check_type ()
 

Protected Attributes

SQLTypes type
 
int param1
 
int param2
 
bool is_array
 
int array_size
 

Detailed Description

Definition at line 23 of file DdlUtils.h.

Constructor & Destructor Documentation

ddl_utils::SqlType::SqlType ( SQLTypes  type,
int  param1,
int  param2,
bool  is_array,
int  array_size 
)

Encapsulates column definition type information.

Parameters
type- Column type.
param1- For column types followed by parenthesis with more information, this represents the first parameter in the parenthesis. For example, in DECIMAL(5, 2), this would represent the precision value of 5. In GEOMETRY(POINT, 4326), this would represent the integer value of the kPOINT enum.
param2- For column types followed by parenthesis with more information, this represents the second parameter in the parenthesis. For example, in DECIMAL(5, 2), this would represent the scale value of 2. In GEOMETRY(POINT, 4326), this would represent the coordinate type integer value of 4326.
is_array- Flag that indicates whether or not column type is an array.
array_size- For array column types, this is the specified size of the array.

Definition at line 73 of file DdlUtils.cpp.

74  : type(type)
75  , param1(param1)
76  , param2(param2)
SQLTypes type
Definition: DdlUtils.h:54

Member Function Documentation

void ddl_utils::SqlType::check_type ( )
virtual

Definition at line 188 of file DdlUtils.cpp.

References kCHAR, kDECIMAL, kLINESTRING, sql_constants::kMaxNumericPrecision, kMULTILINESTRING, kMULTIPOINT, kMULTIPOLYGON, kNUMERIC, kPOINT, kPOLYGON, kTIME, kTIMESTAMP, kVARCHAR, param1, param2, to_string(), and type.

Referenced by ddl_utils::validate_and_set_type().

188  {
189  switch (type) {
190  case kCHAR:
191  case kVARCHAR:
192  if (param1 <= 0) {
193  throw std::runtime_error("CHAR and VARCHAR must have a positive dimension.");
194  }
195  break;
196  case kDECIMAL:
197  case kNUMERIC:
198  if (param1 <= 0) {
199  throw std::runtime_error("DECIMAL and NUMERIC must have a positive precision.");
201  throw std::runtime_error("DECIMAL and NUMERIC precision cannot be larger than " +
203  ".");
204  } else if (param1 <= param2) {
205  throw std::runtime_error(
206  "DECIMAL and NUMERIC must have precision larger than scale.");
207  }
208  break;
209  case kTIMESTAMP:
210  if (param1 == -1) {
211  param1 = 0; // set default to 0
212  } else if (param1 != 0 && param1 != 3 && param1 != 6 &&
213  param1 != 9) { // support ms, us, ns
214  throw std::runtime_error(
215  "Only TIMESTAMP(n) where n = (0,3,6,9) are supported now.");
216  }
217  break;
218  case kTIME:
219  if (param1 == -1) {
220  param1 = 0; // default precision is 0
221  }
222  if (param1 > 0) { // @TODO(wei) support sub-second precision later.
223  throw std::runtime_error("Only TIME(0) is supported now.");
224  }
225  break;
226  case kPOINT:
227  case kMULTIPOINT:
228  case kLINESTRING:
229  case kMULTILINESTRING:
230  case kPOLYGON:
231  case kMULTIPOLYGON:
232  // Storing SRID in param1
233  break;
234  default:
235  param1 = 0;
236  break;
237  }
238 }
static constexpr int32_t kMaxNumericPrecision
Definition: sqltypes.h:58
Definition: sqltypes.h:76
std::string to_string(char const *&&v)
SQLTypes type
Definition: DdlUtils.h:54
Definition: sqltypes.h:68

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int ddl_utils::SqlType::get_array_size ( ) const
virtual

Definition at line 104 of file DdlUtils.cpp.

References array_size.

Referenced by ddl_utils::validate_and_set_array_size().

104  {
105  return array_size;
106 }

+ Here is the caller graph for this function:

bool ddl_utils::SqlType::get_is_array ( ) const
virtual

Definition at line 96 of file DdlUtils.cpp.

References is_array.

Referenced by Parser::set_column_descriptor(), ddl_utils::validate_and_set_array_size(), and ddl_utils::validate_and_set_type().

96  {
97  return is_array;
98 }

+ Here is the caller graph for this function:

int ddl_utils::SqlType::get_param1 ( ) const
virtual

Definition at line 84 of file DdlUtils.cpp.

References param1.

Referenced by ddl_utils::validate_and_set_type().

84  {
85  return param1;
86 }

+ Here is the caller graph for this function:

int ddl_utils::SqlType::get_param2 ( ) const
virtual

Definition at line 92 of file DdlUtils.cpp.

References param2.

Referenced by ddl_utils::validate_and_set_type().

92  {
93  return param2;
94 }

+ Here is the caller graph for this function:

SQLTypes ddl_utils::SqlType::get_type ( ) const
virtual

Definition at line 80 of file DdlUtils.cpp.

References type.

Referenced by ddl_utils::validate_and_set_type().

80  {
81  return type;
82 }
SQLTypes type
Definition: DdlUtils.h:54

+ Here is the caller graph for this function:

void ddl_utils::SqlType::set_array_size ( int  s)
virtual

Definition at line 108 of file DdlUtils.cpp.

References array_size.

108  {
109  array_size = s;
110 }
void ddl_utils::SqlType::set_is_array ( bool  a)
virtual

Definition at line 100 of file DdlUtils.cpp.

References anonymous_namespace{Utm.h}::a, and is_array.

100  {
101  is_array = a;
102 }
constexpr double a
Definition: Utm.h:32
void ddl_utils::SqlType::set_param1 ( int  param)
virtual

Definition at line 88 of file DdlUtils.cpp.

References param1.

88  {
89  param1 = param;
90 }
std::string ddl_utils::SqlType::to_string ( ) const
virtual

Definition at line 112 of file DdlUtils.cpp.

References array_size, is_array, kBIGINT, kBOOLEAN, kCHAR, kDATE, kDECIMAL, kDOUBLE, kFLOAT, kINT, kNUMERIC, kSMALLINT, kTEXT, kTIME, kTIMESTAMP, kTINYINT, kVARCHAR, param1, param2, and type.

Referenced by ddl_utils::validate_and_set_fixed_encoding().

112  {
113  std::string str;
114  switch (type) {
115  case kBOOLEAN:
116  str = "BOOLEAN";
117  break;
118  case kCHAR:
119  str = "CHAR(" + boost::lexical_cast<std::string>(param1) + ")";
120  break;
121  case kVARCHAR:
122  str = "VARCHAR(" + boost::lexical_cast<std::string>(param1) + ")";
123  break;
124  case kTEXT:
125  str = "TEXT";
126  break;
127  case kNUMERIC:
128  str = "NUMERIC(" + boost::lexical_cast<std::string>(param1);
129  if (param2 > 0) {
130  str += ", " + boost::lexical_cast<std::string>(param2);
131  }
132  str += ")";
133  break;
134  case kDECIMAL:
135  str = "DECIMAL(" + boost::lexical_cast<std::string>(param1);
136  if (param2 > 0) {
137  str += ", " + boost::lexical_cast<std::string>(param2);
138  }
139  str += ")";
140  break;
141  case kBIGINT:
142  str = "BIGINT";
143  break;
144  case kINT:
145  str = "INT";
146  break;
147  case kTINYINT:
148  str = "TINYINT";
149  break;
150  case kSMALLINT:
151  str = "SMALLINT";
152  break;
153  case kFLOAT:
154  str = "FLOAT";
155  break;
156  case kDOUBLE:
157  str = "DOUBLE";
158  break;
159  case kTIME:
160  str = "TIME";
161  if (param1 < 6) {
162  str += "(" + boost::lexical_cast<std::string>(param1) + ")";
163  }
164  break;
165  case kTIMESTAMP:
166  str = "TIMESTAMP";
167  if (param1 <= 9) {
168  str += "(" + boost::lexical_cast<std::string>(param1) + ")";
169  }
170  break;
171  case kDATE:
172  str = "DATE";
173  break;
174  default:
175  assert(false);
176  break;
177  }
178  if (is_array) {
179  str += "[";
180  if (array_size > 0) {
181  str += boost::lexical_cast<std::string>(array_size);
182  }
183  str += "]";
184  }
185  return str;
186 }
Definition: sqltypes.h:76
SQLTypes type
Definition: DdlUtils.h:54
Definition: sqltypes.h:79
Definition: sqltypes.h:80
Definition: sqltypes.h:68
Definition: sqltypes.h:72

+ Here is the caller graph for this function:

Member Data Documentation

int ddl_utils::SqlType::array_size
protected

Definition at line 58 of file DdlUtils.h.

Referenced by get_array_size(), set_array_size(), and to_string().

bool ddl_utils::SqlType::is_array
protected
int ddl_utils::SqlType::param1
protected

Definition at line 55 of file DdlUtils.h.

Referenced by check_type(), get_param1(), set_param1(), and to_string().

int ddl_utils::SqlType::param2
protected

Definition at line 56 of file DdlUtils.h.

Referenced by check_type(), get_param2(), and to_string().

SQLTypes ddl_utils::SqlType::type
protected

Definition at line 54 of file DdlUtils.h.

Referenced by check_type(), get_type(), and to_string().


The documentation for this class was generated from the following files: