Logo ROOT   6.18/05
Reference Guide
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 = 0;
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 = 0;
47 fFieldInfo = 0;
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 0;
86
87 if (!fFieldInfo)
88 fFieldInfo = mysql_fetch_fields(fResult);
89
90 if (!fFieldInfo) {
91 Error("GetFieldName", "cannot get field info");
92 return 0;
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 MYSQL_ROW row;
105
106 if (!fResult) {
107 Error("Next", "result set closed");
108 return 0;
109 }
110 row = mysql_fetch_row(fResult);
111 if (!row)
112 return 0;
113 else
114 return new TMySQLRow((void *) fResult, (ULong_t) row);
115}
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
unsigned long ULong_t
Definition: RtypesCore.h:51
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:87
const char Option_t
Definition: RtypesCore.h:62
#define ClassImp(name)
Definition: Rtypes.h:365
const char * GetFieldName(Int_t field)
Get name of specified field.
MYSQL_FIELD * fFieldInfo
Definition: TMySQLResult.h:23
TSQLRow * Next()
Get next query result row.
void Close(Option_t *opt="")
Close query result.
~TMySQLResult()
Cleanup MySQL query result.
MYSQL_RES * fResult
Definition: TMySQLResult.h:22
Int_t GetFieldCount()
Get number of fields in result.
Bool_t IsValid(Int_t field)
Check if result set is open and field index within range.
TMySQLResult(void *result)
MySQL query result.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:880
Int_t fRowCount
Definition: TSQLResult.h:35