ROOT  6.06/09
Reference Guide
TSQLiteRow.cxx
Go to the documentation of this file.
1 // @(#)root/sqlite:$Id$
2 // Author: o.freyermuth <o.f@cern.ch>, 01/06/2013
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2013, 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 "TSQLiteRow.h"
13 
14 
16 
17 ////////////////////////////////////////////////////////////////////////////////
18 /// Single row of query result.
19 
20 TSQLiteRow::TSQLiteRow(void *res, ULong_t /*rowHandle*/)
21 {
22  fResult = (sqlite3_stmt *) res;
23 }
24 
25 ////////////////////////////////////////////////////////////////////////////////
26 /// Destroy row object.
27 
29 {
30  if (fResult)
31  Close();
32 }
33 
34 ////////////////////////////////////////////////////////////////////////////////
35 /// Close row.
36 
38 {
39  fResult = 0;
40 }
41 
42 ////////////////////////////////////////////////////////////////////////////////
43 /// Check if row is open and field index within range.
44 
46 {
47  if (field < 0 || field >= (Int_t)sqlite3_column_count(fResult)) {
48  Error("IsValid", "field index out of bounds");
49  return kFALSE;
50  }
51  return kTRUE;
52 }
53 
54 ////////////////////////////////////////////////////////////////////////////////
55 /// Get length in bytes of specified field.
56 
58 {
59  if (!IsValid(field))
60  return 0;
61 
62  // Should call the access-method first, so sqlite3 can check whether a NULL-terminator
63  // needs to be added to the byte-count, e.g. for BLOB!
64  sqlite3_column_text(fResult, field);
65 
66  ULong_t fieldLength = (ULong_t) sqlite3_column_bytes(fResult, field);
67 
68  if (!fieldLength) {
69  Error("GetFieldLength", "cannot get field length");
70  return 0;
71  }
72 
73  return fieldLength;
74 }
75 
76 ////////////////////////////////////////////////////////////////////////////////
77 /// Get specified field from row (0 <= field < GetFieldCount()).
78 
79 const char *TSQLiteRow::GetField(Int_t field)
80 {
81  if (!IsValid(field))
82  return 0;
83 
84  return reinterpret_cast<const char*>(sqlite3_column_text(fResult, field));
85 }
86 
sqlite3_stmt * fResult
Definition: TSQLiteRow.h:29
ULong_t GetFieldLength(Int_t field)
Get length in bytes of specified field.
Definition: TSQLiteRow.cxx:57
const char Option_t
Definition: RtypesCore.h:62
void Close(Option_t *opt="")
Close row.
Definition: TSQLiteRow.cxx:37
~TSQLiteRow()
Destroy row object.
Definition: TSQLiteRow.cxx:28
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
Bool_t IsValid(Int_t field)
Check if row is open and field index within range.
Definition: TSQLiteRow.cxx:45
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
const char * GetField(Int_t field)
Get specified field from row (0 <= field < GetFieldCount()).
Definition: TSQLiteRow.cxx:79
unsigned long ULong_t
Definition: RtypesCore.h:51
const Bool_t kTRUE
Definition: Rtypes.h:91
ClassImp(TSQLiteRow) TSQLiteRow
Single row of query result.
Definition: TSQLiteRow.cxx:15