activerecord-jdbc-alt-adapter 52.5.1-java → 60.2.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.nvimlog +0 -0
  4. data/.travis.yml +61 -37
  5. data/Gemfile +10 -3
  6. data/README.md +44 -28
  7. data/Rakefile +1 -1
  8. data/Rakefile.jdbc +8 -1
  9. data/activerecord-jdbc-adapter.gemspec +5 -8
  10. data/activerecord-jdbc-alt-adapter.gemspec +5 -8
  11. data/lib/arel/visitors/sqlserver.rb +33 -23
  12. data/lib/arjdbc/abstract/connection_management.rb +7 -0
  13. data/lib/arjdbc/abstract/core.rb +16 -23
  14. data/lib/arjdbc/abstract/database_statements.rb +24 -0
  15. data/lib/arjdbc/abstract/statement_cache.rb +2 -5
  16. data/lib/arjdbc/abstract/transaction_support.rb +5 -3
  17. data/lib/arjdbc/db2/column.rb +0 -39
  18. data/lib/arjdbc/derby/adapter.rb +1 -20
  19. data/lib/arjdbc/firebird/adapter.rb +0 -21
  20. data/lib/arjdbc/h2/adapter.rb +0 -15
  21. data/lib/arjdbc/hsqldb/adapter.rb +0 -14
  22. data/lib/arjdbc/informix/adapter.rb +0 -23
  23. data/lib/arjdbc/jdbc/adapter.rb +3 -1
  24. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  25. data/lib/arjdbc/jdbc/adapter_require.rb +3 -1
  26. data/lib/arjdbc/jdbc/base_ext.rb +3 -1
  27. data/lib/arjdbc/jdbc/callbacks.rb +2 -0
  28. data/lib/arjdbc/jdbc/column.rb +2 -0
  29. data/lib/arjdbc/jdbc/connection.rb +2 -0
  30. data/lib/arjdbc/jdbc/connection_methods.rb +2 -0
  31. data/lib/arjdbc/jdbc/error.rb +2 -0
  32. data/lib/arjdbc/jdbc/extension.rb +2 -0
  33. data/lib/arjdbc/jdbc/java.rb +3 -1
  34. data/lib/arjdbc/jdbc/railtie.rb +3 -1
  35. data/lib/arjdbc/jdbc/rake_tasks.rb +3 -1
  36. data/lib/arjdbc/jdbc/serialized_attributes_helper.rb +3 -1
  37. data/lib/arjdbc/jdbc/type_cast.rb +2 -0
  38. data/lib/arjdbc/jdbc/type_converter.rb +2 -0
  39. data/lib/arjdbc/mssql/adapter.rb +105 -36
  40. data/lib/arjdbc/mssql/column.rb +5 -1
  41. data/lib/arjdbc/mssql/connection_methods.rb +8 -2
  42. data/lib/arjdbc/mssql/database_limits.rb +2 -0
  43. data/lib/arjdbc/mssql/database_statements.rb +43 -5
  44. data/lib/arjdbc/mssql/errors.rb +2 -0
  45. data/lib/arjdbc/mssql/explain_support.rb +3 -1
  46. data/lib/arjdbc/mssql/extensions/attribute_methods.rb +5 -1
  47. data/lib/arjdbc/mssql/extensions/calculations.rb +2 -0
  48. data/lib/arjdbc/mssql/quoting.rb +38 -0
  49. data/lib/arjdbc/mssql/schema_creation.rb +24 -2
  50. data/lib/arjdbc/mssql/schema_definitions.rb +10 -0
  51. data/lib/arjdbc/mssql/schema_dumper.rb +2 -0
  52. data/lib/arjdbc/mssql/schema_statements.rb +63 -21
  53. data/lib/arjdbc/mssql/transaction.rb +2 -0
  54. data/lib/arjdbc/mssql/types/binary_types.rb +2 -0
  55. data/lib/arjdbc/mssql/types/date_and_time_types.rb +2 -0
  56. data/lib/arjdbc/mssql/types/deprecated_types.rb +2 -0
  57. data/lib/arjdbc/mssql/types/numeric_types.rb +2 -0
  58. data/lib/arjdbc/mssql/types/string_types.rb +2 -0
  59. data/lib/arjdbc/mssql/types.rb +2 -0
  60. data/lib/arjdbc/mssql/utils.rb +2 -0
  61. data/lib/arjdbc/mssql.rb +3 -1
  62. data/lib/arjdbc/mysql/adapter.rb +47 -18
  63. data/lib/arjdbc/postgresql/adapter.rb +240 -214
  64. data/lib/arjdbc/postgresql/base/array_decoder.rb +2 -0
  65. data/lib/arjdbc/postgresql/base/array_encoder.rb +4 -2
  66. data/lib/arjdbc/postgresql/base/array_parser.rb +4 -2
  67. data/lib/arjdbc/postgresql/base/pgconn.rb +2 -0
  68. data/lib/arjdbc/postgresql/column.rb +6 -4
  69. data/lib/arjdbc/postgresql/name.rb +2 -0
  70. data/lib/arjdbc/postgresql/oid_types.rb +3 -1
  71. data/lib/arjdbc/sqlite3/adapter.rb +188 -180
  72. data/lib/arjdbc/sqlite3/connection_methods.rb +15 -4
  73. data/lib/arjdbc/tasks/databases.rake +13 -10
  74. data/lib/arjdbc/tasks/mssql_database_tasks.rb +49 -5
  75. data/lib/arjdbc/util/quoted_cache.rb +3 -1
  76. data/lib/arjdbc/util/serialized_attributes.rb +3 -1
  77. data/lib/arjdbc/util/table_copier.rb +3 -1
  78. data/lib/arjdbc/version.rb +1 -1
  79. data/pom.xml +4 -4
  80. data/rakelib/01-tomcat.rake +2 -2
  81. data/src/java/arjdbc/ArJdbcModule.java +5 -5
  82. data/src/java/arjdbc/jdbc/DriverWrapper.java +1 -9
  83. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +406 -629
  84. data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +88 -0
  85. data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +13 -23
  86. data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +56 -30
  87. data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +94 -99
  88. data/src/java/arjdbc/util/DateTimeUtils.java +12 -4
  89. metadata +7 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: af6cc4c4563f32b39f0ddac72fbfa090de13e23eefba9a95c14221787478f132
4
- data.tar.gz: cc6754a427170292ebee5a56201bef82a3dd10cbf2034aff2e8e9d8b52575243
3
+ metadata.gz: 6ba45dfdd067960db619e03cb0bc979ad3d932d78f632748bd4b7c48f9fb8ca1
4
+ data.tar.gz: 3b5defceb44cc698b7cc9cd965e3cb30531c396b1212c5bc37753ed9625a3505
5
5
  SHA512:
6
- metadata.gz: 91fff9a0aabfb206c84759e0370d92a9e843bc8b6271d38adde65292b534052a4bcc20b1a9d454ea40b28feef2b453f7b1c1a0aac12ae4c06625d71ac72164e0
7
- data.tar.gz: e66da4371d5fc890788b6cfb3c7c483e7e7f7c706aba84195495b97ae3d5438353fefef852a4aee24bca044d6b3c75315f32f1f68f194cdbd299bb92ff3fc27c
6
+ metadata.gz: 52f1292397f116ed23a55cfbd44baa445f1096f01f64a1500fa3b44e2fa701e3c14fd6d2076e4aa332bbabd764e6a917dcd7931fbc6284050460dcbfe2d863b8
7
+ data.tar.gz: 7d175792f1eebee0f393d998451bd5966cd55626532527d6cfb58fcf6a98fd2081a72dc78f2438e14446bd6b10efdfa5c8b02fa083af9a780e8f22f629dc04a6
data/.gitignore CHANGED
@@ -34,3 +34,5 @@ activerecord-jdbc.iml
34
34
  lib/arjdbc/jdbc/adapter_java.jar
35
35
  .jrubyrc
36
36
  tags
37
+ pik.sh
38
+ .ruby-version
data/.nvimlog ADDED
File without changes
data/.travis.yml CHANGED
@@ -3,8 +3,6 @@ dist: xenial
3
3
 
4
4
  services:
5
5
  - mysql
6
- addons:
7
- postgresql: 9.4
8
6
 
9
7
  before_install:
10
8
  - unset _JAVA_OPTIONS
@@ -17,7 +15,7 @@ install:
17
15
 
18
16
  language: ruby
19
17
  rvm:
20
- - jruby-9.1.16.0
18
+ - jruby-9.2.7.0
21
19
  jdk:
22
20
  - openjdk8
23
21
 
@@ -49,45 +47,61 @@ before_script:
49
47
  || true
50
48
 
51
49
  env:
52
- - DB=mysql2 PREPARED_STATEMENTS=false
53
- - DB=mysql2 PREPARED_STATEMENTS=true
54
- - DB=mysql2 DRIVER=MariaDB
55
- - DB=postgresql PREPARED_STATEMENTS=false INSERT_RETURNING=false
56
- - DB=postgresql PREPARED_STATEMENTS=false INSERT_RETURNING=true
57
- - DB=postgresql PREPARED_STATEMENTS=true
58
- - DB=postgresql PREPARED_STATEMENTS=true INSERT_RETURNING=true
59
- - DB=sqlite3 PREPARED_STATEMENTS=false
60
- - DB=sqlite3 PREPARED_STATEMENTS=true
61
- - DB=jndi PREPARED_STATEMENTS=false
62
- - DB=jndi PREPARED_STATEMENTS=true
50
+ global:
51
+ - AR_VERSION="6-0-stable"
63
52
  matrix:
64
53
  allow_failures:
65
54
  - rvm: jruby-head
66
55
  include:
67
- # jruby-9.2
68
- - rvm: jruby-9.2.6.0
69
- env: DB=mysql2
70
- - rvm: jruby-9.2.6.0
71
- env: DB=postgresql
72
- - rvm: jruby-9.2.6.0
73
- env: DB=sqlite3
74
- # jruby-9.2 + Java 11
75
- - rvm: jruby-9.2.6.0
76
- env: DB=mysql2
77
- jdk: openjdk11
78
- - rvm: jruby-9.2.6.0
79
- env: DB=postgresql
80
- jdk: openjdk11
81
- - rvm: jruby-9.2.6.0
82
- env: DB=sqlite3
83
- jdk: openjdk11
56
+ - env: DB=mysql2 PREPARED_STATEMENTS=false
57
+ - env: DB=mysql2 PREPARED_STATEMENTS=true
58
+ - env: DB=mysql2 DRIVER=MariaDB
59
+
60
+ - addons:
61
+ postgresql: "10"
62
+ env: DB=postgresql PREPARED_STATEMENTS=false INSERT_RETURNING=false
63
+ - addons:
64
+ postgresql: "10"
65
+ env: DB=postgresql PREPARED_STATEMENTS=false INSERT_RETURNING=true
66
+ - addons:
67
+ postgresql: "10"
68
+ env: DB=postgresql PREPARED_STATEMENTS=true
69
+ - addons:
70
+ postgresql: "10"
71
+ env: DB=postgresql PREPARED_STATEMENTS=true INSERT_RETURNING=true
72
+ - addons:
73
+ postgresql: "10"
74
+ env: DB=postgresql PREPARED_STATEMENTS=true JRUBY_OPTS=-J-Duser.timezone=America/Detroit
75
+ - addons:
76
+ postgresql: "9.4"
77
+ env: DB=postgresql PREPARED_STATEMENTS=true
78
+
79
+ - env: DB=sqlite3 PREPARED_STATEMENTS=false
80
+ - env: DB=sqlite3 PREPARED_STATEMENTS=true
81
+
82
+ - env: DB=jndi PREPARED_STATEMENTS=false
83
+ - env: DB=jndi PREPARED_STATEMENTS=true
84
+
85
+ # Java 11
86
+ - env: DB=mysql2
87
+ jdk: oraclejdk11
88
+ - env: DB=postgresql
89
+ jdk: oraclejdk11
90
+ addons:
91
+ postgresql: "10"
92
+ - env: DB=sqlite3
93
+ jdk: oraclejdk11
94
+
84
95
  # jruby-head
85
96
  - rvm: jruby-head
86
97
  env: DB=mysql2
87
98
  - rvm: jruby-head
88
99
  env: DB=postgresql
100
+ addons:
101
+ postgresql: "10"
89
102
  - rvm: jruby-head
90
103
  env: DB=sqlite3
104
+
91
105
  # testing against MariaDB
92
106
  - addons:
93
107
  mariadb: 10.2
@@ -95,10 +109,20 @@ matrix:
95
109
  - addons:
96
110
  mariadb: 10.3
97
111
  env: DB=mariadb PREPARED_STATEMENTS=true
112
+
98
113
  # Rails test-suite :
99
- - env: DB=mysql2 TEST_PREFIX="rails:" AR_VERSION="v5.2.3" # PS off by default
100
- - env: DB=mysql2 TEST_PREFIX="rails:" AR_VERSION="v5.2.3" PREPARED_STATEMENTS=true
101
- - env: DB=mysql2 TEST_PREFIX="rails:" AR_VERSION="v5.2.3" DRIVER=MariaDB
102
- - env: DB=postgresql TEST_PREFIX="rails:" AR_VERSION="v5.2.3" # PS on by default
103
- - env: DB=postgresql TEST_PREFIX="rails:" AR_VERSION="v5.2.3" PREPARED_STATEMENTS=false
104
- - env: DB=sqlite3 TEST_PREFIX="rails:" AR_VERSION="v5.2.3"
114
+ - env: DB=mysql2 TEST_PREFIX="rails:" AR_VERSION="6-0-stable" # PS off by default
115
+ - env: DB=mysql2 TEST_PREFIX="rails:" AR_VERSION="6-0-stable" PREPARED_STATEMENTS=true
116
+ - env: DB=mysql2 TEST_PREFIX="rails:" AR_VERSION="6-0-stable" DRIVER=MariaDB
117
+
118
+ - addons:
119
+ postgresql: "10"
120
+ env: DB=postgresql TEST_PREFIX="rails:" AR_VERSION="6-0-stable" # PS on by default
121
+ - addons:
122
+ postgresql: "10"
123
+ env: DB=postgresql TEST_PREFIX="rails:" AR_VERSION="6-0-stable" PREPARED_STATEMENTS=false
124
+ - addons:
125
+ postgresql: "9.4"
126
+ env: DB=postgresql TEST_PREFIX="rails:" AR_VERSION="6-0-stable" # PS on by default
127
+
128
+ - env: DB=sqlite3 TEST_PREFIX="rails:" AR_VERSION="6-0-stable"
data/Gemfile CHANGED
@@ -10,10 +10,15 @@ if ENV['RAILS'] # Use local clone of Rails
10
10
 
11
11
  activemodel_dir = ::File.join(rails_dir, 'activemodel')
12
12
  activesupport_dir = ::File.join(rails_dir, 'activesupport')
13
-
13
+ actionpack_dir = ::File.join(rails_dir, 'actionpack')
14
+ actionview_dir = ::File.join(rails_dir, 'actionview')
15
+
14
16
  gem 'activerecord', require: false, path: activerecord_dir
15
17
  gem 'activemodel', require: false, path: activemodel_dir
16
18
  gem 'activesupport', require: false, path: activesupport_dir
19
+ gem 'actionpack', require: false, path: actionpack_dir
20
+ gem 'actionview', require: false, path: actionview_dir
21
+
17
22
  elsif ENV['AR_VERSION'] # Use specific version of AR and not .gemspec version
18
23
  version = ENV['AR_VERSION']
19
24
 
@@ -28,11 +33,13 @@ elsif ENV['AR_VERSION'] # Use specific version of AR and not .gemspec version
28
33
  else # branch
29
34
  opts = {branch: version}
30
35
  end
31
-
36
+
32
37
  git 'https://github.com/rails/rails.git', **opts do
33
38
  gem 'activerecord', require: false
34
39
  gem 'activemodel', require: false
35
40
  gem 'activesupport', require: false
41
+ gem 'actionpack', require: false
42
+ gem 'actionview', require: false
36
43
  end
37
44
  end
38
45
  end
@@ -48,7 +55,7 @@ group :test do
48
55
  gem 'mocha', '~> 1.2', require: false # Rails has '~> 0.14'
49
56
 
50
57
  gem 'bcrypt', '~> 3.1.11', require: false
51
- gem 'jdbc-mssql', '~> 0.7.0', require: nil
58
+ gem 'jdbc-mssql', '~> 0.9.0', require: nil
52
59
  # gem 'pry-debugger-jruby', platform: :jruby
53
60
  end
54
61
 
data/README.md CHANGED
@@ -6,16 +6,20 @@ 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 versions of Rails
9
+ stable of this adapter and Rails
10
10
 
11
- - For Rails `5.0.7.2` install the `50.3.1` version of this adapter
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
14
-
15
- Support for Rails 6.0 is planned in the future.
11
+ | Gem Version | Rails Version | min JRuby |
12
+ | ----------- | ------------- | --------- |
13
+ | 50.7.0 | 5.0.7 | 9.1.x |
14
+ | 51.7.0 | 5.1.7 | 9.1.x |
15
+ | 52.6.0 | 5.2.4 | 9.1.x |
16
+ | 60.1.0 | 6.0.3 | 9.2.9 |
16
17
 
17
18
  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
19
+ exception of some test that are not compatible with the SQL Server. To run
20
+ the test use the following fork [Rails](https://github.com/JesseChavez/rails/tree/6-0-stable-dev),
21
+ and the instructions in file `RUNNING_TESTS.md`. The fork has some
22
+ schema tweaks to make it compatible with SQL Server.
19
23
 
20
24
  ### How to use it:
21
25
 
@@ -24,13 +28,17 @@ Add the following to your `Gemfile`:
24
28
  ```ruby
25
29
  platforms :jruby do
26
30
  # Use jdbc as the database for Active Record
27
- gem 'activerecord-jdbc-alt-adapter', '~> 50.3.1', require: 'arjdbc'
28
- gem 'jdbc-mssql', '~> 0.6.0'
31
+ gem 'activerecord-jdbc-alt-adapter', '~> 60.1.0'
32
+ gem 'jdbc-mssql', '~> 0.9.0'
29
33
  end
30
34
  ```
31
35
 
32
- Or look at the sample rails 5.0 app [wombat](https://github.com/JesseChavez/wombat50)
33
- and see how is set up.
36
+ Or look at the sample rails and see how is set up:
37
+
38
+ - Rails 6.0 sample app [wombat60](https://github.com/JesseChavez/wombat60)
39
+
40
+ - Old rails 5.0 app [wombat50](https://github.com/JesseChavez/wombat50)
41
+
34
42
 
35
43
  ### Breaking changes
36
44
 
@@ -102,14 +110,6 @@ production:
102
110
  ```
103
111
 
104
112
 
105
- ### NOTE
106
-
107
- Keep one eye in the Rails connection pool, we have not thoroughly tested that
108
- part since we don't use the default Rails connection pool, other than that
109
- this adapter should just work.
110
-
111
-
112
-
113
113
  # ActiveRecord JDBC Adapter
114
114
 
115
115
  [![Gem Version](https://badge.fury.io/rb/activerecord-jdbc-adapter.svg)][7]
@@ -130,15 +130,15 @@ is not something we can do with the resources we currently have.
130
130
 
131
131
  Versions are targeted at certain versions of Rails and live on their own branches.
132
132
 
133
- | Gem Version | Rails Version | Branch |
134
- | ----------- | ------------- | ------ |
135
- | 50.x | 5.0.x | 50-stable |
136
- | 51.x | 5.1.x | 51-stable |
137
- | 52.x | 5.2.x | 52-stable |
138
- | future | latest | master |
133
+ | Gem Version | Rails Version | Branch | min JRuby | min Java |
134
+ | ----------- | ------------- | --------- | --------- | -------- |
135
+ | 50.x | 5.0.x | 50-stable | 9.1.x | 7 |
136
+ | 51.x | 5.1.x | 51-stable | 9.1.x | 7 |
137
+ | 52.x | 5.2.x | 52-stable | 9.1.x | 7 |
138
+ | 60.x | 6.0.x | master | 9.2.7 | 8 |
139
139
 
140
- The minimum version of JRuby for 50+ is JRuby **9.1.x** and
141
- JRuby 9.1+ requires Java 7 or newer (we recommend Java 8 at minimum).
140
+ Note that JRuby 9.1.x is end-of-life. We recommend Java 8 at a minimum for all
141
+ versions.
142
142
 
143
143
  ## Using ActiveRecord JDBC
144
144
 
@@ -195,6 +195,21 @@ production:
195
195
  connectTimeout: 60000
196
196
  ```
197
197
 
198
+ #### MySQL specific notes
199
+
200
+ Depending on the MySQL server configuration, it might be required to set
201
+ additional connection properties for date/time support to work correctly. If you
202
+ encounter problems, try adding this to your database configuration:
203
+
204
+ ```yml
205
+ properties:
206
+ serverTimezone: <%= java.util.TimeZone.getDefault.getID %>
207
+ ```
208
+
209
+ The correct timezone depends on the system setup, but the one shown is a good
210
+ place to start and is actually the correct setting for many systems.
211
+
212
+
198
213
  ### Standalone with ActiveRecord
199
214
 
200
215
  Once the setup is made (see below) you can establish a JDBC connection like this
@@ -269,7 +284,8 @@ ask on the #JRuby IRC channel on http://freenode.net/ (try [web-chat][6]).
269
284
  This project was originally written by [Nick Sieger](http://github.com/nicksieger)
270
285
  and [Ola Bini](http://github.com/olabini) with lots of help from the JRuby community.
271
286
  Polished 3.x compatibility and 4.x support (for AR-JDBC >= 1.3.0) was managed by
272
- [Karol Bucek](http://github.com/kares) among others.
287
+ [Karol Bucek](http://github.com/kares) among others. Support for Rails 6 was
288
+ contributed by [shellyBits GmbH](https://shellybits.ch/)
273
289
 
274
290
  ## License
275
291
 
data/Rakefile CHANGED
@@ -185,7 +185,7 @@ if defined? JRUBY_VERSION
185
185
  #directory classes = 'pkg/classes'; CLEAN << classes
186
186
 
187
187
  file jar_file => FileList[ 'src/java/**/*.java' ] do
188
- source = target = '1.7'; debug = true
188
+ source = target = '1.8'; debug = true
189
189
 
190
190
  get_driver_jars_local = lambda do |*args|
191
191
  driver_deps = args.empty? ? [ :Postgres, :MySQL ] : args
data/Rakefile.jdbc CHANGED
@@ -17,4 +17,11 @@ desc "Build and install #{name}-#{version} gem into system gems"
17
17
  task('install') { gem_helper.install_gem }
18
18
 
19
19
  desc "Create tag #{version_tag} build and push #{name}-#{version} gem to Rubygems"
20
- task('release') { gem_helper.release_gem }
20
+ task('release') do
21
+ gem_helper.instance_eval do
22
+ guard_clean
23
+ built_gem_path = build_gem
24
+ tag_version unless already_tagged?
25
+ rubygem_push(built_gem_path) if gem_push?
26
+ end
27
+ end
@@ -11,13 +11,10 @@ Gem::Specification.new do |gem|
11
11
  gem.license = 'BSD-2-Clause'
12
12
  gem.summary = 'JDBC adapter for ActiveRecord, for use within JRuby on Rails.'
13
13
  gem.description = "" <<
14
- "AR-JDBC is a database adapter for Rails' ActiveRecord component designed " <<
15
- "to be used with JRuby built upon Java's JDBC API for database access. " <<
16
- "Provides (ActiveRecord) built-in adapters: MySQL, PostgreSQL and SQLite3 " <<
17
- "as well as adapters for popular databases such as Oracle, SQLServer, " <<
18
- "DB2, FireBird and even Java (embed) databases: Derby, HSQLDB and H2. " <<
19
- "It allows to connect to virtually any JDBC-compliant database with your " <<
20
- "JRuby on Rails application."
14
+ "AR-JDBC is a database adapter for Rails' ActiveRecord component " <<
15
+ "designed to be used with JRuby built upon Java's JDBC API for " <<
16
+ "database access. Provides (ActiveRecord) built-in adapters: MySQL, " <<
17
+ "PostgreSQL, SQLite3, and SQLServer."
21
18
 
22
19
  gem.require_paths = ["lib"]
23
20
 
@@ -44,7 +41,7 @@ Gem::Specification.new do |gem|
44
41
  gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
45
42
  gem.test_files = gem.files.grep(%r{^test/})
46
43
 
47
- gem.add_dependency 'activerecord', '~> 5.2.0'
44
+ gem.add_dependency 'activerecord', '~> 6.0.0'
48
45
 
49
46
  #gem.add_development_dependency 'test-unit', '2.5.4'
50
47
  #gem.add_development_dependency 'test-unit-context', '>= 0.3.0'
@@ -13,13 +13,10 @@ Gem::Specification.new do |gem|
13
13
  gem.description = "" <<
14
14
  "Fork of the ActiveRecord JDBC adapter with support for SQL Server and Azure SQL, " <<
15
15
  "for more information and help look at the README file in the github repository. " <<
16
- "AR-JDBC is a database adapter for Rails' ActiveRecord component designed " <<
17
- "to be used with JRuby built upon Java's JDBC API for database access. " <<
18
- "Provides (ActiveRecord) built-in adapters: MySQL, PostgreSQL and SQLite3 " <<
19
- "as well as adapters for popular databases such as Oracle, SQLServer, " <<
20
- "DB2, FireBird and even Java (embed) databases: Derby, HSQLDB and H2. " <<
21
- "It allows to connect to virtually any JDBC-compliant database with your " <<
22
- "JRuby on Rails application."
16
+ "AR-JDBC is a database adapter for Rails' ActiveRecord component " <<
17
+ "designed to be used with JRuby built upon Java's JDBC API for " <<
18
+ "database access. Provides (ActiveRecord) built-in adapters: MySQL, " <<
19
+ "PostgreSQL, SQLite3, and SQLServer."
23
20
 
24
21
  gem.require_paths = ["lib"]
25
22
 
@@ -46,7 +43,7 @@ Gem::Specification.new do |gem|
46
43
  gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
47
44
  gem.test_files = gem.files.grep(%r{^test/})
48
45
 
49
- gem.add_dependency 'activerecord', '~> 5.2.0', '>= 5.2.3'
46
+ gem.add_dependency 'activerecord', '~> 6.0.0'
50
47
 
51
48
  #gem.add_development_dependency 'test-unit', '2.5.4'
52
49
  #gem.add_development_dependency 'test-unit-context', '>= 0.3.0'
@@ -4,13 +4,8 @@
4
4
  module Arel
5
5
  module Visitors
6
6
  class SQLServer < Arel::Visitors::ToSql
7
-
8
- OFFSET = " OFFSET "
9
- ROWS = " ROWS"
10
- FETCH = " FETCH NEXT "
11
- FETCH0 = " FETCH FIRST (SELECT 0) "
12
- ROWS_ONLY = " ROWS ONLY"
13
-
7
+ # 'FETCH FIRST' or 'FETCH NEXT' do the same thing
8
+ # The SQL ANSI Standard says NEXT and FIRST are synonyms
14
9
 
15
10
  private
16
11
 
@@ -35,24 +30,24 @@ module Arel
35
30
 
36
31
  def visit_Arel_Nodes_Lock o, collector
37
32
  o.expr = Arel.sql('WITH(UPDLOCK)') if o.expr.to_s =~ /FOR UPDATE/
38
- collector << SPACE
33
+ collector << ' '
39
34
  visit o.expr, collector
40
35
  end
41
36
 
42
37
  def visit_Arel_Nodes_Offset o, collector
43
- collector << OFFSET
38
+ collector << ' OFFSET '
44
39
  visit o.expr, collector
45
- collector << ROWS
40
+ collector << ' ROWS'
46
41
  end
47
42
 
48
43
  def visit_Arel_Nodes_Limit o, collector
49
44
  if node_value(o) == 0
50
- collector << FETCH0
51
- collector << ROWS_ONLY
45
+ collector << ' FETCH FIRST (SELECT 0) '
46
+ collector << ' ROWS ONLY'
52
47
  else
53
- collector << FETCH
48
+ collector << ' FETCH NEXT '
54
49
  visit o.expr, collector
55
- collector << ROWS_ONLY
50
+ collector << ' ROWS ONLY'
56
51
  end
57
52
  end
58
53
 
@@ -61,7 +56,7 @@ module Arel
61
56
  distinct_One_As_One_Is_So_Not_Fetch o
62
57
  if o.with
63
58
  collector = visit o.with, collector
64
- collector << SPACE
59
+ collector << ' '
65
60
  end
66
61
  collector = o.cores.inject(collector) { |c,x|
67
62
  visit_Arel_Nodes_SelectCore(x, c)
@@ -99,7 +94,7 @@ module Arel
99
94
  collector = visit_Arel_Nodes_SelectStatement_SQLServer_Lock collector
100
95
  end
101
96
  if o.right.any?
102
- collector << SPACE if o.left
97
+ collector << ' ' if o.left
103
98
  collector = inject_join o.right, collector, ' '
104
99
  end
105
100
  collector
@@ -110,7 +105,7 @@ module Arel
110
105
  collector = visit o.left, collector
111
106
  collector = visit_Arel_Nodes_SelectStatement_SQLServer_Lock collector, space: true
112
107
  if o.right
113
- collector << SPACE
108
+ collector << ' '
114
109
  visit(o.right, collector)
115
110
  else
116
111
  collector
@@ -121,16 +116,31 @@ module Arel
121
116
  collector << "LEFT OUTER JOIN "
122
117
  collector = visit o.left, collector
123
118
  collector = visit_Arel_Nodes_SelectStatement_SQLServer_Lock collector, space: true
124
- collector << SPACE
119
+ collector << ' '
125
120
  visit o.right, collector
126
121
  end
127
122
 
123
+ # NOTE: this overrides the original method in arel visitors 'to_sql.rb'
124
+ # fixes The ORDER BY clause is invalid in subqueries
125
+ # FIXME: we should probably have a 2-pass visitor for this
126
+ def build_subselect(key, o)
127
+ stmt = Nodes::SelectStatement.new
128
+ core = stmt.cores.first
129
+ core.froms = o.relation
130
+ core.wheres = o.wheres
131
+ core.projections = [key]
132
+ stmt.limit = o.limit
133
+ stmt.offset = o.offset
134
+ stmt.orders = []
135
+ stmt
136
+ end
137
+
128
138
  # SQLServer ToSql/Visitor (Additions)
129
139
 
130
140
  def visit_Arel_Nodes_SelectStatement_SQLServer_Lock collector, options = {}
131
141
  if select_statement_lock?
132
142
  collector = visit @select_statement.lock, collector
133
- collector << SPACE if options[:space]
143
+ collector << ' ' if options[:space]
134
144
  end
135
145
  collector
136
146
  end
@@ -138,12 +148,12 @@ module Arel
138
148
  def visit_Orders_And_Let_Fetch_Happen o, collector
139
149
  make_Fetch_Possible_And_Deterministic o
140
150
  unless o.orders.empty?
141
- collector << SPACE
142
- collector << ORDER_BY
151
+ collector << ' '
152
+ collector << ' ORDER BY '
143
153
  len = o.orders.length - 1
144
154
  o.orders.each_with_index { |x, i|
145
155
  collector = visit(x, collector)
146
- collector << COMMA unless len == i
156
+ collector << ', ' unless len == i
147
157
  }
148
158
  end
149
159
  collector
@@ -205,7 +215,7 @@ module Arel
205
215
  elsif Arel::Nodes::SqlLiteral === core.from
206
216
  Arel::Table.new(core.from)
207
217
  elsif Arel::Nodes::JoinSource === core.source
208
- Arel::Nodes::SqlLiteral === core.source.left ? Arel::Table.new(core.source.left, @engine) : core.source.left
218
+ Arel::Nodes::SqlLiteral === core.source.left ? Arel::Table.new(core.source.left, @engine) : core.source.left.left
209
219
  end
210
220
  end
211
221
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ArJdbc
2
4
  module Abstract
3
5
  module ConnectionManagement
@@ -8,6 +10,11 @@ module ArJdbc
8
10
  @connection.active?
9
11
  end
10
12
 
13
+ def really_valid?
14
+ return unless @connection
15
+ @connection.really_valid?
16
+ end
17
+
11
18
  # @override
12
19
  def reconnect!
13
20
  super # clear_cache! && reset_transaction
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ArJdbc
2
4
  module Abstract
3
5
 
@@ -34,28 +36,26 @@ module ArJdbc
34
36
 
35
37
  protected
36
38
 
37
- def translate_exception_class(e, sql)
38
- begin
39
- message = "#{e.class.name}: #{e.message}: #{sql}"
40
- rescue Encoding::CompatibilityError
41
- message = "#{e.class.name}: #{e.message.force_encoding sql.encoding}: #{sql}"
42
- end
39
+ def translate_exception_class(e, sql, binds)
40
+ message = "#{e.class.name}: #{e.message}"
43
41
 
44
- exception = translate_exception(e, message)
45
- exception.set_backtrace e.backtrace unless e.equal?(exception)
42
+ exception = translate_exception(
43
+ e, message: message, sql: sql, binds: binds
44
+ )
45
+ exception.set_backtrace e.backtrace
46
46
  exception
47
47
  end
48
48
 
49
- def translate_exception(e, message)
49
+ def translate_exception(exception, message:, sql:, binds:)
50
50
  # override in derived class
51
51
 
52
52
  # we shall not translate native "Java" exceptions as they might
53
53
  # swallow an ArJdbc / driver bug into an AR::StatementInvalid !
54
- return e if e.is_a?(Java::JavaLang::Throwable)
54
+ return exception if exception.is_a?(Java::JavaLang::Throwable)
55
55
 
56
- case e
57
- when SystemExit, SignalException, NoMemoryError then e
58
- when ActiveModel::RangeError, TypeError, RuntimeError then e
56
+ case exception
57
+ when SystemExit, SignalException, NoMemoryError then exception
58
+ when ActiveModel::RangeError, TypeError, RuntimeError then exception
59
59
  else super
60
60
  end
61
61
  end
@@ -74,13 +74,6 @@ module ArJdbc
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
77
+ JDBC_GEM_ROOT = File.expand_path("../../../..", __FILE__) + "/"
78
+ ActiveRecord::LogSubscriber.backtrace_cleaner.add_silencer { |line| line.start_with?(JDBC_GEM_ROOT) }
79
+ end
@@ -10,6 +10,12 @@ 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
+ if preventing_writes?
14
+ raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}"
15
+ end
16
+
17
+ materialize_transactions
18
+
13
19
  binds = convert_legacy_binds_to_attributes(binds) if binds.first.is_a?(Array)
14
20
 
15
21
  if without_prepared_statement?(binds)
@@ -24,6 +30,12 @@ module ArJdbc
24
30
  # It appears that at this point (AR 5.0) "prepare" should only ever be true
25
31
  # if prepared statements are enabled
26
32
  def exec_query(sql, name = nil, binds = NO_BINDS, prepare: false)
33
+ if preventing_writes? && write_query?(sql)
34
+ raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}"
35
+ end
36
+
37
+ materialize_transactions
38
+
27
39
  binds = convert_legacy_binds_to_attributes(binds) if binds.first.is_a?(Array)
28
40
 
29
41
  if without_prepared_statement?(binds)
@@ -38,6 +50,12 @@ module ArJdbc
38
50
  end
39
51
 
40
52
  def exec_update(sql, name = nil, binds = NO_BINDS)
53
+ if preventing_writes?
54
+ raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}"
55
+ end
56
+
57
+ materialize_transactions
58
+
41
59
  binds = convert_legacy_binds_to_attributes(binds) if binds.first.is_a?(Array)
42
60
 
43
61
  if without_prepared_statement?(binds)
@@ -49,6 +67,12 @@ module ArJdbc
49
67
  alias :exec_delete :exec_update
50
68
 
51
69
  def execute(sql, name = nil)
70
+ if preventing_writes? && write_query?(sql)
71
+ raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}"
72
+ end
73
+
74
+ materialize_transactions
75
+
52
76
  log(sql, name) { @connection.execute(sql) }
53
77
  end
54
78