osaf/services/saf/immsv/immloadd/imm_pbe_load.cc |  25 ++++++++++++++++++-----
 1 files changed, 19 insertions(+), 6 deletions(-)


When PBE is being loaded, sqlite3_column_text function is used for fetching 
double values. The function returns a string representation of double value in 
15 bytes, which is not enough to preserve full floating point presicision.

diff --git a/osaf/services/saf/immsv/immloadd/imm_pbe_load.cc 
b/osaf/services/saf/immsv/immloadd/imm_pbe_load.cc
--- a/osaf/services/saf/immsv/immloadd/imm_pbe_load.cc
+++ b/osaf/services/saf/immsv/immloadd/imm_pbe_load.cc
@@ -587,12 +587,25 @@ bool loadObjectFromPbe(void* pbeHandle, 
                        std::list<char*> attrValueBuffers;
                        char *val;
                        while(rc == SQLITE_ROW) {
-                               val = (char *)sqlite3_column_text(stmt, 0);
-                               if(val) {
-                                       /* Guard for NULL values. */
-                                       char *str = strdup(val);
-                                       attrValueBuffers.push_front(str);
-                                       TRACE("ABT pushed value:%s", str);
+                               if((*it)->attrValueType == 
SA_IMM_ATTR_SADOUBLET) {
+                                       double d = sqlite3_column_double(stmt, 
0);
+                                       /* 30 bytes will be enough large for 
storing a double value */
+                                       val = (char *)malloc(30);
+                                       int size = snprintf(val, 30, "%.17g", 
d);
+                                       size++;
+                                       if(size > 30) {
+                                               val = (char *)realloc(val, 
size);
+                                               snprintf(val, size, "%.17g", d);
+                                       }
+                                       attrValueBuffers.push_front(val);
+                               } else {
+                                       val = (char *)sqlite3_column_text(stmt, 
0);
+                                       if(val) {
+                                               /* Guard for NULL values. */
+                                               char *str = strdup(val);
+                                               
attrValueBuffers.push_front(str);
+                                               TRACE("ABT pushed value:%s", 
str);
+                                       }
                                }
 
                                rc = sqlite3_step(stmt);

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/NeoTech
_______________________________________________
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to