Logo ROOT   6.08/07
Reference Guide
TMySQLRow.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 "TMySQLRow.h"
13 
14 
16 
17 ////////////////////////////////////////////////////////////////////////////////
18 /// Single row of query result.
19 
20 TMySQLRow::TMySQLRow(void *res, ULong_t rowHandle)
21 {
22  fResult = (MYSQL_RES *) res;
23  fFields = (MYSQL_ROW) rowHandle;
24  fFieldLength = 0;
25 }
26 
27 ////////////////////////////////////////////////////////////////////////////////
28 /// Destroy row object.
29 
31 {
32  if (fFields)
33  Close();
34 }
35 
36 ////////////////////////////////////////////////////////////////////////////////
37 /// Close row.
38 
40 {
41  if (!fFields)
42  return;
43 
44  fFields = 0;
45  fResult = 0;
46  fFieldLength = 0;
47 }
48 
49 ////////////////////////////////////////////////////////////////////////////////
50 /// Check if row is open and field index within range.
51 
53 {
54  if (!fFields) {
55  Error("IsValid", "row closed");
56  return kFALSE;
57  }
58  if (field < 0 || field >= (Int_t)mysql_num_fields(fResult)) {
59  Error("IsValid", "field index out of bounds");
60  return kFALSE;
61  }
62  return kTRUE;
63 }
64 
65 ////////////////////////////////////////////////////////////////////////////////
66 /// Get length in bytes of specified field.
67 
69 {
70  if (!IsValid(field))
71  return 0;
72 
73  if (!fFieldLength)
74  fFieldLength = mysql_fetch_lengths(fResult);
75 
76  if (!fFieldLength) {
77  Error("GetFieldLength", "cannot get field length");
78  return 0;
79  }
80 
81  return fFieldLength[field];
82 }
83 
84 ////////////////////////////////////////////////////////////////////////////////
85 /// Get specified field from row (0 <= field < GetFieldCount()).
86 
87 const char *TMySQLRow::GetField(Int_t field)
88 {
89  if (!IsValid(field))
90  return 0;
91 
92  return fFields[field];
93 }
const char Option_t
Definition: RtypesCore.h:62
void Close(Option_t *opt="")
Close row.
Definition: TMySQLRow.cxx:39
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
~TMySQLRow()
Destroy row object.
Definition: TMySQLRow.cxx:30
MYSQL_RES * fResult
Definition: TMySQLRow.h:24
ULong_t * fFieldLength
Definition: TMySQLRow.h:26
MYSQL_ROW fFields
Definition: TMySQLRow.h:25
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:925
ULong_t GetFieldLength(Int_t field)
Get length in bytes of specified field.
Definition: TMySQLRow.cxx:68
#define ClassImp(name)
Definition: Rtypes.h:279
unsigned long ULong_t
Definition: RtypesCore.h:51
const char * GetField(Int_t field)
Get specified field from row (0 <= field < GetFieldCount()).
Definition: TMySQLRow.cxx:87
Bool_t IsValid(Int_t field)
Check if row is open and field index within range.
Definition: TMySQLRow.cxx:52
const Bool_t kTRUE
Definition: Rtypes.h:91