ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TSQLFile.cxx
Go to the documentation of this file.
1 // @(#)root/sql:$Id: 6f6608219c30ddefdf8e25d7cf170d5e69704cd3 $
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 TSQLFile
14 \ingroup IO
15 
16 Access an SQL db via the TFile interface.
17 
18 The main motivation for the TSQLFile development is to have
19 "transparent" access to SQL data base via standard TFile interface.
20 The main approach that each class (but not each object) has one or two tables
21 with names like $(CLASSNAME)_ver$(VERSION) and $(CLASSNAME)_raw$(VERSION)
22 For example: TAxis_ver8 or TList_raw5
23 Second kind of tables appears, when some of class members can not be converted to
24 normalized form or when class has custom streamer.
25 For instance, for TH1 class two tables are required: TH1_ver4 and TH1_raw4
26 Most of memebers are stored in TH1_ver4 table columnwise, and only memeber:
27  Double_t* fBuffer; //[fBufferSize]
28 can not be represented as column while size of array is not known apriory.
29 Therefore, fBuffer will be written as list of values in TH1_raw4 table.
30 All objects, stored in the DB, will be registered in table "ObjectsTable".
31 In this there are following columns:
32 | Name | Description |
33 |------|-------------|
34 | "key:id" | key identifier to which belong object |
35 | "obj:id" | object identifier |
36 | "Class" | object class name |
37 | "Version" | object class version |
38 
39  Data in each "ObjectsTable" row uniqly identify, in which table
40  and which column object is stored.
41 
42 In normal situation all class data should be sorted columnwise.
43 Up to now following member are supported:
44  -# Basic data types. Here is everything clear. Column SQL type will be as much as possible
45  close to the original type of value.
46  -# Fixed array of basic data types. In this case n columns like fArr[0],
47  fArr[1] and so on will be created.
48  If there is multidimensional array, names will be fArr2[1][2][1] and so on
49  -# Parent class. In this case version of parent class is stored and
50  data of parent class will be stored with the same obj:id in corrspondent table.
51  There is a special case, when parent store nothing (this is for instance TQObject).
52  In that case just -1 is written to avoid any extra checks if table exist or not.
53  -# Object as data member. In that case object is saved in normal way to data base and column
54  will contain id of this object.
55  -# Pointer on object. Same as before. In case if object was already stored, just its id
56  will be placed in the column. For NULL pointer 0 is used.
57  -# TString. Now column with limited width like VARCAHR(255) in MySQL is used.
58  Later this will be improved to support maximum possible strings
59  -# Anything else. Data will be converted to raw format and saved in _streamer_ table.
60  Each row supplied with obj:id and row:id, where row:id indicates
61  data, corresponding to this particular data member, and column
62  will contain this raw:id
63 
64 All conversion to SQL statements are done with help of TSQLStructure class.
65 This is special hierarchical structure wich internally is very similar
66 to XML structures. TBufferSQL2 creates these structures, when object
67 data is streamed by ROOT and only afterwards all SQL statements will be produced
68 and applied all together.
69 When data is reading, TBufferSQL2 will produce requests to database
70 during unstreaming of object data.
71 Optionally (default this options on) name of column includes
72 suffix which indicates type of column. For instance:
73 | Name | Description |
74 |------|-------------|
75 | *:parent | parent class, column contain class version |
76 | *:object | other object, column contain object id |
77 | *:rawdata | raw data, column contains id of raw data from _streamer_ table |
78 | *:Int_t | column with integer value |
79 
80 Use TSQLFile::SetUseSuffixes(kFALSE) to disable suffixes usage.
81 This and several other options can be changed only when
82 TSQLFile created with options "CREATE" or "RECREATE" and only before
83 first write operation. These options are:
84 | Name | Description |
85 |------|-------------|
86 | SetUseSuffixes() | suffix usage in column names (default - on) |
87 | SetArrayLimit() | defines maximum array size, which can has column for each element (default 21) |
88 | SetTablesType() | table type name in MySQL database (default "InnoDB") |
89 | SetUseIndexes() | usage of indexes in database (default kIndexesBasic) |
90 
91 Normally these functions should be called immidiately after TSQLFile constructor.
92 When objects data written to database, by default START TRANSACTION/COMMIT
93 SQL commands are used before and after data storage. If TSQLFile detects
94 any problems, ROLLBACK command will be used to restore
95 previous state of data base. If transactions not supported by SQL server,
96 they can be disabled by SetUseTransactions(kTransactionsOff). Or user
97 can take responsibility to use transactions function to hime
98 By default only indexes for basic tables are created.
99 In most cases usage of indexes increase perfomance to data reading,
100 but it also can increase time of writing data to database.
101 There are several modes of index usage available in SetUseIndexes() method
102 There is MakeSelectQuery(TClass*) method, which
103 produces SELECT statement to get objects data of specified class.
104 Difference from simple statement like:
105  mysql> SELECT * FROM TH1I_ver1
106 that not only data for that class, but also data from parent classes
107 will be extracted from other tables and combined in single result table.
108 Such select query can be usufull for external access to objects data.
109 
110 Up to now MySQL 4.1 and Oracle 9i were tested.
111 Some extra work is required for other SQL databases.
112 Hopefully, this should be straigthforward.
113 
114 Known problems and open questions.
115  -# TTree is not supported by TSQLFile. There is independent development
116  of TTreeSQL class, which allows to store trees directly in SQL database
117  -# TClonesArray is store objects in raw format,
118  which can not be accessed outside ROOT.
119  This will be changed later.
120  -# TDirectory cannot work. Hopefully, will (changes in ROOT basic I/O is required)
121  -# Streamer infos are not written to file, therefore schema evolution
122  is not yet supported. All eforts are done to enable this feature in
123  the near future
124 
125 ### Example how TSQLFile can be used
126 
127 #### A session saving data to a SQL data base
128 ~~~{.cpp}
129 auto dbname = "mysql://host.domain:3306/dbname";
130 auto username = "username";
131 auto userpass = "userpass";
132 
133 // Clean data base and create primary tables
134 auto f = new TSQLFile(dbname, "recreate", username, userpass);
135 // Write with standard I/O functions
136 arr->Write("arr", TObject::kSingleKey);
137 h1->Write("histo");
138 // Close connection to DB
139 delete f;
140 ~~~
141 
142 #### A session read data from SQL data base
143 ~~~{.cpp}
144 // Open database again in read-only mode
145 auto f = new TSQLFile(dbname, "open", username, userpass);
146 // Show list of keys
147 f->ls();
148 // Read stored object, again standard ROOT I/O
149 auto h1 = (TH1*) f->Get("histo");
150 if (h1!=0) { h1->SetDirectory(0); h1->Draw(); }
151 auto obj = f->Get("arr");
152 if (obj!=0) obj->Print("*");
153 // close connection to DB
154 delete f;
155 ~~~
156 
157 The "SQL I/O" package is currently under development.
158 Any bug reports and suggestions are welcome.
159 Author: S.Linev, GSI Darmstadt, S.Linev@gsi.de
160 */
161 
162 #include "TSQLFile.h"
163 
164 #include "TROOT.h"
165 #include "TSystem.h"
166 #include "TList.h"
167 #include "TBrowser.h"
168 #include "TObjArray.h"
169 #include "TObjString.h"
170 #include "TList.h"
171 #include "TArrayC.h"
172 #include "TVirtualStreamerInfo.h"
173 #include "TStreamerElement.h"
174 #include "TProcessID.h"
175 #include "TError.h"
176 #include "TClass.h"
177 
178 #include "TSQLServer.h"
179 #include "TSQLTableInfo.h"
180 #include "TSQLColumnInfo.h"
181 #include "TSQLStatement.h"
182 #include "TSQLResult.h"
183 #include "TSQLRow.h"
184 #include "TBufferSQL2.h"
185 #include "TSQLStructure.h"
186 #include "TKeySQL.h"
187 #include "TSQLClassInfo.h"
188 #include "TSQLObjectData.h"
189 
190 #include "Riostream.h"
191 
193 
194 const char* mysql_BasicTypes[21] = {
195 "VARCHAR(255)", // kBase = 0, used for text
196 "TINYINT UNSIGNED", // kChar = 1,
197 "SMALLINT", // kShort = 2,
198 "INT", // kInt = 3,
199 "BIGINT", // kLong = 4,
200 "FLOAT", // kFloat = 5,
201 "INT", // kCounter = 6,
202 "VARCHAR(255)", // kCharStar = 7,
203 "DOUBLE", // kDouble = 8,
204 "DOUBLE", // kDouble32= 9,
205 "", // nothing
206 "TINYINT UNSIGNED", // kUChar = 11,
207 "SMALLINT UNSIGNED",// kUShort = 12,
208 "INT UNSIGNED", // kUInt = 13,
209 "BIGINT UNSIGNED", // kULong = 14,
210 "INT UNSIGNED", // kBits = 15,
211 "BIGINT", // kLong64 = 16,
212 "BIGINT UNSIGNED", // kULong64 = 17,
213 "BOOL", // kBool = 18,
214 "DOUBLE", // kFloat16 = 19,
215 ""
216 };
217 
218 const char* mysql_OtherTypes[13] = {
219 "VARCHAR(255)", // smallest text
220 "255", // maximum length of small text
221 "TEXT", // biggest size text
222 "DATETIME", // date & time
223 "`", // quote for identifier like table name or column name
224 "dir:id", // dir id column
225 "key:id", // key id column
226 "obj:id", // object id column
227 "raw:id", // raw data id column
228 "str:id", // string id column
229 ":", // name separator between name and type like TObject:Parent
230 "\"", // quote for string values in MySQL
231 "InnoDB" // default tables types, used only for MySQL tables
232 };
233 
234 const char* oracle_BasicTypes[21] = {
235 "VARCHAR(255)", // kBase = 0, used for text
236 "INT", // kChar = 1,
237 "INT", // kShort = 2,
238 "INT", // kInt = 3,
239 "INT", // kLong = 4,
240 "FLOAT", // kFloat = 5,
241 "INT", // kCounter = 6,
242 "VARCHAR(255)", // kCharStar = 7,
243 "DOUBLE PRECISION", // kDouble = 8,
244 "DOUBLE PRECISION", // kDouble32= 9,
245 "", // nothing
246 "INT", // kUChar = 11,
247 "INT", // kUShort = 12,
248 "INT", // kUInt = 13,
249 "INT", // kULong = 14,
250 "INT", // kBits = 15,
251 "INT", // kLong64 = 16,
252 "INT", // kULong64 = 17,
253 "INT", // kBool = 18,
254 "FLOAT", // kFloat16 = 19,
255 ""
256 };
257 
258 const char* oracle_OtherTypes[13] = {
259 "VARCHAR(1000)", // smallest text
260 "1000", // maximum size of smallest text
261 "VARCHAR(4000)", // biggest size text, CLOB is not yet supported by TOracleRow
262 "VARCHAR(50)", // date & time
263 "\"", // quote for identifier like table name or column name
264 "dir:id", // dir id column
265 "key:id", // key id column
266 "obj:id", // object id column
267 "raw:id", // raw data id column
268 "str:id", // string id column
269 ":", // name separator between name and type like TObject:parent
270 "'", // quote for string values in Oracle
271 "" // default tables types, used only for MySQL tables
272 };
273 
274 
275 ////////////////////////////////////////////////////////////////////////////////
276 /// default TSQLFile constructor
277 
279  TFile(),
280  fSQL(0),
281  fSQLClassInfos(0),
282  fUseSuffixes(kTRUE),
283  fSQLIOversion(1),
284  fArrayLimit(21),
285  fCanChangeConfig(kFALSE),
286  fTablesType(),
287  fUseTransactions(0),
288  fUseIndexes(0),
289  fModifyCounter(0),
290  fQuerisCounter(0),
291  fBasicTypes(0),
292  fOtherTypes(0),
293  fUserName(),
294  fLogFile(0),
295  fIdsTableExists(kFALSE),
296  fStmtCounter(0)
297 {
299 }
300 
301 ////////////////////////////////////////////////////////////////////////////////
302 /// Connects to SQL server with provided arguments.
303 ///
304 /// If the constructor fails in any way IsZombie() will
305 /// return true. Use IsOpen() to check if the file is (still) open.
306 /// | Option | Description |
307 /// |--------|-------------|
308 /// | NEW or CREATE | Create a ROOT tables in database if the tables already exists connection is not opened.|
309 /// | RECREATE | Create completely new tables. Any existing table will be deleted.|
310 /// | UPDATE | Open an existing database for writing. If data base open by other TSQLFile instance for writing, write access will be rejected.|
311 /// | BREAKLOCK | Special case when lock was not correctly released by TSQLFile instance. This may happen if program crashed when TSQLFile was open with write access mode.|
312 /// | READ / OPEN | Open an existing data base for reading.|
313 ///
314 /// For more details see comments for TFile::TFile() constructor.
315 /// For a moment TSQLFile does not support TTree objects and subdirectories.
316 
317 TSQLFile::TSQLFile(const char* dbname, Option_t* option, const char* user, const char* pass) :
318  TFile(),
319  fSQL(0),
320  fSQLClassInfos(0),
321  fUseSuffixes(kTRUE),
322  fSQLIOversion(1),
323  fArrayLimit(21),
324  fCanChangeConfig(kFALSE),
325  fTablesType(),
326  fUseTransactions(0),
327  fUseIndexes(0),
328  fModifyCounter(0),
329  fQuerisCounter(0),
330  fBasicTypes(mysql_BasicTypes),
331  fOtherTypes(mysql_OtherTypes),
332  fUserName(user),
333  fLogFile(0),
334  fIdsTableExists(kFALSE),
335  fStmtCounter(0)
336 {
337  if (!gROOT)
338  ::Fatal("TFile::TFile", "ROOT system not initialized");
339 
340  gDirectory = 0;
341  SetName(dbname);
342  SetTitle("TFile interface to SQL DB");
344  fFile = this;
345 
346  if (dbname && strstr(dbname,"oracle://")!=0) {
349  }
350 
351  fArrayLimit = 21;
353  fUseIndexes = 1;
355 
356  fD = -1;
357  fFile = this;
358  fFree = 0;
359  fVersion = gROOT->GetVersionInt(); //ROOT version in integer format
360  fUnits = 4;
361  fOption = option;
363  fWritten = 0;
364  fSumBuffer = 0;
365  fSum2Buffer = 0;
366  fBytesRead = 0;
367  fBytesWrite = 0;
368  fClassIndex = 0;
369  fSeekInfo = 0;
370  fNbytesInfo = 0;
371  fProcessIDs = 0;
372  fNProcessIDs= 0;
375 
376  fOption = option;
377  fOption.ToUpper();
378 
379  if (fOption == "NEW") fOption = "CREATE";
380 
381  Bool_t breaklock = kFALSE;
382 
383  if (fOption == "BREAKLOCK") { breaklock = kTRUE; fOption = "UPDATE"; }
384 
385  Bool_t create = (fOption == "CREATE") ? kTRUE : kFALSE;
386  Bool_t recreate = (fOption == "RECREATE") ? kTRUE : kFALSE;
387  Bool_t update = (fOption == "UPDATE") ? kTRUE : kFALSE;
388  Bool_t read = (fOption == "READ") ? kTRUE : kFALSE;
389 
390  if (!create && !recreate && !update && !read) {
391  read = kTRUE;
392  fOption = "READ";
393  }
394 
395  if (!dbname || !dbname[0]) {
396  Error("TSQLFile", "Database not specified");
397  goto zombie;
398  }
399 
400  gROOT->cd();
401 
402  fSQL = TSQLServer::Connect(dbname, user, pass);
403 
404  if (fSQL==0) {
405  Error("TSQLFile", "Cannot connect to DB %s", dbname);
406  goto zombie;
407  }
408 
409  if (recreate) {
410  if (IsTablesExists())
411  if (!IsWriteAccess()) {
412  Error("TSQLFile", "no write permission, DB %s locked", dbname);
413  goto zombie;
414  }
416  recreate = kFALSE;
417  create = kTRUE;
418  fOption = "CREATE";
419  }
420 
421  if (create && IsTablesExists()) {
422  Error("TSQLFile", "DB tables already exists");
423  goto zombie;
424  }
425 
426  if (update) {
427  if (!IsTablesExists()) {
428  update = kFALSE;
429  create = kTRUE;
430  }
431 
432  if (update && !breaklock && !IsWriteAccess()) {
433  Error("TSQLFile", "no write permission, DB %s locked", dbname);
434  goto zombie;
435  }
436  }
437 
438  if (read) {
439  if (!IsTablesExists()) {
440  Error("TSQLFile", "DB %s tables not exist", dbname);
441  goto zombie;
442  }
443  if (!IsReadAccess()) {
444  Error("TSQLFile", "no read permission for DB %s tables", dbname);
445  goto zombie;
446  }
447  }
448 
449  fRealName = dbname;
450 
451  if (create || update) {
453  if (update) SetLocking(kLockBusy);
454  } else
456 
457  // user can change configurations only when create (recreate) options
458  // was specified. When first object will be saved, configurations will
459  // be frozen.
460  fCanChangeConfig = create;
461 
462  InitSqlDatabase(create);
463 
464  return;
465 
466 zombie:
467 
468  delete fSQL;
469  fSQL = 0;
470  MakeZombie();
471  gDirectory = gROOT;
472 }
473 
474 ////////////////////////////////////////////////////////////////////////////////
475 /// start logging of all SQL statements in specified file
476 
477 void TSQLFile::StartLogFile(const char* fname)
478 {
479  StopLogFile();
480  fLogFile = new std::ofstream(fname);
481 }
482 
483 ////////////////////////////////////////////////////////////////////////////////
484 /// close logging file
485 
487 {
488  if (fLogFile!=0) {
489  delete fLogFile;
490  fLogFile = 0;
491  }
492 }
493 
494 ////////////////////////////////////////////////////////////////////////////////
495 /// checks, if MySQL database
496 
498 {
499  if (fSQL==0) return kFALSE;
500  return strcmp(fSQL->ClassName(),"TMySQLServer")==0;
501 }
502 
503 ////////////////////////////////////////////////////////////////////////////////
504 /// checks, if Oracle database
505 
507 {
508  if (fSQL==0) return kFALSE;
509  return strcmp(fSQL->ClassName(),"TOracleServer")==0;
510 }
511 
512 ////////////////////////////////////////////////////////////////////////////////
513 /// checks, if ODBC driver used for database connection
514 
516 {
517  if (fSQL==0) return kFALSE;
518  return strcmp(fSQL->ClassName(),"TODBCServer")==0;
519 
520 }
521 
522 ////////////////////////////////////////////////////////////////////////////////
523 /// enable/disable uasge of suffixes in columns names
524 /// can be changed before first object is saved into file
525 
527 {
528  if (!fCanChangeConfig)
529  Error("SetUseSuffixes", "Configurations already cannot be changed");
530  else
531  fUseSuffixes = on;
532 }
533 
534 ////////////////////////////////////////////////////////////////////////////////
535 /// Defines maximum number of columns for array representation
536 /// If array size bigger than limit, array data will be converted to raw format
537 /// This is usefull to prevent tables with very big number of columns
538 /// If limit==0, all arrays will be stored in raw format
539 /// If limit<0, all array values will be stored in column form
540 /// Default value is 21
541 
543 {
544  if (!fCanChangeConfig)
545  Error("SetArrayLimit", "Configurations already cannot be changed");
546  else
547  fArrayLimit = limit;
548 }
549 
550 ////////////////////////////////////////////////////////////////////////////////
551 /// Defines tables type, which is used in CREATE TABLE statements
552 /// Now is only used for MySQL database, where following types are supported:
553 /// "BDB", "HEAP", "ISAM", "InnoDB", "MERGE", "MRG_MYISAM", "MYISAM"
554 /// Default for TSQLFile is "InnoDB". For more detailes see MySQL docs.
555 
556 void TSQLFile::SetTablesType(const char* tables_type)
557 {
558  if (!fCanChangeConfig)
559  Error("SetTablesType", "Configurations already cannot be changed");
560  else
561  fTablesType = tables_type;
562 }
563 
564 ////////////////////////////////////////////////////////////////////////////////
565 /// Defines usage of transactions statements for writing objects data to database.
566 /// | Index | Description |
567 /// |-------|-------------|
568 /// | kTransactionsOff=0 - no transaction operation are allowed |
569 /// | kTransactionsAuto=1 - automatic mode. Each write operation, produced by TSQLFile, will be supplied by START TRANSACTION and COMMIT calls. If any error happen, ROLLBACK will returns database to previous state |
570 /// | kTransactionsUser=2 - transactions are delegated to user. Methods StartTransaction(), Commit() and Rollback() should be called by user. |
571 ///
572 /// Default UseTransactions option is kTransactionsAuto
573 
575 {
576  fUseTransactions = mode;
577 }
578 
579 ////////////////////////////////////////////////////////////////////////////////
580 /// Start user transaction.
581 ///
582 /// This can be usesful, when big number of objects should be stored in
583 /// data base and commitment required only if all operations were successful.
584 /// In that case in the end of all operations method Commit() should be
585 /// called. If operation on user-level is looks like not successful,
586 /// method Rollback() will return database data and TSQLFile instance to
587 /// previous state.
588 /// In MySQL not all tables types support transaction mode of operation.
589 /// See SetTablesType() method for details .
590 
592 {
594  Error("SQLStartTransaction","Only allowed when SetUseTransactions(kUserTransactions) was configured");
595  return kFALSE;
596  }
597 
598  return SQLStartTransaction();
599 }
600 
601 ////////////////////////////////////////////////////////////////////////////////
602 /// Commit transaction, started by StartTransaction() call.
603 /// Only after that call data will be written and visible on database side.
604 
606 {
608  Error("SQLCommit","Only allowed when SetUseTransactions(kUserTransactions) was configured");
609  return kFALSE;
610  }
611 
612  return SQLCommit();
613 }
614 
615 ////////////////////////////////////////////////////////////////////////////////
616 /// Rollback all operations, done after StartTransaction() call.
617 /// Database should return to initial state.
618 
620 {
622  Error("SQLRollback","Only allowed when SetUseTransactions(kUserTransactions) was configured");
623  return kFALSE;
624  }
625 
626  return SQLRollback();
627 }
628 
629 ////////////////////////////////////////////////////////////////////////////////
630 /// Specify usage of indexes for data tables
631 /// | Index | Description |
632 /// |-------|-------------|
633 /// | kIndexesNone = 0 | no indexes are used|
634 /// | kIndexesBasic = 1 | indexes used only for keys list and objects list tables (default)|
635 /// | kIndexesClass = 2 | index also created for every normal class table|
636 /// | kIndexesAll = 3 | index created for every table, including _streamer_ tables|
637 ///
638 /// Indexes in general should increase speed of access to objects data,
639 /// but they required more operations and more disk space on server side
640 
642 {
643  if (!fCanChangeConfig)
644  Error("SetUseIndexes", "Configurations already cannot be changed");
645  else
646  fUseIndexes = use_type;
647 }
648 
649 ////////////////////////////////////////////////////////////////////////////////
650 /// Return name of data base on the host
651 /// For Oracle always return 0
652 
653 const char* TSQLFile::GetDataBaseName() const
654 {
655  if (IsOracle()) return 0;
656  const char* name = strrchr(GetName(),'/');
657  if (name==0) return 0;
658  return name + 1;
659 }
660 
661 ////////////////////////////////////////////////////////////////////////////////
662 /// Close a SQL file
663 /// For more comments see TFile::Close() function
664 
666 {
667  if (!IsOpen()) return;
668 
669  TString opt = option;
670  if (opt.Length()>0)
671  opt.ToLower();
672 
673  if (IsWritable()) {
674  SaveToDatabase();
676  }
677 
678  fWritable = kFALSE;
679 
680  if (fClassIndex) {
681  delete fClassIndex;
682  fClassIndex = 0;
683  }
684 
685  {
686  TDirectory::TContext ctxt(this);
687  // Delete all supported directories structures from memory
689  }
690 
691  //delete the TProcessIDs
692  TList pidDeleted;
694  TProcessID *pid;
695  while ((pid = (TProcessID*)next())) {
696  if (!pid->DecrementCount()) {
697  if (pid != TProcessID::GetSessionProcessID()) pidDeleted.Add(pid);
698  } else if(opt.Contains("r")) {
699  pid->Clear();
700  }
701  }
702  pidDeleted.Delete();
703 
705  gROOT->GetListOfFiles()->Remove(this);
706 }
707 
708 ////////////////////////////////////////////////////////////////////////////////
709 /// destructor of TSQLFile object
710 
712 {
713  Close();
714 
715  if (fSQLClassInfos!=0) {
717  delete fSQLClassInfos;
718  }
719 
720  StopLogFile();
721 
722  if (fSQL!=0) {
723  delete fSQL;
724  fSQL = 0;
725  }
726 }
727 
728 ////////////////////////////////////////////////////////////////////////////////
729 /// make private to exclude copy operator
730 
732 {
733 }
734 
735 ////////////////////////////////////////////////////////////////////////////////
736 /// return kTRUE if file is opened and can be accessed
737 
739 {
740  return fSQL != 0;
741 }
742 
743 ////////////////////////////////////////////////////////////////////////////////
744 /// Reopen a file with a different access mode, like from READ to
745 /// See TFile::Open() for details
746 
748 {
749  cd();
750 
751  TString opt = mode;
752  opt.ToUpper();
753 
754  if (opt != "READ" && opt != "UPDATE") {
755  Error("ReOpen", "mode must be either READ or UPDATE, not %s", opt.Data());
756  return 1;
757  }
758 
759  if (opt == fOption || (opt == "UPDATE" && fOption == "CREATE"))
760  return 1;
761 
762  if (opt == "READ") {
763  // switch to READ mode
764 
765  if (IsOpen() && IsWritable()) {
766  SaveToDatabase();
768  }
769  fOption = opt;
770 
772 
773  } else {
774  // switch to UPDATE mode
775 
776  if (!IsWriteAccess()) {
777  Error("ReOpen","Tables are locked, no write access");
778  return 1;
779  }
780 
781  fOption = opt;
782 
784 
786  }
787 
788  return 0;
789 }
790 
791 ////////////////////////////////////////////////////////////////////////////////
792 /// create SQL key, which will store object in data base
793 
794 TKey* TSQLFile::CreateKey(TDirectory* mother, const TObject* obj, const char* name, Int_t )
795 {
796  return new TKeySQL(mother, obj, name);
797 }
798 
799 ////////////////////////////////////////////////////////////////////////////////
800 /// create SQL key, which will store object in data base
801 
802 TKey* TSQLFile::CreateKey(TDirectory* mother, const void* obj, const TClass* cl, const char* name, Int_t )
803 {
804  return new TKeySQL(mother, obj, cl, name);
805 }
806 
807 ////////////////////////////////////////////////////////////////////////////////
808 /// Write file info like configurations, title, UUID and other
809 
811 {
813 }
814 
815 ////////////////////////////////////////////////////////////////////////////////
816 /// Store all TVirtualStreamerInfo, used in file, in sql database
817 
819 {
820  // return;
821 
822  // do not write anything when no basic tables was created
823  if (!IsTablesExists()) return;
824 
825  if (gDebug>1)
826  Info("WriteStreamerInfo","Saving streamer infos to database");
827 
828  TList list;
829 
830  TIter iter(gROOT->GetListOfStreamerInfo());
831 
832  TVirtualStreamerInfo* info = 0;
833 
834  while ((info = (TVirtualStreamerInfo*) iter()) !=0 ) {
835  Int_t uid = info->GetNumber();
836  if (fClassIndex->fArray[uid]) {
837  if (gDebug>1) Info("WriteStreamerInfo","Add %s",info->GetName());
838  list.Add(info);
839  }
840  }
841  if (list.GetSize()==0) return;
842  fClassIndex->fArray[0] = 2; //to prevent adding classes in TVirtualStreamerInfo::TagFile
843 
844  WriteSpecialObject(sqlio::Ids_StreamerInfos, &list, "StreamerInfo", "StreamerInfos of this file");
845 
846  fClassIndex->fArray[0] = 0; //to prevent adding classes in TVirtualStreamerInfo::TagFile
847 }
848 
849 ////////////////////////////////////////////////////////////////////////////////
850 /// write special kind of object like streamer infos or file itself
851 /// keys for that objects should exist in tables but not indicated in list of keys,
852 /// therefore users can not get them with TDirectoryFile::Get() method
853 
855 {
856  DeleteKeyFromDB(keyid);
857  if (obj==0) return kTRUE;
858 
859  Long64_t objid = StoreObjectInTables(keyid, obj, obj->IsA());
860 
861  if (objid>0) {
862  TDatime now;
863 
864  TKeySQL* key = new TKeySQL(this, keyid, objid,
865  name, title,
866  now.AsSQLString(), 1, obj->ClassName());
867  WriteKeyData(key);
868  delete key;
869  }
870 
871  return (objid>0);
872 }
873 
874 ////////////////////////////////////////////////////////////////////////////////
875 /// Read data of special kind of objects
876 
878 {
879  TKeySQL* key = 0;
880 
881  StreamKeysForDirectory(this, kFALSE, keyid, &key);
882  if (key==0) return obj;
883 
885 
886  TClass* cl = 0;
887 
888  void* res = buffer.SqlReadAny(key->GetDBKeyId(), key->GetDBObjId(), &cl, obj);
889 
890  if ((cl==TSQLFile::Class()) && (res!=0) && (obj==this)) {
891  // name should not be preserved while name of database may be changed
892  SetTitle(key->GetTitle());
893  }
894 
895  delete key;
896 
897  return (TObject*) res;
898 }
899 
900 ////////////////////////////////////////////////////////////////////////////////
901 /// Read back streamer infos from database
902 /// List of streamer infos is always stored with key:id 0,
903 /// which is not shown in normal keys list
904 
906 {
907 // return new TList;
908 
909  if (gDebug>1)
910  Info("GetStreamerInfoList","Start reading of streamer infos");
911 
913 
914  TList* list = dynamic_cast<TList*> (obj);
915  if (list==0) { delete obj; list = new TList; }
916 
917  return list;
918 }
919 
920 ////////////////////////////////////////////////////////////////////////////////
921 /// save data which is not yet in Database
922 /// Typically this is streamerinfos structures or
923 
925 {
926  if (fSQL==0) return;
927 
929  WriteHeader();
930 }
931 
932 ////////////////////////////////////////////////////////////////////////////////
933 /// read keys for specified directory (when update == kFALSE)
934 /// or update value for modified keys when update == kTRUE
935 /// Returns number of successfully read keys or -1 if error
936 
938 {
939  if (dir==0) return -1;
940 
941  const char* quote = SQLIdentifierQuote();
942 
943  Long64_t dirid = dir->GetSeekDir();
944 
945  TString sqlcmd;
946  sqlcmd.Form("SELECT * FROM %s%s%s WHERE %s%s%s=%lld",
947  quote, sqlio::KeysTable, quote,
948  quote, SQLDirIdColumn(), quote, dirid);
949  if (specialkeyid>=0) {
950  TString buf;
951  buf.Form(" AND %s%s%s=%lld", quote, SQLKeyIdColumn(), quote, specialkeyid);
952  sqlcmd += buf;
953  }
954 
955  TSQLResult* res = SQLQuery(sqlcmd.Data(), 2);
956 
957  if (res==0) return -1;
958 
959  Int_t nkeys = 0;
960 
961  TSQLRow* row = 0;
962 
963  while ((row = res->Next()) != 0) {
964  nkeys++;
965 
966  Long64_t keyid = sqlio::atol64((*row)[0]);
967  // Int_t dirid = atoi((*row)[1]);
968  Long64_t objid = sqlio::atol64((*row)[2]);
969  const char* keyname = (*row)[3];
970  const char* keytitle = (*row)[4];
971  const char* keydatime = (*row)[5];
972  Int_t cycle = atoi((*row)[6]);
973  const char* classname = (*row)[7];
974 
975  if (gDebug>4)
976  std::cout << " Reading keyid = " << keyid << " name = " << keyname << std::endl;
977 
978  if ((keyid>=sqlio::Ids_FirstKey) || (keyid==specialkeyid)) {
979  if (doupdate) {
980  TKeySQL* key = FindSQLKey(dir, keyid);
981 
982  if (key==0) {
983  Error("StreamKeysForDirectory","Key with id %lld not exist in list", keyid);
984  nkeys = -1; // this will finish execution
985  } else
986  if (key->IsKeyModified(keyname, keytitle, keydatime, cycle, classname))
987  UpdateKeyData(key);
988 
989  } else {
990  TKeySQL* key = new TKeySQL(dir, keyid, objid,
991  keyname, keytitle,
992  keydatime, cycle, classname);
993  if (specialkey!=0)
994  { *specialkey = key; nkeys = 1; }
995  else
996  dir->GetListOfKeys()->Add(key);
997  }
998  }
999  delete row;
1000  }
1001 
1002  delete res;
1003 
1004  if (gDebug>4) {
1005  Info("StreamKeysForDirectory","dir = %s numread = %d",dir->GetName(), nkeys);
1006  dir->GetListOfKeys()->Print("*");
1007  }
1008 
1009  return nkeys;
1010 }
1011 
1012 ////////////////////////////////////////////////////////////////////////////////
1013 /// initialize sql database and correspondent structures
1014 /// identical to TFile::Init() function
1015 
1017 {
1018  Int_t len = gROOT->GetListOfStreamerInfo()->GetSize()+1;
1019  if (len<5000) len = 5000;
1020  fClassIndex = new TArrayC(len);
1021  fClassIndex->Reset(0);
1022 
1023  if (!create) {
1024 
1025  Bool_t ok = ReadConfigurations();
1026 
1027  // read data corresponding to TSQLFile
1028  if (ok) {
1030 
1031  ReadStreamerInfo();
1032 
1033  ok = (ReadSpecialObject(sqlio::Ids_TSQLFile, this) != 0);
1034  }
1035 
1036  // read list of keys
1037  if (ok)
1038  ok = StreamKeysForDirectory(this, kFALSE)>=0;
1039 
1040  if (!ok) {
1041  Error("InitSqlDatabase", "Cannot detect proper tabled in database. Close.");
1042  Close();
1043  delete fSQL;
1044  fSQL = 0;
1045  MakeZombie();
1046  gDirectory = gROOT;
1047  return;
1048  }
1049  }
1050 
1051  {
1053  gROOT->GetListOfFiles()->Add(this);
1054  }
1055  cd();
1056 
1057  fNProcessIDs = 0;
1058  TKey* key = 0;
1059  TIter iter(fKeys);
1060  while ((key = (TKey*)iter())!=0) {
1061  if (!strcmp(key->GetClassName(),"TProcessID")) fNProcessIDs++;
1062  }
1063 
1065 }
1066 
1067 ////////////////////////////////////////////////////////////////////////////////
1068 /// read table configurations as special table
1069 
1071 {
1072  const char* quote = SQLIdentifierQuote();
1073 
1074  TString sqlcmd;
1075  sqlcmd.Form("SELECT * FROM %s%s%s",
1076  quote, sqlio::ConfigTable, quote);
1077  TSQLResult* res = SQLQuery(sqlcmd.Data(), 2);
1078 
1079  if (res==0) return kFALSE;
1080 
1081  // should be found, otherwise will be error
1082  fSQLIOversion = 0;
1083 
1084  Int_t lock = 0;
1085 
1086  #define ReadIntCfg(name, target) \
1087  if ((field.CompareTo(name, TString::kIgnoreCase)==0)) \
1088  target = value.Atoi(); else
1089 
1090  #define ReadBoolCfg(name, target) \
1091  if ((field.CompareTo(name, TString::kIgnoreCase)==0)) \
1092  target = value.CompareTo(sqlio::True, TString::kIgnoreCase)==0; else
1093 
1094  #define ReadStrCfg(name, target) \
1095  if ((field.CompareTo(name, TString::kIgnoreCase)==0)) \
1096  target = value; else
1097 
1098  TSQLRow* row = 0;
1099 
1100  while ((row = res->Next()) != 0) {
1101 
1102  TString field = row->GetField(0);
1103  TString value = row->GetField(1);
1104 
1105  delete row;
1106 
1115  {
1116  Error("ReadConfigurations","Invalid configuration field %s", field.Data());
1117  fSQLIOversion = 0;
1118  break;
1119  }
1120  }
1121  (void)lock;
1122 
1123  delete res;
1124 
1125  return (fSQLIOversion>0);
1126 }
1127 
1128 ////////////////////////////////////////////////////////////////////////////////
1129 /// Creates initial tables in database
1130 /// This is table with configurations and table with keys
1131 /// Function called once when first object is stored to the file.
1132 
1134 {
1135  TString sqlcmd;
1136 
1137  const char* quote = SQLIdentifierQuote();
1138  const char* vquote = SQLValueQuote();
1139 
1141  sqlcmd.Form("DROP TABLE %s%s%s", quote, sqlio::ConfigTable, quote);
1142  SQLQuery(sqlcmd.Data());
1143  }
1144 
1145  sqlcmd.Form("CREATE TABLE %s%s%s (%s%s%s %s, %s%s%s %s)",
1146  quote, sqlio::ConfigTable, quote,
1147  quote, sqlio::CT_Field, quote, SQLSmallTextType(),
1148  quote, sqlio::CT_Value, quote, SQLSmallTextType());
1149  if ((fTablesType.Length()>0) && IsMySQL()) {
1150  sqlcmd +=" ENGINE=";
1151  sqlcmd += fTablesType;
1152  }
1153 
1154  SQLQuery(sqlcmd.Data());
1155 
1156  #define WrintCfg(name, type, value) \
1157  { \
1158  sqlcmd.Form("INSERT INTO %s%s%s VALUES (%s%s%s, %s" type "%s)", \
1159  quote, sqlio::ConfigTable, quote, \
1160  vquote, name, vquote, \
1161  vquote, value, vquote); \
1162  SQLQuery(sqlcmd.Data()); \
1163  }
1164 
1173 
1174  // from this moment on user cannot change configurations
1176 
1178  sqlcmd.Form("DROP TABLE %s%s%s", quote, sqlio::KeysTable, quote);
1179  SQLQuery(sqlcmd.Data());
1180  }
1181 
1182  sqlcmd.Form("CREATE TABLE %s%s%s (%s%s%s %s, %s%s%s %s, %s%s%s %s, %s%s%s %s, %s%s%s %s, %s%s%s %s, %s%s%s %s, %s%s%s %s)",
1183  quote, sqlio::KeysTable, quote,
1184  quote, SQLKeyIdColumn(), quote, SQLIntType(),
1185  quote, SQLDirIdColumn(), quote, SQLIntType(),
1186  quote, SQLObjectIdColumn(), quote, SQLIntType(),
1187  quote, sqlio::KT_Name, quote, SQLSmallTextType(),
1188  quote, sqlio::KT_Title, quote, SQLSmallTextType(),
1189  quote, sqlio::KT_Datetime, quote, SQLDatetimeType(),
1190  quote, sqlio::KT_Cycle, quote, SQLIntType(),
1191  quote, sqlio::KT_Class, quote, SQLSmallTextType());
1192 
1193  if ((fTablesType.Length()>0) && IsMySQL()) {
1194  sqlcmd +=" ENGINE=";
1195  sqlcmd += fTablesType;
1196  }
1197 
1198  SQLQuery(sqlcmd.Data());
1199 
1200  if (GetUseIndexes()>kIndexesNone) {
1201  sqlcmd.Form("CREATE UNIQUE INDEX %s%s%s ON %s%s%s (%s%s%s)",
1202  quote, sqlio::KeysTableIndex, quote,
1203  quote, sqlio::KeysTable, quote,
1204  quote, SQLKeyIdColumn(), quote);
1205  SQLQuery(sqlcmd.Data());
1206  }
1207 }
1208 
1209 ////////////////////////////////////////////////////////////////////////////////
1210 /// Update value of modify counter in config table
1211 /// Modify counter used to indicate that something was changed in database.
1212 /// It will be used when multiple instances of TSQLFile for the same data base
1213 /// will be connected.
1214 
1216 {
1217  if (!IsWritable()) {
1218  Error("IncrementModifyCounter","Cannot update tables without write accsess");
1219  return;
1220  }
1221 
1222  TString sqlcmd;
1223  const char* quote = SQLIdentifierQuote();
1224  const char* vquote = SQLValueQuote();
1225 
1226  sqlcmd.Form("UPDATE %s%s%s SET %s%s%s=%d WHERE %s%s%s=%s%s%s",
1227  quote, sqlio::ConfigTable, quote,
1228  quote, sqlio::CT_Value, quote, ++fModifyCounter,
1229  quote, sqlio::CT_Field, quote,
1230  vquote, sqlio::cfg_ModifyCounter, vquote);
1231  SQLQuery(sqlcmd.Data());
1232 }
1233 
1234 ////////////////////////////////////////////////////////////////////////////////
1235 /// Produce \b SELECT statement which can be used to get all data
1236 /// of class cl in one \b SELECT statement.
1237 ///
1238 /// This statement also can be used to create \b VIEW by command like
1239 /// mysql> CREATE VIEW TH1I_view AS $CLASSSELECT$
1240 /// Where \b $CLASSSELECT$ argument should be produced by call
1241 /// f->MakeSelectQuery(TH1I::Class());
1242 /// \b VIEWs supported by latest MySQL 5 and Oracle
1243 
1245 {
1246  TString res = "";
1247  TSQLClassInfo* sqlinfo = FindSQLClassInfo(cl);
1248  if (sqlinfo==0) return res;
1249 
1250  TString columns, tables;
1251  Int_t tablecnt = 0;
1252 
1253  if (!ProduceClassSelectQuery(cl->GetStreamerInfo(), sqlinfo, columns, tables, tablecnt))
1254  return res;
1255 
1256  res.Form("SELECT %s FROM %s", columns.Data(), tables.Data());
1257 
1258  return res;
1259 }
1260 
1261 ////////////////////////////////////////////////////////////////////////////////
1262 /// used by MakeClassSelectQuery method to add columns from table of
1263 /// class, specified by TVirtualStreamerInfo structure
1264 
1266  TSQLClassInfo* sqlinfo,
1267  TString& columns,
1268  TString& tables,
1269  Int_t& tablecnt)
1270 {
1271  if ((info==0) || (sqlinfo==0)) return kFALSE;
1272 
1273  if (!sqlinfo->IsClassTableExist()) return kFALSE;
1274 
1275  const char* quote = SQLIdentifierQuote();
1276 
1277  TString table_syn;
1278  table_syn.Form("t%d", ++tablecnt);
1279 
1280  Bool_t start = tables.Length()==0;
1281 
1282  TString buf;
1283 
1284  if (start)
1285  buf.Form("%s AS %s", sqlinfo->GetClassTableName(), table_syn.Data());
1286  else
1287  buf.Form(" LEFT JOIN %s AS %s USING(%s%s%s)",
1288  sqlinfo->GetClassTableName(), table_syn.Data(),
1289  quote, SQLObjectIdColumn(), quote);
1290 
1291  tables += buf;
1292 
1293  if (start)
1294  columns.Form("%s.%s%s%s",table_syn.Data(), quote, SQLObjectIdColumn(), quote);
1295 
1296  if (info->GetClass()==TObject::Class()) {
1297  buf.Form(", %s.%s",table_syn.Data(), sqlio::TObjectUniqueId);
1298  columns+=buf;
1299  buf.Form(", %s.%s",table_syn.Data(), sqlio::TObjectBits);
1300  columns+=buf;
1301  buf.Form(", %s.%s",table_syn.Data(), sqlio::TObjectProcessId);
1302  columns+=buf;
1303  return kTRUE;
1304  }
1305 
1306  TIter iter(info->GetElements());
1307  TStreamerElement* elem = 0;
1308 
1309  while ((elem = (TStreamerElement*) iter()) != 0) {
1310  Int_t coltype = TSQLStructure::DefineElementColumnType(elem, this);
1311  TString colname = TSQLStructure::DefineElementColumnName(elem, this);
1312 
1313  buf = "";
1314  switch (coltype) {
1315 
1320  buf.Form(", %s.%s%s%s",table_syn.Data(), quote, colname.Data(), quote);
1321  columns+=buf;
1322  break;
1323  }
1324 
1326  TClass* parentcl = elem->GetClassPointer();
1328  FindSQLClassInfo(parentcl),
1329  columns, tables, tablecnt);
1330  break;
1331  }
1332 
1334  for(Int_t n=0;n<elem->GetArrayLength();n++) {
1335  colname = TSQLStructure::DefineElementColumnName(elem, this, n);
1336  buf.Form(", %s.%s%s%s",table_syn.Data(), quote, colname.Data(), quote);
1337  columns+=buf;
1338  }
1339  break;
1340  }
1341  } // switch
1342  }
1343 
1344  return (columns.Length()>0) && (tables.Length()>0);
1345 }
1346 
1347 ////////////////////////////////////////////////////////////////////////////////
1348 /// Checks if main keys table is existing
1349 
1351 {
1353 }
1354 
1355 ////////////////////////////////////////////////////////////////////////////////
1356 /// Checkis, if lock is free in configuration tables
1357 
1359 {
1360  return GetLocking()==kLockFree;
1361 }
1362 
1363 ////////////////////////////////////////////////////////////////////////////////
1364 /// Set locking mode for current database
1365 
1367 {
1368  TString sqlcmd;
1369  const char* quote = SQLIdentifierQuote();
1370  const char* vquote = SQLValueQuote();
1371 
1372  sqlcmd.Form("UPDATE %s%s%s SET %s%s%s=%d WHERE %s%s%s=%s%s%s",
1373  quote, sqlio::ConfigTable, quote,
1374  quote, sqlio::CT_Value, quote, mode,
1375  quote, sqlio::CT_Field, quote,
1376  vquote, sqlio::cfg_LockingMode, vquote);
1377  SQLQuery(sqlcmd.Data());
1378 }
1379 
1380 ////////////////////////////////////////////////////////////////////////////////
1381 /// Return current locking mode for that file
1382 
1384 {
1385  const char* quote = SQLIdentifierQuote();
1386  const char* vquote = SQLValueQuote();
1387 
1388  TString sqlcmd;
1389  sqlcmd.Form("SELECT %s%s%s FROM %s%s%s WHERE %s%s%s=%s%s%s",
1390  quote, sqlio::CT_Value, quote,
1391  quote, sqlio::ConfigTable, quote,
1392  quote, sqlio::CT_Field, quote,
1393  vquote, sqlio::cfg_LockingMode, vquote);
1394 
1395  TSQLResult* res = SQLQuery(sqlcmd.Data(), 1);
1396  TSQLRow* row = (res==0) ? 0 : res->Next();
1397  TString field = (row==0) ? "" : row->GetField(0);
1398  delete row;
1399  delete res;
1400 
1401  if (field.Length()==0) return kLockFree;
1402 
1403  return field.Atoi();
1404 }
1405 
1406 ////////////////////////////////////////////////////////////////////////////////
1407 /// dummy, in future should check about read access to database
1408 
1410 {
1411  return kTRUE;
1412 }
1413 
1414 ////////////////////////////////////////////////////////////////////////////////
1415 /// Submits query to SQL server.
1416 ///
1417 /// | Flag Value | Effect|
1418 /// |------------|-------|
1419 /// | 0 | result is not interesting and will be deleted|
1420 /// | 1 | return result of submitted query
1421 /// | 2 | results is may be necessary for long time Oracle plugin do not support working with several TSQLResult objects, therefore explicit deep copy will be produced|
1422 ///
1423 /// If ok!=0, it will contains kTRUE is Query was successfull, otherwise kFALSE
1424 
1425 TSQLResult* TSQLFile::SQLQuery(const char* cmd, Int_t flag, Bool_t* ok)
1426 {
1427  if (fLogFile!=0)
1428  *fLogFile << cmd << std::endl;
1429 
1430  if (ok!=0) *ok = kFALSE;
1431 
1432  if (fSQL==0) return 0;
1433 
1434  if (gDebug>2) Info("SQLQuery", "%s", cmd);
1435 
1436  fQuerisCounter++;
1437 
1438  if (flag==0) {
1439  Bool_t res = fSQL->Exec(cmd);
1440  if (ok!=0) *ok = res;
1441  return 0;
1442  }
1443 
1444  TSQLResult* res = fSQL->Query(cmd);
1445  if (ok!=0) *ok = res!=0;
1446  if (res==0) return 0;
1447 // if ((flag==2) && IsOracle())
1448 // res = new TSQLResultCopy(res);
1449  return res;
1450 }
1451 
1452 ////////////////////////////////////////////////////////////////////////////////
1453 /// Test if DB support statement and number of open statements is not exceeded
1454 
1456 {
1457  if (fSQL==0) return kFALSE;
1458 
1459  if (!fSQL->HasStatement()) return kFALSE;
1460 
1461  return kTRUE; // !IsOracle() || (fStmtCounter<15);
1462 }
1463 
1464 ////////////////////////////////////////////////////////////////////////////////
1465 /// Produces SQL statement for currently conected DB server
1466 
1467 TSQLStatement* TSQLFile::SQLStatement(const char* cmd, Int_t bufsize)
1468 {
1469  if (fSQL==0) return 0;
1470 
1471  if (!fSQL->HasStatement()) return 0;
1472 
1473  if (gDebug>1)
1474  Info("SQLStatement", "%s", cmd);
1475 
1476  fStmtCounter++;
1477  fQuerisCounter++; // one statement counts as one query
1478 
1479  return fSQL->Statement(cmd, bufsize);
1480 }
1481 
1482 ////////////////////////////////////////////////////////////////////////////////
1483 /// delete statement and decrease counter
1484 
1486 {
1487  if (stmt==0) return;
1488 
1489  fStmtCounter--;
1490 
1491  delete stmt;
1492 }
1493 
1494 ////////////////////////////////////////////////////////////////////////////////
1495 /// supplies set of commands to server
1496 /// Commands is stored as array of TObjString
1497 
1499 {
1500  if ((cmds==0) || (fSQL==0)) return kFALSE;
1501 
1502  Bool_t ok = kTRUE;
1503  TIter iter(cmds);
1504  TObject* cmd= 0;
1505  while ((cmd=iter())!=0) {
1506  SQLQuery(cmd->GetName(),0,&ok);
1507  if(!ok) break;
1508  }
1509 
1510  return ok;
1511 }
1512 
1513 ////////////////////////////////////////////////////////////////////////////////
1514 /// Test, if table of specified name exists
1515 
1516 Bool_t TSQLFile::SQLTestTable(const char* tablename)
1517 {
1518  if (fSQL==0) return kFALSE;
1519 
1520  if (fSQL->HasTable(tablename)) return kTRUE;
1521 
1522  TString buf(tablename);
1523  buf.ToLower();
1524  if (fSQL->HasTable(buf.Data())) return kTRUE;
1525  buf.ToUpper();
1526  return fSQL->HasTable(buf.Data());
1527 }
1528 
1529 ////////////////////////////////////////////////////////////////////////////////
1530 /// Returns maximum value, found in specified columnname of table tablename
1531 /// Column type should be numeric
1532 
1533 Long64_t TSQLFile::SQLMaximumValue(const char* tablename, const char* columnname)
1534 {
1535  if (fSQL==0) return -1;
1536 
1537  if (gDebug>2)
1538  Info("SQLMaximumValue","Requests for %s column %s", tablename, columnname);
1539 
1540  const char* quote = SQLIdentifierQuote();
1541 
1542  TString query;
1543  query.Form("SELECT MAX(%s%s%s) FROM %s%s%s",
1544  quote, columnname, quote,
1545  quote, tablename, quote);
1546  TSQLResult* res = SQLQuery(query.Data(), 1);
1547 
1548  if (res==0) return -1;
1549 
1550  TSQLRow* row = res->Next();
1551 
1552  Long64_t maxid = -1;
1553  if (row!=0)
1554  if (row->GetField(0)!=0)
1555  maxid = sqlio::atol64(row->GetField(0));
1556 
1557  delete row;
1558  delete res;
1559 
1560  if (gDebug>2)
1561  Info("SQLMaximumValue","Result = %lld",maxid);;
1562 
1563  return maxid;
1564 }
1565 
1566 ////////////////////////////////////////////////////////////////////////////////
1567 /// Delete all tables in database
1568 
1570 {
1571  if (fSQL==0) return;
1572 
1573  TList* tables = fSQL->GetTablesList();
1574  if (tables==0) return;
1575 
1576  TString sqlcmd;
1577  const char* quote = SQLIdentifierQuote();
1578 
1579  TIter iter(tables);
1580  TObject* obj = 0;
1581  while ((obj=iter())!=0) {
1582  sqlcmd.Form("DROP TABLE %s%s%s", quote, obj->GetName(), quote);
1583  SQLQuery(sqlcmd.Data());
1584  }
1585  delete tables;
1586 }
1587 
1588 ////////////////////////////////////////////////////////////////////////////////
1589 /// Start SQL transaction.
1590 
1592 {
1593  return fSQL ? fSQL->StartTransaction() : kFALSE;
1594 }
1595 
1596 ////////////////////////////////////////////////////////////////////////////////
1597 /// Commit SQL transaction
1598 
1600 {
1601  return fSQL ? fSQL->Commit() : kFALSE;
1602 }
1603 
1604 ////////////////////////////////////////////////////////////////////////////////
1605 /// Rollback all SQL operations, done after start transaction
1606 
1608 {
1609  return fSQL ? fSQL->Rollback() : kFALSE;
1610 }
1611 
1612 ////////////////////////////////////////////////////////////////////////////////
1613 /// returns maximum allowed length of identifiers
1614 
1616 {
1617  Int_t maxlen = fSQL==0 ? 32 : fSQL->GetMaxIdentifierLength();
1618 
1619  // lets exclude absolute ubnormal data
1620  if (maxlen<10) maxlen = 10;
1621 
1622  return maxlen;
1623 }
1624 
1625 ////////////////////////////////////////////////////////////////////////////////
1626 /// Remove key with specified id from keys table
1627 /// also removes all objects data, related to this table
1628 
1630 {
1631  if (!IsWritable() || (keyid<0) || (fSQL==0)) return;
1632 
1633  TString sqlcmd;
1634  const char* quote = SQLIdentifierQuote();
1635 
1636  sqlcmd.Form("SELECT MIN(%s%s%s), MAX(%s%s%s) FROM %s%s%s WHERE %s%s%s=%lld",
1637  quote, SQLObjectIdColumn(), quote,
1638  quote, SQLObjectIdColumn(), quote,
1639  quote, sqlio::ObjectsTable, quote,
1640  quote, SQLKeyIdColumn(), quote, keyid);
1641  TSQLResult* res = SQLQuery(sqlcmd.Data(), 2);
1642  TSQLRow* row = res==0 ? 0 : res->Next();
1643  Long64_t minid(1), maxid(0);
1644 
1645  if ((row!=0) && (row->GetField(0)!=0) && (row->GetField(1)!=0)) {
1646  minid = sqlio::atol64(row->GetField(0));
1647  maxid = sqlio::atol64(row->GetField(1));
1648  }
1649 
1650  delete row;
1651  delete res;
1652 
1653  // can be that object tables does not include any entry this that keyid
1654  if (minid<=maxid) {
1656  TSQLClassInfo* info = 0;
1657  TString querymask, query;
1658  querymask.Form("DELETE FROM %s%s%s WHERE %s%s%s BETWEEN %lld AND %lld",
1659  quote, "%s", quote,
1660  quote, SQLObjectIdColumn(), quote,
1661  minid, maxid);
1662 
1663  while ((info = (TSQLClassInfo*) iter()) !=0 ) {
1664 
1665  if (info->IsClassTableExist()) {
1666  query.Form(querymask.Data(), info->GetClassTableName());
1667  SQLQuery(query.Data());
1668  }
1669 
1670  if (info->IsRawTableExist()) {
1671  query.Form(querymask.Data(), info->GetRawTableName());
1672  SQLQuery(query.Data());
1673  }
1674  }
1675  }
1676 
1677  sqlcmd.Form("DELETE FROM %s%s%s WHERE %s%s%s=%lld", quote, sqlio::ObjectsTable, quote, quote, SQLKeyIdColumn(), quote, keyid);
1678  SQLQuery(sqlcmd.Data());
1679 
1680  sqlcmd.Form("DELETE FROM %s%s%s WHERE %s%s%s=%lld", quote, sqlio::KeysTable, quote, quote, SQLKeyIdColumn(), quote, keyid);
1681  SQLQuery(sqlcmd.Data());
1682 
1684 }
1685 
1686 ////////////////////////////////////////////////////////////////////////////////
1687 /// Search for TKeySQL object with specified keyid
1688 
1690 {
1691  if (dir==0) return 0;
1692 
1693  TIter next(dir->GetListOfKeys());
1694  TObject* obj = 0;
1695 
1696  while ((obj = next())!=0) {
1697  TKeySQL* key = dynamic_cast<TKeySQL*> (obj);
1698  if (key!=0)
1699  if (key->GetDBKeyId()==keyid) return key;
1700  }
1701 
1702  return 0;
1703 }
1704 
1705 ////////////////////////////////////////////////////////////////////////////////
1706 /// Add entry into keys table
1707 
1709 {
1710  if ((fSQL==0) || (key==0)) return kFALSE;
1711 
1713 
1714  TString sqlcmd;
1715  const char* valuequote = SQLValueQuote();
1716  const char* quote = SQLIdentifierQuote();
1717 
1718  sqlcmd.Form("INSERT INTO %s%s%s VALUES (%lld, %lld, %lld, %s%s%s, %s%s%s, %s%s%s, %d, %s%s%s)",
1719  quote, sqlio::KeysTable, quote,
1720  key->GetDBKeyId(), key->GetDBDirId(), key->GetDBObjId(),
1721  valuequote, key->GetName(), valuequote,
1722  valuequote, key->GetTitle(), valuequote,
1723  valuequote, key->GetDatime().AsSQLString(), valuequote,
1724  key->GetCycle(),
1725  valuequote, key->GetClassName(), valuequote);
1726 
1727  Bool_t ok = kTRUE;
1728 
1729  SQLQuery(sqlcmd.Data(), 0, &ok);
1730 
1731  if (ok) IncrementModifyCounter();
1732 
1733  return ok;
1734 }
1735 
1736 ////////////////////////////////////////////////////////////////////////////////
1737 /// Updates (overwrites) key data in KeysTable
1738 
1740 {
1741  if ((fSQL==0) || (key==0)) return kFALSE;
1742 
1743  TString sqlcmd;
1744  const char* valuequote = SQLValueQuote();
1745  const char* quote = SQLIdentifierQuote();
1746 
1747  TString keyname = key->GetName();
1748  TString keytitle = key->GetTitle();
1749  TString keydatime = key->GetDatime().AsSQLString();
1750 
1751  TSQLStructure::AddStrBrackets(keyname, valuequote);
1752  TSQLStructure::AddStrBrackets(keytitle, valuequote);
1753  TSQLStructure::AddStrBrackets(keydatime, valuequote);
1754 
1755  sqlcmd.Form("UPDATE %s%s%s SET %s%s%s=%s, %s%s%s=%s, %s%s%s=%s, %s%s%s=%d WHERE %s%s%s=%lld",
1756  quote, sqlio::KeysTable, quote,
1757  quote, sqlio::KT_Name, quote, keyname.Data(),
1758  quote, sqlio::KT_Title, quote, keytitle.Data(),
1759  quote, sqlio::KT_Datetime, quote, keydatime.Data(),
1760  quote, sqlio::KT_Cycle, quote, key->GetCycle(),
1761  quote, SQLKeyIdColumn(), quote, key->GetDBKeyId());
1762 
1763  Bool_t ok = kTRUE;
1764 
1765  SQLQuery(sqlcmd.Data(), 0, &ok);
1766 
1767  if (ok) IncrementModifyCounter();
1768 
1769  return ok;
1770 }
1771 
1772 ////////////////////////////////////////////////////////////////////////////////
1773 /// Returns next possible key identifier
1774 
1776 {
1777  Long64_t max = -1;
1778 
1781 
1782  if (max<0) return sqlio::Ids_FirstKey;
1783 
1784  return max+1;
1785 }
1786 
1787 ////////////////////////////////////////////////////////////////////////////////
1788 /// Return (if exists) TSQLClassInfo for specified class name and version
1789 
1790 TSQLClassInfo* TSQLFile::FindSQLClassInfo(const char* clname, Int_t version)
1791 {
1792  if (fSQLClassInfos==0) return 0;
1793 
1795  TSQLClassInfo* info = 0;
1796 
1797  while ((info = (TSQLClassInfo*) iter()) !=0 ) {
1798  if (strcmp(info->GetName(), clname)==0)
1799  if (info->GetClassVersion()==version) return info;
1800  }
1801  return 0;
1802 }
1803 
1804 ////////////////////////////////////////////////////////////////////////////////
1805 /// return (if exists) TSQLClassInfo for specified class
1806 
1808 {
1809  return FindSQLClassInfo(cl->GetName(), cl->GetClassVersion());
1810 }
1811 
1812 ////////////////////////////////////////////////////////////////////////////////
1813 /// Search in database tables for specified class and return TSQLClassInfo object
1814 
1816 {
1817  TSQLClassInfo* info = FindSQLClassInfo(clname, version);
1818  if (info!=0) return info;
1819 
1820  if (fSQL==0) return 0;
1821 
1822  Long64_t maxid = 0;
1823 
1824  if (fSQLClassInfos!=0) {
1826  info = 0;
1827  while ((info = (TSQLClassInfo*) iter()) !=0 ) {
1828  if (info->GetClassId()>maxid)
1829  maxid = info->GetClassId();
1830  }
1831  }
1832 
1833  info = new TSQLClassInfo(maxid+1, clname, version);
1834 
1835  info->SetClassTableName(DefineTableName(clname, version, kFALSE));
1836  info->SetRawTableName(DefineTableName(clname, version, kTRUE));
1837 
1838  if (fSQLClassInfos==0) fSQLClassInfos = new TList;
1839  fSQLClassInfos->Add(info);
1840 
1841  return info;
1842 }
1843 
1844 ////////////////////////////////////////////////////////////////////////////////
1845 /// Proposes table name for class
1846 
1847 TString TSQLFile::DefineTableName(const char* clname, Int_t version, Bool_t rawtable)
1848 {
1849  Int_t maxlen = SQLMaxIdentifierLength();
1850 
1851  TString res;
1852 
1853  const char *suffix = rawtable ? "_raw" : "_ver";
1854 
1855  res.Form("%s%s%d", clname, suffix, version);
1856 
1857  if ((res.Length() <= maxlen) && !HasTable(res.Data()))
1858  return res;
1859 
1860  TString scnt;
1861 
1862  Int_t len = strlen(clname);
1863  Int_t cnt = version;
1864  if (cnt>100) cnt = 0; // do not start with the biggest values
1865 
1866  do {
1867  scnt.Form("%d%s",cnt, suffix);
1868  Int_t numlen = scnt.Length();
1869  if (numlen>=maxlen-2) break;
1870 
1871  res = clname;
1872 
1873  if (len + numlen > maxlen)
1874  res.Resize(maxlen - numlen);
1875 
1876  res+=scnt;
1877 
1878  if (!HasTable(res.Data())) return res;
1879 
1880  cnt++;
1881 
1882  } while (cnt<10000);
1883 
1884  Error("DefineTableName","Cannot produce table name for class %s ver %d", clname, version);
1885  res.Form("%s%s%d", clname, suffix, version);
1886 
1887  return res;
1888 }
1889 
1890 ////////////////////////////////////////////////////////////////////////////////
1891 /// Test if table name exists
1892 
1894 {
1895  if (fSQLClassInfos==0) return kFALSE;
1896 
1898  TSQLClassInfo* info = 0;
1899  while ((info = (TSQLClassInfo*) iter()) !=0 ) {
1900  if (strcmp(info->GetClassTableName(), name)==0) return kTRUE;
1901  if (strcmp(info->GetRawTableName(), name)==0) return kTRUE;
1902  }
1903 
1904  return kFALSE;
1905 }
1906 
1907 ////////////////////////////////////////////////////////////////////////////////
1908 /// Search in database tables for specified class and return TSQLClassInfo object
1909 
1911 {
1912  return RequestSQLClassInfo(cl->GetName(), cl->GetClassVersion());
1913 }
1914 
1915 ////////////////////////////////////////////////////////////////////////////////
1916 /// Read all class infos from IdsTable
1917 
1919 {
1920  if (fSQL==0) return;
1921 
1923 
1924  if (!fIdsTableExists) return;
1925 
1926  TString sqlcmd;
1927  const char* quote = SQLIdentifierQuote();
1928 
1929  sqlcmd.Form("SELECT * FROM %s%s%s WHERE %s%s%s = %d ORDER BY %s%s%s",
1930  quote, sqlio::IdsTable, quote,
1931  quote, sqlio::IT_Type, quote, TSQLStructure::kIdTable,
1932  quote, sqlio::IT_TableID, quote);
1933 
1934  TSQLResult* res = SQLQuery(sqlcmd.Data(), 1);
1935 
1936  TSQLRow* row = 0;
1937 
1938  if (res!=0)
1939  while ((row = res->Next())!=0) {
1940  Long64_t tableid = sqlio::atol64(row->GetField(0));
1941  Int_t version = atoi(row->GetField(1));
1942 
1943  const char* classname = row->GetField(3);
1944  const char* classtable = row->GetField(4);
1945 
1946  TSQLClassInfo* info = new TSQLClassInfo(tableid, classname, version);
1947  info->SetClassTableName(classtable);
1948 
1949  if (fSQLClassInfos==0) fSQLClassInfos = new TList;
1950  fSQLClassInfos->Add(info);
1951 
1952  delete row;
1953  }
1954  delete res;
1955 
1956 
1958  TSQLClassInfo* info = 0;
1959 
1960  while ((info = (TSQLClassInfo*) next()) != 0) {
1961  sqlcmd.Form("SELECT * FROM %s%s%s WHERE %s%s%s = %lld ORDER BY %s%s%s",
1962  quote, sqlio::IdsTable, quote,
1963  quote, sqlio::IT_TableID, quote, info->GetClassId(),
1964  quote, sqlio::IT_SubID, quote);
1965  res = SQLQuery(sqlcmd.Data(), 1);
1966 
1967  TObjArray* cols = 0;
1968 
1969  if (res!=0)
1970  while ((row = res->Next())!=0) {
1971 
1972  Int_t typ = atoi(row->GetField(2));
1973 
1974  const char* fullname = row->GetField(3);
1975  const char* sqlname = row->GetField(4);
1976  const char* info2 = row->GetField(5);
1977 
1978  if (typ==TSQLStructure::kIdColumn) {
1979  if (cols==0) cols = new TObjArray;
1980  cols->Add(new TSQLClassColumnInfo(fullname, sqlname, info2));
1981  }
1982 
1983  delete row;
1984  }
1985 
1986  delete res;
1987 
1988  info->SetColumns(cols);
1989  }
1990 
1991  sqlcmd.Form("SELECT * FROM %s%s%s WHERE %s%s%s = %d ORDER BY %s%s%s",
1992  quote, sqlio::IdsTable, quote,
1994  quote, sqlio::IT_TableID, quote);
1995 
1996  res = SQLQuery(sqlcmd.Data(), 1);
1997 
1998  if (res!=0)
1999  while ((row = res->Next())!=0) {
2000  Long64_t tableid = sqlio::atol64(row->GetField(0));
2001  Int_t version = atoi(row->GetField(1));
2002 
2003  const char* classname = row->GetField(3);
2004  const char* rawtable = row->GetField(4);
2005 
2006  TSQLClassInfo* info2 = FindSQLClassInfo(classname, version);
2007 
2008  if (info2==0) {
2009  info2 = new TSQLClassInfo(tableid, classname, version);
2010 
2011  if (fSQLClassInfos==0) fSQLClassInfos = new TList;
2012  fSQLClassInfos->Add(info2);
2013  }
2014 
2015  info2->SetRawTableName(rawtable);
2016  info2->SetRawExist(kTRUE);
2017 
2018  delete row;
2019  }
2020 
2021  delete res;
2022 }
2023 
2024 
2025 ////////////////////////////////////////////////////////////////////////////////
2026 /// Add entry into IdsTable, where all tables names and columns names are listed
2027 
2029  const char* name, const char* sqlname, const char* info)
2030 {
2031  if ((fSQL==0) || !IsWritable()) return;
2032 
2033  TString sqlcmd;
2034  const char* valuequote = SQLValueQuote();
2035  const char* quote = SQLIdentifierQuote();
2036 
2037  if (!fIdsTableExists) {
2038 
2040  sqlcmd.Form("DROP TABLE %s%s%s", quote, sqlio::IdsTable, quote);
2041  SQLQuery(sqlcmd.Data());
2042  }
2043 
2044  sqlcmd.Form("CREATE TABLE %s%s%s (%s%s%s %s, %s%s%s %s, %s%s%s %s, %s%s%s %s, %s%s%s %s, %s%s%s %s)",
2045  quote, sqlio::IdsTable, quote,
2046  quote, sqlio::IT_TableID, quote, SQLIntType(),
2047  quote, sqlio::IT_SubID, quote, SQLIntType(),
2048  quote, sqlio::IT_Type, quote, SQLIntType(),
2049  quote, sqlio::IT_FullName, quote, SQLSmallTextType(),
2050  quote, sqlio::IT_SQLName, quote, SQLSmallTextType(),
2051  quote, sqlio::IT_Info, quote, SQLSmallTextType());
2052  if ((fTablesType.Length()>0) && IsMySQL()) {
2053  sqlcmd +=" ENGINE=";
2054  sqlcmd += fTablesType;
2055  }
2056  SQLQuery(sqlcmd.Data());
2057 
2059  }
2060 
2061  sqlcmd.Form("INSERT INTO %s%s%s VALUES (%lld, %d, %d, %s%s%s, %s%s%s, %s%s%s)",
2062  quote, sqlio::IdsTable, quote,
2063  tableid, subid, type,
2064  valuequote, name, valuequote,
2065  valuequote, sqlname, valuequote,
2066  valuequote, info, valuequote);
2067 
2068  SQLQuery(sqlcmd.Data());
2069 }
2070 
2071 ////////////////////////////////////////////////////////////////////////////////
2072 /// Create normal class table if required
2073 
2075 {
2076  if (sqlinfo==0) return kFALSE;
2077 
2078  // this is normal situation, when no extra column infos was created when not necessary
2079  if (colinfos==0) return sqlinfo->IsClassTableExist();
2080 
2081  if (sqlinfo->IsClassTableExist()) {
2082  if (colinfos!=0) {
2083  colinfos->Delete();
2084  delete colinfos;
2085  //Error("CreateClassTable","Why colinfos for table %s", sqlinfo->GetClassTableName());
2086  }
2087  return kTRUE;
2088  }
2089 
2090  if (gDebug>2)
2091  Info("CreateClassTable", "cl:%s", sqlinfo->GetName());
2092 
2093  const char* quote = SQLIdentifierQuote();
2094 
2095  AddIdEntry(sqlinfo->GetClassId(),
2096  sqlinfo->GetClassVersion(),
2098  sqlinfo->GetName(),
2099  sqlinfo->GetClassTableName(),
2100  "Main class table");
2101 
2102  TString sqlcmd;
2103  sqlcmd.Form("CREATE TABLE %s%s%s (",
2104  quote, sqlinfo->GetClassTableName(), quote);
2105 
2106  TIter iter(colinfos);
2107  TSQLClassColumnInfo* col;
2108  Bool_t first = kTRUE;
2109  Bool_t forcequote = IsOracle();
2110  Int_t colid = 0;
2111  while ((col=(TSQLClassColumnInfo*)iter())!=0) {
2112  if (!first) sqlcmd+=", "; else first = false;
2113 
2114  const char* colname = col->GetSQLName();
2115  if ((strpbrk(colname,"[:.]<>")!=0) || forcequote) {
2116  sqlcmd += quote;
2117  sqlcmd += colname;
2118  sqlcmd += quote;
2119  sqlcmd += " ";
2120  } else {
2121  sqlcmd += colname,
2122  sqlcmd += " ";
2123  }
2124 
2125  sqlcmd += col->GetSQLType();
2126 
2127  AddIdEntry(sqlinfo->GetClassId(),
2128  colid++,
2130  col->GetName(),
2131  col->GetSQLName(),
2132  col->GetSQLType());
2133  }
2134  sqlcmd += ")";
2135 
2136  if ((fTablesType.Length()>0) && IsMySQL()) {
2137  sqlcmd +=" ENGINE=";
2138  sqlcmd += fTablesType;
2139  }
2140 
2141  SQLQuery(sqlcmd.Data());
2142 
2143  sqlinfo->SetColumns(colinfos);
2144 
2145  if (GetUseIndexes()>kIndexesBasic) {
2146 
2147  TString indxname = sqlinfo->GetClassTableName();
2148  indxname.ReplaceAll("_ver","_i1x");
2149 
2150  sqlcmd.Form("CREATE UNIQUE INDEX %s%s_I1%s ON %s%s%s (%s%s%s)",
2151  quote, indxname.Data(), quote,
2152  quote, sqlinfo->GetClassTableName(), quote,
2153  quote, SQLObjectIdColumn(), quote);
2154  SQLQuery(sqlcmd.Data());
2155  }
2156 
2157  return kTRUE;
2158 }
2159 
2160 ////////////////////////////////////////////////////////////////////////////////
2161 /// Create the raw table
2162 
2164 {
2165  if (sqlinfo==0) return kFALSE;
2166 
2167  if (sqlinfo->IsRawTableExist()) return kTRUE;
2168 
2169  const char* quote = SQLIdentifierQuote();
2170 
2171  if (gDebug>2)
2172  Info("CreateRawTable", "%s", sqlinfo->GetName());
2173 
2174  TString sqlcmd;
2175 
2176  sqlcmd.Form("CREATE TABLE %s%s%s (%s%s%s %s, %s%s%s %s, %s %s, %s %s)",
2177  quote, sqlinfo->GetRawTableName(), quote,
2178  quote, SQLObjectIdColumn(), quote, SQLIntType(),
2179  quote, SQLRawIdColumn(), quote, SQLIntType(),
2182 
2183  if ((fTablesType.Length()>0) && IsMySQL()) {
2184  sqlcmd +=" ENGINE=";
2185  sqlcmd += fTablesType;
2186  }
2187 
2188  SQLQuery(sqlcmd.Data());
2189  sqlinfo->SetRawExist(kTRUE);
2190 
2191  if (GetUseIndexes()>kIndexesClass) {
2192  TString indxname = sqlinfo->GetClassTableName();
2193  indxname.ReplaceAll("_ver","_i2x");
2194 
2195  sqlcmd.Form("CREATE UNIQUE INDEX %s%s_I2%s ON %s%s%s (%s%s%s, %s%s%s)",
2196  quote, indxname.Data(), quote,
2197  quote, sqlinfo->GetRawTableName(), quote,
2198  quote, SQLObjectIdColumn(), quote,
2199  quote, SQLRawIdColumn(), quote);
2200  SQLQuery(sqlcmd.Data());
2201  }
2202 
2203  AddIdEntry(sqlinfo->GetClassId(),
2204  sqlinfo->GetClassVersion(),
2206  sqlinfo->GetName(),
2207  sqlinfo->GetRawTableName(),
2208  "Raw data class table");
2209 
2210  return kTRUE;
2211 }
2212 
2213 ////////////////////////////////////////////////////////////////////////////////
2214 /// Checks that table for big strings is exists
2215 /// If not, will be created
2216 
2218 {
2219  if (fSQL==0) return kFALSE;
2220 
2221  if (SQLTestTable(sqlio::StringsTable)) return kTRUE;
2222 
2223  const char* quote = SQLIdentifierQuote();
2224 
2225  TString sqlcmd;
2226  sqlcmd.Form("CREATE TABLE %s (%s%s%s %s, %s%s%s %s, %s %s)",
2228  quote, SQLObjectIdColumn(), quote, SQLIntType(),
2229  quote, SQLStrIdColumn(), quote, SQLIntType(),
2231 
2232  if (fTablesType.Length()>0) {
2233  sqlcmd +=" ENGINE=";
2234  sqlcmd += fTablesType;
2235  }
2236 
2237  SQLQuery(sqlcmd.Data());
2238 
2239  return kTRUE;
2240 }
2241 
2242 ////////////////////////////////////////////////////////////////////////////////
2243 /// Produces id which will be placed in column instead of string itself
2244 
2246 {
2247  TString res;
2248  res.Form("%s %lld %s %d %s", sqlio::LongStrPrefix, objid, sqlio::LongStrPrefix, strid, sqlio::LongStrPrefix);
2249  return res;
2250 }
2251 
2252 ////////////////////////////////////////////////////////////////////////////////
2253 /// Checks if this is long string code
2254 /// returns 0, if not or string id
2255 
2257 {
2258  if (value==0) return 0;
2259  if (strlen(value)<strlen(sqlio::LongStrPrefix)*3+6) return 0;
2260  if (strstr(value, sqlio::LongStrPrefix)!=value) return 0;
2261 
2262  value+=strlen(sqlio::LongStrPrefix);
2263  if (*value++!=' ') return 0;
2264  TString s_strid, s_objid;
2265  if ((*value<'1') || (*value>'9')) return 0;
2266  do {
2267  s_objid.Append(*value++);
2268  } while ((*value!=0) && (*value>='0') && (*value<='9'));
2269 
2270  if (*value++ != ' ') return 0;
2271  if ((*value==0) || (strstr(value, sqlio::LongStrPrefix)!=value)) return 0;
2272  value+=strlen(sqlio::LongStrPrefix);
2273  if (*value++!=' ') return 0;
2274 
2275  if ((*value<'1') || (*value>'9')) return 0;
2276  do {
2277  s_strid.Append(*value++);
2278  } while ((*value!=0) && (*value>='0') && (*value<='9'));
2279  if (*value++!=' ') return 0;
2280 
2281  if ((*value==0) || (strcmp(value, sqlio::LongStrPrefix)!=0)) return 0;
2282 
2283  Long64_t objid2 = sqlio::atol64(s_objid.Data());
2284  if (objid2!=objid) return 0;
2285 
2286  return atoi(s_strid.Data());
2287 }
2288 
2289 ////////////////////////////////////////////////////////////////////////////////
2290 /// Returns value of string, extracted from special table,
2291 /// where long strings are stored
2292 
2294 {
2295  if (!SQLTestTable(sqlio::StringsTable)) return kFALSE;
2296 
2297  TString cmd;
2298  const char* quote = SQLIdentifierQuote();
2299  cmd.Form("SELECT %s FROM %s%s%s WHERE %s%s%s=%lld AND %s%s%s=%d",
2301  quote, sqlio::StringsTable, quote,
2302  quote, SQLObjectIdColumn(), quote, objid,
2303  quote, SQLStrIdColumn(), quote, strid);
2304 
2305  TSQLResult* res = SQLQuery(cmd.Data(), 1);
2306  if (res==0) return kFALSE;
2307  TSQLRow* row = res->Next();
2308  if (row==0) { delete res; return kFALSE; }
2309  value = row->GetField(0);
2310 
2311  delete row;
2312  delete res;
2313 
2314  return kTRUE;
2315 }
2316 
2317 ////////////////////////////////////////////////////////////////////////////////
2318 /// Checks that objects table is exists
2319 /// If not, table will be created
2320 /// Returns maximum value for existing objects id
2321 
2323 {
2324  if (fSQL==0) return -1;
2325 
2326  Long64_t maxid = -1;
2327 
2328  if (gDebug>2)
2329  Info("VerifyObjectTable", "Checks if object table is there");
2330 
2333  else {
2334  TString sqlcmd;
2335  const char* quote = SQLIdentifierQuote();
2336  sqlcmd.Form("CREATE TABLE %s%s%s (%s%s%s %s, %s%s%s %s, %s%s%s %s, %s%s%s %s)",
2337  quote, sqlio::ObjectsTable, quote,
2338  quote, SQLKeyIdColumn(), quote, SQLIntType(),
2339  quote, SQLObjectIdColumn(), quote, SQLIntType(),
2340  quote, sqlio::OT_Class, quote, SQLSmallTextType(),
2341  quote, sqlio::OT_Version, quote, SQLIntType());
2342 
2343  if ((fTablesType.Length()>0) && IsMySQL()) {
2344  sqlcmd +=" ENGINE=";
2345  sqlcmd += fTablesType;
2346  }
2347 
2348  SQLQuery(sqlcmd.Data());
2349 
2350  if (GetUseIndexes()>kIndexesNone) {
2351  sqlcmd.Form("CREATE UNIQUE INDEX %s%s%s ON %s%s%s (%s%s%s)",
2352  quote, sqlio::ObjectsTableIndex, quote,
2353  quote, sqlio::ObjectsTable, quote,
2354  quote, SQLObjectIdColumn(), quote);
2355  SQLQuery(sqlcmd.Data());
2356  }
2357  }
2358 
2359  return maxid;
2360 }
2361 
2362 ////////////////////////////////////////////////////////////////////////////////
2363 /// Read from objects table data for specified objectid
2364 
2366 {
2367  if (fSQL==0) return kFALSE;
2368 
2369  TString sqlcmd;
2370  const char* quote = SQLIdentifierQuote();
2371  sqlcmd.Form("SELECT %s%s%s, %s%s%s FROM %s%s%s WHERE %s%s%s=%lld",
2372  quote, sqlio::OT_Class, quote,
2373  quote, sqlio::OT_Version, quote,
2374  quote, sqlio::ObjectsTable, quote,
2375  quote, SQLObjectIdColumn(), quote, objid);
2376  TSQLResult* res = SQLQuery(sqlcmd.Data(), 1);
2377  if (res==0) return kFALSE;
2378  TSQLRow* row = res->Next();
2379  if (row!=0) {
2380  clname = row->GetField(0);
2381  version = atoi(row->GetField(1));
2382  }
2383 
2384  delete row;
2385  delete res;
2386  return row!=0;
2387 }
2388 
2389 ////////////////////////////////////////////////////////////////////////////////
2390 /// Produce array of TSQLObjectInfo objects for all objects, belong to that key
2391 /// Array should be deleted by calling function afterwards
2392 
2394 {
2395  if (fSQL==0) return 0;
2396 
2397  TString sqlcmd;
2398  const char* quote = SQLIdentifierQuote();
2399  sqlcmd.Form("SELECT %s%s%s, %s%s%s, %s%s%s FROM %s%s%s WHERE %s%s%s=%lld ORDER BY %s%s%s",
2400  quote, SQLObjectIdColumn(), quote,
2401  quote, sqlio::OT_Class, quote,
2402  quote, sqlio::OT_Version, quote,
2403  quote, sqlio::ObjectsTable, quote,
2404  quote, SQLKeyIdColumn(), quote, keyid,
2405  quote, SQLObjectIdColumn(), quote);
2406 
2407  TObjArray* arr = 0;
2408 
2409  if (fLogFile!=0)
2410  *fLogFile << sqlcmd << std::endl;
2411  if (gDebug>2) Info("SQLObjectsInfo", "%s", sqlcmd.Data());
2412  fQuerisCounter++;
2413 
2414  TSQLStatement* stmt = SQLStatement(sqlcmd.Data(), 1000);
2415 
2416  if (stmt!=0) {
2417  stmt->Process();
2418  stmt->StoreResult();
2419 
2420  while (stmt->NextResultRow()) {
2421  Long64_t objid = stmt->GetLong64(0);
2422  const char* clname = stmt->GetString(1);
2423  Int_t version = stmt->GetInt(2);
2424 
2425  TSQLObjectInfo* info = new TSQLObjectInfo(objid, clname, version);
2426  if (arr==0) arr = new TObjArray();
2427  arr->Add(info);
2428  }
2429 
2430  delete stmt;
2431  return arr;
2432  }
2433 
2434  TSQLResult* res = SQLQuery(sqlcmd.Data(), 1);
2435  if (res==0) return 0;
2436 
2437  TSQLRow* row = 0;
2438  while ((row = res->Next()) != 0) {
2439  Long64_t objid = atoi(row->GetField(0));
2440  const char* clname = row->GetField(1);
2441  Int_t version = atoi(row->GetField(2));
2442 
2443  TSQLObjectInfo* info = new TSQLObjectInfo(objid, clname, version);
2444  if (arr==0) arr = new TObjArray();
2445  arr->Add(info);
2446 
2447  delete row;
2448  }
2449  delete res;
2450  return arr;
2451 }
2452 
2453 ////////////////////////////////////////////////////////////////////////////////
2454 /// Method return request result for specified objid from normal classtable
2455 
2457 {
2458  if (!sqlinfo->IsClassTableExist()) return 0;
2459  TString sqlcmd;
2460  const char* quote = SQLIdentifierQuote();
2461  sqlcmd.Form("SELECT * FROM %s%s%s WHERE %s%s%s=%lld",
2462  quote, sqlinfo->GetClassTableName(), quote,
2463  quote, SQLObjectIdColumn(), quote, objid);
2464  return SQLQuery(sqlcmd.Data(), 2);
2465 }
2466 
2467 ////////////////////////////////////////////////////////////////////////////////
2468 /// Return data for several objects from the range from normal class table
2469 
2471 {
2472  if (!sqlinfo->IsClassTableExist()) return 0;
2473  TString sqlcmd;
2474  const char* quote = SQLIdentifierQuote();
2475  sqlcmd.Form("SELECT * FROM %s%s%s WHERE %s%s%s BETWEEN %lld AND %lld ORDER BY %s%s%s",
2476  quote, sqlinfo->GetClassTableName(), quote,
2477  quote, SQLObjectIdColumn(), quote, minobjid, maxobjid,
2478  quote, SQLObjectIdColumn(), quote);
2479  return SQLQuery(sqlcmd.Data(), 2);
2480 }
2481 
2482 ////////////////////////////////////////////////////////////////////////////////
2483 /// Method return request results for specified objid from _streamer_ classtable
2484 
2486 {
2487  if (!sqlinfo->IsRawTableExist()) return 0;
2488  TString sqlcmd;
2489  const char* quote = SQLIdentifierQuote();
2490  sqlcmd.Form("SELECT %s, %s FROM %s%s%s WHERE %s%s%s=%lld ORDER BY %s%s%s",
2492  quote, sqlinfo->GetRawTableName(), quote,
2493  quote, SQLObjectIdColumn(), quote, objid,
2494  quote, SQLRawIdColumn(), quote);
2495  return SQLQuery(sqlcmd.Data(), 2);
2496 }
2497 
2498 ////////////////////////////////////////////////////////////////////////////////
2499 /// Method return request results for specified objid from _streamer_ classtable
2500 /// Data returned in form of statement, where direct access to values are possible
2501 
2503 {
2504  if (!sqlinfo->IsRawTableExist()) return 0;
2505 
2506  TString sqlcmd;
2507  const char* quote = SQLIdentifierQuote();
2508  sqlcmd.Form("SELECT %s, %s FROM %s%s%s WHERE %s%s%s=%lld ORDER BY %s%s%s",
2510  quote, sqlinfo->GetRawTableName(), quote,
2511  quote, SQLObjectIdColumn(), quote, objid,
2512  quote, SQLRawIdColumn(), quote);
2513 
2514  if (fLogFile!=0)
2515  *fLogFile << sqlcmd << std::endl;
2516  if (gDebug>2) Info("BuildStatement", "%s", sqlcmd.Data());
2517  fQuerisCounter++;
2518 
2519  TSQLStatement* stmt = SQLStatement(sqlcmd.Data(), 1000);
2520  if (stmt==0) return 0;
2521 
2522  stmt->Process();
2523 
2524  stmt->StoreResult();
2525 
2526  return stmt;
2527 }
2528 
2529 ////////////////////////////////////////////////////////////////////////////////
2530 /// Store object in database. Return stored object id or -1 if error
2531 
2533 {
2534  if (fSQL==0) return -1;
2535 
2536  Long64_t objid = VerifyObjectTable();
2537  if (objid<=0) objid = 1; else objid++;
2538 
2540 
2541  TSQLStructure* s = buffer.SqlWriteAny(obj, cl, objid);
2542 
2543  if ((buffer.GetErrorFlag()>0) && s) {
2544  Error("StoreObjectInTables","Cannot convert object data to TSQLStructure");
2545  objid = -1;
2546  } else {
2547  TObjArray cmds;
2548  // here tables may be already created, therefore
2549  // it should be protected by transactions operations
2550  if (s && !s->ConvertToTables(this, keyid, &cmds)) {
2551  Error("StoreObjectInTables","Cannot convert to SQL statements");
2552  objid = -1;
2553  } else {
2554  Bool_t needcommit = kFALSE;
2555 
2558  needcommit = kTRUE;
2559  }
2560 
2561  if (!SQLApplyCommands(&cmds)) {
2562  Error("StoreObject","Cannot correctly store object data in database");
2563  objid = -1;
2564  if (needcommit) SQLRollback();
2565  } else {
2566  if (needcommit) SQLCommit();
2567  }
2568  }
2569  cmds.Delete();
2570  }
2571 
2572  return objid;
2573 }
2574 
2575 ////////////////////////////////////////////////////////////////////////////////
2576 /// Returns sql type name which is most closer to ROOT basic type.
2577 /// typ should be from TVirtualStreamerInfo:: constansts like TVirtualStreamerInfo::kInt
2578 
2579 const char* TSQLFile::SQLCompatibleType(Int_t typ) const
2580 {
2581  return (typ<0) || (typ>18) ? 0 : fBasicTypes[typ];
2582 }
2583 
2584 ////////////////////////////////////////////////////////////////////////////////
2585 /// return SQL integer type
2586 
2587 const char* TSQLFile::SQLIntType() const
2588 {
2590 }
2591 
2592 ////////////////////////////////////////////////////////////////////////////////
2593 /// Create entry for directory in database
2594 
2596 {
2597  TDirectory* mother = dir->GetMotherDir();
2598  if (mother==0) mother = this;
2599 
2600  // key will be added to mother directory
2601  TKeySQL* key = new TKeySQL(mother, dir, dir->GetName(), dir->GetTitle());
2602 
2603  return key->GetDBKeyId();
2604 }
2605 
2606 ////////////////////////////////////////////////////////////////////////////////
2607 /// Read directory list of keys from database
2608 
2610 {
2611  // First delete all old keys
2612  dir->GetListOfKeys()->Delete();
2613 
2614  if (gDebug>2)
2615  Info("DirReadKeys","dir = %s id = %lld", dir->GetName(), dir->GetSeekDir());
2616 
2617  return StreamKeysForDirectory(dir, kFALSE);
2618 }
2619 
2620 ////////////////////////////////////////////////////////////////////////////////
2621 /// Write directory keys list to database
2622 
2624 {
2626 }
2627 
2628 ////////////////////////////////////////////////////////////////////////////////
2629 /// Update dir header in the file
2630 
2632 {
2634  if (sqlinfo==0) return;
2635 
2636  // try to identify key with data for our directory
2637  TKeySQL* key = FindSQLKey(dir->GetMotherDir(), dir->GetSeekDir());
2638  if (key==0) return;
2639 
2640  const char* valuequote = SQLValueQuote();
2641  const char* quote = SQLIdentifierQuote();
2642 
2643  TString timeC = fDatimeC.AsSQLString();
2644  TSQLStructure::AddStrBrackets(timeC, valuequote);
2645 
2646  TString timeM = fDatimeM.AsSQLString();
2647  TSQLStructure::AddStrBrackets(timeM, valuequote);
2648 
2649  TString uuid = dir->GetUUID().AsString();
2650  TSQLStructure::AddStrBrackets(uuid, valuequote);
2651 
2652  TString sqlcmd;
2653 
2654  TString col1name = "CreateTime";
2655  TString col2name = "ModifyTime";
2656  TString col3name = "UUID";
2657  if (GetUseSuffixes()) {
2658  col1name+=sqlio::StrSuffix;
2659  col2name+=sqlio::StrSuffix;
2660  col3name+=sqlio::StrSuffix;
2661  }
2662 
2663  sqlcmd.Form("UPDATE %s%s%s SET %s%s%s=%s, %s%s%s=%s, %s%s%s=%s WHERE %s%s%s=%lld",
2664  quote, sqlinfo->GetClassTableName(), quote,
2665  quote, col1name.Data(), quote, timeC.Data(),
2666  quote, col2name.Data(), quote, timeM.Data(),
2667  quote, col3name.Data(), quote, uuid.Data(),
2668  quote, SQLObjectIdColumn(), quote, key->GetDBObjId());
2669 
2670  SQLQuery(sqlcmd.Data());
2671 }
2672 
2673 ////////////////////////////////////////////////////////////////////////////////
2674 /// Streamer for TSQLFile class.
2675 /// Stores only data for TDirectory.
2676 
2677 void TSQLFile::Streamer(TBuffer &b)
2678 {
2679 
2680  TString sbuf;
2681 
2682  if (b.IsReading()) {
2683  Version_t R__v = b.ReadVersion(0, 0);
2684  b.ClassBegin(TSQLFile::Class(), R__v);
2685 
2686  b.ClassMember("CreateTime","TString");
2687  sbuf.Streamer(b);
2688  TDatime timeC(sbuf.Data());
2689  fDatimeC = timeC;
2690 
2691  b.ClassMember("ModifyTime","TString");
2692  sbuf.Streamer(b);
2693  TDatime timeM(sbuf.Data());
2694  fDatimeM = timeM;
2695 
2696  b.ClassMember("UUID","TString");
2697  sbuf.Streamer(b);
2698  TUUID id(sbuf.Data());
2699  fUUID = id;
2700 
2702  } else {
2703 
2705 
2707 
2708  b.ClassMember("CreateTime","TString");
2709  sbuf = fDatimeC.AsSQLString();
2710  sbuf.Streamer(b);
2711 
2712  b.ClassMember("ModifyTime","TString");
2713  fDatimeM.Set();
2714  sbuf = fDatimeM.AsSQLString();
2715  sbuf.Streamer(b);
2716 
2717  b.ClassMember("UUID","TString");
2718  sbuf = fUUID.AsString();
2719  sbuf.Streamer(b);
2720 
2722  }
2723 }
virtual Bool_t Exec(const char *sql)
Execute sql query.
Definition: TSQLServer.cxx:85
tuple row
Definition: mrt.py:26
virtual Bool_t cd(const char *path=0)
Change current directory to "this" directory.
Int_t GetErrorFlag() const
Definition: TBufferSQL2.h:127
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:52
TSQLResult * GetBlobClassData(Long64_t objid, TSQLClassInfo *sqlinfo)
Method return request results for specified objid from streamer classtable.
Definition: TSQLFile.cxx:2485
void * SqlReadAny(Long64_t keyid, Long64_t objid, TClass **cl, void *obj=0)
Recreate object from sql structure.
const char * ConfigTable
void SetClassTableName(const char *name)
Definition: TSQLClassInfo.h:62
double read(const std::string &file_name)
reading
static Int_t DefineElementColumnType(TStreamerElement *elem, TSQLFile *f)
defines which kind of column can be assigned for this element Possible cases kColSimple - basic data ...
const char ** fOtherTypes
! pointer on list of other SQL types like TEXT or blob
Definition: TSQLFile.h:164
void StartLogFile(const char *fname)
start logging of all SQL statements in specified file
Definition: TSQLFile.cxx:477
int GetClassVersion(const clang::RecordDecl *cl, const cling::Interpreter &interp)
Return the version number of the class or -1 if the function Class_Version does not exist...
An array of TObjects.
Definition: TObjArray.h:39
Char_t fUnits
Number of bytes for file pointers.
Definition: TFile.h:79
Bool_t fCanChangeConfig
! variable indicates can be basic configuration changed or not
Definition: TSQLFile.h:156
Bool_t SQLApplyCommands(TObjArray *cmds)
supplies set of commands to server Commands is stored as array of TObjString
Definition: TSQLFile.cxx:1498
virtual void ClassBegin(const TClass *, Version_t=-1)=0
TString CodeLongString(Long64_t objid, Int_t strid)
Produces id which will be placed in column instead of string itself.
Definition: TSQLFile.cxx:2245
Long64_t SQLMaximumValue(const char *tablename, const char *columnname)
Returns maximum value, found in specified columnname of table tablename Column type should be numeric...
Definition: TSQLFile.cxx:1533
Int_t StreamKeysForDirectory(TDirectory *dir, Bool_t doupdate, Long64_t specialkeyid=-1, TKeySQL **specialkey=0)
read keys for specified directory (when update == kFALSE) or update value for modified keys when upda...
Definition: TSQLFile.cxx:937
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:405
void InitSqlDatabase(Bool_t create)
initialize sql database and correspondent structures identical to TFile::Init() function ...
Definition: TSQLFile.cxx:1016
TObjArray * fProcessIDs
!Array of pointers to TProcessIDs
Definition: TFile.h:82
tuple buffer
Definition: tree.py:99
Info (classname, version) about object in database.
void StopLogFile()
close logging file
Definition: TSQLFile.cxx:486
long long Long64_t
Definition: RtypesCore.h:69
virtual Long64_t GetLong64(Int_t)
Definition: TSQLStatement.h:88
Bool_t SQLCommit()
Commit SQL transaction.
Definition: TSQLFile.cxx:1599
Long64_t fBytesWrite
Number of bytes written to this file.
Definition: TFile.h:62
const char * dbname
Definition: sqlcanvas.C:7
Bool_t IsReading() const
Definition: TBuffer.h:83
Long64_t GetDBDirId() const
return sql id of parent directory
Definition: TKeySQL.cxx:155
const char * GetRawTableName() const
Definition: TSQLClassInfo.h:66
virtual TList * GetListOfKeys() const
Definition: TDirectory.h:158
TSQLResult * GetNormalClassDataAll(Long64_t minobjid, Long64_t maxobjid, TSQLClassInfo *sqlinfo)
Return data for several objects from the range from normal class table.
Definition: TSQLFile.cxx:2470
short Version_t
Definition: RtypesCore.h:61
Double_t fSumBuffer
Sum of buffer sizes of objects written so far.
Definition: TFile.h:60
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
void SetRawTableName(const char *name)
Definition: TSQLClassInfo.h:63
Ssiz_t Length() const
Definition: TString.h:390
std::ofstream * fLogFile
! log file with SQL statements
Definition: TSQLFile.h:168
virtual TClass * GetClass() const =0
Bool_t GetUseSuffixes() const
Definition: TSQLFile.h:197
TSQLResult * GetNormalClassData(Long64_t objid, TSQLClassInfo *sqlinfo)
Method return request result for specified objid from normal classtable.
Definition: TSQLFile.cxx:2456
TArrayC * fClassIndex
!Index of TStreamerInfo classes written to this file
Definition: TFile.h:81
Int_t GetUseIndexes() const
Definition: TSQLFile.h:207
const char Option_t
Definition: RtypesCore.h:62
virtual TSQLResult * Query(const char *sql)=0
static TSQLServer * Connect(const char *db, const char *uid, const char *pw)
virtual void Delete(Option_t *option="")
Remove all objects from the array AND delete all heap based objects.
Definition: TObjArray.cxx:329
Bool_t Rollback()
Rollback all operations, done after StartTransaction() call.
Definition: TSQLFile.cxx:619
virtual Int_t ReOpen(Option_t *mode)
Reopen a file with a different access mode, like from READ to See TFile::Open() for details...
Definition: TSQLFile.cxx:747
TSQLServer * fSQL
! interface to SQL database
Definition: TSQLFile.h:149
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:635
TString fTablesType
! type, used in CREATE TABLE statements
Definition: TSQLFile.h:157
TSQLFile()
default TSQLFile constructor
Definition: TSQLFile.cxx:278
const char * cfg_UseTransactions
virtual void DirWriteHeader(TDirectory *)
Update dir header in the file.
Definition: TSQLFile.cxx:2631
Int_t fUseTransactions
! use transaction statements for writing data into the tables
Definition: TSQLFile.h:158
Bool_t IsClassTableExist() const
Definition: TSQLClassInfo.h:72
Long64_t GetDBObjId() const
Definition: TKeySQL.h:49
const char * SQLDirIdColumn() const
Definition: TSQLFile.h:140
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:892
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
Short_t GetCycle() const
Return cycle number associated to this key.
Definition: TKey.cxx:561
Bool_t SQLStartTransaction()
Start SQL transaction.
Definition: TSQLFile.cxx:1591
const char * CT_Value
void ToUpper()
Change string to upper case.
Definition: TString.cxx:1088
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
Bool_t IsODBC() const
checks, if ODBC driver used for database connection
Definition: TSQLFile.cxx:515
void SQLDeleteStatement(TSQLStatement *stmt)
delete statement and decrease counter
Definition: TSQLFile.cxx:1485
#define ReadBoolCfg(name, target)
Int_t IsLongStringCode(Long64_t objid, const char *value)
Checks if this is long string code returns 0, if not or string id.
Definition: TSQLFile.cxx:2256
virtual Bool_t StartTransaction()
submit "START TRANSACTION" query to database return kTRUE, if successful
Definition: TSQLServer.cxx:141
#define gROOT
Definition: TROOT.h:344
virtual Bool_t IsOpen() const
return kTRUE if file is opened and can be accessed
Definition: TSQLFile.cxx:738
Contains information about tables specific to one class and version.
Definition: TSQLClassInfo.h:48
const char * IT_SQLName
Basic string class.
Definition: TString.h:137
const char * cfg_LockingMode
virtual Bool_t StoreResult()=0
virtual const char * GetClassName() const
Definition: TKey.h:77
Bool_t UpdateKeyData(TKeySQL *key)
Updates (overwrites) key data in KeysTable.
Definition: TSQLFile.cxx:1739
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1075
int Int_t
Definition: RtypesCore.h:41
Long64_t StoreObjectInTables(Long64_t keyid, const void *obj, const TClass *cl)
Store object in database. Return stored object id or -1 if error.
Definition: TSQLFile.cxx:2532
bool Bool_t
Definition: RtypesCore.h:59
R__EXTERN TVirtualMutex * gROOTMutex
Definition: TROOT.h:63
const Bool_t kFALSE
Definition: Rtypes.h:92
const char * IdsTable
const char * SQLIdentifierQuote() const
Definition: TSQLFile.h:139
virtual TSQLStatement * Statement(const char *, Int_t=100)
Definition: TSQLServer.h:83
TSQLClassInfo * RequestSQLClassInfo(const char *clname, Int_t version)
Search in database tables for specified class and return TSQLClassInfo object.
Definition: TSQLFile.cxx:1815
virtual UInt_t WriteVersion(const TClass *cl, Bool_t useBcnt=kFALSE)=0
Int_t fStmtCounter
! count numbers of active statements
Definition: TSQLFile.h:171
const char * SQLObjectIdColumn() const
Definition: TSQLFile.h:142
void CreateBasicTables()
Creates initial tables in database This is table with configurations and table with keys Function cal...
Definition: TSQLFile.cxx:1133
Long64_t fSeekInfo
Location on disk of StreamerInfo record.
Definition: TFile.h:68
Bool_t ReadConfigurations()
read table configurations as special table
Definition: TSQLFile.cxx:1070
const char * IT_Type
const char * cfg_UseIndexes
Bool_t IsMySQL() const
checks, if MySQL database
Definition: TSQLFile.cxx:497
virtual const char * GetString(Int_t)
Definition: TSQLStatement.h:91
void Reset(Char_t val=0)
Definition: TArrayC.h:49
Int_t GetUseTransactions() const
Definition: TSQLFile.h:205
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:732
Bool_t HasTable(const char *name)
Test if table name exists.
Definition: TSQLFile.cxx:1893
This class defines a UUID (Universally Unique IDentifier), also known as GUIDs (Globally Unique IDent...
Definition: TUUID.h:44
Int_t fQuerisCounter
! how many query was applied
Definition: TSQLFile.h:161
const char * GetDataBaseName() const
Return name of data base on the host For Oracle always return 0.
Definition: TSQLFile.cxx:653
const char * Data() const
Definition: TString.h:349
const char * StringsTable
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition: TObject.cxx:946
Long64_t atol64(const char *value)
Int_t fSQLIOversion
! version of SQL I/O which is stored in configurations
Definition: TSQLFile.h:154
Int_t fNbytesInfo
Number of bytes for StreamerInfo record.
Definition: TFile.h:73
virtual void ClassMember(const char *, const char *=0, Int_t=-1, Int_t=-1)=0
const char * StrSuffix
Bool_t StartTransaction()
Start user transaction.
Definition: TSQLFile.cxx:591
virtual const char * GetName() const
Returns name of object.
Definition: TSQLClassInfo.h:59
const char * oracle_OtherTypes[13]
Definition: TSQLFile.cxx:258
Bool_t IsKeyModified(const char *keyname, const char *keytitle, const char *keydatime, Int_t cycle, const char *classname)
Compares keydata with provided and return kTRUE if key was modified Used in TFile::StreamKeysForDirec...
Definition: TKeySQL.cxx:110
const char * IT_FullName
const char ** fBasicTypes
! pointer on list of basic types specific for currently connected SQL server
Definition: TSQLFile.h:163
const char * True
Int_t fD
File descriptor.
Definition: TFile.h:69
const char * ObjectsTableIndex
virtual void SetCompressionLevel(Int_t level=1)
See comments for function SetCompressionSettings.
Definition: TFile.cxx:2131
void SetLocking(Int_t mode)
Set locking mode for current database.
Definition: TSQLFile.cxx:1366
TString fRealName
Effective real file name (not original url)
Definition: TFile.h:77
void Class()
Definition: Class.C:29
ClassImp(TSQLFile)
const char * SQLDefaultTableType() const
Definition: TSQLFile.h:147
Bool_t ProduceClassSelectQuery(TVirtualStreamerInfo *info, TSQLClassInfo *sqlinfo, TString &columns, TString &tables, Int_t &tablecnt)
used by MakeClassSelectQuery method to add columns from table of class, specified by TVirtualStreamer...
Definition: TSQLFile.cxx:1265
const char * KT_Datetime
virtual Bool_t Rollback()
submit "ROLLBACK" query to database return kTRUE, if successful
Definition: TSQLServer.cxx:159
std::map< std::string, std::string >::const_iterator iter
Definition: TAlienJob.cxx:54
TSQLResult * SQLQuery(const char *cmd, Int_t flag=0, Bool_t *res=0)
Submits query to SQL server.
Definition: TSQLFile.cxx:1425
This is hierarhical structure, which is created when data is written by TBufferSQL2.
const char * oracle_BasicTypes[21]
Definition: TSQLFile.cxx:234
virtual Long64_t GetSeekDir() const
Definition: TDirectory.h:163
TString & Append(const char *cs)
Definition: TString.h:492
Int_t fModifyCounter
! indicates how many changes was done with database tables
Definition: TSQLFile.h:160
Bool_t CreateClassTable(TSQLClassInfo *sqlinfo, TObjArray *colinfos)
Create normal class table if required.
Definition: TSQLFile.cxx:2074
const char * KT_Cycle
Bool_t IsWritable() const
Int_t Atoi() const
Return integer value of string.
Definition: TString.cxx:1951
TSQLStatement * SQLStatement(const char *cmd, Int_t bufsize=1000)
Produces SQL statement for currently conected DB server.
Definition: TSQLFile.cxx:1467
Int_t GetClassVersion() const
Definition: TSQLClassInfo.h:60
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition: TKey.h:30
A TProcessID identifies a ROOT job in a unique way in time and space.
Definition: TProcessID.h:34
XFontStruct * id
Definition: TGX11.cxx:108
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
Long64_t fSeekDir
Location of directory on file.
const char * cfg_TablesType
Bool_t IsTablesExists()
Checks if main keys table is existing.
Definition: TSQLFile.cxx:1350
virtual void DirWriteKeys(TDirectory *)
Write directory keys list to database.
Definition: TSQLFile.cxx:2623
virtual Bool_t NextResultRow()=0
Long64_t GetClassId() const
Definition: TSQLClassInfo.h:57
void IncrementModifyCounter()
Update value of modify counter in config table Modify counter used to indicate that something was cha...
Definition: TSQLFile.cxx:1215
const char * ST_Value
Bool_t SQLCanStatement()
Test if DB support statement and number of open statements is not exceeded.
Definition: TSQLFile.cxx:1455
Long64_t DefineNextKeyId()
Returns next possible key identifier.
Definition: TSQLFile.cxx:1775
Bool_t GetLongString(Long64_t objid, Int_t strid, TString &value)
Returns value of string, extracted from special table, where long strings are stored.
Definition: TSQLFile.cxx:2293
virtual const char * GetName() const
Returns name of object.
Definition: TSQLClassInfo.h:34
const char * KT_Title
virtual const char * GetTitle() const
Returns title (title can contain 32x32 xpm thumbnail/icon).
Definition: TKey.cxx:1522
const Int_t Ids_TSQLFile
Bool_t WriteKeyData(TKeySQL *key)
Add entry into keys table.
Definition: TSQLFile.cxx:1708
A doubly linked list.
Definition: TList.h:47
const char * OT_Class
void ReadSQLClassInfos()
Read all class infos from IdsTable.
Definition: TSQLFile.cxx:1918
static TString DefineElementColumnName(TStreamerElement *elem, TSQLFile *f, Int_t indx=0)
returns name of the column in class table for that element
void AddIdEntry(Long64_t tableid, Int_t subid, Int_t type, const char *name, const char *sqlname, const char *info)
Add entry into IdsTable, where all tables names and columns names are listed.
Definition: TSQLFile.cxx:2028
const char * KeysTableIndex
virtual TKey * CreateKey(TDirectory *mother, const TObject *obj, const char *name, Int_t bufsize)
create SQL key, which will store object in data base
Definition: TSQLFile.cxx:794
TString DefineTableName(const char *clname, Int_t version, Bool_t rawtable)
Proposes table name for class.
Definition: TSQLFile.cxx:1847
const char * KT_Class
virtual ~TSQLFile()
destructor of TSQLFile object
Definition: TSQLFile.cxx:711
const char * SQLSmallTextType() const
Definition: TSQLFile.h:135
Access an SQL db via the TFile interface.
Definition: TSQLFile.h:32
const char * SQLRawIdColumn() const
Definition: TSQLFile.h:143
TList * fKeys
Pointer to keys list in memory.
const char * SQLIntType() const
return SQL integer type
Definition: TSQLFile.cxx:2587
TVirtualStreamerInfo * GetStreamerInfo(Int_t version=0) const
returns a pointer to the TVirtualStreamerInfo object for version If the object does not exist...
Definition: TClass.cxx:4256
const char * IT_Info
TPaveLabel title(3, 27.1, 15, 28.7,"ROOT Environment and Tools")
#define ReadStrCfg(name, target)
const char * SQLDatetimeType() const
Definition: TSQLFile.h:138
Bool_t Commit()
Commit transaction, started by StartTransaction() call.
Definition: TSQLFile.cxx:605
void SetRawExist(Bool_t on)
Definition: TSQLClassInfo.h:70
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:187
TSQLClassInfo * FindSQLClassInfo(const char *clname, Int_t version)
Return (if exists) TSQLClassInfo for specified class name and version.
Definition: TSQLFile.cxx:1790
TSQLStatement * GetBlobClassDataStmt(Long64_t objid, TSQLClassInfo *sqlinfo)
Method return request results for specified objid from streamer classtable Data returned in form of s...
Definition: TSQLFile.cxx:2502
virtual Int_t GetMaxIdentifierLength()
Definition: TSQLServer.h:93
const char * GetSQLType() const
Definition: TSQLClassInfo.h:36
const char * GetSQLName() const
Definition: TSQLClassInfo.h:35
static void update(gsl_integration_workspace *workspace, double a1, double b1, double area1, double error1, double a2, double b2, double area2, double error2)
virtual TList * GetStreamerInfoList()
Read back streamer infos from database List of streamer infos is always stored with key:id 0...
Definition: TSQLFile.cxx:905
Bool_t SQLRollback()
Rollback all SQL operations, done after start transaction.
Definition: TSQLFile.cxx:1607
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition: TString.cxx:2308
bool first
Definition: line3Dfit.C:48
Int_t DecrementCount()
The reference fCount is used to delete the TProcessID in the TFile destructor when fCount = 0...
Definition: TProcessID.cxx:207
virtual Bool_t Commit()
submit "COMMIT" query to database return kTRUE, if successful
Definition: TSQLServer.cxx:150
const char * AsString() const
Return UUID as string. Copy string immediately since it will be reused.
Definition: TUUID.cxx:536
const char * LongStrPrefix
virtual const char * GetField(Int_t field)=0
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
TObjArray * SQLObjectsInfo(Long64_t keyid)
Produce array of TSQLObjectInfo objects for all objects, belong to that key Array should be deleted b...
Definition: TSQLFile.cxx:2393
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
virtual Int_t GetInt(Int_t)
Definition: TSQLStatement.h:85
const char * KeysTable
void SetUseIndexes(Int_t use_type=kIndexesBasic)
Specify usage of indexes for data tables Index Description kIndexesNone = 0 no indexes are used kInd...
Definition: TSQLFile.cxx:641
void operator=(const TSQLFile &)
make private to exclude copy operator
Definition: TSQLFile.cxx:731
TString MakeSelectQuery(TClass *cl)
Produce SELECT statement which can be used to get all data of class cl in one SELECT statement...
Definition: TSQLFile.cxx:1244
void Build(TFile *motherFile=0, TDirectory *motherDir=0)
Initialise directory to defaults.
const char * OT_Version
Version_t GetClassVersion() const
Definition: TClass.h:381
const char * TObjectUniqueId
Bool_t fWritable
True if directory is writable.
void DeleteKeyFromDB(Long64_t keyid)
Remove key with specified id from keys table also removes all objects data, related to this table...
Definition: TSQLFile.cxx:1629
const char * cfg_Version
Bool_t IsOracle() const
checks, if Oracle database
Definition: TSQLFile.cxx:506
void SetArrayLimit(Int_t limit=20)
Defines maximum number of columns for array representation If array size bigger than limit...
Definition: TSQLFile.cxx:542
virtual void Print(Option_t *option="") const
Default print for collections, calls Print(option, 1).
const char * mysql_BasicTypes[21]
Definition: TSQLFile.cxx:194
virtual void ReadStreamerInfo()
Read the list of StreamerInfo from this file.
Definition: TFile.cxx:3384
const char * TObjectBits
Double_t fSum2Buffer
Sum of squares of buffer sizes of objects written so far.
Definition: TFile.h:61
Converts data to SQL statements or read data from SQL tables.
Definition: TBufferSQL2.h:36
TList * fFree
Free segments linked list table.
Definition: TFile.h:80
#define WrintCfg(name, type, value)
TFile * fFile
Pointer to current file in memory.
#define ReadIntCfg(name, target)
virtual Int_t GetSize() const
Definition: TCollection.h:95
Bool_t CreateRawTable(TSQLClassInfo *sqlinfo)
Create the raw table.
Definition: TSQLFile.cxx:2163
Int_t GetLocking()
Return current locking mode for that file.
Definition: TSQLFile.cxx:1383
virtual void SetName(const char *newname)
Set the name for directory If the directory name is changed after the directory was written once...
const char * BT_Field
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:415
const char * GetClassTableName() const
Definition: TSQLClassInfo.h:65
virtual TObjArray * GetElements() const =0
const Int_t Ids_StreamerInfos
const char * TObjectProcessId
Describe directory structure in memory.
Definition: TDirectory.h:44
virtual Int_t GetNumber() const =0
int type
Definition: TGX11.cxx:120
virtual void Clear(Option_t *option="")
delete the TObjArray pointing to referenced objects this function is called by TFile::Close("R") ...
Definition: TProcessID.cxx:187
void dir(char *path=0)
Definition: rootalias.C:30
void SetWritable(Bool_t writable=kTRUE)
Set the new value of fWritable recursively.
static void AddStrBrackets(TString &s, const char *quote)
adds quotes arround string value and replaces some special symbols
#define R__LOCKGUARD(mutex)
const char * KT_Name
Bool_t SQLTestTable(const char *tablename)
Test, if table of specified name exists.
Definition: TSQLFile.cxx:1516
TString fOption
File options.
Definition: TFile.h:78
static TProcessID * GetSessionProcessID()
static function returning the pointer to the session TProcessID
Definition: TProcessID.cxx:260
const char * CT_Field
virtual void Close(Option_t *option="")
Delete all objects from memory and directory structure itself.
const char * cfg_ArrayLimit
const Int_t Ids_FirstKey
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
Definition: vector.h:440
virtual TDirectory * GetMotherDir() const
Definition: TDirectory.h:160
#define name(a, b)
Definition: linkTestLib0.cpp:5
const char * SQLStrIdColumn() const
Definition: TSQLFile.h:144
Mother of all ROOT objects.
Definition: TObject.h:58
Bool_t WriteSpecialObject(Long64_t keyid, TObject *obj, const char *name, const char *title)
write special kind of object like streamer infos or file itself keys for that objects should exist in...
Definition: TSQLFile.cxx:854
void SaveToDatabase()
save data which is not yet in Database Typically this is streamerinfos structures or ...
Definition: TSQLFile.cxx:924
void SetTablesType(const char *table_type)
Defines tables type, which is used in CREATE TABLE statements Now is only used for MySQL database...
Definition: TSQLFile.cxx:556
void SetUseTransactions(Int_t mode=kTransactionsAuto)
Defines usage of transactions statements for writing objects data to database.
Definition: TSQLFile.cxx:574
Bool_t fIdsTableExists
! indicate if IdsTable exists
Definition: TSQLFile.h:170
const char * SQLValueQuote() const
Definition: TSQLFile.h:146
typedef void((*Func_t)())
const Int_t Ids_RootDir
virtual TList * GetTablesList(const char *wild=0)
Return list of user tables Parameter wild specifies wildcard for table names.
Definition: TSQLServer.cxx:182
virtual void Add(TObject *obj)
Definition: TList.h:81
Bool_t SQLObjectInfo(Long64_t objid, TString &clname, Version_t &version)
Read from objects table data for specified objectid.
Definition: TSQLFile.cxx:2365
virtual void WriteStreamerInfo()
Store all TVirtualStreamerInfo, used in file, in sql database.
Definition: TSQLFile.cxx:818
virtual void ClassEnd(const TClass *)=0
Bool_t VerifyLongStringTable()
Checks that table for big strings is exists If not, will be created.
Definition: TSQLFile.cxx:2217
const char * ObjectsTable
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:567
void MakeZombie()
Definition: TObject.h:68
const char * BT_Value
Char_t * fArray
Definition: TArrayC.h:32
virtual Bool_t HasStatement() const
Definition: TSQLServer.h:85
virtual Long64_t DirCreateEntry(TDirectory *)
Create entry for directory in database.
Definition: TSQLFile.cxx:2595
Int_t fNProcessIDs
Number of TProcessID written to this file.
Definition: TFile.h:75
TKeySQL represents metainforamtion about object, which was written to SQL database.
Definition: TKeySQL.h:22
TObject * ReadSpecialObject(Long64_t keyid, TObject *obj=0)
Read data of special kind of objects.
Definition: TSQLFile.cxx:877
virtual Bool_t Process()=0
virtual void WriteHeader()
Write file info like configurations, title, UUID and other.
Definition: TSQLFile.cxx:810
R__EXTERN Int_t gDebug
Definition: Rtypes.h:128
Long64_t GetDBKeyId() const
Definition: TKeySQL.h:48
Bool_t IsReadAccess()
dummy, in future should check about read access to database
Definition: TSQLFile.cxx:1409
Int_t fVersion
File format version.
Definition: TFile.h:70
void Add(TObject *obj)
Definition: TObjArray.h:75
#define gDirectory
Definition: TDirectory.h:221
TKeySQL * FindSQLKey(TDirectory *dir, Long64_t keyid)
Search for TKeySQL object with specified keyid.
Definition: TSQLFile.cxx:1689
virtual Bool_t HasTable(const char *tablename)
Tests if table of that name exists in database Return kTRUE, if table exists.
Definition: TSQLServer.cxx:208
Bool_t fUseSuffixes
! use suffixes in column names like fValue:Int_t or fObject:pointer
Definition: TSQLFile.h:153
friend class TKeySQL
Definition: TSQLFile.h:35
TList * fSQLClassInfos
! list of SQL class infos
Definition: TSQLFile.h:151
Int_t fWritten
Number of objects written so far.
Definition: TFile.h:74
TSQLStructure * SqlWriteAny(const void *obj, const TClass *cl, Long64_t objid)
Convert object of any class to sql structures Return pointer on created TSQLStructure TSQLStructure o...
void SQLDeleteAllTables()
Delete all tables in database.
Definition: TSQLFile.cxx:1569
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 SetUseSuffixes(Bool_t on=kTRUE)
enable/disable uasge of suffixes in columns names can be changed before first object is saved into fi...
Definition: TSQLFile.cxx:526
const TDatime & GetDatime() const
Definition: TKey.h:83
Abstract Interface class describing Streamer information for one class.
const Bool_t kTRUE
Definition: Rtypes.h:91
Int_t SQLMaxIdentifierLength()
returns maximum allowed length of identifiers
Definition: TSQLFile.cxx:1615
const char * SQLBigTextType() const
Definition: TSQLFile.h:137
virtual void SetTitle(const char *title="")
Change (i.e. set) the title of the TNamed.
Definition: TNamed.cxx:152
TObject * obj
virtual Int_t DirReadKeys(TDirectory *)
Read directory list of keys from database.
Definition: TSQLFile.cxx:2609
float value
Definition: math.cpp:443
Int_t fUseIndexes
! use indexes for tables: 0 - off, 1 - only for basic tables, 2 + normal class tables, 3 - all tables
Definition: TSQLFile.h:159
Int_t fArrayLimit
! limit for array size. when array bigger, its content converted to raw format
Definition: TSQLFile.h:155
const Int_t n
Definition: legend1.C:16
const char * SQLCompatibleType(Int_t typ) const
Returns sql type name which is most closer to ROOT basic type.
Definition: TSQLFile.cxx:2579
Bool_t IsRawTableExist() const
Definition: TSQLClassInfo.h:73
const char * SQLKeyIdColumn() const
Definition: TSQLFile.h:141
const char * mysql_OtherTypes[13]
Definition: TSQLFile.cxx:218
Long64_t fBytesRead
Number of bytes read from this file.
Definition: TFile.h:63
const char * cnt
Definition: TXMLSetup.cxx:75
virtual void Close(Option_t *option="")
Close a SQL file For more comments see TFile::Close() function.
Definition: TSQLFile.cxx:665
TUUID GetUUID() const
Definition: TDirectory.h:168
const char * AsSQLString() const
Return the date & time in SQL compatible string format, like: 1997-01-15 20:16:28.
Definition: TDatime.cxx:149
const char * IT_TableID
const char * False
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
void Resize(Ssiz_t n)
Resize the string. Truncate or add blanks as necessary.
Definition: TString.cxx:1045
Bool_t IsWriteAccess()
Checkis, if lock is free in configuration tables.
Definition: TSQLFile.cxx:1358
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
Definition: TDatime.h:39
void SetColumns(TObjArray *columns)
assigns new list of columns
Long64_t VerifyObjectTable()
Checks that objects table is exists If not, table will be created Returns maximum value for existing ...
Definition: TSQLFile.cxx:2322
const char * cfg_UseSufixes
virtual TSQLRow * Next()=0
Array of chars or bytes (8 bits per element).
Definition: TArrayC.h:29
const char * IT_SubID
const char * cfg_ModifyCounter