Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add blob fields for sqlite #169

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ormpp/sqlite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,10 @@ class sqlite {
return SQLITE_OK ==
sqlite3_bind_text(stmt_, i, value, strlen(value), nullptr);
}
else if constexpr (std::is_same_v<std::vector<char>, U>) {
return SQLITE_OK ==
sqlite3_bind_blob(stmt_, i, value.data(),static_cast<int>(value.size()), nullptr);
}
#ifdef ORMPP_WITH_CSTRING
else if constexpr (std::is_same_v<CString, U>) {
return SQLITE_OK == sqlite3_bind_text(stmt_, i, value.GetString(),
Expand Down Expand Up @@ -624,6 +628,10 @@ class sqlite {
else if constexpr (iguana::c_array_v<U>) {
memcpy(value, sqlite3_column_text(stmt_, i), sizeof(U));
}
else if constexpr (std::is_same_v<std::vector<char>, U>) {
value.reserve(sqlite3_column_bytes(stmt_, i));
memcpy(value.data(),(const char *)sqlite3_column_blob(stmt_, i),(size_t)sqlite3_column_bytes(stmt_, i));
}
#ifdef ORMPP_WITH_CSTRING
else if constexpr (std::is_same_v<CString, U>) {
value.SetString((const char *)sqlite3_column_text(stmt_, i));
Expand Down
3 changes: 3 additions & 0 deletions ormpp/type_mapping.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ namespace ormpp_sqlite {
REGISTER_TYPE(int, SQLITE_INTEGER)
REGISTER_TYPE(double, SQLITE_FLOAT)

using blob = std::vector<char>;

inline int type_to_id(identity<std::string>) noexcept { return SQLITE_TEXT; }
inline std::string id_to_type(
std::integral_constant<std::size_t, SQLITE_TEXT>) noexcept {
Expand Down Expand Up @@ -113,6 +115,7 @@ inline constexpr auto type_to_name(identity<double>) noexcept {
inline constexpr auto type_to_name(identity<int64_t>) noexcept {
return "INTEGER"sv;
}
inline constexpr auto type_to_name(identity<blob>) noexcept { return "BLOB"sv; }
inline auto type_to_name(identity<std::string>) noexcept { return "TEXT"sv; }
template <size_t N>
inline auto type_to_name(identity<std::array<char, N>>) noexcept {
Expand Down
Loading