sql-parser-vlad 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sql-parser/parser.racc +7 -1
- data/lib/sql-parser/parser.racc.rb +800 -782
- data/lib/sql-parser/parser.rex +2 -0
- data/lib/sql-parser/parser.rex.rb +6 -0
- data/lib/sql-parser/sql_visitor.rb +10 -1
- data/lib/sql-parser/statement.rb +13 -1
- data/lib/sql-parser/version.rb +1 -1
- metadata +1 -1
data/lib/sql-parser/parser.rex
CHANGED
@@ -198,6 +198,12 @@ class SQLParser::Parser < Racc::Parser
|
|
198
198
|
when (text = @ss.scan(/VALUES/i))
|
199
199
|
action { [:VALUES, text] }
|
200
200
|
|
201
|
+
when (text = @ss.scan(/LIMIT/i))
|
202
|
+
action { [:LIMIT, text] }
|
203
|
+
|
204
|
+
when (text = @ss.scan(/OFFSET/i))
|
205
|
+
action { [:OFFSET, text] }
|
206
|
+
|
201
207
|
when (text = @ss.scan(/E/i))
|
202
208
|
action { [:E, text] }
|
203
209
|
|
@@ -60,7 +60,8 @@ module SQLParser
|
|
60
60
|
o.from_clause,
|
61
61
|
o.where_clause,
|
62
62
|
o.group_by_clause,
|
63
|
-
o.having_clause
|
63
|
+
o.having_clause,
|
64
|
+
o.limit_clause
|
64
65
|
].compact.collect { |e| visit(e) }.join(' ')
|
65
66
|
end
|
66
67
|
|
@@ -92,6 +93,14 @@ module SQLParser
|
|
92
93
|
"WHERE #{visit(o.search_condition)}"
|
93
94
|
end
|
94
95
|
|
96
|
+
def visit_LimitClause(o)
|
97
|
+
if o.offset.nil?
|
98
|
+
"LIMIT #{o.limit}"
|
99
|
+
else
|
100
|
+
"LIMIT #{o.limit} OFFSET #{o.offset}"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
95
104
|
def visit_On(o)
|
96
105
|
"ON #{visit(o.search_condition)}"
|
97
106
|
end
|
data/lib/sql-parser/statement.rb
CHANGED
@@ -111,17 +111,19 @@ module SQLParser
|
|
111
111
|
|
112
112
|
class TableExpression < Node
|
113
113
|
|
114
|
-
def initialize(from_clause, where_clause = nil, group_by_clause = nil, having_clause = nil)
|
114
|
+
def initialize(from_clause, where_clause = nil, group_by_clause = nil, having_clause = nil, limit_clause = nil)
|
115
115
|
@from_clause = from_clause
|
116
116
|
@where_clause = where_clause
|
117
117
|
@group_by_clause = group_by_clause
|
118
118
|
@having_clause = having_clause
|
119
|
+
@limit_clause = limit_clause
|
119
120
|
end
|
120
121
|
|
121
122
|
attr_reader :from_clause
|
122
123
|
attr_reader :where_clause
|
123
124
|
attr_reader :group_by_clause
|
124
125
|
attr_reader :having_clause
|
126
|
+
attr_reader :limit_clause
|
125
127
|
|
126
128
|
end
|
127
129
|
|
@@ -191,6 +193,16 @@ module SQLParser
|
|
191
193
|
|
192
194
|
end
|
193
195
|
|
196
|
+
class LimitClause < Node
|
197
|
+
|
198
|
+
def initialize(limit, offset)
|
199
|
+
@limit = limit
|
200
|
+
@offset = offset
|
201
|
+
end
|
202
|
+
|
203
|
+
attr_reader :limit, :offset
|
204
|
+
end
|
205
|
+
|
194
206
|
class On < Node
|
195
207
|
|
196
208
|
def initialize(search_condition)
|
data/lib/sql-parser/version.rb
CHANGED