Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ tmp/*
!tmp/.gitkeep

.vs/*
.claude-session-id
19 changes: 18 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,19 @@ $(ARLIB): $(OBJ_FILES) Makefile
$(SOLIB): $(OBJ_FILES) Makefile
@$(CC) $(CFLAGS) -shared -Wl,$(SOFLAG),$(SONAME) $(LDFLAGS) -o $@ $(OBJ_FILES) $(LIBS)

# PLpgSQL protobuf code generation
generate_plpgsql:
ruby scripts/extract_plpgsql_headers.rb
ruby scripts/generate_plpgsql_protobuf.rb

# Append PLpgSQL proto to main proto file (must be done manually when PLpgSQL definitions change)
# Run: make regenerate_plpgsql_proto
regenerate_plpgsql_proto: generate_plpgsql
@echo "Appending PLpgSQL proto definitions to pg_query.proto"
@# Remove any existing PLpgSQL definitions first (between markers if present)
@cat src/include/pg_query_plpgsql_protobuf.proto >> protobuf/pg_query.proto
@echo "PLpgSQL proto definitions appended. Please commit the changes."

protobuf/pg_query.pb-c.c protobuf/pg_query.pb-c.h: protobuf/pg_query.proto
ifneq ($(shell which protoc-gen-c), )
protoc --c_out=. protobuf/pg_query.proto
Expand Down Expand Up @@ -237,7 +250,7 @@ examples/normalize_error: examples/normalize_error.c $(ARLIB)
examples/simple_plpgsql: examples/simple_plpgsql.c $(ARLIB)
$(CC) $(TEST_CFLAGS) -o $@ -g examples/simple_plpgsql.c $(ARLIB) $(TEST_LDFLAGS)

TESTS = test/complex test/concurrency test/deparse test/fingerprint test/fingerprint_opts test/is_utility_stmt test/normalize test/normalize_utility test/parse test/parse_opts test/parse_protobuf test/parse_protobuf_opts test/parse_plpgsql test/scan test/split test/summary test/summary_truncate
TESTS = test/complex test/concurrency test/deparse test/fingerprint test/fingerprint_opts test/is_utility_stmt test/normalize test/normalize_utility test/parse test/parse_opts test/parse_protobuf test/parse_protobuf_opts test/parse_plpgsql test/parse_plpgsql_protobuf test/scan test/split test/summary test/summary_truncate
test: $(TESTS)
ifeq ($(VALGRIND),1)
$(VALGRIND_MEMCHECK) test/complex || (cat test/valgrind.log && false)
Expand Down Expand Up @@ -279,6 +292,7 @@ else
# Output-based tests
test/parse_plpgsql
diff -Naur test/plpgsql_samples.expected.json test/plpgsql_samples.actual.json
test/parse_plpgsql_protobuf
endif

test/complex: test/complex.c $(ARLIB)
Expand Down Expand Up @@ -326,6 +340,9 @@ test/parse_opts: test/parse_opts.c test/parse_opts_tests.c $(ARLIB)
test/parse_plpgsql: test/parse_plpgsql.c test/parse_tests.c $(ARLIB)
$(CC) $(TEST_CFLAGS) -o $@ test/parse_plpgsql.c $(ARLIB) $(TEST_LDFLAGS)

test/parse_plpgsql_protobuf: test/parse_plpgsql_protobuf.c $(ARLIB)
$(CC) $(TEST_CFLAGS) -o $@ test/parse_plpgsql_protobuf.c $(ARLIB) $(TEST_LDFLAGS)

test/parse_protobuf: test/parse_protobuf.c test/parse_tests.c $(ARLIB)
$(CC) $(TEST_CFLAGS) -o $@ test/parse_protobuf.c $(ARLIB) $(TEST_LDFLAGS)

Expand Down
11 changes: 11 additions & 0 deletions pg_query.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ typedef struct {
PgQueryError* error;
} PgQueryPlpgsqlParseResult;

typedef struct {
PgQueryProtobuf parse_tree;
char* stderr_buffer;
PgQueryError* error;
} PgQueryPlpgsqlProtobufParseResult;

typedef struct {
uint64_t fingerprint;
char* fingerprint_str;
Expand Down Expand Up @@ -124,6 +130,10 @@ PgQueryParseResult pg_query_parse_opts(const char* input, int parser_options);
PgQueryProtobufParseResult pg_query_parse_protobuf(const char* input);
PgQueryProtobufParseResult pg_query_parse_protobuf_opts(const char* input, int parser_options);
PgQueryPlpgsqlParseResult pg_query_parse_plpgsql(const char* input);
PgQueryPlpgsqlProtobufParseResult pg_query_parse_plpgsql_protobuf(const char* input);

// Convert PLpgSQL protobuf back to JSON (for bidirectional support)
char* pg_query_plpgsql_protobuf_to_json(PgQueryProtobuf protobuf);

PgQueryFingerprintResult pg_query_fingerprint(const char* input);
PgQueryFingerprintResult pg_query_fingerprint_opts(const char* input, int parser_options);
Expand Down Expand Up @@ -154,6 +164,7 @@ void pg_query_free_deparse_result(PgQueryDeparseResult result);
void pg_query_free_deparse_comments_result(PgQueryDeparseCommentsResult result);
void pg_query_free_protobuf_parse_result(PgQueryProtobufParseResult result);
void pg_query_free_plpgsql_parse_result(PgQueryPlpgsqlParseResult result);
void pg_query_free_plpgsql_protobuf_parse_result(PgQueryPlpgsqlProtobufParseResult result);
void pg_query_free_fingerprint_result(PgQueryFingerprintResult result);
void pg_query_free_is_utility_result(PgQueryIsUtilityResult result);
void pg_query_free_summary_parse_result(PgQuerySummaryParseResult result);
Expand Down
Loading
Loading