On Tue, Mar 5, 2013 at 12:18 PM, Nicolas Deroche <[email protected]>wrote:
> Thanks 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
> the website !
>
You are right, sorry about that!
>
> In 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
> values
>
I completely agree, there is no reason why v.get<short>(...) shouldn't work
as long as the actual value is in the short's range, no matter what type it
had in the database.
Thanks,
Aleksander
> - bool's, and something else for other specific types.
>
> IMO, this could give some noob-friendly startup for the library !
>
> Thanks again,
>
> nico
>
>
> 2013/3/5 Pawel Aleksander Fedorynski <[email protected]>
>
>>
>>
>> Hello Nico,
>>
>> Right now SOCI (or at least the MySQL backend) is very strict about the
>> types when using the row interface. This is often inconvenient and we
>> should probably change it. But for now the rules are:
>>
>> - All integer types smaller than INT are promoted to int, regardless
>> whether the original type was signed or unsigned. So, e.g., if you select
>> a value of type TINYINT UNSIGNED, you should retrieve it from the rowset
>> using v.get<int>("id").
>>
>> - INT is retrieved as int: v.get<int>("id")
>>
>> - INT UNSIGNED is retrieved as (signed) long long: v.get<long
>> long>("id"), although this will work too: v.get<unsigned>("id").
>>
>> - BIGINT is retrieved as long long.
>>
>> - BIGINT UNSIGNED is retrieved as unsigned long long.
>>
>> If you don't know the type that was selected form the database, you can
>> use v.get_properties("id").get_data_type() to find out. It will be
>> dt_unsigned_long_long for BIGINT UNSIGNED, dt_long_long for BIGINT and INT
>> UNSIGNED, and dt_integer for all the smaller integral types.
>>
>> Unless I'm mistaken this problem only pertains to the row interface
>> (dynamic binding), when you use static binding, i.e., into(n) this should
>> be more forgiving with respect to types.
>>
>> Thanks,
>>
>> Aleksander
>>
>> On Tue, Mar 5, 2013 at 6:21 AM, Nicolas Deroche <[email protected]>wrote:
>>
>>>
>>> Hello,
>>>
>>> I just started using SOCI, and I have one quick question about casting
>>>
>>> Consider this structure:
>>> struct A
>>> { unsigned long one; unsigned int two; unsigned short three; }
>>>
>>> In MySQL, the fields are defined like:
>>> one : INT unsigned
>>> two: SMALLINT unsigned
>>> three: TINYINT unsigned
>>>
>>> How am I supposed to cast using the static templated function from_base
>>> the SQL values into my structure?
>>> static void from_base(values const & v, indicator /* ind */, A& s)
>>> {
>>> s.one = v.get<unsigned long>("id"); /// Throws std::bad_cast()
>>> }
>>>
>>> Thanks,
>>>
>>> nico
>>>
>>>
>>>
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Everyone hates slow websites. So do we.
>>> Make your web apps faster with AppDynamics
>>> Download AppDynamics Lite for free today:
>>> http://p.sf.net/sfu/appdyn_d2d_feb
>>> _______________________________________________
>>> soci-users mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/soci-users
>>>
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Everyone hates slow websites. So do we.
>> Make your web apps faster with AppDynamics
>> Download AppDynamics Lite for free today:
>> http://p.sf.net/sfu/appdyn_d2d_feb
>> _______________________________________________
>> soci-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/soci-users
>>
>>
>
>
> ------------------------------------------------------------------------------
> Everyone hates slow websites. So do we.
> Make your web apps faster with AppDynamics
> Download AppDynamics Lite for free today:
> http://p.sf.net/sfu/appdyn_d2d_feb
> _______________________________________________
> soci-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/soci-users
>
>
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
soci-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/soci-users