Skip to content

Commit db37b50

Browse files
[SqlQuery] Remove unused SqlSelectQueryBuilder::Varying() (#513)
Closes #495. ## Summary `Varying()` flipped the SELECT builder into a mode where the finalizers (`Count`/`All`/`First`/`Range`) returned a *copy* of the internal query instead of moving it out, so a single builder could be finalized into multiple query types. The default "Fluent" mode moves. Per #495 this feature is unused and unneeded, so it is removed. ## Changes - **`SqlQuery/Select.hpp`** — removed the `SqlQueryBuilderMode` enum, the `Varying()` method, the `_mode` member, and the `Varying()` deducing-this override on `SqlSelectQueryStarter`; updated the gate doc comment to reference only `Distinct`. - **`SqlQuery/Select.cpp`** — the four finalizers now unconditionally `std::move(_query)` (the former Fluent path; the `if (_mode == ...)` branches are gone). - **`Lightweight.cppm`** — dropped the `SqlQueryBuilderMode` re-export. - **`docs/sqlquery.md`** — removed `Varying()` from the starter documentation. - **`tests/QueryBuilderTests.cpp`** — removed the now-obsolete "Varying" test case. ## Risk assessment - **API**: breaking change for any external caller using `Varying()` / `SqlQueryBuilderMode` — appropriate for the issue's intent. - **Behavior**: no change for existing default (Fluent) usage. Const finalizer overloads are unaffected (a truly-const builder always had Fluent mode, since `Varying()` was non-const). - **Per-DBMS**: none — the change is purely about C++ move-vs-copy of the builder object and touches no DBMS-specific SQL generation. - **Performance**: removes one per-finalize branch; negligible. ## Databases tested - `sqlite3` — full suite green (1173 passed, 1 skipped). - `mssql2022` (Docker, 16.00.4250) — full suite green (1171 passed, 3 skipped). - `postgres` — **skipped**: no PostgreSQL ODBC driver available in this environment. Low risk given the change is database-agnostic. Built with the `clang-debug` preset (PEDANTIC + ASan/UBSan + clang-tidy), no warnings. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
2 parents 8cd0795 + 0c55bda commit db37b50

5 files changed

Lines changed: 9 additions & 68 deletions

File tree

docs/sqlquery.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ interface. Here we present a compressed list of functions that can be used to cr
163163
> the wildcard. `Fields("*")` and `Fields({"*"})` quote the literal and produce
164164
> `SELECT "*" FROM ...`, which is not what you want.
165165
>
166-
> `Distinct()` and `Varying()` are exposed on the starter as state-preserving
167-
> overrides (they return `SqlSelectQueryStarter&`), so chains like
166+
> `Distinct()` is exposed on the starter as a state-preserving override (it
167+
> returns `SqlSelectQueryStarter&`), so chains like
168168
> `Select().Distinct().Fields(...).All()` keep working while
169169
> `Select().Distinct().All()` is still a compile error. `Where`, `OrderBy`,
170170
> `GroupBy`, and the join family (`InnerJoin`, `LeftOuterJoin`, etc.) are

src/Lightweight/Lightweight.cppm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ using Lightweight::SqlOutputColumnBinder;
173173
using Lightweight::SqlPrimaryKeyType;
174174
using Lightweight::SqlQualifiedTableColumnName;
175175
using Lightweight::SqlQueryBuilder;
176-
using Lightweight::SqlQueryBuilderMode;
177176
using Lightweight::SqlQueryExecutionMode;
178177
using Lightweight::SqlQueryFormatter;
179178
using Lightweight::SqlQueryObject;

src/Lightweight/SqlQuery/Select.cpp

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -162,44 +162,28 @@ SqlSelectQueryBuilder& SqlSelectQueryBuilder::Fields(std::span<SqlQualifiedTable
162162
SqlSelectQueryBuilder::ComposedQuery SqlSelectQueryBuilder::Count()
163163
{
164164
_query.selectType = SelectType::Count;
165-
166-
if (_mode == SqlQueryBuilderMode::Fluent)
167-
return std::move(_query);
168-
else
169-
return _query;
165+
return std::move(_query);
170166
}
171167

172168
SqlSelectQueryBuilder::ComposedQuery SqlSelectQueryBuilder::All()
173169
{
174170
_query.selectType = SelectType::All;
175-
176-
if (_mode == SqlQueryBuilderMode::Fluent)
177-
return std::move(_query);
178-
else
179-
return _query;
171+
return std::move(_query);
180172
}
181173

182174
SqlSelectQueryBuilder::ComposedQuery SqlSelectQueryBuilder::First(size_t count)
183175
{
184176
_query.selectType = SelectType::First;
185177
_query.limit = count;
186-
187-
if (_mode == SqlQueryBuilderMode::Fluent)
188-
return std::move(_query);
189-
else
190-
return _query;
178+
return std::move(_query);
191179
}
192180

193181
SqlSelectQueryBuilder::ComposedQuery SqlSelectQueryBuilder::Range(std::size_t offset, std::size_t limit)
194182
{
195183
_query.selectType = SelectType::Range;
196184
_query.offset = offset;
197185
_query.limit = limit;
198-
199-
if (_mode == SqlQueryBuilderMode::Fluent)
200-
return std::move(_query);
201-
else
202-
return _query;
186+
return std::move(_query);
203187
}
204188

205189
// ---- const overloads ---------------------------------------------------------

src/Lightweight/SqlQuery/Select.hpp

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@
1414
namespace Lightweight
1515
{
1616

17-
enum class SqlQueryBuilderMode : uint8_t
18-
{
19-
Fluent,
20-
Varying
21-
};
22-
2317
struct [[nodiscard]] SqlFieldExpression final
2418
{
2519
std::string expression;
@@ -112,13 +106,6 @@ class [[nodiscard]] SqlSelectQueryBuilder: public SqlBasicSelectQueryBuilder<Sql
112106
_query.fields.reserve(256);
113107
}
114108

115-
/// Sets the builder mode to Varying, allowing varying final query types.
116-
constexpr LIGHTWEIGHT_FORCE_INLINE SqlSelectQueryBuilder& Varying() noexcept
117-
{
118-
_mode = SqlQueryBuilderMode::Varying;
119-
return *this;
120-
}
121-
122109
/// Adds a sequence of columns to the SELECT clause.
123110
template <typename... MoreFields>
124111
SqlSelectQueryBuilder& Fields(std::string_view const& firstField, MoreFields&&... moreFields);
@@ -256,7 +243,6 @@ class [[nodiscard]] SqlSelectQueryBuilder: public SqlBasicSelectQueryBuilder<Sql
256243

257244
private:
258245
SqlQueryFormatter const& _formatter;
259-
SqlQueryBuilderMode _mode = SqlQueryBuilderMode::Fluent;
260246
// mutable: see the note on _query in SqlBasicSelectQueryBuilder — the alias
261247
// flag is part of the projection accumulator, so it follows _query's policy.
262248
// Marked mutable so the const-qualified Field/Fields/As overloads above can
@@ -348,9 +334,9 @@ namespace detail
348334
/// - @c Count is intentionally not overridden — `SELECT COUNT(*) FROM ...`
349335
/// is well-formed without an explicit column list, so the inherited
350336
/// @c Count remains directly callable.
351-
/// - @c Distinct and @c Varying are overridden via deducing this so they
352-
/// return @c Self&& and the starter identity survives them. That keeps
353-
/// the gate intact for `Select().Distinct().All()` while still allowing
337+
/// - @c Distinct is overridden via deducing this so it returns @c Self&& and
338+
/// the starter identity survives it. That keeps the gate intact for
339+
/// `Select().Distinct().All()` while still allowing
354340
/// `Select().Distinct().Fields(...).All()`.
355341
///
356342
/// Methods that conceptually follow the column list (@c Where, @c OrderBy,
@@ -433,14 +419,6 @@ class [[nodiscard]] SqlSelectQueryStarter final: public SqlSelectQueryBuilder
433419
self.SqlSelectQueryBuilder::Distinct();
434420
return std::forward<Self>(self);
435421
}
436-
437-
/// State-preserving override; see @ref Distinct.
438-
template <typename Self>
439-
LIGHTWEIGHT_FORCE_INLINE auto&& Varying(this Self&& self) noexcept
440-
{
441-
self.SqlSelectQueryBuilder::Varying();
442-
return std::forward<Self>(self);
443-
}
444422
};
445423

446424
} // namespace Lightweight

src/tests/QueryBuilderTests.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -990,26 +990,6 @@ TEST_CASE_METHOD(SqlTestFixture, "Where: left IS NULL", "[SqlQueryBuilder]")
990990
WHERE "Left1" IS NOT NULL OR "Left2" IS NOT NULL)"));
991991
}
992992

993-
TEST_CASE_METHOD(SqlTestFixture, "Varying: multiple varying final query types", "[SqlQueryBuilder]")
994-
{
995-
auto const& sqliteFormatter = SqlQueryFormatter::Sqlite();
996-
997-
auto queryBuilder = SqlQueryBuilder { sqliteFormatter }
998-
.FromTable("Table")
999-
.Select()
1000-
.Varying()
1001-
.Fields({ "foo", "bar", "baz" })
1002-
.Where("condition", 42);
1003-
1004-
auto const countQuery = EraseLinefeeds(queryBuilder.Count().ToSql());
1005-
auto const allQuery = EraseLinefeeds(queryBuilder.All().ToSql());
1006-
auto const firstQuery = EraseLinefeeds(queryBuilder.First().ToSql());
1007-
1008-
CHECK(countQuery == R"(SELECT COUNT(*) FROM "Table" WHERE "condition" = 42)");
1009-
CHECK(allQuery == R"(SELECT "foo", "bar", "baz" FROM "Table" WHERE "condition" = 42)");
1010-
CHECK(firstQuery == R"(SELECT "foo", "bar", "baz" FROM "Table" WHERE "condition" = 42 LIMIT 1)");
1011-
}
1012-
1013993
TEST_CASE_METHOD(SqlTestFixture, "Use SqlQueryBuilder for SqlStatement.ExecuteDirct", "[SqlQueryBuilder]")
1014994
{
1015995
auto stmt = SqlStatement {};

0 commit comments

Comments
 (0)