sequel 4.46.0 → 4.49.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (228) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +210 -0
  3. data/Rakefile +1 -1
  4. data/doc/advanced_associations.rdoc +1 -1
  5. data/doc/opening_databases.rdoc +3 -2
  6. data/doc/release_notes/4.47.0.txt +56 -0
  7. data/doc/release_notes/4.48.0.txt +293 -0
  8. data/doc/release_notes/4.49.0.txt +222 -0
  9. data/lib/sequel/adapters/ado/access.rb +2 -1
  10. data/lib/sequel/adapters/do/postgres.rb +5 -2
  11. data/lib/sequel/adapters/ibmdb.rb +30 -8
  12. data/lib/sequel/adapters/jdbc/as400.rb +1 -1
  13. data/lib/sequel/adapters/jdbc/db2.rb +12 -3
  14. data/lib/sequel/adapters/jdbc/derby.rb +4 -5
  15. data/lib/sequel/adapters/jdbc/h2.rb +10 -1
  16. data/lib/sequel/adapters/jdbc/oracle.rb +16 -2
  17. data/lib/sequel/adapters/jdbc/postgresql.rb +46 -20
  18. data/lib/sequel/adapters/jdbc/sqlanywhere.rb +9 -7
  19. data/lib/sequel/adapters/jdbc/sqlserver.rb +20 -6
  20. data/lib/sequel/adapters/jdbc.rb +39 -23
  21. data/lib/sequel/adapters/mock.rb +27 -19
  22. data/lib/sequel/adapters/mysql.rb +17 -16
  23. data/lib/sequel/adapters/mysql2.rb +5 -6
  24. data/lib/sequel/adapters/oracle.rb +5 -9
  25. data/lib/sequel/adapters/postgres.rb +91 -103
  26. data/lib/sequel/adapters/shared/db2.rb +22 -6
  27. data/lib/sequel/adapters/shared/mssql.rb +5 -4
  28. data/lib/sequel/adapters/shared/mysql.rb +79 -25
  29. data/lib/sequel/adapters/shared/oracle.rb +26 -3
  30. data/lib/sequel/adapters/shared/postgres.rb +199 -95
  31. data/lib/sequel/adapters/shared/sqlanywhere.rb +23 -10
  32. data/lib/sequel/adapters/shared/sqlite.rb +72 -82
  33. data/lib/sequel/adapters/sqlanywhere.rb +4 -1
  34. data/lib/sequel/adapters/sqlite.rb +5 -3
  35. data/lib/sequel/adapters/swift/postgres.rb +5 -2
  36. data/lib/sequel/adapters/tinytds.rb +0 -5
  37. data/lib/sequel/adapters/utils/mysql_mysql2.rb +1 -1
  38. data/lib/sequel/adapters/utils/pg_types.rb +2 -76
  39. data/lib/sequel/ast_transformer.rb +1 -1
  40. data/lib/sequel/connection_pool/sharded_single.rb +1 -1
  41. data/lib/sequel/connection_pool/sharded_threaded.rb +1 -1
  42. data/lib/sequel/connection_pool/single.rb +2 -2
  43. data/lib/sequel/connection_pool/threaded.rb +2 -2
  44. data/lib/sequel/connection_pool.rb +9 -2
  45. data/lib/sequel/core.rb +2 -2
  46. data/lib/sequel/database/connecting.rb +8 -8
  47. data/lib/sequel/database/dataset.rb +6 -3
  48. data/lib/sequel/database/dataset_defaults.rb +14 -1
  49. data/lib/sequel/database/misc.rb +1 -1
  50. data/lib/sequel/database/query.rb +3 -0
  51. data/lib/sequel/database/schema_methods.rb +1 -1
  52. data/lib/sequel/dataset/actions.rb +72 -10
  53. data/lib/sequel/dataset/dataset_module.rb +58 -0
  54. data/lib/sequel/dataset/graph.rb +1 -1
  55. data/lib/sequel/dataset/misc.rb +1 -0
  56. data/lib/sequel/dataset/prepared_statements.rb +3 -3
  57. data/lib/sequel/dataset/query.rb +22 -11
  58. data/lib/sequel/dataset.rb +1 -1
  59. data/lib/sequel/exceptions.rb +8 -0
  60. data/lib/sequel/extensions/_model_pg_row.rb +5 -2
  61. data/lib/sequel/extensions/core_extensions.rb +4 -1
  62. data/lib/sequel/extensions/current_datetime_timestamp.rb +2 -1
  63. data/lib/sequel/extensions/date_arithmetic.rb +1 -0
  64. data/lib/sequel/extensions/duplicate_columns_handler.rb +3 -3
  65. data/lib/sequel/extensions/empty_array_ignore_nulls.rb +3 -0
  66. data/lib/sequel/extensions/filter_having.rb +2 -0
  67. data/lib/sequel/extensions/freeze_datasets.rb +2 -0
  68. data/lib/sequel/extensions/from_block.rb +1 -1
  69. data/lib/sequel/extensions/graph_each.rb +2 -2
  70. data/lib/sequel/extensions/hash_aliases.rb +2 -0
  71. data/lib/sequel/extensions/identifier_mangling.rb +0 -7
  72. data/lib/sequel/extensions/meta_def.rb +2 -0
  73. data/lib/sequel/extensions/migration.rb +11 -8
  74. data/lib/sequel/extensions/no_auto_literal_strings.rb +1 -1
  75. data/lib/sequel/extensions/null_dataset.rb +1 -0
  76. data/lib/sequel/extensions/pagination.rb +1 -1
  77. data/lib/sequel/extensions/pg_array.rb +207 -130
  78. data/lib/sequel/extensions/pg_hstore.rb +38 -20
  79. data/lib/sequel/extensions/pg_inet.rb +18 -6
  80. data/lib/sequel/extensions/pg_interval.rb +19 -12
  81. data/lib/sequel/extensions/pg_json.rb +25 -14
  82. data/lib/sequel/extensions/pg_json_ops.rb +2 -2
  83. data/lib/sequel/extensions/pg_range.rb +133 -100
  84. data/lib/sequel/extensions/pg_range_ops.rb +4 -3
  85. data/lib/sequel/extensions/pg_row.rb +68 -39
  86. data/lib/sequel/extensions/pg_row_ops.rb +11 -5
  87. data/lib/sequel/extensions/query_literals.rb +2 -0
  88. data/lib/sequel/extensions/ruby18_symbol_extensions.rb +2 -0
  89. data/lib/sequel/extensions/s.rb +1 -1
  90. data/lib/sequel/extensions/schema_dumper.rb +29 -25
  91. data/lib/sequel/extensions/sequel_3_dataset_methods.rb +3 -1
  92. data/lib/sequel/extensions/sequel_4_dataset_methods.rb +83 -0
  93. data/lib/sequel/extensions/server_block.rb +32 -15
  94. data/lib/sequel/extensions/set_overrides.rb +2 -2
  95. data/lib/sequel/extensions/string_agg.rb +0 -1
  96. data/lib/sequel/extensions/symbol_aref.rb +0 -4
  97. data/lib/sequel/model/associations.rb +35 -7
  98. data/lib/sequel/model/base.rb +113 -87
  99. data/lib/sequel/model/dataset_module.rb +5 -43
  100. data/lib/sequel/model/errors.rb +2 -1
  101. data/lib/sequel/model/inflections.rb +17 -5
  102. data/lib/sequel/model.rb +26 -58
  103. data/lib/sequel/plugins/active_model.rb +2 -2
  104. data/lib/sequel/plugins/association_autoreloading.rb +2 -0
  105. data/lib/sequel/plugins/association_dependencies.rb +3 -3
  106. data/lib/sequel/plugins/association_pks.rb +73 -46
  107. data/lib/sequel/plugins/association_proxies.rb +1 -1
  108. data/lib/sequel/plugins/auto_validations.rb +6 -2
  109. data/lib/sequel/plugins/boolean_readers.rb +2 -2
  110. data/lib/sequel/plugins/boolean_subsets.rb +1 -1
  111. data/lib/sequel/plugins/caching.rb +19 -13
  112. data/lib/sequel/plugins/class_table_inheritance.rb +24 -13
  113. data/lib/sequel/plugins/column_conflicts.rb +7 -2
  114. data/lib/sequel/plugins/column_select.rb +3 -3
  115. data/lib/sequel/plugins/composition.rb +2 -2
  116. data/lib/sequel/plugins/csv_serializer.rb +8 -8
  117. data/lib/sequel/plugins/dataset_associations.rb +25 -13
  118. data/lib/sequel/plugins/defaults_setter.rb +13 -1
  119. data/lib/sequel/plugins/eager_each.rb +1 -1
  120. data/lib/sequel/plugins/force_encoding.rb +2 -2
  121. data/lib/sequel/plugins/hook_class_methods.rb +9 -12
  122. data/lib/sequel/plugins/identifier_columns.rb +2 -0
  123. data/lib/sequel/plugins/instance_filters.rb +3 -1
  124. data/lib/sequel/plugins/instance_hooks.rb +17 -9
  125. data/lib/sequel/plugins/json_serializer.rb +19 -12
  126. data/lib/sequel/plugins/lazy_attributes.rb +8 -7
  127. data/lib/sequel/plugins/many_to_one_pk_lookup.rb +2 -0
  128. data/lib/sequel/plugins/modification_detection.rb +3 -0
  129. data/lib/sequel/plugins/nested_attributes.rb +6 -2
  130. data/lib/sequel/plugins/pg_array_associations.rb +5 -0
  131. data/lib/sequel/plugins/pg_row.rb +4 -2
  132. data/lib/sequel/plugins/pg_typecast_on_load.rb +2 -0
  133. data/lib/sequel/plugins/prepared_statements.rb +1 -0
  134. data/lib/sequel/plugins/rcte_tree.rb +4 -24
  135. data/lib/sequel/plugins/serialization.rb +9 -15
  136. data/lib/sequel/plugins/single_table_inheritance.rb +8 -3
  137. data/lib/sequel/plugins/split_values.rb +6 -5
  138. data/lib/sequel/plugins/static_cache.rb +31 -25
  139. data/lib/sequel/plugins/subset_conditions.rb +3 -1
  140. data/lib/sequel/plugins/table_select.rb +1 -1
  141. data/lib/sequel/plugins/touch.rb +4 -2
  142. data/lib/sequel/plugins/validation_class_methods.rb +5 -6
  143. data/lib/sequel/plugins/validation_helpers.rb +14 -8
  144. data/lib/sequel/plugins/xml_serializer.rb +4 -4
  145. data/lib/sequel/sql.rb +18 -9
  146. data/lib/sequel/version.rb +1 -1
  147. data/spec/adapters/db2_spec.rb +115 -14
  148. data/spec/adapters/mssql_spec.rb +4 -4
  149. data/spec/adapters/mysql_spec.rb +83 -29
  150. data/spec/adapters/oracle_spec.rb +28 -24
  151. data/spec/adapters/postgres_spec.rb +40 -24
  152. data/spec/adapters/sqlanywhere_spec.rb +88 -86
  153. data/spec/adapters/sqlite_spec.rb +29 -24
  154. data/spec/bin_spec.rb +7 -1
  155. data/spec/core/connection_pool_spec.rb +45 -14
  156. data/spec/core/database_spec.rb +155 -0
  157. data/spec/core/dataset_spec.rb +219 -36
  158. data/spec/core/schema_spec.rb +16 -0
  159. data/spec/core/spec_helper.rb +1 -0
  160. data/spec/core_extensions_spec.rb +6 -2
  161. data/spec/extensions/active_model_spec.rb +1 -1
  162. data/spec/extensions/arbitrary_servers_spec.rb +1 -1
  163. data/spec/extensions/association_pks_spec.rb +34 -2
  164. data/spec/extensions/auto_literal_strings_spec.rb +5 -1
  165. data/spec/extensions/auto_validations_spec.rb +2 -0
  166. data/spec/extensions/boolean_readers_spec.rb +1 -1
  167. data/spec/extensions/boolean_subsets_spec.rb +1 -1
  168. data/spec/extensions/class_table_inheritance_spec.rb +106 -19
  169. data/spec/extensions/column_conflicts_spec.rb +11 -0
  170. data/spec/extensions/column_select_spec.rb +1 -0
  171. data/spec/extensions/composition_spec.rb +13 -0
  172. data/spec/extensions/connection_validator_spec.rb +1 -1
  173. data/spec/extensions/dataset_associations_spec.rb +20 -8
  174. data/spec/extensions/defaults_setter_spec.rb +15 -1
  175. data/spec/extensions/filter_having_spec.rb +5 -3
  176. data/spec/extensions/hash_aliases_spec.rb +3 -1
  177. data/spec/extensions/identifier_columns_spec.rb +3 -1
  178. data/spec/extensions/implicit_subquery_spec.rb +4 -2
  179. data/spec/extensions/json_serializer_spec.rb +18 -0
  180. data/spec/extensions/lazy_attributes_spec.rb +3 -3
  181. data/spec/extensions/many_through_many_spec.rb +4 -4
  182. data/spec/extensions/meta_def_spec.rb +9 -0
  183. data/spec/extensions/migration_spec.rb +3 -3
  184. data/spec/extensions/nested_attributes_spec.rb +14 -3
  185. data/spec/extensions/no_auto_literal_strings_spec.rb +8 -4
  186. data/spec/extensions/null_dataset_spec.rb +1 -1
  187. data/spec/extensions/pg_array_associations_spec.rb +29 -18
  188. data/spec/extensions/pg_array_spec.rb +44 -25
  189. data/spec/extensions/pg_hstore_spec.rb +10 -0
  190. data/spec/extensions/pg_inet_spec.rb +26 -0
  191. data/spec/extensions/pg_interval_spec.rb +20 -0
  192. data/spec/extensions/pg_json_spec.rb +24 -0
  193. data/spec/extensions/pg_range_spec.rb +98 -14
  194. data/spec/extensions/pg_row_spec.rb +14 -4
  195. data/spec/extensions/pg_typecast_on_load_spec.rb +11 -9
  196. data/spec/extensions/prepared_statements_safe_spec.rb +1 -1
  197. data/spec/extensions/query_literals_spec.rb +3 -1
  198. data/spec/extensions/schema_dumper_spec.rb +108 -94
  199. data/spec/extensions/sequel_3_dataset_methods_spec.rb +10 -6
  200. data/spec/extensions/sequel_4_dataset_methods_spec.rb +121 -0
  201. data/spec/extensions/serialization_spec.rb +1 -1
  202. data/spec/extensions/server_block_spec.rb +7 -0
  203. data/spec/extensions/single_table_inheritance_spec.rb +17 -1
  204. data/spec/extensions/spec_helper.rb +7 -1
  205. data/spec/extensions/static_cache_spec.rb +75 -24
  206. data/spec/extensions/string_agg_spec.rb +1 -1
  207. data/spec/extensions/touch_spec.rb +9 -0
  208. data/spec/extensions/validation_helpers_spec.rb +10 -5
  209. data/spec/extensions/whitelist_security_spec.rb +26 -0
  210. data/spec/integration/associations_test.rb +8 -0
  211. data/spec/integration/dataset_test.rb +45 -44
  212. data/spec/integration/model_test.rb +53 -4
  213. data/spec/integration/plugin_test.rb +28 -4
  214. data/spec/integration/prepared_statement_test.rb +3 -0
  215. data/spec/integration/schema_test.rb +21 -1
  216. data/spec/integration/transaction_test.rb +40 -40
  217. data/spec/model/association_reflection_spec.rb +43 -1
  218. data/spec/model/associations_spec.rb +29 -9
  219. data/spec/model/class_dataset_methods_spec.rb +20 -4
  220. data/spec/model/dataset_methods_spec.rb +12 -3
  221. data/spec/model/eager_loading_spec.rb +8 -8
  222. data/spec/model/model_spec.rb +45 -1
  223. data/spec/model/plugins_spec.rb +34 -0
  224. data/spec/model/record_spec.rb +1 -1
  225. data/spec/spec_config.rb +2 -0
  226. metadata +11 -4
  227. data/spec/adapters/firebird_spec.rb +0 -405
  228. data/spec/adapters/informix_spec.rb +0 -100
@@ -4,6 +4,7 @@ require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper.rb')
4
4
 
5
5
  uses_pg = Sequel::Postgres::USES_PG if DB.adapter_scheme == :postgres
6
6
  uses_pg_or_jdbc = uses_pg || DB.adapter_scheme == :jdbc
7
+ # SEQUEL5: Remove native handling
7
8
 
8
9
  def DB.sqls
9
10
  (@sqls ||= [])
@@ -168,6 +169,8 @@ describe "PostgreSQL views" do
168
169
  @db[:items_view].select_order_map(:number).must_equal [10, 20]
169
170
  @db.refresh_view(:items_view)
170
171
  @db[:items_view].select_order_map(:number).must_equal [10, 15, 20]
172
+ @db.views.wont_include :items_view
173
+ @db.views(@opts).must_include :items_view
171
174
  end if DB.server_version >= 90300
172
175
 
173
176
  it "should support refreshing materialized views concurrently" do
@@ -443,16 +446,16 @@ describe "A PostgreSQL dataset" do
443
446
  end
444
447
 
445
448
  it "should support regexps" do
446
- @d << {:name => 'abc', :value => 1}
447
- @d << {:name => 'bcd', :value => 2}
449
+ @d.insert(:name => 'abc', :value => 1)
450
+ @d.insert(:name => 'bcd', :value => 2)
448
451
  @d.filter(:name => /bc/).count.must_equal 2
449
452
  @d.filter(:name => /^bc/).count.must_equal 1
450
453
  end
451
454
 
452
455
  it "should support NULLS FIRST and NULLS LAST" do
453
- @d << {:name => 'abc'}
454
- @d << {:name => 'bcd'}
455
- @d << {:name => 'bcd', :value => 2}
456
+ @d.insert(:name => 'abc')
457
+ @d.insert(:name => 'bcd')
458
+ @d.insert(:name => 'bcd', :value => 2)
456
459
  @d.order(Sequel.asc(:value, :nulls=>:first), :name).select_map(:name).must_equal %w[abc bcd bcd]
457
460
  @d.order(Sequel.asc(:value, :nulls=>:last), :name).select_map(:name).must_equal %w[bcd abc bcd]
458
461
  @d.order(Sequel.asc(:value, :nulls=>:first), :name).reverse.select_map(:name).must_equal %w[bcd bcd abc]
@@ -679,12 +682,12 @@ describe "A PostgreSQL dataset" do
679
682
  end
680
683
 
681
684
  it "should truncate with options" do
682
- @d << { :name => 'abc', :value => 1}
685
+ @d.insert( :name => 'abc', :value => 1)
683
686
  @d.count.must_equal 1
684
687
  @d.truncate(:cascade => true)
685
688
  @d.count.must_equal 0
686
689
  if @d.db.server_version > 80400
687
- @d << { :name => 'abc', :value => 1}
690
+ @d.insert( :name => 'abc', :value => 1)
688
691
  @d.truncate(:cascade => true, :only=>true, :restart=>true)
689
692
  @d.count.must_equal 0
690
693
  end
@@ -800,7 +803,7 @@ describe "A PostgreSQL dataset with a timestamp field" do
800
803
 
801
804
  cspecify "should store milliseconds in time fields for Time objects", [:do], [:swift] do
802
805
  t = Time.now
803
- @d << {:time=>t}
806
+ @d.insert(:time=>t)
804
807
  t2 = @d.get(:time)
805
808
  @d.literal(t2).must_equal @d.literal(t)
806
809
  t2.strftime('%Y-%m-%d %H:%M:%S').must_equal t.strftime('%Y-%m-%d %H:%M:%S')
@@ -809,7 +812,7 @@ describe "A PostgreSQL dataset with a timestamp field" do
809
812
 
810
813
  cspecify "should store milliseconds in time fields for DateTime objects", [:do], [:swift] do
811
814
  t = DateTime.now
812
- @d << {:time=>t}
815
+ @d.insert(:time=>t)
813
816
  t2 = @d.get(:time)
814
817
  @d.literal(t2).must_equal @d.literal(t)
815
818
  t2.strftime('%Y-%m-%d %H:%M:%S').must_equal t.strftime('%Y-%m-%d %H:%M:%S')
@@ -818,7 +821,7 @@ describe "A PostgreSQL dataset with a timestamp field" do
818
821
 
819
822
  if DB.adapter_scheme == :postgres
820
823
  it "should handle infinite timestamps if convert_infinite_timestamps is set" do
821
- @d << {:time=>Sequel.cast('infinity', DateTime)}
824
+ @d.insert(:time=>Sequel.cast('infinity', DateTime))
822
825
  @db.convert_infinite_timestamps = :nil
823
826
  @db[:test3].get(:time).must_be_nil
824
827
  @db.convert_infinite_timestamps = :string
@@ -861,7 +864,7 @@ describe "A PostgreSQL dataset with a timestamp field" do
861
864
  end
862
865
 
863
866
  it "should handle infinite dates if convert_infinite_timestamps is set" do
864
- @d << {:date=>Sequel.cast('infinity', Date)}
867
+ @d.insert(:date=>Sequel.cast('infinity', Date))
865
868
  @db.convert_infinite_timestamps = :nil
866
869
  @db[:test3].get(:date).must_be_nil
867
870
  @db.convert_infinite_timestamps = :string
@@ -914,12 +917,12 @@ describe "A PostgreSQL database" do
914
917
 
915
918
  it "should support column operations" do
916
919
  @db.create_table!(:test2){text :name; integer :value}
917
- @db[:test2] << {}
920
+ @db[:test2].insert({})
918
921
  @db[:test2].columns.must_equal [:name, :value]
919
922
 
920
923
  @db.add_column :test2, :xyz, :text, :default => '000'
921
924
  @db[:test2].columns.must_equal [:name, :value, :xyz]
922
- @db[:test2] << {:name => 'mmm', :value => 111}
925
+ @db[:test2].insert(:name => 'mmm', :value => 111)
923
926
  @db[:test2].first[:xyz].must_equal '000'
924
927
 
925
928
  @db[:test2].columns.must_equal [:name, :value, :xyz]
@@ -929,7 +932,7 @@ describe "A PostgreSQL database" do
929
932
 
930
933
  @db[:test2].delete
931
934
  @db.add_column :test2, :xyz, :text, :default => '000'
932
- @db[:test2] << {:name => 'mmm', :value => 111, :xyz => 'qqqq'}
935
+ @db[:test2].insert(:name => 'mmm', :value => 111, :xyz => 'qqqq')
933
936
 
934
937
  @db[:test2].columns.must_equal [:name, :value, :xyz]
935
938
  @db.rename_column :test2, :xyz, :zyx
@@ -938,7 +941,7 @@ describe "A PostgreSQL database" do
938
941
 
939
942
  @db.add_column :test2, :xyz, :float
940
943
  @db[:test2].delete
941
- @db[:test2] << {:name => 'mmm', :value => 111, :xyz => 56.78}
944
+ @db[:test2].insert(:name => 'mmm', :value => 111, :xyz => 56.78)
942
945
  @db.set_column_type :test2, :xyz, :integer
943
946
 
944
947
  @db[:test2].first[:xyz].must_equal 57
@@ -1515,19 +1518,19 @@ if DB.server_version >= 80300
1515
1518
 
1516
1519
  it "should search by indexed column" do
1517
1520
  record = {:title => "oopsla conference", :body => "test"}
1518
- @ds << record
1521
+ @ds.insert(record)
1519
1522
  @ds.full_text_search(:title, "oopsla").all.must_include(record)
1520
1523
  end
1521
1524
 
1522
1525
  it "should join multiple coumns with spaces to search by last words in row" do
1523
1526
  record = {:title => "multiple words", :body => "are easy to search"}
1524
- @ds << record
1527
+ @ds.insert(record)
1525
1528
  @ds.full_text_search([:title, :body], "words").all.must_include(record)
1526
1529
  end
1527
1530
 
1528
1531
  it "should return rows with a NULL in one column if a match in another column" do
1529
1532
  record = {:title => "multiple words", :body =>nil}
1530
- @ds << record
1533
+ @ds.insert(record)
1531
1534
  @ds.full_text_search([:title, :body], "words").all.must_include(record)
1532
1535
  end
1533
1536
  end
@@ -1779,7 +1782,7 @@ if DB.adapter_scheme == :postgres
1779
1782
  before(:all) do
1780
1783
  deprecated do
1781
1784
  @db = DB
1782
- @old_cp = @db.conversion_procs[1013]
1785
+ @cp = @db.conversion_procs.dup
1783
1786
  @db.conversion_procs.delete(1013)
1784
1787
  Sequel::Postgres::PG_NAMED_TYPES[:oidvector] = lambda{|v| v.reverse}
1785
1788
  @db.reset_conversion_procs
@@ -1789,8 +1792,7 @@ if DB.adapter_scheme == :postgres
1789
1792
  after(:all) do
1790
1793
  deprecated do
1791
1794
  Sequel::Postgres::PG_NAMED_TYPES.delete(:oidvector)
1792
- @db.conversion_procs.delete(30)
1793
- @db.conversion_procs[1013] = @old_cp
1795
+ @db.conversion_procs.replace(@cp)
1794
1796
  @db.drop_table?(:foo)
1795
1797
  @db.drop_enum(:foo_enum) rescue nil
1796
1798
  end
@@ -1959,6 +1961,18 @@ if uses_pg_or_jdbc && DB.server_version >= 90000
1959
1961
  buf.must_equal ["1,2\n"]
1960
1962
  @db[:test_copy].select_order_map(:x).must_equal [1, 3]
1961
1963
  end
1964
+
1965
+ it "should not swallow error raised by block" do
1966
+ begin
1967
+ @db.copy_table(:test_copy){|b| raise ArgumentError, "foo"}
1968
+ rescue => e
1969
+ end
1970
+
1971
+ e.must_be_kind_of Sequel::DatabaseDisconnectError
1972
+ e.wrapped_exception.must_be_kind_of ArgumentError
1973
+ e.message.must_include "foo"
1974
+ end
1975
+
1962
1976
  end
1963
1977
  end
1964
1978
 
@@ -3373,7 +3387,7 @@ describe 'PostgreSQL interval types' do
3373
3387
  @native = DB.adapter_scheme == :postgres || DB.adapter_scheme == :jdbc
3374
3388
  end
3375
3389
  after(:all) do
3376
- Sequel::Postgres::PG_TYPES.delete(1186)
3390
+ Sequel::Postgres::PG__TYPES.delete(1186) # SEQUEL5: Remove
3377
3391
  end
3378
3392
  after do
3379
3393
  @db.drop_table?(:items)
@@ -3485,16 +3499,18 @@ describe 'PostgreSQL row-valued/composite types' do
3485
3499
  Integer :id
3486
3500
  column :employees, 'person[]'
3487
3501
  end
3502
+ oids = @db.conversion_procs.keys
3488
3503
  @db.register_row_type(:address)
3489
3504
  @db.register_row_type(Sequel.qualify(:public, :person))
3490
3505
  @db.register_row_type(Sequel[:public][:company])
3506
+ @new_oids = @db.conversion_procs.keys - oids
3491
3507
 
3492
3508
  @native = DB.adapter_scheme == :postgres || DB.adapter_scheme == :jdbc
3493
3509
  end
3494
3510
  after(:all) do
3495
- @db.drop_table?(:company, :person, :address)
3511
+ @new_oids.each{|oid| @db.conversion_procs.delete(oid)}
3496
3512
  @db.row_types.clear
3497
- @db.reset_conversion_procs if @native
3513
+ @db.drop_table?(:company, :person, :address)
3498
3514
  end
3499
3515
  after do
3500
3516
  [:company, :person, :address].each{|t| @db[t].delete}
@@ -6,73 +6,66 @@ if DB.table_exists?(:test)
6
6
  DB.drop_table(:test)
7
7
  end
8
8
 
9
- describe "Convert smallint to boolean" do
9
+ describe "convert_smallint_to_bool" do
10
10
  before do
11
11
  @db = DB
12
+ @ds = @db[:booltest]
13
+ @db.send(:remove_instance_variable, :@convert_smallint_to_bool) if @db.instance_variable_defined?(:@convert_smallint_to_bool)
12
14
  end
13
15
  after do
14
- Sequel::SqlAnywhere.convert_smallint_to_bool = true
15
- @db.convert_smallint_to_bool = true
16
+ deprecated do
17
+ Sequel::SqlAnywhere.convert_smallint_to_bool = true
18
+ end
19
+ @db.send(:remove_instance_variable, :@convert_smallint_to_bool) if @db.instance_variable_defined?(:@convert_smallint_to_bool)
16
20
  end
17
21
 
22
+ # SEQUEL5: Remove
18
23
  describe "Sequel::SqlAnywhere.convert_smallint_to_bool" do
19
24
  before do
20
25
  @db.create_table!(:booltest){column :b, 'smallint'; column :i, 'integer'}
21
- @ds = @db[:booltest]
22
26
  end
23
27
  after do
24
28
  @db.drop_table(:booltest)
25
29
  end
26
30
 
27
- it "should consider smallint datatypes as boolean if set, but if not, as larger smallints" do
31
+ deprecated "should consider smallint datatypes as boolean if set, but if not, as larger smallints" do
28
32
  @db.create_table!(:booltest){column :b, 'smallint'; column :i, 'integer'}
29
33
  @db.schema(:booltest, :reload=>true).first.last[:type].must_equal :boolean
30
34
  @db.schema(:booltest, :reload=>true).first.last[:db_type].must_match /smallint/i
31
35
 
32
36
  Sequel::SqlAnywhere.convert_smallint_to_bool = false
33
- @db2 = Sequel.connect(DB.url)
34
- @db2.schema(:booltest, :reload=>true).first.last[:type].must_equal :integer
35
- @db2.schema(:booltest, :reload=>true).first.last[:db_type].must_match /smallint/i
36
-
37
- @db.schema(:booltest, :reload=>true).first.last[:type].must_equal :boolean
37
+ @db.send(:remove_instance_variable, :@convert_smallint_to_bool) if @db.instance_variable_defined?(:@convert_smallint_to_bool)
38
+ @db.schema(:booltest, :reload=>true).first.last[:type].must_equal :integer
38
39
  @db.schema(:booltest, :reload=>true).first.last[:db_type].must_match /smallint/i
39
-
40
- @db2.disconnect
41
40
  end
42
41
 
43
- describe "datasets" do
44
- it "should return smallints as bools and integers as integers when set" do
45
- @ds.delete
46
- @ds << {:b=>true, :i=>10}
47
- @ds.all.must_equal [{:b=>true, :i=>10}]
48
- @ds.delete
49
- @ds << {:b=>false, :i=>0}
50
- @ds.all.must_equal [{:b=>false, :i=>0}]
51
- @ds.delete
52
- @ds << {:b=>true, :i=>1}
53
- @ds.all.must_equal [{:b=>true, :i=>1}]
54
- end
55
-
56
- it "should return all smallints as integers when unset" do
57
- Sequel::SqlAnywhere.convert_smallint_to_bool = false
58
- @db2 = Sequel.connect(DB.url)
59
- @ds2 = @db2[:booltest]
60
- @ds2.delete
61
- @ds2 << {:b=>true, :i=>10}
62
- @ds2.all.must_equal [{:b=>1, :i=>10}]
63
- @ds2.delete
64
- @ds2 << {:b=>false, :i=>0}
65
- @ds2.all.must_equal [{:b=>0, :i=>0}]
66
-
67
- @ds2.delete
68
- @ds2 << {:b=>1, :i=>10}
69
- @ds2.all.must_equal [{:b=>1, :i=>10}]
70
- @ds2.delete
71
- @ds2 << {:b=>0, :i=>0}
72
- @ds2.all.must_equal [{:b=>0, :i=>0}]
42
+ it "should return smallints as bools and integers as integers when set" do
43
+ @ds.delete
44
+ @ds.insert(:b=>true, :i=>10)
45
+ @ds.all.must_equal [{:b=>true, :i=>10}]
46
+ @ds.delete
47
+ @ds.insert(:b=>false, :i=>0)
48
+ @ds.all.must_equal [{:b=>false, :i=>0}]
49
+ @ds.delete
50
+ @ds.insert(:b=>true, :i=>1)
51
+ @ds.all.must_equal [{:b=>true, :i=>1}]
52
+ end
73
53
 
74
- @db2.disconnect
75
- end
54
+ deprecated "should return all smallints as integers when unset" do
55
+ Sequel::SqlAnywhere.convert_smallint_to_bool = false
56
+ @ds.delete
57
+ @ds.insert(:b=>true, :i=>10)
58
+ @ds.all.must_equal [{:b=>1, :i=>10}]
59
+ @ds.delete
60
+ @ds.insert(:b=>false, :i=>0)
61
+ @ds.all.must_equal [{:b=>0, :i=>0}]
62
+
63
+ @ds.delete
64
+ @ds.insert(:b=>1, :i=>10)
65
+ @ds.all.must_equal [{:b=>1, :i=>10}]
66
+ @ds.delete
67
+ @ds.insert(:b=>0, :i=>0)
68
+ @ds.all.must_equal [{:b=>0, :i=>0}]
76
69
  end
77
70
  end
78
71
 
@@ -92,47 +85,39 @@ describe "Convert smallint to boolean" do
92
85
  @db.schema(:booltest, :reload=>true).first.last[:db_type].must_match /smallint/i
93
86
  end
94
87
 
95
- describe "datasets" do
96
- it "should return smallints as bools and integers as integers when set" do
97
- @ds = @db[:booltest]
98
- @ds.delete
99
- @ds << {:b=>true, :i=>10}
100
- @ds.all.must_equal [{:b=>true, :i=>10}]
101
- @ds.delete
102
- @ds << {:b=>false, :i=>0}
103
- @ds.all.must_equal [{:b=>false, :i=>0}]
104
- @ds.delete
105
- @ds << {:b=>true, :i=>1}
106
- @ds.all.must_equal [{:b=>true, :i=>1}]
107
- end
108
-
109
- it "should return all smallints as integers when unset" do
110
- @db2 = Sequel.connect(DB.url)
111
- @db2.convert_smallint_to_bool = false
112
- @ds2 = @db2[:booltest]
113
- @ds2.delete
114
- @ds2 << {:b=>true, :i=>10}
115
- @ds2.all.must_equal [{:b=>1, :i=>10}]
116
- @ds2.delete
117
- @ds2 << {:b=>false, :i=>0}
118
- @ds2.all.must_equal [{:b=>0, :i=>0}]
119
-
120
- @ds2.delete
121
- @ds2 << {:b=>1, :i=>10}
122
- @ds2.all.must_equal [{:b=>1, :i=>10}]
123
- @ds2.delete
124
- @ds2 << {:b=>0, :i=>0}
125
- @ds2.all.must_equal [{:b=>0, :i=>0}]
88
+ it "should return smallints as bools and integers as integers when set" do
89
+ @ds.delete
90
+ @ds.insert(:b=>true, :i=>10)
91
+ @ds.all.must_equal [{:b=>true, :i=>10}]
92
+ @ds.delete
93
+ @ds.insert(:b=>false, :i=>0)
94
+ @ds.all.must_equal [{:b=>false, :i=>0}]
95
+ @ds.delete
96
+ @ds.insert(:b=>true, :i=>1)
97
+ @ds.all.must_equal [{:b=>true, :i=>1}]
98
+ end
126
99
 
127
- @db2.disconnect
128
- end
100
+ it "should return all smallints as integers when unset" do
101
+ @db.convert_smallint_to_bool = false
102
+ @ds.delete
103
+ @ds.insert(:b=>true, :i=>10)
104
+ @ds.all.must_equal [{:b=>1, :i=>10}]
105
+ @ds.delete
106
+ @ds.insert(:b=>false, :i=>0)
107
+ @ds.all.must_equal [{:b=>0, :i=>0}]
108
+
109
+ @ds.delete
110
+ @ds.insert(:b=>1, :i=>10)
111
+ @ds.all.must_equal [{:b=>1, :i=>10}]
112
+ @ds.delete
113
+ @ds.insert(:b=>0, :i=>0)
114
+ @ds.all.must_equal [{:b=>0, :i=>0}]
129
115
  end
130
116
  end
131
117
 
132
118
  describe "Dataset#convert_smallint_to_bool" do
133
119
  before do
134
120
  @db.create_table!(:booltest){column :b, 'smallint'; column :i, 'integer'}
135
- @ds = @db[:booltest]
136
121
  end
137
122
  after do
138
123
  @db.drop_table(:booltest)
@@ -140,30 +125,47 @@ describe "Convert smallint to boolean" do
140
125
 
141
126
  it "should return smallints as bools and integers as integers when set" do
142
127
  @ds.delete
143
- @ds << {:b=>true, :i=>10}
128
+ @ds.insert(:b=>true, :i=>10)
144
129
  @ds.all.must_equal [{:b=>true, :i=>10}]
145
130
  @ds.delete
146
- @ds << {:b=>false, :i=>0}
131
+ @ds.insert(:b=>false, :i=>0)
147
132
  @ds.all.must_equal [{:b=>false, :i=>0}]
148
133
  @ds.delete
149
- @ds << {:b=>true, :i=>1}
134
+ @ds.insert(:b=>true, :i=>1)
150
135
  @ds.all.must_equal [{:b=>true, :i=>1}]
151
136
  end
152
137
 
153
- it "should return all smallints as integers when unset" do
138
+ deprecated "should return all smallints as integers when unset" do
154
139
  @ds.convert_smallint_to_bool = false
155
140
  @ds.delete
156
- @ds << {:b=>true, :i=>10}
141
+ @ds.insert(:b=>true, :i=>10)
142
+ @ds.all.must_equal [{:b=>1, :i=>10}]
143
+ @ds.delete
144
+ @ds.insert(:b=>false, :i=>0)
145
+ @ds.all.must_equal [{:b=>0, :i=>0}]
146
+
147
+ @ds.delete
148
+ @ds.insert(:b=>1, :i=>10)
149
+ @ds.all.must_equal [{:b=>1, :i=>10}]
150
+ @ds.delete
151
+ @ds.insert(:b=>0, :i=>0)
152
+ @ds.all.must_equal [{:b=>0, :i=>0}]
153
+ end
154
+
155
+ it "should support with_convert_smallint_to_bool for returning modified dataset with setting changed" do
156
+ @ds = @ds.with_convert_smallint_to_bool(false)
157
+ @ds.delete
158
+ @ds.insert(:b=>true, :i=>10)
157
159
  @ds.all.must_equal [{:b=>1, :i=>10}]
158
160
  @ds.delete
159
- @ds << {:b=>false, :i=>0}
161
+ @ds.insert(:b=>false, :i=>0)
160
162
  @ds.all.must_equal [{:b=>0, :i=>0}]
161
163
 
162
164
  @ds.delete
163
- @ds << {:b=>1, :i=>10}
165
+ @ds.insert(:b=>1, :i=>10)
164
166
  @ds.all.must_equal [{:b=>1, :i=>10}]
165
167
  @ds.delete
166
- @ds << {:b=>0, :i=>0}
168
+ @ds.insert(:b=>0, :i=>0)
167
169
  @ds.all.must_equal [{:b=>0, :i=>0}]
168
170
  end
169
171
  end
@@ -134,7 +134,7 @@ describe "An SQLite database" do
134
134
  @db.create_table!(:fk){timestamp :t; datetime :d}
135
135
  @db.use_timestamp_timezones = true
136
136
  t1 = Time.at(1)
137
- @db[:fk] << {:t => t1, :d => t1}
137
+ @db[:fk].insert(:t => t1, :d => t1)
138
138
  @db[:fk].map(:t).must_equal [t1]
139
139
  @db[:fk].map(:d).must_equal [t1]
140
140
  Sequel.datetime_class = DateTime
@@ -145,9 +145,9 @@ describe "An SQLite database" do
145
145
 
146
146
  it "should support sequential primary keys" do
147
147
  @db.create_table!(:fk) {primary_key :id; text :name}
148
- @db[:fk] << {:name => 'abc'}
149
- @db[:fk] << {:name => 'def'}
150
- @db[:fk] << {:name => 'ghi'}
148
+ @db[:fk].insert(:name => 'abc')
149
+ @db[:fk].insert(:name => 'def')
150
+ @db[:fk].insert(:name => 'ghi')
151
151
  @db[:fk].order(:name).all.must_equal [
152
152
  {:id => 1, :name => 'abc'},
153
153
  {:id => 2, :name => 'def'},
@@ -347,9 +347,9 @@ describe "SQLite::Dataset#delete" do
347
347
  end
348
348
  @d = DB[:items]
349
349
  @d.delete # remove all records
350
- @d << {:name => 'abc', :value => 1.23}
351
- @d << {:name => 'def', :value => 4.56}
352
- @d << {:name => 'ghi', :value => 7.89}
350
+ @d.insert(:name => 'abc', :value => 1.23)
351
+ @d.insert(:name => 'def', :value => 4.56)
352
+ @d.insert(:name => 'ghi', :value => 7.89)
353
353
  end
354
354
  after do
355
355
  DB.drop_table?(:items)
@@ -382,9 +382,9 @@ describe "SQLite::Dataset#update" do
382
382
  end
383
383
  @d = DB[:items]
384
384
  @d.delete # remove all records
385
- @d << {:name => 'abc', :value => 1.23}
386
- @d << {:name => 'def', :value => 4.56}
387
- @d << {:name => 'ghi', :value => 7.89}
385
+ @d.insert(:name => 'abc', :value => 1.23)
386
+ @d.insert(:name => 'def', :value => 4.56)
387
+ @d.insert(:name => 'ghi', :value => 7.89)
388
388
  end
389
389
 
390
390
  it "should return the number of records affected" do
@@ -444,16 +444,16 @@ describe "SQLite dataset" do
444
444
  Float :value
445
445
  end
446
446
  @d = DB[:items]
447
- @d << {:name => 'abc', :value => 1.23}
448
- @d << {:name => 'def', :value => 4.56}
449
- @d << {:name => 'ghi', :value => 7.89}
447
+ @d.insert(:name => 'abc', :value => 1.23)
448
+ @d.insert(:name => 'def', :value => 4.56)
449
+ @d.insert(:name => 'ghi', :value => 7.89)
450
450
  end
451
451
  after do
452
452
  DB.drop_table?(:test, :items)
453
453
  end
454
454
 
455
455
  it "should be able to insert from a subquery" do
456
- DB[:test] << @d
456
+ DB[:test].insert(@d)
457
457
  DB[:test].count.must_equal 3
458
458
  DB[:test].select(:name, :value).order(:value).to_a.must_equal \
459
459
  @d.select(:name, :value).order(:value).to_a
@@ -484,21 +484,21 @@ describe "A SQLite database" do
484
484
  @db.add_column :test2, :xyz, :text
485
485
 
486
486
  @db[:test2].columns.must_equal [:name, :value, :xyz]
487
- @db[:test2] << {:name => 'mmm', :value => 111, :xyz=>'000'}
487
+ @db[:test2].insert(:name => 'mmm', :value => 111, :xyz=>'000')
488
488
  @db[:test2].first.must_equal(:name => 'mmm', :value => 111, :xyz=>'000')
489
489
  end
490
490
 
491
491
  it "should support drop_column operations" do
492
492
  @db.drop_column :test2, :value
493
493
  @db[:test2].columns.must_equal [:name]
494
- @db[:test2] << {:name => 'mmm'}
494
+ @db[:test2].insert(:name => 'mmm')
495
495
  @db[:test2].first.must_equal(:name => 'mmm')
496
496
  end
497
497
 
498
498
  it "should support drop_column operations in a transaction" do
499
499
  @db.transaction{@db.drop_column :test2, :value}
500
500
  @db[:test2].columns.must_equal [:name]
501
- @db[:test2] << {:name => 'mmm'}
501
+ @db[:test2].insert(:name => 'mmm')
502
502
  @db[:test2].first.must_equal(:name => 'mmm')
503
503
  end
504
504
 
@@ -506,9 +506,9 @@ describe "A SQLite database" do
506
506
  @db.create_table!(:test2){Integer :a; Integer :b; Integer :c; primary_key [:a, :b]}
507
507
  @db.drop_column :test2, :c
508
508
  @db[:test2].columns.must_equal [:a, :b]
509
- @db[:test2] << {:a=>1, :b=>2}
510
- @db[:test2] << {:a=>2, :b=>3}
511
- proc{@db[:test2] << {:a=>2, :b=>3}}.must_raise(Sequel::UniqueConstraintViolation, Sequel::ConstraintViolation, Sequel::DatabaseError)
509
+ @db[:test2].insert(:a=>1, :b=>2)
510
+ @db[:test2].insert(:a=>2, :b=>3)
511
+ proc{@db[:test2].insert(:a=>2, :b=>3)}.must_raise(Sequel::UniqueConstraintViolation, Sequel::ConstraintViolation, Sequel::DatabaseError)
512
512
  end
513
513
 
514
514
  it "should keep column attributes when dropping a column" do
@@ -520,9 +520,9 @@ describe "A SQLite database" do
520
520
 
521
521
  # This lame set of additions and deletions are to test that the primary keys
522
522
  # don't get messed up when we recreate the database.
523
- @db[:test3] << { :name => "foo", :value => 1}
524
- @db[:test3] << { :name => "foo", :value => 2}
525
- @db[:test3] << { :name => "foo", :value => 3}
523
+ @db[:test3].insert( :name => "foo", :value => 1)
524
+ @db[:test3].insert( :name => "foo", :value => 2)
525
+ @db[:test3].insert( :name => "foo", :value => 3)
526
526
  @db[:test3].filter(:id => 2).delete
527
527
 
528
528
  @db.drop_column :test3, :value
@@ -558,7 +558,7 @@ describe "A SQLite database" do
558
558
  it "should support rename_column operations" do
559
559
  @db[:test2].delete
560
560
  @db.add_column :test2, :xyz, :text
561
- @db[:test2] << {:name => 'mmm', :value => 111, :xyz => 'qqqq'}
561
+ @db[:test2].insert(:name => 'mmm', :value => 111, :xyz => 'qqqq')
562
562
 
563
563
  @db[:test2].columns.must_equal [:name, :value, :xyz]
564
564
  @db.rename_column :test2, :xyz, :zyx, :type => :text
@@ -717,4 +717,9 @@ describe "A SQLite database" do
717
717
  @db[:test2].insert(:name=>'a')
718
718
  proc{@db[:test2].insert(:name=>'a')}.must_raise(Sequel::ConstraintViolation, Sequel::UniqueConstraintViolation)
719
719
  end
720
+
721
+ it "should show unique constraints in Database#indexes" do
722
+ @db.alter_table(:test2){add_unique_constraint :name}
723
+ @db.indexes(:test2).values.first[:columns].must_equal [:name]
724
+ end if DB.sqlite_version >= 30808
720
725
  end
data/spec/bin_spec.rb CHANGED
@@ -40,7 +40,13 @@ describe "bin/sequel" do
40
40
  DB2.disconnect
41
41
  File.delete(BIN_SPEC_DB) if File.file?(BIN_SPEC_DB)
42
42
  File.delete(BIN_SPEC_DB2) if File.file?(BIN_SPEC_DB2)
43
- File.delete(TMP_FILE) if File.file?(TMP_FILE)
43
+ if File.file?(TMP_FILE)
44
+ begin
45
+ File.delete(TMP_FILE)
46
+ rescue Errno::ENOENT
47
+ nil
48
+ end
49
+ end
44
50
  File.delete(OUTPUT) if File.file?(OUTPUT)
45
51
  end
46
52