How can I create a user-defined function?

In this forum you may discuss all issues concerning the Lazarus IDE and Freepascal (both running on Windows or Linux).

Moderators: gto, cipto_kh, EgonHugeist

pastor
Fresh Boarder
Fresh Boarder
Posts: 3
Joined: 28.08.2017, 13:26

How can I create a user-defined function?

Postby pastor » 28.08.2017, 13:37

Hi All!

How can I create a user-defined function in Zeos? I need it for making case-insensitive LIKE.

This this solution for TSQLite3Dataset but I need same for ZeosLib - http://forum.lazarus.freepascal.org/ind ... ic=34259.0

sqlite3_create_function(...

marsupilami
Gold Boarder
Gold Boarder
Posts: 580
Joined: 17.01.2011, 14:17

Re: How can I create a user-defined function?

Postby marsupilami » 29.08.2017, 11:06

Hello pastor,

user defined functions in Firebird have nothing to do with the client program and Zeos. If you want to extend the firebird database with other functions, you need to write a dll/so and register the functions in your database. The following ressources might help you:

https://www.firebirdsql.org/refdocs/lan ... reext.html
https://www.codeproject.com/articles/43 ... sql-server
http://www.firebirdfaq.org/faq83/
http://www.firebirdfaq.org/faq169/

With best regards,

Jan

pastor
Fresh Boarder
Fresh Boarder
Posts: 3
Joined: 28.08.2017, 13:26

Re: How can I create a user-defined function?

Postby pastor » 30.08.2017, 08:53

Thank you, Jan! But I am using SQLite3.

I've found solution for SQLDB:

uses Unit_SQLite3Dataset_LanguageSupport;
...
SQLite3Dataset_LanguageSupport (SQLite3Connection.Handle);

But it does`t work in Zeos.
How to get a Handle of SQLite database in Zeoslib?

marsupilami
Gold Boarder
Gold Boarder
Posts: 580
Joined: 17.01.2011, 14:17

Re: How can I create a user-defined function?

Postby marsupilami » 06.09.2017, 09:36

Hello Pastor,

indeed that seems to be hard. You would have to Query the TZConnection object for the IZConnection interface. You can do that With TZConnection.DbcConnection. That one should be an IZSQLiteConnection interface - so cast it. It most probably doesn't have a method for connecting user defined functions but it should be fairly easy to extend it to do that. Have a look at ZDbcSqlite.pas. There you will find the interface definition and the TZSQLiteConnection object. Extend both and you should be fine. If you have questions, just ask them and I will answer.

With best regards,

Jan

pastor
Fresh Boarder
Fresh Boarder
Posts: 3
Joined: 28.08.2017, 13:26

Re: How can I create a user-defined function?

Postby pastor » 06.09.2017, 14:59

Jan, thanks for the tip!

This code works:

uses ZDbcSqLite, Unit_SQLite3Dataset_LanguageSupport;
var dbHandle: Pointer;
...
dbHandle := (ZConnection1.DbcConnection as TZSQLiteConnection).GetConnectionHandle();
SQLite3Dataset_LanguageSupport(dbHandle);

Blessings..


Return to “Lazarus / Freepascal”

Who is online

Users browsing this forum: No registered users and 1 guest