Forum: Ruby sqlite3-ruby bug

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jon A. Lambert (Guest)
on 2006-03-17 18:34
(Received via mailing list)
Sane as earlier post.   Code to reproduce different.

This is using sqlite3-ruby (1.1.0)

----------
require 'sqlite3'
require 'pp'
require 'base64'

def self.decode(str)
  Marshal.load(Base64.decode64(str))
end
def self.encode(obj)
  Base64.encode64(Marshal.dump(obj)).strip
end
class Foo
end
db = SQLite3::Database.open("test.sqlite3")
begin
  db.execute("drop table test;")
rescue Exception
end
db.execute("create table test (id integer primary key, data object);")
db.type_translation = true
db.translator.add_translator("object") {|type, value|
  decode value
}
db.execute("insert into test values (1, ?);", encode(Foo.new))
db.execute("select * from test;") do |row|
  pp row
end
#db.type_translation = false           <===== uncomment to make work
pp db.execute("pragma table_info(test)")  <======= bug here
db.table_info("test") do |row|     <===== and here
  pp row
end
----------

[1, #<Foo:0x2c26e68>]
C:/apps/ruby/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0-mswin32/lib/sqlite3/translator.rb:85:in
`type_name': undefined method `upcase' for nil:NilClass (NoMethodError)
 from
C:/apps/ruby/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0-mswin32/lib/sqlite3/translator.rb:77:in
`translate'
 from
C:/apps/ruby/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0-mswin32/lib/sqlite3/resultset.rb:135:in
`next'
 from
C:/apps/ruby/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0-mswin32/lib/sqlite3/resultset.rb:134:in
`next'
 from
C:/apps/ruby/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0-mswin32/lib/sqlite3/resultset.rb:160:in
`each'
 from
C:/apps/ruby/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0-mswin32/lib/sqlite3/database.rb:215:in
`execute'
 from
C:/apps/ruby/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0-mswin32/lib/sqlite3/database.rb:186:in
`prepare'
 from
C:/apps/ruby/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0-mswin32/lib/sqlite3/database.rb:210:in
`execute'
 from C:/work/teensymud/trunk/testsql.rb:28

Tool completed with exit code 1


Switching type_translation off allows pragma to work.
This topic is locked and can not be replied to.