OmniSciDB  04ee39c94c
Parser::SQLType Class Reference

#include <ParserNode.h>

+ Inheritance diagram for Parser::SQLType:
+ Collaboration diagram for Parser::SQLType:

Public Member Functions

 SQLType (SQLTypes t)
 
 SQLType (SQLTypes t, int p1)
 
 SQLType (SQLTypes t, int p1, int p2, bool a)
 
SQLTypes get_type () const
 
int get_param1 () const
 
int get_param2 () const
 
bool get_is_array () const
 
void set_is_array (bool a)
 
int get_array_size () const
 
void set_array_size (int s)
 
std::string to_string () const
 
void check_type ()
 
- Public Member Functions inherited from Parser::Node
virtual ~Node ()
 

Private Attributes

SQLTypes type
 
int param1
 
int param2
 
bool is_array
 
int array_size
 

Detailed Description

Definition at line 59 of file ParserNode.h.

Constructor & Destructor Documentation

◆ SQLType() [1/3]

Parser::SQLType::SQLType ( SQLTypes  t)
inlineexplicit

Definition at line 61 of file ParserNode.h.

62  : type(t), param1(-1), param2(0), is_array(false), array_size(-1) {}
SQLTypes type
Definition: ParserNode.h:78

◆ SQLType() [2/3]

Parser::SQLType::SQLType ( SQLTypes  t,
int  p1 
)
inline

Definition at line 63 of file ParserNode.h.

64  : type(t), param1(p1), param2(0), is_array(false), array_size(-1) {}
SQLTypes type
Definition: ParserNode.h:78

◆ SQLType() [3/3]

Parser::SQLType::SQLType ( SQLTypes  t,
int  p1,
int  p2,
bool  a 
)
inline

Definition at line 65 of file ParserNode.h.

66  : type(t), param1(p1), param2(p2), is_array(a), array_size(-1) {}
SQLTypes type
Definition: ParserNode.h:78

Member Function Documentation

◆ check_type()

void Parser::SQLType::check_type ( )

Definition at line 1878 of file ParserNode.cpp.

References kCHAR, kDECIMAL, kLINESTRING, kMULTIPOLYGON, kNUMERIC, kPOINT, kPOLYGON, kTIME, kTIMESTAMP, kVARCHAR, and run-benchmark-import::type.

Referenced by Parser::DDLStmt::setColumnDescriptor().

1878  {
1879  switch (type) {
1880  case kCHAR:
1881  case kVARCHAR:
1882  if (param1 <= 0) {
1883  throw std::runtime_error("CHAR and VARCHAR must have a positive dimension.");
1884  }
1885  break;
1886  case kDECIMAL:
1887  case kNUMERIC:
1888  if (param1 <= 0) {
1889  throw std::runtime_error("DECIMAL and NUMERIC must have a positive precision.");
1890  } else if (param1 > 19) {
1891  throw std::runtime_error(
1892  "DECIMAL and NUMERIC precision cannot be larger than 19.");
1893  } else if (param1 <= param2) {
1894  throw std::runtime_error(
1895  "DECIMAL and NUMERIC must have precision larger than scale.");
1896  }
1897  break;
1898  case kTIMESTAMP:
1899  if (param1 == -1) {
1900  param1 = 0; // set default to 0
1901  } else if (param1 != 0 && param1 != 3 && param1 != 6 &&
1902  param1 != 9) { // support ms, us, ns
1903  throw std::runtime_error(
1904  "Only TIMESTAMP(n) where n = (0,3,6,9) are supported now.");
1905  }
1906  break;
1907  case kTIME:
1908  if (param1 == -1) {
1909  param1 = 0; // default precision is 0
1910  }
1911  if (param1 > 0) { // @TODO(wei) support sub-second precision later.
1912  throw std::runtime_error("Only TIME(0) is supported now.");
1913  }
1914  break;
1915  case kPOINT:
1916  case kLINESTRING:
1917  case kPOLYGON:
1918  case kMULTIPOLYGON:
1919  // Storing SRID in param1
1920  break;
1921  default:
1922  param1 = 0;
1923  break;
1924  }
1925 }
Definition: sqltypes.h:51
Definition: sqltypes.h:43
SQLTypes type
Definition: ParserNode.h:78
+ Here is the caller graph for this function:

◆ get_array_size()

int Parser::SQLType::get_array_size ( ) const
inline

Definition at line 72 of file ParserNode.h.

Referenced by Parser::DDLStmt::setColumnDescriptor().

72 { return array_size; }
+ Here is the caller graph for this function:

◆ get_is_array()

bool Parser::SQLType::get_is_array ( ) const
inline

Definition at line 70 of file ParserNode.h.

Referenced by Parser::DDLStmt::setColumnDescriptor().

70 { return is_array; }
+ Here is the caller graph for this function:

◆ get_param1()

int Parser::SQLType::get_param1 ( ) const
inline

Definition at line 68 of file ParserNode.h.

Referenced by Parser::DDLStmt::setColumnDescriptor().

68 { return param1; }
+ Here is the caller graph for this function:

◆ get_param2()

int Parser::SQLType::get_param2 ( ) const
inline

Definition at line 69 of file ParserNode.h.

Referenced by Parser::DDLStmt::setColumnDescriptor().

69 { return param2; }
+ Here is the caller graph for this function:

◆ get_type()

SQLTypes Parser::SQLType::get_type ( ) const
inline

Definition at line 67 of file ParserNode.h.

References run-benchmark-import::type.

Referenced by Parser::DDLStmt::setColumnDescriptor().

67 { return type; }
SQLTypes type
Definition: ParserNode.h:78
+ Here is the caller graph for this function:

◆ set_array_size()

void Parser::SQLType::set_array_size ( int  s)
inline

Definition at line 73 of file ParserNode.h.

References to_string().

73 { array_size = s; }
+ Here is the call graph for this function:

◆ set_is_array()

void Parser::SQLType::set_is_array ( bool  a)
inline

Definition at line 71 of file ParserNode.h.

71 { is_array = a; }

◆ to_string()

std::string Parser::SQLType::to_string ( ) const

Definition at line 1224 of file ParserNode.cpp.

References kBIGINT, kBOOLEAN, kCHAR, kDATE, kDECIMAL, kDOUBLE, kFLOAT, kINT, kNUMERIC, kSMALLINT, kTEXT, kTIME, kTIMESTAMP, kTINYINT, kVARCHAR, and run-benchmark-import::type.

Referenced by Parser::DDLStmt::setColumnDescriptor().

1224  {
1225  std::string str;
1226  switch (type) {
1227  case kBOOLEAN:
1228  str = "BOOLEAN";
1229  break;
1230  case kCHAR:
1231  str = "CHAR(" + boost::lexical_cast<std::string>(param1) + ")";
1232  break;
1233  case kVARCHAR:
1234  str = "VARCHAR(" + boost::lexical_cast<std::string>(param1) + ")";
1235  break;
1236  case kTEXT:
1237  str = "TEXT";
1238  break;
1239  case kNUMERIC:
1240  str = "NUMERIC(" + boost::lexical_cast<std::string>(param1);
1241  if (param2 > 0) {
1242  str += ", " + boost::lexical_cast<std::string>(param2);
1243  }
1244  str += ")";
1245  break;
1246  case kDECIMAL:
1247  str = "DECIMAL(" + boost::lexical_cast<std::string>(param1);
1248  if (param2 > 0) {
1249  str += ", " + boost::lexical_cast<std::string>(param2);
1250  }
1251  str += ")";
1252  break;
1253  case kBIGINT:
1254  str = "BIGINT";
1255  break;
1256  case kINT:
1257  str = "INT";
1258  break;
1259  case kTINYINT:
1260  str = "TINYINT";
1261  break;
1262  case kSMALLINT:
1263  str = "SMALLINT";
1264  break;
1265  case kFLOAT:
1266  str = "FLOAT";
1267  break;
1268  case kDOUBLE:
1269  str = "DOUBLE";
1270  break;
1271  case kTIME:
1272  str = "TIME";
1273  if (param1 < 6) {
1274  str += "(" + boost::lexical_cast<std::string>(param1) + ")";
1275  }
1276  break;
1277  case kTIMESTAMP:
1278  str = "TIMESTAMP";
1279  if (param1 <= 9) {
1280  str += "(" + boost::lexical_cast<std::string>(param1) + ")";
1281  }
1282  break;
1283  case kDATE:
1284  str = "DATE";
1285  break;
1286  default:
1287  assert(false);
1288  break;
1289  }
1290  if (is_array) {
1291  str += "[";
1292  if (array_size > 0) {
1293  str += boost::lexical_cast<std::string>(array_size);
1294  }
1295  str += "]";
1296  }
1297  return str;
1298 }
Definition: sqltypes.h:51
Definition: sqltypes.h:54
Definition: sqltypes.h:55
Definition: sqltypes.h:43
SQLTypes type
Definition: ParserNode.h:78
Definition: sqltypes.h:47
+ Here is the caller graph for this function:

Member Data Documentation

◆ array_size

int Parser::SQLType::array_size
private

Definition at line 82 of file ParserNode.h.

◆ is_array

bool Parser::SQLType::is_array
private

Definition at line 81 of file ParserNode.h.

◆ param1

int Parser::SQLType::param1
private

Definition at line 79 of file ParserNode.h.

◆ param2

int Parser::SQLType::param2
private

Definition at line 80 of file ParserNode.h.

◆ type

SQLTypes Parser::SQLType::type
private

Definition at line 78 of file ParserNode.h.


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