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

Remove 'if exists' from drop table statement then use table_exists? #16778

Merged
merged 1 commit into from
Sep 2, 2014

Conversation

yahonda
Copy link
Member

@yahonda yahonda commented Sep 2, 2014

This pull request addresses ActiveRecord::StatementInvalid: OCIError: ORA-00933: SQL command not properly ended errors with Oracle database. Since Oracle database does not support 'drop table if exists' statement.

One of current test case output is here:

$ ARCONN=oracle ruby -Itest test/cases/attribute_decorators_test.rb -n test_attributes_can_be_decorated
Using oracle
Run options: -n test_attributes_can_be_decorated --seed 63611

# Running:

E

Finished in 0.138139s, 7.2391 runs/s, 14.4781 assertions/s.

  1) Error:
ActiveRecord::AttributeDecoratorsTest#test_attributes_can_be_decorated:
ActiveRecord::StatementInvalid: OCIError: ORA-00933: SQL command not properly ended: DROP TABLE IF EXISTS attribute_decorators_model
    stmt.c:230:in oci8lib_210.so
    /home/yahonda/.rvm/gems/ruby-2.1.2@rails42/gems/ruby-oci8-2.1.7/lib/oci8/cursor.rb:129:in `exec'
    /home/yahonda/.rvm/gems/ruby-2.1.2@rails42/gems/ruby-oci8-2.1.7/lib/oci8/oci8.rb:278:in `exec_internal'
    /home/yahonda/.rvm/gems/ruby-2.1.2@rails42/gems/ruby-oci8-2.1.7/lib/oci8/oci8.rb:269:in `exec'
    /home/yahonda/git/oracle-enhanced/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:429:in `exec'
    /home/yahonda/git/oracle-enhanced/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:88:in `exec'
    /home/yahonda/git/oracle-enhanced/lib/active_record/connection_adapters/oracle_enhanced_database_statements.rb:10:in `block in execute'
    /home/yahonda/git/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:458:in `block in log'
    /home/yahonda/git/rails/activesupport/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
    /home/yahonda/git/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:452:in `log'
    /home/yahonda/git/oracle-enhanced/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:1270:in `log'
    /home/yahonda/git/oracle-enhanced/lib/active_record/connection_adapters/oracle_enhanced_database_statements.rb:10:in `execute'
    test/cases/attribute_decorators_test.rb:31:in `block in <class:AttributeDecoratorsTest>'
    /home/yahonda/git/rails/activesupport/lib/active_support/callbacks.rb:438:in `instance_exec'
    /home/yahonda/git/rails/activesupport/lib/active_support/callbacks.rb:438:in `block in make_lambda'
    /home/yahonda/git/rails/activesupport/lib/active_support/callbacks.rb:257:in `call'
    /home/yahonda/git/rails/activesupport/lib/active_support/callbacks.rb:257:in `block in simple'
    /home/yahonda/git/rails/activesupport/lib/active_support/callbacks.rb:87:in `call'
    /home/yahonda/git/rails/activesupport/lib/active_support/callbacks.rb:87:in `run_callbacks'
    /home/yahonda/git/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb:45:in `after_teardown'
    /home/yahonda/git/rails/activerecord/lib/active_record/fixtures.rb:820:in `after_teardown'

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

I understand if exists is much simpler and supported by SQLite, PostgreSQL and MySQL, I'd like to execute Rails unit tests with Oracle database to keep support compatibility with Rails. I tested this commit does not cause regressions with sqlite, mysql, mysql2 and postgresql adapters.

Since 'drop table if exists' statement does not always work with
some databases such as Oracle.
rafaelfranca added a commit that referenced this pull request Sep 2, 2014
Remove 'if exists' from drop table statement then use `table_exists?`
@rafaelfranca rafaelfranca merged commit 5ddbaea into rails:master Sep 2, 2014
yahonda referenced this pull request Sep 9, 2014
`AbstractAdapter#supports_views?` defaults to `false` so we have to turn it on
in adapter subclasses. Currently the flag only controls test execution.

/cc @yahonda
@yahonda yahonda deleted the if_exists branch June 22, 2015 20:21
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