activerecord-jdbc-adapter 1.0.3-java → 50.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (268) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +33 -0
  3. data/.travis.yml +79 -0
  4. data/.yardopts +4 -0
  5. data/CONTRIBUTING.md +50 -0
  6. data/Gemfile +91 -0
  7. data/History.md +1191 -0
  8. data/LICENSE.txt +22 -17
  9. data/README.md +169 -0
  10. data/RUNNING_TESTS.md +127 -0
  11. data/Rakefile +294 -5
  12. data/Rakefile.jdbc +20 -0
  13. data/activerecord-jdbc-adapter.gemspec +55 -0
  14. data/lib/active_record/connection_adapters/as400_adapter.rb +2 -0
  15. data/lib/active_record/connection_adapters/db2_adapter.rb +1 -0
  16. data/lib/active_record/connection_adapters/firebird_adapter.rb +1 -0
  17. data/lib/active_record/connection_adapters/mariadb_adapter.rb +1 -0
  18. data/lib/active_record/connection_adapters/sqlserver_adapter.rb +1 -0
  19. data/lib/activerecord-jdbc-adapter.rb +0 -5
  20. data/lib/arel/visitors/compat.rb +60 -0
  21. data/lib/arel/visitors/db2.rb +128 -6
  22. data/lib/arel/visitors/derby.rb +103 -10
  23. data/lib/arel/visitors/firebird.rb +79 -0
  24. data/lib/arel/visitors/h2.rb +25 -0
  25. data/lib/arel/visitors/hsqldb.rb +18 -10
  26. data/lib/arel/visitors/postgresql_jdbc.rb +6 -0
  27. data/lib/arel/visitors/sql_server.rb +225 -0
  28. data/lib/arel/visitors/sql_server/ng42.rb +293 -0
  29. data/lib/arjdbc.rb +11 -21
  30. data/lib/arjdbc/abstract/connection_management.rb +35 -0
  31. data/lib/arjdbc/abstract/core.rb +64 -0
  32. data/lib/arjdbc/abstract/database_statements.rb +64 -0
  33. data/lib/arjdbc/abstract/statement_cache.rb +58 -0
  34. data/lib/arjdbc/abstract/transaction_support.rb +86 -0
  35. data/lib/arjdbc/db2.rb +3 -1
  36. data/lib/arjdbc/db2/adapter.rb +630 -250
  37. data/lib/arjdbc/db2/as400.rb +130 -0
  38. data/lib/arjdbc/db2/column.rb +167 -0
  39. data/lib/arjdbc/db2/connection_methods.rb +44 -0
  40. data/lib/arjdbc/derby.rb +1 -5
  41. data/lib/arjdbc/derby/active_record_patch.rb +13 -0
  42. data/lib/arjdbc/derby/adapter.rb +409 -217
  43. data/lib/arjdbc/derby/connection_methods.rb +16 -14
  44. data/lib/arjdbc/derby/schema_creation.rb +15 -0
  45. data/lib/arjdbc/discover.rb +62 -50
  46. data/lib/arjdbc/firebird.rb +3 -1
  47. data/lib/arjdbc/firebird/adapter.rb +365 -62
  48. data/lib/arjdbc/firebird/connection_methods.rb +23 -0
  49. data/lib/arjdbc/h2.rb +2 -3
  50. data/lib/arjdbc/h2/adapter.rb +273 -6
  51. data/lib/arjdbc/h2/connection_methods.rb +23 -8
  52. data/lib/arjdbc/hsqldb.rb +2 -3
  53. data/lib/arjdbc/hsqldb/adapter.rb +204 -77
  54. data/lib/arjdbc/hsqldb/connection_methods.rb +24 -10
  55. data/lib/arjdbc/hsqldb/explain_support.rb +35 -0
  56. data/lib/arjdbc/hsqldb/schema_creation.rb +11 -0
  57. data/lib/arjdbc/informix.rb +4 -2
  58. data/lib/arjdbc/informix/adapter.rb +78 -54
  59. data/lib/arjdbc/informix/connection_methods.rb +8 -9
  60. data/lib/arjdbc/jdbc.rb +59 -2
  61. data/lib/arjdbc/jdbc/adapter.rb +356 -166
  62. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  63. data/lib/arjdbc/jdbc/adapter_require.rb +46 -0
  64. data/lib/arjdbc/jdbc/base_ext.rb +15 -0
  65. data/lib/arjdbc/jdbc/callbacks.rb +27 -18
  66. data/lib/arjdbc/jdbc/column.rb +79 -20
  67. data/lib/arjdbc/jdbc/connection.rb +5 -119
  68. data/lib/arjdbc/jdbc/connection_methods.rb +32 -4
  69. data/lib/arjdbc/jdbc/error.rb +65 -0
  70. data/lib/arjdbc/jdbc/extension.rb +41 -29
  71. data/lib/arjdbc/jdbc/java.rb +5 -6
  72. data/lib/arjdbc/jdbc/jdbc.rake +3 -126
  73. data/lib/arjdbc/jdbc/railtie.rb +2 -9
  74. data/lib/arjdbc/jdbc/rake_tasks.rb +3 -10
  75. data/lib/arjdbc/jdbc/serialized_attributes_helper.rb +3 -0
  76. data/lib/arjdbc/jdbc/type_cast.rb +166 -0
  77. data/lib/arjdbc/jdbc/type_converter.rb +35 -19
  78. data/lib/arjdbc/mssql.rb +6 -3
  79. data/lib/arjdbc/mssql/adapter.rb +630 -298
  80. data/lib/arjdbc/mssql/column.rb +200 -0
  81. data/lib/arjdbc/mssql/connection_methods.rb +66 -17
  82. data/lib/arjdbc/mssql/explain_support.rb +99 -0
  83. data/lib/arjdbc/mssql/limit_helpers.rb +189 -50
  84. data/lib/arjdbc/mssql/lock_methods.rb +77 -0
  85. data/lib/arjdbc/mssql/types.rb +343 -0
  86. data/lib/arjdbc/mssql/utils.rb +82 -0
  87. data/lib/arjdbc/mysql.rb +2 -3
  88. data/lib/arjdbc/mysql/adapter.rb +86 -356
  89. data/lib/arjdbc/mysql/connection_methods.rb +159 -23
  90. data/lib/arjdbc/oracle/adapter.rb +714 -263
  91. data/lib/arjdbc/postgresql.rb +2 -3
  92. data/lib/arjdbc/postgresql/_bc_time_cast_patch.rb +24 -0
  93. data/lib/arjdbc/postgresql/adapter.rb +570 -400
  94. data/lib/arjdbc/postgresql/base/array_decoder.rb +26 -0
  95. data/lib/arjdbc/postgresql/base/array_encoder.rb +25 -0
  96. data/lib/arjdbc/postgresql/base/array_parser.rb +95 -0
  97. data/lib/arjdbc/postgresql/base/pgconn.rb +11 -0
  98. data/lib/arjdbc/postgresql/column.rb +51 -0
  99. data/lib/arjdbc/postgresql/connection_methods.rb +57 -18
  100. data/lib/arjdbc/postgresql/name.rb +24 -0
  101. data/lib/arjdbc/postgresql/oid_types.rb +192 -0
  102. data/lib/arjdbc/railtie.rb +11 -0
  103. data/lib/arjdbc/sqlite3.rb +2 -3
  104. data/lib/arjdbc/sqlite3/adapter.rb +518 -198
  105. data/lib/arjdbc/sqlite3/connection_methods.rb +49 -24
  106. data/lib/arjdbc/sybase.rb +2 -2
  107. data/lib/arjdbc/sybase/adapter.rb +7 -6
  108. data/lib/arjdbc/tasks.rb +13 -0
  109. data/lib/arjdbc/tasks/database_tasks.rb +52 -0
  110. data/lib/arjdbc/tasks/databases.rake +91 -0
  111. data/lib/arjdbc/tasks/databases3.rake +215 -0
  112. data/lib/arjdbc/tasks/databases4.rake +39 -0
  113. data/lib/arjdbc/tasks/db2_database_tasks.rb +104 -0
  114. data/lib/arjdbc/tasks/derby_database_tasks.rb +95 -0
  115. data/lib/arjdbc/tasks/h2_database_tasks.rb +31 -0
  116. data/lib/arjdbc/tasks/hsqldb_database_tasks.rb +70 -0
  117. data/lib/arjdbc/tasks/jdbc_database_tasks.rb +169 -0
  118. data/lib/arjdbc/tasks/mssql_database_tasks.rb +46 -0
  119. data/lib/arjdbc/util/quoted_cache.rb +60 -0
  120. data/lib/arjdbc/util/serialized_attributes.rb +98 -0
  121. data/lib/arjdbc/util/table_copier.rb +110 -0
  122. data/lib/arjdbc/version.rb +1 -6
  123. data/lib/generators/jdbc/USAGE +9 -0
  124. data/lib/generators/jdbc/jdbc_generator.rb +8 -0
  125. data/lib/jdbc_adapter.rb +1 -1
  126. data/lib/jdbc_adapter/rake_tasks.rb +3 -2
  127. data/lib/jdbc_adapter/version.rb +2 -1
  128. data/pom.xml +114 -0
  129. data/rails_generators/jdbc_generator.rb +1 -1
  130. data/rails_generators/templates/config/initializers/jdbc.rb +8 -5
  131. data/rails_generators/templates/lib/tasks/jdbc.rake +7 -4
  132. data/rakelib/01-tomcat.rake +51 -0
  133. data/rakelib/02-test.rake +132 -0
  134. data/rakelib/bundler_ext.rb +11 -0
  135. data/rakelib/compile.rake +67 -22
  136. data/rakelib/db.rake +61 -0
  137. data/rakelib/rails.rake +204 -29
  138. data/src/java/arjdbc/ArJdbcModule.java +286 -0
  139. data/src/java/arjdbc/db2/DB2Module.java +76 -0
  140. data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +126 -0
  141. data/src/java/arjdbc/derby/DerbyModule.java +99 -243
  142. data/src/java/arjdbc/derby/DerbyRubyJdbcConnection.java +152 -0
  143. data/src/java/arjdbc/firebird/FirebirdRubyJdbcConnection.java +174 -0
  144. data/src/java/arjdbc/{jdbc/JdbcConnectionFactory.java → h2/H2Module.java} +20 -6
  145. data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +27 -12
  146. data/src/java/arjdbc/hsqldb/HSQLDBModule.java +73 -0
  147. data/src/java/arjdbc/informix/InformixRubyJdbcConnection.java +7 -6
  148. data/src/java/arjdbc/jdbc/AdapterJavaService.java +7 -29
  149. data/src/java/arjdbc/jdbc/Callable.java +44 -0
  150. data/src/java/arjdbc/jdbc/ConnectionFactory.java +132 -0
  151. data/src/java/arjdbc/jdbc/DataSourceConnectionFactory.java +157 -0
  152. data/src/java/arjdbc/jdbc/DriverConnectionFactory.java +63 -0
  153. data/src/java/arjdbc/jdbc/DriverWrapper.java +119 -0
  154. data/src/java/arjdbc/jdbc/JdbcResult.java +130 -0
  155. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +3622 -948
  156. data/src/java/arjdbc/mssql/MSSQLModule.java +90 -0
  157. data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +181 -0
  158. data/src/java/arjdbc/mysql/MySQLModule.java +99 -81
  159. data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +294 -0
  160. data/src/java/arjdbc/oracle/OracleModule.java +80 -0
  161. data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +387 -17
  162. data/src/java/arjdbc/postgresql/ByteaUtils.java +157 -0
  163. data/src/java/arjdbc/postgresql/PgResultSetMetaDataWrapper.java +23 -0
  164. data/src/java/arjdbc/postgresql/PostgreSQLModule.java +77 -0
  165. data/src/java/arjdbc/postgresql/PostgreSQLResult.java +184 -0
  166. data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +952 -0
  167. data/src/java/arjdbc/sqlite3/SQLite3Module.java +73 -0
  168. data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +525 -0
  169. data/src/java/arjdbc/util/CallResultSet.java +826 -0
  170. data/src/java/arjdbc/util/DateTimeUtils.java +580 -0
  171. data/src/java/arjdbc/util/ObjectSupport.java +65 -0
  172. data/src/java/arjdbc/util/QuotingUtils.java +138 -0
  173. data/src/java/arjdbc/util/StringCache.java +63 -0
  174. data/src/java/arjdbc/util/StringHelper.java +159 -0
  175. metadata +245 -268
  176. data/History.txt +0 -369
  177. data/Manifest.txt +0 -180
  178. data/README.txt +0 -181
  179. data/lib/active_record/connection_adapters/oracle_adapter.rb +0 -1
  180. data/lib/arel/engines/sql/compilers/db2_compiler.rb +0 -9
  181. data/lib/arel/engines/sql/compilers/derby_compiler.rb +0 -6
  182. data/lib/arel/engines/sql/compilers/h2_compiler.rb +0 -6
  183. data/lib/arel/engines/sql/compilers/hsqldb_compiler.rb +0 -15
  184. data/lib/arel/engines/sql/compilers/jdbc_compiler.rb +0 -6
  185. data/lib/arel/engines/sql/compilers/mssql_compiler.rb +0 -46
  186. data/lib/arel/visitors/mssql.rb +0 -44
  187. data/lib/arjdbc/jdbc/compatibility.rb +0 -51
  188. data/lib/arjdbc/jdbc/core_ext.rb +0 -24
  189. data/lib/arjdbc/jdbc/discover.rb +0 -18
  190. data/lib/arjdbc/jdbc/driver.rb +0 -44
  191. data/lib/arjdbc/jdbc/missing_functionality_helper.rb +0 -87
  192. data/lib/arjdbc/jdbc/quoted_primary_key.rb +0 -28
  193. data/lib/arjdbc/jdbc/require_driver.rb +0 -16
  194. data/lib/arjdbc/mimer.rb +0 -2
  195. data/lib/arjdbc/mimer/adapter.rb +0 -142
  196. data/lib/arjdbc/mssql/tsql_helper.rb +0 -61
  197. data/lib/arjdbc/oracle.rb +0 -3
  198. data/lib/arjdbc/oracle/connection_methods.rb +0 -11
  199. data/lib/pg.rb +0 -4
  200. data/rakelib/package.rake +0 -92
  201. data/rakelib/test.rake +0 -81
  202. data/src/java/arjdbc/jdbc/SQLBlock.java +0 -48
  203. data/src/java/arjdbc/mssql/MssqlRubyJdbcConnection.java +0 -127
  204. data/src/java/arjdbc/postgresql/PostgresqlRubyJdbcConnection.java +0 -57
  205. data/src/java/arjdbc/sqlite3/Sqlite3RubyJdbcConnection.java +0 -64
  206. data/test/abstract_db_create.rb +0 -117
  207. data/test/activerecord/connection_adapters/type_conversion_test.rb +0 -31
  208. data/test/activerecord/connections/native_jdbc_mysql/connection.rb +0 -25
  209. data/test/db/db2.rb +0 -11
  210. data/test/db/derby.rb +0 -12
  211. data/test/db/h2.rb +0 -11
  212. data/test/db/hsqldb.rb +0 -13
  213. data/test/db/informix.rb +0 -11
  214. data/test/db/jdbc.rb +0 -11
  215. data/test/db/jndi_config.rb +0 -40
  216. data/test/db/logger.rb +0 -3
  217. data/test/db/mssql.rb +0 -9
  218. data/test/db/mysql.rb +0 -10
  219. data/test/db/oracle.rb +0 -34
  220. data/test/db/postgres.rb +0 -9
  221. data/test/db/sqlite3.rb +0 -11
  222. data/test/db2_simple_test.rb +0 -66
  223. data/test/derby_migration_test.rb +0 -68
  224. data/test/derby_multibyte_test.rb +0 -12
  225. data/test/derby_simple_test.rb +0 -99
  226. data/test/generic_jdbc_connection_test.rb +0 -29
  227. data/test/h2_simple_test.rb +0 -41
  228. data/test/has_many_through.rb +0 -79
  229. data/test/helper.rb +0 -5
  230. data/test/hsqldb_simple_test.rb +0 -6
  231. data/test/informix_simple_test.rb +0 -48
  232. data/test/jdbc_common.rb +0 -25
  233. data/test/jndi_callbacks_test.rb +0 -40
  234. data/test/jndi_test.rb +0 -25
  235. data/test/manualTestDatabase.rb +0 -191
  236. data/test/models/add_not_null_column_to_table.rb +0 -12
  237. data/test/models/auto_id.rb +0 -18
  238. data/test/models/data_types.rb +0 -28
  239. data/test/models/entry.rb +0 -43
  240. data/test/models/mixed_case.rb +0 -25
  241. data/test/models/reserved_word.rb +0 -18
  242. data/test/models/string_id.rb +0 -18
  243. data/test/models/validates_uniqueness_of_string.rb +0 -19
  244. data/test/mssql_db_create_test.rb +0 -26
  245. data/test/mssql_identity_insert_test.rb +0 -19
  246. data/test/mssql_legacy_types_test.rb +0 -58
  247. data/test/mssql_limit_offset_test.rb +0 -136
  248. data/test/mssql_multibyte_test.rb +0 -18
  249. data/test/mssql_simple_test.rb +0 -55
  250. data/test/mysql_db_create_test.rb +0 -27
  251. data/test/mysql_info_test.rb +0 -113
  252. data/test/mysql_multibyte_test.rb +0 -10
  253. data/test/mysql_nonstandard_primary_key_test.rb +0 -42
  254. data/test/mysql_simple_test.rb +0 -49
  255. data/test/oracle_simple_test.rb +0 -18
  256. data/test/oracle_specific_test.rb +0 -83
  257. data/test/pick_rails_version.rb +0 -3
  258. data/test/postgres_db_create_test.rb +0 -32
  259. data/test/postgres_drop_db_test.rb +0 -16
  260. data/test/postgres_mixed_case_test.rb +0 -29
  261. data/test/postgres_nonseq_pkey_test.rb +0 -38
  262. data/test/postgres_reserved_test.rb +0 -22
  263. data/test/postgres_schema_search_path_test.rb +0 -44
  264. data/test/postgres_simple_test.rb +0 -51
  265. data/test/postgres_table_alias_length_test.rb +0 -15
  266. data/test/simple.rb +0 -546
  267. data/test/sqlite3_simple_test.rb +0 -233
  268. data/test/sybase_jtds_simple_test.rb +0 -28
@@ -0,0 +1,20 @@
1
+ # NOTE: shared Rakefile used for jdbc-xxx gems
2
+
3
+ require 'bundler/gem_helper'
4
+
5
+ name = Dir["*.gemspec"].first.sub('.gemspec', '')
6
+ gem_helper = Bundler::GemHelper.new(Dir.pwd, name)
7
+ def gem_helper.version_tag
8
+ "#{name}-#{version}" # override "v#{version}"
9
+ end
10
+
11
+ version = gem_helper.send(:version)
12
+ version_tag = gem_helper.version_tag
13
+ desc "Build #{name}-#{version} gem into the pkg directory"
14
+ task('build') { gem_helper.build_gem }
15
+
16
+ desc "Build and install #{name}-#{version} gem into system gems"
17
+ task('install') { gem_helper.install_gem }
18
+
19
+ desc "Create tag #{version_tag} build and push #{name}-#{version} gem to Rubygems"
20
+ task('release') { gem_helper.release_gem }
@@ -0,0 +1,55 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = 'activerecord-jdbc-adapter'
5
+ path = File.expand_path('lib/arjdbc/version.rb', File.dirname(__FILE__))
6
+ gem.version = File.read(path).match( /.*VERSION\s*=\s*['"](.*)['"]/m )[1]
7
+ gem.platform = 'java' # due jar-dependencies to resolve requirements for ext
8
+ gem.authors = ['Nick Sieger, Ola Bini, Karol Bucek and JRuby contributors']
9
+ gem.email = ['nick@nicksieger.com', 'ola.bini@gmail.com', 'self@kares.org']
10
+ gem.homepage = 'https://github.com/jruby/activerecord-jdbc-adapter'
11
+ gem.license = 'BSD-2-Clause'
12
+ gem.summary = 'JDBC adapter for ActiveRecord, for use within JRuby on Rails.'
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."
21
+
22
+ gem.require_paths = ["lib"]
23
+
24
+ gem.files = `git ls-files`.split("\n").
25
+ reject { |f| f =~ /^(activerecord-jdbc[^-]|jdbc-)/ }. # gem directories
26
+ reject { |f| f =~ /^(bench|test)/ }. # not sure if including tests is useful
27
+ reject { |f| f =~ /^(gemfiles)/ } # no tests - no Gemfile_s appraised ...
28
+ gem.files += ['lib/arjdbc/jdbc/adapter_java.jar'] #if ENV['RELEASE'].eql?('true')
29
+
30
+ if ENV['RELEASE'] != 'true' # @see Rakefile
31
+ gem.extensions << 'Rakefile' # to support auto-building .jar with :git paths
32
+
33
+ #gem.add_runtime_dependency 'jar-dependencies', '~> 0.1' # development not enough!
34
+ #gem.add_development_dependency 'ruby-maven', '~> 3.1'
35
+ #
36
+ #gem.requirements << "jar mysql:mysql-connector-java, 5.1.44, :scope => :compile"
37
+ #gem.requirements << "jar org.postgresql:postgresql, 42.1.4.jre6, :scope => :compile"
38
+
39
+ # compilation .jar dependencies for extension (at least until `mvn') :
40
+ gem.add_development_dependency 'jdbc-mysql', '~> 5.1.44'
41
+ gem.add_development_dependency 'jdbc-postgres', '~> 42.1'
42
+ end
43
+
44
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
45
+ gem.test_files = gem.files.grep(%r{^test/})
46
+
47
+ gem.add_dependency 'activerecord', '~> 5.0.0'
48
+
49
+ #gem.add_development_dependency 'test-unit', '2.5.4'
50
+ #gem.add_development_dependency 'test-unit-context', '>= 0.3.0'
51
+ #gem.add_development_dependency 'mocha', '~> 0.13.1'
52
+
53
+ gem.rdoc_options = ["--main", "README.md", "-SHN", "-f", "darkfish"]
54
+ end
55
+
@@ -0,0 +1,2 @@
1
+ require 'arjdbc/db2'
2
+ require 'arjdbc/db2/as400'
@@ -0,0 +1 @@
1
+ require 'arjdbc/db2'
@@ -0,0 +1 @@
1
+ require 'arjdbc/firebird'
@@ -0,0 +1 @@
1
+ require 'arjdbc/mysql'
@@ -0,0 +1 @@
1
+ require 'arjdbc/mssql'
@@ -1,6 +1 @@
1
1
  require 'arjdbc'
2
- begin
3
- require 'arjdbc/jdbc/railtie'
4
- rescue LoadError
5
- # Assume we don't have railties in this version of AR
6
- end
@@ -0,0 +1,60 @@
1
+ module Arel
2
+ module Visitors
3
+ module ArJdbcCompat
4
+
5
+ protected
6
+
7
+ if ToSql.instance_method('visit').arity == 1
8
+ def do_visit(x, a); visit(x); end # a = nil
9
+ else # > AREL 4.0
10
+ def do_visit(x, a); visit(x, a); end
11
+ end
12
+
13
+ if ToSql.instance_method('visit_Arel_Nodes_SelectCore').arity == 1
14
+ def do_visit_select_core(x, a) # a = nil
15
+ visit_Arel_Nodes_SelectCore(x)
16
+ end
17
+ else # > AREL 4.0
18
+ def do_visit_select_core(x, a)
19
+ visit_Arel_Nodes_SelectCore(x, a)
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ if ArJdbc::AR42
26
+ if Arel::VERSION < '6.0.2'
27
+ def limit_for(limit_or_node)
28
+ if limit_or_node.respond_to?(:expr)
29
+ expr = limit_or_node.expr
30
+ # NOTE(uwe): Different behavior for Arel 6.0.0 and 6.0.2
31
+ expr.respond_to?(:value) ? expr.value.to_i : expr.to_i
32
+ else
33
+ limit_or_node
34
+ end
35
+ end
36
+ else
37
+ def limit_for(limit_or_node)
38
+ limit_or_node.respond_to?(:expr) ? limit_or_node.expr.to_i : limit_or_node
39
+ end
40
+ end
41
+ else
42
+ def limit_for(limit_or_node)
43
+ limit_or_node.respond_to?(:expr) ? limit_or_node.expr.to_i : limit_or_node
44
+ end
45
+ end
46
+ module_function :limit_for
47
+
48
+ def node_value(node)
49
+ return nil unless node
50
+ case expr = node.expr
51
+ when NilClass then nil
52
+ when Numeric then expr
53
+ when Arel::Nodes::Unary then expr.expr
54
+ end
55
+ end
56
+
57
+ end
58
+ ToSql.send(:include, ArJdbcCompat)
59
+ end
60
+ end
@@ -1,15 +1,137 @@
1
+ # NOTE: file contains code adapted from **ruby-ibmdb**'s adapter, license follows
2
+ =begin
3
+ Copyright (c) 2006 - 2015 IBM Corporation
4
+
5
+ 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:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ 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.
10
+ =end
11
+
12
+ require 'arel/visitors/compat'
13
+
1
14
  module Arel
2
15
  module Visitors
3
16
  class DB2 < Arel::Visitors::ToSql
4
- def visit_Arel_Nodes_SelectStatement o
5
- add_limit_offset([o.cores.map { |x| visit_Arel_Nodes_SelectCore x }.join,
6
- ("ORDER BY #{o.orders.map { |x| visit x }.join(', ')}" unless o.orders.empty?),
7
- ].compact.join(' '), o)
17
+
18
+ if ArJdbc::AR42
19
+ def visit_Arel_Nodes_SelectStatement(o, a = nil)
20
+ a = o.cores.inject(a) { |c, x| visit_Arel_Nodes_SelectCore(x, c) }
21
+
22
+ unless o.orders.empty?
23
+ a << ' ORDER BY '
24
+ last = o.orders.length - 1
25
+ o.orders.each_with_index do |x, i|
26
+ visit(x, a); a << ', ' unless last == i
27
+ end
28
+ end
29
+
30
+ if limit = o.limit
31
+ if limit = limit.value
32
+ limit = limit.to_i
33
+ end
34
+ end
35
+ if offset = o.offset
36
+ if offset = offset.value
37
+ offset = offset.to_i
38
+ end
39
+ end
40
+
41
+ if limit || offset
42
+ add_limit_offset(a, o, limit, offset)
43
+ else
44
+ a
45
+ end
46
+ end
47
+
48
+ def visit_Arel_Nodes_Limit o, collector
49
+ # visit o.expr, collector
50
+ end
51
+
52
+ def visit_Arel_Nodes_Offset o, collector
53
+ # visit o.expr, collector
54
+ end
55
+
56
+ else
57
+ def visit_Arel_Nodes_SelectStatement o, a = nil
58
+ sql = o.cores.map { |x| do_visit_select_core x, a }.join
59
+ sql << " ORDER BY #{o.orders.map { |x| do_visit x, a }.join(', ')}" unless o.orders.empty?
60
+
61
+ if limit = o.limit
62
+ if limit = limit.value
63
+ limit = limit.to_i
64
+ end
65
+ end
66
+ if offset = o.offset
67
+ if offset = offset.value
68
+ offset = offset.to_i
69
+ end
70
+ end
71
+
72
+ if limit || offset
73
+ add_limit_offset(sql, o, limit, offset)
74
+ else
75
+ sql
76
+ end
77
+ end
78
+ end
79
+
80
+ if ArJdbc::AR42
81
+ def visit_Arel_Nodes_InsertStatement o, a = nil
82
+ a << "INSERT INTO "
83
+ visit(o.relation, a)
84
+
85
+ values = o.values
86
+
87
+ if o.columns.any?
88
+ cols = o.columns.map { |x| quote_column_name x.name }
89
+ a << ' (' << cols.join(', ') << ') '
90
+ elsif o.values.eql? ArJdbc::DB2::VALUES_DEFAULT
91
+ cols = o.relation.engine.columns.map { |c| c.name }
92
+ a << ' (' << cols.join(', ') << ')'
93
+ a << ' VALUES '
94
+ a << ' (' << cols.map { 'DEFAULT' }.join(', ') << ')'
95
+ values = false
96
+ end
97
+ visit(values, a) if values
98
+ a
99
+ end
100
+ elsif Arel::VERSION >= '4.0' # AR 4.0 ... AREL 5.0 since AR >= 4.1
101
+ def visit_Arel_Nodes_InsertStatement o, a = nil
102
+ sql = "INSERT INTO "
103
+ sql << visit(o.relation, a)
104
+
105
+ values = o.values
106
+
107
+ if o.columns.any?
108
+ cols = o.columns.map { |x| quote_column_name x.name }
109
+ sql << ' (' << cols.join(', ') << ') '
110
+ # should depend the other way around but who cares it's AR
111
+ elsif o.values.eql? ArJdbc::DB2::VALUES_DEFAULT
112
+ cols = o.relation.engine.columns.map { |c| c.name }
113
+ sql << ' (' << cols.join(', ') << ')'
114
+ sql << ' VALUES '
115
+ sql << ' (' << cols.map { 'DEFAULT' }.join(', ') << ')'
116
+ values = nil
117
+ end
118
+
119
+ sql << visit(values, a) if values
120
+
121
+ sql
122
+ end
8
123
  end
9
124
 
10
- def add_limit_offset(sql, o)
11
- @connection.replace_limit_offset! sql, o.limit, o.offset
125
+ private
126
+
127
+ def add_limit_offset(sql, o, limit, offset)
128
+ @connection.replace_limit_offset! sql, limit, offset, o.orders
12
129
  end
130
+
13
131
  end
14
132
  end
15
133
  end
134
+
135
+ Arel::Collectors::Bind.class_eval do
136
+ attr_reader :parts
137
+ end if defined? Arel::Collectors::Bind
@@ -1,18 +1,111 @@
1
+ require 'arel/visitors/compat'
2
+
1
3
  module Arel
2
4
  module Visitors
3
5
  class Derby < Arel::Visitors::ToSql
4
- def visit_Arel_Nodes_SelectStatement o
5
- [
6
- o.cores.map { |x| visit_Arel_Nodes_SelectCore x }.join,
7
- ("ORDER BY #{o.orders.map { |x| visit x }.join(', ')}" unless o.orders.empty?),
8
- ("FETCH FIRST #{o.limit} ROWS ONLY" if o.limit),
9
- (visit(o.offset) if o.offset),
10
- (visit(o.lock) if o.lock),
11
- ].compact.join ' '
6
+
7
+ # @private
8
+ STR_1 = ' '
9
+
10
+ if ArJdbc::AR42
11
+ def visit_Arel_Nodes_SelectStatement(o, a = nil)
12
+ a = o.cores.inject(a) { |c, x| visit_Arel_Nodes_SelectCore(x, c) }
13
+ unless o.orders.empty?
14
+ a << ' ORDER BY '
15
+ last = o.orders.length - 1
16
+ o.orders.each_with_index do |x, i|
17
+ visit(x, a); a << ', ' unless last == i
18
+ end
19
+ end
20
+ if o.offset
21
+ a << STR_1; visit(o.offset, a)
22
+ end
23
+ if o.limit
24
+ a << STR_1; visit(o.limit, a)
25
+ end
26
+ if o.lock
27
+ a << STR_1; visit(o.lock, a)
28
+ end
29
+ a
30
+ end
31
+ else
32
+ def visit_Arel_Nodes_SelectStatement(o, a = nil)
33
+ sql = o.cores.map { |x| do_visit(x, a) }.join
34
+ sql << " ORDER BY #{o.orders.map { |x| do_visit x, a }.join(', ')}" unless o.orders.empty?
35
+ sql << " #{do_visit o.offset, a}" if o.offset
36
+ sql << " #{do_visit o.limit, a}" if o.limit
37
+ sql << " #{do_visit o.lock, a}" if o.lock
38
+ sql
39
+ end
40
+ end
41
+
42
+ def visit_Arel_Nodes_Limit(o, a = nil)
43
+ limit = "FETCH FIRST #{limit_for(o)} ROWS ONLY"
44
+ a << limit if a
45
+ limit
46
+ end
47
+
48
+ def visit_Arel_Nodes_Offset(o, a = nil)
49
+ if a
50
+ a << 'OFFSET '
51
+ do_visit(o.value, a)
52
+ a << ' ROWS'
53
+ else
54
+ "OFFSET #{do_visit o.value, a} ROWS"
55
+ end
12
56
  end
13
57
 
14
- def visit_Arel_Nodes_Offset o
15
- "OFFSET #{visit o.value} ROWS"
58
+ # This generates SELECT...FOR UPDATE, but it will only work if the
59
+ # current transaction isolation level is set to SERIALIZABLE. Otherwise,
60
+ # locks aren't held for the entire transaction.
61
+ def visit_Arel_Nodes_Lock o, a = nil
62
+ do_visit o.expr, a
63
+ end
64
+
65
+ # @private
66
+ VALUES_DEFAULT = 'VALUES ( DEFAULT )' # NOTE: marker set by ArJdbc::Derby
67
+
68
+ if ArJdbc::AR42
69
+ def visit_Arel_Nodes_InsertStatement o, a = nil
70
+ a << "INSERT INTO "
71
+ visit(o.relation, a)
72
+
73
+ values = o.values
74
+
75
+ if o.columns.any?
76
+ cols = o.columns.map { |x| quote_column_name x.name }
77
+ a << ' (' << cols.join(', ') << ') '
78
+ elsif o.values.eql? VALUES_DEFAULT
79
+ cols = o.relation.engine.columns.map { |c| c.name }
80
+ a << ' (' << cols.join(', ') << ')'
81
+ a << ' VALUES '
82
+ a << ' (' << cols.map { 'DEFAULT' }.join(', ') << ')'
83
+ values = false
84
+ end
85
+ visit(values, a) if values
86
+ a
87
+ end
88
+ elsif Arel::VERSION >= '4.0' # AR 4.0 ... AREL 5.0 since AR >= 4.1
89
+ def visit_Arel_Nodes_InsertStatement o, a = nil
90
+ sql = 'INSERT INTO '
91
+ sql << visit(o.relation, a)
92
+
93
+ values = o.values
94
+
95
+ if o.columns.any?
96
+ cols = o.columns.map { |x| quote_column_name x.name }
97
+ sql << ' (' << cols.join(', ') << ') '
98
+ elsif o.values.eql? VALUES_DEFAULT
99
+ cols = o.relation.engine.columns.map { |c| c.name }
100
+ sql << ' (' << cols.join(', ') << ')'
101
+ sql << ' VALUES '
102
+ sql << ' (' << cols.map { 'DEFAULT' }.join(', ') << ')'
103
+ values = false
104
+ end
105
+
106
+ sql << visit(values, a) if values
107
+ sql
108
+ end
16
109
  end
17
110
  end
18
111
  end
@@ -0,0 +1,79 @@
1
+ require 'arel/visitors/compat'
2
+
3
+ module Arel
4
+ module Visitors
5
+ class Firebird < Arel::Visitors::ToSql
6
+
7
+ if ArJdbc::AR42
8
+ def visit_Arel_Nodes_SelectStatement(o, a)
9
+ a = o.cores.inject(a) { |c, x| visit_Arel_Nodes_SelectCore(x, c) }
10
+
11
+ limit, offset = o.limit, o.offset
12
+ if limit || offset
13
+ select = a.parts[0]
14
+
15
+ sql = Arel::Collectors::SQLString.new
16
+ visit(limit, sql) if limit
17
+ if offset
18
+ sql << ' ' if limit
19
+ visit(offset, sql)
20
+ end
21
+
22
+ a.parts[0] = "#{select} #{sql.value}"
23
+ end
24
+
25
+ unless o.orders.empty?
26
+ a << ' ORDER BY '
27
+ last = o.orders.length - 1
28
+ o.orders.each_with_index do |x, i|
29
+ visit(x, a); a << ', ' unless last == i
30
+ end
31
+ end
32
+
33
+ a
34
+ end
35
+
36
+ def visit_Arel_Nodes_Limit(o, a)
37
+ a << "FIRST #{limit_for(o)}"
38
+ end
39
+
40
+ def visit_Arel_Nodes_Offset(o, a)
41
+ a << 'SKIP '; visit(o.value, a)
42
+ end
43
+
44
+ else
45
+
46
+ def visit_Arel_Nodes_SelectStatement o, a = nil
47
+ if o.limit
48
+ limit = do_visit o.limit.expr, a
49
+ else
50
+ limit = nil
51
+ end
52
+ if o.offset
53
+ offset = do_visit o.offset.expr, a
54
+ else
55
+ offset = nil
56
+ end
57
+
58
+ sql = o.cores.map { |x| do_visit_select_core x, a }.join
59
+ @connection.insert_limit_offset!(sql, limit, offset) if limit || offset
60
+
61
+ unless o.orders.empty?
62
+ sql << ' ORDER BY '
63
+ last = o.orders.length - 1
64
+ o.orders.each_with_index do |x, i|
65
+ sql << do_visit(x, a); sql << ', ' unless last == i
66
+ end
67
+ end
68
+
69
+ sql
70
+ end
71
+ end
72
+
73
+ end
74
+ end
75
+ end
76
+
77
+ Arel::Collectors::Bind.class_eval do
78
+ attr_reader :parts
79
+ end if defined? Arel::Collectors::Bind