BOSS 7.0.4
BESIII Offline Software System
Loading...
Searching...
No Matches
MysqlResults.cxx
Go to the documentation of this file.
1// $Header: /bes/bes/BossCvs/Calibration/rdbModel/src/Db/MysqlResults.cxx,v 1.6 2011/02/22 06:16:29 maqm Exp $
2#ifdef WIN32
3#include <windows.h>
4#endif
5
6#include "rdbModel/Db/MysqlResults.h"
7#include "mysql.h"
8#include "facilities/Util.h"
9#include <iostream>
10#include <cstring>
11
12namespace rdbModel {
13
14 MysqlResults::MysqlResults(MYSQL_RES* results) : m_myres(results) {
15 }
16
17 MysqlResults::~MysqlResults() {
18 mysql_free_result(m_myres);
19 }
20
21 unsigned int MysqlResults::getNRows() const {
22 return mysql_num_rows(m_myres);
23 }
24
25 bool MysqlResults::getRow(std::vector<std::string>& fields,
26 unsigned int i, bool clear) {
27 mysql_data_seek(m_myres, i);
28 MYSQL_ROW myRow = mysql_fetch_row(m_myres);
29
30 unsigned nFields = mysql_num_fields(m_myres);
31
32
33 if (clear) fields.clear();
34
35 for (unsigned int iField = 0; iField < nFields; iField++) {
36 if (myRow[iField]) fields.push_back(std::string(myRow[iField]));
37 else fields.push_back("");
38 }
39
40 return true;
41 }
42
43 bool MysqlResults::getRowPtrs(std::vector<std::string*>& fields,
44 unsigned int i, bool clear) {
45
46 mysql_data_seek(m_myres, i);
47 MYSQL_ROW myRow = mysql_fetch_row(m_myres);
48
49 unsigned nFields = mysql_num_fields(m_myres);
50
51
52 if (clear) fields.clear();
53
54 for (unsigned int iField = 0; iField < nFields; iField++) {
55 if (myRow[iField]) fields.push_back(new std::string(myRow[iField]));
56 else fields.push_back(0);
57 }
58
59 return true;
60
61 }
62
63
64 bool MysqlResults::getRowCon(char* par,unsigned long* treesize,unsigned int* runFrm,
65 unsigned int* runTo,unsigned int i, bool clear){
66 mysql_data_seek(m_myres, i);
67 MYSQL_ROW myRow = mysql_fetch_row(m_myres);
68 unsigned nFields = mysql_num_fields(m_myres);
69 unsigned long* lengths;
70 lengths = mysql_fetch_lengths(m_myres);
71
72 for (unsigned int iField = 0; iField <nFields; iField++) {
73 if (myRow[iField]&&iField<(nFields-4)){
74 memcpy(par+1024000*iField,myRow[iField],lengths[iField]);
75 treesize[iField] = lengths[iField];
76 }
77 }
78
79 *runFrm =facilities::Util::stringToInt(myRow[nFields-4]);
80 *runTo =facilities::Util::stringToInt(myRow[nFields-3]);
81 std::cout<<" CalVerSft is "<<myRow[nFields-2]<<" File name is "<<myRow[nFields-1]<<std::endl;
82
83 return true;
84
85 }
86
87
88 // May also want to do
89 // MYSQL_FIELD* fields = mysql_fetch_fields(m_myres);
90 // and make these available to client, especially for select * queries
91}
static int stringToInt(const std::string &InStr)