WORM 0.2
A C++ DAL/ORM code generation framework
Enumerations | Functions | Variables

WSql::WSqlDataType Namespace Reference

WSqlDataType namespace - Utilities and definitions of supported data types. More...

Enumerations

enum  Type {
  NOTYPE = 0, TINYINT, SMALLINT, MEDIUMINT,
  INT, BIGINT, FLOAT, DOUBLE,
  DECIMAL, DATE, DATETIME, YEAR,
  TIME, TIMESTAMP, TIMESTAMPTZ, CHAR,
  VARCHAR, NCHAR, NVARCHAR, TEXT,
  TINYTEXT, MEDIUMTEXT, LONGTEXT, ENUM,
  SET, BLOB
}

Functions

static std::string toString (Type type)
 Covenience function - returns a string for the type.
static Type toType (std::string name)
 Convenience function - translates a string to a type flag.
static std::string toSingular (const std::string &name)
 Attempt to return a singularized form of name.
static std::string toPlural (const std::string &name)
 Attempt to return a pluralized form of name.
static std::string columnNameToVariable (const std::string &columnname)
 Returns a suitable variable name transformed from columnname.
static std::string tableNameToClass (const std::string &tablename)
 Returns a transformed table name as a class name.

Variables

static const char *const TypeNames []
static const unsigned short number_of_datatypes = 26
 Number of types supported.

Detailed Description

WSqlDataType namespace - Utilities and definitions of supported data types.

This is a container for type flags and convenience functions for the supported SQL datatypes. In this namespace are definitions for datatypes, facilities for translating these to and from other naming conventions as well as facilities for generating transformations of datatypes into various strings used in the ORM generating classes.

This provides a central utility namespace for transformations and definitions related to data types as defined in DBMSs and C++, including ORM mapping of table names to class names, column names and types to variable names and types, etc.

Below is a list the ANSI SQl standard types supported by WSQL - these will be mapped to native C++ data types in ORM class generation. For example a TINYINT column will declared as a member of type "short", a VARCHAR or TEXT as type std::string, a DECIMAL to a double, etc. Implementers of drivers can use this as a guide for translating types for a particular DBMS.

Writers of drivers must translate any proprietary or other data types specific to the DBMS of the driver to these types. Most DBMS metadata is returned in a string identifier of one of these types and can usually be mapped conveniently by using the functions toString(type) or toType(string).

See the following for more information on the specific data types:

   Note: these types are modeled after the MySQL data types (which seemed the broadest
     and closest to ANSI standard). I include these notes for reference only - they are
     for determining how types will be converted..(todo)
     
    TINYINT - A very small integer that can be signed or unsigned. If signed, the
    allowable range is from -128 to 127. If unsigned, the allowable range is from 0
    to 255. You can specify a width of up to 4 digits.

    SMALLINT - A small integer that can be signed or unsigned. If signed, the
    allowable range is from -32768 to 32767. If unsigned, the allowable range is
    from 0 to 65535. You can specify a width of up to 5 digits.

    MEDIUMINT - A medium-sized integer that can be signed or unsigned. If signed,
    the allowable range is from -8388608 to 8388607. If unsigned, the allowable
    range is from 0 to 16777215. You can specify a width of up to 9 digits.

    INT - A normal-sized integer that can be signed or unsigned. If signed, the
    allowable range is from -2147483648 to 2147483647. If unsigned, the allowable
    range is from 0 to 4294967295. You can specify a width of up to 11 digits.

    BIGINT - A large integer that can be signed or unsigned. If signed, the
    allowable range is from -9223372036854775808 to 9223372036854775807. If
    unsigned, the allowable range is from 0 to 18446744073709551615. You can specify
    a width of up to 11 digits.

    FLOAT(M,D) - A floating-point number that cannot be unsigned. You can define the
    display length (M) and the number of decimals (D). This is not required and will
    default to 10,2, where 2 is the number of decimals and 10 is the total number of
    digits (including decimals). Decimal precision can go to 24 places for a FLOAT.

    DOUBLE(M,D) - A double precision floating-point number that cannot be unsigned.
    You can define the display length (M) and the number of decimals (D). This is
    not required and will default to 16,4, where 4 is the number of decimals.
    Decimal precision can go to 53 places for a DOUBLE. REAL is a synonym for
    DOUBLE.

    DECIMAL(M,D) - An unpacked floating-point number that cannot be unsigned. In
    unpacked decimals, each decimal corresponds to one byte. Defining the display
    length (M) and the number of decimals (D) is required. NUMERIC is a synonym for
    DECIMAL.

    Date and Time Types:

    DATE - A date in YYYY-MM-DD format, between 1000-01-01 and 9999-12-31. For
    example, December 30th, 1973 would be stored as 1973-12-30.

    DATETIME - A date and time combination in YYYY-MM-DD HH:MM:SS format, between
    1000-01-01 00:00:00 and 9999-12-31 23:59:59. For example, 3:30 in the afternoon
    on December 30th, 1973 would be stored as 1973-12-30 15:30:00.

    TIMESTAMP - A timestamp between midnight, January 1, 1970 and sometime in 2037.
    This looks like the previous DATETIME format, only without the hyphens between
    numbers; 3:30 in the afternoon on December 30th, 1973 would be stored as
    19731230153000 ( YYYYMMDDHHMMSS ).

    TIME - Stores the time in HH:MM:SS format.

    YEAR(M) - Stores a year in 2-digit or 4-digit format. If the length is specified
    as 2 (for example YEAR(2)), YEAR can be 1970 to 2069 (70 to 69). If the length
    is specified as 4, YEAR can be 1901 to 2155. The default length is 4.

    String Types:

    CHAR(M) - A fixed-length string between 1 and 255 characters in length (for
    example CHAR(5)), right-padded with spaces to the specified length when stored.
    Defining a length is not required, but the default is 1.

    VARCHAR(M) - A variable-length string between 1 and 255 characters in length;
    for example VARCHAR(25). You must define a length when creating a VARCHAR field.

    BLOB or TEXT - A field with a maximum length of 65535 characters. BLOBs are
    "Binary Large Objects" and are used to store large amounts of binary data, such
    as images or other types of files. Fields defined as TEXT also hold large
    amounts of data; the difference between the two is that sorts and comparisons on
    stored data are case sensitive on BLOBs and are not case sensitive in TEXT
    fields. You do not specify a length with BLOB or TEXT.

    TINYBLOB or TINYTEXT - A BLOB or TEXT column with a maximum length of 255
    characters. You do not specify a length with TINYBLOB or TINYTEXT.

    MEDIUMBLOB or MEDIUMTEXT - A BLOB or TEXT column with a maximum length of
    16777215 characters. You do not specify a length with MEDIUMBLOB or MEDIUMTEXT.

    LONGBLOB or LONGTEXT - A BLOB or TEXT column with a maximum length of 4294967295
    characters. You do not specify a length with LONGBLOB or LONGTEXT.

    ENUM - An enumeration, which is a fancy term for list. When defining an ENUM,
    you are creating a list of items from which the value must be selected (or it
    can be NULL). For example, if you wanted your field to contain "A" or "B" or
    "C", you would define your ENUM as ENUM ('A', 'B', 'C') and only those values
    (or NULL) could ever populate that field.

Enumeration Type Documentation

  • flags representing data types The types currently supported - adjust this if/when new strings are added.
Enumerator:
NOTYPE 
TINYINT 
SMALLINT 
MEDIUMINT 
INT 
BIGINT 
FLOAT 
DOUBLE 
DECIMAL 
DATE 
DATETIME 
YEAR 
TIME 
TIMESTAMP 
TIMESTAMPTZ 
CHAR 
VARCHAR 
NCHAR 
NVARCHAR 
TEXT 
TINYTEXT 
MEDIUMTEXT 
LONGTEXT 
ENUM 
SET 
BLOB 

Definition at line 68 of file wsqldatatype.h.


Function Documentation

static std::string WSql::WSqlDataType::columnNameToVariable ( const std::string &  columnname) [static]

Returns a suitable variable name transformed from columnname.

This translates a column name as defined in a database to a variable name. A column name should have the format "name" or "some_name", eg. "user" or "order_id" - these will be rendered as "user" and "orderId". Note that in contrast to tableNameToClass() the first letter is not capitalized and plural are left plural.

Parameters:
std::string- columnname - the name to transform
Return values:
std::string- a string suitable for a variable name

Definition at line 212 of file wsqldatatype.h.

static std::string WSql::WSqlDataType::tableNameToClass ( const std::string &  tablename) [static]

Returns a transformed table name as a class name.

This translates a table name as defined in a database to a class name. A table name should have the format "names" or "some_names", eg. "users" or "phone_numbers" - these will be rendered as "User" and "PhoneNumber". Note that in keeping with accepted convention the table names are plural; these will also be singularized; this results in the table "orders" being rendered as "Order" and "order_items" as "OrderItem"

Note:
This assumes that tables are named according to convention as found also in Rails - tablenames without this convention are left as is - they will be rendered but may cause problems with class instance declarations in generated output.
Parameters:
std::stringtablename - the name to transform
Return values:
std::string- a string suitable for a class name

Definition at line 244 of file wsqldatatype.h.

static std::string WSql::WSqlDataType::toPlural ( const std::string &  name) [static]

Attempt to return a pluralized form of name.

Todo:
make me a little smarter .. people, fish, sheep etc.

Definition at line 183 of file wsqldatatype.h.

static std::string WSql::WSqlDataType::toSingular ( const std::string &  name) [static]

Attempt to return a singularized form of name.

Todo:
add intelligence: std::string cmp = boost::to_lower_copy(strToReturn); if(cmp.compare("people") .. or some such ..

Definition at line 157 of file wsqldatatype.h.

static std::string WSql::WSqlDataType::toString ( Type  type) [static]

Covenience function - returns a string for the type.

Definition at line 133 of file wsqldatatype.h.

static Type WSql::WSqlDataType::toType ( std::string  name) [static]

Convenience function - translates a string to a type flag.

Todo:
intelligence - support more type names, translate to ours ..

Definition at line 144 of file wsqldatatype.h.


Variable Documentation

const unsigned short WSql::WSqlDataType::number_of_datatypes = 26 [static]

Number of types supported.

Note:
Change this if you add types!!

Definition at line 130 of file wsqldatatype.h.

const char* const WSql::WSqlDataType::TypeNames[] [static]
Initial value:
{
        "NOTYPE",
        "TINYINT",
        "SMALLINT",
        "MEDIUMINT",
        "INT",
        "BIGINT",
        "FLOAT",
        "DOUBLE",
        "DECIMAL",
        "DATE",
        "DATETIME",
        "TIME",
        "YEAR",
        "TIMESTAMP",
        "TIMESTAMPTZ",
        "CHAR",
        "VARCHAR",
        "NCHAR",
        "NVARCHAR",
        "TEXT",
        "TINYTEXT",
        "MEDIUMTEXT",
        "LONGTEXT",
        "ENUM",
        "SET",
        "BLOB"
    }

TypeNames - array of strings representing data types The types currently supported in handy string format - adjust this if/when new strings are added.

Definition at line 100 of file wsqldatatype.h.

 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Defines