ROOT
6.07/01
Reference Guide
ROOT Home Page
Main Page
Tutorials
User's Classes
Namespaces
All Classes
Files
Release Notes
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
tutorials
sql
sqlselect.C
Go to the documentation of this file.
1
#ifndef __CINT__
2
#include <
TSQLServer.h
>
3
#include <
TSQLResult.h
>
4
#include <
TSQLRow.h
>
5
#endif
6
7
void
sqlselect
()
8
{
9
TSQLServer
*db =
TSQLServer::Connect
(
"mysql://localhost/test"
,
"nobody"
,
""
);
10
11
printf
(
"Server info: %s\n"
, db->
ServerInfo
());
12
13
TSQLRow
*
row
;
14
TSQLResult
*res;
15
16
// list databases available on server
17
printf
(
"\nList all databases on server %s\n"
, db->
GetHost
());
18
res = db->
GetDataBases
();
19
while
((row = res->Next())) {
20
printf
(
"%s\n"
, row->GetField(0));
21
delete
row
;
22
}
23
delete
res;
24
25
// list tables in database "test" (the permission tables)
26
printf
(
"\nList all tables in database \"test\" on server %s\n"
,
27
db->
GetHost
());
28
res = db->
GetTables
(
"test"
);
29
while
((row = res->Next())) {
30
printf
(
"%s\n"
, row->GetField(0));
31
delete
row
;
32
}
33
delete
res;
34
35
// list columns in table "runcatalog" in database "mysql"
36
printf
(
"\nList all columns in table \"runcatalog\" in database \"test\" on server %s\n"
,
37
db->
GetHost
());
38
res = db->
GetColumns
(
"test"
,
"runcatalog"
);
39
while
((row = res->Next())) {
40
printf
(
"%s\n"
, row->GetField(0));
41
delete
row
;
42
}
43
delete
res;
44
45
// start timer
46
TStopwatch
timer
;
47
timer.
Start
();
48
49
// query database and print results
50
const
char
*sql =
"select dataset,rawfilepath from test.runcatalog "
51
"WHERE tag&(1<<2) AND (run=490001 OR run=300122)"
;
52
// const char *sql = "select count(*) from test.runcatalog "
53
// "WHERE tag&(1<<2)";
54
55
res = db->
Query
(sql);
56
57
int
nrows = res->
GetRowCount
();
58
printf
(
"\nGot %d rows in result\n"
, nrows);
59
60
int
nfields = res->GetFieldCount();
61
for
(
int
i = 0; i < nfields; i++)
62
printf
(
"%40s"
, res->GetFieldName(i));
63
printf
(
"\n"
);
64
for
(
int
i = 0; i < nfields*40; i++)
65
printf
(
"="
);
66
printf
(
"\n"
);
67
68
for
(
int
i = 0; i < nrows; i++) {
69
row = res->Next();
70
for
(
int
j = 0; j < nfields; j++) {
71
printf
(
"%40s"
, row->GetField(j));
72
}
73
printf
(
"\n"
);
74
delete
row
;
75
}
76
77
delete
res;
78
delete
db;
79
80
// stop timer and print results
81
timer.
Stop
();
82
Double_t
rtime = timer.
RealTime
();
83
Double_t
ctime = timer.
CpuTime
();
84
85
printf
(
"\nRealTime=%f seconds, CpuTime=%f seconds\n"
, rtime, ctime);
86
}
mrt.row
tuple row
Definition:
mrt.py:26
TStopwatch::RealTime
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
Definition:
TStopwatch.cxx:108
TStopwatch::Start
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
Definition:
TStopwatch.cxx:56
TSQLServer::GetDataBases
virtual TSQLResult * GetDataBases(const char *wild=0)=0
TSQLServer
Definition:
TSQLServer.h:45
TSQLServer::Query
virtual TSQLResult * Query(const char *sql)=0
TSQLServer::Connect
static TSQLServer * Connect(const char *db, const char *uid, const char *pw)
TStopwatch::CpuTime
Double_t CpuTime()
Stop the stopwatch (if it is running) and return the cputime (in seconds) passed between the start an...
Definition:
TStopwatch.cxx:123
TSQLResult::GetRowCount
virtual Int_t GetRowCount() const
Definition:
TSQLResult.h:47
timer
TStopwatch timer
Definition:
pirndm.C:37
TStopwatch::Stop
void Stop()
Stop the stopwatch.
Definition:
TStopwatch.cxx:75
TSQLResult.h
TSQLServer::GetColumns
virtual TSQLResult * GetColumns(const char *dbname, const char *table, const char *wild=0)=0
TSQLRow.h
TSQLServer::ServerInfo
virtual const char * ServerInfo()=0
TSQLResult
Definition:
TSQLResult.h:34
TSQLRow
Definition:
TSQLRow.h:32
TSQLServer::GetTables
virtual TSQLResult * GetTables(const char *dbname, const char *wild=0)=0
Double_t
double Double_t
Definition:
RtypesCore.h:55
printf
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
sqlselect
void sqlselect()
Definition:
sqlselect.C:7
TSQLServer.h
TSQLServer::GetHost
const char * GetHost() const
Definition:
TSQLServer.h:102
TStopwatch
Stopwatch class.
Definition:
TStopwatch.h:30