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