I've been attempting to get libdbi to work on my MacOSX PowerPC machine so I can use it with GnuCash. This has not been working because of an endian bug in dbi_result.c. The methods that return integer values (dbi_result_get_short_idx, dbi_result_get_int_idx, and dbi_result_get_longlong_idx) all assume that they can simply return the member of the field_values union that corresponds to the type they are supposed to return. For example dbi_result_get_int_idx returns field_values[fieldidx].d_long if DBI_INTEGER_SIZEMASK is less than or equal to 4. This won't work on big-endian machines. Instead you need to return the correct member of the union for the value of DBI_INTEGER_SIZEMASK so the compiler knows to cast it to the return type.

I've attached a patch to fix this. This patch makes the code bigger, but not much slower. If this is a problem it could be made conditional on the endianess of the target machine, but this didn't seem worth the trouble to me.

--
Mike Alexander           [email protected]
Ann Arbor, MI            PGP key ID: BEA343A6
--- src/dbi_result.c	2009-05-21 19:07:09.000000000 -0400
+++ old/dbi_result.c	2009-05-21 19:07:05.000000000 -0400
@@ -891,6 +891,7 @@
 
   switch (RESULT->field_attribs[fieldidx] & DBI_INTEGER_SIZEMASK) {
   case DBI_INTEGER_SIZE1:
+    return RESULT->rows[RESULT->currowidx]->field_values[fieldidx].d_char;
   case DBI_INTEGER_SIZE2:
     return RESULT->rows[RESULT->currowidx]->field_values[fieldidx].d_short;
   case DBI_INTEGER_SIZE3:
@@ -947,8 +948,10 @@
 
   switch (RESULT->field_attribs[fieldidx] & DBI_INTEGER_SIZEMASK) {
   case DBI_INTEGER_SIZE1:
+    return RESULT->rows[RESULT->currowidx]->field_values[fieldidx].d_char;
   case DBI_INTEGER_SIZE2:
   case DBI_INTEGER_SIZE3:
+    return RESULT->rows[RESULT->currowidx]->field_values[fieldidx].d_short;
   case DBI_INTEGER_SIZE4:
     return RESULT->rows[RESULT->currowidx]->field_values[fieldidx].d_long;
   case DBI_INTEGER_SIZE8:
@@ -995,9 +998,12 @@
 
   switch (RESULT->field_attribs[fieldidx] & DBI_INTEGER_SIZEMASK) {
   case DBI_INTEGER_SIZE1:
+    return RESULT->rows[RESULT->currowidx]->field_values[fieldidx].d_char;
   case DBI_INTEGER_SIZE2:
   case DBI_INTEGER_SIZE3:
+    return RESULT->rows[RESULT->currowidx]->field_values[fieldidx].d_short;
   case DBI_INTEGER_SIZE4:
+    return RESULT->rows[RESULT->currowidx]->field_values[fieldidx].d_long;
   case DBI_INTEGER_SIZE8:
     return RESULT->rows[RESULT->currowidx]->field_values[fieldidx].d_longlong;
   default:
------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, & 
iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com 
_______________________________________________
libdbi-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libdbi-devel

Reply via email to