Date: Saturday, January 21, 2006 @ 00:54:06
  Author: marc
    Path: /cvsroot/carob/carob/src

Modified: SQLDataSerialization.cpp (1.13 -> 1.14)

Now directly receiving raw standard IEEE 754 binary representation
into float and double as suggested by Zsolt.  Fix for CAROB-31, but
only partial: some values still fail, probably because of ambiguous
serialization in the reverse direction (writing parameters in class
ParameterStatement relies on strings :-(


--------------------------+
 SQLDataSerialization.cpp |   41 ++++++++++++++++++++++++++++++++++++++---
 1 files changed, 38 insertions(+), 3 deletions(-)


Index: carob/src/SQLDataSerialization.cpp
diff -u carob/src/SQLDataSerialization.cpp:1.13 
carob/src/SQLDataSerialization.cpp:1.14
--- carob/src/SQLDataSerialization.cpp:1.13     Fri Dec 30 17:53:05 2005
+++ carob/src/SQLDataSerialization.cpp  Sat Jan 21 00:54:06 2006
@@ -19,12 +19,25 @@
  * Contributor(s): 
  */
 
-#include <math.h>
+#include "SQLDataSerialization.hpp"
 
 #include "BigDecimal.hpp"
 #include "CarobException.hpp"
 #include "Common.hpp"
-#include "SQLDataSerialization.hpp"
+
+#include <math.h>
+
+
+// What IEEE 754 grants that matters to us:
+// - sizeof(float) = 32 && sizeof(double) = 64
+// - same standard binary representation as the one sent
+//   by Java's DataOutput class
+
+#ifndef __STDC_IEC_559__
+#error only IEEE 754 platforms are supported
+#endif
+ // also available at run-time: numeric_limits<double|float>.is_iec559()
+
 
 using std::wstring;
 
@@ -82,17 +95,24 @@
     throw (SocketIOException, UnexpectedException)
 {
   ResultSetDataType res;
+
+#if 1
+  input >> res.as_int;
+#else
+
   int32_t intRead = 0;
 
   //Receive the float as an integer (intbits)
   input>>intRead;
-// OTHER IMPLEM:
+// OTHER IMPLEM: // buggy? see CAROB-31
   int s = ((intRead & 0x80000000) == 0) ? 1 : -1;
   int e = ((intRead & 0x7f800000) >> 23);
   int m =  (intRead & 0x007fffff);
   m |= 0x00800000;
   res.as_float = (float)s * (float)m * (float)pow(2, e-1075);
 
+#endif
+
   return res;
 }
 
@@ -108,6 +128,11 @@
     throw (SocketIOException, UnexpectedException)
 {
   ResultSetDataType res;
+
+#if 1 // see CAROB-31
+  input >> res.as_long;
+#else
+
   int64_t longRead = 0;
 
   //Receive the float as an integer (intbits)
@@ -119,6 +144,8 @@
   m |= 0x0010000000000000LL;
   res.as_double = (double)s * (double)m * (double)pow(2, e-1075);
 
+#endif
+
   return res;
 }
 
@@ -236,3 +263,11 @@
       throw NotImplementedException(L"Deserialization for unsupported type");
   }
 }
+
+/*
+ * Local Variables:
+ * c-file-style: "bsd"
+ * c-basic-offset: 2
+ * indent-tabs-mode: nil
+ * End:
+ */

_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits

Reply via email to