Author Topic: Memo/blob field showing unusable data sqlite3  (Read 1088 times)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12984
  • FPC developer.

H₂SO₄

  • Sr. Member
  • ****
  • Posts: 486
Re: Memo/blob field showing unusable data sqlite3
« Reply #16 on: July 31, 2026, 06:34:54 am »
Something's wrong with that database file... when I try to open it using DB Browser for SQLite, it throws a nonsensical error. It also doesn't really stick to UTF-16 (LE); use a hex editor to look at the XML data and you'll see what I mean.

Fortunately the SQLite3 CLI can still access the database and is able to rebuild it through back-to-back serialization & deserialization:

sqlite3 74TTL.db -- .dump | sqlite3 74TTL-Rebuilt.db

All symbol drawings are perfectly readable in the resulting database (which is now entirely UTF-8 as a bonus).

cdbc

  • Hero Member
  • *****
  • Posts: 2931
    • http://www.cdbc.dk
Re: Memo/blob field showing unusable data sqlite3
« Reply #17 on: July 31, 2026, 09:46:11 am »
Hi
@Sulfuric Acid: Cool, thanks, how does one go about 'seeing' them nice pictures?!? I mean XML?!?
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

Lutz Mändle

  • Full Member
  • ***
  • Posts: 102
Re: Memo/blob field showing unusable data sqlite3
« Reply #18 on: July 31, 2026, 10:51:51 am »
In the attached archive is a small test program that opens the database and displays the table Symbol.
The archive contains also the original database and 2 rebuilded files as UTF-8 and as UTF-16be, the original file is UTF-16le.

The database filename is set in the FormCreate method of the mainform and can given on the commandline.

Only in the UTF8-version the column Data is readable without tweaks, the other versions need a special sql statement and a special handling of the OnGetText event of the column Data.

The sqlite function unhex used in the tweaked sql statement is available since sqlite version 3.41 (february 2023).

Lutz Mändle

  • Full Member
  • ***
  • Posts: 102
Re: Memo/blob field showing unusable data sqlite3
« Reply #19 on: July 31, 2026, 12:46:24 pm »
The column Data of the table Symbol can read without tweaks if the column type is BLOB instead of TEXT regardless to the encoding.
« Last Edit: July 31, 2026, 12:49:37 pm by Lutz Mändle »

jamie

  • Hero Member
  • *****
  • Posts: 7902
Re: Memo/blob field showing unusable data sqlite3
« Reply #20 on: July 31, 2026, 11:20:42 pm »
Thats perfect!

I down loaded the newer versions of the DLL's and this is the statement I used.

 Sql:= 'SELECT SymbolID, unhex(hex(Data)) as Data from Symbol Where [SymbolID] = '+symbol.FilePos.ToString+';'; 

 I don't understand how the original program was able to process this with the version of the DLL it was using but it did, which leads me to believe there is more to it, I did see a zlib.dll in the source files but I don't know of any area of the code where that is being used, maybe I missed somewhere, the unpacking etc.

Now I need to know how to handle selecting the proper DLL for 32 bit verses 64 bit targets, I need to somehow set the path for the Sqlite.DLL before it loads.

Thank you very much, now I can debug the rest of the code. :D

Jamie
   
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 7902
Re: Memo/blob field showing unusable data sqlite3
« Reply #21 on: August 04, 2026, 12:47:41 am »
Although I have a working code base atm, I have noticed this, the original program reads and writes this field in as "BLOB", but checking the type here reports it as a "MEMO".

 is there a way to change the field definition locally within the FPC/LAZ code to trick the Sql code to read it as BLOB without editing the database files?

Maybe I can construct a SQL statement that indicates it as being a blob?

Jamie
The only true wisdom is knowing you know nothing

Lutz Mändle

  • Full Member
  • ***
  • Posts: 102
Re: Memo/blob field showing unusable data sqlite3
« Reply #22 on: August 04, 2026, 05:39:38 am »
Quote
Maybe I can construct a SQL statement that indicates it as being a blob?

Use:
Code: Text  [Select][+][-]
  1. select SymbolID, cast(Data as Blob) as Data from Symbol;
  2.  

This has the benefit, that older sqlite versions (before 3.41) are also working.

jamie

  • Hero Member
  • *****
  • Posts: 7902
Re: Memo/blob field showing unusable data sqlite3
« Reply #23 on: August 05, 2026, 12:14:32 am »
Thank you for that, I will try that :D


 That works !  Thank you!
Jamie
« Last Edit: August 05, 2026, 12:32:29 am by jamie »
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018