Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
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
17
18////////////////////////////////////////////////////////////////////////////////
19/// Single row of query result.
20
21TSQLiteRow::TSQLiteRow(void *res, ULong_t /*rowHandle*/)
22{
23 fResult = (sqlite3_stmt *) res;
24}
25
26////////////////////////////////////////////////////////////////////////////////
27/// Destroy row object.
28
30{
31 if (fResult)
32 Close();
33}
34
35////////////////////////////////////////////////////////////////////////////////
36/// Close row.
37
39{
40 fResult = nullptr;
41}
42
43////////////////////////////////////////////////////////////////////////////////
44/// Check if row is open and field index within range.
45
47{
48 if (field < 0 || field >= (Int_t)sqlite3_column_count(fResult)) {
49 Error("IsValid", "field index out of bounds");
50 return kFALSE;
51 }
52 return kTRUE;
53}
54
55////////////////////////////////////////////////////////////////////////////////
56/// Get length in bytes of specified field.
57
59{
60 if (!IsValid(field))
61 return 0;
62
63 // Should call the access-method first, so sqlite3 can check whether a NULL-terminator
64 // needs to be added to the byte-count, e.g. for BLOB!
65 sqlite3_column_text(fResult, field);
66
67 ULong_t fieldLength = (ULong_t) sqlite3_column_bytes(fResult, field);
68
69 if (!fieldLength) {
70 Error("GetFieldLength", "cannot get field length");
71 return 0;
72 }
73
74 return fieldLength;
75}
76
77////////////////////////////////////////////////////////////////////////////////
78/// Get specified field from row (0 <= field < GetFieldCount()).
79
80const char *TSQLiteRow::GetField(Int_t field)
81{
82 if (!IsValid(field))
83 return nullptr;
84
85 return reinterpret_cast<const char*>(sqlite3_column_text(fResult, field));
86}
87
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
unsigned long ULong_t
Unsigned long integer 4 bytes (unsigned long). Size depends on architecture.
Definition RtypesCore.h:69
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char).
Definition RtypesCore.h:80
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1098
Bool_t IsValid(Int_t field)
Check if row is open and field index within range.
sqlite3_stmt * fResult
! current result set
Definition TSQLiteRow.h:22
const char * GetField(Int_t field) final
Get specified field from row (0 <= field < GetFieldCount()).
~TSQLiteRow()
Destroy row object.
TSQLiteRow(void *result, ULong_t rowHandle)
Single row of query result.
ULong_t GetFieldLength(Int_t field) final
Get length in bytes of specified field.
void Close(Option_t *opt="") final
Close row.