26 std::string tableAlias,
27 std::vector<SqlVariant>* inputBindings)
noexcept:
29 m_formatter { formatter }
31 m_searchCondition.tableName = std::move(table);
32 m_searchCondition.tableAlias = std::move(tableAlias);
33 m_searchCondition.inputBindings = inputBindings;
36 SqlSearchCondition& SearchCondition() noexcept
38 return m_searchCondition;
48 template <
typename ColumnValue>
52 template <std::
size_t N>
59 [[nodiscard]] std::string
ToSql()
const;
64 SqlSearchCondition m_searchCondition;
67template <
typename ColumnValue>
70 using namespace std::string_view_literals;
72 if (!m_values.empty())
76 m_values += columnName;
77 m_values += R
"(" = )"sv;
79 if constexpr (std::is_same_v<ColumnValue, SqlNullType>)
81 else if constexpr (std::is_same_v<ColumnValue, SqlWildcardType>)
83 else if (m_searchCondition.inputBindings)
86 m_searchCondition.inputBindings->emplace_back(value);
88 else if constexpr (std::is_same_v<ColumnValue, char>)
90 else if constexpr (std::is_arithmetic_v<ColumnValue>)
91 m_values += std::format(
"{}", value);
92 else if constexpr (!WhereConditionLiteralType<ColumnValue>::needsQuotes)
93 m_values += std::format(
"{}", value);
97 m_values += std::format(
"{}", value);
104template <std::
size_t N>
107 return Set(columnName, std::string_view { value, N - 1 });
112 return Set(columnName, std::string_view { value->GetString(), value->GetLength() });
117 return m_formatter.
Update(
118 m_searchCondition.tableName, m_searchCondition.tableAlias, m_values, m_searchCondition.condition);
Query builder for building UPDATE ... queries.
SqlUpdateQueryBuilder & Set(std::string_view columnName, ColumnValue const &value)
Adds a single column to the SET clause.
SqlUpdateQueryBuilder(SqlQueryFormatter const &formatter, std::string table, std::string tableAlias, std::vector< SqlVariant > *inputBindings) noexcept
SqlQueryFormatter const & Formatter() const noexcept
Returns the SQL query formatter.
SqlUpdateQueryBuilder & Set(std::string_view columnName, MFCStringLike auto const *value)
Adds a single column to the SET clause with the value being a MFC like CString.
SqlUpdateQueryBuilder & Set(std::string_view columnName, char const (&value)[N])
Adds a single column to the SET clause with the value being a string literal.
std::string ToSql() const
Finalizes building the query as UPDATE ... query.