aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGirish S <girish.sonawane@gmail.com>2014-02-14 15:32:10 +0530
committerGirish S <girish.sonawane@gmail.com>2014-02-14 15:32:10 +0530
commitbbf6df78a42345eb5343337372fb8602b736222e (patch)
tree5bb9036f758cbae5665186996f7af03a17dade13
parent7d897abeccb8533d770ac1d0768eca20ec2f3971 (diff)
downloadrails-bbf6df78a42345eb5343337372fb8602b736222e.tar.gz
rails-bbf6df78a42345eb5343337372fb8602b736222e.tar.bz2
rails-bbf6df78a42345eb5343337372fb8602b736222e.zip
SQLite3Adapter now checks for views in table_exists? fixes: 14041
-rw-r--r--activerecord/CHANGELOG.md6
-rw-r--r--activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb2
-rw-r--r--activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb10
3 files changed, 17 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index d8bb31a3a7..74f2ed4405 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,3 +1,9 @@
+* SQLite3Adapter now checks for views in `table_exists?`
+
+ Fixes #14041
+
+ *Girish Sonawane*
+
* When inverting add_index use the index name if present instead of
the columns.
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
index 3c5f7a981e..e808a31ff6 100644
--- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
@@ -369,7 +369,7 @@ module ActiveRecord
sql = <<-SQL
SELECT name
FROM sqlite_master
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
+ WHERE (type = 'table' OR type = 'view') AND NOT name = 'sqlite_sequence'
SQL
sql << " AND name = #{quote_table_name(table_name)}" if table_name
diff --git a/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb b/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
index 02834edf7b..fc5c1ef859 100644
--- a/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
+++ b/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
@@ -276,6 +276,16 @@ module ActiveRecord
assert_equal 0, @conn.select_rows(count_sql).first.first
end
+ def test_views
+ assert_equal %w{ items }, @conn.tables
+
+ @conn.execute <<-eosql
+ CREATE VIEW items_view AS
+ select id from items;
+ eosql
+ assert @conn.table_exists?('items_view')
+ end
+
def test_tables
assert_equal %w{ items }, @conn.tables