sql-parser2 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -77,6 +77,7 @@ rule
77
77
  CURRENT_USER { [:CURRENT_USER, text] }
78
78
  VALUES { [:VALUES, text] }
79
79
  SET { [:SET, text] }
80
+ LIMIT { [:LIMIT, text] }
80
81
 
81
82
  # tokens
82
83
  E { [:E, text] }
@@ -198,6 +198,9 @@ class SQLParser::Parser < Racc::Parser
198
198
  when (text = @ss.scan(/SET/i))
199
199
  action { [:SET, text] }
200
200
 
201
+ when (text = @ss.scan(/LIMIT/i))
202
+ action { [:LIMIT, text] }
203
+
201
204
  when (text = @ss.scan(/E/i))
202
205
  action { [:E, text] }
203
206
 
@@ -43,7 +43,8 @@ module SQLParser
43
43
  def visit_DirectSelect(o)
44
44
  [
45
45
  o.query_expression,
46
- o.order_by
46
+ o.order_by,
47
+ o.limit_clause
47
48
  ].compact.collect { |e| visit(e) }.join(' ')
48
49
  end
49
50
 
@@ -51,6 +52,10 @@ module SQLParser
51
52
  "ORDER BY #{arrayize(o.sort_specification)}"
52
53
  end
53
54
 
55
+ def visit_Limit(o)
56
+ "LIMIT #{o.limit_count}"
57
+ end
58
+
54
59
  def visit_Subquery(o)
55
60
  "(#{visit(o.query_specification)})"
56
61
  end
@@ -80,13 +80,15 @@ module SQLParser
80
80
 
81
81
  class DirectSelect < Node
82
82
 
83
- def initialize(query_expression, order_by)
83
+ def initialize(query_expression, order_by, limit_clause = nil)
84
84
  @query_expression = query_expression
85
85
  @order_by = order_by
86
+ @limit_clause = limit_clause
86
87
  end
87
88
 
88
89
  attr_reader :query_expression
89
90
  attr_reader :order_by
91
+ attr_reader :limit_clause
90
92
 
91
93
  end
92
94
 
@@ -100,6 +102,16 @@ module SQLParser
100
102
 
101
103
  end
102
104
 
105
+ class Limit < Node
106
+
107
+ def initialize(limit_count)
108
+ @limit_count = limit_count
109
+ end
110
+
111
+ attr_reader :limit_count
112
+
113
+ end
114
+
103
115
  class Subquery < Node
104
116
 
105
117
  def initialize(query_specification)
@@ -1,5 +1,5 @@
1
1
  module SQLParser
2
2
 
3
- VERSION = '0.0.3'
3
+ VERSION = '0.0.4'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sql-parser2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dray Lacy