ïż
reference:conversions [www.ibpp.org]
[[reference:conversions]]
http://www.ibpp.org/
You are here: ibpp  reference  conversions
Table of Contents
Type
Conversions
Mappings
CHAR and
VARCHAR
SMALLINT,
INTEGER, BIGINT
NUMERIC,
DECIMAL
FLOAT
DOUBLE
TIMESTAMP
DATE
TIME
BLOB
ARRAY
Type Conversions
The bulk of programming with IBPP to interact with a Firebird database is to
exchange values with the database, reading columns values and inserting or
updating columns values. SQL has a number of basic types and
C++ has its own set of primitive types. This article discusses relationships
between both worlds, in the context of IBPP.
Mappings
CHAR and VARCHAR
Reading or writing a CHAR or VARCHAR column is usually done using a
std::string variable. There are no numeric to string or string to numeric
implicit conversions.
There is an exception to this rule, regarding the C++ bool. You can store and
read a bool to/from a CHAR or VARCHAR. Here is the mapping that will happen in
such case.
Writing a bool to a CHAR : a leading â€ÅšT’ or â€ÅšF’ (true or false)
will be written, other characters set to ' ' (space)
Writing a bool to a VARCHAR : a leading â€ÅšT’ or â€ÅšF’ will be
written and the VARCHAR content length set to 1 character
Reading a bool from a CHAR : if the leading character is any of
â€Åšt’, â€ÅšT’, â€Åšy’, â€ÅšY’, or â€Åš1’, store a true, else a false
Reading a bool from a VARCHAR : if the leading character is any
of â€Åšt’, â€ÅšT’, â€Åšy’, â€ÅšY’, or â€Åš1’, store a true, else a false
SMALLINT,
INTEGER, BIGINT
Any of these 3 integer sizes (16, 32 and 64 bits) can be mixed with any
integer size on the C++ side. IBPP will make the appropriate conversions, and
will only throw an exception if an overflow occurs. For instance, storing a 64
bits column to a int16_t is valid, as long as at runtime the value transferred
does not overflow the capacity of the int16_t.
C++ bool can also be used with integer SQL columns on the basis that a 0
means false and anything else means true (when storing, IBPP always writes 1 for
a true, but it is relaxed on reading).
NUMERIC, DECIMAL
Those exact precision SQL types are actually stored in
integer quantities, taking a scaling factor into account, which is declared in
the metadata. IBPP permits to handle these SQL types with C++ float or double,
or integer types. When exchanging these values with integer types, one must
understand that the actual scaled integer value is exchanged. For instance,
NUMERIC(9,2) stores values as integers by multiplying them by a scaling factor
of 100 (FB stores 1234 when you intend 12.34).
When exchanging such a column with a float or a double, IBPP applies the
scaling factor and returns or expects 12.34 in the float or double variable.
When exchanging with an integer type, IBPP returns or expects the value as
is, that is the integer value 1234 in this example.
FLOAT
This floating point SQL
type requires a C++ float variable.
DOUBLE
This floating point SQL
type requires a C++ double variable.
TIMESTAMP
Maps to an IBPP::Timestamp type.
DATE
Maps to an IBPP::Date type.
TIME
Maps to an IBPP::Time type.
BLOB
Maps to an IBPP::Blob type.
ARRAY
Maps to an IBPP::Array type.
reference\conversions.txt · Last modified: 2006/03/30 18:12 by
olivier
Wyszukiwarka
Podobne podstrony:
referenceeventinterface [www ibpp org]referencetimestamp [www ibpp org]reference [www ibpp org]referenceevents [www ibpp org]referencesamples [www ibpp org]referenceexceptions [www ibpp org]referencearray [www ibpp org]referencecompilers [www ibpp org]referenceblob [www ibpp org]referenceclientlibsearchpaths [www ibpp org]referencedate [www ibpp org]referencetime [www ibpp org]referenceguidelines [www ibpp org]referencedatabase [www ibpp org]referenceuser [www ibpp org]referencetransaction [www ibpp org]referencestatement [www ibpp org]referenceoverview [www ibpp org]referenceservice [www ibpp org]więcej podobnych podstron