开发者

Ruby on Rails - Fixtures populate sqlite3 database with wrong utf-8 encoding

开发者 https://www.devze.com 2023-03-23 11:25 出处:网络
Seeding the sqlite3 database with Fixtures did work wit开发者_运维知识库h config1 but with config2 utf-8 support fails.

Seeding the sqlite3 database with Fixtures did work wit开发者_运维知识库h config1 but with config2 utf-8 support fails.

config1: Ubuntu 11.04, ruby 1.9.2p136, Rails 3.0.3, "development" environment

config2: OS X Lion, ruby 1.9.2p290, Rails 3.0.3, "development" environment

When having a yml file like

001: 
  id: 1
  name: "\xC3\xBC"

I use it to populate the database with

Fixtures.create_fixtures(...)

in seed.rb

Afterwards the database shout have an entry with id 1 and name "ü". That would be correct. That worked with config1. With config2 I alway have an entry with name "ü". utf-8 encoding seems to fail.

I already turned on UTF-8 everywhere in the rails project:

encoding: utf-8

in database.yml

# encoding: utf-8

in seeds.rb

Encoding.default_external = "UTF-8"
Encoding.default_internal = "UTF-8"
config.encoding = "utf-8"

in config/environments/development.rb


Is it possible that these two systems have different endianness?

From the SQLite3 release notes:

Support for UTF-8 and UTF-16

The new API for SQLite 3.0 contains routines that accept text as both UTF-8 and UTF-16 in the native byte order of the host machine. Each database file manages text as either UTF-8, UTF-16BE (big-endian), or UTF-16LE (little-endian).

You can check here: http://en.wikipedia.org/wiki/Endianness#Endianness_and_operating_systems_on_architectures

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号