Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Deep conditions nesting on sqlite => stack overflow #414

Open
clyfe opened this issue Jul 8, 2011 · 2 comments
Open

Deep conditions nesting on sqlite => stack overflow #414

clyfe opened this issue Jul 8, 2011 · 2 comments
Labels

Comments

@clyfe
Copy link

clyfe commented Jul 8, 2011

CanCan constructs sql like so

... where cond0 OR (
  cond1 OR (
    cond2 ...
  )
)

this useless deep nesting on sqlite3 results in a Parser Stack Overflow error.

A better SQL would be:

... where cond0 OR cond1 OR cond2 ...

I propose we fix this in CanCan::ModelAdapters::ActiveRecordAdapter like so:

# fix nested imbrication
def merge_conditions(sql, conditions_hash, behavior)
  if conditions_hash.blank?
    behavior ? true_sql : false_sql
  else
    conditions = sanitize_sql(conditions_hash)
    case sql
    when true_sql
      behavior ? true_sql : "not (#{conditions})"
    when false_sql
      behavior ? conditions : false_sql
    else
      behavior ? "(#{conditions}) OR #{sql}" : "(not (#{conditions}) AND #{sql})" # fix here
    end
  end
end
@ryanb
Copy link
Owner

ryanb commented Jul 12, 2011

Thanks for reporting this and providing a fix. I'm marking this to be fixed.

@xhoy
Copy link

xhoy commented Apr 10, 2014

Dear submitter, Since cancan/raynB hasn't been active for more than 6 months and no body else then ryam himself has commit permissions the cancan project is on a stand still.
Since cancan has several issues including missing support for rails 4 cancan is moving forward to cancancan. More details on: #994

If your feel that your pull request or bug is still applicable (and hasn't been merged in to cancan) it would be really appreciated if you would resubmit it to cancancan (https://github.com/cancancommunity/cancancan)

We hope to see you on the other side!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants