While running the script command varDump postgresqlDataDir; was executed, but it was no longer found. It is not needed for the script to work Tests for libecpg were commented, so our changes from the documentation are visible
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;
|
|
}
|