// @(#)root/sql:$Id$
// Author: Sergey Linev  20/11/2005

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

#ifndef ROOT_TSQLObjectData
#define ROOT_TSQLObjectData


/////////////////////////////////////////////////////////////////////////
//                                                                     //
// TSQLObjectData keeps data, requested from SQL server for object     //
//                                                                     //
/////////////////////////////////////////////////////////////////////////


#ifndef ROOT_TObject
#include "TObject.h"
#endif

#ifndef ROOT_TString
#include "TString.h"
#endif

class TObjArray;
class TList;
class TSQLClassInfo;
class TSQLResult;
class TSQLRow;
class TSQLStatement;


class TSQLObjectInfo : public TObject {

public:

   TSQLObjectInfo();
   TSQLObjectInfo(Long64_t objid, const char* classname, Version_t version);
   virtual ~TSQLObjectInfo();
  
   Long64_t          GetObjId() const { return fObjId; }
   const char*       GetObjClassName() const { return fClassName.Data(); }
   Version_t         GetObjVersion() const { return fVersion; }

protected:
   Long64_t          fObjId;
   TString           fClassName;
   Version_t         fVersion;

   ClassDef(TSQLObjectInfo, 1)  //Info (classname, version) about object in database 
    
};

//=======================================================================

class TSQLObjectData : public TObject {

public:
   TSQLObjectData();
   
   TSQLObjectData(TSQLClassInfo* sqlinfo,
                  Long64_t       objid,
                  TSQLResult*    classdata,
                  TSQLRow*       classrow,
                  TSQLResult*    blobdata,
                  TSQLStatement* blobstmt);
   
   virtual ~TSQLObjectData();
   
   Long64_t          GetObjId() const { return fObjId; }
   TSQLClassInfo*    GetInfo() const { return fInfo; }
   
   Bool_t            LocateColumn(const char* colname, Bool_t isblob = kFALSE);
   Bool_t            IsBlobData() const { return fCurrentBlob || (fUnpack!=0); }
   void              ShiftToNextValue();
   
   void              AddUnpack(const char* tname, const char* value);
   void              AddUnpackInt(const char* tname, Int_t value);
   
   const char*       GetValue() const { return fLocatedValue; }
   const char*       GetLocatedField() const { return fLocatedField; }
   const char*       GetBlobPrefixName() const { return fBlobPrefixName; }
   const char*       GetBlobTypeName() const { return fBlobTypeName; }
   
   Bool_t            VerifyDataType(const char* tname, Bool_t errormsg = kTRUE);
   Bool_t            PrepareForRawData();
   
protected: 
   Bool_t            ExtractBlobValues();
   Bool_t            ShiftBlobRow();
   
   Int_t             GetNumClassFields();
   const char*       GetClassFieldName(Int_t n);
   
   TSQLClassInfo*    fInfo;           //!
   Long64_t          fObjId;          //!
   Bool_t            fOwner;          //!
   TSQLResult*       fClassData;      //!
   TSQLResult*       fBlobData;       //!
   TSQLStatement*    fBlobStmt;      //!
   Int_t             fLocatedColumn;  //!
   TSQLRow*          fClassRow;       //!
   TSQLRow*          fBlobRow;        //!
   const char*       fLocatedField;   //!
   const char*       fLocatedValue;   //!
   Bool_t            fCurrentBlob;    //!
   const char*       fBlobPrefixName; //! name prefix in current blob row
   const char*       fBlobTypeName;   //! name type (without prefix) in current blob row
   TObjArray*        fUnpack;         //! 
   
   ClassDef(TSQLObjectData, 1) // Keeps the data requested from the SQL server for an object.
      
};

// ======================================================================

class TSQLObjectDataPool : public TObject {

public:
   TSQLObjectDataPool();
   TSQLObjectDataPool(TSQLClassInfo* info, TSQLResult* data);
   virtual ~TSQLObjectDataPool();
   
   TSQLClassInfo*    GetSqlInfo() const { return fInfo; }
   TSQLResult*       GetClassData() const { return fClassData; }
   TSQLRow*          GetObjectRow(Long64_t objid);   
   
protected:

   TSQLClassInfo*    fInfo;          //!  classinfo, for which pool is created
   TSQLResult*       fClassData;     //!  results with request to selected table
   Bool_t            fIsMoreRows;    //!  indicates if class data has not yet read rows
   TList*            fRowsPool;      //!  pool of extrcted, but didnot used rows

   ClassDef(TSQLObjectDataPool,1) // XML object keeper class     
    
};

#endif
 TSQLObjectData.h:1
 TSQLObjectData.h:2
 TSQLObjectData.h:3
 TSQLObjectData.h:4
 TSQLObjectData.h:5
 TSQLObjectData.h:6
 TSQLObjectData.h:7
 TSQLObjectData.h:8
 TSQLObjectData.h:9
 TSQLObjectData.h:10
 TSQLObjectData.h:11
 TSQLObjectData.h:12
 TSQLObjectData.h:13
 TSQLObjectData.h:14
 TSQLObjectData.h:15
 TSQLObjectData.h:16
 TSQLObjectData.h:17
 TSQLObjectData.h:18
 TSQLObjectData.h:19
 TSQLObjectData.h:20
 TSQLObjectData.h:21
 TSQLObjectData.h:22
 TSQLObjectData.h:23
 TSQLObjectData.h:24
 TSQLObjectData.h:25
 TSQLObjectData.h:26
 TSQLObjectData.h:27
 TSQLObjectData.h:28
 TSQLObjectData.h:29
 TSQLObjectData.h:30
 TSQLObjectData.h:31
 TSQLObjectData.h:32
 TSQLObjectData.h:33
 TSQLObjectData.h:34
 TSQLObjectData.h:35
 TSQLObjectData.h:36
 TSQLObjectData.h:37
 TSQLObjectData.h:38
 TSQLObjectData.h:39
 TSQLObjectData.h:40
 TSQLObjectData.h:41
 TSQLObjectData.h:42
 TSQLObjectData.h:43
 TSQLObjectData.h:44
 TSQLObjectData.h:45
 TSQLObjectData.h:46
 TSQLObjectData.h:47
 TSQLObjectData.h:48
 TSQLObjectData.h:49
 TSQLObjectData.h:50
 TSQLObjectData.h:51
 TSQLObjectData.h:52
 TSQLObjectData.h:53
 TSQLObjectData.h:54
 TSQLObjectData.h:55
 TSQLObjectData.h:56
 TSQLObjectData.h:57
 TSQLObjectData.h:58
 TSQLObjectData.h:59
 TSQLObjectData.h:60
 TSQLObjectData.h:61
 TSQLObjectData.h:62
 TSQLObjectData.h:63
 TSQLObjectData.h:64
 TSQLObjectData.h:65
 TSQLObjectData.h:66
 TSQLObjectData.h:67
 TSQLObjectData.h:68
 TSQLObjectData.h:69
 TSQLObjectData.h:70
 TSQLObjectData.h:71
 TSQLObjectData.h:72
 TSQLObjectData.h:73
 TSQLObjectData.h:74
 TSQLObjectData.h:75
 TSQLObjectData.h:76
 TSQLObjectData.h:77
 TSQLObjectData.h:78
 TSQLObjectData.h:79
 TSQLObjectData.h:80
 TSQLObjectData.h:81
 TSQLObjectData.h:82
 TSQLObjectData.h:83
 TSQLObjectData.h:84
 TSQLObjectData.h:85
 TSQLObjectData.h:86
 TSQLObjectData.h:87
 TSQLObjectData.h:88
 TSQLObjectData.h:89
 TSQLObjectData.h:90
 TSQLObjectData.h:91
 TSQLObjectData.h:92
 TSQLObjectData.h:93
 TSQLObjectData.h:94
 TSQLObjectData.h:95
 TSQLObjectData.h:96
 TSQLObjectData.h:97
 TSQLObjectData.h:98
 TSQLObjectData.h:99
 TSQLObjectData.h:100
 TSQLObjectData.h:101
 TSQLObjectData.h:102
 TSQLObjectData.h:103
 TSQLObjectData.h:104
 TSQLObjectData.h:105
 TSQLObjectData.h:106
 TSQLObjectData.h:107
 TSQLObjectData.h:108
 TSQLObjectData.h:109
 TSQLObjectData.h:110
 TSQLObjectData.h:111
 TSQLObjectData.h:112
 TSQLObjectData.h:113
 TSQLObjectData.h:114
 TSQLObjectData.h:115
 TSQLObjectData.h:116
 TSQLObjectData.h:117
 TSQLObjectData.h:118
 TSQLObjectData.h:119
 TSQLObjectData.h:120
 TSQLObjectData.h:121
 TSQLObjectData.h:122
 TSQLObjectData.h:123
 TSQLObjectData.h:124
 TSQLObjectData.h:125
 TSQLObjectData.h:126
 TSQLObjectData.h:127
 TSQLObjectData.h:128
 TSQLObjectData.h:129
 TSQLObjectData.h:130
 TSQLObjectData.h:131
 TSQLObjectData.h:132
 TSQLObjectData.h:133
 TSQLObjectData.h:134
 TSQLObjectData.h:135
 TSQLObjectData.h:136
 TSQLObjectData.h:137
 TSQLObjectData.h:138
 TSQLObjectData.h:139
 TSQLObjectData.h:140
 TSQLObjectData.h:141
 TSQLObjectData.h:142
 TSQLObjectData.h:143
 TSQLObjectData.h:144
 TSQLObjectData.h:145