sensor: fix the group-by statements of SQL queries to split the timeline properly 03/78203/1
authorMu-Woong Lee <muwoong.lee@samsung.com>
Mon, 4 Jul 2016 12:29:11 +0000 (21:29 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Mon, 4 Jul 2016 12:29:11 +0000 (21:29 +0900)
In SQL, deviding an integer by an integer produces an integer.
The integers need to be casted into real.

Change-Id: I71d407f94fb00503a67255e4935df405e766d757
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
src/sensor/TypesInternal.h
src/sensor/pedometer/PedometerQuerier.cpp
src/sensor/pressure/PressureQuerier.cpp

index 1894520..0bd3cb5 100644 (file)
@@ -40,4 +40,7 @@
 /* Time Conversions */
 #define SEC_TO_MS(X)   ((X) * 1000)
 
+/* SQL Helper */
+#define TIME_QUANTIZER(key)    "ROUND((CAST(" key " AS REAL) - %llu)/CAST(%llu AS REAL) + 0.5)"
+
 #endif /* __CONTEXT_SENSOR_RECORDER_TYPES_INTERNAL_H__ */
index 020e868..c4bda95 100644 (file)
@@ -59,7 +59,7 @@ int PedometerQuerier::query(int startTime, int endTime, int anchor, int interval
                        "SELECT " PROJECTION \
                        " FROM " PEDOMETER_RECORD \
                        " WHERE " KEY_END_TIME " > %llu AND " KEY_END_TIME " <= %llu" \
-                       " GROUP BY ROUND((" KEY_END_TIME " - %llu) / %llu + 0.5)" \
+                       " GROUP BY " TIME_QUANTIZER(KEY_END_TIME) \
                        " ORDER BY " KEY_END_TIME " ASC",
                        SEC_TO_MS(static_cast<uint64_t>(startTime)), SEC_TO_MS(static_cast<uint64_t>(endTime)),
                        SEC_TO_MS(static_cast<uint64_t>(anchor)), SEC_TO_MS(static_cast<uint64_t>(interval)));
index 43d3457..8d19638 100644 (file)
@@ -80,7 +80,7 @@ int PressureQuerier::query(int startTime, int endTime, int anchor, int interval)
                        "SELECT " PROJECTION \
                        " FROM " PRESSURE_RECORD \
                        " WHERE " KEY_UNIV_TIME " > %llu AND " KEY_UNIV_TIME " <= %llu" \
-                       " GROUP BY ROUND((" KEY_UNIV_TIME " - %llu) / %llu + 0.5)" \
+                       " GROUP BY " TIME_QUANTIZER(KEY_UNIV_TIME) \
                        " ORDER BY " KEY_END_TIME " ASC",
                        SEC_TO_MS(static_cast<uint64_t>(startTime)), SEC_TO_MS(static_cast<uint64_t>(endTime)),
                        SEC_TO_MS(static_cast<uint64_t>(anchor)), SEC_TO_MS(static_cast<uint64_t>(interval)));