SQLite3Adapter table_exists? returns false for SQL views #14041

Closed
barriault opened this Issue Feb 13, 2014 · 8 comments

Comments

Projects
None yet
5 participants

The ActiveRecord::ConnectionAdapters::SQLite3Adapter table_exists? method returns false when passed an SQL view.

Member

senny commented Feb 13, 2014

@barriault why should it return true? Are you experiencing any issues related to that fact?

An SQL view is a virtual table based on the result-set of an SQL statement. I would expect the table_exists? method to return true for tables and virtual tables alike. Wouldn't you? I just tested this in postgresql and that adapter returns true for SQL views.

And yes this is causing problems with https://github.com/activerecord-hackery/ransack. I've created some views I'm trying to do some searching on and this was preventing me from being able to use SQLite3. It works fine for postgresql.

barriault referenced this issue in activerecord-hackery/ransack Feb 13, 2014

Closed

No table named #{table} exists for SQL views #338

senny removed the needs feedback label Feb 13, 2014

Contributor

girishso commented Feb 14, 2014

Exploring this, will update my findings

Contributor

dmathieu commented Feb 14, 2014

AR doesn't officially supports views as models, and it never did. I wouldn't consider that as a bug, but as a feature request, which therefore needs to be discussed in the rails code google group.

@dmathieu I'll have to disagree. There is a very good definition of SQL views over on Wikipedia found here http://en.wikipedia.org/wiki/View_(SQL). Most importantly, a view "is a virtual table computed or collated from data in the database." In other words, from the data consumer's perspective it functions like any other table. Given that SQLite3, Postgresql, MySQL, MS SQL, Oracle, MS Access, etc. support views, one would reasonably expect an SQL adapter to recognize a view within it's collection of tables.

Besides, it looks like @girishso already submitted a pull request that fixes the problem.

This issue has been automatically marked as stale because it has not been commented on for at least
three months.

The resources of the Rails team are limited, and so we are asking for your help.

If you can still reproduce this error on the 4-1-stable, 4-0-stable branches or on master,
please reply with all of the information you have about it in order to keep the issue open.

Thank you for all your contributions.

barriault added the stale label May 27, 2014

rails-bot closed this Aug 19, 2014

This issue has been automatically closed because of inactivity.

If you can still reproduce this error on the 4-1-stable, 4-0-stable branches or on master,
please reply with all of the information you have about it in order to keep the issue open.

Thank you for all your contributions.

senny removed the stale label Sep 9, 2014

Member

senny commented Sep 9, 2014

@dmathieu we actually do support views. According to @jeremy it's been a recommended tool for dealing with legacy applications for a long time.

I started adding test-cases to make sure AR behaves correctly with views. That made it obvious that the SQLite3Adapter is behaving differently.

I've merged the PR to unify the behavior across adapters.

@barriault thank you for reporting 💛

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment