Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TMySQLResult.cxx
Go to the documentation of this file.
1// @(#)root/mysql:$Id$
2// Author: Fons Rademakers 15/02/2000
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include "TMySQLResult.h"
13#include "TMySQLRow.h"
14
15
17
18////////////////////////////////////////////////////////////////////////////////
19/// MySQL query result.
20
22{
23 fResult = (MYSQL_RES *) result;
24 fRowCount = fResult ? mysql_num_rows(fResult) : 0;
25 fFieldInfo = nullptr;
26}
27
28////////////////////////////////////////////////////////////////////////////////
29/// Cleanup MySQL query result.
30
32{
33 if (fResult)
34 Close();
35}
36
37////////////////////////////////////////////////////////////////////////////////
38/// Close query result.
39
41{
42 if (!fResult)
43 return;
44
45 mysql_free_result(fResult);
46 fResult = nullptr;
47 fFieldInfo = nullptr;
48 fRowCount = 0;
49}
50
51////////////////////////////////////////////////////////////////////////////////
52/// Check if result set is open and field index within range.
53
55{
56 if (!fResult) {
57 Error("IsValid", "result set closed");
58 return kFALSE;
59 }
60 if (field < 0 || field >= GetFieldCount()) {
61 Error("IsValid", "field index out of bounds");
62 return kFALSE;
63 }
64 return kTRUE;
65}
66
67////////////////////////////////////////////////////////////////////////////////
68/// Get number of fields in result.
69
71{
72 if (!fResult) {
73 Error("GetFieldCount", "result set closed");
74 return 0;
75 }
76 return mysql_num_fields(fResult);
77}
78
79////////////////////////////////////////////////////////////////////////////////
80/// Get name of specified field.
81
83{
84 if (!IsValid(field))
85 return nullptr;
86
87 if (!fFieldInfo)
88 fFieldInfo = mysql_fetch_fields(fResult);
89
90 if (!fFieldInfo) {
91 Error("GetFieldName", "cannot get field info");
92 return nullptr;
93 }
94
95 return fFieldInfo[field].name;
96}
97
98////////////////////////////////////////////////////////////////////////////////
99/// Get next query result row. The returned object must be
100/// deleted by the user.
101
103{
104 if (!fResult) {
105 Error("Next", "result set closed");
106 return nullptr;
107 }
108 MYSQL_ROW row = mysql_fetch_row(fResult);
109 if (!row)
110 return nullptr;
111
112 return new TMySQLRow((void *) fResult, (ULong_t) row);
113}
const Bool_t kFALSE
Definition RtypesCore.h:101
unsigned long ULong_t
Definition RtypesCore.h:55
const Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:364
TSQLRow * Next() final
Get next query result row.
const char * GetFieldName(Int_t field) final
Get name of specified field.
MYSQL_FIELD * fFieldInfo
Int_t GetFieldCount() final
Get number of fields in result.
~TMySQLResult()
Cleanup MySQL query result.
MYSQL_RES * fResult
Bool_t IsValid(Int_t field)
Check if result set is open and field index within range.
TMySQLResult(void *result)
MySQL query result.
void Close(Option_t *opt="") final
Close query result.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:963
Int_t fRowCount
Definition TSQLResult.h:35