activerecord 5.1.7 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activerecord might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +372 -765
- data/MIT-LICENSE +1 -1
- data/README.rdoc +5 -5
- data/examples/performance.rb +2 -0
- data/examples/simple.rb +2 -0
- data/lib/active_record/aggregations.rb +6 -5
- data/lib/active_record/association_relation.rb +4 -2
- data/lib/active_record/associations/alias_tracker.rb +19 -27
- data/lib/active_record/associations/association.rb +16 -27
- data/lib/active_record/associations/association_scope.rb +38 -50
- data/lib/active_record/associations/belongs_to_association.rb +20 -10
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +4 -7
- data/lib/active_record/associations/builder/association.rb +4 -7
- data/lib/active_record/associations/builder/belongs_to.rb +4 -5
- data/lib/active_record/associations/builder/collection_association.rb +1 -1
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +3 -1
- data/lib/active_record/associations/builder/has_many.rb +2 -0
- data/lib/active_record/associations/builder/has_one.rb +2 -0
- data/lib/active_record/associations/builder/singular_association.rb +2 -0
- data/lib/active_record/associations/collection_association.rb +43 -35
- data/lib/active_record/associations/collection_proxy.rb +12 -15
- data/lib/active_record/associations/foreign_association.rb +2 -0
- data/lib/active_record/associations/has_many_association.rb +3 -1
- data/lib/active_record/associations/has_many_through_association.rb +7 -18
- data/lib/active_record/associations/has_one_association.rb +4 -1
- data/lib/active_record/associations/has_one_through_association.rb +8 -7
- data/lib/active_record/associations/join_dependency/join_association.rb +17 -56
- data/lib/active_record/associations/join_dependency/join_base.rb +9 -8
- data/lib/active_record/associations/join_dependency/join_part.rb +2 -9
- data/lib/active_record/associations/join_dependency.rb +23 -43
- data/lib/active_record/associations/preloader/association.rb +45 -61
- data/lib/active_record/associations/preloader/through_association.rb +71 -79
- data/lib/active_record/associations/preloader.rb +17 -37
- data/lib/active_record/associations/singular_association.rb +14 -10
- data/lib/active_record/associations/through_association.rb +25 -10
- data/lib/active_record/associations.rb +31 -54
- data/lib/active_record/attribute_assignment.rb +2 -5
- data/lib/active_record/attribute_decorators.rb +3 -2
- data/lib/active_record/attribute_methods/before_type_cast.rb +2 -0
- data/lib/active_record/attribute_methods/dirty.rb +25 -214
- data/lib/active_record/attribute_methods/primary_key.rb +7 -6
- data/lib/active_record/attribute_methods/query.rb +2 -0
- data/lib/active_record/attribute_methods/read.rb +8 -2
- data/lib/active_record/attribute_methods/serialization.rb +23 -0
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +6 -8
- data/lib/active_record/attribute_methods/write.rb +21 -9
- data/lib/active_record/attribute_methods.rb +65 -24
- data/lib/active_record/attributes.rb +6 -5
- data/lib/active_record/autosave_association.rb +8 -11
- data/lib/active_record/base.rb +2 -0
- data/lib/active_record/callbacks.rb +8 -10
- data/lib/active_record/coders/json.rb +2 -0
- data/lib/active_record/coders/yaml_column.rb +2 -0
- data/lib/active_record/collection_cache_key.rb +11 -7
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +111 -38
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +2 -0
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +157 -29
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +7 -2
- data/lib/active_record/connection_adapters/abstract/quoting.rb +13 -32
- data/lib/active_record/connection_adapters/abstract/savepoints.rb +2 -0
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +14 -5
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +57 -2
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +31 -53
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +158 -78
- data/lib/active_record/connection_adapters/abstract/transaction.rb +45 -9
- data/lib/active_record/connection_adapters/abstract_adapter.rb +81 -96
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +111 -183
- data/lib/active_record/connection_adapters/column.rb +3 -1
- data/lib/active_record/connection_adapters/connection_specification.rb +17 -3
- data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +2 -0
- data/lib/active_record/connection_adapters/mysql/column.rb +2 -0
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +11 -2
- data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +2 -0
- data/lib/active_record/connection_adapters/mysql/quoting.rb +9 -10
- data/lib/active_record/connection_adapters/mysql/schema_creation.rb +5 -3
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +7 -10
- data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +30 -30
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +106 -1
- data/lib/active_record/connection_adapters/mysql/type_metadata.rb +2 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +8 -2
- data/lib/active_record/connection_adapters/postgresql/column.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +6 -0
- data/lib/active_record/connection_adapters/postgresql/explain_pretty_printer.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +3 -11
- data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/bit_varying.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/bytea.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/date.rb +23 -0
- data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/decimal.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/inet.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb +3 -1
- data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/money.rb +3 -1
- data/lib/active_record/connection_adapters/postgresql/oid/oid.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +4 -6
- data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +4 -2
- data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +3 -1
- data/lib/active_record/connection_adapters/postgresql/oid/vector.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/xml.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid.rb +3 -1
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +18 -0
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +19 -25
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +14 -0
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +24 -11
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +20 -13
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +246 -110
- data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/utils.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +58 -82
- data/lib/active_record/connection_adapters/schema_cache.rb +4 -2
- data/lib/active_record/connection_adapters/sql_type_metadata.rb +2 -0
- data/lib/active_record/connection_adapters/sqlite3/explain_pretty_printer.rb +2 -0
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +18 -1
- data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +2 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_definitions.rb +6 -15
- data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +3 -2
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +71 -1
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +80 -90
- data/lib/active_record/connection_adapters/statement_pool.rb +2 -0
- data/lib/active_record/connection_handling.rb +4 -2
- data/lib/active_record/core.rb +39 -60
- data/lib/active_record/counter_cache.rb +15 -12
- data/lib/active_record/define_callbacks.rb +5 -3
- data/lib/active_record/dynamic_matchers.rb +9 -9
- data/lib/active_record/enum.rb +17 -13
- data/lib/active_record/errors.rb +54 -21
- data/lib/active_record/explain.rb +3 -1
- data/lib/active_record/explain_registry.rb +2 -0
- data/lib/active_record/explain_subscriber.rb +2 -0
- data/lib/active_record/fixture_set/file.rb +2 -0
- data/lib/active_record/fixtures.rb +67 -60
- data/lib/active_record/gem_version.rb +4 -2
- data/lib/active_record/inheritance.rb +49 -19
- data/lib/active_record/integration.rb +58 -19
- data/lib/active_record/internal_metadata.rb +2 -0
- data/lib/active_record/legacy_yaml_adapter.rb +3 -1
- data/lib/active_record/locking/optimistic.rb +14 -17
- data/lib/active_record/locking/pessimistic.rb +9 -6
- data/lib/active_record/log_subscriber.rb +43 -0
- data/lib/active_record/migration/command_recorder.rb +11 -9
- data/lib/active_record/migration/compatibility.rb +40 -2
- data/lib/active_record/migration/join_table.rb +2 -0
- data/lib/active_record/migration.rb +189 -139
- data/lib/active_record/model_schema.rb +16 -21
- data/lib/active_record/nested_attributes.rb +18 -6
- data/lib/active_record/no_touching.rb +3 -1
- data/lib/active_record/null_relation.rb +2 -0
- data/lib/active_record/persistence.rb +166 -16
- data/lib/active_record/query_cache.rb +11 -6
- data/lib/active_record/querying.rb +3 -1
- data/lib/active_record/railtie.rb +61 -3
- data/lib/active_record/railties/console_sandbox.rb +2 -0
- data/lib/active_record/railties/controller_runtime.rb +2 -0
- data/lib/active_record/railties/databases.rake +46 -36
- data/lib/active_record/readonly_attributes.rb +3 -2
- data/lib/active_record/reflection.rb +110 -192
- data/lib/active_record/relation/batches/batch_enumerator.rb +2 -0
- data/lib/active_record/relation/batches.rb +20 -5
- data/lib/active_record/relation/calculations.rb +30 -8
- data/lib/active_record/relation/delegation.rb +15 -27
- data/lib/active_record/relation/finder_methods.rb +75 -78
- data/lib/active_record/relation/from_clause.rb +2 -8
- data/lib/active_record/relation/merger.rb +51 -20
- data/lib/active_record/relation/predicate_builder/array_handler.rb +10 -7
- data/lib/active_record/relation/predicate_builder/association_query_value.rb +46 -0
- data/lib/active_record/relation/predicate_builder/base_handler.rb +2 -2
- data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +12 -1
- data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +56 -0
- data/lib/active_record/relation/predicate_builder/range_handler.rb +26 -9
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +6 -0
- data/lib/active_record/relation/predicate_builder.rb +53 -78
- data/lib/active_record/relation/query_attribute.rb +26 -2
- data/lib/active_record/relation/query_methods.rb +89 -88
- data/lib/active_record/relation/record_fetch_warning.rb +2 -0
- data/lib/active_record/relation/spawn_methods.rb +3 -1
- data/lib/active_record/relation/where_clause.rb +65 -68
- data/lib/active_record/relation/where_clause_factory.rb +5 -48
- data/lib/active_record/relation.rb +95 -208
- data/lib/active_record/result.rb +2 -0
- data/lib/active_record/runtime_registry.rb +2 -0
- data/lib/active_record/sanitization.rb +129 -121
- data/lib/active_record/schema.rb +4 -2
- data/lib/active_record/schema_dumper.rb +36 -26
- data/lib/active_record/schema_migration.rb +2 -0
- data/lib/active_record/scoping/default.rb +6 -7
- data/lib/active_record/scoping/named.rb +21 -7
- data/lib/active_record/scoping.rb +9 -8
- data/lib/active_record/secure_token.rb +2 -0
- data/lib/active_record/serialization.rb +2 -0
- data/lib/active_record/statement_cache.rb +22 -12
- data/lib/active_record/store.rb +3 -1
- data/lib/active_record/suppressor.rb +2 -0
- data/lib/active_record/table_metadata.rb +12 -3
- data/lib/active_record/tasks/database_tasks.rb +26 -15
- data/lib/active_record/tasks/mysql_database_tasks.rb +9 -48
- data/lib/active_record/tasks/postgresql_database_tasks.rb +10 -2
- data/lib/active_record/tasks/sqlite_database_tasks.rb +25 -3
- data/lib/active_record/timestamp.rb +5 -12
- data/lib/active_record/touch_later.rb +2 -0
- data/lib/active_record/transactions.rb +9 -7
- data/lib/active_record/translation.rb +2 -0
- data/lib/active_record/type/adapter_specific_registry.rb +2 -0
- data/lib/active_record/type/date.rb +2 -0
- data/lib/active_record/type/date_time.rb +2 -0
- data/lib/active_record/type/decimal_without_scale.rb +2 -0
- data/lib/active_record/type/hash_lookup_type_map.rb +2 -0
- data/lib/active_record/type/internal/timezone.rb +2 -0
- data/lib/active_record/type/json.rb +30 -0
- data/lib/active_record/type/serialized.rb +2 -4
- data/lib/active_record/type/text.rb +2 -0
- data/lib/active_record/type/time.rb +2 -0
- data/lib/active_record/type/type_map.rb +2 -0
- data/lib/active_record/type/unsigned_integer.rb +2 -0
- data/lib/active_record/type.rb +4 -1
- data/lib/active_record/type_caster/connection.rb +2 -0
- data/lib/active_record/type_caster/map.rb +3 -1
- data/lib/active_record/type_caster.rb +2 -0
- data/lib/active_record/validations/absence.rb +2 -0
- data/lib/active_record/validations/associated.rb +2 -0
- data/lib/active_record/validations/length.rb +2 -0
- data/lib/active_record/validations/presence.rb +2 -0
- data/lib/active_record/validations/uniqueness.rb +35 -5
- data/lib/active_record/validations.rb +2 -0
- data/lib/active_record/version.rb +2 -0
- data/lib/active_record.rb +11 -4
- data/lib/rails/generators/active_record/application_record/application_record_generator.rb +27 -0
- data/lib/rails/generators/active_record/{model/templates/application_record.rb → application_record/templates/application_record.rb.tt} +0 -0
- data/lib/rails/generators/active_record/migration/migration_generator.rb +3 -1
- data/lib/rails/generators/active_record/migration/templates/{create_table_migration.rb → create_table_migration.rb.tt} +0 -0
- data/lib/rails/generators/active_record/migration/templates/{migration.rb → migration.rb.tt} +0 -0
- data/lib/rails/generators/active_record/migration.rb +2 -0
- data/lib/rails/generators/active_record/model/model_generator.rb +2 -23
- data/lib/rails/generators/active_record/model/templates/{model.rb → model.rb.tt} +0 -0
- data/lib/rails/generators/active_record/model/templates/{module.rb → module.rb.tt} +0 -0
- data/lib/rails/generators/active_record.rb +3 -1
- metadata +24 -36
- data/lib/active_record/associations/preloader/belongs_to.rb +0 -15
- data/lib/active_record/associations/preloader/collection_association.rb +0 -17
- data/lib/active_record/associations/preloader/has_many.rb +0 -15
- data/lib/active_record/associations/preloader/has_many_through.rb +0 -19
- data/lib/active_record/associations/preloader/has_one.rb +0 -15
- data/lib/active_record/associations/preloader/has_one_through.rb +0 -9
- data/lib/active_record/associations/preloader/singular_association.rb +0 -18
- data/lib/active_record/attribute/user_provided_default.rb +0 -30
- data/lib/active_record/attribute.rb +0 -240
- data/lib/active_record/attribute_mutation_tracker.rb +0 -122
- data/lib/active_record/attribute_set/builder.rb +0 -126
- data/lib/active_record/attribute_set/yaml_encoder.rb +0 -41
- data/lib/active_record/attribute_set.rb +0 -113
- data/lib/active_record/connection_adapters/postgresql/oid/json.rb +0 -10
- data/lib/active_record/railties/jdbcmysql_error.rb +0 -16
- data/lib/active_record/relation/predicate_builder/association_query_handler.rb +0 -88
- data/lib/active_record/relation/predicate_builder/polymorphic_array_handler.rb +0 -59
- data/lib/active_record/type/internal/abstract_json.rb +0 -37
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_record/connection_adapters/abstract_adapter"
|
2
4
|
require "active_record/connection_adapters/statement_pool"
|
3
5
|
require "active_record/connection_adapters/mysql/column"
|
@@ -15,21 +17,8 @@ module ActiveRecord
|
|
15
17
|
module ConnectionAdapters
|
16
18
|
class AbstractMysqlAdapter < AbstractAdapter
|
17
19
|
include MySQL::Quoting
|
18
|
-
include MySQL::ColumnDumper
|
19
20
|
include MySQL::SchemaStatements
|
20
21
|
|
21
|
-
def update_table_definition(table_name, base) # :nodoc:
|
22
|
-
MySQL::Table.new(table_name, base)
|
23
|
-
end
|
24
|
-
|
25
|
-
def schema_creation # :nodoc:
|
26
|
-
MySQL::SchemaCreation.new(self)
|
27
|
-
end
|
28
|
-
|
29
|
-
def arel_visitor # :nodoc:
|
30
|
-
Arel::Visitors::MySQL.new(self)
|
31
|
-
end
|
32
|
-
|
33
22
|
##
|
34
23
|
# :singleton-method:
|
35
24
|
# By default, the Mysql2Adapter will consider all columns of type <tt>tinyint(1)</tt>
|
@@ -37,15 +26,14 @@ module ActiveRecord
|
|
37
26
|
# to your application.rb file:
|
38
27
|
#
|
39
28
|
# ActiveRecord::ConnectionAdapters::Mysql2Adapter.emulate_booleans = false
|
40
|
-
class_attribute :emulate_booleans
|
41
|
-
self.emulate_booleans = true
|
29
|
+
class_attribute :emulate_booleans, default: true
|
42
30
|
|
43
31
|
NATIVE_DATABASE_TYPES = {
|
44
32
|
primary_key: "bigint auto_increment PRIMARY KEY",
|
45
33
|
string: { name: "varchar", limit: 255 },
|
46
34
|
text: { name: "text", limit: 65535 },
|
47
35
|
integer: { name: "int", limit: 4 },
|
48
|
-
float: { name: "float" },
|
36
|
+
float: { name: "float", limit: 24 },
|
49
37
|
decimal: { name: "decimal" },
|
50
38
|
datetime: { name: "datetime" },
|
51
39
|
timestamp: { name: "timestamp" },
|
@@ -56,10 +44,7 @@ module ActiveRecord
|
|
56
44
|
json: { name: "json" },
|
57
45
|
}
|
58
46
|
|
59
|
-
|
60
|
-
INDEX_USINGS = [:btree, :hash]
|
61
|
-
|
62
|
-
class StatementPool < ConnectionAdapters::StatementPool
|
47
|
+
class StatementPool < ConnectionAdapters::StatementPool # :nodoc:
|
63
48
|
private def dealloc(stmt)
|
64
49
|
stmt[:stmt].close
|
65
50
|
end
|
@@ -87,16 +72,8 @@ module ActiveRecord
|
|
87
72
|
true
|
88
73
|
end
|
89
74
|
|
90
|
-
# Returns true, since this connection adapter supports prepared statement
|
91
|
-
# caching.
|
92
|
-
def supports_statement_cache?
|
93
|
-
true
|
94
|
-
end
|
95
|
-
|
96
|
-
# Technically MySQL allows to create indexes with the sort order syntax
|
97
|
-
# but at the moment (5.5) it doesn't yet implement them
|
98
75
|
def supports_index_sort_order?
|
99
|
-
|
76
|
+
!mariadb? && version >= "8.0.1"
|
100
77
|
end
|
101
78
|
|
102
79
|
def supports_transaction_isolation?
|
@@ -152,7 +129,7 @@ module ActiveRecord
|
|
152
129
|
end
|
153
130
|
|
154
131
|
def index_algorithms
|
155
|
-
{ default: "ALGORITHM = DEFAULT", copy: "ALGORITHM = COPY", inplace: "ALGORITHM = INPLACE" }
|
132
|
+
{ default: "ALGORITHM = DEFAULT".dup, copy: "ALGORITHM = COPY".dup, inplace: "ALGORITHM = INPLACE".dup }
|
156
133
|
end
|
157
134
|
|
158
135
|
# HELPER METHODS ===========================================
|
@@ -163,10 +140,6 @@ module ActiveRecord
|
|
163
140
|
raise NotImplementedError
|
164
141
|
end
|
165
142
|
|
166
|
-
def new_column(*args) #:nodoc:
|
167
|
-
MySQL::Column.new(*args)
|
168
|
-
end
|
169
|
-
|
170
143
|
# Must return the MySQL error number from the exception, if the exception has an
|
171
144
|
# error number.
|
172
145
|
def error_number(exception) # :nodoc:
|
@@ -276,7 +249,7 @@ module ActiveRecord
|
|
276
249
|
# create_database 'matt_development', charset: :big5
|
277
250
|
def create_database(name, options = {})
|
278
251
|
if options[:collation]
|
279
|
-
execute "CREATE DATABASE #{quote_table_name(name)} DEFAULT
|
252
|
+
execute "CREATE DATABASE #{quote_table_name(name)} DEFAULT COLLATE #{quote_table_name(options[:collation])}"
|
280
253
|
else
|
281
254
|
execute "CREATE DATABASE #{quote_table_name(name)} DEFAULT CHARACTER SET #{quote_table_name(options[:charset] || 'utf8')}"
|
282
255
|
end
|
@@ -308,50 +281,10 @@ module ActiveRecord
|
|
308
281
|
execute "TRUNCATE TABLE #{quote_table_name(table_name)}", name
|
309
282
|
end
|
310
283
|
|
311
|
-
# Returns an array of indexes for the given table.
|
312
|
-
def indexes(table_name, name = nil) #:nodoc:
|
313
|
-
if name
|
314
|
-
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
315
|
-
Passing name to #indexes is deprecated without replacement.
|
316
|
-
MSG
|
317
|
-
end
|
318
|
-
|
319
|
-
indexes = []
|
320
|
-
current_index = nil
|
321
|
-
execute_and_free("SHOW KEYS FROM #{quote_table_name(table_name)}", "SCHEMA") do |result|
|
322
|
-
each_hash(result) do |row|
|
323
|
-
if current_index != row[:Key_name]
|
324
|
-
next if row[:Key_name] == "PRIMARY" # skip the primary key
|
325
|
-
current_index = row[:Key_name]
|
326
|
-
|
327
|
-
mysql_index_type = row[:Index_type].downcase.to_sym
|
328
|
-
index_type = INDEX_TYPES.include?(mysql_index_type) ? mysql_index_type : nil
|
329
|
-
index_using = INDEX_USINGS.include?(mysql_index_type) ? mysql_index_type : nil
|
330
|
-
indexes << IndexDefinition.new(row[:Table], row[:Key_name], row[:Non_unique].to_i == 0, [], {}, nil, nil, index_type, index_using, row[:Index_comment].presence)
|
331
|
-
end
|
332
|
-
|
333
|
-
indexes.last.columns << row[:Column_name]
|
334
|
-
indexes.last.lengths.merge!(row[:Column_name] => row[:Sub_part].to_i) if row[:Sub_part]
|
335
|
-
end
|
336
|
-
end
|
337
|
-
|
338
|
-
indexes
|
339
|
-
end
|
340
|
-
|
341
|
-
def new_column_from_field(table_name, field) # :nodoc:
|
342
|
-
type_metadata = fetch_type_metadata(field[:Type], field[:Extra])
|
343
|
-
if type_metadata.type == :datetime && /\ACURRENT_TIMESTAMP(?:\(\))?\z/i.match?(field[:Default])
|
344
|
-
default, default_function = nil, "CURRENT_TIMESTAMP"
|
345
|
-
else
|
346
|
-
default, default_function = field[:Default], nil
|
347
|
-
end
|
348
|
-
new_column(field[:Field], default, type_metadata, field[:Null] == "YES", table_name, default_function, field[:Collation], comment: field[:Comment].presence)
|
349
|
-
end
|
350
|
-
|
351
284
|
def table_comment(table_name) # :nodoc:
|
352
285
|
scope = quoted_scope(table_name)
|
353
286
|
|
354
|
-
query_value(<<-SQL.strip_heredoc, "SCHEMA")
|
287
|
+
query_value(<<-SQL.strip_heredoc, "SCHEMA").presence
|
355
288
|
SELECT table_comment
|
356
289
|
FROM information_schema.tables
|
357
290
|
WHERE table_schema = #{scope[:schema]}
|
@@ -359,14 +292,10 @@ module ActiveRecord
|
|
359
292
|
SQL
|
360
293
|
end
|
361
294
|
|
362
|
-
def create_table(table_name, **options) #:nodoc:
|
363
|
-
super(table_name, options: "ENGINE=InnoDB", **options)
|
364
|
-
end
|
365
|
-
|
366
295
|
def bulk_change_table(table_name, operations) #:nodoc:
|
367
296
|
sqls = operations.flat_map do |command, args|
|
368
297
|
table, arguments = args.shift, args
|
369
|
-
method = :"#{command}
|
298
|
+
method = :"#{command}_for_alter"
|
370
299
|
|
371
300
|
if respond_to?(method, true)
|
372
301
|
send(method, table, *arguments)
|
@@ -378,6 +307,11 @@ module ActiveRecord
|
|
378
307
|
execute("ALTER TABLE #{quote_table_name(table_name)} #{sqls}")
|
379
308
|
end
|
380
309
|
|
310
|
+
def change_table_comment(table_name, comment) #:nodoc:
|
311
|
+
comment = "" if comment.nil?
|
312
|
+
execute("ALTER TABLE #{quote_table_name(table_name)} COMMENT #{quote(comment)}")
|
313
|
+
end
|
314
|
+
|
381
315
|
# Renames a table.
|
382
316
|
#
|
383
317
|
# Example:
|
@@ -418,32 +352,33 @@ module ActiveRecord
|
|
418
352
|
|
419
353
|
def change_column_default(table_name, column_name, default_or_changes) #:nodoc:
|
420
354
|
default = extract_new_default_value(default_or_changes)
|
421
|
-
|
422
|
-
change_column table_name, column_name, column.sql_type, default: default
|
355
|
+
change_column table_name, column_name, nil, default: default
|
423
356
|
end
|
424
357
|
|
425
358
|
def change_column_null(table_name, column_name, null, default = nil) #:nodoc:
|
426
|
-
column = column_for(table_name, column_name)
|
427
|
-
|
428
359
|
unless null || default.nil?
|
429
360
|
execute("UPDATE #{quote_table_name(table_name)} SET #{quote_column_name(column_name)}=#{quote(default)} WHERE #{quote_column_name(column_name)} IS NULL")
|
430
361
|
end
|
431
362
|
|
432
|
-
change_column table_name, column_name,
|
363
|
+
change_column table_name, column_name, nil, null: null
|
364
|
+
end
|
365
|
+
|
366
|
+
def change_column_comment(table_name, column_name, comment) #:nodoc:
|
367
|
+
change_column table_name, column_name, nil, comment: comment
|
433
368
|
end
|
434
369
|
|
435
370
|
def change_column(table_name, column_name, type, options = {}) #:nodoc:
|
436
|
-
execute("ALTER TABLE #{quote_table_name(table_name)} #{
|
371
|
+
execute("ALTER TABLE #{quote_table_name(table_name)} #{change_column_for_alter(table_name, column_name, type, options)}")
|
437
372
|
end
|
438
373
|
|
439
374
|
def rename_column(table_name, column_name, new_column_name) #:nodoc:
|
440
|
-
execute("ALTER TABLE #{quote_table_name(table_name)} #{
|
375
|
+
execute("ALTER TABLE #{quote_table_name(table_name)} #{rename_column_for_alter(table_name, column_name, new_column_name)}")
|
441
376
|
rename_column_indexes(table_name, column_name, new_column_name)
|
442
377
|
end
|
443
378
|
|
444
379
|
def add_index(table_name, column_name, options = {}) #:nodoc:
|
445
380
|
index_name, index_type, index_columns, _, index_algorithm, index_using, comment = add_index_options(table_name, column_name, options)
|
446
|
-
sql = "CREATE #{index_type} INDEX #{quote_column_name(index_name)} #{index_using} ON #{quote_table_name(table_name)} (#{index_columns}) #{index_algorithm}"
|
381
|
+
sql = "CREATE #{index_type} INDEX #{quote_column_name(index_name)} #{index_using} ON #{quote_table_name(table_name)} (#{index_columns}) #{index_algorithm}".dup
|
447
382
|
execute add_sql_comment!(sql, comment)
|
448
383
|
end
|
449
384
|
|
@@ -529,7 +464,7 @@ module ActiveRecord
|
|
529
464
|
super
|
530
465
|
end
|
531
466
|
|
532
|
-
sql
|
467
|
+
sql = "#{sql} unsigned" if unsigned && type != :primary_key
|
533
468
|
sql
|
534
469
|
end
|
535
470
|
|
@@ -580,7 +515,7 @@ module ActiveRecord
|
|
580
515
|
s.gsub(/\s+(?:ASC|DESC)\b/i, "")
|
581
516
|
}.reject(&:blank?).map.with_index { |column, i| "#{column} AS alias_#{i}" }
|
582
517
|
|
583
|
-
|
518
|
+
(order_columns << super).join(", ")
|
584
519
|
end
|
585
520
|
|
586
521
|
def strict_mode?
|
@@ -591,9 +526,52 @@ module ActiveRecord
|
|
591
526
|
index.using == :btree || super
|
592
527
|
end
|
593
528
|
|
529
|
+
def insert_fixtures_set(fixture_set, tables_to_delete = [])
|
530
|
+
with_multi_statements do
|
531
|
+
super { discard_remaining_results }
|
532
|
+
end
|
533
|
+
end
|
534
|
+
|
594
535
|
private
|
536
|
+
def combine_multi_statements(total_sql)
|
537
|
+
total_sql.each_with_object([]) do |sql, total_sql_chunks|
|
538
|
+
previous_packet = total_sql_chunks.last
|
539
|
+
sql << ";\n"
|
540
|
+
if max_allowed_packet_reached?(sql, previous_packet) || total_sql_chunks.empty?
|
541
|
+
total_sql_chunks << sql
|
542
|
+
else
|
543
|
+
previous_packet << sql
|
544
|
+
end
|
545
|
+
end
|
546
|
+
end
|
547
|
+
|
548
|
+
def max_allowed_packet_reached?(current_packet, previous_packet)
|
549
|
+
if current_packet.bytesize > max_allowed_packet
|
550
|
+
raise ActiveRecordError, "Fixtures set is too large #{current_packet.bytesize}. Consider increasing the max_allowed_packet variable."
|
551
|
+
elsif previous_packet.nil?
|
552
|
+
false
|
553
|
+
else
|
554
|
+
(current_packet.bytesize + previous_packet.bytesize) > max_allowed_packet
|
555
|
+
end
|
556
|
+
end
|
557
|
+
|
558
|
+
def max_allowed_packet
|
559
|
+
bytes_margin = 2
|
560
|
+
@max_allowed_packet ||= (show_variable("max_allowed_packet") - bytes_margin)
|
561
|
+
end
|
562
|
+
|
563
|
+
def with_multi_statements
|
564
|
+
previous_flags = @config[:flags]
|
565
|
+
@config[:flags] = Mysql2::Client::MULTI_STATEMENTS
|
566
|
+
reconnect!
|
567
|
+
|
568
|
+
yield
|
569
|
+
ensure
|
570
|
+
@config[:flags] = previous_flags
|
571
|
+
reconnect!
|
572
|
+
end
|
595
573
|
|
596
|
-
def initialize_type_map(m)
|
574
|
+
def initialize_type_map(m = type_map)
|
597
575
|
super
|
598
576
|
|
599
577
|
register_class_with_limit m, %r(char)i, MysqlString
|
@@ -608,7 +586,6 @@ module ActiveRecord
|
|
608
586
|
m.register_type %r(longblob)i, Type::Binary.new(limit: 2**32 - 1)
|
609
587
|
m.register_type %r(^float)i, Type::Float.new(limit: 24)
|
610
588
|
m.register_type %r(^double)i, Type::Float.new(limit: 53)
|
611
|
-
m.register_type %r(^json)i, MysqlJson.new
|
612
589
|
|
613
590
|
register_integer_type m, %r(^bigint)i, limit: 8
|
614
591
|
register_integer_type m, %r(^int)i, limit: 4
|
@@ -651,29 +628,6 @@ module ActiveRecord
|
|
651
628
|
end
|
652
629
|
end
|
653
630
|
|
654
|
-
def fetch_type_metadata(sql_type, extra = "")
|
655
|
-
MySQL::TypeMetadata.new(super(sql_type), extra: extra)
|
656
|
-
end
|
657
|
-
|
658
|
-
def add_index_length(quoted_columns, **options)
|
659
|
-
if length = options[:length]
|
660
|
-
case length
|
661
|
-
when Hash
|
662
|
-
length = length.symbolize_keys
|
663
|
-
quoted_columns.each { |name, column| column << "(#{length[name]})" if length[name].present? }
|
664
|
-
when Integer
|
665
|
-
quoted_columns.each { |name, column| column << "(#{length})" }
|
666
|
-
end
|
667
|
-
end
|
668
|
-
|
669
|
-
quoted_columns
|
670
|
-
end
|
671
|
-
|
672
|
-
def add_options_for_index_columns(quoted_columns, **options)
|
673
|
-
quoted_columns = add_index_length(quoted_columns, options)
|
674
|
-
super
|
675
|
-
end
|
676
|
-
|
677
631
|
# See https://dev.mysql.com/doc/refman/5.7/en/error-messages-server.html
|
678
632
|
ER_DUP_ENTRY = 1062
|
679
633
|
ER_NOT_NULL_VIOLATION = 1048
|
@@ -684,6 +638,9 @@ module ActiveRecord
|
|
684
638
|
ER_LOCK_DEADLOCK = 1213
|
685
639
|
ER_CANNOT_ADD_FOREIGN = 1215
|
686
640
|
ER_CANNOT_CREATE_TABLE = 1005
|
641
|
+
ER_LOCK_WAIT_TIMEOUT = 1205
|
642
|
+
ER_QUERY_INTERRUPTED = 1317
|
643
|
+
ER_QUERY_TIMEOUT = 3024
|
687
644
|
|
688
645
|
def translate_exception(exception, message)
|
689
646
|
case error_number(exception)
|
@@ -707,19 +664,20 @@ module ActiveRecord
|
|
707
664
|
NotNullViolation.new(message)
|
708
665
|
when ER_LOCK_DEADLOCK
|
709
666
|
Deadlocked.new(message)
|
667
|
+
when ER_LOCK_WAIT_TIMEOUT
|
668
|
+
LockWaitTimeout.new(message)
|
669
|
+
when ER_QUERY_TIMEOUT
|
670
|
+
StatementTimeout.new(message)
|
671
|
+
when ER_QUERY_INTERRUPTED
|
672
|
+
QueryCanceled.new(message)
|
710
673
|
else
|
711
674
|
super
|
712
675
|
end
|
713
676
|
end
|
714
677
|
|
715
|
-
def
|
716
|
-
td = create_table_definition(table_name)
|
717
|
-
cd = td.new_column_definition(column_name, type, options)
|
718
|
-
schema_creation.accept(AddColumnDefinition.new(cd))
|
719
|
-
end
|
720
|
-
|
721
|
-
def change_column_sql(table_name, column_name, type, options = {})
|
678
|
+
def change_column_for_alter(table_name, column_name, type, options = {})
|
722
679
|
column = column_for(table_name, column_name)
|
680
|
+
type ||= column.sql_type
|
723
681
|
|
724
682
|
unless options.key?(:default)
|
725
683
|
options[:default] = column.default
|
@@ -738,7 +696,7 @@ module ActiveRecord
|
|
738
696
|
schema_creation.accept(ChangeColumnDefinition.new(cd, column.name))
|
739
697
|
end
|
740
698
|
|
741
|
-
def
|
699
|
+
def rename_column_for_alter(table_name, column_name, new_column_name)
|
742
700
|
column = column_for(table_name, column_name)
|
743
701
|
options = {
|
744
702
|
default: column.default,
|
@@ -752,46 +710,37 @@ module ActiveRecord
|
|
752
710
|
schema_creation.accept(ChangeColumnDefinition.new(cd, column.name))
|
753
711
|
end
|
754
712
|
|
755
|
-
def
|
756
|
-
"DROP #{quote_column_name(column_name)}"
|
757
|
-
end
|
758
|
-
|
759
|
-
def remove_columns_sql(table_name, *column_names)
|
760
|
-
column_names.map { |column_name| remove_column_sql(table_name, column_name) }
|
761
|
-
end
|
762
|
-
|
763
|
-
def add_index_sql(table_name, column_name, options = {})
|
713
|
+
def add_index_for_alter(table_name, column_name, options = {})
|
764
714
|
index_name, index_type, index_columns, _, index_algorithm, index_using = add_index_options(table_name, column_name, options)
|
765
715
|
index_algorithm[0, 0] = ", " if index_algorithm.present?
|
766
716
|
"ADD #{index_type} INDEX #{quote_column_name(index_name)} #{index_using} (#{index_columns})#{index_algorithm}"
|
767
717
|
end
|
768
718
|
|
769
|
-
def
|
719
|
+
def remove_index_for_alter(table_name, options = {})
|
770
720
|
index_name = index_name_for_remove(table_name, options)
|
771
|
-
"DROP INDEX #{index_name}"
|
721
|
+
"DROP INDEX #{quote_column_name(index_name)}"
|
772
722
|
end
|
773
723
|
|
774
|
-
def
|
775
|
-
[
|
724
|
+
def add_timestamps_for_alter(table_name, options = {})
|
725
|
+
[add_column_for_alter(table_name, :created_at, :datetime, options), add_column_for_alter(table_name, :updated_at, :datetime, options)]
|
776
726
|
end
|
777
727
|
|
778
|
-
def
|
779
|
-
[
|
728
|
+
def remove_timestamps_for_alter(table_name, options = {})
|
729
|
+
[remove_column_for_alter(table_name, :updated_at), remove_column_for_alter(table_name, :created_at)]
|
780
730
|
end
|
781
731
|
|
782
732
|
# MySQL is too stupid to create a temporary table for use subquery, so we have
|
783
733
|
# to give it some prompting in the form of a subsubquery. Ugh!
|
784
734
|
def subquery_for(key, select)
|
785
|
-
|
786
|
-
|
735
|
+
subselect = select.clone
|
736
|
+
subselect.projections = [key]
|
787
737
|
|
788
738
|
# Materialize subquery by adding distinct
|
789
739
|
# to work with MySQL 5.7.6 which sets optimizer_switch='derived_merge=on'
|
790
|
-
|
740
|
+
subselect.distinct unless select.limit || select.offset || select.orders.any?
|
791
741
|
|
792
|
-
|
793
|
-
subselect.project
|
794
|
-
subselect.from subsubselect.as("__active_record_temp")
|
742
|
+
key_name = quote_column_name(key.name)
|
743
|
+
Arel::SelectManager.new(subselect.as("__active_record_temp")).project(Arel.sql(key_name))
|
795
744
|
end
|
796
745
|
|
797
746
|
def supports_rename_index?
|
@@ -812,7 +761,7 @@ module ActiveRecord
|
|
812
761
|
defaults = [":default", :default].to_set
|
813
762
|
|
814
763
|
# Make MySQL reject illegal values rather than truncating or blanking them, see
|
815
|
-
#
|
764
|
+
# https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_strict_all_tables
|
816
765
|
# If the user has provided another value for sql_mode, don't replace it.
|
817
766
|
if sql_mode = variables.delete("sql_mode")
|
818
767
|
sql_mode = quote(sql_mode)
|
@@ -829,10 +778,10 @@ module ActiveRecord
|
|
829
778
|
sql_mode_assignment = "@@SESSION.sql_mode = #{sql_mode}, " if sql_mode
|
830
779
|
|
831
780
|
# NAMES does not have an equals sign, see
|
832
|
-
#
|
781
|
+
# https://dev.mysql.com/doc/refman/5.7/en/set-names.html
|
833
782
|
# (trailing comma because variable_assignments will always have content)
|
834
783
|
if @config[:encoding]
|
835
|
-
encoding = "NAMES #{@config[:encoding]}"
|
784
|
+
encoding = "NAMES #{@config[:encoding]}".dup
|
836
785
|
encoding << " COLLATE #{@config[:collation]}" if @config[:collation]
|
837
786
|
encoding << ", "
|
838
787
|
end
|
@@ -857,41 +806,24 @@ module ActiveRecord
|
|
857
806
|
end
|
858
807
|
end
|
859
808
|
|
860
|
-
def extract_foreign_key_action(specifier) # :nodoc:
|
861
|
-
case specifier
|
862
|
-
when "CASCADE"; :cascade
|
863
|
-
when "SET NULL"; :nullify
|
864
|
-
end
|
865
|
-
end
|
866
|
-
|
867
809
|
def create_table_info(table_name) # :nodoc:
|
868
810
|
exec_query("SHOW CREATE TABLE #{quote_table_name(table_name)}", "SCHEMA").first["Create Table"]
|
869
811
|
end
|
870
812
|
|
871
|
-
def
|
872
|
-
MySQL
|
813
|
+
def arel_visitor
|
814
|
+
Arel::Visitors::MySQL.new(self)
|
873
815
|
end
|
874
816
|
|
875
817
|
def mismatched_foreign_key(message)
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
REFERENCES\s*(`?(?<target_table>\w+)`?)\s*\(`?(?<primary_key>\w+)`?\)
|
880
|
-
/xmi.match(message)
|
881
|
-
|
882
|
-
options = {
|
818
|
+
parts = message.scan(/`(\w+)`[ $)]/).flatten
|
819
|
+
MismatchedForeignKey.new(
|
820
|
+
self,
|
883
821
|
message: message,
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
options[:target_table] = match[:target_table]
|
890
|
-
options[:primary_key] = match[:primary_key]
|
891
|
-
options[:primary_key_column] = column_for(match[:target_table], match[:primary_key])
|
892
|
-
end
|
893
|
-
|
894
|
-
MismatchedForeignKey.new(options)
|
822
|
+
table: parts[0],
|
823
|
+
foreign_key: parts[1],
|
824
|
+
target_table: parts[2],
|
825
|
+
primary_key: parts[3],
|
826
|
+
)
|
895
827
|
end
|
896
828
|
|
897
829
|
def integer_to_sql(limit) # :nodoc:
|
@@ -929,14 +861,11 @@ module ActiveRecord
|
|
929
861
|
full_version.match(/^(?:5\.5\.5-)?(\d+\.\d+\.\d+)/)[1]
|
930
862
|
end
|
931
863
|
|
932
|
-
class MysqlJson < Type::Internal::AbstractJson # :nodoc:
|
933
|
-
end
|
934
|
-
|
935
864
|
class MysqlString < Type::String # :nodoc:
|
936
865
|
def serialize(value)
|
937
866
|
case value
|
938
|
-
when true then
|
939
|
-
when false then
|
867
|
+
when true then "1"
|
868
|
+
when false then "0"
|
940
869
|
else super
|
941
870
|
end
|
942
871
|
end
|
@@ -945,14 +874,13 @@ module ActiveRecord
|
|
945
874
|
|
946
875
|
def cast_value(value)
|
947
876
|
case value
|
948
|
-
when true then
|
949
|
-
when false then
|
877
|
+
when true then "1"
|
878
|
+
when false then "0"
|
950
879
|
else super
|
951
880
|
end
|
952
881
|
end
|
953
882
|
end
|
954
883
|
|
955
|
-
ActiveRecord::Type.register(:json, MysqlJson, adapter: :mysql2)
|
956
884
|
ActiveRecord::Type.register(:string, MysqlString, adapter: :mysql2)
|
957
885
|
ActiveRecord::Type.register(:unsigned_integer, Type::UnsignedInteger, adapter: :mysql2)
|
958
886
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
# :stopdoc:
|
3
5
|
module ConnectionAdapters
|
@@ -9,7 +11,7 @@ module ActiveRecord
|
|
9
11
|
|
10
12
|
# Instantiates a new column in the table.
|
11
13
|
#
|
12
|
-
# +name+ is the column's name, such as <tt>supplier_id</tt> in <tt>supplier_id
|
14
|
+
# +name+ is the column's name, such as <tt>supplier_id</tt> in <tt>supplier_id bigint</tt>.
|
13
15
|
# +default+ is the type-casted default value, such as +new+ in <tt>sales_stage varchar(20) default 'new'</tt>.
|
14
16
|
# +sql_type_metadata+ is various information about the type of the column
|
15
17
|
# +null+ determines if this column allows +NULL+ values.
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "uri"
|
2
4
|
|
3
5
|
module ActiveRecord
|
@@ -181,13 +183,25 @@ module ActiveRecord
|
|
181
183
|
|
182
184
|
raise(AdapterNotSpecified, "database configuration does not specify adapter") unless spec.key?(:adapter)
|
183
185
|
|
186
|
+
# Require the adapter itself and give useful feedback about
|
187
|
+
# 1. Missing adapter gems and
|
188
|
+
# 2. Adapter gems' missing dependencies.
|
184
189
|
path_to_adapter = "active_record/connection_adapters/#{spec[:adapter]}_adapter"
|
185
190
|
begin
|
186
191
|
require path_to_adapter
|
187
|
-
rescue Gem::LoadError => e
|
188
|
-
raise Gem::LoadError, "Specified '#{spec[:adapter]}' for database adapter, but the gem is not loaded. Add `gem '#{e.name}'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord)."
|
189
192
|
rescue LoadError => e
|
190
|
-
|
193
|
+
# We couldn't require the adapter itself. Raise an exception that
|
194
|
+
# points out config typos and missing gems.
|
195
|
+
if e.path == path_to_adapter
|
196
|
+
# We can assume that a non-builtin adapter was specified, so it's
|
197
|
+
# either misspelled or missing from Gemfile.
|
198
|
+
raise e.class, "Could not load the '#{spec[:adapter]}' Active Record adapter. Ensure that the adapter is spelled correctly in config/database.yml and that you've added the necessary adapter gem to your Gemfile.", e.backtrace
|
199
|
+
|
200
|
+
# Bubbled up from the adapter require. Prefix the exception message
|
201
|
+
# with some guidance about how to address it and reraise.
|
202
|
+
else
|
203
|
+
raise e.class, "Error loading the '#{spec[:adapter]}' Active Record adapter. Missing a gem it depends on? #{e.message}", e.backtrace
|
204
|
+
end
|
191
205
|
end
|
192
206
|
|
193
207
|
adapter_method = "#{spec[:adapter]}_connection"
|
@@ -1,15 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
module ConnectionAdapters
|
3
5
|
module MySQL
|
4
6
|
module DatabaseStatements
|
5
7
|
# Returns an ActiveRecord::Result instance.
|
6
|
-
def select_all(
|
8
|
+
def select_all(*) # :nodoc:
|
7
9
|
result = if ExplainRegistry.collect? && prepared_statements
|
8
10
|
unprepared_statement { super }
|
9
11
|
else
|
10
12
|
super
|
11
13
|
end
|
12
|
-
|
14
|
+
discard_remaining_results
|
13
15
|
result
|
14
16
|
end
|
15
17
|
|
@@ -48,11 +50,18 @@ module ActiveRecord
|
|
48
50
|
alias :exec_update :exec_delete
|
49
51
|
|
50
52
|
private
|
53
|
+
def default_insert_value(column)
|
54
|
+
Arel.sql("DEFAULT") unless column.auto_increment?
|
55
|
+
end
|
51
56
|
|
52
57
|
def last_inserted_id(result)
|
53
58
|
@connection.last_id
|
54
59
|
end
|
55
60
|
|
61
|
+
def discard_remaining_results
|
62
|
+
@connection.next_result while @connection.more_results?
|
63
|
+
end
|
64
|
+
|
56
65
|
def exec_stmt_and_free(sql, name, binds, cache_stmt: false)
|
57
66
|
# make sure we carry over any changes to ActiveRecord::Base.default_timezone that have been
|
58
67
|
# made since we established the connection
|