sequel 4.47.0 → 4.48.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +134 -0
- data/Rakefile +1 -1
- data/doc/release_notes/4.48.0.txt +293 -0
- data/lib/sequel/adapters/ado/access.rb +2 -1
- data/lib/sequel/adapters/do/postgres.rb +5 -2
- data/lib/sequel/adapters/ibmdb.rb +24 -7
- data/lib/sequel/adapters/jdbc.rb +36 -22
- data/lib/sequel/adapters/jdbc/db2.rb +12 -3
- data/lib/sequel/adapters/jdbc/derby.rb +4 -5
- data/lib/sequel/adapters/jdbc/oracle.rb +16 -2
- data/lib/sequel/adapters/jdbc/postgresql.rb +43 -18
- data/lib/sequel/adapters/jdbc/sqlanywhere.rb +9 -7
- data/lib/sequel/adapters/jdbc/sqlserver.rb +11 -4
- data/lib/sequel/adapters/mock.rb +24 -19
- data/lib/sequel/adapters/mysql.rb +17 -16
- data/lib/sequel/adapters/mysql2.rb +4 -5
- data/lib/sequel/adapters/oracle.rb +5 -9
- data/lib/sequel/adapters/postgres.rb +89 -102
- data/lib/sequel/adapters/shared/db2.rb +22 -6
- data/lib/sequel/adapters/shared/mssql.rb +5 -4
- data/lib/sequel/adapters/shared/mysql.rb +75 -24
- data/lib/sequel/adapters/shared/postgres.rb +196 -94
- data/lib/sequel/adapters/shared/sqlanywhere.rb +23 -10
- data/lib/sequel/adapters/shared/sqlite.rb +72 -82
- data/lib/sequel/adapters/sqlanywhere.rb +4 -1
- data/lib/sequel/adapters/sqlite.rb +5 -3
- data/lib/sequel/adapters/swift/postgres.rb +5 -2
- data/lib/sequel/adapters/tinytds.rb +0 -5
- data/lib/sequel/adapters/utils/mysql_mysql2.rb +1 -1
- data/lib/sequel/adapters/utils/pg_types.rb +2 -76
- data/lib/sequel/core.rb +2 -2
- data/lib/sequel/database/connecting.rb +5 -5
- data/lib/sequel/database/dataset.rb +6 -3
- data/lib/sequel/database/misc.rb +1 -1
- data/lib/sequel/database/query.rb +3 -0
- data/lib/sequel/database/schema_methods.rb +1 -1
- data/lib/sequel/dataset/actions.rb +18 -10
- data/lib/sequel/dataset/graph.rb +1 -1
- data/lib/sequel/dataset/misc.rb +1 -0
- data/lib/sequel/dataset/prepared_statements.rb +3 -3
- data/lib/sequel/dataset/query.rb +19 -8
- data/lib/sequel/extensions/core_extensions.rb +4 -1
- data/lib/sequel/extensions/duplicate_columns_handler.rb +1 -1
- data/lib/sequel/extensions/empty_array_ignore_nulls.rb +3 -0
- data/lib/sequel/extensions/filter_having.rb +2 -0
- data/lib/sequel/extensions/freeze_datasets.rb +2 -0
- data/lib/sequel/extensions/from_block.rb +1 -1
- data/lib/sequel/extensions/graph_each.rb +2 -2
- data/lib/sequel/extensions/hash_aliases.rb +2 -0
- data/lib/sequel/extensions/identifier_mangling.rb +0 -7
- data/lib/sequel/extensions/meta_def.rb +2 -0
- data/lib/sequel/extensions/migration.rb +6 -6
- data/lib/sequel/extensions/no_auto_literal_strings.rb +1 -1
- data/lib/sequel/extensions/pagination.rb +1 -1
- data/lib/sequel/extensions/pg_array.rb +207 -130
- data/lib/sequel/extensions/pg_hstore.rb +38 -20
- data/lib/sequel/extensions/pg_inet.rb +18 -6
- data/lib/sequel/extensions/pg_interval.rb +19 -12
- data/lib/sequel/extensions/pg_json.rb +25 -14
- data/lib/sequel/extensions/pg_json_ops.rb +2 -2
- data/lib/sequel/extensions/pg_range.rb +133 -100
- data/lib/sequel/extensions/pg_range_ops.rb +4 -3
- data/lib/sequel/extensions/pg_row.rb +68 -39
- data/lib/sequel/extensions/pg_row_ops.rb +11 -5
- data/lib/sequel/extensions/query_literals.rb +2 -0
- data/lib/sequel/extensions/ruby18_symbol_extensions.rb +2 -0
- data/lib/sequel/extensions/s.rb +1 -1
- data/lib/sequel/extensions/schema_dumper.rb +24 -24
- data/lib/sequel/extensions/sequel_3_dataset_methods.rb +3 -1
- data/lib/sequel/extensions/sequel_4_dataset_methods.rb +83 -0
- data/lib/sequel/extensions/set_overrides.rb +2 -2
- data/lib/sequel/extensions/string_agg.rb +0 -1
- data/lib/sequel/extensions/symbol_aref.rb +0 -4
- data/lib/sequel/model.rb +25 -57
- data/lib/sequel/model/associations.rb +14 -5
- data/lib/sequel/model/base.rb +96 -32
- data/lib/sequel/plugins/association_pks.rb +73 -46
- data/lib/sequel/plugins/association_proxies.rb +1 -1
- data/lib/sequel/plugins/auto_validations.rb +6 -2
- data/lib/sequel/plugins/boolean_readers.rb +1 -1
- data/lib/sequel/plugins/caching.rb +19 -13
- data/lib/sequel/plugins/class_table_inheritance.rb +19 -10
- data/lib/sequel/plugins/column_conflicts.rb +7 -2
- data/lib/sequel/plugins/column_select.rb +1 -1
- data/lib/sequel/plugins/csv_serializer.rb +8 -8
- data/lib/sequel/plugins/defaults_setter.rb +10 -0
- data/lib/sequel/plugins/eager_each.rb +1 -1
- data/lib/sequel/plugins/force_encoding.rb +2 -2
- data/lib/sequel/plugins/hook_class_methods.rb +9 -12
- data/lib/sequel/plugins/identifier_columns.rb +2 -0
- data/lib/sequel/plugins/instance_filters.rb +3 -1
- data/lib/sequel/plugins/instance_hooks.rb +17 -9
- data/lib/sequel/plugins/json_serializer.rb +17 -10
- data/lib/sequel/plugins/lazy_attributes.rb +8 -7
- data/lib/sequel/plugins/modification_detection.rb +3 -0
- data/lib/sequel/plugins/nested_attributes.rb +5 -1
- data/lib/sequel/plugins/pg_array_associations.rb +5 -0
- data/lib/sequel/plugins/prepared_statements.rb +1 -0
- data/lib/sequel/plugins/rcte_tree.rb +4 -4
- data/lib/sequel/plugins/serialization.rb +3 -10
- data/lib/sequel/plugins/single_table_inheritance.rb +2 -2
- data/lib/sequel/plugins/split_values.rb +6 -5
- data/lib/sequel/plugins/static_cache.rb +31 -25
- data/lib/sequel/plugins/subset_conditions.rb +3 -1
- data/lib/sequel/plugins/table_select.rb +1 -1
- data/lib/sequel/plugins/touch.rb +2 -1
- data/lib/sequel/plugins/validation_class_methods.rb +5 -6
- data/lib/sequel/plugins/validation_helpers.rb +2 -4
- data/lib/sequel/plugins/xml_serializer.rb +4 -4
- data/lib/sequel/sql.rb +2 -2
- data/lib/sequel/version.rb +1 -1
- data/spec/adapters/db2_spec.rb +115 -14
- data/spec/adapters/mysql_spec.rb +78 -28
- data/spec/adapters/oracle_spec.rb +24 -24
- data/spec/adapters/postgres_spec.rb +38 -24
- data/spec/adapters/sqlanywhere_spec.rb +88 -86
- data/spec/adapters/sqlite_spec.rb +29 -24
- data/spec/core/connection_pool_spec.rb +17 -0
- data/spec/core/database_spec.rb +6 -0
- data/spec/core/dataset_spec.rb +46 -36
- data/spec/core/schema_spec.rb +16 -0
- data/spec/core/spec_helper.rb +1 -0
- data/spec/core_extensions_spec.rb +6 -2
- data/spec/extensions/active_model_spec.rb +1 -1
- data/spec/extensions/arbitrary_servers_spec.rb +1 -1
- data/spec/extensions/association_pks_spec.rb +34 -2
- data/spec/extensions/auto_literal_strings_spec.rb +5 -1
- data/spec/extensions/auto_validations_spec.rb +2 -0
- data/spec/extensions/boolean_readers_spec.rb +1 -1
- data/spec/extensions/boolean_subsets_spec.rb +1 -1
- data/spec/extensions/class_table_inheritance_spec.rb +48 -2
- data/spec/extensions/column_conflicts_spec.rb +11 -0
- data/spec/extensions/connection_validator_spec.rb +1 -1
- data/spec/extensions/dataset_associations_spec.rb +8 -8
- data/spec/extensions/defaults_setter_spec.rb +1 -1
- data/spec/extensions/filter_having_spec.rb +5 -3
- data/spec/extensions/hash_aliases_spec.rb +3 -1
- data/spec/extensions/identifier_columns_spec.rb +3 -1
- data/spec/extensions/implicit_subquery_spec.rb +4 -2
- data/spec/extensions/json_serializer_spec.rb +18 -0
- data/spec/extensions/lazy_attributes_spec.rb +3 -3
- data/spec/extensions/meta_def_spec.rb +9 -0
- data/spec/extensions/migration_spec.rb +3 -3
- data/spec/extensions/nested_attributes_spec.rb +14 -3
- data/spec/extensions/no_auto_literal_strings_spec.rb +8 -4
- data/spec/extensions/pg_array_associations_spec.rb +29 -18
- data/spec/extensions/pg_array_spec.rb +44 -25
- data/spec/extensions/pg_hstore_spec.rb +10 -0
- data/spec/extensions/pg_inet_spec.rb +26 -0
- data/spec/extensions/pg_interval_spec.rb +20 -0
- data/spec/extensions/pg_json_spec.rb +24 -0
- data/spec/extensions/pg_range_spec.rb +98 -14
- data/spec/extensions/pg_row_spec.rb +14 -4
- data/spec/extensions/prepared_statements_safe_spec.rb +1 -1
- data/spec/extensions/query_literals_spec.rb +3 -1
- data/spec/extensions/schema_dumper_spec.rb +96 -98
- data/spec/extensions/sequel_3_dataset_methods_spec.rb +10 -6
- data/spec/extensions/sequel_4_dataset_methods_spec.rb +121 -0
- data/spec/extensions/single_table_inheritance_spec.rb +1 -1
- data/spec/extensions/spec_helper.rb +7 -1
- data/spec/extensions/static_cache_spec.rb +75 -24
- data/spec/extensions/string_agg_spec.rb +1 -1
- data/spec/extensions/touch_spec.rb +9 -0
- data/spec/extensions/validation_helpers_spec.rb +9 -3
- data/spec/extensions/whitelist_security_spec.rb +26 -0
- data/spec/integration/dataset_test.rb +45 -44
- data/spec/integration/plugin_test.rb +20 -0
- data/spec/integration/prepared_statement_test.rb +3 -0
- data/spec/integration/schema_test.rb +21 -1
- data/spec/integration/transaction_test.rb +40 -40
- data/spec/model/class_dataset_methods_spec.rb +14 -4
- data/spec/model/dataset_methods_spec.rb +12 -3
- data/spec/model/model_spec.rb +8 -0
- metadata +6 -4
- data/spec/adapters/firebird_spec.rb +0 -405
- data/spec/adapters/informix_spec.rb +0 -100
@@ -299,7 +299,8 @@ module Sequel
|
|
299
299
|
|
300
300
|
def fetch_ado_schema(type, criteria=[])
|
301
301
|
execute_open_ado_schema(type, criteria) do |s|
|
302
|
-
cols =
|
302
|
+
cols = []
|
303
|
+
s.Fields.each{|f| cols << f.Name}
|
303
304
|
s.getRows.transpose.each do |r|
|
304
305
|
row = {}
|
305
306
|
cols.each{|c| row[c] = r.shift}
|
@@ -4,8 +4,6 @@ Sequel::DataObjects.load_driver 'do_postgres'
|
|
4
4
|
Sequel.require 'adapters/shared/postgres'
|
5
5
|
|
6
6
|
module Sequel
|
7
|
-
Postgres::CONVERTED_EXCEPTIONS << ::DataObjects::Error
|
8
|
-
|
9
7
|
module DataObjects
|
10
8
|
Sequel.synchronize do
|
11
9
|
DATABASE_SETUP[:postgres] = proc do |db|
|
@@ -31,6 +29,11 @@ module Sequel
|
|
31
29
|
|
32
30
|
private
|
33
31
|
|
32
|
+
DATABASE_ERROR_CLASSES = [::DataObjects::Error].freeze
|
33
|
+
def database_error_classes
|
34
|
+
DATABASE_ERROR_CLASSES
|
35
|
+
end
|
36
|
+
|
34
37
|
# Extend the adapter with the DataObjects PostgreSQL AdapterMethods
|
35
38
|
def setup_connection(conn)
|
36
39
|
conn = super(conn)
|
@@ -6,12 +6,17 @@ Sequel.require 'adapters/shared/db2'
|
|
6
6
|
module Sequel
|
7
7
|
|
8
8
|
module IBMDB
|
9
|
+
# SEQUEL5: Remove
|
9
10
|
@convert_smallint_to_bool = true
|
10
|
-
|
11
11
|
class << self
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
def convert_smallint_to_bool
|
13
|
+
Sequel::Deprecation.deprecate("Sequel::IBMDB.convert_smallint_to_bool", "Call this method on the Database instance")
|
14
|
+
@convert_smallint_to_bool
|
15
|
+
end
|
16
|
+
def convert_smallint_to_bool=(v)
|
17
|
+
Sequel::Deprecation.deprecate("Sequel::IBMDB.convert_smallint_to_bool=", "Call this method on the Database instance")
|
18
|
+
@convert_smallint_to_bool = v
|
19
|
+
end
|
15
20
|
end
|
16
21
|
|
17
22
|
tt = Class.new do
|
@@ -187,6 +192,16 @@ module Sequel
|
|
187
192
|
|
188
193
|
# Hash of connection procs for converting
|
189
194
|
attr_reader :conversion_procs
|
195
|
+
|
196
|
+
# Whether to convert smallint values to bool for this Database instance
|
197
|
+
#attr_accessor :convert_smallint_to_bool # SEQUEL5
|
198
|
+
|
199
|
+
# SEQUEL5: Remove
|
200
|
+
attr_writer :convert_smallint_to_bool
|
201
|
+
def convert_smallint_to_bool
|
202
|
+
v = @convert_smallint_to_bool
|
203
|
+
v.nil? ? Sequel::IBMDB.instance_variable_get(:@convert_smallint_to_bool) : v
|
204
|
+
end
|
190
205
|
|
191
206
|
# Create a new connection object for the given server.
|
192
207
|
def connect(server)
|
@@ -284,6 +299,7 @@ module Sequel
|
|
284
299
|
end
|
285
300
|
|
286
301
|
def adapter_initialize
|
302
|
+
#@convert_smallint_to_bool = typecast_value_boolean(opts.fetch(:convert_smallint_to_bool, true)) # SEQUEL5
|
287
303
|
@conversion_procs = DB2_TYPES.dup
|
288
304
|
@conversion_procs[:timestamp] = method(:to_application_timestamp)
|
289
305
|
end
|
@@ -349,7 +365,7 @@ module Sequel
|
|
349
365
|
|
350
366
|
# Convert smallint type to boolean if convert_smallint_to_bool is true
|
351
367
|
def schema_column_type(db_type)
|
352
|
-
if
|
368
|
+
if convert_smallint_to_bool && db_type =~ /smallint/i
|
353
369
|
:boolean
|
354
370
|
else
|
355
371
|
super
|
@@ -379,13 +395,14 @@ module Sequel
|
|
379
395
|
|
380
396
|
# Override the default IBMDB.convert_smallint_to_bool setting for this dataset.
|
381
397
|
def convert_smallint_to_bool=(v)
|
398
|
+
Sequel::Deprecation.deprecate("Sequel::IBMDB::Dataset#convert_smallint_to_bool=", "Call with_convert_smallint_to_bool instead, which returns a modified copy instead of modifying the object")
|
382
399
|
@opts[:convert_smallint_to_bool] = v
|
383
400
|
end
|
384
401
|
|
385
402
|
# Whether to convert smallint to boolean arguments for this dataset.
|
386
403
|
# Defaults to the IBMDB module setting.
|
387
404
|
def convert_smallint_to_bool
|
388
|
-
opts.has_key?(:convert_smallint_to_bool) ? opts[:convert_smallint_to_bool] :
|
405
|
+
opts.has_key?(:convert_smallint_to_bool) ? opts[:convert_smallint_to_bool] : db.convert_smallint_to_bool
|
389
406
|
end
|
390
407
|
|
391
408
|
# Return a cloned dataset with the convert_smallint_to_bool option set.
|
@@ -405,7 +422,7 @@ module Sequel
|
|
405
422
|
type = stmt.field_type(i).downcase.to_sym
|
406
423
|
# decide if it is a smallint from precision
|
407
424
|
type = :boolean if type == :int && convert && stmt.field_precision(i) < 8
|
408
|
-
type = :blob if type == :clob &&
|
425
|
+
type = :blob if type == :clob && db.use_clob_as_blob
|
409
426
|
columns << [key, cps[type]]
|
410
427
|
end
|
411
428
|
cols = columns.map{|c| c[0]}
|
data/lib/sequel/adapters/jdbc.rb
CHANGED
@@ -142,16 +142,18 @@ module Sequel
|
|
142
142
|
MAP.freeze
|
143
143
|
BASIC_MAP.freeze
|
144
144
|
INSTANCE.freeze
|
145
|
+
# freeze # SEQUEL5
|
145
146
|
end
|
146
147
|
|
148
|
+
# SEQUEL5: Remove
|
149
|
+
Type_Convertor = TypeConvertor
|
150
|
+
Sequel::Deprecation.deprecate_constant(self, :TypeConvertor)
|
151
|
+
|
147
152
|
# JDBC Databases offer a fairly uniform interface that does not change
|
148
153
|
# much based on the sub adapter.
|
149
154
|
class Database < Sequel::Database
|
150
155
|
set_adapter_scheme :jdbc
|
151
156
|
|
152
|
-
# The type of database we are connecting to
|
153
|
-
attr_reader :database_type
|
154
|
-
|
155
157
|
# The Java database driver we are using (should be a Java class)
|
156
158
|
attr_reader :driver
|
157
159
|
|
@@ -185,12 +187,9 @@ module Sequel
|
|
185
187
|
if block_given?
|
186
188
|
yield log_connection_yield(sql, conn){cps.executeQuery}
|
187
189
|
else
|
188
|
-
|
189
|
-
|
190
|
-
log_connection_yield(sql, conn){cps.executeUpdate}
|
190
|
+
log_connection_yield(sql, conn){cps.executeUpdate}
|
191
|
+
if opts[:type] == :insert
|
191
192
|
last_insert_id(conn, opts)
|
192
|
-
else
|
193
|
-
log_connection_yield(sql, conn){cps.executeUpdate}
|
194
193
|
end
|
195
194
|
end
|
196
195
|
rescue NativeException, JavaSQL::SQLException => e
|
@@ -526,7 +525,7 @@ module Sequel
|
|
526
525
|
# Support fractional seconds for Time objects used in bound variables
|
527
526
|
def java_sql_timestamp(time)
|
528
527
|
ts = java.sql.Timestamp.new(time.to_i * 1000)
|
529
|
-
# Work around jruby 1.6 ruby 1.9 mode bug
|
528
|
+
# Work around jruby 1.6 ruby 1.9 mode bug # SEQUEL5: Remove workaround
|
530
529
|
ts.setNanos((RUBY_VERSION >= '1.9.0' && time.nsec != 0) ? time.nsec : time.usec * 1000)
|
531
530
|
ts
|
532
531
|
end
|
@@ -680,8 +679,9 @@ module Sequel
|
|
680
679
|
# Called before loading subadapter-specific code, necessary so that subadapter initialization code
|
681
680
|
# that runs queries works correctly. This cannot be overriding in subadapters,
|
682
681
|
def setup_type_convertor_map_early
|
683
|
-
|
684
|
-
@
|
682
|
+
# SEQUEL5: Change back to TypeConvertor
|
683
|
+
@type_convertor_map = Type_Convertor::MAP.merge(Java::JavaSQL::Types::TIMESTAMP=>method(:timestamp_convert))
|
684
|
+
@basic_type_convertor_map = Type_Convertor::BASIC_MAP.dup
|
685
685
|
end
|
686
686
|
|
687
687
|
# Yield a new statement object, and ensure that it is closed before returning.
|
@@ -694,15 +694,19 @@ module Sequel
|
|
694
694
|
stmt.close if stmt
|
695
695
|
end
|
696
696
|
|
697
|
-
# A conversion
|
697
|
+
# A conversion method for timestamp columns. This is used to make sure timestamps are converted using the
|
698
698
|
# correct timezone.
|
699
|
-
def
|
700
|
-
|
701
|
-
|
702
|
-
to_application_timestamp([v.getYear + 1900, v.getMonth + 1, v.getDate, v.getHours, v.getMinutes, v.getSeconds, v.getNanos])
|
703
|
-
end
|
699
|
+
def timestamp_convert(r, i)
|
700
|
+
if v = r.getTimestamp(i)
|
701
|
+
to_application_timestamp([v.getYear + 1900, v.getMonth + 1, v.getDate, v.getHours, v.getMinutes, v.getSeconds, v.getNanos])
|
704
702
|
end
|
705
703
|
end
|
704
|
+
|
705
|
+
# SEQUEL5: Remove
|
706
|
+
def timestamp_convertor
|
707
|
+
Sequel::Deprecation.deprecate("Sequel::JDBC::Database#timestamp_convertor", "Use method(:timestamp_convert) instead")
|
708
|
+
method(:timestamp_convert)
|
709
|
+
end
|
706
710
|
end
|
707
711
|
|
708
712
|
class Dataset < Sequel::Dataset
|
@@ -745,9 +749,14 @@ module Sequel
|
|
745
749
|
end
|
746
750
|
|
747
751
|
# Whether to convert some Java types to ruby types when retrieving rows.
|
748
|
-
|
749
|
-
|
750
|
-
|
752
|
+
def convert_types
|
753
|
+
Sequel::Deprecation.deprecate("Sequel::JDBC::Dataset#convert_types", "The private #convert_types? method returns whether to convert types for this dataset")
|
754
|
+
@opts[:convert_types]
|
755
|
+
end
|
756
|
+
def convert_types=(v)
|
757
|
+
Sequel::Deprecation.deprecate("Sequel::JDBC::Dataset#convert_types=", "Switch to using #with_convert_types, which returns a modified copy")
|
758
|
+
@opts[:convert_types] = v
|
759
|
+
end
|
751
760
|
|
752
761
|
# Correctly return rows from the database and return them as hashes.
|
753
762
|
def fetch_rows(sql, &block)
|
@@ -755,16 +764,21 @@ module Sequel
|
|
755
764
|
self
|
756
765
|
end
|
757
766
|
|
758
|
-
# Set the fetch size on JDBC ResultSets created from
|
767
|
+
# Set the fetch size on JDBC ResultSets created from the returned dataset.
|
759
768
|
def with_fetch_size(size)
|
760
769
|
clone(:fetch_size=>size)
|
761
770
|
end
|
771
|
+
|
772
|
+
# Set whether to convert Java types to ruby types in the returned dataset.
|
773
|
+
def with_convert_types(v)
|
774
|
+
clone(:convert_types=>v)
|
775
|
+
end
|
762
776
|
|
763
777
|
private
|
764
778
|
|
765
779
|
# Whether we should convert Java types to ruby types for this dataset.
|
766
780
|
def convert_types?
|
767
|
-
ct = @convert_types
|
781
|
+
ct = @opts[:convert_types]
|
768
782
|
ct.nil? ? db.convert_types : ct
|
769
783
|
end
|
770
784
|
|
@@ -35,7 +35,8 @@ module Sequel
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
|
38
|
+
# SEQUEL5: Remove
|
39
|
+
class Type_Convertor
|
39
40
|
def DB2Clob(r, i)
|
40
41
|
if v = r.getClob(i)
|
41
42
|
v = v.getSubString(1, v.length)
|
@@ -63,7 +64,7 @@ module Sequel
|
|
63
64
|
def set_ps_arg(cps, arg, i)
|
64
65
|
case arg
|
65
66
|
when Sequel::SQL::Blob
|
66
|
-
if
|
67
|
+
if use_clob_as_blob
|
67
68
|
cps.setString(i, arg)
|
68
69
|
else
|
69
70
|
super
|
@@ -91,7 +92,15 @@ module Sequel
|
|
91
92
|
super
|
92
93
|
map = @type_convertor_map
|
93
94
|
types = Java::JavaSQL::Types
|
94
|
-
map[types::NCLOB] = map[types::CLOB] =
|
95
|
+
map[types::NCLOB] = map[types::CLOB] = method(:convert_clob)
|
96
|
+
end
|
97
|
+
|
98
|
+
def convert_clob(r, i)
|
99
|
+
if v = r.getClob(i)
|
100
|
+
v = v.getSubString(1, v.length)
|
101
|
+
v = Sequel::SQL::Blob.new(v) if use_clob_as_blob
|
102
|
+
v
|
103
|
+
end
|
95
104
|
end
|
96
105
|
end
|
97
106
|
|
@@ -54,7 +54,7 @@ module Sequel
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
# Derby supports
|
57
|
+
# Derby supports transactional DDL statements.
|
58
58
|
def supports_transactional_ddl?
|
59
59
|
true
|
60
60
|
end
|
@@ -227,8 +227,7 @@ module Sequel
|
|
227
227
|
Sequel::Deprecation.deprecate_constant(self, :EMULATED_FUNCTION_MAP)
|
228
228
|
|
229
229
|
# Derby doesn't support an expression between CASE and WHEN,
|
230
|
-
# so remove
|
231
|
-
# conditions.
|
230
|
+
# so remove conditions.
|
232
231
|
def case_expression_sql_append(sql, ce)
|
233
232
|
super(sql, ce.with_merged_expression)
|
234
233
|
end
|
@@ -300,7 +299,7 @@ module Sequel
|
|
300
299
|
end
|
301
300
|
|
302
301
|
# Derby uses an expression yielding false for false values.
|
303
|
-
# Newer versions can use the FALSE literal, but
|
302
|
+
# Newer versions can use the FALSE literal, but older versions cannot.
|
304
303
|
def literal_false
|
305
304
|
if db.svn_version >= 1040133
|
306
305
|
'FALSE'
|
@@ -315,7 +314,7 @@ module Sequel
|
|
315
314
|
end
|
316
315
|
|
317
316
|
# Derby uses an expression yielding true for true values.
|
318
|
-
# Newer versions can use the TRUE literal, but
|
317
|
+
# Newer versions can use the TRUE literal, but older versions cannot.
|
319
318
|
def literal_true
|
320
319
|
if db.svn_version >= 1040133
|
321
320
|
'TRUE'
|
@@ -14,7 +14,8 @@ module Sequel
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
|
17
|
+
# SEQUEL5: Remove
|
18
|
+
class Type_Convertor
|
18
19
|
JAVA_BIG_DECIMAL_CONSTRUCTOR = java.math.BigDecimal.java_class.constructor(Java::long).method(:new_instance)
|
19
20
|
|
20
21
|
def OracleDecimal(r, i)
|
@@ -31,6 +32,19 @@ module Sequel
|
|
31
32
|
|
32
33
|
# Database and Dataset support for Oracle databases accessed via JDBC.
|
33
34
|
module Oracle
|
35
|
+
JAVA_BIG_DECIMAL_CONSTRUCTOR = java.math.BigDecimal.java_class.constructor(Java::long).method(:new_instance)
|
36
|
+
|
37
|
+
def self.OracleDecimal(r, i)
|
38
|
+
if v = r.getBigDecimal(i)
|
39
|
+
i = v.long_value
|
40
|
+
if v == JAVA_BIG_DECIMAL_CONSTRUCTOR.call(i)
|
41
|
+
i
|
42
|
+
else
|
43
|
+
BigDecimal.new(v.to_string)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
34
48
|
# Instance methods for Oracle Database objects accessed via JDBC.
|
35
49
|
module DatabaseMethods
|
36
50
|
PRIMARY_KEY_INDEX_RE = /\Asys_/i.freeze
|
@@ -110,7 +124,7 @@ module Sequel
|
|
110
124
|
|
111
125
|
def setup_type_convertor_map
|
112
126
|
super
|
113
|
-
@type_convertor_map[:OracleDecimal] =
|
127
|
+
@type_convertor_map[:OracleDecimal] = Oracle.method(:OracleDecimal)
|
114
128
|
end
|
115
129
|
end
|
116
130
|
|
@@ -4,8 +4,6 @@ Sequel::JDBC.load_driver('org.postgresql.Driver', :Postgres)
|
|
4
4
|
Sequel.require 'adapters/shared/postgres'
|
5
5
|
|
6
6
|
module Sequel
|
7
|
-
Postgres::CONVERTED_EXCEPTIONS << NativeException
|
8
|
-
|
9
7
|
module JDBC
|
10
8
|
Sequel.synchronize do
|
11
9
|
DATABASE_SETUP[:postgresql] = proc do |db|
|
@@ -15,11 +13,27 @@ module Sequel
|
|
15
13
|
end
|
16
14
|
end
|
17
15
|
|
18
|
-
|
16
|
+
# SEQUEL5: Remove
|
17
|
+
class Type_Convertor
|
18
|
+
def RubyPGArray(r, i)
|
19
|
+
if v = r.getArray(i)
|
20
|
+
v.array.to_ary
|
21
|
+
end
|
22
|
+
end
|
23
|
+
def RubyPGHstore(r, i)
|
24
|
+
if v = r.getObject(i)
|
25
|
+
v.to_hash
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Adapter, Database, and Dataset support for accessing a PostgreSQL
|
31
|
+
# database via JDBC.
|
32
|
+
module Postgres
|
19
33
|
# Return PostgreSQL array types as ruby Arrays instead of
|
20
34
|
# JDBC PostgreSQL driver-specific array type. Only used if the
|
21
35
|
# database does not have a conversion proc for the type.
|
22
|
-
def RubyPGArray(r, i)
|
36
|
+
def self.RubyPGArray(r, i)
|
23
37
|
if v = r.getArray(i)
|
24
38
|
v.array.to_ary
|
25
39
|
end
|
@@ -28,16 +42,12 @@ module Sequel
|
|
28
42
|
# Return PostgreSQL hstore types as ruby Hashes instead of
|
29
43
|
# Java HashMaps. Only used if the database does not have a
|
30
44
|
# conversion proc for the type.
|
31
|
-
def RubyPGHstore(r, i)
|
45
|
+
def self.RubyPGHstore(r, i)
|
32
46
|
if v = r.getObject(i)
|
33
47
|
v.to_hash
|
34
48
|
end
|
35
49
|
end
|
36
|
-
end
|
37
50
|
|
38
|
-
# Adapter, Database, and Dataset support for accessing a PostgreSQL
|
39
|
-
# database via JDBC.
|
40
|
-
module Postgres
|
41
51
|
# Methods to add to Database instances that access PostgreSQL via
|
42
52
|
# JDBC.
|
43
53
|
module DatabaseMethods
|
@@ -50,6 +60,12 @@ module Sequel
|
|
50
60
|
db.send(:initialize_postgres_adapter)
|
51
61
|
end
|
52
62
|
|
63
|
+
# Remove any current entry for the oid in the oid_convertor_map.
|
64
|
+
def add_conversion_proc(oid, *)
|
65
|
+
super
|
66
|
+
Sequel.synchronize{@oid_convertor_map.delete(oid)}
|
67
|
+
end
|
68
|
+
|
53
69
|
# See Sequel::Postgres::Adapter#copy_into
|
54
70
|
def copy_into(table, opts=OPTS)
|
55
71
|
data = opts[:data]
|
@@ -61,7 +77,7 @@ module Sequel
|
|
61
77
|
raise Error, "Must provide either a :data option or a block to copy_into"
|
62
78
|
end
|
63
79
|
|
64
|
-
synchronize(opts) do |conn|
|
80
|
+
synchronize(opts[:server]) do |conn|
|
65
81
|
begin
|
66
82
|
copy_manager = org.postgresql.copy.CopyManager.new(conn)
|
67
83
|
copier = copy_manager.copy_in(copy_into_sql(table, opts))
|
@@ -73,7 +89,7 @@ module Sequel
|
|
73
89
|
data.each { |d| copier.writeToCopy(d.to_java_bytes, 0, d.length) }
|
74
90
|
end
|
75
91
|
rescue Exception => e
|
76
|
-
copier.cancelCopy
|
92
|
+
copier.cancelCopy if copier
|
77
93
|
raise
|
78
94
|
ensure
|
79
95
|
unless e
|
@@ -105,8 +121,12 @@ module Sequel
|
|
105
121
|
end
|
106
122
|
b
|
107
123
|
end
|
124
|
+
rescue => e
|
125
|
+
raise_error(e, :disconnect=>true)
|
108
126
|
ensure
|
109
|
-
|
127
|
+
if buf && !e
|
128
|
+
raise DatabaseDisconnectError, "disconnecting as a partial COPY may leave the connection in an unusable state"
|
129
|
+
end
|
110
130
|
end
|
111
131
|
end
|
112
132
|
end
|
@@ -122,19 +142,24 @@ module Sequel
|
|
122
142
|
else
|
123
143
|
false
|
124
144
|
end
|
125
|
-
|
145
|
+
Sequel.synchronize{@oid_convertor_map[oid] = conv}
|
126
146
|
end
|
127
147
|
conv
|
128
148
|
end
|
129
149
|
|
130
150
|
private
|
131
151
|
|
132
|
-
#
|
152
|
+
# SEQUEL5: Remove
|
133
153
|
def conversion_procs_updated
|
134
154
|
super
|
135
155
|
Sequel.synchronize{@oid_convertor_map = {}}
|
136
156
|
end
|
137
157
|
|
158
|
+
DATABASE_ERROR_CLASSES = [NativeException].freeze
|
159
|
+
def database_error_classes
|
160
|
+
DATABASE_ERROR_CLASSES
|
161
|
+
end
|
162
|
+
|
138
163
|
def disconnect_error?(exception, opts)
|
139
164
|
super || exception.message =~ /\A(This connection has been closed\.|FATAL: terminating connection due to administrator command|An I\/O error occurred while sending to the backend\.)\z/
|
140
165
|
end
|
@@ -178,8 +203,6 @@ module Sequel
|
|
178
203
|
def setup_type_convertor_map
|
179
204
|
super
|
180
205
|
@oid_convertor_map = {}
|
181
|
-
@type_convertor_map[:RubyPGArray] = TypeConvertor::INSTANCE.method(:RubyPGArray)
|
182
|
-
@type_convertor_map[:RubyPGHstore] = TypeConvertor::INSTANCE.method(:RubyPGHstore)
|
183
206
|
end
|
184
207
|
end
|
185
208
|
|
@@ -203,8 +226,10 @@ module Sequel
|
|
203
226
|
|
204
227
|
STRING_TYPE = Java::JavaSQL::Types::VARCHAR
|
205
228
|
ARRAY_TYPE = Java::JavaSQL::Types::ARRAY
|
229
|
+
ARRAY_METHOD = Postgres.method(:RubyPGArray)
|
206
230
|
PG_SPECIFIC_TYPES = [ARRAY_TYPE, Java::JavaSQL::Types::OTHER, Java::JavaSQL::Types::STRUCT]#.freeze # SEQUEL5
|
207
231
|
HSTORE_TYPE = 'hstore'.freeze
|
232
|
+
HSTORE_METHOD = Postgres.method(:RubyPGHstore)
|
208
233
|
|
209
234
|
def type_convertor(map, meta, type, i)
|
210
235
|
case type
|
@@ -213,11 +238,11 @@ module Sequel
|
|
213
238
|
if pr = db.oid_convertor_proc(oid)
|
214
239
|
pr
|
215
240
|
elsif type == ARRAY_TYPE
|
216
|
-
|
241
|
+
ARRAY_METHOD
|
217
242
|
elsif oid == 2950 # UUID
|
218
243
|
map[STRING_TYPE]
|
219
244
|
elsif meta.getPGType(i) == HSTORE_TYPE
|
220
|
-
|
245
|
+
HSTORE_METHOD
|
221
246
|
else
|
222
247
|
super
|
223
248
|
end
|