Advertisement
jacknpoe

retinens

Oct 18th, 2013
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.09 KB | None | 0 0
  1. //########################### RETINENS (DEVELOPMENT VERSION 2013-10-19)
  2.  
  3. #include <string>
  4.  
  5. namespace retinens{
  6. //########################### STRUCT FOR DATA TYPES DESCRIPTION
  7.     typedef struct {
  8.         bool instantiable;
  9.         bool sized;     // have size or precision
  10.         long maxsize;
  11.         bool scaled;    // have decimal or scale
  12.         char maxscale;
  13.         bool limitedscale;
  14.         bool autovalue; // can't have default or autovalue in field description or be updated
  15.         bool isxml;
  16.         std::string description;
  17.     } DataTypeDescription;
  18.  
  19. //########################### ENUMS FOR SQL DATA TYPES
  20.  
  21. //########################### ISO SQL DATA TYPES (C-Style) ISOSQLDataType
  22.     typedef enum {
  23.         ISO_NONE,
  24. // INTEGERS / BOOLEAN
  25.         ISO_BIGINT,
  26.         ISO_INTEGER,
  27.         ISO_SMALLINT,
  28.         ISO_INTEGER10TO18,     // INTEGER() equivalent to a BIGINT
  29.         ISO_INTEGER5TO9,       // INTEGER() equivalent to a INTEGER
  30.         ISO_INTEGER3TO4,       // INTEGER() equivalent to a SMALLINT
  31.         ISO_INTEGER1TO2,       // INTEGER() equivalent to a BYTE (only specific DBMS)
  32.         ISO_INTEGERN,          // general INTEGER()
  33.         ISO_BOOLEAN,
  34. // NUMERICAL AND APPROXIMATE NUMERICAL
  35.         ISO_DECIMAL,     // SAME AS NUMERIC
  36.         ISO_NUMERIC,     // SAME AS DECIMAL
  37.         ISO_FLOAT,       // SOME AS DOUBLEPRECISION
  38.         ISO_REAL,
  39.         ISO_DOUBLEPRECISION,     // SAME AS FLOAT
  40.         ISO_FLOAT1TO7,           // FLOAT() equivalent to a REAL
  41.         ISO_FLOAT8TO16,          // FLOAT() equivalent to a FLOAT
  42.         ISO_FLOATN,              // general FLOAT()
  43. // TIME
  44.         ISO_DATE,
  45.         ISO_TIME,
  46.         ISO_TIMESTAMP,
  47.         ISO_TIMEZ,
  48.         ISO_TIMESTAMPZ,
  49. // TEXT NON-UNICODE
  50.         ISO_CHARACTER,
  51.         ISO_CHARACTERVARYING,     // SAME AS VARCHAR
  52.         ISO_VARCHAR,              // SAME AS CHARACTERVARYING
  53.         ISO_CHARACTERVARYINGMAX,  // SAME AS VARCHARMAX
  54.         ISO_VARCHARMAX,           // SAME AS CHARACTERVARYINGMAX
  55.         ISO_CHARACTERLARGEOBJECT,
  56. // TEXT UNICODE
  57.         ISO_NATIONALCHARACTER,
  58.         ISO_NATIONALCHARACTERVARYING,
  59.         ISO_NATIONALCHARACTERVARYINGMAX,
  60.         ISO_NATIONALCHARACTERLARGEOBJECT,
  61. // BINARY
  62.         ISO_BINARY,
  63.         ISO_BINARYVARYING,     // SAME AS VARBINARY
  64.         ISO_VARBINARY,         // SAME AS BINARYVARYING
  65.         ISO_BINARYVARYINGMAX,  // SAME AS VARBINARYMAX
  66.         ISO_VARBINARYMAX,      // SAME AS BINARYVARYINGMAX
  67.         ISO_BINARYLARGEOBJECT,
  68. // OTHERS
  69.         ISO_ARRAY,
  70.         ISO_MULTISET,
  71.         ISO_XML,
  72. // INTERVAL
  73.         ISO_INTERVAL,     // GENERAL INTERVAL FOR SINGLE CONVERSION
  74.         ISO_YEAR,
  75.         ISO_MONTH,
  76.         ISO_YEARTOMONTH,
  77.         ISO_DAY,
  78.         ISO_HOUR,
  79.         ISO_MINUTE,
  80.         ISO_SECOND,
  81.         ISO_DAYTOHOUR,
  82.         ISO_DAYTOMINUTE,
  83.         ISO_DAYTOSECOND,
  84.         ISO_HOURTOMINUTE,
  85.         ISO_HOURTOSECOND,
  86.         ISO_MINUTETOSECOND
  87.     } ISOSQLDataType;
  88.  
  89. //########################### ISO SQL DATA TYPES DESCRIPTION
  90.     DataTypeDescription ISOSQLDataTypeDescription[ ISO_MINUTETOSECOND + 1] {
  91. // INTEGERS / BOOLEAN      
  92.         { false, false, 0, false, 0, false, false, false, "<indefined>" },
  93.         { true,  false, 0, false, 0, false, false, false, "bigint" },
  94.         { true,  false, 0, false, 0, false, false, false, "integer" },
  95.         { true,  false, 0, false, 0, false, false, false, "smallint" },
  96.         { false, false, 0, false, 0, false, false, false, "integer( 10-18)" },
  97.         { false, false, 0, false, 0, false, false, false, "integer( 5-9)" },
  98.         { false, false, 0, false, 0, false, false, false, "integer( 3-4)" },
  99.         { false, false, 0, false, 0, false, false, false, "integer( 1-2)" },
  100.         { true,  true, 45, false, 0, false, false, false, "integer( p)" },
  101.         { true,  false, 0, false, 0, false, false, false, "boolean" },
  102. // NUMERICAL AND APPROXIMATE NUMERICAL
  103.         { true,  true,  45, true,  0, true,  false, false, "decimal( p, s)" },
  104.         { true,  true,  45, true,  0, true,  false, false, "numeric( p, s)" },
  105.         { true,  false,  0, false, 0, false, false, false, "float" },
  106.         { true,  false,  0, false, 0, false, false, false, "real" },
  107.         { true,  false,  0, false, 0, false, false, false, "double precision" },
  108.         { false, false,  0, false, 0, false, false, false, "float( 1-7)" },
  109.         { false, false,  0, false, 0, false, false, false, "float( 8-16)" },
  110.         { true,  true,  45, false, 0, false, false, false, "float( p)" },
  111. // TIME
  112.         { true, false, 0, false, 0, false, false, false, "date" },
  113.         { true, true,  9, false, 0, false, false, false, "time" },
  114.         { true, true,  9, false, 0, false, false, false, "timestamp" },
  115.         { true, true,  9, false, 0, false, false, false, "timez" },
  116.         { true, true,  9, false, 0, false, false, false, "timestampz" },
  117. // TEXT NON-UNICODE
  118.         { true, true,  8000,      false, 0, false, false, false, "character( n)" },
  119.         { true, true,  8000,      false, 0, false, false, false, "character varying( n)" },
  120.         { true, true,  8000,      false, 0, false, false, false, "varchar( n)" },
  121.         { true, false, 0,         false, 0, false, false, false, "character varying( max)" },
  122.         { true, false, 0,         false, 0, false, false, false, "varchar( max)" },
  123.         { true, true, 2147483647, false, 0, false, false, false, "character large object" },
  124. // TEXT UNICODE
  125.         { true, true,  4000,      false, 0, false, false, false, "national character( n)" },
  126.         { true, true,  4000,      false, 0, false, false, false, "national character varying( n)" },
  127.         { true, false, 0,         false, 0, false, false, false, "national character varying( max)" },
  128.         { true, true, 2147483647, false, 0, false, false, false, "national character large object" },
  129. // BINARY
  130.         { true, true,  8000,      false, 0, false, false, false, "binary( n)" },
  131.         { true, true,  8000,      false, 0, false, false, false, "binary varying( n)" },
  132.         { true, true,  8000,      false, 0, false, false, false, "varbinary( n)" },
  133.         { true, false, 0,         false, 0, false, false, false, "binary varying( max)" },
  134.         { true, false, 0,         false, 0, false, false, false, "varbinary( max)" },
  135.         { true, true, 2147483647, false, 0, false, false, false, "binary large object" },
  136. // OTHERS
  137.         { true, false, 0, false, 0, false, false, false, "array" },
  138.         { true, false, 0, false, 0, false, false, false, "multiset" },
  139.         { true, false, 0, false, 0, false, false, true,  "xml" },
  140. // INTERVAL
  141.         { false, false, 0, false, 0, false, false, false, "interval" },
  142.         { true,  true,  4, false, 0, false, false, false, "year" },
  143.         { true,  true,  4, false, 0, false, false, false, "month" },
  144.         { true,  true,  4, false, 0, false, false, false, "year to month" },
  145.         { true,  true,  4, false, 0, false, false, false, "day" },
  146.         { true,  true,  4, false, 0, false, false, false, "hour" },
  147.         { true,  true,  4, true,  9, false, false, false, "minute" },
  148.         { true,  true,  4, false, 0, false, false, false, "second" },
  149.         { true,  true,  4, false, 0, false, false, false, "day to hour" },
  150.         { true,  true,  4, false, 0, false, false, false, "day to minute" },
  151.         { true,  true,  4, true,  9, false, false, false, "day to second" },
  152.         { true,  true,  4, false, 0, false, false, false, "hour to minute" },
  153.         { true,  true,  4, true,  9, false, false, false, "hour to second" },
  154.         { true,  true,  4, true,  9, false, false, false, "minute to second" }
  155.     };
  156.  
  157. //########################### SQL SERVER DATA TYPES (C-Style) SQLServerDataType
  158.     typedef enum SQLServerDataType{
  159.         SQLS_NONE
  160.     } SQLServerDataType;
  161. }
  162.  
  163. //########################### TEST SECTION
  164.  
  165. #include<iostream>
  166.  
  167. using namespace std;
  168.  
  169. int main( void){
  170.     retinens::ISOSQLDataType test;
  171.     int int_test;
  172.  
  173.     test = retinens::ISO_NATIONALCHARACTERVARYINGMAX;
  174.     int_test = test;
  175.     cout << "Integer value to retinens::ISO_NATIONALCHARACTERVARYINGMAX: " << int_test << endl;
  176.     test = retinens::ISO_NONE;
  177.     int_test = test;
  178.     cout << "Integer value to retinens::ISO_NONE: " << int_test << endl;
  179.     test = retinens::ISO_MINUTETOSECOND;
  180.     int_test = test;
  181.     cout << "Integer value to retinens::ISO_MINUTETOSECOND: " << int_test << endl;
  182.     int_test = 9;
  183.     cout << "Value 9 is retinens::ISO_BOOLEAN? " << ( int_test == int( retinens::ISO_BOOLEAN) ? "Y" : "N") << endl;
  184.  
  185.     test = retinens::ISO_NUMERIC;
  186.     int_test = test;
  187.     cout << endl << "Description for retinens::ISO_NUMERIC: " << endl;
  188.     cout << "Is it instantiable? " << ( retinens::ISOSQLDataTypeDescription[ int_test].instantiable ? "Y" : "N") << endl;
  189.     cout << "Have size or precision?  " << ( retinens::ISOSQLDataTypeDescription[ int_test].sized ? "Y" : "N") << endl;
  190.     cout << "Maximum size: " << retinens::ISOSQLDataTypeDescription[ int_test].maxsize << endl;
  191.     cout << "Have decimal or scale? " << ( retinens::ISOSQLDataTypeDescription[ int_test].scaled ? "Y" : "N") << endl;
  192.     cout << "Maximum scale (if any): " << int( retinens::ISOSQLDataTypeDescription[ int_test].maxscale) << endl;
  193.     cout << "Is it scale limited to size? " << ( retinens::ISOSQLDataTypeDescription[ int_test].limitedscale ? "Y" : "N") << endl;
  194.     cout << "Is default (or autovalue) forbidden? " << ( retinens::ISOSQLDataTypeDescription[ int_test].autovalue ? "Y" : "N") << endl;
  195.     cout << "Is it a xml type? " << ( retinens::ISOSQLDataTypeDescription[ int_test].isxml ? "Y" : "N") << endl;
  196.     cout << "Description: " << retinens::ISOSQLDataTypeDescription[ int_test].description << endl;
  197.  
  198.     test = retinens::ISO_XML;
  199.     int_test = test;
  200.     cout << endl << "Description for retinens::ISO_XML: " << endl;
  201.     cout << "Is it instantiable? " << ( retinens::ISOSQLDataTypeDescription[ int_test].instantiable ? "Y" : "N") << endl;
  202.     cout << "Have size or precision?  " << ( retinens::ISOSQLDataTypeDescription[ int_test].sized ? "Y" : "N") << endl;
  203.     cout << "Maximum size: " << retinens::ISOSQLDataTypeDescription[ int_test].maxsize << endl;
  204.     cout << "Have decimal or scale? " << ( retinens::ISOSQLDataTypeDescription[ int_test].scaled ? "Y" : "N") << endl;
  205.     cout << "Maximum scale (if any): " << int( retinens::ISOSQLDataTypeDescription[ int_test].maxscale) << endl;
  206.     cout << "Is it scale limited to size? " << ( retinens::ISOSQLDataTypeDescription[ int_test].limitedscale ? "Y" : "N") << endl;
  207.     cout << "Is default (or autovalue) forbidden? " << ( retinens::ISOSQLDataTypeDescription[ int_test].autovalue ? "Y" : "N") << endl;
  208.     cout << "Is it a xml type? " << ( retinens::ISOSQLDataTypeDescription[ int_test].isxml ? "Y" : "N") << endl;
  209.     cout << "Description: " << retinens::ISOSQLDataTypeDescription[ int_test].description << endl;
  210.  
  211.     test = retinens::ISO_DAYTOSECOND;
  212.     int_test = test;
  213.     cout << endl << "Description for retinens::ISO_DAYTOSECOND: " << endl;
  214.     cout << "Is it instantiable? " << ( retinens::ISOSQLDataTypeDescription[ int_test].instantiable ? "Y" : "N") << endl;
  215.     cout << "Have size or precision?  " << ( retinens::ISOSQLDataTypeDescription[ int_test].sized ? "Y" : "N") << endl;
  216.     cout << "Maximum size: " << retinens::ISOSQLDataTypeDescription[ int_test].maxsize << endl;
  217.     cout << "Have decimal or scale? " << ( retinens::ISOSQLDataTypeDescription[ int_test].scaled ? "Y" : "N") << endl;
  218.     cout << "Maximum scale (if any): " << int( retinens::ISOSQLDataTypeDescription[ int_test].maxscale) << endl;
  219.     cout << "Is it scale limited to size? " << ( retinens::ISOSQLDataTypeDescription[ int_test].limitedscale ? "Y" : "N") << endl;
  220.     cout << "Is default (or autovalue) forbidden? " << ( retinens::ISOSQLDataTypeDescription[ int_test].autovalue ? "Y" : "N") << endl;
  221.     cout << "Is it a xml type? " << ( retinens::ISOSQLDataTypeDescription[ int_test].isxml ? "Y" : "N") << endl;
  222.     cout << "Description: " << retinens::ISOSQLDataTypeDescription[ int_test].description << endl;
  223. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement