sequel 5.29.0 → 5.30.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +8 -1922
- data/doc/release_notes/5.30.0.txt +20 -0
- data/lib/sequel/adapters/shared/sqlite.rb +7 -1
- data/lib/sequel/database/transactions.rb +5 -9
- data/lib/sequel/version.rb +1 -1
- metadata +4 -368
- 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 -828
- data/spec/adapters/mysql_spec.rb +0 -1060
- data/spec/adapters/oracle_spec.rb +0 -371
- data/spec/adapters/postgres_spec.rb +0 -4476
- 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 -2915
- data/spec/core/dataset_spec.rb +0 -5544
- data/spec/core/deprecated_spec.rb +0 -70
- data/spec/core/expression_filters_spec.rb +0 -1498
- 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 -1844
- 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/any_not_empty_spec.rb +0 -23
- data/spec/extensions/arbitrary_servers_spec.rb +0 -109
- data/spec/extensions/association_dependencies_spec.rb +0 -125
- data/spec/extensions/association_multi_add_remove_spec.rb +0 -1041
- 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 -222
- 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/empty_failure_backtraces_spec.rb +0 -60
- 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/exclude_or_null_spec.rb +0 -15
- 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_conflict_spec.rb +0 -103
- 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 -346
- 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 -218
- data/spec/extensions/nested_attributes_spec.rb +0 -815
- 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 -209
- 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 -356
- data/spec/extensions/pg_json_spec.rb +0 -451
- 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 -600
- 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 -387
- 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 -135
- data/spec/extensions/server_logging_spec.rb +0 -45
- data/spec/extensions/sharding_spec.rb +0 -197
- 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 -70
- 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_cache_spec.rb +0 -35
- 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 -2037
- 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 -2423
- data/spec/integration/prepared_statement_test.rb +0 -405
- data/spec/integration/schema_test.rb +0 -903
- data/spec/integration/spec_helper.rb +0 -71
- 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 -5
- data/spec/spec_config.rb +0 -12
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'logger'
|
2
|
-
require_relative "../sequel_warning"
|
3
|
-
|
4
|
-
if ENV['COVERAGE']
|
5
|
-
require_relative "../sequel_coverage"
|
6
|
-
SimpleCov.sequel_coverage(:group=>%r{lib/sequel/adapters})
|
7
|
-
end
|
8
|
-
|
9
|
-
$:.unshift(File.join(File.dirname(File.expand_path(__FILE__)), "../../lib/"))
|
10
|
-
require_relative "../../lib/sequel"
|
11
|
-
|
12
|
-
begin
|
13
|
-
require_relative "../spec_config"
|
14
|
-
rescue LoadError
|
15
|
-
end
|
16
|
-
|
17
|
-
Sequel::DB = nil
|
18
|
-
Sequel.split_symbols = true if ENV['SEQUEL_SPLIT_SYMBOLS']
|
19
|
-
Sequel::Database.extension :duplicate_column_handler if ENV['SEQUEL_DUPLICATE_COLUMN_HANDLER']
|
20
|
-
Sequel::Database.extension :columns_introspection if ENV['SEQUEL_COLUMNS_INTROSPECTION']
|
21
|
-
Sequel::Model.cache_associations = false if ENV['SEQUEL_NO_CACHE_ASSOCIATIONS']
|
22
|
-
Sequel::Model.plugin :prepared_statements if ENV['SEQUEL_MODEL_PREPARED_STATEMENTS']
|
23
|
-
Sequel::Model.plugin :throw_failures if ENV['SEQUEL_MODEL_THROW_FAILURES']
|
24
|
-
Sequel::Model.cache_anonymous_models = false
|
25
|
-
|
26
|
-
require_relative '../guards_helper'
|
27
|
-
|
28
|
-
unless defined?(DB)
|
29
|
-
env_var = "SEQUEL_#{SEQUEL_ADAPTER_TEST.to_s.upcase}_URL"
|
30
|
-
env_var = ENV.has_key?(env_var) ? env_var : 'SEQUEL_INTEGRATION_URL'
|
31
|
-
DB = Sequel.connect(ENV[env_var])
|
32
|
-
end
|
33
|
-
|
34
|
-
IDENTIFIER_MANGLING = !!ENV['SEQUEL_IDENTIFIER_MANGLING'] unless defined?(IDENTIFIER_MANGLING)
|
35
|
-
DB.extension(:identifier_mangling) if IDENTIFIER_MANGLING
|
36
|
-
|
37
|
-
DB.extension :pg_timestamptz if ENV['SEQUEL_PG_TIMESTAMPTZ']
|
38
|
-
DB.extension :integer64 if ENV['SEQUEL_INTEGER64']
|
39
|
-
DB.extension :index_caching if ENV['SEQUEL_INDEX_CACHING']
|
40
|
-
|
41
|
-
if dch = ENV['SEQUEL_DUPLICATE_COLUMNS_HANDLER']
|
42
|
-
DB.extension :duplicate_columns_handler
|
43
|
-
DB.opts[:on_duplicate_columns] = dch.to_sym unless dch.empty?
|
44
|
-
end
|
@@ -1,97 +0,0 @@
|
|
1
|
-
SEQUEL_ADAPTER_TEST = :sqlanywhere
|
2
|
-
|
3
|
-
require_relative 'spec_helper'
|
4
|
-
|
5
|
-
describe "convert_smallint_to_bool" do
|
6
|
-
before do
|
7
|
-
@db = DB
|
8
|
-
@ds = @db[:booltest]
|
9
|
-
end
|
10
|
-
after do
|
11
|
-
@db.convert_smallint_to_bool = true
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "Database#convert_smallint_to_bool" do
|
15
|
-
before do
|
16
|
-
@db.create_table!(:booltest){column :b, 'smallint'; column :i, 'integer'}
|
17
|
-
end
|
18
|
-
after do
|
19
|
-
@db.drop_table(:booltest)
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should consider smallint datatypes as boolean if set, but not larger smallints" do
|
23
|
-
@db.schema(:booltest, :reload=>true).first.last[:type].must_equal :boolean
|
24
|
-
@db.schema(:booltest, :reload=>true).first.last[:db_type].must_match /smallint/i
|
25
|
-
@db.convert_smallint_to_bool = false
|
26
|
-
@db.schema(:booltest, :reload=>true).first.last[:type].must_equal :integer
|
27
|
-
@db.schema(:booltest, :reload=>true).first.last[:db_type].must_match /smallint/i
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should return smallints as bools and integers as integers when set" do
|
31
|
-
@ds.delete
|
32
|
-
@ds.insert(:b=>true, :i=>10)
|
33
|
-
@ds.all.must_equal [{:b=>true, :i=>10}]
|
34
|
-
@ds.delete
|
35
|
-
@ds.insert(:b=>false, :i=>0)
|
36
|
-
@ds.all.must_equal [{:b=>false, :i=>0}]
|
37
|
-
@ds.delete
|
38
|
-
@ds.insert(:b=>true, :i=>1)
|
39
|
-
@ds.all.must_equal [{:b=>true, :i=>1}]
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should return all smallints as integers when unset" do
|
43
|
-
@db.convert_smallint_to_bool = false
|
44
|
-
@ds.delete
|
45
|
-
@ds.insert(:b=>true, :i=>10)
|
46
|
-
@ds.all.must_equal [{:b=>1, :i=>10}]
|
47
|
-
@ds.delete
|
48
|
-
@ds.insert(:b=>false, :i=>0)
|
49
|
-
@ds.all.must_equal [{:b=>0, :i=>0}]
|
50
|
-
|
51
|
-
@ds.delete
|
52
|
-
@ds.insert(:b=>1, :i=>10)
|
53
|
-
@ds.all.must_equal [{:b=>1, :i=>10}]
|
54
|
-
@ds.delete
|
55
|
-
@ds.insert(:b=>0, :i=>0)
|
56
|
-
@ds.all.must_equal [{:b=>0, :i=>0}]
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe "Dataset#convert_smallint_to_bool" do
|
61
|
-
before do
|
62
|
-
@db.create_table!(:booltest){column :b, 'smallint'; column :i, 'integer'}
|
63
|
-
end
|
64
|
-
after do
|
65
|
-
@db.drop_table(:booltest)
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should return smallints as bools and integers as integers when set" do
|
69
|
-
@ds.delete
|
70
|
-
@ds.insert(:b=>true, :i=>10)
|
71
|
-
@ds.all.must_equal [{:b=>true, :i=>10}]
|
72
|
-
@ds.delete
|
73
|
-
@ds.insert(:b=>false, :i=>0)
|
74
|
-
@ds.all.must_equal [{:b=>false, :i=>0}]
|
75
|
-
@ds.delete
|
76
|
-
@ds.insert(:b=>true, :i=>1)
|
77
|
-
@ds.all.must_equal [{:b=>true, :i=>1}]
|
78
|
-
end
|
79
|
-
|
80
|
-
it "should support with_convert_smallint_to_bool for returning modified dataset with setting changed" do
|
81
|
-
@ds = @ds.with_convert_smallint_to_bool(false)
|
82
|
-
@ds.delete
|
83
|
-
@ds.insert(:b=>true, :i=>10)
|
84
|
-
@ds.all.must_equal [{:b=>1, :i=>10}]
|
85
|
-
@ds.delete
|
86
|
-
@ds.insert(:b=>false, :i=>0)
|
87
|
-
@ds.all.must_equal [{:b=>0, :i=>0}]
|
88
|
-
|
89
|
-
@ds.delete
|
90
|
-
@ds.insert(:b=>1, :i=>10)
|
91
|
-
@ds.all.must_equal [{:b=>1, :i=>10}]
|
92
|
-
@ds.delete
|
93
|
-
@ds.insert(:b=>0, :i=>0)
|
94
|
-
@ds.all.must_equal [{:b=>0, :i=>0}]
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
@@ -1,652 +0,0 @@
|
|
1
|
-
SEQUEL_ADAPTER_TEST = :sqlite
|
2
|
-
|
3
|
-
require_relative 'spec_helper'
|
4
|
-
|
5
|
-
describe "An SQLite database" do
|
6
|
-
before do
|
7
|
-
@db = DB
|
8
|
-
end
|
9
|
-
after do
|
10
|
-
@db.drop_table?(:fk)
|
11
|
-
@db.use_timestamp_timezones = false
|
12
|
-
Sequel.datetime_class = Time
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should support casting to Date by using the date function" do
|
16
|
-
@db.get(Sequel.cast('2012-10-20 11:12:13', Date)).must_equal '2012-10-20'
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should support casting to Time or DateTime by using the datetime function" do
|
20
|
-
@db.get(Sequel.cast('2012-10-20', Time)).must_equal '2012-10-20 00:00:00'
|
21
|
-
@db.get(Sequel.cast('2012-10-20', DateTime)).must_equal '2012-10-20 00:00:00'
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should provide the SQLite version as an integer" do
|
25
|
-
@db.sqlite_version.must_be_kind_of(Integer)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should support a use_timestamp_timezones setting" do
|
29
|
-
@db.use_timestamp_timezones = true
|
30
|
-
@db.create_table!(:fk){Time :time}
|
31
|
-
@db[:fk].insert(Time.now)
|
32
|
-
@db[:fk].get(Sequel.cast(:time, String)).must_match(/[-+]\d\d\d\d\z/)
|
33
|
-
@db.use_timestamp_timezones = false
|
34
|
-
@db[:fk].delete
|
35
|
-
@db[:fk].insert(Time.now)
|
36
|
-
@db[:fk].get(Sequel.cast(:time, String)).wont_match(/[-+]\d\d\d\d\z/)
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should provide a list of existing tables" do
|
40
|
-
@db.drop_table?(:fk)
|
41
|
-
@db.tables.must_be_kind_of(Array)
|
42
|
-
@db.tables.wont_include(:fk)
|
43
|
-
@db.create_table!(:fk){String :name}
|
44
|
-
@db.tables.must_include(:fk)
|
45
|
-
end
|
46
|
-
|
47
|
-
cspecify "should support timestamps and datetimes and respect datetime_class", [:jdbc] do
|
48
|
-
@db.create_table!(:fk){timestamp :t; datetime :d}
|
49
|
-
@db.use_timestamp_timezones = true
|
50
|
-
t1 = Time.at(1)
|
51
|
-
@db[:fk].insert(:t => t1, :d => t1)
|
52
|
-
@db[:fk].map(:t).must_equal [t1]
|
53
|
-
@db[:fk].map(:d).must_equal [t1]
|
54
|
-
Sequel.datetime_class = DateTime
|
55
|
-
t2 = Sequel.string_to_datetime(t1.iso8601)
|
56
|
-
@db[:fk].map(:t).must_equal [t2]
|
57
|
-
@db[:fk].map(:d).must_equal [t2]
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should support sequential primary keys" do
|
61
|
-
@db.create_table!(:fk) {primary_key :id; text :name}
|
62
|
-
@db[:fk].insert(:name => 'abc')
|
63
|
-
@db[:fk].insert(:name => 'def')
|
64
|
-
@db[:fk].insert(:name => 'ghi')
|
65
|
-
@db[:fk].order(:name).all.must_equal [
|
66
|
-
{:id => 1, :name => 'abc'},
|
67
|
-
{:id => 2, :name => 'def'},
|
68
|
-
{:id => 3, :name => 'ghi'}
|
69
|
-
]
|
70
|
-
end
|
71
|
-
|
72
|
-
it "should correctly parse the schema" do
|
73
|
-
@db.create_table!(:fk) {timestamp :t}
|
74
|
-
@db.schema(:fk, :reload=>true).must_equal [[:t, {:type=>:datetime, :allow_null=>true, :default=>nil, :ruby_default=>nil, :db_type=>"timestamp", :primary_key=>false}]]
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should handle and return BigDecimal values for numeric columns" do
|
78
|
-
DB.create_table!(:fk){numeric :d}
|
79
|
-
d = DB[:fk]
|
80
|
-
d.insert(:d=>BigDecimal('80.0'))
|
81
|
-
d.insert(:d=>BigDecimal('NaN'))
|
82
|
-
d.insert(:d=>BigDecimal('Infinity'))
|
83
|
-
d.insert(:d=>BigDecimal('-Infinity'))
|
84
|
-
ds = d.all
|
85
|
-
ds.shift.must_equal(:d=>BigDecimal('80.0'))
|
86
|
-
ds.map{|x| x[:d].to_s}.must_equal %w'NaN Infinity -Infinity'
|
87
|
-
DB
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
describe "SQLite temporary views" do
|
92
|
-
before do
|
93
|
-
@db = DB
|
94
|
-
@db.drop_view(:items) rescue nil
|
95
|
-
@db.create_table!(:items){Integer :number}
|
96
|
-
@db[:items].insert(10)
|
97
|
-
@db[:items].insert(20)
|
98
|
-
end
|
99
|
-
after do
|
100
|
-
@db.drop_table?(:items)
|
101
|
-
end
|
102
|
-
|
103
|
-
it "should be supported" do
|
104
|
-
@db.create_view(:items_view, @db[:items].where(:number=>10), :temp=>true)
|
105
|
-
@db[:items_view].map(:number).must_equal [10]
|
106
|
-
@db.disconnect
|
107
|
-
lambda{@db[:items_view].map(:number)}.must_raise(Sequel::DatabaseError)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
describe "SQLite VALUES support" do
|
112
|
-
before do
|
113
|
-
@db = DB
|
114
|
-
end
|
115
|
-
|
116
|
-
it "should create a dataset using the VALUES clause via #values" do
|
117
|
-
@db.values([[1, 2], [3, 4]]).map([:column1, :column2]).must_equal [[1, 2], [3, 4]]
|
118
|
-
end
|
119
|
-
|
120
|
-
it "should support VALUES with unions" do
|
121
|
-
@db.values([[1]]).union(@db.values([[3]])).map(&:values).map(&:first).must_equal [1, 3]
|
122
|
-
end
|
123
|
-
|
124
|
-
it "should support VALUES in CTEs" do
|
125
|
-
@db[:a].cross_join(:b).with(:a, @db.values([[1, 2]]), :args=>[:c1, :c2]).with(:b, @db.values([[3, 4]]), :args=>[:c3, :c4]).map([:c1, :c2, :c3, :c4]).must_equal [[1, 2, 3, 4]]
|
126
|
-
end
|
127
|
-
end if DB.sqlite_version >= 30803
|
128
|
-
|
129
|
-
describe "SQLite type conversion" do
|
130
|
-
before do
|
131
|
-
@db = DB
|
132
|
-
@integer_booleans = @db.integer_booleans
|
133
|
-
@db.integer_booleans = true
|
134
|
-
@ds = @db[:items]
|
135
|
-
@db.drop_table?(:items)
|
136
|
-
end
|
137
|
-
after do
|
138
|
-
@db.integer_booleans = @integer_booleans
|
139
|
-
Sequel.datetime_class = Time
|
140
|
-
@db.drop_table?(:items)
|
141
|
-
end
|
142
|
-
|
143
|
-
it "should handle integers in boolean columns" do
|
144
|
-
@db.create_table(:items){TrueClass :a}
|
145
|
-
@db[:items].insert(false)
|
146
|
-
@db[:items].select_map(:a).must_equal [false]
|
147
|
-
@db[:items].select_map(Sequel.expr(:a)+:a).must_equal [0]
|
148
|
-
@db[:items].update(:a=>true)
|
149
|
-
@db[:items].select_map(:a).must_equal [true]
|
150
|
-
@db[:items].select_map(Sequel.expr(:a)+:a).must_equal [2]
|
151
|
-
end
|
152
|
-
|
153
|
-
it "should handle integers/floats/strings/decimals in numeric/decimal columns" do
|
154
|
-
@db.create_table(:items){Numeric :a}
|
155
|
-
@db[:items].insert(100)
|
156
|
-
@db[:items].select_map(:a).must_equal [BigDecimal('100')]
|
157
|
-
@db[:items].get(:a).must_be_kind_of(BigDecimal)
|
158
|
-
|
159
|
-
@db[:items].update(:a=>100.1)
|
160
|
-
@db[:items].select_map(:a).must_equal [BigDecimal('100.1')]
|
161
|
-
@db[:items].get(:a).must_be_kind_of(BigDecimal)
|
162
|
-
|
163
|
-
@db[:items].update(:a=>'100.1')
|
164
|
-
@db[:items].select_map(:a).must_equal [BigDecimal('100.1')]
|
165
|
-
@db[:items].get(:a).must_be_kind_of(BigDecimal)
|
166
|
-
|
167
|
-
@db[:items].update(:a=>BigDecimal('100.1'))
|
168
|
-
@db[:items].select_map(:a).must_equal [BigDecimal('100.1')]
|
169
|
-
@db[:items].get(:a).must_be_kind_of(BigDecimal)
|
170
|
-
end
|
171
|
-
|
172
|
-
it "should handle integer/float date columns as julian date" do
|
173
|
-
@db.create_table(:items){Date :a}
|
174
|
-
i = 2455979
|
175
|
-
@db[:items].insert(i)
|
176
|
-
@db[:items].first.must_equal(:a=>Date.jd(i))
|
177
|
-
@db[:items].update(:a=>2455979.1)
|
178
|
-
@db[:items].first.must_equal(:a=>Date.jd(i))
|
179
|
-
end
|
180
|
-
|
181
|
-
it "should handle integer/float time columns as seconds" do
|
182
|
-
@db.create_table(:items){Time :a, :only_time=>true}
|
183
|
-
@db[:items].insert(3661)
|
184
|
-
@db[:items].first.must_equal(:a=>Sequel::SQLTime.create(1, 1, 1))
|
185
|
-
@db[:items].update(:a=>3661.000001)
|
186
|
-
@db[:items].first.must_equal(:a=>Sequel::SQLTime.create(1, 1, 1, 1))
|
187
|
-
end
|
188
|
-
|
189
|
-
it "should handle integer datetime columns as unix timestamp" do
|
190
|
-
@db.create_table(:items){DateTime :a}
|
191
|
-
i = 1329860756
|
192
|
-
@db[:items].insert(i)
|
193
|
-
@db[:items].first.must_equal(:a=>Time.at(i))
|
194
|
-
Sequel.datetime_class = DateTime
|
195
|
-
@db[:items].first.must_equal(:a=>DateTime.strptime(i.to_s, '%s'))
|
196
|
-
end
|
197
|
-
|
198
|
-
it "should handle float datetime columns as julian date" do
|
199
|
-
@db.create_table(:items){DateTime :a}
|
200
|
-
i = 2455979.5
|
201
|
-
@db[:items].insert(i)
|
202
|
-
@db[:items].first.must_equal(:a=>Time.at(1329825600))
|
203
|
-
Sequel.datetime_class = DateTime
|
204
|
-
@db[:items].first.must_equal(:a=>DateTime.jd(2455979.5))
|
205
|
-
end
|
206
|
-
|
207
|
-
it "should handle integer/float blob columns" do
|
208
|
-
@db.create_table(:items){File :a}
|
209
|
-
@db[:items].insert(1)
|
210
|
-
@db[:items].first.must_equal(:a=>Sequel::SQL::Blob.new('1'))
|
211
|
-
@db[:items].update(:a=>'1.1')
|
212
|
-
@db[:items].first.must_equal(:a=>Sequel::SQL::Blob.new(1.1.to_s))
|
213
|
-
end
|
214
|
-
end if DB.adapter_scheme == :sqlite
|
215
|
-
|
216
|
-
describe "An SQLite dataset" do
|
217
|
-
before do
|
218
|
-
@d = DB.dataset
|
219
|
-
end
|
220
|
-
|
221
|
-
it "should raise errors if given a regexp pattern match" do
|
222
|
-
proc{@d.literal(Sequel.expr(:x).like(/a/))}.must_raise(Sequel::InvalidOperation)
|
223
|
-
proc{@d.literal(~Sequel.expr(:x).like(/a/))}.must_raise(Sequel::InvalidOperation)
|
224
|
-
proc{@d.literal(Sequel.expr(:x).like(/a/i))}.must_raise(Sequel::InvalidOperation)
|
225
|
-
proc{@d.literal(~Sequel.expr(:x).like(/a/i))}.must_raise(Sequel::InvalidOperation)
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
describe "SQLite::Dataset#delete" do
|
230
|
-
before do
|
231
|
-
DB.create_table! :items do
|
232
|
-
primary_key :id
|
233
|
-
String :name
|
234
|
-
Float :value
|
235
|
-
end
|
236
|
-
@d = DB[:items]
|
237
|
-
@d.delete # remove all records
|
238
|
-
@d.insert(:name => 'abc', :value => 1.23)
|
239
|
-
@d.insert(:name => 'def', :value => 4.56)
|
240
|
-
@d.insert(:name => 'ghi', :value => 7.89)
|
241
|
-
end
|
242
|
-
after do
|
243
|
-
DB.drop_table?(:items)
|
244
|
-
end
|
245
|
-
|
246
|
-
it "should return the number of records affected when filtered" do
|
247
|
-
@d.count.must_equal 3
|
248
|
-
@d.filter{value < 3}.delete.must_equal 1
|
249
|
-
@d.count.must_equal 2
|
250
|
-
|
251
|
-
@d.filter{value < 3}.delete.must_equal 0
|
252
|
-
@d.count.must_equal 2
|
253
|
-
end
|
254
|
-
|
255
|
-
it "should return the number of records affected when unfiltered" do
|
256
|
-
@d.count.must_equal 3
|
257
|
-
@d.delete.must_equal 3
|
258
|
-
@d.count.must_equal 0
|
259
|
-
|
260
|
-
@d.delete.must_equal 0
|
261
|
-
end
|
262
|
-
end
|
263
|
-
|
264
|
-
describe "SQLite::Dataset#update" do
|
265
|
-
before do
|
266
|
-
DB.create_table! :items do
|
267
|
-
primary_key :id
|
268
|
-
String :name
|
269
|
-
Float :value
|
270
|
-
end
|
271
|
-
@d = DB[:items]
|
272
|
-
@d.delete # remove all records
|
273
|
-
@d.insert(:name => 'abc', :value => 1.23)
|
274
|
-
@d.insert(:name => 'def', :value => 4.56)
|
275
|
-
@d.insert(:name => 'ghi', :value => 7.89)
|
276
|
-
end
|
277
|
-
|
278
|
-
it "should return the number of records affected" do
|
279
|
-
@d.filter(:name => 'abc').update(:value => 2).must_equal 1
|
280
|
-
|
281
|
-
@d.update(:value => 10).must_equal 3
|
282
|
-
|
283
|
-
@d.filter(:name => 'xxx').update(:value => 23).must_equal 0
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
|
-
describe "SQLite::Dataset#insert_conflict" do
|
288
|
-
before(:all) do
|
289
|
-
DB.create_table! :ic_test do
|
290
|
-
primary_key :id
|
291
|
-
String :name
|
292
|
-
end
|
293
|
-
end
|
294
|
-
|
295
|
-
after(:each) do
|
296
|
-
DB[:ic_test].delete
|
297
|
-
end
|
298
|
-
|
299
|
-
after(:all) do
|
300
|
-
DB.drop_table?(:ic_test)
|
301
|
-
end
|
302
|
-
|
303
|
-
it "Dataset#insert_ignore and insert_constraint should ignore uniqueness violations" do
|
304
|
-
DB[:ic_test].insert(:id => 1, :name => "one")
|
305
|
-
proc {DB[:ic_test].insert(:id => 1, :name => "one")}.must_raise Sequel::ConstraintViolation
|
306
|
-
|
307
|
-
DB[:ic_test].insert_ignore.insert(:id => 1, :name => "one")
|
308
|
-
DB[:ic_test].all.must_equal([{:id => 1, :name => "one"}])
|
309
|
-
|
310
|
-
DB[:ic_test].insert_conflict(:ignore).insert(:id => 1, :name => "one")
|
311
|
-
DB[:ic_test].all.must_equal([{:id => 1, :name => "one"}])
|
312
|
-
end
|
313
|
-
|
314
|
-
it "Dataset#insert_constraint should handle replacement" do
|
315
|
-
DB[:ic_test].insert(:id => 1, :name => "one")
|
316
|
-
|
317
|
-
DB[:ic_test].insert_conflict(:replace).insert(:id => 1, :name => "two")
|
318
|
-
DB[:ic_test].all.must_equal([{:id => 1, :name => "two"}])
|
319
|
-
end
|
320
|
-
end
|
321
|
-
|
322
|
-
describe "SQLite dataset" do
|
323
|
-
before do
|
324
|
-
DB.create_table! :test do
|
325
|
-
primary_key :id
|
326
|
-
String :name
|
327
|
-
Float :value
|
328
|
-
end
|
329
|
-
DB.create_table! :items do
|
330
|
-
primary_key :id
|
331
|
-
String :name
|
332
|
-
Float :value
|
333
|
-
end
|
334
|
-
@d = DB[:items]
|
335
|
-
@d.insert(:name => 'abc', :value => 1.23)
|
336
|
-
@d.insert(:name => 'def', :value => 4.56)
|
337
|
-
@d.insert(:name => 'ghi', :value => 7.89)
|
338
|
-
end
|
339
|
-
after do
|
340
|
-
DB.drop_table?(:test, :items)
|
341
|
-
end
|
342
|
-
|
343
|
-
it "should be able to insert from a subquery" do
|
344
|
-
DB[:test].insert(@d)
|
345
|
-
DB[:test].count.must_equal 3
|
346
|
-
DB[:test].select(:name, :value).order(:value).to_a.must_equal \
|
347
|
-
@d.select(:name, :value).order(:value).to_a
|
348
|
-
end
|
349
|
-
|
350
|
-
it "should support #explain" do
|
351
|
-
DB[:test].explain.must_be_kind_of(String)
|
352
|
-
end
|
353
|
-
|
354
|
-
it "should have #explain work when identifier_output_method is modified" do
|
355
|
-
DB[:test].with_identifier_output_method(:upcase).explain.must_be_kind_of(String)
|
356
|
-
end if IDENTIFIER_MANGLING
|
357
|
-
end
|
358
|
-
|
359
|
-
describe "A SQLite database" do
|
360
|
-
before do
|
361
|
-
@db = DB
|
362
|
-
@db.create_table! :test2 do
|
363
|
-
text :name
|
364
|
-
integer :value
|
365
|
-
end
|
366
|
-
end
|
367
|
-
after do
|
368
|
-
@db.drop_table?(:test, :test2, :test3, :test3_backup0, :test3_backup1, :test3_backup2)
|
369
|
-
end
|
370
|
-
|
371
|
-
it "should support add_column operations" do
|
372
|
-
@db.add_column :test2, :xyz, :text
|
373
|
-
|
374
|
-
@db[:test2].columns.must_equal [:name, :value, :xyz]
|
375
|
-
@db[:test2].insert(:name => 'mmm', :value => 111, :xyz=>'000')
|
376
|
-
@db[:test2].first.must_equal(:name => 'mmm', :value => 111, :xyz=>'000')
|
377
|
-
end
|
378
|
-
|
379
|
-
it "should support drop_column operations" do
|
380
|
-
@db.drop_column :test2, :value
|
381
|
-
@db[:test2].columns.must_equal [:name]
|
382
|
-
@db[:test2].insert(:name => 'mmm')
|
383
|
-
@db[:test2].first.must_equal(:name => 'mmm')
|
384
|
-
end
|
385
|
-
|
386
|
-
it "should support drop_column operations in a transaction" do
|
387
|
-
@db.transaction{@db.drop_column :test2, :value}
|
388
|
-
@db[:test2].columns.must_equal [:name]
|
389
|
-
@db[:test2].insert(:name => 'mmm')
|
390
|
-
@db[:test2].first.must_equal(:name => 'mmm')
|
391
|
-
end
|
392
|
-
|
393
|
-
it "should keep a composite primary key when dropping columns" do
|
394
|
-
@db.create_table!(:test2){Integer :a; Integer :b; Integer :c; primary_key [:a, :b]}
|
395
|
-
@db.drop_column :test2, :c
|
396
|
-
@db[:test2].columns.must_equal [:a, :b]
|
397
|
-
@db[:test2].insert(:a=>1, :b=>2)
|
398
|
-
@db[:test2].insert(:a=>2, :b=>3)
|
399
|
-
proc{@db[:test2].insert(:a=>2, :b=>3)}.must_raise(Sequel::UniqueConstraintViolation, Sequel::ConstraintViolation, Sequel::DatabaseError)
|
400
|
-
end
|
401
|
-
|
402
|
-
it "should keep column attributes when dropping a column" do
|
403
|
-
@db.create_table! :test3 do
|
404
|
-
primary_key :id
|
405
|
-
text :name
|
406
|
-
integer :value
|
407
|
-
end
|
408
|
-
|
409
|
-
# This lame set of additions and deletions are to test that the primary keys
|
410
|
-
# don't get messed up when we recreate the database.
|
411
|
-
@db[:test3].insert( :name => "foo", :value => 1)
|
412
|
-
@db[:test3].insert( :name => "foo", :value => 2)
|
413
|
-
@db[:test3].insert( :name => "foo", :value => 3)
|
414
|
-
@db[:test3].filter(:id => 2).delete
|
415
|
-
|
416
|
-
@db.drop_column :test3, :value
|
417
|
-
|
418
|
-
@db['PRAGMA table_info(?)', :test3][:id][:pk].to_i.must_equal 1
|
419
|
-
@db[:test3].select(:id).all.must_equal [{:id => 1}, {:id => 3}]
|
420
|
-
end
|
421
|
-
|
422
|
-
it "should keep foreign keys when dropping a column" do
|
423
|
-
@db.create_table! :test do
|
424
|
-
primary_key :id
|
425
|
-
String :name
|
426
|
-
Integer :value
|
427
|
-
end
|
428
|
-
@db.create_table! :test3 do
|
429
|
-
String :name
|
430
|
-
Integer :value
|
431
|
-
foreign_key :test_id, :test, :on_delete => :set_null, :on_update => :cascade
|
432
|
-
end
|
433
|
-
|
434
|
-
@db[:test3].insert(:name => "abc", :test_id => @db[:test].insert(:name => "foo", :value => 3))
|
435
|
-
@db[:test3].insert(:name => "def", :test_id => @db[:test].insert(:name => "bar", :value => 4))
|
436
|
-
|
437
|
-
@db.drop_column :test3, :value
|
438
|
-
|
439
|
-
@db[:test].filter(:name => 'bar').delete
|
440
|
-
@db[:test3][:name => 'def'][:test_id].must_be_nil
|
441
|
-
|
442
|
-
@db[:test].filter(:name => 'foo').update(:id=>100)
|
443
|
-
@db[:test3][:name => 'abc'][:test_id].must_equal 100
|
444
|
-
end
|
445
|
-
|
446
|
-
it "should support rename_column operations" do
|
447
|
-
@db[:test2].delete
|
448
|
-
@db.add_column :test2, :xyz, :text
|
449
|
-
@db[:test2].insert(:name => 'mmm', :value => 111, :xyz => 'qqqq')
|
450
|
-
|
451
|
-
@db[:test2].columns.must_equal [:name, :value, :xyz]
|
452
|
-
@db.rename_column :test2, :xyz, :zyx, :type => :text
|
453
|
-
@db[:test2].columns.must_equal [:name, :value, :zyx]
|
454
|
-
@db[:test2].first[:zyx].must_equal 'qqqq'
|
455
|
-
@db[:test2].count.must_equal 1
|
456
|
-
end
|
457
|
-
|
458
|
-
it "should preserve defaults when dropping or renaming columns" do
|
459
|
-
@db.create_table! :test3 do
|
460
|
-
String :s, :default=>'a'
|
461
|
-
Integer :i
|
462
|
-
end
|
463
|
-
|
464
|
-
@db[:test3].insert
|
465
|
-
@db[:test3].first[:s].must_equal 'a'
|
466
|
-
@db[:test3].delete
|
467
|
-
@db.drop_column :test3, :i
|
468
|
-
@db[:test3].insert
|
469
|
-
@db[:test3].first[:s].must_equal 'a'
|
470
|
-
@db[:test3].delete
|
471
|
-
@db.rename_column :test3, :s, :t
|
472
|
-
@db[:test3].insert
|
473
|
-
@db[:test3].first[:t].must_equal 'a'
|
474
|
-
@db[:test3].delete
|
475
|
-
end
|
476
|
-
|
477
|
-
|
478
|
-
it "should preserve autoincrement after table modification" do
|
479
|
-
@db.create_table!(:test2) do
|
480
|
-
primary_key :id
|
481
|
-
Integer :val, :null => false
|
482
|
-
end
|
483
|
-
@db.rename_column(:test2, :val, :value)
|
484
|
-
|
485
|
-
t = @db[:test2]
|
486
|
-
id1 = t.insert(:value=>1)
|
487
|
-
t.delete
|
488
|
-
id2 = t.insert(:value=>1)
|
489
|
-
id2.must_be :>, id1
|
490
|
-
end
|
491
|
-
|
492
|
-
it "should handle quoted tables when dropping or renaming columns" do
|
493
|
-
table_name = "T T"
|
494
|
-
@db.drop_table?(table_name)
|
495
|
-
@db.create_table! table_name do
|
496
|
-
Integer :"s s"
|
497
|
-
Integer :"i i"
|
498
|
-
end
|
499
|
-
|
500
|
-
@db.from(table_name).insert(:"s s"=>1, :"i i"=>2)
|
501
|
-
@db.from(table_name).all.must_equal [{:"s s"=>1, :"i i"=>2}]
|
502
|
-
@db.drop_column table_name, :"i i"
|
503
|
-
@db.from(table_name).all.must_equal [{:"s s"=>1}]
|
504
|
-
@db.rename_column table_name, :"s s", :"t t"
|
505
|
-
@db.from(table_name).all.must_equal [{:"t t"=>1}]
|
506
|
-
@db.drop_table?(table_name)
|
507
|
-
end
|
508
|
-
|
509
|
-
it "should choose a temporary table name that isn't already used when dropping or renaming columns" do
|
510
|
-
@db.tables.each{|t| @db.drop_table(t) if t.to_s =~ /test3/}
|
511
|
-
@db.create_table :test3 do
|
512
|
-
Integer :h
|
513
|
-
Integer :i
|
514
|
-
end
|
515
|
-
@db.create_table :test3_backup0 do
|
516
|
-
Integer :j
|
517
|
-
end
|
518
|
-
@db.create_table :test3_backup1 do
|
519
|
-
Integer :k
|
520
|
-
end
|
521
|
-
|
522
|
-
@db[:test3].columns.must_equal [:h, :i]
|
523
|
-
@db[:test3_backup0].columns.must_equal [:j]
|
524
|
-
@db[:test3_backup1].columns.must_equal [:k]
|
525
|
-
@db.drop_column(:test3, :i)
|
526
|
-
@db[:test3].columns.must_equal [:h]
|
527
|
-
@db[:test3_backup0].columns.must_equal [:j]
|
528
|
-
@db[:test3_backup1].columns.must_equal [:k]
|
529
|
-
|
530
|
-
@db.create_table :test3_backup2 do
|
531
|
-
Integer :l
|
532
|
-
end
|
533
|
-
|
534
|
-
@db.rename_column(:test3, :h, :i)
|
535
|
-
@db[:test3].columns.must_equal [:i]
|
536
|
-
@db[:test3_backup0].columns.must_equal [:j]
|
537
|
-
@db[:test3_backup1].columns.must_equal [:k]
|
538
|
-
@db[:test3_backup2].columns.must_equal [:l]
|
539
|
-
end
|
540
|
-
|
541
|
-
it "should support add_index" do
|
542
|
-
@db.add_index :test2, :value, :unique => true
|
543
|
-
@db.add_index :test2, [:name, :value]
|
544
|
-
end
|
545
|
-
|
546
|
-
it "should support drop_index" do
|
547
|
-
@db.add_index :test2, :value, :unique => true
|
548
|
-
@db.drop_index :test2, :value
|
549
|
-
end
|
550
|
-
|
551
|
-
it "should keep applicable indexes when emulating schema methods" do
|
552
|
-
@db.create_table!(:test3){Integer :a; Integer :b}
|
553
|
-
@db.add_index :test3, :a
|
554
|
-
@db.add_index :test3, :b
|
555
|
-
@db.add_index :test3, [:b, :a]
|
556
|
-
@db.drop_column :test3, :b
|
557
|
-
@db.indexes(:test3)[:test3_a_index].must_equal(:unique=>false, :columns=>[:a])
|
558
|
-
end
|
559
|
-
|
560
|
-
it "should have support for various #transaction modes" do
|
561
|
-
@db.transaction(:mode => :immediate){}
|
562
|
-
@db.transaction(:mode => :exclusive){}
|
563
|
-
@db.transaction(:mode => :deferred){}
|
564
|
-
@db.transaction{}
|
565
|
-
|
566
|
-
@db.transaction_mode.must_be_nil
|
567
|
-
@db.transaction_mode = :immediate
|
568
|
-
@db.transaction_mode.must_equal :immediate
|
569
|
-
@db.transaction{}
|
570
|
-
@db.transaction(:mode => :exclusive){}
|
571
|
-
proc {@db.transaction_mode = :invalid}.must_raise(Sequel::Error)
|
572
|
-
@db.transaction_mode.must_equal :immediate
|
573
|
-
proc {@db.transaction(:mode => :invalid) {}}.must_raise(Sequel::Error)
|
574
|
-
end
|
575
|
-
|
576
|
-
it "should keep unique constraints when copying tables" do
|
577
|
-
@db.alter_table(:test2){add_unique_constraint :name}
|
578
|
-
@db.alter_table(:test2){drop_column :value}
|
579
|
-
@db[:test2].insert(:name=>'a')
|
580
|
-
proc{@db[:test2].insert(:name=>'a')}.must_raise(Sequel::ConstraintViolation, Sequel::UniqueConstraintViolation)
|
581
|
-
end
|
582
|
-
|
583
|
-
it "should not ignore adding new constraints when adding not null constraints" do
|
584
|
-
@db.alter_table :test2 do
|
585
|
-
set_column_not_null :value
|
586
|
-
add_constraint(:value_range1, :value => 3..5)
|
587
|
-
add_constraint(:value_range2, :value => 0..9)
|
588
|
-
end
|
589
|
-
|
590
|
-
@db[:test2].insert(:value => 4)
|
591
|
-
proc{@db[:test2].insert(:value => 1)}.must_raise(Sequel::ConstraintViolation)
|
592
|
-
proc{@db[:test2].insert(:value => nil)}.must_raise(Sequel::ConstraintViolation)
|
593
|
-
@db[:test2].select_order_map(:value).must_equal [4]
|
594
|
-
end
|
595
|
-
|
596
|
-
it "should show unique constraints in Database#indexes" do
|
597
|
-
@db.alter_table(:test2){add_unique_constraint :name}
|
598
|
-
@db.indexes(:test2).values.first[:columns].must_equal [:name]
|
599
|
-
end if DB.sqlite_version >= 30808
|
600
|
-
end
|
601
|
-
|
602
|
-
describe "SQLite", 'INSERT ON CONFLICT' do
|
603
|
-
before(:all) do
|
604
|
-
@db = DB
|
605
|
-
@db.create_table!(:ic_test){Integer :a; Integer :b; Integer :c; TrueClass :c_is_unique, :default=>false; unique :a, :name=>:ic_test_a_uidx; unique [:b, :c], :name=>:ic_test_b_c_uidx; index [:c], :where=>:c_is_unique, :unique=>true}
|
606
|
-
@ds = @db[:ic_test]
|
607
|
-
end
|
608
|
-
before do
|
609
|
-
@ds.delete
|
610
|
-
end
|
611
|
-
after(:all) do
|
612
|
-
@db.drop_table?(:ic_test)
|
613
|
-
end
|
614
|
-
|
615
|
-
it "Dataset#insert_ignore and insert_conflict should ignore uniqueness violations" do
|
616
|
-
@ds.insert(1, 2, 3, false)
|
617
|
-
@ds.insert(10, 11, 3, true)
|
618
|
-
proc{@ds.insert(1, 3, 4, false)}.must_raise Sequel::UniqueConstraintViolation
|
619
|
-
proc{@ds.insert(11, 12, 3, true)}.must_raise Sequel::UniqueConstraintViolation
|
620
|
-
@ds.insert_ignore.insert(1, 3, 4, false)
|
621
|
-
@ds.insert_conflict.insert(1, 3, 4, false)
|
622
|
-
@ds.insert_conflict.insert(11, 12, 3, true)
|
623
|
-
@ds.insert_conflict(:target=>:a).insert(1, 3, 4, false)
|
624
|
-
@ds.insert_conflict(:target=>:c, :conflict_where=>:c_is_unique).insert(11, 12, 3, true)
|
625
|
-
@ds.all.must_equal [{:a=>1, :b=>2, :c=>3, :c_is_unique=>false}, {:a=>10, :b=>11, :c=>3, :c_is_unique=>true}]
|
626
|
-
end unless DB.adapter_scheme == :amalgalite
|
627
|
-
|
628
|
-
it "Dataset#insert_ignore and insert_conflict should work with multi_insert/import" do
|
629
|
-
@ds.insert(1, 2, 3, false)
|
630
|
-
@ds.insert_ignore.multi_insert([{:a=>1, :b=>3, :c=>4}])
|
631
|
-
@ds.insert_ignore.import([:a, :b, :c], [[1, 3, 4]])
|
632
|
-
@ds.all.must_equal [{:a=>1, :b=>2, :c=>3, :c_is_unique=>false}]
|
633
|
-
@ds.insert_conflict(:target=>:a, :update=>{:b=>3}).import([:a, :b, :c], [[1, 3, 4]])
|
634
|
-
@ds.all.must_equal [{:a=>1, :b=>3, :c=>3, :c_is_unique=>false}]
|
635
|
-
@ds.insert_conflict(:target=>:a, :update=>{:b=>4}).multi_insert([{:a=>1, :b=>5, :c=>6}])
|
636
|
-
@ds.all.must_equal [{:a=>1, :b=>4, :c=>3, :c_is_unique=>false}]
|
637
|
-
end
|
638
|
-
|
639
|
-
it "Dataset#insert_conflict should handle upserts" do
|
640
|
-
@ds.insert(1, 2, 3, false)
|
641
|
-
@ds.insert_conflict(:target=>:a, :update=>{:b=>3}).insert(1, 3, 4, false)
|
642
|
-
@ds.all.must_equal [{:a=>1, :b=>3, :c=>3, :c_is_unique=>false}]
|
643
|
-
@ds.insert_conflict(:target=>[:b, :c], :update=>{:c=>5}).insert(5, 3, 3, false)
|
644
|
-
@ds.all.must_equal [{:a=>1, :b=>3, :c=>5, :c_is_unique=>false}]
|
645
|
-
@ds.insert_conflict(:target=>:a, :update=>{:b=>4}).insert(1, 3, nil, false)
|
646
|
-
@ds.all.must_equal [{:a=>1, :b=>4, :c=>5, :c_is_unique=>false}]
|
647
|
-
@ds.insert_conflict(:target=>:a, :update=>{:b=>5}, :update_where=>{Sequel[:ic_test][:b]=>4}).insert(1, 3, 4, false)
|
648
|
-
@ds.all.must_equal [{:a=>1, :b=>5, :c=>5, :c_is_unique=>false}]
|
649
|
-
@ds.insert_conflict(:target=>:a, :update=>{:b=>6}, :update_where=>{Sequel[:ic_test][:b]=>4}).insert(1, 3, 4, false)
|
650
|
-
@ds.all.must_equal [{:a=>1, :b=>5, :c=>5, :c_is_unique=>false}]
|
651
|
-
end
|
652
|
-
end if DB.sqlite_version >= 32400
|