Forum: Ruby on Rails inconsistent data in mySQL using string field

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B148a9a418f647ed8d1358c17e64a2d8?d=identicon&s=25 Louise Rains (rainyglade)
on 2009-01-20 20:27
I have a migration:

class CreateCodeRequests < ActiveRecord::Migration
  def self.up
    create_table :code_requests do |t|
      t.string :key_number
      t.string :version
      t.datetime :maint_end_date
      t.string :nls_name
      t.string :company_name
      t.string :email_address
      t.boolean :temp
      t.integer :temp_week_to_start
      t.integer :temp_num_weeks

      t.timestamps
    end
  end

  def self.down
    drop_table :code_requests
  end
end

and two fixtures in a .yml file:

one:
  id: 1
  key_number: 0200699
  version: 12.2
  maint_end_date: 2009-05-31 12:00:0
  nls_name: automod
  company_name: U of Anywyere
  email_address: Joe.Smith@uanywhere.edu
  temp: false
  temp_week_to_start:
  temp_num_weeks:

two:
  id: 2
  key_number: 0200100
  version: 12.2
  maint_end_date: 2009-03-27 12:00:00
  nls_name:
  company_name: Company1
  email_address: sue_jones@company1.com
  temp: false
  temp_week_to_start:
  temp_num_weeks:


When I do the migration and load the fixtures I get data in the
key_number field of 0200699 for the first one, but 65600 for the 2nd
one, unless I put quotes around "0200100".  What could be the reason for
this?

TIA!

LG Rains
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-01-20 20:35
(Received via mailing list)
On 20 Jan 2009, at 19:27, Louise Rains wrote:

>
> When I do the migration and load the fixtures I get data in the
> key_number field of 0200699 for the first one, but 65600 for the 2nd
> one, unless I put quotes around "0200100".  What could be the reason
> for
> this?
>
because yml assumes that it's a number in base 8. with the quotes it
sees that it's a string and doesn't do anything with it.

Fred
B148a9a418f647ed8d1358c17e64a2d8?d=identicon&s=25 Louise Rains (rainyglade)
on 2009-01-20 21:56
Frederick Cheung wrote:
> On 20 Jan 2009, at 19:27, Louise Rains wrote:
>
>>
>> When I do the migration and load the fixtures I get data in the
>> key_number field of 0200699 for the first one, but 65600 for the 2nd
>> one, unless I put quotes around "0200100".  What could be the reason
>> for
>> this?
>>
> because yml assumes that it's a number in base 8. with the quotes it
> sees that it's a string and doesn't do anything with it.
>
> Fred

Good answer, I knew that :)  Except, 0200699 has the leading 0 on it.
Is it the fact that 0200699 has 9 in it - a non-base 8 digit?

Thanks,
Louise
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-01-20 22:05
(Received via mailing list)
On 20 Jan 2009, at 20:56, Louise Rains wrote:

>>>
>> because yml assumes that it's a number in base 8. with the quotes it
>> sees that it's a string and doesn't do anything with it.
>>
>> Fred
>
> Good answer, I knew that :)  Except, 0200699 has the leading 0 on it.
> Is it the fact that 0200699 has 9 in it - a non-base 8 digit?

I'd guess so.

Fred
This topic is locked and can not be replied to.