Due to permission issues with creating a temporary folder, the two custom tests from PostgreSQL documentation failed as they could not write their results to the temp log file. The issue was resolved by changing the owner of the temporary folder while creating it. While looking for the issue, the varDump command was commented out as it was not needed and not even found. Also, two tests taken from the documentation were edited; therefore, the slight changes which were made to them to work in our scenario can be highlighted.
46 lines
1.3 KiB
Text
46 lines
1.3 KiB
Text
// Taken from https://www.postgresql.org/docs/14/ecpg-variables.html
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <pgtypes_numeric.h>
|
|
|
|
EXEC SQL WHENEVER SQLERROR STOP;
|
|
|
|
int
|
|
main(void)
|
|
{
|
|
EXEC SQL BEGIN DECLARE SECTION;
|
|
numeric *num;
|
|
numeric *num2;
|
|
decimal *dec;
|
|
EXEC SQL END DECLARE SECTION;
|
|
|
|
// Add "USER postgres;"
|
|
EXEC SQL CONNECT TO testdb USER postgres;
|
|
// EXEC SQL SELECT pg_catalog.set_config('search_path', '', false); EXEC SQL COMMIT;
|
|
|
|
num = PGTYPESnumeric_new();
|
|
dec = PGTYPESdecimal_new();
|
|
|
|
EXEC SQL SELECT 12.345::numeric(4,2), 23.456::decimal(4,2) INTO :num, :dec;
|
|
|
|
printf("numeric = %s\n", PGTYPESnumeric_to_asc(num, 0));
|
|
printf("numeric = %s\n", PGTYPESnumeric_to_asc(num, 1));
|
|
printf("numeric = %s\n", PGTYPESnumeric_to_asc(num, 2));
|
|
|
|
/* Convert decimal to numeric to show a decimal value. */
|
|
num2 = PGTYPESnumeric_new();
|
|
PGTYPESnumeric_from_decimal(dec, num2);
|
|
|
|
printf("decimal = %s\n", PGTYPESnumeric_to_asc(num2, 0));
|
|
printf("decimal = %s\n", PGTYPESnumeric_to_asc(num2, 1));
|
|
printf("decimal = %s\n", PGTYPESnumeric_to_asc(num2, 2));
|
|
|
|
PGTYPESnumeric_free(num2);
|
|
PGTYPESdecimal_free(dec);
|
|
PGTYPESnumeric_free(num);
|
|
|
|
EXEC SQL COMMIT;
|
|
EXEC SQL DISCONNECT ALL;
|
|
return 0;
|
|
}
|