Guest User

Untitled

a guest
Jul 15th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. diff --git a/lib/sequel/dataset/sql.rb b/lib/sequel/dataset/sql.rb
  2. index d0d42bc..ffc198d 100644
  3. --- a/lib/sequel/dataset/sql.rb
  4. +++ b/lib/sequel/dataset/sql.rb
  5. @@ -1233,9 +1233,10 @@ module Sequel
  6. end
  7.  
  8. # SQL fragmento for a type of object not handled by Dataset#literal.
  9. - # Raises an error. If a database specific type is allowed,
  10. - # this should be overriden in a subclass.
  11. + # Calls sql_literal if object responds to it, otherwise raises an error.
  12. + # If a database specific type is allowed, this should be overriden in a subclass.
  13. def literal_other(v)
  14. + return v.sql_literal if v.respond_to?(:sql_literal)
  15. raise Error, "can't express #{v.inspect} as a SQL literal"
  16. end
  17.  
  18. diff --git a/spec/core/dataset_spec.rb b/spec/core/dataset_spec.rb
  19. index b7e57f4..178b96b 100644
  20. --- a/spec/core/dataset_spec.rb
  21. +++ b/spec/core/dataset_spec.rb
  22. @@ -779,7 +779,16 @@ context "Dataset#literal" do
  23. @dataset.literal(:items__name).should == "items.name"
  24. end
  25.  
  26. - specify "should raise an error for unsupported types" do
  27. + specify "should call sql_literal on type if not natively supports and the method exists" do
  28. + @a = Class.new do
  29. + def sql_literal
  30. + "called"
  31. + end
  32. + end
  33. + @dataset.literal(@a.new).should == "called"
  34. + end
  35. +
  36. + specify "should raise an error for unsupported types with no sql_literal method" do
  37. proc {@dataset.literal({})}.should raise_error
  38. end
Add Comment
Please, Sign In to add comment