On 25/10/10 15:28, Henning Basold wrote:
> Hi,
> 
> hopefully I've not overlooked another thread which covers this issue.
> 
> The problem is that I want to use std::size_t through soci::row. This
> is not possible because it's base_type is long long which expands to
> _int64 on MSVC. row::operator>> now calls row::get which in turn tries
> a dynamic_cast of holder<int> to holder<_int64> which is not possible.
> This leads to a bad_cast.
> 
> Is there any way to fix this? At the moment I select into an int and
> convert it afterwards. But this is really ugly :) I've attached a
> simple example using SQLite3 which only supports int as datatype.

Henning,

I understand what is the problem, but I'm not sure how to fix it well.
Simply, row triggers implicit construction of "intos" buffers
of types based on data types determined from query result:

- query
-- describe columns (val is described as integer, not unsigned)
--- bind intos based on types
----- in core/statement.cpp:644

case dt_integer:
   bind_into<dt_integer>();

---- allocate type_holder<int>

With soci::row, all the reflection happens behind the scene and is
directly dependant on column types reported by low-level client API.
Currently, no hook is available to override reflected types to make the
cast kosher.
Perhaps we should rethink type_conversion<T>::base_type and introduce
type_conversion<T>::value_type which would be used by the type_holder<T>
and casting, instead of base_type which would stay as larger capacity
type used for safe conversions.

It's a kind of situation, where relax & diversity of dbms meets
strong typing in C++.

Anyway, I've tweaked a bit integer types supported by SQLite3 backend

http://soci.git.sourceforge.net/git/gitweb.cgi?p=soci/soci;a=blob;f=src/backends/sqlite3/statement.cpp;hb=HEAD#l340

This makes it possible to fetch row values into unsigned long long
(still not std::size)
CREATE TABLE x (val unsigned big int);

Also, long long is supported as output from tables created as
CREATE TABLE x (val bigint); where bigint can be replaced with int8.

Perhaps it's possible for you to use unsigned long long instead of
std::size_t. In the meantime, we can brainstorm how to fix the original
issue.

Cheers,
-- 
Mateusz Loskot, http://mateusz.loskot.net
Charter Member of OSGeo, http://osgeo.org
Member of ACCU, http://accu.org

------------------------------------------------------------------------------
Lotusphere 2011
Register now for Lotusphere 2011 and learn how
to connect the dots, take your collaborative environment
to the next level, and enter the era of Social Business.
http://p.sf.net/sfu/lotusphere-d2d
_______________________________________________
Soci-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/soci-users

Reply via email to