BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
work_binary_object.C
Go to the documentation of this file.
1
void
work_binary_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
string
file_name(
"input.txt"
);
21
FILE* input_file = fopen(file_name.c_str(),
"rb"
);
22
if
(input_file ==
nullptr
)
23
return
;
24
fseek(input_file, 0L, SEEK_END);
25
size_t
file_size = ftell(input_file);
26
unsigned
char
* in_array =
new
unsigned
char
[file_size];
27
fseek(input_file, 0L, SEEK_SET);
28
int
bytes_read = fread(in_array,
sizeof
(
unsigned
char
), file_size, input_file);
29
if
(bytes_read != file_size)
30
return
;
31
fclose(input_file);
32
33
stmt->
NextIteration
();
34
stmt->
SetBinary
(0, in_array, file_size);
35
36
if
(!stmt->
Process
()) {
37
cout <<
"ERROR: inserting new record to DB has been failed"
<< endl;
38
delete
[] in_array;
39
delete
stmt;
40
delete
connectionUniDb;
41
return
-11;
42
}
43
delete
[] in_array;
44
delete
stmt;
45
delete
connectionUniDb;
46
47
// print all values
48
connDb =
UniConnection::Open
();
49
if
(connectionUniDb ==
nullptr
) {
50
cout <<
"ERROR: connection to the database can't be established"
<< endl;
51
return
-2;
52
}
53
54
uni_db = connectionUniDb->GetSQLServer();
55
56
stmt = uni_db->Statement(
"select d from test"
);
57
if
(!stmt->
Process
()) {
58
cout <<
"ERROR: reading all record from DB has been failed"
<< endl;
59
delete
stmt;
60
delete
connectionUniDb;
61
return
-12;
62
}
63
64
// store result of statement in buffer
65
stmt->
StoreResult
();
66
67
// if there is no last id then exit with error
68
while
(stmt->
NextResultRow
()) {
69
void
* mem = 0;
70
Long_t
size_mem = 0;
71
stmt->
GetBinary
(0, mem, size_mem);
72
73
string
file_name_out(
"output.txt"
);
74
FILE* output_file = fopen(file_name_out.c_str(),
"wb"
);
75
int
bytes_written = fwrite(mem,
sizeof
(
unsigned
char
), size_mem, output_file);
76
fclose(output_file);
77
}
78
79
delete
stmt;
80
delete
connectionUniDb;
81
82
timer.
Stop
();
83
Double_t
rtime = timer.
RealTime
(), ctime = timer.
CpuTime
();
84
printf(
"RealTime=%f seconds, CpuTime=%f seconds\n"
, rtime, ctime);
85
86
cout <<
"Test was successfull"
<< endl;
87
}
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_binary_object
void work_binary_object()
Definition
work_binary_object.C:1
database
uni_db
macros
etc
work_binary_object.C
Generated on
for BmnRoot by
1.17.0