File indexing completed on 2025-08-03 08:22:07
0001
0002 #include <TError.h>
0003 #include <TString.h>
0004 #include <TFile.h>
0005 #include <TF1.h>
0006 #include <RDBC/TSQLDriverManager.h>
0007 #include <RDBC/TSQLConnection.h>
0008 #include <RDBC/TSQLDatabaseMetaData.h>
0009 #include <RDBC/TSQLResultSet.h>
0010 #include <RDBC/TSQLResultSetMetaData.h>
0011 #include <RDBC/TSQLPreparedStatement.h>
0012 #include <RDBC/TSQLCallableStatement.h>
0013 #include <RDBC/TSQLTypes.h>
0014 extern "C" {
0015 #include <stdlib.h>
0016 };
0017
0018 Int_t RDBCTestInt(const Text_t* dsn,
0019 const Text_t* usr="",
0020 const Text_t* pwd="")
0021 {
0022
0023 TSQLConnection* myConnection = NULL;
0024 if(usr!="" && pwd !=""){
0025 if(getenv("VERBOSE"))
0026 printf( "connecting with: dsn= %s usr=%s pwd=%s\n",dsn,usr,pwd);
0027 myConnection = TSQLDriverManager::GetConnection( dsn, usr, pwd );
0028 } else{
0029 if(getenv("VERBOSE"))
0030 printf( "connecting with: dsn= %s \n",dsn);
0031 myConnection = TSQLDriverManager::GetConnection( dsn );
0032 }
0033
0034 if(!myConnection) {
0035 printf( "failed to connect: dsn= %s usr=%s pwd=%s\n",dsn,usr,pwd);
0036 printf("exiting...\n");
0037 return -1;
0038 }else
0039 printf("connected!!!\n");
0040 TSQLStatement* stmt = myConnection->CreateStatement();
0041
0042 stmt->ExecuteUpdate( "drop table int_table" );
0043 stmt->ExecuteUpdate( "create table int_table (an_int int not null)" );
0044 TSQLPreparedStatement* pstmt =
0045 myConnection->PrepareStatement("insert into int_table (an_int) values(?)");
0046
0047 int some_int = 1;
0048 pstmt->SetInt(1,some_int);
0049 pstmt->ExecuteUpdate("");
0050
0051 some_int = 2;
0052
0053 pstmt->SetInt(1,some_int);
0054 pstmt->ExecuteUpdate("");
0055
0056 TSQLResultSet* rs = stmt->ExecuteQuery("select an_int from int_table order by an_int");
0057 rs->Next();
0058 int my_int = (int)rs->GetInt(1);
0059 printf ("retrieved: %d\n",my_int);
0060 rs->Next();
0061 my_int = (int)rs->GetInt(1);
0062 printf ("retrieved: %d\n",my_int);
0063
0064
0065 myConnection->Close();
0066 return 0;
0067 }
0068
0069
0070 void Catch(TSQLException* e)
0071 {
0072
0073
0074 TString str = e->GetMessage();
0075 printf("SQL Error: %s\n",str.Data());
0076 }
0077
0078
0079
0080 #ifdef STANDALONE
0081
0082 #include <TROOT.h>
0083 #include <TSystem.h>
0084 #include <iostream>
0085
0086
0087
0088 TROOT root("RDBCTestInt","Test RDBC TSQLDriverManager and TSQLConnection");
0089
0090 int main(int argc, char **argv)
0091 {
0092
0093 gSystem->Load("libRDBC");
0094 Int_t ret = -1;
0095
0096 if(argc < 2 || argc > 4){
0097 printf ("usage: RDBCTestInt dsn [usr] [password]\n");
0098 return ret;
0099 }
0100
0101 if(argc==2)
0102 ret=RDBCTestInt(argv[1]);
0103 if(argc==3)
0104 ret=RDBCTestInt(argv[1],argv[2]);
0105 if(argc==4)
0106 ret=RDBCTestInt(argv[1],argv[2],argv[3]);
0107
0108 return ret;
0109 }
0110 #endif