当前位置:网站首页>达梦数据库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命令行控制台配置,否则环境变量不能正常识别。
边栏推荐
- c期末复习
- 关于服装ERP,你想知道的都在这里了
- 彻底理解为什么网络 I/O 会被阻塞?
- How to choose the most formal and safe external futures platform?
- Multithreading (I) processes and threads
- sample_rate(采样率),sample(采样),duration(时长)是什么关系
- [paddleclas] common commands
- Wu Enda team 2022 machine learning course, coming
- Image classification, just look at me!
- 7-1 链表也简单fina
猜你喜欢
pytorch yolov5 训练自定义数据
@Extension, @spi annotation principle
vulnhub之darkhole_2
About Estimation with Cross-Validation
Record a case of using WinDbg to analyze memory "leakage"
Memory management chapter of Kobayashi coding
About statistical power
How to obtain the coordinates of the aircraft passing through both ends of the radar
《2022中国信创生态市场研究及选型评估报告》发布 华云数据入选信创IT基础设施主流厂商!
使用JMeter录制脚本并调试
随机推荐
【在优麒麟上使用Electron开发桌面应】
写作写作写作写作
Writing writing writing
jdbc读大量数据导致内存溢出
Personal understanding of convolutional neural network
How to improve the thermal management in PCB design with the effective placement of thermal through holes?
小林coding的内存管理章节
Generate XML schema from class
音视频包的pts,dts,duration的由来.
关于服装ERP,你想知道的都在这里了
Image classification, just look at me!
Use of print function in MATLAB
The 11th China cloud computing standards and Applications Conference | cloud computing national standards and white paper series release, and Huayun data fully participated in the preparation
Reading notes of Clickhouse principle analysis and Application Practice (5)
Introduction to Resampling
[PM2 details]
兄弟组件进行传值(显示有先后顺序)
MYSQL中 find_in_set() 函数用法详解
Various pits of vs2017 QT
FCN: Fully Convolutional Networks for Semantic Segmentation