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