ASSERT_TRUE(r2);
}
+ void SetInt64() {
+ int64_t i64 = 123456789000LL;
+ tizen_base::Database db(TEST_DB, SQLITE_OPEN_READWRITE);
+ auto q = tizen_base::Database::Sql(Q_INSERT)
+ .Bind("gogo")
+ .Bind(i64)
+ .Bind(9.216)
+ .Bind(std::vector<unsigned char> {'9', '2', '1', '6' });
+
+ auto r1 = db.Exec(q);
+ ASSERT_TRUE(r1);
+ auto r2 = db.Exec(q);
+ ASSERT_TRUE(r2);
+ }
+
void SetDefaultWithNull() {
tizen_base::Database db(TEST_DB, SQLITE_OPEN_READWRITE);
auto q = tizen_base::Database::Sql(Q_INSERT)
EXPECT_EQ(cnt, 0);
}
+TEST_F(DatabaseTest, test_select_i64) {
+ int64_t i64 = 123456789000LL;
+ SetInt64();
+ using tizen_base::_;
+ tizen_base::Database db(TEST_DB, SQLITE_OPEN_READWRITE);
+ auto r = db.Exec({ Q_SELECT });
+
+ EXPECT_TRUE(r);
+ for (const auto& i : r) {
+ int64_t val = static_cast<int64_t>(i.Get(1));
+ std::optional<int64_t> ov = i.Get(1);
+ EXPECT_EQ(val, i64);
+ EXPECT_TRUE(ov);
+ EXPECT_EQ(*ov, i64);
+ }
+}
+
TEST_F(DatabaseTest, test_ToVector) {
SetDefault();
for_(func, std::make_index_sequence<N>());
}
-using DbType = std::optional<std::variant<int, double, std::string,
+using DbType = std::optional<std::variant<int64_t, double, std::string,
std::vector<unsigned char>>>;
class DbException : public std::runtime_error {
explicit operator int () {
if (!db_type_)
throw DbException("invalid type conversion from nullopt to int");
- return std::get<int>(*db_type_);
+ return std::get<int64_t>(*db_type_);
+ }
+
+ explicit operator int64_t () {
+ if (!db_type_)
+ throw DbException("invalid type conversion from nullopt to int");
+ return std::get<int64_t>(*db_type_);
}
explicit operator std::string () {
operator std::optional<int> () {
if (!db_type_)
return std::nullopt;
- return std::get<int>(*db_type_);
+ return std::get<int64_t>(*db_type_);
+ }
+
+ operator std::optional<int64_t> () {
+ if (!db_type_)
+ return std::nullopt;
+ return std::get<int64_t>(*db_type_);
}
operator std::optional<std::string> () {
}
Sql& Bind(int val) {
+ bindings_.push_back(DbType(static_cast<int64_t>(val)));
+ return *this;
+ }
+
+ Sql& Bind(int64_t val) {
bindings_.push_back(DbType(val));
return *this;
}
}
Sql& Bind(int pos, int val) {
+ binding_map_[pos] = DbType(static_cast<int64_t>(val));
+ return *this;
+ }
+
+ Sql& Bind(int pos, int64_t val) {
binding_map_[pos] = DbType(val);
return *this;
}
}
Sql& Bind(std::string name, int val) {
+ binding_name_map_[std::move(name)] = DbType(static_cast<int64_t>(val));
+ return *this;
+ }
+
+ Sql& Bind(std::string name, int64_t val) {
binding_name_map_[std::move(name)] = DbType(val);
return *this;
}
dbt = DbType(reinterpret_cast<const char*>(
sqlite3_column_text(stmt, pos)));
} else if (type == SQLITE_INTEGER) {
- dbt = DbType(sqlite3_column_int(stmt, pos));
+ dbt = DbType(sqlite3_column_int64(stmt, pos));
} else if (type == SQLITE_FLOAT) {
dbt = DbType(sqlite3_column_double(stmt, pos));
} else if (type == SQLITE_BLOB) {
if (const std::string* pstr = std::get_if<std::string>(&(*type))) {
r = sqlite3_bind_text(stmt, pos, (*pstr).c_str(), -1,
SQLITE_TRANSIENT);
- } else if (const int* pint = std::get_if<int>(&(*type))) {
- r = sqlite3_bind_int(stmt, pos, (*pint));
+ } else if (const int64_t* pint = std::get_if<int64_t>(&(*type))) {
+ r = sqlite3_bind_int64(stmt, pos, (*pint));
} else if (const double* pdouble = std::get_if<double>(&(*type))) {
r = sqlite3_bind_double(stmt, pos, (*pdouble));
} else if (const std::vector<unsigned char>* pvector =