aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorPaul Kuruvilla <rohitpaulk@gmail.com>2017-10-25 14:33:51 +0530
committerPaul Kuruvilla <rohitpaulk@gmail.com>2017-10-25 15:38:38 +0530
commitab8c7a518eb9583dbc574ff68fd56bcccf383452 (patch)
tree951071e23e0889b7aba5e95a2f172eee0b39135c /activerecord
parent82ae8369925e152d507486f7520558ac09f090e8 (diff)
downloadrails-ab8c7a518eb9583dbc574ff68fd56bcccf383452.tar.gz
rails-ab8c7a518eb9583dbc574ff68fd56bcccf383452.tar.bz2
rails-ab8c7a518eb9583dbc574ff68fd56bcccf383452.zip
Avoid using index_xinfo, only available in sqlite >= 3.8.9
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb21
1 files changed, 12 insertions, 9 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
index 3ab9dee370..58e5138e02 100644
--- a/activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb
@@ -19,14 +19,17 @@ module ActiveRecord
/\sWHERE\s+(?<where>.+)$/i =~ index_sql
- columns = []
- orders = {}
- exec_query("PRAGMA index_xinfo(#{quote(row['name'])})", "SCHEMA").each do |col|
- # xinfo also lists non-key columns, let's filter those out
- next if col["key"] == 0
+ columns = exec_query("PRAGMA index_info(#{quote(row['name'])})", "SCHEMA").map do |col|
+ col["name"]
+ end
- columns << col["name"]
- orders[col["name"]] = :desc if col["desc"] == 1
+ # Add info on sort order for columns (only desc order is explicitly specified, asc is
+ # the default)
+ orders = {}
+ if index_sql # index_sql can be null in case of primary key indexes
+ index_sql.scan(/"(\w+)" DESC/).flatten.each { |order_column|
+ orders[order_column] = :desc
+ }
end
IndexDefinition.new(
@@ -34,8 +37,8 @@ module ActiveRecord
row["name"],
row["unique"] != 0,
columns,
- orders: orders,
- where: where
+ where: where,
+ orders: orders
)
end
end