Skip to content

Commit 2ce0501

Browse files
authored
Creating a developer helper function pgr_print_notice (#3030)
* Creating a developer helper function pgr_print_notice
1 parent 9d9c911 commit 2ce0501

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

include/c_common/e_report.h

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,35 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
6565
* ~~~~
6666
*/
6767
void
68-
pgr_global_report(
69-
char** log_msg,
70-
char** notice_msg,
71-
char** error_msg);
68+
pgr_global_report(char**, char**, char**);
69+
70+
/*! @brief Generates a notice on PostgreSQL
71+
*
72+
* This is a development helper function
73+
* `pgr_print_notice` on code and related code must be deleted
74+
*
75+
* To use:
76+
* Add at the begining of the .cpp/.hpp file:
77+
* ~~~~{.c}
78+
* extern "C" {
79+
* #include "c_common/postgres_connection.h"
80+
* #include "c_common/e_report.h"
81+
* }
82+
* #include "cpp_common/alloc.hpp"
83+
* ~~~~
84+
*
85+
* Insert a variable where to store the message
86+
* Save the message
87+
* Call the function using the to_pg_msg
88+
* ~~~~{.c}
89+
* std::ostringstream msg;
90+
* int this_variable = 3;
91+
* msg << "This is the message that shows the value of : " << this_variable;
92+
* pgr_print_notice(to_pg_msg(msg));
93+
* ~~~~
94+
*/
95+
void
96+
pgr_print_notice(const char*);
7297

7398
/* @brief throws postgres error when first string is not null */
7499
void pgr_throw_error(const char*, const char*);

src/common/e_report.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ pgr_throw_error(const char *err, const char *hint) {
3939
}
4040
}
4141

42+
43+
/**
44+
* @param[in] msg string to send notice to PostgreSQL
45+
*/
46+
void
47+
pgr_print_notice(const char* msg) {
48+
if (msg) {
49+
ereport(NOTICE, (errmsg_internal("%s", msg)));
50+
}
51+
}
52+
4253
/**
4354
* On C++ side, the message to be returned;
4455
* ~~~~{.c}

0 commit comments

Comments
 (0)