Post by Mateusz LoskotPost by Nicolas DerocheThanks for the reply,
I figured out casting from v.get<int> to C++'s unsigned long doesn't make
any data loss, as you said in your mail
I'd like to point out the lack of this information on the documentation
on
There is however documentation here
http://soci.sourceforge.net/doc/exchange.html#dynamic
and link to backend-specific pages below the small table.
I agree, this could be documented better, certainly.
I updated the documentation for the MySQL backend listing all the types and
what they currently convert to.
Post by Mateusz LoskotIf you see anything missing or you'd like to suggest any improvement,
feel more than welcome to open issue ticket at
https://github.com/SOCI/soci
Post by Nicolas DerocheIn the future, I hope this could change, and be able to use directly C++
types in the get<T> template function, or at least something less strict
like
- short (0 to 255); int (0 to 65K); long (0 to 4M); and long 64 for
greate
Post by Nicolas Derochevalues
- bool's, and something else for other specific types.
IMO, this could give some noob-friendly startup for the library !
You're right. We are aware it causes lots of confusions [1], including
to myself [2].
As Aleksander mentioned, we most likely will change that in future.
Personally, I think we should gear towards "C++ types first" approach
and try to cover them in a way most natural from C++ perspective.
There are two questions here.
1. What is the mapping between SQL types and SOCI types. The answer will
probably be backend specific, since various databases may have different
integral types. The current answer for MySQL is (as of my most recent
commit) documented in backends/mysql.html. I think what we have there is
pretty natural from the C++ perspective:
- All integral types (signed or unsigned) with less than 4 bytes should be
mapped to dt_integer, which corresponds to C++ type int, which in practice
is always 4 bytes in C++.
- Four byte signed integer should also be mapped to dt_integer.
- Four byte unsigned integer should be mapped to dt_long_long, which
corresponds to C++ type long long.
- Eight byte signed integer should be mapped to dt_long_long.
- Eight byte unsigned integer should be mapped to dt_unsigned_long_long.
The backends probably shouldn't change their mapping too willy-nilly since
existing code may depend on it.
2. How flexible SOCI should be when the user tries to read a field value
into a variable of a different type.
This is the actual problem. We're rather unforgiving. We should become
more lenient: it is just sad that when you select a value from a SMALLINT
column and try to read it using r.get<short>(...), which is exactly the
matching type, you get std::bad_cast.
It is not clear how much more lenient exactly.
(a) One option is to look at the actual value and only throw when the value
is out of range for the requested type. I.e., if the column is of type
BIGINT but the actual value read is 1234 then let the user interpret it as
short. If the column is INT but the actual value is positive then let the
user interpret it as unsigned.
(b) Another option is to look at the ranges of types, e.g., if the column
is of type SMALLINT (two byte signed integer), the user should be able to
interpret the values as short, or int, or long long, but not as char.
Also, interpreting values from column of signed types as unsigned C++
types would never be allowed.
As a user I'd slightly prefer (a). I don't know which will be easier to
implement.
Thanks,
Aleksander
I'm slowly sketching document [3] where I'm going to describe proposal on
Post by Mateusz Loskothow
we want to handle C++ integers, in core and backends.
Any input will be appreciated.
[1] https://github.com/SOCI/soci/issues/90
[2] http://sourceforge.net/mailarchive/message.php?msg_id=30443672
[3] https://github.com/SOCI/soci/wiki/RFC1
Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net
------------------------------------------------------------------------------
Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester
Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the
endpoint security space. For insight on selecting the right partner to
tackle endpoint security challenges, access the full report.
http://p.sf.net/sfu/symantec-dev2dev
_______________________________________________
soci-users mailing list
https://lists.sourceforge.net/lists/listinfo/soci-users