Recent

Author Topic: (SOLVED) Lazarus + Firebird + Emoji  (Read 3517 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
(SOLVED) Lazarus + Firebird + Emoji
« on: January 09, 2021, 04:41:33 pm »
Hi guys, can anyone explain to me how to insert a string containing emojis into a firebird database?
« Last Edit: January 10, 2021, 07:05:17 pm by xinyiman »
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

Zoran

  • Hero Member
  • *****
  • Posts: 1831
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Lazarus + Firebird + Emoji
« Reply #1 on: January 09, 2021, 06:21:55 pm »
Hi guys, can anyone explain to me how to insert a string containing emojis into a firebird database?

Hi.

Are you serious?
How can you expect help when you provided no information about what you have tried?
Xinyiman, you have been active member in this forum for quite a long. You should know better.

Would you mind at least providing the example what does work when string contains only ASCII and does not work with some other characters.

Then,
What is the encoding of the database field you are trying to write into? Is it utf8?
What is the encoding of the connection between your application and database? Is this a gui (LCL dependent) application?

What db connection library do you use (SQLDb, IBX, Zeos, ...)?
What is Firebird server version?

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Lazarus + Firebird + Emoji
« Reply #2 on: January 09, 2021, 07:14:23 pm »


s := 'It is 🫖  teatime';

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: Lazarus + Firebird + Emoji
« Reply #3 on: January 09, 2021, 07:33:16 pm »
Hi guys, can anyone explain to me how to insert a string containing emojis into a firebird database?

Hi.

Are you serious?
How can you expect help when you provided no information about what you have tried?
Xinyiman, you have been active member in this forum for quite a long. You should know better.

Would you mind at least providing the example what does work when string contains only ASCII and does not work with some other characters.

Then,
What is the encoding of the database field you are trying to write into? Is it utf8?
What is the encoding of the connection between your application and database? Is this a gui (LCL dependent) application?

What db connection library do you use (SQLDb, IBX, Zeos, ...)?
What is Firebird server version?

You are definitely right. I have not specified anything because any solution suits me. I did a simple test with firebird 2.5 on linux (utf8 charset). I used zeoslib to do a test. The target field is a set_type text blob. By inserting a simple text of course the insert works. But passing it an emoji fails the SQL execution. I didn't do anything else. And obviously being just an analysis for the feasibility of a project, any solution is fine by me. Sorry again if I didn't explain myself well in the first message.

PS: I love martin mystere and his helper: java
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4474
  • I like bugs.
Re: Lazarus + Firebird + Emoji
« Reply #4 on: January 09, 2021, 09:02:53 pm »
I did a simple test with firebird 2.5 on linux (utf8 charset). I used zeoslib to do a test. The target field is a set_type text blob. By inserting a simple text of course the insert works. But passing it an emoji fails the SQL execution. I didn't do anything else.
The bug is either in Firebird or in Zeoslib then.
Usually code dealing with UTF-8 encoding works because multi-byte codepoints are so common.
Code dealing with UTF-16 encoding however is often buggy and actually supports only UCS-2.
Emojis typically are outside of Unicode BMP and the bug shows up.
My guess is that somewhere the UTF-8 data is converted to UTF-16 and then handled with sloppy code.
Maybe you can debug Zeoslib. If it passes the data correctly forward, then Firebird is guilty.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Zoran

  • Hero Member
  • *****
  • Posts: 1831
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Lazarus + Firebird + Emoji
« Reply #5 on: January 09, 2021, 11:14:47 pm »

You are definitely right. I have not specified anything because any solution suits me. I did a simple test with firebird 2.5 on linux (utf8 charset). I used zeoslib to do a test. The target field is a set_type text blob. By inserting a simple text of course the insert works. But passing it an emoji fails the SQL execution. I didn't do anything else. And obviously being just an analysis for the feasibility of a project, any solution is fine by me. Sorry again if I didn't explain myself well in the first message.

Zeos connection has two fields -- ControlsCodePage and ClientCodepage (at least it is so with Zeos 7.2, which is rather old, but I still have it).
I don't know if it helps, but make sure they are set to cCP_UTF8 and UTF8.

If not, try to create simple test with SQLDb. If it works, then it is Zeos bug.
Then report it in their forum.

Anyway, paste here the text example which fails, so that we can try the same.

PS: I love martin mystere and his helper: java

 8-)
« Last Edit: January 09, 2021, 11:16:25 pm by Zoran »

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: Lazarus + Firebird + Emoji
« Reply #6 on: January 10, 2021, 11:31:24 am »
Zoran, I added the two parameters you were telling me. The code no longer failed. He entered the record. But it transformed the emoji 👍 in "=M".

I have searched around and for mysql it seems that utf8 is not enough, it must become utf8mb4. I just don't know how to set it up in firebird when creating the database. I use Flamerobin for db management. Tips?
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

devEric69

  • Hero Member
  • *****
  • Posts: 648
Re: Lazarus + Firebird + Emoji
« Reply #7 on: January 10, 2021, 12:30:51 pm »
I use Flamerobin for db management. Tips?

Hello,

For me, RedExpert "rocks" (nevertheless, I don't preview too many frames arranged at the same time in RedExpert main form; otherwise, some Java widget{s} freeze{s} it; I don't understand which one{s}.), and IBX "rolls" ☺.
« Last Edit: January 10, 2021, 01:09:55 pm by devEric69 »
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4474
  • I like bugs.
Re: Lazarus + Firebird + Emoji
« Reply #8 on: January 10, 2021, 12:52:04 pm »
I have searched around and for mysql it seems that utf8 is not enough, it must become utf8mb4. I just don't know how to set it up in firebird when creating the database.
What is utf8mb4? ... OK, I can find it in the net :

UTF-8 is a variable-length encoding. In the case of UTF-8, this means that storing one code point requires one to four bytes. However, MySQL's encoding called "utf8" (alias of "utf8mb3") only stores a maximum of three bytes per code point. ...
...  As of MySQL 5.5.3, the utf8mb4 character set uses a maximum of four bytes per character supports supplemental characters

WTF! They already handle a variable length encoding but then leave the last byte out. Why? Totally stupid.
What is the connection between Firebird and MySQL? I thought they are separate DBs. I am not a DB expert as you can see.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Zoran

  • Hero Member
  • *****
  • Posts: 1831
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Lazarus + Firebird + Emoji
« Reply #9 on: January 10, 2021, 01:04:09 pm »
The Firebird documentation (see here) says that utf8 reserves four bytes.

That utf8mb4 is something specifically created by MySQL, as from the start they didn't support utf8 correctly.
« Last Edit: January 10, 2021, 01:10:43 pm by Zoran »

Zoran

  • Hero Member
  • *****
  • Posts: 1831
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Lazarus + Firebird + Emoji
« Reply #10 on: January 10, 2021, 01:06:22 pm »
Zoran, I added the two parameters you were telling me. The code no longer failed. He entered the record. But it transformed the emoji 👍 in "=M".

Does it really transform it or it is that FlameRobin does not display it correctly?
Did you try writting the string it in Lazarus application and reading it in string in that same application?

devEric69

  • Hero Member
  • *****
  • Posts: 648
Re: Lazarus + Firebird + Emoji
« Reply #11 on: January 10, 2021, 01:56:16 pm »
Beware: for information, FlameRobin is an abandonware (globally, its database engine's driver has diverged too much from the official Firebird engine features. It can't evolve anymore: bad design choice, AFAIK).
« Last Edit: January 10, 2021, 02:08:46 pm by devEric69 »
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: Lazarus + Firebird + Emoji
« Reply #12 on: January 10, 2021, 07:05:01 pm »
I actually reloaded the data from the same program and I see the emoji correctly. Thanks for the time you have dedicated to me.
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

Zoran

  • Hero Member
  • *****
  • Posts: 1831
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Lazarus + Firebird + Emoji
« Reply #13 on: January 10, 2021, 07:26:18 pm »
I actually reloaded the data from the same program and I see the emoji correctly. Thanks for the time you have dedicated to me.

That was what I expected. I'm glad you solved it.

valdir.marcos

  • Hero Member
  • *****
  • Posts: 1106
Re: Lazarus + Firebird + Emoji
« Reply #14 on: January 12, 2021, 04:32:03 am »
Beware: for information, FlameRobin is an abandonware (globally, its database engine's driver has diverged too much from the official Firebird engine features. It can't evolve anymore: bad design choice, AFAIK).
Are you sure?

I have checked 5 releases in the last 6 months, being 2 in the last 10 days:
https://github.com/mariuz/flamerobin/releases

 

TinyPortal © 2005-2018