[UDF系列]如何编写InterBase UDF 之三

** (接上一篇) **

** ** 如何编写 InterBase UDF

warton 译

(前面讲了在windows下编写UDF)

** 编写 Linux/Unix平台的UDF **

( 译者注:原用大量篇幅讲述了 linux 下的 SO(shared object) 文件和 windows 下的 DLL 文件 , 其实它们都是一种动态链接库 , 在此不做详细翻译 !)

** 怎么在 Linux ** ** 下生成一个 shared library( ** ** 共享库 ) ** ** ? **

1. 建立一个 C 文件(扩展名为 .c )

2.建立模块函数:int modulo(int *, int *);


 


int modulo(a, b)


     int *a;


     int *b;


{


  if (*b == 0)


    return -1; // return something suitably stupid.


  else


    return *a % *b;


}


 


**编译和使用它**


****


在命令行下:


gcc -c -O -fpic -fwritable-strings
 1<your udf="">.c
 2    
 3    
 4    ld -G <your udf="">.o -lm -lc -o <your udflib="">.so
 5    
 6    
 7    cp <your udflib="">.so /usr/interbase/udf
 8    
 9    
10    然后在ISQL中:
11    
12    
13    declare external function f_Modulo
14    
15    
16    integer, integer
17    
18    
19    returns
20    
21    
22    integer by value
23    
24    
25    entry_point 'modulo' module_name 'name of shared library';
26    
27    
28     
29    
30    
31    commit;
32    
33    
34     
35    
36    
37    select f_Modulo(3, 2) from rdb$database;
38    
39    
40     
41    
42    
43    真是太简单了!!
44    
45    
46     
47    
48    
49    结论:
50    
51    
52            看来编写UDF真的不难!看,它包含的内容也不太多!毕竟Linux开发者也不为难了。
53    
54    
55    最后:
56    
57    
58            如果你想要更好的编程例子,可以下载FreeUDFLib—一个Delphi的UDF库和一个FreeUDFLibC―一个基于C的UDF库,它可以运行在Solaris,Linux,Windows等
59    
60    
61     
62    
63    
64    _(注,由于原本少量内容与主题无关,本人没有翻译)_</your></your></your></your>
Published At
Categories with 数据库类
Tagged with
comments powered by Disqus