sequel 3.40.0 → 3.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. data/CHANGELOG +40 -0
  2. data/README.rdoc +2 -2
  3. data/doc/advanced_associations.rdoc +12 -0
  4. data/doc/bin_sequel.rdoc +144 -0
  5. data/doc/migration.rdoc +1 -1
  6. data/doc/object_model.rdoc +29 -0
  7. data/doc/release_notes/3.41.0.txt +155 -0
  8. data/lib/sequel/adapters/ado.rb +4 -4
  9. data/lib/sequel/adapters/amalgalite.rb +0 -5
  10. data/lib/sequel/adapters/cubrid.rb +2 -2
  11. data/lib/sequel/adapters/db2.rb +9 -5
  12. data/lib/sequel/adapters/dbi.rb +4 -6
  13. data/lib/sequel/adapters/do.rb +4 -5
  14. data/lib/sequel/adapters/firebird.rb +8 -4
  15. data/lib/sequel/adapters/ibmdb.rb +2 -3
  16. data/lib/sequel/adapters/informix.rb +0 -6
  17. data/lib/sequel/adapters/jdbc.rb +11 -7
  18. data/lib/sequel/adapters/jdbc/db2.rb +22 -0
  19. data/lib/sequel/adapters/jdbc/derby.rb +5 -5
  20. data/lib/sequel/adapters/jdbc/h2.rb +0 -5
  21. data/lib/sequel/adapters/jdbc/jtds.rb +1 -1
  22. data/lib/sequel/adapters/jdbc/sqlserver.rb +6 -0
  23. data/lib/sequel/adapters/mock.rb +3 -3
  24. data/lib/sequel/adapters/mysql.rb +7 -7
  25. data/lib/sequel/adapters/mysql2.rb +0 -5
  26. data/lib/sequel/adapters/odbc.rb +4 -4
  27. data/lib/sequel/adapters/openbase.rb +4 -6
  28. data/lib/sequel/adapters/oracle.rb +14 -6
  29. data/lib/sequel/adapters/postgres.rb +12 -8
  30. data/lib/sequel/adapters/shared/db2.rb +5 -0
  31. data/lib/sequel/adapters/shared/firebird.rb +10 -0
  32. data/lib/sequel/adapters/shared/mssql.rb +43 -1
  33. data/lib/sequel/adapters/shared/mysql.rb +1 -0
  34. data/lib/sequel/adapters/shared/mysql_prepared_statements.rb +1 -1
  35. data/lib/sequel/adapters/shared/postgres.rb +12 -0
  36. data/lib/sequel/adapters/shared/sqlite.rb +32 -0
  37. data/lib/sequel/adapters/sqlite.rb +9 -8
  38. data/lib/sequel/adapters/swift.rb +3 -8
  39. data/lib/sequel/adapters/tinytds.rb +5 -5
  40. data/lib/sequel/connection_pool.rb +13 -19
  41. data/lib/sequel/connection_pool/sharded_single.rb +12 -12
  42. data/lib/sequel/connection_pool/sharded_threaded.rb +37 -17
  43. data/lib/sequel/connection_pool/single.rb +6 -3
  44. data/lib/sequel/connection_pool/threaded.rb +33 -13
  45. data/lib/sequel/database/connecting.rb +28 -1
  46. data/lib/sequel/database/logging.rb +1 -1
  47. data/lib/sequel/database/misc.rb +2 -5
  48. data/lib/sequel/database/query.rb +2 -2
  49. data/lib/sequel/database/schema_generator.rb +1 -1
  50. data/lib/sequel/database/schema_methods.rb +3 -0
  51. data/lib/sequel/dataset/query.rb +8 -4
  52. data/lib/sequel/dataset/sql.rb +7 -0
  53. data/lib/sequel/extensions/arbitrary_servers.rb +1 -1
  54. data/lib/sequel/extensions/connection_validator.rb +109 -0
  55. data/lib/sequel/extensions/pg_array.rb +2 -0
  56. data/lib/sequel/extensions/pg_hstore.rb +2 -0
  57. data/lib/sequel/extensions/pg_json.rb +4 -0
  58. data/lib/sequel/extensions/pg_range.rb +1 -0
  59. data/lib/sequel/extensions/pg_row.rb +4 -0
  60. data/lib/sequel/plugins/prepared_statements.rb +2 -1
  61. data/lib/sequel/plugins/single_table_inheritance.rb +53 -10
  62. data/lib/sequel/plugins/touch.rb +18 -6
  63. data/lib/sequel/plugins/validation_class_methods.rb +1 -0
  64. data/lib/sequel/plugins/validation_helpers.rb +3 -1
  65. data/lib/sequel/sql.rb +61 -19
  66. data/lib/sequel/version.rb +1 -1
  67. data/spec/adapters/firebird_spec.rb +52 -38
  68. data/spec/adapters/mssql_spec.rb +67 -0
  69. data/spec/adapters/mysql_spec.rb +192 -116
  70. data/spec/adapters/postgres_spec.rb +133 -70
  71. data/spec/adapters/spec_helper.rb +7 -0
  72. data/spec/adapters/sqlite_spec.rb +34 -1
  73. data/spec/core/connection_pool_spec.rb +79 -75
  74. data/spec/core/database_spec.rb +9 -4
  75. data/spec/core/dataset_spec.rb +15 -0
  76. data/spec/core/expression_filters_spec.rb +40 -2
  77. data/spec/extensions/connection_validator_spec.rb +118 -0
  78. data/spec/extensions/pg_array_spec.rb +4 -0
  79. data/spec/extensions/single_table_inheritance_spec.rb +42 -0
  80. data/spec/extensions/touch_spec.rb +40 -0
  81. data/spec/extensions/validation_class_methods_spec.rb +19 -1
  82. data/spec/extensions/validation_helpers_spec.rb +17 -0
  83. data/spec/integration/database_test.rb +14 -0
  84. data/spec/integration/dataset_test.rb +3 -3
  85. data/spec/integration/plugin_test.rb +41 -12
  86. data/spec/integration/schema_test.rb +14 -0
  87. data/spec/integration/spec_helper.rb +7 -0
  88. data/spec/integration/type_test.rb +3 -0
  89. metadata +9 -3
@@ -530,60 +530,89 @@ end
530
530
  describe "Touch plugin" do
531
531
  before(:all) do
532
532
  @db = INTEGRATION_DB
533
- @db.instance_variable_set(:@schemas, {})
534
- @db.create_table!(:artists) do
533
+ @db.drop_table? :albums_artists, :albums, :artists
534
+ @db.create_table(:artists) do
535
535
  primary_key :id
536
536
  String :name
537
537
  DateTime :updated_at
538
538
  end
539
- @db.create_table!(:albums) do
539
+ @db.create_table(:albums) do
540
540
  primary_key :id
541
541
  String :name
542
542
  foreign_key :artist_id, :artists
543
543
  DateTime :updated_at
544
544
  end
545
+ @db.create_join_table({:album_id=>:albums, :artist_id=>:artists}, :no_index=>true)
545
546
  end
546
547
  before do
547
548
  @db[:albums].delete
548
549
  @db[:artists].delete
549
550
  class ::Album < Sequel::Model(@db)
550
- many_to_one :artist
551
- plugin :touch, :associations=>:artist
552
551
  end
553
552
  class ::Artist < Sequel::Model(@db)
554
553
  end
555
554
 
556
555
  @artist = Artist.create(:name=>'1')
557
- @album = Album.create(:name=>'A', :artist=>@artist)
556
+ @album = Album.create(:name=>'A', :artist_id=>@artist.id)
558
557
  end
559
558
  after do
560
559
  [:Album, :Artist].each{|s| Object.send(:remove_const, s)}
561
560
  end
562
561
  after(:all) do
563
- @db.drop_table? :albums, :artists
562
+ @db.drop_table? :albums_artists, :albums, :artists
564
563
  end
565
564
 
566
565
  specify "should update the timestamp column when touching the record" do
566
+ Album.plugin :touch
567
567
  @album.updated_at.should == nil
568
568
  @album.touch
569
569
  @album.updated_at.to_i.should be_within(2).of(Time.now.to_i)
570
570
  end
571
571
 
572
- cspecify "should update the timestamp column for associated records when the record is updated or destroyed", [:do, :sqlite], [:jdbc, :sqlite], [:swift] do
572
+ cspecify "should update the timestamp column for many_to_one associated records when the record is updated or destroyed", [:do, :sqlite], [:jdbc, :sqlite], [:swift] do
573
+ Album.many_to_one :artist
574
+ Album.plugin :touch, :associations=>:artist
573
575
  @artist.updated_at.should == nil
574
576
  @album.update(:name=>'B')
575
577
  ua = @artist.reload.updated_at
576
578
  if ua.is_a?(Time)
577
- ua.to_i.should be_within(2).of(Time.now.to_i)
579
+ ua.to_i.should be_within(60).of(Time.now.to_i)
578
580
  else
579
- (DateTime.now - ua).should be_within(2.0/86400).of(0)
581
+ (DateTime.now - ua).should be_within(60.0/86400).of(0)
580
582
  end
581
583
  @artist.update(:updated_at=>nil)
582
584
  @album.destroy
583
585
  if ua.is_a?(Time)
584
- ua.to_i.should be_within(2).of(Time.now.to_i)
586
+ ua.to_i.should be_within(60).of(Time.now.to_i)
587
+ else
588
+ (DateTime.now - ua).should be_within(60.0/86400).of(0)
589
+ end
590
+ end
591
+
592
+ cspecify "should update the timestamp column for one_to_many associated records when the record is updated", [:do, :sqlite], [:jdbc, :sqlite], [:swift] do
593
+ Artist.one_to_many :albums
594
+ Artist.plugin :touch, :associations=>:albums
595
+ @album.updated_at.should == nil
596
+ @artist.update(:name=>'B')
597
+ ua = @album.reload.updated_at
598
+ if ua.is_a?(Time)
599
+ ua.to_i.should be_within(60).of(Time.now.to_i)
600
+ else
601
+ (DateTime.now - ua).should be_within(60.0/86400).of(0)
602
+ end
603
+ end
604
+
605
+ cspecify "should update the timestamp column for many_to_many associated records when the record is updated", [:do, :sqlite], [:jdbc, :sqlite], [:swift] do
606
+ Artist.many_to_many :albums
607
+ Artist.plugin :touch, :associations=>:albums
608
+ @artist.add_album(@album)
609
+ @album.updated_at.should == nil
610
+ @artist.update(:name=>'B')
611
+ ua = @album.reload.updated_at
612
+ if ua.is_a?(Time)
613
+ ua.to_i.should be_within(60).of(Time.now.to_i)
585
614
  else
586
- (DateTime.now - ua).should be_within(2.0/86400).of(0)
615
+ (DateTime.now - ua).should be_within(60.0/86400).of(0)
587
616
  end
588
617
  end
589
618
  end
@@ -389,6 +389,11 @@ describe "Database schema modifiers" do
389
389
  @ds.all.should == [{:id=>i, :item_id=>nil}]
390
390
  end
391
391
 
392
+ specify "should not allow NULLs in a primary key" do
393
+ @db.create_table!(:items){String :id, :primary_key=>true}
394
+ proc{@ds.insert(:id=>nil)}.should raise_error(Sequel::DatabaseError)
395
+ end
396
+
392
397
  specify "should rename columns correctly" do
393
398
  @db.create_table!(:items){Integer :id}
394
399
  @ds.insert(:id=>10)
@@ -430,6 +435,15 @@ describe "Database schema modifiers" do
430
435
  @db[:items2].select_order_map([:id, :b]).should == [[1, 10], [2, 20]]
431
436
  end
432
437
 
438
+ cspecify "should rename primary_key columns correctly", :db2 do
439
+ @db.create_table!(:items){Integer :id, :primary_key=>true}
440
+ @ds.insert(:id=>10)
441
+ @db.alter_table(:items){rename_column :id, :id2}
442
+ @db.schema(:items, :reload=>true).map{|x| x.first}.should == [:id2]
443
+ @ds.columns!.should == [:id2]
444
+ @ds.all.should == [{:id2=>10}]
445
+ end
446
+
433
447
  cspecify "should set column NULL/NOT NULL correctly", [:jdbc, :db2], [:db2] do
434
448
  @db.create_table!(:items, :engine=>:InnoDB){Integer :id}
435
449
  @ds.insert(:id=>10)
@@ -94,3 +94,10 @@ if INTEGRATION_DB.adapter_scheme == :ibmdb || (INTEGRATION_DB.adapter_scheme ==
94
94
  super
95
95
  end
96
96
  end
97
+
98
+ if ENV['SEQUEL_CONNECTION_VALIDATOR']
99
+ ENV['SEQUEL_NO_CHECK_SQLS'] = '1'
100
+ INTEGRATION_DB.extension(:connection_validator)
101
+ INTEGRATION_DB.pool.connection_validation_timeout = -1
102
+ end
103
+
@@ -64,6 +64,9 @@ describe "Supported types" do
64
64
  ds = create_items_table_with_column(:name, String, :text=>true)
65
65
  ds.insert(:name => 'Test User'*100)
66
66
  ds.all.should == [{:name=>'Test User'*100}]
67
+
68
+ ds.update(:name=>ds.get(:name))
69
+ ds.all.should == [{:name=>'Test User'*100}]
67
70
  end
68
71
 
69
72
  cspecify "should support generic date type", [:do, :sqlite], [:jdbc, :sqlite], :mssql, :oracle do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.40.0
4
+ version: 3.41.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-26 00:00:00.000000000 Z
12
+ date: 2012-11-01 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: The Database Toolkit for Ruby
15
15
  email: code@jeremyevans.net
@@ -43,6 +43,7 @@ extra_rdoc_files:
43
43
  - doc/thread_safety.rdoc
44
44
  - doc/object_model.rdoc
45
45
  - doc/core_extensions.rdoc
46
+ - doc/bin_sequel.rdoc
46
47
  - doc/release_notes/1.0.txt
47
48
  - doc/release_notes/1.1.txt
48
49
  - doc/release_notes/1.3.txt
@@ -102,6 +103,7 @@ extra_rdoc_files:
102
103
  - doc/release_notes/3.38.0.txt
103
104
  - doc/release_notes/3.39.0.txt
104
105
  - doc/release_notes/3.40.0.txt
106
+ - doc/release_notes/3.41.0.txt
105
107
  files:
106
108
  - MIT-LICENSE
107
109
  - CHANGELOG
@@ -179,6 +181,7 @@ files:
179
181
  - doc/release_notes/3.38.0.txt
180
182
  - doc/release_notes/3.39.0.txt
181
183
  - doc/release_notes/3.40.0.txt
184
+ - doc/release_notes/3.41.0.txt
182
185
  - doc/sharding.rdoc
183
186
  - doc/sql.rdoc
184
187
  - doc/validations.rdoc
@@ -190,6 +193,7 @@ files:
190
193
  - doc/thread_safety.rdoc
191
194
  - doc/object_model.rdoc
192
195
  - doc/core_extensions.rdoc
196
+ - doc/bin_sequel.rdoc
193
197
  - spec/adapters/firebird_spec.rb
194
198
  - spec/adapters/informix_spec.rb
195
199
  - spec/adapters/mssql_spec.rb
@@ -243,7 +247,6 @@ files:
243
247
  - spec/extensions/thread_local_timezones_spec.rb
244
248
  - spec/extensions/timestamps_spec.rb
245
249
  - spec/extensions/typecast_on_load_spec.rb
246
- - spec/extensions/validation_class_methods_spec.rb
247
250
  - spec/extensions/validation_helpers_spec.rb
248
251
  - spec/extensions/composition_spec.rb
249
252
  - spec/extensions/rcte_tree_spec.rb
@@ -297,6 +300,8 @@ files:
297
300
  - spec/extensions/pg_typecast_on_load_spec.rb
298
301
  - spec/extensions/constraint_validations_plugin_spec.rb
299
302
  - spec/extensions/constraint_validations_spec.rb
303
+ - spec/extensions/connection_validator_spec.rb
304
+ - spec/extensions/validation_class_methods_spec.rb
300
305
  - spec/integration/associations_test.rb
301
306
  - spec/integration/database_test.rb
302
307
  - spec/integration/dataset_test.rb
@@ -497,6 +502,7 @@ files:
497
502
  - lib/sequel/extensions/pg_row.rb
498
503
  - lib/sequel/extensions/pg_row_ops.rb
499
504
  - lib/sequel/extensions/constraint_validations.rb
505
+ - lib/sequel/extensions/connection_validator.rb
500
506
  - lib/sequel/metaprogramming.rb
501
507
  - lib/sequel/model.rb
502
508
  - lib/sequel/model/associations.rb