sequel 5.20.0 → 5.49.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +398 -1922
- data/MIT-LICENSE +1 -1
- data/README.rdoc +7 -7
- data/doc/advanced_associations.rdoc +4 -4
- data/doc/association_basics.rdoc +80 -16
- data/doc/cheat_sheet.rdoc +6 -5
- data/doc/code_order.rdoc +10 -12
- data/doc/dataset_filtering.rdoc +17 -2
- data/doc/fork_safety.rdoc +84 -0
- data/doc/migration.rdoc +11 -5
- data/doc/model_dataset_method_design.rdoc +1 -1
- data/doc/model_plugins.rdoc +1 -1
- data/doc/opening_databases.rdoc +10 -2
- data/doc/postgresql.rdoc +82 -3
- data/doc/querying.rdoc +4 -4
- data/doc/release_notes/5.21.0.txt +87 -0
- data/doc/release_notes/5.22.0.txt +48 -0
- data/doc/release_notes/5.23.0.txt +56 -0
- data/doc/release_notes/5.24.0.txt +56 -0
- data/doc/release_notes/5.25.0.txt +32 -0
- data/doc/release_notes/5.26.0.txt +35 -0
- data/doc/release_notes/5.27.0.txt +21 -0
- data/doc/release_notes/5.28.0.txt +16 -0
- data/doc/release_notes/5.29.0.txt +22 -0
- data/doc/release_notes/5.30.0.txt +20 -0
- data/doc/release_notes/5.31.0.txt +148 -0
- data/doc/release_notes/5.32.0.txt +46 -0
- data/doc/release_notes/5.33.0.txt +24 -0
- data/doc/release_notes/5.34.0.txt +40 -0
- data/doc/release_notes/5.35.0.txt +56 -0
- data/doc/release_notes/5.36.0.txt +60 -0
- data/doc/release_notes/5.37.0.txt +30 -0
- data/doc/release_notes/5.38.0.txt +28 -0
- data/doc/release_notes/5.39.0.txt +19 -0
- data/doc/release_notes/5.40.0.txt +40 -0
- data/doc/release_notes/5.41.0.txt +25 -0
- data/doc/release_notes/5.42.0.txt +136 -0
- data/doc/release_notes/5.43.0.txt +98 -0
- data/doc/release_notes/5.44.0.txt +32 -0
- data/doc/release_notes/5.45.0.txt +34 -0
- data/doc/release_notes/5.46.0.txt +87 -0
- data/doc/release_notes/5.47.0.txt +59 -0
- data/doc/release_notes/5.48.0.txt +14 -0
- data/doc/release_notes/5.49.0.txt +59 -0
- data/doc/sharding.rdoc +2 -0
- data/doc/sql.rdoc +13 -1
- data/doc/testing.rdoc +20 -7
- data/doc/transactions.rdoc +0 -8
- data/doc/validations.rdoc +1 -1
- data/doc/virtual_rows.rdoc +1 -1
- data/lib/sequel/adapters/ado/access.rb +1 -1
- data/lib/sequel/adapters/ado.rb +43 -35
- data/lib/sequel/adapters/ibmdb.rb +2 -2
- data/lib/sequel/adapters/jdbc/mysql.rb +6 -6
- data/lib/sequel/adapters/jdbc/postgresql.rb +11 -17
- data/lib/sequel/adapters/jdbc/sqlite.rb +29 -0
- data/lib/sequel/adapters/jdbc.rb +24 -6
- data/lib/sequel/adapters/mysql.rb +1 -1
- data/lib/sequel/adapters/mysql2.rb +2 -3
- data/lib/sequel/adapters/odbc.rb +8 -6
- data/lib/sequel/adapters/oracle.rb +5 -4
- data/lib/sequel/adapters/postgres.rb +15 -9
- data/lib/sequel/adapters/shared/access.rb +6 -6
- data/lib/sequel/adapters/shared/mssql.rb +66 -21
- data/lib/sequel/adapters/shared/mysql.rb +27 -10
- data/lib/sequel/adapters/shared/oracle.rb +29 -23
- data/lib/sequel/adapters/shared/postgres.rb +271 -32
- data/lib/sequel/adapters/shared/sqlanywhere.rb +9 -9
- data/lib/sequel/adapters/shared/sqlite.rb +161 -19
- data/lib/sequel/adapters/sqlanywhere.rb +1 -1
- data/lib/sequel/adapters/sqlite.rb +1 -1
- data/lib/sequel/adapters/tinytds.rb +15 -2
- data/lib/sequel/adapters/utils/mysql_mysql2.rb +4 -1
- data/lib/sequel/ast_transformer.rb +6 -0
- data/lib/sequel/connection_pool/sharded_single.rb +4 -1
- data/lib/sequel/connection_pool/sharded_threaded.rb +12 -12
- data/lib/sequel/connection_pool/single.rb +1 -1
- data/lib/sequel/connection_pool/threaded.rb +2 -2
- data/lib/sequel/core.rb +333 -319
- data/lib/sequel/database/connecting.rb +3 -4
- data/lib/sequel/database/logging.rb +7 -1
- data/lib/sequel/database/misc.rb +31 -12
- data/lib/sequel/database/query.rb +3 -1
- data/lib/sequel/database/schema_generator.rb +53 -51
- data/lib/sequel/database/schema_methods.rb +38 -23
- data/lib/sequel/database/transactions.rb +17 -18
- data/lib/sequel/dataset/actions.rb +14 -9
- data/lib/sequel/dataset/features.rb +16 -0
- data/lib/sequel/dataset/misc.rb +2 -2
- data/lib/sequel/dataset/placeholder_literalizer.rb +3 -7
- data/lib/sequel/dataset/prepared_statements.rb +2 -0
- data/lib/sequel/dataset/query.rb +26 -9
- data/lib/sequel/dataset/sql.rb +76 -25
- data/lib/sequel/dataset.rb +4 -2
- data/lib/sequel/deprecated.rb +3 -1
- data/lib/sequel/exceptions.rb +2 -0
- data/lib/sequel/extensions/_pretty_table.rb +1 -2
- data/lib/sequel/extensions/any_not_empty.rb +45 -0
- data/lib/sequel/extensions/async_thread_pool.rb +438 -0
- data/lib/sequel/extensions/blank.rb +8 -0
- data/lib/sequel/extensions/columns_introspection.rb +1 -2
- data/lib/sequel/extensions/connection_expiration.rb +2 -2
- data/lib/sequel/extensions/connection_validator.rb +2 -2
- data/lib/sequel/extensions/core_refinements.rb +2 -0
- data/lib/sequel/extensions/date_arithmetic.rb +36 -24
- data/lib/sequel/extensions/duplicate_columns_handler.rb +3 -1
- data/lib/sequel/extensions/eval_inspect.rb +2 -0
- data/lib/sequel/extensions/exclude_or_null.rb +68 -0
- data/lib/sequel/extensions/fiber_concurrency.rb +24 -0
- data/lib/sequel/extensions/index_caching.rb +9 -7
- data/lib/sequel/extensions/inflector.rb +9 -1
- data/lib/sequel/extensions/integer64.rb +2 -0
- data/lib/sequel/extensions/migration.rb +11 -3
- data/lib/sequel/extensions/named_timezones.rb +56 -8
- data/lib/sequel/extensions/pagination.rb +1 -1
- data/lib/sequel/extensions/pg_array.rb +5 -0
- data/lib/sequel/extensions/pg_array_ops.rb +14 -6
- data/lib/sequel/extensions/pg_enum.rb +11 -3
- data/lib/sequel/extensions/pg_extended_date_support.rb +2 -2
- data/lib/sequel/extensions/pg_hstore.rb +6 -0
- data/lib/sequel/extensions/pg_hstore_ops.rb +54 -2
- data/lib/sequel/extensions/pg_inet.rb +15 -5
- data/lib/sequel/extensions/pg_interval.rb +36 -8
- data/lib/sequel/extensions/pg_json.rb +387 -123
- data/lib/sequel/extensions/pg_json_ops.rb +238 -0
- data/lib/sequel/extensions/pg_loose_count.rb +3 -1
- data/lib/sequel/extensions/pg_range.rb +17 -9
- data/lib/sequel/extensions/pg_range_ops.rb +2 -0
- data/lib/sequel/extensions/pg_row.rb +4 -2
- data/lib/sequel/extensions/pg_row_ops.rb +24 -0
- data/lib/sequel/extensions/pg_timestamptz.rb +2 -0
- data/lib/sequel/extensions/query.rb +3 -0
- data/lib/sequel/extensions/run_transaction_hooks.rb +72 -0
- data/lib/sequel/extensions/s.rb +2 -0
- data/lib/sequel/extensions/schema_dumper.rb +24 -7
- data/lib/sequel/extensions/server_block.rb +18 -7
- data/lib/sequel/extensions/sql_comments.rb +2 -2
- data/lib/sequel/extensions/string_agg.rb +1 -1
- data/lib/sequel/extensions/symbol_aref_refinement.rb +2 -0
- data/lib/sequel/extensions/symbol_as_refinement.rb +2 -0
- data/lib/sequel/extensions/to_dot.rb +9 -3
- data/lib/sequel/model/associations.rb +356 -117
- data/lib/sequel/model/base.rb +107 -68
- data/lib/sequel/model/errors.rb +10 -1
- data/lib/sequel/model/inflections.rb +1 -1
- data/lib/sequel/model/plugins.rb +9 -3
- data/lib/sequel/model.rb +3 -1
- data/lib/sequel/plugins/association_lazy_eager_option.rb +66 -0
- data/lib/sequel/plugins/association_multi_add_remove.rb +85 -0
- data/lib/sequel/plugins/association_pks.rb +60 -18
- data/lib/sequel/plugins/association_proxies.rb +8 -2
- data/lib/sequel/plugins/async_thread_pool.rb +39 -0
- data/lib/sequel/plugins/auto_validations.rb +39 -5
- data/lib/sequel/plugins/auto_validations_constraint_validations_presence_message.rb +68 -0
- data/lib/sequel/plugins/blacklist_security.rb +1 -2
- data/lib/sequel/plugins/boolean_subsets.rb +4 -1
- data/lib/sequel/plugins/caching.rb +3 -0
- data/lib/sequel/plugins/class_table_inheritance.rb +33 -28
- data/lib/sequel/plugins/column_encryption.rb +728 -0
- data/lib/sequel/plugins/composition.rb +7 -2
- data/lib/sequel/plugins/concurrent_eager_loading.rb +174 -0
- data/lib/sequel/plugins/constraint_validations.rb +2 -1
- data/lib/sequel/plugins/csv_serializer.rb +28 -9
- data/lib/sequel/plugins/dataset_associations.rb +4 -1
- data/lib/sequel/plugins/dirty.rb +60 -22
- data/lib/sequel/plugins/empty_failure_backtraces.rb +38 -0
- data/lib/sequel/plugins/forbid_lazy_load.rb +216 -0
- data/lib/sequel/plugins/insert_conflict.rb +72 -0
- data/lib/sequel/plugins/instance_specific_default.rb +113 -0
- data/lib/sequel/plugins/json_serializer.rb +57 -35
- data/lib/sequel/plugins/lazy_attributes.rb +1 -1
- data/lib/sequel/plugins/many_through_many.rb +108 -9
- data/lib/sequel/plugins/nested_attributes.rb +15 -3
- data/lib/sequel/plugins/pg_array_associations.rb +58 -41
- data/lib/sequel/plugins/pg_auto_constraint_validations.rb +91 -30
- data/lib/sequel/plugins/prepared_statements.rb +15 -12
- data/lib/sequel/plugins/prepared_statements_safe.rb +1 -3
- data/lib/sequel/plugins/rcte_tree.rb +43 -35
- data/lib/sequel/plugins/serialization.rb +8 -3
- data/lib/sequel/plugins/serialization_modification_detection.rb +1 -1
- data/lib/sequel/plugins/sharding.rb +11 -5
- data/lib/sequel/plugins/single_table_inheritance.rb +22 -15
- data/lib/sequel/plugins/skip_saving_columns.rb +108 -0
- data/lib/sequel/plugins/static_cache.rb +9 -4
- data/lib/sequel/plugins/static_cache_cache.rb +53 -0
- data/lib/sequel/plugins/string_stripper.rb +1 -1
- data/lib/sequel/plugins/subclasses.rb +2 -0
- data/lib/sequel/plugins/throw_failures.rb +1 -1
- data/lib/sequel/plugins/timestamps.rb +1 -1
- data/lib/sequel/plugins/tree.rb +9 -4
- data/lib/sequel/plugins/typecast_on_load.rb +3 -2
- data/lib/sequel/plugins/unused_associations.rb +521 -0
- data/lib/sequel/plugins/update_or_create.rb +1 -1
- data/lib/sequel/plugins/validation_class_methods.rb +5 -1
- data/lib/sequel/plugins/validation_helpers.rb +18 -11
- data/lib/sequel/plugins/xml_serializer.rb +1 -1
- data/lib/sequel/sql.rb +20 -5
- data/lib/sequel/timezones.rb +63 -17
- data/lib/sequel/version.rb +1 -1
- metadata +113 -381
- data/Rakefile +0 -151
- data/doc/release_notes/4.0.0.txt +0 -262
- data/doc/release_notes/4.1.0.txt +0 -85
- data/doc/release_notes/4.10.0.txt +0 -226
- data/doc/release_notes/4.11.0.txt +0 -147
- data/doc/release_notes/4.12.0.txt +0 -105
- data/doc/release_notes/4.13.0.txt +0 -169
- data/doc/release_notes/4.14.0.txt +0 -68
- data/doc/release_notes/4.15.0.txt +0 -56
- data/doc/release_notes/4.16.0.txt +0 -36
- data/doc/release_notes/4.17.0.txt +0 -38
- data/doc/release_notes/4.18.0.txt +0 -36
- data/doc/release_notes/4.19.0.txt +0 -45
- data/doc/release_notes/4.2.0.txt +0 -129
- data/doc/release_notes/4.20.0.txt +0 -79
- data/doc/release_notes/4.21.0.txt +0 -94
- data/doc/release_notes/4.22.0.txt +0 -72
- data/doc/release_notes/4.23.0.txt +0 -65
- data/doc/release_notes/4.24.0.txt +0 -99
- data/doc/release_notes/4.25.0.txt +0 -181
- data/doc/release_notes/4.26.0.txt +0 -44
- data/doc/release_notes/4.27.0.txt +0 -78
- data/doc/release_notes/4.28.0.txt +0 -57
- data/doc/release_notes/4.29.0.txt +0 -41
- data/doc/release_notes/4.3.0.txt +0 -40
- data/doc/release_notes/4.30.0.txt +0 -37
- data/doc/release_notes/4.31.0.txt +0 -57
- data/doc/release_notes/4.32.0.txt +0 -132
- data/doc/release_notes/4.33.0.txt +0 -88
- data/doc/release_notes/4.34.0.txt +0 -86
- data/doc/release_notes/4.35.0.txt +0 -130
- data/doc/release_notes/4.36.0.txt +0 -116
- data/doc/release_notes/4.37.0.txt +0 -50
- data/doc/release_notes/4.38.0.txt +0 -67
- data/doc/release_notes/4.39.0.txt +0 -127
- data/doc/release_notes/4.4.0.txt +0 -92
- data/doc/release_notes/4.40.0.txt +0 -179
- data/doc/release_notes/4.41.0.txt +0 -77
- data/doc/release_notes/4.42.0.txt +0 -221
- data/doc/release_notes/4.43.0.txt +0 -87
- data/doc/release_notes/4.44.0.txt +0 -125
- data/doc/release_notes/4.45.0.txt +0 -370
- data/doc/release_notes/4.46.0.txt +0 -404
- data/doc/release_notes/4.47.0.txt +0 -56
- data/doc/release_notes/4.48.0.txt +0 -293
- data/doc/release_notes/4.49.0.txt +0 -222
- data/doc/release_notes/4.5.0.txt +0 -34
- data/doc/release_notes/4.6.0.txt +0 -30
- data/doc/release_notes/4.7.0.txt +0 -103
- data/doc/release_notes/4.8.0.txt +0 -175
- data/doc/release_notes/4.9.0.txt +0 -190
- data/spec/adapter_spec.rb +0 -4
- data/spec/adapters/db2_spec.rb +0 -170
- data/spec/adapters/mssql_spec.rb +0 -804
- data/spec/adapters/mysql_spec.rb +0 -1065
- data/spec/adapters/oracle_spec.rb +0 -371
- data/spec/adapters/postgres_spec.rb +0 -4125
- data/spec/adapters/spec_helper.rb +0 -44
- data/spec/adapters/sqlanywhere_spec.rb +0 -97
- data/spec/adapters/sqlite_spec.rb +0 -652
- data/spec/bin_spec.rb +0 -278
- data/spec/core/connection_pool_spec.rb +0 -1250
- data/spec/core/database_spec.rb +0 -2865
- data/spec/core/dataset_spec.rb +0 -5515
- data/spec/core/deprecated_spec.rb +0 -70
- data/spec/core/expression_filters_spec.rb +0 -1455
- data/spec/core/mock_adapter_spec.rb +0 -722
- data/spec/core/object_graph_spec.rb +0 -336
- data/spec/core/placeholder_literalizer_spec.rb +0 -166
- data/spec/core/schema_generator_spec.rb +0 -214
- data/spec/core/schema_spec.rb +0 -1826
- data/spec/core/spec_helper.rb +0 -24
- data/spec/core/version_spec.rb +0 -14
- data/spec/core_extensions_spec.rb +0 -763
- data/spec/core_model_spec.rb +0 -2
- data/spec/core_spec.rb +0 -1
- data/spec/deprecation_helper.rb +0 -30
- data/spec/extensions/accessed_columns_spec.rb +0 -51
- data/spec/extensions/active_model_spec.rb +0 -99
- data/spec/extensions/after_initialize_spec.rb +0 -28
- data/spec/extensions/arbitrary_servers_spec.rb +0 -109
- data/spec/extensions/association_dependencies_spec.rb +0 -125
- data/spec/extensions/association_pks_spec.rb +0 -423
- data/spec/extensions/association_proxies_spec.rb +0 -100
- data/spec/extensions/auto_literal_strings_spec.rb +0 -205
- data/spec/extensions/auto_validations_spec.rb +0 -229
- data/spec/extensions/blacklist_security_spec.rb +0 -95
- data/spec/extensions/blank_spec.rb +0 -69
- data/spec/extensions/boolean_readers_spec.rb +0 -93
- data/spec/extensions/boolean_subsets_spec.rb +0 -47
- data/spec/extensions/caching_spec.rb +0 -273
- data/spec/extensions/caller_logging_spec.rb +0 -52
- data/spec/extensions/class_table_inheritance_spec.rb +0 -750
- data/spec/extensions/column_conflicts_spec.rb +0 -75
- data/spec/extensions/column_select_spec.rb +0 -129
- data/spec/extensions/columns_introspection_spec.rb +0 -90
- data/spec/extensions/columns_updated_spec.rb +0 -35
- data/spec/extensions/composition_spec.rb +0 -248
- data/spec/extensions/connection_expiration_spec.rb +0 -151
- data/spec/extensions/connection_validator_spec.rb +0 -144
- data/spec/extensions/constant_sql_override_spec.rb +0 -24
- data/spec/extensions/constraint_validations_plugin_spec.rb +0 -300
- data/spec/extensions/constraint_validations_spec.rb +0 -439
- data/spec/extensions/core_refinements_spec.rb +0 -528
- data/spec/extensions/csv_serializer_spec.rb +0 -183
- data/spec/extensions/current_datetime_timestamp_spec.rb +0 -27
- data/spec/extensions/dataset_associations_spec.rb +0 -365
- data/spec/extensions/dataset_source_alias_spec.rb +0 -51
- data/spec/extensions/date_arithmetic_spec.rb +0 -181
- data/spec/extensions/datetime_parse_to_time_spec.rb +0 -169
- data/spec/extensions/def_dataset_method_spec.rb +0 -100
- data/spec/extensions/defaults_setter_spec.rb +0 -150
- data/spec/extensions/delay_add_association_spec.rb +0 -73
- data/spec/extensions/dirty_spec.rb +0 -189
- data/spec/extensions/duplicate_columns_handler_spec.rb +0 -104
- data/spec/extensions/eager_each_spec.rb +0 -62
- data/spec/extensions/eager_graph_eager_spec.rb +0 -100
- data/spec/extensions/empty_array_consider_nulls_spec.rb +0 -24
- data/spec/extensions/error_splitter_spec.rb +0 -18
- data/spec/extensions/error_sql_spec.rb +0 -20
- data/spec/extensions/escaped_like_spec.rb +0 -40
- data/spec/extensions/eval_inspect_spec.rb +0 -81
- data/spec/extensions/finder_spec.rb +0 -260
- data/spec/extensions/force_encoding_spec.rb +0 -126
- data/spec/extensions/freeze_datasets_spec.rb +0 -31
- data/spec/extensions/graph_each_spec.rb +0 -113
- data/spec/extensions/hook_class_methods_spec.rb +0 -402
- data/spec/extensions/identifier_mangling_spec.rb +0 -201
- data/spec/extensions/implicit_subquery_spec.rb +0 -58
- data/spec/extensions/index_caching_spec.rb +0 -66
- data/spec/extensions/inflector_spec.rb +0 -183
- data/spec/extensions/input_transformer_spec.rb +0 -69
- data/spec/extensions/insert_returning_select_spec.rb +0 -72
- data/spec/extensions/instance_filters_spec.rb +0 -79
- data/spec/extensions/instance_hooks_spec.rb +0 -246
- data/spec/extensions/integer64_spec.rb +0 -22
- data/spec/extensions/inverted_subsets_spec.rb +0 -33
- data/spec/extensions/json_serializer_spec.rb +0 -336
- data/spec/extensions/lazy_attributes_spec.rb +0 -183
- data/spec/extensions/list_spec.rb +0 -291
- data/spec/extensions/looser_typecasting_spec.rb +0 -43
- data/spec/extensions/many_through_many_spec.rb +0 -2177
- data/spec/extensions/migration_spec.rb +0 -864
- data/spec/extensions/modification_detection_spec.rb +0 -93
- data/spec/extensions/mssql_optimistic_locking_spec.rb +0 -92
- data/spec/extensions/named_timezones_spec.rb +0 -111
- data/spec/extensions/nested_attributes_spec.rb +0 -767
- data/spec/extensions/null_dataset_spec.rb +0 -85
- data/spec/extensions/optimistic_locking_spec.rb +0 -127
- data/spec/extensions/pagination_spec.rb +0 -116
- data/spec/extensions/pg_array_associations_spec.rb +0 -802
- data/spec/extensions/pg_array_ops_spec.rb +0 -144
- data/spec/extensions/pg_array_spec.rb +0 -398
- data/spec/extensions/pg_auto_constraint_validations_spec.rb +0 -172
- data/spec/extensions/pg_enum_spec.rb +0 -118
- data/spec/extensions/pg_extended_date_support_spec.rb +0 -126
- data/spec/extensions/pg_hstore_ops_spec.rb +0 -238
- data/spec/extensions/pg_hstore_spec.rb +0 -219
- data/spec/extensions/pg_inet_ops_spec.rb +0 -102
- data/spec/extensions/pg_inet_spec.rb +0 -72
- data/spec/extensions/pg_interval_spec.rb +0 -103
- data/spec/extensions/pg_json_ops_spec.rb +0 -289
- data/spec/extensions/pg_json_spec.rb +0 -262
- data/spec/extensions/pg_loose_count_spec.rb +0 -23
- data/spec/extensions/pg_range_ops_spec.rb +0 -60
- data/spec/extensions/pg_range_spec.rb +0 -519
- data/spec/extensions/pg_row_ops_spec.rb +0 -61
- data/spec/extensions/pg_row_plugin_spec.rb +0 -60
- data/spec/extensions/pg_row_spec.rb +0 -363
- data/spec/extensions/pg_static_cache_updater_spec.rb +0 -93
- data/spec/extensions/pg_timestamptz_spec.rb +0 -17
- data/spec/extensions/prepared_statements_safe_spec.rb +0 -66
- data/spec/extensions/prepared_statements_spec.rb +0 -177
- data/spec/extensions/pretty_table_spec.rb +0 -123
- data/spec/extensions/query_spec.rb +0 -94
- data/spec/extensions/rcte_tree_spec.rb +0 -381
- data/spec/extensions/round_timestamps_spec.rb +0 -39
- data/spec/extensions/s_spec.rb +0 -60
- data/spec/extensions/schema_caching_spec.rb +0 -64
- data/spec/extensions/schema_dumper_spec.rb +0 -870
- data/spec/extensions/select_remove_spec.rb +0 -38
- data/spec/extensions/sequel_4_dataset_methods_spec.rb +0 -121
- data/spec/extensions/serialization_modification_detection_spec.rb +0 -98
- data/spec/extensions/serialization_spec.rb +0 -365
- data/spec/extensions/server_block_spec.rb +0 -97
- data/spec/extensions/server_logging_spec.rb +0 -45
- data/spec/extensions/sharding_spec.rb +0 -189
- data/spec/extensions/shared_caching_spec.rb +0 -151
- data/spec/extensions/single_table_inheritance_spec.rb +0 -347
- data/spec/extensions/singular_table_names_spec.rb +0 -22
- data/spec/extensions/skip_create_refresh_spec.rb +0 -18
- data/spec/extensions/spec_helper.rb +0 -63
- data/spec/extensions/split_array_nil_spec.rb +0 -24
- data/spec/extensions/split_values_spec.rb +0 -57
- data/spec/extensions/sql_comments_spec.rb +0 -33
- data/spec/extensions/sql_expr_spec.rb +0 -59
- data/spec/extensions/static_cache_spec.rb +0 -471
- data/spec/extensions/string_agg_spec.rb +0 -90
- data/spec/extensions/string_date_time_spec.rb +0 -95
- data/spec/extensions/string_stripper_spec.rb +0 -68
- data/spec/extensions/subclasses_spec.rb +0 -79
- data/spec/extensions/subset_conditions_spec.rb +0 -38
- data/spec/extensions/symbol_aref_refinement_spec.rb +0 -28
- data/spec/extensions/symbol_as_refinement_spec.rb +0 -21
- data/spec/extensions/synchronize_sql_spec.rb +0 -124
- data/spec/extensions/table_select_spec.rb +0 -83
- data/spec/extensions/tactical_eager_loading_spec.rb +0 -402
- data/spec/extensions/thread_local_timezones_spec.rb +0 -67
- data/spec/extensions/throw_failures_spec.rb +0 -74
- data/spec/extensions/timestamps_spec.rb +0 -209
- data/spec/extensions/to_dot_spec.rb +0 -153
- data/spec/extensions/touch_spec.rb +0 -226
- data/spec/extensions/tree_spec.rb +0 -334
- data/spec/extensions/typecast_on_load_spec.rb +0 -86
- data/spec/extensions/unlimited_update_spec.rb +0 -21
- data/spec/extensions/update_or_create_spec.rb +0 -83
- data/spec/extensions/update_primary_key_spec.rb +0 -105
- data/spec/extensions/update_refresh_spec.rb +0 -59
- data/spec/extensions/uuid_spec.rb +0 -101
- data/spec/extensions/validate_associated_spec.rb +0 -52
- data/spec/extensions/validation_class_methods_spec.rb +0 -1040
- data/spec/extensions/validation_contexts_spec.rb +0 -31
- data/spec/extensions/validation_helpers_spec.rb +0 -525
- data/spec/extensions/whitelist_security_spec.rb +0 -157
- data/spec/extensions/xml_serializer_spec.rb +0 -213
- data/spec/files/bad_down_migration/001_create_alt_basic.rb +0 -4
- data/spec/files/bad_down_migration/002_create_alt_advanced.rb +0 -4
- data/spec/files/bad_timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/bad_timestamped_migrations/1273253851_create_nodes.rb +0 -9
- data/spec/files/bad_timestamped_migrations/1273253853_3_create_users.rb +0 -3
- data/spec/files/bad_up_migration/001_create_alt_basic.rb +0 -4
- data/spec/files/bad_up_migration/002_create_alt_advanced.rb +0 -3
- data/spec/files/convert_to_timestamp_migrations/001_create_sessions.rb +0 -9
- data/spec/files/convert_to_timestamp_migrations/002_create_nodes.rb +0 -9
- data/spec/files/convert_to_timestamp_migrations/003_3_create_users.rb +0 -4
- data/spec/files/convert_to_timestamp_migrations/1273253850_create_artists.rb +0 -9
- data/spec/files/convert_to_timestamp_migrations/1273253852_create_albums.rb +0 -9
- data/spec/files/double_migration/001_create_sessions.rb +0 -9
- data/spec/files/double_migration/002_create_nodes.rb +0 -19
- data/spec/files/double_migration/003_3_create_users.rb +0 -4
- data/spec/files/duplicate_integer_migrations/001_create_alt_advanced.rb +0 -4
- data/spec/files/duplicate_integer_migrations/001_create_alt_basic.rb +0 -4
- data/spec/files/duplicate_timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/duplicate_timestamped_migrations/1273253853_create_nodes.rb +0 -9
- data/spec/files/duplicate_timestamped_migrations/1273253853_create_users.rb +0 -4
- data/spec/files/empty_migration/001_create_sessions.rb +0 -9
- data/spec/files/empty_migration/002_create_nodes.rb +0 -0
- data/spec/files/empty_migration/003_3_create_users.rb +0 -4
- data/spec/files/integer_migrations/001_create_sessions.rb +0 -9
- data/spec/files/integer_migrations/002_create_nodes.rb +0 -9
- data/spec/files/integer_migrations/003_3_create_users.rb +0 -4
- data/spec/files/interleaved_timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/interleaved_timestamped_migrations/1273253850_create_artists.rb +0 -9
- data/spec/files/interleaved_timestamped_migrations/1273253851_create_nodes.rb +0 -9
- data/spec/files/interleaved_timestamped_migrations/1273253852_create_albums.rb +0 -9
- data/spec/files/interleaved_timestamped_migrations/1273253853_3_create_users.rb +0 -4
- data/spec/files/missing_integer_migrations/001_create_alt_basic.rb +0 -4
- data/spec/files/missing_integer_migrations/003_create_alt_advanced.rb +0 -4
- data/spec/files/missing_timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/missing_timestamped_migrations/1273253853_3_create_users.rb +0 -4
- data/spec/files/reversible_migrations/001_reversible.rb +0 -5
- data/spec/files/reversible_migrations/002_reversible.rb +0 -5
- data/spec/files/reversible_migrations/003_reversible.rb +0 -5
- data/spec/files/reversible_migrations/004_reversible.rb +0 -5
- data/spec/files/reversible_migrations/005_reversible.rb +0 -10
- data/spec/files/reversible_migrations/006_reversible.rb +0 -10
- data/spec/files/reversible_migrations/007_reversible.rb +0 -10
- data/spec/files/timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/timestamped_migrations/1273253851_create_nodes.rb +0 -9
- data/spec/files/timestamped_migrations/1273253853_3_create_users.rb +0 -4
- data/spec/files/transaction_specified_migrations/001_create_alt_basic.rb +0 -4
- data/spec/files/transaction_specified_migrations/002_create_basic.rb +0 -4
- data/spec/files/transaction_unspecified_migrations/001_create_alt_basic.rb +0 -3
- data/spec/files/transaction_unspecified_migrations/002_create_basic.rb +0 -3
- data/spec/files/uppercase_timestamped_migrations/1273253849_CREATE_SESSIONS.RB +0 -9
- data/spec/files/uppercase_timestamped_migrations/1273253851_CREATE_NODES.RB +0 -9
- data/spec/files/uppercase_timestamped_migrations/1273253853_3_CREATE_USERS.RB +0 -4
- data/spec/guards_helper.rb +0 -59
- data/spec/integration/associations_test.rb +0 -2597
- data/spec/integration/database_test.rb +0 -113
- data/spec/integration/dataset_test.rb +0 -1981
- data/spec/integration/eager_loader_test.rb +0 -687
- data/spec/integration/migrator_test.rb +0 -262
- data/spec/integration/model_test.rb +0 -203
- data/spec/integration/plugin_test.rb +0 -2396
- data/spec/integration/prepared_statement_test.rb +0 -405
- data/spec/integration/schema_test.rb +0 -889
- data/spec/integration/spec_helper.rb +0 -65
- data/spec/integration/timezone_test.rb +0 -86
- data/spec/integration/transaction_test.rb +0 -603
- data/spec/integration/type_test.rb +0 -127
- data/spec/model/association_reflection_spec.rb +0 -803
- data/spec/model/associations_spec.rb +0 -4738
- data/spec/model/base_spec.rb +0 -875
- data/spec/model/class_dataset_methods_spec.rb +0 -146
- data/spec/model/dataset_methods_spec.rb +0 -198
- data/spec/model/eager_loading_spec.rb +0 -2377
- data/spec/model/hooks_spec.rb +0 -370
- data/spec/model/inflector_spec.rb +0 -26
- data/spec/model/model_spec.rb +0 -956
- data/spec/model/plugins_spec.rb +0 -429
- data/spec/model/record_spec.rb +0 -2118
- data/spec/model/spec_helper.rb +0 -46
- data/spec/model/validations_spec.rb +0 -220
- data/spec/model_no_assoc_spec.rb +0 -1
- data/spec/model_spec.rb +0 -1
- data/spec/plugin_spec.rb +0 -1
- data/spec/sequel_coverage.rb +0 -15
- data/spec/sequel_warning.rb +0 -4
- data/spec/spec_config.rb +0 -12
data/spec/adapters/mssql_spec.rb
DELETED
@@ -1,804 +0,0 @@
|
|
1
|
-
SEQUEL_ADAPTER_TEST = :mssql
|
2
|
-
|
3
|
-
require_relative 'spec_helper'
|
4
|
-
|
5
|
-
describe "A MSSQL database" do
|
6
|
-
before do
|
7
|
-
@db = DB
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should be able to read fractional part of timestamp" do
|
11
|
-
rs = @db["select getutcdate() as full_date, cast(round(datepart(millisecond, getutcdate()), 0) as int) as milliseconds"].first
|
12
|
-
rs[:milliseconds].must_be_close_to(rs[:full_date].usec/1000, 2)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should be able to write fractional part of timestamp" do
|
16
|
-
t = Time.utc(2001, 12, 31, 23, 59, 59, 996000)
|
17
|
-
(t.usec/1000).must_equal @db["select cast(round(datepart(millisecond, ?), 0) as int) as milliseconds", t].get
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should not raise an error when getting the server version" do
|
21
|
-
@db.server_version
|
22
|
-
@db.dataset.server_version
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe "A MSSQL database" do
|
27
|
-
before do
|
28
|
-
@db = DB
|
29
|
-
@db.create_table! :test3 do
|
30
|
-
Integer :value
|
31
|
-
Time :time
|
32
|
-
end
|
33
|
-
end
|
34
|
-
after do
|
35
|
-
@db.drop_table?(:test3)
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should work with NOLOCK" do
|
39
|
-
@db.transaction{@db[:test3].nolock.all.must_equal []}
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe "MSSQL" do
|
44
|
-
before(:all) do
|
45
|
-
@db = DB
|
46
|
-
@db.create_table!(:test3){Integer :v3}
|
47
|
-
@db.create_table!(:test4){Integer :v4}
|
48
|
-
@db[:test3].import([:v3], [[1], [2]])
|
49
|
-
@db[:test4].import([:v4], [[1], [3]])
|
50
|
-
end
|
51
|
-
after(:all) do
|
52
|
-
@db.drop_table?(:test3, :test4)
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should should support CROSS APPLY" do
|
56
|
-
@db[:test3].cross_apply(@db[:test4].where(Sequel[:test3][:v3]=>Sequel[:test4][:v4])).select_order_map([:v3, :v4]).must_equal [[1,1]]
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should should support OUTER APPLY" do
|
60
|
-
@db[:test3].outer_apply(@db[:test4].where(Sequel[:test3][:v3]=>Sequel[:test4][:v4])).select_order_map([:v3, :v4]).must_equal [[1,1], [2, nil]]
|
61
|
-
end
|
62
|
-
|
63
|
-
cspecify "should handle time values with fractional seconds", [:ado] do
|
64
|
-
# ado: Returns nil values
|
65
|
-
t = Sequel::SQLTime.create(10, 20, 30, 999900)
|
66
|
-
v = @db.get(Sequel.cast(t, 'time'))
|
67
|
-
v = Sequel.string_to_time(v) if v.is_a?(String)
|
68
|
-
pr = lambda{|x| [:hour, :min, :sec, :usec].map{|m| x.send(m)}}
|
69
|
-
pr[v].must_equal(pr[t])
|
70
|
-
end
|
71
|
-
|
72
|
-
cspecify "should get datetimeoffset values as Time with fractional seconds", [:odbc], [:ado], [:tinytds, proc{|db| TinyTds::VERSION < '0.9'}] do
|
73
|
-
# odbc: Returns string rounded to nearest second
|
74
|
-
# ado: Returns nil values
|
75
|
-
# tiny_tds < 0.9: Returns wrong value for hour
|
76
|
-
t = Time.local(2010, 11, 12, 10, 20, 30, 999000)
|
77
|
-
v = @db.get(Sequel.cast(t, 'datetimeoffset'))
|
78
|
-
v = Sequel.string_to_datetime(v) if v.is_a?(String)
|
79
|
-
pr = lambda{|x| [:year, :month, :day, :hour, :min, :sec, :usec].map{|m| x.send(m)}}
|
80
|
-
pr[v].must_equal(pr[t])
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
# This spec is currently disabled as the SQL Server 2008 R2 Express doesn't support
|
85
|
-
# full text searching. Even if full text searching is supported,
|
86
|
-
# you may need to create a full text catalog on the database first via:
|
87
|
-
# CREATE FULLTEXT CATALOG ftscd AS DEFAULT
|
88
|
-
describe "MSSQL full_text_search" do
|
89
|
-
before do
|
90
|
-
@db = DB
|
91
|
-
@db.drop_table?(:posts)
|
92
|
-
end
|
93
|
-
after do
|
94
|
-
@db.drop_table?(:posts)
|
95
|
-
end
|
96
|
-
|
97
|
-
it "should support fulltext indexes and full_text_search" do
|
98
|
-
log do
|
99
|
-
@db.create_table(:posts){Integer :id, :null=>false; String :title; String :body; index :id, :name=>:fts_id_idx, :unique=>true; full_text_index :title, :key_index=>:fts_id_idx; full_text_index [:title, :body], :key_index=>:fts_id_idx}
|
100
|
-
@db[:posts].insert(:title=>'ruby rails', :body=>'y')
|
101
|
-
@db[:posts].insert(:title=>'sequel', :body=>'ruby')
|
102
|
-
@db[:posts].insert(:title=>'ruby scooby', :body=>'x')
|
103
|
-
|
104
|
-
@db[:posts].full_text_search(:title, 'rails').all.must_equal [{:title=>'ruby rails', :body=>'y'}]
|
105
|
-
@db[:posts].full_text_search([:title, :body], ['sequel', 'ruby']).all.must_equal [{:title=>'sequel', :body=>'ruby'}]
|
106
|
-
|
107
|
-
@db[:posts].full_text_search(:title, :$n).call(:select, :n=>'rails').must_equal [{:title=>'ruby rails', :body=>'y'}]
|
108
|
-
@db[:posts].full_text_search(:title, :$n).prepare(:select, :fts_select).call(:n=>'rails').must_equal [{:title=>'ruby rails', :body=>'y'}]
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end if false
|
112
|
-
|
113
|
-
describe "MSSQL Dataset#output" do
|
114
|
-
before(:all) do
|
115
|
-
@db = DB
|
116
|
-
@db.create_table!(:items){String :name; Integer :value}
|
117
|
-
@db.create_table!(:out){String :name; Integer :value}
|
118
|
-
@ds = @db[:items]
|
119
|
-
end
|
120
|
-
after do
|
121
|
-
@ds.delete
|
122
|
-
@db[:out].delete
|
123
|
-
end
|
124
|
-
after(:all) do
|
125
|
-
@db.drop_table?(:items, :out)
|
126
|
-
end
|
127
|
-
|
128
|
-
it "should handle OUTPUT clauses without INTO for DELETE statements" do
|
129
|
-
@ds.insert(:name=>'a', :value=>1)
|
130
|
-
@ds.output(nil, [Sequel[:deleted][:name], Sequel[:deleted][:value]]).with_sql(:delete_sql).all.must_equal [{:name=>"a", :value=>1}]
|
131
|
-
@ds.insert(:name=>'a', :value=>1)
|
132
|
-
@ds.output(nil, [Sequel[:deleted][:name]]).with_sql(:delete_sql).all.must_equal [{:name=>"a"}]
|
133
|
-
@ds.insert(:name=>'a', :value=>1)
|
134
|
-
@ds.output(nil, [Sequel::SQL::ColumnAll.new(:deleted)]).with_sql(:delete_sql).all.must_equal [{:name=>"a", :value=>1}]
|
135
|
-
end
|
136
|
-
|
137
|
-
it "should handle OUTPUT clauses with INTO for DELETE statements" do
|
138
|
-
@ds.insert(:name=>'a', :value=>1)
|
139
|
-
@ds.output(:out, {:name => Sequel[:deleted][:name], :value => Sequel[:deleted][:value]}).delete
|
140
|
-
@db[:out].all.must_equal [{:name=>"a", :value=>1}]
|
141
|
-
end
|
142
|
-
|
143
|
-
it "should handle OUTPUT clauses without INTO for INSERT statements" do
|
144
|
-
@ds.output(nil, [Sequel[:inserted][:name], Sequel[:inserted][:value]]).with_sql(:insert_sql, :name => "name", :value => 1).all.must_equal [{:name=>"name", :value=>1}]
|
145
|
-
@ds.all.must_equal [{:name=>"name", :value=>1}]
|
146
|
-
end
|
147
|
-
|
148
|
-
it "should handle OUTPUT clauses with INTO for INSERT statements" do
|
149
|
-
@ds.output(:out, {:name => Sequel[:inserted][:name], :value => Sequel[:inserted][:value]}).insert(:name => "name", :value => 1)
|
150
|
-
@db[:out].all.must_equal [{:name=>"name", :value=>1}]
|
151
|
-
end
|
152
|
-
|
153
|
-
it "should handle OUTPUT clauses without INTO for UPDATE statements" do
|
154
|
-
@ds.insert(:name=>'a', :value=>1)
|
155
|
-
@ds.output(nil, [Sequel[:inserted][:name], Sequel[:deleted][:value]]).with_sql(:update_sql, :value => 2).all.must_equal [{:name=>"a", :value=>1}]
|
156
|
-
@ds.all.must_equal [{:name=>"a", :value=>2}]
|
157
|
-
@ds.output(nil, [Sequel[:inserted][:name]]).with_sql(:update_sql, :value => 3).all.must_equal [{:name=>"a"}]
|
158
|
-
@ds.all.must_equal [{:name=>"a", :value=>3}]
|
159
|
-
@ds.output(nil, [Sequel::SQL::ColumnAll.new(:inserted)]).with_sql(:update_sql, :value => 4).all.must_equal [{:name=>"a", :value=>4}]
|
160
|
-
end
|
161
|
-
|
162
|
-
it "should handle OUTPUT clauses with INTO for UPDATE statements" do
|
163
|
-
@ds.insert(:name=>'a', :value=>1)
|
164
|
-
@ds.output(:out, {:name => Sequel[:inserted][:name], :value => Sequel[:deleted][:value]}).update(:value => 2)
|
165
|
-
@db[:out].all.must_equal [{:name=>"a", :value=>1}]
|
166
|
-
end
|
167
|
-
|
168
|
-
it "should execute OUTPUT clauses in DELETE statements" do
|
169
|
-
@ds.insert(:name => "name", :value => 1)
|
170
|
-
@ds.output(:out, [Sequel[:deleted][:name], Sequel[:deleted][:value]]).delete
|
171
|
-
@db[:out].all.must_equal [{:name => "name", :value => 1}]
|
172
|
-
@ds.insert(:name => "name", :value => 2)
|
173
|
-
@ds.output(:out, {:name => Sequel[:deleted][:name], :value => Sequel[:deleted][:value]}).delete
|
174
|
-
@db[:out].all.must_equal [{:name => "name", :value => 1}, {:name => "name", :value => 2}]
|
175
|
-
end
|
176
|
-
|
177
|
-
it "should execute OUTPUT clauses in INSERT statements" do
|
178
|
-
@ds.output(:out, [Sequel[:inserted][:name], Sequel[:inserted][:value]]).insert(:name => "name", :value => 1)
|
179
|
-
@db[:out].all.must_equal [{:name => "name", :value => 1}]
|
180
|
-
@ds.output(:out, {:name => Sequel[:inserted][:name], :value => Sequel[:inserted][:value]}).insert(:name => "name", :value => 2)
|
181
|
-
@db[:out].all.must_equal [{:name => "name", :value => 1}, {:name => "name", :value => 2}]
|
182
|
-
end
|
183
|
-
|
184
|
-
it "should execute OUTPUT clauses in UPDATE statements" do
|
185
|
-
@ds.insert(:name => "name", :value => 1)
|
186
|
-
@ds.output(:out, [Sequel[:inserted][:name], Sequel[:deleted][:value]]).update(:value => 2)
|
187
|
-
@db[:out].all.must_equal [{:name => "name", :value => 1}]
|
188
|
-
@ds.output(:out, {:name => Sequel[:inserted][:name], :value => Sequel[:deleted][:value]}).update(:value => 3)
|
189
|
-
@db[:out].all.must_equal [{:name => "name", :value => 1}, {:name => "name", :value => 2}]
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
describe "MSSQL dataset using #with and #with_recursive" do
|
194
|
-
before(:all) do
|
195
|
-
@db = DB
|
196
|
-
@ds = DB[:x]
|
197
|
-
@ds1 = @ds.with(:t, @db[:x])
|
198
|
-
@ds2 = @ds.with_recursive(:t, @db[:x], @db[:t].where(false))
|
199
|
-
@db.create_table!(:x){Integer :v; Integer :y}
|
200
|
-
end
|
201
|
-
before do
|
202
|
-
@db[:x].insert(:v=>1, :y=>2)
|
203
|
-
end
|
204
|
-
after do
|
205
|
-
@db[:x].delete
|
206
|
-
end
|
207
|
-
after(:all) do
|
208
|
-
@db.drop_table?(:x)
|
209
|
-
end
|
210
|
-
|
211
|
-
it "should handle CTEs in UPDATE queries" do
|
212
|
-
@ds1.update(:v => @db[:t].select(:y))
|
213
|
-
@ds.all.must_equal [{:v=>2, :y=>2}]
|
214
|
-
@ds2.update(:v => Sequel.+(@db[:t].select(:y), 1))
|
215
|
-
@ds.all.must_equal [{:v=>3, :y=>2}]
|
216
|
-
end
|
217
|
-
|
218
|
-
it "should handle CTEs in DELETE queries" do
|
219
|
-
@ds1.where(@db[:t].select(:y)=>1).delete
|
220
|
-
@ds.all.must_equal [{:v=>1, :y=>2}]
|
221
|
-
@ds1.where(@db[:t].select(:y)=>2).delete
|
222
|
-
@ds.all.must_equal []
|
223
|
-
|
224
|
-
@db[:x].insert(:v=>1, :y=>2)
|
225
|
-
@ds2.where(@db[:t].select(:y)=>1).delete
|
226
|
-
@ds.all.must_equal [{:v=>1, :y=>2}]
|
227
|
-
@ds2.where(@db[:t].select(:y)=>2).delete
|
228
|
-
@ds.all.must_equal []
|
229
|
-
end
|
230
|
-
|
231
|
-
it "should handle CTEs in INSERT queries" do
|
232
|
-
@ds1.insert(:v => @db[:t].select(:y), :y => @db[:t].select(:v))
|
233
|
-
@ds.select_order_map([:v, :y]).must_equal [[1, 2], [2, 1]]
|
234
|
-
@ds1.insert(:v => Sequel.+(@db[:t].where(:v=>1).select(:y), 2), :y => Sequel.+(@db[:t].where(:y=>1).select(:v), 3))
|
235
|
-
@ds.select_order_map([:v, :y]).must_equal [[1, 2], [2, 1], [4, 5]]
|
236
|
-
end
|
237
|
-
|
238
|
-
it "should handle WITH clause on joined dataset" do
|
239
|
-
@ds.cross_join(@ds1.select(Sequel[:v].as(:v1), Sequel[:y].as(:y1))).all.must_equal [{:v=>1, :y=>2, :v1=>1, :y1=>2}]
|
240
|
-
@ds.cross_join(@ds2.select(Sequel[:v].as(:v1), Sequel[:y].as(:y1))).all.must_equal [{:v=>1, :y=>2, :v1=>1, :y1=>2}]
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
describe "MSSQL::Dataset#import" do
|
245
|
-
before do
|
246
|
-
@db = DB
|
247
|
-
@ds = @db[:test]
|
248
|
-
end
|
249
|
-
after do
|
250
|
-
@db.drop_table?(:test)
|
251
|
-
end
|
252
|
-
|
253
|
-
it "#import should work correctly with an arbitrary output value" do
|
254
|
-
@db.create_table!(:test){primary_key :x; Integer :y}
|
255
|
-
@ds.output(nil, [Sequel[:inserted][:y], Sequel[:inserted][:x]]).import([:y], [[3], [4]]).must_equal [{:y=>3, :x=>1}, {:y=>4, :x=>2}]
|
256
|
-
@ds.all.must_equal [{:x=>1, :y=>3}, {:x=>2, :y=>4}]
|
257
|
-
end
|
258
|
-
|
259
|
-
it "should handle WITH statements" do
|
260
|
-
@db.create_table!(:test){Integer :x; Integer :y}
|
261
|
-
@db[:testx].with(:testx, @db[:test]).import([:x, :y], [[1, 2], [3, 4], [5, 6]], :slice => 2)
|
262
|
-
@ds.select_order_map([:x, :y]).must_equal [[1, 2], [3, 4], [5, 6]]
|
263
|
-
end
|
264
|
-
end
|
265
|
-
|
266
|
-
describe "MSSQL joined datasets" do
|
267
|
-
before do
|
268
|
-
@db = DB
|
269
|
-
@db.create_table!(:a){Integer :v}
|
270
|
-
@db[:a].insert(:v=>1)
|
271
|
-
end
|
272
|
-
after do
|
273
|
-
@db.drop_table?(:a)
|
274
|
-
end
|
275
|
-
|
276
|
-
it "should handle DELETE statements" do
|
277
|
-
@db[:a].inner_join(Sequel[:a].as(:b), :v=>:v).delete.must_equal 1
|
278
|
-
@db[:a].empty?.must_equal true
|
279
|
-
end
|
280
|
-
|
281
|
-
it "should handle UPDATE statements" do
|
282
|
-
@db[:a].inner_join(Sequel[:a].as(:b), :v=>:v).update(:v=>2).must_equal 1
|
283
|
-
@db[:a].all.must_equal [{:v=>2}]
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
|
-
describe "Offset support" do
|
288
|
-
before do
|
289
|
-
@db = DB
|
290
|
-
@db.create_table!(:i){Integer :id; Integer :parent_id}
|
291
|
-
@ds = @db[:i].order(:id)
|
292
|
-
@hs = []
|
293
|
-
@ds = @ds.with_row_proc(proc{|r| @hs << r.dup; r[:id] *= 2; r[:parent_id] *= 3; r})
|
294
|
-
@ds.import [:id, :parent_id], [[1,nil],[2,nil],[3,1],[4,1],[5,3],[6,5]]
|
295
|
-
end
|
296
|
-
after do
|
297
|
-
@db.drop_table?(:i)
|
298
|
-
end
|
299
|
-
|
300
|
-
it "should return correct rows" do
|
301
|
-
@ds.limit(2, 2).all.must_equal [{:id=>6, :parent_id=>3}, {:id=>8, :parent_id=>3}]
|
302
|
-
end
|
303
|
-
|
304
|
-
it "should not include offset column in hashes passed to row_proc" do
|
305
|
-
@ds.limit(2, 2).all
|
306
|
-
@hs.must_equal [{:id=>3, :parent_id=>1}, {:id=>4, :parent_id=>1}]
|
307
|
-
end
|
308
|
-
end
|
309
|
-
|
310
|
-
describe "Update/Delete on limited datasets" do
|
311
|
-
before do
|
312
|
-
@db = DB
|
313
|
-
@db.create_table!(:i){Integer :id}
|
314
|
-
@ds = @db[:i]
|
315
|
-
@ds.import [:id], [[1], [2]]
|
316
|
-
end
|
317
|
-
after do
|
318
|
-
@db.drop_table?(:i)
|
319
|
-
end
|
320
|
-
|
321
|
-
it "should handle deletes and updates on limited datasets" do
|
322
|
-
@ds.limit(1).update(:id=>Sequel[:id]+10)
|
323
|
-
[[2, 11], [1, 12]].must_include @ds.select_order_map(:id)
|
324
|
-
@ds.limit(1).delete
|
325
|
-
[[1], [2]].must_include @ds.select_order_map(:id)
|
326
|
-
end
|
327
|
-
|
328
|
-
it "should raise error for updates on ordered, limited datasets" do
|
329
|
-
end
|
330
|
-
|
331
|
-
it "should raise error for updates and deletes on datasets with offsets or limits with orders" do
|
332
|
-
proc{@ds.offset(1).delete}.must_raise Sequel::InvalidOperation
|
333
|
-
proc{@ds.offset(1).update(:id=>Sequel[:id]+10)}.must_raise Sequel::InvalidOperation
|
334
|
-
proc{@ds.limit(1, 1).delete}.must_raise Sequel::InvalidOperation
|
335
|
-
proc{@ds.limit(1, 1).update(:id=>Sequel[:id]+10)}.must_raise Sequel::InvalidOperation
|
336
|
-
proc{@ds.order(:id).limit(1).update(:id=>Sequel[:id]+10)}.must_raise Sequel::InvalidOperation
|
337
|
-
proc{@ds.order(:id).limit(1).delete}.must_raise Sequel::InvalidOperation
|
338
|
-
end
|
339
|
-
end if DB.dataset.send(:is_2012_or_later?)
|
340
|
-
|
341
|
-
describe "Common Table Expressions" do
|
342
|
-
before do
|
343
|
-
@db = DB
|
344
|
-
@db.create_table!(:i1){Integer :id; Integer :parent_id}
|
345
|
-
@db.create_table!(:i2){Integer :id; Integer :parent_id}
|
346
|
-
@ds = @db[:i1]
|
347
|
-
@ds2 = @db[:i2]
|
348
|
-
@ds.import [:id, :parent_id], [[1,nil],[2,nil],[3,1],[4,1],[5,3],[6,5]]
|
349
|
-
end
|
350
|
-
after do
|
351
|
-
@db.drop_table?(:i1, :i2)
|
352
|
-
end
|
353
|
-
|
354
|
-
it "using #with should be able to update" do
|
355
|
-
@ds.insert(:id=>1)
|
356
|
-
@ds2.insert(:id=>2, :parent_id=>1)
|
357
|
-
@ds2.insert(:id=>3, :parent_id=>2)
|
358
|
-
@ds.with(:t, @ds2).filter(:id => @db[:t].select(:id)).update(:parent_id => @db[:t].filter(:id => Sequel[:i1][:id]).select(:parent_id).limit(1))
|
359
|
-
@ds[:id => 1].must_equal(:id => 1, :parent_id => nil)
|
360
|
-
@ds[:id => 2].must_equal(:id => 2, :parent_id => 1)
|
361
|
-
@ds[:id => 3].must_equal(:id => 3, :parent_id => 2)
|
362
|
-
@ds[:id => 4].must_equal(:id => 4, :parent_id => 1)
|
363
|
-
end
|
364
|
-
|
365
|
-
it "using #with_recursive should be able to update" do
|
366
|
-
ds = @ds.with_recursive(:t, @ds.filter(:parent_id=>1).or(:id => 1), @ds.join(:t, :i=>:parent_id).select(Sequel[:i1][:id], Sequel[:i1][:parent_id]), :args=>[:i, :pi])
|
367
|
-
ds.exclude(:id => @db[:t].select(:i)).update(:parent_id => 1)
|
368
|
-
@ds[:id => 1].must_equal(:id => 1, :parent_id => nil)
|
369
|
-
@ds[:id => 2].must_equal(:id => 2, :parent_id => 1)
|
370
|
-
@ds[:id => 5].must_equal(:id => 5, :parent_id => 3)
|
371
|
-
end
|
372
|
-
|
373
|
-
it "using #with should be able to insert" do
|
374
|
-
@ds2.insert(:id=>7)
|
375
|
-
@ds.with(:t, @ds2).insert(@db[:t])
|
376
|
-
@ds[:id => 7].must_equal(:id => 7, :parent_id => nil)
|
377
|
-
end
|
378
|
-
|
379
|
-
it "using #with_recursive should be able to insert" do
|
380
|
-
ds = @ds2.with_recursive(:t, @ds.filter(:parent_id=>1), @ds.join(:t, :i=>:parent_id).select(Sequel[:i1][:id], Sequel[:i1][:parent_id]), :args=>[:i, :pi])
|
381
|
-
ds.insert @db[:t]
|
382
|
-
@ds2.all.must_equal [{:id => 3, :parent_id => 1}, {:id => 4, :parent_id => 1}, {:id => 5, :parent_id => 3}, {:id => 6, :parent_id => 5}]
|
383
|
-
end
|
384
|
-
|
385
|
-
it "using #with should be able to delete" do
|
386
|
-
@ds2.insert(:id=>6)
|
387
|
-
@ds2.insert(:id=>5)
|
388
|
-
@ds2.insert(:id=>4)
|
389
|
-
@ds.with(:t, @ds2).filter(:id => @db[:t].select(:id)).delete
|
390
|
-
@ds.all.must_equal [{:id => 1, :parent_id => nil}, {:id => 2, :parent_id => nil}, {:id => 3, :parent_id => 1}]
|
391
|
-
end
|
392
|
-
|
393
|
-
it "using #with_recursive should be able to delete" do
|
394
|
-
@ds.insert(:id=>7, :parent_id=>2)
|
395
|
-
ds = @ds.with_recursive(:t, @ds.filter(:parent_id=>1), @ds.join(:t, :i=>:parent_id).select(Sequel[:i1][:id], Sequel[:i1][:parent_id]), :args=>[:i, :pi])
|
396
|
-
ds.filter(Sequel[:i1][:id] => @db[:t].select(:i)).delete
|
397
|
-
@ds.all.must_equal [{:id => 1, :parent_id => nil}, {:id => 2, :parent_id => nil}, {:id => 7, :parent_id => 2}]
|
398
|
-
end
|
399
|
-
|
400
|
-
it "using #with should be able to import" do
|
401
|
-
@ds2.insert(:id=>7)
|
402
|
-
@ds.with(:t, @ds2).import [:id, :parent_id], @db[:t].select(:id, :parent_id)
|
403
|
-
@ds[:id => 7].must_equal(:id => 7, :parent_id => nil)
|
404
|
-
end
|
405
|
-
|
406
|
-
it "using #with_recursive should be able to import" do
|
407
|
-
ds = @ds2.with_recursive(:t, @ds.filter(:parent_id=>1), @ds.join(:t, :i=>:parent_id).select(Sequel[:i1][:id], Sequel[:i1][:parent_id]), :args=>[:i, :pi])
|
408
|
-
ds.import [:id, :parent_id], @db[:t].select(:i, :pi)
|
409
|
-
@ds2.all.must_equal [{:id => 3, :parent_id => 1}, {:id => 4, :parent_id => 1}, {:id => 5, :parent_id => 3}, {:id => 6, :parent_id => 5}]
|
410
|
-
end
|
411
|
-
end
|
412
|
-
|
413
|
-
describe "MSSSQL::Dataset#insert" do
|
414
|
-
before do
|
415
|
-
@db = DB
|
416
|
-
@db.create_table!(:test5){primary_key :xid; Integer :value}
|
417
|
-
@db.create_table! :test4 do
|
418
|
-
String :name, :size => 20
|
419
|
-
column :value, 'varbinary(max)'
|
420
|
-
end
|
421
|
-
@ds = @db[:test5]
|
422
|
-
end
|
423
|
-
after do
|
424
|
-
@db.drop_table?(:test5, :test4)
|
425
|
-
end
|
426
|
-
|
427
|
-
it "should have insert_select return nil if disable_insert_output is used" do
|
428
|
-
@ds.disable_insert_output.insert_select(:value=>10).must_be_nil
|
429
|
-
end
|
430
|
-
|
431
|
-
it "should have insert_select return nil if the server version is not 2005+" do
|
432
|
-
@ds = @ds.with_extend do
|
433
|
-
def server_version() 8000760 end
|
434
|
-
end
|
435
|
-
@ds.insert_select(:value=>10).must_be_nil
|
436
|
-
end
|
437
|
-
|
438
|
-
it "should have insert_select insert the record and return the inserted record" do
|
439
|
-
h = @ds.insert_select(:value=>10)
|
440
|
-
h[:value].must_equal 10
|
441
|
-
@ds.first(:xid=>h[:xid])[:value].must_equal 10
|
442
|
-
end
|
443
|
-
|
444
|
-
cspecify "should allow large text and binary values", [:odbc] do
|
445
|
-
blob = Sequel::SQL::Blob.new("0" * (65*1024))
|
446
|
-
@db[:test4].insert(:name => 'max varbinary test', :value => blob)
|
447
|
-
b = @db[:test4].where(:name => 'max varbinary test').get(:value)
|
448
|
-
b.length.must_equal blob.length
|
449
|
-
b.must_equal blob
|
450
|
-
end
|
451
|
-
|
452
|
-
it "should play nicely with simple_select_all?" do
|
453
|
-
DB[:test4].disable_insert_output.send(:simple_select_all?).must_equal true
|
454
|
-
end
|
455
|
-
end
|
456
|
-
|
457
|
-
describe "MSSSQL::Dataset#into" do
|
458
|
-
before do
|
459
|
-
@db = DB
|
460
|
-
@db.drop_table?(:t, :new)
|
461
|
-
end
|
462
|
-
after do
|
463
|
-
@db.drop_table?(:t, :new)
|
464
|
-
end
|
465
|
-
|
466
|
-
it "should select rows into a new table" do
|
467
|
-
@db.create_table!(:t) {Integer :id; String :value}
|
468
|
-
@db[:t].insert(:id => 1, :value => "test")
|
469
|
-
@db[:t].into(:new).with_sql(:select_sql).insert
|
470
|
-
@db[:new].all.must_equal [{:id => 1, :value => "test"}]
|
471
|
-
end
|
472
|
-
end
|
473
|
-
|
474
|
-
describe "A MSSQL database" do
|
475
|
-
before do
|
476
|
-
@db = DB
|
477
|
-
end
|
478
|
-
after do
|
479
|
-
@db.drop_table?(:a)
|
480
|
-
end
|
481
|
-
|
482
|
-
it "should handle many existing types for set_column_allow_null" do
|
483
|
-
@db.create_table!(:a){column :a, 'integer'}
|
484
|
-
@db.alter_table(:a){set_column_allow_null :a, false}
|
485
|
-
@db.create_table!(:a){column :a, 'decimal(24, 2)'}
|
486
|
-
@db.alter_table(:a){set_column_allow_null :a, false}
|
487
|
-
@db.schema(:a).first.last[:column_size].must_equal 24
|
488
|
-
@db.schema(:a).first.last[:scale].must_equal 2
|
489
|
-
@db.create_table!(:a){column :a, 'decimal(10)'}
|
490
|
-
@db.schema(:a).first.last[:column_size].must_equal 10
|
491
|
-
@db.schema(:a).first.last[:scale].must_equal 0
|
492
|
-
@db.alter_table(:a){set_column_allow_null :a, false}
|
493
|
-
@db.create_table!(:a){column :a, 'nchar(2)'}
|
494
|
-
@db.alter_table(:a){set_column_allow_null :a, false}
|
495
|
-
s = @db.schema(:a).first.last
|
496
|
-
(s[:max_chars] || s[:column_size]).must_equal 2
|
497
|
-
end
|
498
|
-
end
|
499
|
-
|
500
|
-
describe "MSSQL::Database#rename_table" do
|
501
|
-
it "should work on non-schema bound tables which need escaping" do
|
502
|
-
DB.create_table! :'foo bar' do
|
503
|
-
text :name
|
504
|
-
end
|
505
|
-
DB.rename_table 'foo bar', 'foo'
|
506
|
-
DB.drop_table :foo
|
507
|
-
end
|
508
|
-
|
509
|
-
it "should work on schema bound tables within the same schema" do
|
510
|
-
DB.execute(<<-SQL)
|
511
|
-
IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = 'MY')
|
512
|
-
EXECUTE sp_executesql N'create schema MY'
|
513
|
-
SQL
|
514
|
-
DB.create_table! Sequel[:MY][:foo] do
|
515
|
-
text :name
|
516
|
-
end
|
517
|
-
DB.rename_table Sequel[:MY][:foo], Sequel[:MY][:bar]
|
518
|
-
DB.rename_table Sequel[:MY][:bar], :foo
|
519
|
-
DB.drop_table Sequel[:MY][:foo]
|
520
|
-
end
|
521
|
-
end
|
522
|
-
|
523
|
-
describe "MSSQL::Dataset#count" do
|
524
|
-
it "should work with a distinct query with an order clause" do
|
525
|
-
DB.create_table!(:items){String :name; Integer :value}
|
526
|
-
DB[:items].insert(:name => "name", :value => 1)
|
527
|
-
DB[:items].insert(:name => "name", :value => 1)
|
528
|
-
DB[:items].select(:name, :value).distinct.order(:name).count.must_equal 1
|
529
|
-
DB[:items].select(:name, :value).group(:name, :value).order(:name).count.must_equal 1
|
530
|
-
end
|
531
|
-
end
|
532
|
-
|
533
|
-
describe "MSSQL::Database#create_table" do
|
534
|
-
it "should support collate with various other column options" do
|
535
|
-
DB.create_table!(:items){ String :name, :size => 128, :collate => :sql_latin1_general_cp1_ci_as, :default => 'foo', :null => false, :unique => true}
|
536
|
-
DB[:items].insert
|
537
|
-
DB[:items].select_map(:name).must_equal ["foo"]
|
538
|
-
end
|
539
|
-
end
|
540
|
-
|
541
|
-
describe "MSSQL::Database#mssql_unicode_strings = false" do
|
542
|
-
before do
|
543
|
-
DB.mssql_unicode_strings = false
|
544
|
-
end
|
545
|
-
after do
|
546
|
-
DB.drop_table?(:items)
|
547
|
-
DB.mssql_unicode_strings = true
|
548
|
-
end
|
549
|
-
|
550
|
-
it "should work correctly" do
|
551
|
-
DB.create_table!(:items){String :name}
|
552
|
-
DB[:items].mssql_unicode_strings.must_equal false
|
553
|
-
DB[:items].insert(:name=>'foo')
|
554
|
-
DB[:items].select_map(:name).must_equal ['foo']
|
555
|
-
end
|
556
|
-
|
557
|
-
it "should be overridable at the dataset level" do
|
558
|
-
DB.create_table!(:items){String :name}
|
559
|
-
ds = DB[:items]
|
560
|
-
ds.mssql_unicode_strings.must_equal false
|
561
|
-
ds1 = ds.with_mssql_unicode_strings(true)
|
562
|
-
ds.mssql_unicode_strings.must_equal false
|
563
|
-
ds1.mssql_unicode_strings.must_equal true
|
564
|
-
ds1.insert(:name=>'foo')
|
565
|
-
ds1.select_map(:name).must_equal ['foo']
|
566
|
-
end
|
567
|
-
end
|
568
|
-
|
569
|
-
describe "A MSSQL database adds index with include" do
|
570
|
-
before :all do
|
571
|
-
@table_name = :test_index_include
|
572
|
-
@db = DB
|
573
|
-
@db.create_table! @table_name do
|
574
|
-
integer :col1
|
575
|
-
integer :col2
|
576
|
-
integer :col3
|
577
|
-
end
|
578
|
-
end
|
579
|
-
|
580
|
-
after :all do
|
581
|
-
@db.drop_table? @table_name
|
582
|
-
end
|
583
|
-
|
584
|
-
it "should be able add index with include" do
|
585
|
-
@db.alter_table @table_name do
|
586
|
-
add_index [:col1], :include => [:col2,:col3]
|
587
|
-
end
|
588
|
-
@db.indexes(@table_name).keys.must_include(:"#{@table_name}_col1_index")
|
589
|
-
end
|
590
|
-
end
|
591
|
-
|
592
|
-
describe "MSSQL set_column_allow_null" do
|
593
|
-
before do
|
594
|
-
@db = DB
|
595
|
-
end
|
596
|
-
after do
|
597
|
-
@db.drop_table?(:test3)
|
598
|
-
end
|
599
|
-
|
600
|
-
it "should work with nvarchar(MAX) columns" do
|
601
|
-
@db.create_table!(:test3) do
|
602
|
-
column :t, 'nvarchar(MAX)'
|
603
|
-
end
|
604
|
-
@db.alter_table(:test3) do
|
605
|
-
set_column_not_null :t
|
606
|
-
end
|
607
|
-
end
|
608
|
-
|
609
|
-
it "should work with text columns" do
|
610
|
-
@db.create_table!(:test3) do
|
611
|
-
column :t, 'text'
|
612
|
-
end
|
613
|
-
@db.alter_table(:test3) do
|
614
|
-
set_column_not_null :t
|
615
|
-
end
|
616
|
-
end
|
617
|
-
end
|
618
|
-
|
619
|
-
describe "MSSQL::Database#drop_column with a schema" do
|
620
|
-
before do
|
621
|
-
DB.run "create schema test" rescue nil
|
622
|
-
end
|
623
|
-
after do
|
624
|
-
DB.drop_table(Sequel[:test][:items])
|
625
|
-
DB.run "drop schema test" rescue nil
|
626
|
-
end
|
627
|
-
|
628
|
-
it "drops columns with a default value" do
|
629
|
-
DB.create_table!(Sequel[:test][:items]){ Integer :id; String :name, :default => 'widget' }
|
630
|
-
DB.drop_column(Sequel[:test][:items], :name)
|
631
|
-
DB[Sequel[:test][:items]].columns.must_equal [:id]
|
632
|
-
end
|
633
|
-
end
|
634
|
-
|
635
|
-
describe "Database#foreign_key_list" do
|
636
|
-
before(:all) do
|
637
|
-
DB.create_table! :items do
|
638
|
-
primary_key :id
|
639
|
-
Integer :sku
|
640
|
-
end
|
641
|
-
DB.create_table! :prices do
|
642
|
-
Integer :item_id
|
643
|
-
datetime :valid_from
|
644
|
-
float :price
|
645
|
-
primary_key [:item_id, :valid_from]
|
646
|
-
foreign_key [:item_id], :items, :key => :id, :name => :fk_prices_items
|
647
|
-
end
|
648
|
-
DB.create_table! :sales do
|
649
|
-
Integer :id
|
650
|
-
Integer :price_item_id
|
651
|
-
datetime :price_valid_from
|
652
|
-
foreign_key [:price_item_id, :price_valid_from], :prices, :key => [:item_id, :valid_from], :name => :fk_sales_prices, :on_delete => :cascade
|
653
|
-
end
|
654
|
-
end
|
655
|
-
after(:all) do
|
656
|
-
DB.drop_table :sales
|
657
|
-
DB.drop_table :prices
|
658
|
-
DB.drop_table :items
|
659
|
-
end
|
660
|
-
it "should support typical foreign keys" do
|
661
|
-
DB.foreign_key_list(:prices).must_equal [{:name => :fk_prices_items,
|
662
|
-
:table => :items,
|
663
|
-
:columns => [:item_id],
|
664
|
-
:key => [:id],
|
665
|
-
:on_update => :no_action,
|
666
|
-
:on_delete => :no_action }]
|
667
|
-
end
|
668
|
-
it "should support a foreign key with multiple columns" do
|
669
|
-
DB.foreign_key_list(:sales).must_equal [{:name => :fk_sales_prices,
|
670
|
-
:table => :prices,
|
671
|
-
:columns => [:price_item_id, :price_valid_from],
|
672
|
-
:key => [:item_id, :valid_from],
|
673
|
-
:on_update => :no_action,
|
674
|
-
:on_delete => :cascade }]
|
675
|
-
end
|
676
|
-
|
677
|
-
describe "with multiple schemas" do
|
678
|
-
before(:all) do
|
679
|
-
DB.execute_ddl "create schema vendor"
|
680
|
-
DB.create_table! Sequel[:vendor][:vendors] do
|
681
|
-
primary_key :id
|
682
|
-
varchar :name
|
683
|
-
end
|
684
|
-
DB.create_table! Sequel[:vendor][:mapping] do
|
685
|
-
Integer :vendor_id
|
686
|
-
Integer :item_id
|
687
|
-
foreign_key [:vendor_id], Sequel[:vendor][:vendors], :name => :fk_mapping_vendor
|
688
|
-
foreign_key [:item_id], :items, :name => :fk_mapping_item
|
689
|
-
end
|
690
|
-
end
|
691
|
-
after(:all) do
|
692
|
-
DB.drop_table? Sequel[:vendor][:mapping]
|
693
|
-
DB.drop_table? Sequel[:vendor][:vendors]
|
694
|
-
DB.execute_ddl "drop schema vendor"
|
695
|
-
end
|
696
|
-
it "should support mixed schema bound tables" do
|
697
|
-
DB.foreign_key_list(Sequel[:vendor][:mapping]).sort_by{|h| h[:name].to_s}.must_equal [{:name => :fk_mapping_item, :table => :items, :columns => [:item_id], :key => [:id], :on_update => :no_action, :on_delete => :no_action }, {:name => :fk_mapping_vendor, :table => Sequel.qualify(:vendor, :vendors), :columns => [:vendor_id], :key => [:id], :on_update => :no_action, :on_delete => :no_action }]
|
698
|
-
end
|
699
|
-
end
|
700
|
-
end
|
701
|
-
|
702
|
-
describe "MSSQL optimistic locking plugin" do
|
703
|
-
before do
|
704
|
-
@db = DB
|
705
|
-
@db.create_table! :items do
|
706
|
-
primary_key :id
|
707
|
-
String :name, :size => 20
|
708
|
-
column :timestamp, 'timestamp'
|
709
|
-
end
|
710
|
-
end
|
711
|
-
after do
|
712
|
-
@db.drop_table?(:items)
|
713
|
-
end
|
714
|
-
|
715
|
-
it "should not allow stale updates" do
|
716
|
-
c = Class.new(Sequel::Model(:items))
|
717
|
-
c.plugin :mssql_optimistic_locking
|
718
|
-
o = c.create(:name=>'test')
|
719
|
-
o2 = c.first
|
720
|
-
ts = o.timestamp
|
721
|
-
ts.wont_equal nil
|
722
|
-
o.name = 'test2'
|
723
|
-
o.save
|
724
|
-
o.timestamp.wont_equal ts
|
725
|
-
proc{o2.save}.must_raise(Sequel::NoExistingObject)
|
726
|
-
end
|
727
|
-
end unless DB.adapter_scheme == :odbc
|
728
|
-
|
729
|
-
describe "MSSQL Stored Procedure support" do
|
730
|
-
before do
|
731
|
-
@db = DB
|
732
|
-
@now = DateTime.now.to_s
|
733
|
-
@db.execute('CREATE PROCEDURE dbo.SequelTest
|
734
|
-
(@Input varchar(25), @IntegerInput int, @Output varchar(25) OUTPUT, @IntegerOutput int OUTPUT) AS
|
735
|
-
BEGIN SET @Output = @Input SET @IntegerOutput = @IntegerInput RETURN @IntegerInput END')
|
736
|
-
end
|
737
|
-
after do
|
738
|
-
@db.execute('DROP PROCEDURE dbo.SequelTest')
|
739
|
-
end
|
740
|
-
|
741
|
-
describe "with unnamed parameters" do
|
742
|
-
it "should return a hash of output variables" do
|
743
|
-
r = @db.call_mssql_sproc(:SequelTest, {:args => [@now, 1, :output, :output]})
|
744
|
-
r.must_be_kind_of(Hash)
|
745
|
-
r.values_at(:var2, :var3).must_equal [@now, '1']
|
746
|
-
end
|
747
|
-
|
748
|
-
it "should support typed output variables" do
|
749
|
-
@db.call_mssql_sproc(:SequelTest, {:args => [@now, 1, :output, [:output, 'int']]})[:var3].must_equal 1
|
750
|
-
end
|
751
|
-
|
752
|
-
it "should support named output variables" do
|
753
|
-
@db.call_mssql_sproc(:SequelTest, {:args => [@now, 1, [:output, nil, 'output'], :output]})[:output].must_equal @now
|
754
|
-
end
|
755
|
-
|
756
|
-
it "should return the number of Affected Rows" do
|
757
|
-
@db.call_mssql_sproc(:SequelTest, {:args => [@now, 1, :output, :output]})[:numrows].must_equal 1
|
758
|
-
end
|
759
|
-
|
760
|
-
it "should return the Result Code" do
|
761
|
-
@db.call_mssql_sproc(:SequelTest, {:args => [@now, 1, :output, :output]})[:result].must_equal 1
|
762
|
-
end
|
763
|
-
end
|
764
|
-
|
765
|
-
describe "with named parameters" do
|
766
|
-
it "should return a hash of output variables" do
|
767
|
-
r = @db.call_mssql_sproc(:SequelTest, :args => {
|
768
|
-
'Input' => @now,
|
769
|
-
'IntegerInput' => 1,
|
770
|
-
'Output' => [:output, nil, 'output'],
|
771
|
-
'IntegerOutput' => [:output, nil, 'integer_output']
|
772
|
-
})
|
773
|
-
r.must_be_kind_of(Hash)
|
774
|
-
r.values_at(:output, :integer_output).must_equal [@now, '1']
|
775
|
-
end
|
776
|
-
|
777
|
-
it "should support typed output variables" do
|
778
|
-
@db.call_mssql_sproc(:SequelTest, :args => {
|
779
|
-
'Input' => @now,
|
780
|
-
'IntegerInput' => 1,
|
781
|
-
'Output' => [:output, nil, 'output'],
|
782
|
-
'IntegerOutput' => [:output, 'int', 'integer_output']
|
783
|
-
})[:integer_output].must_equal 1
|
784
|
-
end
|
785
|
-
|
786
|
-
it "should return the number of Affected Rows" do
|
787
|
-
@db.call_mssql_sproc(:SequelTest, :args => {
|
788
|
-
'Input' => @now,
|
789
|
-
'IntegerInput' => 1,
|
790
|
-
'Output' => [:output, nil, 'output'],
|
791
|
-
'IntegerOutput' => [:output, nil, 'integer_output']
|
792
|
-
})[:numrows].must_equal 1
|
793
|
-
end
|
794
|
-
|
795
|
-
it "should return the Result Code" do
|
796
|
-
@db.call_mssql_sproc(:SequelTest, :args => {
|
797
|
-
'Input' => @now,
|
798
|
-
'IntegerInput' => 1,
|
799
|
-
'Output' => [:output, nil, 'output'],
|
800
|
-
'IntegerOutput' => [:output, nil, 'integer_output']
|
801
|
-
})[:result].must_equal 1
|
802
|
-
end
|
803
|
-
end
|
804
|
-
end unless DB.adapter_scheme == :odbc
|