Database uses the type checker to strictly bind the attribute values to SQL queries.
Change-Id: I761cdaef508313de46c70ba4c2bf51d8e168fb72
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
namespace ctx {
+ enum class DataType {
+ UNKNOWN = 0,
+ INT64 = 1,
+ DOUBLE,
+ STRING
+ };
+
class EXPORT_API Tuple {
public:
Tuple(GVariant* gVar);
unsigned int size();
+ DataType getType(unsigned int idx);
+
bool getAt(unsigned int idx, int64_t* val);
bool getAt(unsigned int idx, double* val);
bool getAt(unsigned int idx, std::string* val);
for (unsigned int i = 0; i < tuple->size(); ++i) {
++idx;
- if (tuple->getAt(i, &str)) {
+ DataType type = tuple->getType(i);
+
+ if (type == DataType::STRING) {
+ tuple->getAt(i, &str);
if (sqlite3_bind_text(__stmt, idx, str, -1, SQLITE_STATIC) != SQLITE_OK)
return E_FAILED;
- } else if (tuple->getAt(i, &i64)) {
+ } else if (type == DataType::INT64) {
+ tuple->getAt(i, &i64);
if (sqlite3_bind_int64(__stmt, idx, i64) != SQLITE_OK)
return E_FAILED;
- } else if (tuple->getAt(i, &dbl)) {
+ } else if (type == DataType::DOUBLE) {
+ tuple->getAt(i, &dbl);
if (sqlite3_bind_double(__stmt, idx, dbl) != SQLITE_OK)
return E_FAILED;
} else {
return static_cast<unsigned int>(__numElements);
}
+DataType Tuple::getType(unsigned int idx)
+{
+ if (__verify(idx, G_VARIANT_TYPE_INT64))
+ return DataType::INT64;
+
+ if (__verify(idx, G_VARIANT_TYPE_DOUBLE))
+ return DataType::DOUBLE;
+
+ if (__verify(idx, G_VARIANT_TYPE_STRING))
+ return DataType::STRING;
+
+ return DataType::UNKNOWN;
+}
+
bool Tuple::getAt(unsigned int idx, int64_t* val)
{
if (__verify(idx, G_VARIANT_TYPE_INT64)) {