Logo ROOT  
Reference Guide
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_sql
3/// \notebook -js
5/// This tutorial demonstrates how TSQLServer can be used to create a
6/// connection with a SQlite3 database. It accesses the Sqlite data base.
7/// Download from https://root.cern/download/root_download_stats.sqlite
8/// Then a TH1F histogram is created and filled
9/// using a expression which receives the recorded
10/// values in the "version" column of the sqlite3 database.
11/// The histogram shows the usage of the ROOT development version.
12/// This product includes GeoLite2 data created by MaxMind, available from
13/// <a href="http://www.maxmind.com">http://www.maxmind.com</a>.
15/// \macro_code
17/// \author Alexandra-Maria Dobrescu 08/2018
19#include <TSQLiteServer.h>
20#include <TSQLiteResult.h>
21#include <TSQLRow.h>
22#include <TString.h>
24void SQLiteVersionsOfRoot(){
26 TSQLServer *db = TSQLServer::Connect("sqlite://root_download_stats.sqlite", "", "");
28 const char *rootSourceVersion = "SELECT Version FROM accesslog;";
30 TSQLResult *rootSourceVersionRes = db->Query(rootSourceVersion);
32 TH1F *hVersionOfRoot= new TH1F("hVersionOfRoot", "Development Versions of ROOT", 7, 0, -1);
34 while (TSQLRow *row = rootSourceVersionRes->Next()) {
35 TString rowVersion(row->GetField(0));
36 TString shortVersion(rowVersion(0,4));
37 hVersionOfRoot->Fill(shortVersion,1);
38 delete row;
39 }
41 TCanvas *VersionOfRootHistogram = new TCanvas();
43 hVersionOfRoot->GetXaxis()->LabelsOption("a");
44 hVersionOfRoot->LabelsDeflate("X");
45 hVersionOfRoot->Draw();
virtual void LabelsOption(Option_t *option="h")
Set option(s) to draw axis with labels option can be:
Definition: TAxis.cxx:613
The Canvas class.
Definition: TCanvas.h:23
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:575
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:320
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3350
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:3073
virtual void LabelsDeflate(Option_t *axis="X")
Reduce the number of bins for the axis passed in the option to the number of bins having a label.
Definition: TH1.cxx:5177
virtual TSQLRow * Next()=0
virtual TSQLResult * Query(const char *sql)=0
static TSQLServer * Connect(const char *db, const char *uid, const char *pw)
The db should be of the form: <dbms>://<host>[:<port>][/<database>], e.g.: mysql://pcroot....
Definition: TSQLServer.cxx:61
Basic string class.
Definition: TString.h:136