KaliVeda
Toolkit for HIC analysis
TSQLiteRow.cxx
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 #include <sqlite3.h>
14 
15 
17 
20 
21 
23 
24 TSQLiteRow::TSQLiteRow(void* res, ULong_t /*rowHandle*/)
25 {
26  fResult = (sqlite3_stmt*) res;
27 }
28 
29 
32 
33 
35 
37 {
38  if (fResult)
39  Close();
40 }
41 
42 
45 
46 
48 
50 {
51  fResult = nullptr;
52 }
53 
54 
57 
58 
60 
62 {
63  if (field < 0 || field >= (Int_t)sqlite3_column_count(fResult)) {
64  Error("IsValid", "field index out of bounds");
65  return kFALSE;
66  }
67  return kTRUE;
68 }
69 
70 
73 
74 
76 
78 {
79  if (!IsValid(field))
80  return 0;
81 
82  // Should call the access-method first, so sqlite3 can check whether a NULL-terminator
83  // needs to be added to the byte-count, e.g. for BLOB!
84  sqlite3_column_text(fResult, field);
85 
86  ULong_t fieldLength = (ULong_t) sqlite3_column_bytes(fResult, field);
87 
88  if (!fieldLength) {
89  Error("GetFieldLength", "cannot get field length");
90  return 0;
91  }
92 
93  return fieldLength;
94 }
95 
96 
99 
100 
102 
103 const char* TSQLiteRow::GetField(Int_t field)
104 {
105  if (!IsValid(field))
106  return nullptr;
107 
108  return reinterpret_cast<const char*>(sqlite3_column_text(fResult, field));
109 }
110 
111 
112 
int Int_t
unsigned long ULong_t
bool Bool_t
constexpr Bool_t kFALSE
constexpr Bool_t kTRUE
const char Option_t
virtual void Error(const char *method, const char *msgfmt,...) const
Bool_t IsValid(Int_t field)
Definition: TSQLiteRow.cxx:61
sqlite3_stmt * fResult
Definition: TSQLiteRow.h:31
const char * GetField(Int_t field) final
Definition: TSQLiteRow.cxx:103
TSQLiteRow(void *result, ULong_t rowHandle)
Definition: TSQLiteRow.cxx:24
ULong_t GetFieldLength(Int_t field) final
Definition: TSQLiteRow.cxx:77
void Close(Option_t *opt="") final
Definition: TSQLiteRow.cxx:49
ClassImp(TPyArg)