File indexing completed on 2025-08-05 08:21:34
0001
0002 #include <TError.h>
0003 #include <TString.h>
0004 #include <RDBC/TSQLDriverManager.h>
0005 #include <RDBC/TSQLConnection.h>
0006 #include <RDBC/TSQLDatabaseMetaData.h>
0007 #include <RDBC/TSQLResultSet.h>
0008 #include <RDBC/TSQLResultSetMetaData.h>
0009 #include <RDBC/TSQLPreparedStatement.h>
0010 #include <RDBC/TSQLCallableStatement.h>
0011 #include <RDBC/TSQLTypes.h>
0012 extern "C" {
0013 #include <stdlib.h>
0014 };
0015
0016 Int_t RDBCTestConnect(const Text_t* dsn,
0017 const Text_t* usr="",
0018 const Text_t* pwd="")
0019 {
0020
0021 TSQLConnection* myConnection = NULL;
0022 if(usr!="" && pwd !=""){
0023 if(getenv("VERBOSE"))
0024 printf( "connecting with: dsn= %s usr=%s pwd=%s\n",dsn,usr,pwd);
0025 myConnection = TSQLDriverManager::GetConnection( dsn, usr, pwd );
0026 } else{
0027 if(getenv("VERBOSE"))
0028 printf( "connecting with: dsn= %s \n",dsn);
0029 myConnection = TSQLDriverManager::GetConnection( dsn );
0030 }
0031
0032 if(!myConnection) {
0033 printf( "failed to connect: dsn= %s usr=%s pwd=%s\n",dsn,usr,pwd);
0034 printf("exiting...\n");
0035 return -1;
0036 }else
0037 printf("connected!!!\n");
0038
0039 myConnection->Close();
0040 return 0;
0041 }
0042
0043
0044 void Catch(TSQLException* e)
0045 {
0046
0047
0048 TString str = e->GetMessage();
0049 printf("SQL Error: %s\n",str.Data());
0050 }
0051
0052
0053
0054 #ifdef STANDALONE
0055
0056 #include <TROOT.h>
0057 #include <TSystem.h>
0058 #include <iostream>
0059
0060
0061
0062 TROOT root("RDBCTestConnect","Test RDBC TSQLDriverManager and TSQLConnection");
0063
0064 int main(int argc, char **argv)
0065 {
0066
0067 gSystem->Load("libRDBC");
0068 Int_t ret = -1;
0069
0070 if(argc < 2 || argc > 4){
0071 printf ("usage: RDBCTestConnect dsn [usr] [password]\n");
0072 return ret;
0073 }
0074
0075 if(argc==2)
0076 ret=RDBCTestConnect(argv[1]);
0077 if(argc==3)
0078 ret=RDBCTestConnect(argv[1],argv[2]);
0079 if(argc==4)
0080 ret=RDBCTestConnect(argv[1],argv[2],argv[3]);
0081
0082 return ret;
0083 }
0084 #endif