ROOT and Binary Mysql data types


I am implementing a MySql database, composed of many columns (doubles, strings etc.) and one BLOB variable which should be a ROOT file (TFile).
I would like to manage the writing and reading operations through ROOT classes (TSQLStatement).
No problem to deal with double/string, but I am encountering problems in using the TFile.
What is the best way to write and retrieve the TFile?
I could not find any example around.

Thank you in advance for any help you can provide.

Edoardo Farina

Hi Edoardo,

these two howtos will get you started
o … file.ipynb
o … file.ipynb


Hello Danilo,

Thanks a lot for your answer.
My question was about how I can write a TFile to the database as binary data (BLOB) and how I can, from the database, retrieve a TFile from a binary value.
I found this discussion: [url]Problem retrieve a longblob from a mysql db
Here the code I tried to use, just to explain you better my question:


TSQLStatement* stmt = serv->Statement(ss.str().c_str(), 4000);
if (stmt->Process()) {
if (stmt->GetNumFields()>0){

  while (stmt->NextResultRow()) {
    unsigned char* blob = 0;
    Long_t blobSize;
    stmt->GetBinary(9, (void*&) blob, blobSize);
     TMessage mess;
      mess.SetBuffer(blob, blobSize, kFALSE);
       TFile* m= (TFile*)(mess.ReadObjectAny(TFile::Class()));



Hi Fabio,

probably the best way to transform a TFile in a blob is to treat this entity as a normal file, e.g. w/o using the ROOT API, and stream it into the db.
Upon retrieval, two options are available:

  1. Restore the file on disk, open it and proceed with some operations
  2. Use TMemFile and directly open the file in memory based on the content of the blob: … 5c1f6dba53