Logo ROOT  
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
22TSQLiteRow::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 = nullptr;
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
81const char *TSQLiteRow::GetField(Int_t field)
82{
83 if (!IsValid(field))
84 return nullptr;
85
86 return reinterpret_cast<const char*>(sqlite3_column_text(fResult, field));
87}
88
const Bool_t kFALSE
Definition: RtypesCore.h:101
const Bool_t kTRUE
Definition: RtypesCore.h:100
unsigned long ULong_t
Definition: RtypesCore.h:55
const char Option_t
Definition: RtypesCore.h:66
ClassImp(TSQLiteRow)
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:969
Bool_t IsValid(Int_t field)
Check if row is open and field index within range.
Definition: TSQLiteRow.cxx:47
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()).
Definition: TSQLiteRow.cxx:81
~TSQLiteRow()
Destroy row object.
Definition: TSQLiteRow.cxx:30
TSQLiteRow(void *result, ULong_t rowHandle)
Single row of query result.
Definition: TSQLiteRow.cxx:22
ULong_t GetFieldLength(Int_t field) final
Get length in bytes of specified field.
Definition: TSQLiteRow.cxx:59
void Close(Option_t *opt="") final
Close row.
Definition: TSQLiteRow.cxx:39