Skip to content

Commit

Permalink
converting file names to UTF-8 when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Feb 15, 2010
1 parent f79833c commit 746adcd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
7 changes: 7 additions & 0 deletions ext/sqlite3/database.c
Expand Up @@ -58,6 +58,13 @@ static VALUE initialize(int argc, VALUE *argv, VALUE self)
if(Qtrue == rb_hash_aref(opts, ID2SYM(rb_intern("utf16")))) {
status = sqlite3_open16(StringValuePtr(file), &ctx->db);
} else {

#ifdef HAVE_RUBY_ENCODING_H
if(!UTF8_P(file)) {
file = rb_str_export_to_enc(file, rb_utf8_encoding());
}
#endif

status = sqlite3_open_v2(
StringValuePtr(file),
&ctx->db,
Expand Down
10 changes: 4 additions & 6 deletions test/test_encoding.rb
Expand Up @@ -23,12 +23,10 @@ def test_blob_is_binary
assert_equal str, string.force_encoding('UTF-8')
end

#def test_db_with_eucjp
# #db = SQLite3::Database.new(':memory:'.encode('EUC-JP'))
# db = SQLite3::Database.new(':memory:')
# assert_equal(Encoding.find('UTF-8'), db.encoding)
# p db.execute('select * from sqlite_master')
#end
def test_db_with_eucjp
db = SQLite3::Database.new(':memory:'.encode('EUC-JP'))
assert_equal(Encoding.find('UTF-8'), db.encoding)
end

def test_db_with_utf16
db = SQLite3::Database.new(':memory:'.encode('UTF-16LE'))
Expand Down

0 comments on commit 746adcd

Please sign in to comment.