Warning, file /include/root/TSQLFile.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_TSQLFile
0013 #define ROOT_TSQLFile
0014
0015 #include "TFile.h"
0016 #include <stdlib.h>
0017
0018 class TList;
0019 class TStreamerElement;
0020 class TVirtualStreamerInfo;
0021
0022 class TSQLServer;
0023 class TSQLStatement;
0024 class TSQLResult;
0025 class TSQLRow;
0026 class TKeySQL;
0027 class TBufferSQL2;
0028 class TSQLClassInfo;
0029
0030 class TSQLFile final : public TFile {
0031
0032 friend class TBufferSQL2;
0033 friend class TKeySQL;
0034 friend class TSQLStructure;
0035 friend class TSQLTableData;
0036 friend class TSqlRegistry;
0037 friend class TSqlRawBuffer;
0038 friend class TSqlCmdsBuffer;
0039
0040 protected:
0041 enum ELockingKinds { kLockFree = 0, kLockBusy = 1 };
0042
0043
0044 Int_t SysOpen(const char *, Int_t, UInt_t) final { return 0; }
0045 Int_t SysClose(Int_t) final { return 0; }
0046 Int_t SysRead(Int_t, void *, Int_t) final { return 0; }
0047 Int_t SysWrite(Int_t, const void *, Int_t) final { return 0; }
0048 Long64_t SysSeek(Int_t, Long64_t, Int_t) final { return 0; }
0049 Int_t SysStat(Int_t, Long_t *, Long64_t *, Long_t *, Long_t *) final { return 0; }
0050 Int_t SysSync(Int_t) final { return 0; }
0051
0052
0053 Long64_t DirCreateEntry(TDirectory *) final;
0054 Int_t DirReadKeys(TDirectory *) final;
0055 void DirWriteKeys(TDirectory *) final;
0056 void DirWriteHeader(TDirectory *) final;
0057
0058 InfoListRet GetStreamerInfoListImpl(bool) final;
0059
0060
0061 void SaveToDatabase();
0062 Bool_t ReadConfigurations();
0063 Bool_t IsTablesExists();
0064 void InitSqlDatabase(Bool_t create);
0065 void CreateBasicTables();
0066 void IncrementModifyCounter();
0067 void SetLocking(Int_t mode);
0068 Int_t GetLocking();
0069
0070
0071 Bool_t IsWriteAccess();
0072 Bool_t IsReadAccess();
0073
0074
0075 TSQLResult *SQLQuery(const char *cmd, Int_t flag = 0, Bool_t *res = nullptr);
0076 Bool_t SQLCanStatement();
0077 TSQLStatement *SQLStatement(const char *cmd, Int_t bufsize = 1000);
0078 void SQLDeleteStatement(TSQLStatement *stmt);
0079 Bool_t SQLApplyCommands(TObjArray *cmds);
0080 Bool_t SQLTestTable(const char *tablename);
0081 Long64_t SQLMaximumValue(const char *tablename, const char *columnname);
0082 void SQLDeleteAllTables();
0083 Bool_t SQLStartTransaction();
0084 Bool_t SQLCommit();
0085 Bool_t SQLRollback();
0086 Int_t SQLMaxIdentifierLength();
0087
0088
0089 void DeleteKeyFromDB(Long64_t keyid);
0090 Bool_t WriteKeyData(TKeySQL *key);
0091 Bool_t UpdateKeyData(TKeySQL *key);
0092 TKeySQL *FindSQLKey(TDirectory *dir, Long64_t keyid);
0093 Long64_t DefineNextKeyId();
0094 Int_t StreamKeysForDirectory(TDirectory *dir, Bool_t doupdate, Long64_t specialkeyid = -1, TKeySQL **specialkey = nullptr);
0095
0096
0097 TSQLClassInfo *FindSQLClassInfo(const char *clname, Int_t version);
0098 TSQLClassInfo *FindSQLClassInfo(const TClass *cl);
0099 TSQLClassInfo *RequestSQLClassInfo(const char *clname, Int_t version);
0100 TSQLClassInfo *RequestSQLClassInfo(const TClass *cl);
0101 Bool_t CreateClassTable(TSQLClassInfo *sqlinfo, TObjArray *colinfos);
0102 Bool_t CreateRawTable(TSQLClassInfo *sqlinfo);
0103
0104 Bool_t ProduceClassSelectQuery(TVirtualStreamerInfo *info, TSQLClassInfo *sqlinfo, TString &columns, TString &tables,
0105 Int_t &tablecnt);
0106 void AddIdEntry(Long64_t tableid, Int_t subid, Int_t type, const char *name, const char *sqlname, const char *info);
0107 void ReadSQLClassInfos();
0108 TString DefineTableName(const char *clname, Int_t version, Bool_t rawtable);
0109 Bool_t HasTable(const char *name);
0110
0111
0112 TString CodeLongString(Long64_t objid, Int_t strid);
0113 Int_t IsLongStringCode(Long64_t objid, const char *value);
0114 Bool_t VerifyLongStringTable();
0115 Bool_t GetLongString(Long64_t objid, Int_t strid, TString &value);
0116
0117
0118 Long64_t VerifyObjectTable();
0119 Bool_t SQLObjectInfo(Long64_t objid, TString &clname, Version_t &version);
0120 TObjArray *SQLObjectsInfo(Long64_t keyid);
0121 TSQLResult *GetNormalClassData(Long64_t objid, TSQLClassInfo *sqlinfo);
0122 TSQLResult *GetNormalClassDataAll(Long64_t minobjid, Long64_t maxobjid, TSQLClassInfo *sqlinfo);
0123 TSQLResult *GetBlobClassData(Long64_t objid, TSQLClassInfo *sqlinfo);
0124 TSQLStatement *GetBlobClassDataStmt(Long64_t objid, TSQLClassInfo *sqlinfo);
0125 Long64_t StoreObjectInTables(Long64_t keyid, const void *obj, const TClass *cl);
0126 Bool_t WriteSpecialObject(Long64_t keyid, TObject *obj, const char *name, const char *title);
0127 TObject *ReadSpecialObject(Long64_t keyid, TObject *obj = nullptr);
0128
0129
0130 const char *SQLCompatibleType(Int_t typ) const;
0131 const char *SQLIntType() const;
0132 const char *SQLSmallTextType() const { return fOtherTypes[0]; }
0133 Int_t SQLSmallTextTypeLimit() const { return atoi(fOtherTypes[1]); }
0134 const char *SQLBigTextType() const { return fOtherTypes[2]; }
0135 const char *SQLDatetimeType() const { return fOtherTypes[3]; }
0136 const char *SQLIdentifierQuote() const { return fOtherTypes[4]; }
0137 const char *SQLDirIdColumn() const { return fOtherTypes[5]; }
0138 const char *SQLKeyIdColumn() const { return fOtherTypes[6]; }
0139 const char *SQLObjectIdColumn() const { return fOtherTypes[7]; }
0140 const char *SQLRawIdColumn() const { return fOtherTypes[8]; }
0141 const char *SQLStrIdColumn() const { return fOtherTypes[9]; }
0142 const char *SQLNameSeparator() const { return fOtherTypes[10]; }
0143 const char *SQLValueQuote() const { return fOtherTypes[11]; }
0144 const char *SQLDefaultTableType() const { return fOtherTypes[12]; }
0145
0146 TSQLServer *fSQL;
0147
0148 TList *fSQLClassInfos;
0149
0150 Bool_t fUseSuffixes;
0151 Int_t fSQLIOversion;
0152 Int_t fArrayLimit;
0153 Bool_t fCanChangeConfig;
0154 TString fTablesType;
0155 Int_t fUseTransactions;
0156 Int_t fUseIndexes;
0157 Int_t fModifyCounter;
0158 Int_t fQuerisCounter;
0159
0160 const char **fBasicTypes;
0161 const char **fOtherTypes;
0162
0163 TString fUserName;
0164
0165 std::ofstream *fLogFile;
0166
0167 Bool_t fIdsTableExists;
0168 Int_t fStmtCounter;
0169
0170 private:
0171 TSQLFile(const TSQLFile &) = delete;
0172 void operator=(const TSQLFile &) = delete;
0173
0174 public:
0175 enum ETransactionKinds { kTransactionsOff = 0, kTransactionsAuto = 1, kTransactionsUser = 2 };
0176
0177 enum EIndexesKinds { kIndexesNone = 0, kIndexesBasic = 1, kIndexesClass = 2, kIndexesAll = 3 };
0178
0179 TSQLFile();
0180 TSQLFile(const char *dbname, Option_t *option = "read", const char *user = "user", const char *pass = "pass");
0181 ~TSQLFile() override;
0182
0183
0184 Bool_t GetUseSuffixes() const { return fUseSuffixes; }
0185 void SetUseSuffixes(Bool_t on = kTRUE);
0186 Int_t GetArrayLimit() const { return fArrayLimit; }
0187 void SetArrayLimit(Int_t limit = 20);
0188 void SkipArrayLimit() { SetArrayLimit(-1); }
0189 void SetTablesType(const char *table_type);
0190 const char *GetTablesType() const { return fTablesType.Data(); }
0191 void SetUseTransactions(Int_t mode = kTransactionsAuto);
0192 Int_t GetUseTransactions() const { return fUseTransactions; }
0193 void SetUseIndexes(Int_t use_type = kIndexesBasic);
0194 Int_t GetUseIndexes() const { return fUseIndexes; }
0195 Int_t GetQuerisCounter() const { return fQuerisCounter; }
0196 Int_t GetIOVersion() const { return fSQLIOversion; }
0197
0198 TString MakeSelectQuery(TClass *cl);
0199 Bool_t StartTransaction();
0200 Bool_t Commit();
0201 Bool_t Rollback();
0202
0203
0204 void StartLogFile(const char *fname);
0205 void StopLogFile();
0206
0207 void Close(Option_t *option = "") final;
0208 TKey *CreateKey(TDirectory *mother, const TObject *obj, const char *name, Int_t bufsize) final;
0209 TKey *CreateKey(TDirectory *mother, const void *obj, const TClass *cl, const char *name, Int_t bufsize) final;
0210 void DrawMap(const char * = "*", Option_t * = "") final {}
0211 void FillBuffer(char *&) final {}
0212 void Flush() final {}
0213
0214 Long64_t GetEND() const final { return 0; }
0215 Int_t GetErrno() const final { return 0; }
0216 void ResetErrno() const final {}
0217
0218 const char *GetDataBaseName() const;
0219 Int_t GetNfree() const final { return 0; }
0220 Int_t GetNbytesInfo() const final{ return 0; }
0221 Int_t GetNbytesFree() const final { return 0; }
0222 Long64_t GetSeekFree() const final { return 0; }
0223 Long64_t GetSeekInfo() const final { return 0; }
0224 Long64_t GetSize() const final { return 0; }
0225
0226 Bool_t IsOpen() const final;
0227 Bool_t IsMySQL() const;
0228 Bool_t IsOracle() const;
0229 Bool_t IsODBC() const;
0230
0231 void MakeFree(Long64_t, Long64_t) final {}
0232 void MakeProject(const char *, const char * = "*", Option_t * = "new") final {}
0233 void Map(Option_t *) final {}
0234 void Map() final {}
0235 void Paint(Option_t * = "") final {}
0236 void Print(Option_t * = "") const final {}
0237 Bool_t ReadBuffer(char *, Int_t) final { return kFALSE; }
0238 Bool_t ReadBuffer(char *, Long64_t, Int_t) final { return kFALSE; }
0239 void ReadFree() final {}
0240 Int_t Recover() final { return 0; }
0241 Int_t ReOpen(Option_t *mode) final;
0242 void Seek(Long64_t, ERelativeTo = kBeg) final {}
0243
0244 void SetEND(Long64_t) final {}
0245 Int_t Sizeof() const final { return 0; }
0246
0247 Bool_t WriteBuffer(const char *, Int_t) final { return kFALSE; }
0248 Int_t Write(const char * = nullptr, Int_t = 0, Int_t = 0) final { return 0; }
0249 Int_t Write(const char * = nullptr, Int_t = 0, Int_t = 0) const final { return 0; }
0250 void WriteFree() final {}
0251 void WriteHeader() final;
0252 void WriteStreamerInfo() final;
0253
0254 ClassDefOverride(TSQLFile, 1)
0255 };
0256
0257 #endif