55 #include <TClassTable.h>
60 #include <TSysEvtHandler.h>
61 #include <TApplication.h>
62 #include <TInterpreter.h>
96 gApplication->Terminate(0);
124 TString homedir =
"/tmp";
125 fOldIni = gSystem->Getenv(
"ODBCINI");
126 fNewIni = homedir + Form(
"/.odbcini.%d",gSystem->GetPid());
127 gSystem->Setenv(
"ODBCINI",
fNewIni.Data());
137 gSystem->Setenv(
"ODBCINI",
fOldIni.Data());
139 if(gSystem->Unlink(
fNewIni.Data())) {
140 TString
message =
"Failed to delete file: ";
142 Warning(
"Restore ODBCINI",message.Data());
154 if ( i1 < 0 )
return kFALSE;
156 int i2 = str.Last(
' ');
177 if(gSystem) gSystem->RemoveOnExit(gSQLDriverManager);
178 if(gInterpreter) gInterpreter->SaveGlobalsContext();
188 if(TClassTable::GetDict(
"TSQL")) {
201 if(!gSQLDriverManager) {
202 gSQLDriverManager =
this;
203 gDataSources =
new TList();
219 if(gDebug) Warning(
"~TSQLDriverManager()",
"Shutting down DriverManager");
231 gDataSources->Delete();
240 gSQLDriverManager = 0;
249 if(!TClassTable::GetDict(
"ODBCConnection")) {
251 "TSQLDriverManager::GetDrivers:RDBC-ODBC driver not loaded"));
255 return gDrivers = (TList*)gROOT->ProcessLineFast(
256 Form(
"ODBCConnection::RefreshDrivers((TList*)%ul)",
gDrivers));
264 if(!TClassTable::GetDict(
"ODBCConnection")) {
266 "TSQLDriverManager::GetDataSources:RDBC-ODBC driver not loaded"));
270 return gDataSources = (TList*)gROOT->ProcessLineFast(
271 Form(
"ODBCConnection::RefreshDataSources((TList*)%ul)",gDataSources));
282 #define TERMIO struct termio
293 const int bufsiz = 128;
296 if(isatty(fileno(
stdout))) {
297 fputs(
"Enter password:",
stdout);
300 ioctl(fileno(stdin), (
int) TCGETA, &org);
302 tmp.c_lflag &= ~(ECHO | ISIG | ICANON);
305 ioctl(fileno(stdin),(
int) TCSETA, &tmp);
307 fgets(passtr,bufsiz,stdin);
311 ioctl(fileno(stdin),(
int) TCSETA, &org);
326 char *
pos=to,*
end = to+
sizeof(to)-1;
335 if (tmp ==
'\b' || (
int) tmp == 127) {
342 if (tmp ==
'\n' || tmp ==
'\r' || tmp == 3)
break;
343 if (iscntrl(tmp) || pos == end)
continue;
348 while (pos != to && isspace(pos[-1]) ==
' ') pos--;
361 const TString& password )
388 Form(
"TSQLDriverManager::GetConnection:URL %s is not valid:-\n"
389 " Protocol : %s SubProtocol: %s Driver: %s Port: %d",
399 TString pswd = password;
410 sqlurl =
"mysql:odbc://localhost/test";
422 if(!TClassTable::GetDict(
"ODBCConnection")) {
424 "TSQLDriverManager::GetConnection:RDBC-ODBC driver not loaded"));
428 TString dsn = sqlurl.
GetDSN();
430 if(gODBCini) {
delete gODBCini; gODBCini = 0; }
434 "new ODBCConnection(\"%s\",\"%s\",\"%s\")",dsn.Data(),user.Data(),pswd.Data()));
436 if(gODBCini) {
delete gODBCini; gODBCini = 0; }
441 if ( con && !con->
fImp ) {
449 if(!anchor.IsNull()) {
452 importer->Connect(
"Throw(TSQLException*)",
"TSQLDriverManager",gSQLDriverManager,
"Throw(TSQLException*)");
453 importer->
Import(anchor,con);
463 if(con->References()==1) {
471 if(importer)
delete importer;
497 if(gODBCini) {
delete gODBCini; gODBCini = 0; }
506 if(!TClassTable::GetDict(
"ODBCConnection")) {
508 "TSQLDriverManager::GetConnection:RDBC-ODBC driver not loaded"));
513 "new ODBCConnection(\"%s\")",connectString.Data()));
516 if(con->References()==1) {
518 con->
SetURL(connectString.Data());
536 if(TClassTable::GetDict(
"ODBCConnection"))
537 gROOT->ProcessLineFast(Form(
"ODBCConnection::SetLoginTimeout(%d)",seconds));
549 return TClassTable::GetDict(
"ODBCConnection") ?
550 (Int_t) gROOT->ProcessLineFast(
"ODBCConnection::GetLoginTimeout()") : 0;