aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2017-03-13 19:56:12 -0400
committerGitHub <noreply@github.com>2017-03-13 19:56:12 -0400
commite2e63770f59ce4585944447ee237ec722761e77d (patch)
treebe527e3434eaefebc55cc4f4a8b02df7f942c870 /activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb
parent82aa2c124f4c2091ca4924735af466c22f0eebb4 (diff)
parent9d5217db5dce5e61cf3308329d94593a0e1cf6ff (diff)
downloadrails-e2e63770f59ce4585944447ee237ec722761e77d.tar.gz
rails-e2e63770f59ce4585944447ee237ec722761e77d.tar.bz2
rails-e2e63770f59ce4585944447ee237ec722761e77d.zip
Merge pull request #28068 from kamipo/refactor_data_sources
Extract `data_source_sql` to refactor data source statements
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb
new file mode 100644
index 0000000000..4ba245a0d8
--- /dev/null
+++ b/activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb
@@ -0,0 +1,32 @@
+module ActiveRecord
+ module ConnectionAdapters
+ module SQLite3
+ module SchemaStatements # :nodoc:
+ private
+ def data_source_sql(name = nil, type: nil)
+ scope = quoted_scope(name, type: type)
+ scope[:type] ||= "'table','view'"
+
+ sql = "SELECT name FROM sqlite_master WHERE name <> 'sqlite_sequence'"
+ sql << " AND name = #{scope[:name]}" if scope[:name]
+ sql << " AND type IN (#{scope[:type]})"
+ sql
+ end
+
+ def quoted_scope(name = nil, type: nil)
+ type = \
+ case type
+ when "BASE TABLE"
+ "'table'"
+ when "VIEW"
+ "'view'"
+ end
+ scope = {}
+ scope[:name] = quote(name) if name
+ scope[:type] = type if type
+ scope
+ end
+ end
+ end
+ end
+end