activerecord-jdbc-adapter-ficoh 1.3.21-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +35 -0
- data/.travis.yml +462 -0
- data/.yardopts +4 -0
- data/Appraisals +36 -0
- data/CONTRIBUTING.md +49 -0
- data/Gemfile +68 -0
- data/History.md +1191 -0
- data/LICENSE.txt +25 -0
- data/README.md +277 -0
- data/RUNNING_TESTS.md +88 -0
- data/Rakefile +298 -0
- data/Rakefile.jdbc +20 -0
- data/activerecord-jdbc-adapter.gemspec +63 -0
- data/lib/active_record/connection_adapters/as400_adapter.rb +2 -0
- data/lib/active_record/connection_adapters/db2_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/derby_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/firebird_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/h2_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/hsqldb_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/informix_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/jdbc_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/jndi_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mariadb_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mssql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mysql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/oracle_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/sqlserver_adapter.rb +1 -0
- data/lib/activerecord-jdbc-adapter.rb +1 -0
- data/lib/arel/visitors/compat.rb +64 -0
- data/lib/arel/visitors/db2.rb +137 -0
- data/lib/arel/visitors/derby.rb +112 -0
- data/lib/arel/visitors/firebird.rb +79 -0
- data/lib/arel/visitors/h2.rb +25 -0
- data/lib/arel/visitors/hsqldb.rb +32 -0
- data/lib/arel/visitors/postgresql_jdbc.rb +6 -0
- data/lib/arel/visitors/sql_server.rb +225 -0
- data/lib/arel/visitors/sql_server/ng42.rb +293 -0
- data/lib/arjdbc.rb +22 -0
- data/lib/arjdbc/db2.rb +4 -0
- data/lib/arjdbc/db2/adapter.rb +802 -0
- data/lib/arjdbc/db2/as400.rb +137 -0
- data/lib/arjdbc/db2/column.rb +177 -0
- data/lib/arjdbc/db2/connection_methods.rb +45 -0
- data/lib/arjdbc/derby.rb +3 -0
- data/lib/arjdbc/derby/active_record_patch.rb +13 -0
- data/lib/arjdbc/derby/adapter.rb +567 -0
- data/lib/arjdbc/derby/connection_methods.rb +16 -0
- data/lib/arjdbc/derby/schema_creation.rb +15 -0
- data/lib/arjdbc/discover.rb +104 -0
- data/lib/arjdbc/firebird.rb +4 -0
- data/lib/arjdbc/firebird/adapter.rb +468 -0
- data/lib/arjdbc/firebird/connection_methods.rb +20 -0
- data/lib/arjdbc/h2.rb +3 -0
- data/lib/arjdbc/h2/adapter.rb +335 -0
- data/lib/arjdbc/h2/connection_methods.rb +22 -0
- data/lib/arjdbc/hsqldb.rb +3 -0
- data/lib/arjdbc/hsqldb/adapter.rb +304 -0
- data/lib/arjdbc/hsqldb/connection_methods.rb +23 -0
- data/lib/arjdbc/hsqldb/explain_support.rb +35 -0
- data/lib/arjdbc/hsqldb/schema_creation.rb +11 -0
- data/lib/arjdbc/informix.rb +5 -0
- data/lib/arjdbc/informix/adapter.rb +160 -0
- data/lib/arjdbc/informix/connection_methods.rb +9 -0
- data/lib/arjdbc/jdbc.rb +62 -0
- data/lib/arjdbc/jdbc/adapter.rb +997 -0
- data/lib/arjdbc/jdbc/adapter_require.rb +46 -0
- data/lib/arjdbc/jdbc/arel_support.rb +149 -0
- data/lib/arjdbc/jdbc/base_ext.rb +34 -0
- data/lib/arjdbc/jdbc/callbacks.rb +52 -0
- data/lib/arjdbc/jdbc/column.rb +83 -0
- data/lib/arjdbc/jdbc/connection.rb +26 -0
- data/lib/arjdbc/jdbc/connection_methods.rb +59 -0
- data/lib/arjdbc/jdbc/driver.rb +44 -0
- data/lib/arjdbc/jdbc/error.rb +75 -0
- data/lib/arjdbc/jdbc/extension.rb +69 -0
- data/lib/arjdbc/jdbc/java.rb +13 -0
- data/lib/arjdbc/jdbc/type_cast.rb +154 -0
- data/lib/arjdbc/jdbc/type_converter.rb +142 -0
- data/lib/arjdbc/mssql.rb +7 -0
- data/lib/arjdbc/mssql/adapter.rb +822 -0
- data/lib/arjdbc/mssql/column.rb +207 -0
- data/lib/arjdbc/mssql/connection_methods.rb +72 -0
- data/lib/arjdbc/mssql/explain_support.rb +99 -0
- data/lib/arjdbc/mssql/limit_helpers.rb +231 -0
- data/lib/arjdbc/mssql/lock_methods.rb +77 -0
- data/lib/arjdbc/mssql/types.rb +343 -0
- data/lib/arjdbc/mssql/utils.rb +82 -0
- data/lib/arjdbc/mysql.rb +3 -0
- data/lib/arjdbc/mysql/adapter.rb +998 -0
- data/lib/arjdbc/mysql/bulk_change_table.rb +150 -0
- data/lib/arjdbc/mysql/column.rb +167 -0
- data/lib/arjdbc/mysql/connection_methods.rb +137 -0
- data/lib/arjdbc/mysql/explain_support.rb +82 -0
- data/lib/arjdbc/mysql/schema_creation.rb +58 -0
- data/lib/arjdbc/oracle.rb +4 -0
- data/lib/arjdbc/oracle/adapter.rb +968 -0
- data/lib/arjdbc/oracle/column.rb +136 -0
- data/lib/arjdbc/oracle/connection_methods.rb +21 -0
- data/lib/arjdbc/postgresql.rb +3 -0
- data/lib/arjdbc/postgresql/_bc_time_cast_patch.rb +21 -0
- data/lib/arjdbc/postgresql/adapter.rb +1498 -0
- data/lib/arjdbc/postgresql/base/array_parser.rb +95 -0
- data/lib/arjdbc/postgresql/base/oid.rb +412 -0
- data/lib/arjdbc/postgresql/base/pgconn.rb +8 -0
- data/lib/arjdbc/postgresql/base/schema_definitions.rb +132 -0
- data/lib/arjdbc/postgresql/column.rb +640 -0
- data/lib/arjdbc/postgresql/connection_methods.rb +44 -0
- data/lib/arjdbc/postgresql/explain_support.rb +53 -0
- data/lib/arjdbc/postgresql/oid/bytea.rb +3 -0
- data/lib/arjdbc/postgresql/oid_types.rb +265 -0
- data/lib/arjdbc/postgresql/schema_creation.rb +60 -0
- data/lib/arjdbc/railtie.rb +11 -0
- data/lib/arjdbc/sqlite3.rb +3 -0
- data/lib/arjdbc/sqlite3/adapter.rb +654 -0
- data/lib/arjdbc/sqlite3/connection_methods.rb +36 -0
- data/lib/arjdbc/sqlite3/explain_support.rb +29 -0
- data/lib/arjdbc/sybase.rb +2 -0
- data/lib/arjdbc/sybase/adapter.rb +47 -0
- data/lib/arjdbc/tasks.rb +13 -0
- data/lib/arjdbc/tasks/database_tasks.rb +66 -0
- data/lib/arjdbc/tasks/databases.rake +91 -0
- data/lib/arjdbc/tasks/databases3.rake +239 -0
- data/lib/arjdbc/tasks/databases4.rake +39 -0
- data/lib/arjdbc/tasks/db2_database_tasks.rb +104 -0
- data/lib/arjdbc/tasks/derby_database_tasks.rb +95 -0
- data/lib/arjdbc/tasks/h2_database_tasks.rb +31 -0
- data/lib/arjdbc/tasks/hsqldb_database_tasks.rb +70 -0
- data/lib/arjdbc/tasks/jdbc_database_tasks.rb +169 -0
- data/lib/arjdbc/tasks/mssql_database_tasks.rb +46 -0
- data/lib/arjdbc/tasks/oracle/enhanced_structure_dump.rb +297 -0
- data/lib/arjdbc/tasks/oracle_database_tasks.rb +65 -0
- data/lib/arjdbc/util/quoted_cache.rb +60 -0
- data/lib/arjdbc/util/serialized_attributes.rb +98 -0
- data/lib/arjdbc/util/table_copier.rb +108 -0
- data/lib/arjdbc/version.rb +8 -0
- data/lib/generators/jdbc/USAGE +9 -0
- data/lib/generators/jdbc/jdbc_generator.rb +17 -0
- data/pom.xml +285 -0
- data/rails_generators/jdbc_generator.rb +15 -0
- data/rails_generators/templates/config/initializers/jdbc.rb +10 -0
- data/rails_generators/templates/lib/tasks/jdbc.rake +11 -0
- data/rakelib/01-tomcat.rake +51 -0
- data/rakelib/02-test.rake +151 -0
- data/rakelib/bundler_ext.rb +11 -0
- data/rakelib/db.rake +58 -0
- data/rakelib/rails.rake +77 -0
- data/src/java/arjdbc/ArJdbcModule.java +288 -0
- data/src/java/arjdbc/db2/DB2Module.java +77 -0
- data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +128 -0
- data/src/java/arjdbc/derby/DerbyModule.java +180 -0
- data/src/java/arjdbc/derby/DerbyRubyJdbcConnection.java +153 -0
- data/src/java/arjdbc/firebird/FirebirdRubyJdbcConnection.java +190 -0
- data/src/java/arjdbc/h2/H2Module.java +50 -0
- data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +86 -0
- data/src/java/arjdbc/hsqldb/HSQLDBModule.java +74 -0
- data/src/java/arjdbc/informix/InformixRubyJdbcConnection.java +76 -0
- data/src/java/arjdbc/jdbc/AdapterJavaService.java +43 -0
- data/src/java/arjdbc/jdbc/Callable.java +44 -0
- data/src/java/arjdbc/jdbc/ConnectionFactory.java +77 -0
- data/src/java/arjdbc/jdbc/DataSourceConnectionFactory.java +156 -0
- data/src/java/arjdbc/jdbc/DriverConnectionFactory.java +63 -0
- data/src/java/arjdbc/jdbc/DriverWrapper.java +128 -0
- data/src/java/arjdbc/jdbc/JdbcConnectionFactory.java +32 -0
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +4541 -0
- data/src/java/arjdbc/jdbc/SQLBlock.java +54 -0
- data/src/java/arjdbc/jdbc/WithResultSet.java +37 -0
- data/src/java/arjdbc/mssql/MSSQLModule.java +91 -0
- data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +193 -0
- data/src/java/arjdbc/mysql/MySQLModule.java +140 -0
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +456 -0
- data/src/java/arjdbc/oracle/OracleModule.java +81 -0
- data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +477 -0
- data/src/java/arjdbc/postgresql/ByteaUtils.java +171 -0
- data/src/java/arjdbc/postgresql/DriverImplementation.java +78 -0
- data/src/java/arjdbc/postgresql/PGDriverImplementation.java +535 -0
- data/src/java/arjdbc/postgresql/PostgreSQLModule.java +189 -0
- data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +489 -0
- data/src/java/arjdbc/sqlite3/SQLite3Module.java +93 -0
- data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +405 -0
- data/src/java/arjdbc/util/CallResultSet.java +826 -0
- data/src/java/arjdbc/util/DateTimeUtils.java +517 -0
- data/src/java/arjdbc/util/NumberUtils.java +50 -0
- data/src/java/arjdbc/util/ObjectSupport.java +65 -0
- data/src/java/arjdbc/util/QuotingUtils.java +139 -0
- data/src/java/arjdbc/util/StringCache.java +60 -0
- data/src/java/arjdbc/util/StringHelper.java +155 -0
- metadata +288 -0
data/Rakefile.jdbc
ADDED
@@ -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,63 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = 'activerecord-jdbc-adapter-ficoh'
|
5
|
+
gem.platform = 'java'
|
6
|
+
|
7
|
+
path = File.expand_path('lib/arjdbc/version.rb', File.dirname(__FILE__))
|
8
|
+
gem.version = File.read(path).match( /.*VERSION\s*=\s*['"](.*)['"]/m )[1]
|
9
|
+
|
10
|
+
gem.authors = ['Nick Sieger', 'Ola Bini', 'Karol Bucek', 'JRuby contributors']
|
11
|
+
gem.email = ['nick@nicksieger.com', 'ola.bini@gmail.com', 'self@kares.org']
|
12
|
+
gem.homepage = 'https://github.com/jruby/activerecord-jdbc-adapter'
|
13
|
+
gem.license = "BSD"
|
14
|
+
gem.summary = 'JDBC adapter for ActiveRecord, for use within JRuby on Rails.'
|
15
|
+
gem.description = "" <<
|
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."
|
23
|
+
|
24
|
+
gem.require_paths = ["lib"]
|
25
|
+
|
26
|
+
gem.files = `git ls-files`.split("\n").
|
27
|
+
reject { |f| f =~ /^(activerecord-jdbc[^-]|jdbc-)/ }. # gem directories
|
28
|
+
reject { |f| f =~ /^(bench|test)/ }. # not sure if including tests is useful
|
29
|
+
reject { |f| f =~ /^(gemfiles)/ } # no tests - no Gemfile_s appraised ...
|
30
|
+
gem.test_files = gem.files.grep /^test\//
|
31
|
+
|
32
|
+
if ENV['RELEASE'] == 'true'
|
33
|
+
gem.files << 'lib/arjdbc/jdbc/adapter_java.jar' # no longer in git since 1.4
|
34
|
+
else
|
35
|
+
gem.extensions << 'Rakefile' # to support auto-building .jar with :git paths
|
36
|
+
gem.add_dependency 'jar-dependencies', '~> 0.1.13' # development not enough!
|
37
|
+
gem.add_development_dependency 'ruby-maven', '~> 3.1.1.0.11'
|
38
|
+
|
39
|
+
gem.requirements << "jar mysql:mysql-connector-java, 5.1.33, :scope => :compile"
|
40
|
+
gem.requirements << "jar org.postgresql:postgresql, 9.4-1200-jdbc4, :scope => :compile"
|
41
|
+
# TODO Bundler won't copy, since the extension is supposed to live elsewhere ?!
|
42
|
+
#gem.files << 'lib/arjdbc/jdbc/adapter_java.jar'
|
43
|
+
|
44
|
+
#gem.requirements << "jar 'org.postgresql:postgresql, 9.4-1200-jdbc4, :scope => :compile"
|
45
|
+
# compilation .jar dependencies for extension (at least until `mvn') :
|
46
|
+
#gem.add_development_dependency 'jdbc-mysql', '~> 5.1.33'
|
47
|
+
#gem.add_development_dependency 'jdbc-postgres', '~> 9.4-1200'
|
48
|
+
end
|
49
|
+
|
50
|
+
# NOTE: we're leaving it out as it seems to be confusing to users as
|
51
|
+
# gem install activerecord-jdbc-adapter installs latest activerecord!
|
52
|
+
#gem.add_dependency 'activerecord', '>= 2.2'
|
53
|
+
|
54
|
+
gem.add_development_dependency 'rake', '~> 10.4.2'
|
55
|
+
|
56
|
+
#gem.add_development_dependency 'test-unit', '~> 2.5.4'
|
57
|
+
#gem.add_development_dependency 'test-unit-context', '>= 0.4.0'
|
58
|
+
#gem.add_development_dependency 'mocha', '~> 0.13.1'
|
59
|
+
|
60
|
+
#gem.rdoc_options = ["--main", "README.md", "-SHN", "-f", "darkfish"]
|
61
|
+
|
62
|
+
end
|
63
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'arjdbc/db2'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'arjdbc/derby'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'arjdbc/firebird'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'arjdbc/h2'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'arjdbc/hsqldb'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'arjdbc/informix'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'arjdbc/jdbc'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'arjdbc/jdbc'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'arjdbc/mysql'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'arjdbc/mssql'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'arjdbc/mysql'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'arjdbc/mysql'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'arjdbc/oracle'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'arjdbc/postgresql'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'arjdbc/sqlite3'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'arjdbc/mssql'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'arjdbc'
|
@@ -0,0 +1,64 @@
|
|
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
|
+
# We need to force the downgrade of the api here (commented conditional below)because of patch to make
|
14
|
+
# TOP work instead of LIMIT for MSSQL support. When moving to a newer version of rails and arel this change
|
15
|
+
# should be reverted if TOP support is included else a similar change will need to be done on that new version
|
16
|
+
# as well.
|
17
|
+
# if ToSql.instance_method('visit_Arel_Nodes_SelectCore').arity == 1
|
18
|
+
def do_visit_select_core(x, a) # a = nil
|
19
|
+
visit_Arel_Nodes_SelectCore(x)
|
20
|
+
end
|
21
|
+
# else # > AREL 4.0
|
22
|
+
# def do_visit_select_core(x, a)
|
23
|
+
# visit_Arel_Nodes_SelectCore(x, a)
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
if ArJdbc::AR42
|
30
|
+
if Arel::VERSION < '6.0.2'
|
31
|
+
def limit_for(limit_or_node)
|
32
|
+
if limit_or_node.respond_to?(:expr)
|
33
|
+
expr = limit_or_node.expr
|
34
|
+
# NOTE(uwe): Different behavior for Arel 6.0.0 and 6.0.2
|
35
|
+
expr.respond_to?(:value) ? expr.value.to_i : expr.to_i
|
36
|
+
else
|
37
|
+
limit_or_node
|
38
|
+
end
|
39
|
+
end
|
40
|
+
else
|
41
|
+
def limit_for(limit_or_node)
|
42
|
+
limit_or_node.respond_to?(:expr) ? limit_or_node.expr.to_i : limit_or_node
|
43
|
+
end
|
44
|
+
end
|
45
|
+
else
|
46
|
+
def limit_for(limit_or_node)
|
47
|
+
limit_or_node.respond_to?(:expr) ? limit_or_node.expr.to_i : limit_or_node
|
48
|
+
end
|
49
|
+
end
|
50
|
+
module_function :limit_for
|
51
|
+
|
52
|
+
def node_value(node)
|
53
|
+
return nil unless node
|
54
|
+
case expr = node.expr
|
55
|
+
when NilClass then nil
|
56
|
+
when Numeric then expr
|
57
|
+
when Arel::Nodes::Unary then expr.expr
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
ToSql.send(:include, ArJdbcCompat)
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +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
|
+
|
14
|
+
module Arel
|
15
|
+
module Visitors
|
16
|
+
class DB2 < Arel::Visitors::ToSql
|
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
|
123
|
+
end
|
124
|
+
|
125
|
+
private
|
126
|
+
|
127
|
+
def add_limit_offset(sql, o, limit, offset)
|
128
|
+
@connection.replace_limit_offset! sql, limit, offset, o.orders
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
Arel::Collectors::Bind.class_eval do
|
136
|
+
attr_reader :parts
|
137
|
+
end if defined? Arel::Collectors::Bind
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'arel/visitors/compat'
|
2
|
+
|
3
|
+
module Arel
|
4
|
+
module Visitors
|
5
|
+
class Derby < Arel::Visitors::ToSql
|
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
|
56
|
+
end
|
57
|
+
|
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
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|