From ab8c7a518eb9583dbc574ff68fd56bcccf383452 Mon Sep 17 00:00:00 2001 From: Paul Kuruvilla Date: Wed, 25 Oct 2017 14:33:51 +0530 Subject: Avoid using index_xinfo, only available in sqlite >= 3.8.9 --- .../sqlite3/schema_statements.rb | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'activerecord') 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+(?.+)$/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 -- cgit v1.2.3