Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > PostgreSQL > How to get conn ptr in C-lang external function?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-17-08, 10:56
brbrbr brbrbr is offline
Registered User
 
Join Date: Jan 2008
Location: Moscow
Posts: 8
How to get conn ptr in C-lang external function?

Hi again )

I have C-language external function in which I need to execute some SQL commands like SELECT\UPDATE\DELETE.

To do this via libpq.dll I need *conninfo. Is there any way to get it inside the external function? Or may be is there any another way to execute some SQL commands inside the external C-language function?
Reply With Quote
  #2 (permalink)  
Old 01-17-08, 12:05
brbrbr brbrbr is offline
Registered User
 
Join Date: Jan 2008
Location: Moscow
Posts: 8
I solve it myself again. : )

There is SPI (server programming interface) for these purposes.

To execute an SQL command in external function u should first include "executor/spi.h", then
Code:
SPI_connect(); SPI_execute(...); SPI_finish();

And it should work... If only u will not get linker error as I do : (

Code:
trigf.obj : error LNK2001: unresolved external symbol _SPI_finish trigf.obj : error LNK2001: unresolved external symbol _SPI_execute trigf.obj : error LNK2001: unresolved external symbol _SPI_connect

Looks like I miss some libraries or .def files...
Reply With Quote
  #3 (permalink)  
Old 01-18-08, 06:46
brbrbr brbrbr is offline
Registered User
 
Join Date: Jan 2008
Location: Moscow
Posts: 8
Last problem was solved after compiling postgres.lib from PostgreSQL sources and including it into library modules in project settings.

Or it also can be solved using plpgsql.dll (from PostgreSQL binaries), but in this way u'll have to use LoadLibrary() and etc.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On