| 1 | // @(#)root/tree:$Id: MBufferSQL.cxx 43518 2012-03-28 01:04:07Z pcanal $
|
|---|
| 2 | // Author: Philippe Canal and al. 08/2004
|
|---|
| 3 |
|
|---|
| 4 | /*************************************************************************
|
|---|
| 5 | * Copyright (C) 1995-2000, 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 | //////////////////////////////////////////////////////////////////////////
|
|---|
| 13 | // //
|
|---|
| 14 | // MBufferSQL //
|
|---|
| 15 | // //
|
|---|
| 16 | // Implement TBuffer for a SQL backend //
|
|---|
| 17 | // //
|
|---|
| 18 | //////////////////////////////////////////////////////////////////////////
|
|---|
| 19 | #include "MBufferSQL.h"
|
|---|
| 20 |
|
|---|
| 21 | #include <stdio.h>
|
|---|
| 22 | #include <stdlib.h>
|
|---|
| 23 |
|
|---|
| 24 | #include "TError.h"
|
|---|
| 25 |
|
|---|
| 26 | #include "TSQLResult.h"
|
|---|
| 27 | #include "TSQLRow.h"
|
|---|
| 28 |
|
|---|
| 29 | #include "MTime.h"
|
|---|
| 30 |
|
|---|
| 31 | using namespace std;
|
|---|
| 32 |
|
|---|
| 33 | ClassImp(MBufferSQL);
|
|---|
| 34 |
|
|---|
| 35 | //________________________________________________________________________
|
|---|
| 36 | MBufferSQL::MBufferSQL() : TBufferFile(), fRowPtr(0)
|
|---|
| 37 | {
|
|---|
| 38 | // Constructor.
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | //________________________________________________________________________
|
|---|
| 42 | MBufferSQL::MBufferSQL(TSQLRow **r, Int_t index, TString type) :
|
|---|
| 43 | TBufferFile(TBufferFile::kRead), fRowPtr(r), fIndex(index), fIsDate(kFALSE)
|
|---|
| 44 | {
|
|---|
| 45 | // Constructor.
|
|---|
| 46 | if (type.BeginsWith("date", TString::kIgnoreCase) ||
|
|---|
| 47 | type.BeginsWith("time", TString::kIgnoreCase))
|
|---|
| 48 | fIsDate = kTRUE;
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | //________________________________________________________________________
|
|---|
| 52 | void MBufferSQL::ReadDouble(Double_t &d)
|
|---|
| 53 | {
|
|---|
| 54 | // Operator>>
|
|---|
| 55 | const char *ptr = (*fRowPtr)->GetField(fIndex);
|
|---|
| 56 |
|
|---|
| 57 | if (ptr==0)
|
|---|
| 58 | {
|
|---|
| 59 | d = 0;
|
|---|
| 60 | Error("operator>>(Double_t&)","NULL value found in cell");
|
|---|
| 61 | return;
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | if (!fIsDate)
|
|---|
| 65 | {
|
|---|
| 66 | d = atof(ptr);
|
|---|
| 67 | return;
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | d = MTime(ptr).GetAxisTime();
|
|---|
| 71 | }
|
|---|