Logo ROOT  
Reference Guide
No Matches
Go to the documentation of this file.
1// @(#)root/sql:$Id$
2// Author: Sergey Linev 20/11/2005
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 *************************************************************************/
12#ifndef ROOT_TSQLStructure
13#define ROOT_TSQLStructure
15#include "TObjArray.h"
17#ifdef Bool
18#undef Bool
20#ifdef True
21#undef True
23#ifdef False
24#undef False
27class TStreamerInfo;
28class TStreamerInfo;
30class TSQLFile;
31class TSqlRegistry;
32class TSqlRawBuffer;
33class TSQLObjectData;
34class TSQLClassInfo;
35class TBufferSQL2;
37class TSQLColumnData final : public TObject {
40 TString fName; ///<! name of the table column
41 TString fType; ///<! type of the table column
42 TString fValue; ///<! value of the table column
43 Bool_t fNumeric{kFALSE}; ///<! for numeric quotes (double quotes) are not required
45 TSQLColumnData(const char *name, const char *sqltype, const char *value, Bool_t numeric);
47 TSQLColumnData(const char *name, Long64_t value);
49 const char *GetName() const final { return fName.Data(); }
50 const char *GetType() const { return fType.Data(); }
51 const char *GetValue() const { return fValue.Data(); }
52 Bool_t IsNumeric() const { return fNumeric; }
54 ClassDefOverride(TSQLColumnData, 1); // Single SQL column data.
59class TSQLTableData : public TObject {
62 TSQLFile *fFile{nullptr}; ///<!
63 TSQLClassInfo *fInfo{nullptr}; ///<!
64 TObjArray fColumns; ///<! collection of columns
65 TObjArray *fColInfos{nullptr}; ///<! array with TSQLClassColumnInfo, used later for TSQLClassInfo
67 TString DefineSQLName(const char *fullname);
68 Bool_t HasSQLName(const char *sqlname);
71 TSQLTableData(TSQLFile *f = nullptr, TSQLClassInfo *info = nullptr);
72 virtual ~TSQLTableData();
74 void AddColumn(const char *name, Long64_t value);
75 void AddColumn(const char *name, const char *sqltype, const char *value, Bool_t numeric);
80 const char *GetColumn(Int_t n);
83 ClassDef(TSQLTableData, 1); // Collection of columns data for single SQL table
88class TSQLStructure : public TObject {
93 void PerformConversion(TSqlRegistry *reg, TSqlRawBuffer *blobs, const char *topname, Bool_t useblob = kFALSE);
94 Bool_t StoreObject(TSqlRegistry *reg, Long64_t objid, TClass *cl, Bool_t registerobj = kTRUE);
95 Bool_t StoreObjectInNormalForm(TSqlRegistry *reg);
96 Bool_t StoreClassInNormalForm(TSqlRegistry *reg);
97 Bool_t StoreElementInNormalForm(TSqlRegistry *reg, TSQLTableData *columns);
98 Bool_t TryConvertObjectArray(TSqlRegistry *reg, TSqlRawBuffer *blobs);
100 Bool_t StoreTObject(TSqlRegistry *reg);
101 Bool_t StoreTString(TSqlRegistry *reg);
102 Bool_t RecognizeTString(const char *&value);
104 TSQLStructure *fParent{nullptr}; //!
105 Int_t fType{0}; //!
106 const void *fPointer{nullptr}; //!
113 TSQLStructure() {} // NOLINT: not allowed to use = default because of TObject::kIsOnHeap detection, see ROOT-10300
114 virtual ~TSQLStructure();
116 TSQLStructure *GetParent() const { return fParent; }
118 Int_t NumChilds() const;
121 void SetType(Int_t typ) { fType = typ; }
122 Int_t GetType() const { return fType; }
124 // this part requried for writing to SQL tables
125 void SetObjectRef(Long64_t refid, const TClass *cl);
126 void SetObjectPointer(Long64_t ptrid);
127 void SetVersion(const TClass *cl, Int_t version = -100);
128 void SetClassStreamer(const TClass *cl);
129 void SetStreamerInfo(const TStreamerInfo *info);
130 void SetStreamerElement(const TStreamerElement *elem, Int_t number);
131 void SetCustomClass(const TClass *cl, Version_t version);
133 void SetValue(const char *value, const char *tname = 0);
134 void SetArrayIndex(Int_t indx, Int_t cnt = 1);
135 void SetArray(Int_t sz = -1);
136 void ChangeValueOnly(const char *value);
138 TClass *GetObjectClass() const;
139 TClass *GetVersionClass() const;
142 Int_t GetElementNumber() const;
143 TClass *GetCustomClass() const;
145 Bool_t GetClassInfo(TClass *&cl, Version_t &version);
146 const char *GetValueType() const;
147 const char *GetValue() const;
148 Int_t GetArrayIndex() const { return fArrayIndex; }
151 void Add(TSQLStructure *child);
152 void AddVersion(const TClass *cl, Int_t version = -100);
153 void AddValue(const char *value, const char *tname = 0);
154 void ChildArrayIndex(Int_t index, Int_t cnt = 1);
156 // this is part specially for reading of sql tables
158 Long64_t DefineObjectId(Bool_t recursive = kTRUE);
160 void SetObjectData(TSQLObjectData *objdata);
161 void AddObjectData(TSQLObjectData *objdata);
162 TSQLObjectData *GetObjectData(Bool_t search = false);
164 virtual void Print(Option_t *option = "") const;
165 void PrintLevel(Int_t level) const;
171 static Bool_t UnpackTObject(TSQLFile *f, TBufferSQL2 *buf, TSQLObjectData *data, Long64_t objid, Int_t clversion);
172 static Bool_t UnpackTString(TSQLFile *f, TBufferSQL2 *buf, TSQLObjectData *data, Long64_t objid, Int_t clversion);
173 static Bool_t IsNumericType(Int_t typ);
174 static const char *GetSimpleTypeName(Int_t typ);
178 static void AddStrBrackets(TString &s, const char *quote);
181 kSqlObject = 10001,
182 kSqlPointer = 10002,
183 kSqlVersion = 10003,
186 kSqlElement = 10006,
187 kSqlValue = 10007,
188 kSqlArray = 10008,
191 kSqlCustomElement = 10011
192 };
205 kColRawData = 10
206 };
208 enum ESQLIdType { kIdTable = 0, kIdRawTable = 1, kIdColumn = 2 };
210 ClassDef(TSQLStructure, 1); // Table/structure description used internally by TBufferSQL.
213// text constants, used in SQL I/O
215namespace sqlio {
217extern Long64_t atol64(const char *value);
219extern const Int_t Ids_NullPtr;
220extern const Int_t Ids_RootDir;
221extern const Int_t Ids_TSQLFile;
222extern const Int_t Ids_StreamerInfos;
223extern const Int_t Ids_FirstKey;
224extern const Int_t Ids_FirstObject;
226extern const char *ObjectRef;
227extern const char *ObjectRef_Arr;
228extern const char *ObjectPtr;
229extern const char *ObjectInst;
230extern const char *Version;
231extern const char *TObjectUniqueId;
232extern const char *TObjectBits;
233extern const char *TObjectProcessId;
234extern const char *TStringValue;
235extern const char *IndexSepar;
236extern const char *RawSuffix;
237extern const char *ParentSuffix;
238extern const char *ObjectSuffix;
239extern const char *PointerSuffix;
240extern const char *StrSuffix;
241extern const char *LongStrPrefix;
243extern const char *Array;
244extern const char *Bool;
245extern const char *Char;
246extern const char *Short;
247extern const char *Int;
248extern const char *Long;
249extern const char *Long64;
250extern const char *Float;
251extern const char *Double;
252extern const char *UChar;
253extern const char *UShort;
254extern const char *UInt;
255extern const char *ULong;
256extern const char *ULong64;
257extern const char *CharStar;
258extern const char *True;
259extern const char *False;
261extern const char *KeysTable;
262extern const char *KeysTableIndex;
263extern const char *KT_Name;
264extern const char *KT_Title;
265extern const char *KT_Datetime;
266extern const char *KT_Cycle;
267extern const char *KT_Class;
269extern const char *DT_Create;
270extern const char *DT_Modified;
271extern const char *DT_UUID;
273extern const char *ObjectsTable;
274extern const char *ObjectsTableIndex;
275extern const char *OT_Class;
276extern const char *OT_Version;
278extern const char *IdsTable;
279extern const char *IdsTableIndex;
280extern const char *IT_TableID;
281extern const char *IT_SubID;
282extern const char *IT_Type;
283extern const char *IT_FullName;
284extern const char *IT_SQLName;
285extern const char *IT_Info;
287extern const char *BT_Field;
288extern const char *BT_Value;
290extern const char *StringsTable;
291extern const char *ST_Value;
293extern const char *ConfigTable;
294extern const char *CT_Field;
295extern const char *CT_Value;
297extern const char *cfg_Version;
298extern const char *cfg_UseSufixes;
299extern const char *cfg_ArrayLimit;
300extern const char *cfg_TablesType;
301extern const char *cfg_UseTransactions;
302extern const char *cfg_UseIndexes;
303extern const char *cfg_LockingMode;
304extern const char *cfg_ModifyCounter;
#define f(i)
Definition RSha256.hxx:104
int Int_t
Definition RtypesCore.h:45
short Version_t
Definition RtypesCore.h:65
const Bool_t kFALSE
Definition RtypesCore.h:92
bool Bool_t
Definition RtypesCore.h:63
long long Long64_t
Definition RtypesCore.h:73
const Bool_t kTRUE
Definition RtypesCore.h:91
const char Option_t
Definition RtypesCore.h:66
#define ClassDef(name, id)
Definition Rtypes.h:325
char name[80]
Definition TGX11.cxx:110
Converts data to SQL statements or read data from SQL tables.
Definition TBufferSQL2.h:27
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:80
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.
TString fName
! name of the table column
const char * GetName() const final
Returns name of object.
ClassDefOverride(TSQLColumnData, 1)
TString fValue
! value of the table column
const char * GetType() const
const char * GetValue() const
Bool_t fNumeric
! for numeric quotes (double quotes) are not required
Bool_t IsNumeric() const
TString fType
! type of the table column
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.
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 structures 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()
void AddValue(const char *value, const char *tname=0)
Add child structure as value.
TClass * GetCustomClass() const
return element custom class if structures 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
TSQLClassInfo * fInfo
Int_t GetNumColumns()
returns number of columns in provided set
TSQLFile * fFile
TObjArray * fColInfos
! array with TSQLClassColumnInfo, used later for TSQLClassInfo
virtual ~TSQLTableData()
TObjArray * TakeColInfos()
take ownership over colinfos
Describe Streamer information for one class version.
Basic string class.
Definition TString.h:136
const char * Data() const
Definition TString.h:369
const Int_t n
Definition legend1.C:16
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