Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Inserting integer saves different value

#5149

Hello,

When I submit a form with an integer field value: 5551231234
A different value is saved in the database.

Server Log when submitting the form

Started POST "/admin/customers" for 127.0.0.1 at 2010-07-18 23:23:42 -0500
  Processing by Admin::CustomersController#create as HTML
  Parameters: {"_snowman"=>"☃", "authenticity_token"=>"RwTyuC1ZegeSODuOPiVmrvscaFwDSVpXY08zF4GCOR0=", "customer"=>{"first_name"=>"Joe", "last_name"=>"Shmoe", "company_name"=>"Awesome LLC", "phone_number"=>"5551231234", "street"=>"Some Street", "city"=>"TheCity", "state"=>"MO", "zipcode"=>"63342"}, "commit"=>"Create Customer"}
  SQL (0.5ms)  SHOW TABLES
  SQL (0.2ms)  BEGIN
  SQL (1.4ms)  describe customers
  SQL (0.3ms)  INSERT INTO customers (city, company_name, created_at, first_name, last_name, phone_number, state, street, submitted_at, updated_at, zipcode) VALUES ('TheCity', 'Awesome LLC', '2010-07-19 04:23:43', 'Joe', 'Shmoe', 5551231234, 'MO', 'Some Street', NULL, '2010-07-19 04:23:43', 63342)
  SQL (1.1ms)  COMMIT
Redirected to http://127.0.0.1:3000/admin/customers
Completed 302 Found in 147ms

When I get the customer in console I get a different phone number:

ruby-1.9.2-rc1 > Customer.all
 => [#<Customer id: 3, submitted_at: nil, first_name: "Joe", last_name: "Shmoe", company_name: "Awesome LLC", phone_number: 2147483647, street: "Some Street", city: "TheCity", state: "MO", zipcode: 63342, created_at: "2010-07-19 04:25:47", updated_at: "2010-07-19 04:25:47">]

Trying to save as 5551231234 and got 2147483647. I tried the same value with zipcode and got the same results "2147483647". It seems whenever inserting with a value greater than an x amount does not work. This worked in previous rails versions so I do not think it is a database issue but I could be wrong, please help.

I also tried as a float field_type with no avail.

[msimpson@dakota Code] (master) $ ruby -v
ruby 1.9.2dev (2010-07-02 revision 28524) [x86_64-darwin10.4.0]
[msimpson@dakota Code] (master) $ rails -v
Rails 3.0.0.beta4

Reported by Matt Simpson · July 19th, 2010 @ 05:39 AM

State: stale
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Matt Simpson
    Matt Simpson
    • Tag changed from create, field_type, integer to create, field_type, integer, mysql, rails3, ruby1.9

    July 19th, 2010 @ 05:40 AM

  2. Miles Egan
    Miles Egan

    I think what you're seeing here is a MySQL limitation:
    http://dev.mysql.com/doc/refman/5.1/en/numeric-types.html

    The largest value an int field can contain is 2147483647.

    You can use a MySQL bigint to hold larger numbers than that. You can declare them like this;

        create_table :customers do |t|
          t.integer :code, :limit => 5
          t.timestamps
        end
    

    July 19th, 2010 @ 06:00 AM

  3. rails
    rails
    • Tag changed from create, field_type, integer, mysql, rails3, ruby1.9 to create, field_type, integer, mysql, rails3, ruby19
    • State changed from new to open

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    April 5th, 2011 @ 01:00 AM

  4. rails
    rails
    • State changed from open to stale

    April 5th, 2011 @ 01:00 AM