Search Postgresql Archives

Re: C-Functions using SPI - Missing Magic Block

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



HI,

El viernes, 2 de julio de 2010 10:26:43 UTC-3, (desconocido)  escribió:
> 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_<WBR>person);
> 
> __declspec(dllexport) Datum count_person(PG_FUNCTION_ARGS) {
>     int32    ret;
>     SPI_connect();
>     ret = SPI_exec(&quot;SELECT count(*) FROM person&quot;, 0);
>     SPI_finish();
>     PG_RETURN_INT32(ret);
> }
> 
> - then I&#39;ve copied the resulting file &quot;pgExampleSPI.dll&quot; into the directory &quot;G:\PostgreSQL\8.3\lib&quot;
> - I tried to load to function into PostgreSQL with the command:
> 
> CREATE FUNCTION count_person() RETURNS int
>      AS &#39;G:/PostgreSQL/8.3/lib/<WBR>pgExampleSPI.dll&#39;, &#39;count_person&#39;
>      LANGUAGE C STRICT;
> 
> - and received the following error description:
> 
> ERROR:  incompatible library &quot;G:/PostgreSQL/8.3/lib/<WBR>pgExampleSPI.dll&quot;: missing magic block
> TIP:  Extension libraries are required to use the PG_MODULE_MAGIC macro.
> 
> 
> After searching google for about 5 hours in couldn&#39;t find a way to solve this problem.
> 
> Can anybody help, please?
> 
> <span style="font-size:9pt"><span style="font-family:verdana,geneva"><span style="background-color:transparent"><span style="color:#000000"><span style="color:#000000"></span></span></span></span></span></div>  
> 
> <table cellpadding="0" cellspacing="0" border="0"><tr><td bgcolor="#000000"><img width="1" height="1" border="0" alt="" origsrc="https://img.web.de/p.gif";></td></tr><tr><td style="font-family:verdana;font-size:12px;line-height:17px">GRATIS für alle <a href="http://WEB.DE"; target="_blank">WEB.DE</a> Nutzer: Die maxdome Movie-FLAT!   
> Jetzt freischalten unter <a href="http://movieflat.web.de"; target="_blank">http://movieflat.web.de</a></td></tr></table>
> </div>

 Hi, you must put "PG_MODULE_MAGIC" after include sentences, if you use include own put in firth .h of you call in .c code, remenber after include section

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux