OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 70 of file ParserNode.h.

Constructor & Destructor Documentation

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

Definition at line 72 of file ParserNode.h.

73  : type(t), param1(-1), param2(0), is_array(false), array_size(-1) {}
SQLTypes type
Definition: ParserNode.h:89
Parser::SQLType::SQLType ( SQLTypes  t,
int  p1 
)
inline

Definition at line 74 of file ParserNode.h.

75  : type(t), param1(p1), param2(0), is_array(false), array_size(-1) {}
SQLTypes type
Definition: ParserNode.h:89
Parser::SQLType::SQLType ( SQLTypes  t,
int  p1,
int  p2,
bool  a 
)
inline

Definition at line 76 of file ParserNode.h.

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

Member Function Documentation

void Parser::SQLType::check_type ( )

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

1893  {
1894  switch (type) {
1895  case kCHAR:
1896  case kVARCHAR:
1897  if (param1 <= 0) {
1898  throw std::runtime_error("CHAR and VARCHAR must have a positive dimension.");
1899  }
1900  break;
1901  case kDECIMAL:
1902  case kNUMERIC:
1903  if (param1 <= 0) {
1904  throw std::runtime_error("DECIMAL and NUMERIC must have a positive precision.");
1905  } else if (param1 > 19) {
1906  throw std::runtime_error(
1907  "DECIMAL and NUMERIC precision cannot be larger than 19.");
1908  } else if (param1 <= param2) {
1909  throw std::runtime_error(
1910  "DECIMAL and NUMERIC must have precision larger than scale.");
1911  }
1912  break;
1913  case kTIMESTAMP:
1914  if (param1 == -1) {
1915  param1 = 0; // set default to 0
1916  } else if (param1 != 0 && param1 != 3 && param1 != 6 &&
1917  param1 != 9) { // support ms, us, ns
1918  throw std::runtime_error(
1919  "Only TIMESTAMP(n) where n = (0,3,6,9) are supported now.");
1920  }
1921  break;
1922  case kTIME:
1923  if (param1 == -1) {
1924  param1 = 0; // default precision is 0
1925  }
1926  if (param1 > 0) { // @TODO(wei) support sub-second precision later.
1927  throw std::runtime_error("Only TIME(0) is supported now.");
1928  }
1929  break;
1930  case kPOINT:
1931  case kLINESTRING:
1932  case kPOLYGON:
1933  case kMULTIPOLYGON:
1934  // Storing SRID in param1
1935  break;
1936  default:
1937  param1 = 0;
1938  break;
1939  }
1940 }
Definition: sqltypes.h:52
Definition: sqltypes.h:44
SQLTypes type
Definition: ParserNode.h:89

+ Here is the caller graph for this function:

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

Definition at line 83 of file ParserNode.h.

References array_size.

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

83 { return array_size; }

+ Here is the caller graph for this function:

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

Definition at line 81 of file ParserNode.h.

References is_array.

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

81 { return is_array; }

+ Here is the caller graph for this function:

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

Definition at line 79 of file ParserNode.h.

References param1.

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

79 { return param1; }

+ Here is the caller graph for this function:

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

Definition at line 80 of file ParserNode.h.

References param2.

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

80 { return param2; }

+ Here is the caller graph for this function:

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

Definition at line 78 of file ParserNode.h.

References type.

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

78 { return type; }
SQLTypes type
Definition: ParserNode.h:89

+ Here is the caller graph for this function:

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

Definition at line 84 of file ParserNode.h.

References array_size.

84 { array_size = s; }
void Parser::SQLType::set_is_array ( bool  a)
inline

Definition at line 82 of file ParserNode.h.

References is_array.

82 { is_array = a; }
std::string Parser::SQLType::to_string ( ) const

Definition at line 1239 of file ParserNode.cpp.

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

1239  {
1240  std::string str;
1241  switch (type) {
1242  case kBOOLEAN:
1243  str = "BOOLEAN";
1244  break;
1245  case kCHAR:
1246  str = "CHAR(" + boost::lexical_cast<std::string>(param1) + ")";
1247  break;
1248  case kVARCHAR:
1249  str = "VARCHAR(" + boost::lexical_cast<std::string>(param1) + ")";
1250  break;
1251  case kTEXT:
1252  str = "TEXT";
1253  break;
1254  case kNUMERIC:
1255  str = "NUMERIC(" + boost::lexical_cast<std::string>(param1);
1256  if (param2 > 0) {
1257  str += ", " + boost::lexical_cast<std::string>(param2);
1258  }
1259  str += ")";
1260  break;
1261  case kDECIMAL:
1262  str = "DECIMAL(" + boost::lexical_cast<std::string>(param1);
1263  if (param2 > 0) {
1264  str += ", " + boost::lexical_cast<std::string>(param2);
1265  }
1266  str += ")";
1267  break;
1268  case kBIGINT:
1269  str = "BIGINT";
1270  break;
1271  case kINT:
1272  str = "INT";
1273  break;
1274  case kTINYINT:
1275  str = "TINYINT";
1276  break;
1277  case kSMALLINT:
1278  str = "SMALLINT";
1279  break;
1280  case kFLOAT:
1281  str = "FLOAT";
1282  break;
1283  case kDOUBLE:
1284  str = "DOUBLE";
1285  break;
1286  case kTIME:
1287  str = "TIME";
1288  if (param1 < 6) {
1289  str += "(" + boost::lexical_cast<std::string>(param1) + ")";
1290  }
1291  break;
1292  case kTIMESTAMP:
1293  str = "TIMESTAMP";
1294  if (param1 <= 9) {
1295  str += "(" + boost::lexical_cast<std::string>(param1) + ")";
1296  }
1297  break;
1298  case kDATE:
1299  str = "DATE";
1300  break;
1301  default:
1302  assert(false);
1303  break;
1304  }
1305  if (is_array) {
1306  str += "[";
1307  if (array_size > 0) {
1308  str += boost::lexical_cast<std::string>(array_size);
1309  }
1310  str += "]";
1311  }
1312  return str;
1313 }
Definition: sqltypes.h:52
Definition: sqltypes.h:55
Definition: sqltypes.h:56
int64_t const int32_t sz assert(dest)
Definition: sqltypes.h:44
SQLTypes type
Definition: ParserNode.h:89
Definition: sqltypes.h:48

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

int Parser::SQLType::array_size
private

Definition at line 93 of file ParserNode.h.

Referenced by get_array_size(), and set_array_size().

bool Parser::SQLType::is_array
private

Definition at line 92 of file ParserNode.h.

Referenced by get_is_array(), and set_is_array().

int Parser::SQLType::param1
private

Definition at line 90 of file ParserNode.h.

Referenced by get_param1().

int Parser::SQLType::param2
private

Definition at line 91 of file ParserNode.h.

Referenced by get_param2().

SQLTypes Parser::SQLType::type
private

Definition at line 89 of file ParserNode.h.

Referenced by get_type().


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