postgresql_cursor icon indicating copy to clipboard operation
postgresql_cursor copied to clipboard

Bug: SyntaxError when using ActiveRecord none

Open collimarco opened this issue 5 years ago • 0 comments

We have discovered that this gem doesn't handle properly the ActiveRecord none method.

subscriptions = Subscription.none
subscriptions.each_row { |row| p row }

The above code raises:

     ActiveRecord::StatementInvalid:
       PG::SyntaxError: ERROR:  syntax error at end of input
       LINE 1: ...ursor_a7205fd123ab9169d9a3105 no scroll cursor for 
                                                                                                                     ^

The expected behavior is that no error is raised, because the above code is perfectly valid. For example the following code that uses ActiveRecord each does not raise any error:

subscriptions = Subscription.none
subscriptions.each { |row| p row }

I think that the problem is that this gem uses the to_sql method, which returns an empty string when none is used (somewhere in the filter chain).

Probably the best solution is to check if to_sql returns an empty string and in that case return an empty array of results.

collimarco avatar Nov 15 '20 13:11 collimarco