diff options
author | Cody Cutrer <cody@cutrer.us> | 2013-12-17 10:10:23 -0700 |
---|---|---|
committer | Cody Cutrer <cody@cutrer.us> | 2014-01-14 08:53:32 -0700 |
commit | 547ed456337dda54799d9c5f316dcbce43cfce9d (patch) | |
tree | 6da876a012f7dea77de9e9cfdc935a5e7ed8f15b /activerecord/lib/active_record/connection_adapters | |
parent | 8a60f479b0580e88bae77c0ab3dd9e95082cb437 (diff) | |
download | rails-547ed456337dda54799d9c5f316dcbce43cfce9d.tar.gz rails-547ed456337dda54799d9c5f316dcbce43cfce9d.tar.bz2 rails-547ed456337dda54799d9c5f316dcbce43cfce9d.zip |
sqlite >= 3.8.0 supports partial indexes
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-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 |