File indexing completed on 2025-08-03 08:22:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152 #include "ODBCConnection.h"
0153 #include "ODBCStatement.h"
0154 #include "ODBCPreparedStatement.h"
0155 #include "ODBCCallableStatement.h"
0156 #include "ODBCDatabaseMetaData.h"
0157 #include "ODBCResultSet.h"
0158 #include <RDBC/TSQLDriverManager.h>
0159 #include <RDBC/TSQLUrl.h>
0160 #include <RDBC/TSQLDriverInfo.h>
0161 #include <TList.h>
0162 #include <TNamed.h>
0163 #include <RDBC/odbc++/connection.h>
0164 #include <RDBC/odbc++/statement.h>
0165 #include <RDBC/odbc++/resultset.h>
0166 #include <RDBC/odbc++/preparedstatement.h>
0167 #include <RDBC/odbc++/callablestatement.h>
0168 #include <RDBC/odbc++/drivermanager.h>
0169
0170 using namespace odbc;
0171 using namespace std;
0172
0173 ClassImpQ(ODBCConnection)
0174
0175
0176
0177 ODBCConnection::ODBCConnection( const TString& connectString ):
0178 TSQLConnection(connectString)
0179 {
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194 odbc::Connection* imp = 0;
0195 odbc::DatabaseMetaData* md = 0;
0196
0197 try {
0198 imp = odbc::DriverManager::getConnection(
0199 ODBCXX_STRING_C(connectString) );
0200 fImp = imp;
0201 if(imp) md = imp->getMetaData();
0202 } catch(odbc::SQLException& e) {
0203 gSQLDriverManager->Throw( new TSQLException(
0204 ODBCXX_STRING_CSTR(e.getMessage()),
0205 ODBCXX_STRING_CSTR(e.getSQLState()),
0206 e.getErrorCode()) );
0207
0208 if(imp) delete imp;
0209 fImp = 0;
0210 return;
0211 }
0212
0213 if(!fMetaData) fMetaData = new ODBCDatabaseMetaData(this,md);
0214 }
0215
0216
0217 ODBCConnection::ODBCConnection( const TString& dsn,
0218 const TString& username,
0219 const TString& password ):
0220 TSQLConnection(dsn,username,password)
0221 {
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236 odbc::Connection* imp = 0;
0237 odbc::DatabaseMetaData* md = 0;
0238
0239 try {
0240 imp = odbc::DriverManager::getConnection(
0241 ODBCXX_STRING_C(dsn),
0242 ODBCXX_STRING_C(username),
0243 ODBCXX_STRING_C(password) );
0244 fImp = imp;
0245 if(imp) md = imp->getMetaData();
0246 } catch(odbc::SQLException& e) {
0247 gSQLDriverManager->Throw( new TSQLException(
0248 ODBCXX_STRING_CSTR(e.getMessage()),
0249 ODBCXX_STRING_CSTR(e.getSQLState()),
0250 e.getErrorCode()) );
0251
0252 if(imp) delete imp;
0253 fImp = 0;
0254 return;
0255 }
0256 if(!fMetaData) fMetaData = new ODBCDatabaseMetaData(this,md);
0257 }
0258
0259
0260 ODBCConnection::~ODBCConnection()
0261 {
0262
0263
0264
0265
0266
0267 if(IsClosed()) return;
0268
0269 odbc::Connection* con = (odbc::Connection*)fImp;
0270
0271 if(fListOfStatements) {
0272 fListOfStatements->Delete();
0273 delete fListOfStatements;
0274 }
0275
0276 fListOfStatements = 0;
0277
0278 try {
0279 if(con) delete con;
0280 } catch(odbc::SQLException& e) {
0281 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0282 ODBCXX_STRING_CSTR(e.getSQLState()),
0283 e.getErrorCode()) );
0284 }
0285
0286 if(fMetaData) delete ((ODBCDatabaseMetaData*)fMetaData);
0287
0288 fImp = 0;
0289 fMetaData = 0;
0290 }
0291
0292
0293 TSQLStatement* ODBCConnection::CreateStatement()
0294 {
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308
0309 if(IsClosed()) {
0310 Throw( new TSQLException( "Connection is closed","",0) );
0311 return 0;
0312 }
0313
0314 ClearWarnings();
0315
0316 TSQLStatement* stmt = 0;
0317 odbc::Connection* con = (odbc::Connection*)fImp;
0318 odbc::Statement* imp = 0;
0319
0320 try {
0321 imp = con->createStatement();
0322 } catch(odbc::SQLException& e) {
0323 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0324 ODBCXX_STRING_CSTR(e.getSQLState()),
0325 e.getErrorCode()) );
0326 if(imp) delete imp;
0327 return 0;
0328 }
0329 stmt = new ODBCStatement(this,imp);
0330 fListOfStatements->Add(stmt);
0331 return stmt;
0332 }
0333
0334
0335 TSQLStatement* ODBCConnection::CreateStatement( Int_t resultSetType,
0336 Int_t resultSetConcurrency )
0337 {
0338
0339
0340
0341
0342
0343
0344
0345
0346
0347
0348
0349
0350
0351
0352
0353
0354 if(IsClosed()) {
0355 Throw( new TSQLException( "Connection is closed","",0) );
0356 return 0;
0357 }
0358 ClearWarnings();
0359
0360 TSQLStatement* stmt = 0;
0361 odbc::Connection* con = (odbc::Connection*)fImp;
0362 odbc::Statement* imp = 0;
0363
0364 try {
0365 imp = con->createStatement( resultSetType,resultSetConcurrency );
0366 } catch(odbc::SQLException& e) {
0367 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0368 ODBCXX_STRING_CSTR(e.getSQLState()),
0369 e.getErrorCode()) );
0370 if(imp) delete imp;
0371 return 0;
0372 }
0373 stmt = new ODBCStatement(this,imp);
0374 fListOfStatements->Add(stmt);
0375 return stmt;
0376 }
0377
0378
0379 TSQLPreparedStatement* ODBCConnection::PrepareStatement( const TString& sql )
0380 {
0381
0382
0383
0384
0385
0386
0387
0388
0389
0390
0391
0392
0393
0394
0395
0396
0397
0398
0399
0400
0401
0402
0403
0404
0405
0406
0407
0408 if(IsClosed()) {
0409 Throw( new TSQLException( "Connection is closed","",0) );
0410 return 0;
0411 }
0412
0413 ClearWarnings();
0414
0415 ODBCPreparedStatement* stmt = 0;
0416 odbc::Connection* con = (odbc::Connection*)fImp;
0417 odbc::PreparedStatement* imp = 0;
0418
0419 try {
0420 imp = con->prepareStatement( ODBCXX_STRING_C(sql.Data()) );
0421 } catch(odbc::SQLException& e) {
0422 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0423 ODBCXX_STRING_CSTR(e.getSQLState()),
0424 e.getErrorCode()) );
0425 if(imp) delete imp;
0426 return 0;
0427 }
0428 stmt = new ODBCPreparedStatement(this,imp);
0429 fListOfStatements->Add(stmt);
0430 return stmt;
0431 }
0432
0433
0434 TSQLCallableStatement* ODBCConnection::PrepareCall( const TString& sql )
0435 {
0436
0437
0438
0439
0440
0441
0442
0443
0444
0445
0446
0447
0448
0449
0450
0451
0452
0453
0454
0455
0456
0457
0458
0459
0460 if(IsClosed()) {
0461 Throw( new TSQLException( "Connection is closed","",0) );
0462 return 0;
0463 }
0464
0465 ClearWarnings();
0466
0467 ODBCCallableStatement* stmt = 0;
0468 odbc::Connection* con = (odbc::Connection*)fImp;
0469 odbc::CallableStatement* imp = 0;
0470
0471 try {
0472 imp = con->prepareCall( ODBCXX_STRING_C(sql.Data()) );
0473 } catch(odbc::SQLException& e) {
0474 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0475 ODBCXX_STRING_CSTR(e.getSQLState()),
0476 e.getErrorCode()) );
0477 if(imp) delete imp;
0478 return 0;
0479 }
0480 stmt = new ODBCCallableStatement(this,imp);
0481 fListOfStatements->Add(stmt);
0482 return stmt;
0483 }
0484
0485
0486 TSQLPreparedStatement* ODBCConnection::PrepareStatement( const TString& sql,
0487 Int_t resultSetType,
0488 Int_t resultSetConcurrency )
0489 {
0490
0491
0492
0493
0494
0495
0496
0497
0498
0499
0500
0501
0502
0503
0504
0505
0506
0507 if(IsClosed()) {
0508 Throw( new TSQLException( "Connection is closed","",0) );
0509 return 0;
0510 }
0511
0512 ClearWarnings();
0513
0514 ODBCPreparedStatement* stmt = 0;
0515 odbc::Connection* con = (odbc::Connection*)fImp;
0516 odbc::PreparedStatement* imp =0;
0517
0518 try {
0519 imp = con->prepareStatement( ODBCXX_STRING_C(sql.Data()),
0520 resultSetType,
0521 resultSetConcurrency );
0522 } catch(odbc::SQLException& e) {
0523 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0524 ODBCXX_STRING_CSTR(e.getSQLState()),
0525 e.getErrorCode()) );
0526 if(imp) delete imp;
0527 return 0;
0528 }
0529 stmt = new ODBCPreparedStatement(this,imp);
0530 fListOfStatements->Add(stmt);
0531 return stmt;
0532 }
0533
0534
0535 TSQLCallableStatement* ODBCConnection::PrepareCall( const TString& sql,
0536 Int_t resultSetType,
0537 Int_t resultSetConcurrency )
0538 {
0539
0540
0541
0542
0543
0544
0545
0546
0547
0548
0549
0550
0551
0552
0553
0554
0555
0556
0557 if(IsClosed()) {
0558 Throw( new TSQLException( "Connection is closed","",0) );
0559 return 0;
0560 }
0561
0562 ClearWarnings();
0563
0564 ODBCCallableStatement* stmt = 0;
0565 odbc::Connection* con = (odbc::Connection*)fImp;
0566 odbc::CallableStatement* imp = 0;
0567
0568 try {
0569 imp= con->prepareCall( ODBCXX_STRING_C(sql.Data()),
0570 resultSetType,
0571 resultSetConcurrency );
0572 } catch(odbc::SQLException& e) {
0573 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0574 ODBCXX_STRING_CSTR(e.getSQLState()),
0575 e.getErrorCode()) );
0576 if(imp) delete imp;
0577 return 0;
0578 }
0579 stmt = new ODBCCallableStatement(this,imp);
0580 fListOfStatements->Add(stmt);
0581 return stmt;
0582 }
0583
0584
0585 TString ODBCConnection::NativeSQL( const TString& sql )
0586 {
0587
0588
0589
0590
0591
0592
0593
0594
0595
0596
0597
0598
0599
0600
0601 if(IsClosed()) {
0602 Throw( new TSQLException( "Connection is closed","",0) );
0603 return "0";
0604 }
0605
0606 ClearWarnings();
0607
0608 TString str;
0609 odbc::Connection* con = (odbc::Connection*)fImp;
0610
0611 try {
0612 ODBCXX_STRING s = con->nativeSQL( ODBCXX_STRING_C(sql.Data()) );
0613 str = ODBCXX_STRING_CSTR(s);
0614 } catch(odbc::SQLException& e) {
0615 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0616 ODBCXX_STRING_CSTR(e.getSQLState()),
0617 e.getErrorCode()) );
0618 return "";
0619 }
0620 return str;
0621 }
0622
0623
0624 void ODBCConnection::SetAutoCommit( Bool_t autoCommit )
0625 {
0626
0627
0628
0629
0630
0631
0632
0633
0634
0635
0636
0637
0638
0639
0640
0641
0642
0643
0644
0645
0646
0647 if(IsClosed()) {
0648 Throw( new TSQLException( "Connection is closed","",0) );
0649 return;
0650 }
0651 odbc::Connection* con = (odbc::Connection*)fImp;
0652
0653 try {
0654 con->setAutoCommit(autoCommit);
0655 } catch(odbc::SQLException& e) {
0656 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0657 ODBCXX_STRING_CSTR(e.getSQLState()),
0658 e.getErrorCode()) );
0659 }
0660 }
0661
0662
0663 Bool_t ODBCConnection::GetAutoCommit()
0664 {
0665
0666
0667
0668
0669
0670
0671
0672
0673
0674 if(IsClosed()) {
0675 Throw( new TSQLException( "Connection is closed","",0) );
0676 return 0;
0677 }
0678
0679 Bool_t return_value = kFALSE;
0680 odbc::Connection* con = (odbc::Connection*)fImp;
0681
0682 try {
0683 return_value = con->getAutoCommit();
0684 } catch(odbc::SQLException& e) {
0685 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0686 ODBCXX_STRING_CSTR(e.getSQLState()),
0687 e.getErrorCode()) );
0688 return kFALSE;
0689 }
0690 return return_value;
0691 }
0692
0693
0694 void ODBCConnection::Commit()
0695 {
0696
0697
0698
0699
0700
0701
0702
0703
0704
0705
0706 if(IsClosed()) {
0707 Throw( new TSQLException( "Connection is closed","",0) );
0708 return;
0709 }
0710
0711 odbc::Connection* con = (odbc::Connection*)fImp;
0712
0713 try {
0714 con->commit();
0715 } catch(odbc::SQLException& e) {
0716 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0717 ODBCXX_STRING_CSTR(e.getSQLState()),
0718 e.getErrorCode()) );
0719 }
0720 }
0721
0722
0723 void ODBCConnection::Rollback()
0724 {
0725
0726
0727
0728
0729
0730
0731
0732
0733
0734 if(IsClosed()) {
0735 Throw( new TSQLException( "Connection is closed","",0) );
0736 return;
0737 }
0738
0739 odbc::Connection* con = (odbc::Connection*)fImp;
0740
0741 try {
0742 con->rollback();
0743 } catch(odbc::SQLException& e) {
0744 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0745 ODBCXX_STRING_CSTR(e.getSQLState()),
0746 e.getErrorCode()) );
0747 }
0748 }
0749
0750
0751 void ODBCConnection::Close()
0752 {
0753
0754
0755
0756
0757
0758
0759 TSQLConnection::Close();
0760 if(!IsClosed()) return;
0761
0762 odbc::Connection* con = (odbc::Connection*)fImp;
0763
0764 try {
0765 if(con) delete con;
0766 } catch(odbc::SQLException& e) {
0767 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0768 ODBCXX_STRING_CSTR(e.getSQLState()),
0769 e.getErrorCode()) );
0770 }
0771
0772 if(fMetaData) delete ((ODBCDatabaseMetaData*)fMetaData);
0773 fMetaData = 0;
0774 fImp = 0;
0775 }
0776
0777
0778 TSQLDatabaseMetaData* ODBCConnection::GetMetaData()
0779 {
0780
0781
0782
0783
0784
0785
0786
0787
0788
0789
0790
0791
0792 if(IsClosed()) {
0793 Throw( new TSQLException( "Connection is closed","",0) );
0794 return 0;
0795 }
0796
0797 odbc::DatabaseMetaData* md = 0;
0798 odbc::Connection* con = (odbc::Connection*)fImp;
0799
0800 try {
0801 md = con->getMetaData();
0802 } catch(odbc::SQLException& e) {
0803 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0804 ODBCXX_STRING_CSTR(e.getSQLState()),
0805 e.getErrorCode()) );
0806 return 0;
0807 }
0808 if(fMetaData) ((ODBCDatabaseMetaData*)fMetaData)->Set(this,md);
0809 return fMetaData;
0810 }
0811
0812
0813 void ODBCConnection::SetReadOnly( Bool_t readOnly )
0814 {
0815
0816
0817
0818
0819
0820
0821
0822
0823
0824
0825
0826
0827 if(IsClosed()) {
0828 Throw( new TSQLException( "Connection is closed","",0) );
0829 return;
0830 }
0831 odbc::Connection* con = (odbc::Connection*)fImp;
0832
0833 try {
0834 con->setReadOnly(readOnly);
0835 } catch(odbc::SQLException& e) {
0836 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0837 ODBCXX_STRING_CSTR(e.getSQLState()),
0838 e.getErrorCode()) );
0839 }
0840 }
0841
0842
0843 Bool_t ODBCConnection::IsReadOnly()
0844 {
0845
0846
0847
0848
0849
0850
0851
0852 if(IsClosed()) {
0853 Throw( new TSQLException( "Connection is closed","",0) );
0854 return kTRUE;
0855 }
0856
0857 Bool_t return_value = kTRUE;
0858 odbc::Connection* con = (odbc::Connection*)fImp;
0859
0860 try {
0861 return_value = con->isReadOnly();
0862 } catch(odbc::SQLException& e) {
0863 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0864 ODBCXX_STRING_CSTR(e.getSQLState()),
0865 e.getErrorCode()) );
0866 return kTRUE;
0867 }
0868 return return_value;
0869 }
0870
0871
0872 void ODBCConnection::SetCatalog( const TString& catalog )
0873 {
0874
0875
0876
0877
0878
0879
0880
0881
0882 if(IsClosed()) {
0883 Throw( new TSQLException( "Connection is closed","",0) );
0884 return;
0885 }
0886
0887 odbc::Connection* con = (odbc::Connection*)fImp;
0888
0889 try {
0890 con->setCatalog( ODBCXX_STRING_C(catalog.Data()) );
0891 } catch(odbc::SQLException& e) {
0892 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0893 ODBCXX_STRING_CSTR(e.getSQLState()),
0894 e.getErrorCode()) );
0895 }
0896 }
0897
0898
0899 TString ODBCConnection::GetCatalog()
0900 {
0901
0902
0903
0904
0905
0906
0907
0908 if(IsClosed()) {
0909 Throw( new TSQLException( "Connection is closed","",0) );
0910 return "0";
0911 }
0912
0913 TString str;
0914 odbc::Connection* con = (odbc::Connection*)fImp;
0915
0916 try {
0917 str = ODBCXX_STRING_CSTR( con->getCatalog() );
0918 } catch(odbc::SQLException& e) {
0919 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0920 ODBCXX_STRING_CSTR(e.getSQLState()),
0921 e.getErrorCode()) );
0922 return "";
0923 }
0924 return str;
0925 }
0926
0927
0928 void ODBCConnection::SetTransactionIsolation( Int_t level )
0929 {
0930
0931
0932
0933
0934
0935
0936
0937
0938
0939
0940
0941
0942
0943
0944
0945
0946
0947 if(IsClosed()) {
0948 Throw( new TSQLException( "Connection is closed","",0) );
0949 return;
0950 }
0951
0952 try {
0953
0954 } catch(odbc::SQLException& e) {
0955 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0956 ODBCXX_STRING_CSTR(e.getSQLState()),
0957 e.getErrorCode()) );
0958 }
0959 }
0960
0961
0962 Int_t ODBCConnection::GetTransactionIsolation()
0963 {
0964
0965
0966
0967
0968
0969
0970
0971 if(IsClosed()) {
0972 Throw( new TSQLException( "Connection is closed","",0) );
0973 return 0;
0974 }
0975
0976 Int_t return_value = 0;
0977 odbc::Connection* con = (odbc::Connection*)fImp;
0978
0979 try {
0980 return_value = con->getTransactionIsolation();
0981
0982 } catch(odbc::SQLException& e) {
0983 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0984 ODBCXX_STRING_CSTR(e.getSQLState()),
0985 e.getErrorCode()) );
0986 return 0;
0987 }
0988 return return_value;
0989 }
0990
0991
0992 Bool_t ODBCConnection::GetTrace()
0993 {
0994
0995
0996 if(IsClosed()) {
0997 Throw( new TSQLException( "Connection is closed","",0) );
0998 return kFALSE;
0999 }
1000
1001 Bool_t return_value = kFALSE;
1002 odbc::Connection* con = (odbc::Connection*)fImp;
1003
1004 try {
1005 return_value = con->getTrace();
1006 } catch(odbc::SQLException& e) {
1007 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
1008 ODBCXX_STRING_CSTR(e.getSQLState()),
1009 e.getErrorCode()) );
1010 return kFALSE;
1011 }
1012 return return_value;
1013 }
1014
1015
1016 void ODBCConnection::SetTrace( Bool_t on )
1017 {
1018
1019
1020 if(IsClosed()) {
1021 Throw( new TSQLException( "Connection is closed","",0) );
1022 return;
1023 }
1024
1025 odbc::Connection* con = (odbc::Connection*)fImp;
1026
1027 try {
1028 con->setTrace(on);
1029 } catch(odbc::SQLException& e) {
1030 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
1031 ODBCXX_STRING_CSTR(e.getSQLState()),
1032 e.getErrorCode()) );
1033 }
1034 }
1035
1036
1037 TString ODBCConnection::GetTraceFile()
1038 {
1039
1040
1041 TString str;
1042
1043 if(IsClosed()) {
1044 Throw( new TSQLException( "Connection is closed","",0) );
1045 return str;
1046 }
1047
1048 if(!fImp) { Destroyed(); return str; }
1049 odbc::Connection* con = (odbc::Connection*)fImp;
1050
1051 try {
1052 str = ODBCXX_STRING_CSTR( con->getTraceFile() );
1053 } catch(odbc::SQLException& e) {
1054 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
1055 ODBCXX_STRING_CSTR(e.getSQLState()),
1056 e.getErrorCode()) );
1057 return "";
1058 }
1059 return str;
1060 }
1061
1062
1063 void ODBCConnection::SetTraceFile( const TString& fn )
1064 {
1065
1066
1067 if(IsClosed()) {
1068 Throw( new TSQLException( "Connection is closed","",0) );
1069 return;
1070 }
1071
1072 odbc::Connection* con = (odbc::Connection*)fImp;
1073
1074 try {
1075 con->setTraceFile( ODBCXX_STRING_C(fn.Data()) );
1076 } catch(odbc::SQLException& e) {
1077 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
1078 ODBCXX_STRING_CSTR(e.getSQLState()),
1079 e.getErrorCode()) );
1080 }
1081 }
1082
1083
1084 Bool_t ODBCConnection::HasBatchSupport()
1085 {
1086
1087
1088
1089
1090
1091 return kFALSE;
1092 }
1093
1094
1095
1096
1097 void ODBCConnection::SetLoginTimeout( Int_t seconds )
1098 {
1099
1100
1101
1102
1103
1104
1105 odbc::DriverManager::setLoginTimeout( seconds );
1106 }
1107
1108
1109 Int_t ODBCConnection::GetLoginTimeout()
1110 {
1111
1112
1113
1114
1115
1116
1117 return odbc::DriverManager::getLoginTimeout();
1118 }
1119
1120
1121 void ODBCConnection::Shutdown()
1122 {
1123
1124
1125 try {
1126 odbc::DriverManager::shutdown();
1127 } catch(odbc::SQLException& e) {
1128 gSQLDriverManager->Throw( new TSQLException(
1129 ODBCXX_STRING_CSTR(e.getMessage()),
1130 ODBCXX_STRING_CSTR(e.getSQLState()),
1131 e.getErrorCode()) );
1132 }
1133 }
1134
1135
1136 TList* ODBCConnection::RefreshDrivers(TList* gDrivers)
1137 {
1138
1139
1140
1141 if(!gDrivers) return 0;
1142
1143 gDrivers->Delete();
1144
1145 TSQLDriverInfo* driver;
1146 TNamed* attribute;
1147 TList* attributeList;
1148
1149 try {
1150 odbc::DriverList* list = odbc::DriverManager::getDrivers();
1151
1152 for( odbc::DriverList::iterator i=list->begin();
1153 i != list->end(); i++) {
1154
1155 TString description = ODBCXX_STRING_CSTR((*i)->getDescription());
1156 const vector<ODBCXX_STRING>& attrs=(*i)->getAttributes();
1157
1158 attributeList = new TList();
1159
1160 for( vector<ODBCXX_STRING>::const_iterator x=attrs.begin();
1161 x!=attrs.end(); x++) {
1162
1163 attribute = new TNamed( ODBCXX_STRING_CSTR((*x)), "attribute" );
1164 attributeList->Add(attribute);
1165 }
1166 driver = new TSQLDriverInfo(description,attributeList);
1167 gDrivers->Add(driver);
1168 }
1169 } catch(odbc::SQLException& e) {
1170 gSQLDriverManager->Throw( new TSQLException(
1171 ODBCXX_STRING_CSTR(e.getMessage()),
1172 ODBCXX_STRING_CSTR(e.getSQLState()),
1173 e.getErrorCode()) );
1174 }
1175 return gDrivers;
1176 }
1177
1178
1179 TList* ODBCConnection::RefreshDataSources(TList* gDataSources)
1180 {
1181
1182
1183 if(!gDataSources) return 0;
1184
1185 gDataSources->Delete();
1186 TSQLUrl* url;
1187
1188 try {
1189 odbc::DataSourceList* list =
1190 odbc::DriverManager::getDataSources();
1191
1192 for( odbc::DataSourceList::iterator i=list->begin();
1193 i != list->end(); i++) {
1194
1195 odbc::DataSource* ds = (*i);
1196 url = new TSQLUrl(ODBCXX_STRING_CSTR(ds->getName()),
1197 ODBCXX_STRING_CSTR(ds->getDescription()));
1198 gDataSources->Add(url);
1199 }
1200 } catch(odbc::SQLException& e) {
1201 gSQLDriverManager->Throw( new TSQLException(
1202 ODBCXX_STRING_CSTR(e.getMessage()),
1203 ODBCXX_STRING_CSTR(e.getSQLState()),
1204 e.getErrorCode()) );
1205 }
1206 return gDataSources;
1207 }