activerecord-jdbc-alt-adapter 51.7.0-java → 52.2.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -3
- data/.travis.yml +24 -28
- data/Gemfile +2 -3
- data/README.md +27 -19
- data/Rakefile +4 -30
- data/activerecord-jdbc-adapter.gemspec +2 -2
- data/activerecord-jdbc-alt-adapter.gemspec +4 -4
- data/lib/arel/visitors/sqlserver.rb +2 -1
- data/lib/arjdbc/abstract/core.rb +12 -2
- data/lib/arjdbc/abstract/database_statements.rb +22 -8
- data/lib/arjdbc/abstract/statement_cache.rb +1 -0
- data/lib/arjdbc/db2/adapter.rb +77 -8
- data/lib/arjdbc/db2/as400.rb +12 -0
- data/lib/arjdbc/db2/column.rb +3 -0
- data/lib/arjdbc/db2/connection_methods.rb +4 -0
- data/lib/arjdbc/jdbc/adapter.rb +4 -6
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/column.rb +14 -6
- data/lib/arjdbc/jdbc.rb +7 -0
- data/lib/arjdbc/mssql/adapter.rb +20 -32
- data/lib/arjdbc/mssql/connection_methods.rb +1 -5
- data/lib/arjdbc/mssql/database_limits.rb +29 -0
- data/lib/arjdbc/mssql/database_statements.rb +41 -1
- data/lib/arjdbc/mssql/explain_support.rb +6 -1
- data/lib/arjdbc/mssql/quoting.rb +9 -2
- data/lib/arjdbc/mssql/schema_creation.rb +2 -1
- data/lib/arjdbc/mssql/schema_dumper.rb +1 -1
- data/lib/arjdbc/mssql/schema_statements.rb +11 -3
- data/lib/arjdbc/mssql/transaction.rb +3 -3
- data/lib/arjdbc/mssql.rb +1 -1
- data/lib/arjdbc/mysql/adapter.rb +20 -4
- data/lib/arjdbc/mysql/connection_methods.rb +7 -13
- data/lib/arjdbc/postgresql/adapter.rb +23 -20
- data/lib/arjdbc/postgresql/column.rb +3 -6
- data/lib/arjdbc/postgresql/connection_methods.rb +1 -3
- data/lib/arjdbc/postgresql/oid_types.rb +6 -11
- data/lib/arjdbc/sqlite3/adapter.rb +86 -91
- data/lib/arjdbc/sqlite3/connection_methods.rb +0 -1
- data/lib/arjdbc/tasks/database_tasks.rb +1 -0
- data/lib/arjdbc/tasks/sqlite_database_tasks_patch.rb +17 -0
- data/lib/arjdbc/version.rb +1 -1
- data/rakelib/01-tomcat.rake +2 -2
- data/rakelib/02-test.rake +2 -0
- data/rakelib/rails.rake +1 -1
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +10 -65
- data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +38 -282
- data/src/java/arjdbc/postgresql/PostgreSQLResult.java +69 -4
- data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +69 -13
- data/src/java/arjdbc/util/DateTimeUtils.java +17 -28
- data/src/java/arjdbc/util/PG.java +8 -0
- metadata +15 -12
- data/lib/activerecord-jdbc-alt-adapter.rb +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b4f2f45217c4f0c6288ef6375f304b68a243adfe3a436c06c101e24d50e1ec5
|
4
|
+
data.tar.gz: 2304823483354e2e1c2cd2d5eae14325e7980da104e0e3b717fd373daa8c01ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad807e645ff8175d8822ab5ffd32ca5f80a67d7a056987e15297611efeec5161a4dae42cc1a40dbcba71ae09df169c16f7f5c3591d0eb068bb8d8e7bf80385f3
|
7
|
+
data.tar.gz: c16e63f118c4a4609516e6f43c7bf0fcf17521bde1ab0e7587a500049863473f59eeeeca9d3c4882da38b546a8387338c8ffd1bc210bfd7b28aad595bc1e2f10
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,27 +1,18 @@
|
|
1
|
+
language: ruby
|
1
2
|
sudo: false
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
branches:
|
4
|
+
only:
|
5
|
+
- master
|
6
|
+
- /.*-stable$/
|
7
|
+
- /^test-.*/
|
8
|
+
- /maintenance|support/
|
9
|
+
- /.*dev$/
|
10
|
+
bundler_args: --without development
|
11
|
+
script: bundle exec rake ${TEST_PREFIX}test_$DB
|
9
12
|
before_install:
|
10
13
|
- unset _JAVA_OPTIONS
|
11
14
|
- rvm @default,@global do gem uninstall bundler -a -x -I || true
|
12
15
|
- gem install bundler -v "~>1.17.3"
|
13
|
-
install:
|
14
|
-
- bundle install --retry 3 --without development
|
15
|
-
# to fix this issue: https://travis-ci.community/t/mariadb-10-1-fails-to-install-on-xenial/3151/3
|
16
|
-
- mysql -u root -e 'CREATE USER IF NOT EXISTS travis@localhost; GRANT ALL ON *.* TO travis@localhost;' || true
|
17
|
-
|
18
|
-
language: ruby
|
19
|
-
rvm:
|
20
|
-
- jruby-9.1.16.0
|
21
|
-
jdk:
|
22
|
-
- openjdk8
|
23
|
-
|
24
|
-
script: bundle exec rake ${TEST_PREFIX}test_$DB
|
25
16
|
before_script:
|
26
17
|
- echo "JAVA_OPTS=$JAVA_OPTS"
|
27
18
|
- export JRUBY_OPTS="-J-Xms64M -J-Xmx1024M"
|
@@ -47,7 +38,12 @@ before_script:
|
|
47
38
|
psql -c "create database activerecord_unittest;" -U postgres && \
|
48
39
|
psql -c "create database activerecord_unittest2;" -U postgres \
|
49
40
|
|| true
|
50
|
-
|
41
|
+
rvm:
|
42
|
+
- jruby-9.1.16.0
|
43
|
+
jdk:
|
44
|
+
- openjdk8
|
45
|
+
addons:
|
46
|
+
postgresql: "9.4"
|
51
47
|
env:
|
52
48
|
- DB=mysql2 PREPARED_STATEMENTS=false
|
53
49
|
- DB=mysql2 PREPARED_STATEMENTS=true
|
@@ -90,15 +86,15 @@ matrix:
|
|
90
86
|
env: DB=sqlite3
|
91
87
|
# testing against MariaDB
|
92
88
|
- addons:
|
93
|
-
mariadb: 10.
|
89
|
+
mariadb: '10.0'
|
94
90
|
env: DB=mariadb PREPARED_STATEMENTS=false
|
95
91
|
- addons:
|
96
|
-
mariadb: 10.
|
92
|
+
mariadb: '10.1'
|
97
93
|
env: DB=mariadb PREPARED_STATEMENTS=true
|
98
94
|
# Rails test-suite :
|
99
|
-
- env: DB=mysql2 TEST_PREFIX="rails:" AR_VERSION="v5.
|
100
|
-
- env: DB=mysql2 TEST_PREFIX="rails:" AR_VERSION="v5.
|
101
|
-
- env: DB=mysql2 TEST_PREFIX="rails:" AR_VERSION="v5.
|
102
|
-
- env: DB=postgresql TEST_PREFIX="rails:" AR_VERSION="v5.
|
103
|
-
- env: DB=postgresql TEST_PREFIX="rails:" AR_VERSION="v5.
|
104
|
-
- env: DB=sqlite3 TEST_PREFIX="rails:" AR_VERSION="v5.
|
95
|
+
- env: DB=mysql2 TEST_PREFIX="rails:" AR_VERSION="v5.2.3" # PS off by default
|
96
|
+
- env: DB=mysql2 TEST_PREFIX="rails:" AR_VERSION="v5.2.3" PREPARED_STATEMENTS=true
|
97
|
+
- env: DB=mysql2 TEST_PREFIX="rails:" AR_VERSION="v5.2.3" DRIVER=MariaDB
|
98
|
+
- env: DB=postgresql TEST_PREFIX="rails:" AR_VERSION="v5.2.3" # PS on by default
|
99
|
+
- env: DB=postgresql TEST_PREFIX="rails:" AR_VERSION="v5.2.3" PREPARED_STATEMENTS=false
|
100
|
+
- env: DB=sqlite3 TEST_PREFIX="rails:" AR_VERSION="v5.2.3"
|
data/Gemfile
CHANGED
@@ -48,14 +48,13 @@ group :test do
|
|
48
48
|
gem 'mocha', '~> 1.2', require: false # Rails has '~> 0.14'
|
49
49
|
|
50
50
|
gem 'bcrypt', '~> 3.1.11', require: false
|
51
|
-
gem 'jdbc-mssql', '~> 0.
|
51
|
+
gem 'jdbc-mssql', '~> 0.6.0', require: nil
|
52
52
|
# gem 'pry-debugger-jruby', platform: :jruby
|
53
53
|
end
|
54
54
|
|
55
55
|
group :rails do
|
56
56
|
group :test do
|
57
|
-
|
58
|
-
gem 'minitest', '< 5.3.4', require: nil
|
57
|
+
gem 'minitest', '~> 5.11.3', require: nil
|
59
58
|
gem 'minitest-excludes', '~> 2.0.1', require: nil
|
60
59
|
gem 'minitest-rg', require: nil
|
61
60
|
|
data/README.md
CHANGED
@@ -6,13 +6,16 @@ supported by the original adapter such as PostgreSQL but it is advised to
|
|
6
6
|
use the [original adapter](https://github.com/jruby/active)
|
7
7
|
|
8
8
|
This adapter only works with JRuby and it is advised to install the latest
|
9
|
-
stable
|
9
|
+
stable versions of Rails
|
10
10
|
|
11
11
|
- For Rails `5.0.7.2` install the `50.3.1` version of this adapter
|
12
12
|
- For Rails `5.1.7` install the `51.3.0` version of this adapter
|
13
|
+
- For Rails `5.2.3` install the `52.2.0` version of this adapter
|
13
14
|
|
14
|
-
Support for Rails
|
15
|
+
Support for Rails 6.0 is planned in the future.
|
15
16
|
|
17
|
+
This adapter passes most of the Rails tests (ActiveRecord tests) with the
|
18
|
+
exception of some test that are not compatible with the SQL Server
|
16
19
|
|
17
20
|
### How to use it:
|
18
21
|
|
@@ -99,7 +102,7 @@ production:
|
|
99
102
|
```
|
100
103
|
|
101
104
|
|
102
|
-
###
|
105
|
+
### NOTE
|
103
106
|
|
104
107
|
Keep one eye in the Rails connection pool, we have not thoroughly tested that
|
105
108
|
part since we don't use the default Rails connection pool, other than that
|
@@ -114,20 +117,26 @@ this adapter should just work.
|
|
114
117
|
ActiveRecord-JDBC-Adapter (AR-JDBC) is the main database adapter for Rails'
|
115
118
|
*ActiveRecord* component that can be used with [JRuby][0].
|
116
119
|
ActiveRecord-JDBC-Adapter provides full or nearly full support for:
|
117
|
-
**MySQL**, **PostgreSQL**, **SQLite3
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
Version
|
130
|
-
|
120
|
+
**MySQL**, **PostgreSQL**, **SQLite3**. In the near future there are plans to
|
121
|
+
add support **MSSQL**. Unless we get more contributions we will not be going
|
122
|
+
beyond these four adapters. Note that the amount of work needed to get
|
123
|
+
another adapter is not huge but the amount of testing required to make sure
|
124
|
+
that adapter continues to work is not something we can do with the resources
|
125
|
+
we currently have.
|
126
|
+
|
127
|
+
For Oracle database users you are encouraged to use
|
128
|
+
https://github.com/rsim/oracle-enhanced.
|
129
|
+
|
130
|
+
Versions are targeted at certain versions of Rails and live on their own branches.
|
131
|
+
|
132
|
+
| Gem Version | Rails Version | Branch |
|
133
|
+
| ----------- | ------------- | ------ |
|
134
|
+
| 50.x | 5.0.x | 50-stable |
|
135
|
+
| 51.x | 5.1.x | 51-stable |
|
136
|
+
| 52.x | 5.2.x | 52-stable |
|
137
|
+
| future | latest | master |
|
138
|
+
|
139
|
+
The minimum version of JRuby for 50+ is JRuby **9.1.x** and
|
131
140
|
JRuby 9.1+ requires Java 7 or newer (we recommend Java 8 at minimum).
|
132
141
|
|
133
142
|
## Using ActiveRecord JDBC
|
@@ -142,7 +151,6 @@ adapters are available:
|
|
142
151
|
- MySQL (`activerecord-jdbcmysql-adapter`)
|
143
152
|
- PostgreSQL (`activerecord-jdbcpostgresql-adapter`)
|
144
153
|
- SQLite3 (`activerecord-jdbcsqlite3-adapter`)
|
145
|
-
- MSSQL (`activerecord-jdbcsqlserver-adapter`)
|
146
154
|
|
147
155
|
2. If you're generating a new Rails application, use the following command:
|
148
156
|
|
@@ -277,4 +285,4 @@ license the database's drivers are licensed. See each driver gem's LICENSE.txt.
|
|
277
285
|
[5]: https://github.com/jruby/activerecord-jdbc-adapter/wiki
|
278
286
|
[6]: https://webchat.freenode.net/?channels=#jruby
|
279
287
|
[7]: http://badge.fury.io/rb/activerecord-jdbc-adapter
|
280
|
-
[8]: https://github.com/jruby/activerecord-
|
288
|
+
[8]: https://github.com/jruby/activerecord-jdbc-adapter/wiki/Migrating-from-1.2.x-to-1.3.0
|
data/Rakefile
CHANGED
@@ -1,29 +1,3 @@
|
|
1
|
-
# Common usage
|
2
|
-
#
|
3
|
-
# rake build:adapters - to build all specific adapter gems and the base gem
|
4
|
-
# rake release:do - build:adapters + git tag + push gems
|
5
|
-
#
|
6
|
-
# Environment variables used by this Rakefile:
|
7
|
-
#
|
8
|
-
# INCLUDE_JAR_IN_GEM [default task - false, other taks - true]:
|
9
|
-
# Note: This is something you should not normally have to set.
|
10
|
-
# For local development we always will end up including the jar file
|
11
|
-
# in any task which generates our main gem. The wrinkle to this
|
12
|
-
# is when we do a custom github link in bundler:
|
13
|
-
#
|
14
|
-
# gem 'ar-jdbc', github: '...'
|
15
|
-
#
|
16
|
-
# Because we stopped committing a .jar file for every change and so when
|
17
|
-
# we include a gem like this it clones the repository and does a default
|
18
|
-
# build in rake. This in turn will end up forcing a compile to generate
|
19
|
-
# that jar (similar to how c-extensions compile at the time of install).
|
20
|
-
# For shipped gems we do include the jar so that people do not require
|
21
|
-
# this compile step.
|
22
|
-
#
|
23
|
-
# NOOP [release:do - false]
|
24
|
-
#
|
25
|
-
# No commands or gem pushing during a release.
|
26
|
-
|
27
1
|
require 'rake/clean'
|
28
2
|
|
29
3
|
CLEAN.include 'derby*', 'test.db.*', '*test.sqlite3', 'test/reports'
|
@@ -64,8 +38,7 @@ rake = lambda { |task| ruby "-S", "rake", task }
|
|
64
38
|
|
65
39
|
desc "Build #{gem_name} gem into the pkg directory."
|
66
40
|
task :build => :jar do
|
67
|
-
|
68
|
-
sh("INCLUDE_JAR_IN_GEM=#{include_jar} gem build -V '#{gemspec_path}'") do
|
41
|
+
sh("RELEASE=#{ENV['RELEASE']} gem build -V '#{gemspec_path}'") do
|
69
42
|
gem_path = built_gem_path.call
|
70
43
|
file_name = File.basename(gem_path)
|
71
44
|
FileUtils.mkdir_p(File.join(base_dir, 'pkg'))
|
@@ -85,6 +58,7 @@ end
|
|
85
58
|
|
86
59
|
desc "Releasing AR-JDBC gems (use NOOP=true to disable gem pushing)"
|
87
60
|
task 'release:do' do
|
61
|
+
ENV['RELEASE'] = 'true' # so that .gemspec is built with adapter_java.jar
|
88
62
|
Rake::Task['build'].invoke
|
89
63
|
# Rake::Task['build:adapters'].invoke
|
90
64
|
|
@@ -283,7 +257,7 @@ if defined? JRUBY_VERSION
|
|
283
257
|
begin
|
284
258
|
require 'arjdbc/version'
|
285
259
|
rescue LoadError
|
286
|
-
path = File.expand_path('lib', File.dirname(__FILE__))
|
260
|
+
path = File.expand_path('../lib', File.dirname(__FILE__))
|
287
261
|
unless $LOAD_PATH.include?(path)
|
288
262
|
$LOAD_PATH << path; retry
|
289
263
|
end
|
@@ -323,7 +297,7 @@ if defined? JRUBY_VERSION
|
|
323
297
|
# class_files.gsub!('$', '\$') unless windows?
|
324
298
|
# args = class_files.map { |path| [ "-C #{classes_dir}", path ] }.flatten
|
325
299
|
|
326
|
-
if ENV['
|
300
|
+
if ENV['RELEASE'] == 'true'; require 'tempfile'
|
327
301
|
manifest = "Built-Time: #{Time.now.utc.strftime('%Y-%m-%d %H:%M:%S')}\n"
|
328
302
|
manifest += "Built-JRuby: #{JRUBY_VERSION}\n"
|
329
303
|
manifest += "Specification-Title: ActiveRecord-JDBC\n"
|
@@ -27,7 +27,7 @@ Gem::Specification.new do |gem|
|
|
27
27
|
reject { |f| f =~ /^(gemfiles)/ } # no tests - no Gemfile_s appraised ...
|
28
28
|
gem.files += ['lib/arjdbc/jdbc/adapter_java.jar'] #if ENV['RELEASE'].eql?('true')
|
29
29
|
|
30
|
-
if ENV['
|
30
|
+
if ENV['RELEASE'] != 'true' # @see Rakefile
|
31
31
|
gem.extensions << 'Rakefile' # to support auto-building .jar with :git paths
|
32
32
|
|
33
33
|
#gem.add_runtime_dependency 'jar-dependencies', '~> 0.1' # development not enough!
|
@@ -44,7 +44,7 @@ Gem::Specification.new do |gem|
|
|
44
44
|
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
45
45
|
gem.test_files = gem.files.grep(%r{^test/})
|
46
46
|
|
47
|
-
gem.add_dependency 'activerecord', '~> 5.
|
47
|
+
gem.add_dependency 'activerecord', '~> 5.2.0'
|
48
48
|
|
49
49
|
#gem.add_development_dependency 'test-unit', '2.5.4'
|
50
50
|
#gem.add_development_dependency 'test-unit-context', '>= 0.3.0'
|
@@ -11,7 +11,7 @@ Gem::Specification.new do |gem|
|
|
11
11
|
gem.license = 'BSD-2-Clause'
|
12
12
|
gem.summary = 'ActiveRecord JDBC adapter, for use within JRuby on Rails and SQL Server'
|
13
13
|
gem.description = "" <<
|
14
|
-
"Fork of the ActiveRecord JDBC adapter with support for SQL Server
|
14
|
+
"Fork of the ActiveRecord JDBC adapter with support for SQL Server/Azure SQL, " <<
|
15
15
|
"for more information and help look at the README file in the github repository. " <<
|
16
16
|
"AR-JDBC is a database adapter for Rails' ActiveRecord component designed " <<
|
17
17
|
"to be used with JRuby built upon Java's JDBC API for database access. " <<
|
@@ -19,7 +19,7 @@ Gem::Specification.new do |gem|
|
|
19
19
|
"as well as adapters for popular databases such as Oracle, SQLServer, " <<
|
20
20
|
"DB2, FireBird and even Java (embed) databases: Derby, HSQLDB and H2. " <<
|
21
21
|
"It allows to connect to virtually any JDBC-compliant database with your " <<
|
22
|
-
"JRuby on Rails application.
|
22
|
+
"JRuby on Rails application."
|
23
23
|
|
24
24
|
gem.require_paths = ["lib"]
|
25
25
|
|
@@ -29,7 +29,7 @@ Gem::Specification.new do |gem|
|
|
29
29
|
reject { |f| f =~ /^(gemfiles)/ } # no tests - no Gemfile_s appraised ...
|
30
30
|
gem.files += ['lib/arjdbc/jdbc/adapter_java.jar'] #if ENV['RELEASE'].eql?('true')
|
31
31
|
|
32
|
-
if ENV['
|
32
|
+
if ENV['RELEASE'] != 'true' # @see Rakefile
|
33
33
|
gem.extensions << 'Rakefile' # to support auto-building .jar with :git paths
|
34
34
|
|
35
35
|
#gem.add_runtime_dependency 'jar-dependencies', '~> 0.1' # development not enough!
|
@@ -46,7 +46,7 @@ Gem::Specification.new do |gem|
|
|
46
46
|
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
47
47
|
gem.test_files = gem.files.grep(%r{^test/})
|
48
48
|
|
49
|
-
gem.add_dependency 'activerecord', '~> 5.
|
49
|
+
gem.add_dependency 'activerecord', '~> 5.2.0', '>= 5.2.3'
|
50
50
|
|
51
51
|
#gem.add_development_dependency 'test-unit', '2.5.4'
|
52
52
|
#gem.add_development_dependency 'test-unit-context', '>= 0.3.0'
|
@@ -18,7 +18,7 @@ module Arel
|
|
18
18
|
|
19
19
|
def visit_Arel_Nodes_BindParam o, collector
|
20
20
|
# collector.add_bind(o) { |i| "@#{i-1}" }
|
21
|
-
collector.add_bind(o) { |i| '?' }
|
21
|
+
collector.add_bind(o.value) { |i| '?' }
|
22
22
|
end
|
23
23
|
|
24
24
|
def visit_Arel_Nodes_Bin o, collector
|
@@ -212,6 +212,7 @@ module Arel
|
|
212
212
|
def primary_Key_From_Table t
|
213
213
|
return unless t
|
214
214
|
# column_name = schema_cache.primary_keys(t.name) || column_cache(t.name).first.try(:second).try(:name)
|
215
|
+
# NOTE: for table name aliases columns_hash('table_alias') requires to return an empty hash.
|
215
216
|
column_name = @connection.schema_cache.primary_keys(t.name) ||
|
216
217
|
@connection.schema_cache.columns_hash(t.name).first.try(:second).try(:name)
|
217
218
|
column_name ? t[column_name] : nil
|
data/lib/arjdbc/abstract/core.rb
CHANGED
@@ -56,7 +56,7 @@ module ArJdbc
|
|
56
56
|
case e
|
57
57
|
when SystemExit, SignalException, NoMemoryError then e
|
58
58
|
when ActiveModel::RangeError, TypeError, RuntimeError then e
|
59
|
-
else
|
59
|
+
else ActiveRecord::StatementInvalid.new(message)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
@@ -73,4 +73,14 @@ module ArJdbc
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
|
+
module LogSubscriber
|
78
|
+
JDBC_GEM_ROOT = File.expand_path("../../../..", __FILE__) + "/"
|
79
|
+
|
80
|
+
# Remove this gem from log trace so that query shows where it was called in application
|
81
|
+
def ignored_callstack(path)
|
82
|
+
super || path.start_with?(JDBC_GEM_ROOT)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
ActiveRecord::LogSubscriber.prepend(ArJdbc::LogSubscriber)
|
86
|
+
end
|
@@ -10,13 +10,11 @@ module ArJdbc
|
|
10
10
|
NO_BINDS = [].freeze
|
11
11
|
|
12
12
|
def exec_insert(sql, name = nil, binds = NO_BINDS, pk = nil, sequence_name = nil)
|
13
|
-
binds = convert_legacy_binds_to_attributes(binds) if binds.first.is_a?(Array)
|
14
|
-
|
15
13
|
if without_prepared_statement?(binds)
|
16
|
-
log(sql, name) { @connection.
|
14
|
+
log(sql, name) { @connection.execute_insert(sql) }
|
17
15
|
else
|
18
16
|
log(sql, name, binds) do
|
19
|
-
@connection.
|
17
|
+
@connection.execute_insert(sql, binds)
|
20
18
|
end
|
21
19
|
end
|
22
20
|
end
|
@@ -24,8 +22,6 @@ module ArJdbc
|
|
24
22
|
# It appears that at this point (AR 5.0) "prepare" should only ever be true
|
25
23
|
# if prepared statements are enabled
|
26
24
|
def exec_query(sql, name = nil, binds = NO_BINDS, prepare: false)
|
27
|
-
binds = convert_legacy_binds_to_attributes(binds) if binds.first.is_a?(Array)
|
28
|
-
|
29
25
|
if without_prepared_statement?(binds)
|
30
26
|
log(sql, name) { @connection.execute_query(sql) }
|
31
27
|
else
|
@@ -38,8 +34,6 @@ module ArJdbc
|
|
38
34
|
end
|
39
35
|
|
40
36
|
def exec_update(sql, name = nil, binds = NO_BINDS)
|
41
|
-
binds = convert_legacy_binds_to_attributes(binds) if binds.first.is_a?(Array)
|
42
|
-
|
43
37
|
if without_prepared_statement?(binds)
|
44
38
|
log(sql, name) { @connection.execute_update(sql) }
|
45
39
|
else
|
@@ -48,10 +42,30 @@ module ArJdbc
|
|
48
42
|
end
|
49
43
|
alias :exec_delete :exec_update
|
50
44
|
|
45
|
+
# overridden to support legacy binds
|
46
|
+
def insert(arel, name = nil, pk = nil, id_value = nil, sequence_name = nil, binds = [])
|
47
|
+
binds = convert_legacy_binds_to_attributes(binds) if binds.first.is_a?(Array)
|
48
|
+
super
|
49
|
+
end
|
50
|
+
alias create insert
|
51
|
+
|
52
|
+
# overridden to support legacy binds
|
53
|
+
def update(arel, name = nil, binds = [])
|
54
|
+
binds = convert_legacy_binds_to_attributes(binds) if binds.first.is_a?(Array)
|
55
|
+
super
|
56
|
+
end
|
57
|
+
|
58
|
+
# overridden to support legacy binds
|
59
|
+
def delete(arel, name = nil, binds = [])
|
60
|
+
binds = convert_legacy_binds_to_attributes(binds) if binds.first.is_a?(Array)
|
61
|
+
super
|
62
|
+
end
|
63
|
+
|
51
64
|
def execute(sql, name = nil)
|
52
65
|
log(sql, name) { @connection.execute(sql) }
|
53
66
|
end
|
54
67
|
|
68
|
+
# overridden to support legacy binds
|
55
69
|
def select_all(arel, name = nil, binds = NO_BINDS, preparable: nil)
|
56
70
|
binds = convert_legacy_binds_to_attributes(binds) if binds.first.is_a?(Array)
|
57
71
|
super
|
data/lib/arjdbc/db2/adapter.rb
CHANGED
@@ -30,6 +30,65 @@ module ArJdbc
|
|
30
30
|
# @note This adapter doesn't support explain `config.active_record.auto_explain_threshold_in_seconds` should be commented (Rails < 4.0)
|
31
31
|
module DB2
|
32
32
|
|
33
|
+
|
34
|
+
module ActiveRecord::ConnectionAdapters
|
35
|
+
|
36
|
+
remove_const(:DB2Adapter) if const_defined?(:DB2Adapter)
|
37
|
+
|
38
|
+
class DB2Adapter < JdbcAdapter
|
39
|
+
|
40
|
+
include ArJdbc::DB2
|
41
|
+
include ArJdbc::DB2::Column
|
42
|
+
|
43
|
+
# AR 5.2 Fix
|
44
|
+
def initialize(connection, logger = nil, connection_parameters = nil, config = {})
|
45
|
+
super(connection, logger, config) # configure_connection happens in super
|
46
|
+
end
|
47
|
+
|
48
|
+
def jdbc_connection_class(spec)
|
49
|
+
ArJdbc::DB2.jdbc_connection_class
|
50
|
+
end
|
51
|
+
|
52
|
+
def data_source_sql(name = nil, type: nil)
|
53
|
+
scope = quoted_scope(name, type: type)
|
54
|
+
|
55
|
+
sql = if scope[:type] == "'T'"
|
56
|
+
"select table_name from sysibm.tables".dup
|
57
|
+
else
|
58
|
+
"select table_name from sysibm.views".dup
|
59
|
+
end
|
60
|
+
|
61
|
+
wheres = []
|
62
|
+
|
63
|
+
wheres << " table_type = #{scope[:type]}" if scope[:type]
|
64
|
+
wheres << " table_schema = #{scope[:schema]}" if scope[:schema]
|
65
|
+
wheres << " UPPER(table_name) = UPPER(#{scope[:name]})" if scope[:name]
|
66
|
+
|
67
|
+
if wheres.present?
|
68
|
+
sql << ' WHERE '
|
69
|
+
sql << wheres.join(' AND ')
|
70
|
+
end
|
71
|
+
sql
|
72
|
+
end
|
73
|
+
|
74
|
+
def quoted_scope(name = nil, type: nil)
|
75
|
+
type = \
|
76
|
+
case type
|
77
|
+
when "BASE TABLE"
|
78
|
+
"'T'"
|
79
|
+
when "VIEW"
|
80
|
+
"'V'"
|
81
|
+
end
|
82
|
+
scope = {}
|
83
|
+
scope[:name] = quote(name) if name
|
84
|
+
scope[:type] = type if type
|
85
|
+
scope[:schema] = quote(scope[:schema] || schema)
|
86
|
+
scope
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
33
92
|
# @private
|
34
93
|
def self.extended(adapter); initialize!; end
|
35
94
|
|
@@ -269,6 +328,17 @@ module ArJdbc
|
|
269
328
|
select_one(sql).nil?
|
270
329
|
end
|
271
330
|
|
331
|
+
# @override
|
332
|
+
def primary_keys(table)
|
333
|
+
# If no schema in table name is given but present in URL parameter. Use the URL parameter one
|
334
|
+
# This avoids issues if the table is present in multiple schemas
|
335
|
+
if table.split(".").size == 1 && schema
|
336
|
+
table = "#{schema}.#{table}"
|
337
|
+
end
|
338
|
+
|
339
|
+
super
|
340
|
+
end
|
341
|
+
|
272
342
|
def next_sequence_value(sequence_name)
|
273
343
|
select_value("SELECT NEXT VALUE FOR #{sequence_name} FROM sysibm.sysdummy1")
|
274
344
|
end
|
@@ -378,9 +448,9 @@ module ArJdbc
|
|
378
448
|
types
|
379
449
|
end
|
380
450
|
|
381
|
-
def type_to_sql(type, limit
|
451
|
+
def type_to_sql(type, limit: nil, precision: nil, scale: nil, **)
|
382
452
|
limit = nil if type.to_sym == :integer
|
383
|
-
super
|
453
|
+
super
|
384
454
|
end
|
385
455
|
|
386
456
|
# @private
|
@@ -393,7 +463,7 @@ module ArJdbc
|
|
393
463
|
|
394
464
|
def add_column(table_name, column_name, type, options = {})
|
395
465
|
# The keyword COLUMN allows to use reserved names for columns (ex: date)
|
396
|
-
add_column_sql = "ALTER TABLE #{quote_table_name(table_name)} ADD COLUMN #{quote_column_name(column_name)} #{type_to_sql(type, options
|
466
|
+
add_column_sql = "ALTER TABLE #{quote_table_name(table_name)} ADD COLUMN #{quote_column_name(column_name)} #{type_to_sql(type, options)}"
|
397
467
|
add_column_options!(add_column_sql, options)
|
398
468
|
execute(add_column_sql)
|
399
469
|
end
|
@@ -536,7 +606,7 @@ module ArJdbc
|
|
536
606
|
end
|
537
607
|
|
538
608
|
def change_column(table_name, column_name, type, options = {})
|
539
|
-
data_type = type_to_sql(type, options
|
609
|
+
data_type = type_to_sql(type, options)
|
540
610
|
sql = "ALTER TABLE #{table_name} ALTER COLUMN #{column_name} SET DATA TYPE #{data_type}"
|
541
611
|
execute_table_change(sql, table_name, 'Change Column')
|
542
612
|
|
@@ -644,11 +714,10 @@ module ArJdbc
|
|
644
714
|
|
645
715
|
# alias_method :execute_and_auto_confirm, :execute
|
646
716
|
|
647
|
-
# Returns the value of an identity column of the last *INSERT* statement
|
648
|
-
# made over this connection.
|
717
|
+
# Returns the value of an identity column of the last *INSERT* statement made over this connection.
|
649
718
|
# @note Check the *IDENTITY_VAL_LOCAL* function for documentation.
|
650
|
-
# @return [
|
651
|
-
def
|
719
|
+
# @return [Integer, NilClass]
|
720
|
+
def last_inserted_id(result)
|
652
721
|
@connection.identity_val_local
|
653
722
|
end
|
654
723
|
|
data/lib/arjdbc/db2/as400.rb
CHANGED
@@ -4,6 +4,18 @@ module ArJdbc
|
|
4
4
|
module AS400
|
5
5
|
include DB2
|
6
6
|
|
7
|
+
module ActiveRecord::ConnectionAdapters
|
8
|
+
remove_const(:AS400Adapter) if const_defined?(:AS400Adapter)
|
9
|
+
class AS400Adapter < DB2Adapter
|
10
|
+
|
11
|
+
include ::ArJdbc::AS400
|
12
|
+
|
13
|
+
def jdbc_connection_class(spec)
|
14
|
+
ArJdbc::AS400.jdbc_connection_class
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
7
19
|
# @private
|
8
20
|
def self.extended(adapter); DB2.extended(adapter); end
|
9
21
|
|
data/lib/arjdbc/db2/column.rb
CHANGED
@@ -15,6 +15,8 @@ ArJdbc::ConnectionMethods.module_eval do
|
|
15
15
|
end
|
16
16
|
config[:driver] ||= ::ArJdbc::DB2::DRIVER_NAME
|
17
17
|
config[:connection_alive_sql] ||= 'SELECT 1 FROM syscat.tables FETCH FIRST 1 ROWS ONLY'
|
18
|
+
config[:adapter_class] = ActiveRecord::ConnectionAdapters::DB2Adapter unless config.key?(:adapter_class)
|
19
|
+
|
18
20
|
jdbc_connection(config)
|
19
21
|
end
|
20
22
|
alias_method :jdbcdb2_connection, :db2_connection
|
@@ -38,6 +40,8 @@ ArJdbc::ConnectionMethods.module_eval do
|
|
38
40
|
require 'arjdbc/db2/as400'
|
39
41
|
config[:driver] ||= ::ArJdbc::AS400::DRIVER_NAME
|
40
42
|
config[:connection_alive_sql] ||= 'SELECT 1 FROM sysibm.tables FETCH FIRST 1 ROWS ONLY'
|
43
|
+
config[:adapter_class] = ActiveRecord::ConnectionAdapters::AS400Adapter unless config.key?(:adapter_class)
|
44
|
+
|
41
45
|
jdbc_connection(config)
|
42
46
|
end
|
43
47
|
alias_method :jdbcas400_connection, :as400_connection
|
data/lib/arjdbc/jdbc/adapter.rb
CHANGED
@@ -250,12 +250,6 @@ module ActiveRecord
|
|
250
250
|
end
|
251
251
|
end
|
252
252
|
|
253
|
-
# @private
|
254
|
-
# @override
|
255
|
-
def select_rows(sql, name = nil, binds = [])
|
256
|
-
exec_query_raw(sql, name, binds).map!(&:values)
|
257
|
-
end
|
258
|
-
|
259
253
|
# Executes the SQL statement in the context of this connection.
|
260
254
|
# The return value from this method depends on the SQL type (whether
|
261
255
|
# it's a SELECT, INSERT etc.). For INSERTs a generated id might get
|
@@ -364,6 +358,10 @@ module ActiveRecord
|
|
364
358
|
# @return [Integer, NilClass]
|
365
359
|
def last_inserted_id(result)
|
366
360
|
if result.is_a?(Hash) || result.is_a?(ActiveRecord::Result)
|
361
|
+
# If table does not have primary key defined
|
362
|
+
return nil if result.first.blank?
|
363
|
+
|
364
|
+
|
367
365
|
result.first.first[1] # .first = { "id"=>1 } .first = [ "id", 1 ]
|
368
366
|
else
|
369
367
|
result
|
Binary file
|