activerecord-import-oracle_enhanced 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7cb0ea339d2e70c0301aa5042049b9e8929cf3e0
4
+ data.tar.gz: d309a177339065038b28a832c4feda1a7ce03e58
5
+ SHA512:
6
+ metadata.gz: 621390f69914709019c7b796a5690dea37afc9b9264859297f900807d95698066e8f765caf60694c38834635b785e0c7512a97d8581bec81125c8124346d80b3
7
+ data.tar.gz: 777ce720ab5ed7d4a0eb8f0adcb50bd9ad8caaef18e08005600c017caa94cf3f710521719471c858a4612e4b254ee0ea1bd6528a22053e7a8a46d45e5bbac352
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "http://rubygems.org"
2
+
3
+ # load the gem's dependencies
4
+ gemspec
5
+
6
+ # oracle_enhanced driver
7
+ gem "activerecord-oracle_enhanced-adapter"
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # activerecord-import-oracle_enhanced
2
+
3
+ activerecord-import-oracle_enhanced is an extension for activerecord-import to provide support for the activerecord-oracle_enhanced-adapter.
4
+
5
+ It uses Oracle multitable insert and assumes that you have a DML trigger setup for the targeting table before inserting.
6
+
7
+ ## DML Trigger
8
+
9
+ Since Oracle needs to prefetch the primary key and a call to `<sequence_name>.nextval` will always return the same value in an INSERT ALL statement. Consequently, if you want to properly use this gem and bulk insert data into tables which have a primary key without providing said key, you have to create a DML trigger which fires before inserting a row into your table and setting your primary key if it is not set. Such a trigger could be written as such (replacing `<table_name>` and `<sequence_name>` with the proper values) :
10
+
11
+ ```sql
12
+ CREATE OR REPLACE trigger <table_name>_trg
13
+ before insert on <table_name>
14
+ for each row
15
+ BEGIN
16
+ IF :new.id = NULL THEN
17
+ :new.id := <sequence_name>.nextval;
18
+ END IF;
19
+ END;
20
+ /
21
+ ```
22
+
23
+ Bear in mind that you have to respect Oracle limitations of 30 characters for the trigger name.
24
+
25
+ ## License
26
+
27
+ Copyright (c) 2017 Félix Bellanger <felix.bellanger@gmail.com>
28
+
29
+ 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:
30
+
31
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
32
+
33
+ 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.
data/Rakefile ADDED
File without changes
@@ -0,0 +1,22 @@
1
+ require File.expand_path('../lib/activerecord-import-oracle_enhanced/version', __FILE__)
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.authors = ["Félix Bellanger"]
5
+ gem.email = ["felix.bellanger@gmail.com"]
6
+ gem.summary = "Bulk insert extension for ActiveRecord and Oracle"
7
+ gem.description = "A library for bulk inserting data using ActiveRecord and Oracle."
8
+ gem.homepage = "http://github.com/keeguon/activerecord-import-oracle_enhanced"
9
+ gem.license = "MIT"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "activerecord-import-oracle_enhanced"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = ActiveRecord::Import::OracleEnhanced::VERSION
17
+
18
+ gem.required_ruby_version = ">= 1.9.2"
19
+
20
+ gem.add_runtime_dependency "activerecord-import", ">= 0.18"
21
+ gem.add_development_dependency "rake"
22
+ end
File without changes
@@ -0,0 +1,7 @@
1
+ module ActiveRecord
2
+ module Import
3
+ module OracleEnhanced
4
+ VERSION = "0.1.0".freeze
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ require "active_record/connection_adapters/oracle_enhanced_adapter"
2
+ require "activerecord-import/adapters/oracle_enhanced_adapter"
3
+
4
+ class ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter
5
+ include ActiveRecord::Import::OracleEnhancedAdapter
6
+ end
@@ -0,0 +1,51 @@
1
+ module ActiveRecord::Import::OracleEnhancedAdapter
2
+ include ActiveRecord::Import::ImportSupport
3
+
4
+ def insert_many( sql, values, options = {}, *args ) # :nodoc:
5
+ number_of_inserts = 0
6
+ into_statement = ""
7
+
8
+ base_sql, post_sql = if sql.is_a?( String )
9
+ [sql, '']
10
+ elsif sql.is_a?( Array )
11
+ [sql.shift, sql.join( ' ' )]
12
+ end
13
+
14
+ # Tweak base_sql and fetch into_statement
15
+ into_statement = base_sql.match(/INTO .* VALUES/)[0]
16
+ base_sql.gsub!(/INTO .* VALUES /, '')
17
+
18
+ value_sets = ::ActiveRecord::Import::ValueSetsRecordsParser.parse(values,
19
+ max_records: max_allowed_packet)
20
+
21
+ transaction(requires_new: true) do
22
+ value_sets.each do |value_set|
23
+ number_of_inserts += 1
24
+ sql2insert = base_sql + value_set.map { |values| "#{into_statement} #{values}" }.join( ' ' ) + post_sql
25
+ insert( sql2insert, *args )
26
+ end
27
+ end
28
+
29
+ [number_of_inserts, []]
30
+ end
31
+
32
+ def next_value_for_sequence(sequence_name)
33
+ %{NULL}
34
+ end
35
+
36
+ def pre_sql_statements(options)
37
+ sql = []
38
+ sql << "ALL"
39
+ sql + super
40
+ end
41
+
42
+ def post_sql_statements(table_name, options)
43
+ sql = []
44
+ sql << " SELECT * FROM dual";
45
+ sql + super(table_name, options)
46
+ end
47
+
48
+ def max_allowed_packet
49
+ 1000
50
+ end
51
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activerecord-import-oracle_enhanced
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Félix Bellanger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-07-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord-import
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0.18'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0.18'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A library for bulk inserting data using ActiveRecord and Oracle.
42
+ email:
43
+ - felix.bellanger@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - Gemfile
49
+ - README.md
50
+ - Rakefile
51
+ - activerecord-import-oracle_enhanced.gemspec
52
+ - lib/activerecord-import-oracle_enhanced.rb
53
+ - lib/activerecord-import-oracle_enhanced/version.rb
54
+ - lib/activerecord-import/active_record/adapters/oracle_enhanced_adapter.rb
55
+ - lib/activerecord-import/adapters/oracle_enhanced_adapter.rb
56
+ homepage: http://github.com/keeguon/activerecord-import-oracle_enhanced
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 1.9.2
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.6.12
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: Bulk insert extension for ActiveRecord and Oracle
80
+ test_files: []