BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
work_large_object.C
Go to the documentation of this file.
1
void
work_large_object
()
2
{
3
TStopwatch
timer;
4
timer.
Start
();
5
gDebug
= 0;
6
7
UniConnection
* connDb =
UniConnection::Open
();
8
if
(connectionUniDb ==
nullptr
) {
9
cout <<
"ERROR: connection to the database can not be established"
<< endl;
10
return
-1;
11
}
12
13
TSQLServer
* db_server = connectionUniDb->GetSQLServer();
14
15
cout <<
"DB: "
<< uni_db->
GetDB
() <<
". Type: "
<< uni_db->GetDBMS() <<
"."
<< endl;
16
17
TSQLStatement
* stmt = uni_db->Statement(
"insert into test(d) "
18
"values ($1)"
);
19
20
int
d = 8332;
21
cout <<
"Input: "
<< d << endl;
22
stmt->
NextIteration
();
23
stmt->
SetBinary
(0, &d,
sizeof
(
int
));
24
string
ds =
"fgh'\\123"
;
25
cout <<
"Input: "
<< ds << endl;
26
stmt->
NextIteration
();
27
stmt->
SetBinary
(0, (
char
*)ds.c_str(),
sizeof
(
char
) * 9);
28
29
if
(!stmt->
Process
()) {
30
cout <<
"ERROR: inserting new record to DB has been failed"
<< endl;
31
delete
stmt;
32
delete
connectionUniDb;
33
return
-11;
34
}
35
delete
stmt;
36
delete
connectionUniDb;
37
38
// print all values
39
connDb =
UniConnection::Open
();
40
if
(connectionUniDb ==
nullptr
) {
41
cout <<
"ERROR: connection to the database can't be established"
<< endl;
42
return
-2;
43
}
44
45
uni_db = connectionUniDb->GetSQLServer();
46
47
stmt = uni_db->Statement(
"select d from test"
);
48
if
(!stmt->
Process
()) {
49
cout <<
"ERROR: reading all record from DB has been failed"
<< endl;
50
delete
stmt;
51
delete
connectionUniDb;
52
return
-12;
53
}
54
55
// store result of statement in buffer
56
stmt->
StoreResult
();
57
58
// if there is no last id then exit with error
59
while
(stmt->
NextResultRow
()) {
60
void
* mem = 0;
61
Long_t
size_mem = 0;
62
stmt->
GetBinary
(0, mem, size_mem);
63
if
(size_mem == 4) {
64
int
* val =
new
int;
65
memcpy(val, mem, size_mem);
66
cout <<
"Binary size: "
<< size_mem <<
". Value: "
<< *val << endl;
67
}
else
{
68
char
* val =
new
char
[size_mem];
69
memcpy(val, mem, size_mem);
70
cout <<
"Binary size: "
<< size_mem <<
". Value: "
<< string(val) << endl;
71
}
72
}
73
74
delete
stmt;
75
delete
connectionUniDb;
76
77
timer.
Stop
();
78
Double_t
rtime = timer.
RealTime
(), ctime = timer.
CpuTime
();
79
printf(
"RealTime=%f seconds, CpuTime=%f seconds\n"
, rtime, ctime);
80
81
cout <<
"Test was successfull"
<< endl;
82
}
gDebug
Int_t gDebug
Long_t
long Long_t
Double_t
double Double_t
TSQLServer
TSQLServer::GetDB
const char * GetDB() const
TSQLStatement
TSQLStatement::SetBinary
virtual Bool_t SetBinary(Int_t, void *, Long_t, Long_t=0x1000)
TSQLStatement::NextIteration
virtual Bool_t NextIteration()=0
TSQLStatement::NextResultRow
virtual Bool_t NextResultRow()=0
TSQLStatement::Process
virtual Bool_t Process()=0
TSQLStatement::StoreResult
virtual Bool_t StoreResult()=0
TSQLStatement::GetBinary
virtual Bool_t GetBinary(Int_t, void *&, Long_t &)
TStopwatch
TStopwatch::RealTime
Double_t RealTime()
TStopwatch::Start
void Start(Bool_t reset=kTRUE)
TStopwatch::CpuTime
Double_t CpuTime()
TStopwatch::Stop
void Stop()
UniConnection
Definition
UniConnection.h:27
UniConnection::Open
static UniConnection * Open()
Definition
UniConnection.cxx:56
work_large_object
void work_large_object()
Definition
work_large_object.C:1
database
uni_db
macros
etc
work_large_object.C
Generated on
for BmnRoot by
1.17.0