Skip to content

Commit

Permalink
future proofing the sqlite3 adapter code
Browse files Browse the repository at this point in the history
Signed-off-by: Yehuda Katz <wycats@Yehuda-Katz.local>
  • Loading branch information
tenderlove authored and Yehuda Katz committed Jan 26, 2010
1 parent 6404fee commit beda2d4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
Expand Up @@ -193,20 +193,20 @@ def tables(name = nil) #:nodoc:
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
Expand Down
3 changes: 3 additions & 0 deletions activerecord/test/cases/calculations_test.rb
Expand Up @@ -288,6 +288,9 @@ def test_should_sum_expression
# 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
Expand Down
6 changes: 6 additions & 0 deletions activerecord/test/cases/query_cache_test.rb
Expand Up @@ -49,10 +49,16 @@ def test_cache_is_flat
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
Expand Down

0 comments on commit beda2d4

Please sign in to comment.