activerecord 4.2.0 → 6.0.5.1
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 +5 -5
- data/CHANGELOG.md +852 -801
- data/MIT-LICENSE +4 -2
- data/README.rdoc +14 -13
- data/examples/performance.rb +33 -32
- data/examples/simple.rb +5 -4
- data/lib/active_record/advisory_lock_base.rb +18 -0
- data/lib/active_record/aggregations.rb +267 -249
- data/lib/active_record/association_relation.rb +26 -6
- data/lib/active_record/associations/alias_tracker.rb +29 -36
- data/lib/active_record/associations/association.rb +137 -55
- data/lib/active_record/associations/association_scope.rb +110 -132
- data/lib/active_record/associations/belongs_to_association.rb +67 -54
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +8 -12
- data/lib/active_record/associations/builder/association.rb +27 -40
- data/lib/active_record/associations/builder/belongs_to.rb +69 -55
- data/lib/active_record/associations/builder/collection_association.rb +10 -29
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +58 -70
- data/lib/active_record/associations/builder/has_many.rb +8 -4
- data/lib/active_record/associations/builder/has_one.rb +46 -5
- data/lib/active_record/associations/builder/singular_association.rb +16 -10
- data/lib/active_record/associations/collection_association.rb +150 -275
- data/lib/active_record/associations/collection_proxy.rb +253 -152
- data/lib/active_record/associations/foreign_association.rb +20 -0
- data/lib/active_record/associations/has_many_association.rb +35 -84
- data/lib/active_record/associations/has_many_through_association.rb +62 -80
- data/lib/active_record/associations/has_one_association.rb +62 -49
- data/lib/active_record/associations/has_one_through_association.rb +20 -11
- data/lib/active_record/associations/join_dependency/join_association.rb +43 -78
- data/lib/active_record/associations/join_dependency/join_base.rb +10 -9
- data/lib/active_record/associations/join_dependency/join_part.rb +14 -14
- data/lib/active_record/associations/join_dependency.rb +159 -162
- data/lib/active_record/associations/preloader/association.rb +102 -113
- data/lib/active_record/associations/preloader/through_association.rb +85 -65
- data/lib/active_record/associations/preloader.rb +96 -95
- data/lib/active_record/associations/singular_association.rb +18 -45
- data/lib/active_record/associations/through_association.rb +49 -24
- data/lib/active_record/associations.rb +1737 -1596
- data/lib/active_record/attribute_assignment.rb +57 -185
- data/lib/active_record/attribute_decorators.rb +39 -17
- data/lib/active_record/attribute_methods/before_type_cast.rb +14 -5
- data/lib/active_record/attribute_methods/dirty.rb +174 -134
- data/lib/active_record/attribute_methods/primary_key.rb +90 -84
- data/lib/active_record/attribute_methods/query.rb +6 -5
- data/lib/active_record/attribute_methods/read.rb +20 -77
- data/lib/active_record/attribute_methods/serialization.rb +40 -21
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +61 -37
- data/lib/active_record/attribute_methods/write.rb +33 -56
- data/lib/active_record/attribute_methods.rb +124 -143
- data/lib/active_record/attributes.rb +213 -74
- data/lib/active_record/autosave_association.rb +125 -54
- data/lib/active_record/base.rb +60 -49
- data/lib/active_record/callbacks.rb +101 -76
- data/lib/active_record/coders/json.rb +3 -1
- data/lib/active_record/coders/yaml_column.rb +36 -13
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +810 -291
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +26 -8
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +253 -108
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +83 -24
- data/lib/active_record/connection_adapters/abstract/quoting.rb +171 -53
- data/lib/active_record/connection_adapters/abstract/savepoints.rb +6 -4
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +74 -47
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +383 -239
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +79 -36
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +736 -235
- data/lib/active_record/connection_adapters/abstract/transaction.rb +190 -87
- data/lib/active_record/connection_adapters/abstract_adapter.rb +487 -192
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +536 -600
- data/lib/active_record/connection_adapters/column.rb +56 -43
- data/lib/active_record/connection_adapters/connection_specification.rb +174 -153
- data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +29 -0
- data/lib/active_record/connection_adapters/mysql/column.rb +27 -0
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +196 -0
- data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +71 -0
- data/lib/active_record/connection_adapters/mysql/quoting.rb +81 -0
- data/lib/active_record/connection_adapters/mysql/schema_creation.rb +71 -0
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +95 -0
- data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +88 -0
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +268 -0
- data/lib/active_record/connection_adapters/mysql/type_metadata.rb +31 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +59 -196
- data/lib/active_record/connection_adapters/postgresql/column.rb +21 -11
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +71 -115
- data/lib/active_record/connection_adapters/postgresql/explain_pretty_printer.rb +44 -0
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +49 -57
- data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +9 -8
- data/lib/active_record/connection_adapters/postgresql/oid/bit_varying.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/bytea.rb +5 -2
- data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +5 -1
- data/lib/active_record/connection_adapters/postgresql/oid/date.rb +13 -1
- data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +17 -13
- data/lib/active_record/connection_adapters/postgresql/oid/decimal.rb +3 -1
- data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +6 -3
- data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +31 -20
- data/lib/active_record/connection_adapters/postgresql/oid/inet.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb +3 -11
- data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +44 -0
- data/lib/active_record/connection_adapters/postgresql/oid/money.rb +7 -9
- data/lib/active_record/connection_adapters/postgresql/oid/{infinity.rb → oid.rb} +5 -3
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +32 -11
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +70 -34
- data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +4 -1
- data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +67 -51
- data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +9 -5
- data/lib/active_record/connection_adapters/postgresql/oid/vector.rb +3 -1
- data/lib/active_record/connection_adapters/postgresql/oid/xml.rb +3 -1
- data/lib/active_record/connection_adapters/postgresql/oid.rb +23 -25
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +144 -47
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +27 -14
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +76 -0
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +178 -108
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +49 -0
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +465 -291
- data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +36 -0
- data/lib/active_record/connection_adapters/postgresql/utils.rb +11 -8
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +565 -363
- data/lib/active_record/connection_adapters/schema_cache.rb +72 -25
- data/lib/active_record/connection_adapters/sql_type_metadata.rb +37 -0
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +119 -0
- data/lib/active_record/connection_adapters/sqlite3/explain_pretty_printer.rb +21 -0
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +102 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +17 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_definitions.rb +19 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +18 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +137 -0
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +299 -364
- data/lib/active_record/connection_adapters/statement_pool.rb +33 -13
- data/lib/active_record/connection_handling.rb +167 -41
- data/lib/active_record/core.rb +277 -233
- data/lib/active_record/counter_cache.rb +71 -50
- data/lib/active_record/database_configurations/database_config.rb +37 -0
- data/lib/active_record/database_configurations/hash_config.rb +50 -0
- data/lib/active_record/database_configurations/url_config.rb +78 -0
- data/lib/active_record/database_configurations.rb +233 -0
- data/lib/active_record/define_callbacks.rb +22 -0
- data/lib/active_record/dynamic_matchers.rb +87 -106
- data/lib/active_record/enum.rb +172 -89
- data/lib/active_record/errors.rb +189 -53
- data/lib/active_record/explain.rb +22 -11
- data/lib/active_record/explain_registry.rb +4 -2
- data/lib/active_record/explain_subscriber.rb +11 -6
- data/lib/active_record/fixture_set/file.rb +35 -9
- data/lib/active_record/fixture_set/model_metadata.rb +33 -0
- data/lib/active_record/fixture_set/render_context.rb +17 -0
- data/lib/active_record/fixture_set/table_row.rb +152 -0
- data/lib/active_record/fixture_set/table_rows.rb +46 -0
- data/lib/active_record/fixtures.rb +225 -497
- data/lib/active_record/gem_version.rb +6 -4
- data/lib/active_record/inheritance.rb +158 -115
- data/lib/active_record/insert_all.rb +179 -0
- data/lib/active_record/integration.rb +123 -29
- data/lib/active_record/internal_metadata.rb +53 -0
- data/lib/active_record/legacy_yaml_adapter.rb +48 -0
- data/lib/active_record/locale/en.yml +3 -2
- data/lib/active_record/locking/optimistic.rb +99 -98
- data/lib/active_record/locking/pessimistic.rb +18 -6
- data/lib/active_record/log_subscriber.rb +76 -33
- data/lib/active_record/middleware/database_selector/resolver/session.rb +45 -0
- data/lib/active_record/middleware/database_selector/resolver.rb +87 -0
- data/lib/active_record/middleware/database_selector.rb +74 -0
- data/lib/active_record/migration/command_recorder.rb +166 -91
- data/lib/active_record/migration/compatibility.rb +244 -0
- data/lib/active_record/migration/join_table.rb +8 -7
- data/lib/active_record/migration.rb +636 -290
- data/lib/active_record/model_schema.rb +344 -112
- data/lib/active_record/nested_attributes.rb +265 -215
- data/lib/active_record/no_touching.rb +15 -2
- data/lib/active_record/null_relation.rb +24 -38
- data/lib/active_record/persistence.rb +559 -125
- data/lib/active_record/query_cache.rb +19 -23
- data/lib/active_record/querying.rb +44 -30
- data/lib/active_record/railtie.rb +166 -47
- data/lib/active_record/railties/collection_cache_association_loading.rb +34 -0
- data/lib/active_record/railties/console_sandbox.rb +2 -0
- data/lib/active_record/railties/controller_runtime.rb +34 -33
- data/lib/active_record/railties/databases.rake +341 -202
- data/lib/active_record/readonly_attributes.rb +5 -4
- data/lib/active_record/reflection.rb +461 -302
- data/lib/active_record/relation/batches/batch_enumerator.rb +69 -0
- data/lib/active_record/relation/batches.rb +206 -55
- data/lib/active_record/relation/calculations.rb +270 -249
- data/lib/active_record/relation/delegation.rb +76 -84
- data/lib/active_record/relation/finder_methods.rb +287 -255
- data/lib/active_record/relation/from_clause.rb +30 -0
- data/lib/active_record/relation/merger.rb +86 -68
- data/lib/active_record/relation/predicate_builder/array_handler.rb +27 -25
- data/lib/active_record/relation/predicate_builder/association_query_value.rb +43 -0
- data/lib/active_record/relation/predicate_builder/base_handler.rb +18 -0
- data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +19 -0
- data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +53 -0
- data/lib/active_record/relation/predicate_builder/range_handler.rb +22 -0
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +7 -1
- data/lib/active_record/relation/predicate_builder.rb +112 -92
- data/lib/active_record/relation/query_attribute.rb +50 -0
- data/lib/active_record/relation/query_methods.rb +612 -392
- data/lib/active_record/relation/record_fetch_warning.rb +51 -0
- data/lib/active_record/relation/spawn_methods.rb +18 -17
- data/lib/active_record/relation/where_clause.rb +189 -0
- data/lib/active_record/relation/where_clause_factory.rb +33 -0
- data/lib/active_record/relation.rb +533 -340
- data/lib/active_record/result.rb +79 -43
- data/lib/active_record/runtime_registry.rb +6 -4
- data/lib/active_record/sanitization.rb +144 -121
- data/lib/active_record/schema.rb +21 -24
- data/lib/active_record/schema_dumper.rb +112 -93
- data/lib/active_record/schema_migration.rb +24 -20
- data/lib/active_record/scoping/default.rb +98 -82
- data/lib/active_record/scoping/named.rb +91 -33
- data/lib/active_record/scoping.rb +45 -27
- data/lib/active_record/secure_token.rb +40 -0
- data/lib/active_record/serialization.rb +5 -5
- data/lib/active_record/statement_cache.rb +73 -36
- data/lib/active_record/store.rb +127 -42
- data/lib/active_record/suppressor.rb +61 -0
- data/lib/active_record/table_metadata.rb +90 -0
- data/lib/active_record/tasks/database_tasks.rb +309 -99
- data/lib/active_record/tasks/mysql_database_tasks.rb +58 -89
- data/lib/active_record/tasks/postgresql_database_tasks.rb +81 -31
- data/lib/active_record/tasks/sqlite_database_tasks.rb +37 -16
- data/lib/active_record/test_databases.rb +23 -0
- data/lib/active_record/test_fixtures.rb +243 -0
- data/lib/active_record/timestamp.rb +86 -41
- data/lib/active_record/touch_later.rb +65 -0
- data/lib/active_record/transactions.rb +222 -146
- data/lib/active_record/translation.rb +3 -1
- data/lib/active_record/type/adapter_specific_registry.rb +126 -0
- data/lib/active_record/type/date.rb +4 -41
- data/lib/active_record/type/date_time.rb +4 -38
- data/lib/active_record/type/decimal_without_scale.rb +6 -2
- data/lib/active_record/type/hash_lookup_type_map.rb +12 -5
- data/lib/active_record/type/internal/timezone.rb +17 -0
- data/lib/active_record/type/json.rb +30 -0
- data/lib/active_record/type/serialized.rb +29 -15
- data/lib/active_record/type/text.rb +2 -2
- data/lib/active_record/type/time.rb +21 -16
- data/lib/active_record/type/type_map.rb +16 -19
- data/lib/active_record/type/unsigned_integer.rb +9 -8
- data/lib/active_record/type.rb +77 -23
- data/lib/active_record/type_caster/connection.rb +34 -0
- data/lib/active_record/type_caster/map.rb +20 -0
- data/lib/active_record/type_caster.rb +9 -0
- data/lib/active_record/validations/absence.rb +25 -0
- data/lib/active_record/validations/associated.rb +12 -4
- data/lib/active_record/validations/length.rb +26 -0
- data/lib/active_record/validations/presence.rb +14 -13
- data/lib/active_record/validations/uniqueness.rb +43 -46
- data/lib/active_record/validations.rb +38 -35
- data/lib/active_record/version.rb +3 -1
- data/lib/active_record.rb +44 -21
- data/lib/arel/alias_predication.rb +9 -0
- data/lib/arel/attributes/attribute.rb +37 -0
- data/lib/arel/attributes.rb +22 -0
- data/lib/arel/collectors/bind.rb +24 -0
- data/lib/arel/collectors/composite.rb +31 -0
- data/lib/arel/collectors/plain_string.rb +20 -0
- data/lib/arel/collectors/sql_string.rb +20 -0
- data/lib/arel/collectors/substitute_binds.rb +28 -0
- data/lib/arel/crud.rb +42 -0
- data/lib/arel/delete_manager.rb +18 -0
- data/lib/arel/errors.rb +9 -0
- data/lib/arel/expressions.rb +29 -0
- data/lib/arel/factory_methods.rb +49 -0
- data/lib/arel/insert_manager.rb +49 -0
- data/lib/arel/math.rb +45 -0
- data/lib/arel/nodes/and.rb +32 -0
- data/lib/arel/nodes/ascending.rb +23 -0
- data/lib/arel/nodes/binary.rb +52 -0
- data/lib/arel/nodes/bind_param.rb +36 -0
- data/lib/arel/nodes/case.rb +55 -0
- data/lib/arel/nodes/casted.rb +50 -0
- data/lib/arel/nodes/comment.rb +29 -0
- data/lib/arel/nodes/count.rb +12 -0
- data/lib/arel/nodes/delete_statement.rb +45 -0
- data/lib/arel/nodes/descending.rb +23 -0
- data/lib/arel/nodes/equality.rb +18 -0
- data/lib/arel/nodes/extract.rb +24 -0
- data/lib/arel/nodes/false.rb +16 -0
- data/lib/arel/nodes/full_outer_join.rb +8 -0
- data/lib/arel/nodes/function.rb +44 -0
- data/lib/arel/nodes/grouping.rb +8 -0
- data/lib/arel/nodes/in.rb +8 -0
- data/lib/arel/nodes/infix_operation.rb +80 -0
- data/lib/arel/nodes/inner_join.rb +8 -0
- data/lib/arel/nodes/insert_statement.rb +37 -0
- data/lib/arel/nodes/join_source.rb +20 -0
- data/lib/arel/nodes/matches.rb +18 -0
- data/lib/arel/nodes/named_function.rb +23 -0
- data/lib/arel/nodes/node.rb +50 -0
- data/lib/arel/nodes/node_expression.rb +13 -0
- data/lib/arel/nodes/outer_join.rb +8 -0
- data/lib/arel/nodes/over.rb +15 -0
- data/lib/arel/nodes/regexp.rb +16 -0
- data/lib/arel/nodes/right_outer_join.rb +8 -0
- data/lib/arel/nodes/select_core.rb +67 -0
- data/lib/arel/nodes/select_statement.rb +41 -0
- data/lib/arel/nodes/sql_literal.rb +16 -0
- data/lib/arel/nodes/string_join.rb +11 -0
- data/lib/arel/nodes/table_alias.rb +27 -0
- data/lib/arel/nodes/terminal.rb +16 -0
- data/lib/arel/nodes/true.rb +16 -0
- data/lib/arel/nodes/unary.rb +45 -0
- data/lib/arel/nodes/unary_operation.rb +20 -0
- data/lib/arel/nodes/unqualified_column.rb +22 -0
- data/lib/arel/nodes/update_statement.rb +41 -0
- data/lib/arel/nodes/values_list.rb +9 -0
- data/lib/arel/nodes/window.rb +126 -0
- data/lib/arel/nodes/with.rb +11 -0
- data/lib/arel/nodes.rb +68 -0
- data/lib/arel/order_predications.rb +13 -0
- data/lib/arel/predications.rb +256 -0
- data/lib/arel/select_manager.rb +271 -0
- data/lib/arel/table.rb +110 -0
- data/lib/arel/tree_manager.rb +72 -0
- data/lib/arel/update_manager.rb +34 -0
- data/lib/arel/visitors/depth_first.rb +203 -0
- data/lib/arel/visitors/dot.rb +296 -0
- data/lib/arel/visitors/ibm_db.rb +34 -0
- data/lib/arel/visitors/informix.rb +62 -0
- data/lib/arel/visitors/mssql.rb +156 -0
- data/lib/arel/visitors/mysql.rb +83 -0
- data/lib/arel/visitors/oracle.rb +158 -0
- data/lib/arel/visitors/oracle12.rb +65 -0
- data/lib/arel/visitors/postgresql.rb +109 -0
- data/lib/arel/visitors/sqlite.rb +38 -0
- data/lib/arel/visitors/to_sql.rb +888 -0
- data/lib/arel/visitors/visitor.rb +45 -0
- data/lib/arel/visitors/where_sql.rb +22 -0
- data/lib/arel/visitors.rb +20 -0
- data/lib/arel/window_predications.rb +9 -0
- data/lib/arel.rb +62 -0
- data/lib/rails/generators/active_record/application_record/application_record_generator.rb +26 -0
- data/lib/rails/generators/active_record/application_record/templates/application_record.rb.tt +5 -0
- data/lib/rails/generators/active_record/migration/migration_generator.rb +42 -37
- data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +24 -0
- data/lib/rails/generators/active_record/migration/templates/{migration.rb → migration.rb.tt} +11 -8
- data/lib/rails/generators/active_record/migration.rb +30 -1
- data/lib/rails/generators/active_record/model/model_generator.rb +18 -22
- data/lib/rails/generators/active_record/model/templates/model.rb.tt +22 -0
- data/lib/rails/generators/active_record.rb +7 -5
- metadata +174 -63
- data/lib/active_record/associations/preloader/belongs_to.rb +0 -17
- data/lib/active_record/associations/preloader/collection_association.rb +0 -24
- data/lib/active_record/associations/preloader/has_many.rb +0 -17
- data/lib/active_record/associations/preloader/has_many_through.rb +0 -19
- data/lib/active_record/associations/preloader/has_one.rb +0 -23
- data/lib/active_record/associations/preloader/has_one_through.rb +0 -9
- data/lib/active_record/associations/preloader/singular_association.rb +0 -21
- data/lib/active_record/attribute.rb +0 -149
- data/lib/active_record/attribute_set/builder.rb +0 -86
- data/lib/active_record/attribute_set.rb +0 -77
- data/lib/active_record/connection_adapters/mysql_adapter.rb +0 -491
- data/lib/active_record/connection_adapters/postgresql/array_parser.rb +0 -93
- data/lib/active_record/connection_adapters/postgresql/oid/float.rb +0 -21
- data/lib/active_record/connection_adapters/postgresql/oid/integer.rb +0 -11
- data/lib/active_record/connection_adapters/postgresql/oid/json.rb +0 -35
- data/lib/active_record/connection_adapters/postgresql/oid/time.rb +0 -11
- data/lib/active_record/railties/jdbcmysql_error.rb +0 -16
- data/lib/active_record/serializers/xml_serializer.rb +0 -193
- data/lib/active_record/type/big_integer.rb +0 -13
- data/lib/active_record/type/binary.rb +0 -50
- data/lib/active_record/type/boolean.rb +0 -30
- data/lib/active_record/type/decimal.rb +0 -40
- data/lib/active_record/type/decorator.rb +0 -14
- data/lib/active_record/type/float.rb +0 -19
- data/lib/active_record/type/integer.rb +0 -55
- data/lib/active_record/type/mutable.rb +0 -16
- data/lib/active_record/type/numeric.rb +0 -36
- data/lib/active_record/type/string.rb +0 -36
- data/lib/active_record/type/time_value.rb +0 -38
- data/lib/active_record/type/value.rb +0 -101
- data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb +0 -22
- data/lib/rails/generators/active_record/model/templates/model.rb +0 -10
- /data/lib/rails/generators/active_record/model/templates/{module.rb → module.rb.tt} +0 -0
@@ -1,14 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "set"
|
4
|
+
require "active_record/connection_adapters/determine_if_preparable_visitor"
|
5
|
+
require "active_record/connection_adapters/schema_cache"
|
6
|
+
require "active_record/connection_adapters/sql_type_metadata"
|
7
|
+
require "active_record/connection_adapters/abstract/schema_dumper"
|
8
|
+
require "active_record/connection_adapters/abstract/schema_creation"
|
9
|
+
require "active_support/concurrency/load_interlock_aware_monitor"
|
10
|
+
require "active_support/deprecation"
|
11
|
+
require "arel/collectors/bind"
|
12
|
+
require "arel/collectors/composite"
|
13
|
+
require "arel/collectors/sql_string"
|
14
|
+
require "arel/collectors/substitute_binds"
|
12
15
|
|
13
16
|
module ActiveRecord
|
14
17
|
module ConnectionAdapters # :nodoc:
|
@@ -17,22 +20,22 @@ module ActiveRecord
|
|
17
20
|
autoload :Column
|
18
21
|
autoload :ConnectionSpecification
|
19
22
|
|
20
|
-
autoload_at
|
23
|
+
autoload_at "active_record/connection_adapters/abstract/schema_definitions" do
|
21
24
|
autoload :IndexDefinition
|
22
25
|
autoload :ColumnDefinition
|
23
26
|
autoload :ChangeColumnDefinition
|
27
|
+
autoload :ForeignKeyDefinition
|
24
28
|
autoload :TableDefinition
|
25
29
|
autoload :Table
|
26
30
|
autoload :AlterTable
|
27
|
-
autoload :
|
31
|
+
autoload :ReferenceDefinition
|
28
32
|
end
|
29
33
|
|
30
|
-
autoload_at
|
34
|
+
autoload_at "active_record/connection_adapters/abstract/connection_pool" do
|
31
35
|
autoload :ConnectionHandler
|
32
|
-
autoload :ConnectionManagement
|
33
36
|
end
|
34
37
|
|
35
|
-
autoload_under
|
38
|
+
autoload_under "abstract" do
|
36
39
|
autoload :SchemaStatements
|
37
40
|
autoload :DatabaseStatements
|
38
41
|
autoload :DatabaseLimits
|
@@ -42,7 +45,7 @@ module ActiveRecord
|
|
42
45
|
autoload :Savepoints
|
43
46
|
end
|
44
47
|
|
45
|
-
autoload_at
|
48
|
+
autoload_at "active_record/connection_adapters/abstract/transaction" do
|
46
49
|
autoload :TransactionManager
|
47
50
|
autoload :NullTransaction
|
48
51
|
autoload :RealTransaction
|
@@ -54,34 +57,38 @@ module ActiveRecord
|
|
54
57
|
# related classes form the abstraction layer which makes this possible.
|
55
58
|
# An AbstractAdapter represents a connection to a database, and provides an
|
56
59
|
# abstract interface for database-specific functionality such as establishing
|
57
|
-
# a connection, escaping values, building the right SQL fragments for
|
58
|
-
# and
|
60
|
+
# a connection, escaping values, building the right SQL fragments for +:offset+
|
61
|
+
# and +:limit+ options, etc.
|
59
62
|
#
|
60
63
|
# All the concrete database adapters follow the interface laid down in this class.
|
61
|
-
# ActiveRecord::Base.connection returns an AbstractAdapter object, which
|
64
|
+
# {ActiveRecord::Base.connection}[rdoc-ref:ConnectionHandling#connection] returns an AbstractAdapter object, which
|
62
65
|
# you can use.
|
63
66
|
#
|
64
67
|
# Most of the methods in the adapter are useful during migrations. Most
|
65
|
-
# notably, the instance methods provided by
|
68
|
+
# notably, the instance methods provided by SchemaStatements are very useful.
|
66
69
|
class AbstractAdapter
|
67
|
-
ADAPTER_NAME =
|
70
|
+
ADAPTER_NAME = "Abstract"
|
71
|
+
include ActiveSupport::Callbacks
|
72
|
+
define_callbacks :checkout, :checkin
|
73
|
+
|
68
74
|
include Quoting, DatabaseStatements, SchemaStatements
|
69
75
|
include DatabaseLimits
|
70
76
|
include QueryCache
|
71
|
-
include
|
72
|
-
include MonitorMixin
|
73
|
-
include ColumnDumper
|
77
|
+
include Savepoints
|
74
78
|
|
75
79
|
SIMPLE_INT = /\A\d+\z/
|
80
|
+
COMMENT_REGEX = %r{/\*(?:[^\*]|\*[^/])*\*/}m
|
76
81
|
|
77
|
-
|
78
|
-
|
79
|
-
attr_accessor :visitor, :pool
|
80
|
-
attr_reader :schema_cache, :owner, :logger
|
82
|
+
attr_accessor :pool
|
83
|
+
attr_reader :visitor, :owner, :logger, :lock
|
81
84
|
alias :in_use? :owner
|
82
85
|
|
86
|
+
set_callback :checkin, :after, :enable_lazy_transactions!
|
87
|
+
|
83
88
|
def self.type_cast_config_to_integer(config)
|
84
|
-
if config
|
89
|
+
if config.is_a?(Integer)
|
90
|
+
config
|
91
|
+
elsif SIMPLE_INT.match?(config)
|
85
92
|
config.to_i
|
86
93
|
else
|
87
94
|
config
|
@@ -96,71 +103,182 @@ module ActiveRecord
|
|
96
103
|
end
|
97
104
|
end
|
98
105
|
|
99
|
-
|
106
|
+
DEFAULT_READ_QUERY = [:begin, :commit, :explain, :release, :rollback, :savepoint, :select, :with] # :nodoc:
|
107
|
+
private_constant :DEFAULT_READ_QUERY
|
108
|
+
|
109
|
+
def self.build_read_query_regexp(*parts) # :nodoc:
|
110
|
+
parts += DEFAULT_READ_QUERY
|
111
|
+
parts = parts.map { |part| /#{part}/i }
|
112
|
+
/\A(?:[\(\s]|#{COMMENT_REGEX})*#{Regexp.union(*parts)}/
|
113
|
+
end
|
114
|
+
|
115
|
+
def self.quoted_column_names # :nodoc:
|
116
|
+
@quoted_column_names ||= {}
|
117
|
+
end
|
100
118
|
|
101
|
-
def
|
119
|
+
def self.quoted_table_names # :nodoc:
|
120
|
+
@quoted_table_names ||= {}
|
121
|
+
end
|
122
|
+
|
123
|
+
def initialize(connection, logger = nil, config = {}) # :nodoc:
|
102
124
|
super()
|
103
125
|
|
104
126
|
@connection = connection
|
105
127
|
@owner = nil
|
106
128
|
@instrumenter = ActiveSupport::Notifications.instrumenter
|
107
129
|
@logger = logger
|
108
|
-
@
|
109
|
-
@
|
110
|
-
@
|
111
|
-
@
|
130
|
+
@config = config
|
131
|
+
@pool = ActiveRecord::ConnectionAdapters::NullPool.new
|
132
|
+
@idle_since = Concurrent.monotonic_time
|
133
|
+
@visitor = arel_visitor
|
134
|
+
@statements = build_statement_pool
|
135
|
+
@lock = ActiveSupport::Concurrency::LoadInterlockAwareMonitor.new
|
136
|
+
|
137
|
+
if self.class.type_cast_config_to_boolean(config.fetch(:prepared_statements) { true })
|
138
|
+
@prepared_statements = true
|
139
|
+
@visitor.extend(DetermineIfPreparableVisitor)
|
140
|
+
else
|
141
|
+
@prepared_statements = false
|
142
|
+
end
|
143
|
+
|
144
|
+
@advisory_locks_enabled = self.class.type_cast_config_to_boolean(
|
145
|
+
config.fetch(:advisory_locks, true)
|
146
|
+
)
|
112
147
|
end
|
113
148
|
|
114
|
-
|
115
|
-
|
116
|
-
super(bvs.map { |bv| conn.quote(*bv.reverse) })
|
117
|
-
end
|
149
|
+
def replica?
|
150
|
+
@config[:replica] || false
|
118
151
|
end
|
119
152
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
153
|
+
# Determines whether writes are currently being prevents.
|
154
|
+
#
|
155
|
+
# Returns true if the connection is a replica, or if +prevent_writes+
|
156
|
+
# is set to true.
|
157
|
+
def preventing_writes?
|
158
|
+
replica? || ActiveRecord::Base.connection_handler.prevent_writes
|
124
159
|
end
|
125
160
|
|
126
|
-
def
|
127
|
-
|
128
|
-
SQLString.new
|
129
|
-
else
|
130
|
-
BindCollector.new
|
131
|
-
end
|
161
|
+
def migrations_paths # :nodoc:
|
162
|
+
@config[:migrations_paths] || Migrator.migrations_paths
|
132
163
|
end
|
133
164
|
|
134
|
-
def
|
135
|
-
|
165
|
+
def migration_context # :nodoc:
|
166
|
+
MigrationContext.new(migrations_paths, schema_migration)
|
136
167
|
end
|
137
168
|
|
138
|
-
def
|
139
|
-
|
169
|
+
def schema_migration # :nodoc:
|
170
|
+
@schema_migration ||= begin
|
171
|
+
conn = self
|
172
|
+
spec_name = conn.pool.spec.name
|
173
|
+
name = "#{spec_name}::SchemaMigration"
|
174
|
+
|
175
|
+
return ActiveRecord::SchemaMigration if spec_name == "primary"
|
176
|
+
|
177
|
+
Class.new(ActiveRecord::SchemaMigration) do
|
178
|
+
define_singleton_method(:name) { name }
|
179
|
+
define_singleton_method(:to_s) { name }
|
180
|
+
|
181
|
+
self.connection_specification_name = spec_name
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def prepared_statements
|
187
|
+
@prepared_statements && !prepared_statements_disabled_cache.include?(object_id)
|
188
|
+
end
|
189
|
+
|
190
|
+
def prepared_statements_disabled_cache # :nodoc:
|
191
|
+
Thread.current[:ar_prepared_statements_disabled_cache] ||= Set.new
|
192
|
+
end
|
193
|
+
|
194
|
+
class Version
|
195
|
+
include Comparable
|
196
|
+
|
197
|
+
attr_reader :full_version_string
|
198
|
+
|
199
|
+
def initialize(version_string, full_version_string = nil)
|
200
|
+
@version = version_string.split(".").map(&:to_i)
|
201
|
+
@full_version_string = full_version_string
|
202
|
+
end
|
203
|
+
|
204
|
+
def <=>(version_string)
|
205
|
+
@version <=> version_string.split(".").map(&:to_i)
|
206
|
+
end
|
207
|
+
|
208
|
+
def to_s
|
209
|
+
@version.join(".")
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
def valid_type?(type) # :nodoc:
|
214
|
+
!native_database_types[type].nil?
|
140
215
|
end
|
141
216
|
|
217
|
+
# this method must only be called while holding connection pool's mutex
|
142
218
|
def lease
|
143
|
-
|
144
|
-
|
145
|
-
|
219
|
+
if in_use?
|
220
|
+
msg = +"Cannot lease connection, "
|
221
|
+
if @owner == Thread.current
|
222
|
+
msg << "it is already leased by the current thread."
|
223
|
+
else
|
224
|
+
msg << "it is already in use by a different thread: #{@owner}. " \
|
225
|
+
"Current thread: #{Thread.current}."
|
146
226
|
end
|
227
|
+
raise ActiveRecordError, msg
|
147
228
|
end
|
229
|
+
|
230
|
+
@owner = Thread.current
|
231
|
+
end
|
232
|
+
|
233
|
+
def schema_cache
|
234
|
+
@pool.get_schema_cache(self)
|
148
235
|
end
|
149
236
|
|
150
237
|
def schema_cache=(cache)
|
151
238
|
cache.connection = self
|
152
|
-
@
|
239
|
+
@pool.set_schema_cache(cache)
|
153
240
|
end
|
154
241
|
|
242
|
+
# this method must only be called while holding connection pool's mutex
|
155
243
|
def expire
|
156
|
-
|
244
|
+
if in_use?
|
245
|
+
if @owner != Thread.current
|
246
|
+
raise ActiveRecordError, "Cannot expire connection, " \
|
247
|
+
"it is owned by a different thread: #{@owner}. " \
|
248
|
+
"Current thread: #{Thread.current}."
|
249
|
+
end
|
250
|
+
|
251
|
+
@idle_since = Concurrent.monotonic_time
|
252
|
+
@owner = nil
|
253
|
+
else
|
254
|
+
raise ActiveRecordError, "Cannot expire connection, it is not currently leased."
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
# this method must only be called while holding connection pool's mutex (and a desire for segfaults)
|
259
|
+
def steal! # :nodoc:
|
260
|
+
if in_use?
|
261
|
+
if @owner != Thread.current
|
262
|
+
pool.send :remove_connection_from_thread_cache, self, @owner
|
263
|
+
|
264
|
+
@owner = Thread.current
|
265
|
+
end
|
266
|
+
else
|
267
|
+
raise ActiveRecordError, "Cannot steal connection, it is not currently leased."
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
# Seconds since this connection was returned to the pool
|
272
|
+
def seconds_idle # :nodoc:
|
273
|
+
return 0 if in_use?
|
274
|
+
Concurrent.monotonic_time - @idle_since
|
157
275
|
end
|
158
276
|
|
159
277
|
def unprepared_statement
|
160
|
-
|
278
|
+
cache = prepared_statements_disabled_cache.add(object_id) if @prepared_statements
|
161
279
|
yield
|
162
280
|
ensure
|
163
|
-
|
281
|
+
cache&.delete(object_id)
|
164
282
|
end
|
165
283
|
|
166
284
|
# Returns the human-readable name of the adapter. Use mixed case - one
|
@@ -169,15 +287,9 @@ module ActiveRecord
|
|
169
287
|
self.class::ADAPTER_NAME
|
170
288
|
end
|
171
289
|
|
172
|
-
# Does this adapter
|
173
|
-
def
|
174
|
-
|
175
|
-
end
|
176
|
-
|
177
|
-
# Can this adapter determine the primary key for tables not attached
|
178
|
-
# to an Active Record class, such as join tables?
|
179
|
-
def supports_primary_key?
|
180
|
-
false
|
290
|
+
# Does the database for this adapter exist?
|
291
|
+
def self.database_exists?(config)
|
292
|
+
raise NotImplementedError
|
181
293
|
end
|
182
294
|
|
183
295
|
# Does this adapter support DDL rollbacks in transactions? That is, would
|
@@ -195,6 +307,11 @@ module ActiveRecord
|
|
195
307
|
false
|
196
308
|
end
|
197
309
|
|
310
|
+
# Does this adapter support application-enforced advisory locking?
|
311
|
+
def supports_advisory_locks?
|
312
|
+
false
|
313
|
+
end
|
314
|
+
|
198
315
|
# Should primary key values be selected from their corresponding
|
199
316
|
# sequence before the insert statement? If true, next_sequence_value
|
200
317
|
# is called before each insert to set the record's primary key.
|
@@ -202,6 +319,10 @@ module ActiveRecord
|
|
202
319
|
false
|
203
320
|
end
|
204
321
|
|
322
|
+
def supports_partitioned_indexes?
|
323
|
+
false
|
324
|
+
end
|
325
|
+
|
205
326
|
# Does this adapter support index sort order?
|
206
327
|
def supports_index_sort_order?
|
207
328
|
false
|
@@ -212,6 +333,11 @@ module ActiveRecord
|
|
212
333
|
false
|
213
334
|
end
|
214
335
|
|
336
|
+
# Does this adapter support expression indices?
|
337
|
+
def supports_expression_index?
|
338
|
+
false
|
339
|
+
end
|
340
|
+
|
215
341
|
# Does this adapter support explain?
|
216
342
|
def supports_explain?
|
217
343
|
false
|
@@ -238,11 +364,93 @@ module ActiveRecord
|
|
238
364
|
false
|
239
365
|
end
|
240
366
|
|
367
|
+
# Does this adapter support creating invalid constraints?
|
368
|
+
def supports_validate_constraints?
|
369
|
+
false
|
370
|
+
end
|
371
|
+
|
372
|
+
# Does this adapter support creating foreign key constraints
|
373
|
+
# in the same statement as creating the table?
|
374
|
+
def supports_foreign_keys_in_create?
|
375
|
+
supports_foreign_keys?
|
376
|
+
end
|
377
|
+
deprecate :supports_foreign_keys_in_create?
|
378
|
+
|
241
379
|
# Does this adapter support views?
|
242
380
|
def supports_views?
|
243
381
|
false
|
244
382
|
end
|
245
383
|
|
384
|
+
# Does this adapter support materialized views?
|
385
|
+
def supports_materialized_views?
|
386
|
+
false
|
387
|
+
end
|
388
|
+
|
389
|
+
# Does this adapter support datetime with precision?
|
390
|
+
def supports_datetime_with_precision?
|
391
|
+
false
|
392
|
+
end
|
393
|
+
|
394
|
+
# Does this adapter support json data type?
|
395
|
+
def supports_json?
|
396
|
+
false
|
397
|
+
end
|
398
|
+
|
399
|
+
# Does this adapter support metadata comments on database objects (tables, columns, indexes)?
|
400
|
+
def supports_comments?
|
401
|
+
false
|
402
|
+
end
|
403
|
+
|
404
|
+
# Can comments for tables, columns, and indexes be specified in create/alter table statements?
|
405
|
+
def supports_comments_in_create?
|
406
|
+
false
|
407
|
+
end
|
408
|
+
|
409
|
+
# Does this adapter support multi-value insert?
|
410
|
+
def supports_multi_insert?
|
411
|
+
true
|
412
|
+
end
|
413
|
+
deprecate :supports_multi_insert?
|
414
|
+
|
415
|
+
# Does this adapter support virtual columns?
|
416
|
+
def supports_virtual_columns?
|
417
|
+
false
|
418
|
+
end
|
419
|
+
|
420
|
+
# Does this adapter support foreign/external tables?
|
421
|
+
def supports_foreign_tables?
|
422
|
+
false
|
423
|
+
end
|
424
|
+
|
425
|
+
# Does this adapter support optimizer hints?
|
426
|
+
def supports_optimizer_hints?
|
427
|
+
false
|
428
|
+
end
|
429
|
+
|
430
|
+
def supports_common_table_expressions?
|
431
|
+
false
|
432
|
+
end
|
433
|
+
|
434
|
+
def supports_lazy_transactions?
|
435
|
+
false
|
436
|
+
end
|
437
|
+
|
438
|
+
def supports_insert_returning?
|
439
|
+
false
|
440
|
+
end
|
441
|
+
|
442
|
+
def supports_insert_on_duplicate_skip?
|
443
|
+
false
|
444
|
+
end
|
445
|
+
|
446
|
+
def supports_insert_on_duplicate_update?
|
447
|
+
false
|
448
|
+
end
|
449
|
+
|
450
|
+
def supports_insert_conflict_target?
|
451
|
+
false
|
452
|
+
end
|
453
|
+
|
246
454
|
# This is meant to be implemented by the adapters that support extensions
|
247
455
|
def disable_extension(name)
|
248
456
|
end
|
@@ -251,6 +459,24 @@ module ActiveRecord
|
|
251
459
|
def enable_extension(name)
|
252
460
|
end
|
253
461
|
|
462
|
+
def advisory_locks_enabled? # :nodoc:
|
463
|
+
supports_advisory_locks? && @advisory_locks_enabled
|
464
|
+
end
|
465
|
+
|
466
|
+
# This is meant to be implemented by the adapters that support advisory
|
467
|
+
# locks
|
468
|
+
#
|
469
|
+
# Return true if we got the lock, otherwise false
|
470
|
+
def get_advisory_lock(lock_id) # :nodoc:
|
471
|
+
end
|
472
|
+
|
473
|
+
# This is meant to be implemented by the adapters that support advisory
|
474
|
+
# locks.
|
475
|
+
#
|
476
|
+
# Return true if we released the lock, otherwise false
|
477
|
+
def release_advisory_lock(lock_id) # :nodoc:
|
478
|
+
end
|
479
|
+
|
254
480
|
# A list of extensions, to be filled in by adapters that support them.
|
255
481
|
def extensions
|
256
482
|
[]
|
@@ -261,14 +487,6 @@ module ActiveRecord
|
|
261
487
|
{}
|
262
488
|
end
|
263
489
|
|
264
|
-
# QUOTING ==================================================
|
265
|
-
|
266
|
-
# Returns a bind substitution value given a bind +column+
|
267
|
-
# NOTE: The column param is currently being used by the sqlserver-adapter
|
268
|
-
def substitute_at(column, _unused = 0)
|
269
|
-
Arel::Nodes::BindParam.new
|
270
|
-
end
|
271
|
-
|
272
490
|
# REFERENTIAL INTEGRITY ====================================
|
273
491
|
|
274
492
|
# Override to turn off referential integrity while executing <tt>&block</tt>.
|
@@ -299,6 +517,22 @@ module ActiveRecord
|
|
299
517
|
reset_transaction
|
300
518
|
end
|
301
519
|
|
520
|
+
# Immediately forget this connection ever existed. Unlike disconnect!,
|
521
|
+
# this will not communicate with the server.
|
522
|
+
#
|
523
|
+
# After calling this method, the behavior of all other methods becomes
|
524
|
+
# undefined. This is called internally just before a forked process gets
|
525
|
+
# rid of a connection that belonged to its parent.
|
526
|
+
def discard!
|
527
|
+
# This should be overridden by concrete adapters.
|
528
|
+
#
|
529
|
+
# Prevent @connection's finalizer from touching the socket, or
|
530
|
+
# otherwise communicating with its server, when it is collected.
|
531
|
+
if schema_cache.connection == self
|
532
|
+
schema_cache.connection = nil
|
533
|
+
end
|
534
|
+
end
|
535
|
+
|
302
536
|
# Reset the state of this connection, directing the DBMS to clear
|
303
537
|
# transactions and other connection-related server-side state. Usually a
|
304
538
|
# database-dependent operation.
|
@@ -309,11 +543,9 @@ module ActiveRecord
|
|
309
543
|
# this should be overridden by concrete adapters
|
310
544
|
end
|
311
545
|
|
312
|
-
|
313
|
-
# Clear any caching the database adapter may be doing, for example
|
314
|
-
# clearing the prepared statement cache. This is database specific.
|
546
|
+
# Clear any caching the database adapter may be doing.
|
315
547
|
def clear_cache!
|
316
|
-
|
548
|
+
@lock.synchronize { @statements.clear } if @statements
|
317
549
|
end
|
318
550
|
|
319
551
|
# Returns true if its required to reload the connection between requests for development mode.
|
@@ -322,166 +554,229 @@ module ActiveRecord
|
|
322
554
|
end
|
323
555
|
|
324
556
|
# Checks whether the connection to the database is still active (i.e. not stale).
|
325
|
-
# This is done under the hood by calling
|
557
|
+
# This is done under the hood by calling #active?. If the connection
|
326
558
|
# is no longer active, then this method will reconnect to the database.
|
327
|
-
def verify!
|
559
|
+
def verify!
|
328
560
|
reconnect! unless active?
|
329
561
|
end
|
330
562
|
|
331
563
|
# Provides access to the underlying database driver for this adapter. For
|
332
|
-
# example, this method returns a
|
333
|
-
# and a
|
564
|
+
# example, this method returns a Mysql2::Client object in case of Mysql2Adapter,
|
565
|
+
# and a PG::Connection object in case of PostgreSQLAdapter.
|
334
566
|
#
|
335
567
|
# This is useful for when you need to call a proprietary method such as
|
336
568
|
# PostgreSQL's lo_* methods.
|
337
569
|
def raw_connection
|
570
|
+
disable_lazy_transactions!
|
338
571
|
@connection
|
339
572
|
end
|
340
573
|
|
341
|
-
def
|
574
|
+
def default_uniqueness_comparison(attribute, value, klass) # :nodoc:
|
575
|
+
attribute.eq(value)
|
342
576
|
end
|
343
577
|
|
344
|
-
def
|
578
|
+
def case_sensitive_comparison(attribute, value) # :nodoc:
|
579
|
+
attribute.eq(value)
|
345
580
|
end
|
346
581
|
|
347
|
-
def
|
348
|
-
|
582
|
+
def case_insensitive_comparison(attribute, value) # :nodoc:
|
583
|
+
column = column_for_attribute(attribute)
|
349
584
|
|
350
|
-
|
351
|
-
|
585
|
+
if can_perform_case_insensitive_comparison_for?(column)
|
586
|
+
attribute.lower.eq(attribute.relation.lower(value))
|
587
|
+
else
|
588
|
+
attribute.eq(value)
|
589
|
+
end
|
352
590
|
end
|
353
591
|
|
354
|
-
def
|
355
|
-
|
356
|
-
value = case_sensitive_modifier(value, table_attr) unless value.nil?
|
357
|
-
table_attr.eq(value)
|
592
|
+
def can_perform_case_insensitive_comparison_for?(column)
|
593
|
+
true
|
358
594
|
end
|
595
|
+
private :can_perform_case_insensitive_comparison_for?
|
359
596
|
|
360
|
-
|
361
|
-
|
597
|
+
# Check the connection back in to the connection pool
|
598
|
+
def close
|
599
|
+
pool.checkin self
|
362
600
|
end
|
363
601
|
|
364
|
-
def
|
365
|
-
|
602
|
+
def column_name_for_operation(operation, node) # :nodoc:
|
603
|
+
visitor.compile(node)
|
366
604
|
end
|
367
605
|
|
368
|
-
|
369
|
-
|
370
|
-
pool.checkin self
|
606
|
+
def default_index_type?(index) # :nodoc:
|
607
|
+
index.using.nil?
|
371
608
|
end
|
372
609
|
|
373
|
-
|
374
|
-
|
375
|
-
|
610
|
+
# Called by ActiveRecord::InsertAll,
|
611
|
+
# Passed an instance of ActiveRecord::InsertAll::Builder,
|
612
|
+
# This method implements standard bulk inserts for all databases, but
|
613
|
+
# should be overridden by adapters to implement common features with
|
614
|
+
# non-standard syntax like handling duplicates or returning values.
|
615
|
+
def build_insert_sql(insert) # :nodoc:
|
616
|
+
if insert.skip_duplicates? || insert.update_duplicates?
|
617
|
+
raise NotImplementedError, "#{self.class} should define `build_insert_sql` to implement adapter-specific logic for handling duplicates during INSERT"
|
376
618
|
end
|
619
|
+
|
620
|
+
"INSERT #{insert.into} #{insert.values_list}"
|
377
621
|
end
|
378
622
|
|
379
|
-
def
|
380
|
-
Column.new(name, default, cast_type, sql_type, null)
|
623
|
+
def get_database_version # :nodoc:
|
381
624
|
end
|
382
625
|
|
383
|
-
def
|
384
|
-
|
626
|
+
def database_version # :nodoc:
|
627
|
+
schema_cache.database_version
|
385
628
|
end
|
386
629
|
|
387
|
-
def
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
register_class_with_limit m, %r(boolean)i, Type::Boolean
|
395
|
-
register_class_with_limit m, %r(char)i, Type::String
|
396
|
-
register_class_with_limit m, %r(binary)i, Type::Binary
|
397
|
-
register_class_with_limit m, %r(text)i, Type::Text
|
398
|
-
register_class_with_limit m, %r(date)i, Type::Date
|
399
|
-
register_class_with_limit m, %r(time)i, Type::Time
|
400
|
-
register_class_with_limit m, %r(datetime)i, Type::DateTime
|
401
|
-
register_class_with_limit m, %r(float)i, Type::Float
|
402
|
-
register_class_with_limit m, %r(int)i, Type::Integer
|
403
|
-
|
404
|
-
m.alias_type %r(blob)i, 'binary'
|
405
|
-
m.alias_type %r(clob)i, 'text'
|
406
|
-
m.alias_type %r(timestamp)i, 'datetime'
|
407
|
-
m.alias_type %r(numeric)i, 'decimal'
|
408
|
-
m.alias_type %r(number)i, 'decimal'
|
409
|
-
m.alias_type %r(double)i, 'float'
|
410
|
-
|
411
|
-
m.register_type(%r(decimal)i) do |sql_type|
|
412
|
-
scale = extract_scale(sql_type)
|
413
|
-
precision = extract_precision(sql_type)
|
414
|
-
|
415
|
-
if scale == 0
|
416
|
-
# FIXME: Remove this class as well
|
417
|
-
Type::DecimalWithoutScale.new(precision: precision)
|
418
|
-
else
|
419
|
-
Type::Decimal.new(precision: precision, scale: scale)
|
630
|
+
def check_version # :nodoc:
|
631
|
+
end
|
632
|
+
|
633
|
+
private
|
634
|
+
def type_map
|
635
|
+
@type_map ||= Type::TypeMap.new.tap do |mapping|
|
636
|
+
initialize_type_map(mapping)
|
420
637
|
end
|
421
638
|
end
|
422
|
-
end
|
423
639
|
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
640
|
+
def initialize_type_map(m = type_map)
|
641
|
+
register_class_with_limit m, %r(boolean)i, Type::Boolean
|
642
|
+
register_class_with_limit m, %r(char)i, Type::String
|
643
|
+
register_class_with_limit m, %r(binary)i, Type::Binary
|
644
|
+
register_class_with_limit m, %r(text)i, Type::Text
|
645
|
+
register_class_with_precision m, %r(date)i, Type::Date
|
646
|
+
register_class_with_precision m, %r(time)i, Type::Time
|
647
|
+
register_class_with_precision m, %r(datetime)i, Type::DateTime
|
648
|
+
register_class_with_limit m, %r(float)i, Type::Float
|
649
|
+
register_class_with_limit m, %r(int)i, Type::Integer
|
650
|
+
|
651
|
+
m.alias_type %r(blob)i, "binary"
|
652
|
+
m.alias_type %r(clob)i, "text"
|
653
|
+
m.alias_type %r(timestamp)i, "datetime"
|
654
|
+
m.alias_type %r(numeric)i, "decimal"
|
655
|
+
m.alias_type %r(number)i, "decimal"
|
656
|
+
m.alias_type %r(double)i, "float"
|
657
|
+
|
658
|
+
m.register_type %r(^json)i, Type::Json.new
|
659
|
+
|
660
|
+
m.register_type(%r(decimal)i) do |sql_type|
|
661
|
+
scale = extract_scale(sql_type)
|
662
|
+
precision = extract_precision(sql_type)
|
663
|
+
|
664
|
+
if scale == 0
|
665
|
+
# FIXME: Remove this class as well
|
666
|
+
Type::DecimalWithoutScale.new(precision: precision)
|
667
|
+
else
|
668
|
+
Type::Decimal.new(precision: precision, scale: scale)
|
669
|
+
end
|
670
|
+
end
|
671
|
+
end
|
428
672
|
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
klass.new(limit: limit)
|
673
|
+
def reload_type_map
|
674
|
+
type_map.clear
|
675
|
+
initialize_type_map
|
433
676
|
end
|
434
|
-
end
|
435
677
|
|
436
|
-
|
437
|
-
|
678
|
+
def register_class_with_limit(mapping, key, klass)
|
679
|
+
mapping.register_type(key) do |*args|
|
680
|
+
limit = extract_limit(args.last)
|
681
|
+
klass.new(limit: limit)
|
682
|
+
end
|
683
|
+
end
|
684
|
+
|
685
|
+
def register_class_with_precision(mapping, key, klass)
|
686
|
+
mapping.register_type(key) do |*args|
|
687
|
+
precision = extract_precision(args.last)
|
688
|
+
klass.new(precision: precision)
|
689
|
+
end
|
690
|
+
end
|
691
|
+
|
692
|
+
def extract_scale(sql_type)
|
693
|
+
case sql_type
|
438
694
|
when /\((\d+)\)/ then 0
|
439
695
|
when /\((\d+)(,(\d+))\)/ then $3.to_i
|
696
|
+
end
|
440
697
|
end
|
441
|
-
end
|
442
698
|
|
443
|
-
|
444
|
-
|
445
|
-
|
699
|
+
def extract_precision(sql_type)
|
700
|
+
$1.to_i if sql_type =~ /\((\d+)(,\d+)?\)/
|
701
|
+
end
|
446
702
|
|
447
|
-
|
448
|
-
|
449
|
-
|
703
|
+
def extract_limit(sql_type)
|
704
|
+
$1.to_i if sql_type =~ /\((.*)\)/
|
705
|
+
end
|
450
706
|
|
451
|
-
|
452
|
-
|
453
|
-
@logger.error message if @logger
|
454
|
-
exception = translate_exception(e, message)
|
455
|
-
exception.set_backtrace e.backtrace
|
456
|
-
exception
|
457
|
-
end
|
707
|
+
def translate_exception_class(e, sql, binds)
|
708
|
+
message = "#{e.class.name}: #{e.message}"
|
458
709
|
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
:statement_name => statement_name,
|
466
|
-
:binds => binds) { yield }
|
467
|
-
rescue => e
|
468
|
-
raise translate_exception_class(e, sql)
|
469
|
-
end
|
710
|
+
exception = translate_exception(
|
711
|
+
e, message: message, sql: sql, binds: binds
|
712
|
+
)
|
713
|
+
exception.set_backtrace e.backtrace
|
714
|
+
exception
|
715
|
+
end
|
470
716
|
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
717
|
+
def log(sql, name = "SQL", binds = [], type_casted_binds = [], statement_name = nil) # :doc:
|
718
|
+
@instrumenter.instrument(
|
719
|
+
"sql.active_record",
|
720
|
+
sql: sql,
|
721
|
+
name: name,
|
722
|
+
binds: binds,
|
723
|
+
type_casted_binds: type_casted_binds,
|
724
|
+
statement_name: statement_name,
|
725
|
+
connection_id: object_id,
|
726
|
+
connection: self) do
|
727
|
+
@lock.synchronize do
|
728
|
+
yield
|
729
|
+
end
|
730
|
+
rescue => e
|
731
|
+
raise translate_exception_class(e, sql, binds)
|
732
|
+
end
|
733
|
+
end
|
475
734
|
|
476
|
-
|
477
|
-
|
478
|
-
|
735
|
+
def translate_exception(exception, message:, sql:, binds:)
|
736
|
+
# override in derived class
|
737
|
+
case exception
|
738
|
+
when RuntimeError
|
739
|
+
exception
|
740
|
+
else
|
741
|
+
ActiveRecord::StatementInvalid.new(message, sql: sql, binds: binds)
|
742
|
+
end
|
743
|
+
end
|
479
744
|
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
745
|
+
def without_prepared_statement?(binds)
|
746
|
+
!prepared_statements || binds.empty?
|
747
|
+
end
|
748
|
+
|
749
|
+
def column_for(table_name, column_name)
|
750
|
+
column_name = column_name.to_s
|
751
|
+
columns(table_name).detect { |c| c.name == column_name } ||
|
752
|
+
raise(ActiveRecordError, "No such column: #{table_name}.#{column_name}")
|
753
|
+
end
|
754
|
+
|
755
|
+
def column_for_attribute(attribute)
|
756
|
+
table_name = attribute.relation.name
|
757
|
+
schema_cache.columns_hash(table_name)[attribute.name.to_s]
|
758
|
+
end
|
759
|
+
|
760
|
+
def collector
|
761
|
+
if prepared_statements
|
762
|
+
Arel::Collectors::Composite.new(
|
763
|
+
Arel::Collectors::SQLString.new,
|
764
|
+
Arel::Collectors::Bind.new,
|
765
|
+
)
|
766
|
+
else
|
767
|
+
Arel::Collectors::SubstituteBinds.new(
|
768
|
+
self,
|
769
|
+
Arel::Collectors::SQLString.new,
|
770
|
+
)
|
771
|
+
end
|
772
|
+
end
|
773
|
+
|
774
|
+
def arel_visitor
|
775
|
+
Arel::Visitors::ToSql.new(self)
|
776
|
+
end
|
777
|
+
|
778
|
+
def build_statement_pool
|
779
|
+
end
|
485
780
|
end
|
486
781
|
end
|
487
782
|
end
|