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 #include <sstream>
0089 #include "ODBCCallableStatement.h"
0090 #include <RDBC/odbc++/statement.h>
0091 #include <RDBC/odbc++/preparedstatement.h>
0092 #include <RDBC/odbc++/callablestatement.h>
0093 #include <iostream>
0094 #include "ODBCResultSet.h"
0095 #include <RDBC/odbc++/resultset.h>
0096 #include <TList.h>
0097
0098 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,15,0)
0099 #include <TBufferFile.h>
0100 #endif
0101
0102
0103 using namespace odbc;
0104
0105 ClassImpQ(ODBCCallableStatement)
0106
0107
0108
0109 ODBCCallableStatement::ODBCCallableStatement(TSQLConnection* con,void* imp):
0110 TSQLCallableStatement(con,imp)
0111
0112 {
0113
0114 }
0115
0116
0117 ODBCCallableStatement::~ODBCCallableStatement()
0118 {
0119
0120
0121 odbc::CallableStatement* imp = (odbc::CallableStatement*)fImp;
0122
0123 try {
0124 if(imp) delete imp;
0125 } catch(odbc::SQLException& e) {
0126 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0127 ODBCXX_STRING_CSTR(e.getSQLState()),
0128 e.getErrorCode()) );
0129 }
0130
0131
0132 if(fCurrentResult) ((ODBCResultSet*)fCurrentResult)->fImp = 0;
0133 fImp = 0;
0134 }
0135
0136
0137 void ODBCCallableStatement::RegisterOutParameter(Int_t parameterIndex,
0138 Int_t sqlType)
0139 {
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188 if(!fImp) { Destroyed(); return; }
0189 odbc::CallableStatement* stmt=(odbc::CallableStatement*)fImp;
0190
0191 try {
0192 stmt->registerOutParameter( parameterIndex,sqlType );
0193
0194 } catch(odbc::SQLException& e) {
0195 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0196 ODBCXX_STRING_CSTR(e.getSQLState()),
0197 e.getErrorCode()) );
0198 }
0199 }
0200
0201
0202 void ODBCCallableStatement::RegisterOutParameter(Int_t parameterIndex,
0203 Int_t sqlType,
0204 Int_t scale)
0205 {
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256 if(!fImp) { Destroyed(); return; }
0257 odbc::CallableStatement* stmt=(odbc::CallableStatement*)fImp;
0258
0259 try {
0260 stmt->registerOutParameter( parameterIndex,sqlType,scale );
0261
0262 } catch(odbc::SQLException& e) {
0263 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0264 ODBCXX_STRING_CSTR(e.getSQLState()),
0265 e.getErrorCode()) );
0266 }
0267 }
0268
0269
0270 Bool_t ODBCCallableStatement::WasNull()
0271 {
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283 Bool_t return_value = kFALSE;
0284
0285 if(!fImp) { Destroyed(); return return_value; }
0286 odbc::CallableStatement* stmt=(odbc::CallableStatement*)fImp;
0287
0288 try {
0289 return_value = stmt->wasNull();
0290
0291 } catch(odbc::SQLException& e) {
0292 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0293 ODBCXX_STRING_CSTR(e.getSQLState()),
0294 e.getErrorCode()) );
0295 return kFALSE;
0296 }
0297 return return_value;
0298 }
0299
0300
0301 TString ODBCCallableStatement::GetString( Int_t parameterIndex )
0302 {
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318 TString str;
0319
0320 if(!fImp) { Destroyed(); return str; }
0321 odbc::CallableStatement* stmt=(odbc::CallableStatement*)fImp;
0322
0323 try {
0324 ODBCXX_STRING s = stmt->getString(parameterIndex);
0325 str = ODBCXX_STRING_CSTR(s);
0326
0327 } catch(odbc::SQLException& e) {
0328 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0329 ODBCXX_STRING_CSTR(e.getSQLState()),
0330 e.getErrorCode()) );
0331 return "";
0332 }
0333 return str;
0334 }
0335
0336
0337 Bool_t ODBCCallableStatement::GetBoolean( Int_t parameterIndex )
0338 {
0339
0340
0341
0342
0343
0344
0345
0346
0347
0348
0349
0350 Bool_t return_value = kFALSE;
0351
0352 if(!fImp) { Destroyed(); return return_value; }
0353 odbc::CallableStatement* stmt=(odbc::CallableStatement*)fImp;
0354
0355 try {
0356 return_value = stmt->getBoolean(parameterIndex);
0357
0358 } catch(odbc::SQLException& e) {
0359 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0360 ODBCXX_STRING_CSTR(e.getSQLState()),
0361 e.getErrorCode()) );
0362 return kFALSE;
0363 }
0364 return return_value;
0365 }
0366
0367
0368 Char_t ODBCCallableStatement::GetByte( Int_t parameterIndex )
0369 {
0370
0371
0372
0373
0374
0375
0376
0377
0378
0379
0380
0381 Char_t return_value = 0;
0382
0383 if(!fImp) { Destroyed(); return return_value; }
0384 odbc::CallableStatement* stmt=(odbc::CallableStatement*)fImp;
0385
0386 try {
0387 return_value = stmt->getByte(parameterIndex);
0388
0389 } catch(odbc::SQLException& e) {
0390 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0391 ODBCXX_STRING_CSTR(e.getSQLState()),
0392 e.getErrorCode()) );
0393 return 0;
0394 }
0395 return return_value;
0396 }
0397
0398
0399 Short_t ODBCCallableStatement::GetShort( Int_t parameterIndex )
0400 {
0401
0402
0403
0404
0405
0406
0407
0408
0409
0410
0411
0412 Short_t return_value = 0;
0413
0414 if(!fImp) { Destroyed(); return return_value; }
0415 odbc::CallableStatement* stmt=(odbc::CallableStatement*)fImp;
0416
0417 try {
0418 return_value = stmt->getShort(parameterIndex);
0419
0420 } catch(odbc::SQLException& e) {
0421 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0422 ODBCXX_STRING_CSTR(e.getSQLState()),
0423 e.getErrorCode()) );
0424 return 0;
0425 }
0426 return return_value;
0427 }
0428
0429
0430 Int_t ODBCCallableStatement::GetInt( Int_t parameterIndex )
0431 {
0432
0433
0434
0435
0436
0437
0438
0439
0440
0441
0442
0443 Int_t return_value = 0;
0444
0445 if(!fImp) { Destroyed(); return return_value; }
0446 odbc::CallableStatement* stmt=(odbc::CallableStatement*)fImp;
0447
0448 try {
0449 return_value = stmt->getInt(parameterIndex);
0450
0451 } catch(odbc::SQLException& e) {
0452 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0453 ODBCXX_STRING_CSTR(e.getSQLState()),
0454 e.getErrorCode()) );
0455 return 0;
0456 }
0457 return return_value;
0458 }
0459
0460
0461 Long_t ODBCCallableStatement::GetLong( Int_t parameterIndex )
0462 {
0463
0464
0465
0466
0467
0468
0469
0470
0471
0472
0473
0474 Long_t return_value = 0;
0475
0476 if(!fImp) { Destroyed(); return return_value; }
0477 odbc::CallableStatement* stmt=(odbc::CallableStatement*)fImp;
0478
0479 try {
0480 return_value = stmt->getLong(parameterIndex);
0481
0482 } catch(odbc::SQLException& e) {
0483 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0484 ODBCXX_STRING_CSTR(e.getSQLState()),
0485 e.getErrorCode()) );
0486 return 0;
0487 }
0488 return return_value;
0489 }
0490
0491
0492 Float_t ODBCCallableStatement::GetFloat( Int_t parameterIndex )
0493 {
0494
0495
0496
0497
0498
0499
0500
0501
0502
0503
0504
0505 Float_t return_value = 0;
0506
0507 if(!fImp) { Destroyed(); return return_value; }
0508 odbc::CallableStatement* stmt=(odbc::CallableStatement*)fImp;
0509
0510 try {
0511 return_value = stmt->getFloat(parameterIndex);
0512
0513 } catch(odbc::SQLException& e) {
0514 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0515 ODBCXX_STRING_CSTR(e.getSQLState()),
0516 e.getErrorCode()) );
0517 return 0;
0518 }
0519 return return_value;
0520 }
0521
0522
0523 Double_t ODBCCallableStatement::GetDouble( Int_t parameterIndex )
0524 {
0525
0526
0527
0528
0529
0530
0531
0532
0533
0534
0535
0536 Double_t return_value = 0;
0537
0538 if(!fImp) { Destroyed(); return return_value; }
0539 odbc::CallableStatement* stmt=(odbc::CallableStatement*)fImp;
0540
0541 try {
0542 return_value = stmt->getDouble(parameterIndex);
0543
0544 } catch(odbc::SQLException& e) {
0545 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0546 ODBCXX_STRING_CSTR(e.getSQLState()),
0547 e.getErrorCode()) );
0548 return 0;
0549 }
0550 return return_value;
0551 }
0552
0553
0554 TArrayC ODBCCallableStatement::GetBytes( Int_t parameterIndex )
0555 {
0556
0557
0558
0559
0560
0561
0562
0563
0564
0565
0566
0567 TArrayC array;
0568
0569 if(!fImp) { Destroyed(); return array; }
0570 odbc::CallableStatement* stmt=(odbc::CallableStatement*)fImp;
0571
0572 try {
0573 ODBCXX_BYTES b = stmt->getBytes(parameterIndex);
0574
0575 array.Set( (Int_t)ODBCXX_BYTES_SIZE(b),
0576 (Char_t*)ODBCXX_BYTES_DATA(b) );
0577
0578 } catch(odbc::SQLException& e) {
0579 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0580 ODBCXX_STRING_CSTR(e.getSQLState()),
0581 e.getErrorCode()) );
0582 return TArrayC();
0583 }
0584 return array;
0585 }
0586
0587
0588 TSQLDate ODBCCallableStatement::GetDate( Int_t parameterIndex )
0589 {
0590
0591
0592
0593
0594
0595
0596
0597
0598
0599
0600
0601 TSQLDate return_value;
0602
0603 if(!fImp) { Destroyed(); return return_value; }
0604 odbc::CallableStatement* stmt=(odbc::CallableStatement*)fImp;
0605
0606 try {
0607 odbc::Date dt = stmt->getDate(parameterIndex);
0608
0609 return_value = TSQLDate( dt.getYear(),
0610 dt.getMonth(),
0611 dt.getDay() );
0612
0613 } catch(odbc::SQLException& e) {
0614 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0615 ODBCXX_STRING_CSTR(e.getSQLState()),
0616 e.getErrorCode()) );
0617 return TSQLDate();
0618 }
0619 return return_value;
0620 }
0621
0622
0623 TSQLTime ODBCCallableStatement::GetTime( Int_t parameterIndex )
0624 {
0625
0626
0627
0628
0629
0630
0631
0632
0633
0634
0635
0636 TSQLTime return_value;
0637
0638 if(!fImp) { Destroyed(); return return_value; }
0639 odbc::CallableStatement* stmt=(odbc::CallableStatement*)fImp;
0640
0641 try {
0642 odbc::Time tm = stmt->getTime(parameterIndex);
0643
0644 return_value = TSQLTime( tm.getHour(),
0645 tm.getMinute(),
0646 tm.getSecond() );
0647
0648 } catch(odbc::SQLException& e) {
0649 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0650 ODBCXX_STRING_CSTR(e.getSQLState()),
0651 e.getErrorCode()) );
0652 return TSQLTime();
0653 }
0654 return return_value;
0655 }
0656
0657
0658 TSQLTimestamp ODBCCallableStatement::GetTimestamp( Int_t parameterIndex )
0659 {
0660
0661
0662
0663
0664
0665
0666
0667
0668
0669
0670
0671 TSQLTimestamp return_value;
0672
0673 if(!fImp) { Destroyed(); return return_value; }
0674 odbc::CallableStatement* stmt=(odbc::CallableStatement*)fImp;
0675
0676 try {
0677 odbc::Timestamp tmstmp = stmt->getTimestamp(parameterIndex);
0678
0679 return_value = TSQLTimestamp( tmstmp.getYear(),
0680 tmstmp.getMonth(),
0681 tmstmp.getDay(),
0682 tmstmp.getHour(),
0683 tmstmp.getMinute(),
0684 tmstmp.getSecond(),
0685 tmstmp.getNanos() );
0686
0687 } catch(odbc::SQLException& e) {
0688 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0689 ODBCXX_STRING_CSTR(e.getSQLState()),
0690 e.getErrorCode()) );
0691 return TSQLTimestamp();
0692 }
0693 return return_value;
0694 }
0695
0696
0697
0698 void ODBCCallableStatement::SetNull( Int_t parameterIndex,Int_t sqlType )
0699 {
0700
0701
0702
0703
0704
0705
0706
0707
0708
0709
0710
0711 if(!fImp) { Destroyed(); return; }
0712 odbc::PreparedStatement* imp = (odbc::PreparedStatement*)fImp;
0713
0714 try {
0715 imp->setNull(parameterIndex,sqlType);
0716
0717 } catch(odbc::SQLException& e) {
0718 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0719 ODBCXX_STRING_CSTR(e.getSQLState()),
0720 e.getErrorCode()) );
0721 }
0722 }
0723
0724
0725 void ODBCCallableStatement::SetBoolean( Int_t parameterIndex,Bool_t x )
0726 {
0727
0728
0729
0730
0731
0732
0733
0734
0735
0736
0737
0738 if(!fImp) { Destroyed(); return; }
0739 odbc::PreparedStatement* imp = (odbc::PreparedStatement*)fImp;
0740
0741 try {
0742 imp->setBoolean(parameterIndex,x);
0743
0744 } catch(odbc::SQLException& e) {
0745 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0746 ODBCXX_STRING_CSTR(e.getSQLState()),
0747 e.getErrorCode()) );
0748 }
0749 }
0750
0751
0752 void ODBCCallableStatement::SetByte( Int_t parameterIndex,Char_t x )
0753 {
0754
0755
0756
0757
0758
0759
0760
0761
0762
0763
0764
0765 if(!fImp) { Destroyed(); return; }
0766 odbc::PreparedStatement* imp = (odbc::PreparedStatement*)fImp;
0767
0768 try {
0769 imp->setByte(parameterIndex,x);
0770
0771 } catch(odbc::SQLException& e) {
0772 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0773 ODBCXX_STRING_CSTR(e.getSQLState()),
0774 e.getErrorCode()) );
0775 }
0776 }
0777
0778
0779 void ODBCCallableStatement::SetShort( Int_t parameterIndex,Short_t x )
0780 {
0781
0782
0783
0784
0785
0786
0787
0788
0789
0790
0791
0792 if(!fImp) { Destroyed(); return; }
0793 odbc::PreparedStatement* imp = (odbc::PreparedStatement*)fImp;
0794
0795 try {
0796 imp->setShort(parameterIndex,x);
0797
0798 } catch(odbc::SQLException& e) {
0799 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0800 ODBCXX_STRING_CSTR(e.getSQLState()),
0801 e.getErrorCode()) );
0802 }
0803 }
0804
0805
0806 void ODBCCallableStatement::SetInt( Int_t parameterIndex,Int_t x )
0807 {
0808
0809
0810
0811
0812
0813
0814
0815
0816
0817
0818
0819 if(!fImp) { Destroyed(); return; }
0820 odbc::PreparedStatement* imp = (odbc::PreparedStatement*)fImp;
0821
0822 try {
0823 imp->setInt(parameterIndex,x);
0824
0825 } catch(odbc::SQLException& e) {
0826 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0827 ODBCXX_STRING_CSTR(e.getSQLState()),
0828 e.getErrorCode()) );
0829 }
0830 }
0831
0832
0833 void ODBCCallableStatement::SetLong( Int_t parameterIndex,Long_t x )
0834 {
0835
0836
0837
0838
0839
0840
0841
0842
0843
0844
0845
0846 if(!fImp) { Destroyed(); return; }
0847 odbc::PreparedStatement* imp = (odbc::PreparedStatement*)fImp;
0848
0849 try {
0850 imp->setLong(parameterIndex,x);
0851
0852 } catch(odbc::SQLException& e) {
0853 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0854 ODBCXX_STRING_CSTR(e.getSQLState()),
0855 e.getErrorCode()) );
0856 }
0857 }
0858
0859
0860 void ODBCCallableStatement::SetFloat( Int_t parameterIndex,Float_t x )
0861 {
0862
0863
0864
0865
0866
0867
0868
0869
0870
0871
0872
0873 if(!fImp) { Destroyed(); return; }
0874 odbc::PreparedStatement* imp = (odbc::PreparedStatement*)fImp;
0875
0876 try {
0877 imp->setFloat(parameterIndex,x);
0878
0879 } catch(odbc::SQLException& e) {
0880 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0881 ODBCXX_STRING_CSTR(e.getSQLState()),
0882 e.getErrorCode()) );
0883 }
0884 }
0885
0886
0887 void ODBCCallableStatement::SetDouble( Int_t parameterIndex,Double_t x )
0888 {
0889
0890
0891
0892
0893
0894
0895
0896
0897
0898
0899
0900 if(!fImp) { Destroyed(); return; }
0901 odbc::PreparedStatement* imp = (odbc::PreparedStatement*)fImp;
0902
0903 try {
0904 imp->setDouble(parameterIndex,x);
0905
0906 } catch(odbc::SQLException& e) {
0907 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0908 ODBCXX_STRING_CSTR(e.getSQLState()),
0909 e.getErrorCode()) );
0910 }
0911 }
0912
0913
0914 void ODBCCallableStatement::SetString( Int_t parameterIndex,
0915 const TString& x )
0916 {
0917
0918
0919
0920
0921
0922
0923
0924
0925
0926
0927
0928
0929 if(!fImp) { Destroyed(); return; }
0930 odbc::PreparedStatement* imp = (odbc::PreparedStatement*)fImp;
0931
0932 try {
0933 imp->setString( parameterIndex, ODBCXX_STRING_C(x.Data()) );
0934
0935 } catch(odbc::SQLException& e) {
0936 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0937 ODBCXX_STRING_CSTR(e.getSQLState()),
0938 e.getErrorCode()) );
0939 }
0940 }
0941
0942
0943 void ODBCCallableStatement::SetBytes( Int_t parameterIndex,
0944 const TArrayC& x )
0945 {
0946
0947
0948
0949
0950
0951
0952
0953
0954
0955
0956
0957
0958 if(!fImp) { Destroyed(); return; }
0959 odbc::PreparedStatement* imp = (odbc::PreparedStatement*)fImp;
0960
0961 try {
0962 imp->setBytes( parameterIndex,
0963 ODBCXX_BYTES_C(x.GetArray(),x.GetSize()) );
0964
0965 } catch(odbc::SQLException& e) {
0966 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0967 ODBCXX_STRING_CSTR(e.getSQLState()),
0968 e.getErrorCode()) );
0969 }
0970 }
0971
0972
0973 void ODBCCallableStatement::SetDate( Int_t parameterIndex,
0974 const TSQLDate& x )
0975 {
0976
0977
0978
0979
0980
0981
0982
0983
0984
0985
0986
0987 if(!fImp) { Destroyed(); return; }
0988 odbc::PreparedStatement* imp = (odbc::PreparedStatement*)fImp;
0989
0990 try {
0991 odbc::Date dt( x.GetYear(),
0992 x.GetMonth(),
0993 x.GetDay() );
0994
0995 imp->setDate(parameterIndex,dt);
0996
0997 } catch(odbc::SQLException& e) {
0998 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
0999 ODBCXX_STRING_CSTR(e.getSQLState()),
1000 e.getErrorCode()) );
1001 }
1002 }
1003
1004
1005 void ODBCCallableStatement::SetTime( Int_t parameterIndex,
1006 const TSQLTime& x )
1007 {
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019 if(!fImp) { Destroyed(); return; }
1020 odbc::PreparedStatement* imp = (odbc::PreparedStatement*)fImp;
1021
1022 try {
1023 odbc::Time tm( x.GetHour(),
1024 x.GetMinute(),
1025 x.GetSecond() );
1026
1027 imp->setTime(parameterIndex,tm);
1028
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 void ODBCCallableStatement::SetTimestamp( Int_t parameterIndex,
1038 const TSQLTimestamp& x )
1039 {
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051 if(!fImp) { Destroyed(); return; }
1052 odbc::PreparedStatement* imp = (odbc::PreparedStatement*)fImp;
1053
1054 try {
1055 odbc::Timestamp tmstmp( x.GetYear(),
1056 x.GetMonth(),
1057 x.GetDay(),
1058 x.GetHour(),
1059 x.GetMinute(),
1060 x.GetSecond(),
1061 x.GetNanos() );
1062
1063 imp->setTimestamp(parameterIndex,tmstmp);
1064
1065 } catch(odbc::SQLException& e) {
1066 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
1067 ODBCXX_STRING_CSTR(e.getSQLState()),
1068 e.getErrorCode()) );
1069 }
1070 }
1071
1072
1073 void ODBCCallableStatement::SetAsciiStream( Int_t parameterIndex,
1074 TBuffer* x,
1075 Int_t length )
1076 {
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095 if(!fImp) { Destroyed(); return; }
1096 odbc::PreparedStatement* imp = (odbc::PreparedStatement*)fImp;
1097
1098 try {
1099 Int_t xl = x->BufferSize()>length ? length : x->BufferSize();
1100 std::istringstream* s = new std::istringstream( x->Buffer() );
1101 imp->setAsciiStream( parameterIndex,(std::istream*)s,xl );
1102
1103 } catch(odbc::SQLException& e) {
1104 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
1105 ODBCXX_STRING_CSTR(e.getSQLState()),
1106 e.getErrorCode()) );
1107 }
1108 }
1109
1110
1111 void ODBCCallableStatement::SetBinaryStream( Int_t parameterIndex,
1112 TBuffer* x,
1113 Int_t length )
1114 {
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132 if(!fImp) { Destroyed(); return; }
1133 odbc::PreparedStatement* imp = (odbc::PreparedStatement*)fImp;
1134
1135 try {
1136 Int_t xl = x->BufferSize()>length ? length : x->BufferSize();
1137 std::string a(x->Buffer(),xl);
1138 std::istream* s = new std::istringstream(a);
1139 imp->setBinaryStream( parameterIndex,s,xl );
1140
1141 } catch(odbc::SQLException& e) {
1142 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
1143 ODBCXX_STRING_CSTR(e.getSQLState()),
1144 e.getErrorCode()) );
1145 }
1146 }
1147
1148
1149 void ODBCCallableStatement::SetObject( Int_t parameterIndex,TObject* x )
1150 {
1151
1152
1153
1154
1155
1156
1157
1158
1159 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,15,0)
1160 TBuffer *b = new TBufferFile(TBuffer::kWrite);
1161 #else
1162 TBuffer *b = new TBuffer(TBuffer::kWrite);
1163 #endif
1164 b->WriteObject(x);
1165 SetBinaryStream(parameterIndex,b,b->BufferSize());
1166 b->DetachBuffer();
1167 delete b;
1168 }
1169
1170
1171 void ODBCCallableStatement::ClearParameters()
1172 {
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185 if(!fImp) { Destroyed(); return; }
1186 odbc::PreparedStatement* imp = (odbc::PreparedStatement*)fImp;
1187
1188 try {
1189 imp->clearParameters();
1190
1191 } catch(odbc::SQLException& e) {
1192 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
1193 ODBCXX_STRING_CSTR(e.getSQLState()),
1194 e.getErrorCode()) );
1195 }
1196 }
1197
1198
1199
1200 TSQLResultSet* ODBCCallableStatement::ExecuteQuery( const TString& sql )
1201 {
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213 if(!fImp) { Destroyed(); return 0; }
1214 odbc::Statement* stmt = (odbc::Statement*)fImp;
1215 odbc::PreparedStatement* imp = (odbc::PreparedStatement*)fImp;
1216 odbc::ResultSet* rs = 0;
1217 ClearWarnings();
1218
1219 if(fCurrentResult) delete fCurrentResult;
1220
1221 try {
1222 if(!sql.IsNull()) {
1223 rs = stmt->executeQuery(ODBCXX_STRING_C(sql.Data()));
1224 } else {
1225 rs = imp->executeQuery();
1226 }
1227 } catch(odbc::SQLException& e) {
1228 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
1229 ODBCXX_STRING_CSTR(e.getSQLState()),
1230 e.getErrorCode()) );
1231 if(rs) delete rs;
1232 fCurrentResult = 0;
1233 return 0;
1234 }
1235
1236 return fCurrentResult = new ODBCResultSet(this,(void*)rs);;
1237 }
1238
1239
1240 Bool_t ODBCCallableStatement::Execute( const TString& sql )
1241 {
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266 if(!fImp) { Destroyed(); return kFALSE; }
1267
1268 Bool_t return_value = kFALSE;
1269 ClearWarnings();
1270 odbc::Statement* stmt = (odbc::Statement*)fImp;
1271 odbc::PreparedStatement* imp = (odbc::PreparedStatement*)fImp;
1272
1273 try {
1274 if(!sql.IsNull()) {
1275 return_value = (Bool_t)stmt->execute(ODBCXX_STRING_C(sql.Data()));
1276 } else {
1277 return_value = (Bool_t)imp->execute();
1278 }
1279 } catch(odbc::SQLException& e) {
1280 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
1281 ODBCXX_STRING_CSTR(e.getSQLState()),
1282 e.getErrorCode()) );
1283 return_value = kFALSE;
1284 }
1285 return return_value;
1286 }
1287
1288
1289 Int_t ODBCCallableStatement::ExecuteUpdate( const TString& sql )
1290 {
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305 if(!fImp) { Destroyed(); return 0; }
1306
1307 Int_t return_value = 0;
1308 ClearWarnings();
1309 odbc::Statement* stmt = (odbc::Statement*)fImp;
1310 odbc::PreparedStatement* imp = (odbc::PreparedStatement*)fImp;
1311
1312 try {
1313 if(!sql.IsNull()) {
1314 return_value = (Bool_t)stmt->executeUpdate(ODBCXX_STRING_C(sql.Data()));
1315 } else {
1316 return_value = (Bool_t)imp->executeUpdate();
1317 }
1318 } catch(odbc::SQLException& e) {
1319 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
1320 ODBCXX_STRING_CSTR(e.getSQLState()),
1321 e.getErrorCode()) );
1322 return_value = 0;
1323 }
1324 return return_value;
1325 }
1326
1327
1328 TSQLResultSet* ODBCCallableStatement::GetResultSet()
1329 {
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343 if(!fImp) { Destroyed(); return 0; }
1344 odbc::ResultSet* rs = 0;
1345 odbc::Statement* stmt = (odbc::Statement*)fImp;
1346
1347 if(fCurrentResult) delete fCurrentResult;
1348
1349 try {
1350 rs = stmt->getResultSet();
1351 } catch(odbc::SQLException& e) {
1352 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
1353 ODBCXX_STRING_CSTR(e.getSQLState()),
1354 e.getErrorCode()) );
1355 if(rs) delete rs;
1356 fCurrentResult = 0;
1357 return 0;
1358 }
1359
1360 return fCurrentResult = new ODBCResultSet(this,(void*)rs);
1361 }
1362
1363
1364 Int_t ODBCCallableStatement::GetUpdateCount()
1365 {
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378 if(!fImp) { Destroyed(); return 0; }
1379
1380 Int_t return_value = 0;
1381 odbc::Statement* stmt = (odbc::Statement*)fImp;
1382
1383 try {
1384 return_value = stmt->getUpdateCount();
1385 } catch(odbc::SQLException& e) {
1386 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
1387 ODBCXX_STRING_CSTR(e.getSQLState()),
1388 e.getErrorCode()) );
1389 return 0;
1390 }
1391 return return_value;
1392 }
1393
1394
1395 Bool_t ODBCCallableStatement::GetMoreResults()
1396 {
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412 Bool_t return_value = kFALSE;
1413
1414 if(!fImp) { Destroyed(); return return_value; }
1415 odbc::Statement* stmt = (odbc::Statement*)fImp;
1416
1417 try {
1418 return_value = (Bool_t)stmt->getMoreResults();
1419 } catch(odbc::SQLException& e) {
1420 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
1421 ODBCXX_STRING_CSTR(e.getSQLState()),
1422 e.getErrorCode()) );
1423 return kFALSE;
1424 }
1425 return return_value;
1426 }
1427
1428
1429 Int_t ODBCCallableStatement::GetMaxFieldSize()
1430 {
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443 if(!fImp) { Destroyed(); return 0; }
1444
1445 Int_t return_value = 0;
1446 odbc::Statement* stmt = (odbc::Statement*)fImp;
1447
1448 try {
1449 return_value = stmt->getMaxFieldSize();
1450 } catch(odbc::SQLException& e) {
1451 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
1452 ODBCXX_STRING_CSTR(e.getSQLState()),
1453 e.getErrorCode()) );
1454 return 0;
1455 }
1456 return return_value;
1457 }
1458
1459
1460 void ODBCCallableStatement::SetMaxFieldSize( Int_t max )
1461 {
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475 if(!fImp) { Destroyed(); return; }
1476 odbc::Statement* stmt = (odbc::Statement*)fImp;
1477
1478 try {
1479 stmt->setMaxFieldSize(max);
1480 } catch(odbc::SQLException& e) {
1481 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
1482 ODBCXX_STRING_CSTR(e.getSQLState()),
1483 e.getErrorCode()) );
1484 }
1485 }
1486
1487
1488 Int_t ODBCCallableStatement::GetMaxRows()
1489 {
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499 if(!fImp) { Destroyed(); return 0; }
1500
1501 Int_t return_value = 0;
1502 odbc::Statement* stmt = (odbc::Statement*)fImp;
1503
1504 try {
1505 return_value = stmt->getMaxRows();
1506 } catch(odbc::SQLException& e) {
1507 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
1508 ODBCXX_STRING_CSTR(e.getSQLState()),
1509 e.getErrorCode()) );
1510 return 0;
1511 }
1512 return return_value;
1513 }
1514
1515
1516 void ODBCCallableStatement::SetMaxRows( Int_t max )
1517 {
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527 if(!fImp) { Destroyed(); return; }
1528 odbc::Statement* stmt = (odbc::Statement*)fImp;
1529
1530 try {
1531 stmt->setMaxRows(max);
1532 } catch(odbc::SQLException& e) {
1533 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
1534 ODBCXX_STRING_CSTR(e.getSQLState()),
1535 e.getErrorCode()) );
1536 }
1537 }
1538
1539
1540 void ODBCCallableStatement::SetEscapeProcessing( Bool_t enable )
1541 {
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556 if(!fImp) { Destroyed(); return; }
1557 odbc::Statement* stmt = (odbc::Statement*)fImp;
1558
1559 try {
1560 stmt->setEscapeProcessing(enable);
1561 } catch(odbc::SQLException& e) {
1562 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
1563 ODBCXX_STRING_CSTR(e.getSQLState()),
1564 e.getErrorCode()) );
1565 }
1566 }
1567
1568
1569 Bool_t ODBCCallableStatement::GetEscapeProcessing()
1570 {
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585 if(!fImp) { Destroyed(); return kFALSE; }
1586
1587 Bool_t return_value = kFALSE;
1588 odbc::Statement* stmt = (odbc::Statement*)fImp;
1589
1590 try {
1591 return_value = stmt->getEscapeProcessing();
1592 } catch(odbc::SQLException& e) {
1593 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
1594 ODBCXX_STRING_CSTR(e.getSQLState()),
1595 e.getErrorCode()) );
1596 return kFALSE;
1597 }
1598 return return_value;
1599 }
1600
1601
1602 Int_t ODBCCallableStatement::GetQueryTimeout()
1603 {
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614 Int_t return_value = 0;
1615
1616 if(!fImp) { Destroyed(); return return_value; }
1617 odbc::Statement* stmt = (odbc::Statement*)fImp;
1618
1619 try {
1620 return_value = stmt->getQueryTimeout();
1621 } catch(odbc::SQLException& e) {
1622 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
1623 ODBCXX_STRING_CSTR(e.getSQLState()),
1624 e.getErrorCode()) );
1625 return 0;
1626 }
1627 return return_value;
1628 }
1629
1630
1631 void ODBCCallableStatement::SetQueryTimeout( Int_t seconds )
1632 {
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643 if(!fImp) { Destroyed(); return; }
1644 odbc::Statement* stmt = (odbc::Statement*)fImp;
1645
1646 try {
1647 stmt->setQueryTimeout(seconds);
1648 } catch(odbc::SQLException& e) {
1649 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
1650 ODBCXX_STRING_CSTR(e.getSQLState()),
1651 e.getErrorCode()) );
1652 }
1653 }
1654
1655
1656 void ODBCCallableStatement::Cancel()
1657 {
1658
1659
1660
1661
1662
1663
1664
1665
1666 if(!fImp) { Destroyed(); return; }
1667 odbc::Statement* stmt = (odbc::Statement*)fImp;
1668
1669 try {
1670 stmt->cancel();
1671 } catch(odbc::SQLException& e) {
1672 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
1673 ODBCXX_STRING_CSTR(e.getSQLState()),
1674 e.getErrorCode()) );
1675 }
1676 }
1677
1678
1679 void ODBCCallableStatement::Close()
1680 {
1681
1682
1683
1684
1685
1686
1687
1688
1689 if(!fImp) { Destroyed(); return; }
1690
1691 try {
1692 if(fCurrentResult) {
1693 delete fCurrentResult;
1694 fCurrentResult = 0;
1695 }
1696 ClearBatch();
1697 SafeDelete(fBatches);
1698
1699 odbc::Statement* imp = (odbc::Statement*)fImp;
1700 if(imp) delete imp;
1701 } catch(odbc::SQLException& e) {
1702 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
1703 ODBCXX_STRING_CSTR(e.getSQLState()),
1704 e.getErrorCode()) );
1705 }
1706 fImp = 0;
1707 Destroyed();
1708 }
1709
1710
1711 void ODBCCallableStatement::SetCursorName( const TString& name )
1712 {
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735 if(!fImp) { Destroyed(); return; }
1736 odbc::Statement* stmt = (odbc::Statement*)fImp;
1737
1738 try {
1739 stmt->setCursorName(ODBCXX_STRING_C(name.Data()));
1740 } catch(odbc::SQLException& e) {
1741 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
1742 ODBCXX_STRING_CSTR(e.getSQLState()),
1743 e.getErrorCode()) );
1744 }
1745 }
1746
1747
1748 void ODBCCallableStatement::SetFetchDirection( Int_t )
1749 {
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765 if(!fImp) { Destroyed(); return; }
1766 }
1767
1768
1769 Int_t ODBCCallableStatement::GetFetchDirection()
1770 {
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783 return 0;
1784 }
1785
1786
1787 void ODBCCallableStatement::SetFetchSize( Int_t )
1788 {
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801 if(!fImp) { Destroyed(); return; }
1802 }
1803
1804
1805 Int_t ODBCCallableStatement::GetFetchSize()
1806 {
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819 Int_t return_value = 0;
1820
1821 if(!fImp) { Destroyed(); return return_value; }
1822 odbc::Statement* stmt = (odbc::Statement*)fImp;
1823
1824 try {
1825 return_value = stmt->getFetchSize();
1826 } catch(odbc::SQLException& e) {
1827 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
1828 ODBCXX_STRING_CSTR(e.getSQLState()),
1829 e.getErrorCode()) );
1830 return 0;
1831 }
1832 return return_value;
1833 }
1834
1835
1836 Int_t ODBCCallableStatement::GetResultSetConcurrency()
1837 {
1838
1839
1840
1841
1842
1843
1844
1845 Int_t return_value = 0;
1846
1847 if(!fImp) { Destroyed(); return return_value; }
1848 odbc::Statement* stmt = (odbc::Statement*)fImp;
1849
1850 try {
1851 return_value = stmt->getResultSetConcurrency();
1852 } catch(odbc::SQLException& e) {
1853 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
1854 ODBCXX_STRING_CSTR(e.getSQLState()),
1855 e.getErrorCode()) );
1856 return 0;
1857 }
1858 return return_value;
1859 }
1860
1861
1862 Int_t ODBCCallableStatement::GetResultSetType()
1863 {
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873 Int_t return_value = 0;
1874
1875 if(!fImp) { Destroyed(); return return_value; }
1876 odbc::Statement* stmt = (odbc::Statement*)fImp;
1877
1878 try {
1879 return_value = stmt->getResultSetType();
1880 } catch(odbc::SQLException& e) {
1881 Throw( new TSQLException( ODBCXX_STRING_CSTR(e.getMessage()),
1882 ODBCXX_STRING_CSTR(e.getSQLState()),
1883 e.getErrorCode()) );
1884 return 0;
1885 }
1886 return return_value;
1887 }
1888
1889
1890 void ODBCCallableStatement::AddBatch( const TString& )
1891 {
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902 }
1903
1904
1905 void ODBCCallableStatement::ClearBatch()
1906 {
1907
1908
1909
1910
1911
1912
1913
1914 }
1915
1916
1917 Int_t* ODBCCallableStatement::ExecuteBatch()
1918 {
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932 return 0;
1933 }