OmniSciDB  95562058bd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 35 of file DdlUtils.cpp.

36  : type(type)
37  , param1(param1)
38  , param2(param2)
SQLTypes type
Definition: DdlUtils.h:54

Member Function Documentation

void ddl_utils::SqlType::check_type ( )
virtual

Definition at line 150 of file DdlUtils.cpp.

References kCHAR, kDECIMAL, kLINESTRING, kMULTIPOLYGON, kNUMERIC, kPOINT, kPOLYGON, kTIME, kTIMESTAMP, kVARCHAR, param1, param2, and type.

Referenced by ddl_utils::validate_and_set_type().

150  {
151  switch (type) {
152  case kCHAR:
153  case kVARCHAR:
154  if (param1 <= 0) {
155  throw std::runtime_error("CHAR and VARCHAR must have a positive dimension.");
156  }
157  break;
158  case kDECIMAL:
159  case kNUMERIC:
160  if (param1 <= 0) {
161  throw std::runtime_error("DECIMAL and NUMERIC must have a positive precision.");
162  } else if (param1 > 19) {
163  throw std::runtime_error(
164  "DECIMAL and NUMERIC precision cannot be larger than 19.");
165  } else if (param1 <= param2) {
166  throw std::runtime_error(
167  "DECIMAL and NUMERIC must have precision larger than scale.");
168  }
169  break;
170  case kTIMESTAMP:
171  if (param1 == -1) {
172  param1 = 0; // set default to 0
173  } else if (param1 != 0 && param1 != 3 && param1 != 6 &&
174  param1 != 9) { // support ms, us, ns
175  throw std::runtime_error(
176  "Only TIMESTAMP(n) where n = (0,3,6,9) are supported now.");
177  }
178  break;
179  case kTIME:
180  if (param1 == -1) {
181  param1 = 0; // default precision is 0
182  }
183  if (param1 > 0) { // @TODO(wei) support sub-second precision later.
184  throw std::runtime_error("Only TIME(0) is supported now.");
185  }
186  break;
187  case kPOINT:
188  case kLINESTRING:
189  case kPOLYGON:
190  case kMULTIPOLYGON:
191  // Storing SRID in param1
192  break;
193  default:
194  param1 = 0;
195  break;
196  }
197 }
Definition: sqltypes.h:51
SQLTypes type
Definition: DdlUtils.h:54
Definition: sqltypes.h:43

+ Here is the caller graph for this function:

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

Definition at line 66 of file DdlUtils.cpp.

References array_size.

Referenced by ddl_utils::validate_and_set_array_size().

66  {
67  return array_size;
68 }

+ Here is the caller graph for this function:

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

Definition at line 58 of file DdlUtils.cpp.

References is_array.

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

58  {
59  return is_array;
60 }

+ Here is the caller graph for this function:

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

Definition at line 46 of file DdlUtils.cpp.

References param1.

Referenced by ddl_utils::validate_and_set_type().

46  {
47  return param1;
48 }

+ Here is the caller graph for this function:

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

Definition at line 54 of file DdlUtils.cpp.

References param2.

Referenced by ddl_utils::validate_and_set_type().

54  {
55  return param2;
56 }

+ Here is the caller graph for this function:

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

Definition at line 42 of file DdlUtils.cpp.

References type.

Referenced by ddl_utils::validate_and_set_type().

42  {
43  return type;
44 }
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 70 of file DdlUtils.cpp.

References array_size.

70  {
71  array_size = s;
72 }
void ddl_utils::SqlType::set_is_array ( bool  a)
virtual

Definition at line 62 of file DdlUtils.cpp.

References is_array.

62  {
63  is_array = a;
64 }
void ddl_utils::SqlType::set_param1 ( int  param)
virtual

Definition at line 50 of file DdlUtils.cpp.

References param1.

50  {
51  param1 = param;
52 }
std::string ddl_utils::SqlType::to_string ( ) const
virtual

Definition at line 74 of file DdlUtils.cpp.

References array_size, assert(), 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().

74  {
75  std::string str;
76  switch (type) {
77  case kBOOLEAN:
78  str = "BOOLEAN";
79  break;
80  case kCHAR:
81  str = "CHAR(" + boost::lexical_cast<std::string>(param1) + ")";
82  break;
83  case kVARCHAR:
84  str = "VARCHAR(" + boost::lexical_cast<std::string>(param1) + ")";
85  break;
86  case kTEXT:
87  str = "TEXT";
88  break;
89  case kNUMERIC:
90  str = "NUMERIC(" + boost::lexical_cast<std::string>(param1);
91  if (param2 > 0) {
92  str += ", " + boost::lexical_cast<std::string>(param2);
93  }
94  str += ")";
95  break;
96  case kDECIMAL:
97  str = "DECIMAL(" + boost::lexical_cast<std::string>(param1);
98  if (param2 > 0) {
99  str += ", " + boost::lexical_cast<std::string>(param2);
100  }
101  str += ")";
102  break;
103  case kBIGINT:
104  str = "BIGINT";
105  break;
106  case kINT:
107  str = "INT";
108  break;
109  case kTINYINT:
110  str = "TINYINT";
111  break;
112  case kSMALLINT:
113  str = "SMALLINT";
114  break;
115  case kFLOAT:
116  str = "FLOAT";
117  break;
118  case kDOUBLE:
119  str = "DOUBLE";
120  break;
121  case kTIME:
122  str = "TIME";
123  if (param1 < 6) {
124  str += "(" + boost::lexical_cast<std::string>(param1) + ")";
125  }
126  break;
127  case kTIMESTAMP:
128  str = "TIMESTAMP";
129  if (param1 <= 9) {
130  str += "(" + boost::lexical_cast<std::string>(param1) + ")";
131  }
132  break;
133  case kDATE:
134  str = "DATE";
135  break;
136  default:
137  assert(false);
138  break;
139  }
140  if (is_array) {
141  str += "[";
142  if (array_size > 0) {
143  str += boost::lexical_cast<std::string>(array_size);
144  }
145  str += "]";
146  }
147  return str;
148 }
Definition: sqltypes.h:51
SQLTypes type
Definition: DdlUtils.h:54
Definition: sqltypes.h:54
Definition: sqltypes.h:55
int64_t const int32_t sz assert(dest)
Definition: sqltypes.h:43
Definition: sqltypes.h:47

+ Here is the call graph for this function:

+ 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

Definition at line 57 of file DdlUtils.h.

Referenced by get_is_array(), set_is_array(), and to_string().

int ddl_utils::SqlType::param1
protected
int ddl_utils::SqlType::param2
protected

Definition at line 56 of file DdlUtils.h.

Referenced by check_type(), get_param2(), JsonColumnSqlType::getParam2(), and to_string().

SQLTypes ddl_utils::SqlType::type
protected

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