Server crash during simple c-language function

Поиск
Список
Период
Сортировка
Искать

Server crash during simple c-language function

От:
Tomáš Kovářík <kovarik.tomas@gmail.com>
Дата:
Hi,

I am trying to create a simple c-language function for "PostgreSQL
8.4.4, compiled by Visual C++ build 1400, 32-bit" running on Windows 7
(32-bit). It works, until I use a SPI.

1) CRASH: I successfully execute a simple query using SPI_exec(), but
when getting the result, it crashes:
SPI_getvalue(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1);
I tried to look wherever I could, but I have no idea what could go wrong.

2) NOT COMPILE: When I what to read value of global SPI_result, I
cannot compile - unresolved external symbol "_SPI_result". I am
currently linking with 'postgres.lib" and I haven't found anything
else what to link with additionally. Compiling using Visual Studio
2008, C/C++ project set to compile for "C".

Can anybody point out, what I am doing wrong?
The complete code and project are below.

Thanks, Tomas

======================== CODE =============
#define BUILDING_DLL 1

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

#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif

PG_FUNCTION_INFO_V1(crash_repro);


__declspec (dllexport)
Datum crash_repro(PG_FUNCTION_ARGS)
{
	int exec_result;

	SPI_connect();

	exec_result = SPI_exec("select 'test'", 0);

	elog(NOTICE, "exect_result_state = %i", exec_result);
	elog(NOTICE, "SPI_processed = %u", SPI_processed);

	if ((SPI_processed > 0) && (SPI_tuptable != NULL))
	{
		elog(NOTICE, "SPI_tuptable is not NULL");
		SPI_getvalue(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1);
	}

	SPI_finish();

	PG_RETURN_NULL();
}

===================== VISUAL STUDIO PROJECT ===============


	
		
	
	
	
	
		
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
		
		
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
		
	
	
	
	
		
			
			
		
		
		
		
		
	
	
	

FAQ