sequel 3.21.0 → 3.24.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 (104) hide show
  1. data/CHANGELOG +112 -0
  2. data/README.rdoc +15 -1
  3. data/doc/association_basics.rdoc +159 -40
  4. data/doc/model_hooks.rdoc +64 -27
  5. data/doc/prepared_statements.rdoc +8 -4
  6. data/doc/reflection.rdoc +8 -2
  7. data/doc/release_notes/3.22.0.txt +39 -0
  8. data/doc/release_notes/3.23.0.txt +172 -0
  9. data/doc/release_notes/3.24.0.txt +420 -0
  10. data/doc/virtual_rows.rdoc +2 -2
  11. data/lib/sequel/adapters/ado.rb +2 -1
  12. data/lib/sequel/adapters/db2.rb +8 -1
  13. data/lib/sequel/adapters/firebird.rb +25 -9
  14. data/lib/sequel/adapters/informix.rb +4 -19
  15. data/lib/sequel/adapters/jdbc/h2.rb +5 -0
  16. data/lib/sequel/adapters/jdbc/informix.rb +31 -0
  17. data/lib/sequel/adapters/jdbc/jtds.rb +34 -0
  18. data/lib/sequel/adapters/jdbc/mssql.rb +0 -32
  19. data/lib/sequel/adapters/jdbc/mysql.rb +9 -0
  20. data/lib/sequel/adapters/jdbc/sqlserver.rb +46 -0
  21. data/lib/sequel/adapters/jdbc.rb +39 -20
  22. data/lib/sequel/adapters/odbc.rb +2 -0
  23. data/lib/sequel/adapters/oracle.rb +12 -0
  24. data/lib/sequel/adapters/postgres.rb +30 -1
  25. data/lib/sequel/adapters/shared/access.rb +10 -0
  26. data/lib/sequel/adapters/shared/informix.rb +45 -0
  27. data/lib/sequel/adapters/shared/mssql.rb +106 -11
  28. data/lib/sequel/adapters/shared/mysql.rb +25 -7
  29. data/lib/sequel/adapters/shared/postgres.rb +39 -6
  30. data/lib/sequel/adapters/shared/sqlite.rb +57 -5
  31. data/lib/sequel/adapters/sqlite.rb +8 -3
  32. data/lib/sequel/adapters/swift/mysql.rb +9 -0
  33. data/lib/sequel/adapters/tinytds.rb +4 -3
  34. data/lib/sequel/ast_transformer.rb +190 -0
  35. data/lib/sequel/core.rb +1 -1
  36. data/lib/sequel/database/connecting.rb +1 -1
  37. data/lib/sequel/database/misc.rb +6 -0
  38. data/lib/sequel/database/query.rb +33 -3
  39. data/lib/sequel/database/schema_methods.rb +13 -4
  40. data/lib/sequel/dataset/features.rb +6 -0
  41. data/lib/sequel/dataset/prepared_statements.rb +17 -2
  42. data/lib/sequel/dataset/query.rb +17 -0
  43. data/lib/sequel/dataset/sql.rb +2 -53
  44. data/lib/sequel/exceptions.rb +4 -0
  45. data/lib/sequel/extensions/columns_introspection.rb +61 -0
  46. data/lib/sequel/extensions/migration.rb +4 -3
  47. data/lib/sequel/extensions/to_dot.rb +95 -83
  48. data/lib/sequel/model/associations.rb +234 -32
  49. data/lib/sequel/model/base.rb +187 -60
  50. data/lib/sequel/model/exceptions.rb +3 -1
  51. data/lib/sequel/model.rb +5 -0
  52. data/lib/sequel/plugins/association_pks.rb +6 -4
  53. data/lib/sequel/plugins/defaults_setter.rb +58 -0
  54. data/lib/sequel/plugins/identity_map.rb +2 -2
  55. data/lib/sequel/plugins/many_through_many.rb +33 -3
  56. data/lib/sequel/plugins/prepared_statements.rb +140 -0
  57. data/lib/sequel/plugins/prepared_statements_associations.rb +84 -0
  58. data/lib/sequel/plugins/prepared_statements_safe.rb +72 -0
  59. data/lib/sequel/plugins/prepared_statements_with_pk.rb +59 -0
  60. data/lib/sequel/plugins/serialization_modification_detection.rb +51 -0
  61. data/lib/sequel/plugins/single_table_inheritance.rb +2 -0
  62. data/lib/sequel/plugins/xml_serializer.rb +1 -1
  63. data/lib/sequel/sql.rb +8 -0
  64. data/lib/sequel/version.rb +1 -1
  65. data/spec/adapters/mssql_spec.rb +36 -0
  66. data/spec/adapters/mysql_spec.rb +6 -0
  67. data/spec/adapters/postgres_spec.rb +43 -18
  68. data/spec/adapters/spec_helper.rb +5 -0
  69. data/spec/core/connection_pool_spec.rb +56 -77
  70. data/spec/core/database_spec.rb +33 -0
  71. data/spec/core/dataset_spec.rb +127 -16
  72. data/spec/core/expression_filters_spec.rb +13 -0
  73. data/spec/core/schema_spec.rb +13 -1
  74. data/spec/core/spec_helper.rb +5 -0
  75. data/spec/extensions/association_pks_spec.rb +7 -0
  76. data/spec/extensions/columns_introspection_spec.rb +91 -0
  77. data/spec/extensions/defaults_setter_spec.rb +64 -0
  78. data/spec/extensions/many_through_many_spec.rb +77 -0
  79. data/spec/extensions/migration_spec.rb +17 -17
  80. data/spec/extensions/nested_attributes_spec.rb +1 -0
  81. data/spec/extensions/prepared_statements_associations_spec.rb +126 -0
  82. data/spec/extensions/prepared_statements_safe_spec.rb +69 -0
  83. data/spec/extensions/prepared_statements_spec.rb +72 -0
  84. data/spec/extensions/prepared_statements_with_pk_spec.rb +38 -0
  85. data/spec/extensions/serialization_modification_detection_spec.rb +36 -0
  86. data/spec/extensions/single_table_inheritance_spec.rb +11 -0
  87. data/spec/extensions/spec_helper.rb +3 -1
  88. data/spec/extensions/to_dot_spec.rb +3 -5
  89. data/spec/extensions/xml_serializer_spec.rb +12 -0
  90. data/spec/integration/associations_test.rb +212 -0
  91. data/spec/integration/dataset_test.rb +8 -1
  92. data/spec/integration/plugin_test.rb +134 -0
  93. data/spec/integration/prepared_statement_test.rb +72 -1
  94. data/spec/integration/schema_test.rb +66 -8
  95. data/spec/integration/spec_helper.rb +5 -0
  96. data/spec/integration/transaction_test.rb +40 -0
  97. data/spec/integration/type_test.rb +7 -0
  98. data/spec/model/associations_spec.rb +463 -5
  99. data/spec/model/base_spec.rb +59 -0
  100. data/spec/model/eager_loading_spec.rb +269 -1
  101. data/spec/model/hooks_spec.rb +161 -0
  102. data/spec/model/record_spec.rb +30 -0
  103. data/spec/model/spec_helper.rb +5 -0
  104. metadata +29 -4
@@ -174,6 +174,15 @@ describe "Database schema modifiers" do
174
174
  @db.create_table!(:items, :temp=>true){Integer :number}
175
175
  end
176
176
 
177
+ specify "should have create_table? only create the table if it doesn't already exist" do
178
+ @db.create_table!(:items){String :a}
179
+ @db.create_table?(:items){String :b}
180
+ @db[:items].columns.should == [:a]
181
+ @db.drop_table(:items) rescue nil
182
+ @db.create_table?(:items){String :b}
183
+ @db[:items].columns.should == [:b]
184
+ end
185
+
177
186
  specify "should rename tables correctly" do
178
187
  @db.drop_table(:items) rescue nil
179
188
  @db.create_table!(:items2){Integer :number}
@@ -362,25 +371,74 @@ describe "Database#tables" do
362
371
  "xxxxx#{@@xxxxx += 1}"
363
372
  end
364
373
  end
365
- @iom = INTEGRATION_DB.identifier_output_method
366
- @iim = INTEGRATION_DB.identifier_input_method
374
+ @db = INTEGRATION_DB
375
+ @db.create_table(:sequel_test_table){Integer :a}
376
+ @db.create_view :sequel_test_view, @db[:sequel_test_table]
377
+ @iom = @db.identifier_output_method
378
+ @iim = @db.identifier_input_method
367
379
  clear_sqls
368
380
  end
369
381
  after do
370
- INTEGRATION_DB.identifier_output_method = @iom
371
- INTEGRATION_DB.identifier_input_method = @iim
382
+ @db.drop_view :sequel_test_view
383
+ @db.drop_table :sequel_test_table
384
+ @db.identifier_output_method = @iom
385
+ @db.identifier_input_method = @iim
386
+ end
387
+
388
+ specify "should return an array of symbols" do
389
+ ts = @db.tables
390
+ ts.should be_a_kind_of(Array)
391
+ ts.each{|t| t.should be_a_kind_of(Symbol)}
392
+ ts.should include(:sequel_test_table)
393
+ ts.should_not include(:sequel_test_view)
394
+ end
395
+
396
+ specify "should respect the database's identifier_output_method" do
397
+ @db.identifier_output_method = :xxxxx
398
+ @db.identifier_input_method = :xxxxx
399
+ @db.tables.each{|t| t.to_s.should =~ /\Ax{5}\d+\z/}
400
+ end
401
+ end
402
+ end
403
+
404
+ begin
405
+ INTEGRATION_DB.views
406
+ rescue Sequel::NotImplemented
407
+ rescue
408
+ describe "Database#views" do
409
+ before do
410
+ class ::String
411
+ @@xxxxx = 0
412
+ def xxxxx
413
+ "xxxxx#{@@xxxxx += 1}"
414
+ end
415
+ end
416
+ @db = INTEGRATION_DB
417
+ @db.create_table(:sequel_test_table){Integer :a}
418
+ @db.create_view :sequel_test_view, @db[:sequel_test_table]
419
+ @iom = @db.identifier_output_method
420
+ @iim = @db.identifier_input_method
421
+ clear_sqls
422
+ end
423
+ after do
424
+ @db.drop_view :sequel_test_view
425
+ @db.drop_table :sequel_test_table
426
+ @db.identifier_output_method = @iom
427
+ @db.identifier_input_method = @iim
372
428
  end
373
429
 
374
430
  specify "should return an array of symbols" do
375
- ts = INTEGRATION_DB.tables
431
+ ts = @db.views
376
432
  ts.should be_a_kind_of(Array)
377
433
  ts.each{|t| t.should be_a_kind_of(Symbol)}
434
+ ts.should_not include(:sequel_test_table)
435
+ ts.should include(:sequel_test_view)
378
436
  end
379
437
 
380
438
  specify "should respect the database's identifier_output_method" do
381
- INTEGRATION_DB.identifier_output_method = :xxxxx
382
- INTEGRATION_DB.identifier_input_method = :xxxxx
383
- INTEGRATION_DB.tables.each{|t| t.to_s.should =~ /\Ax{5}\d+\z/}
439
+ @db.identifier_output_method = :xxxxx
440
+ @db.identifier_input_method = :xxxxx
441
+ @db.views.each{|t| t.to_s.should =~ /\Ax{5}\d+\z/}
384
442
  end
385
443
  end
386
444
  end
@@ -9,6 +9,11 @@ begin
9
9
  rescue LoadError
10
10
  end
11
11
 
12
+ if ENV['SEQUEL_COLUMNS_INTROSPECTION']
13
+ Sequel.extension :columns_introspection
14
+ Sequel::Dataset.introspect_all_columns
15
+ end
16
+
12
17
  Sequel::Model.use_transactions = false
13
18
 
14
19
  $sqls = []
@@ -134,4 +134,44 @@ describe "Database transactions" do
134
134
  @d.count.should == i + 1
135
135
  end
136
136
  end
137
+
138
+ if (! defined?(RUBY_ENGINE) or RUBY_ENGINE == 'ruby' or (RUBY_ENGINE == 'rbx' && ![[:do, :sqlite], [:tinytds, :mssql]].include?([INTEGRATION_DB.adapter_scheme, INTEGRATION_DB.database_type]))) and RUBY_VERSION < '1.9'
139
+ specify "should handle Thread#kill for transactions inside threads" do
140
+ q = Queue.new
141
+ q1 = Queue.new
142
+ t = Thread.new do
143
+ @db.transaction do
144
+ @d << {:name => 'abc', :value => 1}
145
+ q1.push nil
146
+ q.pop
147
+ @d << {:name => 'def', :value => 2}
148
+ end
149
+ end
150
+ q1.pop
151
+ t.kill
152
+ @d.count.should == 0
153
+ end
154
+
155
+ if INTEGRATION_DB.supports_savepoints?
156
+ specify "should handle Thread#kill for transactions with savepoints inside threads" do
157
+ q = Queue.new
158
+ q1 = Queue.new
159
+ t = Thread.new do
160
+ @db.transaction do
161
+ @d << {:name => 'abc', :value => 1}
162
+ @db.transaction(:savepoint=>true) do
163
+ @d << {:name => 'def', :value => 2}
164
+ q1.push nil
165
+ q.pop
166
+ @d << {:name => 'ghi', :value => 3}
167
+ end
168
+ @d << {:name => 'jkl', :value => 4}
169
+ end
170
+ end
171
+ q1.pop
172
+ t.kill
173
+ @d.count.should == 0
174
+ end
175
+ end
176
+ end
137
177
  end
@@ -68,6 +68,13 @@ describe "Supported types" do
68
68
  ds.first[:dat].to_s.should == d.to_s
69
69
  end
70
70
 
71
+ cspecify "should support generic time type", [:do], [:swift], [:odbc], [:jdbc, :mssql], [:tinytds] do
72
+ ds = create_items_table_with_column(:tim, Time, :only_time=>true)
73
+ t = Time.now
74
+ ds.insert(:tim => t)
75
+ ds.first[:tim].strftime('%H%M%S').should == t.strftime('%H%M%S')
76
+ end
77
+
71
78
  cspecify "should support generic datetime type", [:do, :sqlite], [:jdbc, :sqlite] do
72
79
  ds = create_items_table_with_column(:tim, DateTime)
73
80
  t = DateTime.now