[UDF Series] How to write one of Interbase UDFs

zhaozj2021-02-16  46

How to write Interbase UDF

(Author: Gregory Deatz - Hoagland, Longo, Moran, Dunst & Doukas)

Warton translation

Translator's narrative:

Due to Interbase performance, it is prominent, and it is an open source and cross-platform, there are many programmers using Delphi, C Builder to start using it as a subsequent database platform. But interbase's Chinese information is too small. Yesterday, a netizen mentioned the UDF of Interbase on 9CBS (User Defined Functions User Custom Function), I took a check, I couldn't find Chinese information in this area. So, I will translate one how to write and use Interbase UDF articles to everyone, I hope to use Interbase, C Builder, Delphi friends can like it!

----- Warton 2003.01.21

What is UDF?

UDF - (User Defined Functions) User-Defined Functions, is written in InterBase (generally C / C , or other languages ​​such as PASCAL) and compile into a shared library function. Under the Windows platform, shared libraries generally refer to Dynamic Link Library (DLL).

Why write UDF?

After all, the stored procedure itself can achieve considerable functions. Then why do you still use UDF?

However, the fact is that InterBase does not provide a considerable built-in function. Some common functions, string operations, date operations, etc. are not available.

So this happens, programming languages ​​such as Delphi, c, which can provide a modular algorithm, date variable processing, floating point format, and characters, and characters.

Writing UDF is a simple task, which can be said to be known. However, no experience writers may feel too difficult to write DLL / shared libraries ...

Use Delphi to write UDF for Windows platform

First launch a Delphi project

1. Start the car Delphi DLL project (a special type of project, when you choose "File", "New")

Generate a new unit for your function

2. Select "File", "New" ... Unit

3. Smart, you are best to save all files ... save your project to a place you think is appropriate.

Generate a module program

4. In the newly generated unit file:

5. Define your function in the interface segment:

Function Modulo (VAR i, J: Integer): Integer; CDECL; Export;

6. Implement this function:

Function Modulo (VAR i, J: Integer): Integer;

Begin

IF (j = 0) THEN

Result: = -1 // Just Check The Boundary Condition, And

// Return A Reasonably Uninteresting Answer.

Else

Result: = i mod j;

END;

7. In the newly generated project source code, write the following code to "Begin End.":

Exports

Modulo;

8. Now compile the project, you will get a work-run dynamic link library.

9. Now, what I must do is copying this DLL to the UDF directory that INTERBASE can be found, it may be:

C: / Program Files / Borland / Interbase / UDF

10. How to use UDF .... Press as follows. Use ISQL to connect to a new database

11. Write as follows:

DECLE EXTERNAL FUNCTION F_MODULO

Integer, IntegerReturns

INTEGER by value

Entry_point 'modulo' module_name 'DLL Name Minus ".dll"';

12 Submit your changes.

13. Test it now ...

SELECT F_MODULO (3, 2) from RDB $ DATABASE

吆 ... this is too simple, isn't it?

But how to deal with the string and date type?

(Due to time problems, I translated this today, I have to make a program, I am sorry J :), see you tomorrow !!)

转载请注明原文地址:https://www.9cbs.com/read-26653.html

New Post(0)