Problem with PG_GETARG_CSTRING

Поиск
Список
Период
Сортировка
От Brett Maton
Тема Problem with PG_GETARG_CSTRING
Дата
Msg-id 05ED21952E28E94E8352836547A6BA37042317C6@achmsx001.hsa.co.uk
обсуждение исходный текст
Ответы Re: Problem with PG_GETARG_CSTRING
Список pgsql-novice

I'm probably just being a numpty, but I can't seem to get arguments with PG_GETARG_CSTRING.
I would much appreciate it if someone could point me in the right direction!

  The following code is simply test stuff and doesn't actually do anything other than raise notices

Thanks,
Brett

#include <strings.h>

#include "postgres.h"
#include "fmgr.h"
#include "executor/spi.h"

//PG_MODULE_MAGIC;

Datum bm_test(PG_FUNCTION_ARGS);

PG_FUNCTION_INFO_V1(bm_test);

Datum
bm_test(PG_FUNCTION_ARGS)
{
HeapTuple     tuple = NULL;
TupleDesc     tupdesc;
SPITupleTable *tuptable;
char          *szHostName = NULL;
int           i, ret;

//  palloc
  char *szPolicy = PG_GETARG_CSTRING(0);

elog(NOTICE, "szPolicy len [%d]'%s'\n", strlen(szPolicy), szPolicy);

  /*  Connect to the SPI Manager */
  if ((ret = SPI_connect()) < 0)
    /* internal error */
    elog(ERROR, "check_primary_key: SPI_connect returned %d", ret);

  /* Execute SELECT */
  if((ret = SPI_exec("SELECT sv_HostName FROM servers", 0)) != SPI_OK_SELECT) {
    /* CASE Error results ?, external function ? */
    elog(ERROR, "SELECT Failed, SP_exec returned %d.", ret);
  }

  while (SPI_tuptable->vals[i] != NULL)
  {
    tupdesc  = SPI_tuptable->tupdesc;
    tuptable = SPI_tuptable;
    tuple    = SPI_tuptable->vals[i];
    i++;

    szHostName = SPI_getvalue(tuple, tupdesc, 1);
    elog(NOTICE, "HostName %s", szHostName);
  }

  SPI_finish();
  PG_RETURN_NULL();
}

Compiled with:

gcc -Wall -Wmissing-prototypes -fpic -I/usr/include/pgsql/server/ -c bkptime.c
gcc -shared -o bkptime.so bkptime.o

Function created with:

create function bm_test(CSTRING) returns TEXT as '/home/brettm/BkpTime/bkptime.so' LANGUAGE 'c';

Executing the function returns the following:

ServerStats=# select * from bm_test('PRODAPP');
NOTICE:  szPolicy len [1]'
                          '

NOTICE:  HostName .......


-----------------------------------------------------------------------------------------------
This email, and the contents contained within, are private
and confidential between the sender and the individual(s)
to whom it is addressed.
The contents do not necessarily represent the views of Simplyhealth Group
Limited.

In the event of misdirection, the recipient is prohibited from 
using, copying or disseminating it or any information contained in it.
If you have received this email in error please notify Simplyhealth
immediately by telephone on 0845 075 2020, or by email to 
network.administrator@simplyhealth.co.uk

Simplyhealth Group Limited is registered and incorporated in England and Wales  
as a company limited by guarantee. Its registered office is at Hambleden House, 
Waterloo Court, Andover, Hampshire, SP10 1LQ, registered no. 5445654. We 
may record or monitor telephone calls to help improve our service and protect our 
members.
-----------------------------------------------------------------------------------------------

В списке pgsql-novice по дате отправления:

Предыдущее
От: Richard Broersma Jr
Дата:
Сообщение: Re: support for distributed transactions
Следующее
От: "Oeschey, Lars (I/EK-142, extern)"
Дата:
Сообщение: running second instance