pg_query 6.1.0 → 6.2.1
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 +38 -1
- data/README.md +1 -1
- data/Rakefile +3 -2
- data/ext/pg_query/extconf.rb +2 -2
- data/ext/pg_query/include/pg_query.h +32 -2
- data/ext/pg_query/include/postgres/access/amapi.h +1 -1
- data/ext/pg_query/include/postgres/access/slru.h +1 -1
- data/ext/pg_query/include/postgres/access/tableam.h +11 -4
- data/ext/pg_query/include/postgres/access/xlog.h +1 -0
- data/ext/pg_query/include/postgres/access/xlogdefs.h +2 -1
- data/ext/pg_query/include/postgres/commands/defrem.h +1 -1
- data/ext/pg_query/include/postgres/commands/trigger.h +18 -0
- data/ext/pg_query/include/postgres/executor/executor.h +4 -0
- data/ext/pg_query/include/postgres/mb/pg_wchar.h +2 -0
- data/ext/pg_query/include/postgres/miscadmin.h +2 -1
- data/ext/pg_query/include/postgres/nodes/execnodes.h +6 -8
- data/ext/pg_query/include/postgres/nodes/pathnodes.h +1 -2
- data/ext/pg_query/include/postgres/pg_config.h +10 -9
- data/ext/pg_query/include/postgres/pg_config_manual.h +2 -0
- data/ext/pg_query/include/postgres/port/atomics/generic-gcc.h +10 -2
- data/ext/pg_query/include/postgres/port/pg_iovec.h +9 -3
- data/ext/pg_query/include/postgres/replication/reorderbuffer.h +29 -9
- data/ext/pg_query/include/postgres/replication/slot.h +2 -0
- data/ext/pg_query/include/postgres/utils/elog.h +1 -0
- data/ext/pg_query/include/postgres/utils/guc.h +1 -1
- data/ext/pg_query/include/postgres/utils/guc_hooks.h +0 -2
- data/ext/pg_query/include/postgres/utils/pg_locale.h +5 -0
- data/ext/pg_query/include/postgres_deparse.h +34 -0
- data/ext/pg_query/include/protobuf/pg_query.pb-c.h +673 -516
- data/ext/pg_query/pg_query.pb-c.c +488 -0
- data/ext/pg_query/pg_query_deparse.c +148 -15
- data/ext/pg_query/pg_query_internal.h +9 -8
- data/ext/pg_query/pg_query_is_utility_stmt.c +70 -0
- data/ext/pg_query/pg_query_normalize.c +3 -0
- data/ext/pg_query/pg_query_raw_tree_walker_supports.c +117 -0
- data/ext/pg_query/pg_query_ruby.c +150 -0
- data/ext/pg_query/pg_query_summary.c +941 -0
- data/ext/pg_query/pg_query_summary.h +109 -0
- data/ext/pg_query/pg_query_summary_statement_type.c +797 -0
- data/ext/pg_query/pg_query_summary_truncate.c +530 -0
- data/ext/pg_query/postgres_deparse.c +4481 -3870
- data/ext/pg_query/src_backend_catalog_namespace.c +29 -0
- data/ext/pg_query/src_backend_nodes_bitmapset.c +84 -1
- data/ext/pg_query/src_backend_nodes_list.c +60 -1
- data/ext/pg_query/src_backend_parser_gram.c +739 -732
- data/ext/pg_query/src_backend_utils_activity_pgstat_database.c +2 -2
- data/ext/pg_query/src_backend_utils_error_elog.c +11 -0
- data/ext/pg_query/src_backend_utils_mb_mbutils.c +43 -4
- data/ext/pg_query/src_backend_utils_mmgr_alignedalloc.c +22 -7
- data/ext/pg_query/src_backend_utils_mmgr_aset.c +3 -3
- data/ext/pg_query/src_backend_utils_mmgr_bump.c +1 -1
- data/ext/pg_query/src_common_stringinfo.c +20 -0
- data/ext/pg_query/src_common_wchar.c +46 -6
- data/lib/pg_query/deparse.rb +29 -8
- data/lib/pg_query/parse.rb +19 -0
- data/lib/pg_query/pg_query_pb.rb +7 -2
- data/lib/pg_query/split.rb +20 -0
- data/lib/pg_query/treewalker.rb +9 -7
- data/lib/pg_query/version.rb +1 -1
- data/lib/pg_query.rb +1 -0
- metadata +10 -3
- data/ext/pg_query/postgres_deparse.h +0 -9
|
@@ -12247,6 +12247,75 @@ void pg_query__scan_token__free_unpacked
|
|
|
12247
12247
|
assert(message->base.descriptor == &pg_query__scan_token__descriptor);
|
|
12248
12248
|
protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
|
|
12249
12249
|
}
|
|
12250
|
+
void pg_query__summary_result__table__init
|
|
12251
|
+
(PgQuery__SummaryResult__Table *message)
|
|
12252
|
+
{
|
|
12253
|
+
static const PgQuery__SummaryResult__Table init_value = PG_QUERY__SUMMARY_RESULT__TABLE__INIT;
|
|
12254
|
+
*message = init_value;
|
|
12255
|
+
}
|
|
12256
|
+
void pg_query__summary_result__aliases_entry__init
|
|
12257
|
+
(PgQuery__SummaryResult__AliasesEntry *message)
|
|
12258
|
+
{
|
|
12259
|
+
static const PgQuery__SummaryResult__AliasesEntry init_value = PG_QUERY__SUMMARY_RESULT__ALIASES_ENTRY__INIT;
|
|
12260
|
+
*message = init_value;
|
|
12261
|
+
}
|
|
12262
|
+
void pg_query__summary_result__function__init
|
|
12263
|
+
(PgQuery__SummaryResult__Function *message)
|
|
12264
|
+
{
|
|
12265
|
+
static const PgQuery__SummaryResult__Function init_value = PG_QUERY__SUMMARY_RESULT__FUNCTION__INIT;
|
|
12266
|
+
*message = init_value;
|
|
12267
|
+
}
|
|
12268
|
+
void pg_query__summary_result__filter_column__init
|
|
12269
|
+
(PgQuery__SummaryResult__FilterColumn *message)
|
|
12270
|
+
{
|
|
12271
|
+
static const PgQuery__SummaryResult__FilterColumn init_value = PG_QUERY__SUMMARY_RESULT__FILTER_COLUMN__INIT;
|
|
12272
|
+
*message = init_value;
|
|
12273
|
+
}
|
|
12274
|
+
void pg_query__summary_result__init
|
|
12275
|
+
(PgQuery__SummaryResult *message)
|
|
12276
|
+
{
|
|
12277
|
+
static const PgQuery__SummaryResult init_value = PG_QUERY__SUMMARY_RESULT__INIT;
|
|
12278
|
+
*message = init_value;
|
|
12279
|
+
}
|
|
12280
|
+
size_t pg_query__summary_result__get_packed_size
|
|
12281
|
+
(const PgQuery__SummaryResult *message)
|
|
12282
|
+
{
|
|
12283
|
+
assert(message->base.descriptor == &pg_query__summary_result__descriptor);
|
|
12284
|
+
return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
|
|
12285
|
+
}
|
|
12286
|
+
size_t pg_query__summary_result__pack
|
|
12287
|
+
(const PgQuery__SummaryResult *message,
|
|
12288
|
+
uint8_t *out)
|
|
12289
|
+
{
|
|
12290
|
+
assert(message->base.descriptor == &pg_query__summary_result__descriptor);
|
|
12291
|
+
return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
|
|
12292
|
+
}
|
|
12293
|
+
size_t pg_query__summary_result__pack_to_buffer
|
|
12294
|
+
(const PgQuery__SummaryResult *message,
|
|
12295
|
+
ProtobufCBuffer *buffer)
|
|
12296
|
+
{
|
|
12297
|
+
assert(message->base.descriptor == &pg_query__summary_result__descriptor);
|
|
12298
|
+
return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
|
|
12299
|
+
}
|
|
12300
|
+
PgQuery__SummaryResult *
|
|
12301
|
+
pg_query__summary_result__unpack
|
|
12302
|
+
(ProtobufCAllocator *allocator,
|
|
12303
|
+
size_t len,
|
|
12304
|
+
const uint8_t *data)
|
|
12305
|
+
{
|
|
12306
|
+
return (PgQuery__SummaryResult *)
|
|
12307
|
+
protobuf_c_message_unpack (&pg_query__summary_result__descriptor,
|
|
12308
|
+
allocator, len, data);
|
|
12309
|
+
}
|
|
12310
|
+
void pg_query__summary_result__free_unpacked
|
|
12311
|
+
(PgQuery__SummaryResult *message,
|
|
12312
|
+
ProtobufCAllocator *allocator)
|
|
12313
|
+
{
|
|
12314
|
+
if(!message)
|
|
12315
|
+
return;
|
|
12316
|
+
assert(message->base.descriptor == &pg_query__summary_result__descriptor);
|
|
12317
|
+
protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
|
|
12318
|
+
}
|
|
12250
12319
|
static const ProtobufCFieldDescriptor pg_query__parse_result__field_descriptors[2] =
|
|
12251
12320
|
{
|
|
12252
12321
|
{
|
|
@@ -40673,6 +40742,425 @@ const ProtobufCMessageDescriptor pg_query__scan_token__descriptor =
|
|
|
40673
40742
|
(ProtobufCMessageInit) pg_query__scan_token__init,
|
|
40674
40743
|
NULL,NULL,NULL /* reserved[123] */
|
|
40675
40744
|
};
|
|
40745
|
+
static const ProtobufCFieldDescriptor pg_query__summary_result__table__field_descriptors[4] =
|
|
40746
|
+
{
|
|
40747
|
+
{
|
|
40748
|
+
"name",
|
|
40749
|
+
1,
|
|
40750
|
+
PROTOBUF_C_LABEL_NONE,
|
|
40751
|
+
PROTOBUF_C_TYPE_STRING,
|
|
40752
|
+
0, /* quantifier_offset */
|
|
40753
|
+
offsetof(PgQuery__SummaryResult__Table, name),
|
|
40754
|
+
NULL,
|
|
40755
|
+
&protobuf_c_empty_string,
|
|
40756
|
+
0, /* flags */
|
|
40757
|
+
0,NULL,NULL /* reserved1,reserved2, etc */
|
|
40758
|
+
},
|
|
40759
|
+
{
|
|
40760
|
+
"schema_name",
|
|
40761
|
+
2,
|
|
40762
|
+
PROTOBUF_C_LABEL_NONE,
|
|
40763
|
+
PROTOBUF_C_TYPE_STRING,
|
|
40764
|
+
0, /* quantifier_offset */
|
|
40765
|
+
offsetof(PgQuery__SummaryResult__Table, schema_name),
|
|
40766
|
+
NULL,
|
|
40767
|
+
&protobuf_c_empty_string,
|
|
40768
|
+
0, /* flags */
|
|
40769
|
+
0,NULL,NULL /* reserved1,reserved2, etc */
|
|
40770
|
+
},
|
|
40771
|
+
{
|
|
40772
|
+
"table_name",
|
|
40773
|
+
3,
|
|
40774
|
+
PROTOBUF_C_LABEL_NONE,
|
|
40775
|
+
PROTOBUF_C_TYPE_STRING,
|
|
40776
|
+
0, /* quantifier_offset */
|
|
40777
|
+
offsetof(PgQuery__SummaryResult__Table, table_name),
|
|
40778
|
+
NULL,
|
|
40779
|
+
&protobuf_c_empty_string,
|
|
40780
|
+
0, /* flags */
|
|
40781
|
+
0,NULL,NULL /* reserved1,reserved2, etc */
|
|
40782
|
+
},
|
|
40783
|
+
{
|
|
40784
|
+
"context",
|
|
40785
|
+
4,
|
|
40786
|
+
PROTOBUF_C_LABEL_NONE,
|
|
40787
|
+
PROTOBUF_C_TYPE_ENUM,
|
|
40788
|
+
0, /* quantifier_offset */
|
|
40789
|
+
offsetof(PgQuery__SummaryResult__Table, context),
|
|
40790
|
+
&pg_query__summary_result__context__descriptor,
|
|
40791
|
+
NULL,
|
|
40792
|
+
0, /* flags */
|
|
40793
|
+
0,NULL,NULL /* reserved1,reserved2, etc */
|
|
40794
|
+
},
|
|
40795
|
+
};
|
|
40796
|
+
static const unsigned pg_query__summary_result__table__field_indices_by_name[] = {
|
|
40797
|
+
3, /* field[3] = context */
|
|
40798
|
+
0, /* field[0] = name */
|
|
40799
|
+
1, /* field[1] = schema_name */
|
|
40800
|
+
2, /* field[2] = table_name */
|
|
40801
|
+
};
|
|
40802
|
+
static const ProtobufCIntRange pg_query__summary_result__table__number_ranges[1 + 1] =
|
|
40803
|
+
{
|
|
40804
|
+
{ 1, 0 },
|
|
40805
|
+
{ 0, 4 }
|
|
40806
|
+
};
|
|
40807
|
+
const ProtobufCMessageDescriptor pg_query__summary_result__table__descriptor =
|
|
40808
|
+
{
|
|
40809
|
+
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
|
|
40810
|
+
"pg_query.SummaryResult.Table",
|
|
40811
|
+
"Table",
|
|
40812
|
+
"PgQuery__SummaryResult__Table",
|
|
40813
|
+
"pg_query",
|
|
40814
|
+
sizeof(PgQuery__SummaryResult__Table),
|
|
40815
|
+
4,
|
|
40816
|
+
pg_query__summary_result__table__field_descriptors,
|
|
40817
|
+
pg_query__summary_result__table__field_indices_by_name,
|
|
40818
|
+
1, pg_query__summary_result__table__number_ranges,
|
|
40819
|
+
(ProtobufCMessageInit) pg_query__summary_result__table__init,
|
|
40820
|
+
NULL,NULL,NULL /* reserved[123] */
|
|
40821
|
+
};
|
|
40822
|
+
static const ProtobufCFieldDescriptor pg_query__summary_result__aliases_entry__field_descriptors[2] =
|
|
40823
|
+
{
|
|
40824
|
+
{
|
|
40825
|
+
"key",
|
|
40826
|
+
1,
|
|
40827
|
+
PROTOBUF_C_LABEL_NONE,
|
|
40828
|
+
PROTOBUF_C_TYPE_STRING,
|
|
40829
|
+
0, /* quantifier_offset */
|
|
40830
|
+
offsetof(PgQuery__SummaryResult__AliasesEntry, key),
|
|
40831
|
+
NULL,
|
|
40832
|
+
&protobuf_c_empty_string,
|
|
40833
|
+
0, /* flags */
|
|
40834
|
+
0,NULL,NULL /* reserved1,reserved2, etc */
|
|
40835
|
+
},
|
|
40836
|
+
{
|
|
40837
|
+
"value",
|
|
40838
|
+
2,
|
|
40839
|
+
PROTOBUF_C_LABEL_NONE,
|
|
40840
|
+
PROTOBUF_C_TYPE_STRING,
|
|
40841
|
+
0, /* quantifier_offset */
|
|
40842
|
+
offsetof(PgQuery__SummaryResult__AliasesEntry, value),
|
|
40843
|
+
NULL,
|
|
40844
|
+
&protobuf_c_empty_string,
|
|
40845
|
+
0, /* flags */
|
|
40846
|
+
0,NULL,NULL /* reserved1,reserved2, etc */
|
|
40847
|
+
},
|
|
40848
|
+
};
|
|
40849
|
+
static const unsigned pg_query__summary_result__aliases_entry__field_indices_by_name[] = {
|
|
40850
|
+
0, /* field[0] = key */
|
|
40851
|
+
1, /* field[1] = value */
|
|
40852
|
+
};
|
|
40853
|
+
static const ProtobufCIntRange pg_query__summary_result__aliases_entry__number_ranges[1 + 1] =
|
|
40854
|
+
{
|
|
40855
|
+
{ 1, 0 },
|
|
40856
|
+
{ 0, 2 }
|
|
40857
|
+
};
|
|
40858
|
+
const ProtobufCMessageDescriptor pg_query__summary_result__aliases_entry__descriptor =
|
|
40859
|
+
{
|
|
40860
|
+
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
|
|
40861
|
+
"pg_query.SummaryResult.AliasesEntry",
|
|
40862
|
+
"AliasesEntry",
|
|
40863
|
+
"PgQuery__SummaryResult__AliasesEntry",
|
|
40864
|
+
"pg_query",
|
|
40865
|
+
sizeof(PgQuery__SummaryResult__AliasesEntry),
|
|
40866
|
+
2,
|
|
40867
|
+
pg_query__summary_result__aliases_entry__field_descriptors,
|
|
40868
|
+
pg_query__summary_result__aliases_entry__field_indices_by_name,
|
|
40869
|
+
1, pg_query__summary_result__aliases_entry__number_ranges,
|
|
40870
|
+
(ProtobufCMessageInit) pg_query__summary_result__aliases_entry__init,
|
|
40871
|
+
NULL,NULL,NULL /* reserved[123] */
|
|
40872
|
+
};
|
|
40873
|
+
static const ProtobufCFieldDescriptor pg_query__summary_result__function__field_descriptors[4] =
|
|
40874
|
+
{
|
|
40875
|
+
{
|
|
40876
|
+
"name",
|
|
40877
|
+
1,
|
|
40878
|
+
PROTOBUF_C_LABEL_NONE,
|
|
40879
|
+
PROTOBUF_C_TYPE_STRING,
|
|
40880
|
+
0, /* quantifier_offset */
|
|
40881
|
+
offsetof(PgQuery__SummaryResult__Function, name),
|
|
40882
|
+
NULL,
|
|
40883
|
+
&protobuf_c_empty_string,
|
|
40884
|
+
0, /* flags */
|
|
40885
|
+
0,NULL,NULL /* reserved1,reserved2, etc */
|
|
40886
|
+
},
|
|
40887
|
+
{
|
|
40888
|
+
"function_name",
|
|
40889
|
+
2,
|
|
40890
|
+
PROTOBUF_C_LABEL_NONE,
|
|
40891
|
+
PROTOBUF_C_TYPE_STRING,
|
|
40892
|
+
0, /* quantifier_offset */
|
|
40893
|
+
offsetof(PgQuery__SummaryResult__Function, function_name),
|
|
40894
|
+
NULL,
|
|
40895
|
+
&protobuf_c_empty_string,
|
|
40896
|
+
0, /* flags */
|
|
40897
|
+
0,NULL,NULL /* reserved1,reserved2, etc */
|
|
40898
|
+
},
|
|
40899
|
+
{
|
|
40900
|
+
"schema_name",
|
|
40901
|
+
3,
|
|
40902
|
+
PROTOBUF_C_LABEL_NONE,
|
|
40903
|
+
PROTOBUF_C_TYPE_STRING,
|
|
40904
|
+
0, /* quantifier_offset */
|
|
40905
|
+
offsetof(PgQuery__SummaryResult__Function, schema_name),
|
|
40906
|
+
NULL,
|
|
40907
|
+
&protobuf_c_empty_string,
|
|
40908
|
+
0, /* flags */
|
|
40909
|
+
0,NULL,NULL /* reserved1,reserved2, etc */
|
|
40910
|
+
},
|
|
40911
|
+
{
|
|
40912
|
+
"context",
|
|
40913
|
+
4,
|
|
40914
|
+
PROTOBUF_C_LABEL_NONE,
|
|
40915
|
+
PROTOBUF_C_TYPE_ENUM,
|
|
40916
|
+
0, /* quantifier_offset */
|
|
40917
|
+
offsetof(PgQuery__SummaryResult__Function, context),
|
|
40918
|
+
&pg_query__summary_result__context__descriptor,
|
|
40919
|
+
NULL,
|
|
40920
|
+
0, /* flags */
|
|
40921
|
+
0,NULL,NULL /* reserved1,reserved2, etc */
|
|
40922
|
+
},
|
|
40923
|
+
};
|
|
40924
|
+
static const unsigned pg_query__summary_result__function__field_indices_by_name[] = {
|
|
40925
|
+
3, /* field[3] = context */
|
|
40926
|
+
1, /* field[1] = function_name */
|
|
40927
|
+
0, /* field[0] = name */
|
|
40928
|
+
2, /* field[2] = schema_name */
|
|
40929
|
+
};
|
|
40930
|
+
static const ProtobufCIntRange pg_query__summary_result__function__number_ranges[1 + 1] =
|
|
40931
|
+
{
|
|
40932
|
+
{ 1, 0 },
|
|
40933
|
+
{ 0, 4 }
|
|
40934
|
+
};
|
|
40935
|
+
const ProtobufCMessageDescriptor pg_query__summary_result__function__descriptor =
|
|
40936
|
+
{
|
|
40937
|
+
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
|
|
40938
|
+
"pg_query.SummaryResult.Function",
|
|
40939
|
+
"Function",
|
|
40940
|
+
"PgQuery__SummaryResult__Function",
|
|
40941
|
+
"pg_query",
|
|
40942
|
+
sizeof(PgQuery__SummaryResult__Function),
|
|
40943
|
+
4,
|
|
40944
|
+
pg_query__summary_result__function__field_descriptors,
|
|
40945
|
+
pg_query__summary_result__function__field_indices_by_name,
|
|
40946
|
+
1, pg_query__summary_result__function__number_ranges,
|
|
40947
|
+
(ProtobufCMessageInit) pg_query__summary_result__function__init,
|
|
40948
|
+
NULL,NULL,NULL /* reserved[123] */
|
|
40949
|
+
};
|
|
40950
|
+
static const ProtobufCFieldDescriptor pg_query__summary_result__filter_column__field_descriptors[3] =
|
|
40951
|
+
{
|
|
40952
|
+
{
|
|
40953
|
+
"schema_name",
|
|
40954
|
+
1,
|
|
40955
|
+
PROTOBUF_C_LABEL_NONE,
|
|
40956
|
+
PROTOBUF_C_TYPE_STRING,
|
|
40957
|
+
0, /* quantifier_offset */
|
|
40958
|
+
offsetof(PgQuery__SummaryResult__FilterColumn, schema_name),
|
|
40959
|
+
NULL,
|
|
40960
|
+
&protobuf_c_empty_string,
|
|
40961
|
+
0, /* flags */
|
|
40962
|
+
0,NULL,NULL /* reserved1,reserved2, etc */
|
|
40963
|
+
},
|
|
40964
|
+
{
|
|
40965
|
+
"table_name",
|
|
40966
|
+
2,
|
|
40967
|
+
PROTOBUF_C_LABEL_NONE,
|
|
40968
|
+
PROTOBUF_C_TYPE_STRING,
|
|
40969
|
+
0, /* quantifier_offset */
|
|
40970
|
+
offsetof(PgQuery__SummaryResult__FilterColumn, table_name),
|
|
40971
|
+
NULL,
|
|
40972
|
+
&protobuf_c_empty_string,
|
|
40973
|
+
0, /* flags */
|
|
40974
|
+
0,NULL,NULL /* reserved1,reserved2, etc */
|
|
40975
|
+
},
|
|
40976
|
+
{
|
|
40977
|
+
"column",
|
|
40978
|
+
3,
|
|
40979
|
+
PROTOBUF_C_LABEL_NONE,
|
|
40980
|
+
PROTOBUF_C_TYPE_STRING,
|
|
40981
|
+
0, /* quantifier_offset */
|
|
40982
|
+
offsetof(PgQuery__SummaryResult__FilterColumn, column),
|
|
40983
|
+
NULL,
|
|
40984
|
+
&protobuf_c_empty_string,
|
|
40985
|
+
0, /* flags */
|
|
40986
|
+
0,NULL,NULL /* reserved1,reserved2, etc */
|
|
40987
|
+
},
|
|
40988
|
+
};
|
|
40989
|
+
static const unsigned pg_query__summary_result__filter_column__field_indices_by_name[] = {
|
|
40990
|
+
2, /* field[2] = column */
|
|
40991
|
+
0, /* field[0] = schema_name */
|
|
40992
|
+
1, /* field[1] = table_name */
|
|
40993
|
+
};
|
|
40994
|
+
static const ProtobufCIntRange pg_query__summary_result__filter_column__number_ranges[1 + 1] =
|
|
40995
|
+
{
|
|
40996
|
+
{ 1, 0 },
|
|
40997
|
+
{ 0, 3 }
|
|
40998
|
+
};
|
|
40999
|
+
const ProtobufCMessageDescriptor pg_query__summary_result__filter_column__descriptor =
|
|
41000
|
+
{
|
|
41001
|
+
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
|
|
41002
|
+
"pg_query.SummaryResult.FilterColumn",
|
|
41003
|
+
"FilterColumn",
|
|
41004
|
+
"PgQuery__SummaryResult__FilterColumn",
|
|
41005
|
+
"pg_query",
|
|
41006
|
+
sizeof(PgQuery__SummaryResult__FilterColumn),
|
|
41007
|
+
3,
|
|
41008
|
+
pg_query__summary_result__filter_column__field_descriptors,
|
|
41009
|
+
pg_query__summary_result__filter_column__field_indices_by_name,
|
|
41010
|
+
1, pg_query__summary_result__filter_column__number_ranges,
|
|
41011
|
+
(ProtobufCMessageInit) pg_query__summary_result__filter_column__init,
|
|
41012
|
+
NULL,NULL,NULL /* reserved[123] */
|
|
41013
|
+
};
|
|
41014
|
+
static const ProtobufCEnumValue pg_query__summary_result__context__enum_values_by_number[5] =
|
|
41015
|
+
{
|
|
41016
|
+
{ "None", "PG_QUERY__SUMMARY_RESULT__CONTEXT__None", 0 },
|
|
41017
|
+
{ "Select", "PG_QUERY__SUMMARY_RESULT__CONTEXT__Select", 1 },
|
|
41018
|
+
{ "DML", "PG_QUERY__SUMMARY_RESULT__CONTEXT__DML", 2 },
|
|
41019
|
+
{ "DDL", "PG_QUERY__SUMMARY_RESULT__CONTEXT__DDL", 3 },
|
|
41020
|
+
{ "Call", "PG_QUERY__SUMMARY_RESULT__CONTEXT__Call", 4 },
|
|
41021
|
+
};
|
|
41022
|
+
static const ProtobufCIntRange pg_query__summary_result__context__value_ranges[] = {
|
|
41023
|
+
{0, 0},{0, 5}
|
|
41024
|
+
};
|
|
41025
|
+
static const ProtobufCEnumValueIndex pg_query__summary_result__context__enum_values_by_name[5] =
|
|
41026
|
+
{
|
|
41027
|
+
{ "Call", 4 },
|
|
41028
|
+
{ "DDL", 3 },
|
|
41029
|
+
{ "DML", 2 },
|
|
41030
|
+
{ "None", 0 },
|
|
41031
|
+
{ "Select", 1 },
|
|
41032
|
+
};
|
|
41033
|
+
const ProtobufCEnumDescriptor pg_query__summary_result__context__descriptor =
|
|
41034
|
+
{
|
|
41035
|
+
PROTOBUF_C__ENUM_DESCRIPTOR_MAGIC,
|
|
41036
|
+
"pg_query.SummaryResult.Context",
|
|
41037
|
+
"Context",
|
|
41038
|
+
"PgQuery__SummaryResult__Context",
|
|
41039
|
+
"pg_query",
|
|
41040
|
+
5,
|
|
41041
|
+
pg_query__summary_result__context__enum_values_by_number,
|
|
41042
|
+
5,
|
|
41043
|
+
pg_query__summary_result__context__enum_values_by_name,
|
|
41044
|
+
1,
|
|
41045
|
+
pg_query__summary_result__context__value_ranges,
|
|
41046
|
+
NULL,NULL,NULL,NULL /* reserved[1234] */
|
|
41047
|
+
};
|
|
41048
|
+
static const ProtobufCFieldDescriptor pg_query__summary_result__field_descriptors[7] =
|
|
41049
|
+
{
|
|
41050
|
+
{
|
|
41051
|
+
"tables",
|
|
41052
|
+
1,
|
|
41053
|
+
PROTOBUF_C_LABEL_REPEATED,
|
|
41054
|
+
PROTOBUF_C_TYPE_MESSAGE,
|
|
41055
|
+
offsetof(PgQuery__SummaryResult, n_tables),
|
|
41056
|
+
offsetof(PgQuery__SummaryResult, tables),
|
|
41057
|
+
&pg_query__summary_result__table__descriptor,
|
|
41058
|
+
NULL,
|
|
41059
|
+
0, /* flags */
|
|
41060
|
+
0,NULL,NULL /* reserved1,reserved2, etc */
|
|
41061
|
+
},
|
|
41062
|
+
{
|
|
41063
|
+
"aliases",
|
|
41064
|
+
2,
|
|
41065
|
+
PROTOBUF_C_LABEL_REPEATED,
|
|
41066
|
+
PROTOBUF_C_TYPE_MESSAGE,
|
|
41067
|
+
offsetof(PgQuery__SummaryResult, n_aliases),
|
|
41068
|
+
offsetof(PgQuery__SummaryResult, aliases),
|
|
41069
|
+
&pg_query__summary_result__aliases_entry__descriptor,
|
|
41070
|
+
NULL,
|
|
41071
|
+
0, /* flags */
|
|
41072
|
+
0,NULL,NULL /* reserved1,reserved2, etc */
|
|
41073
|
+
},
|
|
41074
|
+
{
|
|
41075
|
+
"cte_names",
|
|
41076
|
+
3,
|
|
41077
|
+
PROTOBUF_C_LABEL_REPEATED,
|
|
41078
|
+
PROTOBUF_C_TYPE_STRING,
|
|
41079
|
+
offsetof(PgQuery__SummaryResult, n_cte_names),
|
|
41080
|
+
offsetof(PgQuery__SummaryResult, cte_names),
|
|
41081
|
+
NULL,
|
|
41082
|
+
&protobuf_c_empty_string,
|
|
41083
|
+
0, /* flags */
|
|
41084
|
+
0,NULL,NULL /* reserved1,reserved2, etc */
|
|
41085
|
+
},
|
|
41086
|
+
{
|
|
41087
|
+
"functions",
|
|
41088
|
+
4,
|
|
41089
|
+
PROTOBUF_C_LABEL_REPEATED,
|
|
41090
|
+
PROTOBUF_C_TYPE_MESSAGE,
|
|
41091
|
+
offsetof(PgQuery__SummaryResult, n_functions),
|
|
41092
|
+
offsetof(PgQuery__SummaryResult, functions),
|
|
41093
|
+
&pg_query__summary_result__function__descriptor,
|
|
41094
|
+
NULL,
|
|
41095
|
+
0, /* flags */
|
|
41096
|
+
0,NULL,NULL /* reserved1,reserved2, etc */
|
|
41097
|
+
},
|
|
41098
|
+
{
|
|
41099
|
+
"filter_columns",
|
|
41100
|
+
5,
|
|
41101
|
+
PROTOBUF_C_LABEL_REPEATED,
|
|
41102
|
+
PROTOBUF_C_TYPE_MESSAGE,
|
|
41103
|
+
offsetof(PgQuery__SummaryResult, n_filter_columns),
|
|
41104
|
+
offsetof(PgQuery__SummaryResult, filter_columns),
|
|
41105
|
+
&pg_query__summary_result__filter_column__descriptor,
|
|
41106
|
+
NULL,
|
|
41107
|
+
0, /* flags */
|
|
41108
|
+
0,NULL,NULL /* reserved1,reserved2, etc */
|
|
41109
|
+
},
|
|
41110
|
+
{
|
|
41111
|
+
"statement_types",
|
|
41112
|
+
6,
|
|
41113
|
+
PROTOBUF_C_LABEL_REPEATED,
|
|
41114
|
+
PROTOBUF_C_TYPE_STRING,
|
|
41115
|
+
offsetof(PgQuery__SummaryResult, n_statement_types),
|
|
41116
|
+
offsetof(PgQuery__SummaryResult, statement_types),
|
|
41117
|
+
NULL,
|
|
41118
|
+
&protobuf_c_empty_string,
|
|
41119
|
+
0, /* flags */
|
|
41120
|
+
0,NULL,NULL /* reserved1,reserved2, etc */
|
|
41121
|
+
},
|
|
41122
|
+
{
|
|
41123
|
+
"truncated_query",
|
|
41124
|
+
7,
|
|
41125
|
+
PROTOBUF_C_LABEL_NONE,
|
|
41126
|
+
PROTOBUF_C_TYPE_STRING,
|
|
41127
|
+
0, /* quantifier_offset */
|
|
41128
|
+
offsetof(PgQuery__SummaryResult, truncated_query),
|
|
41129
|
+
NULL,
|
|
41130
|
+
&protobuf_c_empty_string,
|
|
41131
|
+
0, /* flags */
|
|
41132
|
+
0,NULL,NULL /* reserved1,reserved2, etc */
|
|
41133
|
+
},
|
|
41134
|
+
};
|
|
41135
|
+
static const unsigned pg_query__summary_result__field_indices_by_name[] = {
|
|
41136
|
+
1, /* field[1] = aliases */
|
|
41137
|
+
2, /* field[2] = cte_names */
|
|
41138
|
+
4, /* field[4] = filter_columns */
|
|
41139
|
+
3, /* field[3] = functions */
|
|
41140
|
+
5, /* field[5] = statement_types */
|
|
41141
|
+
0, /* field[0] = tables */
|
|
41142
|
+
6, /* field[6] = truncated_query */
|
|
41143
|
+
};
|
|
41144
|
+
static const ProtobufCIntRange pg_query__summary_result__number_ranges[1 + 1] =
|
|
41145
|
+
{
|
|
41146
|
+
{ 1, 0 },
|
|
41147
|
+
{ 0, 7 }
|
|
41148
|
+
};
|
|
41149
|
+
const ProtobufCMessageDescriptor pg_query__summary_result__descriptor =
|
|
41150
|
+
{
|
|
41151
|
+
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
|
|
41152
|
+
"pg_query.SummaryResult",
|
|
41153
|
+
"SummaryResult",
|
|
41154
|
+
"PgQuery__SummaryResult",
|
|
41155
|
+
"pg_query",
|
|
41156
|
+
sizeof(PgQuery__SummaryResult),
|
|
41157
|
+
7,
|
|
41158
|
+
pg_query__summary_result__field_descriptors,
|
|
41159
|
+
pg_query__summary_result__field_indices_by_name,
|
|
41160
|
+
1, pg_query__summary_result__number_ranges,
|
|
41161
|
+
(ProtobufCMessageInit) pg_query__summary_result__init,
|
|
41162
|
+
NULL,NULL,NULL /* reserved[123] */
|
|
41163
|
+
};
|
|
40676
41164
|
static const ProtobufCEnumValue pg_query__query_source__enum_values_by_number[6] =
|
|
40677
41165
|
{
|
|
40678
41166
|
{ "QUERY_SOURCE_UNDEFINED", "PG_QUERY__QUERY_SOURCE__QUERY_SOURCE_UNDEFINED", 0 },
|
|
@@ -4,13 +4,29 @@
|
|
|
4
4
|
|
|
5
5
|
#include "postgres_deparse.h"
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
#include "postgres.h"
|
|
8
|
+
#include "lib/stringinfo.h"
|
|
9
|
+
#include "nodes/parsenodes.h"
|
|
10
|
+
|
|
11
|
+
#include "protobuf/pg_query.pb-c.h"
|
|
12
|
+
|
|
13
|
+
PgQueryDeparseResult
|
|
14
|
+
pg_query_deparse_protobuf(PgQueryProtobuf parse_tree)
|
|
15
|
+
{
|
|
16
|
+
PostgresDeparseOpts opts;
|
|
17
|
+
|
|
18
|
+
MemSet(&opts, 0, sizeof(PostgresDeparseOpts));
|
|
19
|
+
return pg_query_deparse_protobuf_opts(parse_tree, opts);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
PgQueryDeparseResult
|
|
23
|
+
pg_query_deparse_protobuf_opts(PgQueryProtobuf parse_tree, PostgresDeparseOpts opts)
|
|
8
24
|
{
|
|
9
25
|
PgQueryDeparseResult result = {0};
|
|
10
26
|
StringInfoData str;
|
|
11
27
|
MemoryContext ctx;
|
|
12
|
-
List
|
|
13
|
-
ListCell
|
|
28
|
+
List *stmts;
|
|
29
|
+
ListCell *lc;
|
|
14
30
|
|
|
15
31
|
ctx = pg_query_enter_memory_context();
|
|
16
32
|
|
|
@@ -20,8 +36,9 @@ PgQueryDeparseResult pg_query_deparse_protobuf(PgQueryProtobuf parse_tree)
|
|
|
20
36
|
|
|
21
37
|
initStringInfo(&str);
|
|
22
38
|
|
|
23
|
-
foreach(lc, stmts)
|
|
24
|
-
|
|
39
|
+
foreach(lc, stmts)
|
|
40
|
+
{
|
|
41
|
+
deparseRawStmtOpts(&str, castNode(RawStmt, lfirst(lc)), opts);
|
|
25
42
|
if (lnext(stmts, lc))
|
|
26
43
|
appendStringInfoString(&str, "; ");
|
|
27
44
|
}
|
|
@@ -29,19 +46,22 @@ PgQueryDeparseResult pg_query_deparse_protobuf(PgQueryProtobuf parse_tree)
|
|
|
29
46
|
}
|
|
30
47
|
PG_CATCH();
|
|
31
48
|
{
|
|
32
|
-
ErrorData*
|
|
33
|
-
PgQueryError*
|
|
49
|
+
ErrorData *error_data;
|
|
50
|
+
PgQueryError *error;
|
|
34
51
|
|
|
35
52
|
MemoryContextSwitchTo(ctx);
|
|
36
53
|
error_data = CopyErrorData();
|
|
37
54
|
|
|
38
|
-
|
|
55
|
+
/*
|
|
56
|
+
* Note: This is intentionally malloc so exiting the memory context
|
|
57
|
+
* doesn't free this
|
|
58
|
+
*/
|
|
39
59
|
error = malloc(sizeof(PgQueryError));
|
|
40
|
-
error->message
|
|
41
|
-
error->filename
|
|
42
|
-
error->funcname
|
|
43
|
-
error->context
|
|
44
|
-
error->lineno
|
|
60
|
+
error->message = strdup(error_data->message);
|
|
61
|
+
error->filename = strdup(error_data->filename);
|
|
62
|
+
error->funcname = strdup(error_data->funcname);
|
|
63
|
+
error->context = NULL;
|
|
64
|
+
error->lineno = error_data->lineno;
|
|
45
65
|
error->cursorpos = error_data->cursorpos;
|
|
46
66
|
|
|
47
67
|
result.error = error;
|
|
@@ -54,11 +74,124 @@ PgQueryDeparseResult pg_query_deparse_protobuf(PgQueryProtobuf parse_tree)
|
|
|
54
74
|
return result;
|
|
55
75
|
}
|
|
56
76
|
|
|
57
|
-
void
|
|
77
|
+
void
|
|
78
|
+
pg_query_free_deparse_result(PgQueryDeparseResult result)
|
|
58
79
|
{
|
|
59
|
-
if (result.error)
|
|
80
|
+
if (result.error)
|
|
81
|
+
{
|
|
60
82
|
pg_query_free_error(result.error);
|
|
61
83
|
}
|
|
62
84
|
|
|
63
85
|
free(result.query);
|
|
64
86
|
}
|
|
87
|
+
|
|
88
|
+
PgQueryDeparseCommentsResult
|
|
89
|
+
pg_query_deparse_comments_for_query(const char *query)
|
|
90
|
+
{
|
|
91
|
+
PgQueryDeparseCommentsResult result;
|
|
92
|
+
PgQueryScanResult scan_result_raw = pg_query_scan(query);
|
|
93
|
+
|
|
94
|
+
if (scan_result_raw.error)
|
|
95
|
+
{
|
|
96
|
+
result.error = scan_result_raw.error;
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
PgQuery__ScanResult *scan_result = pg_query__scan_result__unpack(NULL, scan_result_raw.pbuf.len, (void *) scan_result_raw.pbuf.data);
|
|
101
|
+
bool prior_token_was_comment = false;
|
|
102
|
+
int32_t prior_non_comment_end = 0;
|
|
103
|
+
int32_t prior_token_end = 0;
|
|
104
|
+
|
|
105
|
+
result.comment_count = 0;
|
|
106
|
+
for (int i = 0; i < scan_result->n_tokens; i++)
|
|
107
|
+
{
|
|
108
|
+
PgQuery__ScanToken *token = scan_result->tokens[i];
|
|
109
|
+
|
|
110
|
+
if (token->token == PG_QUERY__TOKEN__SQL_COMMENT || token->token == PG_QUERY__TOKEN__C_COMMENT)
|
|
111
|
+
result.comment_count++;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
result.comments = malloc(result.comment_count * sizeof(PostgresDeparseComment *));
|
|
115
|
+
size_t comment_idx = 0;
|
|
116
|
+
|
|
117
|
+
for (int i = 0; i < scan_result->n_tokens; i++)
|
|
118
|
+
{
|
|
119
|
+
PgQuery__ScanToken *token = scan_result->tokens[i];
|
|
120
|
+
|
|
121
|
+
if (token->token == PG_QUERY__TOKEN__SQL_COMMENT || token->token == PG_QUERY__TOKEN__C_COMMENT)
|
|
122
|
+
{
|
|
123
|
+
size_t token_len = token->end - token->start;
|
|
124
|
+
PostgresDeparseComment *comment = malloc(sizeof(PostgresDeparseComment));
|
|
125
|
+
|
|
126
|
+
/*
|
|
127
|
+
* Set to the end of the prior non-comment token.
|
|
128
|
+
*
|
|
129
|
+
* We could alternatively set the match location to the start of
|
|
130
|
+
* the next non-comment token instead (which would be more in line
|
|
131
|
+
* with emitting that happens before the node once the location is
|
|
132
|
+
* matched).
|
|
133
|
+
*
|
|
134
|
+
* However, that doesn't work well in practice, specifically.
|
|
135
|
+
* RawStmt start locations are 0, even when there are comments at
|
|
136
|
+
* the start of the statement.
|
|
137
|
+
*/
|
|
138
|
+
comment->match_location = prior_non_comment_end;
|
|
139
|
+
|
|
140
|
+
comment->newlines_before_comment = 0;
|
|
141
|
+
comment->newlines_after_comment = 0;
|
|
142
|
+
|
|
143
|
+
/*
|
|
144
|
+
* Emit newlines before the comment if prior token was not a
|
|
145
|
+
* comment (otherwise that comment would have emitted them)
|
|
146
|
+
*/
|
|
147
|
+
if (!prior_token_was_comment)
|
|
148
|
+
{
|
|
149
|
+
for (int j = prior_token_end; j < token->start; j++)
|
|
150
|
+
{
|
|
151
|
+
if (query[j] == '\n')
|
|
152
|
+
comment->newlines_before_comment++;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (i < scan_result->n_tokens - 1)
|
|
157
|
+
{
|
|
158
|
+
for (int j = token->end; j < scan_result->tokens[i + 1]->start; j++)
|
|
159
|
+
{
|
|
160
|
+
if (query[j] == '\n')
|
|
161
|
+
comment->newlines_after_comment++;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
comment->str = malloc(token_len + 1);
|
|
166
|
+
memcpy(comment->str, &(query[token->start]), token_len);
|
|
167
|
+
comment->str[token_len] = '\0';
|
|
168
|
+
|
|
169
|
+
result.comments[comment_idx] = comment;
|
|
170
|
+
comment_idx++;
|
|
171
|
+
prior_token_was_comment = true;
|
|
172
|
+
}
|
|
173
|
+
else
|
|
174
|
+
{
|
|
175
|
+
prior_non_comment_end = token->end;
|
|
176
|
+
prior_token_was_comment = false;
|
|
177
|
+
}
|
|
178
|
+
prior_token_end = token->end;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
pg_query__scan_result__free_unpacked(scan_result, NULL);
|
|
182
|
+
pg_query_free_scan_result(scan_result_raw);
|
|
183
|
+
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
void
|
|
188
|
+
pg_query_free_deparse_comments_result(PgQueryDeparseCommentsResult result)
|
|
189
|
+
{
|
|
190
|
+
for (int i = 0; i < result.comment_count; i++)
|
|
191
|
+
{
|
|
192
|
+
free(result.comments[i]->str);
|
|
193
|
+
free(result.comments[i]);
|
|
194
|
+
}
|
|
195
|
+
if (result.comments != NULL)
|
|
196
|
+
free(result.comments);
|
|
197
|
+
}
|