It's possible to call C functions through CREATE FUNCTION
but how can .NET functions in dll's be called from postgres?
可以通过CREATE FUNCTION调用C函数,但是如何从postgres调用dll中的.NET函数?
2 个解决方案
#1
You can define an external function using CREATE FUNCTION. This reference implies that the DLL must be a native DLL using the C calling convention and hence cannot handle managed code.
您可以使用CREATE FUNCTION定义外部函数。此引用意味着DLL必须是使用C调用约定的本机DLL,因此无法处理托管代码。
You could try to use Mono AOT or MS Native Image Generator to compile the managed code to native code, but I cannot tell if this will result in a native DLL using C calling convention. You have to try.
您可以尝试使用Mono AOT或MS Native Image Generator将托管代码编译为本机代码,但我无法判断这是否会导致使用C调用约定的本机DLL。你得试试。
If this does not work, you could create an unmanged wrapper for your DLL.
如果这不起作用,您可以为DLL创建一个unmanged包装器。
UPDATE
You have to write a wrapper - C-Language Functions states that the DLL must include a magic block that will not be availiable if you compile managed code to native code.
您必须编写一个包装器 - C语言函数声明DLL必须包含一个魔术块,如果您将托管代码编译为本机代码,则该魔术块将无法使用。
#2
It looks like there is some overhead to calling C functions from PosgtreSQL, External Functions in Postgres @ Linux Gazette covers writing such a method in C. I would surmise from that that you could, if you REALLY need to, build a hosting module that loads a CLR instance and provides an entry point into your C# method that is mapped with the appropriate Postgres linking logic. This seems extremely costly.
看起来从PosgtreSQL调用C函数有一些开销,Postgres @Linux Gazette中的外部函数涵盖了用C编写这样的方法。我猜想你可以,如果你真的需要,你可以构建一个加载的托管模块一个CLR实例,并为您的C#方法提供一个入口点,该入口点与相应的Postgres链接逻辑映射。这看起来非常昂贵。
Another approach that might be better would be to encapsulate the C# method (which I am assuming is already written) in a web service, and use a wrapper (not necessarily C, but one of the lighter-weight extension development bindings for Postgres) that will call out to the web service.
另一种可能更好的方法是在Web服务中封装C#方法(我假设已经编写),并使用包装器(不一定是C,但是Postgres的轻量级扩展开发绑定之一)将呼叫网络服务。
#1
You can define an external function using CREATE FUNCTION. This reference implies that the DLL must be a native DLL using the C calling convention and hence cannot handle managed code.
您可以使用CREATE FUNCTION定义外部函数。此引用意味着DLL必须是使用C调用约定的本机DLL,因此无法处理托管代码。
You could try to use Mono AOT or MS Native Image Generator to compile the managed code to native code, but I cannot tell if this will result in a native DLL using C calling convention. You have to try.
您可以尝试使用Mono AOT或MS Native Image Generator将托管代码编译为本机代码,但我无法判断这是否会导致使用C调用约定的本机DLL。你得试试。
If this does not work, you could create an unmanged wrapper for your DLL.
如果这不起作用,您可以为DLL创建一个unmanged包装器。
UPDATE
You have to write a wrapper - C-Language Functions states that the DLL must include a magic block that will not be availiable if you compile managed code to native code.
您必须编写一个包装器 - C语言函数声明DLL必须包含一个魔术块,如果您将托管代码编译为本机代码,则该魔术块将无法使用。
#2
It looks like there is some overhead to calling C functions from PosgtreSQL, External Functions in Postgres @ Linux Gazette covers writing such a method in C. I would surmise from that that you could, if you REALLY need to, build a hosting module that loads a CLR instance and provides an entry point into your C# method that is mapped with the appropriate Postgres linking logic. This seems extremely costly.
看起来从PosgtreSQL调用C函数有一些开销,Postgres @Linux Gazette中的外部函数涵盖了用C编写这样的方法。我猜想你可以,如果你真的需要,你可以构建一个加载的托管模块一个CLR实例,并为您的C#方法提供一个入口点,该入口点与相应的Postgres链接逻辑映射。这看起来非常昂贵。
Another approach that might be better would be to encapsulate the C# method (which I am assuming is already written) in a web service, and use a wrapper (not necessarily C, but one of the lighter-weight extension development bindings for Postgres) that will call out to the web service.
另一种可能更好的方法是在Web服务中封装C#方法(我假设已经编写),并使用包装器(不一定是C,但是Postgres的轻量级扩展开发绑定之一)将呼叫网络服务。