Analysis Software
Documentation for
sPHENIX
simulation software
Home page
Related Pages
Modules
Namespaces
Classes
Files
Examples
External Links
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
RDBCTestConnect.C
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file RDBCTestConnect.C
1
2
#include <TError.h>
3
#include <TString.h>
4
#include <
RDBC/TSQLDriverManager.h
>
5
#include <
RDBC/TSQLConnection.h
>
6
#include <
RDBC/TSQLDatabaseMetaData.h
>
7
#include <
RDBC/TSQLResultSet.h
>
8
#include <
RDBC/TSQLResultSetMetaData.h
>
9
#include <
RDBC/TSQLPreparedStatement.h
>
10
#include <
RDBC/TSQLCallableStatement.h
>
11
#include <
RDBC/TSQLTypes.h
>
12
extern
"C"
{
13
#include <stdlib.h>
14
};
15
//___________________________________________________________________
16
Int_t
RDBCTestConnect
(
const
Text_t* dsn,
17
const
Text_t* usr=
""
,
18
const
Text_t* pwd=
""
)
19
{
20
// Open a connection...
21
TSQLConnection
* myConnection = NULL;
22
if
(usr!=
""
&& pwd !=
""
){
23
if
(getenv(
"VERBOSE"
))
24
printf
(
"connecting with: dsn= %s usr=%s pwd=%s\n"
,dsn,usr,pwd);
25
myConnection =
TSQLDriverManager::GetConnection
( dsn, usr, pwd );
26
}
else
{
27
if
(getenv(
"VERBOSE"
))
28
printf
(
"connecting with: dsn= %s \n"
,dsn);
29
myConnection =
TSQLDriverManager::GetConnection
( dsn );
30
}
31
32
if
(!myConnection) {
33
printf
(
"failed to connect: dsn= %s usr=%s pwd=%s\n"
,dsn,usr,pwd);
34
printf
(
"exiting...\n"
);
35
return
-1;
// return on error
36
}
else
37
printf
(
"connected!!!\n"
);
38
39
myConnection->
Close
();
40
return
0;
41
}
42
43
//___________________________________________________________________
44
void
Catch
(
TSQLException
*
e
)
45
{
46
// handle exceptions
47
48
TString
str
= e->
GetMessage
();
49
printf
(
"SQL Error: %s\n"
,str.Data());
50
}
51
52
54
#ifdef STANDALONE
55
56
#include <TROOT.h>
57
#include <TSystem.h>
58
#include <iostream>
59
60
//---- Main program ------------------------------------------------------------
61
62
TROOT
root
(
"RDBCTestConnect"
,
"Test RDBC TSQLDriverManager and TSQLConnection"
);
63
64
int
main
(
int
argc,
char
**argv)
65
{
66
67
gSystem->Load(
"libRDBC"
);
68
Int_t ret = -1;
69
70
if
(argc < 2 || argc > 4){
71
printf
(
"usage: RDBCTestConnect dsn [usr] [password]\n"
);
72
return
ret;
73
}
74
75
if
(argc==2)
76
ret=
RDBCTestConnect
(argv[1]);
77
if
(argc==3)
78
ret=
RDBCTestConnect
(argv[1],argv[2]);
79
if
(argc==4)
80
ret=
RDBCTestConnect
(argv[1],argv[2],argv[3]);
81
82
return
ret;
83
}
84
#endif
RDBC
blob
master
test
RDBCTestConnect
RDBCTestConnect.C
Built by
Jin Huang
. updated:
Sat Feb 17 2024 22:18:49
using
1.8.2 with
sPHENIX GitHub integration