copiousfreetime / amalgalite

SQLite database engine embedded in a ruby extension.
Other
97 stars 20 forks source link

select statement through ruby interface fails when sqlite column data type is a "string" #2

Closed jgodse closed 14 years ago

jgodse commented 15 years ago

Start with a table with one data type as string (using sqlite command line 3.6.10 or better)

sqlite> create table test (id integer, name string) sqlite> insert into test values (1, "Jay") sqlite> insert into test values (2, "May")

From the ruby programming interface,

irb(main):036:0> db.execute("select * from test") do |row| irb(main):037:1* puts row.to_s irb(main):038:1> end Amalgalite::Error: Unable to convert SQL type of string to a Ruby class from /usr/lib/ruby/gems/1.8/gems/amalgalite-0.10.0/lib/amalgalite/type_maps/default_map.rb:99:in result_value_of' from /usr/lib/ruby/gems/1.8/gems/amalgalite-0.10.0/lib/amalgalite/statement.rb:291:innext_row' from (irb):38:in each_with_index' from /usr/lib/ruby/gems/1.8/gems/amalgalite-0.10.0/lib/amalgalite/statement.rb:261:ineach' from /usr/lib/ruby/gems/1.8/gems/amalgalite-0.10.0/lib/amalgalite/statement.rb:261:in each_with_index' from /usr/lib/ruby/gems/1.8/gems/amalgalite-0.10.0/lib/amalgalite/statement.rb:261:innext_row' from /usr/lib/ruby/gems/1.8/gems/amalgalite-0.10.0/lib/amalgalite/statement.rb:247:in each' from /usr/lib/ruby/gems/1.8/gems/amalgalite-0.10.0/lib/amalgalite/database.rb:292:inexecute' from (irb):36 from :0 irb(main):039:0>

The software defect seems to be in line lib/amalgalite/type_maps/default_map.rb on line 27

'string' => %w[ text char varchar character ],

Line 27 should include 'string' in the list as well and probably say

'string' => %w[ string text char varchar character ],

Although I didn't test it there is probably also a bug in line 25, which says

'float' => %w[ double real numeric decimal ],

Line 25 should include "float" in the list and it should probably say,

'float' => %w[ float double real numeric decimal ],

copiousfreetime commented 15 years ago

Thanks for the report, I'll fix it up for the next release. I need to revamp the type conversion in the near future too.

copiousfreetime commented 14 years ago

I never closed this but its been fixed since 0.12.0, and 0.15.0 is now released.