Class: SQLTree::Node::Expression::EscapedValue
- Defined in:
- lib/active_record/turntable/sql_tree_patch.rb
Class Method Summary collapse
Instance Method Summary collapse
- #escape_string ⇒ Object
-
#initialize(value, escape = nil) ⇒ EscapedValue
constructor
A new instance of EscapedValue.
- #to_sql(options = {}) ⇒ Object
Constructor Details
#initialize(value, escape = nil) ⇒ EscapedValue
Returns a new instance of EscapedValue.
298 299 300 301 |
# File 'lib/active_record/turntable/sql_tree_patch.rb', line 298 def initialize(value, escape = nil) @value = value @escape = escape end |
Class Method Details
.parse(tokens) ⇒ Object
318 319 320 321 322 323 324 325 326 |
# File 'lib/active_record/turntable/sql_tree_patch.rb', line 318 def self.parse(tokens) escape = tokens.next case tokens.next when SQLTree::Token::String SQLTree::Node::Expression::EscapedValue.new(tokens.current.literal, escape.literal) else raise SQLTree::Parser::UnexpectedToken.new(tokens.current, :literal) end end |
Instance Method Details
#escape_string ⇒ Object
314 315 316 |
# File 'lib/active_record/turntable/sql_tree_patch.rb', line 314 def escape_string @escape.to_s end |
#to_sql(options = {}) ⇒ Object
303 304 305 306 307 308 309 310 311 312 |
# File 'lib/active_record/turntable/sql_tree_patch.rb', line 303 def to_sql( = {}) case value when nil then "NULL" when String then "#{escape_string}#{quote_str(@value)}" when Numeric then @value.to_s when Date then @value.strftime("'%Y-%m-%d'") when DateTime, Time then @value.strftime("'%Y-%m-%d %H:%M:%S'") else raise "Don't know how te represent this value in SQL!" end end |