C-Language function invocation from another one.
От | Ilya Urikh |
---|---|
Тема | C-Language function invocation from another one. |
Дата | |
Msg-id | adf175f70905131639p7ec5d660le3ec6ad137d9368a@mail.gmail.com обсуждение исходный текст |
Ответы |
Re: C-Language function invocation from another one.
|
Список | pgsql-novice |
Hi,
What is the best way to call C-Language function from another one?
Now I see only one method - to call SPI_execute("EXECUTE funcName(...);", false, 0).
For example:
PG_FUNCTION_INFO_V1(calculateAccount);
PG_FUNCTION_INFO_V1(calculateAccountService);
Datum calculateAccount(PG_FUNCTION_ARGS);
Datum calculateAccountService(PG_FUNCTION_ARGS);
Datum calculateAccount(PG_FUNCTION_ARGS)
{
// Arguments
int32 accountId = PG_GETARG_INT32(0);
DateADT startDate = PG_GETARG_DATEADT(1);
DateADT endDate = PG_GETARG_DATEADT(2);
char command[1000];
...
SPI_connect();
snprintf(command, sizeof(command), "execute calculateAccountService(%d,
%d);", accountId, serviceId);
SPI_execute(command, false, 0);
SPI_finish();
PG_RETURN_NULL();
}
Datum calculateAccountService(PG_FUNCTION_ARGS)
{
int32 accountId = PG_GETARG_INT32(0);
int32 serviceId = PG_GETARG_INT32(1);
...
PG_RETURN_NULL();
}
What is the best way to call C-Language function from another one?
Now I see only one method - to call SPI_execute("EXECUTE funcName(...);", false, 0).
For example:
PG_FUNCTION_INFO_V1(calculateAccount);
PG_FUNCTION_INFO_V1(calculateAccountService);
Datum calculateAccount(PG_FUNCTION_ARGS);
Datum calculateAccountService(PG_FUNCTION_ARGS);
Datum calculateAccount(PG_FUNCTION_ARGS)
{
// Arguments
int32 accountId = PG_GETARG_INT32(0);
DateADT startDate = PG_GETARG_DATEADT(1);
DateADT endDate = PG_GETARG_DATEADT(2);
char command[1000];
...
SPI_connect();
snprintf(command, sizeof(command), "execute calculateAccountService(%d,
%d);", accountId, serviceId);
SPI_execute(command, false, 0);
SPI_finish();
PG_RETURN_NULL();
}
Datum calculateAccountService(PG_FUNCTION_ARGS)
{
int32 accountId = PG_GETARG_INT32(0);
int32 serviceId = PG_GETARG_INT32(1);
...
PG_RETURN_NULL();
}
--
Best regards,
Ilya Urikh.
В списке pgsql-novice по дате отправления: