pagy icon indicating copy to clipboard operation
pagy copied to clipboard

fix column names quotation in keyset

Open t0ch1k opened this issue 7 months ago • 2 comments

This PR should fix the problem with column names quotes in MySQL introduced by this commit.

Demo of the problem:

irb(main):002> scope = Service.order(id: :desc)
irb(main):003> page = Pagy::Keyset.new(scope, limit: 3000)
irb(main):004> page.records.count
  Service Load (25.3ms)  SELECT `services`.* FROM `services` ORDER BY `services`.`id` DESC LIMIT 3001
irb(main):006> page = Pagy::Keyset.new(scope, limit: 3000, page: page.next)
  Service Load (2.9ms)  SELECT `services`.* FROM `services` /* loading for pp */ ORDER BY `services`.`id` DESC LIMIT 11
=>
#<Pagy::Keyset::ActiveRecord:0x0000000109b270f0
...
irb(main):007> page.records.count
  Service Load (2.3ms)  SELECT `services`.* FROM `services` WHERE (( "services"."id" < '7002' )) ORDER BY `services`.`id` DESC LIMIT 3001
(irb):7:in `<main>': Mysql2::Error: 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 '."id" < '7002' )) ORDER BY `services`.`id` DESC LIMIT 3001' at line 1 (ActiveRecord::StatementInvalid)
/Users/alexeyt/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/mysql2-0.5.6/lib/mysql2/client.rb:151:in `_query': 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 '."id" < '7002' )) ORDER BY `services`.`id` DESC LIMIT 3001' at line 1 (Mysql2::Error)

t0ch1k avatar May 29 '25 09:05 t0ch1k

Thank you! I totally overlooked that different DBs like to do things their ways. 😬

That is actually a bug that was persisting in the upcoming version, now fixed also for sequel datasets in dev.

Please, extrapolate the changes in 81b4222 (new code) to the current version and I will be glad to merge and release it ASAP. Also, please ensure that all tests pass.

Thank you!

ddnexus avatar May 30 '25 05:05 ddnexus

@ddnexus thanks for your comment! I checked out your commit and took the implementation from there

t0ch1k avatar Jun 04 '25 11:06 t0ch1k

@ddnexus could you have a look pls?

t0ch1k avatar Jul 03 '25 14:07 t0ch1k

@t0ch1k I am terribly late on all the PRs... sorry, but I have been abroad solving a few family problems, and focusing on the development of the new major version. You can see the rc1 here.

Will do next.

ddnexus avatar Jul 05 '25 15:07 ddnexus