如何与火鸟UDF中的char阵列一起工作

发布于 2025-01-27 06:09:45 字数 1655 浏览 2 评论 0原文

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]

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文