BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
work_large_object.C
Go to the documentation of this file.
2{
3 TStopwatch timer;
4 timer.Start();
5 gDebug = 0;
6
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}
Int_t gDebug
long Long_t
double Double_t
const char * GetDB() const
virtual Bool_t SetBinary(Int_t, void *, Long_t, Long_t=0x1000)
virtual Bool_t NextIteration()=0
virtual Bool_t NextResultRow()=0
virtual Bool_t Process()=0
virtual Bool_t StoreResult()=0
virtual Bool_t GetBinary(Int_t, void *&, Long_t &)
Double_t RealTime()
void Start(Bool_t reset=kTRUE)
Double_t CpuTime()
void Stop()
static UniConnection * Open()
void work_large_object()