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