如何与火鸟UDF中的char阵列一起工作
ib_util.h
#ifndef _IB_UTIL_H
#define _IB_UTIL_H
#ifdef __cplusplus
extern "C"
{
#endif
extern void *ib_util_malloc(long);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* _IB_UTIL_H */
test_udf.c
#include "ib_util.h"
#define MALLOC ib_util_malloc
typedef struct blob
{
short (*blob_get_segment)();
void *blob_handle;
int blob_number_segments;
int blob_max_segment;
int blob_total_length;
void (*blob_put_segment)();
} * BLOB;
char* fn_blob_echo(BLOB b)
{
char *buffer = (char *)ib_util_malloc(256);
return buffer;
}
编译为.so
FIREBIRD_UDF='/usr/lib/x86_64-linux-gnu/firebird/3.0/UDF/';
NameFile='test_udf';
gcc -c -O -fpic -Wwrite-strings $NameFile'.c'; ld -G $NameFile'.o' -lm -lc -o $NameFile'.so'; sudo cp $NameFile'.so' $FIREBIRD_UDF
在Firebird中
DECLARE EXTERNAL FUNCTION fn_blob_echo
BLOB
RETURNS CSTRING (256) FREE_IT
ENTRY_POINT 'fn_blob_echo' MODULE_NAME 'test_udf';
使用
select fn_blob_echo(CAST('please run' AS blob)) from rdb$database;
错误
SQL Error [335544721] [08006]: Unable to complete network request to host "localhost". [SQLState:08006, ISC error code:335544721]
ib_util.h
#ifndef _IB_UTIL_H
#define _IB_UTIL_H
#ifdef __cplusplus
extern "C"
{
#endif
extern void *ib_util_malloc(long);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* _IB_UTIL_H */
test_udf.c
#include "ib_util.h"
#define MALLOC ib_util_malloc
typedef struct blob
{
short (*blob_get_segment)();
void *blob_handle;
int blob_number_segments;
int blob_max_segment;
int blob_total_length;
void (*blob_put_segment)();
} * BLOB;
char* fn_blob_echo(BLOB b)
{
char *buffer = (char *)ib_util_malloc(256);
return buffer;
}
compile to .so
FIREBIRD_UDF='/usr/lib/x86_64-linux-gnu/firebird/3.0/UDF/';
NameFile='test_udf';
gcc -c -O -fpic -Wwrite-strings $NameFile'.c'; ld -G $NameFile'.o' -lm -lc -o $NameFile'.so'; sudo cp $NameFile'.so' $FIREBIRD_UDF
declare in firebird
DECLARE EXTERNAL FUNCTION fn_blob_echo
BLOB
RETURNS CSTRING (256) FREE_IT
ENTRY_POINT 'fn_blob_echo' MODULE_NAME 'test_udf';
using
select fn_blob_echo(CAST('please run' AS blob)) from rdb$database;
ERROR
SQL Error [335544721] [08006]: Unable to complete network request to host "localhost". [SQLState:08006, ISC error code:335544721]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论