fernandobatels / rsfbclient

Rust Firebird Client
MIT License
76 stars 11 forks source link

Question: Example or ressource for UDF / UDR. #143

Closed GilShoshan94 closed 1 year ago

GilShoshan94 commented 1 year ago

Hi @fernandobatels,

It's not an issue, just a question.

Do you know how to write a UDR in Rust for Firebird 4 ? Do you have a example you can share or can you point me to a ressource on how it can be achieved please ?

Thank you

fernandobatels commented 1 year ago

Do you know how to write a UDR in Rust for Firebird 4 ?

Unfortunately no. I never tried to write an UDF.

Do you have a example you can share or can you point me to a ressource on how it can be achieved please ?

Do you have experience writing UDFs in other languages? Firebird has a doc about it.

To do this in rust, you can write a C API.

Tonight I will try make some tests and share it here.

fernandobatels commented 1 year ago

Do you know how to write a UDR in Rust for Firebird 4 ?

Unfortunately no. I never tried to write an UDF.

Do you have a example you can share or can you point me to a ressource on how it can be achieved please ?

Do you have experience writing UDFs in other languages? Firebird has a doc about it.

To do this in rust, you can write a C API.

Tonight I will try make some tests and share it here.

GilShoshan94 commented 1 year ago

Do you have experience writing UDFs in other languages?

No, not yet. Thank you for the ressource.

I don't have a lot of experience in C nor C++, I know mainly Rust and Python. And in Rust I do mainly Tokio stuff, I didn't had the chance to try embedded stuff yet, nor trying to FFI with C.

I found this ressource too to write a UDR if it can help: https://scm.ibphoenix.com:3000/public/MyFirstUDRKit

I appreciate you looking into this. Thank you.

fernandobatels commented 1 year ago

I don't have lot of experience with UDF too, so this is my two cents.

  1. Enable the UdfAccess on firebird.conf;
  2. Enable the lib section on your crate project. Like on setting up a project;
  3. Create your function:
    #[no_mangle]
    pub extern "C" fn check_status() -> u8 {
       9
    }
  4. Build the project and copy the target/debug/....so file to your UDF path;
  5. Register your function on your firebird database:
    declare external function f_check_status
    returns int by value
    entry_point 'check_status' module_name 'YOURLIB';
    commit;
  6. Enjoy your new function:
    select f_check_status() from RDB$DATABASE;
GilShoshan94 commented 1 year ago

Thank you @fernandobatels ! This helped me.