@@ -6,11 +6,13 @@ void raise_ruby_parse_error(PgQueryProtobufParseResult result);
6
6
void raise_ruby_normalize_error (PgQueryNormalizeResult result );
7
7
void raise_ruby_fingerprint_error (PgQueryFingerprintResult result );
8
8
void raise_ruby_scan_error (PgQueryScanResult result );
9
+ void raise_ruby_plpgsql_parse_error (PgQueryPlpgsqlParseResult result );
9
10
10
11
VALUE pg_query_ruby_parse_protobuf (VALUE self , VALUE input );
11
12
VALUE pg_query_ruby_deparse_protobuf (VALUE self , VALUE input );
12
13
VALUE pg_query_ruby_normalize (VALUE self , VALUE input );
13
14
VALUE pg_query_ruby_fingerprint (VALUE self , VALUE input );
15
+ VALUE pg_query_ruby_parse_plpgsql (VALUE self , VALUE input );
14
16
VALUE pg_query_ruby_scan (VALUE self , VALUE input );
15
17
VALUE pg_query_ruby_hash_xxh3_64 (VALUE self , VALUE input , VALUE seed );
16
18
@@ -24,6 +26,7 @@ __attribute__((visibility ("default"))) void Init_pg_query(void)
24
26
rb_define_singleton_method (cPgQuery , "deparse_protobuf" , pg_query_ruby_deparse_protobuf , 1 );
25
27
rb_define_singleton_method (cPgQuery , "normalize" , pg_query_ruby_normalize , 1 );
26
28
rb_define_singleton_method (cPgQuery , "fingerprint" , pg_query_ruby_fingerprint , 1 );
29
+ rb_define_singleton_method (cPgQuery , "_raw_parse_plpgsql" , pg_query_ruby_parse_plpgsql , 1 );
27
30
rb_define_singleton_method (cPgQuery , "_raw_scan" , pg_query_ruby_scan , 1 );
28
31
rb_define_singleton_method (cPgQuery , "hash_xxh3_64" , pg_query_ruby_hash_xxh3_64 , 2 );
29
32
rb_define_const (cPgQuery , "PG_VERSION" , rb_str_new2 (PG_VERSION ));
@@ -121,6 +124,24 @@ void raise_ruby_scan_error(PgQueryScanResult result)
121
124
rb_exc_raise (rb_class_new_instance (4 , args , cScanError ));
122
125
}
123
126
127
+ void raise_ruby_plpgsql_parse_error (PgQueryPlpgsqlParseResult result )
128
+ {
129
+ VALUE cPgQuery , cPlpgsqlParseError ;
130
+ VALUE args [4 ];
131
+
132
+ cPgQuery = rb_const_get (rb_cObject , rb_intern ("PgQuery" ));
133
+ cPlpgsqlParseError = rb_const_get_at (cPgQuery , rb_intern ("PlpgsqlParseError" ));
134
+
135
+ args [0 ] = rb_str_new2 (result .error -> message );
136
+ args [1 ] = rb_str_new2 (result .error -> filename );
137
+ args [2 ] = INT2NUM (result .error -> lineno );
138
+ args [3 ] = INT2NUM (result .error -> cursorpos );
139
+
140
+ pg_query_free_plpgsql_parse_result (result );
141
+
142
+ rb_exc_raise (rb_class_new_instance (4 , args , cPlpgsqlParseError ));
143
+ }
144
+
124
145
VALUE pg_query_ruby_parse_protobuf (VALUE self , VALUE input )
125
146
{
126
147
Check_Type (input , T_STRING );
@@ -197,6 +218,22 @@ VALUE pg_query_ruby_fingerprint(VALUE self, VALUE input)
197
218
return output ;
198
219
}
199
220
221
+ VALUE pg_query_ruby_parse_plpgsql (VALUE self , VALUE input )
222
+ {
223
+ Check_Type (input , T_STRING );
224
+
225
+ VALUE output ;
226
+ PgQueryPlpgsqlParseResult result = pg_query_parse_plpgsql (StringValueCStr (input ));
227
+
228
+ if (result .error ) raise_ruby_plpgsql_parse_error (result );
229
+
230
+ output = rb_str_new2 (result .plpgsql_funcs );
231
+
232
+ pg_query_free_plpgsql_parse_result (result );
233
+
234
+ return output ;
235
+ }
236
+
200
237
VALUE pg_query_ruby_scan (VALUE self , VALUE input )
201
238
{
202
239
Check_Type (input , T_STRING );
0 commit comments