Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/lib/sequel/dataset/sql.rb b/lib/sequel/dataset/sql.rb
- index d0d42bc..ffc198d 100644
- --- a/lib/sequel/dataset/sql.rb
- +++ b/lib/sequel/dataset/sql.rb
- @@ -1233,9 +1233,10 @@ module Sequel
- end
- # SQL fragmento for a type of object not handled by Dataset#literal.
- - # Raises an error. If a database specific type is allowed,
- - # this should be overriden in a subclass.
- + # Calls sql_literal if object responds to it, otherwise raises an error.
- + # If a database specific type is allowed, this should be overriden in a subclass.
- def literal_other(v)
- + return v.sql_literal if v.respond_to?(:sql_literal)
- raise Error, "can't express #{v.inspect} as a SQL literal"
- end
- diff --git a/spec/core/dataset_spec.rb b/spec/core/dataset_spec.rb
- index b7e57f4..178b96b 100644
- --- a/spec/core/dataset_spec.rb
- +++ b/spec/core/dataset_spec.rb
- @@ -779,7 +779,16 @@ context "Dataset#literal" do
- @dataset.literal(:items__name).should == "items.name"
- end
- - specify "should raise an error for unsupported types" do
- + specify "should call sql_literal on type if not natively supports and the method exists" do
- + @a = Class.new do
- + def sql_literal
- + "called"
- + end
- + end
- + @dataset.literal(@a.new).should == "called"
- + end
- +
- + specify "should raise an error for unsupported types with no sql_literal method" do
- proc {@dataset.literal({})}.should raise_error
- end
Add Comment
Please, Sign In to add comment