How to use sqlite3 in ROOT?

I have an sqlite3 database which I can interrogate with command lines in macOS.
I would like to interrogate this database in a ROOT macro and would like to know,
how to do that:
What are the necessary lines to insert into the macro?
Can I execute the macro interactively or should I compile, load and run it?


Maybe you can take a look at those tutorials

It seems to me that those tutorials are dealing with sqlite databases which were created in a ROOT session.
I have a sqlite3 database already created and filled outside ROOT and would like to read it inside ROOT. How to do that? Or how to convert it into a TSQLFile?

Sorry, but I don’t know. I was hoping those tutorials were enough… I’ll ask next week if someone knows more about sqlite

Many thanks in advance!

I could incorporate straightforwardly the sqlite example inside ROOT, see attached files.
The only think I don’t know how to transport from the “callback” function the data outside
this function, i.e. to the main body of the program, i.e. printing histograms from the data, etc.
Test_sqlite3.C (1.5 KB)
Test_sqlite3.txt (3.5 KB)

I have no experience with it, but as the documentation says:

Hi Elemer,

Yes, TSQLFile creates own tables in database and therefore not useful, when you want to read data from existing database.

You should rather look examples sqlselect.C or sqlfilldb.C.
These examples were created for MySQL, but you can use SQLite DB also if connect specifies:

TSQLServer *db = TSQLServer::Connect("sqlite://bridge.db");

Few more hints you can find in TSQLiteServer docu:


Hello again,
many thanks for your hints. Unfortunately I have still problem to analyze data in ROOT read from the
sqlite database. I send you here an updated Test_sqlite3.C macro to illustrate the problem.
In this macro I can perfectly read and print the first 10 events in the database (see Test_sqlite3.txt).
However I don’t know how to fill my histogram inside the callback function which read the database.
What I want to do is to fill the histogram TH1F* hTNA with the value read in the 8th column (val8)
of the database (called LEVEE_FINAL). Where should I put and in which form the hTNA->Fill(val8);
C++ line?
Maybe it is explained in the sqlselect.C example, but unfortunately I couldn’t find it.
Test_sqlite3_update.C (1.7 KB)


If you want to use histogram in callback, just move its declaration before main function. see modified example:
Test_sqlite3_update.C (1.8 KB)


Many thanks Sergey, it works fine now.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.