Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map :bigint as NUMBER(19) sql_type by using :limit => 19 for Oracle #20401

Merged

Conversation

yahonda
Copy link
Member

@yahonda yahonda commented Jun 1, 2015

since NUMBER(8) is not enough to store the maximum number of bigint.
Oracle NUMBER(p,0) as handled as integer
because there is no dedicated integer sql data type exist in Oracle database.

Also NUMBER(p,s) precision can take up to 38. p means the number of digits, not the byte length.
bigint type needs 19 digits as follows.

    $ irb
    2.2.2 :001 > limit = 8
     => 8
    2.2.2 :002 > maxvalue_of_bigint = 1 << ( limit * 8 - 1)
     => 9223372036854775808
    2.2.2 :003 > puts maxvalue_of_bigint.to_s.length
    19
     => nil
    2.2.2 :004 >

Also this pull request addresses following failures. Actually Oracle enhanced adapter is still trying to
support Rails 4.2. Then these tests are done in 4-2-stable branch. but I wanted to include this pull request in master branch first. Then I tested in 4-2-stable branch and cherry-pick it to the master branch.

$ ARCONN=oracle ruby -Itest test/cases/connection_adapters/type_lookup_test.rb -n test_bigint_limit
Using oracle
Run options: -n test_bigint_limit --seed 46517

# Running:

F

Finished in 0.005952s, 168.0172 runs/s, 168.0172 assertions/s.

  1) Failure:
ActiveRecord::ConnectionAdapters::TypeLookupTest#test_bigint_limit [test/cases/connection_adapters/type_lookup_test.rb:84]:
Expected: 8
  Actual: 19

1 runs, 1 assertions, 1 failures, 0 errors, 0 skips
$
$ ARCONN=oracle ruby -Itest test/cases/migration/change_schema_test.rb -n test_create_table_with_bigint

Using oracle
Run options: -n test_create_table_with_bigint --seed 57162

# Running:

F

Finished in 0.054332s, 18.4054 runs/s, 18.4054 assertions/s.

  1) Failure:
ActiveRecord::Migration::ChangeSchemaTest#test_create_table_with_bigint [test/cases/migration/change_schema_test.rb:108]:
Expected: "NUMBER(8)"
  Actual: "NUMBER(19)"

1 runs, 1 assertions, 1 failures, 0 errors, 0 skips
$

since NUMBER(8) is not enough to store the maximum number of bigint.
Oracle NUMBER(p,0) as handled as integer
because there is no dedicated integer sql data type exist in Oracle database.

Also NUMBER(p,s) precision can take up to 38. p means the number of digits, not the byte length.
bigint type needs 19 digits as follows.

	$ irb
	2.2.2 :001 > limit = 8
	 => 8
	2.2.2 :002 > maxvalue_of_bigint = 1 << ( limit * 8 - 1)
	 => 9223372036854775808
	2.2.2 :003 > puts maxvalue_of_bigint.to_s.length
	19
	 => nil
	2.2.2 :004 >
rafaelfranca added a commit that referenced this pull request Jun 1, 2015
…racle

Map :bigint as NUMBER(19) sql_type by using `:limit => 19` for Oracle
@rafaelfranca rafaelfranca merged commit 1bfa81b into rails:master Jun 1, 2015
@yahonda yahonda deleted the master_bigint_as_limit_19_in_oracle branch June 22, 2015 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants