From beda2d43d6ac5c3435fc2fba0cbd108c20fe1c67 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 26 Jan 2010 13:00:19 -0800 Subject: future proofing the sqlite3 adapter code Signed-off-by: Yehuda Katz --- .../lib/active_record/connection_adapters/sqlite_adapter.rb | 6 +++--- activerecord/test/cases/calculations_test.rb | 3 +++ activerecord/test/cases/query_cache_test.rb | 6 ++++++ 3 files changed, 12 insertions(+), 3 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb index 0a52f3a6a2..29225b83c5 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb @@ -193,20 +193,20 @@ module ActiveRecord SQL execute(sql, name).map do |row| - row[0] + row['name'] end end def columns(table_name, name = nil) #:nodoc: table_structure(table_name).map do |field| - SQLiteColumn.new(field['name'], field['dflt_value'], field['type'], field['notnull'] == "0") + SQLiteColumn.new(field['name'], field['dflt_value'], field['type'], field['notnull'].to_i == 0) end end def indexes(table_name, name = nil) #:nodoc: execute("PRAGMA index_list(#{quote_table_name(table_name)})", name).map do |row| index = IndexDefinition.new(table_name, row['name']) - index.unique = row['unique'] != '0' + index.unique = row['unique'].to_i != 0 index.columns = execute("PRAGMA index_info('#{index.name}')").map { |col| col['name'] } index end diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb index c3b2e56387..e6d56a7193 100644 --- a/activerecord/test/cases/calculations_test.rb +++ b/activerecord/test/cases/calculations_test.rb @@ -288,6 +288,9 @@ class CalculationsTest < ActiveRecord::TestCase # Oracle adapter returns floating point value 636.0 after SUM if current_adapter?(:OracleAdapter) assert_equal 636, Account.sum("2 * credit_limit") + elsif current_adapter?(:SQLite3Adapter) + # Future versions of the SQLite3 adapter will return a number + assert_equal 636, Account.sum("2 * credit_limit").to_i else assert_equal '636', Account.sum("2 * credit_limit") end diff --git a/activerecord/test/cases/query_cache_test.rb b/activerecord/test/cases/query_cache_test.rb index 2af6a56b6a..3710f8e40b 100644 --- a/activerecord/test/cases/query_cache_test.rb +++ b/activerecord/test/cases/query_cache_test.rb @@ -49,10 +49,16 @@ class QueryCacheTest < ActiveRecord::TestCase end def test_cache_does_not_wrap_string_results_in_arrays + require 'sqlite3/version' if current_adapter?(:SQLite3Adapter) + Task.cache do # Oracle adapter returns count() as Fixnum or Float if current_adapter?(:OracleAdapter) assert Task.connection.select_value("SELECT count(*) AS count_all FROM tasks").is_a?(Numeric) + elsif current_adapter?(:SQLite3Adapter) && SQLite3::Version::VERSION > '1.2.5' + # Future versions of the sqlite3 adapter will return numeric + assert_instance_of Fixnum, + Task.connection.select_value("SELECT count(*) AS count_all FROM tasks") else assert_instance_of String, Task.connection.select_value("SELECT count(*) AS count_all FROM tasks") end -- cgit v1.2.3