tags:

views:

27

answers:

1

I store utf-8 strings in KirbyBase table but later when I check string value encoding it is specified as IBM437. I'd like to have all strings stored in utf-8. Is this possible?

Now when I have something like this:

table.insert(some_utf8_string)

table.select(:recno) { |r| r.utf8_field == some_utf8_string }

select query doesn't find rows because of mismatched encoding.

A: 
require 'rubygems'
require 'kirbybase'

db = KirbyBase.new

plane_tbl = db.create_table(:plane, :name, :String, :country, :String)
plane_tbl.insert('FW-190', 'Germany')
plane_tbl.insert('FW-190', 'Résume')
plane_tbl.insert('Escaped', "R\303\251sume")

p plane_tbl.select(:recno, :name, :country) { |r| r.country == 'Résume' }
p plane_tbl.select(:recno, :name, :country) { |r| r.country == "R\303\251sume" }
$KCODE = 'u'
p plane_tbl.select(:recno, :name, :country) { |r| r.country == "R\303\251sume" }

That works for me all three ways with KirbyBase 2.6 and Ruby 1.8.6.

> ruby test_kb.rb
[#<struct #<Class:0xb7afcbf4> recno=2, name="FW-190", country="R\303\251sume">, #<struct #<Class:0xb7afcbf4> recno=3, name="Escaped", country="R\303\251sume">]
[#<struct #<Class:0xb7afada4> recno=2, name="FW-190", country="R\303\251sume">, #<struct #<Class:0xb7afada4> recno=3, name="Escaped", country="R\303\251sume">]
[#<struct #<Class:0xb7af8e50> recno=2, name="FW-190", country="Résume">, #<struct #<Class:0xb7af8e50> recno=3, name="Escaped", country="Résume">]

Can you give an example of strings that don't work and the code that handles them?

rjp
I ran your sample (saved file as utf8), and the effect is:[][]test_unicode.rb:13: warning: variable $KCODE is no longer effective; ignored[]I forgot to write that I'm using ruby 1.9
ternyk