activerecord-oracle_enhanced-adapter 1.5.1 → 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +21 -0
- data/VERSION +1 -1
- data/activerecord-oracle_enhanced-adapter.gemspec +5 -6
- data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +20 -107
- data/lib/active_record/connection_adapters/oracle_enhanced_column.rb +15 -2
- data/lib/active_record/connection_adapters/oracle_enhanced_database_tasks.rb +61 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb +7 -67
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_creation.rb +89 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_definitions.rb +0 -38
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements.rb +2 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_structure_dump.rb +4 -4
- data/lib/activerecord-oracle_enhanced-adapter.rb +2 -2
- data/spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb +6 -3
- data/spec/active_record/connection_adapters/oracle_enhanced_database_tasks_spec.rb +89 -0
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +19 -0
- metadata +35 -35
- data/lib/active_record/connection_adapters/oracle_enhanced.rake +0 -105
- data/lib/active_record/connection_adapters/oracle_enhanced_core_ext.rb +0 -25
- data/spec/active_record/connection_adapters/oracle_enhanced_core_ext_spec.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7bf4f74b9131f30ae47274a973191aea66e03d3
|
4
|
+
data.tar.gz: 2af0f28befbf925eb787298ee035658312d428e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d85c334b48b66f131f75a1762f1db4e70c5d0908847f83261b4e36a7d91cbfdddb8d5dfeea74c41cf3a3abf969f4e7079cecc8727647346abd0685fbbfa4252
|
7
|
+
data.tar.gz: 6a47685852c79569b1e7bec9bbb4c20835009144ed5e10e9725d20cb4337da8ce1406836151dd89890b00729e958655fcdb5b0f6273f11e88c91ca8cec94ed69
|
data/History.md
CHANGED
@@ -1,3 +1,24 @@
|
|
1
|
+
## 1.5.2 / 2014-01-24
|
2
|
+
|
3
|
+
* Enhancements
|
4
|
+
* Supports Rails 4.1.0.beta1
|
5
|
+
* Support Rails 4 Database Tasks [#404]
|
6
|
+
* Create sequence when add primary_key column [#406]
|
7
|
+
* Move `SchemaCreation` to its own file [#381]
|
8
|
+
* Remove unused OracleEnhancedColumnDefinition [#382]
|
9
|
+
* Log bind variables after they were type casted [#385]
|
10
|
+
* Remove add_order_by_for_association_limiting! [#388]
|
11
|
+
* Support named savepoints [#389]
|
12
|
+
* Support self.extract_value_from_default [#395]
|
13
|
+
* Remove oracle_enhanced_core_ext.rb [#397]
|
14
|
+
* Remove unused to_sql_with_foreign_keys and lob_columns [#398]
|
15
|
+
* Remove ruby-oci8 v1 code [#405]
|
16
|
+
|
17
|
+
* Bug Fix
|
18
|
+
* Move add_column_options! into SchemaCreation class [#384]
|
19
|
+
* Add options_include_default! [#384]
|
20
|
+
* Use OCI8::Metadata::Base#obj_link [#399]
|
21
|
+
|
1
22
|
## 1.5.1 / 2013-11-30
|
2
23
|
|
3
24
|
* Enhancements
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.5.
|
1
|
+
1.5.2
|
@@ -5,12 +5,12 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{activerecord-oracle_enhanced-adapter}
|
8
|
-
s.version = "1.5.
|
8
|
+
s.version = "1.5.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.license = 'MIT'
|
12
12
|
s.authors = [%q{Raimonds Simanovskis}]
|
13
|
-
s.date = %q{
|
13
|
+
s.date = %q{2014-01-24}
|
14
14
|
s.description = %q{Oracle "enhanced" ActiveRecord adapter contains useful additional methods for working with new and legacy Oracle databases.
|
15
15
|
This adapter is superset of original ActiveRecord Oracle adapter.
|
16
16
|
}
|
@@ -29,18 +29,17 @@ This adapter is superset of original ActiveRecord Oracle adapter.
|
|
29
29
|
"VERSION",
|
30
30
|
"activerecord-oracle_enhanced-adapter.gemspec",
|
31
31
|
"lib/active_record/connection_adapters/emulation/oracle_adapter.rb",
|
32
|
-
"lib/active_record/connection_adapters/oracle_enhanced.rake",
|
33
32
|
"lib/active_record/connection_adapters/oracle_enhanced_adapter.rb",
|
34
33
|
"lib/active_record/connection_adapters/oracle_enhanced_column.rb",
|
35
34
|
"lib/active_record/connection_adapters/oracle_enhanced_column_dumper.rb",
|
36
35
|
"lib/active_record/connection_adapters/oracle_enhanced_connection.rb",
|
37
36
|
"lib/active_record/connection_adapters/oracle_enhanced_context_index.rb",
|
38
|
-
"lib/active_record/connection_adapters/oracle_enhanced_core_ext.rb",
|
39
37
|
"lib/active_record/connection_adapters/oracle_enhanced_cpk.rb",
|
40
38
|
"lib/active_record/connection_adapters/oracle_enhanced_dirty.rb",
|
41
39
|
"lib/active_record/connection_adapters/oracle_enhanced_jdbc_connection.rb",
|
42
40
|
"lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb",
|
43
41
|
"lib/active_record/connection_adapters/oracle_enhanced_procedures.rb",
|
42
|
+
"lib/active_record/connection_adapters/oracle_enhanced_schema_creation.rb",
|
44
43
|
"lib/active_record/connection_adapters/oracle_enhanced_schema_definitions.rb",
|
45
44
|
"lib/active_record/connection_adapters/oracle_enhanced_schema_dumper.rb",
|
46
45
|
"lib/active_record/connection_adapters/oracle_enhanced_schema_statements.rb",
|
@@ -51,8 +50,8 @@ This adapter is superset of original ActiveRecord Oracle adapter.
|
|
51
50
|
"spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb",
|
52
51
|
"spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb",
|
53
52
|
"spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb",
|
54
|
-
"spec/active_record/connection_adapters/oracle_enhanced_core_ext_spec.rb",
|
55
53
|
"spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb",
|
54
|
+
"spec/active_record/connection_adapters/oracle_enhanced_database_tasks_spec.rb",
|
56
55
|
"spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb",
|
57
56
|
"spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb",
|
58
57
|
"spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb",
|
@@ -71,8 +70,8 @@ This adapter is superset of original ActiveRecord Oracle adapter.
|
|
71
70
|
"spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb",
|
72
71
|
"spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb",
|
73
72
|
"spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb",
|
74
|
-
"spec/active_record/connection_adapters/oracle_enhanced_core_ext_spec.rb",
|
75
73
|
"spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb",
|
74
|
+
"spec/active_record/connection_adapters/oracle_enhanced_database_tasks_spec.rb",
|
76
75
|
"spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb",
|
77
76
|
"spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb",
|
78
77
|
"spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb",
|
@@ -736,7 +736,10 @@ module ActiveRecord
|
|
736
736
|
end
|
737
737
|
|
738
738
|
def exec_query(sql, name = 'SQL', binds = [])
|
739
|
-
|
739
|
+
type_casted_binds = binds.map { |col, val|
|
740
|
+
[col, type_cast(val, col)]
|
741
|
+
}
|
742
|
+
log(sql, name, type_casted_binds) do
|
740
743
|
cursor = nil
|
741
744
|
cached = false
|
742
745
|
if binds.empty?
|
@@ -938,15 +941,15 @@ module ActiveRecord
|
|
938
941
|
@connection.autocommit = true
|
939
942
|
end
|
940
943
|
|
941
|
-
def create_savepoint #:nodoc:
|
944
|
+
def create_savepoint(name = current_savepoint_name) #:nodoc:
|
942
945
|
execute("SAVEPOINT #{current_savepoint_name}")
|
943
946
|
end
|
944
947
|
|
945
|
-
def rollback_to_savepoint #:nodoc:
|
948
|
+
def rollback_to_savepoint(name = current_savepoint_name) #:nodoc:
|
946
949
|
execute("ROLLBACK TO #{current_savepoint_name}")
|
947
950
|
end
|
948
951
|
|
949
|
-
def release_savepoint #:nodoc:
|
952
|
+
def release_savepoint(name = current_savepoint_name) #:nodoc:
|
950
953
|
# there is no RELEASE SAVEPOINT statement in Oracle
|
951
954
|
end
|
952
955
|
|
@@ -1332,6 +1335,13 @@ module ActiveRecord
|
|
1332
1335
|
def pk_and_sequence_for_without_cache(table_name, owner=nil, desc_table_name=nil, db_link=nil) #:nodoc:
|
1333
1336
|
(owner, desc_table_name, db_link) = @connection.describe(table_name) unless owner
|
1334
1337
|
|
1338
|
+
seqs = select_values(<<-SQL.strip.gsub(/\s+/, ' '), 'Sequence')
|
1339
|
+
select us.sequence_name
|
1340
|
+
from all_sequences#{db_link} us
|
1341
|
+
where us.sequence_owner = '#{owner}'
|
1342
|
+
and us.sequence_name = '#{desc_table_name}_SEQ'
|
1343
|
+
SQL
|
1344
|
+
|
1335
1345
|
# changed back from user_constraints to all_constraints for consistency
|
1336
1346
|
pks = select_values(<<-SQL.strip.gsub(/\s+/, ' '), 'Primary Key')
|
1337
1347
|
SELECT cc.column_name
|
@@ -1344,7 +1354,8 @@ module ActiveRecord
|
|
1344
1354
|
SQL
|
1345
1355
|
|
1346
1356
|
# only support single column keys
|
1347
|
-
pks.size == 1 ? [oracle_downcase(pks.first),
|
1357
|
+
pks.size == 1 ? [oracle_downcase(pks.first),
|
1358
|
+
oracle_downcase(seqs.first)] : nil
|
1348
1359
|
end
|
1349
1360
|
|
1350
1361
|
# Returns just a table's primary key
|
@@ -1394,8 +1405,8 @@ module ActiveRecord
|
|
1394
1405
|
s = s.to_sql unless s.is_a?(String)
|
1395
1406
|
# remove any ASC/DESC modifiers
|
1396
1407
|
s.gsub(/\s+(ASC|DESC)\s*?/i, '')
|
1397
|
-
}.reject(&:blank?).map.with_index { |column,i|
|
1398
|
-
"FIRST_VALUE(#{column}) OVER (PARTITION BY #{columns} ORDER BY #{column}) AS alias_#{i}__"
|
1408
|
+
}.reject(&:blank?).map.with_index { |column,i|
|
1409
|
+
"FIRST_VALUE(#{column}) OVER (PARTITION BY #{columns} ORDER BY #{column}) AS alias_#{i}__"
|
1399
1410
|
}
|
1400
1411
|
[super, *order_columns].join(', ')
|
1401
1412
|
end
|
@@ -1404,21 +1415,6 @@ module ActiveRecord
|
|
1404
1415
|
select_value("SELECT temporary FROM user_tables WHERE table_name = '#{table_name.upcase}'") == 'Y'
|
1405
1416
|
end
|
1406
1417
|
|
1407
|
-
# ORDER BY clause for the passed order option.
|
1408
|
-
#
|
1409
|
-
# Uses column aliases as defined by #distinct.
|
1410
|
-
#
|
1411
|
-
# In Rails 3.x this method is moved to Arel
|
1412
|
-
def add_order_by_for_association_limiting!(sql, options) #:nodoc:
|
1413
|
-
return sql if options[:order].blank?
|
1414
|
-
|
1415
|
-
order = options[:order].split(',').collect { |s| s.strip }.reject(&:blank?)
|
1416
|
-
order.map! {|s| $1 if s =~ / (.*)/}
|
1417
|
-
order = order.zip((0...order.size).to_a).map { |s,i| "alias_#{i}__ #{s}" }.join(', ')
|
1418
|
-
|
1419
|
-
sql << " ORDER BY #{order}"
|
1420
|
-
end
|
1421
|
-
|
1422
1418
|
# construct additional wrapper subquery if select.offset is used to avoid generation of invalid subquery
|
1423
1419
|
# ... IN ( SELECT * FROM ( SELECT raw_sql_.*, rownum raw_rnum_ FROM ( ... ) raw_sql_ ) WHERE raw_rnum_ > ... )
|
1424
1420
|
def join_to_update(update, select) #:nodoc:
|
@@ -1551,9 +1547,6 @@ require 'active_record/connection_adapters/oracle_enhanced_schema_dumper'
|
|
1551
1547
|
# Implementation of structure dump
|
1552
1548
|
require 'active_record/connection_adapters/oracle_enhanced_structure_dump'
|
1553
1549
|
|
1554
|
-
# Add BigDecimal#to_d, Fixnum#to_d and Bignum#to_d methods if not already present
|
1555
|
-
require 'active_record/connection_adapters/oracle_enhanced_core_ext'
|
1556
|
-
|
1557
1550
|
require 'active_record/connection_adapters/oracle_enhanced_version'
|
1558
1551
|
|
1559
1552
|
module ActiveRecord
|
@@ -1563,85 +1556,5 @@ end
|
|
1563
1556
|
# Patches and enhancements for column dumper
|
1564
1557
|
require 'active_record/connection_adapters/oracle_enhanced_column_dumper'
|
1565
1558
|
|
1566
|
-
|
1567
|
-
|
1568
|
-
class OracleEnhancedAdapter < AbstractAdapter
|
1569
|
-
class SchemaCreation < AbstractAdapter::SchemaCreation
|
1570
|
-
private
|
1571
|
-
|
1572
|
-
def visit_ColumnDefinition(o)
|
1573
|
-
if o.type.to_sym == :virtual
|
1574
|
-
sql_type = type_to_sql(o.default[:type], o.limit, o.precision, o.scale) if o.default[:type]
|
1575
|
-
"#{quote_column_name(o.name)} #{sql_type} AS (#{o.default[:as]})"
|
1576
|
-
else
|
1577
|
-
super
|
1578
|
-
end
|
1579
|
-
end
|
1580
|
-
|
1581
|
-
def visit_TableDefinition(o)
|
1582
|
-
tablespace = tablespace_for(:table, o.options[:tablespace])
|
1583
|
-
create_sql = "CREATE#{' GLOBAL TEMPORARY' if o.temporary} TABLE "
|
1584
|
-
create_sql << "#{quote_table_name(o.name)} ("
|
1585
|
-
create_sql << o.columns.map { |c| accept c }.join(', ')
|
1586
|
-
create_sql << ")"
|
1587
|
-
unless o.temporary
|
1588
|
-
create_sql << " ORGANIZATION #{o.options[:organization]}" if o.options[:organization]
|
1589
|
-
create_sql << "#{tablespace}"
|
1590
|
-
end
|
1591
|
-
create_sql << " #{o.options[:options]}"
|
1592
|
-
create_sql
|
1593
|
-
end
|
1594
|
-
|
1595
|
-
def tablespace_for(obj_type, tablespace_option, table_name=nil, column_name=nil)
|
1596
|
-
tablespace_sql = ''
|
1597
|
-
if tablespace = (tablespace_option || default_tablespace_for(obj_type))
|
1598
|
-
tablespace_sql << if [:blob, :clob].include?(obj_type.to_sym)
|
1599
|
-
" LOB (#{quote_column_name(column_name)}) STORE AS #{column_name.to_s[0..10]}_#{table_name.to_s[0..14]}_ls (TABLESPACE #{tablespace})"
|
1600
|
-
else
|
1601
|
-
" TABLESPACE #{tablespace}"
|
1602
|
-
end
|
1603
|
-
end
|
1604
|
-
tablespace_sql
|
1605
|
-
end
|
1606
|
-
|
1607
|
-
def default_tablespace_for(type)
|
1608
|
-
(ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[type] ||
|
1609
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[native_database_types[type][:name]]) rescue nil
|
1610
|
-
end
|
1611
|
-
|
1612
|
-
def foreign_key_definition(to_table, options = {})
|
1613
|
-
@conn.foreign_key_definition(to_table, options)
|
1614
|
-
end
|
1615
|
-
|
1616
|
-
end
|
1617
|
-
|
1618
|
-
def schema_creation
|
1619
|
-
SchemaCreation.new self
|
1620
|
-
end
|
1621
|
-
end
|
1622
|
-
|
1623
|
-
def add_column_options!(sql, options)
|
1624
|
-
type = options[:type] || ((column = options[:column]) && column.type)
|
1625
|
-
type = type && type.to_sym
|
1626
|
-
# handle case of defaults for CLOB columns, which would otherwise get "quoted" incorrectly
|
1627
|
-
if options_include_default?(options)
|
1628
|
-
if type == :text
|
1629
|
-
sql << " DEFAULT #{quote(options[:default])}"
|
1630
|
-
else
|
1631
|
-
# from abstract adapter
|
1632
|
-
sql << " DEFAULT #{quote(options[:default], options[:column])}"
|
1633
|
-
end
|
1634
|
-
end
|
1635
|
-
# must explicitly add NULL or NOT NULL to allow change_column to work on migrations
|
1636
|
-
if options[:null] == false
|
1637
|
-
sql << " NOT NULL"
|
1638
|
-
elsif options[:null] == true
|
1639
|
-
sql << " NULL" unless type == :primary_key
|
1640
|
-
end
|
1641
|
-
# add AS expression for virtual columns
|
1642
|
-
if options[:as].present?
|
1643
|
-
sql << " AS (#{options[:as]})"
|
1644
|
-
end
|
1645
|
-
end
|
1646
|
-
end
|
1647
|
-
end
|
1559
|
+
# Moved SchemaCreation class
|
1560
|
+
require 'active_record/connection_adapters/oracle_enhanced_schema_creation'
|
@@ -10,8 +10,12 @@ module ActiveRecord
|
|
10
10
|
@virtual = virtual
|
11
11
|
@virtual_column_data_default = default.inspect if virtual
|
12
12
|
@returning_id = returning_id
|
13
|
-
|
14
|
-
|
13
|
+
if virtual
|
14
|
+
default_value = nil
|
15
|
+
else
|
16
|
+
default_value = self.class.extract_value_from_default(default)
|
17
|
+
end
|
18
|
+
super(name, default_value, sql_type, null)
|
15
19
|
# Is column NCHAR or NVARCHAR2 (will need to use N'...' value quoting for these data types)?
|
16
20
|
# Define only when needed as adapter "quote" method will check at first if instance variable is defined.
|
17
21
|
@nchar = true if @type == :string && sql_type[0,1] == 'N'
|
@@ -114,6 +118,15 @@ module ActiveRecord
|
|
114
118
|
end
|
115
119
|
end
|
116
120
|
|
121
|
+
def self.extract_value_from_default(default)
|
122
|
+
case default
|
123
|
+
when String
|
124
|
+
default.gsub(/''/, "'")
|
125
|
+
else
|
126
|
+
default
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
117
130
|
def guess_date_or_time(value)
|
118
131
|
value.respond_to?(:hour) && (value.hour == 0 and value.min == 0 and value.sec == 0) ?
|
119
132
|
Date.new(value.year, value.month, value.day) : value
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
class OracleEnhancedAdapter
|
4
|
+
class DatabaseTasks
|
5
|
+
delegate :connection, :establish_connection, :to => ActiveRecord::Base
|
6
|
+
|
7
|
+
def initialize(config)
|
8
|
+
@config = config
|
9
|
+
end
|
10
|
+
|
11
|
+
def create
|
12
|
+
print "Please provide the SYSTEM password for your Oracle installation\n>"
|
13
|
+
system_password = $stdin.gets.strip
|
14
|
+
establish_connection(@config.merge('username' => 'SYSTEM', 'password' => system_password))
|
15
|
+
begin
|
16
|
+
connection.execute "CREATE USER #{@config['username']} IDENTIFIED BY #{@config['password']}"
|
17
|
+
rescue => e
|
18
|
+
if e.message =~ /ORA-01920/ # user name conflicts with another user or role name
|
19
|
+
connection.execute "ALTER USER #{@config['username']} IDENTIFIED BY #{@config['password']}"
|
20
|
+
else
|
21
|
+
raise e
|
22
|
+
end
|
23
|
+
end
|
24
|
+
connection.execute "GRANT unlimited tablespace TO #{@config['username']}"
|
25
|
+
connection.execute "GRANT create session TO #{@config['username']}"
|
26
|
+
connection.execute "GRANT create table TO #{@config['username']}"
|
27
|
+
connection.execute "GRANT create sequence TO #{@config['username']}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def drop
|
31
|
+
establish_connection(@config)
|
32
|
+
connection.execute_structure_dump(connection.full_drop)
|
33
|
+
end
|
34
|
+
|
35
|
+
def purge
|
36
|
+
drop
|
37
|
+
connection.execute('PURGE RECYCLEBIN') rescue nil
|
38
|
+
end
|
39
|
+
|
40
|
+
def structure_dump(filename)
|
41
|
+
establish_connection(@config)
|
42
|
+
File.open(filename, 'w:utf-8') { |f| f << connection.structure_dump }
|
43
|
+
if connection.supports_migrations?
|
44
|
+
File.open(filename, 'a') { |f| f << connection.dump_schema_information }
|
45
|
+
end
|
46
|
+
if @config['structure_dump'] == 'db_stored_code'
|
47
|
+
File.open(filename, 'a') { |f| f << connection.structure_dump_db_stored_code }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def structure_load(filename)
|
52
|
+
establish_connection(@config)
|
53
|
+
connection.execute_structure_dump(File.read(filename))
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
ActiveRecord::Tasks::DatabaseTasks.register_task(/(oci|oracle)/, ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter::DatabaseTasks)
|
61
|
+
|
@@ -254,9 +254,7 @@ module ActiveRecord
|
|
254
254
|
else
|
255
255
|
value
|
256
256
|
end
|
257
|
-
|
258
|
-
# ruby-oci8 2.0 returns Time or DateTime
|
259
|
-
when OraDate, Time, DateTime
|
257
|
+
when Time, DateTime
|
260
258
|
if OracleEnhancedAdapter.emulate_dates && date_without_time?(value)
|
261
259
|
value.to_date
|
262
260
|
else
|
@@ -353,66 +351,15 @@ end
|
|
353
351
|
|
354
352
|
class OCI8 #:nodoc:
|
355
353
|
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
alias :enhanced_define_a_column_pre_ar :define_a_column
|
363
|
-
def define_a_column(i)
|
364
|
-
case do_ocicall(@ctx) { @parms[i - 1].attrGet(OCI_ATTR_DATA_TYPE) }
|
365
|
-
when 8; @stmt.defineByPos(i, String, 65535) # Read LONG values
|
366
|
-
when 187; @stmt.defineByPos(i, OraDate) # Read TIMESTAMP values
|
367
|
-
when 108
|
368
|
-
if @parms[i - 1].attrGet(OCI_ATTR_TYPE_NAME) == 'XMLTYPE'
|
369
|
-
@stmt.defineByPos(i, String, 65535)
|
370
|
-
else
|
371
|
-
raise 'unsupported datatype'
|
372
|
-
end
|
373
|
-
else enhanced_define_a_column_pre_ar i
|
374
|
-
end
|
375
|
-
end
|
376
|
-
end
|
377
|
-
end
|
378
|
-
|
379
|
-
if OCI8.public_method_defined?(:describe_table)
|
380
|
-
# ruby-oci8 2.0 or upper
|
381
|
-
|
382
|
-
def describe(name)
|
383
|
-
info = describe_table(name.to_s)
|
384
|
-
raise %Q{"DESC #{name}" failed} if info.nil?
|
354
|
+
def describe(name)
|
355
|
+
info = describe_table(name.to_s)
|
356
|
+
raise %Q{"DESC #{name}" failed} if info.nil?
|
357
|
+
if info.respond_to? :obj_link and info.obj_link
|
358
|
+
[info.obj_schema, info.obj_name, '@' + info.obj_link]
|
359
|
+
else
|
385
360
|
[info.obj_schema, info.obj_name]
|
386
361
|
end
|
387
|
-
else
|
388
|
-
# ruby-oci8 1.0.x or lower
|
389
|
-
|
390
|
-
# missing constant from oci8 < 0.1.14
|
391
|
-
OCI_PTYPE_UNK = 0 unless defined?(OCI_PTYPE_UNK)
|
392
|
-
|
393
|
-
# Uses the describeAny OCI call to find the target owner and table_name
|
394
|
-
# indicated by +name+, parsing through synonynms as necessary. Returns
|
395
|
-
# an array of [owner, table_name].
|
396
|
-
def describe(name)
|
397
|
-
@desc ||= @@env.alloc(OCIDescribe)
|
398
|
-
@desc.attrSet(OCI_ATTR_DESC_PUBLIC, -1) if VERSION >= '0.1.14'
|
399
|
-
do_ocicall(@ctx) { @desc.describeAny(@svc, name.to_s, OCI_PTYPE_UNK) } rescue raise %Q{"DESC #{name}" failed; does it exist?}
|
400
|
-
info = @desc.attrGet(OCI_ATTR_PARAM)
|
401
|
-
|
402
|
-
case info.attrGet(OCI_ATTR_PTYPE)
|
403
|
-
when OCI_PTYPE_TABLE, OCI_PTYPE_VIEW
|
404
|
-
owner = info.attrGet(OCI_ATTR_OBJ_SCHEMA)
|
405
|
-
table_name = info.attrGet(OCI_ATTR_OBJ_NAME)
|
406
|
-
[owner, table_name]
|
407
|
-
when OCI_PTYPE_SYN
|
408
|
-
schema = info.attrGet(OCI_ATTR_SCHEMA_NAME)
|
409
|
-
name = info.attrGet(OCI_ATTR_NAME)
|
410
|
-
describe(schema + '.' + name)
|
411
|
-
else raise %Q{"DESC #{name}" failed; not a table or view.}
|
412
|
-
end
|
413
|
-
end
|
414
362
|
end
|
415
|
-
|
416
363
|
end
|
417
364
|
|
418
365
|
# The OCI8AutoRecover class enhances the OCI8 driver with auto-recover and
|
@@ -490,12 +437,5 @@ class OCI8EnhancedAutoRecover < DelegateClass(OCI8) #:nodoc:
|
|
490
437
|
end
|
491
438
|
end
|
492
439
|
|
493
|
-
# otherwise not working in Ruby 1.9.1
|
494
|
-
if RUBY_VERSION =~ /^1\.9/
|
495
|
-
def describe(name) #:nodoc:
|
496
|
-
@connection.describe(name)
|
497
|
-
end
|
498
|
-
end
|
499
|
-
|
500
440
|
end
|
501
441
|
#:startdoc:
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
class OracleEnhancedAdapter < AbstractAdapter
|
4
|
+
class SchemaCreation < AbstractAdapter::SchemaCreation
|
5
|
+
private
|
6
|
+
|
7
|
+
def visit_ColumnDefinition(o)
|
8
|
+
if o.type.to_sym == :virtual
|
9
|
+
sql_type = type_to_sql(o.default[:type], o.limit, o.precision, o.scale) if o.default[:type]
|
10
|
+
"#{quote_column_name(o.name)} #{sql_type} AS (#{o.default[:as]})"
|
11
|
+
else
|
12
|
+
super
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def visit_TableDefinition(o)
|
17
|
+
tablespace = tablespace_for(:table, o.options[:tablespace])
|
18
|
+
create_sql = "CREATE#{' GLOBAL TEMPORARY' if o.temporary} TABLE "
|
19
|
+
create_sql << "#{quote_table_name(o.name)} ("
|
20
|
+
create_sql << o.columns.map { |c| accept c }.join(', ')
|
21
|
+
create_sql << ")"
|
22
|
+
unless o.temporary
|
23
|
+
create_sql << " ORGANIZATION #{o.options[:organization]}" if o.options[:organization]
|
24
|
+
create_sql << "#{tablespace}"
|
25
|
+
end
|
26
|
+
create_sql << " #{o.options[:options]}"
|
27
|
+
create_sql
|
28
|
+
end
|
29
|
+
|
30
|
+
def tablespace_for(obj_type, tablespace_option, table_name=nil, column_name=nil)
|
31
|
+
tablespace_sql = ''
|
32
|
+
if tablespace = (tablespace_option || default_tablespace_for(obj_type))
|
33
|
+
tablespace_sql << if [:blob, :clob].include?(obj_type.to_sym)
|
34
|
+
" LOB (#{quote_column_name(column_name)}) STORE AS #{column_name.to_s[0..10]}_#{table_name.to_s[0..14]}_ls (TABLESPACE #{tablespace})"
|
35
|
+
else
|
36
|
+
" TABLESPACE #{tablespace}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
tablespace_sql
|
40
|
+
end
|
41
|
+
|
42
|
+
def default_tablespace_for(type)
|
43
|
+
(ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[type] ||
|
44
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[native_database_types[type][:name]]) rescue nil
|
45
|
+
end
|
46
|
+
|
47
|
+
def foreign_key_definition(to_table, options = {})
|
48
|
+
@conn.foreign_key_definition(to_table, options)
|
49
|
+
end
|
50
|
+
|
51
|
+
def add_column_options!(sql, options)
|
52
|
+
type = options[:type] || ((column = options[:column]) && column.type)
|
53
|
+
type = type && type.to_sym
|
54
|
+
# handle case of defaults for CLOB columns, which would otherwise get "quoted" incorrectly
|
55
|
+
if options_include_default?(options)
|
56
|
+
if type == :text
|
57
|
+
sql << " DEFAULT #{@conn.quote(options[:default])}"
|
58
|
+
else
|
59
|
+
# from abstract adapter
|
60
|
+
sql << " DEFAULT #{@conn.quote(options[:default], options[:column])}"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
# must explicitly add NULL or NOT NULL to allow change_column to work on migrations
|
64
|
+
if options[:null] == false
|
65
|
+
sql << " NOT NULL"
|
66
|
+
elsif options[:null] == true
|
67
|
+
sql << " NULL" unless type == :primary_key
|
68
|
+
end
|
69
|
+
# add AS expression for virtual columns
|
70
|
+
if options[:as].present?
|
71
|
+
sql << " AS (#{options[:as]})"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# This method does not exist in SchemaCreation at Rails 4.0
|
76
|
+
# It can be removed only when Oracle enhanced adapter supports Rails 4.1 and higher
|
77
|
+
def options_include_default?(options)
|
78
|
+
options.include?(:default) && !(options[:null] == false && options[:default].nil?)
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
def schema_creation
|
84
|
+
SchemaCreation.new self
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -10,38 +10,12 @@ module ActiveRecord
|
|
10
10
|
:tablespace, :columns) #:nodoc:
|
11
11
|
end
|
12
12
|
|
13
|
-
module OracleEnhancedColumnDefinition
|
14
|
-
def self.included(base) #:nodoc:
|
15
|
-
base.class_eval do
|
16
|
-
#alias_method_chain :to_sql, :virtual_columns
|
17
|
-
#alias to_s :to_sql
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def to_sql_with_virtual_columns
|
22
|
-
if type == :virtual
|
23
|
-
sql_type = base.type_to_sql(default[:type], limit, precision, scale) if default[:type]
|
24
|
-
"#{base.quote_column_name(name)} #{sql_type} AS (#{default[:as]})"
|
25
|
-
else
|
26
|
-
to_sql_without_virtual_columns
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def lob?
|
31
|
-
['CLOB', 'BLOB'].include?(sql_type)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
13
|
module OracleEnhancedSchemaDefinitions #:nodoc:
|
36
14
|
def self.included(base)
|
37
15
|
base::TableDefinition.class_eval do
|
38
16
|
include OracleEnhancedTableDefinition
|
39
17
|
end
|
40
18
|
|
41
|
-
base::ColumnDefinition.class_eval do
|
42
|
-
include OracleEnhancedColumnDefinition
|
43
|
-
end
|
44
|
-
|
45
19
|
# Available starting from ActiveRecord 2.1
|
46
20
|
base::Table.class_eval do
|
47
21
|
include OracleEnhancedTable
|
@@ -60,8 +34,6 @@ module ActiveRecord
|
|
60
34
|
def self.included(base) #:nodoc:
|
61
35
|
base.class_eval do
|
62
36
|
alias_method_chain :references, :foreign_keys
|
63
|
-
#alias_method_chain :to_sql, :foreign_keys
|
64
|
-
|
65
37
|
alias_method_chain :column, :virtual_columns
|
66
38
|
end
|
67
39
|
end
|
@@ -142,16 +114,6 @@ module ActiveRecord
|
|
142
114
|
end
|
143
115
|
end
|
144
116
|
|
145
|
-
def to_sql_with_foreign_keys #:nodoc:
|
146
|
-
sql = to_sql_without_foreign_keys
|
147
|
-
sql << ', ' << (foreign_keys * ', ') unless foreign_keys.blank?
|
148
|
-
sql
|
149
|
-
end
|
150
|
-
|
151
|
-
def lob_columns
|
152
|
-
columns.select(&:lob?)
|
153
|
-
end
|
154
|
-
|
155
117
|
def foreign_keys
|
156
118
|
@foreign_keys ||= []
|
157
119
|
end
|
@@ -278,6 +278,8 @@ module ActiveRecord
|
|
278
278
|
add_column_sql << tablespace_for((type_to_sql(type).downcase.to_sym), nil, table_name, column_name) if type
|
279
279
|
|
280
280
|
execute(add_column_sql)
|
281
|
+
|
282
|
+
create_sequence_and_trigger(table_name, options) if type && type.to_sym == :primary_key
|
281
283
|
ensure
|
282
284
|
clear_table_columns_cache(table_name)
|
283
285
|
end
|
@@ -149,17 +149,17 @@ module ActiveRecord #:nodoc:
|
|
149
149
|
AND name NOT LIKE 'BIN$%'
|
150
150
|
AND owner = SYS_CONTEXT('userenv', 'session_user') ORDER BY type").each do |source|
|
151
151
|
ddl = "CREATE OR REPLACE \n"
|
152
|
-
|
152
|
+
select_all(%Q{
|
153
153
|
SELECT text
|
154
154
|
FROM all_source
|
155
155
|
WHERE name = '#{source['name']}'
|
156
156
|
AND type = '#{source['type']}'
|
157
157
|
AND owner = SYS_CONTEXT('userenv', 'session_user')
|
158
158
|
ORDER BY line
|
159
|
-
}).
|
159
|
+
}).each do |row|
|
160
160
|
ddl << row['text']
|
161
161
|
end
|
162
|
-
ddl << ";" unless ddl.strip[-1,1] ==
|
162
|
+
ddl << ";" unless ddl.strip[-1,1] == ';'
|
163
163
|
structure << ddl
|
164
164
|
end
|
165
165
|
|
@@ -240,7 +240,7 @@ module ActiveRecord #:nodoc:
|
|
240
240
|
|
241
241
|
def execute_structure_dump(string)
|
242
242
|
string.split(STATEMENT_TOKEN).each do |ddl|
|
243
|
-
ddl.chop! if ddl
|
243
|
+
ddl.chop! if ddl[-1,1] == ';'
|
244
244
|
execute(ddl) unless ddl.blank?
|
245
245
|
end
|
246
246
|
end
|
@@ -5,7 +5,7 @@ if defined?(::Rails::Railtie)
|
|
5
5
|
module ConnectionAdapters
|
6
6
|
class OracleEnhancedRailtie < ::Rails::Railtie
|
7
7
|
rake_tasks do
|
8
|
-
load 'active_record/connection_adapters/
|
8
|
+
load 'active_record/connection_adapters/oracle_enhanced_database_tasks.rb'
|
9
9
|
end
|
10
10
|
|
11
11
|
ActiveSupport.on_load(:active_record) do
|
@@ -22,4 +22,4 @@ if defined?(::Rails::Railtie)
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
end
|
25
|
+
end
|
@@ -174,6 +174,8 @@ describe "OracleEnhancedAdapter context index" do
|
|
174
174
|
describe "on multiple tables" do
|
175
175
|
before(:all) do
|
176
176
|
@conn = ActiveRecord::Base.connection
|
177
|
+
@oracle12c = !! @conn.select_value(
|
178
|
+
"select * from product_component_version where product like 'Oracle%' and to_number(substr(version,1,2)) = 12")
|
177
179
|
create_tables
|
178
180
|
class ::Post < ActiveRecord::Base
|
179
181
|
has_many :comments, dependent: :destroy
|
@@ -192,10 +194,13 @@ describe "OracleEnhancedAdapter context index" do
|
|
192
194
|
end
|
193
195
|
|
194
196
|
after(:each) do
|
197
|
+
@conn.remove_context_index :posts, name: 'post_and_comments_index' rescue nil
|
198
|
+
@conn.remove_context_index :posts, index_column: :all_text rescue nil
|
195
199
|
Post.destroy_all
|
196
200
|
end
|
197
201
|
|
198
202
|
it "should create multiple table index with specified main index column" do
|
203
|
+
pending "It always fails when Oracle 12c 12.1.0 used." if @oracle12c
|
199
204
|
@conn.add_context_index :posts,
|
200
205
|
[:title, :body,
|
201
206
|
# specify aliases always with AS keyword
|
@@ -210,10 +215,10 @@ describe "OracleEnhancedAdapter context index" do
|
|
210
215
|
["aaa", "bbb", "ccc", "ddd", "eee", "fff"].each do |word|
|
211
216
|
Post.contains(:all_text, word).to_a.should == [@post]
|
212
217
|
end
|
213
|
-
@conn.remove_context_index :posts, name: 'post_and_comments_index'
|
214
218
|
end
|
215
219
|
|
216
220
|
it "should create multiple table index with specified main index column (when subquery has newlines)" do
|
221
|
+
pending "It always fails when Oracle 12c 12.1.0 used." if @oracle12c
|
217
222
|
@conn.add_context_index :posts,
|
218
223
|
[:title, :body,
|
219
224
|
# specify aliases always with AS keyword
|
@@ -232,7 +237,6 @@ describe "OracleEnhancedAdapter context index" do
|
|
232
237
|
["aaa", "bbb", "ccc", "ddd", "eee", "fff"].each do |word|
|
233
238
|
Post.contains(:all_text, word).to_a.should == [@post]
|
234
239
|
end
|
235
|
-
@conn.remove_context_index :posts, name: 'post_and_comments_index'
|
236
240
|
end
|
237
241
|
|
238
242
|
it "should find by search term within specified field" do
|
@@ -252,7 +256,6 @@ describe "OracleEnhancedAdapter context index" do
|
|
252
256
|
Post.contains(:all_text, "ccc within comment_body").to_a.should be_empty
|
253
257
|
Post.contains(:all_text, "ddd within comment_body").to_a.should == [@post]
|
254
258
|
Post.contains(:all_text, "ddd within comment_author").to_a.should be_empty
|
255
|
-
@conn.remove_context_index :posts, index_column: :all_text
|
256
259
|
end
|
257
260
|
|
258
261
|
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'active_record/connection_adapters/oracle_enhanced_database_tasks'
|
3
|
+
require 'stringio'
|
4
|
+
require 'tempfile'
|
5
|
+
|
6
|
+
describe "Oracle Enhanced adapter database tasks" do
|
7
|
+
let(:config) { CONNECTION_PARAMS.with_indifferent_access }
|
8
|
+
|
9
|
+
describe "create" do
|
10
|
+
let(:new_user_config) { config.merge({username: "oracle_enhanced_test_user"}) }
|
11
|
+
before do
|
12
|
+
fake_terminal(SYSTEM_CONNECTION_PARAMS[:password]) do
|
13
|
+
ActiveRecord::Tasks::DatabaseTasks.create(new_user_config)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
it "creates user" do
|
17
|
+
query = "SELECT COUNT(*) FROM dba_users WHERE UPPER(username) = '#{new_user_config[:username].upcase}'"
|
18
|
+
ActiveRecord::Base.connection.select_value(query).should == 1
|
19
|
+
end
|
20
|
+
after do
|
21
|
+
ActiveRecord::Base.connection.execute("DROP USER #{new_user_config[:username]}");
|
22
|
+
end
|
23
|
+
|
24
|
+
def fake_terminal(input)
|
25
|
+
$stdin = StringIO.new
|
26
|
+
$stdout = StringIO.new
|
27
|
+
$stdin.puts(input)
|
28
|
+
$stdin.rewind
|
29
|
+
yield
|
30
|
+
ensure
|
31
|
+
$stdin = STDIN
|
32
|
+
$stdout = STDOUT
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "with test table" do
|
37
|
+
before do
|
38
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
39
|
+
ActiveRecord::Base.connection.execute "CREATE TABLE test_posts (name VARCHAR2(20))"
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "drop" do
|
43
|
+
before { ActiveRecord::Tasks::DatabaseTasks.drop(config) }
|
44
|
+
it "drops all tables" do
|
45
|
+
ActiveRecord::Base.connection.table_exists?(:test_posts).should be_false
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "purge" do
|
50
|
+
before { ActiveRecord::Tasks::DatabaseTasks.purge(config) }
|
51
|
+
it "drops all tables" do
|
52
|
+
ActiveRecord::Base.connection.table_exists?(:test_posts).should be_false
|
53
|
+
ActiveRecord::Base.connection.select_value("SELECT COUNT(*) FROM RECYCLEBIN").should == 0
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "structure" do
|
58
|
+
let(:temp_file) { Tempfile.new(["oracle_enhanced", ".sql"]).path }
|
59
|
+
before { ActiveRecord::SchemaMigration.create_table }
|
60
|
+
|
61
|
+
describe "structure_dump" do
|
62
|
+
before { ActiveRecord::Tasks::DatabaseTasks.structure_dump(config, temp_file) }
|
63
|
+
it "dumps the database structure to a file" do
|
64
|
+
contents = File.read(temp_file)
|
65
|
+
contents.should include('CREATE TABLE "TEST_POSTS"')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "structure_load" do
|
70
|
+
before do
|
71
|
+
ActiveRecord::Tasks::DatabaseTasks.structure_dump(config, temp_file)
|
72
|
+
ActiveRecord::Tasks::DatabaseTasks.drop(config)
|
73
|
+
ActiveRecord::Tasks::DatabaseTasks.structure_load(config, temp_file)
|
74
|
+
end
|
75
|
+
it "loads the database structure from a file" do
|
76
|
+
ActiveRecord::Base.connection.table_exists?(:test_posts).should be_true
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
after do
|
81
|
+
File.delete(temp_file)
|
82
|
+
ActiveRecord::SchemaMigration.drop_table
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
after { ActiveRecord::Base.connection.execute "DROP TABLE test_posts" rescue nil }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
@@ -10,6 +10,25 @@ describe "OracleEnhancedAdapter schema definition" do
|
|
10
10
|
"select * from product_component_version where product like 'Oracle%' and to_number(substr(version,1,2)) >= 11")
|
11
11
|
end
|
12
12
|
|
13
|
+
describe 'option to create sequence when adding a column' do
|
14
|
+
before do
|
15
|
+
@conn = ActiveRecord::Base.connection
|
16
|
+
schema_define do
|
17
|
+
create_table :keyboards, :force => true, :id => false do |t|
|
18
|
+
t.string :name
|
19
|
+
end
|
20
|
+
add_column :keyboards, :id, :primary_key
|
21
|
+
end
|
22
|
+
class ::Keyboard < ActiveRecord::Base; end
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'creates a sequence when adding a column with create_sequence = true' do
|
26
|
+
_, sequence_name = ActiveRecord::Base.connection.pk_and_sequence_for_without_cache(:keyboards)
|
27
|
+
|
28
|
+
sequence_name.should == Keyboard.sequence_name
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
13
32
|
describe "table and sequence creation with non-default primary key" do
|
14
33
|
|
15
34
|
before(:all) do
|
metadata
CHANGED
@@ -1,195 +1,195 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-oracle_enhanced-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Raimonds Simanovskis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jeweler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.8'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.8'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '2.4'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '2.4'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rdoc
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: activerecord
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: activemodel
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: activesupport
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: actionpack
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: railties
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- -
|
122
|
+
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: arel
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- -
|
129
|
+
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- -
|
136
|
+
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: journey
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- -
|
143
|
+
- - ">="
|
144
144
|
- !ruby/object:Gem::Version
|
145
145
|
version: '0'
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
|
-
- -
|
150
|
+
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: activerecord-deprecated_finders
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
|
-
- -
|
157
|
+
- - ">="
|
158
158
|
- !ruby/object:Gem::Version
|
159
159
|
version: '0'
|
160
160
|
type: :development
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
|
-
- -
|
164
|
+
- - ">="
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: ruby-plsql
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
170
170
|
requirements:
|
171
|
-
- -
|
171
|
+
- - ">="
|
172
172
|
- !ruby/object:Gem::Version
|
173
173
|
version: 0.5.0
|
174
174
|
type: :development
|
175
175
|
prerelease: false
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
|
-
- -
|
178
|
+
- - ">="
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: 0.5.0
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
182
|
name: ruby-oci8
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|
184
184
|
requirements:
|
185
|
-
- -
|
185
|
+
- - ">="
|
186
186
|
- !ruby/object:Gem::Version
|
187
187
|
version: '0'
|
188
188
|
type: :development
|
189
189
|
prerelease: false
|
190
190
|
version_requirements: !ruby/object:Gem::Requirement
|
191
191
|
requirements:
|
192
|
-
- -
|
192
|
+
- - ">="
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '0'
|
195
195
|
description: |
|
@@ -201,7 +201,7 @@ extensions: []
|
|
201
201
|
extra_rdoc_files:
|
202
202
|
- README.md
|
203
203
|
files:
|
204
|
-
- .rspec
|
204
|
+
- ".rspec"
|
205
205
|
- Gemfile
|
206
206
|
- History.md
|
207
207
|
- License.txt
|
@@ -211,18 +211,18 @@ files:
|
|
211
211
|
- VERSION
|
212
212
|
- activerecord-oracle_enhanced-adapter.gemspec
|
213
213
|
- lib/active_record/connection_adapters/emulation/oracle_adapter.rb
|
214
|
-
- lib/active_record/connection_adapters/oracle_enhanced.rake
|
215
214
|
- lib/active_record/connection_adapters/oracle_enhanced_adapter.rb
|
216
215
|
- lib/active_record/connection_adapters/oracle_enhanced_column.rb
|
217
216
|
- lib/active_record/connection_adapters/oracle_enhanced_column_dumper.rb
|
218
217
|
- lib/active_record/connection_adapters/oracle_enhanced_connection.rb
|
219
218
|
- lib/active_record/connection_adapters/oracle_enhanced_context_index.rb
|
220
|
-
- lib/active_record/connection_adapters/oracle_enhanced_core_ext.rb
|
221
219
|
- lib/active_record/connection_adapters/oracle_enhanced_cpk.rb
|
220
|
+
- lib/active_record/connection_adapters/oracle_enhanced_database_tasks.rb
|
222
221
|
- lib/active_record/connection_adapters/oracle_enhanced_dirty.rb
|
223
222
|
- lib/active_record/connection_adapters/oracle_enhanced_jdbc_connection.rb
|
224
223
|
- lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb
|
225
224
|
- lib/active_record/connection_adapters/oracle_enhanced_procedures.rb
|
225
|
+
- lib/active_record/connection_adapters/oracle_enhanced_schema_creation.rb
|
226
226
|
- lib/active_record/connection_adapters/oracle_enhanced_schema_definitions.rb
|
227
227
|
- lib/active_record/connection_adapters/oracle_enhanced_schema_dumper.rb
|
228
228
|
- lib/active_record/connection_adapters/oracle_enhanced_schema_statements.rb
|
@@ -233,9 +233,9 @@ files:
|
|
233
233
|
- spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb
|
234
234
|
- spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb
|
235
235
|
- spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb
|
236
|
-
- spec/active_record/connection_adapters/oracle_enhanced_core_ext_spec.rb
|
237
236
|
- spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb
|
238
237
|
- spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb
|
238
|
+
- spec/active_record/connection_adapters/oracle_enhanced_database_tasks_spec.rb
|
239
239
|
- spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb
|
240
240
|
- spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb
|
241
241
|
- spec/active_record/connection_adapters/oracle_enhanced_emulate_oracle_adapter_spec.rb
|
@@ -254,17 +254,17 @@ require_paths:
|
|
254
254
|
- lib
|
255
255
|
required_ruby_version: !ruby/object:Gem::Requirement
|
256
256
|
requirements:
|
257
|
-
- -
|
257
|
+
- - ">="
|
258
258
|
- !ruby/object:Gem::Version
|
259
259
|
version: '0'
|
260
260
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
261
261
|
requirements:
|
262
|
-
- -
|
262
|
+
- - ">="
|
263
263
|
- !ruby/object:Gem::Version
|
264
264
|
version: '0'
|
265
265
|
requirements: []
|
266
266
|
rubyforge_project:
|
267
|
-
rubygems_version: 2.1
|
267
|
+
rubygems_version: 2.2.1
|
268
268
|
signing_key:
|
269
269
|
specification_version: 4
|
270
270
|
summary: Oracle enhanced adapter for ActiveRecord
|
@@ -1,105 +0,0 @@
|
|
1
|
-
# implementation idea taken from JDBC adapter
|
2
|
-
# added possibility to execute previously defined task (passed as argument to task block)
|
3
|
-
def redefine_task(*args, &block)
|
4
|
-
task_name = Hash === args.first ? args.first.keys[0] : args.first
|
5
|
-
existing_task = Rake.application.lookup task_name
|
6
|
-
existing_actions = nil
|
7
|
-
if existing_task
|
8
|
-
class << existing_task; public :instance_variable_set, :instance_variable_get; end
|
9
|
-
existing_task.instance_variable_set "@prerequisites", FileList[]
|
10
|
-
existing_actions = existing_task.instance_variable_get "@actions"
|
11
|
-
existing_task.instance_variable_set "@actions", []
|
12
|
-
end
|
13
|
-
task(*args) do
|
14
|
-
block.call(existing_actions)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
# Creates database user with db:create
|
19
|
-
if defined?(create_database) == 'method'
|
20
|
-
def create_database_with_oracle_enhanced(config)
|
21
|
-
if config['adapter'] == 'oracle_enhanced'
|
22
|
-
print "Please provide the SYSTEM password for your oracle installation\n>"
|
23
|
-
system_password = $stdin.gets.strip
|
24
|
-
ActiveRecord::Base.establish_connection(config.merge('username' => 'SYSTEM', 'password' => system_password))
|
25
|
-
begin
|
26
|
-
ActiveRecord::Base.connection.execute "CREATE USER #{config['username']} IDENTIFIED BY #{config['password']}"
|
27
|
-
rescue => e
|
28
|
-
if e.message =~ /ORA-01920/ # user name conflicts with another user or role name
|
29
|
-
ActiveRecord::Base.connection.execute "ALTER USER #{config['username']} IDENTIFIED BY #{config['password']}"
|
30
|
-
else
|
31
|
-
raise e
|
32
|
-
end
|
33
|
-
end
|
34
|
-
ActiveRecord::Base.connection.execute "GRANT unlimited tablespace TO #{config['username']}"
|
35
|
-
ActiveRecord::Base.connection.execute "GRANT create session TO #{config['username']}"
|
36
|
-
ActiveRecord::Base.connection.execute "GRANT create table TO #{config['username']}"
|
37
|
-
ActiveRecord::Base.connection.execute "GRANT create sequence TO #{config['username']}"
|
38
|
-
else
|
39
|
-
create_database_without_oracle_enhanced(config)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
alias :create_database_without_oracle_enhanced :create_database
|
43
|
-
alias :create_database :create_database_with_oracle_enhanced
|
44
|
-
end
|
45
|
-
|
46
|
-
# Drops database user with db:drop
|
47
|
-
if defined?(drop_database) == 'method'
|
48
|
-
def drop_database_with_oracle_enhanced(config)
|
49
|
-
if config['adapter'] == 'oracle_enhanced'
|
50
|
-
ActiveRecord::Base.establish_connection(config)
|
51
|
-
ActiveRecord::Base.connection.execute_structure_dump(ActiveRecord::Base.connection.full_drop)
|
52
|
-
else
|
53
|
-
drop_database_without_oracle_enhanced(config)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
alias :drop_database_without_oracle_enhanced :drop_database
|
57
|
-
alias :drop_database :drop_database_with_oracle_enhanced
|
58
|
-
end
|
59
|
-
|
60
|
-
namespace :db do
|
61
|
-
|
62
|
-
namespace :structure do
|
63
|
-
redefine_task :dump => :environment do |existing_actions|
|
64
|
-
abcs = ActiveRecord::Base.configurations
|
65
|
-
rails_env = defined?(Rails.env) ? Rails.env : RAILS_ENV
|
66
|
-
if abcs[rails_env]['adapter'] == 'oracle_enhanced'
|
67
|
-
ActiveRecord::Base.establish_connection(abcs[rails_env])
|
68
|
-
File.open("db/#{rails_env}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump }
|
69
|
-
if ActiveRecord::Base.connection.supports_migrations?
|
70
|
-
File.open("db/#{rails_env}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.dump_schema_information }
|
71
|
-
end
|
72
|
-
if abcs[rails_env]['structure_dump'] == "db_stored_code"
|
73
|
-
File.open("db/#{rails_env}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.structure_dump_db_stored_code }
|
74
|
-
end
|
75
|
-
else
|
76
|
-
Array(existing_actions).each{|action| action.call}
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
namespace :test do
|
82
|
-
redefine_task :clone_structure => [ "db:structure:dump", "db:test:purge" ] do |existing_actions|
|
83
|
-
abcs = ActiveRecord::Base.configurations
|
84
|
-
rails_env = defined?(Rails.env) ? Rails.env : RAILS_ENV
|
85
|
-
if abcs[rails_env]['adapter'] == 'oracle_enhanced' && abcs['test']['adapter'] == 'oracle_enhanced'
|
86
|
-
ActiveRecord::Base.establish_connection(:test)
|
87
|
-
ActiveRecord::Base.connection.execute_structure_dump(File.read("db/#{rails_env}_structure.sql"))
|
88
|
-
else
|
89
|
-
Array(existing_actions).each{|action| action.call}
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
redefine_task :purge => :environment do |existing_actions|
|
94
|
-
abcs = ActiveRecord::Base.configurations
|
95
|
-
if abcs['test']['adapter'] == 'oracle_enhanced'
|
96
|
-
ActiveRecord::Base.establish_connection(:test)
|
97
|
-
ActiveRecord::Base.connection.execute_structure_dump(ActiveRecord::Base.connection.full_drop)
|
98
|
-
ActiveRecord::Base.connection.execute("PURGE RECYCLEBIN") rescue nil
|
99
|
-
else
|
100
|
-
Array(existing_actions).each{|action| action.call}
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
end
|
105
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require "bigdecimal"
|
2
|
-
|
3
|
-
unless BigDecimal.method_defined?(:to_d)
|
4
|
-
BigDecimal.class_eval do
|
5
|
-
def to_d #:nodoc:
|
6
|
-
self
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
unless Bignum.method_defined?(:to_d)
|
12
|
-
Bignum.class_eval do
|
13
|
-
def to_d #:nodoc:
|
14
|
-
BigDecimal.new(self.to_s)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
unless Fixnum.method_defined?(:to_d)
|
20
|
-
Fixnum.class_eval do
|
21
|
-
def to_d #:nodoc:
|
22
|
-
BigDecimal.new(self.to_s)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe "OracleEnhancedAdapter to_d method" do
|
5
|
-
it "BigDecimal#to_d returns the same decimal number" do
|
6
|
-
d = BigDecimal.new("12345678901234567890.0123456789")
|
7
|
-
d.to_d.should == d
|
8
|
-
end
|
9
|
-
|
10
|
-
it "Bignum#to_d translates large integer to decimal" do
|
11
|
-
n = 12345678901234567890
|
12
|
-
n.to_d.should == BigDecimal.new(n.to_s)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "Fixnum#to_d translates small integer to decimal" do
|
16
|
-
n = 123456
|
17
|
-
n.to_d.should == BigDecimal.new(n.to_s)
|
18
|
-
end
|
19
|
-
end
|