Skip to content

Commit d421b95

Browse files
committed
LibDatabase: Support storing ByteString values
1 parent f4eef9d commit d421b95

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Libraries/LibDatabase/Database.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ static constexpr StringView sql_error(int error_code)
4040

4141
#define ENUMERATE_SQL_TYPES \
4242
__ENUMERATE_TYPE(String) \
43+
__ENUMERATE_TYPE(ByteString) \
4344
__ENUMERATE_TYPE(UnixDateTime) \
4445
__ENUMERATE_TYPE(i8) \
4546
__ENUMERATE_TYPE(i16) \
@@ -118,7 +119,7 @@ void Database::apply_placeholder(StatementID statement_id, int index, ValueType
118119
{
119120
auto* statement = prepared_statement(statement_id);
120121

121-
if constexpr (IsSame<ValueType, String>) {
122+
if constexpr (IsOneOf<ValueType, String, ByteString>) {
122123
StringView string { value };
123124
SQL_MUST(sqlite3_bind_text(statement, index, string.characters_without_null_termination(), static_cast<int>(string.length()), SQLITE_TRANSIENT));
124125
} else if constexpr (IsSame<ValueType, UnixDateTime>) {
@@ -146,6 +147,9 @@ ValueType Database::result_column(StatementID statement_id, int column)
146147
if constexpr (IsSame<ValueType, String>) {
147148
auto const* text = reinterpret_cast<char const*>(sqlite3_column_text(statement, column));
148149
return MUST(String::from_utf8(StringView { text, strlen(text) }));
150+
} else if constexpr (IsSame<ValueType, ByteString>) {
151+
auto const* text = reinterpret_cast<char const*>(sqlite3_column_text(statement, column));
152+
return ByteString { text, strlen(text) };
149153
} else if constexpr (IsSame<ValueType, UnixDateTime>) {
150154
auto milliseconds = result_column<sqlite3_int64>(statement_id, column);
151155
return UnixDateTime::from_milliseconds_since_epoch(milliseconds);

0 commit comments

Comments
 (0)