activerecord-jdbc-alt-adapter 51.7.0-java → 52.2.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -3
- data/.travis.yml +24 -28
- data/Gemfile +2 -3
- data/README.md +27 -19
- data/Rakefile +4 -30
- data/activerecord-jdbc-adapter.gemspec +2 -2
- data/activerecord-jdbc-alt-adapter.gemspec +4 -4
- data/lib/arel/visitors/sqlserver.rb +2 -1
- data/lib/arjdbc/abstract/core.rb +12 -2
- data/lib/arjdbc/abstract/database_statements.rb +22 -8
- data/lib/arjdbc/abstract/statement_cache.rb +1 -0
- data/lib/arjdbc/db2/adapter.rb +77 -8
- data/lib/arjdbc/db2/as400.rb +12 -0
- data/lib/arjdbc/db2/column.rb +3 -0
- data/lib/arjdbc/db2/connection_methods.rb +4 -0
- data/lib/arjdbc/jdbc/adapter.rb +4 -6
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/column.rb +14 -6
- data/lib/arjdbc/jdbc.rb +7 -0
- data/lib/arjdbc/mssql/adapter.rb +20 -32
- data/lib/arjdbc/mssql/connection_methods.rb +1 -5
- data/lib/arjdbc/mssql/database_limits.rb +29 -0
- data/lib/arjdbc/mssql/database_statements.rb +41 -1
- data/lib/arjdbc/mssql/explain_support.rb +6 -1
- data/lib/arjdbc/mssql/quoting.rb +9 -2
- data/lib/arjdbc/mssql/schema_creation.rb +2 -1
- data/lib/arjdbc/mssql/schema_dumper.rb +1 -1
- data/lib/arjdbc/mssql/schema_statements.rb +11 -3
- data/lib/arjdbc/mssql/transaction.rb +3 -3
- data/lib/arjdbc/mssql.rb +1 -1
- data/lib/arjdbc/mysql/adapter.rb +20 -4
- data/lib/arjdbc/mysql/connection_methods.rb +7 -13
- data/lib/arjdbc/postgresql/adapter.rb +23 -20
- data/lib/arjdbc/postgresql/column.rb +3 -6
- data/lib/arjdbc/postgresql/connection_methods.rb +1 -3
- data/lib/arjdbc/postgresql/oid_types.rb +6 -11
- data/lib/arjdbc/sqlite3/adapter.rb +86 -91
- data/lib/arjdbc/sqlite3/connection_methods.rb +0 -1
- data/lib/arjdbc/tasks/database_tasks.rb +1 -0
- data/lib/arjdbc/tasks/sqlite_database_tasks_patch.rb +17 -0
- data/lib/arjdbc/version.rb +1 -1
- data/rakelib/01-tomcat.rake +2 -2
- data/rakelib/02-test.rake +2 -0
- data/rakelib/rails.rake +1 -1
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +10 -65
- data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +38 -282
- data/src/java/arjdbc/postgresql/PostgreSQLResult.java +69 -4
- data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +69 -13
- data/src/java/arjdbc/util/DateTimeUtils.java +17 -28
- data/src/java/arjdbc/util/PG.java +8 -0
- metadata +15 -12
- data/lib/activerecord-jdbc-alt-adapter.rb +0 -1
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
ArJdbc::ConnectionMethods.module_eval do
|
3
3
|
def postgresql_connection(config)
|
4
|
-
config = config.deep_dup
|
5
4
|
# NOTE: this isn't "really" necessary but Rails (in tests) assumes being able to :
|
6
5
|
# ActiveRecord::Base.postgresql_connection ActiveRecord::Base.configurations['arunit'].merge(:insert_returning => false)
|
7
6
|
# ... while using symbols by default but than configurations returning string keys ;(
|
@@ -17,8 +16,7 @@ ArJdbc::ConnectionMethods.module_eval do
|
|
17
16
|
::Jdbc::Postgres.load_driver(:require) if defined?(::Jdbc::Postgres.load_driver)
|
18
17
|
rescue LoadError # assuming driver.jar is on the class-path
|
19
18
|
end
|
20
|
-
driver =
|
21
|
-
defined?(::Jdbc::Postgres.driver_name) ? ::Jdbc::Postgres.driver_name : 'org.postgresql.Driver')
|
19
|
+
driver = config[:driver] ||= 'org.postgresql.Driver'
|
22
20
|
|
23
21
|
host = config[:host] ||= ( config[:hostaddr] || ENV['PGHOST'] || 'localhost' )
|
24
22
|
port = config[:port] ||= ( ENV['PGPORT'] || 5432 )
|
@@ -88,12 +88,6 @@ module ArJdbc
|
|
88
88
|
@extensions ||= super
|
89
89
|
end
|
90
90
|
|
91
|
-
# @override
|
92
|
-
def lookup_cast_type(sql_type)
|
93
|
-
oid = execute("SELECT #{quote(sql_type)}::regtype::oid", "SCHEMA")
|
94
|
-
super oid.first['oid'].to_i
|
95
|
-
end
|
96
|
-
|
97
91
|
def get_oid_type(oid, fmod, column_name, sql_type = '') # :nodoc:
|
98
92
|
if !type_map.key?(oid)
|
99
93
|
load_additional_types(type_map, oid)
|
@@ -120,7 +114,7 @@ module ArJdbc
|
|
120
114
|
|
121
115
|
private
|
122
116
|
|
123
|
-
def initialize_type_map(m)
|
117
|
+
def initialize_type_map(m = type_map)
|
124
118
|
register_class_with_limit m, 'int2', Type::Integer
|
125
119
|
register_class_with_limit m, 'int4', Type::Integer
|
126
120
|
register_class_with_limit m, 'int8', Type::Integer
|
@@ -136,13 +130,13 @@ module ArJdbc
|
|
136
130
|
register_class_with_limit m, 'bit', OID::Bit
|
137
131
|
register_class_with_limit m, 'varbit', OID::BitVarying
|
138
132
|
m.alias_type 'timestamptz', 'timestamp'
|
139
|
-
m.register_type 'date',
|
133
|
+
m.register_type 'date', OID::Date.new
|
140
134
|
|
141
135
|
m.register_type 'money', OID::Money.new
|
142
136
|
m.register_type 'bytea', OID::Bytea.new
|
143
137
|
m.register_type 'point', OID::Point.new
|
144
138
|
m.register_type 'hstore', OID::Hstore.new
|
145
|
-
m.register_type 'json',
|
139
|
+
m.register_type 'json', Type::Json.new
|
146
140
|
m.register_type 'jsonb', OID::Jsonb.new
|
147
141
|
m.register_type 'cidr', OID::Cidr.new
|
148
142
|
m.register_type 'inet', OID::Inet.new
|
@@ -228,7 +222,7 @@ module ArJdbc
|
|
228
222
|
query += "WHERE t.typname = '%s' AND ns.nspname = ANY(current_schemas(true))" % oid
|
229
223
|
end
|
230
224
|
else
|
231
|
-
query += initializer.query_conditions_for_initial_load
|
225
|
+
query += initializer.query_conditions_for_initial_load
|
232
226
|
end
|
233
227
|
|
234
228
|
records = execute(query, 'SCHEMA')
|
@@ -242,12 +236,13 @@ module ArJdbc
|
|
242
236
|
ActiveRecord::Type.register(:bit_varying, OID::BitVarying, adapter: :postgresql)
|
243
237
|
ActiveRecord::Type.register(:binary, OID::Bytea, adapter: :postgresql)
|
244
238
|
ActiveRecord::Type.register(:cidr, OID::Cidr, adapter: :postgresql)
|
239
|
+
ActiveRecord::Type.register(:date, OID::Date, adapter: :postgresql)
|
245
240
|
ActiveRecord::Type.register(:datetime, OID::DateTime, adapter: :postgresql)
|
246
241
|
ActiveRecord::Type.register(:decimal, OID::Decimal, adapter: :postgresql)
|
247
242
|
ActiveRecord::Type.register(:enum, OID::Enum, adapter: :postgresql)
|
248
243
|
ActiveRecord::Type.register(:hstore, OID::Hstore, adapter: :postgresql)
|
249
244
|
ActiveRecord::Type.register(:inet, OID::Inet, adapter: :postgresql)
|
250
|
-
ActiveRecord::Type.register(:json,
|
245
|
+
ActiveRecord::Type.register(:json, Type::Json, adapter: :postgresql)
|
251
246
|
ActiveRecord::Type.register(:jsonb, OID::Jsonb, adapter: :postgresql)
|
252
247
|
ActiveRecord::Type.register(:money, OID::Money, adapter: :postgresql)
|
253
248
|
ActiveRecord::Type.register(:point, OID::Point, adapter: :postgresql)
|
@@ -12,6 +12,7 @@ require "active_record/connection_adapters/sqlite3/schema_creation"
|
|
12
12
|
require "active_record/connection_adapters/sqlite3/schema_definitions"
|
13
13
|
require "active_record/connection_adapters/sqlite3/schema_dumper"
|
14
14
|
require "active_record/connection_adapters/sqlite3/schema_statements"
|
15
|
+
require "active_support/core_ext/class/attribute"
|
15
16
|
|
16
17
|
module ArJdbc
|
17
18
|
# All the code in this module is a copy of ConnectionAdapters::SQLite3Adapter from active_record 5.
|
@@ -33,11 +34,10 @@ module ArJdbc
|
|
33
34
|
|
34
35
|
# DIFFERENCE: FQN
|
35
36
|
include ::ActiveRecord::ConnectionAdapters::SQLite3::Quoting
|
36
|
-
include ::ActiveRecord::ConnectionAdapters::SQLite3::ColumnDumper
|
37
37
|
include ::ActiveRecord::ConnectionAdapters::SQLite3::SchemaStatements
|
38
38
|
|
39
39
|
NATIVE_DATABASE_TYPES = {
|
40
|
-
primary_key: "
|
40
|
+
primary_key: "integer PRIMARY KEY AUTOINCREMENT NOT NULL",
|
41
41
|
string: { name: "varchar" },
|
42
42
|
text: { name: "text" },
|
43
43
|
integer: { name: "integer" },
|
@@ -47,9 +47,13 @@ module ArJdbc
|
|
47
47
|
time: { name: "time" },
|
48
48
|
date: { name: "date" },
|
49
49
|
binary: { name: "blob" },
|
50
|
-
boolean: { name: "boolean" }
|
50
|
+
boolean: { name: "boolean" },
|
51
|
+
json: { name: "json" },
|
51
52
|
}
|
52
53
|
|
54
|
+
# DIFFERENCE: class_attribute in original adapter is moved down to our section which is a class
|
55
|
+
# since we cannot define it here in the module (original source this is a class).
|
56
|
+
|
53
57
|
class StatementPool < ConnectionAdapters::StatementPool
|
54
58
|
private
|
55
59
|
|
@@ -58,24 +62,10 @@ module ArJdbc
|
|
58
62
|
end
|
59
63
|
end
|
60
64
|
|
61
|
-
def update_table_definition(table_name, base) # :nodoc:
|
62
|
-
# DIFFERENCE: FQN
|
63
|
-
::ActiveRecord::ConnectionAdapters::SQLite3::Table.new(table_name, base)
|
64
|
-
end
|
65
|
-
|
66
|
-
def schema_creation # :nodoc:
|
67
|
-
# DIFFERENCE: FQN
|
68
|
-
::ActiveRecord::ConnectionAdapters::SQLite3::SchemaCreation.new self
|
69
|
-
end
|
70
|
-
|
71
|
-
def arel_visitor # :nodoc:
|
72
|
-
Arel::Visitors::SQLite.new(self)
|
73
|
-
end
|
74
|
-
|
75
65
|
def initialize(connection, logger, connection_options, config)
|
76
66
|
super(connection, logger, config)
|
77
67
|
|
78
|
-
@active =
|
68
|
+
@active = true
|
79
69
|
@statements = StatementPool.new(self.class.type_cast_config_to_integer(config[:statement_limit]))
|
80
70
|
|
81
71
|
configure_connection
|
@@ -93,12 +83,6 @@ module ArJdbc
|
|
93
83
|
sqlite_version >= "3.8.0"
|
94
84
|
end
|
95
85
|
|
96
|
-
# Returns true, since this connection adapter supports prepared statement
|
97
|
-
# caching.
|
98
|
-
def supports_statement_cache?
|
99
|
-
true
|
100
|
-
end
|
101
|
-
|
102
86
|
def requires_reloading?
|
103
87
|
true
|
104
88
|
end
|
@@ -120,7 +104,7 @@ module ArJdbc
|
|
120
104
|
end
|
121
105
|
|
122
106
|
def active?
|
123
|
-
@active
|
107
|
+
@active
|
124
108
|
end
|
125
109
|
|
126
110
|
# Disconnects from the database if already connected. Otherwise, this
|
@@ -248,53 +232,6 @@ module ArJdbc
|
|
248
232
|
|
249
233
|
# SCHEMA STATEMENTS ========================================
|
250
234
|
|
251
|
-
def new_column_from_field(table_name, field) # :nondoc:
|
252
|
-
case field["dflt_value"]
|
253
|
-
when /^null$/i
|
254
|
-
field["dflt_value"] = nil
|
255
|
-
when /^'(.*)'$/m
|
256
|
-
field["dflt_value"] = $1.gsub("''", "'")
|
257
|
-
when /^"(.*)"$/m
|
258
|
-
field["dflt_value"] = $1.gsub('""', '"')
|
259
|
-
end
|
260
|
-
|
261
|
-
collation = field["collation"]
|
262
|
-
sql_type = field["type"]
|
263
|
-
type_metadata = fetch_type_metadata(sql_type)
|
264
|
-
new_column(field["name"], field["dflt_value"], type_metadata, field["notnull"].to_i == 0, table_name, nil, collation)
|
265
|
-
end
|
266
|
-
|
267
|
-
# Returns an array of indexes for the given table.
|
268
|
-
def indexes(table_name, name = nil) #:nodoc:
|
269
|
-
if name
|
270
|
-
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
271
|
-
Passing name to #indexes is deprecated without replacement.
|
272
|
-
MSG
|
273
|
-
end
|
274
|
-
|
275
|
-
exec_query("PRAGMA index_list(#{quote_table_name(table_name)})", "SCHEMA").map do |row|
|
276
|
-
sql = <<-SQL
|
277
|
-
SELECT sql
|
278
|
-
FROM sqlite_master
|
279
|
-
WHERE name=#{quote(row['name'])} AND type='index'
|
280
|
-
UNION ALL
|
281
|
-
SELECT sql
|
282
|
-
FROM sqlite_temp_master
|
283
|
-
WHERE name=#{quote(row['name'])} AND type='index'
|
284
|
-
SQL
|
285
|
-
index_sql = exec_query(sql).first["sql"]
|
286
|
-
match = /\sWHERE\s+(.+)$/i.match(index_sql)
|
287
|
-
where = match[1] if match
|
288
|
-
IndexDefinition.new(
|
289
|
-
table_name,
|
290
|
-
row["name"],
|
291
|
-
row["unique"] != 0,
|
292
|
-
exec_query("PRAGMA index_info('#{row['name']}')", "SCHEMA").map { |col|
|
293
|
-
col["name"]
|
294
|
-
}, nil, nil, where)
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
235
|
def primary_keys(table_name) # :nodoc:
|
299
236
|
pks = table_structure(table_name).select { |f| f["pk"] > 0 }
|
300
237
|
pks.sort_by { |f| f["pk"] }.map { |f| f["name"] }
|
@@ -314,19 +251,20 @@ module ArJdbc
|
|
314
251
|
rename_table_indexes(table_name, new_name)
|
315
252
|
end
|
316
253
|
|
317
|
-
#
|
318
|
-
|
319
|
-
|
320
|
-
type
|
254
|
+
# DIFFERENCE: deprecated causes a JRuby 9.1 bug where "super" calls itself -> do inline
|
255
|
+
def valid_alter_table_type?(type, options = {})
|
256
|
+
ActiveSupport::Deprecation.deprecation_warning(__method__)
|
257
|
+
!invalid_alter_table_type?(type, options)
|
321
258
|
end
|
259
|
+
#deprecate :valid_alter_table_type?
|
322
260
|
|
323
261
|
def add_column(table_name, column_name, type, options = {}) #:nodoc:
|
324
|
-
if
|
325
|
-
super(table_name, column_name, type, options)
|
326
|
-
else
|
262
|
+
if invalid_alter_table_type?(type, options)
|
327
263
|
alter_table(table_name) do |definition|
|
328
264
|
definition.column(column_name, type, options)
|
329
265
|
end
|
266
|
+
else
|
267
|
+
super
|
330
268
|
end
|
331
269
|
end
|
332
270
|
|
@@ -391,8 +329,32 @@ module ArJdbc
|
|
391
329
|
::ActiveRecord::ConnectionAdapters::ForeignKeyDefinition.new(table_name, row["table"], options)
|
392
330
|
end
|
393
331
|
end
|
332
|
+
|
333
|
+
def insert_fixtures(rows, table_name)
|
334
|
+
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
335
|
+
`insert_fixtures` is deprecated and will be removed in the next version of Rails.
|
336
|
+
Consider using `insert_fixtures_set` for performance improvement.
|
337
|
+
MSG
|
338
|
+
insert_fixtures_set(table_name => rows)
|
339
|
+
end
|
340
|
+
|
341
|
+
def insert_fixtures_set(fixture_set, tables_to_delete = [])
|
342
|
+
disable_referential_integrity do
|
343
|
+
transaction(requires_new: true) do
|
344
|
+
tables_to_delete.each { |table| delete "DELETE FROM #{quote_table_name(table)}", "Fixture Delete" }
|
345
|
+
|
346
|
+
fixture_set.each do |table_name, rows|
|
347
|
+
rows.each { |row| insert_fixture(row, table_name) }
|
348
|
+
end
|
349
|
+
end
|
350
|
+
end
|
351
|
+
end
|
394
352
|
|
395
353
|
private
|
354
|
+
def initialize_type_map(m = type_map)
|
355
|
+
super
|
356
|
+
register_class_with_limit m, %r(int)i, SQLite3Integer
|
357
|
+
end
|
396
358
|
|
397
359
|
def table_structure(table_name)
|
398
360
|
structure = exec_query("PRAGMA table_info(#{quote_table_name(table_name)})", "SCHEMA")
|
@@ -400,7 +362,13 @@ module ArJdbc
|
|
400
362
|
table_structure_with_collation(table_name, structure)
|
401
363
|
end
|
402
364
|
alias column_definitions table_structure
|
403
|
-
|
365
|
+
|
366
|
+
# See: https://www.sqlite.org/lang_altertable.html
|
367
|
+
# SQLite has an additional restriction on the ALTER TABLE statement
|
368
|
+
def invalid_alter_table_type?(type, options)
|
369
|
+
type.to_sym == :primary_key || options[:primary_key]
|
370
|
+
end
|
371
|
+
|
404
372
|
def alter_table(table_name, options = {}) #:nodoc:
|
405
373
|
altered_table_name = "a#{table_name}"
|
406
374
|
caller = lambda { |definition| yield definition if block_given? }
|
@@ -551,23 +519,28 @@ module ArJdbc
|
|
551
519
|
end
|
552
520
|
end
|
553
521
|
|
554
|
-
def
|
555
|
-
|
556
|
-
::ActiveRecord::ConnectionAdapters::SQLite3::TableDefinition.new(*args)
|
557
|
-
end
|
558
|
-
|
559
|
-
def extract_foreign_key_action(specifier)
|
560
|
-
case specifier
|
561
|
-
when "CASCADE"; :cascade
|
562
|
-
when "SET NULL"; :nullify
|
563
|
-
when "RESTRICT"; :restrict
|
564
|
-
end
|
522
|
+
def arel_visitor
|
523
|
+
Arel::Visitors::SQLite.new(self)
|
565
524
|
end
|
566
525
|
|
567
526
|
def configure_connection
|
568
527
|
execute("PRAGMA foreign_keys = ON", "SCHEMA")
|
569
528
|
end
|
529
|
+
|
530
|
+
# DIFFERENCE: FQN
|
531
|
+
class SQLite3Integer < ::ActiveRecord::Type::Integer # :nodoc:
|
532
|
+
private
|
533
|
+
def _limit
|
534
|
+
# INTEGER storage class can be stored 8 bytes value.
|
535
|
+
# See https://www.sqlite.org/datatype3.html#storage_classes_and_datatypes
|
536
|
+
limit || 8
|
537
|
+
end
|
538
|
+
end
|
539
|
+
|
540
|
+
# DIFFERENCE: FQN
|
541
|
+
::ActiveRecord::Type.register(:integer, SQLite3Integer, adapter: :sqlite3)
|
570
542
|
end
|
543
|
+
# DIFFERENCE: A registration here is moved down to concrete class so we are not registering part of an adapter.
|
571
544
|
end
|
572
545
|
|
573
546
|
module ActiveRecord::ConnectionAdapters
|
@@ -677,6 +650,25 @@ module ActiveRecord::ConnectionAdapters
|
|
677
650
|
include ArJdbc::Abstract::StatementCache
|
678
651
|
include ArJdbc::Abstract::TransactionSupport
|
679
652
|
|
653
|
+
# Note: This is part of original AR sqlite3_adapter.rb and not an override by us. This is to just
|
654
|
+
# work around our copy of Sqlite3Adapter being a module above and not a class.
|
655
|
+
##
|
656
|
+
# :singleton-method:
|
657
|
+
# Indicates whether boolean values are stored in sqlite3 databases as 1
|
658
|
+
# and 0 or 't' and 'f'. Leaving <tt>ActiveRecord::ConnectionAdapters::SQLite3Adapter.represent_boolean_as_integer</tt>
|
659
|
+
# set to false is deprecated. SQLite databases have used 't' and 'f' to
|
660
|
+
# serialize boolean values and must have old data converted to 1 and 0
|
661
|
+
# (its native boolean serialization) before setting this flag to true.
|
662
|
+
# Conversion can be accomplished by setting up a rake task which runs
|
663
|
+
#
|
664
|
+
# ExampleModel.where("boolean_column = 't'").update_all(boolean_column: 1)
|
665
|
+
# ExampleModel.where("boolean_column = 'f'").update_all(boolean_column: 0)
|
666
|
+
# for all models and all boolean columns, after which the flag must be set
|
667
|
+
# to true by adding the following to your <tt>application.rb</tt> file:
|
668
|
+
#
|
669
|
+
# Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true
|
670
|
+
class_attribute :represent_boolean_as_integer, default: false
|
671
|
+
|
680
672
|
def supports_transaction_isolation?
|
681
673
|
false
|
682
674
|
end
|
@@ -704,5 +696,8 @@ module ActiveRecord::ConnectionAdapters
|
|
704
696
|
def self.jdbc_connection_class
|
705
697
|
::ActiveRecord::ConnectionAdapters::SQLite3JdbcConnection
|
706
698
|
end
|
699
|
+
|
700
|
+
# Note: This is not an override of ours but a moved line from AR Sqlite3Adapter to register ours vs our copied module (which would be their class).
|
701
|
+
# ActiveSupport.run_load_hooks(:active_record_sqlite3adapter, SQLite3Adapter)
|
707
702
|
end
|
708
703
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
ArJdbc::ConnectionMethods.module_eval do
|
3
3
|
def sqlite3_connection(config)
|
4
|
-
config = config.deep_dup
|
5
4
|
config[:adapter_spec] ||= ::ArJdbc::SQLite3
|
6
5
|
config[:adapter_class] = ActiveRecord::ConnectionAdapters::SQLite3Adapter unless config.key?(:adapter_class)
|
7
6
|
|
@@ -9,6 +9,7 @@ module ArJdbc
|
|
9
9
|
register_tasks(/mariadb/, ActiveRecord::Tasks::MySQLDatabaseTasks)
|
10
10
|
|
11
11
|
require 'arjdbc/tasks/jdbc_database_tasks'
|
12
|
+
require 'arjdbc/tasks/sqlite_database_tasks_patch'
|
12
13
|
require 'arjdbc/tasks/mssql_database_tasks'
|
13
14
|
#require 'arjdbc/tasks/db2_database_tasks'
|
14
15
|
#require 'arjdbc/tasks/derby_database_tasks'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# patch SQLiteDatabaseTasks for JRuby
|
2
|
+
# The problem is that JRuby does not yet support the "out:" option for
|
3
|
+
# Kernel.system(). Uses plain output redirection as a workaround.
|
4
|
+
|
5
|
+
require 'active_record/tasks/sqlite_database_tasks'
|
6
|
+
require 'shellwords'
|
7
|
+
|
8
|
+
module ActiveRecord
|
9
|
+
module Tasks
|
10
|
+
class SQLiteDatabaseTasks
|
11
|
+
private
|
12
|
+
def run_cmd(cmd, args, out)
|
13
|
+
`#{cmd} #{Shellwords.join(args)} > "#{out}"`
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/arjdbc/version.rb
CHANGED
data/rakelib/01-tomcat.rake
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
namespace :'tomcat-jndi' do # contains a FS JNDI impl (for tests)
|
2
2
|
|
3
|
-
TOMCAT_MAVEN_REPO = '
|
3
|
+
TOMCAT_MAVEN_REPO = 'http://repo2.maven.org/maven2/org/apache/tomcat'
|
4
4
|
TOMCAT_VERSION = '7.0.54'
|
5
5
|
|
6
6
|
DOWNLOAD_DIR = File.expand_path('../test/jars', File.dirname(__FILE__))
|
@@ -48,4 +48,4 @@ namespace :'tomcat-jndi' do # contains a FS JNDI impl (for tests)
|
|
48
48
|
rm jar_path if File.exist?(jar_path)
|
49
49
|
end
|
50
50
|
|
51
|
-
end
|
51
|
+
end
|
data/rakelib/02-test.rake
CHANGED
@@ -76,6 +76,8 @@ end
|
|
76
76
|
test_task_for adapter, :desc => "Run tests against #{adapter} (ensure driver is on class-path)"
|
77
77
|
end
|
78
78
|
|
79
|
+
#test_task_for :MSSQL, :name => 'test_sqlserver', :driver => nil, :database_name => 'MS-SQL using SQLJDBC'
|
80
|
+
|
79
81
|
test_task_for :AS400, :desc => "Run tests against AS400 (DB2) (ensure driver is on class-path)",
|
80
82
|
:files => FileList["test/db2*_test.rb"] + FileList["test/db/db2/*_test.rb"]
|
81
83
|
|
data/rakelib/rails.rake
CHANGED
@@ -57,7 +57,7 @@ namespace :rails do
|
|
57
57
|
ruby_opts_string += " -C \"#{ar_path}\""
|
58
58
|
ruby_opts_string += " -rbundler/setup"
|
59
59
|
ruby_opts_string += " -rminitest -rminitest/excludes" unless ENV['NO_EXCLUDES'].eql?('true')
|
60
|
-
file_list = ENV["TEST"] ? FileList[ ENV["TEST"]
|
60
|
+
file_list = ENV["TEST"] ? FileList[ ENV["TEST"] ] : test_files_finder.call
|
61
61
|
file_list_string = file_list.map { |fn| "\"#{fn}\"" }.join(' ')
|
62
62
|
# test_loader_code = "-e \"ARGV.each{|f| require f}\"" # :direct
|
63
63
|
option_list = ( ENV["TESTOPTS"] || ENV["TESTOPT"] || ENV["TEST_OPTS"] || '' )
|
@@ -487,7 +487,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
487
487
|
savepoint = ((IRubyObject) savepoint).toJava(Savepoint.class);
|
488
488
|
}
|
489
489
|
|
490
|
-
releaseSavepoint(
|
490
|
+
connection.releaseSavepoint((Savepoint) savepoint);
|
491
491
|
return context.nil;
|
492
492
|
}
|
493
493
|
catch (SQLException e) {
|
@@ -495,11 +495,6 @@ public class RubyJdbcConnection extends RubyObject {
|
|
495
495
|
}
|
496
496
|
}
|
497
497
|
|
498
|
-
// MSSQL doesn't support releasing savepoints so we make it possible to override the actual release action
|
499
|
-
protected void releaseSavepoint(final Connection connection, final Savepoint savepoint) throws SQLException {
|
500
|
-
connection.releaseSavepoint(savepoint);
|
501
|
-
}
|
502
|
-
|
503
498
|
protected static RuntimeException newSavepointNotSetError(final ThreadContext context, final IRubyObject name, final String op) {
|
504
499
|
RubyClass StatementInvalid = ActiveRecord(context).getClass("StatementInvalid");
|
505
500
|
return context.runtime.newRaiseException(StatementInvalid, "could not " + op + " savepoint: '" + name + "' (not set)");
|
@@ -727,10 +722,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
727
722
|
|
728
723
|
private void connectImpl(final boolean forceConnection) throws SQLException {
|
729
724
|
setConnection( forceConnection ? newConnection() : null );
|
730
|
-
if (forceConnection)
|
731
|
-
if (getConnectionImpl() == null) throw new SQLException("Didn't get a connection. Wrong URL?");
|
732
|
-
configureConnection();
|
733
|
-
}
|
725
|
+
if ( forceConnection ) configureConnection();
|
734
726
|
}
|
735
727
|
|
736
728
|
@JRubyMethod(name = "read_only?")
|
@@ -888,31 +880,15 @@ public class RubyJdbcConnection extends RubyObject {
|
|
888
880
|
return mapQueryResult(context, connection, resultSet);
|
889
881
|
}
|
890
882
|
|
891
|
-
private static String[] createStatementPk(IRubyObject pk) {
|
892
|
-
String[] statementPk;
|
893
|
-
if (pk instanceof RubyArray) {
|
894
|
-
RubyArray ary = (RubyArray) pk;
|
895
|
-
int size = ary.size();
|
896
|
-
statementPk = new String[size];
|
897
|
-
for (int i = 0; i < size; i++) {
|
898
|
-
statementPk[i] = sqlString(ary.eltInternal(i));
|
899
|
-
}
|
900
|
-
} else {
|
901
|
-
statementPk = new String[] { sqlString(pk) };
|
902
|
-
}
|
903
|
-
return statementPk;
|
904
|
-
}
|
905
|
-
|
906
883
|
/**
|
907
884
|
* Executes an INSERT SQL statement
|
908
885
|
* @param context
|
909
886
|
* @param sql
|
910
|
-
* @param pk Rails PK
|
911
887
|
* @return ActiveRecord::Result
|
912
888
|
* @throws SQLException
|
913
889
|
*/
|
914
|
-
@JRubyMethod(name = "
|
915
|
-
public IRubyObject
|
890
|
+
@JRubyMethod(name = "execute_insert", required = 1)
|
891
|
+
public IRubyObject execute_insert(final ThreadContext context, final IRubyObject sql) {
|
916
892
|
return withConnection(context, new Callable<IRubyObject>() {
|
917
893
|
public IRubyObject call(final Connection connection) throws SQLException {
|
918
894
|
Statement statement = null;
|
@@ -920,13 +896,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
920
896
|
try {
|
921
897
|
|
922
898
|
statement = createStatement(context, connection);
|
923
|
-
|
924
|
-
if (pk == context.nil || pk == context.fals || !supportsGeneratedKeys(connection)) {
|
925
|
-
statement.executeUpdate(query, Statement.RETURN_GENERATED_KEYS);
|
926
|
-
} else {
|
927
|
-
statement.executeUpdate(query, createStatementPk(pk));
|
928
|
-
}
|
929
|
-
|
899
|
+
statement.executeUpdate(query, Statement.RETURN_GENERATED_KEYS);
|
930
900
|
return mapGeneratedKeys(context, connection, statement);
|
931
901
|
|
932
902
|
} catch (final SQLException e) {
|
@@ -939,35 +909,23 @@ public class RubyJdbcConnection extends RubyObject {
|
|
939
909
|
});
|
940
910
|
}
|
941
911
|
|
942
|
-
@Deprecated
|
943
|
-
@JRubyMethod(name = "execute_insert", required = 1)
|
944
|
-
public IRubyObject execute_insert(final ThreadContext context, final IRubyObject sql) {
|
945
|
-
return execute_insert_pk(context, sql, context.nil);
|
946
|
-
}
|
947
|
-
|
948
912
|
/**
|
949
913
|
* Executes an INSERT SQL statement using a prepared statement
|
950
914
|
* @param context
|
951
915
|
* @param sql
|
952
916
|
* @param binds RubyArray of values to be bound to the query
|
953
|
-
* @param pk Rails PK
|
954
917
|
* @return ActiveRecord::Result
|
955
918
|
* @throws SQLException
|
956
919
|
*/
|
957
|
-
@JRubyMethod(name = "
|
958
|
-
public IRubyObject
|
959
|
-
final IRubyObject pk) {
|
920
|
+
@JRubyMethod(name = "execute_insert", required = 2)
|
921
|
+
public IRubyObject execute_insert(final ThreadContext context, final IRubyObject sql, final IRubyObject binds) {
|
960
922
|
return withConnection(context, new Callable<IRubyObject>() {
|
961
923
|
public IRubyObject call(final Connection connection) throws SQLException {
|
962
924
|
PreparedStatement statement = null;
|
963
925
|
final String query = sqlString(sql);
|
964
926
|
try {
|
965
|
-
if (pk == context.nil || pk == context.fals || !supportsGeneratedKeys(connection)) {
|
966
|
-
statement = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
|
967
|
-
} else {
|
968
|
-
statement = connection.prepareStatement(query, createStatementPk(pk));
|
969
|
-
}
|
970
927
|
|
928
|
+
statement = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
|
971
929
|
setStatementParameters(context, connection, statement, (RubyArray) binds);
|
972
930
|
statement.executeUpdate();
|
973
931
|
return mapGeneratedKeys(context, connection, statement);
|
@@ -982,12 +940,6 @@ public class RubyJdbcConnection extends RubyObject {
|
|
982
940
|
});
|
983
941
|
}
|
984
942
|
|
985
|
-
@Deprecated
|
986
|
-
@JRubyMethod(name = "execute_insert", required = 2)
|
987
|
-
public IRubyObject execute_insert(final ThreadContext context, final IRubyObject binds, final IRubyObject sql) {
|
988
|
-
return execute_insert_pk(context, sql, binds, context.nil);
|
989
|
-
}
|
990
|
-
|
991
943
|
/**
|
992
944
|
* Executes an UPDATE (DELETE) SQL statement
|
993
945
|
* @param context
|
@@ -2947,9 +2899,8 @@ public class RubyJdbcConnection extends RubyObject {
|
|
2947
2899
|
value = value.callMethod(context, "to_date");
|
2948
2900
|
}
|
2949
2901
|
|
2950
|
-
// NOTE:
|
2951
|
-
|
2952
|
-
statement.setDate(index, Date.valueOf(value.callMethod(context, "to_s", context.runtime.newSymbol("db")).toString()));
|
2902
|
+
// NOTE: assuming Date#to_s does right ...
|
2903
|
+
statement.setDate(index, Date.valueOf(value.toString()));
|
2953
2904
|
}
|
2954
2905
|
|
2955
2906
|
protected void setBooleanParameter(final ThreadContext context,
|
@@ -3976,12 +3927,6 @@ public class RubyJdbcConnection extends RubyObject {
|
|
3976
3927
|
}
|
3977
3928
|
}
|
3978
3929
|
|
3979
|
-
public static void debugMessage(final ThreadContext context, final IRubyObject obj) {
|
3980
|
-
if ( isDebug(context.runtime) ) {
|
3981
|
-
debugMessage(context.runtime, obj.callMethod(context, "inspect"));
|
3982
|
-
}
|
3983
|
-
}
|
3984
|
-
|
3985
3930
|
public static void debugMessage(final Ruby runtime, final String msg, final Object e) {
|
3986
3931
|
if ( isDebug(runtime) ) {
|
3987
3932
|
final PrintStream out = runtime != null ? runtime.getOut() : System.out;
|