20 std::string tableName,
21 std::vector<SqlVariant>* inputBindings)
noexcept;
24 template <
typename ColumnValue>
28 template <std::
size_t N>
35 [[nodiscard]] LIGHTWEIGHT_API std::string
ToSql()
const;
39 std::string m_tableName;
42 std::vector<SqlVariant>* m_inputBindings;
45inline LIGHTWEIGHT_FORCE_INLINE SqlInsertQueryBuilder::SqlInsertQueryBuilder(
46 SqlQueryFormatter const& formatter, std::string tableName, std::vector<SqlVariant>* inputBindings)
noexcept:
47 m_formatter { formatter },
48 m_tableName { std::move(tableName) },
49 m_inputBindings { inputBindings }
53template <
typename ColumnValue>
54SqlInsertQueryBuilder& SqlInsertQueryBuilder::Set(std::string_view columnName, ColumnValue
const& value)
56 using namespace std::string_view_literals;
58 if (!m_fields.empty())
62 m_fields += columnName;
65 if (!m_values.empty())
68 if constexpr (std::is_same_v<ColumnValue, SqlNullType>)
70 else if constexpr (std::is_same_v<ColumnValue, SqlWildcardType>)
72 else if (m_inputBindings)
75 m_inputBindings->emplace_back(value);
77 else if constexpr (std::is_same_v<ColumnValue, char>)
79 else if constexpr (std::is_arithmetic_v<ColumnValue>)
80 m_values += std::format(
"{}", value);
81 else if constexpr (std::is_convertible_v<ColumnValue, std::string>
82 || std::is_convertible_v<ColumnValue, std::string_view>
83 || std::is_convertible_v<ColumnValue, char const*>)
89 m_values += m_formatter.
StringLiteral(std::format(
"{}", value));
95template <std::
size_t N>
96inline SqlInsertQueryBuilder& SqlInsertQueryBuilder::Set(std::string_view columnName,
char const (&value)[N])
98 return Set(columnName, std::string_view { value, N - 1 });
101inline SqlInsertQueryBuilder& SqlInsertQueryBuilder::Set(std::string_view columnName, MFCStringLike
auto const* value)
103 return Set(columnName, std::string_view { value->GetString(), value->GetLength() });
106inline std::string SqlInsertQueryBuilder::ToSql()
const
108 return m_formatter.
Insert(m_tableName, m_fields, m_values);
Query builder for building INSERT INTO ... queries.
LIGHTWEIGHT_API std::vector< std::string > ToSql(SqlQueryFormatter const &formatter, SqlMigrationPlanElement const &element)