diff options
author | Yves Senn <yves.senn@gmail.com> | 2014-01-14 07:58:06 -0800 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-01-14 07:58:06 -0800 |
commit | 93b38d54df7133c1404b492c14f15034e5b8f40e (patch) | |
tree | 6da876a012f7dea77de9e9cfdc935a5e7ed8f15b /activerecord/lib/active_record | |
parent | 8a60f479b0580e88bae77c0ab3dd9e95082cb437 (diff) | |
parent | 547ed456337dda54799d9c5f316dcbce43cfce9d (diff) | |
download | rails-93b38d54df7133c1404b492c14f15034e5b8f40e.tar.gz rails-93b38d54df7133c1404b492c14f15034e5b8f40e.tar.bz2 rails-93b38d54df7133c1404b492c14f15034e5b8f40e.zip |
Merge pull request #13350 from ccutrer/sqlite-partial-indexes
sqlite >= 3.8.0 supports partial indexes
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb index 92bb70ba53..170dddb08e 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb @@ -155,6 +155,10 @@ module ActiveRecord true end + def supports_partial_index? + sqlite_version >= '3.8.0' + end + # Returns true, since this connection adapter supports prepared statement # caching. def supports_statement_cache? @@ -397,13 +401,25 @@ module ActiveRecord # Returns an array of indexes for the given table. def indexes(table_name, name = nil) #:nodoc: exec_query("PRAGMA index_list(#{quote_table_name(table_name)})", 'SCHEMA').map do |row| + sql = <<-SQL + SELECT sql + FROM sqlite_master + WHERE name=#{quote(row['name'])} AND type='index' + UNION ALL + SELECT sql + FROM sqlite_temp_master + WHERE name=#{quote(row['name'])} AND type='index' + SQL + index_sql = exec_query(sql).first['sql'] + match = /\sWHERE\s+(.+)$/i.match(index_sql) + where = match[1] if match IndexDefinition.new( table_name, row['name'], row['unique'] != 0, exec_query("PRAGMA index_info('#{row['name']}')", "SCHEMA").map { |col| col['name'] - }) + }, nil, nil, where) end end |