Search Postgresql Archives

Re: C-Functions using SPI - Missing Magic Block

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

 



Hi people,

after a two days break:

I could compile the following code with Visual C++ Express 2010 under Windows Server 2003 R2:

/* Use 32-bit timer (provided header file uses 64-bit timer, not
* compatible with Windows postgreSQL versions */
#define _USE_32BIT_TIME_T
#define BUILDING_DLL 1
#include "postgres.h"
#include "fmgr.h" /* PG_MODULE_MAGIC */
#include "executor\spi.h" /* SPI - Server Programming Interface */

PG_MODULE_MAGIC;

PG_FUNCTION_INFO_V1(count_person);

__declspec(dllexport)
Datum count_person(PG_FUNCTION_ARGS) {
int ret;

SPI_connect();
ret = SPI_exec("SELECT count(*) FROM person", 0);
SPI_finish();

PG_RETURN_INT32(ret);
}

 

The steps I did:

- install GnuWin32 (GetText for Windows) and copy libintl.h to ...\PostgreSQL\8.3\include\server\port\win32

- edit "pg_config.h" and replace #define ENABLE_NLS 1 by #undef ENABLE_NLS

- create new empty DLL-Project and add new C++-File
- Rename file into "filename.c"

- in Visual C++ add:

PostgreSQL\8.3\include\server\port\win32

PostgreSQL\8.3\include\server\

PostgreSQL\8.3\bin

postgres.lib

compile as C-Code !!!

see also:

http://www.postgresql.org/docs/8.2/interactive/xfunc-c.html

http://www.postgresql.org/docs/8.0/interactive/xfunc-c.html

http://www.dbforums.com/postgresql/1626445-how-get-conn-ptr-c-lang-external-function.html

 

But I guess I still did something wrong, because no matter how many rows exist in my table "person" the result in always 5.

Could this be an data type problem? count(*) returns int8

int8 -> int (C-type) -> PG_RETURN_INT32 ??? Could this cause the problem?

 

Thanks for any advise, Max.
___________________________________________________________
WEB.DE DSL ab 19,99 Euro/Monat. Bis zu 150,- Euro Startguthaben und 
50,- Euro Geldprämie inklusive! https://freundschaftswerbung.web.de

-- 
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