colincasey-sequel 2.10.1 → 2.10.2

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 (39) hide show
  1. data/CHANGELOG +10 -0
  2. data/lib/sequel_core/adapters/ado.rb +3 -0
  3. data/lib/sequel_core/adapters/db2.rb +0 -11
  4. data/lib/sequel_core/adapters/dbi.rb +0 -11
  5. data/lib/sequel_core/adapters/do.rb +0 -12
  6. data/lib/sequel_core/adapters/firebird.rb +19 -14
  7. data/lib/sequel_core/adapters/informix.rb +1 -11
  8. data/lib/sequel_core/adapters/jdbc/h2.rb +3 -11
  9. data/lib/sequel_core/adapters/jdbc/mysql.rb +0 -10
  10. data/lib/sequel_core/adapters/jdbc/postgresql.rb +3 -15
  11. data/lib/sequel_core/adapters/jdbc.rb +1 -13
  12. data/lib/sequel_core/adapters/mysql.rb +6 -13
  13. data/lib/sequel_core/adapters/odbc.rb +34 -28
  14. data/lib/sequel_core/adapters/openbase.rb +0 -11
  15. data/lib/sequel_core/adapters/oracle.rb +11 -9
  16. data/lib/sequel_core/adapters/postgres.rb +13 -16
  17. data/lib/sequel_core/adapters/shared/ms_access.rb +8 -2
  18. data/lib/sequel_core/adapters/shared/mssql.rb +6 -15
  19. data/lib/sequel_core/adapters/shared/mysql.rb +23 -14
  20. data/lib/sequel_core/adapters/shared/oracle.rb +4 -0
  21. data/lib/sequel_core/adapters/shared/postgres.rb +27 -25
  22. data/lib/sequel_core/adapters/shared/progress.rb +4 -0
  23. data/lib/sequel_core/adapters/shared/sqlite.rb +9 -16
  24. data/lib/sequel_core/adapters/sqlite.rb +5 -14
  25. data/lib/sequel_core/core_sql.rb +7 -3
  26. data/lib/sequel_core/dataset/convenience.rb +1 -1
  27. data/lib/sequel_core/dataset/prepared_statements.rb +1 -1
  28. data/lib/sequel_core/dataset/sql.rb +116 -30
  29. data/lib/sequel_core/dataset.rb +2 -2
  30. data/lib/sequel_core/sql.rb +2 -31
  31. data/lib/sequel_model/base.rb +23 -7
  32. data/spec/integration/dataset_test.rb +2 -2
  33. data/spec/sequel_core/core_sql_spec.rb +9 -0
  34. data/spec/sequel_core/dataset_spec.rb +27 -31
  35. data/spec/sequel_model/base_spec.rb +66 -0
  36. data/spec/sequel_model/spec_helper.rb +3 -0
  37. metadata +1 -1
  38. data/lib/sequel_core/dataset/stored_procedures.rb +0 -75
  39. data/lib/sequel_core/dataset/unsupported.rb +0 -43
@@ -703,6 +703,10 @@ context "Dataset#literal" do
703
703
  @dataset.literal("a\\'bc").should == "'a\\\\''bc'"
704
704
  end
705
705
 
706
+ specify "should escape blobs as strings by default" do
707
+ @dataset.literal('abc'.to_sequel_blob).should == "'abc'"
708
+ end
709
+
706
710
  specify "should literalize numbers properly" do
707
711
  @dataset.literal(1).should == "1"
708
712
  @dataset.literal(1.5).should == "1.5"
@@ -734,13 +738,19 @@ context "Dataset#literal" do
734
738
 
735
739
  specify "should literalize Time properly" do
736
740
  t = Time.now
737
- s = t.strftime("TIMESTAMP '%Y-%m-%d %H:%M:%S'")
741
+ s = t.strftime("'%Y-%m-%dT%H:%M:%S%z'").gsub(/(\d\d')\z/, ':\1')
742
+ @dataset.literal(t).should == s
743
+ end
744
+
745
+ specify "should literalize DateTime properly" do
746
+ t = DateTime.now
747
+ s = t.strftime("'%Y-%m-%dT%H:%M:%S%z'").gsub(/(\d\d')\z/, ':\1')
738
748
  @dataset.literal(t).should == s
739
749
  end
740
750
 
741
751
  specify "should literalize Date properly" do
742
752
  d = Date.today
743
- s = d.strftime("DATE '%Y-%m-%d'")
753
+ s = d.strftime("'%Y-%m-%d'")
744
754
  @dataset.literal(d).should == s
745
755
  end
746
756
 
@@ -998,6 +1008,21 @@ context "Dataset#unordered" do
998
1008
  end
999
1009
  end
1000
1010
 
1011
+ context "Dataset#with_sql" do
1012
+ setup do
1013
+ @dataset = Sequel::Dataset.new(nil).from(:test)
1014
+ end
1015
+
1016
+ specify "should remove use static sql" do
1017
+ @dataset.with_sql('SELECT 1 FROM test').sql.should == 'SELECT 1 FROM test'
1018
+ end
1019
+
1020
+ specify "should keep row_proc and transform" do
1021
+ @dataset.with_sql('SELECT 1 FROM test').row_proc.should == @dataset.row_proc
1022
+ @dataset.with_sql('SELECT 1 FROM test').instance_variable_get(:@transform).should == @dataset.instance_variable_get(:@transform)
1023
+ end
1024
+ end
1025
+
1001
1026
  context "Dataset#order_by" do
1002
1027
  setup do
1003
1028
  @dataset = Sequel::Dataset.new(nil).from(:test)
@@ -3450,32 +3475,3 @@ context "Sequel::Dataset#each" do
3450
3475
  end
3451
3476
  end
3452
3477
  end
3453
-
3454
- context Sequel::Dataset::UnsupportedIntersectExcept do
3455
- before do
3456
- @ds = Sequel::Dataset.new(nil).from(:items)
3457
- @ds2 = Sequel::Dataset.new(nil).from(:i)
3458
- @ds.extend(Sequel::Dataset::UnsupportedIntersectExcept)
3459
- end
3460
-
3461
- specify "should raise an error if INTERSECT or EXCEPT is USED" do
3462
- @ds.union(@ds2).sql.should == 'SELECT * FROM items UNION SELECT * FROM i'
3463
- proc{@ds.intersect(@ds2)}.should raise_error(Sequel::Error)
3464
- proc{@ds.except(@ds2)}.should raise_error(Sequel::Error)
3465
- end
3466
- end
3467
-
3468
- context Sequel::Dataset::UnsupportedIntersectExceptAll do
3469
- before do
3470
- @ds = Sequel::Dataset.new(nil).from(:items)
3471
- @ds2 = Sequel::Dataset.new(nil).from(:i)
3472
- @ds.extend(Sequel::Dataset::UnsupportedIntersectExceptAll)
3473
- end
3474
-
3475
- specify "should raise an error if INTERSECT or EXCEPT is USED" do
3476
- @ds.intersect(@ds2).sql.should == 'SELECT * FROM items INTERSECT SELECT * FROM i'
3477
- @ds.except(@ds2).sql.should == 'SELECT * FROM items EXCEPT SELECT * FROM i'
3478
- proc{@ds.intersect(@ds2, true)}.should raise_error(Sequel::Error)
3479
- proc{@ds.except(@ds2, true)}.should raise_error(Sequel::Error)
3480
- end
3481
- end
@@ -417,3 +417,69 @@ describe Sequel::Model, ".strict_param_setting" do
417
417
  proc{@c.new(:z=>1)}.should_not raise_error
418
418
  end
419
419
  end
420
+
421
+ describe Sequel::Model, ".[] optimization" do
422
+ setup do
423
+ @c = Class.new(Sequel::Model(:a))
424
+ @c.instance_eval do
425
+ def simple_table
426
+ @simple_table
427
+ end
428
+ end
429
+ end
430
+
431
+ it "should set simple_pk to the literalized primary key column name if a single primary key" do
432
+ @c.simple_pk.should == 'id'
433
+ @c.set_primary_key :b
434
+ @c.simple_pk.should == 'b'
435
+ @c.set_primary_key :b__a.identifier
436
+ @c.simple_pk.should == 'b__a'
437
+ end
438
+
439
+ it "should have simple_pk be blank if compound or no primary key" do
440
+ @c.no_primary_key
441
+ @c.simple_pk.should == nil
442
+ @c.set_primary_key :b, :a
443
+ @c.simple_pk.should == nil
444
+ end
445
+
446
+ it "should have simple table set if passed a Symbol to set_dataset" do
447
+ @c.set_dataset :a
448
+ @c.simple_table.should == 'a'
449
+ @c.set_dataset :b
450
+ @c.simple_table.should == 'b'
451
+ @c.set_dataset :b__a
452
+ @c.simple_table.should == 'b.a'
453
+ end
454
+
455
+ it "should have simple_table = nil if passed a dataset to set_dataset" do
456
+ @c.set_dataset @c.db[:a]
457
+ @c.simple_table.should == nil
458
+ end
459
+
460
+ it "should have simple_table superclasses setting if inheriting" do
461
+ @c.set_dataset :a
462
+ Class.new(@c).simple_table.should == 'a'
463
+ @c.instance_variable_set(:@simple_table, nil)
464
+ Class.new(@c).simple_table.should == nil
465
+ @c.instance_variable_set(:@simple_table, "'b'")
466
+ Class.new(@c).simple_table.should == "'b'"
467
+ end
468
+
469
+ it "should have simple_table = nil if inheriting and sti_key is set" do
470
+ @c.set_sti_key :x
471
+ Class.new(@c).simple_table.should == nil
472
+ end
473
+
474
+ it "should use Dataset#with_sql if simple_table and simple_pk are true" do
475
+ @c.set_dataset :a
476
+ @c.dataset.should_receive(:with_sql).and_return(@c.dataset)
477
+ @c[1]
478
+ end
479
+
480
+ it "should not use Dataset#with_sql if either simple_table or simple_pk is nil" do
481
+ @c.set_dataset @c.dataset
482
+ @c.dataset.should_not_receive(:with_sql)
483
+ @c[1]
484
+ end
485
+ end
@@ -73,6 +73,9 @@ class << Sequel::Model
73
73
  @db_schema = {}
74
74
  cols.each{|c| @db_schema[c] = {}}
75
75
  end
76
+ def simple_table
77
+ nil
78
+ end
76
79
  end
77
80
 
78
81
  Sequel::Model.db = MODEL_DB = MockDatabase.new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: colincasey-sequel
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.10.1
4
+ version: 2.10.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
@@ -1,75 +0,0 @@
1
- module Sequel
2
- class Dataset
3
- module StoredProcedureMethods
4
- SQL_QUERY_TYPE = Hash.new{|h,k| h[k] = k}
5
- SQL_QUERY_TYPE[:first] = SQL_QUERY_TYPE[:all] = :select
6
-
7
- # The name of the stored procedure to call
8
- attr_accessor :sproc_name
9
-
10
- # Call the prepared statement
11
- def call(*args, &block)
12
- @sproc_args = args
13
- case @sproc_type
14
- when :select, :all
15
- all(&block)
16
- when :first
17
- first
18
- when :insert
19
- insert
20
- when :update
21
- update
22
- when :delete
23
- delete
24
- end
25
- end
26
-
27
- # Programmer friendly string showing this is a stored procedure,
28
- # showing the name of the procedure.
29
- def inspect
30
- "<#{self.class.name}/StoredProcedure name=#{@sproc_name}>"
31
- end
32
-
33
- # Set the type of the sproc and override the corresponding _sql
34
- # method to return the empty string (since the result will be
35
- # ignored anyway).
36
- def sproc_type=(type)
37
- @sproc_type = type
38
- meta_def("#{sql_query_type}_sql"){|*a| ''}
39
- end
40
-
41
- private
42
-
43
- # The type of query (:select, :insert, :delete, :update).
44
- def sql_query_type
45
- SQL_QUERY_TYPE[@sproc_type]
46
- end
47
- end
48
-
49
- module StoredProcedures
50
- # For the given type (:select, :first, :insert, :update, or :delete),
51
- # run the database stored procedure with the given name with the given
52
- # arguments.
53
- def call_sproc(type, name, *args)
54
- prepare_sproc(type, name).call(*args)
55
- end
56
-
57
- # Transform this dataset into a stored procedure that you can call
58
- # multiple times with new arguments.
59
- def prepare_sproc(type, name)
60
- sp = clone
61
- prepare_extend_sproc(sp)
62
- sp.sproc_type = type
63
- sp.sproc_name = name
64
- sp
65
- end
66
-
67
- private
68
-
69
- # Extend the dataset with the stored procedure methods.
70
- def prepare_extend_sproc(ds)
71
- ds.extend(StoredProcedureMethods)
72
- end
73
- end
74
- end
75
- end
@@ -1,43 +0,0 @@
1
- class Sequel::Dataset
2
- # This module should be included in the dataset class for all databases that
3
- # don't support INTERSECT or EXCEPT.
4
- module UnsupportedIntersectExcept
5
- # Raise an Error if EXCEPT is used
6
- def except(ds, all=false)
7
- raise(Sequel::Error, "EXCEPT not supported")
8
- end
9
-
10
- # Raise an Error if INTERSECT is used
11
- def intersect(ds, all=false)
12
- raise(Sequel::Error, "INTERSECT not supported")
13
- end
14
-
15
- private
16
-
17
- # Since EXCEPT and INTERSECT are not supported, and order shouldn't matter
18
- # when UNION is used, don't worry about parantheses. This may potentially
19
- # give incorrect results if UNION ALL is used.
20
- def select_compounds_sql(sql, opts)
21
- return unless opts[:compounds]
22
- opts[:compounds].each do |type, dataset, all|
23
- sql << " #{type.to_s.upcase}#{' ALL' if all} #{subselect_sql(dataset)}"
24
- end
25
- end
26
- end
27
-
28
- # This module should be included in the dataset class for all databases that
29
- # don't support INTERSECT ALL or EXCEPT ALL.
30
- module UnsupportedIntersectExceptAll
31
- # Raise an Error if EXCEPT is used
32
- def except(ds, all=false)
33
- raise(Sequel::Error, "EXCEPT ALL not supported") if all
34
- super(ds)
35
- end
36
-
37
- # Raise an Error if INTERSECT is used
38
- def intersect(ds, all=false)
39
- raise(Sequel::Error, "INTERSECT ALL not supported") if all
40
- super(ds)
41
- end
42
- end
43
- end