1#pragma once
2
3#include <stdlib.h>
4#include <string>
5
6#define fprintf(...)
7
8#include "pg_definitions.hpp"
9
10#include "nodes/pg_list.hpp"
11#include "nodes/parsenodes.hpp"
12
13namespace duckdb_libpgquery {
14
15typedef struct parse_result_str parse_result;
16struct parse_result_str {
17 bool success;
18 PGList *parse_tree;
19 std::string error_message;
20 int error_location;
21};
22
23void pg_parser_init();
24void pg_parser_parse(const char *query, parse_result *res);
25void pg_parser_cleanup();
26
27// error handling
28int ereport(int code, ...);
29
30void elog(int code, const char *fmt, ...);
31int errcode(int sqlerrcode);
32int errmsg(const char *fmt, ...);
33int errhint(const char *msg);
34int errmsg_internal(const char *fmt, ...);
35int errdetail(const char *fmt, ...);
36int errposition(int cursorpos);
37char *psprintf(const char *fmt, ...);
38
39// memory mgmt
40char *pstrdup(const char *in);
41void *palloc(size_t n);
42void pfree(void *ptr);
43void *palloc0fast(size_t n);
44void *repalloc(void *ptr, size_t n);
45
46char *NameListToString(PGList *names);
47void *copyObject(const void *from);
48bool equal(const void *a, const void *b);
49int exprLocation(const PGNode *expr);
50
51// string gunk
52int pg_database_encoding_max_length(void);
53bool pg_verifymbstr(const char *mbstr, int len, bool noError);
54int pg_mbstrlen_with_len(const char *mbstr, int len);
55int pg_mbcliplen(const char *mbstr, int len, int limit);
56int pg_mblen(const char *mbstr);
57
58PGDefElem *defWithOids(bool value);
59
60typedef unsigned int pg_wchar;
61unsigned char *unicode_to_utf8(pg_wchar c, unsigned char *utf8string);
62
63}