Replies: 3 comments 8 replies
-
If |
Beta Was this translation helpful? Give feedback.
-
Proof is here: I wouldn't go this far as to completely disable bindings for select id from object order by case when id > 2 then 0 else 1 end is perfectly valid and can involve placeholders (bindables). I understand that you are reluctant to introduce yet another thing, which is good. However I want to convince you that user-defined numeric literals are a good thing here as per the points mentioned above 😃 What's speaking against capturing a value into a compile-time constant value? I find the ability to check the syntax at compile-time very compelling. |
Beta Was this translation helpful? Give feedback.
-
I asked on the SQLite forum about single parameters as ORDER-BY expressions. It's like it's upon the user to decide not to use it, and we can decide whether we simply allow or disallow such a construct. Well, whatever we do, what I wanted to accomplish is forming a positional ordinal. See PR #966 showcasing how I imagine the implementation. |
Beta Was this translation helpful? Give feedback.
-
In the CTE branch I introduced the ability to sort via column number by passing compile-time integral constants to order_by like
order_by(1_nth_col)
. Yevgeniy thought that this is most likely over-engineering for something that is already working, likeorder_by(1)
.However, sqlite_orm currently always treats the thing passed to order_by as a regular sub expression, and replaces the integer by a question mark, because it is 'bindable'.
Preparing a parameterized statement
is not the same as an unparameterized
.
Executing those two statements yield different results; the parameterized is not sorted at all. SQlite wouldn't even compile such a compound statement and would immediately tell that there's no such column alias.
I am not saying that sqlite_orm's current implementation is wrong.
I merely set out to escape the bindable mechanism, utilizing std::integral_constant for that purpose.
I think that std::integral_constant, or better yet a struct derived from it, serves the following 3 purposes well:
Also see The ORDER BY clause, stating "If the ORDER BY expression is a constant integer K then the expression is considered an alias for the K-th column of the result set".
At the same time I would also set out to reject passing arithmetic types and strings to order_by, because it doesn't make sense and leads to errors when preparing statements.
The only thing that baffles me is that statements like
select 1 order by 1+0
orselect 1 order by 'abc'
is accepted by SQlite, just not bringing about anything useful; which leads to "doesn't make sense" and sqlite_orm should reject it.Beta Was this translation helpful? Give feedback.
All reactions