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 
14 #include <sqlite3.h>
15 
16 
18 
21 
22 
24 
25 TSQLiteRow::TSQLiteRow(void* res, ULong_t /*rowHandle*/)
26 {
27  fResult = (sqlite3_stmt*) res;
28 }
29 
30 
33 
34 
36 
38 {
39  if (fResult)
40  Close();
41 }
42 
43 
46 
47 
49 
51 {
52  fResult = nullptr;
53 }
54 
55 
58 
59 
61 
63 {
64  if (field < 0 || field >= (Int_t)sqlite3_column_count(fResult)) {
65  Error("IsValid", "field index out of bounds");
66  return kFALSE;
67  }
68  return kTRUE;
69 }
70 
71 
74 
75 
77 
79 {
80  if (!IsValid(field))
81  return 0;
82 
83  // Should call the access-method first, so sqlite3 can check whether a NULL-terminator
84  // needs to be added to the byte-count, e.g. for BLOB!
85  sqlite3_column_text(fResult, field);
86 
87  ULong_t fieldLength = (ULong_t) sqlite3_column_bytes(fResult, field);
88 
89  if (!fieldLength) {
90  Error("GetFieldLength", "cannot get field length");
91  return 0;
92  }
93 
94  return fieldLength;
95 }
96 
97 
100 
101 
103 
104 const char* TSQLiteRow::GetField(Int_t field)
105 {
106  if (!IsValid(field))
107  return nullptr;
108 
109  return reinterpret_cast<const char*>(sqlite3_column_text(fResult, field));
110 }
111 
112 
113 
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:62
sqlite3_stmt * fResult
const char * GetField(Int_t field) final
Definition: TSQLiteRow.cxx:104
TSQLiteRow(void *result, ULong_t rowHandle)
Definition: TSQLiteRow.cxx:25
ULong_t GetFieldLength(Int_t field) final
Definition: TSQLiteRow.cxx:78
void Close(Option_t *opt="") final
Definition: TSQLiteRow.cxx:50
ClassImp(TPyArg)