diff options
author | Casey Bodley <cbodley@redhat.com> | 2023-05-04 17:38:16 +0200 |
---|---|---|
committer | Casey Bodley <cbodley@redhat.com> | 2023-05-04 17:42:56 +0200 |
commit | fca2126e3ea7aaad2e8c6fb8014bd4d358d77191 (patch) | |
tree | c5515cf500ff2e25fad8ea23793514dc00281772 /src/rgw/driver/dbstore | |
parent | qa/rgw: dbstore suite uses db for config store (diff) | |
download | ceph-fca2126e3ea7aaad2e8c6fb8014bd4d358d77191.tar.xz ceph-fca2126e3ea7aaad2e8c6fb8014bd4d358d77191.zip |
rgw/sqlite: add bind_null()
Signed-off-by: Casey Bodley <cbodley@redhat.com>
Diffstat (limited to 'src/rgw/driver/dbstore')
-rw-r--r-- | src/rgw/driver/dbstore/config/sqlite.cc | 11 | ||||
-rw-r--r-- | src/rgw/driver/dbstore/sqlite/statement.cc | 15 | ||||
-rw-r--r-- | src/rgw/driver/dbstore/sqlite/statement.h | 4 |
3 files changed, 30 insertions, 0 deletions
diff --git a/src/rgw/driver/dbstore/config/sqlite.cc b/src/rgw/driver/dbstore/config/sqlite.cc index a1b21773556..04d681a2cf9 100644 --- a/src/rgw/driver/dbstore/config/sqlite.cc +++ b/src/rgw/driver/dbstore/config/sqlite.cc @@ -58,6 +58,17 @@ static constexpr const char* P4 = ":4"; static constexpr const char* P5 = ":5"; static constexpr const char* P6 = ":6"; +// bind as text unless value is empty +void bind_text_or_null(const DoutPrefixProvider* dpp, + const sqlite::stmt_binding& stmt, + const char* name, std::string_view value) +{ + if (value.empty()) { + sqlite::bind_null(dpp, stmt, name); + } else { + sqlite::bind_text(dpp, stmt, name, value); + } +} void read_text_rows(const DoutPrefixProvider* dpp, const sqlite::stmt_execution& stmt, diff --git a/src/rgw/driver/dbstore/sqlite/statement.cc b/src/rgw/driver/dbstore/sqlite/statement.cc index dcf7dba9c50..3e44f4c0b6e 100644 --- a/src/rgw/driver/dbstore/sqlite/statement.cc +++ b/src/rgw/driver/dbstore/sqlite/statement.cc @@ -58,6 +58,21 @@ static int bind_index(const DoutPrefixProvider* dpp, return index; } +void bind_null(const DoutPrefixProvider* dpp, const stmt_binding& stmt, + const char* name) +{ + const int index = bind_index(dpp, stmt, name); + + int result = ::sqlite3_bind_null(stmt.get(), index); + auto ec = std::error_code{result, sqlite::error_category()}; + if (ec != sqlite::errc::ok) { + ldpp_dout(dpp, 1) << "binding failed on parameter name=" + << name << dendl; + sqlite3* db = ::sqlite3_db_handle(stmt.get()); + throw sqlite::error(db, ec); + } +} + void bind_text(const DoutPrefixProvider* dpp, const stmt_binding& stmt, const char* name, std::string_view value) { diff --git a/src/rgw/driver/dbstore/sqlite/statement.h b/src/rgw/driver/dbstore/sqlite/statement.h index 98b4acfea23..99f796e9e61 100644 --- a/src/rgw/driver/dbstore/sqlite/statement.h +++ b/src/rgw/driver/dbstore/sqlite/statement.h @@ -48,6 +48,10 @@ using stmt_execution = std::unique_ptr<sqlite3_stmt, stmt_execution_deleter>; stmt_ptr prepare_statement(const DoutPrefixProvider* dpp, sqlite3* db, std::string_view sql); +// bind a NULL input for the given parameter name +void bind_null(const DoutPrefixProvider* dpp, const stmt_binding& stmt, + const char* name); + // bind an input string for the given parameter name void bind_text(const DoutPrefixProvider* dpp, const stmt_binding& stmt, const char* name, std::string_view value); |