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.
Louise R. (Guest)
on 2009-01-20 21: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: removed_email_address@domain.invalid
  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: removed_email_address@domain.invalid
  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
Frederick C. (Guest)
on 2009-01-20 21:35
(Received via mailing list)
On 20 Jan 2009, at 19:27, Louise R. 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
Louise R. (Guest)
on 2009-01-20 22:56
Frederick C. wrote:
> On 20 Jan 2009, at 19:27, Louise R. 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
Frederick C. (Guest)
on 2009-01-20 23:05
(Received via mailing list)
On 20 Jan 2009, at 20:56, Louise R. 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.