Skip to content

Commit

Permalink
Include :single_value prepared statements in specs
Browse files Browse the repository at this point in the history
  • Loading branch information
rintaun committed Sep 17, 2018
1 parent 1fd8f62 commit 8afbdb1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 9 additions & 2 deletions spec/core/dataset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3841,6 +3841,7 @@ class ::InspectDataset < Sequel::Dataset; end
@ds.filter(:num=>:$n).call([:to_hash, :a, :b], :n=>1)
@ds.filter(:num=>:$n).call([:to_hash_groups, :a, :b], :n=>1)
@ds.filter(:num=>:$n).call(:first, :n=>1)
@ds.filter(:num=>:$n).call(:single_value, :n=>1)
@ds.filter(:num=>:$n).call(:delete, :n=>1)
@ds.filter(:num=>:$n).call(:update, {:n=>1, :n2=>2}, :num=>:$n2)
@ds.call(:insert, {:n=>1}, :num=>:$n)
Expand All @@ -3854,6 +3855,7 @@ class ::InspectDataset < Sequel::Dataset; end
'SELECT * FROM items WHERE (num = 1)',
'SELECT * FROM items WHERE (num = 1)',
'SELECT * FROM items WHERE (num = 1) LIMIT 1',
'SELECT * FROM items WHERE (num = 1) LIMIT 1',
'DELETE FROM items WHERE (num = 1)',
'UPDATE items SET num = 2 WHERE (num = 1)',
'INSERT INTO items (num) VALUES (1)',
Expand All @@ -3870,20 +3872,22 @@ class ::InspectDataset < Sequel::Dataset; end
pss << @ds.filter(:num=>:$n).prepare([:to_hash, :a, :b], :sh)
pss << @ds.filter(:num=>:$n).prepare([:to_hash_groups, :a, :b], :shg)
pss << @ds.filter(:num=>:$n).prepare(:first, :fn)
pss << @ds.filter(:num=>:$n).prepare(:single_value, :svn)
pss << @ds.filter(:num=>:$n).prepare(:delete, :dn)
pss << @ds.filter(:num=>:$n).prepare(:update, :un, :num=>:$n2)
pss << @ds.prepare(:insert, :in, :num=>:$n)
pss << @ds.prepare(:insert_pk, :inp, :num=>:$n)
pss << @ds.prepare(:insert_select, :ins, :num=>:$n)
@db.prepared_statements.keys.sort_by{|k| k.to_s}.must_equal [:ah, :dn, :en, :fn, :in, :inp, :ins, :sh, :shg, :sm, :sn, :un]
[:en, :sn, :sm, :ah, :sh, :shg, :fn, :dn, :un, :in, :inp, :ins].each_with_index{|x, i| @db.prepared_statements[x].must_equal pss[i]}
@db.prepared_statements.keys.sort_by{|k| k.to_s}.must_equal [:ah, :dn, :en, :fn, :in, :inp, :ins, :sh, :shg, :sm, :sn, :svn, :un]
[:en, :sn, :sm, :ah, :sh, :shg, :fn, :svn, :dn, :un, :in, :inp, :ins].each_with_index{|x, i| @db.prepared_statements[x].must_equal pss[i]}
@db.call(:en, :n=>1){}
@db.call(:sn, :n=>1)
@db.call(:sm, :n=>1)
@db.call(:ah, :n=>1)
@db.call(:sh, :n=>1)
@db.call(:shg, :n=>1)
@db.call(:fn, :n=>1)
@db.call(:svn, :n=>1)
@db.call(:dn, :n=>1)
@db.call(:un, :n=>1, :n2=>2)
@db.call(:in, :n=>1)
Expand All @@ -3897,6 +3901,7 @@ class ::InspectDataset < Sequel::Dataset; end
'SELECT * FROM items WHERE (num = 1)',
'SELECT * FROM items WHERE (num = 1)',
'SELECT * FROM items WHERE (num = 1) LIMIT 1',
'SELECT * FROM items WHERE (num = 1) LIMIT 1',
'DELETE FROM items WHERE (num = 1)',
'UPDATE items SET num = 2 WHERE (num = 1)',
'INSERT INTO items (num) VALUES (1)',
Expand Down Expand Up @@ -4037,6 +4042,7 @@ def prepared_statement_modules
@ps << @ds.prepare(:select, :s)
@ps << @ds.prepare(:all, :a)
@ps << @ds.prepare(:first, :f)
@ps << @ds.prepare(:single_value, :sv)
@ps << @ds.prepare(:delete, :d)
@ps << @ds.prepare(:insert, :i, :num=>:$n)
@ps << @ds.prepare(:update, :u, :num=>:$n)
Expand All @@ -4051,6 +4057,7 @@ def prepared_statement_modules
@db.sqls.must_equal ["SELECT * FROM items WHERE (num = ?) -- args: [1]",
"SELECT * FROM items WHERE (num = ?) -- args: [1]",
"SELECT * FROM items WHERE (num = ?) LIMIT 1 -- args: [1]",
"SELECT * FROM items WHERE (num = ?) LIMIT 1 -- args: [1]",
"DELETE FROM items WHERE (num = ?) -- args: [1]",
"INSERT INTO items (num) VALUES (?) -- args: [1]",
"UPDATE items SET num = ? WHERE (num = ?) -- args: [1, 1]"]
Expand Down
7 changes: 7 additions & 0 deletions spec/integration/prepared_statement_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
@ds.filter(:numb=>:$n).call(:select, :n=>10).must_equal [{:id=>1, :numb=>10}]
@ds.filter(:numb=>:$n).call(:all, :n=>10).must_equal [{:id=>1, :numb=>10}]
@ds.filter(:numb=>:$n).call(:first, :n=>10).must_equal(:id=>1, :numb=>10)
@ds.select(:numb).filter(:numb=>:$n).call(:single_value, :n=>10).must_equal(10)
@ds.filter(:numb=>:$n).call([:map, :numb], :n=>10).must_equal [10]
@ds.filter(:numb=>:$n).call([:as_hash, :id, :numb], :n=>10).must_equal(1=>10)
@ds.filter(:numb=>:$n).call([:to_hash, :id, :numb], :n=>10).must_equal(1=>10)
Expand All @@ -39,20 +40,24 @@
@ds.filter(:numb=>:$n).bind(:n=>10).call(:select).must_equal [{:id=>1, :numb=>10}]
@ds.filter(:numb=>:$n).bind(:n=>10).call(:all).must_equal [{:id=>1, :numb=>10}]
@ds.filter(:numb=>:$n).bind(:n=>10).call(:first).must_equal(:id=>1, :numb=>10)
@ds.select(:numb).filter(:numb=>:$n).bind(:n=>10).call(:single_value).must_equal(10)

@ds.bind(:n=>10).filter(:numb=>:$n).call(:select).must_equal [{:id=>1, :numb=>10}]
@ds.bind(:n=>10).filter(:numb=>:$n).call(:all).must_equal [{:id=>1, :numb=>10}]
@ds.bind(:n=>10).filter(:numb=>:$n).call(:first).must_equal(:id=>1, :numb=>10)
@ds.bind(:n=>10).select(:numb).filter(:numb=>:$n).call(:single_value).must_equal(10)
end

it "should allow overriding variables specified with #bind" do
@ds.filter(:numb=>:$n).bind(:n=>1).call(:select, :n=>10).must_equal [{:id=>1, :numb=>10}]
@ds.filter(:numb=>:$n).bind(:n=>1).call(:all, :n=>10).must_equal [{:id=>1, :numb=>10}]
@ds.filter(:numb=>:$n).bind(:n=>1).call(:first, :n=>10).must_equal(:id=>1, :numb=>10)
@ds.select(:numb).filter(:numb=>:$n).bind(:n=>1).call(:single_value, :n=>10).must_equal(10)

@ds.filter(:numb=>:$n).bind(:n=>1).bind(:n=>10).call(:select).must_equal [{:id=>1, :numb=>10}]
@ds.filter(:numb=>:$n).bind(:n=>1).bind(:n=>10).call(:all).must_equal [{:id=>1, :numb=>10}]
@ds.filter(:numb=>:$n).bind(:n=>1).bind(:n=>10).call(:first).must_equal(:id=>1, :numb=>10)
@ds.select(:numb).filter(:numb=>:$n).bind(:n=>1).bind(:n=>10).call(:single_value).must_equal(10)
end

it "should support placeholder literal strings with call" do
Expand Down Expand Up @@ -160,6 +165,8 @@
@db.call(:select_n, :n=>10).must_equal [{:id=>1, :numb=>10}]
@ds.filter(:numb=>:$n).prepare(:first, :select_n)
@db.call(:select_n, :n=>10).must_equal(:id=>1, :numb=>10)
@ds.select(:numb).filter(:numb=>:$n).prepare(:single_value, :select_n)
@db.call(:select_n, :n=>10).must_equal(10)
@ds.filter(:numb=>:$n).prepare([:map, :numb], :select_n)
@db.call(:select_n, :n=>10).must_equal [10]
@ds.filter(:numb=>:$n).prepare([:as_hash, :id, :numb], :select_n)
Expand Down

0 comments on commit 8afbdb1

Please sign in to comment.