Replies: 14 comments 1 reply
-
Is that a question or a statement? :) |
Beta Was this translation helpful? Give feedback.
-
it is an example which has |
Beta Was this translation helpful? Give feedback.
-
Sorry if I am only slowly following all the gory details... I expect this specific query to work. Do you expect something different? |
Beta Was this translation helpful? Give feedback.
-
wait I expect this query not to work (I mean ordering not to work) because it has |
Beta Was this translation helpful? Give feedback.
-
No, the SQLite team didn't say anything of that. They just agreed that |
Beta Was this translation helpful? Give feedback.
-
yes this is what I am talking about: SQLite team told that ordering doesn't work in this expression (cause |
Beta Was this translation helpful? Give feedback.
-
I still don't get the problem: Just because |
Beta Was this translation helpful? Give feedback.
-
What do you mean parameters to work? The only way how parameters must work inside |
Beta Was this translation helpful? Give feedback.
-
We are probably intermixing words from different abstraction levels here... So, in this case (simplified) auto statement = storage.prepare(select(asterisk<Employee>,
order_by(case_<int>().when(is_null(&Employee::m_commission), then(0)).else_(1).end()))); the SQL query string that gets passed to SELECT * FROM Emp ORDER BY CASE WHEN comm IS NULL THEN ? ELSE ? END This is desired as it allows reusing the prepared statement. |
Beta Was this translation helpful? Give feedback.
-
ok I see. I am talking about working ordering with parameters. Juan tells me that ordering works, SQLite team tells that it doesn't |
Beta Was this translation helpful? Give feedback.
-
The term "not working" is relative it seems.
With this expression auto statement = storage.prepare(select(asterisk<Employee>,
order_by(1))); the SQL query string that gets passed to SELECT * from Emp ORDER BY ? As we are discussing already a long time, this statement IS CORRECT and works in the sense that it is NOT AN ERROR, and the parameter used as a whole order-by expression IS A VALID EXPRESSION. However the result set is unordered. So a parameter used as the only order-by expression doesn't make sense. Because of our lengthy and insightful discussion PR #966 will change this in a way such that 'bindables' will be serialized as literal values. auto statement = storage.prepare(select(asterisk<Employee>,
order_by(1))); the SQL query string that gets passed to SELECT * from Emp ORDER BY 1 Other expressions are still treated the same way as before. auto statement = storage.prepare(select(asterisk<Employee>,
order_by(c(&Employee::m_commission) == 1))); the SQL query string that gets passed to SELECT * from Emp ORDER BY (comm = ?) The unit test for AST iteration makes it clear on what's happening. @fnc12 Not sure whether this still isn't what you want. @juandent Can you please let us know what exactly works or does not work? |
Beta Was this translation helpful? Give feedback.
-
This query works (by that I mean: it compiles, it runs without exception throwing and it orders the rows correctly): auto statement = storage.prepare(select(columns(&Employee::m_ename, &Employee::m_salary, &Employee::m_commission),
order_by(case_<int>().when(is_null(&Employee::m_commission), then(0)).else_(1).end()).desc()));
auto sql = statement.expanded_sql();
auto rows = storage.execute(statement); Is this your question? |
Beta Was this translation helpful? Give feedback.
-
thanks @trueqbit for details. Thanks @juandent for answering. Why are we talking so much about ordering? Ordering has only one and only meaning in SQL. And words 'working ordering' mean that ordering works as @juandent told. @trueqbit described all the history of the issue one more time. We need to check who is not right: Juan or SQLite team. Please note that I am repeating the same every message here. IDK what happened. |
Beta Was this translation helpful? Give feedback.
-
Interesting results. Looks like Juan and SQLite team both right. {
auto statement = storage.prepare(select(columns(&Employee::m_ename, &Employee::m_salary, &Employee::m_commission),
order_by(case_<int>().when(is_null(&Employee::m_commission), then(2)).else_(1).end()).desc()));
auto rows = storage.execute(statement);
for (auto &row: rows) {
cout << get<0>(row) << '\t' << get<1>(row) << '\t' << get<2>(row) << endl;
}
cout << endl;
}
{
auto statement = storage.prepare(select(columns(&Employee::m_ename, &Employee::m_salary, &Employee::m_commission),
order_by(case_<int>().when(is_null(&Employee::m_commission), then(1)).else_(2).end()).desc()));
auto rows = storage.execute(statement);
for (auto &row: rows) {
cout << get<0>(row) << '\t' << get<1>(row) << '\t' << get<2>(row) << endl;
}
cout << endl;
}
{
auto statement = storage.prepare(select(columns(&Employee::m_ename, &Employee::m_salary, &Employee::m_commission),
order_by(1)));
auto rows = storage.execute(statement);
for (auto &row: rows) {
cout << get<0>(row) << '\t' << get<1>(row) << '\t' << get<2>(row) << endl;
}
cout << endl;
}
{
auto statement = storage.prepare(select(columns(&Employee::m_ename, &Employee::m_salary, &Employee::m_commission),
order_by(2)));
auto rows = storage.execute(statement);
for (auto &row: rows) {
cout << get<0>(row) << '\t' << get<1>(row) << '\t' << get<2>(row) << endl;
}
cout << endl;
} Output of this code:
@trueqbit do you know why changing |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The extended ORDER BY clause is working with latest Dev branch:
Schema would be:
Beta Was this translation helpful? Give feedback.
All reactions