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