Class: SQLTree::Node::Expression::Value
- Inherits:
-
Object
- Object
- SQLTree::Node::Expression::Value
- Defined in:
- lib/active_record/turntable/sql_tree_patch.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.parse(tokens) ⇒ Object
281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/active_record/turntable/sql_tree_patch.rb', line 281 def self.parse(tokens) case tokens.next when SQLTree::Token::String, SQLTree::Token::Number SQLTree::Node::Expression::Value.new(tokens.current.literal) when SQLTree::Token::NULL SQLTree::Node::Expression::Value.new(nil) when SQLTree::Token::TRUE SQLTree::Node::Expression::Value.new(true) when SQLTree::Token::FALSE SQLTree::Node::Expression::Value.new(false) else raise SQLTree::Parser::UnexpectedToken.new(tokens.current, :literal) end end |
Instance Method Details
#to_sql(options = {}) ⇒ Object
268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/active_record/turntable/sql_tree_patch.rb', line 268 def to_sql( = {}) case value when nil; 'NULL' when true; 'TRUE' when false; 'FALSE' when String; quote_str(@value) when Numeric; @value.to_s when Date; @value.strftime("'%Y-%m-%d'") when DateTime, Time; @value.strftime("'%Y-%m-%d %H:%M:%S'") else raise "Don't know how te represent this value in SQL!" end end |