pg_query 2.1.2 → 2.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/ext/pg_query/extconf.rb +7 -1
- data/ext/pg_query/pg_query_ruby.sym +0 -1
- data/ext/pg_query/pg_query_ruby_freebsd.sym +2 -0
- data/lib/pg_query/filter_columns.rb +5 -3
- data/lib/pg_query/parse.rb +15 -2
- data/lib/pg_query/truncate.rb +53 -7
- data/lib/pg_query/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe9be3677078ec8a4990a53c9e0aa74c21f2a66672fe3a0990b23c00a6da34af
|
4
|
+
data.tar.gz: 31e3bbcdfac0cd27a1553ac0f0d33f7cbd7e36ce8c5080f29a314da67adcc76a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a8e0ef4b389446f952988903aa6b5772c6caabaea80d97e4f40affdf0830227285e60af0848a2786fcdab98232e96a5a75d3b5f73b24378b9ef67e9d24d9bf8
|
7
|
+
data.tar.gz: ffd90f7bdf9a155cb7a014eaf9c8bfbf06d0905e70bc5dadc739015c4d11695ead10ae1960e1bcee44e3d81d3c8a5b7d47b6705a32ef93daa8d909b328ee9602
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,23 @@
|
|
4
4
|
|
5
5
|
* ...
|
6
6
|
|
7
|
+
## 2.1.4 2022-09-19
|
8
|
+
|
9
|
+
* Truncate: Simplify VALUES(...) lists
|
10
|
+
* Truncate: Correctly handle UPDATE and ON CONFLICT target lists
|
11
|
+
* Support complex queries with deeply nested ASTs ([#238](https://github.com/pganalyze/pg_query/pull/238))
|
12
|
+
* Find table references inside type casts
|
13
|
+
* Find function calls referenced in expression indexes ([#249](https://github.com/pganalyze/pg_query/pull/249))
|
14
|
+
* Drop `Init_pg_query` from exported symbol map ([#256](https://github.com/pganalyze/pg_query/pull/256))
|
15
|
+
|
16
|
+
## 2.1.3 2022-01-28
|
17
|
+
|
18
|
+
* Track tables in EXCEPT and INTERSECT queries ([#239](https://github.com/pganalyze/pg_query/pull/239))
|
19
|
+
* Get filter_columns working with UNION/EXCEPT/INTERSECT ([#240](https://github.com/pganalyze/pg_query/pull/240))
|
20
|
+
* Update google-protobuf to address CVE scanner complaints
|
21
|
+
- Note that none of the CVEs apply to pg_query, but this avoids unnecessary errors when
|
22
|
+
the google-protobuf dependency is pulled in
|
23
|
+
|
7
24
|
|
8
25
|
## 2.1.2 2021-11-12
|
9
26
|
|
data/ext/pg_query/extconf.rb
CHANGED
@@ -11,7 +11,13 @@ $CFLAGS << " -fvisibility=hidden -O3 -Wall -fno-strict-aliasing -fwrapv -fstack-
|
|
11
11
|
|
12
12
|
$INCFLAGS = "-I#{File.join(__dir__, 'include')} " + $INCFLAGS
|
13
13
|
|
14
|
-
SYMFILE =
|
14
|
+
SYMFILE =
|
15
|
+
if RUBY_PLATFORM =~ /freebsd/
|
16
|
+
File.join(__dir__, 'pg_query_ruby_freebsd.sym')
|
17
|
+
else
|
18
|
+
File.join(__dir__, 'pg_query_ruby.sym')
|
19
|
+
end
|
20
|
+
|
15
21
|
if RUBY_PLATFORM =~ /darwin/
|
16
22
|
$DLDFLAGS << " -Wl,-exported_symbols_list #{SYMFILE}" unless defined?(::Rubinius)
|
17
23
|
else
|
@@ -42,14 +42,16 @@ module PgQuery
|
|
42
42
|
statements << item.common_table_expr.ctequery if item.node == :common_table_expr
|
43
43
|
end
|
44
44
|
end
|
45
|
-
when :SETOP_UNION
|
46
|
-
statements << statement.select_stmt.larg if statement.select_stmt.larg
|
47
|
-
statements << statement.select_stmt.rarg if statement.select_stmt.rarg
|
45
|
+
when :SETOP_UNION, :SETOP_EXCEPT, :SETOP_INTERSECT
|
46
|
+
statements << PgQuery::Node.new(select_stmt: statement.select_stmt.larg) if statement.select_stmt.larg
|
47
|
+
statements << PgQuery::Node.new(select_stmt: statement.select_stmt.rarg) if statement.select_stmt.rarg
|
48
48
|
end
|
49
49
|
when :update_stmt
|
50
50
|
condition_items << statement.update_stmt.where_clause if statement.update_stmt.where_clause
|
51
51
|
when :delete_stmt
|
52
52
|
condition_items << statement.delete_stmt.where_clause if statement.delete_stmt.where_clause
|
53
|
+
when :index_stmt
|
54
|
+
condition_items << statement.index_stmt.where_clause if statement.index_stmt.where_clause
|
53
55
|
end
|
54
56
|
end
|
55
57
|
|
data/lib/pg_query/parse.rb
CHANGED
@@ -3,7 +3,13 @@ module PgQuery
|
|
3
3
|
result, stderr = parse_protobuf(query)
|
4
4
|
|
5
5
|
begin
|
6
|
-
result = PgQuery::ParseResult.decode
|
6
|
+
result = if PgQuery::ParseResult.method(:decode).arity == 1
|
7
|
+
PgQuery::ParseResult.decode(result)
|
8
|
+
elsif PgQuery::ParseResult.method(:decode).arity == -1
|
9
|
+
PgQuery::ParseResult.decode(result, recursion_limit: 1_000)
|
10
|
+
else
|
11
|
+
raise ArgumentError, 'Unsupported protobuf Ruby API'
|
12
|
+
end
|
7
13
|
rescue Google::Protobuf::ParseError => e
|
8
14
|
raise PgQuery::ParseError.new(format('Failed to parse tree: %s', e.message), __FILE__, __LINE__, -1)
|
9
15
|
end
|
@@ -123,7 +129,7 @@ module PgQuery
|
|
123
129
|
(statement.select_stmt.from_clause || []).each do |item|
|
124
130
|
from_clause_items << { item: item, type: :select }
|
125
131
|
end
|
126
|
-
when :SETOP_UNION
|
132
|
+
when :SETOP_UNION, :SETOP_EXCEPT, :SETOP_INTERSECT
|
127
133
|
statements << PgQuery::Node.new(select_stmt: statement.select_stmt.larg) if statement.select_stmt.larg
|
128
134
|
statements << PgQuery::Node.new(select_stmt: statement.select_stmt.rarg) if statement.select_stmt.rarg
|
129
135
|
end
|
@@ -180,6 +186,11 @@ module PgQuery
|
|
180
186
|
statements << statement.view_stmt.query
|
181
187
|
when :index_stmt
|
182
188
|
from_clause_items << { item: PgQuery::Node.new(range_var: statement.index_stmt.relation), type: :ddl }
|
189
|
+
statement.index_stmt.index_params.each do |p|
|
190
|
+
next if p.index_elem.expr.nil?
|
191
|
+
subselect_items << p.index_elem.expr
|
192
|
+
end
|
193
|
+
subselect_items << statement.index_stmt.where_clause if statement.index_stmt.where_clause
|
183
194
|
when :create_trig_stmt
|
184
195
|
from_clause_items << { item: PgQuery::Node.new(range_var: statement.create_trig_stmt.relation), type: :ddl }
|
185
196
|
when :rule_stmt
|
@@ -274,6 +285,8 @@ module PgQuery
|
|
274
285
|
subselect_items.concat(next_item.case_expr.args.map { |arg| arg.case_when.expr })
|
275
286
|
subselect_items.concat(next_item.case_expr.args.map { |arg| arg.case_when.result })
|
276
287
|
subselect_items << next_item.case_expr.defresult
|
288
|
+
when :type_cast
|
289
|
+
subselect_items << next_item.type_cast.arg
|
277
290
|
end
|
278
291
|
end
|
279
292
|
|
data/lib/pg_query/truncate.rb
CHANGED
@@ -32,6 +32,12 @@ module PgQuery
|
|
32
32
|
)
|
33
33
|
when :where_clause
|
34
34
|
node.where_clause = dummy_column_ref
|
35
|
+
when :values_lists
|
36
|
+
node.values_lists.replace(
|
37
|
+
[
|
38
|
+
PgQuery::Node.new(list: PgQuery::List.new(items: [dummy_column_ref]))
|
39
|
+
]
|
40
|
+
)
|
35
41
|
when :ctequery
|
36
42
|
node.ctequery = PgQuery::Node.new(select_stmt: PgQuery::SelectStmt.new(where_clause: dummy_column_ref, op: :SETOP_NONE))
|
37
43
|
when :cols
|
@@ -58,7 +64,11 @@ module PgQuery
|
|
58
64
|
case k
|
59
65
|
when :target_list
|
60
66
|
next unless node.is_a?(PgQuery::SelectStmt) || node.is_a?(PgQuery::UpdateStmt) || node.is_a?(PgQuery::OnConflictClause)
|
61
|
-
length =
|
67
|
+
length = if node.is_a?(PgQuery::SelectStmt)
|
68
|
+
select_target_list_len(v)
|
69
|
+
else # UpdateStmt / OnConflictClause
|
70
|
+
update_target_list_len(v)
|
71
|
+
end
|
62
72
|
truncations << PossibleTruncation.new(location, :target_list, length, true)
|
63
73
|
when :where_clause
|
64
74
|
next unless node.is_a?(PgQuery::SelectStmt) || node.is_a?(PgQuery::UpdateStmt) || node.is_a?(PgQuery::DeleteStmt) ||
|
@@ -67,23 +77,59 @@ module PgQuery
|
|
67
77
|
|
68
78
|
length = PgQuery.deparse_expr(v).size
|
69
79
|
truncations << PossibleTruncation.new(location, :where_clause, length, false)
|
80
|
+
when :values_lists
|
81
|
+
length = select_values_lists_len(v)
|
82
|
+
truncations << PossibleTruncation.new(location, :values_lists, length, false)
|
70
83
|
when :ctequery
|
71
84
|
next unless node.is_a?(PgQuery::CommonTableExpr)
|
72
85
|
length = PgQuery.deparse_stmt(v[v.node.to_s]).size
|
73
86
|
truncations << PossibleTruncation.new(location, :ctequery, length, false)
|
74
87
|
when :cols
|
75
88
|
next unless node.is_a?(PgQuery::InsertStmt)
|
76
|
-
length =
|
77
|
-
PgQuery::InsertStmt.new(
|
78
|
-
relation: PgQuery::RangeVar.new(relname: 'x', inh: true),
|
79
|
-
cols: v.to_a
|
80
|
-
)
|
81
|
-
).size - 31 # "INSERT INTO x () DEFAULT VALUES".size
|
89
|
+
length = cols_len(v)
|
82
90
|
truncations << PossibleTruncation.new(location, :cols, length, true)
|
83
91
|
end
|
84
92
|
end
|
85
93
|
|
86
94
|
truncations
|
87
95
|
end
|
96
|
+
|
97
|
+
def select_target_list_len(target_list)
|
98
|
+
deparsed_len = PgQuery.deparse_stmt(
|
99
|
+
PgQuery::SelectStmt.new(
|
100
|
+
target_list: target_list.to_a, op: :SETOP_NONE
|
101
|
+
)
|
102
|
+
).size
|
103
|
+
deparsed_len - 7 # 'SELECT '.size
|
104
|
+
end
|
105
|
+
|
106
|
+
def select_values_lists_len(values_lists)
|
107
|
+
deparsed_len = PgQuery.deparse_stmt(
|
108
|
+
PgQuery::SelectStmt.new(
|
109
|
+
values_lists: values_lists.to_a, op: :SETOP_NONE
|
110
|
+
)
|
111
|
+
).size
|
112
|
+
deparsed_len - 7 # 'SELECT '.size
|
113
|
+
end
|
114
|
+
|
115
|
+
def update_target_list_len(target_list)
|
116
|
+
deparsed_len = PgQuery.deparse_stmt(
|
117
|
+
PgQuery::UpdateStmt.new(
|
118
|
+
target_list: target_list.to_a,
|
119
|
+
relation: PgQuery::RangeVar.new(relname: 'x', inh: true)
|
120
|
+
)
|
121
|
+
).size
|
122
|
+
deparsed_len - 13 # 'UPDATE x SET '.size
|
123
|
+
end
|
124
|
+
|
125
|
+
def cols_len(cols)
|
126
|
+
deparsed_len = PgQuery.deparse_stmt(
|
127
|
+
PgQuery::InsertStmt.new(
|
128
|
+
relation: PgQuery::RangeVar.new(relname: 'x', inh: true),
|
129
|
+
cols: cols.to_a
|
130
|
+
)
|
131
|
+
).size
|
132
|
+
deparsed_len - 31 # "INSERT INTO x () DEFAULT VALUES".size
|
133
|
+
end
|
88
134
|
end
|
89
135
|
end
|
data/lib/pg_query/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg_query
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lukas Fittl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 3.
|
75
|
+
version: 3.19.2
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 3.
|
82
|
+
version: 3.19.2
|
83
83
|
description: Parses SQL queries using a copy of the PostgreSQL server query parser
|
84
84
|
email: lukas@fittl.com
|
85
85
|
executables: []
|
@@ -484,6 +484,7 @@ files:
|
|
484
484
|
- ext/pg_query/pg_query_readfuncs_protobuf.c
|
485
485
|
- ext/pg_query/pg_query_ruby.c
|
486
486
|
- ext/pg_query/pg_query_ruby.sym
|
487
|
+
- ext/pg_query/pg_query_ruby_freebsd.sym
|
487
488
|
- ext/pg_query/pg_query_scan.c
|
488
489
|
- ext/pg_query/pg_query_split.c
|
489
490
|
- ext/pg_query/protobuf-c.c
|