EXPECT_NE(db_raw, nullptr);
}
+
+TEST_F(DatabaseTest, test_nullptr_bind) {
+ tizen_base::Database db(TEST_DB, SQLITE_OPEN_READWRITE);
+ auto q = tizen_base::Database::Sql(Q_INSERT)
+ .Bind(nullptr)
+ .Bind(1234)
+ .Bind(9.216)
+ .Bind(std::vector<unsigned char> {'9', '2', '1', '6' });
+ auto r = db.Exec(q);
+ ASSERT_TRUE(r);
+}
public:
Sql(std::string query) : query_(std::move(query)) {}
+ Sql& Bind(const char* val) {
+ if (val == nullptr) {
+ bindings_.push_back(DbType(std::nullopt));
+ } else {
+ std::string str = val;
+ if (empty_string_as_null_ && str.empty())
+ bindings_.push_back(DbType(std::nullopt));
+ else
+ bindings_.push_back(DbType(std::move(str)));
+ }
+ return *this;
+ }
+
Sql& Bind(std::string val) {
if (empty_string_as_null_ && val.empty())
bindings_.push_back(DbType(std::nullopt));
return *this;
}
+ Sql& Bind(int pos, const char* val) {
+ if (val == nullptr) {
+ binding_map_[pos] = DbType(std::nullopt);
+ } else {
+ std::string str = val;
+ if (empty_string_as_null_ && str.empty())
+ binding_map_[pos] = DbType(std::nullopt);
+ else
+ binding_map_[pos] = DbType(std::move(str));
+ }
+ return *this;
+ }
+
Sql& Bind(int pos, std::string val) {
if (empty_string_as_null_ && val.empty())
binding_map_[pos] = DbType(std::nullopt);
return *this;
}
+ Sql& Bind(std::string name, const char* val) {
+ if (val == nullptr) {
+ binding_name_map_[std::move(name)] = DbType(std::nullopt);
+ } else {
+ std::string str = val;
+ if (empty_string_as_null_ && str.empty())
+ binding_name_map_[std::move(name)] = DbType(std::nullopt);
+ else
+ binding_name_map_[std::move(name)] = DbType(std::move(str));
+ }
+ return *this;
+ }
+
Sql& Bind(std::string name, std::string val) {
if (empty_string_as_null_ && val.empty())
binding_name_map_[std::move(name)] = DbType(std::nullopt);