Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RDBCTestMetaData.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file RDBCTestMetaData.C
1 
2 #include <TError.h>
3 #include <TString.h>
5 #include <RDBC/TSQLConnection.h>
7 #include <RDBC/TSQLResultSet.h>
11 #include <RDBC/TSQLTypes.h>
12 #include <string>
13 extern "C" {
14 #include <stdlib.h>
15 };
16 
17 //A quick test to make sure TSQLResultSetMetaData::GetTables() works
18 //and TSQLResultSetMetaData::GetColumnName() and ::GetColumnTypeName()
19 //work OK
20 //Author dbox@fnal.gov
21 //Date 1/6/03
22 //
23 //___________________________________________________________________
24 Int_t RDBCTestMetaData(const Text_t* dsn, const Text_t* schema,
25  const Text_t* usr="",
26  const Text_t* pwd="")
27 {
28  // Open a connection...
29  TSQLConnection* myConnection = NULL;
30  if(usr!="" && pwd !=""){
31  if(getenv("VERBOSE"))
32  printf( "connecting with: dsn= %s usr=%s pwd=%s\n",dsn,usr,pwd);
33  myConnection = TSQLDriverManager::GetConnection( dsn, usr, pwd );
34  } else{
35  if(getenv("VERBOSE"))
36  printf( "connecting with: dsn= %s \n",dsn);
37  myConnection = TSQLDriverManager::GetConnection( dsn );
38  }
39 
40  if(!myConnection) {
41 
42  printf( "failed to connect: dsn= %s usr=%s pwd=%s\n",dsn,usr,pwd);
43  printf("exiting...\n");
44  return -1; // return on error
45  }else
46  printf("connected!!!\n");
47 
48  TSQLDatabaseMetaData *md = myConnection->GetMetaData();
49 
50 
51 
52 
53 
54 
55 
56  TString schm=schema;
57  TString catalog=schema;
58  TString tab_pattern="";
59  TString tab_type="TABLE";
60  TString tableName="";
61  TSQLResultSet *rs = md->GetTables(catalog,schm,tab_pattern,tab_type);
62  while(rs->Next()){
63  tableName = rs->GetString(3);
64  printf("%s\n",tableName.Data());
65  }
66 
67  printf("Bool_t AllProceduresAreCallable():%d\n",
69  printf("Bool_t AllTablesAreSelectable():%d\n",
71  printf("TString GetUserName():%s\n", md->GetUserName().Data());
72  printf("Bool_t IsReadOnly():%d\n", md->IsReadOnly());
73  printf("Bool_t NullsAreSortedHigh():%d\n", md->NullsAreSortedHigh());
74  printf("Bool_t NullsAreSortedLow():%d\n", md->NullsAreSortedLow());
75  printf("Bool_t NullsAreSortedAtStart():%d\n", md->NullsAreSortedAtStart());
76  printf("Bool_t NullsAreSortedAtEnd():%d\n", md->NullsAreSortedAtEnd());
77  printf("TString GetDatabaseProductName():%s\n",
78  md->GetDatabaseProductName().Data());
79  printf("TString GetDatabaseProductVersion():%s\n",
80  md->GetDatabaseProductVersion().Data());
81  printf("TString GetDriverName():%s\n", md->GetDriverName().Data());
82  printf("TString GetDriverVersion():%s\n", md->GetDriverVersion().Data());
83  printf("Int_t GetDriverMajorVersion():%d\n", md->GetDriverMajorVersion());
84  printf("Int_t GetDriverMinorVersion():%d\n", md->GetDriverMinorVersion());
85  printf("Bool_t UsesLocalFiles():%d\n", md->UsesLocalFiles());
86  printf("Bool_t UsesLocalFilePerTable():%d\n", md->UsesLocalFilePerTable());
87  printf("Bool_t SupportsMixedCaseIdentifiers():%d\n",
89  printf("Bool_t StoresUpperCaseIdentifiers():%d\n",
91  printf("Bool_t StoresLowerCaseIdentifiers():%d\n",
93  printf("Bool_t StoresMixedCaseIdentifiers():%d\n",
95  printf("Bool_t SupportsMixedCaseQuotedIdentifiers():%d\n",
97  printf("Bool_t StoresUpperCaseQuotedIdentifiers():%d\n",
99  printf("Bool_t StoresLowerCaseQuotedIdentifiers():%d\n",
101  printf("Bool_t StoresMixedCaseQuotedIdentifiers():%d\n",
103  printf("TString GetIdentifierQuoteString():%s\n",
104  md->GetIdentifierQuoteString().Data());
105  printf("TString GetSQLKeywords():%s\n",
106  md->GetSQLKeywords().Data());
107  printf("TString GetNumericFunctions():%s\n",
108  md->GetNumericFunctions().Data());
109  printf("TString GetStringFunctions():%s\n",
110  md->GetStringFunctions().Data());
111  printf("TString GetSystemFunctions():%s\n",
112  md->GetSystemFunctions().Data());
113  printf("TString GetTimeDateFunctions():%s\n",
114  md->GetTimeDateFunctions().Data());
115  printf("TString GetSearchStringEscape():%s\n",
116  md->GetSearchStringEscape().Data());
117  printf("TString GetExtraNameCharacters():%s\n",
118  md->GetExtraNameCharacters().Data());
119  printf("Bool_t SupportsAlterTableWithAddColumn():%d\n",
121  printf("Bool_t SupportsAlterTableWithDropColumn():%d\n",
123  printf("Bool_t SupportsColumnAliasing():%d\n",
124  md->SupportsColumnAliasing());
125  printf("Bool_t NullPlusNonNullIsNull():%d\n",
126  md->NullPlusNonNullIsNull());
127  printf("Bool_t SupportsConvert():%d\n", md->SupportsConvert());
128  //printf("Bool_t SupportsConvert(Int_t:%d\n", md->SupportsConvert(Int_t);
129  printf("Bool_t SupportsTableCorrelationNames():%d\n",
131  printf("Bool_t SupportsDifferentTableCorrelationNames():%d\n",
133  printf("Bool_t SupportsExpressionsInOrderBy():%d\n",
135  printf("Bool_t SupportsOrderByUnrelated():%d\n",
137  printf("Bool_t SupportsGroupBy():%d\n",
138  md->SupportsGroupBy());
139  printf("Bool_t SupportsGroupByUnrelated():%d\n",
141  printf("Bool_t SupportsGroupByBeyondSelect():%d\n",
143  printf("Bool_t SupportsLikeEscapeClause():%d\n",
145  printf("Bool_t SupportsMultipleResultSets():%d\n",
147  printf("Bool_t SupportsMultipleTransactions():%d\n",
149  printf("Bool_t SupportsNonNullableColumns():%d\n",
151  printf("Bool_t SupportsMinimumSQLGrammar():%d\n",
153  printf("Bool_t SupportsCoreSQLGrammar():%d\n",
154  md->SupportsCoreSQLGrammar());
155  printf("Bool_t SupportsExtendedSQLGrammar():%d\n",
157  printf("Bool_t SupportsANSI92EntryLevelSQL():%d\n",
159  printf("Bool_t SupportsANSI92IntermediateSQL():%d\n",
161  printf("Bool_t SupportsANSI92FullSQL():%d\n",
162  md->SupportsANSI92FullSQL());
163  printf("Bool_t SupportsIntegrityEnhancementFacility():%d\n",
165  printf("Bool_t SupportsOuterJoins():%d\n",
166  md->SupportsOuterJoins());
167  printf("Bool_t SupportsFullOuterJoins():%d\n",
168  md->SupportsFullOuterJoins());
169  printf("Bool_t SupportsLimitedOuterJoins():%d\n",
171  printf("TString GetSchemaTerm():%s\n",
172  md->GetSchemaTerm().Data());
173  printf("TString GetTableTerm():%s\n",
174  md->GetTableTerm().Data());
175  printf("TString GetProcedureTerm():%s\n",
176  md->GetProcedureTerm().Data());
177  printf("TString GetCatalogTerm():%s\n",
178  md->GetCatalogTerm().Data());
179  printf("Bool_t IsCatalogAtStart():%d\n",
180  md->IsCatalogAtStart());
181  printf("TString GetCatalogSeparator():%s\n",
182  md->GetCatalogSeparator().Data());
183  printf("Bool_t SupportsSchemasInDataManipulation():%d\n",
185  printf("Bool_t SupportsSchemasInProcedureCalls():%d\n",
187  printf("Bool_t SupportsSchemasInTableDefinitions():%d\n",
189  printf("Bool_t SupportsSchemasInIndexDefinitions():%d\n",
191  printf("Bool_t SupportsSchemasInPrivilegeDefinitions():%d\n",
193  printf("Bool_t SupportsCatalogsInDataManipulation():%d\n",
195  printf("Bool_t SupportsCatalogsInProcedureCalls():%d\n",
197  printf("Bool_t SupportsCatalogsInTableDefinitions():%d\n",
199  printf("Bool_t SupportsCatalogsInIndexDefinitions():%d\n",
201  printf("Bool_t SupportsCatalogsInPrivilegeDefinitions():%d\n",
203  printf("Bool_t SupportsPositionedDelete():%d\n",
205  printf("Bool_t SupportsPositionedUpdate():%d\n",
207  printf("Bool_t SupportsSelectForUpdate():%d\n",
209  printf("Bool_t SupportsStoredProcedures():%d\n",
211  printf("Bool_t SupportsSubqueriesInComparisons():%d\n",
213  printf("Bool_t SupportsSubqueriesInExists():%d\n",
215  printf("Bool_t SupportsSubqueriesInIns():%d\n",
217  printf("Bool_t SupportsSubqueriesInQuantifieds():%d\n",
219  printf("Bool_t SupportsCorrelatedSubqueries():%d\n",
221  printf("Bool_t SupportsUnion():%d\n",
222  md->SupportsUnion());
223  printf("Bool_t SupportsUnionAll():%d\n",
224  md->SupportsUnionAll());
225  printf("Bool_t SupportsOpenCursorsAcrossRollback():%d\n",
227  printf("Bool_t SupportsOpenStatementsAcrossCommit():%d\n",
229  printf("Bool_t SupportsOpenStatementsAcrossRollback():%d\n",
231  printf("Int_t GetMaxBinaryLiteralLength():%d\n",
233  printf("Int_t GetMaxCharLiteralLength():%d\n",
235  printf("Int_t GetMaxColumnNameLength():%d\n",
236  md->GetMaxColumnNameLength());
237  printf("Int_t GetMaxColumnsInGroupBy():%d\n",
238  md->GetMaxColumnsInGroupBy());
239  printf("Int_t GetMaxColumnsInIndex():%d\n",
240  md->GetMaxColumnsInIndex());
241  printf("Int_t GetMaxColumnsInOrderBy():%d\n",
242  md->GetMaxColumnsInOrderBy());
243  printf("Int_t GetMaxColumnsInSelect():%d\n",
244  md->GetMaxColumnsInSelect());
245  printf("Int_t GetMaxColumnsInTable():%d\n",
246  md->GetMaxColumnsInTable());
247  printf("Int_t GetMaxConnections():%d\n",
248  md->GetMaxConnections());
249  printf("Int_t GetMaxCursorNameLength():%d\n",
250  md->GetMaxCursorNameLength());
251  printf("Int_t GetMaxIndexLength():%d\n",
252  md->GetMaxIndexLength());
253  printf("Int_t GetMaxSchemaNameLength():%d\n",
254  md->GetMaxSchemaNameLength());
255  printf("Int_t GetMaxProcedureNameLength():%d\n",
257  printf("Int_t GetMaxCatalogNameLength():%d\n",
259  printf("Int_t GetMaxRowSize():%d\n", md->GetMaxRowSize());
260  printf("Bool_t DoesMaxRowSizeIncludeBlobs():%d\n",
262  printf("Int_t GetMaxStatementLength():%d\n",
263  md->GetMaxStatementLength());
264  printf("Int_t GetMaxStatements():%d\n",
265  md->GetMaxStatements());
266  printf("Int_t GetMaxTableNameLength():%d\n",
267  md->GetMaxTableNameLength());
268  printf("Int_t GetMaxTablesInSelect():%d\n",
269  md->GetMaxTablesInSelect());
270  printf("Int_t GetMaxUserNameLength():%d\n",
271  md->GetMaxUserNameLength());
272  printf("Int_t GetDefaultTransactionIsolation():%d\n",
274  printf("Bool_t SupportsTransactions():%d\n",
275  md->SupportsTransactions());
276 
277  printf("Bool_t SupportsDataDefinitionAndDataManipulationTransactions():%d\n",
279 
280  printf("Bool_t SupportsDataManipulationTransactionsOnly():%d\n",
282  printf("Bool_t DataDefinitionCausesTransactionCommit():%d\n",
284  printf("Bool_t DataDefinitionIgnoredInTransactions():%d\n",
286 
287  printf("looking at columns of %s\n",tableName.Data());
288  TString query = "select * from ";
289  query += tableName + " where 1=0;";
290  TSQLStatement* stmt = myConnection->CreateStatement();
291  TSQLResultSet *rs2 =stmt->ExecuteQuery( query);
292 
293  TSQLResultSetMetaData *rsmd = rs2->GetMetaData();
294  int numCols = rsmd->GetColumnCount();
295 
296  for(int i=1; i<= numCols; i++)
297  {
298 
299  printf( "col name= '%s' type = '%s' \n",
300  rsmd->GetColumnName(i).Data(),
301  rsmd->GetColumnTypeName(i).Data() );
302 
303  }
304 
305 
306  myConnection->Close();
307  return 0;
308 }
309 
310 //___________________________________________________________________
312 {
313  // handle exceptions
314 
315  TString str = e->GetMessage();
316  printf("SQL Error: %s\n",str.Data());
317 }
318 
319 
321 #ifdef STANDALONE
322 
323 #include <TROOT.h>
324 #include <TSystem.h>
325 #include <iostream>
326 
327 //---- Main program ------------------------------------------------------------
328 
329 TROOT root("RDBCTestMetaData","Test RDBC TSQLDriverManager and TSQLConnection");
330 
331 int main(int argc, char **argv)
332 {
333 
334  gSystem->Load("libRDBC");
335  Int_t ret = -1;
336  /*
337  printf("arg0:'%s'\n",argv[0]);
338  printf("arg1:'%s'\n",argv[1]);
339  printf("arg2:'%s'\n",argv[2]);
340  printf("arg3:'%s'\n",argv[3]);
341  printf("arg4:'%s'\n",argv[4]);
342  */
343 
344 
345  if(argc != 3 && argc != 5){
346  printf ("usage: RDBCTestMetaData dsn schema [usr] [password]\n");
347  return ret;
348  }
349 
350 
351  if(argc==3)
352  ret=RDBCTestMetaData(argv[1],argv[2]);
353  if(argc==5)
354  ret=RDBCTestMetaData(argv[1],argv[2],argv[3], argv[4]);
355 
356  return ret;
357 }
358 #endif