Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: ctreatma/oracle-enhanced
...
head fork: barendt/oracle-enhanced
compare: master
Checking mergeability… Don't worry, you can still create the pull request.
  • 7 commits
  • 8 files changed
  • 0 commit comments
  • 1 contributor
View
8 Rakefile
@@ -12,15 +12,15 @@ require 'rake'
require 'jeweler'
Jeweler::Tasks.new do |gem|
- gem.name = "activerecord-oracle_enhanced-adapter"
+ gem.name = "ctreatma-activerecord-oracle_enhanced-adapter"
gem.summary = "Oracle enhanced adapter for ActiveRecord"
gem.description = <<-EOS
Oracle "enhanced" ActiveRecord adapter contains useful additional methods for working with new and legacy Oracle databases.
This adapter is superset of original ActiveRecord Oracle adapter.
EOS
- gem.email = "raimonds.simanovskis@gmail.com"
- gem.homepage = "http://github.com/rsim/oracle-enhanced"
- gem.authors = ["Raimonds Simanovskis"]
+ gem.email = "charles.treatman@gmail.com"
+ gem.homepage = "http://github.com/ctreatma/oracle-enhanced"
+ gem.authors = ["Charles Treatman", "Raimonds Simanovskis"]
gem.extra_rdoc_files = ['README.md']
end
Jeweler::RubygemsDotOrgTasks.new
View
129 ctreatma-activerecord-oracle_enhanced-adapter.gemspec
@@ -0,0 +1,129 @@
+# Generated by jeweler
+# DO NOT EDIT THIS FILE DIRECTLY
+# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = "ctreatma-activerecord-oracle_enhanced-adapter"
+ s.version = "1.4.1"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Charles Treatman", "Raimonds Simanovskis"]
+ s.date = "2012-03-28"
+ s.description = "Oracle \"enhanced\" ActiveRecord adapter contains useful additional methods for working with new and legacy Oracle databases.\nThis adapter is superset of original ActiveRecord Oracle adapter.\n"
+ s.email = "charles.treatman@gmail.com"
+ s.extra_rdoc_files = [
+ "README.md"
+ ]
+ s.files = [
+ ".rspec",
+ "Gemfile",
+ "History.md",
+ "License.txt",
+ "README.md",
+ "RUNNING_TESTS.md",
+ "Rakefile",
+ "VERSION",
+ "activerecord-oracle_enhanced-adapter.gemspec",
+ "ctreatma-activerecord-oracle_enhanced-adapter.gemspec",
+ "lib/active_record/connection_adapters/emulation/oracle_adapter.rb",
+ "lib/active_record/connection_adapters/oracle_enhanced.rake",
+ "lib/active_record/connection_adapters/oracle_enhanced_activerecord_patches.rb",
+ "lib/active_record/connection_adapters/oracle_enhanced_adapter.rb",
+ "lib/active_record/connection_adapters/oracle_enhanced_base_ext.rb",
+ "lib/active_record/connection_adapters/oracle_enhanced_column.rb",
+ "lib/active_record/connection_adapters/oracle_enhanced_connection.rb",
+ "lib/active_record/connection_adapters/oracle_enhanced_context_index.rb",
+ "lib/active_record/connection_adapters/oracle_enhanced_core_ext.rb",
+ "lib/active_record/connection_adapters/oracle_enhanced_cpk.rb",
+ "lib/active_record/connection_adapters/oracle_enhanced_dirty.rb",
+ "lib/active_record/connection_adapters/oracle_enhanced_jdbc_connection.rb",
+ "lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb",
+ "lib/active_record/connection_adapters/oracle_enhanced_procedures.rb",
+ "lib/active_record/connection_adapters/oracle_enhanced_schema_definitions.rb",
+ "lib/active_record/connection_adapters/oracle_enhanced_schema_dumper.rb",
+ "lib/active_record/connection_adapters/oracle_enhanced_schema_statements.rb",
+ "lib/active_record/connection_adapters/oracle_enhanced_schema_statements_ext.rb",
+ "lib/active_record/connection_adapters/oracle_enhanced_structure_dump.rb",
+ "lib/active_record/connection_adapters/oracle_enhanced_tasks.rb",
+ "lib/active_record/connection_adapters/oracle_enhanced_version.rb",
+ "lib/activerecord-oracle_enhanced-adapter.rb",
+ "spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb",
+ "spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb",
+ "spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb",
+ "spec/active_record/connection_adapters/oracle_enhanced_core_ext_spec.rb",
+ "spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb",
+ "spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb",
+ "spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb",
+ "spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb",
+ "spec/active_record/connection_adapters/oracle_enhanced_emulate_oracle_adapter_spec.rb",
+ "spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb",
+ "spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb",
+ "spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb",
+ "spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb",
+ "spec/spec_helper.rb"
+ ]
+ s.homepage = "http://github.com/ctreatma/oracle-enhanced"
+ s.require_paths = ["lib"]
+ s.rubygems_version = "1.8.21"
+ s.summary = "Oracle enhanced adapter for ActiveRecord"
+ s.test_files = [
+ "spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb",
+ "spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb",
+ "spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb",
+ "spec/active_record/connection_adapters/oracle_enhanced_core_ext_spec.rb",
+ "spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb",
+ "spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb",
+ "spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb",
+ "spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb",
+ "spec/active_record/connection_adapters/oracle_enhanced_emulate_oracle_adapter_spec.rb",
+ "spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb",
+ "spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb",
+ "spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb",
+ "spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb",
+ "spec/spec_helper.rb"
+ ]
+
+ if s.respond_to? :specification_version then
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
+ s.add_development_dependency(%q<rspec>, ["~> 2.4"])
+ s.add_development_dependency(%q<activerecord>, [">= 0"])
+ s.add_development_dependency(%q<activemodel>, [">= 0"])
+ s.add_development_dependency(%q<activesupport>, [">= 0"])
+ s.add_development_dependency(%q<actionpack>, [">= 0"])
+ s.add_development_dependency(%q<railties>, [">= 0"])
+ s.add_development_dependency(%q<arel>, [">= 0"])
+ s.add_development_dependency(%q<journey>, [">= 0"])
+ s.add_development_dependency(%q<ruby-plsql>, [">= 0.4.4"])
+ s.add_development_dependency(%q<ruby-oci8>, [">= 2.0.4"])
+ else
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
+ s.add_dependency(%q<rspec>, ["~> 2.4"])
+ s.add_dependency(%q<activerecord>, [">= 0"])
+ s.add_dependency(%q<activemodel>, [">= 0"])
+ s.add_dependency(%q<activesupport>, [">= 0"])
+ s.add_dependency(%q<actionpack>, [">= 0"])
+ s.add_dependency(%q<railties>, [">= 0"])
+ s.add_dependency(%q<arel>, [">= 0"])
+ s.add_dependency(%q<journey>, [">= 0"])
+ s.add_dependency(%q<ruby-plsql>, [">= 0.4.4"])
+ s.add_dependency(%q<ruby-oci8>, [">= 2.0.4"])
+ end
+ else
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
+ s.add_dependency(%q<rspec>, ["~> 2.4"])
+ s.add_dependency(%q<activerecord>, [">= 0"])
+ s.add_dependency(%q<activemodel>, [">= 0"])
+ s.add_dependency(%q<activesupport>, [">= 0"])
+ s.add_dependency(%q<actionpack>, [">= 0"])
+ s.add_dependency(%q<railties>, [">= 0"])
+ s.add_dependency(%q<arel>, [">= 0"])
+ s.add_dependency(%q<journey>, [">= 0"])
+ s.add_dependency(%q<ruby-plsql>, [">= 0.4.4"])
+ s.add_dependency(%q<ruby-oci8>, [">= 2.0.4"])
+ end
+end
+
View
11 lib/active_record/connection_adapters/oracle_enhanced_adapter.rb
@@ -899,14 +899,19 @@ def current_user
select_value("SELECT SYS_CONTEXT('userenv', 'session_user') FROM dual")
end
+ # Current database session schema
+ def current_schema
+ select_value("SELECT SYS_CONTEXT('userenv', 'current_schema') FROM dual")
+ end
+
# Default tablespace name of current user
def default_tablespace
- select_value("SELECT LOWER(default_tablespace) FROM user_users WHERE username = SYS_CONTEXT('userenv', 'session_user')")
+ select_value("SELECT LOWER(default_tablespace) FROM user_users WHERE username = SYS_CONTEXT('userenv', 'current_schema')")
end
def tables(name = nil) #:nodoc:
select_values(
- "SELECT DECODE(table_name, UPPER(table_name), LOWER(table_name), table_name) FROM all_tables WHERE owner = SYS_CONTEXT('userenv', 'session_user') AND secondary = 'N'",
+ "SELECT DECODE(table_name, UPPER(table_name), LOWER(table_name), table_name) FROM all_tables WHERE owner = SYS_CONTEXT('userenv', 'current_schema') AND secondary = 'N'",
name)
end
@@ -919,7 +924,7 @@ def table_exists?(table_name)
end
def materialized_views #:nodoc:
- select_values("SELECT LOWER(mview_name) FROM all_mviews WHERE owner = SYS_CONTEXT('userenv', 'session_user')")
+ select_values("SELECT LOWER(mview_name) FROM all_mviews WHERE owner = SYS_CONTEXT('userenv', 'current_schema')")
end
cattr_accessor :all_schema_indexes #:nodoc:
View
2  lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb
@@ -303,6 +303,7 @@ def self.new_connection(config)
cursor_sharing = config[:cursor_sharing] || 'force'
# get session time_zone from configuration or from TZ environment variable
time_zone = config[:time_zone] || ENV['TZ']
+ schema = config[:schema]
# connection using host, port and database name
connection_string = if host || port
@@ -322,6 +323,7 @@ def self.new_connection(config)
conn.prefetch_rows = prefetch_rows
conn.exec "alter session set cursor_sharing = #{cursor_sharing}" rescue nil
conn.exec "alter session set time_zone = '#{time_zone}'" unless time_zone.blank?
+ conn.exec "alter session set current_schema = #{schema}" unless schema.blank?
# Initialize NLS parameters
OracleEnhancedAdapter::DEFAULT_NLS_PARAMETERS.each do |key, default_value|
View
10 lib/active_record/connection_adapters/oracle_enhanced_schema_definitions.rb
@@ -20,10 +20,14 @@ def self.included(base) #:nodoc:
def to_sql_with_virtual_columns
if type==:virtual
- "#{base.quote_column_name(name)} AS (#{default})"
+ column_sql = "#{base.quote_column_name(name)} AS (#{default})"
else
- to_sql_without_virtual_columns
+ column_sql = to_sql_without_virtual_columns
+ if type==:primary_key
+ column_sql << base.table_definition_tablespace
+ end
end
+ column_sql
end
def lob?
@@ -51,7 +55,7 @@ def self.included(base)
module OracleEnhancedTableDefinition
class ForeignKey < Struct.new(:base, :to_table, :options) #:nodoc:
def to_sql
- base.foreign_key_definition(to_table, options)
+ base.foreign_key_definition(to_table, options) << base.table_definition_tablespace
end
alias to_s :to_sql
end
View
11 lib/active_record/connection_adapters/oracle_enhanced_schema_statements_ext.rb
@@ -26,6 +26,15 @@ def add_primary_key_trigger(table_name, options={})
create_primary_key_trigger(table_name, options)
end
+ def table_definition_tablespace
+ # TODO: Support specifying an :index_tablespace option in create_table?
+ tablespace_sql = ''
+ if tablespace = default_tablespace_for(:index)
+ tablespace_sql << " USING INDEX TABLESPACE #{tablespace}"
+ end
+ tablespace_sql
+ end
+
# Adds a new foreign key to the +from_table+, referencing the primary key of +to_table+
# (syntax and partial implementation taken from http://github.com/matthuhiggins/foreigner)
#
@@ -241,7 +250,7 @@ def remove_synonym(name)
# get synonyms for schema dump
def synonyms #:nodoc:
- select_all("SELECT synonym_name, table_owner, table_name, db_link FROM user_synonyms").collect do |row|
+ select_all("SELECT synonym_name, table_owner, table_name, db_link FROM all_synonyms WHERE owner = SYS_CONTEXT('userenv', 'current_schema')").collect do |row|
OracleEnhancedSynonymDefinition.new(oracle_downcase(row['synonym_name']),
oracle_downcase(row['table_owner']), oracle_downcase(row['table_name']), oracle_downcase(row['db_link']))
end
View
18 lib/active_record/connection_adapters/oracle_enhanced_structure_dump.rb
@@ -10,7 +10,7 @@ def structure_dump #:nodoc:
"CREATE SEQUENCE \"#{seq}\""
end
select_values("SELECT table_name FROM all_tables t
- WHERE owner = SYS_CONTEXT('userenv', 'session_user') AND secondary = 'N'
+ WHERE owner = SYS_CONTEXT('userenv', 'current_schema') AND secondary = 'N'
AND NOT EXISTS (SELECT mv.mview_name FROM all_mviews mv WHERE mv.owner = t.owner AND mv.mview_name = t.table_name)
AND NOT EXISTS (SELECT mvl.log_table FROM all_mview_logs mvl WHERE mvl.log_owner = t.owner AND mvl.log_table = t.table_name)
ORDER BY 1").each do |table_name|
@@ -77,7 +77,7 @@ def structure_dump_primary_key(table) #:nodoc:
ON a.constraint_name = c.constraint_name
WHERE c.table_name = '#{table.upcase}'
AND c.constraint_type = 'P'
- AND c.owner = SYS_CONTEXT('userenv', 'session_user')
+ AND c.owner = SYS_CONTEXT('userenv', 'current_schema')
SQL
pks.each do |row|
opts[:name] = row['constraint_name']
@@ -95,7 +95,7 @@ def structure_dump_unique_keys(table) #:nodoc:
ON a.constraint_name = c.constraint_name
WHERE c.table_name = '#{table.upcase}'
AND c.constraint_type = 'U'
- AND c.owner = SYS_CONTEXT('userenv', 'session_user')
+ AND c.owner = SYS_CONTEXT('userenv', 'current_schema')
SQL
uks.each do |uk|
keys[uk['constraint_name']] ||= []
@@ -123,7 +123,7 @@ def structure_dump_indexes(table_name) #:nodoc:
end
def structure_dump_fk_constraints #:nodoc:
- fks = select_all("SELECT table_name FROM all_tables WHERE owner = SYS_CONTEXT('userenv', 'session_user') ORDER BY 1").map do |table|
+ fks = select_all("SELECT table_name FROM all_tables WHERE owner = SYS_CONTEXT('userenv', 'current_schema') ORDER BY 1").map do |table|
if respond_to?(:foreign_keys) && (foreign_keys = foreign_keys(table["table_name"])).any?
foreign_keys.map do |fk|
sql = "ALTER TABLE #{quote_table_name(fk.from_table)} ADD CONSTRAINT #{quote_column_name(fk.options[:name])} "
@@ -147,14 +147,14 @@ def structure_dump_db_stored_code #:nodoc:
FROM all_source
WHERE type IN ('PROCEDURE', 'PACKAGE', 'PACKAGE BODY', 'FUNCTION', 'TRIGGER', 'TYPE')
AND name NOT LIKE 'BIN$%'
- AND owner = SYS_CONTEXT('userenv', 'session_user') ORDER BY type").each do |source|
+ AND owner = SYS_CONTEXT('userenv', 'current_schema') ORDER BY type").each do |source|
ddl = "CREATE OR REPLACE \n"
lines = select_all(%Q{
SELECT text
FROM all_source
WHERE name = '#{source['name']}'
AND type = '#{source['type']}'
- AND owner = SYS_CONTEXT('userenv', 'session_user')
+ AND owner = SYS_CONTEXT('userenv', 'current_schema')
ORDER BY line
}).map do |row|
ddl << row['text']
@@ -171,7 +171,7 @@ def structure_dump_db_stored_code #:nodoc:
# export synonyms
select_all("SELECT owner, synonym_name, table_name, table_owner
FROM all_synonyms
- WHERE owner = SYS_CONTEXT('userenv', 'session_user') ").each do |synonym|
+ WHERE owner = SYS_CONTEXT('userenv', 'current_schema') ").each do |synonym|
structure << "CREATE OR REPLACE #{synonym['owner'] == 'PUBLIC' ? 'PUBLIC' : '' } SYNONYM #{synonym['synonym_name']}"
structure << " FOR #{synonym['table_owner']}.#{synonym['table_name']}"
end
@@ -184,7 +184,7 @@ def structure_drop #:nodoc:
"DROP SEQUENCE \"#{seq}\""
end
select_values("SELECT table_name from all_tables t
- WHERE owner = SYS_CONTEXT('userenv', 'session_user') AND secondary = 'N'
+ WHERE owner = SYS_CONTEXT('userenv', 'current_schema') AND secondary = 'N'
AND NOT EXISTS (SELECT mv.mview_name FROM all_mviews mv WHERE mv.owner = t.owner AND mv.mview_name = t.table_name)
AND NOT EXISTS (SELECT mvl.log_table FROM all_mview_logs mvl WHERE mvl.log_owner = t.owner AND mvl.log_table = t.table_name)
ORDER BY 1").each do |table|
@@ -196,7 +196,7 @@ def structure_drop #:nodoc:
def temp_table_drop #:nodoc:
join_with_statement_token(select_values(
"SELECT table_name FROM all_tables
- WHERE owner = SYS_CONTEXT('userenv', 'session_user') AND secondary = 'N' AND temporary = 'Y' ORDER BY 1").map do |table|
+ WHERE owner = SYS_CONTEXT('userenv', 'current_schema') AND secondary = 'N' AND temporary = 'Y' ORDER BY 1").map do |table|
"DROP TABLE \"#{table}\" CASCADE CONSTRAINTS"
end)
end
View
0  lib/activerecord-oracle_enhanced-adapter.rb → lib/ctreatma-activerecord-oracle_enhanced-adapter.rb
File renamed without changes

No commit comments for this range

Something went wrong with that request. Please try again.