OmniSciDB  471d68cefb
 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 37 of file DdlUtils.cpp.

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

Member Function Documentation

void ddl_utils::SqlType::check_type ( )
virtual

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

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

References array_size.

Referenced by ddl_utils::validate_and_set_array_size().

68  {
69  return array_size;
70 }

+ Here is the caller graph for this function:

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

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

60  {
61  return is_array;
62 }

+ Here is the caller graph for this function:

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

Definition at line 48 of file DdlUtils.cpp.

References param1.

Referenced by ddl_utils::validate_and_set_type().

48  {
49  return param1;
50 }

+ Here is the caller graph for this function:

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

Definition at line 56 of file DdlUtils.cpp.

References param2.

Referenced by ddl_utils::validate_and_set_type().

56  {
57  return param2;
58 }

+ Here is the caller graph for this function:

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

Definition at line 44 of file DdlUtils.cpp.

References type.

Referenced by ddl_utils::validate_and_set_type().

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

References array_size.

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

Definition at line 64 of file DdlUtils.cpp.

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

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

Definition at line 52 of file DdlUtils.cpp.

References param1.

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

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

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