Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

euc is converted to utf-8

  • Loading branch information...
commit ab626d96239259073fc315291bb20d9d00de559d 1 parent 8cfa9f9
@tenderlove authored
Showing with 23 additions and 2 deletions.
  1. +6 −2 ext/deebee/deebee.c
  2. +17 −0 test/test_statement.rb
View
8 ext/deebee/deebee.c
@@ -24,10 +24,14 @@ static VALUE prepare(VALUE self, VALUE sql)
sqlite3_stmt *stmt;
Data_Get_Struct(self, sqlite3, ctx);
+
+ VALUE utf8_string = rb_funcall(sql, rb_intern("encode"), 1,
+ rb_str_new2("UTF-8"));
+
int status = sqlite3_prepare_v2(
ctx,
- StringValuePtr(sql), // TODO: convert this to UTF-8
- RSTRING_LEN(sql),
+ StringValuePtr(utf8_string),
+ RSTRING_LEN(utf8_string),
&stmt,
NULL
);
View
17 test/test_statement.rb
@@ -26,4 +26,21 @@ def test_string_encoding
assert_equal test, string
assert_equal db.encoding, string.encoding
end
+
+ def test_string_encoding_euc_jp
+ db = SQLite3::DeeBee.open(File.join(Dir.tmpdir, 'foo.db'))
+ string = nil
+ test = "日本語は楽しい"
+
+ sql = "select '#{test}'".encode('EUC-JP')
+ stmt = db.prepare sql
+ assert_equal "EUC-JP", sql.encoding.name
+
+ stmt.each { |row| string = row.first }
+
+ utf8 = Encoding.find('UTF-8')
+ assert_equal utf8, string.encoding
+ assert_equal test, string
+ assert_equal db.encoding, string.encoding
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.