OmniSciDB  085a039ca4
 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 38 of file DdlUtils.cpp.

39  : type(type)
40  , param1(param1)
41  , param2(param2)
SQLTypes type
Definition: DdlUtils.h:54

Member Function Documentation

void ddl_utils::SqlType::check_type ( )
virtual

Definition at line 153 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().

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

+ Here is the caller graph for this function:

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

Definition at line 69 of file DdlUtils.cpp.

References array_size.

Referenced by ddl_utils::validate_and_set_array_size().

69  {
70  return array_size;
71 }

+ Here is the caller graph for this function:

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

Definition at line 61 of file DdlUtils.cpp.

References is_array.

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

61  {
62  return is_array;
63 }

+ Here is the caller graph for this function:

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

Definition at line 49 of file DdlUtils.cpp.

References param1.

Referenced by ddl_utils::validate_and_set_type().

49  {
50  return param1;
51 }

+ Here is the caller graph for this function:

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

Definition at line 57 of file DdlUtils.cpp.

References param2.

Referenced by ddl_utils::validate_and_set_type().

57  {
58  return param2;
59 }

+ Here is the caller graph for this function:

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

Definition at line 45 of file DdlUtils.cpp.

References type.

Referenced by ddl_utils::validate_and_set_type().

45  {
46  return type;
47 }
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 73 of file DdlUtils.cpp.

References array_size.

73  {
74  array_size = s;
75 }
void ddl_utils::SqlType::set_is_array ( bool  a)
virtual

Definition at line 65 of file DdlUtils.cpp.

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

65  {
66  is_array = a;
67 }
constexpr double a
Definition: Utm.h:32
void ddl_utils::SqlType::set_param1 ( int  param)
virtual

Definition at line 53 of file DdlUtils.cpp.

References param1.

53  {
54  param1 = param;
55 }
std::string ddl_utils::SqlType::to_string ( ) const
virtual

Definition at line 77 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().

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

+ 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

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: