Skip to content
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

Treat offset and limit input the same way #3183

Closed
wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented May 6, 2019

Currently, if you give offset a string, it will throw an error like this:

code: 'ER_PARSE_ERROR',
  errno: 1064,
  sqlMessage:
   'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'\'0\'\' at line 1',
  sqlState: '42000',
  index: 0,
  sql:
   'select * from `Alert` inner join `AlertType` on `Alert`.`AlertTypeID` = `AlertType`.`AlertTypeID` order by `AlertDate` desc limit 2 offset \'0\'' }

This is problematic, seeing how offset is likely used in pagination using a query in the url, which is usually treated as a string. It's weird to me that it's not like this already since limit, a relatively similar method, is implemented this way.

Currently, if you give offset a string, it will throw an error like this:
```
code: 'ER_PARSE_ERROR',
  errno: 1064,
  sqlMessage:
   'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'\'0\'\' at line 1',
  sqlState: '42000',
  index: 0,
  sql:
   'select * from `Alert` inner join `AlertType` on `Alert`.`AlertTypeID` = `AlertType`.`AlertTypeID` order by `AlertDate` desc limit 2 offset \'0\'' }
```
This is problematic, seeing how offset is likely used in pagination using a query in the url, which is usually treated as a string. It's weird to me that it's not like this already since `limit`, a relatively similar method, is implemented this way.
Copy link
Member

@elhigu elhigu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implementation looks fine, but needs a test case.

@ghost
Copy link
Author

ghost commented May 6, 2019

Alright, I'll take a look at tests later. Haven't really looked through the source code at all, I just went straight for this.

On another note, I found this: #2908
What happened here? Why did this not go all the way?

@elhigu
Copy link
Member

elhigu commented May 6, 2019

Alright, I'll take a look at tests later. Haven't really looked through the source code at all, I just went straight for this.

On another note, I found this: #2908
What happened here? Why did this not go all the way?

Good point. Actually this PR has the same problem that .offset() should allow passing knex.Raw as input too and maybe even query builder (not sure if SQL spec allows subqueries in offset...)

So implementation or that PR was not complete and the he closed it for some reason.

@ghost
Copy link
Author

ghost commented May 6, 2019

Yeah, probably it would be easier to reopen/duplicate that one and take it from there.

@HurSungYun
Copy link
Contributor

@AndreasClausen FYI #2908 has been merged.

@ghost
Copy link
Author

ghost commented Oct 16, 2019

Right, thank you

@ghost ghost closed this Oct 16, 2019
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants