ROOT logo
// @(#)root/sqlite:$Id$
// Author: o.freyermuth <o.f@cern.ch>, 01/06/2013

/*************************************************************************
 * Copyright (C) 1995-2013, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "TSQLiteRow.h"


ClassImp(TSQLiteRow)

//______________________________________________________________________________
TSQLiteRow::TSQLiteRow(void *res, ULong_t /*rowHandle*/)
{
   // Single row of query result.

   fResult = (sqlite3_stmt *) res;
}

//______________________________________________________________________________
TSQLiteRow::~TSQLiteRow()
{
   // Destroy row object.

   if (fResult)
      Close();
}

//______________________________________________________________________________
void TSQLiteRow::Close(Option_t *)
{
   // Close row.

   fResult = 0;
}

//______________________________________________________________________________
Bool_t TSQLiteRow::IsValid(Int_t field)
{
   // Check if row is open and field index within range.

   if (field < 0 || field >= (Int_t)sqlite3_column_count(fResult)) {
      Error("IsValid", "field index out of bounds");
      return kFALSE;
   }
   return kTRUE;
}

//______________________________________________________________________________
ULong_t TSQLiteRow::GetFieldLength(Int_t field)
{
   // Get length in bytes of specified field.

   if (!IsValid(field))
      return 0;

   // Should call the access-method first, so sqlite3 can check whether a NULL-terminator
   // needs to be added to the byte-count, e.g. for BLOB!
   sqlite3_column_text(fResult, field);

   ULong_t fieldLength = (ULong_t) sqlite3_column_bytes(fResult, field);

   if (!fieldLength) {
      Error("GetFieldLength", "cannot get field length");
      return 0;
   }

   return fieldLength;
}

//______________________________________________________________________________
const char *TSQLiteRow::GetField(Int_t field)
{
   // Get specified field from row (0 <= field < GetFieldCount()).

   if (!IsValid(field))
      return 0;

   return reinterpret_cast<const char*>(sqlite3_column_text(fResult, field));
}

 TSQLiteRow.cxx:1
 TSQLiteRow.cxx:2
 TSQLiteRow.cxx:3
 TSQLiteRow.cxx:4
 TSQLiteRow.cxx:5
 TSQLiteRow.cxx:6
 TSQLiteRow.cxx:7
 TSQLiteRow.cxx:8
 TSQLiteRow.cxx:9
 TSQLiteRow.cxx:10
 TSQLiteRow.cxx:11
 TSQLiteRow.cxx:12
 TSQLiteRow.cxx:13
 TSQLiteRow.cxx:14
 TSQLiteRow.cxx:15
 TSQLiteRow.cxx:16
 TSQLiteRow.cxx:17
 TSQLiteRow.cxx:18
 TSQLiteRow.cxx:19
 TSQLiteRow.cxx:20
 TSQLiteRow.cxx:21
 TSQLiteRow.cxx:22
 TSQLiteRow.cxx:23
 TSQLiteRow.cxx:24
 TSQLiteRow.cxx:25
 TSQLiteRow.cxx:26
 TSQLiteRow.cxx:27
 TSQLiteRow.cxx:28
 TSQLiteRow.cxx:29
 TSQLiteRow.cxx:30
 TSQLiteRow.cxx:31
 TSQLiteRow.cxx:32
 TSQLiteRow.cxx:33
 TSQLiteRow.cxx:34
 TSQLiteRow.cxx:35
 TSQLiteRow.cxx:36
 TSQLiteRow.cxx:37
 TSQLiteRow.cxx:38
 TSQLiteRow.cxx:39
 TSQLiteRow.cxx:40
 TSQLiteRow.cxx:41
 TSQLiteRow.cxx:42
 TSQLiteRow.cxx:43
 TSQLiteRow.cxx:44
 TSQLiteRow.cxx:45
 TSQLiteRow.cxx:46
 TSQLiteRow.cxx:47
 TSQLiteRow.cxx:48
 TSQLiteRow.cxx:49
 TSQLiteRow.cxx:50
 TSQLiteRow.cxx:51
 TSQLiteRow.cxx:52
 TSQLiteRow.cxx:53
 TSQLiteRow.cxx:54
 TSQLiteRow.cxx:55
 TSQLiteRow.cxx:56
 TSQLiteRow.cxx:57
 TSQLiteRow.cxx:58
 TSQLiteRow.cxx:59
 TSQLiteRow.cxx:60
 TSQLiteRow.cxx:61
 TSQLiteRow.cxx:62
 TSQLiteRow.cxx:63
 TSQLiteRow.cxx:64
 TSQLiteRow.cxx:65
 TSQLiteRow.cxx:66
 TSQLiteRow.cxx:67
 TSQLiteRow.cxx:68
 TSQLiteRow.cxx:69
 TSQLiteRow.cxx:70
 TSQLiteRow.cxx:71
 TSQLiteRow.cxx:72
 TSQLiteRow.cxx:73
 TSQLiteRow.cxx:74
 TSQLiteRow.cxx:75
 TSQLiteRow.cxx:76
 TSQLiteRow.cxx:77
 TSQLiteRow.cxx:78
 TSQLiteRow.cxx:79
 TSQLiteRow.cxx:80
 TSQLiteRow.cxx:81
 TSQLiteRow.cxx:82
 TSQLiteRow.cxx:83
 TSQLiteRow.cxx:84
 TSQLiteRow.cxx:85
 TSQLiteRow.cxx:86