当前位置:网站首页>达梦数据库udf实现
达梦数据库udf实现
2022-07-05 18:24:00 【Q446512799】
官方介绍的很简单,其实有点小坑
头文件引用
//-I/dm/dmdbms/include/
#include "de_pub.h"
库文件引用
-L/dm/dmdbms/bin/ -ldmde字符串拼接代码(函数名必须是大写,否则创建成功,调用报错【[-7095]:外部函数加载失败.】)
de_data C_CONCAT(de_args *args)
{
de_data de_ret;
char* str1;
char* str2;
char* str3;
int len1;
int len2;
str1 = (char*)de_get_str(args, 0); /*从参数列表中取第0个参数*/
str2 = (char*)de_get_str_with_len(args, 1, (udint4*)&len2); /*从参数列表中取第1个参数的值以及长度*/
len1 = strlen(str1);
str3 = (char*)malloc(len1 + len2);
memcpy(str3, str1, len1);
memcpy(str3 + len1, str2, len2);
de_str_free((sdbyte*)str1); /*调用get函数得到字符串之后,需要调用此函数释放字符串空间*/
de_str_free((sdbyte*)str2);
de_ret = de_return_str_with_len((udbyte*)str3, len1 + len2); /*返回字符串*/
free(str3);
return de_ret;
}编译生成动态库
创建函数
CREATE OR REPLACE FUNCTION C_CONCAT(A VARCHAR, B VARCHAR)
RETURN VARCHAR
EXTERNAL '/dm/dmdbms/bin/libtestudf.so' C_CONCAT USING C;
/实际项目使用

注:因为c编写达梦udf走的是dmap代理(/dm/dmdbms/bin/dmap),所以首先需要启动代理。如果库依赖外部环境变量,需要在配置环境变量的控制台手工启动dmap,而不是在运行disql命令行控制台配置,否则环境变量不能正常识别。
边栏推荐
猜你喜欢

图像分类,看我就够啦!

U-Net: Convolutional Networks for Biomedical Images Segmentation

Thoroughly understand why network i/o is blocked?

Record eval() and no in pytoch_ grad()

爬虫01-爬虫基本原理讲解

第十一届中国云计算标准和应用大会 | 云计算国家标准及白皮书系列发布 华云数据全面参与编制

About Estimation with Cross-Validation

How to obtain the coordinates of the aircraft passing through both ends of the radar

About Statistical Power(统计功效)

vulnhub之darkhole_2
随机推荐
第十一届中国云计算标准和应用大会 | 华云数据成为全国信标委云计算标准工作组云迁移专题组副组长单位副组长单位
7-2 保持链表有序
爬虫01-爬虫基本原理讲解
案例分享|金融业数据运营运维一体化建设
The 11th China cloud computing standards and Applications Conference | China cloud data has become the deputy leader unit of the cloud migration special group of the cloud computing standards working
Exemple Quelle est la relation entre le taux d'échantillonnage, l'échantillon et la durée?
Huaxia Fund: sharing of practical achievements of digital transformation in the fund industry
含重复元素取不重复子集[如何取子集?如何去重?]
开户注册股票炒股安全吗?有没有风险的?靠谱吗?
Cronab log: how to record the output of my cron script
Access the database and use redis as the cache of MySQL (a combination of redis and MySQL)
How to automatically install pythn third-party libraries
Xiaobai getting started with NAS - quick building private cloud tutorial series (I) [easy to understand]
Share: ZTE Yuanhang 30 Pro root unlock BL magick ZTE 7532n 8040n 9041n brush mask original brush package root method Download
MYSQL中 find_in_set() 函数用法详解
Insufficient picture data? I made a free image enhancement software
ViewPager + RecyclerView的内存泄漏
【PaddlePaddle】 PaddleDetection 人脸识别 自定义数据集
Notes on common management commands of openshift
模拟百囚徒问题