{
"cells": [
{
"cell_type": "markdown",
"id": "feaf287f",
"metadata": {},
"source": [
"# SQLiteTimeVersionOfRoot\n",
"This tutorial demonstrates how TSQLServer can be used to create a connection with a SQlite3 database.\n",
"It accesses the Sqlite data base.\n",
"Download from https://root.cern/files/root_download_stats.sqlite\n",
"In order to demonstrate the dependency over ROOT version 6.14, this tutorial uses the TSQLResult\n",
"function which allows to extract the minimum time stored in the SQlite3 database.\n",
"The next step is to create a TH1F Histogram, which will be filled with the values stored in\n",
"two different columns from the database, the \"Time\" and \"Version\" columns.\n",
"This product includes GeoLite2 data created by MaxMind, available from\n",
"http://www.maxmind.com.\n",
"\n",
"\n",
"\n",
"\n",
"**Author:** Alexandra-Maria Dobrescu 08/2018 \n",
"This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Monday, December 15, 2025 at 04:14 AM."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ec56832f",
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"TSQLServer *db = TSQLServer::Connect(\"sqlite://root_download_stats.sqlite\", \"\", \"\");\n",
"\n",
"const char *minTime = \"SELECT min(Time) FROM accesslog;\";\n",
"TSQLResult *minTimeRes = db->Query(minTime);\n",
"\n",
"std::string strMinTimeField = minTimeRes->Next()->GetField(0);\n",
"TDatime minTimeFormat(strMinTimeField.c_str());\n",
"\n",
"TDatime now;\n",
"TH1F *hTime = new TH1F(\"hTime\", \"Duration of ROOT dependency over version 6.14\", 10, minTimeFormat.Convert(), now.Convert());\n",
"\n",
"const char *time = \"SELECT Time, Version FROM accesslog;\";\n",
"TSQLResult *timeRes = db->Query(time);\n",
"\n",
"while (TSQLRow *row = timeRes->Next()) {\n",
" TDatime rowTime(row->GetField(0));\n",
" TString rowVersion(row->GetField(1));\n",
" TString shortVersion(rowVersion(0,4));\n",
" if ( shortVersion == \"6.14\" ) {\n",
" hTime->Fill(rowTime.Convert());\n",
" }\n",
" delete row;\n",
"}\n",
"\n",
"TCanvas *timeHistogram = new TCanvas();\n",
"\n",
"gStyle->SetTimeOffset(0);\n",
"hTime->GetXaxis()->SetTimeDisplay(1);\n",
"hTime->GetXaxis()->SetLabelSize(0.02);\n",
"hTime->GetXaxis()->SetNdivisions(512, kFALSE);\n",
"hTime->GetXaxis()->SetTimeFormat(\"%Y-%m-%d\");\n",
"\n",
"hTime->Draw();"
]
},
{
"cell_type": "markdown",
"id": "d781d597",
"metadata": {},
"source": [
"Draw all canvases "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c528c820",
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%jsroot on\n",
"gROOT->GetListOfCanvases()->Draw()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "ROOT C++",
"language": "c++",
"name": "root"
},
"language_info": {
"codemirror_mode": "text/x-c++src",
"file_extension": ".C",
"mimetype": " text/x-c++src",
"name": "c++"
}
},
"nbformat": 4,
"nbformat_minor": 5
}