Hello,

I've got a problem with Functions in C using SPI.

Using: PostgreSQL 8.3, Codeblocks, Windows Server 2003 R2

I compiled the file "pgExampleSPI.c" with the following code without any error:

/* Use 32-bit timer (provided header file uses 64-bit timer, not
* compatible with Windows postgreSQL versions */
#define _USE_32BIT_TIME_T

#include "postgres.h"
#include "executor\spi.h"

#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif

extern Datum count_person (PG_FUNCTION_ARGS);

PG_FUNCTION_INFO_V1(count_person);

__declspec(dllexport) Datum count_person(PG_FUNCTION_ARGS) {
    int32    ret;
    SPI_connect();
    ret = SPI_exec("SELECT count(*) FROM person", 0);
    SPI_finish();
    PG_RETURN_INT32(ret);
}

- then I've copied the resulting file "pgExampleSPI.dll" into the directory "G:\PostgreSQL\8.3\lib"
- I tried to load to function into PostgreSQL with the command:

CREATE FUNCTION count_person() RETURNS int
     AS 'G:/PostgreSQL/8.3/lib/pgExampleSPI.dll', 'count_person'
     LANGUAGE C STRICT;

- and received the following error description:

ERROR:  incompatible library "G:/PostgreSQL/8.3/lib/pgExampleSPI.dll": missing magic block
TIP:  Extension libraries are required to use the PG_MODULE_MAGIC macro.


After searching google for about 5 hours in couldn't find a way to solve this problem.

Can anybody help, please?

  

GRATIS für alle WEB.DE Nutzer: Die maxdome Movie-FLAT!   
Jetzt freischalten unter http://movieflat.web.de