-
Notifications
You must be signed in to change notification settings - Fork 84
MS SQL syntax for LIMIT/OFFSET #312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
mbostock
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mind running Prettier on the parts you’ve changed? I see some formatting nits here and I’d rather not comment on them. Thanks!
src/table.mjs
Outdated
| if (slice.to !== null || slice.from !== null) { | ||
| if(!sort.length){ | ||
| appendSql(`\nORDER BY `, args); | ||
| appendOrderBy({column: select.columns[0], direction: 'ASC'}, args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we’ll want the escaped column name here, to match the SELECT.
| appendOrderBy({column: select.columns[0], direction: 'ASC'}, args); | |
| appendOrderBy({column: columns[0], direction: 'ASC'}, args); |
Also, this will crash if select.columns is null, as it is with SELECT *. In practice this should never happen for a MS SQL data source because we would always materialize the selected columns in a table cell, but we should either throw an error here with a human-readable message or perhaps we can make it work with something like ORDER BY NULL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like ORDER BY NULL won't work, mssql is not happy with it. So I added a catch and throwing an error with a human-readable message as you suggested.
Regarding the escaping, it seems that columns[0] has the alias of the table (t) prepended to it (L245). The table alias is also added in the appendOrderBy method (L286), so we end up with something like ORDER BY t.t."ModifiedDate" ASC. I decided to apply the escaper to the select.columns[0].
Also after looking at it for the other operations (sort and filter) I realized these are not escaped either. So I added the escape logic for both of these as well + some test.
I applied the styling. Should we change the |
7fe0016 to
71c0bfc
Compare
mbostock
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good find on the need for more escaping! Thanks for adding tests, too. 🙏
|
Sent #314 for your consideration. 🙏 |
5cd4e9e to
267af6c
Compare
Merged. Thanks a lot ! |
mbostock
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there…
mbostock
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍👍
Resolves https://github.com/observablehq/projects/issues/269.
SQL server syntax for LIMIT/OFFSET type query is
The table cell is currently generating the standard SQL syntax only.
If the source is of dialect
mssqlit should use the rightLIMIT/OFFSETsyntax.MS SQL documentation.