// @(#)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.             *
 *************************************************************************/

//________________________________________________________________________
// 
// TSQLClassInfo class containes info about tables specific to one class and
// version. It provides names of table for that class. For each version of 
// class not more than two tables can exists. Normal table has typically
// name like TH1_ver4 and additional table has name like TH1_raw4
// List of this objects are kept by TSQLFile class
//
//________________________________________________________________________

#include "TSQLClassInfo.h"

#include "TObjArray.h"


ClassImp(TSQLClassColumnInfo)

//______________________________________________________________________________
TSQLClassColumnInfo::TSQLClassColumnInfo() :
   TObject(),
   fName(),
   fSQLName(),
   fSQLType()
{
   // default constructor 
}

//______________________________________________________________________________
TSQLClassColumnInfo::TSQLClassColumnInfo(const char* name,
                                         const char* sqlname,
                                         const char* sqltype) :
   TObject(),
   fName(name),
   fSQLName(sqlname),
   fSQLType(sqltype)
{
   // normal constructor 
}
                     
//______________________________________________________________________________
TSQLClassColumnInfo::~TSQLClassColumnInfo()
{
   // destructor
}


ClassImp(TSQLClassInfo)

//______________________________________________________________________________
TSQLClassInfo::TSQLClassInfo() :
   TObject(),
   fClassName(),
   fClassVersion(0),
   fClassId(0),
   fClassTable(),
   fRawTable(),
   fColumns(0),
   fRawtableExist(kFALSE)
{
// default constructor
}

//______________________________________________________________________________
TSQLClassInfo::TSQLClassInfo(Long64_t classid,
                             const char* classname, 
                             Int_t version) : 
   TObject(),
   fClassName(classname),
   fClassVersion(version),
   fClassId(classid),
   fClassTable(),
   fRawTable(),
   fColumns(0),
   fRawtableExist(kFALSE)
{
   // normal constructor of TSQLClassInfo class
   // Sets names of tables, which are used for that version of class    
   fClassTable.Form("%s_ver%d", classname, version);
   fRawTable.Form("%s_raw%d", classname, version);
}
   
//______________________________________________________________________________
TSQLClassInfo::~TSQLClassInfo()
{
// destructor

   if (fColumns!=0) {
      fColumns->Delete();  
      delete fColumns; 
   }
}

//______________________________________________________________________________
void TSQLClassInfo::SetColumns(TObjArray* columns)
{
// assigns new list of columns
    
   if (fColumns!=0) {
      fColumns->Delete();  
      delete fColumns; 
   }
   fColumns = columns;
}

//______________________________________________________________________________
void TSQLClassInfo::SetTableStatus(TObjArray* columns, Bool_t israwtable)
{
// set current status of class tables
    
   SetColumns(columns); 
   fRawtableExist = israwtable;
}

//______________________________________________________________________________
Int_t TSQLClassInfo::FindColumn(const char* name, Bool_t sqlname)
{
   // Search for column of that name
   // Can search either for full column name (sqlname = kFALSE, default)
   // or for name, used as column name (sqlname = kTRUE)
   // Return index of column in list (-1 if not found)

   if ((name==0) || (fColumns==0)) return -1;
   
   TIter next(fColumns);

   TSQLClassColumnInfo* col = 0;
   
   Int_t indx = 0;
   
   while ((col = (TSQLClassColumnInfo*) next()) != 0) {
      const char* colname = sqlname ? col->GetSQLName() : col->GetName();
      if (strcmp(colname, name)==0) return indx;
      indx++;
   }
   
   return -1;
}
 TSQLClassInfo.cxx:1
 TSQLClassInfo.cxx:2
 TSQLClassInfo.cxx:3
 TSQLClassInfo.cxx:4
 TSQLClassInfo.cxx:5
 TSQLClassInfo.cxx:6
 TSQLClassInfo.cxx:7
 TSQLClassInfo.cxx:8
 TSQLClassInfo.cxx:9
 TSQLClassInfo.cxx:10
 TSQLClassInfo.cxx:11
 TSQLClassInfo.cxx:12
 TSQLClassInfo.cxx:13
 TSQLClassInfo.cxx:14
 TSQLClassInfo.cxx:15
 TSQLClassInfo.cxx:16
 TSQLClassInfo.cxx:17
 TSQLClassInfo.cxx:18
 TSQLClassInfo.cxx:19
 TSQLClassInfo.cxx:20
 TSQLClassInfo.cxx:21
 TSQLClassInfo.cxx:22
 TSQLClassInfo.cxx:23
 TSQLClassInfo.cxx:24
 TSQLClassInfo.cxx:25
 TSQLClassInfo.cxx:26
 TSQLClassInfo.cxx:27
 TSQLClassInfo.cxx:28
 TSQLClassInfo.cxx:29
 TSQLClassInfo.cxx:30
 TSQLClassInfo.cxx:31
 TSQLClassInfo.cxx:32
 TSQLClassInfo.cxx:33
 TSQLClassInfo.cxx:34
 TSQLClassInfo.cxx:35
 TSQLClassInfo.cxx:36
 TSQLClassInfo.cxx:37
 TSQLClassInfo.cxx:38
 TSQLClassInfo.cxx:39
 TSQLClassInfo.cxx:40
 TSQLClassInfo.cxx:41
 TSQLClassInfo.cxx:42
 TSQLClassInfo.cxx:43
 TSQLClassInfo.cxx:44
 TSQLClassInfo.cxx:45
 TSQLClassInfo.cxx:46
 TSQLClassInfo.cxx:47
 TSQLClassInfo.cxx:48
 TSQLClassInfo.cxx:49
 TSQLClassInfo.cxx:50
 TSQLClassInfo.cxx:51
 TSQLClassInfo.cxx:52
 TSQLClassInfo.cxx:53
 TSQLClassInfo.cxx:54
 TSQLClassInfo.cxx:55
 TSQLClassInfo.cxx:56
 TSQLClassInfo.cxx:57
 TSQLClassInfo.cxx:58
 TSQLClassInfo.cxx:59
 TSQLClassInfo.cxx:60
 TSQLClassInfo.cxx:61
 TSQLClassInfo.cxx:62
 TSQLClassInfo.cxx:63
 TSQLClassInfo.cxx:64
 TSQLClassInfo.cxx:65
 TSQLClassInfo.cxx:66
 TSQLClassInfo.cxx:67
 TSQLClassInfo.cxx:68
 TSQLClassInfo.cxx:69
 TSQLClassInfo.cxx:70
 TSQLClassInfo.cxx:71
 TSQLClassInfo.cxx:72
 TSQLClassInfo.cxx:73
 TSQLClassInfo.cxx:74
 TSQLClassInfo.cxx:75
 TSQLClassInfo.cxx:76
 TSQLClassInfo.cxx:77
 TSQLClassInfo.cxx:78
 TSQLClassInfo.cxx:79
 TSQLClassInfo.cxx:80
 TSQLClassInfo.cxx:81
 TSQLClassInfo.cxx:82
 TSQLClassInfo.cxx:83
 TSQLClassInfo.cxx:84
 TSQLClassInfo.cxx:85
 TSQLClassInfo.cxx:86
 TSQLClassInfo.cxx:87
 TSQLClassInfo.cxx:88
 TSQLClassInfo.cxx:89
 TSQLClassInfo.cxx:90
 TSQLClassInfo.cxx:91
 TSQLClassInfo.cxx:92
 TSQLClassInfo.cxx:93
 TSQLClassInfo.cxx:94
 TSQLClassInfo.cxx:95
 TSQLClassInfo.cxx:96
 TSQLClassInfo.cxx:97
 TSQLClassInfo.cxx:98
 TSQLClassInfo.cxx:99
 TSQLClassInfo.cxx:100
 TSQLClassInfo.cxx:101
 TSQLClassInfo.cxx:102
 TSQLClassInfo.cxx:103
 TSQLClassInfo.cxx:104
 TSQLClassInfo.cxx:105
 TSQLClassInfo.cxx:106
 TSQLClassInfo.cxx:107
 TSQLClassInfo.cxx:108
 TSQLClassInfo.cxx:109
 TSQLClassInfo.cxx:110
 TSQLClassInfo.cxx:111
 TSQLClassInfo.cxx:112
 TSQLClassInfo.cxx:113
 TSQLClassInfo.cxx:114
 TSQLClassInfo.cxx:115
 TSQLClassInfo.cxx:116
 TSQLClassInfo.cxx:117
 TSQLClassInfo.cxx:118
 TSQLClassInfo.cxx:119
 TSQLClassInfo.cxx:120
 TSQLClassInfo.cxx:121
 TSQLClassInfo.cxx:122
 TSQLClassInfo.cxx:123
 TSQLClassInfo.cxx:124
 TSQLClassInfo.cxx:125
 TSQLClassInfo.cxx:126
 TSQLClassInfo.cxx:127
 TSQLClassInfo.cxx:128
 TSQLClassInfo.cxx:129
 TSQLClassInfo.cxx:130
 TSQLClassInfo.cxx:131
 TSQLClassInfo.cxx:132
 TSQLClassInfo.cxx:133
 TSQLClassInfo.cxx:134
 TSQLClassInfo.cxx:135
 TSQLClassInfo.cxx:136
 TSQLClassInfo.cxx:137
 TSQLClassInfo.cxx:138
 TSQLClassInfo.cxx:139
 TSQLClassInfo.cxx:140
 TSQLClassInfo.cxx:141
 TSQLClassInfo.cxx:142
 TSQLClassInfo.cxx:143
 TSQLClassInfo.cxx:144
 TSQLClassInfo.cxx:145
 TSQLClassInfo.cxx:146
 TSQLClassInfo.cxx:147
 TSQLClassInfo.cxx:148