Skip to content

Commit

Permalink
Add required argument dataset to sql_literal. Add alias sql_literal f…
Browse files Browse the repository at this point in the history
…or to_s.
  • Loading branch information
michaeldiamond authored and jeremyevans committed Oct 27, 2009
1 parent 2218e51 commit 5c2fa38
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/sequel/dataset/sql.rb
Expand Up @@ -810,12 +810,15 @@ def literal_integer(v)
v.to_s v.to_s
end end


# SQL fragmento for a type of object not handled by Dataset#literal. # SQL fragment for a type of object not handled by Dataset#literal.
# Calls sql_literal if object responds to it, otherwise raises an error. # Calls sql_literal if object responds to it, otherwise raises an error.
# Classes implementing sql_literal should call a class-specific method on the dataset
# provided and should add that method to Sequel::Dataset, allowing for adapters
# to provide customized literalizations.
# If a database specific type is allowed, this should be overriden in a subclass. # If a database specific type is allowed, this should be overriden in a subclass.
def literal_other(v) def literal_other(v)
if v.respond_to?(:sql_literal) if v.respond_to?(:sql_literal)
v.sql_literal v.sql_literal(self)
else else
raise Error, "can't express #{v.inspect} as a SQL literal" raise Error, "can't express #{v.inspect} as a SQL literal"
end end
Expand Down
5 changes: 5 additions & 0 deletions lib/sequel/sql.rb
Expand Up @@ -49,6 +49,11 @@ def self.to_s_method(meth, args=:self) # :nodoc:
def lit def lit
self self
end end

# Alias for to_s
def sql_literal(ds)
to_s(ds)
end
end end


# Represents a complex SQL expression, with a given operator and one # Represents a complex SQL expression, with a given operator and one
Expand Down

0 comments on commit 5c2fa38

Please sign in to comment.