以下是我最终使用错误的ActiveRecord类型的方法。
首先,表格的架构:
Field | Type
------------------------------
id | int(10) unsigned
user_name | varchar(255)
以下是我在irb中尝试的代码:
require 'active_record'
ActiveRecord::Base.establish_connection(adapter: 'mysql', host: 'mrom.akamai.com', username: 'SOME_USER', password: 'SOME_PASSWORD', database: 'mrom_v3')
c=ActiveRecord::Base.connection
r = c.exec_query("select id, user_name, 'fixed string' value from user limit 2")
t = r.column_types
=> {"id"=>#<ActiveRecord::Type::Integer:0x007fc144a5ed00 @precision=nil, @scale=nil, @limit=nil, @range=-2147483648...2147483648>, "user_name"=>#<ActiveRecord::Type::Value:0x007fc144113f20 @precision=nil, @scale=nil, @limit=nil>, "value"=>#<ActiveRecord::Type::Decimal:0x007fc144113e30 @precision=nil, @scale=nil, @limit=nil>}
注意user_name和value列的:: Value和:: Decimal类型。我期待着String。
我该如何解决这个问题?