Skip to content

Commit 49a4d85

Browse files
committed
Fix auto-quoting of elements in SQL range functions
Now only applies to types that will use the QString constructor based converter. This may need further work long term.
1 parent 8318ce9 commit 49a4d85

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

lib/sql/include/qx/sql/__private/qx-sqlstring_helpers.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,28 @@ void appendKeywordParen(QString& str, const QString& word, const R& range)
5757
* we rely on the SqlString ctor to reliably get a string from value_type.
5858
*/
5959

60-
/* NOTE: With current implementation it is up to the caller to ensure that the elements
61-
* in 'range' end up quoted as required (or of a type that automatically quotes them
62-
* during construction).
60+
/* TODO: This is a bit of a hack. We manually quote when the contained type of R is QString
61+
* based. This works, but there is an arugment to be made that the caller should be responsible
62+
* for ensuring that everything is quoted as required (or is a type that auto quotes) ahead of
63+
* time, and this may on occasion cause accidental double quoting.
6364
*/
65+
constexpr bool quote = std::constructible_from<QString, Qx::unwrap<R>>;
6466
QString rStr;
67+
if constexpr(quote)
68+
rStr += u"'"_s;
6569
for(auto n = std::size(range); const auto& value : range)
6670
{
6771
rStr += __private::qstring_compat(value);
6872
if(n-- != 1)
69-
rStr += u","_s;
73+
{
74+
if constexpr(quote)
75+
rStr += u"','"_s;
76+
else
77+
rStr += u","_s;
78+
}
7079
}
80+
if constexpr(quote)
81+
rStr += u"'"_s;
7182

7283
appendKeywordParen(str, word, rStr);
7384
}

0 commit comments

Comments
 (0)