Skip to content

Commit

Permalink
PgQuery.parse: Support complex queries with deeply nested ASTs
Browse files Browse the repository at this point in the history
Depends on protocolbuffers/protobuf#9218, until
that is merged this can only be used with a custom built protobuf gem.

Fixes #209
  • Loading branch information
lfittl committed Nov 13, 2021
1 parent 195126e commit c60464a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/pg_query/parse.rb
Expand Up @@ -3,7 +3,13 @@ def self.parse(query)
result, stderr = parse_protobuf(query)

begin
result = PgQuery::ParseResult.decode(result)
result = if PgQuery::ParseResult.method(:decode).arity == 1
PgQuery::ParseResult.decode(result)
elsif PgQuery::ParseResult.method(:decode).arity == -1
PgQuery::ParseResult.decode(result, max_recursion_depth: 100)
else
raise ArgumentError.new('Unsupported protobuf Ruby API')
end
rescue Google::Protobuf::ParseError => e
raise PgQuery::ParseError.new(format('Failed to parse tree: %s', e.message), __FILE__, __LINE__, -1)
end
Expand Down

0 comments on commit c60464a

Please sign in to comment.