This project is archived and is in readonly mode.

#5149 ✓stale
Matt Simpson

Inserting integer saves different value

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

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

Comments and changes to this ticket

  • Matt Simpson

    Matt Simpson July 19th, 2010 @ 05:40 AM

    • Tag changed from create, field_type, integer to create, field_type, integer, mysql, rails3, ruby1.9
  • Miles Egan

    Miles Egan July 19th, 2010 @ 06:00 AM

    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
    
  • rails

    rails April 5th, 2011 @ 01:00 AM

    • 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.

  • rails

    rails April 5th, 2011 @ 01:00 AM

    • State changed from “open” to “stale”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages