kSQL_NONE = -1, // data type unknown
kSQL_CHAR = 1, // CHAR(n) - string with fixed length n
kSQL_VARCHAR = 2, // VARCHAR(n) - string with variable length upto n
kSQL_INTEGER = 3, // INTEGER, INT - integer value
kSQL_FLOAT = 4, // FLOAT - float value
kSQL_DOUBLE = 5, // DOUBLE - double value
kSQL_NUMERIC = 6, // NUMERIC - numeric values with length and precion
kSQL_BINARY = 7, // BLOB - binary data
kSQL_TIMESTAMP = 8 // TIMESTAMP
};
1 MYSQL_TYPE_TINY TINYINT field
2 MYSQL_TYPE_SHORT SMALLINT field
3 MYSQL_TYPE_LONG INTEGER field
9 MYSQL_TYPE_INT24 MEDIUMINT field
8 MYSQL_TYPE_LONGLONG BIGINT field
MYSQL_TYPE_DECIMAL DECIMAL or NUMERIC field
246 MYSQL_TYPE_NEWDECIMAL Precision math DECIMAL or NUMERIC field (MySQL 5.0.3 and up)
4 MYSQL_TYPE_FLOAT FLOAT field
5 MYSQL_TYPE_DOUBLE DOUBLE or REAL field
MYSQL_TYPE_BIT BIT field (MySQL 5.0.3 and up)
7 MYSQL_TYPE_TIMESTAMP TIMESTAMP field
10 MYSQL_TYPE_DATE DATE field
11 MYSQL_TYPE_TIME TIME field
12 MYSQL_TYPE_DATETIME DATETIME field
13 MYSQL_TYPE_YEAR YEAR field
254 MYSQL_TYPE_STRING CHAR or BINARY field
253 MYSQL_TYPE_VAR_STRING VARCHAR or VARBINARY field
252 MYSQL_TYPE_BLOB BLOB or TEXT field (use max_length to determine the maximum length)
248 MYSQL_TYPE_SET SET field
MYSQL_TYPE_ENUM ENUM field
MYSQL_TYPE_GEOMETRY Spatial field
6 MYSQL_TYPE_NULL NULL-type field
MYSQL_TYPE_CHAR Deprecated; use MYSQL_TYPE_TINY instead.
Conversions are handled DbiFieldType which can be created from:-
1) DbiFieldType(Int_t type = Dbi::kInt);
Where:-
type corresponds to ROOT's types (Dbi:: DataTypes)
2) DbiFieldType(Int_t type,
Int_t size,
const char* typeName);
Where:-
type value from TSQLColumnInfo::GetSQLType()
size value from TSQLColumnInfo::GetLength()
dbType value from TSQLColumnInfo::GetTypeName()
3) DbiFieldType(const string& sql precision);
Where:-
sql A MySQL type as a string.
It can be used to generate:-
1) string AsString() const;
The C++ name, but with first letter capitalised and extended to
include TString and Date
2) string AsSQLString(Dbi::DbTypes dbType = Dbi::kMySQL) const;
The MySQL type as a string.
The various mapping are list below.
Standard Mappings
---- DbiFieldType ----- ---- Root ---- TSQL ---- MySQL ---- Type Concept Size Type DataTypes type type len Bool Bool 1 Bool 1 Tiny Int 1 Tiny 4 3 TINYINT 4 UTiny Int 1 UTiny 5 Short Int 2 Short 6 3 SMALLINT 6 UShort UInt 2 UShort 7 Int Int 4 Int 8 3 INT 11 UInt UInt 4 UInt 9 Long Int 8 Long 10 3 BIGINT 20 ULong UInt 8 ULong 11 Float Float 4 Float 12 4 FLOAT 12 Double Float 8 Double 13 5 DOUBLE 22 Char Char 1 Char 2 1 CHAR 1 UChar UChar 1 UChar 3 String String 255 2 TINTTEXT -1 String String 65535 String 14 2 TEXT -1 TString String 65535 TString 15 Date Date 19 Date 16 8 DATETIME 19 Unknown Unknown 0 Unknown 0 -1 Char Char i 1 CHAR(i) i String String i 2 VARCHAR(i) iNotes
To achieve this the DbiOutRowStream operator << methods for unsigned integers first converts the value to signed (using a cast to preserve the bits) and then tests to see if the sign bit (whose position is determined by the capacity of the receiving column is set, and if so extends the sign bit.
Historical note: the code still has partial support for unsigned database types, which explains why it still tests to see that it is signed before doing the conversion.