On 04/12/2012 02:41 PM, Neil Morgenstern wrote:
Is __WORDSIZE portable?
Wouldn't using sizeof() be more appropriate? You can then use a helper
"traits" template that has a size parameter.
In reality though you should be matching against the type the database
is using.
This define __WORDSIZE is already used in here:
#if defined (__LP64__) || ( __WORDSIZE == 64 )
template <>
struct exchange_traits<long int>
{
typedef basic_type_tag type_family;
enum { x_type = x_long_long };
};
#endif // #if defined (__LP64__) || ( __WORDSIZE == 64 )
And I don't understand why does SOCI provide exchange_traits<long> only
for 64-bit systems.
So minimal change I would suggest is to provide it also for 32-bit
systems preserving the style.
We can avoid use of defines within this style:
template<int long_size> struct long_size_struct
{ enum { x_type = x_long_long }; };
template<> struct long_size_struct<4>
{ enum { x_type = x_integer }; };
template<>
struct exchange_traits<long int>
{
typedef basic_type_tag type_family;
enum { x_type = long_size_struct<sizeof(long int)>::x_type };
};
But this case others exchange_traits<> should be rewritten.
In practical use, by the way, we found SOCI too restrictive when we
were converting existing code to use it as SOCI generates runtime
errors when the type does not match exactly, and in reality it doesn't
need to match exactly as long as the types are compatible. Our code
was using "long" to receive integral values all over and we had to put
in conversions (in our own code) to make this work.
Yes. I have already seen this restrictiveness. One of the way is always
to use "long long" type. But it is inconvenient. For 64-bit system you
can use "long" which is equal to "long long".
But in 32-bit system "long" is "int".
And when I use "long" I don't care if it is big enough. I just want it
to be handled properly. And here reading "long" as "int" from DB is CORRECT.
It is like having perfectly working code for 64-bit system and sometimes
giving correctable errors in 32-bit mode.
But the main problem is that SOCI does not provide exchange_traits<long
int> for 32-bit mode.
Is it possible to fix?
Thanks.
The other main thing I changed was allowing later binding of "intos"
when the statement had been executed thus you could get the result
columns. SOCI was rather restrictive in this too.
On Thu, Apr 12, 2012 at 8:58 AM, Michael Evdokimov
<[email protected] <mailto:[email protected]>> wrote:
Hello!
Please consider applying this patch.
Otherwise we don't have long int for 32-bit arch.
diff --git a/src/core/exchange-traits.h b/src/core/exchange-traits.h
index 90314d9..81ecec4 100644
--- a/src/core/exchange-traits.h
+++ b/src/core/exchange-traits.h
@@ -90,6 +90,13 @@ struct exchange_traits<long int>
typedef basic_type_tag type_family;
enum { x_type = x_long_long };
};
+#elif ( __WORDSIZE == 32 )
+template <>
+struct exchange_traits<long int>
+{
+ typedef basic_type_tag type_family;
+ enum { x_type = x_integer };
+};
#endif // #if defined (__LP64__) || ( __WORDSIZE == 64 )
template <>
--
Best regards, Michael Evdokimov
Network Solutions, Moscow, Russia, Office: +7-495-7950677
<tel:%2B7-495-7950677>, Mobile:
+7-963-6054013 <tel:%2B7-963-6054013>
Web: www.lanbilling.ru <http://www.lanbilling.ru>,
www.lanbilling.tv <http://www.lanbilling.tv>, www.helpdesk2.ru
<http://www.helpdesk2.ru>
------------------------------------------------------------------------------
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
_______________________________________________
Soci-users mailing list
[email protected]
<mailto:[email protected]>
https://lists.sourceforge.net/lists/listinfo/soci-users
------------------------------------------------------------------------------
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
_______________________________________________
Soci-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/soci-users
--
Best regards, Michael Evdokimov
Network Solutions, Moscow, Russia, Office: +7-495-7950677, Mobile:
+7-963-6054013
Web: www.lanbilling.ru, www.lanbilling.tv, www.helpdesk2.ru
------------------------------------------------------------------------------
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
_______________________________________________
Soci-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/soci-users