activerecord-jdbc-adapter 1.3.0.beta2 → 1.3.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +14 -8
- data/.travis.yml +40 -31
- data/.yardopts +4 -0
- data/Appraisals +2 -5
- data/CONTRIBUTING.md +46 -0
- data/Gemfile +21 -4
- data/Gemfile.lock +42 -17
- data/{History.txt → History.md} +142 -75
- data/README.md +102 -104
- data/RUNNING_TESTS.md +76 -0
- data/Rakefile.jdbc +20 -0
- data/activerecord-jdbc-adapter.gemspec +35 -18
- data/gemfiles/rails23.gemfile +4 -3
- data/gemfiles/rails23.gemfile.lock +9 -6
- data/gemfiles/rails30.gemfile +4 -3
- data/gemfiles/rails30.gemfile.lock +9 -6
- data/gemfiles/rails31.gemfile +4 -3
- data/gemfiles/rails31.gemfile.lock +9 -6
- data/gemfiles/rails32.gemfile +4 -3
- data/gemfiles/rails32.gemfile.lock +17 -14
- data/gemfiles/rails40.gemfile +5 -5
- data/gemfiles/rails40.gemfile.lock +17 -69
- data/lib/active_record/connection_adapters/firebird_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/sqlserver_adapter.rb +1 -0
- data/lib/arel/visitors/compat.rb +22 -3
- data/lib/arel/visitors/db2.rb +8 -4
- data/lib/arel/visitors/derby.rb +14 -13
- data/lib/arel/visitors/firebird.rb +5 -4
- data/lib/arel/visitors/hsqldb.rb +11 -9
- data/lib/arel/visitors/sql_server.rb +89 -61
- data/lib/arjdbc.rb +1 -1
- data/lib/arjdbc/db2/adapter.rb +181 -212
- data/lib/arjdbc/db2/as400.rb +31 -18
- data/lib/arjdbc/db2/column.rb +167 -0
- data/lib/arjdbc/db2/connection_methods.rb +2 -0
- data/lib/arjdbc/derby/adapter.rb +206 -107
- data/lib/arjdbc/derby/connection_methods.rb +4 -9
- data/lib/arjdbc/firebird.rb +1 -0
- data/lib/arjdbc/firebird/adapter.rb +202 -64
- data/lib/arjdbc/firebird/connection_methods.rb +20 -0
- data/lib/arjdbc/h2/adapter.rb +56 -36
- data/lib/arjdbc/hsqldb/adapter.rb +99 -68
- data/lib/arjdbc/jdbc/adapter.rb +474 -265
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/adapter_require.rb +8 -7
- data/lib/arjdbc/jdbc/arel_support.rb +132 -0
- data/lib/arjdbc/jdbc/base_ext.rb +8 -7
- data/lib/arjdbc/jdbc/callbacks.rb +16 -10
- data/lib/arjdbc/jdbc/column.rb +25 -3
- data/lib/arjdbc/jdbc/connection.rb +28 -55
- data/lib/arjdbc/jdbc/extension.rb +14 -14
- data/lib/arjdbc/jdbc/java.rb +6 -3
- data/lib/arjdbc/jdbc/jdbc.rake +1 -1
- data/lib/arjdbc/jdbc/quoted_primary_key.rb +2 -2
- data/lib/arjdbc/jdbc/rake_tasks.rb +1 -1
- data/lib/arjdbc/jdbc/type_converter.rb +5 -2
- data/lib/arjdbc/mssql/adapter.rb +160 -280
- data/lib/arjdbc/mssql/column.rb +182 -0
- data/lib/arjdbc/mssql/connection_methods.rb +37 -4
- data/lib/arjdbc/mssql/explain_support.rb +13 -21
- data/lib/arjdbc/mssql/limit_helpers.rb +79 -42
- data/lib/arjdbc/mssql/lock_methods.rb +77 -0
- data/lib/arjdbc/mssql/utils.rb +11 -11
- data/lib/arjdbc/mysql/adapter.rb +165 -247
- data/lib/arjdbc/mysql/column.rb +123 -0
- data/lib/arjdbc/mysql/connection_methods.rb +3 -6
- data/lib/arjdbc/oracle/adapter.rb +282 -288
- data/lib/arjdbc/oracle/column.rb +122 -0
- data/lib/arjdbc/oracle/connection_methods.rb +3 -0
- data/lib/arjdbc/postgresql/adapter.rb +336 -574
- data/lib/arjdbc/postgresql/column.rb +458 -0
- data/lib/arjdbc/postgresql/connection_methods.rb +1 -2
- data/lib/arjdbc/postgresql/schema_creation.rb +38 -0
- data/lib/arjdbc/sqlite3/adapter.rb +189 -145
- data/lib/arjdbc/sqlite3/explain_support.rb +1 -1
- data/lib/arjdbc/tasks/oracle/enhanced_structure_dump.rb +8 -8
- data/lib/arjdbc/util/quoted_cache.rb +60 -0
- data/lib/arjdbc/util/table_copier.rb +110 -0
- data/lib/arjdbc/version.rb +6 -7
- data/pom.xml +56 -2
- data/rakelib/02-test.rake +72 -83
- data/rakelib/db.rake +29 -17
- data/src/java/arjdbc/ArJdbcModule.java +21 -18
- data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +84 -12
- data/src/java/arjdbc/derby/DerbyModule.java +140 -143
- data/src/java/arjdbc/derby/DerbyRubyJdbcConnection.java +58 -7
- data/src/java/arjdbc/h2/H2Module.java +43 -0
- data/src/java/arjdbc/informix/InformixRubyJdbcConnection.java +7 -6
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +1223 -648
- data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +24 -23
- data/src/java/arjdbc/mysql/MySQLModule.java +33 -32
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +147 -30
- data/src/java/arjdbc/oracle/OracleModule.java +13 -13
- data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +114 -6
- data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +166 -36
- data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +101 -19
- data/src/java/arjdbc/util/QuotingUtils.java +19 -19
- metadata +240 -394
- data/bench/bench_attributes.rb +0 -13
- data/bench/bench_attributes_new.rb +0 -14
- data/bench/bench_create.rb +0 -12
- data/bench/bench_find_all.rb +0 -12
- data/bench/bench_find_all_mt.rb +0 -25
- data/bench/bench_model.rb +0 -85
- data/bench/bench_new.rb +0 -12
- data/bench/bench_new_valid.rb +0 -12
- data/bench/bench_valid.rb +0 -13
- data/lib/arel/engines/sql/compilers/db2_compiler.rb +0 -9
- data/lib/arel/engines/sql/compilers/derby_compiler.rb +0 -6
- data/lib/arel/engines/sql/compilers/h2_compiler.rb +0 -6
- data/lib/arel/engines/sql/compilers/hsqldb_compiler.rb +0 -15
- data/lib/arel/engines/sql/compilers/jdbc_compiler.rb +0 -6
- data/lib/arel/engines/sql/compilers/mssql_compiler.rb +0 -46
- data/lib/arjdbc/jdbc/missing_functionality_helper.rb +0 -98
- data/lib/arjdbc/mssql/lock_helpers.rb +0 -76
- data/lib/arjdbc/mssql/tsql_methods.rb +0 -58
- data/lib/arjdbc/postgresql/column_cast.rb +0 -134
- data/test/activerecord/connections/native_jdbc_mysql/connection.rb +0 -25
- data/test/activerecord/jall.sh +0 -7
- data/test/activerecord/jtest.sh +0 -3
- data/test/assets/flowers.jpg +0 -0
- data/test/binary.rb +0 -67
- data/test/db/db2.rb +0 -43
- data/test/db/db2/binary_test.rb +0 -6
- data/test/db/db2/has_many_through_test.rb +0 -6
- data/test/db/db2/rake_test.rb +0 -82
- data/test/db/db2/rake_test_data.sql +0 -35
- data/test/db/db2/reset_column_information_test.rb +0 -5
- data/test/db/db2/serialize_test.rb +0 -6
- data/test/db/db2/simple_test.rb +0 -81
- data/test/db/db2/test_helper.rb +0 -6
- data/test/db/db2/unit_test.rb +0 -73
- data/test/db/derby.rb +0 -12
- data/test/db/derby/binary_test.rb +0 -6
- data/test/db/derby/migration_test.rb +0 -74
- data/test/db/derby/rake_test.rb +0 -96
- data/test/db/derby/reset_column_information_test.rb +0 -6
- data/test/db/derby/row_locking_test.rb +0 -20
- data/test/db/derby/schema_dump_test.rb +0 -5
- data/test/db/derby/serialize_test.rb +0 -6
- data/test/db/derby/simple_test.rb +0 -173
- data/test/db/derby/test_helper.rb +0 -6
- data/test/db/derby/unit_test.rb +0 -32
- data/test/db/derby/xml_column_test.rb +0 -17
- data/test/db/h2.rb +0 -11
- data/test/db/h2/binary_test.rb +0 -6
- data/test/db/h2/change_column_test.rb +0 -68
- data/test/db/h2/identity_column_test.rb +0 -35
- data/test/db/h2/offset_test.rb +0 -49
- data/test/db/h2/rake_test.rb +0 -98
- data/test/db/h2/schema_dump_test.rb +0 -29
- data/test/db/h2/serialize_test.rb +0 -6
- data/test/db/h2/simple_test.rb +0 -56
- data/test/db/hsqldb.rb +0 -11
- data/test/db/hsqldb/binary_test.rb +0 -6
- data/test/db/hsqldb/rake_test.rb +0 -101
- data/test/db/hsqldb/schema_dump_test.rb +0 -19
- data/test/db/hsqldb/serialize_test.rb +0 -6
- data/test/db/hsqldb/simple_test.rb +0 -17
- data/test/db/informix.rb +0 -13
- data/test/db/jdbc.rb +0 -16
- data/test/db/jdbc_derby.rb +0 -14
- data/test/db/jdbc_h2.rb +0 -17
- data/test/db/jdbc_mysql.rb +0 -13
- data/test/db/jdbc_postgres.rb +0 -23
- data/test/db/jndi_config.rb +0 -32
- data/test/db/jndi_pooled_config.rb +0 -32
- data/test/db/mssql.rb +0 -11
- data/test/db/mssql/binary_test.rb +0 -6
- data/test/db/mssql/exec_proc_test.rb +0 -46
- data/test/db/mssql/identity_insert_test.rb +0 -18
- data/test/db/mssql/ignore_system_views_test.rb +0 -40
- data/test/db/mssql/limit_offset_test.rb +0 -190
- data/test/db/mssql/multibyte_test.rb +0 -16
- data/test/db/mssql/multiple_connections_test.rb +0 -71
- data/test/db/mssql/rake_test.rb +0 -143
- data/test/db/mssql/reset_column_information_test.rb +0 -6
- data/test/db/mssql/row_locking_test.rb +0 -7
- data/test/db/mssql/serialize_test.rb +0 -6
- data/test/db/mssql/simple_test.rb +0 -140
- data/test/db/mssql/transaction_test.rb +0 -6
- data/test/db/mssql/types_test.rb +0 -205
- data/test/db/mssql/unit_test.rb +0 -249
- data/test/db/mysql.rb +0 -4
- data/test/db/mysql/_rails_test_mysql.32.out +0 -6585
- data/test/db/mysql/binary_test.rb +0 -6
- data/test/db/mysql/connection_test.rb +0 -51
- data/test/db/mysql/index_length_test.rb +0 -58
- data/test/db/mysql/multibyte_test.rb +0 -10
- data/test/db/mysql/nonstandard_primary_key_test.rb +0 -39
- data/test/db/mysql/rake_test.rb +0 -97
- data/test/db/mysql/reset_column_information_test.rb +0 -6
- data/test/db/mysql/schema_dump_test.rb +0 -228
- data/test/db/mysql/serialize_test.rb +0 -6
- data/test/db/mysql/simple_test.rb +0 -187
- data/test/db/mysql/statement_escaping_test.rb +0 -46
- data/test/db/mysql/transaction_test.rb +0 -6
- data/test/db/mysql/types_test.rb +0 -30
- data/test/db/mysql/unit_test.rb +0 -93
- data/test/db/mysql_config.rb +0 -7
- data/test/db/oracle.rb +0 -27
- data/test/db/oracle/binary_test.rb +0 -6
- data/test/db/oracle/limit_test.rb +0 -24
- data/test/db/oracle/multibyte_test.rb +0 -22
- data/test/db/oracle/rake_test.rb +0 -100
- data/test/db/oracle/reset_column_information_test.rb +0 -6
- data/test/db/oracle/serialize_test.rb +0 -6
- data/test/db/oracle/simple_test.rb +0 -140
- data/test/db/oracle/specific_test.rb +0 -180
- data/test/db/oracle/transaction_test.rb +0 -31
- data/test/db/oracle/unit_test.rb +0 -31
- data/test/db/postgres.rb +0 -11
- data/test/db/postgres/_rails_test_postgres.32.out +0 -6405
- data/test/db/postgres/a_custom_primary_key_test.rb +0 -50
- data/test/db/postgres/active_schema_unit_test.rb +0 -68
- data/test/db/postgres/array_type_test.rb +0 -101
- data/test/db/postgres/binary_test.rb +0 -6
- data/test/db/postgres/connection_test.rb +0 -63
- data/test/db/postgres/data_types_test.rb +0 -703
- data/test/db/postgres/hstore_test.rb +0 -200
- data/test/db/postgres/information_schema_leak_test.rb +0 -30
- data/test/db/postgres/json_test.rb +0 -86
- data/test/db/postgres/ltree_test.rb +0 -51
- data/test/db/postgres/mixed_case_test.rb +0 -29
- data/test/db/postgres/native_types_test.rb +0 -124
- data/test/db/postgres/rake_test.rb +0 -117
- data/test/db/postgres/reserved_test.rb +0 -22
- data/test/db/postgres/reset_column_information_test.rb +0 -6
- data/test/db/postgres/row_locking_test.rb +0 -21
- data/test/db/postgres/schema_dump_test.rb +0 -95
- data/test/db/postgres/schema_test.rb +0 -115
- data/test/db/postgres/simple_test.rb +0 -260
- data/test/db/postgres/table_alias_length_test.rb +0 -16
- data/test/db/postgres/transaction_test.rb +0 -6
- data/test/db/postgres/unit_test.rb +0 -31
- data/test/db/postgres_config.rb +0 -10
- data/test/db/sqlite3.rb +0 -6
- data/test/db/sqlite3/_rails_test_sqlite3.32.out +0 -6274
- data/test/db/sqlite3/has_many_though_test.rb +0 -6
- data/test/db/sqlite3/rake_test.rb +0 -71
- data/test/db/sqlite3/reset_column_information_test.rb +0 -6
- data/test/db/sqlite3/schema_dump_test.rb +0 -6
- data/test/db/sqlite3/serialize_test.rb +0 -6
- data/test/db/sqlite3/simple_test.rb +0 -268
- data/test/db/sqlite3/transaction_test.rb +0 -32
- data/test/db/sqlite3/type_conversion_test.rb +0 -104
- data/test/has_many_through.rb +0 -61
- data/test/informix_simple_test.rb +0 -48
- data/test/jdbc/db2.rb +0 -36
- data/test/jdbc/oracle.rb +0 -34
- data/test/jdbc_column_test.rb +0 -23
- data/test/jdbc_common.rb +0 -16
- data/test/jdbc_connection_test.rb +0 -196
- data/test/jndi_callbacks_test.rb +0 -33
- data/test/jndi_test.rb +0 -55
- data/test/manualTestDatabase.rb +0 -191
- data/test/models/add_not_null_column_to_table.rb +0 -9
- data/test/models/auto_id.rb +0 -15
- data/test/models/binary.rb +0 -18
- data/test/models/custom_pk_name.rb +0 -15
- data/test/models/data_types.rb +0 -40
- data/test/models/entry.rb +0 -41
- data/test/models/mixed_case.rb +0 -22
- data/test/models/reserved_word.rb +0 -15
- data/test/models/rights_and_roles.rb +0 -57
- data/test/models/string_id.rb +0 -17
- data/test/models/thing.rb +0 -17
- data/test/models/topic.rb +0 -32
- data/test/models/validates_uniqueness_of_string.rb +0 -19
- data/test/rails/mysql.rb +0 -13
- data/test/rails/sqlite3/version.rb +0 -6
- data/test/rails_stub.rb +0 -31
- data/test/rake_test_support.rb +0 -298
- data/test/row_locking.rb +0 -102
- data/test/schema_dump.rb +0 -182
- data/test/serialize.rb +0 -275
- data/test/shared_helper.rb +0 -35
- data/test/simple.rb +0 -1317
- data/test/sybase_jtds_simple_test.rb +0 -28
- data/test/sybase_reset_column_information_test.rb +0 -6
- data/test/test_helper.rb +0 -304
- data/test/transaction.rb +0 -109
data/bench/bench_attributes.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/bench_model'
|
2
|
-
|
3
|
-
puts "Widget.find(:first).attributes"
|
4
|
-
Benchmark.bm do |make|
|
5
|
-
TIMES.times do
|
6
|
-
w = Widget.find(:first)
|
7
|
-
make.report do
|
8
|
-
10_000.times do
|
9
|
-
w.attributes # rails makes copy for every call
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/bench_model'
|
2
|
-
|
3
|
-
puts "w = Widget.find(:first); Widget.new(w.attributes)"
|
4
|
-
Benchmark.bm do |make|
|
5
|
-
TIMES.times do
|
6
|
-
w = Widget.find(:first)
|
7
|
-
params = w.attributes
|
8
|
-
make.report do
|
9
|
-
10_000.times do
|
10
|
-
Widget.new(params)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
data/bench/bench_create.rb
DELETED
data/bench/bench_find_all.rb
DELETED
data/bench/bench_find_all_mt.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/bench_model'
|
2
|
-
|
3
|
-
Benchmark.bm do |make|
|
4
|
-
TIMES.times do
|
5
|
-
make.report do
|
6
|
-
thrs = []
|
7
|
-
errs = 0
|
8
|
-
10.times do
|
9
|
-
thrs << Thread.new do
|
10
|
-
1000.times do
|
11
|
-
begin
|
12
|
-
Widget.find(:all)
|
13
|
-
rescue Exception => e
|
14
|
-
errs += 1
|
15
|
-
Widget.logger.warn e.to_s
|
16
|
-
end
|
17
|
-
end
|
18
|
-
Widget.clear_active_connections!
|
19
|
-
end
|
20
|
-
end
|
21
|
-
thrs.each {|t| t.join}
|
22
|
-
puts "errors: #{errs}" if errs > 0
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
data/bench/bench_model.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
=begin
|
2
|
-
|
3
|
-
* This scripts looks for an optional argv0 which is number of times to
|
4
|
-
execute the particular benchmark this file is getting required into. argv1
|
5
|
-
is an optional parameter which represents the number of rows to create.
|
6
|
-
* Use ENV['LOGGER'] (=severe|warn|info|debug) to turn on the logger
|
7
|
-
* Add ActiveRecord to load path to use a specific (non-gem version) for testing (e.g., edge).
|
8
|
-
|
9
|
-
+----------+------+-----+---------+-----------------+----------------+
|
10
|
-
| Field | Type | Null | Key | Default | Extra |
|
11
|
-
+-------------+--------------+------+-----+---------+----------------+
|
12
|
-
| id | int(11) | NO | PRI | NULL | auto_increment |
|
13
|
-
| name | varchar(255) | YES | | NULL | |
|
14
|
-
| description | text | YES | | NULL | |
|
15
|
-
| created_at | datetime | YES | | NULL | |
|
16
|
-
| updated_at | datetime | YES | | NULL | |
|
17
|
-
+-------------+--------------+------+-----+---------+----------------+
|
18
|
-
=end
|
19
|
-
|
20
|
-
TIMES = (ARGV[0] || 5).to_i
|
21
|
-
ROW_COUNT = (ARGV[1] || 10).to_i
|
22
|
-
|
23
|
-
ENV["RAILS_ENV"] = "production"
|
24
|
-
begin
|
25
|
-
print "Loading ActiveRecord w/o gems..."
|
26
|
-
require 'active_record'
|
27
|
-
require 'active_record/version'
|
28
|
-
puts "version #{ActiveRecord::VERSION::STRING}"
|
29
|
-
rescue LoadError
|
30
|
-
puts "FAILED."
|
31
|
-
print "Loading ActiveRecord with gems..."
|
32
|
-
require 'rubygems'
|
33
|
-
gem 'activerecord'
|
34
|
-
puts "version #{Gem.loaded_specs['activerecord'].version.version}"
|
35
|
-
require 'active_record'
|
36
|
-
end
|
37
|
-
require 'benchmark'
|
38
|
-
|
39
|
-
if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
|
40
|
-
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
41
|
-
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../drivers/mysql/lib'
|
42
|
-
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../adapters/mysql/lib'
|
43
|
-
require 'active_record/connection_adapters/jdbcmysql_adapter'
|
44
|
-
end
|
45
|
-
|
46
|
-
if ENV['LOGGER']
|
47
|
-
require 'logger'
|
48
|
-
ActiveRecord::Base.logger = Logger.new(File.expand_path(File.dirname(__FILE__) + "/debug.log"))
|
49
|
-
lvl = %(DEBUG INFO WARN ERROR FATAL).detect {|s| s =~ /#{ENV['LOGGER'].upcase}/}
|
50
|
-
ActiveRecord::Base.logger.level = lvl && Logger.const_get(lvl) || Logger::INFO
|
51
|
-
else
|
52
|
-
ActiveRecord::Base.logger = Logger.new($stdout)
|
53
|
-
ActiveRecord::Base.logger.level = Logger::UNKNOWN
|
54
|
-
end
|
55
|
-
|
56
|
-
ActiveRecord::Base.establish_connection(
|
57
|
-
:adapter => "mysql",
|
58
|
-
:host => "localhost",
|
59
|
-
:username => "root",
|
60
|
-
:database => "ar_bench",
|
61
|
-
:pool => 10,
|
62
|
-
:wait_timeout => 0.5
|
63
|
-
)
|
64
|
-
|
65
|
-
class CreateWidgets < ActiveRecord::Migration
|
66
|
-
def self.up
|
67
|
-
create_table :widgets do |t|
|
68
|
-
t.string :name
|
69
|
-
t.text :description
|
70
|
-
t.timestamps
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
CreateWidgets.up unless ActiveRecord::Base.connection.tables.include?("widgets")
|
76
|
-
|
77
|
-
class Widget < ActiveRecord::Base; end
|
78
|
-
Widget.destroy_all if Widget.count > ROW_COUNT
|
79
|
-
count = Widget.count
|
80
|
-
while (count < ROW_COUNT)
|
81
|
-
Widget.create!(:name => "bench#{count}", :description => "Bench record#{count}")
|
82
|
-
count = Widget.count
|
83
|
-
end
|
84
|
-
|
85
|
-
ActiveRecord::Base.clear_active_connections!
|
data/bench/bench_new.rb
DELETED
data/bench/bench_new_valid.rb
DELETED
data/bench/bench_valid.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
module Arel
|
2
|
-
module SqlCompiler
|
3
|
-
class HsqldbCompiler < GenericCompiler
|
4
|
-
def select_sql
|
5
|
-
# HSQLDB needs to add LIMIT in right after SELECT
|
6
|
-
query = super
|
7
|
-
offset = relation.skipped
|
8
|
-
limit = relation.taken
|
9
|
-
@engine.connection.add_limit_offset!(query, :limit => limit,
|
10
|
-
:offset => offset) if offset || limit
|
11
|
-
query
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
module Arel
|
2
|
-
module SqlCompiler
|
3
|
-
class MSSQLCompiler < GenericCompiler
|
4
|
-
def select_sql
|
5
|
-
projections = @relation.projections
|
6
|
-
offset = relation.skipped
|
7
|
-
limit = relation.taken
|
8
|
-
if Count === projections.first && projections.size == 1 &&
|
9
|
-
(relation.taken.present? || relation.wheres.present?) && relation.joins(self).blank?
|
10
|
-
subquery = [
|
11
|
-
"SELECT * FROM #{relation.from_clauses}", build_clauses
|
12
|
-
].join ' '
|
13
|
-
@engine.connection.add_limit_offset!(subquery, :limit => limit, :offset => offset) if offset || limit
|
14
|
-
query = "SELECT COUNT(*) AS count_id FROM (#{subquery}) AS subquery"
|
15
|
-
else
|
16
|
-
query = [
|
17
|
-
"SELECT #{relation.select_clauses.join(', ')}",
|
18
|
-
"FROM #{relation.from_clauses}",
|
19
|
-
build_clauses
|
20
|
-
].compact.join ' '
|
21
|
-
@engine.connection.add_limit_offset!(query, :limit => limit, :offset => offset) if offset || limit
|
22
|
-
end
|
23
|
-
query
|
24
|
-
end
|
25
|
-
|
26
|
-
def build_clauses
|
27
|
-
joins = relation.joins(self)
|
28
|
-
wheres = relation.where_clauses
|
29
|
-
groups = relation.group_clauses
|
30
|
-
havings = relation.having_clauses
|
31
|
-
orders = relation.order_clauses
|
32
|
-
|
33
|
-
clauses = [ "",
|
34
|
-
joins,
|
35
|
-
("WHERE #{wheres.join(' AND ')}" unless wheres.empty?),
|
36
|
-
("GROUP BY #{groups.join(', ')}" unless groups.empty?),
|
37
|
-
("HAVING #{havings.join(' AND ')}" unless havings.empty?),
|
38
|
-
("ORDER BY #{orders.join(', ')}" unless orders.empty?)
|
39
|
-
].compact.join ' '
|
40
|
-
|
41
|
-
clauses << " #{locked}" unless locked.blank?
|
42
|
-
clauses unless clauses.blank?
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,98 +0,0 @@
|
|
1
|
-
module ArJdbc
|
2
|
-
module MissingFunctionalityHelper
|
3
|
-
|
4
|
-
# taken from SQLite adapter, code loosely based on http://git.io/P7tFQA
|
5
|
-
|
6
|
-
def alter_table(table_name, options = {}) #:nodoc:
|
7
|
-
table_name = table_name.to_s.downcase
|
8
|
-
altered_table_name = "a#{table_name}"
|
9
|
-
caller = lambda { |definition| yield definition if block_given? }
|
10
|
-
|
11
|
-
transaction do
|
12
|
-
# A temporary table might improve performance here, but
|
13
|
-
# it doesn't seem to maintain indices across the whole move.
|
14
|
-
move_table(table_name, altered_table_name, options)
|
15
|
-
move_table(altered_table_name, table_name, &caller)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def move_table(from, to, options = {}, &block) #:nodoc:
|
20
|
-
copy_table(from, to, options, &block)
|
21
|
-
drop_table(from)
|
22
|
-
end
|
23
|
-
|
24
|
-
def copy_table(from, to, options = {}) # :nodoc:
|
25
|
-
from_primary_key = primary_key(from)
|
26
|
-
create_table(to, options.merge(:id => false)) do |definition|
|
27
|
-
@definition = definition
|
28
|
-
@definition.primary_key(from_primary_key) if from_primary_key.present?
|
29
|
-
columns(from).each do |column|
|
30
|
-
column_name = options[:rename] ?
|
31
|
-
(options[:rename][column.name] ||
|
32
|
-
options[:rename][column.name.to_sym] ||
|
33
|
-
column.name) : column.name
|
34
|
-
|
35
|
-
next if column_name == from_primary_key
|
36
|
-
|
37
|
-
@definition.column(column_name, column.type,
|
38
|
-
:limit => column.limit, :default => column.default,
|
39
|
-
:precision => column.precision, :scale => column.scale,
|
40
|
-
:null => column.null)
|
41
|
-
end
|
42
|
-
yield @definition if block_given?
|
43
|
-
end
|
44
|
-
|
45
|
-
copy_table_indexes(from, to, options[:rename] || {})
|
46
|
-
copy_table_contents(from, to,
|
47
|
-
@definition.columns.map {|column| column.name},
|
48
|
-
options[:rename] || {})
|
49
|
-
end
|
50
|
-
|
51
|
-
def copy_table_indexes(from, to, rename = {}) #:nodoc:
|
52
|
-
indexes(from).each do |index|
|
53
|
-
name = index.name.downcase
|
54
|
-
if to == "a#{from}"
|
55
|
-
name = "t#{name}"
|
56
|
-
elsif from == "a#{to}"
|
57
|
-
name = name[1..-1]
|
58
|
-
end
|
59
|
-
|
60
|
-
to_column_names = columns(to).map(&:name)
|
61
|
-
columns = index.columns.map { |column| rename[column] || column }
|
62
|
-
columns = columns.select { |column| to_column_names.include?(column) }
|
63
|
-
|
64
|
-
unless columns.empty?
|
65
|
-
# index name can't be the same
|
66
|
-
opts = { :name => name.gsub(/(^|_)(#{from})_/, "\\1#{to}_"), :internal => true }
|
67
|
-
opts[:unique] = true if index.unique
|
68
|
-
add_index(to, columns, opts)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def copy_table_contents(from, to, columns, rename = {}) #:nodoc:
|
74
|
-
column_mappings = Hash[ columns.map { |name| [name, name] } ]
|
75
|
-
rename.each { |a| column_mappings[a.last] = a.first }
|
76
|
-
from_columns = columns(from).collect {|col| col.name}
|
77
|
-
columns = columns.find_all{ |col| from_columns.include?(column_mappings[col]) }
|
78
|
-
quoted_columns = columns.map { |col| quote_column_name(col) } * ','
|
79
|
-
|
80
|
-
quoted_to = quote_table_name(to)
|
81
|
-
|
82
|
-
raw_column_mappings = Hash[ columns(from).map { |c| [c.name, c] } ]
|
83
|
-
|
84
|
-
execute("SELECT * FROM #{quote_table_name(from)}", 'Copy Table').each do |row|
|
85
|
-
sql = "INSERT INTO #{quoted_to} (#{quoted_columns}) VALUES ("
|
86
|
-
|
87
|
-
column_values = columns.map do |col|
|
88
|
-
quote(row[column_mappings[col]], raw_column_mappings[col])
|
89
|
-
end
|
90
|
-
|
91
|
-
sql << column_values * ', '
|
92
|
-
sql << ')'
|
93
|
-
exec_insert sql, 'Copy Table', []
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
end
|
98
|
-
end
|
@@ -1,76 +0,0 @@
|
|
1
|
-
module ArJdbc
|
2
|
-
module MSSQL
|
3
|
-
module LockHelpers
|
4
|
-
module SqlServerAddLock
|
5
|
-
|
6
|
-
SELECT_FROM_WHERE_RE = /\A(\s*SELECT\s.*?)(\sFROM\s)(.*?)(\sWHERE\s.*|)\Z/mi # :nodoc:
|
7
|
-
|
8
|
-
# Microsoft SQL Server uses its own syntax for SELECT .. FOR UPDATE:
|
9
|
-
# SELECT .. FROM table1 WITH(ROWLOCK,UPDLOCK), table2 WITH(ROWLOCK,UPDLOCK) WHERE ..
|
10
|
-
#
|
11
|
-
# This does in-place modification of the passed-in string.
|
12
|
-
def add_lock!(sql, options)
|
13
|
-
if options[:lock] and sql =~ /\A\s*SELECT/mi
|
14
|
-
# Check for and extract the :limit/:offset sub-query
|
15
|
-
if sql =~ /\A(\s*SELECT t\.\* FROM \()(.*)(\) AS t WHERE t._row_num BETWEEN \d+ AND \d+\s*)\Z/m
|
16
|
-
prefix, subselect, suffix = [$1, $2, $3]
|
17
|
-
add_lock!(subselect, options)
|
18
|
-
return sql.replace(prefix + subselect + suffix)
|
19
|
-
end
|
20
|
-
unless sql =~ SELECT_FROM_WHERE_RE
|
21
|
-
# If you get this error, this driver probably needs to be fixed.
|
22
|
-
raise NotImplementedError, "Don't know how to add_lock! to SQL statement: #{sql.inspect}"
|
23
|
-
end
|
24
|
-
select_clause, from_word, from_tables, where_clause = [$1, $2, $3, $4]
|
25
|
-
with_clause = options[:lock].is_a?(String) ? " #{options[:lock]} " : " WITH(ROWLOCK,UPDLOCK) "
|
26
|
-
|
27
|
-
# Split the FROM clause into its constituent tables, and add the with clause after each one.
|
28
|
-
new_from_tables = []
|
29
|
-
s = StringScanner.new(from_tables)
|
30
|
-
until s.eos?
|
31
|
-
prev_pos = s.pos
|
32
|
-
if s.scan_until(/,|(INNER\s+JOIN|CROSS\s+JOIN|(LEFT|RIGHT|FULL)(\s+OUTER)?\s+JOIN)\s+/mi)
|
33
|
-
join_operand = s.pre_match[prev_pos..-1]
|
34
|
-
join_operator = s.matched
|
35
|
-
else
|
36
|
-
join_operand = s.rest
|
37
|
-
join_operator = ""
|
38
|
-
s.terminate
|
39
|
-
end
|
40
|
-
|
41
|
-
# At this point, we have something like:
|
42
|
-
# join_operand == "appointments "
|
43
|
-
# join_operator == "INNER JOIN "
|
44
|
-
# or:
|
45
|
-
# join_operand == "appointment_details AS d1 ON appointments.[id] = d1.[appointment_id]"
|
46
|
-
# join_operator == ""
|
47
|
-
if join_operand =~ /\A(.*)(\s+ON\s+.*)\Z/mi
|
48
|
-
table_spec, on_clause = [$1, $2]
|
49
|
-
else
|
50
|
-
table_spec = join_operand
|
51
|
-
on_clause = ""
|
52
|
-
end
|
53
|
-
|
54
|
-
# Add the "WITH(ROWLOCK,UPDLOCK)" option to the table specification
|
55
|
-
table_spec << with_clause unless table_spec =~ /\A\(\s*SELECT\s+/mi # HACK - this parser isn't so great
|
56
|
-
join_operand = table_spec + on_clause
|
57
|
-
|
58
|
-
# So now we have something like:
|
59
|
-
# join_operand == "appointments WITH(ROWLOCK,UPDLOCK) "
|
60
|
-
# join_operator == "INNER JOIN "
|
61
|
-
# or:
|
62
|
-
# join_operand == "appointment_details AS d1 WITH(ROWLOCK,UPDLOCK) ON appointments.[id] = d1.[appointment_id]"
|
63
|
-
# join_operator == ""
|
64
|
-
|
65
|
-
new_from_tables << join_operand
|
66
|
-
new_from_tables << join_operator
|
67
|
-
end
|
68
|
-
sql.replace([select_clause, from_word, new_from_tables, where_clause].flatten.join)
|
69
|
-
end
|
70
|
-
sql
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|