Skip to content

Instantly share code, notes, and snippets.

@yukikaoru
Created January 18, 2010 06:31
Show Gist options
  • Save yukikaoru/279829 to your computer and use it in GitHub Desktop.
Save yukikaoru/279829 to your computer and use it in GitHub Desktop.
# vim:set encoding=utf-8:
# by ruby1.9.1-p378
require "dbi"
require "kconv"
DBI.connect("DBI:ODBC:foobar", "sa", "sa") do |dbh|
q = "select * from foo_table"
dbh.select_all(q) do |row|
row[0] = NKF.nkf("-wZ1", row[1]).strip
row[0] = row[0].gsub(/([a-zA-Z0-9])/){ NKF.nkf("-wWZ", $1) }
#=> ok
row[1] = row[1].gsub(/([a-zA-Z0-9])/){ NKF.nkf("-wWZ", $1) }
row[1] = NKF.nkf("-wZ1", row[1]).strip
#=> error
# `gsub': incompatible encoding regexp match
# (UTF-8 regexp with ASCII-8BIT string)
# (Encoding::CompatibilityError)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment