Alexey Muranov wrote in post #1019177:
> I confirm that there is a problem.
> This is with Rails 3.1.0rc8
>
> $ rails new test_ip
> $ cd test_ip
> $ rails generate model MyModel ip:string description:string
> $ rake db:migrate
> $ rails generate controller Writer write_records
>
> app/controllers/writer_controller.rb:
>
> class WriterController < ApplicationController
> def write_records
> MyModel.create!(:ip => request.remote_ip, :description => 'request')
> MyModel.create!(:ip => '127.0.0.1', :description => 'string')
> end
> end
>
> $ rails s
>
> go to
> http://localhost:3000/writer/write_records
>
> $ rails c
>
>> MyModel.all
> MyModel Load (0.2ms) SELECT "my_models".* FROM "my_models"
> => [#<MyModel id: 1, ip: "127.0.0.1", description: "request",
> created_at: "2011-08-30 09:42:09", updated_at: "2011-08-30 09:42:09">,
> #<MyModel id: 2, ip: "127.0.0.1", description: "string", created_at:
> "2011-08-30 09:42:09", updated_at: "2011-08-30 09:42:09">]
>
>> MyModel.where(:ip => '127.0.0.1').all
> MyModel Load (0.2ms) SELECT "my_models".* FROM "my_models" WHERE
> "my_models"."ip" = '127.0.0.1'
> => [#<MyModel id: 2, ip: "127.0.0.1", description: "string",
> created_at: "2011-08-30 09:42:09", updated_at: "2011-08-30 09:42:09">]
>
>> MyModel.first.ip == '127.0.0.1'
> MyModel Load (0.2ms) SELECT "my_models".* FROM "my_models" LIMIT 1
> => true
>
> In the database for the first ip i have: X'3132372E302E302E31'
Yes, Christoph linked to his sqlite dump, which showed the sane thing::
# dump shows:
sqlite> .dump doc_types
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE "doc_types" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT
NULL, "name" varchar(255), "description" varchar(255));
INSERT INTO "doc_types" VALUES(6,X'3132372E302E302E31','request');
INSERT INTO "doc_types" VALUES(7,'127.0.0.1','string');
It sure seems like an encoding issue. If you read the sqlite docs,
labeling a column as a certain type is not very rigid: you can insert
different types in a column. In fact, the sqlite2 docs say that having
typed columns is a "misfeature" of other databases. sqlite3 seems to
have backed off that statement because sqlite3 appears to provide loose
typing for columns. In any case, just because the column type is string
does not mean the types in the column are necessarily the same.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.