Code Monkey home page Code Monkey logo

oracle-enhanced's Introduction

activerecord-oracle_enhanced-adapter

Oracle enhanced adapter for ActiveRecord

DESCRIPTION

Oracle enhanced ActiveRecord adapter provides Oracle database access from Ruby on Rails applications. Oracle enhanced adapter can be used from Ruby on Rails versions between 2.3.x and 7.0 and it is working with Oracle database versions 10g and higher

INSTALLATION

Rails 7.0

Oracle enhanced adapter version 7.0 supports Rails 7.0 When using Ruby on Rails version 7.0 then in Gemfile include

# Use oracle as the database for Active Record
gem 'activerecord-oracle_enhanced-adapter', '~> 7.0.0'

Rails 6.1

Oracle enhanced adapter version 6.1 supports Rails 6.1. When using Ruby on Rails version 6.1 then in Gemfile include

# Use oracle as the database for Active Record
gem 'activerecord-oracle_enhanced-adapter', '~> 6.1.0'
gem 'ruby-oci8' # only for CRuby users

Rails 6.0

Oracle enhanced adapter version 6.0 supports Rails 6.0. When using Ruby on Rails version 6.0 then in Gemfile include

# Use oracle as the database for Active Record
gem 'activerecord-oracle_enhanced-adapter', '~> 6.0.0'
gem 'ruby-oci8' # only for CRuby users

Rails 5.2

Oracle enhanced adapter version 5.2 supports Rails 5.2. When using Ruby on Rails version 5.2 then in Gemfile include

# Use oracle as the database for Active Record
gem 'activerecord-oracle_enhanced-adapter', '~> 5.2.0'
gem 'ruby-oci8' # only for CRuby users

Rails 5.1

Oracle enhanced adapter version 1.8 just supports Rails 5.1 and does not support Rails 5.0 or lower version of Rails. When using Ruby on Rails version 5.1 then in Gemfile include

# Use oracle as the database for Active Record
gem 'activerecord-oracle_enhanced-adapter', '~> 1.8.0'
gem 'ruby-oci8' # only for CRuby users

Rails 5.0

Oracle enhanced adapter version 1.7 just supports Rails 5.0 and does not support Rails 4.2 or lower version of Rails. When using Ruby on Rails version 5.0 then in Gemfile include

# Use oracle as the database for Active Record
gem 'activerecord-oracle_enhanced-adapter', '~> 1.7.0'
gem 'ruby-oci8' # only for CRuby users

Rails 4.2

Oracle enhanced adapter version 1.6 just supports Rails 4.2 and does not support Rails 4.1 or lower version of Rails. When using Ruby on Rails version 4.2 then in Gemfile include

gem 'activerecord-oracle_enhanced-adapter', '~> 1.6.0'

where instead of 1.6.0 you can specify any other desired version. It is recommended to specify version with ~> which means that use specified version or later patch versions (in this example any later 1.6.x version but not 1.7.x version). Oracle enhanced adapter maintains API backwards compatibility during patch version upgrades and therefore it is safe to always upgrade to latest patch version.

Rails 4.0 and 4.1

Oracle enhanced adapter version 1.5 supports Rails 4.0 and 4.1 and does not support Rails 3.2 or lower version of Rails.

When using Ruby on Rails version 4.0 and 4.1 then in Gemfile include

gem 'activerecord-oracle_enhanced-adapter', '~> 1.5.0'

where instead of 1.5.0 you can specify any other desired version. It is recommended to specify version with ~> which means that use specified version or later patch versions (in this example any later 1.5.x version but not 1.6.x version). Oracle enhanced adapter maintains API backwards compatibility during patch version upgrades and therefore it is safe to always upgrade to latest patch version.

If you would like to use latest adapter version from github then specify

gem 'activerecord-oracle_enhanced-adapter', :git => 'git://github.com/rsim/oracle-enhanced.git'

If you are using CRuby >= 1.9.3 then you need to install ruby-oci8 gem as well as Oracle client, e.g. Oracle Instant Client. Include in Gemfile also ruby-oci8:

gem 'ruby-oci8', '~> 2.1.0'

If you are using JRuby then you need to download latest Oracle JDBC driver - either ojdbc7.jar or ojdbc6.jar for Java 7, ojdbc6.jar for Java 6 or ojdbc5.jar for Java 5. And copy this file to one of these locations:

  • in ./lib directory of Rails application
  • in some directory which is in PATH
  • in JRUBY_HOME/lib directory
  • or include path to JDBC driver jar file in Java CLASSPATH

After specifying necessary gems in Gemfile run

bundle install

to install the adapter (or later run bundle update to force updating to latest version).

Rails 3

When using Ruby on Rails version 3 then in Gemfile include

gem 'activerecord-oracle_enhanced-adapter', '~> 1.4.0'

where instead of 1.4.0 you can specify any other desired version. It is recommended to specify version with ~> which means that use specified version or later patch versions (in this example any later 1.4.x version but not 1.5.x version). Oracle enhanced adapter maintains API backwards compatibility during patch version upgrades and therefore it is safe to always upgrade to latest patch version.

If you would like to use latest adapter version from github then specify

gem 'activerecord-oracle_enhanced-adapter', :git => 'git://github.com/rsim/oracle-enhanced.git'

If you are using MRI 1.8 or 1.9 Ruby implementation then you need to install ruby-oci8 gem as well as Oracle client, e.g. Oracle Instant Client. Include in Gemfile also ruby-oci8:

gem 'ruby-oci8', '~> 2.1.0'

If you are using JRuby then you need to download latest Oracle JDBC driver - either ojdbc6.jar for Java 6 or ojdbc5.jar for Java 5. And copy this file to one of these locations:

  • in ./lib directory of Rails application
  • in some directory which is in PATH
  • in JRUBY_HOME/lib directory
  • or include path to JDBC driver jar file in Java CLASSPATH

After specifying necessary gems in Gemfile run

bundle install

to install the adapter (or later run bundle update to force updating to latest version).

Rails 2.3

If you don't use Bundler in Rails 2 application then you need to specify gems in config/environment.rb, e.g.

Rails::Initializer.run do |config|
  # ...
  config.gem 'activerecord-oracle_enhanced-adapter', :lib => 'active_record/connection_adapters/oracle_enhanced_adapter'
  config.gem 'ruby-oci8'
  # ...
end

But it is recommended to use Bundler for gem version management also for Rails 2.3 applications (search for instructions in Google).

Without Rails and Bundler

If you want to use ActiveRecord and Oracle enhanced adapter without Rails and Bundler then install it just as a gem:

gem install activerecord-oracle_enhanced-adapter

USAGE

Database connection

In Rails application config/database.yml use oracle_enhanced as adapter name, e.g.

development:
  adapter: oracle_enhanced
  database: xe
  username: user
  password: secret

If you're connecting to a service name, indicate the service with a leading slash on the database parameter:

development:
  adapter: oracle_enhanced
  database: /xe
  username: user
  password: secret

If TNS_ADMIN environment variable is pointing to directory where tnsnames.ora file is located then you can use TNS connection name in database parameter. Otherwise you can directly specify database host, port (defaults to 1521) and database name in the following way:

development:
  adapter: oracle_enhanced
  host: localhost
  port: 1521
  database: xe
  username: user
  password: secret

or you can use Oracle specific format in database parameter:

development:
  adapter: oracle_enhanced
  database: //localhost:1521/xe
  username: user
  password: secret

or you can even use Oracle specific TNS connection description:

development:
  adapter: oracle_enhanced
  database: "(DESCRIPTION=
    (ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
    (CONNECT_DATA=(SERVICE_NAME=xe))
  )"
  username: user
  password: secret

If you choose to specify your database connection via the DATABASE_URL environment variable, note that the adapter name uses a dash instead of an underscore:

DATABASE_URL=oracle-enhanced://localhost/XE

You can also specify a connection string via the DATABASE_URL, as long as it doesn't have any whitespace:

DATABASE_URL=oracle-enhanced://user:secret@connection-string/(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=xe)))

If you deploy JRuby on Rails application in Java application server that supports JNDI connections then you can specify JNDI connection as well:

development:
  adapter: oracle_enhanced
  jndi: "jdbc/jndi_connection_name"

To use jndi with Tomcat you need to set the accessToUnderlyingConnectionAllowed to true property on the pool. See the Tomcat Documentation for reference.

You can find other available database.yml connection parameters in oracle_enhanced_adapter.rb. There are many NLS settings as well as some other Oracle session settings.

Adapter settings

If you want to change Oracle enhanced adapter default settings then create initializer file e.g. config/initializers/oracle.rb specify there necessary defaults, e.g.:

# It is recommended to set time zone in TZ environment variable so that the same timezone will be used by Ruby and by Oracle session
ENV['TZ'] = 'UTC'

ActiveSupport.on_load(:active_record) do
  ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.class_eval do
    # true and false will be stored as 'Y' and 'N'
    self.emulate_booleans_from_strings = true

    # start primary key sequences from 1 (and not 10000) and take just one next value in each session
    self.default_sequence_start_value = "1 NOCACHE INCREMENT BY 1"

    # Use old visitor for Oracle 12c database
    self.use_old_oracle_visitor = true

    # other settings ...
  end
end

In case of Rails 2 application you do not need to use ActiveSupport.on_load(:active_record) do ... end around settings code block.

See other adapter settings in oracle_enhanced_adapter.rb.

Legacy schema support

If you want to put Oracle enhanced adapter on top of existing schema tables then there are several methods how to override ActiveRecord defaults, see example:

class Employee < ActiveRecord::Base
  # specify schema and table name
  self.table_name = "hr.hr_employees"

  # specify primary key name
  self.primary_key = "employee_id"

  # specify sequence name
  self.sequence_name = "hr.hr_employee_s"

  # set which DATE columns should be converted to Ruby Date using ActiveRecord Attribute API
  # Starting from Oracle enhanced adapter 1.7 Oracle `DATE` columns are mapped to Ruby `Date` by default.
  attribute :hired_on, :date
  attribute :birth_date_on, :date

  # set which DATE columns should be converted to Ruby Time using ActiveRecord Attribute API
  attribute :last_login_time, :datetime

  # set which VARCHAR2 columns should be converted to true and false using ActiveRecord Attribute API
  attribute :manager, :boolean
  attribute :active, :boolean

  # set which columns should be ignored in ActiveRecord
  ignore_table_columns :attribute1, :attribute2
end

You can also access remote tables over database link using

self.table_name "hr_employees@db_link"

Examples for Rails 4.x

class Employee < ActiveRecord::Base
  # specify schema and table name
  self.table_name = "hr.hr_employees"

  # specify primary key name
  self.primary_key = "employee_id"

  # specify sequence name
  self.sequence_name = "hr.hr_employee_s"

  # If you're using Rails 4.2 or earlier you can do this

  # set which DATE columns should be converted to Ruby Date
  set_date_columns :hired_on, :birth_date_on

  # set which DATE columns should be converted to Ruby Time
  set_datetime_columns :last_login_time

  # set which VARCHAR2 columns should be converted to true and false
  set_boolean_columns :manager, :active

  # set which columns should be ignored in ActiveRecord
  ignore_table_columns :attribute1, :attribute2
end

Examples for Rails 3.2 and lower version of Rails

class Employee < ActiveRecord::Base
  # specify schema and table name
  set_table_name "hr.hr_employees"

  # specify primary key name
  set_primary_key "employee_id"

  # specify sequence name
  set_sequence_name "hr.hr_employee_s"

  # set which DATE columns should be converted to Ruby Date
  set_date_columns :hired_on, :birth_date_on

  # set which DATE columns should be converted to Ruby Time
  set_datetime_columns :last_login_time

  # set which VARCHAR2 columns should be converted to true and false
  set_boolean_columns :manager, :active

  # set which columns should be ignored in ActiveRecord
  ignore_table_columns :attribute1, :attribute2
end

You can also access remote tables over database link using

set_table_name "hr_employees@db_link"

Custom create, update and delete methods

If you have legacy schema and you are not allowed to do direct INSERTs, UPDATEs and DELETEs in legacy schema tables and need to use existing PL/SQL procedures for create, updated, delete operations then you should add ruby-plsql gem to your application, include ActiveRecord::OracleEnhancedProcedures in your model and then define custom create, update and delete methods, see example:

class Employee < ActiveRecord::Base
  include ActiveRecord::OracleEnhancedProcedures

  # when defining create method then return ID of new record that will be assigned to id attribute of new object
  set_create_method do
    plsql.employees_pkg.create_employee(
      :p_first_name => first_name,
      :p_last_name => last_name,
      :p_employee_id => nil
    )[:p_employee_id]
  end

  set_update_method do
    plsql.employees_pkg.update_employee(
      :p_employee_id => id,
      :p_first_name => first_name,
      :p_last_name => last_name
    )
  end

  set_delete_method do
    plsql.employees_pkg.delete_employee(
      :p_employee_id => id
    )
  end
end

In addition in config/initializers/oracle.rb initializer specify that ruby-plsql should use ActiveRecord database connection:

plsql.activerecord_class = ActiveRecord::Base

Oracle CONTEXT index support

Every edition of Oracle database includes Oracle Text option for free which provides several full text indexing capabilities. Therefore in Oracle database case you don’t need external full text indexing and searching engines which can simplify your application deployment architecture.

To create simple single column index create migration with, e.g.

add_context_index :posts, :title

and you can remove context index with

remove_context_index :posts, :title

Include in class definition

has_context_index

and then you can do full text search with

Post.contains(:title, 'word')

You can create index on several columns (which will generate additional stored procedure for providing XML document with specified columns to indexer):

add_context_index :posts, [:title, :body]

And you can search either in all columns or specify in which column you want to search (as first argument you need to specify first column name as this is the column which is referenced during index creation):

Post.contains(:title, 'word')
Post.contains(:title, 'word within title')
Post.contains(:title, 'word within body')

See Oracle Text documentation for syntax that you can use in CONTAINS function in SELECT WHERE clause.

You can also specify some dummy main column name when creating multiple column index as well as specify to update index automatically after each commit (as otherwise you need to synchronize index manually or schedule periodic update):

add_context_index :posts, [:title, :body], :index_column => :all_text, :sync => 'ON COMMIT'

Post.contains(:all_text, 'word')

Or you can specify that index should be updated when specified columns are updated (e.g. in ActiveRecord you can specify to trigger index update when created_at or updated_at columns are updated). Otherwise index is updated only when main index column is updated.

add_context_index :posts, [:title, :body], :index_column => :all_text,
  :sync => 'ON COMMIT', :index_column_trigger_on => [:created_at, :updated_at]

And you can even create index on multiple tables by providing SELECT statements which should be used to fetch necessary columns from related tables:

add_context_index :posts,
  [:title, :body,
  # specify aliases always with AS keyword
  "SELECT comments.author AS comment_author, comments.body AS comment_body FROM comments WHERE comments.post_id = :id"
  ],
  :name => 'post_and_comments_index',
  :index_column => :all_text,
  :index_column_trigger_on => [:updated_at, :comments_count],
  :sync => 'ON COMMIT'

# search in any table columns
Post.contains(:all_text, 'word')
# search in specified column
Post.contains(:all_text, "aaa within title")
Post.contains(:all_text, "bbb within comment_author")

Please note that index_column must be a real column in your database and it's value will be overridden every time your index_column_trigger_on columns are changed. So, do not use columns with real data as index_column.

Index column can be created as:

add_column :posts, :all_text, :string, limit: 2, comment: 'Service column for context search index'

Oracle virtual columns support

Since version R11G1 Oracle database allows adding computed Virtual Columns to the table. They can be used as normal fields in the queries, in the foreign key contstraints and to partitioning data.

To define virtual column you can use virtual method in the create_table block, providing column expression in the :as option:

create_table :mytable do |t|
  t.decimal :price, :precision => 15, :scale => 2
  t.decimal :quantity, :precision => 15, :scale => 2
  t.virtual :amount, :as => 'price * quantity'
end

Oracle tries to predict type of the virtual column, based on its expression but sometimes it is necessary to state type explicitly. This can be done by providing :type option to the virtual method:

# ...
t.virtual :amount_2, :as => 'ROUND(price * quantity,2)', :type => :decimal, :precision => 15, :scale => 2
t.virtual :amount_str, :as => "TO_CHAR(quantity) || ' x ' || TO_CHAR(price) || ' USD = ' || TO_CHAR(quantity*price) || ' USD'",
    :type => :string, :limit => 100
# ...

It is possible to add virtual column to existing table:

add_column :mytable, :amount_4, :virtual, :as => 'ROUND(price * quantity,4)', :precision => 38, :scale => 4

You can use the same options here as in the create_table virtual method.

Changing virtual columns is also possible:

change_column :mytable, :amount, :virtual, :as => 'ROUND(price * quantity,0)', :type => :integer

Virtual columns allowed in the foreign key constraints. For example it can be used to force foreign key constraint on polymorphic association:

create_table :comments do |t|
  t.string :subject_type
  t.integer :subject_id
  t.virtual :subject_photo_id, :as => "CASE subject_type WHEN 'Photo' THEN subject_id END"
  t.virtual :subject_event_id, :as => "CASE subject_type WHEN 'Event' THEN subject_id END"
end

add_foreign_key :comments, :photos, :column => :subject_photo_id
add_foreign_key :comments, :events, :column => :subject_event_id

For backward compatibility reasons it is possible to use :default option in the create_table instead of :as option. But this is deprecated and may be removed in the future version.

Oracle specific schema statements and data types

There are several additional schema statements and data types available that you can use in database migrations:

  • add_foreign_key and remove_foreign_key for foreign key definition (and they are also dumped in db/schema.rb)
  • add_synonym and remove_synonym for synonym definition (and they are also dumped in db/schema.rb)
  • You can create table with primary key trigger using :primary_key_trigger => true option for create_table
  • You can define columns with raw type which maps to Oracle's RAW type
  • You can add table and column comments with :comment option
  • Default tablespaces can be specified for tables, indexes, clobs and blobs, for example:
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces =
  {:clob => 'TS_LOB', :blob => 'TS_LOB', :index => 'TS_INDEX', :table => 'TS_DATA'}

Switching to another schema

There are some requirements to connect to Oracle database first and switch to another user. Oracle enhanced adapter supports schema: option.

Note: Oracle enhanced adapter does not take care if the database user specified in username: parameter has appropriate privilege to select, insert, update and delete database objects owned by the schema specified in schema: parameter.

development:
  adapter: oracle_enhanced
  database: xe
  username: user
  password: secret
  schema: tableowner

Timeouts

By default, OCI libraries set a connect timeout of 60 seconds (as of v12.0), and do not set a data receive timeout.

While this may desirable if you process queries that take several minutes to complete, it may also lead to resource exhaustion if connections are teared down improperly during a query, e.g. by misbehaving networking equipment that does not inform both peers of connection reset. In this scenario, the OCI libraries will wait indefinitely for data to arrive, thus blocking indefinitely the application that initiated the query.

You can set a connect timeout, in seconds, using the following TNSNAMES parameters:

  • CONNECT_TIMEOUT
  • TCP_CONNECT_TIMEOUT

Example setting a 5 seconds connect timeout:

development:
  database: "(DESCRIPTION=
    (ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
    (CONNECT_TIMEOUT=5)(TCP_CONNECT_TIMEOUT=5)
    (CONNECT_DATA=(SERVICE_NAME=xe))
  )"

You should set a timeout value dependant on your network topology, and the time needed to establish a TCP connection with your ORACLE server. In real-world scenarios, a value larger than 5 should be avoided.

You can set receive and send timeouts, in seconds, using the following TNSNAMES parameters:

  • RECV_TIMEOUT - the maximum time the OCI libraries should wait for data to arrive on the TCP socket. Internally, it is implemented through a setsockopt(s, SOL_SOCKET, SO_RCVTIMEO). You should set this value to an integer larger than the server-side execution time of your longest-running query.
  • SEND_TIMEOUT the maximum time the OCI libraries should wait for write operations to complete on the TCP socket. Internally, it is implemented through a setsockopt(s, SOL_SOCKET, SO_SNDTIMEO). Values larger than 5 are a sign of poorly performing network, and as such it should be avoided.

Example setting a 60 seconds receive timeout and 5 seconds send timeout:

development:
  database: "(DESCRIPTION=
    (ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
    (RECV_TIMEOUT=60)(SEND_TIMEOUT=5)
    (CONNECT_DATA=(SERVICE_NAME=xe))
  )"

Example setting the above send/recv timeout plus a 5 seconds connect timeout:

development:
  database: "(DESCRIPTION=
    (ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
    (CONNECT_TIMEOUT=5)(TCP_CONNECT_TIMEOUT=5)
    (RECV_TIMEOUT=60)(SEND_TIMEOUT=5)
    (CONNECT_DATA=(SERVICE_NAME=xe))
  )"

Schema cache

rails db:schema:cache:dump generates db/schema_cache.yml to avoid queries for Oracle database dictionary, which could help your application response time if it takes time to look up database structure.

if any database structure changed by migrations, execute rails db:schema:cache:dump again and restart Rails server to reflect changes.

UPGRADE

Upgrade Rails 5.1 or older version to Rails 5.2

  • emulate_booleans_from_strings = true change

VARCHAR2(1) sql type is not registered as Type:Boolean even if emulate_booleans_from_strings = true

Configure each model attribute as follows:

class Post < ActiveRecord::Base
  attribute :is_default, :boolean
end
  • Remove OracleEnhancedAdapter.cache_columns to use Rails db:schema:cache:dump

Refer https://github.com/rsim/oracle-enhanced#schema-cache

Upgrade Rails 5.0 or older version to Rails 5.1

If your application gets ORA-01000: maximum open cursors exceeded after upgrading to Rails 5.1, check these two values and configure open_cursors parameter value at Oracle database instance is larger than :statement_limit value at database.yml.

  • open_cursors value at Oracle database instance
SQL> select name,value from v$parameter where name = 'open_cursors';

NAME
--------------------------------------------------------------------------------
VALUE
--------------------------------------------------------------------------------
open_cursors
1200
  • :statement_limit value at database.yml

Since Oracle enhanced adapter 1.8.0 this default value changed from 250 to 1000.

Upgrade Rails 4.2 or older version to Rails 5

If your Oracle table columns have been created for Rails :datetime attributes in Rails 4.2 or earlier, they need to migrate to :datetime in Rails 5 using one of two following ways:

  • Rails migration code example:
change_column :posts, :created_at, :datetime
change_column :posts, :updated_at, :datetime

or

  • SQL statement example
ALTER TABLE "POSTS" MODIFY "CREATED_AT" TIMESTAMP
ALTER TABLE "POSTS" MODIFY "UPDATED_AT" TIMESTAMP

In Rails 5 without running this migration or sql statement, these attributes will be handled as Rails :date type.

TROUBLESHOOTING

What to do if Oracle enhanced adapter is not working?

Please verify that

  1. Oracle Instant Client is installed correctly Can you connect to database using sqlnet?

  2. ruby-oci8 is installed correctly Try something like:

    ruby -rubygems -e "require 'oci8'; OCI8.new('username','password','database').exec('select * from dual') do |r| puts r.join(','); end"
    

    to verify that ruby-oci8 is working

  3. Verify that activerecord-oracle_enhanced-adapter is working from irb

require 'rubygems'
gem 'activerecord'
gem 'activerecord-oracle_enhanced-adapter'
require 'active_record'
ActiveRecord::Base.establish_connection(:adapter => "oracle_enhanced", :database => "database",:username => "user",:password => "password")

and see if it is successful (use your correct database, username and password)

What to do if Oracle enhanced adapter is not working with Phusion Passenger?

Oracle Instant Client and ruby-oci8 requires that several environment variables are set:

  • LD_LIBRARY_PATH (on Linux) or DYLD_LIBRARY_PATH (on Mac) should point to Oracle Instant Client directory (where Oracle client shared libraries are located)
  • TNS_ADMIN should point to directory where tnsnames.ora file is located
  • NLS_LANG should specify which territory and language NLS settings to use and which character set to use (e.g. "AMERICAN_AMERICA.UTF8")

If this continues to throw "OCI Library Initialization Error (OCIError)", you might also need

  • ORACLE_HOME set to full Oracle client installation directory

When Apache with Phusion Passenger (mod_passenger or previously mod_rails) is used for Rails application deployment then by default Ruby is launched without environment variables that you have set in shell profile scripts (e.g. .profile). Therefore it is necessary to set environment variables in one of the following ways:

  • Create wrapper script as described in Phusion blog or RayApps::Blog
  • Set environment variables in the file which is used by Apache before launching Apache worker processes - on Linux it typically is envvars file (look in apachectl or apache2ctl script where it is looking for envvars file) or /System/Library/LaunchDaemons/org.apache.httpd.plist on Mac OS X. See the following discussion thread for more hints.

What to do if my application is stuck?

If you see established TCP connections that do not exchange data, and you are unable to terminate your application using a TERM or an INT signal, and you are forced to use the KILL signal, then the OCI libraries may be waiting indefinitely for a network read operation to complete.

See the Timeouts section above.

RUNNING TESTS

See RUNNING_TESTS.md for information how to set up environment and run Oracle enhanced adapter unit tests.

LINKS

LICENSE

(The MIT License)

Copyright (c) 2008-2011 Graham Jenkins, Michael Schoen, Raimonds Simanovskis

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

oracle-enhanced's People

Contributors

akostadinov avatar andynu avatar basking2 avatar cdinger avatar chriger avatar dabla avatar ebeigarts avatar hss-mateus avatar joekhoobyar avatar josecoelho avatar joshpencheon avatar kamipo avatar kennyj avatar koic avatar kubo avatar matthewd avatar mkurkov avatar nhance avatar rammpeter avatar riyengar8 avatar rsim avatar rwc9u avatar rypit avatar sanelson2000 avatar substars avatar swamp09 avatar tenderlove avatar unclebilly avatar vjt avatar yahonda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

oracle-enhanced's Issues

find_each broken

Hi,

Ruby 1.8.7
Rails 3.0.5
activerecord-oracle_enhanced-adapter 1.3.2

When using the oracle_enhanced adapter the find_each method breaks:

/usr/local/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/
relation/batches.rb:68:in `find_in_batches': undefined method `gteq'
for nil:NilClass (NoMethodError)
        from /usr/local/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/
active_record/relation/batches.rb:20:in `find_each'
        from /usr/local/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/
active_record/base.rb:440:in `__send__'
        from /usr/local/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/
active_record/base.rb:440:in `find_each'
        from find_each.rb:19

Line 68 is: records = relation.where(primary_key.gteq(start)).all

My code was simply:

require 'active_record'

class SiteLocation < ActiveRecord::Base
  set_table_name = 'site_location'
  set_primary_key 'schoolid'
end

ActiveRecord::Base.establish_connection(
  :adapter  => 'oracle_enhanced',
  :database => 'our_db',
  :username => 'user',
  :password => 'xxxx'
)

SiteLocation.find_each{ |rec|
  p rec
}

Removing the "set_primary_key" call did not help.

The adapter complains about no ojdbc14.jar at the time of being included but not used

I'm working on an JRuby on Rails app which allows multiple database types. I include multiple JDBC connection adapter gems (including oracle-enhanced) and let the user/admin choose the connection type in database.yml.
However, oracle-enhanced looks for ojdbc14.jar file at the time the class is being loaded (a static block in lib/active_record/connection_adapters/oracle_enhanced_jdbc_connection.rb) and raises an exception (line 26) when not found, even if oracle-enhanced is not referenced in database.yml and thus not to be used at all.
The easy fix is to comment out the 'raise' line but I believe it can be done in a prettier way.

schema dumper cant't generate right foreign key name

after rake db:migrate,it generate db/schema.rb,why :name is like this:

add_foreign_key "countries", "regions", :name => "sys_c005603"

add_foreign_key "provinces", "countries", :name => "sys_c005607"

Should I have to asign :name option in migration file? I think the adapter should make it auto.

ActiveRecord 2.3.5 does not write data to the database

Using version 1.3.1 of the adapter and version 2.3.5 of ActiveRecord, I can query data from the database. However, if I update a ActiveRecord model object and try to save it (using save and save!), it returns true and the model object in memory contains the updated data, but the database itself is unchanged. If I try to fetch the same record from the database, the changes aren't there in the returned ActiveRecord model object.

The account I'm using to connect to the database has privileges to update the database data. I can update the same data using the same connection information in other database admin programs. Any idea why this is happening?

Allowing JNDI connections through oracle enhanced

I've patched the new_connection method in the 'oracle_enhanced_adapter'.rb-file so that JNDI connections through Java are possible. I've taken inspiration from the activerecord-jdbc-adapter-0.9.2 gem code to make it work. Actually it's just a matter of calling Java classes through JRuby as you would do in native Java, so it's pretty straight forward and the modification is minimal. Hope this will be added in the next release (I couldn't found out how to contribute directly so I wanted to share):

module ActiveRecord
    module ConnectionAdapters
    include_class "jdbc_adapter.JdbcConnectionFactory"

    class OracleEnhancedJDBCConnection < OracleEnhancedConnection

    ...

    # added logic to support JNDI connections
    def new_connection(config)
      if config[:jndi]
        jndi = "java:comp/env/#{config[:jndi].to_s}"
        ctx = javax.naming.InitialContext.new
        ds = ctx.lookup(jndi)
        @raw_connection = JdbcConnectionFactory.impl do
          ds.connection
        end
        config[:driver] ||= @raw_connection.meta_data.connection.java_class.name
      else        
        username, password, database = config[:username].to_s, config[:password].to_s, config[:database].to_s
        privilege = config[:privilege] && config[:privilege].to_s
        host, port = config[:host], config[:port]

        # connection using TNS alias
        if database && !host && !config[:url] && ENV['TNS_ADMIN']
          url = "jdbc:oracle:thin:@#{database || 'XE'}"
        else
          url = config[:url] || "jdbc:oracle:thin:@#{host || 'localhost'}:#{port || 1521}:#{database || 'XE'}"
        end

        prefetch_rows = config[:prefetch_rows] || 100
        cursor_sharing = config[:cursor_sharing] || 'force'
        # by default VARCHAR2 column size will be interpreted as max number of characters (and not bytes)
        nls_length_semantics = config[:nls_length_semantics] || 'CHAR'
        # get session time_zone from configuration or from TZ environment variable
        time_zone = config[:time_zone] || ENV['TZ'] || java.util.TimeZone.default.getID

        properties = java.util.Properties.new
        properties.put("user", username)
        properties.put("password", password)
        properties.put("defaultRowPrefetch", "#{prefetch_rows}") if prefetch_rows
        properties.put("internal_logon", privilege) if privilege

        @raw_connection = java.sql.DriverManager.getConnection(url, properties)
      end
    end
  end
end

issues using emulate_booleans and emulate_booleans_from_strings

I am having issues using the two emulate booleans options with an 11G database.

I found the boolean values seem to be set as NUMBER(1). So I have overridden simplified_type(field_type) to use this type. This was failing at times, and it seems the at times the field_type is actually coming in as NUMBER(1)(1) or even NUMBER(1)(1)(1). Other field types also have the size repeated several times.

Also, this seems to be different between my dev database and my production database.

I put in a temporary fix, but I would like to understand why this is happening.

My fix in simplified_type is:

   return :boolean if OracleEnhancedAdapter.emulate_booleans && ['NUMBER(1)', 'NUMBER(1)(1)', 'NUMBER(1)(1)(1)', 'NUMBER(1)(1)(1)(1)'].include?(field_type)

Any idea why this is happening?

valid table names treated as if invalid

I ran into an issue where valid_table_name? returns false for schema names with a $ in them, even though $ is valid in schema names. This ends up causing quote_table_name to quote these table names and the result can be an error like:

OCIError: ORA-00972: identifier is too long

For example "ops$username.an_otherwise_ok_name" is 33 characters and bombs even though the individual parts are below the 30 character limit.

I patched this issue with bahuvrihi/oracle-enhanced@625395760c831e3f460e073fffc09d2221dc3ace. The patch also adds support for other irregular but legal characters such as '@' in a database link. As an FYI I am no database expert and I was not able to run the full test suite, just the parts I modified. Please be sure to double-check my work. Thanks!

BLOB fields terribly slow

Mapping oracle's blob columns to the ruby equivalent is terribly slow right now. Fetching 135 records over a slow connection and creating the appropriate model objects takes about 5 seconds. I've added some benchmark stuff to OracleEnhancedJDBCConnection#select_no_retry. My select_no_retry run produces the following numbers:

VARCHAR2 0.03s 0.62%
TIMESTAMP 0.08s 1.47%
NUMBER 0.13s 2.35%
BLOB 5.25s 95.56%

I have only a single BLOB column (the picture), but no pictures have been set yet (no data).

I'm using java 1.6, Jruby 1.4.0, rails 2.3.5, oracle-enhanced 1.2.3, Oracle 10g express edition, and the ojdbc14.jar jdbc driver.

Please let me know if you need more details. Thanks for your great work on the enhanced adapter!

Getting weird issues with 20:Fixnum.empty? call

Hi,

I have the following database.yml config:

     development:
       adapter: oracle_enhanced
       database: xxx/yyy
       username: zzz
       password: aaa
       encoding: utf8
       cursor_sharing: similar

with the following model:

    class Status < ActiveRecord::Base
            set_table_name  "reporter_status"

    end

When trying to instantiate a Status object with:

    Status.first

I get the following:

    NoMethodError: undefined method `empty?' for 20:Fixnum
        from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:1628:in `instantiate'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:661:in `find_by_sql'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:661:in `collect!'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:661:in `find_by_sql'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:1548:in `find_every'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:1505:in `find_initial'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:613:in `find'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:623:in `first'
        from (irb):1

The schema for the table is as follows:

  create_table "reporter_status", :id => false, :force => true do |t|
    t.string   "identifier"
    t.integer  "serial",             :limit => 16, :precision => 16, :scale => 0
    t.string   "node",               :limit => 64
    t.string   "nodealias",          :limit => 64
    t.string   "manager",            :limit => 64
    t.string   "agent",              :limit => 64
    t.string   "alertgroup",         :limit => 64
    t.string   "alertkey",           :limit => 64
    t.string   "summary"
    t.string   "location",           :limit => 64
    t.integer  "class",              :limit => 16, :precision => 16, :scale => 0
    t.integer  "poll",               :limit => 16, :precision => 16, :scale => 0
    t.integer  "type",               :limit => 16, :precision => 16, :scale => 0
    t.integer  "tally",              :limit => 16, :precision => 16, :scale => 0
    t.boolean  "severity",                         :precision => 1,  :scale => 0
    t.integer  "owneruid",           :limit => 16, :precision => 16, :scale => 0
    t.integer  "ownergid",           :limit => 16, :precision => 16, :scale => 0
    t.integer  "acknowledged",       :limit => 16, :precision => 16, :scale => 0
    t.datetime "lastmodified"
    t.datetime "firstoccurrence"
    t.datetime "lastoccurrence"
    t.datetime "deletedat"
    t.boolean  "originalseverity",                 :precision => 1,  :scale => 0
    t.string   "ipaddress",          :limit => 64
    t.string   "customername",       :limit => 64
    t.integer  "devicecategory",     :limit => 8,  :precision => 8,  :scale => 0
    t.string   "position",           :limit => 64
    t.string   "tag",                :limit => 64
    t.string   "custlocation",       :limit => 64
    t.string   "ttno",               :limit => 64
    t.integer  "escalation",         :limit => 8,  :precision => 8,  :scale => 0
    t.datetime "clearedtime"
    t.datetime "acktime"
    t.string   "circuitdetails",     :limit => 50
    t.integer  "impactstate",        :limit => 4,  :precision => 4,  :scale => 0
    t.integer  "notificationid",     :limit => 16, :precision => 16, :scale => 0
    t.string   "accountid",          :limit => 64
    t.integer  "servicediff",        :limit => 4,  :precision => 4,  :scale => 0
    t.string   "relationship",       :limit => 64
    t.integer  "sourceserverserial", :limit => 16, :precision => 16, :scale => 0
    t.string   "servername",         :limit => 64,                                :null => false
    t.integer  "serverserial",       :limit => 16, :precision => 16, :scale => 0, :null => false
    t.decimal  "expiretime"
    t.string   "alerttype",          :limit => 64
  end

Any ideas?

Regards

JRuby issues when active_record.default_timezone is not 'utc'

OracleEnhancedOCIConnection has the following code:

# code from Time.time_with_datetime_fallback
begin
Time.send(Base.default_timezone, year, month, day, hour, min, sec, usec)
rescue
offset = Base.default_timezone.to_sym == :local ? ::DateTime.local_offset : 0
::DateTime.civil(year, month, day, hour, min, sec, offset)
end

OracleEnhancedJDBCConnection should have similar behaviour when active_record.default_timezone is not 'utc'

Suppress logging optionally for class reloading

Hi Raimonds!

Thank you so much for oracle_enhanced. It's a blessing for those of us using Oracle with Rails.

Is there a way to suppress the logging of ActiveRecord's columns and keys lookup in development? Because classes keep being reloaded, my logs are overwhelmed with primary key, primary key trigger, and columns lookups moreso than actual queries.

Thank you!

Best,
Milan

Column case wrong/changed in v1.3.0

I have a table with a column named 'number' which works fine in v1.2.4.

After upgrading to 1.3.0, Rails referres to the column as 'TABLENAME'.'NUMBER' (all uppercase), which fails with an ORA-00904 invalid identifier.

schema dump produces a lot of precision

When I run rake db:schema:dump, all my integers and booleans are given redundant precision:

t.integer  "patient_id",         :precision => 38, :scale => 0
t.integer  "user_id",            :precision => 38, :scale => 0
t.integer  "parent_id",          :precision => 38, :scale => 0
t.boolean  "is_deleted",     :precision => 1,  :scale => 0
t.boolean  "display_status", :precision => 1,  :scale => 0

Is there a way for oracle-enhanced to suppress:precision => 38, :scale => 0 for integers and :precision => 1, :scale => 0 for booleans?

Do people just live with all this precision? Or is there something about my installation that is misconfigured? Thanks!

Caching column information breaks migrations

Enable the column caching breaks migrations run in dev mode (production migrations are probably broken as well).

I've started to see 01451 errors after enabling column caching:

ORA-01451: column to be modified to NULL cannot be modified to NULL: ALTER TABLE versions MODIFY effective_date DATE DEFAULT NULL NULL

It appears like oracle expects the 'not null' or 'null' keyword not in a alter table statement when the column is already in this modus. Oracle enhanced adapter is smart enough to check what has to be changed (and what should not be mentioned by the migration) and only sends the necessarry commands). But when this information is cached it can happen that the enhanced adapter is out of sync and creates invalid alter table statements. nasty!

ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.cache_columns = true

TypeError: can't convert nil into String

Any call to an oracle backed model throws this error.

Step 2 from the Troubleshooting guide works fine: http://github.com/rsim/oracle-enhanced/wiki/Troubleshooting

Step 3 doesn't work. It dies with:

require 'activerecord'
Gem::LoadError: can't activate activerecord (= 2.3.9, runtime) for [], already activated activerecord-3.0.1 for []
from /usr/local/lib/site_ruby/1.8/rubygems.rb:233:in activate' from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:35:inrequire'
from (irb):4

Infoaccess::HrDirectoryAdmin
TypeError: can't convert nil into String
from /home/jpd800/.bundler/ruby/1.8/oracle-enhanced-1551b79913bc/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:245:in initialize' from /home/jpd800/.bundler/ruby/1.8/oracle-enhanced-1551b79913bc/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:245:innew'
from /home/jpd800/.bundler/ruby/1.8/oracle-enhanced-1551b79913bc/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:245:in new_connection' from /home/jpd800/.bundler/ruby/1.8/oracle-enhanced-1551b79913bc/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:350:ininitialize'
from /home/jpd800/.bundler/ruby/1.8/oracle-enhanced-1551b79913bc/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:24:in new' from /home/jpd800/.bundler/ruby/1.8/oracle-enhanced-1551b79913bc/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:24:ininitialize'
from /home/jpd800/.bundler/ruby/1.8/oracle-enhanced-1551b79913bc/lib/active_record/connection_adapters/oracle_enhanced_connection.rb:9:in new' from /home/jpd800/.bundler/ruby/1.8/oracle-enhanced-1551b79913bc/lib/active_record/connection_adapters/oracle_enhanced_connection.rb:9:increate'

Table/Column alias maximum length in schema_statements

I just came across an obscure little bug in AR - I ran something like this:

SomeModel.count(:group => 'foofoofoofoo, barbarbarbar, bazbazbazbaz')

which generates a (unnecessary) column alias longer than the 30 characters allowed by Oracle:

SELECT 1 AS foofoofoofoo_barbarbarbar_bazbazbazbaz FROM dual;
ORA-00972: identifier is too long

This seems to have been addressed to some extent between AR2.1.2 (where I'm stuck at present) and 2.3.4, which has

module ActiveRecord
module ConnectionAdapters # :nodoc:
module SchemaStatements
# Returns a Hash of mappings from the abstract data types to the native
# database types. See TableDefinition#column for details on the recognized
# abstract data types.
def native_database_types
{}
end

  # This is the maximum length a table alias can be
  def table_alias_length
    255
  end

  # Truncates a table alias according to the limits of the current adapter.
  def table_alias_for(table_name)
    table_name[0..table_alias_length-1].gsub(/\./, '_')
  end

For Oracle, we need table_alias_length to return 30.

Not that I can actually use it, of course (I had to hack calculations.rb, grrr) but it would be nice to see it in the adapter if I ever get to update...

Patch to tables_in_string method breaks queries with MySQL

In our application we use oracle and mysql databases side-by-side. After introducing this gem, we started getting mysql queries failing due to missing join tables. After investigation, we found that "tables_in_string" the method patch was causing this issue.

Ideally, we should just apply this patch if the query is made against "OracleEnhanced" adapter. The rest of the adapters should rely on the default activerecord implementation.

We fixed it by adding the following code after the line 'establish_connection' in the ActiveRecord::Base class for the oracle adapter in our application:

if ActiveRecord::VERSION::MAJOR == 2 && ActiveRecord::VERSION::MINOR == 3
  require "active_record/associations"

  ActiveRecord::Associations::ClassMethods.module_eval do

    private
    def tables_in_string(string)
      return [] if string.blank?

      if self.connection.adapter_name == "OracleEnhanced"
        # always convert table names to downcase as in Oracle quoted table names are in uppercase
        # ignore raw_sql_ that is used by Oracle adapter as alias for limit/offset subqueries
        string.scan(/([a-zA-Z_][\.\w]+).?\./).flatten.map(&:downcase).uniq - ['raw_sql_']
      else
        string.scan(/([\.a-zA-Z_]+).?\./).flatten
      end

    end
  end
end

The oracle enhanced adapter should at least include something similar so that it doesn't disable other database adapters by changing their functionality.

Rake fails in oracle_enhanced_tasks.rb

Using rails 3 beta 3, and the rails3_oracle_patches from the rails3_oracle_sample, then rake -T doesn't work.

rake aborted!
undefined method `[]' for nil:NilClass
/Users/copa/.rvm/gems/ree-1.8.7-2010.01/bundler/gems/oracle-enhanced-35f26176bf0c8e76ceaff468030e8aebad7d65bf-rails3/lib/active_record/connection_adapters/oracle_enhanced_tasks.rb:4

Basically ActiveRecord::Base.configurations is empty, it hasn't loaded database.yml yet.

idea about 'set_date(time)_columns'

instead of actually having to write column-name-symbols, it would be cool if we could determine patterns for symbol names....
here in germany we often use date-field-names with certain postfixes that make the field recognizable as date like '_seit' (since), '_bis' (until), 'am' (at)
so it would be lovely if we could just define, maybe an array to hold patterns for column recognition ... like [ /\w*
(am|seit|bis|at|on)/, /exceptionaldatename/ ]
just food for thought

quoted camelcase table names

I have a self-referencing many to many relation which causes rails to create an sql query with an alter table name when ordering by a column of the self referencing relation. The alter table name contains the name of the relation (pluralized) and the original table name. For example: users_FRIENDSHIPS.

This mixed case method doesn't pass the valid_table_name? method in OracleEnhancedAdapter, because it is treated as "CamelCase" and is therefore quoted in quote_table_name, causing the sql statement to be invalid.

This fixes my problem, but treats CamelCase names as valid:


def self.valid_table_name?(name)
   name = name.to_s
   name =~ /\A([A-Za-z_0-9]+\.)?[A-Za-z][A-Za-z_0-9\$#]*(@[A-Za-z_0-9\.]+)?\Z/ ? true : false
end

OS Authentication Gets Mungled

OCI8 allows me to use OS authentication if I pass nil:

OCI8.new(nil, nil, [database]) # works!

It does not work with empty strings:

OCI8.new('', '', [database]) # fails :(

oracle_enhanced mungles this a little. It occurs in OracleEnhancedOCIFactory::new_connection. The line (around line 257?):

username, password, database = config[:username].to_s, config[:password].to_s, config[:database].to_s

Converting the config[:username] with "to_s" turns my nil into an empty string. I removed the "to_s" and oracle_enhanced connects using OS authentication (because it honors the nil). And it still works when I pass in a hard-coded username and password.

Thanks for the great work!

ORA-19011 when reading large XMLType columns

When reading large XMLType columns, somehow oracle_enhanced-adapter reads it wrong and does not treat it like a CLOB. Oracle then raises: "ORA-19011: Character string buffer too small".

For now, I managed the situation this way:

# does not work, raises "ORA-19011: Character string buffer too small"
rec = MyTable.find_by_somekey(id)

# works
rec = MyTable.where(["somekey = ?", id]).select('(rawxml).getClobVal() as rawxml').first

Here's the backtrace:

.../vendor/bundle/ruby/1.8/gems/activerecord-3.0.5/lib/active_record/connection_adapters/abstract_adapter.rb:207:in `log'
.../vendor/bundle/ruby/1.8/gems/activerecord-oracle_enhanced-adapter-1.3.2/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:1077:in `log'
.../vendor/bundle/ruby/1.8/gems/activerecord-oracle_enhanced-adapter-1.3.2/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:1034:in `select'
.../vendor/bundle/ruby/1.8/gems/activerecord-3.0.5/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all'
.../vendor/bundle/ruby/1.8/gems/activerecord-3.0.5/lib/active_record/connection_adapters/abstract/query_cache.rb:56:in `select_all'
.../vendor/bundle/ruby/1.8/gems/activerecord-3.0.5/lib/active_record/base.rb:467:in `find_by_sql'
.../vendor/bundle/ruby/1.8/gems/activerecord-3.0.5/lib/active_record/relation.rb:64:in `to_a'
.../vendor/bundle/ruby/1.8/gems/activerecord-3.0.5/lib/active_record/relation/finder_methods.rb:333:in `find_first'
.../vendor/bundle/ruby/1.8/gems/activerecord-3.0.5/lib/active_record/relation/finder_methods.rb:122:in `first'
.../vendor/bundle/ruby/1.8/gems/activerecord-3.0.5/lib/active_record/relation/finder_methods.rb:234:in `send'
.../vendor/bundle/ruby/1.8/gems/activerecord-3.0.5/lib/active_record/relation/finder_methods.rb:234:in `find_by_attributes'
.../vendor/bundle/ruby/1.8/gems/activerecord-3.0.5/lib/active_record/base.rb:987:in `send'
.../vendor/bundle/ruby/1.8/gems/activerecord-3.0.5/lib/active_record/base.rb:987:in `method_missing'

rake:db:test:clone_structure does not create valid SQL for Oracle 10g R 2

Hi. I'm trying to copy a dev database to test in order to test properly.

Given the following environment:
Rails 2.3.8
ruby-oci8 2.0.4
oracle_enhanced 1.2.4
Ruby 1.8.6 p 399 in RVM
Oracle 10g test database running locally on OS X
Oracle 11g development database running remotely

When I try to copy the development database to a test database in order to run specs on it,
Then I'm getting the following errors in this gist (the second file): https://gist.github.com/1fca1f0b2fb1f0d0f3eb

The gist shows part of the development_structure.sql file that is created by db:structure:dump starting on line 16 of lib/active_record/connection_adapters/oracle_enhanced.rake. My Oracle 10g instance does not like the STATEMENT_TOKEN that the structure_dump method uses starting at line 1203 of ib/active_record/connection_adapters/oracle_enhanced_adapter.rb. I replaced the STATEMENT_TOKEN "\n\n-- @@@ --\n\n" with ";\n\n" on line 1456 to get that to work.

Once that worked, I ran into the issue created by the SQL in the part of the gist called "unique constraint problem". Running this through the driver as well as through sqlplus resulted in an ORA-00955 error, as shown in the gist.

Based on these issues, I have some questions:

  1. Has the "rake db:test:clone_structure" task worked for people? I tried running the activerecord_oracle_enhanced tests (the last file in the gist) but didn't see any output.
  2. If so, what environment did it work in?
  3. I noticed that there isn't a spec for the rake task. I've used code from this post http://blog.codahale.com/2007/12/20/rake-vs-rspec-fight/ to add specs for rake tasks. Are there any objections to me making a fork, adding those spec changes and submitting?

Thanks,
Mark Nyon

active? doesn't check if connection is stale / database unresponsive

According to abstract_adapter.rb (from ActiveRecord) active? should check if the database is actually capable of responding (usually by issuing a "select 1", like in the ping method).

We have a production problem over this issue because the Cisco router drops inactive connections, ActiveRecord::Base.verify_active_connections! should resolve this issue, but this only works if active? checks for database response capabilty, like with postgres and mysql adapters.

float maps to decimal maps to integer through schema dump & schema load iteration

When creating a schema dump the float type will degrade into a decimal, and decimal type will degrade into an integer.

Steps to reproduce:

  1. define a float column X, migrate it to database
  2. create a schema dump, the schema.rb will state "decimal" for type of column X
  3. load the acquired schema.rb file into the database, and dump again
  4. the new schema.rb will have type integer (number 38,0) for column X

Confirmed on Oracle 11 enterprise, Oracle 10 express, oracle-enhanced v1.3.2 and v.1.3.1 and activerecord 3.0.4 and 3.0.3

Connection errors. oci8.c:270:in oci8lib_191.so: ORA-12154: TNS:could not resolve the connect identifier

Note: We do not use tnsnames.ora. We use Oracle OID. Always worked with standard activerecord oracle adapter.

Worked perfectly before 1.9.2
ruby 1.9.2p0 (2010-08-18) [i386-mingw32]
gems 1.3.7
Oracle client: SQL*Plus: Release 11.2.0.1.0

Connection errors with these gems installed:

activemodel (3.0.1)
activerecord (3.0.1)
activerecord-oracle_enhanced-adapter (1.3.1)
activesupport (3.0.1)
arel (1.0.1)
builder (2.1.2)
i18n (0.4.1)
minitest (1.6.0)
rake (0.8.7)
rdoc (2.5.8)
ruby-oci8 (2.0.4 x86-mingw32)
tzinfo (0.3.23)

ActiveRecord::Base.establish_connection(
:adapter => 'oracle_enhanced',
:database => 'mydb',
:username => 'username',
:password => 'mypassword'
)

Error:

oci8.c:270:in oci8lib_191.so: ORA-12154: TNS:could not resolve the connect identifier specified (OCIError)
from D:/ruby/lib/ruby/gems/1.9.1/gems/activerecord-oracle_enhanced-adapter-1.3.1/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:244:in new' from D:/ruby/lib/ruby/gems/1.9.1/gems/activerecord-oracle_enhanced-adapter-1.3.1/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:244:innew_connection'
from D:/ruby/lib/ruby/gems/1.9.1/gems/activerecord-oracle_enhanced-adapter-1.3.1/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:349:in initialize' from D:/ruby/lib/ruby/gems/1.9.1/gems/activerecord-oracle_enhanced-adapter-1.3.1/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:24:innew'
from D:/ruby/lib/ruby/gems/1.9.1/gems/activerecord-oracle_enhanced-adapter-1.3.1/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:24:in initialize' from D:/ruby/lib/ruby/gems/1.9.1/gems/activerecord-oracle_enhanced-adapter-1.3.1/lib/active_record/connection_adapters/oracle_enhanced_connection.rb:9:innew'
from D:/ruby/lib/ruby/gems/1.9.1/gems/activerecord-oracle_enhanced-adapter-1.3.1/lib/active_record/connection_adapters/oracle_enhanced_connection.rb:9:in create' from D:/ruby/lib/ruby/gems/1.9.1/gems/activerecord-oracle_enhanced-adapter-1.3.1/lib/active_record/connection_adapters/oracle_enhanced_base_ext.rb:13:inoracle_enhanced_connection'
from D:/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:230:in new_connection' from D:/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:238:incheckout_new_connection'
from D:/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:194:in block (2 levels) in checkout' from D:/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:190:inloop'
from D:/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:190:in block in checkout' from D:/ruby/lib/ruby/1.9.1/monitor.rb:201:inmon_synchronize'
from D:/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:189:in checkout' from D:/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:96:inconnection'
from D:/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:318:in retrieve_connection' from D:/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:97:inretrieve_connection'
from D:/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:89:in connection' from D:/ruby/lib/ruby/gems/1.9.1/gems/arel-1.0.1/lib/arel/engines/sql/engine.rb:9:inconnection'
from D:/ruby/lib/ruby/gems/1.9.1/gems/arel-1.0.1/lib/arel/engines/sql/relations/table.rb:37:in initialize' from D:/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/base.rb:850:innew'
from D:/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/base.rb:850:in arel_table' from D:/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/base.rb:896:inrelation'
from D:/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.1/lib/active_record/named_scope.rb:32:in `scoped'

"database" connection key interpretation change breaks connections to TNS-named databases

In our oracle client setup, we use TNS aliases set up in the default location, $ORACLE_HOME/network/admin/tnsnames.ora. In oracle_enhanced 1.2.3, we could use database: somedb to refer to the database aliased as "somedb" in tnsnames.ora. In 1.3.0, that no longer works β€” we get ORA-12154, could not resolve the connect identifier errors.

The relevant change seems to be a6b5c0d. The root of the problem is apparently that oracle_enhanced now assumes that an unqualified database name is relative to a host and port and then assumes that the host:port is localhost:1521 if not specified.

By inspection of the code, we discovered that if you set the TNS_ADMIN environment variable, oracle_enhanced won't monkey with the specified database name. Since we're using the default TNS_ADMIN location, though, we'd rather not set the environment variable (it's redundant). I don't have particularly broad experience with oracle deployments, but my impression is that using tnsnames is more common than not. It seems like it would be nicer if oracle_enhanced would just leave the database value alone if you don't specify a host or port.

Is this a change you'd be willing to accept? I could provide a patch if so.

Sequence Case Sensitivity Issues

I am running into an issue with sequences and this gem.

The gem creates the sequence as "TABLENAME_SEQ" appropriately quoted, however when trying to retrieve it, it uses "TABLENAME_seq". This causes the sequence to not be found (at least this is the case in our Oracle installation). This appears to be due to the options being passed to "default_sequence_name" differing from migration time to run time. At migration time, the "table name" param is all lower case, however at run time the table name is all upper case (due to the result of "describe" giving the table name as stored...uppercase). Since "quote_table_name" will not upcase anything that already starts with an uppercase letter, the mixed case remains all the way through to the query.

I don't have a fix to recommend for this. I used a naive fix that works for our specific case by downcasing anything sent to default_sequence_name, however I am unsure of what other issues this may cause in a broader user base.

Error in oracle_enhanced_adapter.rb line 131

I got a error when i try to launch rails console.

ERROR:
D:\data\My Dropbox\HQ\projets\hqp>rails console
C:/Ruby187/lib/ruby/gems/1.8/gems/oracle_enhanced-1.2.5/lib/active_record/connec
tion_adapters/oracle_enhanced_adapter.rb:131:in alias_method': undefined method add_order!' for class `Class' (NameError)

If I comment out line 131 and 132 in oracle_enhanced_adapter.rb it's work.

D:\data\My Dropbox\HQ\projets\hqp>bundle list
Gems included by the bundle:

  • abstract (1.0.0)
  • actionmailer (3.0.3)
  • actionpack (3.0.3)
  • activemodel (3.0.3)
  • activerecord (3.0.3)
  • activerecord-oracle_enhanced-adapter (1.3.2)
  • activeresource (3.0.3)
  • activesupport (3.0.3)
  • arel (2.0.7)
  • builder (2.1.2)
  • bundler (1.0.9)
  • erubis (2.6.6)
  • i18n (0.5.0)
  • mail (2.2.14)
  • mime-types (1.16)
  • oracle_enhanced (1.2.5)
  • polyglot (0.3.1)
  • rack (1.2.1)
  • rack-mount (0.6.13)
  • rack-test (0.5.7)
  • rails (3.0.3)
  • railties (3.0.3)
  • rake (0.8.7)
  • ruby-oci8 (2.0.4)
  • sinatra (1.1.2)
  • thor (0.14.6)
  • tilt (1.2.2)
  • treetop (1.4.9)
  • tzinfo (0.3.24)

D:\data\My Dropbox\HQ\projets\hqp>ruby --version
ruby 1.8.7 (2010-12-23 patchlevel 330) [i386-mingw32]

D:\data\My Dropbox\HQ\projets\hqp>gem env
RubyGems Environment:

  • RUBYGEMS VERSION: 1.4.2
  • RUBY VERSION: 1.8.7 (2010-12-23 patchlevel 330) [i386-mingw32]
  • INSTALLATION DIRECTORY: C:/Ruby187/lib/ruby/gems/1.8
  • RUBY EXECUTABLE: C:/Ruby187/bin/ruby.exe
  • EXECUTABLE DIRECTORY: C:/Ruby187/bin
  • RUBYGEMS PLATFORMS:
    • ruby
    • x86-mingw32
  • GEM PATHS:
    • C:/Ruby187/lib/ruby/gems/1.8
    • D:/Documents and Settings/cx4316/.gem/ruby/1.8
  • GEM CONFIGURATION:
    • :update_sources => true
    • :verbose => true
    • :benchmark => false
    • :backtrace => false
    • :bulk_threshold => 1000
  • REMOTE SOURCES:

Running on windows xp.

Thanks!

structure_drop creating, but not executing, sql to drop schema

I was having issues where rake db:drop wouldn't actually drop either table or sequence, so I dug into the code to find where oracle-enhanced was dropping these items.

I found structure_drop, which seems to fit my needs exactly. However, when I run:
ActiveRecord::Base.connection.structure_drop

I'm getting back the SQL to drop all the tables, returned as a long string, but it's not actually executed. When I run that SQL through sqlplus, it does seem to be valid, and the tables/sequences are dropped.

I feel like I must be missing something very simple, but I'm executing that ruby statement under the same user/pass as the sqlplus, and getting different results.

I've tried this with both 1.8.7p299 and 1.9.1p378 using ActiveRecord 3.0.0beta4 and activerecord-oracle_enhanced-adapter version 1.3.0

Thoughts?

ActiveRecord::Base #last throws error

I have a simple model, and when calling last on the class I get:

ActiveRecord::StatementInvalid: OCIError: ORA-00904: "APP"."VENDOR"."ID": invalid identifier: select * from (select raw_sql_.*, rownum raw_rnum_ from (SELECT * FROM APP.VENDOR ORDER BY APP.VENDOR.id DESC) raw_sql_ where rownum <= 1) where raw_rnum_ > 0

The #first method works fine.

I can't run the tests when schema_format = :sql

When I configured active_record.schema_format = :sql and I performed my tests the adapter didn't complete the dumping because it didn't can execute "--@@@--" (a constant that is used to separate the statements in development_structure.sql).

For while I fixed it replacing this constant to "\n\n" in a config/initializer file:
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter::STATEMENT_TOKEN = "\n\n"

Somebody already did have this problem?

"undefined method `[]' for nil:NilClass" when running "rake middleware" task

  M Y    C O N F I G U R A T I O N

RUBY: ruby-1.8.7-p249 (on rvm)
RAILS: Rails 3.0.0.beta4
GEMS:
*** LOCAL GEMS ***
abstract (1.0.0)
actionmailer (3.0.0.beta4, 3.0.0.beta)
actionpack (3.0.0.beta4, 3.0.0.beta)
activemodel (3.0.0.beta4, 3.0.0.beta)
activerecord (3.0.0.beta4, 3.0.0.beta)
activerecord-oracle_enhanced-adapter (1.2.4)
activeresource (3.0.0.beta4, 3.0.0.beta)
activesupport (3.0.0.beta4, 3.0.0.beta)
arel (0.4.0, 0.2.1)
builder (2.1.2)
bundler (1.0.0.beta.1, 0.9.26)
cgi_multipart_eof_fix (2.5.0)
daemons (1.1.0, 1.0.10)
erubis (2.6.6, 2.6.5)
fastthread (1.0.7)
gem_plugin (0.2.3)
i18n (0.4.1, 0.3.7)
jrails (0.6.0)
mail (2.2.5, 2.2.3, 2.1.5.3)
memcache-client (1.8.3, 1.7.8)
mime-types (1.16)
mongrel (1.2.0.pre2, 1.1.5)
pdfkit (0.3.3)
polyglot (0.3.1)
rack (1.1.0)
rack-mount (0.6.4, 0.6.3, 0.4.7)
rack-test (0.5.4)
rails (3.0.0.beta4, 3.0.0.beta)
railties (3.0.0.beta4, 3.0.0.beta)
rake (0.8.7)
rdoc (2.5.8)
rspec (1.3.0)
ruby-graphviz (0.9.12)
ruby-oci8 (2.0.4)
ruby-plsql (0.4.3)
sqlite3-ruby (1.3.0)
text-format (1.0.0)
text-hyphen (1.0.0)
thor (0.13.7, 0.13.6)
treetop (1.4.8)
tzinfo (0.3.22)

GEMS included by the bundle:

abstract (1.0.0)
actionmailer (3.0.0.beta4)
actionpack (3.0.0.beta4)
activemodel (3.0.0.beta4)
activerecord (3.0.0.beta4)
activerecord-oracle_enhanced-adapter (1.3.0 6f204a4)
activeresource (3.0.0.beta4)
activesupport (3.0.0.beta4)
arel (0.4.0)
authlogic (2.1.3 a087ad0)
builder (2.1.2)
bundler (1.0.0.beta.1)
erubis (2.6.5)
i18n (0.4.1)
jrails (0.6.0)
mail (2.2.5)
mime-types (1.16)
pdfkit (0.3.3)
polyglot (0.3.1)
rack (1.1.0)
rack-mount (0.6.4)
rack-test (0.5.4)
rails (3.0.0.beta4 0421fb7)
railties (3.0.0.beta4)
rake (0.8.7)
rspec (1.3.0)
ruby-oci8 (2.0.4)
ruby-plsql (0.4.3)
thor (0.13.6)
treetop (1.4.8)
tzinfo (0.3.22)

When I try to run 'rake middleware' I got an error "undefined method `[]' for nil:NilClass".
Using the same command with the option '--trace', as suggested by the output, I see that it seems a problem of oracle_enhanced_tasks.rb, here is the full output of the command 'rake middleware --trace':

rake aborted!
undefined method `[]' for nil:NilClass
/home/asalicetti/.rvm/gems/ruby-1.8.7-p249/bundler/gems/oracle-enhanced-6f204a4/lib/active_record/connection_adapters/oracle_enhanced_tasks.rb:3
/home/asalicetti/.rvm/gems/ruby-1.8.7-p249/bundler/gems/rails-0421fb7/activesupport/lib/active_support/dependencies.rb:212:in `require'
/home/asalicetti/.rvm/gems/ruby-1.8.7-p249/bundler/gems/rails-0421fb7/activesupport/lib/active_support/dependencies.rb:212:in `require'
/home/asalicetti/.rvm/gems/ruby-1.8.7-p249/bundler/gems/rails-0421fb7/activesupport/lib/active_support/dependencies.rb:198:in `load_dependency'
/home/asalicetti/.rvm/gems/ruby-1.8.7-p249/bundler/gems/rails-0421fb7/activesupport/lib/active_support/dependencies.rb:554:in `new_constants_in'
/home/asalicetti/.rvm/gems/ruby-1.8.7-p249/bundler/gems/rails-0421fb7/activesupport/lib/active_support/dependencies.rb:198:in `load_dependency'
/home/asalicetti/.rvm/gems/ruby-1.8.7-p249/bundler/gems/rails-0421fb7/activesupport/lib/active_support/dependencies.rb:212:in `require'
/home/asalicetti/.rvm/gems/ruby-1.8.7-p249/bundler/gems/oracle-enhanced-6f204a4/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:1777
/home/asalicetti/.rvm/gems/ruby-1.8.7-p249/gems/bundler-1.0.0.beta.1/lib/bundler/runtime.rb:48:in `require'
/home/asalicetti/.rvm/gems/ruby-1.8.7-p249/gems/bundler-1.0.0.beta.1/lib/bundler/runtime.rb:48:in `require'
/home/asalicetti/.rvm/gems/ruby-1.8.7-p249/gems/bundler-1.0.0.beta.1/lib/bundler/runtime.rb:47:in `each'
/home/asalicetti/.rvm/gems/ruby-1.8.7-p249/gems/bundler-1.0.0.beta.1/lib/bundler/runtime.rb:47:in `require'
/home/asalicetti/.rvm/gems/ruby-1.8.7-p249/gems/bundler-1.0.0.beta.1/lib/bundler/runtime.rb:38:in `each'
/home/asalicetti/.rvm/gems/ruby-1.8.7-p249/gems/bundler-1.0.0.beta.1/lib/bundler/runtime.rb:38:in `require'
/home/asalicetti/.rvm/gems/ruby-1.8.7-p249/gems/bundler-1.0.0.beta.1/lib/bundler.rb:112:in `require'
/home/asalicetti/Ruby/Rails/GS3/config/application.rb:7
/home/asalicetti/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/home/asalicetti/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
/home/asalicetti/Ruby/Rails/GS3/Rakefile:4
/home/asalicetti/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake.rb:2383:in `load'
/home/asalicetti/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake.rb:2383:in `raw_load_rakefile'
/home/asalicetti/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake.rb:2017:in `load_rakefile'
/home/asalicetti/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/home/asalicetti/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake.rb:2016:in `load_rakefile'
/home/asalicetti/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake.rb:2000:in `run'
/home/asalicetti/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/home/asalicetti/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/home/asalicetti/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/bin/rake:31
/home/asalicetti/.rvm/rubies/ruby-1.8.7-p249/bin/rake:24:in `load'
/home/asalicetti/.rvm/rubies/ruby-1.8.7-p249/bin/rake:24

I've done a little debug and it turns out that 'Rails.env', at runtime, is equal to 'development', but Rails.env['adapter'] is undefined.

Looking on Google I found this:
http://groups.google.com/group/oracle-enhanced/browse_thread/thread/7e246a9b85c4b2ed/a48a06f8946bd400

Basically the solution suggested here is to remove the bit of code:
, :require => 'active_record/connection_adapters/oracle_enhanced_adapter'
from the line of the activerecord-oracle_enhanced-adapter gem's requirement.

It works!

My question is: does it have any drawback such kind of fix?
I don't remember even why I put it on there...

Thank you!

can't start in production mode in mac osx

rails 2.3.5
oracle_enhanced: 1.3.1

/Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/rails-2.3.5/lib/rails/gem_dependency.rb:119:Warning: Gem::Dependency#version_requirements is deprecated and will be removed on or after August 2010. Use #requirement
oci8.c:270:in oci8lib.bundle: ORA-12514: TNS:listener does not currently know of service requested in connect descriptor (OCIError)
from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-oracle_enhanced-adapter-1.3.1/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:244:in new' from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-oracle_enhanced-adapter-1.3.1/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:244:innew_connection'
from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-oracle_enhanced-adapter-1.3.1/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:349:in initialize' from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-oracle_enhanced-adapter-1.3.1/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:24:innew'
from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-oracle_enhanced-adapter-1.3.1/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:24:in initialize' from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-oracle_enhanced-adapter-1.3.1/lib/active_record/connection_adapters/oracle_enhanced_connection.rb:9:innew'
from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-oracle_enhanced-adapter-1.3.1/lib/active_record/connection_adapters/oracle_enhanced_connection.rb:9:in create' from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-oracle_enhanced-adapter-1.3.1/lib/active_record/connection_adapters/oracle_enhanced_base_ext.rb:13:inoracle_enhanced_connection'
from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:223:in send' from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:223:innew_connection'
from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:245:in checkout_new_connection' from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:188:incheckout'
from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:184:in loop' from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:184:incheckout'
from /Users/qichunren/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/1.8/monitor.rb:242:in synchronize' from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:183:incheckout'
from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:98:in connection' from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:326:inretrieve_connection'
from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:123:in retrieve_connection' from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:115:inconnection'
from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/activerecord-2.3.5/lib/active_record/base.rb:3113:in quoted_table_name' from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/acts_as_audited-1.1.1/lib/acts_as_audited.rb:82:inacts_as_audited'
from /Users/qichunren/code/demo_Business/app/models/admin.rb:24
from /Users/qichunren/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in gem_original_require' from /Users/qichunren/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:inrequire'
from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:158:in require' from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:265:inrequire_or_load'
from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:224:in depend_on' from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:136:inrequire_dependency'
from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/rails-2.3.5/lib/initializer.rb:414:in load_application_classes' from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/rails-2.3.5/lib/initializer.rb:413:ineach'
from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/rails-2.3.5/lib/initializer.rb:413:in load_application_classes' from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/rails-2.3.5/lib/initializer.rb:411:ineach'
from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/rails-2.3.5/lib/initializer.rb:411:in load_application_classes' from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/rails-2.3.5/lib/initializer.rb:197:inprocess'
from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/rails-2.3.5/lib/initializer.rb:113:in send' from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/rails-2.3.5/lib/initializer.rb:113:inrun'
from /Users/qichunren/code/demo_Business/config/environment.rb:14
from /Users/qichunren/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in gem_original_require' from /Users/qichunren/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:inrequire'
from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in require' from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:521:innew_constants_in'
from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in require' from /Users/qichunren/.rvm/gems/ruby-1.8.7-p302/gems/rails-2.3.5/lib/commands/server.rb:84 from /Users/qichunren/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:ingem_original_require'
from /Users/qichunren/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from script/server:3
usermatoMacBook-Pro:demo_Business qichunren$

and in RAILS_ROOT/sqlnet.log:


Fatal NI connect error 12514, connecting to:
(DESCRIPTION=(CONNECT_DATA=(SERVICE_NAME=zhaodb)(CID=(PROGRAM=ruby)(HOST=usermatoMacBook-Pro.local)(USER=qichunren)))(ADDRESS=(PROTOCOL=TCP)(HOST=114.80.138.164)(PORT=1521)))

VERSION INFORMATION:
TNS for MacOS X Server: Version 10.2.0.4.0 - Production
TCP/IP NT Protocol Adapter for MacOS X Server: Version 10.2.0.4.0 - Production
Time: 01-NOV-2010 11:10:40
Tracing not turned on.
Tns error struct:
ns main err code: 12564
TNS-12564: Message 12564 not found; No message file for product=network, facility=TNS
ns secondary err code: 0
nt main err code: 0
nt secondary err code: 0
nt OS err code: 0

Rake test tasks cannot drop test database with 10g express

When running any rake db:test command that will first drop the test database (clone, purge, load...) on an Oracle 10g Express Edition database, the connector returns an ORA-00904: Invalid identifier exception on the following query:

select type_name from user_types

On 10g, the "type_name" column has been renamed to "name".

I'm using:
activerecord-oracle_enhanced-adapter 1.3.2
ruby-oci8 2.0.4
activerecord 3.0.3

DESC teble_name failed; does it exist?

Hi,
I found weird behavior inside oracle_enhanced_connection.rb (version 1.3.0) file, from where i always get error mentioned in title. I looked into source code of this file at line 68, which states "if result = select_one(sql)"
before this statement I created code "puts sql" which returns SELECT statement which is about to be executed, when I run this statement inside sql developer, under same connection(user,password) as set in database.yml, I get result one line, but inside oracle_enhanced_connection.rb will return nil and cause exception from line 76.

RAW Type Would be Nice

We love the adapter but would like to use RAW to store some encoded binary information.

I have a patch I would like to submit that seems to dump/restore the raw type correctly.

Associations BLOBs issue

Hi,

I'm an absolute newbie to rails but I encountered a problem using the following structure:

create_table :experiments do |t|
  t.string :name
end
create_table :experiment_attachments do |t|
  t.references :experiment
  t.references :attachment
end
create_table :attachments do |t|
  t.binary :content
  t.string :description
end

class Attachment < ActiveRecord::Base
  has_many :experiment_attachments
  has_many :experiments, :through => :experiment_attachments
end
class Experiment < ActiveRecord::Base
  has_many :experiment_attachments
  has_many :attachments, :through => :experiment_attachments, :uniq => true
end
class ExperimentAttachment < ActiveRecord::Base
  belongs_to :experiment
  belongs_to :attachment
end

In the app I set up an experiment and a related attachment instance:

e=Experiment.create(:name => "test")
a=e.attachments.create(:description => "mmm", :content => "ddfgdg")

The following query leads to an ORA-00932 error:

e.attachments

If I remove the BLOB column (:content) in the attachment model it works as expected. This error does not occur with the mysql2 adapter. Btw, my configuration: Rails 3.0.3, Ruby 1.9.2p136, oracle-enhanced 1.3.2, ruby-oci8 2.0.4

What do I do wrong here?

Udo

active? doesn't check if connection is stale / database unresponsive

According to abstract_adapter.rb (from ActiveRecord) active? should check if the database is actually capable of responding (usually by issuing a "select 1", like in the ping method).

We have a production problem over this issue because the Cisco router drops inactive connections, ActiveRecord::Base.verify_active_connections! should resolve this issue, but this only works if active? checks for database response capabilty, like with postgres and mysql adapters.

PS I'm using OCI driver, accidentally closed the former issue :oops:
PS

Rails.logger nil on ruby 1.9.2-head (actually 1.9.3)

Rails 3 beta 4
Ruby 1.9.2-head

On oracle_enhanced_core_ext.rb, line 57 I had to add a check to avoid a NullPointerException:
From:
if defined?(Rails.logger)
Rails.logger.warn warning_message
To:
if defined?(Rails.logger)
Rails.logger.warn warning_message if Rails.logger

Inconsistencies in eager loading with select

ActiveRecord has an issue determining when to revert to the left-outer-join strategy for eager loading, and as a result the behavior of select + include can be inconsistent.

I saw your patches to rails 3 for that problem. They're a big improvement but they will not handle all valid identifiers much as in http://github.com/rsim/oracle-enhanced/issues/13. I opened a ticket for rails regarding this issue. I propose they move the tables_in_string method to the adapter so you can make it more robust on oracle. Thought you might like to know!

Reserved column names oracle rails 2.3.5

Hi, I have a problem with number column name in a legacy database which is oracle. The problem is that activerecord tries to execute SQL statement that gives an error :
ORA-00936: missing expression: select * from (SELECT * FROM "BINS" WHERE ("BINS".issuer_id = 5 AND (number like '%936214')) ) where rownum <= 1
Problem is with number like part of the statement, for oracle it should be quoted and in upper case, so how that could be done? Thanks in advance!
Best Regards,
Josip Povreslo

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.