Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TSQLClassInfo.cxx
Go to the documentation of this file.
1 // @(#)root/sql:$Id$
2 // Author: Sergey Linev 20/11/2005
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2005, 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 \class TSQLClassInfo
14 \ingroup IO
15 
16 Contains information about tables specific to one class and
17 version. It provides names of table for that class. For each version of
18 class not more than two tables can exists. Normal table has typically
19 name like TH1_ver4 and additional table has name like TH1_raw4.
20 List of this objects are kept by TSQLFile class.
21 */
22 
23 #include "TSQLClassInfo.h"
24 
25 #include "TObjArray.h"
26 
27 ClassImp(TSQLClassColumnInfo);
28 
29 ////////////////////////////////////////////////////////////////////////////////
30 /// normal constructor
31 
32 TSQLClassColumnInfo::TSQLClassColumnInfo(const char *name, const char *sqlname, const char *sqltype)
33  : TObject(), fName(name), fSQLName(sqlname), fSQLType(sqltype)
34 {
35 }
36 
37 ClassImp(TSQLClassInfo);
38 
39 
40 ////////////////////////////////////////////////////////////////////////////////
41 /// normal constructor of TSQLClassInfo class
42 /// Sets names of tables, which are used for that version of class
43 
44 TSQLClassInfo::TSQLClassInfo(Long64_t classid, const char *classname, Int_t version)
45  : TObject(), fClassName(classname), fClassVersion(version), fClassId(classid)
46 {
47  fClassTable.Form("%s_ver%d", classname, version);
48  fRawTable.Form("%s_raw%d", classname, version);
49 }
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 /// destructor
53 
54 TSQLClassInfo::~TSQLClassInfo()
55 {
56  SetColumns(nullptr);
57 }
58 
59 ////////////////////////////////////////////////////////////////////////////////
60 /// assigns new list of columns
61 
62 void TSQLClassInfo::SetColumns(TObjArray *columns)
63 {
64  if (fColumns) {
65  fColumns->Delete();
66  delete fColumns;
67  }
68  fColumns = columns;
69 }
70 
71 ////////////////////////////////////////////////////////////////////////////////
72 /// set current status of class tables
73 
74 void TSQLClassInfo::SetTableStatus(TObjArray *columns, Bool_t israwtable)
75 {
76  SetColumns(columns);
77  fRawtableExist = israwtable;
78 }
79 
80 ////////////////////////////////////////////////////////////////////////////////
81 /// Search for column of that name
82 ///
83 /// Can search either for full column name (sqlname = kFALSE, default)
84 /// or for name, used as column name (sqlname = kTRUE)
85 /// Return index of column in list (-1 if not found)
86 
87 Int_t TSQLClassInfo::FindColumn(const char *name, Bool_t sqlname)
88 {
89  if (!name || !fColumns)
90  return -1;
91 
92  TIter next(fColumns);
93 
94  TSQLClassColumnInfo *col = nullptr;
95 
96  Int_t indx = 0;
97 
98  while ((col = (TSQLClassColumnInfo *)next()) != nullptr) {
99  const char *colname = sqlname ? col->GetSQLName() : col->GetName();
100  if (strcmp(colname, name) == 0)
101  return indx;
102  indx++;
103  }
104 
105  return -1;
106 }