sql_tree 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/README.rdoc +6 -5
- data/lib/sql_tree.rb +11 -3
- data/lib/sql_tree/node.rb +75 -4
- data/lib/sql_tree/node/delete_query.rb +19 -6
- data/lib/sql_tree/node/expression.rb +431 -163
- data/lib/sql_tree/node/insert_query.rb +13 -17
- data/lib/sql_tree/node/join.rb +8 -12
- data/lib/sql_tree/node/ordering.rb +4 -3
- data/lib/sql_tree/node/select_declaration.rb +62 -0
- data/lib/sql_tree/node/select_query.rb +27 -46
- data/lib/sql_tree/node/source.rb +5 -8
- data/lib/sql_tree/node/table_reference.rb +7 -10
- data/lib/sql_tree/node/update_query.rb +73 -12
- data/lib/sql_tree/parser.rb +70 -14
- data/lib/sql_tree/token.rb +48 -22
- data/lib/sql_tree/tokenizer.rb +23 -16
- data/spec/integration/parse_and_generate_spec.rb +8 -0
- data/spec/lib/matchers.rb +3 -2
- data/spec/unit/delete_query_spec.rb +2 -2
- data/spec/unit/expression_node_spec.rb +24 -23
- data/spec/unit/insert_query_spec.rb +8 -8
- data/spec/unit/leaf_node_spec.rb +17 -17
- data/spec/unit/select_query_spec.rb +4 -4
- data/spec/unit/tokenizer_spec.rb +17 -21
- data/spec/unit/update_query_spec.rb +6 -6
- data/sql_tree.gemspec +3 -3
- metadata +4 -8
- data/lib/sql_tree/node/assignment.rb +0 -22
- data/lib/sql_tree/node/field.rb +0 -49
- data/lib/sql_tree/node/select_expression.rb +0 -45
- data/lib/sql_tree/node/value.rb +0 -33
- data/lib/sql_tree/node/variable.rb +0 -31
data/lib/sql_tree/node/value.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
module SQLTree::Node
|
2
|
-
|
3
|
-
class Value < Base
|
4
|
-
attr_accessor :value
|
5
|
-
|
6
|
-
def initialize(value)
|
7
|
-
@value = value
|
8
|
-
end
|
9
|
-
|
10
|
-
def to_sql
|
11
|
-
case value
|
12
|
-
when nil then 'NULL'
|
13
|
-
when String then quote_str(@value)
|
14
|
-
else @value.to_s
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def ==(other)
|
19
|
-
other.kind_of?(self.class) && other.value == self.value
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.parse(tokens)
|
23
|
-
case tokens.next
|
24
|
-
when SQLTree::Token::String, SQLTree::Token::Number
|
25
|
-
SQLTree::Node::Value.new(tokens.current.literal)
|
26
|
-
when SQLTree::Token::NULL
|
27
|
-
SQLTree::Node::Value.new(nil)
|
28
|
-
else
|
29
|
-
raise SQLTree::Parser::UnexpectedToken.new(tokens.current, :literal)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module SQLTree::Node
|
2
|
-
|
3
|
-
class Variable < Base
|
4
|
-
|
5
|
-
attr_accessor :name
|
6
|
-
|
7
|
-
def initialize(name)
|
8
|
-
@name = name
|
9
|
-
end
|
10
|
-
|
11
|
-
def to_sql
|
12
|
-
quote_var(@name)
|
13
|
-
end
|
14
|
-
|
15
|
-
def ==(other)
|
16
|
-
other.class == self.class && other.name == self.name
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.parse(tokens)
|
20
|
-
if SQLTree::Token::Variable === tokens.peek
|
21
|
-
if tokens.peek(2) == SQLTree::Token::DOT
|
22
|
-
SQLTree::Node::Field.parse(tokens)
|
23
|
-
else
|
24
|
-
self.new(tokens.next.literal)
|
25
|
-
end
|
26
|
-
else
|
27
|
-
raise SQLTree::Parser::UnexpectedToken.new(tokens.peek, :variable)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|