Logo ROOT   6.16/01
Reference Guide
TSQLStructure.h
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#ifndef ROOT_TSQLStructure
13#define ROOT_TSQLStructure
14
15#include "TNamed.h"
16
17#include "TObjArray.h"
18
19#include "TAttAxis.h"
20
21#ifdef Bool
22#undef Bool
23#endif
24#ifdef True
25#undef True
26#endif
27#ifdef False
28#undef False
29#endif
30
31class TStreamerInfo;
32class TStreamerInfo;
34class TSQLFile;
35class TSqlRegistry;
36class TSqlRawBuffer;
37class TSQLObjectData;
38class TSQLClassInfo;
39class TBufferSQL2;
40
41class TSQLColumnData : public TObject {
42
43protected:
44 TString fName; ///<! name of the table column
45 TString fType; ///<! type of the table column
46 TString fValue; ///<! value of the table column
47 Bool_t fNumeric; ///<! for numeric quotes (double quotes) are not required
48public:
50 TSQLColumnData(const char *name, const char *sqltype, const char *value, Bool_t numeric);
51
52 TSQLColumnData(const char *name, Long64_t value);
53 virtual ~TSQLColumnData();
54
55 virtual const char *GetName() const { return fName.Data(); }
56 const char *GetType() const { return fType.Data(); }
57 const char *GetValue() const { return fValue.Data(); }
58 Bool_t IsNumeric() const { return fNumeric; }
59
60 ClassDef(TSQLColumnData, 1); // Single SQL column data.
61};
62
63//______________________________________________________________________
64
65class TSQLTableData : public TObject {
66
67protected:
70 TObjArray fColumns; ///<! collection of columns
71 TObjArray *fColInfos; ///<! array with TSQLClassColumnInfo, used later for TSQLClassInfo
72
73 TString DefineSQLName(const char *fullname);
74 Bool_t HasSQLName(const char *sqlname);
75
76public:
77 TSQLTableData(TSQLFile *f = 0, TSQLClassInfo *info = 0);
78 virtual ~TSQLTableData();
79
80 void AddColumn(const char *name, Long64_t value);
81 void AddColumn(const char *name, const char *sqltype, const char *value, Bool_t numeric);
82
84
86 const char *GetColumn(Int_t n);
88
89 ClassDef(TSQLTableData, 1); // Collection of columns data for single SQL table
90};
91
92//______________________________________________________________________
93
94class TSQLStructure : public TObject {
95protected:
97
99 void PerformConversion(TSqlRegistry *reg, TSqlRawBuffer *blobs, const char *topname, Bool_t useblob = kFALSE);
100 Bool_t StoreObject(TSqlRegistry *reg, Long64_t objid, TClass *cl, Bool_t registerobj = kTRUE);
101 Bool_t StoreObjectInNormalForm(TSqlRegistry *reg);
102 Bool_t StoreClassInNormalForm(TSqlRegistry *reg);
103 Bool_t StoreElementInNormalForm(TSqlRegistry *reg, TSQLTableData *columns);
104 Bool_t TryConvertObjectArray(TSqlRegistry *reg, TSqlRawBuffer *blobs);
105
106 Bool_t StoreTObject(TSqlRegistry *reg);
107 Bool_t StoreTString(TSqlRegistry *reg);
108 Bool_t RecognizeTString(const char *&value);
109
112 const void *fPointer; //!
117
118public:
120 virtual ~TSQLStructure();
121
122 TSQLStructure *GetParent() const { return fParent; }
124 Int_t NumChilds() const;
126
127 void SetType(Int_t typ) { fType = typ; }
128 Int_t GetType() const { return fType; }
129
130 // this part requried for writing to SQL tables
131 void SetObjectRef(Long64_t refid, const TClass *cl);
132 void SetObjectPointer(Long64_t ptrid);
133 void SetVersion(const TClass *cl, Int_t version = -100);
134 void SetClassStreamer(const TClass *cl);
135 void SetStreamerInfo(const TStreamerInfo *info);
136 void SetStreamerElement(const TStreamerElement *elem, Int_t number);
137 void SetCustomClass(const TClass *cl, Version_t version);
139 void SetValue(const char *value, const char *tname = 0);
140 void SetArrayIndex(Int_t indx, Int_t cnt = 1);
141 void SetArray(Int_t sz = -1);
142 void ChangeValueOnly(const char *value);
143
144 TClass *GetObjectClass() const;
145 TClass *GetVersionClass() const;
148 Int_t GetElementNumber() const;
149 TClass *GetCustomClass() const;
151 Bool_t GetClassInfo(TClass *&cl, Version_t &version);
152 const char *GetValueType() const;
153 const char *GetValue() const;
154 Int_t GetArrayIndex() const { return fArrayIndex; }
156
157 void Add(TSQLStructure *child);
158 void AddVersion(const TClass *cl, Int_t version = -100);
159 void AddValue(const char *value, const char *tname = 0);
160 void ChildArrayIndex(Int_t index, Int_t cnt = 1);
161
162 // this is part specially for reading of sql tables
163
164 Long64_t DefineObjectId(Bool_t recursive = kTRUE);
165
166 void SetObjectData(TSQLObjectData *objdata);
167 void AddObjectData(TSQLObjectData *objdata);
168 TSQLObjectData *GetObjectData(Bool_t search = false);
169
170 virtual void Print(Option_t *option = "") const;
171 void PrintLevel(Int_t level) const;
172
174
176
177 static Bool_t UnpackTObject(TSQLFile *f, TBufferSQL2 *buf, TSQLObjectData *data, Long64_t objid, Int_t clversion);
178 static Bool_t UnpackTString(TSQLFile *f, TBufferSQL2 *buf, TSQLObjectData *data, Long64_t objid, Int_t clversion);
179 static Bool_t IsNumericType(Int_t typ);
180 static const char *GetSimpleTypeName(Int_t typ);
184 static void AddStrBrackets(TString &s, const char *quote);
185
187 kSqlObject = 10001,
188 kSqlPointer = 10002,
189 kSqlVersion = 10003,
192 kSqlElement = 10006,
193 kSqlValue = 10007,
194 kSqlArray = 10008,
197 kSqlCustomElement = 10011
198 };
199
211 kColRawData = 10
212 };
213
214 enum ESQLIdType { kIdTable = 0, kIdRawTable = 1, kIdColumn = 2 };
215
216 ClassDef(TSQLStructure, 1); // Table/structure description used internally by TBufferSQL.
217};
218
219// text constants, used in SQL I/O
220
221namespace sqlio {
222
223extern Long64_t atol64(const char *value);
224
225extern const Int_t Ids_NullPtr;
226extern const Int_t Ids_RootDir;
227extern const Int_t Ids_TSQLFile;
228extern const Int_t Ids_StreamerInfos;
229extern const Int_t Ids_FirstKey;
230extern const Int_t Ids_FirstObject;
231
232extern const char *ObjectRef;
233extern const char *ObjectRef_Arr;
234extern const char *ObjectPtr;
235extern const char *ObjectInst;
236extern const char *Version;
237extern const char *TObjectUniqueId;
238extern const char *TObjectBits;
239extern const char *TObjectProcessId;
240extern const char *TStringValue;
241extern const char *IndexSepar;
242extern const char *RawSuffix;
243extern const char *ParentSuffix;
244extern const char *ObjectSuffix;
245extern const char *PointerSuffix;
246extern const char *StrSuffix;
247extern const char *LongStrPrefix;
248
249extern const char *Array;
250extern const char *Bool;
251extern const char *Char;
252extern const char *Short;
253extern const char *Int;
254extern const char *Long;
255extern const char *Long64;
256extern const char *Float;
257extern const char *Double;
258extern const char *UChar;
259extern const char *UShort;
260extern const char *UInt;
261extern const char *ULong;
262extern const char *ULong64;
263extern const char *CharStar;
264extern const char *True;
265extern const char *False;
266
267extern const char *KeysTable;
268extern const char *KeysTableIndex;
269extern const char *KT_Name;
270extern const char *KT_Title;
271extern const char *KT_Datetime;
272extern const char *KT_Cycle;
273extern const char *KT_Class;
274
275extern const char *DT_Create;
276extern const char *DT_Modified;
277extern const char *DT_UUID;
278
279extern const char *ObjectsTable;
280extern const char *ObjectsTableIndex;
281extern const char *OT_Class;
282extern const char *OT_Version;
283
284extern const char *IdsTable;
285extern const char *IdsTableIndex;
286extern const char *IT_TableID;
287extern const char *IT_SubID;
288extern const char *IT_Type;
289extern const char *IT_FullName;
290extern const char *IT_SQLName;
291extern const char *IT_Info;
292
293extern const char *BT_Field;
294extern const char *BT_Value;
295
296extern const char *StringsTable;
297extern const char *ST_Value;
298
299extern const char *ConfigTable;
300extern const char *CT_Field;
301extern const char *CT_Value;
302
303extern const char *cfg_Version;
304extern const char *cfg_UseSufixes;
305extern const char *cfg_ArrayLimit;
306extern const char *cfg_TablesType;
307extern const char *cfg_UseTransactions;
308extern const char *cfg_UseIndexes;
309extern const char *cfg_LockingMode;
310extern const char *cfg_ModifyCounter;
311}
312
313#endif
#define f(i)
Definition: RSha256.hxx:104
int Int_t
Definition: RtypesCore.h:41
short Version_t
Definition: RtypesCore.h:61
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
long long Long64_t
Definition: RtypesCore.h:69
const Bool_t kTRUE
Definition: RtypesCore.h:87
const char Option_t
Definition: RtypesCore.h:62
#define ClassDef(name, id)
Definition: Rtypes.h:324
Converts data to SQL statements or read data from SQL tables.
Definition: TBufferSQL2.h:29
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:75
An array of TObjects.
Definition: TObjArray.h:37
Mother of all ROOT objects.
Definition: TObject.h:37
Contains information about tables specific to one class and version.
Definition: TSQLClassInfo.h:42
TString fName
! name of the table column
Definition: TSQLStructure.h:44
TSQLColumnData()
default constructor
TString fValue
! value of the table column
Definition: TSQLStructure.h:46
const char * GetType() const
Definition: TSQLStructure.h:56
virtual const char * GetName() const
Returns name of object.
Definition: TSQLStructure.h:55
const char * GetValue() const
Definition: TSQLStructure.h:57
Bool_t fNumeric
! for numeric quotes (double quotes) are not required
Definition: TSQLStructure.h:47
Bool_t IsNumeric() const
Definition: TSQLStructure.h:58
virtual ~TSQLColumnData()
TSQLColumnData destructor.
TString fType
! type of the table column
Definition: TSQLStructure.h:45
Access an SQL db via the TFile interface.
Definition: TSQLFile.h:30
TSQLObjectData is used in TBufferSQL2 class in reading procedure.
This is hierarchical structure, which is created when data is written by TBufferSQL2.
Definition: TSQLStructure.h:94
Bool_t RecognizeTString(const char *&value)
prove that structure contains TString data
TSQLStructure * GetParent() const
Int_t LocateElementColumn(TSQLFile *f, TBufferSQL2 *buf, TSQLObjectData *data)
find column in TSQLObjectData object, which correspond to current element
TClass * GetObjectClass() const
return object class if type kSqlObject
virtual void Print(Option_t *option="") const
print content of complete structure
Bool_t TryConvertObjectArray(TSqlRegistry *reg, TSqlRawBuffer *blobs)
tries to write array of objects as list of object references in streamer table, while objects itself ...
static void AddStrBrackets(TString &s, const char *quote)
adds quotes around string value and replaces some special symbols
void Add(TSQLStructure *child)
Add child structure.
void AddVersion(const TClass *cl, Int_t version=-100)
add child as version
void SetVersion(const TClass *cl, Int_t version=-100)
set structure type as kSqlVersion
const void * fPointer
TObjArray fChilds
void SetObjectPointer(Long64_t ptrid)
set structure type as kSqlPointer
void SetValue(const char *value, const char *tname=0)
set structure type as kSqlValue
void SetArray(Int_t sz=-1)
Set structure as array element.
static Bool_t IsNumericType(Int_t typ)
defines if value is numeric and not requires quotes when writing
Int_t GetElementNumber() const
returns number of TStremerElement in TStreamerInfo
TSQLObjectData * GetObjectData(Bool_t search=false)
searches for objects data
TStreamerInfo * GetStreamerInfo() const
return TStreamerInfo* if type is kSqlStreamerInfo
void PerformConversion(TSqlRegistry *reg, TSqlRawBuffer *blobs, const char *topname, Bool_t useblob=kFALSE)
perform conversion of structure to sql statements first tries convert it to normal form if fails,...
Bool_t StoreTObject(TSqlRegistry *reg)
store data of TObject in special table workaround custom TObject streamer
void SetType(Int_t typ)
TSQLStructure * GetChild(Int_t n) const
return child structure of index n
Bool_t GetClassInfo(TClass *&cl, Version_t &version)
provides class info if structure kSqlStreamerInfo or kSqlCustomClass
void SetCustomClass(const TClass *cl, Version_t version)
set structure type as kSqlCustomClass
const char * GetValue() const
returns value for different structure kinds has different sense For kSqlVersion it version,...
static Bool_t UnpackTString(TSQLFile *f, TBufferSQL2 *buf, TSQLObjectData *data, Long64_t objid, Int_t clversion)
Unpack TString data in form, accepted by custom TString streamer.
static Int_t DefineElementColumnType(TStreamerElement *elem, TSQLFile *f)
defines which kind of column can be assigned for this element Possible cases kColSimple - basic data ...
Int_t GetRepeatCounter() const
Long64_t FindMaxObjectId()
define maximum reference id, used for objects
Bool_t StoreObjectInNormalForm(TSqlRegistry *reg)
this function verify object child elements and calls transformation to class table
void SetStreamerInfo(const TStreamerInfo *info)
set structure type as kSqlStreamerInfo
void AddObjectData(TSQLObjectData *objdata)
add element with pointer to object data
void SetArrayIndex(Int_t indx, Int_t cnt=1)
set array index for this structure
Int_t GetType() const
Bool_t StoreClassInNormalForm(TSqlRegistry *reg)
produces data for complete class table where not possible, raw data for some elements are created
static TString MakeArrayIndex(TStreamerElement *elem, Int_t n)
produce string with complete index like [1][2][0]
Version_t GetCustomClassVersion() const
return custom class version if strutures is kSqlCustomClass
static Bool_t UnpackTObject(TSQLFile *f, TBufferSQL2 *buf, TSQLObjectData *data, Long64_t objid, Int_t clversion)
Unpack TObject data in form, accepted by custom TObject streamer.
Bool_t StoreObject(TSqlRegistry *reg, Long64_t objid, TClass *cl, Bool_t registerobj=kTRUE)
convert object data to sql statements if normal (column-wise) representation is not possible,...
void ChangeValueOnly(const char *value)
change value of this structure used as "workaround" to keep object id in kSqlElement node
Bool_t ConvertToTables(TSQLFile *f, Long64_t keyid, TObjArray *cmds)
Convert structure to sql statements This function is called immidiately after TBufferSQL2 produces th...
void SetCustomElement(TStreamerElement *elem)
set structure type as kSqlCustomElement
const char * GetValueType() const
return value type if structure is kSqlValue
TSQLStructure * fParent
static TString DefineElementColumnName(TStreamerElement *elem, TSQLFile *f, Int_t indx=0)
returns name of the column in class table for that element
Int_t GetArrayIndex() const
void SetObjectData(TSQLObjectData *objdata)
set element to be used for object data
void SetParent(TSQLStructure *p)
void SetObjectRef(Long64_t refid, const TClass *cl)
set structure type as kSqlObject
Long64_t DefineObjectId(Bool_t recursive=kTRUE)
defines current object id, to which this structure belong make life complicated, because some objects...
TStreamerElement * GetElement() const
return TStremerElement* if type is kSqlElement
TClass * GetVersionClass() const
return class for version tag if type is kSqlVersion
void PrintLevel(Int_t level) const
print content of current structure
static const char * GetSimpleTypeName(Int_t typ)
provides name for basic types used as suffix for column name or field suffix in raw table
Bool_t StoreElementInNormalForm(TSqlRegistry *reg, TSQLTableData *columns)
tries to store element data in column
Bool_t CheckNormalClassPair(TSQLStructure *vers, TSQLStructure *info)
check if pair of two element corresponds to start of object, stored in normal form
Int_t NumChilds() const
number of child structures
virtual ~TSQLStructure()
destructor
void AddValue(const char *value, const char *tname=0)
Add child structure as value.
TClass * GetCustomClass() const
return element custom class if strutures is kSqlCustomClass
Bool_t StoreTString(TSqlRegistry *reg)
store data of TString in special table it is required when TString stored as pointer and reference to...
void SetClassStreamer(const TClass *cl)
set structure type as kSqlClassStreamer
void SetStreamerElement(const TStreamerElement *elem, Int_t number)
set structure type as kSqlElement
void ChildArrayIndex(Int_t index, Int_t cnt=1)
set array index for last child element if (cnt<=1) return;
void AddColumn(const char *name, Long64_t value)
Add INT column to list of columns.
TString DefineSQLName(const char *fullname)
produce suitable name for column, taking into account length limitation
Bool_t HasSQLName(const char *sqlname)
checks if columns list already has that sql name
const char * GetColumn(Int_t n)
return column value
Bool_t IsNumeric(Int_t n)
identifies if column has numeric value
TObjArray fColumns
! collection of columns
Definition: TSQLStructure.h:70
TSQLClassInfo * fInfo
!
Definition: TSQLStructure.h:69
Int_t GetNumColumns()
returns number of columns in provided set
TSQLFile * fFile
!
Definition: TSQLStructure.h:68
TObjArray * fColInfos
! array with TSQLClassColumnInfo, used later for TSQLClassInfo
Definition: TSQLStructure.h:71
TSQLTableData(TSQLFile *f=0, TSQLClassInfo *info=0)
normal constructor
virtual ~TSQLTableData()
destructor
TObjArray * TakeColInfos()
take ownership over colinfos
Describe Streamer information for one class version.
Definition: TStreamerInfo.h:43
Basic string class.
Definition: TString.h:131
const char * Data() const
Definition: TString.h:364
const Int_t n
Definition: legend1.C:16
static constexpr double s
const char * cfg_UseIndexes
const char * DT_UUID
const char * KT_Name
const char * StringsTable
const char * KT_Title
const Int_t Ids_RootDir
const Int_t Ids_TSQLFile
const char * Long
const char * ULong
const char * ObjectsTableIndex
const char * ObjectSuffix
const char * KT_Cycle
const char * KeysTableIndex
const char * Float
const char * StrSuffix
const char * BT_Value
const char * OT_Version
const Int_t Ids_NullPtr
const char * KeysTable
Long64_t atol64(const char *value)
const char * TStringValue
const char * ObjectRef
const char * cfg_TablesType
const char * IdsTable
const Int_t Ids_FirstObject
const char * False
const char * CT_Field
const char * Double
const char * CT_Value
const char * ObjectRef_Arr
const char * KT_Datetime
const Int_t Ids_FirstKey
const char * DT_Create
const char * ST_Value
const char * UChar
const Int_t Ids_StreamerInfos
const char * ParentSuffix
const char * cfg_ArrayLimit
const char * IT_SubID
const char * ObjectPtr
const char * ULong64
const char * IT_SQLName
const char * IndexSepar
const char * TObjectProcessId
const char * PointerSuffix
const char * OT_Class
const char * IdsTableIndex
const char * ObjectInst
const char * ConfigTable
const char * Version
const char * cfg_UseTransactions
const char * Short
const char * Int
const char * BT_Field
const char * cfg_LockingMode
const char * cfg_UseSufixes
const char * Long64
const char * IT_Type
const char * IT_TableID
const char * UInt
const char * TObjectBits
const char * RawSuffix
const char * IT_Info
const char * True
const char * ObjectsTable
const char * KT_Class
const char * Array
const char * UShort
const char * cfg_ModifyCounter
const char * cfg_Version
const char * TObjectUniqueId
const char * DT_Modified
const char * Bool
const char * LongStrPrefix
const char * Char
const char * CharStar
const char * IT_FullName
const char * cnt
Definition: TXMLSetup.cxx:74